netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] can: bxcan: add support for single peripheral configuration
@ 2023-04-27 20:45 Dario Binacchi
  2023-04-27 20:45 ` [PATCH v2 1/5] dt-bindings: net: can: add "st,can-secondary" property Dario Binacchi
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Dario Binacchi @ 2023-04-27 20:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: michael, Amarula patchwork, Dario Binacchi, Alexandre Torgue,
	David S. Miller, Eric Dumazet, Jakub Kicinski,
	Krzysztof Kozlowski, Marc Kleine-Budde, Maxime Coquelin,
	Paolo Abeni, Rob Herring, Wolfgang Grandegger, devicetree,
	linux-arm-kernel, linux-can, linux-stm32, netdev


The series adds support for managing bxCAN controllers in single peripheral
configuration.
Unlike stm32f4 SOCs, where bxCAN controllers are only in dual peripheral
configuration, stm32f7 SOCs contain three CAN peripherals, CAN1 and CAN2
in dual peripheral configuration and CAN3 in single peripheral
configuration:
- Dual CAN peripheral configuration:
 * CAN1: Primary bxCAN for managing the communication between a secondary
   bxCAN and the 512-byte SRAM memory.
 * CAN2: Secondary bxCAN with no direct access to the SRAM memory.
   This means that the two bxCAN cells share the 512-byte SRAM memory and
   CAN2 can't be used without enabling CAN1.
- Single CAN peripheral configuration:
 * CAN3: Primary bxCAN with dedicated Memory Access Controller unit and
   512-byte SRAM memory.

The driver has been tested on the stm32f769i-discovery board with a
kernel version 5.19.0-rc2 in loopback + silent mode:

ip link set can[0-2] type can bitrate 125000 loopback on listen-only on
ip link set up can[0-2]
candump can[0-2] -L &
cansend can[0-2] 300#AC.AB.AD.AE.75.49.AD.D1


Changes in v2:
- s/fiter/filter/ in the commit message
- Replace struct bxcan_mb::primary with struct bxcan_mb::cfg.
- Move after the patch "can: bxcan: add support for single peripheral configuration".
- Add node gcan3.
- Rename gcan as gcan1.
- Add property "st,can-secondary" to can2 node.
- Drop patch "dt-bindings: mfd: stm32f7: add binding definition for CAN3"
  because it has been accepted.
- Add patch "ARM: dts: stm32f429: put can2 in secondary mode".
- Add patch "dt-bindings: net: can: add "st,can-secondary" property".

Dario Binacchi (5):
  dt-bindings: net: can: add "st,can-secondary" property
  ARM: dts: stm32f429: put can2 in secondary mode
  ARM: dts: stm32: add pin map for CAN controller on stm32f7
  can: bxcan: add support for single peripheral configuration
  ARM: dts: stm32: add CAN support on stm32f746

 .../bindings/net/can/st,stm32-bxcan.yaml      | 19 ++++-
 arch/arm/boot/dts/stm32f429.dtsi              |  1 +
 arch/arm/boot/dts/stm32f7-pinctrl.dtsi        | 82 +++++++++++++++++++
 arch/arm/boot/dts/stm32f746.dtsi              | 47 +++++++++++
 drivers/net/can/bxcan.c                       | 34 +++++---
 5 files changed, 168 insertions(+), 15 deletions(-)

-- 
2.32.0


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

* [PATCH v2 1/5] dt-bindings: net: can: add "st,can-secondary" property
  2023-04-27 20:45 [PATCH v2 0/5] can: bxcan: add support for single peripheral configuration Dario Binacchi
@ 2023-04-27 20:45 ` Dario Binacchi
  2023-05-05 19:50   ` Rob Herring
  2023-04-27 20:45 ` [PATCH v2 4/5] can: bxcan: add support for single peripheral configuration Dario Binacchi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Dario Binacchi @ 2023-04-27 20:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: michael, Amarula patchwork, Dario Binacchi, Alexandre Torgue,
	David S. Miller, Eric Dumazet, Jakub Kicinski,
	Krzysztof Kozlowski, Marc Kleine-Budde, Maxime Coquelin,
	Paolo Abeni, Rob Herring, Wolfgang Grandegger, devicetree,
	linux-arm-kernel, linux-can, linux-stm32, netdev

On the stm32f7 Socs the can peripheral can be in single or dual
configuration. In the dual configuration, in turn, it can be in primary
or secondary mode. The addition of the 'st,can-secondary' property allows
you to specify this mode in the dual configuration.

CAN peripheral nodes in single configuration contain neither
"st,can-primary" nor "st,can-secondary".

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

(no changes since v1)

 .../bindings/net/can/st,stm32-bxcan.yaml      | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/st,stm32-bxcan.yaml b/Documentation/devicetree/bindings/net/can/st,stm32-bxcan.yaml
index 769fa5c27b76..de1d4298893b 100644
--- a/Documentation/devicetree/bindings/net/can/st,stm32-bxcan.yaml
+++ b/Documentation/devicetree/bindings/net/can/st,stm32-bxcan.yaml
@@ -21,11 +21,22 @@ properties:
 
   st,can-primary:
     description:
-      Primary and secondary mode of the bxCAN peripheral is only relevant
-      if the chip has two CAN peripherals. In that case they share some
-      of the required logic.
+      Primary mode of the bxCAN peripheral is only relevant if the chip has
+      two CAN peripherals in dual CAN configuration. In that case they share
+      some of the required logic.
+      Not to be used if the peripheral is in single CAN configuration.
       To avoid misunderstandings, it should be noted that ST documentation
-      uses the terms master/slave instead of primary/secondary.
+      uses the terms master instead of primary.
+    type: boolean
+
+  st,can-secondary:
+    description:
+      Secondary mode of the bxCAN peripheral is only relevant if the chip
+      has two CAN peripherals in dual CAN configuration. In that case they
+      share some of the required logic.
+      Not to be used if the peripheral is in single CAN configuration.
+      To avoid misunderstandings, it should be noted that ST documentation
+      uses the terms slave instead of secondary.
     type: boolean
 
   reg:
-- 
2.32.0


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

* [PATCH v2 4/5] can: bxcan: add support for single peripheral configuration
  2023-04-27 20:45 [PATCH v2 0/5] can: bxcan: add support for single peripheral configuration Dario Binacchi
  2023-04-27 20:45 ` [PATCH v2 1/5] dt-bindings: net: can: add "st,can-secondary" property Dario Binacchi
@ 2023-04-27 20:45 ` Dario Binacchi
  2023-04-27 21:08 ` [PATCH v2 0/5] " Marc Kleine-Budde
  2023-05-09 12:38 ` Marc Kleine-Budde
  3 siblings, 0 replies; 7+ messages in thread
From: Dario Binacchi @ 2023-04-27 20:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: michael, Amarula patchwork, Dario Binacchi, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Marc Kleine-Budde, Paolo Abeni,
	Wolfgang Grandegger, linux-can, netdev

Add support for bxCAN controller in single peripheral configuration:
- primary bxCAN
- dedicated Memory Access Controller unit
- 512-byte SRAM memory
- 14 filter banks

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>

---

Changes in v2:
- s/fiter/filter/ in the commit message
- Replace struct bxcan_mb::primary with struct bxcan_mb::cfg.

 drivers/net/can/bxcan.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/net/can/bxcan.c b/drivers/net/can/bxcan.c
index e26ccd41e3cb..027a8a162fe4 100644
--- a/drivers/net/can/bxcan.c
+++ b/drivers/net/can/bxcan.c
@@ -118,7 +118,7 @@
 #define BXCAN_FiR1_REG(b) (0x40 + (b) * 8)
 #define BXCAN_FiR2_REG(b) (0x44 + (b) * 8)
 
-#define BXCAN_FILTER_ID(primary) (primary ? 0 : 14)
+#define BXCAN_FILTER_ID(cfg) ((cfg) == BXCAN_CFG_DUAL_SECONDARY ? 14 : 0)
 
 /* Filter primary register (FMR) bits */
 #define BXCAN_FMR_CANSB_MASK GENMASK(13, 8)
@@ -135,6 +135,12 @@ enum bxcan_lec_code {
 	BXCAN_LEC_UNUSED
 };
 
+enum bxcan_cfg {
+	BXCAN_CFG_SINGLE = 0,
+	BXCAN_CFG_DUAL_PRIMARY,
+	BXCAN_CFG_DUAL_SECONDARY
+};
+
 /* Structure of the message buffer */
 struct bxcan_mb {
 	u32 id;			/* can identifier */
@@ -167,7 +173,7 @@ struct bxcan_priv {
 	struct regmap *gcan;
 	int tx_irq;
 	int sce_irq;
-	bool primary;
+	enum bxcan_cfg cfg;
 	struct clk *clk;
 	spinlock_t rmw_lock;	/* lock for read-modify-write operations */
 	unsigned int tx_head;
@@ -202,17 +208,17 @@ static inline void bxcan_rmw(struct bxcan_priv *priv, void __iomem *addr,
 	spin_unlock_irqrestore(&priv->rmw_lock, flags);
 }
 
-static void bxcan_disable_filters(struct bxcan_priv *priv, bool primary)
+static void bxcan_disable_filters(struct bxcan_priv *priv, enum bxcan_cfg cfg)
 {
-	unsigned int fid = BXCAN_FILTER_ID(primary);
+	unsigned int fid = BXCAN_FILTER_ID(cfg);
 	u32 fmask = BIT(fid);
 
 	regmap_update_bits(priv->gcan, BXCAN_FA1R_REG, fmask, 0);
 }
 
-static void bxcan_enable_filters(struct bxcan_priv *priv, bool primary)
+static void bxcan_enable_filters(struct bxcan_priv *priv, enum bxcan_cfg cfg)
 {
-	unsigned int fid = BXCAN_FILTER_ID(primary);
+	unsigned int fid = BXCAN_FILTER_ID(cfg);
 	u32 fmask = BIT(fid);
 
 	/* Filter settings:
@@ -680,7 +686,7 @@ static int bxcan_chip_start(struct net_device *ndev)
 		  BXCAN_BTR_BRP_MASK | BXCAN_BTR_TS1_MASK | BXCAN_BTR_TS2_MASK |
 		  BXCAN_BTR_SJW_MASK, set);
 
-	bxcan_enable_filters(priv, priv->primary);
+	bxcan_enable_filters(priv, priv->cfg);
 
 	/* Clear all internal status */
 	priv->tx_head = 0;
@@ -806,7 +812,7 @@ static void bxcan_chip_stop(struct net_device *ndev)
 		  BXCAN_IER_EPVIE | BXCAN_IER_EWGIE | BXCAN_IER_FOVIE1 |
 		  BXCAN_IER_FFIE1 | BXCAN_IER_FMPIE1 | BXCAN_IER_FOVIE0 |
 		  BXCAN_IER_FFIE0 | BXCAN_IER_FMPIE0 | BXCAN_IER_TMEIE, 0);
-	bxcan_disable_filters(priv, priv->primary);
+	bxcan_disable_filters(priv, priv->cfg);
 	bxcan_enter_sleep_mode(priv);
 	priv->can.state = CAN_STATE_STOPPED;
 }
@@ -931,7 +937,7 @@ static int bxcan_probe(struct platform_device *pdev)
 	struct clk *clk = NULL;
 	void __iomem *regs;
 	struct regmap *gcan;
-	bool primary;
+	enum bxcan_cfg cfg;
 	int err, rx_irq, tx_irq, sce_irq;
 
 	regs = devm_platform_ioremap_resource(pdev, 0);
@@ -946,7 +952,13 @@ static int bxcan_probe(struct platform_device *pdev)
 		return PTR_ERR(gcan);
 	}
 
-	primary = of_property_read_bool(np, "st,can-primary");
+	if (of_property_read_bool(np, "st,can-primary"))
+		cfg = BXCAN_CFG_DUAL_PRIMARY;
+	else if (of_property_read_bool(np, "st,can-secondary"))
+		cfg = BXCAN_CFG_DUAL_SECONDARY;
+	else
+		cfg = BXCAN_CFG_SINGLE;
+
 	clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(clk)) {
 		dev_err(dev, "failed to get clock\n");
@@ -992,7 +1004,7 @@ static int bxcan_probe(struct platform_device *pdev)
 	priv->clk = clk;
 	priv->tx_irq = tx_irq;
 	priv->sce_irq = sce_irq;
-	priv->primary = primary;
+	priv->cfg = cfg;
 	priv->can.clock.freq = clk_get_rate(clk);
 	spin_lock_init(&priv->rmw_lock);
 	priv->tx_head = 0;
-- 
2.32.0


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

* Re: [PATCH v2 0/5] can: bxcan: add support for single peripheral configuration
  2023-04-27 20:45 [PATCH v2 0/5] can: bxcan: add support for single peripheral configuration Dario Binacchi
  2023-04-27 20:45 ` [PATCH v2 1/5] dt-bindings: net: can: add "st,can-secondary" property Dario Binacchi
  2023-04-27 20:45 ` [PATCH v2 4/5] can: bxcan: add support for single peripheral configuration Dario Binacchi
@ 2023-04-27 21:08 ` Marc Kleine-Budde
  2023-05-09 12:33   ` Marc Kleine-Budde
  2023-05-09 12:38 ` Marc Kleine-Budde
  3 siblings, 1 reply; 7+ messages in thread
From: Marc Kleine-Budde @ 2023-04-27 21:08 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, michael, Amarula patchwork, Alexandre Torgue,
	David S. Miller, Eric Dumazet, Jakub Kicinski,
	Krzysztof Kozlowski, Maxime Coquelin, Paolo Abeni, Rob Herring,
	Wolfgang Grandegger, devicetree, linux-arm-kernel, linux-can,
	linux-stm32, netdev

[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]

On 27.04.2023 22:45:35, Dario Binacchi wrote:
> 
> The series adds support for managing bxCAN controllers in single peripheral
> configuration.
> Unlike stm32f4 SOCs, where bxCAN controllers are only in dual peripheral
> configuration, stm32f7 SOCs contain three CAN peripherals, CAN1 and CAN2
> in dual peripheral configuration and CAN3 in single peripheral
> configuration:
> - Dual CAN peripheral configuration:
>  * CAN1: Primary bxCAN for managing the communication between a secondary
>    bxCAN and the 512-byte SRAM memory.
>  * CAN2: Secondary bxCAN with no direct access to the SRAM memory.
>    This means that the two bxCAN cells share the 512-byte SRAM memory and
>    CAN2 can't be used without enabling CAN1.
> - Single CAN peripheral configuration:
>  * CAN3: Primary bxCAN with dedicated Memory Access Controller unit and
>    512-byte SRAM memory.

This really looks good! Great work! Who takes the DT changes? I can take
the whole series.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 1/5] dt-bindings: net: can: add "st,can-secondary" property
  2023-04-27 20:45 ` [PATCH v2 1/5] dt-bindings: net: can: add "st,can-secondary" property Dario Binacchi
@ 2023-05-05 19:50   ` Rob Herring
  0 siblings, 0 replies; 7+ messages in thread
From: Rob Herring @ 2023-05-05 19:50 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: Wolfgang Grandegger, Rob Herring, linux-can, devicetree,
	Amarula patchwork, Alexandre Torgue, Jakub Kicinski,
	linux-arm-kernel, netdev, michael, Krzysztof Kozlowski,
	Paolo Abeni, Eric Dumazet, Marc Kleine-Budde, Maxime Coquelin,
	David S. Miller, linux-stm32, linux-kernel


On Thu, 27 Apr 2023 22:45:36 +0200, Dario Binacchi wrote:
> On the stm32f7 Socs the can peripheral can be in single or dual
> configuration. In the dual configuration, in turn, it can be in primary
> or secondary mode. The addition of the 'st,can-secondary' property allows
> you to specify this mode in the dual configuration.
> 
> CAN peripheral nodes in single configuration contain neither
> "st,can-primary" nor "st,can-secondary".
> 
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> ---
> 
> (no changes since v1)
> 
>  .../bindings/net/can/st,stm32-bxcan.yaml      | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>


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

* Re: [PATCH v2 0/5] can: bxcan: add support for single peripheral configuration
  2023-04-27 21:08 ` [PATCH v2 0/5] " Marc Kleine-Budde
@ 2023-05-09 12:33   ` Marc Kleine-Budde
  0 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2023-05-09 12:33 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, michael, Amarula patchwork, Alexandre Torgue,
	David S. Miller, Eric Dumazet, Jakub Kicinski,
	Krzysztof Kozlowski, Maxime Coquelin, Paolo Abeni, Rob Herring,
	Wolfgang Grandegger, devicetree, linux-arm-kernel, linux-can,
	linux-stm32, netdev

[-- Attachment #1: Type: text/plain, Size: 1441 bytes --]

On 27.04.2023 23:08:57, Marc Kleine-Budde wrote:
> On 27.04.2023 22:45:35, Dario Binacchi wrote:
> > 
> > The series adds support for managing bxCAN controllers in single peripheral
> > configuration.
> > Unlike stm32f4 SOCs, where bxCAN controllers are only in dual peripheral
> > configuration, stm32f7 SOCs contain three CAN peripherals, CAN1 and CAN2
> > in dual peripheral configuration and CAN3 in single peripheral
> > configuration:
> > - Dual CAN peripheral configuration:
> >  * CAN1: Primary bxCAN for managing the communication between a secondary
> >    bxCAN and the 512-byte SRAM memory.
> >  * CAN2: Secondary bxCAN with no direct access to the SRAM memory.
> >    This means that the two bxCAN cells share the 512-byte SRAM memory and
> >    CAN2 can't be used without enabling CAN1.
> > - Single CAN peripheral configuration:
> >  * CAN3: Primary bxCAN with dedicated Memory Access Controller unit and
> >    512-byte SRAM memory.
> 
> This really looks good! Great work! Who takes the DT changes? I can take
> the whole series.

I've upstreamed the DT changes for the first bxCAN driver, so I'll take
them this time, too.

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 0/5] can: bxcan: add support for single peripheral configuration
  2023-04-27 20:45 [PATCH v2 0/5] can: bxcan: add support for single peripheral configuration Dario Binacchi
                   ` (2 preceding siblings ...)
  2023-04-27 21:08 ` [PATCH v2 0/5] " Marc Kleine-Budde
@ 2023-05-09 12:38 ` Marc Kleine-Budde
  3 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2023-05-09 12:38 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, michael, Amarula patchwork, Alexandre Torgue,
	David S. Miller, Eric Dumazet, Jakub Kicinski,
	Krzysztof Kozlowski, Maxime Coquelin, Paolo Abeni, Rob Herring,
	Wolfgang Grandegger, devicetree, linux-arm-kernel, linux-can,
	linux-stm32, netdev

[-- Attachment #1: Type: text/plain, Size: 1508 bytes --]

On 27.04.2023 22:45:35, Dario Binacchi wrote:
> 
> The series adds support for managing bxCAN controllers in single peripheral
> configuration.
> Unlike stm32f4 SOCs, where bxCAN controllers are only in dual peripheral
> configuration, stm32f7 SOCs contain three CAN peripherals, CAN1 and CAN2
> in dual peripheral configuration and CAN3 in single peripheral
> configuration:
> - Dual CAN peripheral configuration:
>  * CAN1: Primary bxCAN for managing the communication between a secondary
>    bxCAN and the 512-byte SRAM memory.
>  * CAN2: Secondary bxCAN with no direct access to the SRAM memory.
>    This means that the two bxCAN cells share the 512-byte SRAM memory and
>    CAN2 can't be used without enabling CAN1.
> - Single CAN peripheral configuration:
>  * CAN3: Primary bxCAN with dedicated Memory Access Controller unit and
>    512-byte SRAM memory.
> 
> The driver has been tested on the stm32f769i-discovery board with a
> kernel version 5.19.0-rc2 in loopback + silent mode:
> 
> ip link set can[0-2] type can bitrate 125000 loopback on listen-only on
> ip link set up can[0-2]
> candump can[0-2] -L &
> cansend can[0-2] 300#AC.AB.AD.AE.75.49.AD.D1

Applied to linux-can-next.

Thanks,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2023-05-09 12:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-27 20:45 [PATCH v2 0/5] can: bxcan: add support for single peripheral configuration Dario Binacchi
2023-04-27 20:45 ` [PATCH v2 1/5] dt-bindings: net: can: add "st,can-secondary" property Dario Binacchi
2023-05-05 19:50   ` Rob Herring
2023-04-27 20:45 ` [PATCH v2 4/5] can: bxcan: add support for single peripheral configuration Dario Binacchi
2023-04-27 21:08 ` [PATCH v2 0/5] " Marc Kleine-Budde
2023-05-09 12:33   ` Marc Kleine-Budde
2023-05-09 12:38 ` Marc Kleine-Budde

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).