mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver
@ 2026-08-03 10:19 Sean Nyekjaer
  2026-08-03 10:59 ` Marc Kleine-Budde
  2026-08-12 10:29 ` kernel test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Sean Nyekjaer @ 2026-08-03 10:19 UTC (permalink / raw)
  To: Markus Schneider-Pargmann, Marc Kleine-Budde, Vincent Mailhol
  Cc: Sean Nyekjaer, linux-can, linux-kernel

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@geanix.com>
---
Changes since v1:
 - Moved enter sleep mode into tcan4x5x_power_enable()

 drivers/net/can/m_can/tcan4x5x-core.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
index 31cc9d0abd45..67902b8b0fab 100644
--- a/drivers/net/can/m_can/tcan4x5x-core.c
+++ b/drivers/net/can/m_can/tcan4x5x-core.c
@@ -211,15 +211,21 @@ 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)
 {
-	if (IS_ERR_OR_NULL(reg))
+	if (IS_ERR_OR_NULL(priv->power)) {
+		if (priv->reset_gpio && !enable)
+			return regmap_update_bits(priv->regmap, TCAN4X5X_CONFIG,
+						  TCAN4X5X_MODE_SEL_MASK,
+						  TCAN4X5X_MODE_SLEEP);
+
 		return 0;
+	}
 
 	if (enable)
-		return regulator_enable(reg);
+		return regulator_enable(priv->power);
 	else
-		return regulator_disable(reg);
+		return regulator_disable(priv->power);
 }
 
 static int tcan4x5x_write_tcan_reg(struct m_can_classdev *cdev,
@@ -476,7 +482,7 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 		goto out_m_can_class_free_dev;
 	}
 
-	ret = tcan4x5x_power_enable(priv->power, 1);
+	ret = tcan4x5x_power_enable(priv, 1);
 	if (ret) {
 		dev_err(&spi->dev, "Enabling regulator failed %pe\n",
 			ERR_PTR(ret));
@@ -531,7 +537,7 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 	return 0;
 
 out_power:
-	tcan4x5x_power_enable(priv->power, 0);
+	tcan4x5x_power_enable(priv, 0);
  out_m_can_class_free_dev:
 	m_can_class_free_dev(mcan_class->net);
 	return ret;
-- 
2.55.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver
  2026-08-03 10:19 [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver Sean Nyekjaer
@ 2026-08-03 10:59 ` Marc Kleine-Budde
  2026-08-03 11:32   ` Sean Nyekjaer
  2026-08-12 10:29 ` kernel test robot
  1 sibling, 1 reply; 4+ messages in thread
From: Marc Kleine-Budde @ 2026-08-03 10:59 UTC (permalink / raw)
  To: Sean Nyekjaer
  Cc: Markus Schneider-Pargmann, Vincent Mailhol, linux-can, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2474 bytes --]

On 03.08.2026 12:19: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@geanix.com>

Seems you patch is not complete:

| drivers/net/can/m_can/tcan4x5x-core.c: In function ‘tcan4x5x_can_remove’:
| drivers/net/can/m_can/tcan4x5x-core.c:552:35: error: passing argument 1 of ‘tcan4x5x_power_enable’ from incompatible pointer type [-Wincompatible-pointer-types]
|   552 |         tcan4x5x_power_enable(priv->power, 0);
|       |                               ~~~~^~~~~~~
|       |                                   |
|       |                                   struct regulator *
| drivers/net/can/m_can/tcan4x5x-core.c:214:56: note: expected ‘struct tcan4x5x_priv *’ but argument is of type ‘struct regulator *’
|   214 | static int tcan4x5x_power_enable(struct tcan4x5x_priv *priv, int enable)
|       |                                  ~~~~~~~~~~~~~~~~~~~~~~^~~~

> ---
> Changes since v1:
>  - Moved enter sleep mode into tcan4x5x_power_enable()
>
>  drivers/net/can/m_can/tcan4x5x-core.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
> index 31cc9d0abd45..67902b8b0fab 100644
> --- a/drivers/net/can/m_can/tcan4x5x-core.c
> +++ b/drivers/net/can/m_can/tcan4x5x-core.c
> @@ -211,15 +211,21 @@ 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)
>  {

If you add:

        struct regulator *reg = priv->power;

the diff should be smaller.

> -	if (IS_ERR_OR_NULL(reg))
> +	if (IS_ERR_OR_NULL(priv->power)) {

Can you please add a comment that the reset GPIO is needed to get the
device out of sleep mode.

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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver
  2026-08-03 10:59 ` Marc Kleine-Budde
@ 2026-08-03 11:32   ` Sean Nyekjaer
  0 siblings, 0 replies; 4+ messages in thread
From: Sean Nyekjaer @ 2026-08-03 11:32 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Markus Schneider-Pargmann, Vincent Mailhol, linux-can, linux-kernel





On Monday, 3 August 2026 at 13:27, Marc Kleine-Budde <mkl@pengutronix.de> wrote:

> On 03.08.2026 12:19: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@geanix.com>
> 
> Seems you patch is not complete:
> 
> | drivers/net/can/m_can/tcan4x5x-core.c: In function ‘tcan4x5x_can_remove’:
> | drivers/net/can/m_can/tcan4x5x-core.c:552:35: error: passing argument 1 of ‘tcan4x5x_power_enable’ from incompatible pointer type [-Wincompatible-pointer-types]
> |   552 |         tcan4x5x_power_enable(priv->power, 0);
> |       |                               ~~~~^~~~~~~
> |       |                                   |
> |       |                                   struct regulator *
> | drivers/net/can/m_can/tcan4x5x-core.c:214:56: note: expected ‘struct tcan4x5x_priv *’ but argument is of type ‘struct regulator *’
> |   214 | static int tcan4x5x_power_enable(struct tcan4x5x_priv *priv, int enable)
> |       |                                  ~~~~~~~~~~~~~~~~~~~~~~^~~~

Yes.

> 
> > ---
> > Changes since v1:
> >  - Moved enter sleep mode into tcan4x5x_power_enable()
> >
> >  drivers/net/can/m_can/tcan4x5x-core.c | 18 ++++++++++++------
> >  1 file changed, 12 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
> > index 31cc9d0abd45..67902b8b0fab 100644
> > --- a/drivers/net/can/m_can/tcan4x5x-core.c
> > +++ b/drivers/net/can/m_can/tcan4x5x-core.c
> > @@ -211,15 +211,21 @@ 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)
> >  {
> 
> If you add:
> 
>         struct regulator *reg = priv->power;
> 
> the diff should be smaller.

Yes.

> 
> > -	if (IS_ERR_OR_NULL(reg))
> > +	if (IS_ERR_OR_NULL(priv->power)) {
> 
> Can you please add a comment that the reset GPIO is needed to get the
> device out of sleep mode.

Will do! Sorry first day after vacation.

/Sean

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver
  2026-08-03 10:19 [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver Sean Nyekjaer
  2026-08-03 10:59 ` Marc Kleine-Budde
@ 2026-08-12 10:29 ` kernel test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-08-12 10:29 UTC (permalink / raw)
  To: Sean Nyekjaer, Markus Schneider-Pargmann, Marc Kleine-Budde,
	Vincent Mailhol
  Cc: oe-kbuild-all, Sean Nyekjaer, linux-can, linux-kernel

Hi Sean,

kernel test robot noticed the following build errors:

[auto build test ERROR on mkl-can-next/testing]
[also build test ERROR on linus/master v7.2-rc7 next-20260810]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sean-Nyekjaer/can-tcan4x5x-put-tcan-into-sleep-when-removing-driver/20260812-163135
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git testing
patch link:    https://lore.kernel.org/r/20260803101927.17122-1-sean%40geanix.com
patch subject: [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver
config: alpha-allmodconfig (https://download.01.org/0day-ci/archive/20260812/202608121810.7mcuyYMc-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260812/202608121810.7mcuyYMc-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202608121810.7mcuyYMc-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/net/can/m_can/tcan4x5x-core.c: In function 'tcan4x5x_can_remove':
>> drivers/net/can/m_can/tcan4x5x-core.c:552:35: error: passing argument 1 of 'tcan4x5x_power_enable' from incompatible pointer type [-Wincompatible-pointer-types]
     552 |         tcan4x5x_power_enable(priv->power, 0);
         |                               ~~~~^~~~~~~
         |                                   |
         |                                   struct regulator *
   drivers/net/can/m_can/tcan4x5x-core.c:214:56: note: expected 'struct tcan4x5x_priv *' but argument is of type 'struct regulator *'
     214 | static int tcan4x5x_power_enable(struct tcan4x5x_priv *priv, int enable)
         |                                  ~~~~~~~~~~~~~~~~~~~~~~^~~~


vim +/tcan4x5x_power_enable +552 drivers/net/can/m_can/tcan4x5x-core.c

5443c226ba9166 drivers/net/can/m_can/tcan4x5x.c      Dan Murphy        2019-05-09  545  
a0386bba70934d drivers/net/can/m_can/tcan4x5x-core.c Uwe Kleine-König  2022-01-23  546  static void tcan4x5x_can_remove(struct spi_device *spi)
5443c226ba9166 drivers/net/can/m_can/tcan4x5x.c      Dan Murphy        2019-05-09  547  {
5443c226ba9166 drivers/net/can/m_can/tcan4x5x.c      Dan Murphy        2019-05-09  548  	struct tcan4x5x_priv *priv = spi_get_drvdata(spi);
5443c226ba9166 drivers/net/can/m_can/tcan4x5x.c      Dan Murphy        2019-05-09  549  
ac33ffd3e2b037 drivers/net/can/m_can/tcan4x5x.c      Marc Kleine-Budde 2020-12-12  550  	m_can_class_unregister(&priv->cdev);
5443c226ba9166 drivers/net/can/m_can/tcan4x5x.c      Dan Murphy        2019-05-09  551  
c81d0b6ca66547 drivers/net/can/m_can/tcan4x5x.c      Marc Kleine-Budde 2020-08-10 @552  	tcan4x5x_power_enable(priv->power, 0);
c81d0b6ca66547 drivers/net/can/m_can/tcan4x5x.c      Marc Kleine-Budde 2020-08-10  553  
ac33ffd3e2b037 drivers/net/can/m_can/tcan4x5x.c      Marc Kleine-Budde 2020-12-12  554  	m_can_class_free_dev(priv->cdev.net);
5443c226ba9166 drivers/net/can/m_can/tcan4x5x.c      Dan Murphy        2019-05-09  555  }
5443c226ba9166 drivers/net/can/m_can/tcan4x5x.c      Dan Murphy        2019-05-09  556  

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-12 10:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-03 10:19 [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver Sean Nyekjaer
2026-08-03 10:59 ` Marc Kleine-Budde
2026-08-03 11:32   ` Sean Nyekjaer
2026-08-12 10:29 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®