From: Martin Blumenstingl <[email protected]>
[ Upstream commit 82ca4c922b8992013a238d65cf4e60cc33e12f36 ]
The m250_sel mux clock uses bit 4 in the PRG_ETH0 register. Fix this by
shifting the PRG_ETH0_CLK_M250_SEL_MASK accordingly as the "mask" in
struct clk_mux expects the mask relative to the "shift" field in the
same struct.
While here, get rid of the PRG_ETH0_CLK_M250_SEL_SHIFT macro and use
__ffs() to determine it from the existing PRG_ETH0_CLK_M250_SEL_MASK
macro.
Fixes: 566e8251625304 ("net: stmmac: add a glue driver for the Amlogic Meson 8b / GXBB DWMAC")
Signed-off-by: Martin Blumenstingl <[email protected]>
Reviewed-by: Jerome Brunet <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
@@ -30,7 +30,6 @@
#define PRG_ETH0_EXT_RMII_MODE 4
/* mux to choose between fclk_div2 (bit unset) and mpll2 (bit set) */
-#define PRG_ETH0_CLK_M250_SEL_SHIFT 4
#define PRG_ETH0_CLK_M250_SEL_MASK GENMASK(4, 4)
/* TX clock delay in ns = "8ns / 4 * tx_dly_val" (where 8ns are exactly one
@@ -155,8 +154,9 @@ static int meson8b_init_rgmii_tx_clk(str
return -ENOMEM;
clk_configs->m250_mux.reg = dwmac->regs + PRG_ETH0;
- clk_configs->m250_mux.shift = PRG_ETH0_CLK_M250_SEL_SHIFT;
- clk_configs->m250_mux.mask = PRG_ETH0_CLK_M250_SEL_MASK;
+ clk_configs->m250_mux.shift = __ffs(PRG_ETH0_CLK_M250_SEL_MASK);
+ clk_configs->m250_mux.mask = PRG_ETH0_CLK_M250_SEL_MASK >>
+ clk_configs->m250_mux.shift;
clk = meson8b_dwmac_register_clk(dwmac, "m250_sel", mux_parents,
ARRAY_SIZE(mux_parents), &clk_mux_ops,
&clk_configs->m250_mux.hw);
Hi!
> From: Martin Blumenstingl <[email protected]>
>
> [ Upstream commit 82ca4c922b8992013a238d65cf4e60cc33e12f36 ]
>
> The m250_sel mux clock uses bit 4 in the PRG_ETH0 register. Fix this by
> shifting the PRG_ETH0_CLK_M250_SEL_MASK accordingly as the "mask" in
> struct clk_mux expects the mask relative to the "shift" field in the
> same struct.
>
> While here, get rid of the PRG_ETH0_CLK_M250_SEL_SHIFT macro and use
> __ffs() to determine it from the existing PRG_ETH0_CLK_M250_SEL_MASK
> macro.
I can't say I like this one:
> clk_configs->m250_mux.reg = dwmac->regs + PRG_ETH0;
> - clk_configs->m250_mux.shift = PRG_ETH0_CLK_M250_SEL_SHIFT;
> - clk_configs->m250_mux.mask = PRG_ETH0_CLK_M250_SEL_MASK;
> + clk_configs->m250_mux.shift = __ffs(PRG_ETH0_CLK_M250_SEL_MASK);
It replaces constant with computation done at runtime; compiler can't
optimize it as __ffs is implemented with asm().
Best regards,
Pavel
--
http://www.livejournal.com/~pavelmachek
Hi Pavel,
On Sat, Dec 19, 2020 at 10:51 PM Pavel Machek <[email protected]> wrote:
[...]
> I can't say I like this one:
>
>
> > clk_configs->m250_mux.reg = dwmac->regs + PRG_ETH0;
> > - clk_configs->m250_mux.shift = PRG_ETH0_CLK_M250_SEL_SHIFT;
> > - clk_configs->m250_mux.mask = PRG_ETH0_CLK_M250_SEL_MASK;
> > + clk_configs->m250_mux.shift = __ffs(PRG_ETH0_CLK_M250_SEL_MASK);
>
> It replaces constant with computation done at runtime; compiler can't
> optimize it as __ffs is implemented with asm().
what do you suggest to use instead?
personally I don't see a problem because this is only called once at
driver probe time.
Best regards,
Martin
On Sat 2020-12-19 23:38:25, Martin Blumenstingl wrote:
> Hi Pavel,
>
> On Sat, Dec 19, 2020 at 10:51 PM Pavel Machek <[email protected]> wrote:
> [...]
> > I can't say I like this one:
> >
> >
> > > clk_configs->m250_mux.reg = dwmac->regs + PRG_ETH0;
> > > - clk_configs->m250_mux.shift = PRG_ETH0_CLK_M250_SEL_SHIFT;
> > > - clk_configs->m250_mux.mask = PRG_ETH0_CLK_M250_SEL_MASK;
> > > + clk_configs->m250_mux.shift = __ffs(PRG_ETH0_CLK_M250_SEL_MASK);
> >
> > It replaces constant with computation done at runtime; compiler can't
> > optimize it as __ffs is implemented with asm().
> what do you suggest to use instead?
> personally I don't see a problem because this is only called once at
> driver probe time.
I believe canonical solution is version before this patch, just with
fixed values....
I mean yes, computation at runtime is not end of the world, but it is
both slower and needs more code space...
Best regards,
Pavel
--
http://www.livejournal.com/~pavelmachek
Hi Pavel,
On Sun, Dec 20, 2020 at 12:13 AM Pavel Machek <[email protected]> wrote:
>
> On Sat 2020-12-19 23:38:25, Martin Blumenstingl wrote:
> > Hi Pavel,
> >
> > On Sat, Dec 19, 2020 at 10:51 PM Pavel Machek <[email protected]> wrote:
> > [...]
> > > I can't say I like this one:
> > >
> > >
> > > > clk_configs->m250_mux.reg = dwmac->regs + PRG_ETH0;
> > > > - clk_configs->m250_mux.shift = PRG_ETH0_CLK_M250_SEL_SHIFT;
> > > > - clk_configs->m250_mux.mask = PRG_ETH0_CLK_M250_SEL_MASK;
> > > > + clk_configs->m250_mux.shift = __ffs(PRG_ETH0_CLK_M250_SEL_MASK);
> > >
> > > It replaces constant with computation done at runtime; compiler can't
> > > optimize it as __ffs is implemented with asm().
> > what do you suggest to use instead?
> > personally I don't see a problem because this is only called once at
> > driver probe time.
>
> I believe canonical solution is version before this patch, just with
> fixed values....
OK, thanks for the hint
I will keep it in my for patches in the future
Best regards,
Martin