linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] R-Car CANFD Improvements
@ 2025-08-21 14:14 Biju
  2025-08-21 14:14 ` [PATCH v2 1/4] can: rcar_canfd: Add shared_bittiming variable to struct rcar_canfd_hw_info Biju
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Biju @ 2025-08-21 14:14 UTC (permalink / raw)
  To: Marc Kleine-Budde, Vincent Mailhol, Geert Uytterhoeven,
	Magnus Damm
  Cc: Biju Das, linux-can, linux-renesas-soc, linux-kernel,
	Prabhakar Mahadev Lad, Biju Das

From: Biju Das <biju.das.jz@bp.renesas.com>

The calculation formula for nominal bit rate of classical CAN is same as
that of nominal bit rate of CANFD on the RZ/G3E SoC compared to other SoCs.
Add shared_bittiming variable to struct rcar_canfd_hw_info to handle this
difference.

Apart from this, for replacing function-like macros, introduced
rcar_canfd_compute_{nominal,data}_bit_rate_cfg().

v1->v2:
 * Dropped patch#2 as it is accepted.
 * Moved patch#4 to patch#2.
 * Updated commit header and description for patch#2.
 * Kept RCANFD_CFG* macro definitions to give a meaning to the magic
   number using GENMASK macro and used FIELD_PREP to extract value.
 * Split patch#3 for computing nominal  and data bit rate config separate.
 * Updated rcar_canfd_compute_nominal_bit_rate_cfg() to handle
   nominal bit rate configuration for both classical CAN and CANFD.
 * Replaced RCANFD_NCFG_NBRP->RCANFD_NCFG_NBRP_MASK and used FIELD_PREP to
   extract value.
 * Replaced RCANFD_DCFG_DBRP->RCANFD_DCFG_DBRP_MASK and used FIELD_PREP to
   extract value.

Biju Das (4):
  can: rcar_canfd: Add shared_bittiming variable to struct
    rcar_canfd_hw_info
  can: rcar_canfd: Update RCANFD_CFG_* macros
  can: rcar_canfd: Simplify nominal bit rate config
  can: rcar_canfd: Simplify data bit rate config

 drivers/net/can/rcar/rcar_canfd.c | 89 ++++++++++++++++++-------------
 1 file changed, 52 insertions(+), 37 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/4] can: rcar_canfd: Add shared_bittiming variable to struct rcar_canfd_hw_info
  2025-08-21 14:14 [PATCH v2 0/4] R-Car CANFD Improvements Biju
@ 2025-08-21 14:14 ` Biju
  2025-09-01 13:16   ` Geert Uytterhoeven
  2025-08-21 14:14 ` [PATCH v2 2/4] can: rcar_canfd: Update RCANFD_CFG_* macros Biju
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Biju @ 2025-08-21 14:14 UTC (permalink / raw)
  To: Marc Kleine-Budde, Vincent Mailhol, Geert Uytterhoeven,
	Magnus Damm
  Cc: Biju Das, linux-can, linux-renesas-soc, linux-kernel,
	Prabhakar Mahadev Lad, Biju Das, Fabrizio Castro

From: Biju Das <biju.das.jz@bp.renesas.com>

The calculation formula for nominal bit rate of classical CAN is same as
that of nominal bit rate of CANFD on the RZ/G3E SoC compared to other SoCs.
Add shared_bittiming variable to struct rcar_canfd_hw_info to handle this
difference.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Fabrizio Castro <fabrizio.castro.jz@renesas.com>
---
v1->v2:
 * No change.
---
 drivers/net/can/rcar/rcar_canfd.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
index b3c8c592fb0e..ce355f79e6b6 100644
--- a/drivers/net/can/rcar/rcar_canfd.c
+++ b/drivers/net/can/rcar/rcar_canfd.c
@@ -461,6 +461,7 @@ struct rcar_canfd_hw_info {
 	unsigned ch_interface_mode:1;	/* Has channel interface mode */
 	unsigned shared_can_regs:1;	/* Has shared classical can registers */
 	unsigned external_clk:1;	/* Has external clock */
+	unsigned shared_bittiming:1;	/* Has shared nominal bittiming constants */
 };
 
 /* Channel priv data */
@@ -632,6 +633,7 @@ static const struct rcar_canfd_hw_info rcar_gen3_hw_info = {
 	.ch_interface_mode = 0,
 	.shared_can_regs = 0,
 	.external_clk = 1,
+	.shared_bittiming = 0,
 };
 
 static const struct rcar_canfd_hw_info rcar_gen4_hw_info = {
@@ -649,6 +651,7 @@ static const struct rcar_canfd_hw_info rcar_gen4_hw_info = {
 	.ch_interface_mode = 1,
 	.shared_can_regs = 1,
 	.external_clk = 1,
+	.shared_bittiming = 0,
 };
 
 static const struct rcar_canfd_hw_info rzg2l_hw_info = {
@@ -666,6 +669,7 @@ static const struct rcar_canfd_hw_info rzg2l_hw_info = {
 	.ch_interface_mode = 0,
 	.shared_can_regs = 0,
 	.external_clk = 1,
+	.shared_bittiming = 0,
 };
 
 static const struct rcar_canfd_hw_info r9a09g047_hw_info = {
@@ -683,6 +687,7 @@ static const struct rcar_canfd_hw_info r9a09g047_hw_info = {
 	.ch_interface_mode = 1,
 	.shared_can_regs = 1,
 	.external_clk = 0,
+	.shared_bittiming = 1,
 };
 
 /* Helper functions */
@@ -1912,7 +1917,10 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,
 		priv->can.fd.do_get_auto_tdcv = rcar_canfd_get_auto_tdcv;
 	} else {
 		/* Controller starts in Classical CAN only mode */
-		priv->can.bittiming_const = &rcar_canfd_bittiming_const;
+		if (gpriv->info->shared_bittiming)
+			priv->can.bittiming_const = gpriv->info->nom_bittiming;
+		else
+			priv->can.bittiming_const = &rcar_canfd_bittiming_const;
 		priv->can.ctrlmode_supported = CAN_CTRLMODE_BERR_REPORTING;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/4] can: rcar_canfd: Update RCANFD_CFG_* macros
  2025-08-21 14:14 [PATCH v2 0/4] R-Car CANFD Improvements Biju
  2025-08-21 14:14 ` [PATCH v2 1/4] can: rcar_canfd: Add shared_bittiming variable to struct rcar_canfd_hw_info Biju
@ 2025-08-21 14:14 ` Biju
  2025-09-01 13:21   ` Geert Uytterhoeven
  2025-09-01 13:24   ` Geert Uytterhoeven
  2025-08-21 14:14 ` [PATCH v2 3/4] can: rcar_canfd: Simplify nominal bit rate config Biju
  2025-08-21 14:14 ` [PATCH v2 4/4] can: rcar_canfd: Simplify data " Biju
  3 siblings, 2 replies; 10+ messages in thread
From: Biju @ 2025-08-21 14:14 UTC (permalink / raw)
  To: Marc Kleine-Budde, Vincent Mailhol, Geert Uytterhoeven,
	Magnus Damm
  Cc: Biju Das, linux-can, linux-renesas-soc, linux-kernel,
	Prabhakar Mahadev Lad, Biju Das

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 3/4] can: rcar_canfd: Simplify nominal bit rate config
  2025-08-21 14:14 [PATCH v2 0/4] R-Car CANFD Improvements Biju
  2025-08-21 14:14 ` [PATCH v2 1/4] can: rcar_canfd: Add shared_bittiming variable to struct rcar_canfd_hw_info Biju
  2025-08-21 14:14 ` [PATCH v2 2/4] can: rcar_canfd: Update RCANFD_CFG_* macros Biju
@ 2025-08-21 14:14 ` Biju
  2025-09-01 13:37   ` Geert Uytterhoeven
  2025-08-21 14:14 ` [PATCH v2 4/4] can: rcar_canfd: Simplify data " Biju
  3 siblings, 1 reply; 10+ messages in thread
From: Biju @ 2025-08-21 14:14 UTC (permalink / raw)
  To: Marc Kleine-Budde, Vincent Mailhol, Geert Uytterhoeven,
	Magnus Damm
  Cc: Biju Das, linux-can, linux-renesas-soc, linux-kernel,
	Prabhakar Mahadev Lad, Biju Das

From: Biju Das <biju.das.jz@bp.renesas.com>

Introduce rcar_canfd_compute_nominal_bit_rate_cfg() for simplifying
nominal bit rate configuration by replacing function-like macros.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2:
 * Split from patch#3 for computing nominal bit rate config separate.
 * Updated rcar_canfd_compute_nominal_bit_rate_cfg() to handle
   nominal bit rate configuration for both classical CAN and CANFD.
 * Replaced RCANFD_NCFG_NBRP->RCANFD_NCFG_NBRP_MASK and used FIELD_PREP to
   extract value.
---
 drivers/net/can/rcar/rcar_canfd.c | 45 ++++++++++++++++---------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
index 8bae25758924..944b960c0b5e 100644
--- a/drivers/net/can/rcar/rcar_canfd.c
+++ b/drivers/net/can/rcar/rcar_canfd.c
@@ -109,16 +109,7 @@
 #define RCANFD_CFG_BRP_MASK		GENMASK(9, 0)
 
 /* RSCFDnCFDCmNCFG - CAN FD only */
-#define RCANFD_NCFG_NTSEG2(gpriv, x) \
-	(((x) & ((gpriv)->info->nom_bittiming->tseg2_max - 1)) << (gpriv)->info->sh->ntseg2)
-
-#define RCANFD_NCFG_NTSEG1(gpriv, x) \
-	(((x) & ((gpriv)->info->nom_bittiming->tseg1_max - 1)) << (gpriv)->info->sh->ntseg1)
-
-#define RCANFD_NCFG_NSJW(gpriv, x) \
-	(((x) & ((gpriv)->info->nom_bittiming->sjw_max - 1)) << (gpriv)->info->sh->nsjw)
-
-#define RCANFD_NCFG_NBRP(x)		(((x) & 0x3ff) << 0)
+#define RCANFD_NCFG_NBRP_MASK		GENMASK(9, 0)
 
 /* RSCFDnCFDCmCTR / RSCFDnCmCTR */
 #define RCANFD_CCTR_CTME		BIT(24)
@@ -1393,6 +1384,28 @@ static irqreturn_t rcar_canfd_channel_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static inline u32 rcar_canfd_compute_nominal_bit_rate_cfg(struct rcar_canfd_channel *priv,
+							  u16 tseg1, u16 brp, u16 sjw, u16 tseg2)
+{
+	struct rcar_canfd_global *gpriv = priv->gpriv;
+	const struct rcar_canfd_hw_info *info = gpriv->info;
+	u32 ntseg2, ntseg1, nsjw, nbrp;
+
+	if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) || gpriv->info->shared_can_regs) {
+		ntseg2 = (tseg2 & (info->nom_bittiming->tseg2_max - 1)) << info->sh->ntseg2;
+		ntseg1 = (tseg1 & (info->nom_bittiming->tseg1_max - 1)) << info->sh->ntseg1;
+		nsjw = (sjw & (info->nom_bittiming->sjw_max - 1)) << info->sh->nsjw;
+		nbrp = FIELD_PREP(RCANFD_NCFG_NBRP_MASK, brp);
+	} else {
+		ntseg2 = FIELD_PREP(RCANFD_CFG_TSEG2_MASK, tseg2);
+		ntseg1 = FIELD_PREP(RCANFD_CFG_TSEG1_MASK, tseg1);
+		nsjw = FIELD_PREP(RCANFD_CFG_SJW_MASK, sjw);
+		nbrp = FIELD_PREP(RCANFD_CFG_BRP_MASK, brp);
+	}
+
+	return (ntseg1 | nbrp | nsjw | ntseg2);
+}
+
 static void rcar_canfd_set_bittiming(struct net_device *ndev)
 {
 	u32 mask = RCANFD_FDCFG_TDCO | RCANFD_FDCFG_TDCE | RCANFD_FDCFG_TDCOC;
@@ -1411,17 +1424,7 @@ static void rcar_canfd_set_bittiming(struct net_device *ndev)
 	sjw = bt->sjw - 1;
 	tseg1 = bt->prop_seg + bt->phase_seg1 - 1;
 	tseg2 = bt->phase_seg2 - 1;
-
-	if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) || gpriv->info->shared_can_regs) {
-		cfg = (RCANFD_NCFG_NTSEG1(gpriv, tseg1) | RCANFD_NCFG_NBRP(brp) |
-		       RCANFD_NCFG_NSJW(gpriv, sjw) | RCANFD_NCFG_NTSEG2(gpriv, tseg2));
-	} else {
-		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);
-	}
-
+	cfg = rcar_canfd_compute_nominal_bit_rate_cfg(priv, tseg1, brp, sjw, tseg2);
 	rcar_canfd_write(priv->base, RCANFD_CCFG(ch), cfg);
 
 	if (!(priv->can.ctrlmode & CAN_CTRLMODE_FD))
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 4/4] can: rcar_canfd: Simplify data bit rate config
  2025-08-21 14:14 [PATCH v2 0/4] R-Car CANFD Improvements Biju
                   ` (2 preceding siblings ...)
  2025-08-21 14:14 ` [PATCH v2 3/4] can: rcar_canfd: Simplify nominal bit rate config Biju
@ 2025-08-21 14:14 ` Biju
  2025-09-01 13:42   ` Geert Uytterhoeven
  3 siblings, 1 reply; 10+ messages in thread
From: Biju @ 2025-08-21 14:14 UTC (permalink / raw)
  To: Marc Kleine-Budde, Vincent Mailhol, Geert Uytterhoeven,
	Magnus Damm
  Cc: Biju Das, linux-can, linux-renesas-soc, linux-kernel,
	Prabhakar Mahadev Lad, Biju Das

From: Biju Das <biju.das.jz@bp.renesas.com>

Introduce rcar_canfd_compute_data_bit_rate_cfg() for simplifying data bit
rate configuration by replacing function-like macros.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2:
 * Split from patch#3 for computing data bit rate config separate.
   separate.
 * Replaced RCANFD_DCFG_DBRP->RCANFD_DCFG_DBRP_MASK and used FIELD_PREP to
   extract value.
---
 drivers/net/can/rcar/rcar_canfd.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
index 944b960c0b5e..f56ed8967212 100644
--- a/drivers/net/can/rcar/rcar_canfd.c
+++ b/drivers/net/can/rcar/rcar_canfd.c
@@ -169,15 +169,7 @@
 #define RCANFD_CERFL_ERR(x)		((x) & (0x7fff)) /* above bits 14:0 */
 
 /* RSCFDnCFDCmDCFG */
-#define RCANFD_DCFG_DSJW(gpriv, x)	(((x) & ((gpriv)->info->data_bittiming->sjw_max - 1)) << 24)
-
-#define RCANFD_DCFG_DTSEG2(gpriv, x) \
-	(((x) & ((gpriv)->info->data_bittiming->tseg2_max - 1)) << (gpriv)->info->sh->dtseg2)
-
-#define RCANFD_DCFG_DTSEG1(gpriv, x) \
-	(((x) & ((gpriv)->info->data_bittiming->tseg1_max - 1)) << (gpriv)->info->sh->dtseg1)
-
-#define RCANFD_DCFG_DBRP(x)		(((x) & 0xff) << 0)
+#define RCANFD_DCFG_DBRP_MASK		GENMASK(7, 0)
 
 /* RSCFDnCFDCmFDCFG */
 #define RCANFD_GEN4_FDCFG_CLOE		BIT(30)
@@ -1406,6 +1398,19 @@ static inline u32 rcar_canfd_compute_nominal_bit_rate_cfg(struct rcar_canfd_chan
 	return (ntseg1 | nbrp | nsjw | ntseg2);
 }
 
+static inline u32 rcar_canfd_compute_data_bit_rate_cfg(const struct rcar_canfd_hw_info *info,
+						       u16 tseg1, u16 brp, u16 sjw, u16 tseg2)
+{
+	u32 dtseg2, dtseg1, dsjw, dbrp;
+
+	dtseg2 = (tseg2 & (info->data_bittiming->tseg2_max - 1)) << info->sh->dtseg2;
+	dtseg1 = (tseg1 & (info->data_bittiming->tseg1_max - 1)) << info->sh->dtseg1;
+	dsjw = (sjw & (info->data_bittiming->sjw_max - 1)) << 24;
+	dbrp = FIELD_PREP(RCANFD_DCFG_DBRP_MASK, brp);
+
+	return (dtseg1 | dbrp | dsjw | dtseg2);
+}
+
 static void rcar_canfd_set_bittiming(struct net_device *ndev)
 {
 	u32 mask = RCANFD_FDCFG_TDCO | RCANFD_FDCFG_TDCE | RCANFD_FDCFG_TDCOC;
@@ -1435,10 +1440,7 @@ static void rcar_canfd_set_bittiming(struct net_device *ndev)
 	sjw = dbt->sjw - 1;
 	tseg1 = dbt->prop_seg + dbt->phase_seg1 - 1;
 	tseg2 = dbt->phase_seg2 - 1;
-
-	cfg = (RCANFD_DCFG_DTSEG1(gpriv, tseg1) | RCANFD_DCFG_DBRP(brp) |
-	       RCANFD_DCFG_DSJW(gpriv, sjw) | RCANFD_DCFG_DTSEG2(gpriv, tseg2));
-
+	cfg = rcar_canfd_compute_data_bit_rate_cfg(gpriv->info, tseg1, brp, sjw, tseg2);
 	writel(cfg, &gpriv->fcbase[ch].dcfg);
 
 	/* Transceiver Delay Compensation */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/4] can: rcar_canfd: Add shared_bittiming variable to struct rcar_canfd_hw_info
  2025-08-21 14:14 ` [PATCH v2 1/4] can: rcar_canfd: Add shared_bittiming variable to struct rcar_canfd_hw_info Biju
@ 2025-09-01 13:16   ` Geert Uytterhoeven
  0 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2025-09-01 13:16 UTC (permalink / raw)
  To: Biju
  Cc: Marc Kleine-Budde, Vincent Mailhol, Magnus Damm, Biju Das,
	linux-can, linux-renesas-soc, linux-kernel, Prabhakar Mahadev Lad,
	Fabrizio Castro

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>
>
> The calculation formula for nominal bit rate of classical CAN is same as
> that of nominal bit rate of CANFD on the RZ/G3E SoC compared to other SoCs.
> Add shared_bittiming variable to struct rcar_canfd_hw_info to handle this
> difference.
>
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> Reviewed-by: Fabrizio Castro <fabrizio.castro.jz@renesas.com>

Thanks for your patch!

> --- a/drivers/net/can/rcar/rcar_canfd.c
> +++ b/drivers/net/can/rcar/rcar_canfd.c
> @@ -461,6 +461,7 @@ struct rcar_canfd_hw_info {
>         unsigned ch_interface_mode:1;   /* Has channel interface mode */
>         unsigned shared_can_regs:1;     /* Has shared classical can registers */
>         unsigned external_clk:1;        /* Has external clock */
> +       unsigned shared_bittiming:1;    /* Has shared nominal bittiming constants */
>  };
>
>  /* Channel priv data */
> @@ -632,6 +633,7 @@ static const struct rcar_canfd_hw_info rcar_gen3_hw_info = {
>         .ch_interface_mode = 0,
>         .shared_can_regs = 0,
>         .external_clk = 1,
> +       .shared_bittiming = 0,
>  };
>
>  static const struct rcar_canfd_hw_info rcar_gen4_hw_info = {
> @@ -649,6 +651,7 @@ static const struct rcar_canfd_hw_info rcar_gen4_hw_info = {
>         .ch_interface_mode = 1,
>         .shared_can_regs = 1,
>         .external_clk = 1,
> +       .shared_bittiming = 0,

I could find no stricter limitation of the bit timings in classical
CAN mode on R-Car Gen4, so it looks like this should be 1, too...

>  };
>
>  static const struct rcar_canfd_hw_info rzg2l_hw_info = {
> @@ -666,6 +669,7 @@ static const struct rcar_canfd_hw_info rzg2l_hw_info = {
>         .ch_interface_mode = 0,
>         .shared_can_regs = 0,
>         .external_clk = 1,
> +       .shared_bittiming = 0,
>  };
>
>  static const struct rcar_canfd_hw_info r9a09g047_hw_info = {
> @@ -683,6 +687,7 @@ static const struct rcar_canfd_hw_info r9a09g047_hw_info = {
>         .ch_interface_mode = 1,
>         .shared_can_regs = 1,
>         .external_clk = 0,
> +       .shared_bittiming = 1,
>  };
>
>  /* Helper functions */
> @@ -1912,7 +1917,10 @@ static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch,
>                 priv->can.fd.do_get_auto_tdcv = rcar_canfd_get_auto_tdcv;
>         } else {
>                 /* Controller starts in Classical CAN only mode */
> -               priv->can.bittiming_const = &rcar_canfd_bittiming_const;
> +               if (gpriv->info->shared_bittiming)

... hence you can just check the existing shared_can_regs flag here,
and don't need to introduce a new flag for shared bittimings?

> +                       priv->can.bittiming_const = gpriv->info->nom_bittiming;
> +               else
> +                       priv->can.bittiming_const = &rcar_canfd_bittiming_const;
>                 priv->can.ctrlmode_supported = CAN_CTRLMODE_BERR_REPORTING;
>         }

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/4] can: rcar_canfd: Update RCANFD_CFG_* macros
  2025-08-21 14:14 ` [PATCH v2 2/4] can: rcar_canfd: Update RCANFD_CFG_* macros Biju
@ 2025-09-01 13:21   ` Geert Uytterhoeven
  2025-09-01 13:24   ` Geert Uytterhoeven
  1 sibling, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2025-09-01 13:21 UTC (permalink / raw)
  To: Biju
  Cc: Marc Kleine-Budde, Vincent Mailhol, Magnus Damm, Biju Das,
	linux-can, linux-renesas-soc, linux-kernel, Prabhakar Mahadev Lad

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/4] can: rcar_canfd: Update RCANFD_CFG_* macros
  2025-08-21 14:14 ` [PATCH v2 2/4] can: rcar_canfd: Update RCANFD_CFG_* macros Biju
  2025-09-01 13:21   ` Geert Uytterhoeven
@ 2025-09-01 13:24   ` Geert Uytterhoeven
  1 sibling, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2025-09-01 13:24 UTC (permalink / raw)
  To: Biju
  Cc: Marc Kleine-Budde, Vincent Mailhol, Magnus Damm, Biju Das,
	linux-can, linux-renesas-soc, linux-kernel, Prabhakar Mahadev Lad

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 3/4] can: rcar_canfd: Simplify nominal bit rate config
  2025-08-21 14:14 ` [PATCH v2 3/4] can: rcar_canfd: Simplify nominal bit rate config Biju
@ 2025-09-01 13:37   ` Geert Uytterhoeven
  0 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2025-09-01 13:37 UTC (permalink / raw)
  To: Biju
  Cc: Marc Kleine-Budde, Vincent Mailhol, Magnus Damm, Biju Das,
	linux-can, linux-renesas-soc, linux-kernel, Prabhakar Mahadev Lad

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>
>
> Introduce rcar_canfd_compute_nominal_bit_rate_cfg() for simplifying
> nominal bit rate configuration by replacing function-like macros.
>
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> v1->v2:
>  * Split from patch#3 for computing nominal bit rate config separate.
>  * Updated rcar_canfd_compute_nominal_bit_rate_cfg() to handle
>    nominal bit rate configuration for both classical CAN and CANFD.
>  * Replaced RCANFD_NCFG_NBRP->RCANFD_NCFG_NBRP_MASK and used FIELD_PREP to
>    extract value.

Thanks for your patch!

Your patch is correct, so
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Still a few suggestions for improvement below...

> --- a/drivers/net/can/rcar/rcar_canfd.c
> +++ b/drivers/net/can/rcar/rcar_canfd.c
> @@ -109,16 +109,7 @@
>  #define RCANFD_CFG_BRP_MASK            GENMASK(9, 0)
>
>  /* RSCFDnCFDCmNCFG - CAN FD only */
> -#define RCANFD_NCFG_NTSEG2(gpriv, x) \
> -       (((x) & ((gpriv)->info->nom_bittiming->tseg2_max - 1)) << (gpriv)->info->sh->ntseg2)
> -
> -#define RCANFD_NCFG_NTSEG1(gpriv, x) \
> -       (((x) & ((gpriv)->info->nom_bittiming->tseg1_max - 1)) << (gpriv)->info->sh->ntseg1)
> -
> -#define RCANFD_NCFG_NSJW(gpriv, x) \
> -       (((x) & ((gpriv)->info->nom_bittiming->sjw_max - 1)) << (gpriv)->info->sh->nsjw)
> -
> -#define RCANFD_NCFG_NBRP(x)            (((x) & 0x3ff) << 0)
> +#define RCANFD_NCFG_NBRP_MASK          GENMASK(9, 0)

I would drop the "_MASK" suffix.

> @@ -1393,6 +1384,28 @@ static irqreturn_t rcar_canfd_channel_interrupt(int irq, void *dev_id)
>         return IRQ_HANDLED;
>  }
>
> +static inline u32 rcar_canfd_compute_nominal_bit_rate_cfg(struct rcar_canfd_channel *priv,
> +                                                         u16 tseg1, u16 brp, u16 sjw, u16 tseg2)

Perhaps follow the order as used in struct can_bittiming{_const}?
I.e. tseg1, tseg2, sjw, brp.

> +{
> +       struct rcar_canfd_global *gpriv = priv->gpriv;
> +       const struct rcar_canfd_hw_info *info = gpriv->info;
> +       u32 ntseg2, ntseg1, nsjw, nbrp;
> +
> +       if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) || gpriv->info->shared_can_regs) {
> +               ntseg2 = (tseg2 & (info->nom_bittiming->tseg2_max - 1)) << info->sh->ntseg2;
> +               ntseg1 = (tseg1 & (info->nom_bittiming->tseg1_max - 1)) << info->sh->ntseg1;
> +               nsjw = (sjw & (info->nom_bittiming->sjw_max - 1)) << info->sh->nsjw;
> +               nbrp = FIELD_PREP(RCANFD_NCFG_NBRP_MASK, brp);

Perhaps use the order of the function parameters?

> +       } else {
> +               ntseg2 = FIELD_PREP(RCANFD_CFG_TSEG2_MASK, tseg2);
> +               ntseg1 = FIELD_PREP(RCANFD_CFG_TSEG1_MASK, tseg1);
> +               nsjw = FIELD_PREP(RCANFD_CFG_SJW_MASK, sjw);
> +               nbrp = FIELD_PREP(RCANFD_CFG_BRP_MASK, brp);

Likewise.

> +       }
> +
> +       return (ntseg1 | nbrp | nsjw | ntseg2);

Likewise.

> +}
> +
>  static void rcar_canfd_set_bittiming(struct net_device *ndev)
>  {
>         u32 mask = RCANFD_FDCFG_TDCO | RCANFD_FDCFG_TDCE | RCANFD_FDCFG_TDCOC;

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 4/4] can: rcar_canfd: Simplify data bit rate config
  2025-08-21 14:14 ` [PATCH v2 4/4] can: rcar_canfd: Simplify data " Biju
@ 2025-09-01 13:42   ` Geert Uytterhoeven
  0 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2025-09-01 13:42 UTC (permalink / raw)
  To: Biju
  Cc: Marc Kleine-Budde, Vincent Mailhol, Magnus Damm, Biju Das,
	linux-can, linux-renesas-soc, linux-kernel, Prabhakar Mahadev Lad

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>
>
> Introduce rcar_canfd_compute_data_bit_rate_cfg() for simplifying data bit
> rate configuration by replacing function-like macros.
>
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> v1->v2:
>  * Split from patch#3 for computing data bit rate config separate.
>    separate.
>  * Replaced RCANFD_DCFG_DBRP->RCANFD_DCFG_DBRP_MASK and used FIELD_PREP to
>    extract value.

Thanks for your patch!

For correctness:
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

But I have the same comments as for "[PATCH v2 3/4] can: rcar_canfd:
Simplify nominal bit rate config".

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-09-01 13:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 14:14 [PATCH v2 0/4] R-Car CANFD Improvements Biju
2025-08-21 14:14 ` [PATCH v2 1/4] can: rcar_canfd: Add shared_bittiming variable to struct rcar_canfd_hw_info Biju
2025-09-01 13:16   ` Geert Uytterhoeven
2025-08-21 14:14 ` [PATCH v2 2/4] can: rcar_canfd: Update RCANFD_CFG_* macros Biju
2025-09-01 13:21   ` Geert Uytterhoeven
2025-09-01 13:24   ` Geert Uytterhoeven
2025-08-21 14:14 ` [PATCH v2 3/4] can: rcar_canfd: Simplify nominal bit rate config Biju
2025-09-01 13:37   ` Geert Uytterhoeven
2025-08-21 14:14 ` [PATCH v2 4/4] can: rcar_canfd: Simplify data " Biju
2025-09-01 13:42   ` Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).