Re: [PATCH v4] can: tcan4x5x: put tcan into sleep when removing driver

From: Marc Kleine-Budde

Date: Wed Aug 05 2026 - 03:32:31 EST


On 04.08.2026 13:30:26, Sean Nyekjaer wrote:
> Put the tcan4x5x transceiver into sleep mode when the driver is
> removed, instead of leaving it in its current operating mode.
> This reduces power consumption(3mA@12V) once the driver is
> no longer bound to the device.
>
> Signed-off-by: Sean Nyekjaer <sean@xxxxxxxxxx>
> ---
> Changes since v1:
> - Moved enter sleep mode into tcan4x5x_power_enable()
>
> Changes since v2:
> - Added comment about RST pin
> - Fixed all calls to tcan4x5x_power_enable()
>
> Changes since v3:
> - When powering off, always put the device into sleep mode (if the RST pin is
> present). This will ensure the device is in sleep mode even if the
> power regulator is shared.
>
> drivers/net/can/m_can/tcan4x5x-core.c | 29 +++++++++++++++++++++++----
> 1 file changed, 25 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
> index 31cc9d0abd45..d8fd219a27cc 100644
> --- a/drivers/net/can/m_can/tcan4x5x-core.c
> +++ b/drivers/net/can/m_can/tcan4x5x-core.c
> @@ -211,8 +211,29 @@ static int tcan4x5x_write_fifo(struct m_can_classdev *cdev,
> return regmap_bulk_write(priv->regmap, TCAN4X5X_MRAM_START + addr_offset, val, val_count);
> }
>
> -static int tcan4x5x_power_enable(struct regulator *reg, int enable)
> +static int tcan4x5x_power_enable(struct tcan4x5x_priv *priv, int enable)
> {
> + struct regulator *reg = priv->power;
> + int ret;
> +
> + /*
> + * Put the device into sleep mode if the RST pin is available,
> + * since a wake-up event, RST pin toggle, or power cycle are the only
> + * ways to exit sleep mode.
> + * Redundant if the regulator is exclusive to this device, but that
> + * can't be determined here.
> + *
> + * Datasheet: TCAN4550, section "8.4.3 Sleep Mode"
> + * https://www.ti.com/lit/gpn/tcan4550
> + */
> + if (priv->reset_gpio && !enable) {
> + ret = regmap_update_bits(priv->regmap, TCAN4X5X_CONFIG,
> + TCAN4X5X_MODE_SEL_MASK,
> + TCAN4X5X_MODE_SLEEP);
> + if (ret)
> + return ret;

As sashiko pointed out, maybe only log a error here and continue.

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: signature.asc
Description: PGP signature