Skip to content

Commit 789976a

Browse files
commodoJonathan Cameron
authored andcommitted
iio: adc: at91-sama5d2_adc: merge buffer & trigger init into a function
This change is mostly cosmetic, but it's also a pre-cursor to the the change for 'iio_buffer_set_attrs()', where the helper gets updated to better support multiple IIO buffers for 1 IIO device. The only functional change is that the error message for the trigger alloc failure is bound to the parent device vs the IIO device object. Also, the new at91_adc_buffer_and_trigger_init() function was moved after the definition of the 'at91_adc_fifo_attributes'. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20200929125949.69934-3-alexandru.ardelean@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 5e6dc43 commit 789976a

1 file changed

Lines changed: 36 additions & 42 deletions

File tree

‎drivers/iio/adc/at91-sama5d2_adc.c‎

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,21 +1013,6 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *indio,
10131013

10141014
return trig;
10151015
}
1016-
1017-
static int at91_adc_trigger_init(struct iio_dev *indio)
1018-
{
1019-
struct at91_adc_state *st = iio_priv(indio);
1020-
1021-
st->trig = at91_adc_allocate_trigger(indio, st->selected_trig->name);
1022-
if (IS_ERR(st->trig)) {
1023-
dev_err(&indio->dev,
1024-
"could not allocate trigger\n");
1025-
return PTR_ERR(st->trig);
1026-
}
1027-
1028-
return 0;
1029-
}
1030-
10311016
static void at91_adc_trigger_handler_nodma(struct iio_dev *indio_dev,
10321017
struct iio_poll_func *pf)
10331018
{
@@ -1155,13 +1140,6 @@ static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
11551140
return IRQ_HANDLED;
11561141
}
11571142

1158-
static int at91_adc_buffer_init(struct iio_dev *indio)
1159-
{
1160-
return devm_iio_triggered_buffer_setup(&indio->dev, indio,
1161-
&iio_pollfunc_store_time,
1162-
&at91_adc_trigger_handler, &at91_buffer_setup_ops);
1163-
}
1164-
11651143
static unsigned at91_adc_startup_time(unsigned startup_time_min,
11661144
unsigned adc_clk_khz)
11671145
{
@@ -1691,6 +1669,40 @@ static const struct iio_info at91_adc_info = {
16911669
.hwfifo_set_watermark = &at91_adc_set_watermark,
16921670
};
16931671

1672+
static int at91_adc_buffer_and_trigger_init(struct device *dev,
1673+
struct iio_dev *indio)
1674+
{
1675+
struct at91_adc_state *st = iio_priv(indio);
1676+
int ret;
1677+
1678+
ret = devm_iio_triggered_buffer_setup(&indio->dev, indio,
1679+
&iio_pollfunc_store_time,
1680+
&at91_adc_trigger_handler, &at91_buffer_setup_ops);
1681+
if (ret < 0) {
1682+
dev_err(dev, "couldn't initialize the buffer.\n");
1683+
return ret;
1684+
}
1685+
1686+
if (!st->selected_trig->hw_trig)
1687+
return 0;
1688+
1689+
iio_buffer_set_attrs(indio->buffer, at91_adc_fifo_attributes);
1690+
1691+
st->trig = at91_adc_allocate_trigger(indio, st->selected_trig->name);
1692+
if (IS_ERR(st->trig)) {
1693+
dev_err(dev, "could not allocate trigger\n");
1694+
return PTR_ERR(st->trig);
1695+
}
1696+
1697+
/*
1698+
* Initially the iio buffer has a length of 2 and
1699+
* a watermark of 1
1700+
*/
1701+
st->dma_st.watermark = 1;
1702+
1703+
return 0;
1704+
}
1705+
16941706
static int at91_adc_probe(struct platform_device *pdev)
16951707
{
16961708
struct iio_dev *indio_dev;
@@ -1826,27 +1838,9 @@ static int at91_adc_probe(struct platform_device *pdev)
18261838

18271839
platform_set_drvdata(pdev, indio_dev);
18281840

1829-
ret = at91_adc_buffer_init(indio_dev);
1830-
if (ret < 0) {
1831-
dev_err(&pdev->dev, "couldn't initialize the buffer.\n");
1841+
ret = at91_adc_buffer_and_trigger_init(&pdev->dev, indio_dev);
1842+
if (ret < 0)
18321843
goto per_clk_disable_unprepare;
1833-
}
1834-
1835-
if (st->selected_trig->hw_trig) {
1836-
ret = at91_adc_trigger_init(indio_dev);
1837-
if (ret < 0) {
1838-
dev_err(&pdev->dev, "couldn't setup the triggers.\n");
1839-
goto per_clk_disable_unprepare;
1840-
}
1841-
/*
1842-
* Initially the iio buffer has a length of 2 and
1843-
* a watermark of 1
1844-
*/
1845-
st->dma_st.watermark = 1;
1846-
1847-
iio_buffer_set_attrs(indio_dev->buffer,
1848-
at91_adc_fifo_attributes);
1849-
}
18501844

18511845
if (dma_coerce_mask_and_coherent(&indio_dev->dev, DMA_BIT_MASK(32)))
18521846
dev_info(&pdev->dev, "cannot set DMA mask to 32-bit\n");

0 commit comments

Comments
 (0)