Re: [PATCH v1 08/13] iio: chemical: bme680: add power management

Vasileios Aoiridis
2024-10-11T19:02:36Z

On Fri, Oct 11, 2024 at 01:10:20PM +0300, Andy Shevchenko wrote:
> On Thu, Oct 10, 2024 at 11:00:25PM +0200, vamoirid wrote:
> > From: Vasileios Amoiridis <vassilisamir@gmail.com>
> >
> > Add runtime power management to the device. To facilitate this, add also
> > a struct dev * inside the bme680_data structure to have the device
> > accesible from the data structure.
>
> ...
>
> > --- a/drivers/iio/chemical/bme680.h
> > +++ b/drivers/iio/chemical/bme680.h
> > @@ -75,6 +75,7 @@
> > #define BME680_CALIB_RANGE_3_LEN 5
> >
> > extern const struct regmap_config bme680_regmap_config;
> > +extern const struct dev_pm_ops bmp280_dev_pm_ops;
>
> Is pm.h being included already in this header? Otherwise you need to add it.
>

No it is not, and indeed I need to add it. Probably because it was
included by some other file I didn't get an error from gcc?

> ...
>
> > struct regmap *regmap;
> > struct bme680_calib bme680;
> > struct mutex lock; /* Protect multiple serial R/W ops to device. */
> > + struct device *dev;
>
> Is it the same that you may get wia regmap_get_device()?
>

Yes it is the same. Maybe I can try and see if I can use the following

regmap_get_device(data->regmap)

in the places where the pm functions are used in order to not declare a
new value inside the struct bme680_data. But in general, is this approach
prefered?

> > u8 oversampling_temp;
> > u8 oversampling_press;
> > u8 oversampling_humid;
>
> ...
>
> > + /* Enable runtime PM */
> > + pm_runtime_get_noresume(dev);
> > + pm_runtime_set_active(dev);
> > + pm_runtime_enable(dev);
> > + pm_runtime_set_autosuspend_delay(dev, BME680_STARTUP_TIME_US * 100);
> > + pm_runtime_use_autosuspend(dev);
> > + pm_runtime_put(dev);
>
> Can we use devm_pm_runtime_enable() for some of the above?
>

I will have to check its use, and I will let you know.

> > + ret = devm_add_action_or_reset(dev, bme680_pm_disable, dev);
> > + if (ret)
> > + return ret;
>
> ...
>
> > +static int bme680_runtime_resume(struct device *dev)
> > +{
> > + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> > + struct bme680_data *data = iio_priv(indio_dev);
> > + int ret;
> > +
> > + ret = regulator_bulk_enable(BME680_NUM_SUPPLIES, data->supplies);
> > + if (ret)
> > + return ret;
> > +
> > + fsleep(BME680_STARTUP_TIME_US);
> > +
> > + ret = bme680_chip_config(data);
> > + if (ret)
> > + return ret;
>
> > + ret = bme680_gas_config(data);
> > + if (ret)
> > + return ret;
> > +
> > + return 0;
>
> return bme680_gas_config(...);
>

Indeed, much cleaner, thanks!

> > +}
>
> ...
>
> > +EXPORT_RUNTIME_DEV_PM_OPS(bme680_dev_pm_ops, bme680_runtime_suspend,
> > + bme680_runtime_resume, NULL);
>
> You also need pm.h for the macro IIRC.
>

ACK.

> --
> With Best Regards,
> Andy Shevchenko
>
>

Cheers,
Vasilis