mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 08:14:15 +08:00
iio: adc: ad_sigma_delta: introduct devm_ad_sd_setup_buffer_and_trigger()
This is a version of ad_sd_setup_buffer_and_trigger() with all underlying functions (that are used) being replaced with their device-managed variants. One thing to take care here is with {devm_}iio_trigger_alloc(), where both functions take a parent-device object as the first parameter. To make sure nothing quirky is happening, the devm_ad_sd_probe_trigger() function is checking that the provided 'dev' reference is the same as the one stored on the 'struct ad_sigma_delta' driver data. Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com> Link: https://lore.kernel.org/r/20210513120752.90074-6-aardelean@deviqon.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
e6148fe791
commit
718fb2bcf1
@ -513,6 +513,46 @@ error_ret:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int devm_ad_sd_probe_trigger(struct device *dev, struct iio_dev *indio_dev)
|
||||
{
|
||||
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
|
||||
int ret;
|
||||
|
||||
if (dev != &sigma_delta->spi->dev) {
|
||||
dev_err(dev, "Trigger parent should be '%s', got '%s'\n",
|
||||
dev_name(dev), dev_name(&sigma_delta->spi->dev));
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
sigma_delta->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
|
||||
iio_device_id(indio_dev));
|
||||
if (sigma_delta->trig == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
sigma_delta->trig->ops = &ad_sd_trigger_ops;
|
||||
init_completion(&sigma_delta->completion);
|
||||
|
||||
sigma_delta->irq_dis = true;
|
||||
ret = devm_request_irq(dev, sigma_delta->spi->irq,
|
||||
ad_sd_data_rdy_trig_poll,
|
||||
sigma_delta->info->irq_flags | IRQF_NO_AUTOEN,
|
||||
indio_dev->name,
|
||||
sigma_delta);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta);
|
||||
|
||||
ret = devm_iio_trigger_register(dev, sigma_delta->trig);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* select default trigger */
|
||||
indio_dev->trig = iio_trigger_get(sigma_delta->trig);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ad_sd_remove_trigger(struct iio_dev *indio_dev)
|
||||
{
|
||||
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
|
||||
@ -556,6 +596,26 @@ void ad_sd_cleanup_buffer_and_trigger(struct iio_dev *indio_dev)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ad_sd_cleanup_buffer_and_trigger);
|
||||
|
||||
/**
|
||||
* devm_ad_sd_setup_buffer_and_trigger() - Device-managed buffer & trigger setup
|
||||
* @dev: Device object to which to bind the life-time of the resources attached
|
||||
* @indio_dev: The IIO device
|
||||
*/
|
||||
int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indio_dev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
|
||||
&iio_pollfunc_store_time,
|
||||
&ad_sd_trigger_handler,
|
||||
&ad_sd_buffer_setup_ops);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return devm_ad_sd_probe_trigger(dev, indio_dev);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(devm_ad_sd_setup_buffer_and_trigger);
|
||||
|
||||
/**
|
||||
* ad_sd_init() - Initializes a ad_sigma_delta struct
|
||||
* @sigma_delta: The ad_sigma_delta device
|
||||
|
@ -26,6 +26,7 @@ struct ad_sd_calib_data {
|
||||
};
|
||||
|
||||
struct ad_sigma_delta;
|
||||
struct device;
|
||||
struct iio_dev;
|
||||
|
||||
/**
|
||||
@ -135,6 +136,8 @@ int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev,
|
||||
int ad_sd_setup_buffer_and_trigger(struct iio_dev *indio_dev);
|
||||
void ad_sd_cleanup_buffer_and_trigger(struct iio_dev *indio_dev);
|
||||
|
||||
int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indio_dev);
|
||||
|
||||
int ad_sd_validate_trigger(struct iio_dev *indio_dev, struct iio_trigger *trig);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user