From 8bb59ca2faee83ba50850900c8b4edf9331ae931 Mon Sep 17 00:00:00 2001 From: Jianjun Wang Date: Tue, 30 Nov 2021 10:51:53 +0800 Subject: lib: Add __fls() (Find Last Set) Implement __fls() as an alias for log2(), and remove the duplicate definitions in commonlib/storage/sdhci.c. Signed-off-by: Jianjun Wang Change-Id: Ib458abfec7e03b2979569a8440a6e69b0285ac32 Reviewed-on: https://review.coreboot.org/c/coreboot/+/59738 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner Reviewed-by: Yu-Ping Wu --- src/commonlib/storage/sdhci.c | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) (limited to 'src/commonlib') diff --git a/src/commonlib/storage/sdhci.c b/src/commonlib/storage/sdhci.c index 6d39a45f5e..16420d99fa 100644 --- a/src/commonlib/storage/sdhci.c +++ b/src/commonlib/storage/sdhci.c @@ -6,14 +6,15 @@ #include "bouncebuf.h" #include #include +#include #include #include #include +#include #include "sdhci.h" #include "sd_mmc.h" #include "storage.h" #include -#include #define DMA_AVAILABLE ((CONFIG(SDHCI_ADMA_IN_BOOTBLOCK) && ENV_BOOTBLOCK) \ || (CONFIG(SDHCI_ADMA_IN_VERSTAGE) && ENV_SEPARATE_VERSTAGE) \ @@ -411,36 +412,6 @@ static int sdhci_set_clock(struct sdhci_ctrlr *sdhci_ctrlr, unsigned int clock) return 0; } -/* Find leftmost set bit in a 32 bit integer */ -static int fls(u32 x) -{ - int r = 32; - - if (!x) - return 0; - if (!(x & 0xffff0000u)) { - x <<= 16; - r -= 16; - } - if (!(x & 0xff000000u)) { - x <<= 8; - r -= 8; - } - if (!(x & 0xf0000000u)) { - x <<= 4; - r -= 4; - } - if (!(x & 0xc0000000u)) { - x <<= 2; - r -= 2; - } - if (!(x & 0x80000000u)) { - x <<= 1; - r -= 1; - } - return r; -} - static void sdhci_set_power(struct sdhci_ctrlr *sdhci_ctrlr, unsigned short power) { @@ -718,7 +689,7 @@ static int sdhci_init(struct sdhci_ctrlr *sdhci_ctrlr) if (rv) return rv; /* The error has been already reported */ - sdhci_set_power(sdhci_ctrlr, fls(ctrlr->voltages) - 1); + sdhci_set_power(sdhci_ctrlr, __fls(ctrlr->voltages)); if (ctrlr->caps & DRVR_CAP_NO_CD) { unsigned int status; -- cgit v1.2.3