Skip to contentSkip to conversation

mmc: meson-gx: fix wrong conversion of __bf_shf to __ffs

PATCH In review Christian Marangi 2 participants 2 messages Aug 12, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: meson-gx: fix wrong conversion of __bf_shf to __ffs

Commit 795c633f6093 ("mmc: meson-gx: fix __ffsdi2 undefined on arm32") changed __bf_shf to __ffs to fix a compile error on 32bit arch that have problems with __ffsdi2. This comes from the fact that __bf_shf use __builtin_ffsll and on 32bit __ffsdi2 is missing.

Problem is that __bf_shf is defined as

  #define __bf_shf(x) (__builtin_ffsll(x) - 1)

but the patch doesn't account for the - 1.

Fix this by using the __builtin_ffs and add the - 1 to reflect the original implementation.

The commit also converted other entry of __bf_shf in the code but those got dropped in later patches.

Fixes 795c633f6093 ("mmc: meson-gx: fix __ffsdi2 undefined on arm32")
Cc [email protected] # see patch description, needs adjustements for < 5.2
---
 drivers/mmc/host/meson-gx-mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +2 -2
index c7c067b9415a..8f64083a08fa 100644
@@ -464,7 +464,7 @@ static int meson_mmc_clk_init(struct meson_host *host)
 	init.num_parents = MUX_CLK_NUM_PARENTS;
 
 	mux->reg = host->regs + SD_EMMC_CLOCK;
-	mux->shift = __ffs(CLK_SRC_MASK);
+	mux->shift = __builtin_ffs(CLK_SRC_MASK) - 1;
 	mux->mask = CLK_SRC_MASK >> mux->shift;
 	mux->hw.init = &init;
 
@@ -486,7 +486,7 @@ static int meson_mmc_clk_init(struct meson_host *host)
 	init.num_parents = 1;
 
 	div->reg = host->regs + SD_EMMC_CLOCK;
-	div->shift = __ffs(CLK_DIV_MASK);
+	div->shift = __builtin_ffs(CLK_DIV_MASK) - 1;
 	div->width = __builtin_popcountl(CLK_DIV_MASK);
 	div->hw.init = &init;
 	div->flags = CLK_DIVIDER_ONE_BASED;
Signature · 1 line
2.45.2
reviewer
#1 lore raw
Quoted 11 lines · Christian Marangi

Commit 795c633f6093 ("mmc: meson-gx: fix __ffsdi2 undefined on arm32") changed __bf_shf to __ffs to fix a compile error on 32bit arch that have problems with __ffsdi2. This comes from the fact that __bf_shf use __builtin_ffsll and on 32bit __ffsdi2 is missing.

Problem is that __bf_shf is defined as

  #define __bf_shf(x) (__builtin_ffsll(x) - 1)

but the patch doesn't account for the - 1.

Quoted 8 lines

Fix this by using the __builtin_ffs and add the - 1 to reflect the original implementation.

The commit also converted other entry of __bf_shf in the code but those got dropped in later patches.

Fixes 795c633f6093 ("mmc: meson-gx: fix __ffsdi2 undefined on arm32")

Hi Christian,

Are you fixing an actual problem you've seen with the platform and or this solely based on the original commit description ?

If I dump the shift values with what we have right now, on sm1 at least
* Mux shift is 6
* Div shift is 0

This is aligned with the datasheet and has been working for while now.

Quoted 27 lines
Cc [email protected] # see patch description, needs adjustements for < 5.2
---
 drivers/mmc/host/meson-gx-mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +2 -2
index c7c067b9415a..8f64083a08fa 100644
@@ -464,7 +464,7 @@ static int meson_mmc_clk_init(struct meson_host *host)
 	init.num_parents = MUX_CLK_NUM_PARENTS;
 
 	mux->reg = host->regs + SD_EMMC_CLOCK;
-	mux->shift = __ffs(CLK_SRC_MASK);
+	mux->shift = __builtin_ffs(CLK_SRC_MASK) - 1;
 	mux->mask = CLK_SRC_MASK >> mux->shift;
 	mux->hw.init = &init;
 
@@ -486,7 +486,7 @@ static int meson_mmc_clk_init(struct meson_host *host)
 	init.num_parents = 1;
 
 	div->reg = host->regs + SD_EMMC_CLOCK;
-	div->shift = __ffs(CLK_DIV_MASK);
+	div->shift = __builtin_ffs(CLK_DIV_MASK) - 1;
 	div->width = __builtin_popcountl(CLK_DIV_MASK);
 	div->hw.init = &init;
 	div->flags = CLK_DIVIDER_ONE_BASED;
Signature · 1 line
Jerome