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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > > +
> > >  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@xxxxxxxxx>");
> > >  MODULE_DESCRIPTION("Bosch BME680 Driver");
> > >  MODULE_LICENSE("GPL v2");  
> >   





[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux