[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20241030203514.349d8142@jic23-huawei>
Date: Wed, 30 Oct 2024 20:35:14 +0000
From: Jonathan Cameron <jic23@...nel.org>
To: Vasileios Amoiridis <vassilisamir@...il.com>
Cc: lars@...afoo.de, robh@...nel.org, krzk+dt@...nel.org,
conor+dt@...nel.org, andriy.shevchenko@...ux.intel.com,
anshulusr@...il.com, gustavograzs@...il.com, linux-iio@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 13/13] iio: chemical: bme680: add power management
> > > +
> > > int bme680_core_probe(struct device *dev, struct regmap *regmap,
> > > const char *name)
> > > {
> > > @@ -1164,15 +1231,60 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap,
> > > ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> > > iio_pollfunc_store_time,
> > > bme680_trigger_handler,
> > > - NULL);
> > > + &bme680_buffer_setup_ops);
> > > if (ret)
> > > return dev_err_probe(dev, ret,
> > > "iio triggered buffer setup failed\n");
> > >
> > > + /* Enable runtime PM */
> > > + pm_runtime_get_noresume(dev);
> > > + pm_runtime_set_autosuspend_delay(dev, BME680_STARTUP_TIME_US * 100);
> > > + pm_runtime_use_autosuspend(dev);
> > > + pm_runtime_set_active(dev);
> > > + ret = devm_pm_runtime_enable(dev);
> >
> > Take a look at what this unwinds in the devm handler. You don't need to do
> > as much (or possibly anything) yourself.
> >
> >
>
> Well, in general what I see that could probably be dropped here is the
> extra add_action_or_reset because of the devm_*. About the functions
> get_noresume() and put(), I feel that they could be dropped as well
> because the device registration will happen well before the autosuspend
> delay, but does it make sense to depend on something like this?
If you haven't enabled runtime pm yet all you need to do is set up the
current state Shouldn't need the get etc as you don't care if it powers
down here anyway as you aren't talking to the device.
>
> Cheers,
> Vasilis
>
> > > + if (ret)
> > > + return ret;
> > > +
> > > + pm_runtime_put(dev);
> > > +
> > > + ret = devm_add_action_or_reset(dev, bme680_pm_disable, dev);
> > > + if (ret)
> > > + return ret;
> > > +
> > > return devm_iio_device_register(dev, indio_dev);
> > > }
> > > EXPORT_SYMBOL_NS_GPL(bme680_core_probe, IIO_BME680);
> > >
> > > +static int bme680_runtime_suspend(struct device *dev)
> > > +{
> > > + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> > > + struct bme680_data *data = iio_priv(indio_dev);
> > > +
> > > + return regulator_bulk_disable(BME680_NUM_SUPPLIES, data->supplies);
> > > +}
> > > +
> > > +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;
> > > +
> > > + return bme680_gas_config(data);
> > > +}
> > > +
> > > +EXPORT_RUNTIME_DEV_PM_OPS(bme680_dev_pm_ops, bme680_runtime_suspend,
> > > + bme680_runtime_resume, NULL);
> > > +
> > > MODULE_AUTHOR("Himanshu Jha <himanshujha199640@...il.com>");
> > > MODULE_DESCRIPTION("Bosch BME680 Driver");
> > > MODULE_LICENSE("GPL v2");
> >
Powered by blists - more mailing lists