Skip to contentSkip to conversation

can: flexcan: disable transceiver during system PM

PATCH Superseded [email protected] 2 participants 3 messages Mar 4, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 can: flexcan: disable transceiver during system PM

From: Haibo Chen <[email protected]>

During system PM, if no wakeup requirement, disable transceiver to save power.

---
 drivers/net/can/flexcan/flexcan-core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/can/flexcan/flexcan-core.c +5 -0
index b347a1c93536..74f3137295fb 100644
@@ -2292,6 +2292,7 @@ static int __maybe_unused flexcan_suspend(struct device *device)
 				return err;
 
 			flexcan_chip_interrupts_disable(dev);
+			flexcan_transceiver_disable(priv);
 
 			err = pinctrl_pm_select_sleep_state(device);
 			if (err)
@@ -2325,6 +2326,10 @@ static int __maybe_unused flexcan_resume(struct device *device)
 			if (err)
 				return err;
 
+			err = flexcan_transceiver_enable(priv);
+			if (err)
+				return err;
+
 			err = flexcan_chip_start(dev);
 			if (err)
 				return err;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 14 lines · On 04/03/2025 at 12:37, [email protected] wrote:

From: Haibo Chen <[email protected]>

During system PM, if no wakeup requirement, disable transceiver to save power.

 drivers/net/can/flexcan/flexcan-core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/can/flexcan/flexcan-core.c +0 -0
index b347a1c93536..74f3137295fb 100644

drivers/net/can/flexcan/flexcan-core.c static int __maybe_unused flexcan_suspend(struct device *device) · line 2295

Quoted 4 lines
drivers/net/can/flexcan/flexcan-core.c +1 -0
@@ -2292,6 +2292,7 @@ static int __maybe_unused flexcan_suspend(struct device *device)
 				return err;
 
 			flexcan_chip_interrupts_disable(dev);
+			flexcan_transceiver_disable(priv);

flexcan_transceiver_disable() may return an error. Can you check its return value?

drivers/net/can/flexcan/flexcan-core.c static int __maybe_unused flexcan_resume(struct device *device) · line 2335

Quoted 13 lines
drivers/net/can/flexcan/flexcan-core.c +4 -0
 			err = pinctrl_pm_select_sleep_state(device);
 			if (err)
@@ -2325,6 +2326,10 @@ static int __maybe_unused flexcan_resume(struct device *device)
 			if (err)
 				return err;
 
+			err = flexcan_transceiver_enable(priv);
+			if (err)
+				return err;
+
 			err = flexcan_chip_start(dev);
 			if (err)
 				return err;

If flexcan_chip_start() fails, shouldn't you have a clean-up branch that will flexcan_transceiver_disable()? Or do you consider that it is acceptable to keep the transceiver enabled if an error occurs?

Speaking of which, if flexcan_resume() fails, priv->can.state would still be set to CAN_STATE_ERROR_ACTIVE.

Yours sincerely,
Vincent Mailhol

author
#2 lore raw
Quoted 26 lines

-----Original Message-----
From: Vincent Mailhol <[email protected]>
Sent: 2025年3月4日 12:06
To: Bough Chen <[email protected]>; [email protected]
Cc: Ciprian Marian Costea (OSS) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] can: flexcan: disable transceiver during system PM

drivers/net/can/flexcan/flexcan-core.c static int __maybe_unused flexcan_suspend(struct

Quoted 15 lines · On 04/03/2025 at 12:37, [email protected] wrote:

From: Haibo Chen <[email protected]>

During system PM, if no wakeup requirement, disable transceiver to save power.

drivers/net/can/flexcan/flexcan-core.c | 5 +++++

 1 file changed, 5 insertions(+)
drivers/net/can/flexcan/flexcan-core.c +0 -0
index b347a1c93536..74f3137295fb 100644
@@ -2292,6 +2292,7 @@ static int __maybe_unused flexcan_suspend(struct

device *device)

Quoted 7 lines

drivers/net/can/flexcan/flexcan-core.c static int __maybe_unused flexcan_suspend(struct device *device) · line 2295

Quoted 4 lines
drivers/net/can/flexcan/flexcan-core.c +1 -0
 				return err;
 
 			flexcan_chip_interrupts_disable(dev);
+			flexcan_transceiver_disable(priv);

flexcan_transceiver_disable() may return an error. Can you check its return value?

Yes, sure.

Quoted 8 lines

drivers/net/can/flexcan/flexcan-core.c static int __maybe_unused flexcan_resume(struct

Quoted 4 lines
drivers/net/can/flexcan/flexcan-core.c +0 -0
 			err = pinctrl_pm_select_sleep_state(device);
 			if (err)
@@ -2325,6 +2326,10 @@ static int __maybe_unused flexcan_resume(struct

device *device)

Quoted 3 lines
drivers/net/can/flexcan/flexcan-core.c +0 -0
 			if (err)
 				return err;
 
Quoted 11 lines

drivers/net/can/flexcan/flexcan-core.c static int __maybe_unused flexcan_resume(struct device *device) · line 2335

Quoted 7 lines
drivers/net/can/flexcan/flexcan-core.c +4 -0
+			err = flexcan_transceiver_enable(priv);
+			if (err)
+				return err;
+
 			err = flexcan_chip_start(dev);
 			if (err)
 				return err;

If flexcan_chip_start() fails, shouldn't you have a clean-up branch that will flexcan_transceiver_disable()? Or do you consider that it is acceptable to keep the transceiver enabled if an error occurs?

Good suggestion, I will add a clean-up branch.

Quoted 3 lines

Speaking of which, if flexcan_resume() fails, priv->can.state would still be set to CAN_STATE_ERROR_ACTIVE.

Thanks for your quick response, I will take all these suggestions into consideration and prepare v2 patch.

Regards
Haibo Chen

Quoted 4 lines

Yours sincerely,
Vincent Mailhol