can: tcan4x5x/m_can: use standby mode when down and in suspend
Subsystems (2)
v3 cover can: tcan4x5x/m_can: use standby mode when down and in suspend
When downing the tcan4x5x there is no reason to keep the tcan4x5x in "normal" mode and waste power.
So set standby mode when the interface is down and normal mode when interface is up.
Also when going into suspend, set the tcan4x5x into standby mode. The tcan4x5x can still be used as a wake-source when in standby as low power rx is enabled.
---
Changes in v3:
- Run deinit in m_can_stop() in any case even if m_can_cccr_update_bits() fails
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Reduced code in tcan4x5x_deinit()
- Taken care of return values from deinit callback
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Sean Nyekjaer (3):
can: m_can: add deinit callback
can: tcan4x5x: add deinit callback to set standby mode
can: m_can: call deinit/init callback when going into suspend/resume
drivers/net/can/m_can/m_can.c | 22 ++++++++++++++++++---- drivers/net/can/m_can/m_can.h | 1 + drivers/net/can/m_can/tcan4x5x-core.c | 9 +++++++++ 3 files changed, 28 insertions(+), 4 deletions(-)
---
base-commit: e0b741bc53c94f9ae25d4140202557a0aa51b5a0
change-id: 20241107-tcan-standby-def358771b2b
Best regards,
Signature · 1 line
Sean Nyekjaer <[email protected]>
PATCH v3 1/3 can: m_can: add deinit callback
This is added in preparation for calling standby mode in the tcan4x5x driver or other users of m_can.
For the tcan4x5x; If Vsup 12V, standby mode will save 7-8mA, when the interface is down.
--- drivers/net/can/m_can/m_can.c | 7 +++++++ drivers/net/can/m_can/m_can.h | 1 + 2 files changed, 8 insertions(+)
drivers/net/can/m_can/m_can.c +7 -0
@@ -1756,6 +1756,13 @@ static void m_can_stop(struct net_device *dev)/* set the state as STOPPED */ cdev->can.state =CAN_STATE_STOPPED ; + +if (cdev->ops->deinit) { + ret = cdev->ops->deinit (cdev); +if (ret) +netdev_err (dev,"failed to deinitialize: %pe\n" , +ERR_PTR (ret)); + } }static int m_can_close (struct net_device *dev)
drivers/net/can/m_can/m_can.h +1 -0
@@ -68,6 +68,7 @@ struct m_can_ops {int (*write_fifo)(struct m_can_classdev *cdev,int addr_offset,const void *val,size_t val_count);int (*init)(struct m_can_classdev *cdev); +int (*deinit)(struct m_can_classdev *cdev); };struct m_can_tx_op {
Signature · 1 line
2.46.2
PATCH v3 2/3 can: tcan4x5x: add deinit callback to set standby mode
In reply to Sean NyekjaerAt Vsup 12V, standby mode will save 7-8mA, when the interface is down.
--- drivers/net/can/m_can/tcan4x5x-core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/can/m_can/tcan4x5x-core.c +9 -0
@@ -279,6 +279,14 @@ static int tcan4x5x_init(struct m_can_classdev *cdev)return ret; } +static int tcan4x5x_deinit (struct m_can_classdev *cdev) +{ +struct tcan4x5x_priv *tcan4x5x =cdev_to_priv (cdev); + +return regmap_update_bits (tcan4x5x->regmap,TCAN4X5X_CONFIG , +TCAN4X5X_MODE_SEL_MASK ,TCAN4X5X_MODE_STANDBY ); +}; +static int tcan4x5x_disable_wake (struct m_can_classdev *cdev) {struct tcan4x5x_priv *tcan4x5x =cdev_to_priv (cdev);
@@ -377,6 +385,7 @@ static int tcan4x5x_get_gpios(struct m_can_classdev *cdev,static const struct m_can_ops tcan4x5x_ops = { .init = tcan4x5x_init, + .deinit = tcan4x5x_deinit, .read_reg = tcan4x5x_read_reg, .write_reg = tcan4x5x_write_reg, .write_fifo = tcan4x5x_write_fifo,
Signature · 1 line
2.46.2
PATCH v3 3/3 can: m_can: call deinit/init callback when going into suspend/resume
In reply to Sean Nyekjaerm_can user like the tcan4x5x device, can go into standby mode. Low power RX mode is enabled to allow wake on can.
--- drivers/net/can/m_can/m_can.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/net/can/m_can/m_can.c +11 -4
@@ -2444,6 +2444,7 @@ int m_can_class_suspend(struct device *dev) {struct m_can_classdev *cdev =dev_get_drvdata (dev);struct net_device *ndev = cdev->net; +int ret =0 ;if (netif_running (ndev)) {netif_stop_queue (ndev);
@@ -2456,6 +2457,9 @@ int m_can_class_suspend(struct device *dev)if (cdev->pm_wake_source) {hrtimer_cancel (&cdev->hrtimer);m_can_write (cdev,M_CAN_IE ,IR_RF0N ); + +if (cdev->ops->deinit) + ret = cdev->ops->deinit (cdev); }else {m_can_stop (ndev); }
@@ -2467,7 +2471,7 @@ int m_can_class_suspend(struct device *dev) cdev->can.state =CAN_STATE_SLEEPING ; -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (m_can_class_suspend);
@@ -2475,14 +2479,13 @@ int m_can_class_resume(struct device *dev) {struct m_can_classdev *cdev =dev_get_drvdata (dev);struct net_device *ndev = cdev->net; +int ret =0 ;pinctrl_pm_select_default_state (dev); cdev->can.state =CAN_STATE_ERROR_ACTIVE ;if (netif_running (ndev)) { -int ret; - ret =m_can_clk_start (cdev);if (ret)return ret;
@@ -2495,6 +2498,10 @@ int m_can_class_resume(struct device *dev)* again. */ cdev->active_interrupts |=IR_RF0N |IR_TEFN ; + +if (cdev->ops->init) + ret = cdev->ops->init (cdev); +m_can_write (cdev,M_CAN_IE , cdev->active_interrupts); }else { ret =m_can_start (ndev);
@@ -2508,7 +2515,7 @@ int m_can_class_resume(struct device *dev)netif_start_queue (ndev); } -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (m_can_class_resume);
Signature · 1 line
2.46.2
Quoted 15 lines · Sean Nyekjaer
When downing the tcan4x5x there is no reason to keep the tcan4x5x in "normal" mode and waste power.
So set standby mode when the interface is down and normal mode when interface is up.Also when going into suspend, set the tcan4x5x into standby mode. The tcan4x5x can still be used as a wake-source when in standby as low power rx is enabled.
Signed-off-by Sean Nyekjaer <[email protected]>---
Changes in v3:
- Run deinit inm_can_stop()in any case even ifm_can_cccr_update_bits()fails
- Link to v2: https://lore.kernel.org/r/[email protected]
Quoted 6 lines
Changes in v2:
- Reduced code intcan4x5x_deinit()
- Taken care of return values from deinit callback
- Link to v1: https://lore.kernel.org/r/[email protected]---
Hi,
Anything needed from my side on this?
/Sean
Marc Kleine-Budde
maintainerQuoted 21 lines · Sean Nyekjaer
Quoted 20 lines · Sean Nyekjaer
When downing the tcan4x5x there is no reason to keep the tcan4x5x in "normal" mode and waste power.
So set standby mode when the interface is down and normal mode when interface is up.Also when going into suspend, set the tcan4x5x into standby mode. The tcan4x5x can still be used as a wake-source when in standby as low power rx is enabled.
Signed-off-by Sean Nyekjaer <[email protected]>---
Changes in v3:
- Run deinit inm_can_stop()in any case even ifm_can_cccr_update_bits()fails
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Reduced code intcan4x5x_deinit()
- Taken care of return values from deinit callback
- Link to v1: https://lore.kernel.org/r/[email protected]
Quoted 5 lines
Quoted 1 line
---
Hi,
Anything needed from my side on this?
I think this all could be hidden behind runtime PM, but that would mean a bigger re-write and a lot of testing. So applied to linux-can-next as is.
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 |