Skip to contentSkip to conversation

can: m_can: introduce ti,am62-m_can compatible for out-of-band wakeup

PATCH Superseded Kendall Willis 3 participants 11 messages Sep 2 – Sep 3

Subsystems (3)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v4 cover can: m_can: introduce ti,am62-m_can compatible for out-of-band wakeup

This series introduces the "ti,am62-m_can" compatible which adds support for out-of-band wakeup capability in m_can devices.

A corresponding DTS series enabling this feature on TI K3 AM62 family of devices has been submitted separately:
"arm64: dts: ti: use ti,am62-m_can compatible for m_can devices"

Testing
-------
Tested suspend/resume with CAN wakeup on AM62P SK EVM.

---
Changes in v4:
- Remove patch for "out-band-wakeup" property in dt binding.
- Create "ti,am62-m_can" compatible in the dt binding and m_can driver.
- Add "struct m_can_pdata" for compatible-specific data which keeps track of "out_band_wakeup" flag.
- Replace check "out-band-wakeup" dt property in the device driver upon suspend with check for "out_band_wakeup" variable from the "m_can_pdata".
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Remove definition of "out-band-wakeup" property in dt binding.
- Allow "out-band-wakeup" property in dt binding.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Create "out-band-wakeup" property in dt bindings.
- Use "out-band-wakeup" property to set the out_band_wakeup flag upon suspend.
- Rebase to v7.2
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Kendall Willis (2):
dt-bindings: can: m_can: add ti,am62-m_can compatible
can: m_can: add ti,am62-m_can compatible with out-of-band wakeup support

 Documentation/devicetree/bindings/net/can/bosch,m_can.yaml | 4 +++-
 drivers/net/can/m_can/m_can.c                              | 7 ++++++-
 drivers/net/can/m_can/m_can.h                              | 4 ++++
 drivers/net/can/m_can/m_can_platform.c                     | 5 +++++
 4 files changed, 18 insertions(+), 2 deletions(-)

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260819-temp-93299bee27b7

Best regards,

Signature · 1 line
Kendall Willis <[email protected]>
#1 lore raw

PATCH v4 1/2 dt-bindings: can: m_can: add ti,am62-m_can compatible

Add "ti,am62-m_can" to the list of compatible strings for the M_CAN controller binding. This compatible identifies TI AM62 SoCs which support out-of-band wakeup capability.

---
 Documentation/devicetree/bindings/net/can/bosch,m_can.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/can/bosch,m_can.yaml +3 -1
index 2c9d37975bedd652b3060ab11ba75c37565edaad..89e5a44453372c57506e9cf3a009b55a70cc4446 100644
@@ -16,7 +16,9 @@ allOf:
 
 properties:
   compatible:
-    const: bosch,m_can
+    enum:
+      - bosch,m_can
+      - ti,am62-m_can
 
   reg:
     items:
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v4 1/2] dt-bindings: can: m_can: add ti,am62-m_can compatible

Hi Kendall,

Quoted 14 lines · Kendall Willis

Add "ti,am62-m_can" to the list of compatible strings for the M_CAN controller binding. This compatible identifies TI AM62 SoCs which support out-of-band wakeup capability.

---
 Documentation/devicetree/bindings/net/can/bosch,m_can.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/can/bosch,m_can.yaml +0 -0
index 2c9d37975bedd652b3060ab11ba75c37565edaad..89e5a44453372c57506e9cf3a009b55a70cc4446 100644

Documentation/devicetree/bindings/net/can/bosch,m_can.yaml allOf: · line 21

Quoted 7 lines
Documentation/devicetree/bindings/net/can/bosch,m_can.yaml +3 -1
@@ -16,7 +16,9 @@ allOf:
 
 properties:
   compatible:
-    const: bosch,m_can
+    enum:
+      - bosch,m_can
+      - ti,am62-m_can

I think you should use oneOf here to allow the use of

  compatible = "ti,am62-m_can", "bosch,m_can";

Best
Markus

#3 lore raw

Re: [PATCH v4 1/2] dt-bindings: can: m_can: add ti,am62-m_can compatible

Hi Markus,

Quoted 27 lines · Markus Schneider-Pargmann

Hi Kendall,

Quoted 14 lines · Kendall Willis

Add "ti,am62-m_can" to the list of compatible strings for the M_CAN controller binding. This compatible identifies TI AM62 SoCs which support out-of-band wakeup capability.

---
 Documentation/devicetree/bindings/net/can/bosch,m_can.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/can/bosch,m_can.yaml +0 -0
index 2c9d37975bedd652b3060ab11ba75c37565edaad..89e5a44453372c57506e9cf3a009b55a70cc4446 100644

Documentation/devicetree/bindings/net/can/bosch,m_can.yaml allOf: · line 21

Quoted 7 lines
Documentation/devicetree/bindings/net/can/bosch,m_can.yaml +3 -1
@@ -16,7 +16,9 @@ allOf:
 
 properties:
   compatible:
-    const: bosch,m_can
+    enum:
+      - bosch,m_can
+      - ti,am62-m_can

I think you should use oneOf here to allow the use of

Quoted 2 lines
  compatible = "ti,am62-m_can", "bosch,m_can";

Oops, yes this was a mistake on my part. Will fix in the next version.

Best,
Kendall

#4 lore raw

Re: [PATCH v4 1/2] dt-bindings: can: m_can: add ti,am62-m_can compatible

In reply to Kendall Willis
Quoted 1 line · Kendall Willis

Add "ti,am62-m_can" to the list of compatible strings for the M_CAN

Compatibles do not have underscores. Poor existing examples are not the example to follow.

Also, no need to repeat the diff - we see that from the diff. Just say "Add foo bar, a baz-baz device, fully compatible or not compatible with Bosch because of this and that".

Quoted 3 lines

controller binding. This compatible identifies TI AM62 SoCs which support out-of-band wakeup capability.

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH v4 1/2] dt-bindings: can: m_can: add ti,am62-m_can compatible

Hi Krzysztof,

Quoted 6 lines · Krzysztof Kozlowski
Quoted 1 line · Kendall Willis

Add "ti,am62-m_can" to the list of compatible strings for the M_CAN

Compatibles do not have underscores. Poor existing examples are not the example to follow.

I'll change it to "ti,am62-mcu-mcan" in the next revision.

Quoted 4 lines

Also, no need to repeat the diff - we see that from the diff. Just say "Add foo bar, a baz-baz device, fully compatible or not compatible with Bosch because of this and that".

Noted.

Best,
Kendall

#6 lore raw

PATCH v4 2/2 can: m_can: add ti,am62-m_can compatible with out-of-band wakeup support

In reply to Kendall Willis

In TI AM62X, AM62A, and AM62P SoCs, the M_CAN controller is a part of the MCU power domain which is OFF in the deepest low power states. However, the m_can pins are able to wakeup the system from states where the MCU domain is OFF through its out-of-band wakeup functionality.

Introduce the ti,am62-m_can compatible with match data to identify the out-of-band wakeup capability for TI AM62 SoCs. During suspend, set the out-of-band wakeup flag when the device is configured as a wakeup source, the "wakeup" pinctrl state is present, and the match data indicates out-of-band wakeup support.

---
 drivers/net/can/m_can/m_can.c          | 7 ++++++-
 drivers/net/can/m_can/m_can.h          | 4 ++++
 drivers/net/can/m_can/m_can_platform.c | 5 +++++
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/net/can/m_can/m_can.c +6 -1
index 16f80607e150e2ca2950616ff2c39b7aa13710b4..0788816d881ef8ba84ad5a84a6d2d3e60517ea7a 100644
@@ -2598,6 +2598,7 @@ int m_can_class_suspend(struct device *dev)
 {
 	struct m_can_classdev *cdev = dev_get_drvdata(dev);
 	struct net_device *ndev = cdev->net;
+	const struct m_can_pdata *pdata = of_device_get_match_data(dev);
 	int ret = 0;
 
 	if (netif_running(ndev)) {
@@ -2622,8 +2623,12 @@ int m_can_class_suspend(struct device *dev)
 		cdev->can.state = CAN_STATE_SLEEPING;
 	}
 
-	if (!m_can_class_wakeup_pinctrl_enabled(cdev))
+	if (m_can_class_wakeup_pinctrl_enabled(cdev)) {
+		if (pdata && pdata->out_band_wakeup)
+			device_set_out_band_wakeup(dev);
+	} else {
 		pinctrl_pm_select_sleep_state(dev);
+	}
 
 	return ret;
 }
drivers/net/can/m_can/m_can.h +4 -0
index 4743342b2fba3823819b9e2bc5b085cc0fe6d1e2..486d808bc677482acf446b1450c3a9b6b7405178 100644
@@ -134,6 +134,10 @@ struct m_can_classdev {
 	struct pinctrl_state *pinctrl_state_wakeup;
 };
 
+struct m_can_pdata {
+	bool out_band_wakeup;
+};
+
 struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, int sizeof_priv);
 void m_can_class_free_dev(struct net_device *net);
 int m_can_class_register(struct m_can_classdev *cdev);
drivers/net/can/m_can/m_can_platform.c +5 -0
index 56da411878af0185ff9cc512e325137428a68255..ae2d89b65fe8da65b1ca73cbf80cd8ee8483e2e8 100644
@@ -218,8 +218,13 @@ static const struct dev_pm_ops m_can_pmops = {
 	SET_SYSTEM_SLEEP_PM_OPS(m_can_suspend, m_can_resume)
 };
 
+static const struct m_can_pdata m_can_plat_am62 = {
+	.out_band_wakeup = true,
+};
+
 static const struct of_device_id m_can_of_table[] = {
 	{ .compatible = "bosch,m_can", .data = NULL },
+	{ .compatible = "ti,am62-m_can", .data = &m_can_plat_am62 },
 	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, m_can_of_table);
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v4 2/2] can: m_can: add ti,am62-m_can compatible with out-of-band wakeup support

Quoted 4 lines · Kendall Willis

In TI AM62X, AM62A, and AM62P SoCs, the M_CAN controller is a part of the MCU power domain which is OFF in the deepest low power states. However, the m_can pins are able to wakeup the system from states where the MCU domain is OFF through its out-of-band wakeup functionality.

There are m_can devices in the main domain as well. Does this apply to these as well?

Quoted 19 lines

Introduce the ti,am62-m_can compatible with match data to identify the out-of-band wakeup capability for TI AM62 SoCs. During suspend, set the out-of-band wakeup flag when the device is configured as a wakeup source, the "wakeup" pinctrl state is present, and the match data indicates out-of-band wakeup support.

---
 drivers/net/can/m_can/m_can.c          | 7 ++++++-
 drivers/net/can/m_can/m_can.h          | 4 ++++
 drivers/net/can/m_can/m_can_platform.c | 5 +++++
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/net/can/m_can/m_can.c +0 -0
index 16f80607e150e2ca2950616ff2c39b7aa13710b4..0788816d881ef8ba84ad5a84a6d2d3e60517ea7a 100644

drivers/net/can/m_can/m_can.c int m_can_class_suspend(struct device *dev) · line 2601

Quoted 4 lines
drivers/net/can/m_can/m_can.c +1 -0
@@ -2598,6 +2598,7 @@ int m_can_class_suspend(struct device *dev)
 {
 	struct m_can_classdev *cdev = dev_get_drvdata(dev);
 	struct net_device *ndev = cdev->net;
+	const struct m_can_pdata *pdata = of_device_get_match_data(dev);

The core m_can driver works for all m_can forms, tcan, platform and pci. I think it would be cleaner if you parse this in the platform driver and set it in m_can_classdev instead. Otherwise of_match_data has to be the same for all drivers which is not obvious when you are editing tcan for example.

Quoted 4 lines
drivers/net/can/m_can/m_can.c +0 -0
 	int ret = 0;
 
 	if (netif_running(ndev)) {

drivers/net/can/m_can/m_can.c int m_can_class_suspend(struct device *dev) · line 2631

Quoted 10 lines
drivers/net/can/m_can/m_can.c +5 -1
@@ -2622,8 +2623,12 @@ int m_can_class_suspend(struct device *dev)
 		cdev->can.state = CAN_STATE_SLEEPING;
 	}
 
-	if (!m_can_class_wakeup_pinctrl_enabled(cdev))
+	if (m_can_class_wakeup_pinctrl_enabled(cdev)) {
+		if (pdata && pdata->out_band_wakeup)
+			device_set_out_band_wakeup(dev);
+	} else {
 		pinctrl_pm_select_sleep_state(dev);
+	}

I just noticed these are called even if ret is not 0, so suspend failed. This shouldn't happen, but not a problem of your patch. But you could add a fix for that.

Quoted 23 lines
drivers/net/can/m_can/m_can.c +0 -0
 	return ret;
 }
drivers/net/can/m_can/m_can.h +4 -0
index 4743342b2fba3823819b9e2bc5b085cc0fe6d1e2..486d808bc677482acf446b1450c3a9b6b7405178 100644
@@ -134,6 +134,10 @@ struct m_can_classdev {
 	struct pinctrl_state *pinctrl_state_wakeup;
 };
 
+struct m_can_pdata {
+	bool out_band_wakeup;
+};
+
 struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, int sizeof_priv);
 void m_can_class_free_dev(struct net_device *net);
 int m_can_class_register(struct m_can_classdev *cdev);
drivers/net/can/m_can/m_can_platform.c +0 -0
index 56da411878af0185ff9cc512e325137428a68255..ae2d89b65fe8da65b1ca73cbf80cd8ee8483e2e8 100644

drivers/net/can/m_can/m_can_platform.c static const struct dev_pm_ops m_can_pmops = { · line 221

Quoted 4 lines
drivers/net/can/m_can/m_can_platform.c +1 -0
@@ -218,8 +218,13 @@ static const struct dev_pm_ops m_can_pmops = {
 	SET_SYSTEM_SLEEP_PM_OPS(m_can_suspend, m_can_resume)
 };
 
+static const struct m_can_pdata m_can_plat_am62 = {

I don't like the pdata name here, this suggests to be platform data, but this is of match data instead. Maybe of_data?

Best
Markus

#8 lore raw

Re: [PATCH v4 2/2] can: m_can: add ti,am62-m_can compatible with out-of-band wakeup support

Quoted 9 lines · Markus Schneider-Pargmann
Quoted 4 lines · Kendall Willis

In TI AM62X, AM62A, and AM62P SoCs, the M_CAN controller is a part of the MCU power domain which is OFF in the deepest low power states. However, the m_can pins are able to wakeup the system from states where the MCU domain is OFF through its out-of-band wakeup functionality.

There are m_can devices in the main domain as well. Does this apply to these as well?

This doesn't apply to the m_can devices in the main domain, so I'll make the compatible to be more specific. Maybe something like "ti,am62-mcu-mcan".

Quoted 14 lines
Quoted 14 lines

Introduce the ti,am62-m_can compatible with match data to identify the out-of-band wakeup capability for TI AM62 SoCs. During suspend, set the out-of-band wakeup flag when the device is configured as a wakeup source, the "wakeup" pinctrl state is present, and the match data indicates out-of-band wakeup support.

---
 drivers/net/can/m_can/m_can.c          | 7 ++++++-
 drivers/net/can/m_can/m_can.h          | 4 ++++
 drivers/net/can/m_can/m_can_platform.c | 5 +++++
 3 files changed, 15 insertions(+), 1 deletion(-)
Quoted 16 lines

drivers/net/can/m_can/m_can.c int m_can_class_suspend(struct device *dev) · line 2601

Quoted 9 lines
drivers/net/can/m_can/m_can.c +1 -0
index 16f80607e150e2ca2950616ff2c39b7aa13710b4..0788816d881ef8ba84ad5a84a6d2d3e60517ea7a 100644
@@ -2598,6 +2598,7 @@ int m_can_class_suspend(struct device *dev)
 {
 	struct m_can_classdev *cdev = dev_get_drvdata(dev);
 	struct net_device *ndev = cdev->net;
+	const struct m_can_pdata *pdata = of_device_get_match_data(dev);

The core m_can driver works for all m_can forms, tcan, platform and pci. I think it would be cleaner if you parse this in the platform driver and set it in m_can_classdev instead. Otherwise of_match_data has to be the same for all drivers which is not obvious when you are editing tcan for example.

That makes sense. I'll add it to m_can_classdev in the platform driver in the next version.

Quoted 7 lines
Quoted 7 lines
drivers/net/can/m_can/m_can.c +0 -0
 	int ret = 0;
 
 	if (netif_running(ndev)) {
@@ -2622,8 +2623,12 @@ int m_can_class_suspend(struct device *dev)
 		cdev->can.state = CAN_STATE_SLEEPING;
 	}
 
Quoted 12 lines

drivers/net/can/m_can/m_can.c int m_can_class_suspend(struct device *dev) · line 2631

Quoted 7 lines
drivers/net/can/m_can/m_can.c +5 -1
-	if (!m_can_class_wakeup_pinctrl_enabled(cdev))
+	if (m_can_class_wakeup_pinctrl_enabled(cdev)) {
+		if (pdata && pdata->out_band_wakeup)
+			device_set_out_band_wakeup(dev);
+	} else {
 		pinctrl_pm_select_sleep_state(dev);
+	}

I just noticed these are called even if ret is not 0, so suspend failed. This shouldn't happen, but not a problem of your patch. But you could add a fix for that.

Yep, I could add a fix for that.

Quoted 26 lines
Quoted 26 lines
drivers/net/can/m_can/m_can.c +0 -0
 	return ret;
 }
drivers/net/can/m_can/m_can.h +4 -0
index 4743342b2fba3823819b9e2bc5b085cc0fe6d1e2..486d808bc677482acf446b1450c3a9b6b7405178 100644
@@ -134,6 +134,10 @@ struct m_can_classdev {
 	struct pinctrl_state *pinctrl_state_wakeup;
 };
 
+struct m_can_pdata {
+	bool out_band_wakeup;
+};
+
 struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, int sizeof_priv);
 void m_can_class_free_dev(struct net_device *net);
 int m_can_class_register(struct m_can_classdev *cdev);
drivers/net/can/m_can/m_can_platform.c +0 -0
index 56da411878af0185ff9cc512e325137428a68255..ae2d89b65fe8da65b1ca73cbf80cd8ee8483e2e8 100644
@@ -218,8 +218,13 @@ static const struct dev_pm_ops m_can_pmops = {
 	SET_SYSTEM_SLEEP_PM_OPS(m_can_suspend, m_can_resume)
 };
 
Quoted 4 lines

drivers/net/can/m_can/m_can_platform.c static const struct dev_pm_ops m_can_pmops = { · line 221

Quoted 1 line
drivers/net/can/m_can/m_can_platform.c +1 -0
+static const struct m_can_pdata m_can_plat_am62 = {

I don't like the pdata name here, this suggests to be platform data, but this is of match data instead. Maybe of_data?

I can change it to of_data. I've also seen soc_data as well, but that doesn't really work since the compatible is per power domain.

Best,
Kendall

#9 lore raw

Re: [PATCH v4 2/2] can: m_can: add ti,am62-m_can compatible with out-of-band wakeup support

In reply to Kendall Willis
Quoted 12 lines · Kendall Willis
drivers/net/can/m_can/m_can.h +4 -0
+struct m_can_pdata {
+	bool out_band_wakeup;
+};
+
 struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, int sizeof_priv);
 void m_can_class_free_dev(struct net_device *net);
 int m_can_class_register(struct m_can_classdev *cdev);
drivers/net/can/m_can/m_can_platform.c +0 -0
index 56da411878af0185ff9cc512e325137428a68255..ae2d89b65fe8da65b1ca73cbf80cd8ee8483e2e8 100644

drivers/net/can/m_can/m_can_platform.c static const struct dev_pm_ops m_can_pmops = { · line 227

Quoted 10 lines
drivers/net/can/m_can/m_can_platform.c +5 -0
@@ -218,8 +218,13 @@ static const struct dev_pm_ops m_can_pmops = {
 	SET_SYSTEM_SLEEP_PM_OPS(m_can_suspend, m_can_resume)
 };
 
+static const struct m_can_pdata m_can_plat_am62 = {
+	.out_band_wakeup = true,
+};
+
 static const struct of_device_id m_can_of_table[] = {
 	{ .compatible = "bosch,m_can", .data = NULL },
+	{ .compatible = "ti,am62-m_can", .data = &m_can_plat_am62 },

How exactly having out of band wakeup makes this device INCOMPATIBLE with Bosch (in terms of DT compatibility)?

Best regards,
Krzysztof

#10 lore raw

Re: [PATCH v4 2/2] can: m_can: add ti,am62-m_can compatible with out-of-band wakeup support

Hi Krzysztof,

Quoted 16 lines · Krzysztof Kozlowski
Quoted 15 lines · Kendall Willis
drivers/net/can/m_can/m_can.h +4 -0
+struct m_can_pdata {
+	bool out_band_wakeup;
+};
+
 struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, int sizeof_priv);
 void m_can_class_free_dev(struct net_device *net);
 int m_can_class_register(struct m_can_classdev *cdev);
drivers/net/can/m_can/m_can_platform.c +0 -0
index 56da411878af0185ff9cc512e325137428a68255..ae2d89b65fe8da65b1ca73cbf80cd8ee8483e2e8 100644
@@ -218,8 +218,13 @@ static const struct dev_pm_ops m_can_pmops = {
 	SET_SYSTEM_SLEEP_PM_OPS(m_can_suspend, m_can_resume)
 };
 
Quoted 11 lines

drivers/net/can/m_can/m_can_platform.c static const struct dev_pm_ops m_can_pmops = { · line 227

Quoted 7 lines
drivers/net/can/m_can/m_can_platform.c +5 -0
+static const struct m_can_pdata m_can_plat_am62 = {
+	.out_band_wakeup = true,
+};
+
 static const struct of_device_id m_can_of_table[] = {
 	{ .compatible = "bosch,m_can", .data = NULL },
+	{ .compatible = "ti,am62-m_can", .data = &m_can_plat_am62 },

How exactly having out of band wakeup makes this device INCOMPATIBLE with Bosch (in terms of DT compatibility)?

It does not make it incompatible with Bosch. The DT binding is incorrect for having it be compatible with both TI and Bosch. I'm correcting it on the next revision.

Best,
Kendall