Commit 3c530805 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron

iio: adc: ti_am335x_adc: alloc kfifo & IRQ via devm_ functions

This change attaches the life-cycle of the kfifo buffer & IRQ to the
parent-device. This in turn cleans up the exit & error paths, since we
don't need to explicitly cleanup these resources.

The main intent here is to remove the explicit cleanup of the
'indio_dev->buffer' via 'iio_kfifo_free(indio_dev->buffer);'.

As we want to add support for multiple buffers per IIO device, having it
exposed like this makes it tricky to consider a safe backwards compatible
approach for it.
Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 6ff0199a
...@@ -377,7 +377,8 @@ static const struct iio_buffer_setup_ops tiadc_buffer_setup_ops = { ...@@ -377,7 +377,8 @@ static const struct iio_buffer_setup_ops tiadc_buffer_setup_ops = {
.postdisable = &tiadc_buffer_postdisable, .postdisable = &tiadc_buffer_postdisable,
}; };
static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev, static int tiadc_iio_buffered_hardware_setup(struct device *dev,
struct iio_dev *indio_dev,
irqreturn_t (*pollfunc_bh)(int irq, void *p), irqreturn_t (*pollfunc_bh)(int irq, void *p),
irqreturn_t (*pollfunc_th)(int irq, void *p), irqreturn_t (*pollfunc_th)(int irq, void *p),
int irq, int irq,
...@@ -387,13 +388,13 @@ static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev, ...@@ -387,13 +388,13 @@ static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev,
struct iio_buffer *buffer; struct iio_buffer *buffer;
int ret; int ret;
buffer = iio_kfifo_allocate(); buffer = devm_iio_kfifo_allocate(dev);
if (!buffer) if (!buffer)
return -ENOMEM; return -ENOMEM;
iio_device_attach_buffer(indio_dev, buffer); iio_device_attach_buffer(indio_dev, buffer);
ret = request_threaded_irq(irq, pollfunc_th, pollfunc_bh, ret = devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh,
flags, indio_dev->name, indio_dev); flags, indio_dev->name, indio_dev);
if (ret) if (ret)
goto error_kfifo_free; goto error_kfifo_free;
...@@ -408,15 +409,6 @@ static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev, ...@@ -408,15 +409,6 @@ static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev,
return ret; return ret;
} }
static void tiadc_iio_buffered_hardware_remove(struct iio_dev *indio_dev)
{
struct tiadc_device *adc_dev = iio_priv(indio_dev);
free_irq(adc_dev->mfd_tscadc->irq, indio_dev);
iio_kfifo_free(indio_dev->buffer);
}
static const char * const chan_name_ain[] = { static const char * const chan_name_ain[] = {
"AIN0", "AIN0",
"AIN1", "AIN1",
...@@ -635,7 +627,7 @@ static int tiadc_probe(struct platform_device *pdev) ...@@ -635,7 +627,7 @@ static int tiadc_probe(struct platform_device *pdev)
if (err < 0) if (err < 0)
return err; return err;
err = tiadc_iio_buffered_hardware_setup(indio_dev, err = tiadc_iio_buffered_hardware_setup(&pdev->dev, indio_dev,
&tiadc_worker_h, &tiadc_worker_h,
&tiadc_irq_h, &tiadc_irq_h,
adc_dev->mfd_tscadc->irq, adc_dev->mfd_tscadc->irq,
...@@ -660,7 +652,6 @@ static int tiadc_probe(struct platform_device *pdev) ...@@ -660,7 +652,6 @@ static int tiadc_probe(struct platform_device *pdev)
err_dma: err_dma:
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
err_buffer_unregister: err_buffer_unregister:
tiadc_iio_buffered_hardware_remove(indio_dev);
err_free_channels: err_free_channels:
return err; return err;
} }
...@@ -678,7 +669,6 @@ static int tiadc_remove(struct platform_device *pdev) ...@@ -678,7 +669,6 @@ static int tiadc_remove(struct platform_device *pdev)
dma_release_channel(dma->chan); dma_release_channel(dma->chan);
} }
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
tiadc_iio_buffered_hardware_remove(indio_dev);
step_en = get_adc_step_mask(adc_dev); step_en = get_adc_step_mask(adc_dev);
am335x_tsc_se_clr(adc_dev->mfd_tscadc, step_en); am335x_tsc_se_clr(adc_dev->mfd_tscadc, step_en);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment