Skip to contentSkip to conversation

can: m_can: Add am62 wakeup support

PATCH Superseded Markus Schneider-Pargmann 4 participants 11 messages May 23, 2024 – Jun 20, 2024

Subsystems (6)

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Markus Schneider-Pargmann

author maintainer
#0 lore raw

cover can: m_can: Add am62 wakeup support

Hi,

am62, am62a and am62p support Partial-IO, a poweroff SoC state with a few pin groups being active for wakeup.

To support mcu_mcan0 and mcu_mcan1 wakeup for the mentioned SoCs, the series introduces a notion of wake-on-lan for m_can. If the user decides to enable wake-on-lan for a m_can device, the device is set to wakeup enabled. A 'wakeup' pinctrl state is selected to enable wakeup flags for the relevant pins. If wake-on-lan is disabled the default pinctrl is selected.

It is based on v6.9-rc1.

This series is part of a bigger topic to support Partial-IO on am62, am62a and am62p. Partial-IO is a poweroff state in which some pins are able to wakeup the SoC. In detail MCU m_can and two serial port pins can trigger the wakeup.

These two other series are relevant for the support of Partial-IO:

- firmware: ti_sci: Partial-IO support
- serial: 8250: omap: Add am62 wakeup support

A test branch is available here that includes all patches required to test Partial-IO:

https://gitlab.baylibre.com/msp8/linux/-/tree/integration/am62-lp-sk-partialio/v6.9?ref_type=heads

After enabling Wake-on-LAN the system can be powered off and will enter the Partial-IO state in which it can be woken up by activity on the specific pins:
ethtool -s can0 wol p
ethtool -s can1 wol p
poweroff

I tested these patches on am62-lp-sk.

Best,
Markus

Markus Schneider-Pargmann (6):
dt-bindings: can: m_can: Add wakeup-source property
dt-bindings: can: m_can: Add wakeup pinctrl state
can: m_can: Map WoL to device_set_wakeup_enable
can: m_can: Support pinctrl wakeup state
arm64: dts: ti: k3-am62: Mark mcu_mcan0/1 as wakeup-source
arm64: dts: ti: k3-am62a-mcu: Mark mcu_mcan0/1 as wakeup-source

Vibhore Vardhan (1):
arm64: dts: ti: k3-am62p-mcu: Mark mcu_mcan0/1 as wakeup-source

 .../bindings/net/can/bosch,m_can.yaml         | 20 +++++++++
 arch/arm64/boot/dts/ti/k3-am62-mcu.dtsi       |  2 +
 arch/arm64/boot/dts/ti/k3-am62a-mcu.dtsi      |  2 +
 arch/arm64/boot/dts/ti/k3-am62p-mcu.dtsi      |  2 +
 drivers/net/can/m_can/m_can.c                 | 43 +++++++++++++++++++
 drivers/net/can/m_can/m_can.h                 |  4 ++
 6 files changed, 73 insertions(+)
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/7 dt-bindings: can: m_can: Add wakeup-source property

m_can can be a wakeup source on some devices. Especially on some of the am62* SoCs pins, connected to m_can in the mcu, can be used to wakeup the SoC.

This property defines on which devices m_can can be used for wakeup.

---
 Documentation/devicetree/bindings/net/can/bosch,m_can.yaml | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/net/can/bosch,m_can.yaml +4 -0
index f9ffb963d6b1..33f1688ca208 100644
@@ -118,6 +118,10 @@ properties:
   phys:
     maxItems: 1
 
+  wakeup-source:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description: This device is capable to wakeup the SoC.
+
 required:
   - compatible
   - reg
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/7] dt-bindings: can: m_can: Add wakeup-source property

Quoted 16 lines · Markus Schneider-Pargmann

m_can can be a wakeup source on some devices. Especially on some of the am62* SoCs pins, connected to m_can in the mcu, can be used to wakeup the SoC.

This property defines on which devices m_can can be used for wakeup.

---
 Documentation/devicetree/bindings/net/can/bosch,m_can.yaml | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/net/can/bosch,m_can.yaml +0 -0
index f9ffb963d6b1..33f1688ca208 100644

Documentation/devicetree/bindings/net/can/bosch,m_can.yaml properties: · line 123

Quoted 6 lines
Documentation/devicetree/bindings/net/can/bosch,m_can.yaml +3 -0
@@ -118,6 +118,10 @@ properties:
   phys:
     maxItems: 1
 
+  wakeup-source:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description: This device is capable to wakeup the SoC.

It seems to me like patch 1 & 2 should be squashed, with "wakeup-source" depending on the correct pinctrl setup?

author maintainer
#3 lore raw

PATCH 2/7 dt-bindings: can: m_can: Add wakeup pinctrl state

In reply to Markus Schneider-Pargmann

Pins associated with m_can can be the source of a wakeup in deep sleep states. To be able to wakeup these pins have to be configured in a special way. To support this configuration add the default and wakeup pinctrl states.

---
 .../devicetree/bindings/net/can/bosch,m_can.yaml | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
Documentation/devicetree/bindings/net/can/bosch,m_can.yaml +16 -0
index 33f1688ca208..7c6fa7367c37 100644
@@ -106,6 +106,22 @@ properties:
         maximum: 32
     minItems: 1
 
+  pinctrl-0:
+    description: Default pinctrl state
+
+  pinctrl-1:
+    description: Wakeup pinctrl state
+
+  pinctrl-names:
+    description:
+      When present should contain at least "default" describing the default pin
+      states. The second state called "wakeup" describes the pins in their
+      wakeup configuration required to exit sleep states.
+    minItems: 1
+    items:
+      - const: default
+      - const: wakeup
+
   power-domains:
     description:
       Power domain provider node and an args specifier containing
Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH 3/7 can: m_can: Map WoL to device_set_wakeup_enable

In reply to Markus Schneider-Pargmann

In some devices the pins of the m_can module can act as a wakeup source. This patch helps do that by connecting the PHY_WAKE WoL option to device_set_wakeup_enable. By marking this device as being wakeup enabled, this setting can be used by platform code to decide which sleep or poweroff mode to use.

Also this prepares the driver for the next patch in which the pinctrl settings are changed depending on the desired wakeup source.

---
 drivers/net/can/m_can/m_can.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/net/can/m_can/m_can.c +25 -0
index 14b231c4d7ec..80964e403a5e 100644
@@ -2129,6 +2129,26 @@ static int m_can_set_coalesce(struct net_device *dev,
 	return 0;
 }
 
+static void m_can_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+	struct m_can_classdev *cdev = netdev_priv(dev);
+
+	wol->supported = device_can_wakeup(cdev->dev) ? WAKE_PHY : 0;
+	wol->wolopts = device_may_wakeup(cdev->dev) ? WAKE_PHY : 0;
+}
+
+static int m_can_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+	struct m_can_classdev *cdev = netdev_priv(dev);
+
+	if ((wol->wolopts & WAKE_PHY) != wol->wolopts)
+		return -EINVAL;
+
+	device_set_wakeup_enable(cdev->dev, !!wol->wolopts & WAKE_PHY);
+
+	return 0;
+}
+
 static const struct ethtool_ops m_can_ethtool_ops = {
 	.supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS_IRQ |
 		ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ |
@@ -2142,6 +2162,8 @@ static const struct ethtool_ops m_can_ethtool_ops = {
 
 static const struct ethtool_ops m_can_ethtool_ops_polling = {
 	.get_ts_info = ethtool_op_get_ts_info,
+	.get_wol = m_can_get_wol,
+	.set_wol = m_can_set_wol,
 };
 
 static int register_m_can_dev(struct net_device *dev)
@@ -2266,6 +2288,9 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev,
 		goto out;
 	}
 
+	if (dev->of_node && of_property_read_bool(dev->of_node, "wakeup-source"))
+		device_set_wakeup_capable(dev, true);
+
 	/* Get TX FIFO size
 	 * Defines the total amount of echo buffers for loopback
 	 */
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH 3/7] can: m_can: Map WoL to device_set_wakeup_enable

Quoted 28 lines · Markus Schneider-Pargmann

In some devices the pins of the m_can module can act as a wakeup source. This patch helps do that by connecting the PHY_WAKE WoL option to device_set_wakeup_enable. By marking this device as being wakeup enabled, this setting can be used by platform code to decide which sleep or poweroff mode to use.

Also this prepares the driver for the next patch in which the pinctrl settings are changed depending on the desired wakeup source.

---
 drivers/net/can/m_can/m_can.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/net/can/m_can/m_can.c +6 -0
index 14b231c4d7ec..80964e403a5e 100644
@@ -2129,6 +2129,26 @@ static int m_can_set_coalesce(struct net_device *dev,
 	return 0;
 }
 
+static void m_can_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+	struct m_can_classdev *cdev = netdev_priv(dev);
+
+	wol->supported = device_can_wakeup(cdev->dev) ? WAKE_PHY : 0;
+	wol->wolopts = device_may_wakeup(cdev->dev) ? WAKE_PHY : 0;

drivers/net/can/m_can/m_can.c static int m_can_set_coalesce(struct net_device *dev, · line 2147

Quoted 10 lines
drivers/net/can/m_can/m_can.c +10 -0
+}
+
+static int m_can_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+	struct m_can_classdev *cdev = netdev_priv(dev);
+
+	if ((wol->wolopts & WAKE_PHY) != wol->wolopts)
+		return -EINVAL;
+
+	device_set_wakeup_enable(cdev->dev, !!wol->wolopts & WAKE_PHY);

Can you please add error handling here? Same for the modifications in the next patch.

regards,
Marc

Signature · 4 lines
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   |
author maintainer
#6 lore raw

PATCH 4/7 can: m_can: Support pinctrl wakeup state

In reply to Markus Schneider-Pargmann

am62 requires a wakeup flag being set in pinctrl when mcan pins acts as a wakeup source. Add support to select the wakeup state if WOL is enabled.

---
 drivers/net/can/m_can/m_can.c | 20 +++++++++++++++++++-
 drivers/net/can/m_can/m_can.h |  4 ++++
 2 files changed, 23 insertions(+), 1 deletion(-)
drivers/net/can/m_can/m_can.c +19 -1
index 80964e403a5e..c5585dc68f2f 100644
@@ -2140,11 +2140,21 @@ static void m_can_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
 static int m_can_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
 {
 	struct m_can_classdev *cdev = netdev_priv(dev);
+	struct pinctrl_state *new_pinctrl_state = NULL;
+	bool wol_enable = !!wol->wolopts & WAKE_PHY;
 
 	if ((wol->wolopts & WAKE_PHY) != wol->wolopts)
 		return -EINVAL;
 
-	device_set_wakeup_enable(cdev->dev, !!wol->wolopts & WAKE_PHY);
+	if (wol_enable)
+		new_pinctrl_state = cdev->pinctrl_state_wakeup;
+	else
+		new_pinctrl_state = cdev->pinctrl_state_default;
+
+	if (!IS_ERR_OR_NULL(new_pinctrl_state))
+		pinctrl_select_state(cdev->pinctrl, new_pinctrl_state);
+
+	device_set_wakeup_enable(cdev->dev, wol_enable);
 
 	return 0;
 }
@@ -2309,6 +2319,14 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev,
 	SET_NETDEV_DEV(net_dev, dev);
 
 	m_can_of_parse_mram(class_dev, mram_config_vals);
+
+	class_dev->pinctrl = devm_pinctrl_get(dev);
+	if (!IS_ERR_OR_NULL(class_dev->pinctrl)) {
+		class_dev->pinctrl_state_default =
+			pinctrl_lookup_state(class_dev->pinctrl, "default");
+		class_dev->pinctrl_state_wakeup =
+			pinctrl_lookup_state(class_dev->pinctrl, "wakeup");
+	}
 out:
 	return class_dev;
 }
drivers/net/can/m_can/m_can.h +4 -0
index 3a9edc292593..bdfbba67b336 100644
@@ -126,6 +126,10 @@ struct m_can_classdev {
 	struct mram_cfg mcfg[MRAM_CFG_NUM];
 
 	struct hrtimer hrtimer;
+
+	struct pinctrl *pinctrl;
+	struct pinctrl_state *pinctrl_state_default;
+	struct pinctrl_state *pinctrl_state_wakeup;
 };
 
 struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, int sizeof_priv);
Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH 5/7 arm64: dts: ti: k3-am62: Mark mcu_mcan0/1 as wakeup-source

In reply to Markus Schneider-Pargmann

mcu_mcan0 and mcu_mcan1 can be wakeup sources for the SoC. Mark them accordingly in the devicetree.

---
 arch/arm64/boot/dts/ti/k3-am62-mcu.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/ti/k3-am62-mcu.dtsi +2 -0
index e66d486ef1f2..56a40b641667 100644
@@ -159,6 +159,7 @@ mcu_mcan0: can@4e08000 {
 		clocks = <&k3_clks 188 6>, <&k3_clks 188 1>;
 		clock-names = "hclk", "cclk";
 		bosch,mram-cfg = <0x0 128 64 64 64 64 32 32>;
+		wakeup-source;
 		status = "disabled";
 	};
 
@@ -171,6 +172,7 @@ mcu_mcan1: can@4e18000 {
 		clocks = <&k3_clks 189 6>, <&k3_clks 189 1>;
 		clock-names = "hclk", "cclk";
 		bosch,mram-cfg = <0x0 128 64 64 64 64 32 32>;
+		wakeup-source;
 		status = "disabled";
 	};
 };
Signature · 1 line
2.43.0
author maintainer
#8 lore raw

PATCH 6/7 arm64: dts: ti: k3-am62a-mcu: Mark mcu_mcan0/1 as wakeup-source

In reply to Markus Schneider-Pargmann

mcu_mcan0 and mcu_mcan1 can be wakeup sources for the SoC. Mark them accordingly in the devicetree.

---
 arch/arm64/boot/dts/ti/k3-am62a-mcu.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/ti/k3-am62a-mcu.dtsi +2 -0
index 8c36e56f4138..f0f6b7650233 100644
@@ -153,6 +153,7 @@ mcu_mcan0: can@4e08000 {
 		clocks = <&k3_clks 188 6>, <&k3_clks 188 1>;
 		clock-names = "hclk", "cclk";
 		bosch,mram-cfg = <0x0 128 64 64 64 64 32 32>;
+		wakeup-source;
 		status = "disabled";
 	};
 
@@ -165,6 +166,7 @@ mcu_mcan1: can@4e18000 {
 		clocks = <&k3_clks 189 6>, <&k3_clks 189 1>;
 		clock-names = "hclk", "cclk";
 		bosch,mram-cfg = <0x0 128 64 64 64 64 32 32>;
+		wakeup-source;
 		status = "disabled";
 	};
 };
Signature · 1 line
2.43.0
author maintainer
#9 lore raw

PATCH 7/7 arm64: dts: ti: k3-am62p-mcu: Mark mcu_mcan0/1 as wakeup-source

In reply to Markus Schneider-Pargmann

From: Vibhore Vardhan <[email protected]>

mcu_mcan0 and mcu_mcan1 can be wakeup sources for the SoC. Mark them accordingly in the devicetree. Based on the patch for AM62a.

---
 arch/arm64/boot/dts/ti/k3-am62p-mcu.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/ti/k3-am62p-mcu.dtsi +2 -0
index b973b550eb9d..e434b258e90c 100644
@@ -162,6 +162,7 @@ mcu_mcan0: can@4e08000 {
 		interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>,
 			     <GIC_SPI 27 IRQ_TYPE_LEVEL_HIGH>;
 		interrupt-names = "int0", "int1";
+		wakeup-source;
 		status = "disabled";
 	};
 
@@ -177,6 +178,7 @@ mcu_mcan1: can@4e18000 {
 		interrupts = <GIC_SPI 28 IRQ_TYPE_LEVEL_HIGH>,
 			     <GIC_SPI 29 IRQ_TYPE_LEVEL_HIGH>;
 		interrupt-names = "int0", "int1";
+		wakeup-source;
 		status = "disabled";
 	};
 
Signature · 1 line
2.43.0
maintainer
#10 lore raw

Re: [PATCH 7/7] arm64: dts: ti: k3-am62p-mcu: Mark mcu_mcan0/1 as wakeup-source

Quoted 34 lines · Markus Schneider-Pargmann

From: Vibhore Vardhan <[email protected]>

mcu_mcan0 and mcu_mcan1 can be wakeup sources for the SoC. Mark them accordingly in the devicetree. Based on the patch for AM62a.

---
 arch/arm64/boot/dts/ti/k3-am62p-mcu.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/ti/k3-am62p-mcu.dtsi +2 -0
index b973b550eb9d..e434b258e90c 100644
@@ -162,6 +162,7 @@ mcu_mcan0: can@4e08000 {
 		interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>,
 			     <GIC_SPI 27 IRQ_TYPE_LEVEL_HIGH>;
 		interrupt-names = "int0", "int1";
+		wakeup-source;
 		status = "disabled";
 	};
 
@@ -177,6 +178,7 @@ mcu_mcan1: can@4e18000 {
 		interrupts = <GIC_SPI 28 IRQ_TYPE_LEVEL_HIGH>,
 			     <GIC_SPI 29 IRQ_TYPE_LEVEL_HIGH>;
 		interrupt-names = "int0", "int1";
+		wakeup-source;
 		status = "disabled";
 	};
 
Signature · 1 line
2.43.0

Curious:
https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/pm/lpm.html#supported-low-power-modes
Does not seem to call out am62p. Is that an documentation oversight?

what happens to j722s?

Signature · 3 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D