From: Biju Das <biju.das.jz@bp.renesas.com>
Update RCANFD_CFG_* macros to give a meaning to the magic number using
GENMASK macro and extract the values using FIELD_PREP macro.
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2:
* Moved from patch#4 to patch#2.
* Updated commit header and description.
* Kept RCANFD_CFG* macro definitions to give a meaning to the magic
number using GENMASK macro and used FIELD_PREP to extract value.
---
drivers/net/can/rcar/rcar_canfd.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
index ce355f79e6b6..8bae25758924 100644
--- a/drivers/net/can/rcar/rcar_canfd.c
+++ b/drivers/net/can/rcar/rcar_canfd.c
@@ -103,10 +103,10 @@
/* Channel register bits */
/* RSCFDnCmCFG - Classical CAN only */
-#define RCANFD_CFG_SJW(x) (((x) & 0x3) << 24)
-#define RCANFD_CFG_TSEG2(x) (((x) & 0x7) << 20)
-#define RCANFD_CFG_TSEG1(x) (((x) & 0xf) << 16)
-#define RCANFD_CFG_BRP(x) (((x) & 0x3ff) << 0)
+#define RCANFD_CFG_SJW_MASK GENMASK(25, 24)
+#define RCANFD_CFG_TSEG2_MASK GENMASK(22, 20)
+#define RCANFD_CFG_TSEG1_MASK GENMASK(19, 16)
+#define RCANFD_CFG_BRP_MASK GENMASK(9, 0)
/* RSCFDnCFDCmNCFG - CAN FD only */
#define RCANFD_NCFG_NTSEG2(gpriv, x) \
@@ -1416,8 +1416,10 @@ static void rcar_canfd_set_bittiming(struct net_device *ndev)
cfg = (RCANFD_NCFG_NTSEG1(gpriv, tseg1) | RCANFD_NCFG_NBRP(brp) |
RCANFD_NCFG_NSJW(gpriv, sjw) | RCANFD_NCFG_NTSEG2(gpriv, tseg2));
} else {
- cfg = (RCANFD_CFG_TSEG1(tseg1) | RCANFD_CFG_BRP(brp) |
- RCANFD_CFG_SJW(sjw) | RCANFD_CFG_TSEG2(tseg2));
+ cfg = FIELD_PREP(RCANFD_CFG_TSEG1_MASK, tseg1) |
+ FIELD_PREP(RCANFD_CFG_BRP_MASK, brp) |
+ FIELD_PREP(RCANFD_CFG_SJW_MASK, sjw) |
+ FIELD_PREP(RCANFD_CFG_TSEG2_MASK, tseg2);
}
rcar_canfd_write(priv->base, RCANFD_CCFG(ch), cfg);
--
2.43.0
Hi Biju, On Thu, 21 Aug 2025 at 16:14, Biju <biju.das.au@gmail.com> wrote: > From: Biju Das <biju.das.jz@bp.renesas.com> > > Update RCANFD_CFG_* macros to give a meaning to the magic number using > GENMASK macro and extract the values using FIELD_PREP macro. > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > --- > v1->v2: > * Moved from patch#4 to patch#2. > * Updated commit header and description. > * Kept RCANFD_CFG* macro definitions to give a meaning to the magic > number using GENMASK macro and used FIELD_PREP to extract value. > --- a/drivers/net/can/rcar/rcar_canfd.c > +++ b/drivers/net/can/rcar/rcar_canfd.c > @@ -103,10 +103,10 @@ > /* Channel register bits */ > > /* RSCFDnCmCFG - Classical CAN only */ > -#define RCANFD_CFG_SJW(x) (((x) & 0x3) << 24) > -#define RCANFD_CFG_TSEG2(x) (((x) & 0x7) << 20) > -#define RCANFD_CFG_TSEG1(x) (((x) & 0xf) << 16) > -#define RCANFD_CFG_BRP(x) (((x) & 0x3ff) << 0) > +#define RCANFD_CFG_SJW_MASK GENMASK(25, 24) > +#define RCANFD_CFG_TSEG2_MASK GENMASK(22, 20) > +#define RCANFD_CFG_TSEG1_MASK GENMASK(19, 16) > +#define RCANFD_CFG_BRP_MASK GENMASK(9, 0) Upon a second look, I would drop the "_MASK" suffix. > > /* RSCFDnCFDCmNCFG - CAN FD only */ > #define RCANFD_NCFG_NTSEG2(gpriv, x) \ Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
On Thu, 21 Aug 2025 at 16:14, Biju <biju.das.au@gmail.com> wrote: > From: Biju Das <biju.das.jz@bp.renesas.com> > > Update RCANFD_CFG_* macros to give a meaning to the magic number using > GENMASK macro and extract the values using FIELD_PREP macro. > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > --- > v1->v2: > * Moved from patch#4 to patch#2. > * Updated commit header and description. > * Kept RCANFD_CFG* macro definitions to give a meaning to the magic > number using GENMASK macro and used FIELD_PREP to extract value. Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
© 2016 - 2025 Red Hat, Inc.