All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Akshay Jindal <akshayaj.lkd@gmail.com>,
	anshulusr@gmail.com, jic23@kernel.org, dlechner@baylibre.com,
	nuno.sa@analog.com, andy@kernel.org, shuah@kernel.org,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: light: ltr390: Add remove callback with needed support in device registration
Date: Sat, 9 Aug 2025 12:53:40 +0300	[thread overview]
Message-ID: <aJcapPt8f5YMUBH3@smile.fi.intel.com> (raw)
In-Reply-To: <20250807140401.00006c85@huawei.com>

On Thu, Aug 07, 2025 at 02:04:01PM +0100, Jonathan Cameron wrote:
> On Wed, 6 Aug 2025 23:02:44 +0300
> Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > On Wed, Aug 06, 2025 at 04:18:01PM +0100, Jonathan Cameron wrote:
> > > On Tue, 5 Aug 2025 14:47:32 +0200
> > > Andy Shevchenko <andy.shevchenko@gmail.com> wrote:  
> > > > On Tue, Aug 5, 2025 at 6:05 AM Akshay Jindal <akshayaj.lkd@gmail.com> wrote:  
> > > > > On Tue, Aug 5, 2025 at 2:36 AM Andy Shevchenko
> > > > > <andy.shevchenko@gmail.com> wrote:    

...

> > > > > > Doesn't sound right to me. HAve you investigated PM runtime paths?    
> > > > > Yes I did investigate and found that PM runtime->suspend() callback
> > > > > co-exists with remove callback.
> > > > >    
> > > > > > Looking at what the code you added there it sounds to me like a part
> > > > > > of PM runtime ->suspend() callback.    
> > > > > Yes, part of functionality will always be common, because both the
> > > > > callback implementations put
> > > > > the device into powered down or low power state which is what has been done here
> > > > > Both _suspend() and remove are called at different times in the lifecycle of the
> > > > > driver, but with respect to register setting, they put the device into
> > > > > power down state.    
> > > > 
> > > > Are you sure about the remove stage and how it interacts with runtime
> > > > PM? Please, check how the device driver core manages PM on the remove
> > > > stage.
> > > >   
> > > > > Additionally .remove() can have code for:
> > > > > 1. disable runtime power management (if enabled while device registration).    
> > > > 
> > > > If the device core enables it for you, it will disable it
> > > > symmetrically. I don't see the issue here, it should be done
> > > > automatically. If you do that explicitly, use the respective
> > > > devm_pm_runtime_*() call.
> > > >   
> > > > > 2. device cleanup (disabling interrupt and cleaning up other configs done).    
> > > > 
> > > > Wrap them into devm if required.
> > > >   
> > > > > 2. unregister the device.    
> > > > 
> > > > Already done in the original code which your patch reverts, why?
> > > >   
> > > > > For eg: another light sensor bh1750
> > > > > static void bh1750_remove(struct i2c_client *client)
> > > > > {
> > > > >     iio_device_unregister(indio_dev);
> > > > >     mutex_lock(&data->lock);
> > > > >     i2c_smbus_write_byte(client, BH1750_POWER_DOWN);
> > > > >     mutex_unlock(&data->lock);
> > > > > }
> > > > >
> > > > > static int bh1750_suspend(struct device *dev)
> > > > > {
> > > > >     mutex_lock(&data->lock);
> > > > >     ret = i2c_smbus_write_byte(data->client, BH1750_POWER_DOWN);
> > > > >     mutex_unlock(&data->lock);
> > > > >     return ret;
> > > > > }    
> > > > 
> > > > Correct and where do you see the problem here? Perhaps the problem is
> > > > in the cleanup aordering and some other bugs vs. devm calls?
> > > >   
> > > > > In drivers/iio/light, you can find similar examples in pa12203001,
> > > > > rpr0521, apds9960,
> > > > > vcnl4000, isl29028, vcnl4035. You can find many more examples in
> > > > > sensors other than light sensors.    
> > > > 
> > > > Good, should all they need to be fixed?  
> > > 
> > > The complex corners that occur with devm + runtime pm are around
> > > things that we must not run if we are already in runtime suspend.
> > > Typically disabling power supplies (as we can underflow counters
> > > and getting warning prints).  Seeing as this driver is not
> > > doing that it should be simple to use a devm_add_action_or_reset()
> > > 
> > > Key thing to consider is that runtime pm may not be built.  
> > 
> > This will mean that user does not want to handle PM at all at runtime, so why
> > should it be our problem? If device is off, it's not the problem of the driver
> > to do the power cycle at run time (yes, this might not apply to the system
> > suspend and resume cases, which has to be implemented as well).
> > 
> > > So the flow should work with those calls doing nothing.  That means that
> > > if you turn the device on in probe we should make sure to explicitly turn
> > > it off in the remove flow. That's where devm_add_action_or_reset()
> > > comes in handy.  
> > 
> > I don't think we should do that explicitly in remove. As I pointed out above,
> > this the case that driver should not override.  Otherwise there is no point in
> > having the common runtime PM. User deliberately makes it not compiled, so they
> > should prepare to leave with it.
> 
> Hmm. I don't agree. We turned it on so on error or remove I think we
> should turn it off again.  We do that in many drivers that never made use of
> any of the standard PM stuff because they only touch enable and disable in
> probe and remove.  If nothing else I don't like the lack of balance between
> probe and remove if we don't do it.

We can do it, but this sounds to me like a step back. Implementing proper PM
runtime callbacks is a step forward.

Doing the former in the existing drivers is not an argument to me because all
of them avoiding use of the PM APIs. Note, with PM APIs it may also involve
devlink and other benefits that device driver core gives us.

> > > ret = regmap_set_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_SENSOR_ENABLE);
> > > Is the paired operation with the second disable you add in remove.
> > > Wrap that in a devm callback.
> > > 
> > > More complex is the interrupt enable as that doesn't pair with
> > > anything in particular in probe. I'm curious though, do we need
> > > to disable it given the next operation turns off the sensor and on
> > > probe we reset the sensor.
> > > 
> > > Is just clearing the enable bit enough?   

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-08-09  9:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-04 19:25 [PATCH] iio: light: ltr390: Add remove callback with needed support in device registration Akshay Jindal
2025-08-04 21:05 ` Andy Shevchenko
2025-08-05  4:05   ` Akshay Jindal
2025-08-05 12:47     ` Andy Shevchenko
2025-08-06 15:18       ` Jonathan Cameron
2025-08-06 20:02         ` Andy Shevchenko
2025-08-07 13:04           ` Jonathan Cameron
2025-08-09  9:53             ` Andy Shevchenko [this message]
2025-08-09 19:57               ` Jonathan Cameron
2025-08-09 20:34                 ` Andy Shevchenko
2025-08-10 20:48                   ` Akshay Jindal
2025-08-11 20:25                     ` Jonathan Cameron
2025-08-08 14:23       ` Akshay Jindal
2025-08-08 14:33         ` Andy Shevchenko
2025-08-08 14:55           ` Akshay Jindal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aJcapPt8f5YMUBH3@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=akshayaj.lkd@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=anshulusr@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.