Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
789976ac 5e6dc43e

+36 -42
+36 -42
drivers/iio/adc/at91-sama5d2_adc.c
··· 1013 1013 1014 1014 return trig; 1015 1015 } 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 - 1031 1016 static void at91_adc_trigger_handler_nodma(struct iio_dev *indio_dev, 1032 1017 struct iio_poll_func *pf) 1033 1018 { ··· 1138 1153 iio_trigger_notify_done(indio_dev->trig); 1139 1154 1140 1155 return IRQ_HANDLED; 1141 - } 1142 - 1143 - static int at91_adc_buffer_init(struct iio_dev *indio) 1144 - { 1145 - return devm_iio_triggered_buffer_setup(&indio->dev, indio, 1146 - &iio_pollfunc_store_time, 1147 - &at91_adc_trigger_handler, &at91_buffer_setup_ops); 1148 1156 } 1149 1157 1150 1158 static unsigned at91_adc_startup_time(unsigned startup_time_min, ··· 1669 1691 .hwfifo_set_watermark = &at91_adc_set_watermark, 1670 1692 }; 1671 1693 1694 + static int at91_adc_buffer_and_trigger_init(struct device *dev, 1695 + struct iio_dev *indio) 1696 + { 1697 + struct at91_adc_state *st = iio_priv(indio); 1698 + int ret; 1699 + 1700 + ret = devm_iio_triggered_buffer_setup(&indio->dev, indio, 1701 + &iio_pollfunc_store_time, 1702 + &at91_adc_trigger_handler, &at91_buffer_setup_ops); 1703 + if (ret < 0) { 1704 + dev_err(dev, "couldn't initialize the buffer.\n"); 1705 + return ret; 1706 + } 1707 + 1708 + if (!st->selected_trig->hw_trig) 1709 + return 0; 1710 + 1711 + iio_buffer_set_attrs(indio->buffer, at91_adc_fifo_attributes); 1712 + 1713 + st->trig = at91_adc_allocate_trigger(indio, st->selected_trig->name); 1714 + if (IS_ERR(st->trig)) { 1715 + dev_err(dev, "could not allocate trigger\n"); 1716 + return PTR_ERR(st->trig); 1717 + } 1718 + 1719 + /* 1720 + * Initially the iio buffer has a length of 2 and 1721 + * a watermark of 1 1722 + */ 1723 + st->dma_st.watermark = 1; 1724 + 1725 + return 0; 1726 + } 1727 + 1672 1728 static int at91_adc_probe(struct platform_device *pdev) 1673 1729 { 1674 1730 struct iio_dev *indio_dev; ··· 1838 1826 1839 1827 platform_set_drvdata(pdev, indio_dev); 1840 1828 1841 - ret = at91_adc_buffer_init(indio_dev); 1842 - if (ret < 0) { 1843 - dev_err(&pdev->dev, "couldn't initialize the buffer.\n"); 1829 + ret = at91_adc_buffer_and_trigger_init(&pdev->dev, indio_dev); 1830 + if (ret < 0) 1844 1831 goto per_clk_disable_unprepare; 1845 - } 1846 - 1847 - if (st->selected_trig->hw_trig) { 1848 - ret = at91_adc_trigger_init(indio_dev); 1849 - if (ret < 0) { 1850 - dev_err(&pdev->dev, "couldn't setup the triggers.\n"); 1851 - goto per_clk_disable_unprepare; 1852 - } 1853 - /* 1854 - * Initially the iio buffer has a length of 2 and 1855 - * a watermark of 1 1856 - */ 1857 - st->dma_st.watermark = 1; 1858 - 1859 - iio_buffer_set_attrs(indio_dev->buffer, 1860 - at91_adc_fifo_attributes); 1861 - } 1862 1832 1863 1833 if (dma_coerce_mask_and_coherent(&indio_dev->dev, DMA_BIT_MASK(32))) 1864 1834 dev_info(&pdev->dev, "cannot set DMA mask to 32-bit\n");