Linux-IIO Archive on lore.kernel.org
 help / Atom feed
* [PATCH 00/11] staging: iio: ad7606: Move out of staging
@ 2018-12-13 12:46 Stefan Popa
  2018-12-13 12:46 ` [PATCH 01/11] staging: iio: adc: ad7606: Simplify the Kconfing menu Stefan Popa
                   ` (10 more replies)
  0 siblings, 11 replies; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

This series attempts to clean up the driver according to the feedback
received during review and finally moves it out of staging.

Stefan Popa (11):
  staging: iio: adc: ad7606: Simplify the Kconfing menu
  staging: iio: adc: ad7606: Use SPDX identifier
  staging: iio: adc: ad7606: Use wait-for-completion handler
  staging: iio: adc: ad7606: Use devm functions in probe
  staging: iio: adc: ad7606: Add support for threaded irq
  staging: iio: adc: ad7606: Use find_closest() macro
  staging: iio: adc: ad7606: Use vendor prefix for DT properties
  staging: iio: adc: ad7606: Add OF device ID table
  staging: iio: adc: ad7606: Misc style fixes (no functional change)
  staging: iio: adc: ad7606: Move out of staging
  dt-bindings: iio: adc: Add docs for AD7606 ADC

 .../devicetree/bindings/iio/adc/adi,ad7606.txt     |  65 +++
 MAINTAINERS                                        |   8 +
 drivers/iio/adc/Kconfig                            |  28 +
 drivers/iio/adc/Makefile                           |   3 +
 drivers/iio/adc/ad7606.c                           | 588 +++++++++++++++++++++
 drivers/iio/adc/ad7606.h                           |  99 ++++
 drivers/iio/adc/ad7606_par.c                       | 105 ++++
 drivers/iio/adc/ad7606_spi.c                       |  82 +++
 drivers/staging/iio/adc/Kconfig                    |  34 --
 drivers/staging/iio/adc/Makefile                   |   4 -
 drivers/staging/iio/adc/ad7606.c                   | 563 --------------------
 drivers/staging/iio/adc/ad7606.h                   | 106 ----
 drivers/staging/iio/adc/ad7606_par.c               | 113 ----
 drivers/staging/iio/adc/ad7606_spi.c               |  79 ---
 14 files changed, 978 insertions(+), 899 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
 create mode 100644 drivers/iio/adc/ad7606.c
 create mode 100644 drivers/iio/adc/ad7606.h
 create mode 100644 drivers/iio/adc/ad7606_par.c
 create mode 100644 drivers/iio/adc/ad7606_spi.c
 delete mode 100644 drivers/staging/iio/adc/ad7606.c
 delete mode 100644 drivers/staging/iio/adc/ad7606.h
 delete mode 100644 drivers/staging/iio/adc/ad7606_par.c
 delete mode 100644 drivers/staging/iio/adc/ad7606_spi.c

-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 01/11] staging: iio: adc: ad7606: Simplify the Kconfing menu
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-13 15:37   ` Rob Herring
  2018-12-13 12:46 ` [PATCH 02/11] staging: iio: adc: ad7606: Use SPDX identifier Stefan Popa
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

There is no point in having three menu entries that can be selected
individually. Instead, the SPI and parallel interfaces should select
AD7606.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/staging/iio/adc/Kconfig | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index fc23059..af1bad8 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -4,35 +4,29 @@
 menu "Analog to digital converters"
 
 config AD7606
-	tristate "Analog Devices AD7606 ADC driver"
+	tristate
 	depends on GPIOLIB || COMPILE_TEST
 	depends on HAS_IOMEM
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
-	help
-	  Say yes here to build support for Analog Devices:
-	  ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called ad7606.
 
 config AD7606_IFACE_PARALLEL
-	tristate "parallel interface support"
-	depends on AD7606
+	tristate "Analog Devices AD7606 ADC driver with parallel interface support"
+	select AD7606
 	help
-	  Say yes here to include parallel interface support on the AD7606
-	  ADC driver.
+	  Say yes here to build parallel interface support for Analog Devices:
+	  ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called ad7606_parallel.
 
 config AD7606_IFACE_SPI
-	tristate "spi interface support"
-	depends on AD7606
+	tristate "Analog Devices AD7606 ADC driver with spi interface support"
 	depends on SPI
+	select AD7606
 	help
-	  Say yes here to include parallel interface support on the AD7606
-	  ADC driver.
+	  Say yes here to build spi interface support for Analog Devices:
+	  ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called ad7606_spi.
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 02/11] staging: iio: adc: ad7606: Use SPDX identifier
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
  2018-12-13 12:46 ` [PATCH 01/11] staging: iio: adc: ad7606: Simplify the Kconfing menu Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-13 13:21   ` Dan Carpenter
  2018-12-13 12:46 ` [PATCH 03/11] staging: iio: adc: ad7606: Use wait-for-completion handler Stefan Popa
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

This patch replaces the license text at the top of ad7606 driver files
and instead adds SPDX GPL-2.0+ license identifier.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/staging/iio/adc/ad7606.c     | 5 ++---
 drivers/staging/iio/adc/ad7606.h     | 3 +--
 drivers/staging/iio/adc/ad7606_par.c | 5 ++---
 drivers/staging/iio/adc/ad7606_spi.c | 5 ++---
 4 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 7308fa8..aa5ab1e 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * AD7606 SPI ADC driver
  *
  * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
  */
 
 #include <linux/interrupt.h>
@@ -560,4 +559,4 @@ EXPORT_SYMBOL_GPL(ad7606_pm_ops);
 
 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL v2");
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
index 8618805..e365fa0 100644
--- a/drivers/staging/iio/adc/ad7606.h
+++ b/drivers/staging/iio/adc/ad7606.h
@@ -1,9 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * AD7606 ADC driver
  *
  * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
  */
 
 #ifndef IIO_ADC_AD7606_H_
diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
index 8bd86e7..db2fede46 100644
--- a/drivers/staging/iio/adc/ad7606_par.c
+++ b/drivers/staging/iio/adc/ad7606_par.c
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * AD7606 Parallel Interface ADC driver
  *
  * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
  */
 
 #include <linux/module.h>
@@ -110,4 +109,4 @@ module_platform_driver(ad7606_driver);
 
 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL v2");
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
index b76ca5a..b6553ce 100644
--- a/drivers/staging/iio/adc/ad7606_spi.c
+++ b/drivers/staging/iio/adc/ad7606_spi.c
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * AD7606 SPI ADC driver
  *
  * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
  */
 
 #include <linux/module.h>
@@ -76,4 +75,4 @@ module_spi_driver(ad7606_driver);
 
 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL v2");
+MODULE_LICENSE("GPL");
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 03/11] staging: iio: adc: ad7606: Use wait-for-completion handler
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
  2018-12-13 12:46 ` [PATCH 01/11] staging: iio: adc: ad7606: Simplify the Kconfing menu Stefan Popa
  2018-12-13 12:46 ` [PATCH 02/11] staging: iio: adc: ad7606: Use SPDX identifier Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-16 13:41   ` Jonathan Cameron
  2018-12-13 12:46 ` [PATCH 04/11] staging: iio: adc: ad7606: Use devm functions in probe Stefan Popa
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

This patch replaces the use of wait_event_interruptible() with
wait_for_completion_timeout() when reading the result of a single
conversion. In this way, if the interrupt never occurs, the program will
not remain blocked.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/staging/iio/adc/ad7606.c | 14 +++++++-------
 drivers/staging/iio/adc/ad7606.h |  6 ++----
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index aa5ab1e..4b1bc20 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -118,12 +118,13 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
 	struct ad7606_state *st = iio_priv(indio_dev);
 	int ret;
 
-	st->done = false;
 	gpiod_set_value(st->gpio_convst, 1);
-
-	ret = wait_event_interruptible(st->wq_data_avail, st->done);
-	if (ret)
+	ret = wait_for_completion_timeout(&st->completion,
+					  msecs_to_jiffies(1000));
+	if (!ret) {
+		ret = -ETIMEDOUT;
 		goto error_ret;
+	}
 
 	ret = ad7606_read_samples(st);
 	if (ret == 0)
@@ -388,8 +389,7 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
 	if (iio_buffer_enabled(indio_dev)) {
 		schedule_work(&st->poll_work);
 	} else {
-		st->done = true;
-		wake_up_interruptible(&st->wq_data_avail);
+		complete(&st->completion);
 	}
 
 	return IRQ_HANDLED;
@@ -473,7 +473,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 	indio_dev->channels = st->chip_info->channels;
 	indio_dev->num_channels = st->chip_info->num_channels;
 
-	init_waitqueue_head(&st->wq_data_avail);
+	init_completion(&st->completion);
 
 	ret = ad7606_reset(st);
 	if (ret)
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
index e365fa0..cf20ca2 100644
--- a/drivers/staging/iio/adc/ad7606.h
+++ b/drivers/staging/iio/adc/ad7606.h
@@ -28,11 +28,9 @@ struct ad7606_chip_info {
  * @reg		regulator info for the the power supply of the device
  * @poll_work		work struct for continuously reading data from the device
  *			into an IIO triggered buffer
- * @wq_data_avail	wait queue struct for buffer mode
  * @bops		bus operations (SPI or parallel)
  * @range		voltage range selection, selects which scale to apply
  * @oversampling	oversampling selection
- * @done		marks whether reading data is done
  * @base_address	address from where to read data in parallel operation
  * @lock		protect sensor state from concurrent accesses to GPIOs
  * @gpio_convst	GPIO descriptor for conversion start signal (CONVST)
@@ -43,6 +41,7 @@ struct ad7606_chip_info {
  * @gpio_frstdata	GPIO descriptor for reading from device when data
  *			is being read on the first channel
  * @gpio_os		GPIO descriptors to control oversampling on the device
+ * @complete		completion to indicate end of conversion
  * @data		buffer for reading data from the device
  */
 
@@ -51,11 +50,9 @@ struct ad7606_state {
 	const struct ad7606_chip_info	*chip_info;
 	struct regulator		*reg;
 	struct work_struct		poll_work;
-	wait_queue_head_t		wq_data_avail;
 	const struct ad7606_bus_ops	*bops;
 	unsigned int			range;
 	unsigned int			oversampling;
-	bool				done;
 	void __iomem			*base_address;
 
 	struct mutex			lock; /* protect sensor state */
@@ -65,6 +62,7 @@ struct ad7606_state {
 	struct gpio_desc		*gpio_standby;
 	struct gpio_desc		*gpio_frstdata;
 	struct gpio_descs		*gpio_os;
+	struct completion		completion;
 
 	/*
 	 * DMA (thus cache coherency maintenance) requires the
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 04/11] staging: iio: adc: ad7606: Use devm functions in probe
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
                   ` (2 preceding siblings ...)
  2018-12-13 12:46 ` [PATCH 03/11] staging: iio: adc: ad7606: Use wait-for-completion handler Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-16 13:43   ` Jonathan Cameron
  2018-12-13 12:46 ` [PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq Stefan Popa
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

Switch to devm version of request_irq, iio_triggered_buffer_setup,
iio_device_register. To avoid potential ordering issues in probe,
devm_add_action_or_reset() is used for the regulator_disable(). This
simplifies the code and decreases the chance of bugs.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/staging/iio/adc/ad7606.c     | 59 +++++++++++++-----------------------
 drivers/staging/iio/adc/ad7606.h     |  1 -
 drivers/staging/iio/adc/ad7606_par.c |  6 ----
 drivers/staging/iio/adc/ad7606_spi.c |  6 ----
 4 files changed, 21 insertions(+), 51 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 4b1bc20..7191d51 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -417,6 +417,13 @@ static const struct iio_info ad7606_info_range = {
 	.attrs = &ad7606_attribute_group_range,
 };
 
+static void ad7606_regulator_disable(void *data)
+{
+	struct ad7606_state *st = data;
+
+	regulator_disable(st->reg);
+}
+
 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 		 const char *name, unsigned int id,
 		 const struct ad7606_bus_ops *bops)
@@ -430,6 +437,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
+	dev_set_drvdata(dev, indio_dev);
 
 	st->dev = dev;
 	mutex_init(&st->lock);
@@ -450,11 +458,15 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 		return ret;
 	}
 
+	ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
+	if (ret)
+		return ret;
+
 	st->chip_info = &ad7606_chip_info_tbl[id];
 
 	ret = ad7606_request_gpios(st);
 	if (ret)
-		goto error_disable_reg;
+		return ret;
 
 	indio_dev->dev.parent = dev;
 	if (st->gpio_os) {
@@ -479,50 +491,21 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 	if (ret)
 		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
 
-	ret = request_irq(irq, ad7606_interrupt, IRQF_TRIGGER_FALLING, name,
-			  indio_dev);
-	if (ret)
-		goto error_disable_reg;
-
-	ret = iio_triggered_buffer_setup(indio_dev, &ad7606_trigger_handler,
-					 NULL, NULL);
+	ret = devm_request_irq(dev, irq, ad7606_interrupt, IRQF_TRIGGER_FALLING,
+			       name, indio_dev);
 	if (ret)
-		goto error_free_irq;
+		return ret;
 
-	ret = iio_device_register(indio_dev);
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      &ad7606_trigger_handler,
+					      NULL, NULL);
 	if (ret)
-		goto error_unregister_ring;
-
-	dev_set_drvdata(dev, indio_dev);
-
-	return 0;
-error_unregister_ring:
-	iio_triggered_buffer_cleanup(indio_dev);
-
-error_free_irq:
-	free_irq(irq, indio_dev);
+		return ret;
 
-error_disable_reg:
-	regulator_disable(st->reg);
-	return ret;
+	return devm_iio_device_register(dev, indio_dev);
 }
 EXPORT_SYMBOL_GPL(ad7606_probe);
 
-int ad7606_remove(struct device *dev, int irq)
-{
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
-	iio_triggered_buffer_cleanup(indio_dev);
-
-	free_irq(irq, indio_dev);
-	regulator_disable(st->reg);
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(ad7606_remove);
-
 #ifdef CONFIG_PM_SLEEP
 
 static int ad7606_suspend(struct device *dev)
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
index cf20ca2..70486ef 100644
--- a/drivers/staging/iio/adc/ad7606.h
+++ b/drivers/staging/iio/adc/ad7606.h
@@ -84,7 +84,6 @@ struct ad7606_bus_ops {
 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 		 const char *name, unsigned int id,
 		 const struct ad7606_bus_ops *bops);
-int ad7606_remove(struct device *dev, int irq);
 
 enum ad7606_supported_device_ids {
 	ID_AD7605_4,
diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
index db2fede46..6269ee7 100644
--- a/drivers/staging/iio/adc/ad7606_par.c
+++ b/drivers/staging/iio/adc/ad7606_par.c
@@ -71,11 +71,6 @@ static int ad7606_par_probe(struct platform_device *pdev)
 			    &ad7606_par8_bops);
 }
 
-static int ad7606_par_remove(struct platform_device *pdev)
-{
-	return ad7606_remove(&pdev->dev, platform_get_irq(pdev, 0));
-}
-
 static const struct platform_device_id ad7606_driver_ids[] = {
 	{
 		.name		= "ad7605-4",
@@ -97,7 +92,6 @@ MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
 
 static struct platform_driver ad7606_driver = {
 	.probe = ad7606_par_probe,
-	.remove	= ad7606_par_remove,
 	.id_table = ad7606_driver_ids,
 	.driver = {
 		.name	 = "ad7606",
diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
index b6553ce..9291598 100644
--- a/drivers/staging/iio/adc/ad7606_spi.c
+++ b/drivers/staging/iio/adc/ad7606_spi.c
@@ -48,11 +48,6 @@ static int ad7606_spi_probe(struct spi_device *spi)
 			    &ad7606_spi_bops);
 }
 
-static int ad7606_spi_remove(struct spi_device *spi)
-{
-	return ad7606_remove(&spi->dev, spi->irq);
-}
-
 static const struct spi_device_id ad7606_id[] = {
 	{"ad7605-4", ID_AD7605_4},
 	{"ad7606-8", ID_AD7606_8},
@@ -68,7 +63,6 @@ static struct spi_driver ad7606_driver = {
 		.pm = AD7606_PM_OPS,
 	},
 	.probe = ad7606_spi_probe,
-	.remove = ad7606_spi_remove,
 	.id_table = ad7606_id,
 };
 module_spi_driver(ad7606_driver);
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
                   ` (3 preceding siblings ...)
  2018-12-13 12:46 ` [PATCH 04/11] staging: iio: adc: ad7606: Use devm functions in probe Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-13 13:28   ` Dan Carpenter
  2018-12-16 13:49   ` Jonathan Cameron
  2018-12-13 12:46 ` [PATCH 06/11] staging: iio: adc: ad7606: Use find_closest() macro Stefan Popa
                   ` (5 subsequent siblings)
  10 siblings, 2 replies; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

This patch replaces the use of a polling ring buffer with a threaded
interrupt.

Enabling the buffer sets the CONVST signal to high. When the rising edge
of the CONVST is applied, BUSY signal goes logic high and transitions low
at the end of the entire conversion process. The falling edge of the BUSY
signal triggers the interrupt.

ad7606_trigger_handler() is used as bottom half of the poll function.
It reads data from the device and stores it in the internal buffer.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/staging/iio/adc/ad7606.c | 116 +++++++++++++++++++++++++++++----------
 drivers/staging/iio/adc/ad7606.h |   6 +-
 2 files changed, 89 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 7191d51..13aeeec 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -21,6 +21,7 @@
 #include <linux/iio/sysfs.h>
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger_consumer.h>
+#include <linux/iio/trigger.h>
 #include <linux/iio/triggered_buffer.h>
 
 #include "ad7606.h"
@@ -81,36 +82,24 @@ static int ad7606_read_samples(struct ad7606_state *st)
 static irqreturn_t ad7606_trigger_handler(int irq, void *p)
 {
 	struct iio_poll_func *pf = p;
-	struct ad7606_state *st = iio_priv(pf->indio_dev);
-
-	gpiod_set_value(st->gpio_convst, 1);
-
-	return IRQ_HANDLED;
-}
-
-/**
- * ad7606_poll_bh_to_ring() bh of trigger launched polling to ring buffer
- * @work_s:	the work struct through which this was scheduled
- *
- * Currently there is no option in this driver to disable the saving of
- * timestamps within the ring.
- * I think the one copy of this at a time was to avoid problems if the
- * trigger was set far too high and the reads then locked up the computer.
- **/
-static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
-{
-	struct ad7606_state *st = container_of(work_s, struct ad7606_state,
-						poll_work);
-	struct iio_dev *indio_dev = iio_priv_to_dev(st);
+	struct iio_dev *indio_dev = pf->indio_dev;
+	struct ad7606_state *st = iio_priv(indio_dev);
 	int ret;
 
+	mutex_lock(&st->lock);
+
 	ret = ad7606_read_samples(st);
 	if (ret == 0)
 		iio_push_to_buffers_with_timestamp(indio_dev, st->data,
 						   iio_get_time_ns(indio_dev));
 
-	gpiod_set_value(st->gpio_convst, 0);
 	iio_trigger_notify_done(indio_dev->trig);
+	/* The rising edge of the CONVST signal starts a new conversion. */
+	gpiod_set_value(st->gpio_convst, 1);
+
+	mutex_unlock(&st->lock);
+
+	return IRQ_HANDLED;
 }
 
 static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
@@ -378,8 +367,11 @@ static int ad7606_request_gpios(struct ad7606_state *st)
 	return PTR_ERR_OR_ZERO(st->gpio_os);
 }
 
-/**
- *  Interrupt handler
+/*
+ * The BUSY signal indicates when conversions are in progress, so when a rising
+ * edge of CONVST is applied, BUSY goes logic high and transitions low at the
+ * end of the entire conversion process. The falling edge of the BUSY signal
+ * triggers this interrupt.
  */
 static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
 {
@@ -387,7 +379,8 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
 	struct ad7606_state *st = iio_priv(indio_dev);
 
 	if (iio_buffer_enabled(indio_dev)) {
-		schedule_work(&st->poll_work);
+		gpiod_set_value(st->gpio_convst, 0);
+		iio_trigger_poll_chained(st->trig);
 	} else {
 		complete(&st->completion);
 	}
@@ -395,26 +388,74 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 };
 
+static int ad7606_validate_trigger(struct iio_dev *indio_dev,
+				   struct iio_trigger *trig)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	if (st->trig != trig)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int ad7606_buffer_postenable(struct iio_dev *indio_dev)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	iio_triggered_buffer_postenable(indio_dev);
+	gpiod_set_value(st->gpio_convst, 1);
+
+	return 0;
+}
+
+static int ad7606_buffer_predisable(struct iio_dev *indio_dev)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+	int ret;
+
+	reinit_completion(&st->completion);
+	gpiod_set_value(st->gpio_convst, 1);
+	ret = wait_for_completion_timeout(&st->completion,
+					  msecs_to_jiffies(1000));
+	gpiod_set_value(st->gpio_convst, 0);
+
+	return iio_triggered_buffer_predisable(indio_dev);
+}
+
+static const struct iio_buffer_setup_ops ad7606_buffer_ops = {
+	.postenable = &ad7606_buffer_postenable,
+	.predisable = &ad7606_buffer_predisable,
+};
+
 static const struct iio_info ad7606_info_no_os_or_range = {
 	.read_raw = &ad7606_read_raw,
+	.validate_trigger = &ad7606_validate_trigger,
 };
 
 static const struct iio_info ad7606_info_os_and_range = {
 	.read_raw = &ad7606_read_raw,
 	.write_raw = &ad7606_write_raw,
 	.attrs = &ad7606_attribute_group_os_and_range,
+	.validate_trigger = &ad7606_validate_trigger,
 };
 
 static const struct iio_info ad7606_info_os = {
 	.read_raw = &ad7606_read_raw,
 	.write_raw = &ad7606_write_raw,
 	.attrs = &ad7606_attribute_group_os,
+	.validate_trigger = &ad7606_validate_trigger,
 };
 
 static const struct iio_info ad7606_info_range = {
 	.read_raw = &ad7606_read_raw,
 	.write_raw = &ad7606_write_raw,
 	.attrs = &ad7606_attribute_group_range,
+	.validate_trigger = &ad7606_validate_trigger,
+};
+
+static const struct iio_trigger_ops ad7606_trigger_ops = {
+	.validate_device = iio_trigger_validate_own_device,
 };
 
 static void ad7606_regulator_disable(void *data)
@@ -446,7 +487,6 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 	/* tied to logic low, analog input range is +/- 5V */
 	st->range = 0;
 	st->oversampling = 1;
-	INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring);
 
 	st->reg = devm_regulator_get(dev, "avcc");
 	if (IS_ERR(st->reg))
@@ -491,14 +531,32 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 	if (ret)
 		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
 
-	ret = devm_request_irq(dev, irq, ad7606_interrupt, IRQF_TRIGGER_FALLING,
-			       name, indio_dev);
+	st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
+					  indio_dev->name, indio_dev->id);
+	if (!st->trig)
+		return -ENOMEM;
+
+	st->trig->ops = &ad7606_trigger_ops;
+	st->trig->dev.parent = dev;
+	iio_trigger_set_drvdata(st->trig, indio_dev);
+	ret = devm_iio_trigger_register(dev, st->trig);
+	if (ret)
+		return ret;
+
+	indio_dev->trig = iio_trigger_get(st->trig);
+
+	ret = devm_request_threaded_irq(dev, irq,
+					NULL,
+					&ad7606_interrupt,
+					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+					name, indio_dev);
 	if (ret)
 		return ret;
 
 	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      &iio_pollfunc_store_time,
 					      &ad7606_trigger_handler,
-					      NULL, NULL);
+					      &ad7606_buffer_ops);
 	if (ret)
 		return ret;
 
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
index 70486ef..b238e9b 100644
--- a/drivers/staging/iio/adc/ad7606.h
+++ b/drivers/staging/iio/adc/ad7606.h
@@ -26,8 +26,6 @@ struct ad7606_chip_info {
  * @dev		pointer to kernel device
  * @chip_info		entry in the table of chips that describes this device
  * @reg		regulator info for the the power supply of the device
- * @poll_work		work struct for continuously reading data from the device
- *			into an IIO triggered buffer
  * @bops		bus operations (SPI or parallel)
  * @range		voltage range selection, selects which scale to apply
  * @oversampling	oversampling selection
@@ -42,14 +40,13 @@ struct ad7606_chip_info {
  *			is being read on the first channel
  * @gpio_os		GPIO descriptors to control oversampling on the device
  * @complete		completion to indicate end of conversion
+ * @trig		The IIO trigger associated with the device.
  * @data		buffer for reading data from the device
  */
-
 struct ad7606_state {
 	struct device			*dev;
 	const struct ad7606_chip_info	*chip_info;
 	struct regulator		*reg;
-	struct work_struct		poll_work;
 	const struct ad7606_bus_ops	*bops;
 	unsigned int			range;
 	unsigned int			oversampling;
@@ -62,6 +59,7 @@ struct ad7606_state {
 	struct gpio_desc		*gpio_standby;
 	struct gpio_desc		*gpio_frstdata;
 	struct gpio_descs		*gpio_os;
+	struct iio_trigger		*trig;
 	struct completion		completion;
 
 	/*
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 06/11] staging: iio: adc: ad7606: Use find_closest() macro
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
                   ` (4 preceding siblings ...)
  2018-12-13 12:46 ` [PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-16 13:51   ` Jonathan Cameron
  2018-12-13 12:46 ` [PATCH 07/11] staging: iio: adc: ad7606: Use vendor prefix for DT properties Stefan Popa
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

When looking for the available scale or oversampling ratio, it is better
to use the find_closest() macro. This simplifies the code and also does
not require an exact value to be entered from the user space.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/staging/iio/adc/ad7606.c | 58 +++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 13aeeec..0925379 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/sched.h>
 #include <linux/module.h>
+#include <linux/util_macros.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -30,8 +31,12 @@
  * Scales are computed as 5000/32768 and 10000/32768 respectively,
  * so that when applied to the raw values they provide mV values
  */
-static const unsigned int scale_avail[2][2] = {
-	{0, 152588}, {0, 305176}
+static const unsigned int scale_avail[2] = {
+	152588, 305176
+};
+
+static const unsigned int ad7606_oversampling_avail[7] = {
+	1, 2, 4, 8, 16, 32, 64,
 };
 
 static int ad7606_reset(struct ad7606_state *st)
@@ -148,8 +153,8 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
 		*val = (short)ret;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
-		*val = scale_avail[st->range][0];
-		*val2 = scale_avail[st->range][1];
+		*val = 0;
+		*val2 = scale_avail[st->range];
 		return IIO_VAL_INT_PLUS_MICRO;
 	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
 		*val = st->oversampling;
@@ -165,8 +170,8 @@ static ssize_t in_voltage_scale_available_show(struct device *dev,
 	int i, len = 0;
 
 	for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
-		len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06u ",
-				 scale_avail[i][0], scale_avail[i][1]);
+		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
+				 scale_avail[i]);
 
 	buf[len - 1] = '\n';
 
@@ -175,18 +180,6 @@ static ssize_t in_voltage_scale_available_show(struct device *dev,
 
 static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
 
-static int ad7606_oversampling_get_index(unsigned int val)
-{
-	unsigned char supported[] = {1, 2, 4, 8, 16, 32, 64};
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(supported); i++)
-		if (val == supported[i])
-			return i;
-
-	return -EINVAL;
-}
-
 static int ad7606_write_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
 			    int val,
@@ -195,36 +188,29 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
 {
 	struct ad7606_state *st = iio_priv(indio_dev);
 	DECLARE_BITMAP(values, 3);
-	int ret, i;
+	int i;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_SCALE:
-		ret = -EINVAL;
 		mutex_lock(&st->lock);
-		for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
-			if (val2 == scale_avail[i][1]) {
-				gpiod_set_value(st->gpio_range, i);
-				st->range = i;
-
-				ret = 0;
-				break;
-			}
+		i = find_closest(val2, scale_avail, ARRAY_SIZE(scale_avail));
+		gpiod_set_value(st->gpio_range, i);
+		st->range = i;
 		mutex_unlock(&st->lock);
 
-		return ret;
+		return 0;
 	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
 		if (val2)
 			return -EINVAL;
-		ret = ad7606_oversampling_get_index(val);
-		if (ret < 0)
-			return ret;
+		i = find_closest(val, ad7606_oversampling_avail,
+				 ARRAY_SIZE(ad7606_oversampling_avail));
 
-		values[0] = ret;
+		values[0] = i;
 
 		mutex_lock(&st->lock);
-		gpiod_set_array_value(3, st->gpio_os->desc, st->gpio_os->info,
-				      values);
-		st->oversampling = val;
+		gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
+				      st->gpio_os->info, values);
+		st->oversampling = ad7606_oversampling_avail[i];
 		mutex_unlock(&st->lock);
 
 		return 0;
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 07/11] staging: iio: adc: ad7606: Use vendor prefix for DT properties
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
                   ` (5 preceding siblings ...)
  2018-12-13 12:46 ` [PATCH 06/11] staging: iio: adc: ad7606: Use find_closest() macro Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-16 13:53   ` Jonathan Cameron
  2018-12-13 12:46 ` [PATCH 08/11] staging: iio: adc: ad7606: Add OF device ID table Stefan Popa
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

The 'adi' vendor prefix needs to be added to conversion-start, range,
first-data and oversampling-ratio properties.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/staging/iio/adc/ad7606.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 0925379..3355301 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -322,7 +322,7 @@ static int ad7606_request_gpios(struct ad7606_state *st)
 {
 	struct device *dev = st->dev;
 
-	st->gpio_convst = devm_gpiod_get(dev, "conversion-start",
+	st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start",
 					 GPIOD_OUT_LOW);
 	if (IS_ERR(st->gpio_convst))
 		return PTR_ERR(st->gpio_convst);
@@ -331,7 +331,8 @@ static int ad7606_request_gpios(struct ad7606_state *st)
 	if (IS_ERR(st->gpio_reset))
 		return PTR_ERR(st->gpio_reset);
 
-	st->gpio_range = devm_gpiod_get_optional(dev, "range", GPIOD_OUT_LOW);
+	st->gpio_range = devm_gpiod_get_optional(dev, "adi,range",
+						 GPIOD_OUT_LOW);
 	if (IS_ERR(st->gpio_range))
 		return PTR_ERR(st->gpio_range);
 
@@ -340,7 +341,7 @@ static int ad7606_request_gpios(struct ad7606_state *st)
 	if (IS_ERR(st->gpio_standby))
 		return PTR_ERR(st->gpio_standby);
 
-	st->gpio_frstdata = devm_gpiod_get_optional(dev, "first-data",
+	st->gpio_frstdata = devm_gpiod_get_optional(dev, "adi,first-data",
 						    GPIOD_IN);
 	if (IS_ERR(st->gpio_frstdata))
 		return PTR_ERR(st->gpio_frstdata);
@@ -348,7 +349,8 @@ static int ad7606_request_gpios(struct ad7606_state *st)
 	if (!st->chip_info->has_oversampling)
 		return 0;
 
-	st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio",
+	st->gpio_os = devm_gpiod_get_array_optional(dev,
+						    "adi,oversampling-ratio",
 						    GPIOD_OUT_LOW);
 	return PTR_ERR_OR_ZERO(st->gpio_os);
 }
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 08/11] staging: iio: adc: ad7606: Add OF device ID table
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
                   ` (6 preceding siblings ...)
  2018-12-13 12:46 ` [PATCH 07/11] staging: iio: adc: ad7606: Use vendor prefix for DT properties Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-16 13:54   ` Jonathan Cameron
  2018-12-13 12:46 ` [PATCH 09/11] staging: iio: adc: ad7606: Misc style fixes (no functional change) Stefan Popa
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

The driver does not have a struct of_device_id table, but supported
devices are registered via Device Trees. This patch adds and OF device
ID table.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/staging/iio/adc/ad7606_par.c | 10 ++++++++++
 drivers/staging/iio/adc/ad7606_spi.c | 10 ++++++++++
 2 files changed, 20 insertions(+)

diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
index 6269ee7..ac0c7b0 100644
--- a/drivers/staging/iio/adc/ad7606_par.c
+++ b/drivers/staging/iio/adc/ad7606_par.c
@@ -90,12 +90,22 @@ static const struct platform_device_id ad7606_driver_ids[] = {
 
 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
 
+static const struct of_device_id ad7606_of_match[] = {
+	{ .compatible = "adi,ad7605-4" },
+	{ .compatible = "adi,ad7606-4" },
+	{ .compatible = "adi,ad7606-6" },
+	{ .compatible = "adi,ad7606-8" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, ad7606_of_match);
+
 static struct platform_driver ad7606_driver = {
 	.probe = ad7606_par_probe,
 	.id_table = ad7606_driver_ids,
 	.driver = {
 		.name	 = "ad7606",
 		.pm	 = AD7606_PM_OPS,
+		.of_match_table = ad7606_of_match,
 	},
 };
 
diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
index 9291598..2608d34 100644
--- a/drivers/staging/iio/adc/ad7606_spi.c
+++ b/drivers/staging/iio/adc/ad7606_spi.c
@@ -57,9 +57,19 @@ static const struct spi_device_id ad7606_id[] = {
 };
 MODULE_DEVICE_TABLE(spi, ad7606_id);
 
+static const struct of_device_id ad7606_of_match[] = {
+	{ .compatible = "adi,ad7605-4" },
+	{ .compatible = "adi,ad7606-4" },
+	{ .compatible = "adi,ad7606-6" },
+	{ .compatible = "adi,ad7606-8" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, ad7606_of_match);
+
 static struct spi_driver ad7606_driver = {
 	.driver = {
 		.name = "ad7606",
+		.of_match_table = ad7606_of_match,
 		.pm = AD7606_PM_OPS,
 	},
 	.probe = ad7606_spi_probe,
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 09/11] staging: iio: adc: ad7606: Misc style fixes (no functional change)
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
                   ` (7 preceding siblings ...)
  2018-12-13 12:46 ` [PATCH 08/11] staging: iio: adc: ad7606: Add OF device ID table Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-16 13:56   ` Jonathan Cameron
  2018-12-13 12:46 ` [PATCH 10/11] staging: iio: adc: ad7606: Move out of staging Stefan Popa
  2018-12-13 12:46 ` [PATCH 11/11] dt-bindings: iio: adc: Add docs for AD7606 ADC Stefan Popa
  10 siblings, 1 reply; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

* Placed includes in alphabetical order
* Added brackets around num and mask through out for AD760X_CHANNEL
* Used single line comments where needed
* Removed extra lines and spaces

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 drivers/staging/iio/adc/ad7606.c     | 27 ++++++++++++---------------
 drivers/staging/iio/adc/ad7606.h     |  1 -
 drivers/staging/iio/adc/ad7606_par.c | 27 ++++++++-------------------
 drivers/staging/iio/adc/ad7606_spi.c | 16 ++++++++--------
 4 files changed, 28 insertions(+), 43 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 3355301..5733760 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -5,25 +5,25 @@
  * Copyright 2011 Analog Devices Inc.
  */
 
-#include <linux/interrupt.h>
+#include <linux/delay.h>
 #include <linux/device.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/sysfs.h>
-#include <linux/regulator/consumer.h>
 #include <linux/err.h>
 #include <linux/gpio/consumer.h>
-#include <linux/delay.h>
-#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/regulator/consumer.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/util_macros.h>
 
 #include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
 #include <linux/iio/buffer.h>
-#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/sysfs.h>
 #include <linux/iio/trigger.h>
 #include <linux/iio/triggered_buffer.h>
+#include <linux/iio/trigger_consumer.h>
 
 #include "ad7606.h"
 
@@ -249,8 +249,7 @@ static const struct attribute_group ad7606_attribute_group_range = {
 	.attrs = ad7606_attributes_range,
 };
 
-#define AD760X_CHANNEL(num, mask)				\
-	{							\
+#define AD760X_CHANNEL(num, mask) {				\
 		.type = IIO_VOLTAGE,				\
 		.indexed = 1,					\
 		.channel = num,					\
@@ -265,7 +264,7 @@ static const struct attribute_group ad7606_attribute_group_range = {
 			.storagebits = 16,			\
 			.endianness = IIO_CPU,			\
 		},						\
-	}
+}
 
 #define AD7605_CHANNEL(num)	\
 	AD760X_CHANNEL(num, 0)
@@ -294,9 +293,7 @@ static const struct iio_chan_spec ad7606_channels[] = {
 };
 
 static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
-	/*
-	 * More devices added in future
-	 */
+	/* More devices added in future */
 	[ID_AD7605_4] = {
 		.channels = ad7605_channels,
 		.num_channels = 5,
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
index b238e9b..40433af 100644
--- a/drivers/staging/iio/adc/ad7606.h
+++ b/drivers/staging/iio/adc/ad7606.h
@@ -14,7 +14,6 @@
  * @num_channels:	number of channels
  * @has_oversampling:   whether the device has oversampling support
  */
-
 struct ad7606_chip_info {
 	const struct iio_chan_spec	*channels;
 	unsigned int			num_channels;
diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
index ac0c7b0..32c7069 100644
--- a/drivers/staging/iio/adc/ad7606_par.c
+++ b/drivers/staging/iio/adc/ad7606_par.c
@@ -26,7 +26,7 @@ static int ad7606_par16_read_block(struct device *dev,
 }
 
 static const struct ad7606_bus_ops ad7606_par16_bops = {
-	.read_block	= ad7606_par16_read_block,
+	.read_block = ad7606_par16_read_block,
 };
 
 static int ad7606_par8_read_block(struct device *dev,
@@ -41,7 +41,7 @@ static int ad7606_par8_read_block(struct device *dev,
 }
 
 static const struct ad7606_bus_ops ad7606_par8_bops = {
-	.read_block	= ad7606_par8_read_block,
+	.read_block = ad7606_par8_read_block,
 };
 
 static int ad7606_par_probe(struct platform_device *pdev)
@@ -72,22 +72,12 @@ static int ad7606_par_probe(struct platform_device *pdev)
 }
 
 static const struct platform_device_id ad7606_driver_ids[] = {
-	{
-		.name		= "ad7605-4",
-		.driver_data	= ID_AD7605_4,
-	}, {
-		.name		= "ad7606-8",
-		.driver_data	= ID_AD7606_8,
-	}, {
-		.name		= "ad7606-6",
-		.driver_data	= ID_AD7606_6,
-	}, {
-		.name		= "ad7606-4",
-		.driver_data	= ID_AD7606_4,
-	},
+	{ .name	= "ad7605-4", .driver_data = ID_AD7605_4, },
+	{ .name	= "ad7606-4", .driver_data = ID_AD7606_4, },
+	{ .name	= "ad7606-6", .driver_data = ID_AD7606_6, },
+	{ .name	= "ad7606-8", .driver_data = ID_AD7606_8, },
 	{ }
 };
-
 MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
 
 static const struct of_device_id ad7606_of_match[] = {
@@ -103,12 +93,11 @@ static struct platform_driver ad7606_driver = {
 	.probe = ad7606_par_probe,
 	.id_table = ad7606_driver_ids,
 	.driver = {
-		.name	 = "ad7606",
-		.pm	 = AD7606_PM_OPS,
+		.name = "ad7606",
+		.pm = AD7606_PM_OPS,
 		.of_match_table = ad7606_of_match,
 	},
 };
-
 module_platform_driver(ad7606_driver);
 
 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
index 2608d34..b628389 100644
--- a/drivers/staging/iio/adc/ad7606_spi.c
+++ b/drivers/staging/iio/adc/ad7606_spi.c
@@ -36,7 +36,7 @@ static int ad7606_spi_read_block(struct device *dev,
 }
 
 static const struct ad7606_bus_ops ad7606_spi_bops = {
-	.read_block	= ad7606_spi_read_block,
+	.read_block = ad7606_spi_read_block,
 };
 
 static int ad7606_spi_probe(struct spi_device *spi)
@@ -48,14 +48,14 @@ static int ad7606_spi_probe(struct spi_device *spi)
 			    &ad7606_spi_bops);
 }
 
-static const struct spi_device_id ad7606_id[] = {
-	{"ad7605-4", ID_AD7605_4},
-	{"ad7606-8", ID_AD7606_8},
-	{"ad7606-6", ID_AD7606_6},
-	{"ad7606-4", ID_AD7606_4},
+static const struct spi_device_id ad7606_id_table[] = {
+	{ "ad7605-4", ID_AD7605_4 },
+	{ "ad7606-4", ID_AD7606_4 },
+	{ "ad7606-6", ID_AD7606_6 },
+	{ "ad7606-8", ID_AD7606_8 },
 	{}
 };
-MODULE_DEVICE_TABLE(spi, ad7606_id);
+MODULE_DEVICE_TABLE(spi, ad7606_id_table);
 
 static const struct of_device_id ad7606_of_match[] = {
 	{ .compatible = "adi,ad7605-4" },
@@ -73,7 +73,7 @@ static struct spi_driver ad7606_driver = {
 		.pm = AD7606_PM_OPS,
 	},
 	.probe = ad7606_spi_probe,
-	.id_table = ad7606_id,
+	.id_table = ad7606_id_table,
 };
 module_spi_driver(ad7606_driver);
 
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 10/11] staging: iio: adc: ad7606: Move out of staging
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
                   ` (8 preceding siblings ...)
  2018-12-13 12:46 ` [PATCH 09/11] staging: iio: adc: ad7606: Misc style fixes (no functional change) Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-16 14:14   ` Jonathan Cameron
  2018-12-20 19:45   ` kbuild test robot
  2018-12-13 12:46 ` [PATCH 11/11] dt-bindings: iio: adc: Add docs for AD7606 ADC Stefan Popa
  10 siblings, 2 replies; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

Move ad7606 ADC driver out of staging and into the mainline.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
---
 MAINTAINERS                          |   7 +
 drivers/iio/adc/Kconfig              |  28 ++
 drivers/iio/adc/Makefile             |   3 +
 drivers/iio/adc/ad7606.c             | 588 +++++++++++++++++++++++++++++++++++
 drivers/iio/adc/ad7606.h             |  99 ++++++
 drivers/iio/adc/ad7606_par.c         | 105 +++++++
 drivers/iio/adc/ad7606_spi.c         |  82 +++++
 drivers/staging/iio/adc/Kconfig      |  28 --
 drivers/staging/iio/adc/Makefile     |   4 -
 drivers/staging/iio/adc/ad7606.c     | 588 -----------------------------------
 drivers/staging/iio/adc/ad7606.h     |  99 ------
 drivers/staging/iio/adc/ad7606_par.c | 105 -------
 drivers/staging/iio/adc/ad7606_spi.c |  82 -----
 13 files changed, 912 insertions(+), 906 deletions(-)
 create mode 100644 drivers/iio/adc/ad7606.c
 create mode 100644 drivers/iio/adc/ad7606.h
 create mode 100644 drivers/iio/adc/ad7606_par.c
 create mode 100644 drivers/iio/adc/ad7606_spi.c
 delete mode 100644 drivers/staging/iio/adc/ad7606.c
 delete mode 100644 drivers/staging/iio/adc/ad7606.h
 delete mode 100644 drivers/staging/iio/adc/ad7606_par.c
 delete mode 100644 drivers/staging/iio/adc/ad7606_spi.c

diff --git a/MAINTAINERS b/MAINTAINERS
index d904229..7256ce6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -853,6 +853,13 @@ S:	Supported
 F:	drivers/iio/adc/ad7124.c
 F:	Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
 
+ANALOG DEVICES INC AD7606 DRIVER
+M:	Stefan Popa <stefan.popa@analog.com>
+L:	linux-iio@vger.kernel.org
+W:	http://ez.analog.com/community/linux-device-drivers
+S:	Supported
+F:	drivers/iio/adc/ad7606.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M:	Hans Verkuil <hans.verkuil@cisco.com>
 L:	linux-media@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index da9644b..9c0b50b 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -69,6 +69,34 @@ config AD7476
 	  To compile this driver as a module, choose M here: the
 	  module will be called ad7476.
 
+config AD7606
+	tristate
+	depends on GPIOLIB || COMPILE_TEST
+	depends on HAS_IOMEM
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+
+config AD7606_IFACE_PARALLEL
+	tristate "Analog Devices AD7606 ADC driver with parallel interface support"
+	select AD7606
+	help
+	  Say yes here to build parallel interface support for Analog Devices:
+	  ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ad7606_parallel.
+
+config AD7606_IFACE_SPI
+	tristate "Analog Devices AD7606 ADC driver with spi interface support"
+	depends on SPI
+	select AD7606
+	help
+	  Say yes here to build spi interface support for Analog Devices:
+	  ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ad7606_spi.
+
 config AD7766
 	tristate "Analog Devices AD7766/AD7767 ADC driver"
 	depends on SPI_MASTER
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 07df37f..ea50313 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -11,6 +11,9 @@ obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
 obj-$(CONFIG_AD7923) += ad7923.o
 obj-$(CONFIG_AD7476) += ad7476.o
+obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
+obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
+obj-$(CONFIG_AD7606) += ad7606.o
 obj-$(CONFIG_AD7766) += ad7766.o
 obj-$(CONFIG_AD7791) += ad7791.o
 obj-$(CONFIG_AD7793) += ad7793.o
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
new file mode 100644
index 0000000..5733760
--- /dev/null
+++ b/drivers/iio/adc/ad7606.c
@@ -0,0 +1,588 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7606 SPI ADC driver
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/regulator/consumer.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/sysfs.h>
+#include <linux/util_macros.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/iio/trigger_consumer.h>
+
+#include "ad7606.h"
+
+/*
+ * Scales are computed as 5000/32768 and 10000/32768 respectively,
+ * so that when applied to the raw values they provide mV values
+ */
+static const unsigned int scale_avail[2] = {
+	152588, 305176
+};
+
+static const unsigned int ad7606_oversampling_avail[7] = {
+	1, 2, 4, 8, 16, 32, 64,
+};
+
+static int ad7606_reset(struct ad7606_state *st)
+{
+	if (st->gpio_reset) {
+		gpiod_set_value(st->gpio_reset, 1);
+		ndelay(100); /* t_reset >= 100ns */
+		gpiod_set_value(st->gpio_reset, 0);
+		return 0;
+	}
+
+	return -ENODEV;
+}
+
+static int ad7606_read_samples(struct ad7606_state *st)
+{
+	unsigned int num = st->chip_info->num_channels;
+	u16 *data = st->data;
+	int ret;
+
+	/*
+	 * The frstdata signal is set to high while and after reading the sample
+	 * of the first channel and low for all other channels. This can be used
+	 * to check that the incoming data is correctly aligned. During normal
+	 * operation the data should never become unaligned, but some glitch or
+	 * electrostatic discharge might cause an extra read or clock cycle.
+	 * Monitoring the frstdata signal allows to recover from such failure
+	 * situations.
+	 */
+
+	if (st->gpio_frstdata) {
+		ret = st->bops->read_block(st->dev, 1, data);
+		if (ret)
+			return ret;
+
+		if (!gpiod_get_value(st->gpio_frstdata)) {
+			ad7606_reset(st);
+			return -EIO;
+		}
+
+		data++;
+		num--;
+	}
+
+	return st->bops->read_block(st->dev, num, data);
+}
+
+static irqreturn_t ad7606_trigger_handler(int irq, void *p)
+{
+	struct iio_poll_func *pf = p;
+	struct iio_dev *indio_dev = pf->indio_dev;
+	struct ad7606_state *st = iio_priv(indio_dev);
+	int ret;
+
+	mutex_lock(&st->lock);
+
+	ret = ad7606_read_samples(st);
+	if (ret == 0)
+		iio_push_to_buffers_with_timestamp(indio_dev, st->data,
+						   iio_get_time_ns(indio_dev));
+
+	iio_trigger_notify_done(indio_dev->trig);
+	/* The rising edge of the CONVST signal starts a new conversion. */
+	gpiod_set_value(st->gpio_convst, 1);
+
+	mutex_unlock(&st->lock);
+
+	return IRQ_HANDLED;
+}
+
+static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+	int ret;
+
+	gpiod_set_value(st->gpio_convst, 1);
+	ret = wait_for_completion_timeout(&st->completion,
+					  msecs_to_jiffies(1000));
+	if (!ret) {
+		ret = -ETIMEDOUT;
+		goto error_ret;
+	}
+
+	ret = ad7606_read_samples(st);
+	if (ret == 0)
+		ret = st->data[ch];
+
+error_ret:
+	gpiod_set_value(st->gpio_convst, 0);
+
+	return ret;
+}
+
+static int ad7606_read_raw(struct iio_dev *indio_dev,
+			   struct iio_chan_spec const *chan,
+			   int *val,
+			   int *val2,
+			   long m)
+{
+	int ret;
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	switch (m) {
+	case IIO_CHAN_INFO_RAW:
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			return ret;
+
+		ret = ad7606_scan_direct(indio_dev, chan->address);
+		iio_device_release_direct_mode(indio_dev);
+
+		if (ret < 0)
+			return ret;
+		*val = (short)ret;
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_SCALE:
+		*val = 0;
+		*val2 = scale_avail[st->range];
+		return IIO_VAL_INT_PLUS_MICRO;
+	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+		*val = st->oversampling;
+		return IIO_VAL_INT;
+	}
+	return -EINVAL;
+}
+
+static ssize_t in_voltage_scale_available_show(struct device *dev,
+					       struct device_attribute *attr,
+					       char *buf)
+{
+	int i, len = 0;
+
+	for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
+		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
+				 scale_avail[i]);
+
+	buf[len - 1] = '\n';
+
+	return len;
+}
+
+static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
+
+static int ad7606_write_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int val,
+			    int val2,
+			    long mask)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+	DECLARE_BITMAP(values, 3);
+	int i;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		mutex_lock(&st->lock);
+		i = find_closest(val2, scale_avail, ARRAY_SIZE(scale_avail));
+		gpiod_set_value(st->gpio_range, i);
+		st->range = i;
+		mutex_unlock(&st->lock);
+
+		return 0;
+	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+		if (val2)
+			return -EINVAL;
+		i = find_closest(val, ad7606_oversampling_avail,
+				 ARRAY_SIZE(ad7606_oversampling_avail));
+
+		values[0] = i;
+
+		mutex_lock(&st->lock);
+		gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
+				      st->gpio_os->info, values);
+		st->oversampling = ad7606_oversampling_avail[i];
+		mutex_unlock(&st->lock);
+
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
+static IIO_CONST_ATTR(oversampling_ratio_available, "1 2 4 8 16 32 64");
+
+static struct attribute *ad7606_attributes_os_and_range[] = {
+	&iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
+	&iio_const_attr_oversampling_ratio_available.dev_attr.attr,
+	NULL,
+};
+
+static const struct attribute_group ad7606_attribute_group_os_and_range = {
+	.attrs = ad7606_attributes_os_and_range,
+};
+
+static struct attribute *ad7606_attributes_os[] = {
+	&iio_const_attr_oversampling_ratio_available.dev_attr.attr,
+	NULL,
+};
+
+static const struct attribute_group ad7606_attribute_group_os = {
+	.attrs = ad7606_attributes_os,
+};
+
+static struct attribute *ad7606_attributes_range[] = {
+	&iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
+	NULL,
+};
+
+static const struct attribute_group ad7606_attribute_group_range = {
+	.attrs = ad7606_attributes_range,
+};
+
+#define AD760X_CHANNEL(num, mask) {				\
+		.type = IIO_VOLTAGE,				\
+		.indexed = 1,					\
+		.channel = num,					\
+		.address = num,					\
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
+		.info_mask_shared_by_all = mask,		\
+		.scan_index = num,				\
+		.scan_type = {					\
+			.sign = 's',				\
+			.realbits = 16,				\
+			.storagebits = 16,			\
+			.endianness = IIO_CPU,			\
+		},						\
+}
+
+#define AD7605_CHANNEL(num)	\
+	AD760X_CHANNEL(num, 0)
+
+#define AD7606_CHANNEL(num)	\
+	AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
+
+static const struct iio_chan_spec ad7605_channels[] = {
+	IIO_CHAN_SOFT_TIMESTAMP(4),
+	AD7605_CHANNEL(0),
+	AD7605_CHANNEL(1),
+	AD7605_CHANNEL(2),
+	AD7605_CHANNEL(3),
+};
+
+static const struct iio_chan_spec ad7606_channels[] = {
+	IIO_CHAN_SOFT_TIMESTAMP(8),
+	AD7606_CHANNEL(0),
+	AD7606_CHANNEL(1),
+	AD7606_CHANNEL(2),
+	AD7606_CHANNEL(3),
+	AD7606_CHANNEL(4),
+	AD7606_CHANNEL(5),
+	AD7606_CHANNEL(6),
+	AD7606_CHANNEL(7),
+};
+
+static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
+	/* More devices added in future */
+	[ID_AD7605_4] = {
+		.channels = ad7605_channels,
+		.num_channels = 5,
+	},
+	[ID_AD7606_8] = {
+		.channels = ad7606_channels,
+		.num_channels = 9,
+		.has_oversampling = true,
+	},
+	[ID_AD7606_6] = {
+		.channels = ad7606_channels,
+		.num_channels = 7,
+		.has_oversampling = true,
+	},
+	[ID_AD7606_4] = {
+		.channels = ad7606_channels,
+		.num_channels = 5,
+		.has_oversampling = true,
+	},
+};
+
+static int ad7606_request_gpios(struct ad7606_state *st)
+{
+	struct device *dev = st->dev;
+
+	st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start",
+					 GPIOD_OUT_LOW);
+	if (IS_ERR(st->gpio_convst))
+		return PTR_ERR(st->gpio_convst);
+
+	st->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(st->gpio_reset))
+		return PTR_ERR(st->gpio_reset);
+
+	st->gpio_range = devm_gpiod_get_optional(dev, "adi,range",
+						 GPIOD_OUT_LOW);
+	if (IS_ERR(st->gpio_range))
+		return PTR_ERR(st->gpio_range);
+
+	st->gpio_standby = devm_gpiod_get_optional(dev, "standby",
+						   GPIOD_OUT_HIGH);
+	if (IS_ERR(st->gpio_standby))
+		return PTR_ERR(st->gpio_standby);
+
+	st->gpio_frstdata = devm_gpiod_get_optional(dev, "adi,first-data",
+						    GPIOD_IN);
+	if (IS_ERR(st->gpio_frstdata))
+		return PTR_ERR(st->gpio_frstdata);
+
+	if (!st->chip_info->has_oversampling)
+		return 0;
+
+	st->gpio_os = devm_gpiod_get_array_optional(dev,
+						    "adi,oversampling-ratio",
+						    GPIOD_OUT_LOW);
+	return PTR_ERR_OR_ZERO(st->gpio_os);
+}
+
+/*
+ * The BUSY signal indicates when conversions are in progress, so when a rising
+ * edge of CONVST is applied, BUSY goes logic high and transitions low at the
+ * end of the entire conversion process. The falling edge of the BUSY signal
+ * triggers this interrupt.
+ */
+static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
+{
+	struct iio_dev *indio_dev = dev_id;
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	if (iio_buffer_enabled(indio_dev)) {
+		gpiod_set_value(st->gpio_convst, 0);
+		iio_trigger_poll_chained(st->trig);
+	} else {
+		complete(&st->completion);
+	}
+
+	return IRQ_HANDLED;
+};
+
+static int ad7606_validate_trigger(struct iio_dev *indio_dev,
+				   struct iio_trigger *trig)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	if (st->trig != trig)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int ad7606_buffer_postenable(struct iio_dev *indio_dev)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	iio_triggered_buffer_postenable(indio_dev);
+	gpiod_set_value(st->gpio_convst, 1);
+
+	return 0;
+}
+
+static int ad7606_buffer_predisable(struct iio_dev *indio_dev)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+	int ret;
+
+	reinit_completion(&st->completion);
+	gpiod_set_value(st->gpio_convst, 1);
+	ret = wait_for_completion_timeout(&st->completion,
+					  msecs_to_jiffies(1000));
+	gpiod_set_value(st->gpio_convst, 0);
+
+	return iio_triggered_buffer_predisable(indio_dev);
+}
+
+static const struct iio_buffer_setup_ops ad7606_buffer_ops = {
+	.postenable = &ad7606_buffer_postenable,
+	.predisable = &ad7606_buffer_predisable,
+};
+
+static const struct iio_info ad7606_info_no_os_or_range = {
+	.read_raw = &ad7606_read_raw,
+	.validate_trigger = &ad7606_validate_trigger,
+};
+
+static const struct iio_info ad7606_info_os_and_range = {
+	.read_raw = &ad7606_read_raw,
+	.write_raw = &ad7606_write_raw,
+	.attrs = &ad7606_attribute_group_os_and_range,
+	.validate_trigger = &ad7606_validate_trigger,
+};
+
+static const struct iio_info ad7606_info_os = {
+	.read_raw = &ad7606_read_raw,
+	.write_raw = &ad7606_write_raw,
+	.attrs = &ad7606_attribute_group_os,
+	.validate_trigger = &ad7606_validate_trigger,
+};
+
+static const struct iio_info ad7606_info_range = {
+	.read_raw = &ad7606_read_raw,
+	.write_raw = &ad7606_write_raw,
+	.attrs = &ad7606_attribute_group_range,
+	.validate_trigger = &ad7606_validate_trigger,
+};
+
+static const struct iio_trigger_ops ad7606_trigger_ops = {
+	.validate_device = iio_trigger_validate_own_device,
+};
+
+static void ad7606_regulator_disable(void *data)
+{
+	struct ad7606_state *st = data;
+
+	regulator_disable(st->reg);
+}
+
+int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
+		 const char *name, unsigned int id,
+		 const struct ad7606_bus_ops *bops)
+{
+	struct ad7606_state *st;
+	int ret;
+	struct iio_dev *indio_dev;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+	dev_set_drvdata(dev, indio_dev);
+
+	st->dev = dev;
+	mutex_init(&st->lock);
+	st->bops = bops;
+	st->base_address = base_address;
+	/* tied to logic low, analog input range is +/- 5V */
+	st->range = 0;
+	st->oversampling = 1;
+
+	st->reg = devm_regulator_get(dev, "avcc");
+	if (IS_ERR(st->reg))
+		return PTR_ERR(st->reg);
+
+	ret = regulator_enable(st->reg);
+	if (ret) {
+		dev_err(dev, "Failed to enable specified AVcc supply\n");
+		return ret;
+	}
+
+	ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
+	if (ret)
+		return ret;
+
+	st->chip_info = &ad7606_chip_info_tbl[id];
+
+	ret = ad7606_request_gpios(st);
+	if (ret)
+		return ret;
+
+	indio_dev->dev.parent = dev;
+	if (st->gpio_os) {
+		if (st->gpio_range)
+			indio_dev->info = &ad7606_info_os_and_range;
+		else
+			indio_dev->info = &ad7606_info_os;
+	} else {
+		if (st->gpio_range)
+			indio_dev->info = &ad7606_info_range;
+		else
+			indio_dev->info = &ad7606_info_no_os_or_range;
+	}
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->name = name;
+	indio_dev->channels = st->chip_info->channels;
+	indio_dev->num_channels = st->chip_info->num_channels;
+
+	init_completion(&st->completion);
+
+	ret = ad7606_reset(st);
+	if (ret)
+		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
+
+	st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
+					  indio_dev->name, indio_dev->id);
+	if (!st->trig)
+		return -ENOMEM;
+
+	st->trig->ops = &ad7606_trigger_ops;
+	st->trig->dev.parent = dev;
+	iio_trigger_set_drvdata(st->trig, indio_dev);
+	ret = devm_iio_trigger_register(dev, st->trig);
+	if (ret)
+		return ret;
+
+	indio_dev->trig = iio_trigger_get(st->trig);
+
+	ret = devm_request_threaded_irq(dev, irq,
+					NULL,
+					&ad7606_interrupt,
+					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+					name, indio_dev);
+	if (ret)
+		return ret;
+
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      &iio_pollfunc_store_time,
+					      &ad7606_trigger_handler,
+					      &ad7606_buffer_ops);
+	if (ret)
+		return ret;
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+EXPORT_SYMBOL_GPL(ad7606_probe);
+
+#ifdef CONFIG_PM_SLEEP
+
+static int ad7606_suspend(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	if (st->gpio_standby) {
+		gpiod_set_value(st->gpio_range, 1);
+		gpiod_set_value(st->gpio_standby, 0);
+	}
+
+	return 0;
+}
+
+static int ad7606_resume(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	if (st->gpio_standby) {
+		gpiod_set_value(st->gpio_range, st->range);
+		gpiod_set_value(st->gpio_standby, 1);
+		ad7606_reset(st);
+	}
+
+	return 0;
+}
+
+SIMPLE_DEV_PM_OPS(ad7606_pm_ops, ad7606_suspend, ad7606_resume);
+EXPORT_SYMBOL_GPL(ad7606_pm_ops);
+
+#endif
+
+MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
+MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
+MODULE_LICENSE("GPL");
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
new file mode 100644
index 0000000..40433af
--- /dev/null
+++ b/drivers/iio/adc/ad7606.h
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * AD7606 ADC driver
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#ifndef IIO_ADC_AD7606_H_
+#define IIO_ADC_AD7606_H_
+
+/**
+ * struct ad7606_chip_info - chip specific information
+ * @channels:		channel specification
+ * @num_channels:	number of channels
+ * @has_oversampling:   whether the device has oversampling support
+ */
+struct ad7606_chip_info {
+	const struct iio_chan_spec	*channels;
+	unsigned int			num_channels;
+	bool				has_oversampling;
+};
+
+/**
+ * struct ad7606_state - driver instance specific data
+ * @dev		pointer to kernel device
+ * @chip_info		entry in the table of chips that describes this device
+ * @reg		regulator info for the the power supply of the device
+ * @bops		bus operations (SPI or parallel)
+ * @range		voltage range selection, selects which scale to apply
+ * @oversampling	oversampling selection
+ * @base_address	address from where to read data in parallel operation
+ * @lock		protect sensor state from concurrent accesses to GPIOs
+ * @gpio_convst	GPIO descriptor for conversion start signal (CONVST)
+ * @gpio_reset		GPIO descriptor for device hard-reset
+ * @gpio_range		GPIO descriptor for range selection
+ * @gpio_standby	GPIO descriptor for stand-by signal (STBY),
+ *			controls power-down mode of device
+ * @gpio_frstdata	GPIO descriptor for reading from device when data
+ *			is being read on the first channel
+ * @gpio_os		GPIO descriptors to control oversampling on the device
+ * @complete		completion to indicate end of conversion
+ * @trig		The IIO trigger associated with the device.
+ * @data		buffer for reading data from the device
+ */
+struct ad7606_state {
+	struct device			*dev;
+	const struct ad7606_chip_info	*chip_info;
+	struct regulator		*reg;
+	const struct ad7606_bus_ops	*bops;
+	unsigned int			range;
+	unsigned int			oversampling;
+	void __iomem			*base_address;
+
+	struct mutex			lock; /* protect sensor state */
+	struct gpio_desc		*gpio_convst;
+	struct gpio_desc		*gpio_reset;
+	struct gpio_desc		*gpio_range;
+	struct gpio_desc		*gpio_standby;
+	struct gpio_desc		*gpio_frstdata;
+	struct gpio_descs		*gpio_os;
+	struct iio_trigger		*trig;
+	struct completion		completion;
+
+	/*
+	 * DMA (thus cache coherency maintenance) requires the
+	 * transfer buffers to live in their own cache lines.
+	 * 8 * 16-bit samples + 64-bit timestamp
+	 */
+	unsigned short			data[12] ____cacheline_aligned;
+};
+
+/**
+ * struct ad7606_bus_ops - driver bus operations
+ * @read_block		function pointer for reading blocks of data
+ */
+struct ad7606_bus_ops {
+	/* more methods added in future? */
+	int (*read_block)(struct device *dev, int num, void *data);
+};
+
+int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
+		 const char *name, unsigned int id,
+		 const struct ad7606_bus_ops *bops);
+
+enum ad7606_supported_device_ids {
+	ID_AD7605_4,
+	ID_AD7606_8,
+	ID_AD7606_6,
+	ID_AD7606_4
+};
+
+#ifdef CONFIG_PM_SLEEP
+extern const struct dev_pm_ops ad7606_pm_ops;
+#define AD7606_PM_OPS (&ad7606_pm_ops)
+#else
+#define AD7606_PM_OPS NULL
+#endif
+
+#endif /* IIO_ADC_AD7606_H_ */
diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c
new file mode 100644
index 0000000..32c7069
--- /dev/null
+++ b/drivers/iio/adc/ad7606_par.c
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7606 Parallel Interface ADC driver
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/types.h>
+#include <linux/err.h>
+#include <linux/io.h>
+
+#include <linux/iio/iio.h>
+#include "ad7606.h"
+
+static int ad7606_par16_read_block(struct device *dev,
+				   int count, void *buf)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	insw((unsigned long)st->base_address, buf, count);
+
+	return 0;
+}
+
+static const struct ad7606_bus_ops ad7606_par16_bops = {
+	.read_block = ad7606_par16_read_block,
+};
+
+static int ad7606_par8_read_block(struct device *dev,
+				  int count, void *buf)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	insb((unsigned long)st->base_address, buf, count * 2);
+
+	return 0;
+}
+
+static const struct ad7606_bus_ops ad7606_par8_bops = {
+	.read_block = ad7606_par8_read_block,
+};
+
+static int ad7606_par_probe(struct platform_device *pdev)
+{
+	const struct platform_device_id *id = platform_get_device_id(pdev);
+	struct resource *res;
+	void __iomem *addr;
+	resource_size_t remap_size;
+	int irq;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "no irq: %d\n", irq);
+		return irq;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	addr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(addr))
+		return PTR_ERR(addr);
+
+	remap_size = resource_size(res);
+
+	return ad7606_probe(&pdev->dev, irq, addr,
+			    id->name, id->driver_data,
+			    remap_size > 1 ? &ad7606_par16_bops :
+			    &ad7606_par8_bops);
+}
+
+static const struct platform_device_id ad7606_driver_ids[] = {
+	{ .name	= "ad7605-4", .driver_data = ID_AD7605_4, },
+	{ .name	= "ad7606-4", .driver_data = ID_AD7606_4, },
+	{ .name	= "ad7606-6", .driver_data = ID_AD7606_6, },
+	{ .name	= "ad7606-8", .driver_data = ID_AD7606_8, },
+	{ }
+};
+MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
+
+static const struct of_device_id ad7606_of_match[] = {
+	{ .compatible = "adi,ad7605-4" },
+	{ .compatible = "adi,ad7606-4" },
+	{ .compatible = "adi,ad7606-6" },
+	{ .compatible = "adi,ad7606-8" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, ad7606_of_match);
+
+static struct platform_driver ad7606_driver = {
+	.probe = ad7606_par_probe,
+	.id_table = ad7606_driver_ids,
+	.driver = {
+		.name = "ad7606",
+		.pm = AD7606_PM_OPS,
+		.of_match_table = ad7606_of_match,
+	},
+};
+module_platform_driver(ad7606_driver);
+
+MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
+MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
+MODULE_LICENSE("GPL");
diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
new file mode 100644
index 0000000..b628389
--- /dev/null
+++ b/drivers/iio/adc/ad7606_spi.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7606 SPI ADC driver
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#include <linux/module.h>
+#include <linux/spi/spi.h>
+#include <linux/types.h>
+#include <linux/err.h>
+
+#include <linux/iio/iio.h>
+#include "ad7606.h"
+
+#define MAX_SPI_FREQ_HZ		23500000	/* VDRIVE above 4.75 V */
+
+static int ad7606_spi_read_block(struct device *dev,
+				 int count, void *buf)
+{
+	struct spi_device *spi = to_spi_device(dev);
+	int i, ret;
+	unsigned short *data = buf;
+	__be16 *bdata = buf;
+
+	ret = spi_read(spi, buf, count * 2);
+	if (ret < 0) {
+		dev_err(&spi->dev, "SPI read error\n");
+		return ret;
+	}
+
+	for (i = 0; i < count; i++)
+		data[i] = be16_to_cpu(bdata[i]);
+
+	return 0;
+}
+
+static const struct ad7606_bus_ops ad7606_spi_bops = {
+	.read_block = ad7606_spi_read_block,
+};
+
+static int ad7606_spi_probe(struct spi_device *spi)
+{
+	const struct spi_device_id *id = spi_get_device_id(spi);
+
+	return ad7606_probe(&spi->dev, spi->irq, NULL,
+			    id->name, id->driver_data,
+			    &ad7606_spi_bops);
+}
+
+static const struct spi_device_id ad7606_id_table[] = {
+	{ "ad7605-4", ID_AD7605_4 },
+	{ "ad7606-4", ID_AD7606_4 },
+	{ "ad7606-6", ID_AD7606_6 },
+	{ "ad7606-8", ID_AD7606_8 },
+	{}
+};
+MODULE_DEVICE_TABLE(spi, ad7606_id_table);
+
+static const struct of_device_id ad7606_of_match[] = {
+	{ .compatible = "adi,ad7605-4" },
+	{ .compatible = "adi,ad7606-4" },
+	{ .compatible = "adi,ad7606-6" },
+	{ .compatible = "adi,ad7606-8" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, ad7606_of_match);
+
+static struct spi_driver ad7606_driver = {
+	.driver = {
+		.name = "ad7606",
+		.of_match_table = ad7606_of_match,
+		.pm = AD7606_PM_OPS,
+	},
+	.probe = ad7606_spi_probe,
+	.id_table = ad7606_id_table,
+};
+module_spi_driver(ad7606_driver);
+
+MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
+MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index af1bad8..7a93d3a 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -3,34 +3,6 @@
 #
 menu "Analog to digital converters"
 
-config AD7606
-	tristate
-	depends on GPIOLIB || COMPILE_TEST
-	depends on HAS_IOMEM
-	select IIO_BUFFER
-	select IIO_TRIGGERED_BUFFER
-
-config AD7606_IFACE_PARALLEL
-	tristate "Analog Devices AD7606 ADC driver with parallel interface support"
-	select AD7606
-	help
-	  Say yes here to build parallel interface support for Analog Devices:
-	  ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called ad7606_parallel.
-
-config AD7606_IFACE_SPI
-	tristate "Analog Devices AD7606 ADC driver with spi interface support"
-	depends on SPI
-	select AD7606
-	help
-	  Say yes here to build spi interface support for Analog Devices:
-	  ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called ad7606_spi.
-
 config AD7780
 	tristate "Analog Devices AD7780 and similar ADCs driver"
 	depends on SPI
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index ebe83c1..7a42108 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -3,10 +3,6 @@
 # Makefile for industrial I/O ADC drivers
 #
 
-obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
-obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
-obj-$(CONFIG_AD7606) += ad7606.o
-
 obj-$(CONFIG_AD7780) += ad7780.o
 obj-$(CONFIG_AD7816) += ad7816.o
 obj-$(CONFIG_AD7192) += ad7192.o
diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
deleted file mode 100644
index 5733760..0000000
--- a/drivers/staging/iio/adc/ad7606.c
+++ /dev/null
@@ -1,588 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * AD7606 SPI ADC driver
- *
- * Copyright 2011 Analog Devices Inc.
- */
-
-#include <linux/delay.h>
-#include <linux/device.h>
-#include <linux/err.h>
-#include <linux/gpio/consumer.h>
-#include <linux/interrupt.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/regulator/consumer.h>
-#include <linux/sched.h>
-#include <linux/slab.h>
-#include <linux/sysfs.h>
-#include <linux/util_macros.h>
-
-#include <linux/iio/iio.h>
-#include <linux/iio/buffer.h>
-#include <linux/iio/sysfs.h>
-#include <linux/iio/trigger.h>
-#include <linux/iio/triggered_buffer.h>
-#include <linux/iio/trigger_consumer.h>
-
-#include "ad7606.h"
-
-/*
- * Scales are computed as 5000/32768 and 10000/32768 respectively,
- * so that when applied to the raw values they provide mV values
- */
-static const unsigned int scale_avail[2] = {
-	152588, 305176
-};
-
-static const unsigned int ad7606_oversampling_avail[7] = {
-	1, 2, 4, 8, 16, 32, 64,
-};
-
-static int ad7606_reset(struct ad7606_state *st)
-{
-	if (st->gpio_reset) {
-		gpiod_set_value(st->gpio_reset, 1);
-		ndelay(100); /* t_reset >= 100ns */
-		gpiod_set_value(st->gpio_reset, 0);
-		return 0;
-	}
-
-	return -ENODEV;
-}
-
-static int ad7606_read_samples(struct ad7606_state *st)
-{
-	unsigned int num = st->chip_info->num_channels;
-	u16 *data = st->data;
-	int ret;
-
-	/*
-	 * The frstdata signal is set to high while and after reading the sample
-	 * of the first channel and low for all other channels. This can be used
-	 * to check that the incoming data is correctly aligned. During normal
-	 * operation the data should never become unaligned, but some glitch or
-	 * electrostatic discharge might cause an extra read or clock cycle.
-	 * Monitoring the frstdata signal allows to recover from such failure
-	 * situations.
-	 */
-
-	if (st->gpio_frstdata) {
-		ret = st->bops->read_block(st->dev, 1, data);
-		if (ret)
-			return ret;
-
-		if (!gpiod_get_value(st->gpio_frstdata)) {
-			ad7606_reset(st);
-			return -EIO;
-		}
-
-		data++;
-		num--;
-	}
-
-	return st->bops->read_block(st->dev, num, data);
-}
-
-static irqreturn_t ad7606_trigger_handler(int irq, void *p)
-{
-	struct iio_poll_func *pf = p;
-	struct iio_dev *indio_dev = pf->indio_dev;
-	struct ad7606_state *st = iio_priv(indio_dev);
-	int ret;
-
-	mutex_lock(&st->lock);
-
-	ret = ad7606_read_samples(st);
-	if (ret == 0)
-		iio_push_to_buffers_with_timestamp(indio_dev, st->data,
-						   iio_get_time_ns(indio_dev));
-
-	iio_trigger_notify_done(indio_dev->trig);
-	/* The rising edge of the CONVST signal starts a new conversion. */
-	gpiod_set_value(st->gpio_convst, 1);
-
-	mutex_unlock(&st->lock);
-
-	return IRQ_HANDLED;
-}
-
-static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
-{
-	struct ad7606_state *st = iio_priv(indio_dev);
-	int ret;
-
-	gpiod_set_value(st->gpio_convst, 1);
-	ret = wait_for_completion_timeout(&st->completion,
-					  msecs_to_jiffies(1000));
-	if (!ret) {
-		ret = -ETIMEDOUT;
-		goto error_ret;
-	}
-
-	ret = ad7606_read_samples(st);
-	if (ret == 0)
-		ret = st->data[ch];
-
-error_ret:
-	gpiod_set_value(st->gpio_convst, 0);
-
-	return ret;
-}
-
-static int ad7606_read_raw(struct iio_dev *indio_dev,
-			   struct iio_chan_spec const *chan,
-			   int *val,
-			   int *val2,
-			   long m)
-{
-	int ret;
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	switch (m) {
-	case IIO_CHAN_INFO_RAW:
-		ret = iio_device_claim_direct_mode(indio_dev);
-		if (ret)
-			return ret;
-
-		ret = ad7606_scan_direct(indio_dev, chan->address);
-		iio_device_release_direct_mode(indio_dev);
-
-		if (ret < 0)
-			return ret;
-		*val = (short)ret;
-		return IIO_VAL_INT;
-	case IIO_CHAN_INFO_SCALE:
-		*val = 0;
-		*val2 = scale_avail[st->range];
-		return IIO_VAL_INT_PLUS_MICRO;
-	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
-		*val = st->oversampling;
-		return IIO_VAL_INT;
-	}
-	return -EINVAL;
-}
-
-static ssize_t in_voltage_scale_available_show(struct device *dev,
-					       struct device_attribute *attr,
-					       char *buf)
-{
-	int i, len = 0;
-
-	for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
-		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
-				 scale_avail[i]);
-
-	buf[len - 1] = '\n';
-
-	return len;
-}
-
-static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
-
-static int ad7606_write_raw(struct iio_dev *indio_dev,
-			    struct iio_chan_spec const *chan,
-			    int val,
-			    int val2,
-			    long mask)
-{
-	struct ad7606_state *st = iio_priv(indio_dev);
-	DECLARE_BITMAP(values, 3);
-	int i;
-
-	switch (mask) {
-	case IIO_CHAN_INFO_SCALE:
-		mutex_lock(&st->lock);
-		i = find_closest(val2, scale_avail, ARRAY_SIZE(scale_avail));
-		gpiod_set_value(st->gpio_range, i);
-		st->range = i;
-		mutex_unlock(&st->lock);
-
-		return 0;
-	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
-		if (val2)
-			return -EINVAL;
-		i = find_closest(val, ad7606_oversampling_avail,
-				 ARRAY_SIZE(ad7606_oversampling_avail));
-
-		values[0] = i;
-
-		mutex_lock(&st->lock);
-		gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
-				      st->gpio_os->info, values);
-		st->oversampling = ad7606_oversampling_avail[i];
-		mutex_unlock(&st->lock);
-
-		return 0;
-	default:
-		return -EINVAL;
-	}
-}
-
-static IIO_CONST_ATTR(oversampling_ratio_available, "1 2 4 8 16 32 64");
-
-static struct attribute *ad7606_attributes_os_and_range[] = {
-	&iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
-	&iio_const_attr_oversampling_ratio_available.dev_attr.attr,
-	NULL,
-};
-
-static const struct attribute_group ad7606_attribute_group_os_and_range = {
-	.attrs = ad7606_attributes_os_and_range,
-};
-
-static struct attribute *ad7606_attributes_os[] = {
-	&iio_const_attr_oversampling_ratio_available.dev_attr.attr,
-	NULL,
-};
-
-static const struct attribute_group ad7606_attribute_group_os = {
-	.attrs = ad7606_attributes_os,
-};
-
-static struct attribute *ad7606_attributes_range[] = {
-	&iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
-	NULL,
-};
-
-static const struct attribute_group ad7606_attribute_group_range = {
-	.attrs = ad7606_attributes_range,
-};
-
-#define AD760X_CHANNEL(num, mask) {				\
-		.type = IIO_VOLTAGE,				\
-		.indexed = 1,					\
-		.channel = num,					\
-		.address = num,					\
-		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
-		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
-		.info_mask_shared_by_all = mask,		\
-		.scan_index = num,				\
-		.scan_type = {					\
-			.sign = 's',				\
-			.realbits = 16,				\
-			.storagebits = 16,			\
-			.endianness = IIO_CPU,			\
-		},						\
-}
-
-#define AD7605_CHANNEL(num)	\
-	AD760X_CHANNEL(num, 0)
-
-#define AD7606_CHANNEL(num)	\
-	AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
-
-static const struct iio_chan_spec ad7605_channels[] = {
-	IIO_CHAN_SOFT_TIMESTAMP(4),
-	AD7605_CHANNEL(0),
-	AD7605_CHANNEL(1),
-	AD7605_CHANNEL(2),
-	AD7605_CHANNEL(3),
-};
-
-static const struct iio_chan_spec ad7606_channels[] = {
-	IIO_CHAN_SOFT_TIMESTAMP(8),
-	AD7606_CHANNEL(0),
-	AD7606_CHANNEL(1),
-	AD7606_CHANNEL(2),
-	AD7606_CHANNEL(3),
-	AD7606_CHANNEL(4),
-	AD7606_CHANNEL(5),
-	AD7606_CHANNEL(6),
-	AD7606_CHANNEL(7),
-};
-
-static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
-	/* More devices added in future */
-	[ID_AD7605_4] = {
-		.channels = ad7605_channels,
-		.num_channels = 5,
-	},
-	[ID_AD7606_8] = {
-		.channels = ad7606_channels,
-		.num_channels = 9,
-		.has_oversampling = true,
-	},
-	[ID_AD7606_6] = {
-		.channels = ad7606_channels,
-		.num_channels = 7,
-		.has_oversampling = true,
-	},
-	[ID_AD7606_4] = {
-		.channels = ad7606_channels,
-		.num_channels = 5,
-		.has_oversampling = true,
-	},
-};
-
-static int ad7606_request_gpios(struct ad7606_state *st)
-{
-	struct device *dev = st->dev;
-
-	st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start",
-					 GPIOD_OUT_LOW);
-	if (IS_ERR(st->gpio_convst))
-		return PTR_ERR(st->gpio_convst);
-
-	st->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
-	if (IS_ERR(st->gpio_reset))
-		return PTR_ERR(st->gpio_reset);
-
-	st->gpio_range = devm_gpiod_get_optional(dev, "adi,range",
-						 GPIOD_OUT_LOW);
-	if (IS_ERR(st->gpio_range))
-		return PTR_ERR(st->gpio_range);
-
-	st->gpio_standby = devm_gpiod_get_optional(dev, "standby",
-						   GPIOD_OUT_HIGH);
-	if (IS_ERR(st->gpio_standby))
-		return PTR_ERR(st->gpio_standby);
-
-	st->gpio_frstdata = devm_gpiod_get_optional(dev, "adi,first-data",
-						    GPIOD_IN);
-	if (IS_ERR(st->gpio_frstdata))
-		return PTR_ERR(st->gpio_frstdata);
-
-	if (!st->chip_info->has_oversampling)
-		return 0;
-
-	st->gpio_os = devm_gpiod_get_array_optional(dev,
-						    "adi,oversampling-ratio",
-						    GPIOD_OUT_LOW);
-	return PTR_ERR_OR_ZERO(st->gpio_os);
-}
-
-/*
- * The BUSY signal indicates when conversions are in progress, so when a rising
- * edge of CONVST is applied, BUSY goes logic high and transitions low at the
- * end of the entire conversion process. The falling edge of the BUSY signal
- * triggers this interrupt.
- */
-static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
-{
-	struct iio_dev *indio_dev = dev_id;
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	if (iio_buffer_enabled(indio_dev)) {
-		gpiod_set_value(st->gpio_convst, 0);
-		iio_trigger_poll_chained(st->trig);
-	} else {
-		complete(&st->completion);
-	}
-
-	return IRQ_HANDLED;
-};
-
-static int ad7606_validate_trigger(struct iio_dev *indio_dev,
-				   struct iio_trigger *trig)
-{
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	if (st->trig != trig)
-		return -EINVAL;
-
-	return 0;
-}
-
-static int ad7606_buffer_postenable(struct iio_dev *indio_dev)
-{
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	iio_triggered_buffer_postenable(indio_dev);
-	gpiod_set_value(st->gpio_convst, 1);
-
-	return 0;
-}
-
-static int ad7606_buffer_predisable(struct iio_dev *indio_dev)
-{
-	struct ad7606_state *st = iio_priv(indio_dev);
-	int ret;
-
-	reinit_completion(&st->completion);
-	gpiod_set_value(st->gpio_convst, 1);
-	ret = wait_for_completion_timeout(&st->completion,
-					  msecs_to_jiffies(1000));
-	gpiod_set_value(st->gpio_convst, 0);
-
-	return iio_triggered_buffer_predisable(indio_dev);
-}
-
-static const struct iio_buffer_setup_ops ad7606_buffer_ops = {
-	.postenable = &ad7606_buffer_postenable,
-	.predisable = &ad7606_buffer_predisable,
-};
-
-static const struct iio_info ad7606_info_no_os_or_range = {
-	.read_raw = &ad7606_read_raw,
-	.validate_trigger = &ad7606_validate_trigger,
-};
-
-static const struct iio_info ad7606_info_os_and_range = {
-	.read_raw = &ad7606_read_raw,
-	.write_raw = &ad7606_write_raw,
-	.attrs = &ad7606_attribute_group_os_and_range,
-	.validate_trigger = &ad7606_validate_trigger,
-};
-
-static const struct iio_info ad7606_info_os = {
-	.read_raw = &ad7606_read_raw,
-	.write_raw = &ad7606_write_raw,
-	.attrs = &ad7606_attribute_group_os,
-	.validate_trigger = &ad7606_validate_trigger,
-};
-
-static const struct iio_info ad7606_info_range = {
-	.read_raw = &ad7606_read_raw,
-	.write_raw = &ad7606_write_raw,
-	.attrs = &ad7606_attribute_group_range,
-	.validate_trigger = &ad7606_validate_trigger,
-};
-
-static const struct iio_trigger_ops ad7606_trigger_ops = {
-	.validate_device = iio_trigger_validate_own_device,
-};
-
-static void ad7606_regulator_disable(void *data)
-{
-	struct ad7606_state *st = data;
-
-	regulator_disable(st->reg);
-}
-
-int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
-		 const char *name, unsigned int id,
-		 const struct ad7606_bus_ops *bops)
-{
-	struct ad7606_state *st;
-	int ret;
-	struct iio_dev *indio_dev;
-
-	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
-	if (!indio_dev)
-		return -ENOMEM;
-
-	st = iio_priv(indio_dev);
-	dev_set_drvdata(dev, indio_dev);
-
-	st->dev = dev;
-	mutex_init(&st->lock);
-	st->bops = bops;
-	st->base_address = base_address;
-	/* tied to logic low, analog input range is +/- 5V */
-	st->range = 0;
-	st->oversampling = 1;
-
-	st->reg = devm_regulator_get(dev, "avcc");
-	if (IS_ERR(st->reg))
-		return PTR_ERR(st->reg);
-
-	ret = regulator_enable(st->reg);
-	if (ret) {
-		dev_err(dev, "Failed to enable specified AVcc supply\n");
-		return ret;
-	}
-
-	ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
-	if (ret)
-		return ret;
-
-	st->chip_info = &ad7606_chip_info_tbl[id];
-
-	ret = ad7606_request_gpios(st);
-	if (ret)
-		return ret;
-
-	indio_dev->dev.parent = dev;
-	if (st->gpio_os) {
-		if (st->gpio_range)
-			indio_dev->info = &ad7606_info_os_and_range;
-		else
-			indio_dev->info = &ad7606_info_os;
-	} else {
-		if (st->gpio_range)
-			indio_dev->info = &ad7606_info_range;
-		else
-			indio_dev->info = &ad7606_info_no_os_or_range;
-	}
-	indio_dev->modes = INDIO_DIRECT_MODE;
-	indio_dev->name = name;
-	indio_dev->channels = st->chip_info->channels;
-	indio_dev->num_channels = st->chip_info->num_channels;
-
-	init_completion(&st->completion);
-
-	ret = ad7606_reset(st);
-	if (ret)
-		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
-
-	st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
-					  indio_dev->name, indio_dev->id);
-	if (!st->trig)
-		return -ENOMEM;
-
-	st->trig->ops = &ad7606_trigger_ops;
-	st->trig->dev.parent = dev;
-	iio_trigger_set_drvdata(st->trig, indio_dev);
-	ret = devm_iio_trigger_register(dev, st->trig);
-	if (ret)
-		return ret;
-
-	indio_dev->trig = iio_trigger_get(st->trig);
-
-	ret = devm_request_threaded_irq(dev, irq,
-					NULL,
-					&ad7606_interrupt,
-					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
-					name, indio_dev);
-	if (ret)
-		return ret;
-
-	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
-					      &iio_pollfunc_store_time,
-					      &ad7606_trigger_handler,
-					      &ad7606_buffer_ops);
-	if (ret)
-		return ret;
-
-	return devm_iio_device_register(dev, indio_dev);
-}
-EXPORT_SYMBOL_GPL(ad7606_probe);
-
-#ifdef CONFIG_PM_SLEEP
-
-static int ad7606_suspend(struct device *dev)
-{
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	if (st->gpio_standby) {
-		gpiod_set_value(st->gpio_range, 1);
-		gpiod_set_value(st->gpio_standby, 0);
-	}
-
-	return 0;
-}
-
-static int ad7606_resume(struct device *dev)
-{
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	if (st->gpio_standby) {
-		gpiod_set_value(st->gpio_range, st->range);
-		gpiod_set_value(st->gpio_standby, 1);
-		ad7606_reset(st);
-	}
-
-	return 0;
-}
-
-SIMPLE_DEV_PM_OPS(ad7606_pm_ops, ad7606_suspend, ad7606_resume);
-EXPORT_SYMBOL_GPL(ad7606_pm_ops);
-
-#endif
-
-MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
-MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
deleted file mode 100644
index 40433af..0000000
--- a/drivers/staging/iio/adc/ad7606.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * AD7606 ADC driver
- *
- * Copyright 2011 Analog Devices Inc.
- */
-
-#ifndef IIO_ADC_AD7606_H_
-#define IIO_ADC_AD7606_H_
-
-/**
- * struct ad7606_chip_info - chip specific information
- * @channels:		channel specification
- * @num_channels:	number of channels
- * @has_oversampling:   whether the device has oversampling support
- */
-struct ad7606_chip_info {
-	const struct iio_chan_spec	*channels;
-	unsigned int			num_channels;
-	bool				has_oversampling;
-};
-
-/**
- * struct ad7606_state - driver instance specific data
- * @dev		pointer to kernel device
- * @chip_info		entry in the table of chips that describes this device
- * @reg		regulator info for the the power supply of the device
- * @bops		bus operations (SPI or parallel)
- * @range		voltage range selection, selects which scale to apply
- * @oversampling	oversampling selection
- * @base_address	address from where to read data in parallel operation
- * @lock		protect sensor state from concurrent accesses to GPIOs
- * @gpio_convst	GPIO descriptor for conversion start signal (CONVST)
- * @gpio_reset		GPIO descriptor for device hard-reset
- * @gpio_range		GPIO descriptor for range selection
- * @gpio_standby	GPIO descriptor for stand-by signal (STBY),
- *			controls power-down mode of device
- * @gpio_frstdata	GPIO descriptor for reading from device when data
- *			is being read on the first channel
- * @gpio_os		GPIO descriptors to control oversampling on the device
- * @complete		completion to indicate end of conversion
- * @trig		The IIO trigger associated with the device.
- * @data		buffer for reading data from the device
- */
-struct ad7606_state {
-	struct device			*dev;
-	const struct ad7606_chip_info	*chip_info;
-	struct regulator		*reg;
-	const struct ad7606_bus_ops	*bops;
-	unsigned int			range;
-	unsigned int			oversampling;
-	void __iomem			*base_address;
-
-	struct mutex			lock; /* protect sensor state */
-	struct gpio_desc		*gpio_convst;
-	struct gpio_desc		*gpio_reset;
-	struct gpio_desc		*gpio_range;
-	struct gpio_desc		*gpio_standby;
-	struct gpio_desc		*gpio_frstdata;
-	struct gpio_descs		*gpio_os;
-	struct iio_trigger		*trig;
-	struct completion		completion;
-
-	/*
-	 * DMA (thus cache coherency maintenance) requires the
-	 * transfer buffers to live in their own cache lines.
-	 * 8 * 16-bit samples + 64-bit timestamp
-	 */
-	unsigned short			data[12] ____cacheline_aligned;
-};
-
-/**
- * struct ad7606_bus_ops - driver bus operations
- * @read_block		function pointer for reading blocks of data
- */
-struct ad7606_bus_ops {
-	/* more methods added in future? */
-	int (*read_block)(struct device *dev, int num, void *data);
-};
-
-int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
-		 const char *name, unsigned int id,
-		 const struct ad7606_bus_ops *bops);
-
-enum ad7606_supported_device_ids {
-	ID_AD7605_4,
-	ID_AD7606_8,
-	ID_AD7606_6,
-	ID_AD7606_4
-};
-
-#ifdef CONFIG_PM_SLEEP
-extern const struct dev_pm_ops ad7606_pm_ops;
-#define AD7606_PM_OPS (&ad7606_pm_ops)
-#else
-#define AD7606_PM_OPS NULL
-#endif
-
-#endif /* IIO_ADC_AD7606_H_ */
diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
deleted file mode 100644
index 32c7069..0000000
--- a/drivers/staging/iio/adc/ad7606_par.c
+++ /dev/null
@@ -1,105 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * AD7606 Parallel Interface ADC driver
- *
- * Copyright 2011 Analog Devices Inc.
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/types.h>
-#include <linux/err.h>
-#include <linux/io.h>
-
-#include <linux/iio/iio.h>
-#include "ad7606.h"
-
-static int ad7606_par16_read_block(struct device *dev,
-				   int count, void *buf)
-{
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	insw((unsigned long)st->base_address, buf, count);
-
-	return 0;
-}
-
-static const struct ad7606_bus_ops ad7606_par16_bops = {
-	.read_block = ad7606_par16_read_block,
-};
-
-static int ad7606_par8_read_block(struct device *dev,
-				  int count, void *buf)
-{
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	insb((unsigned long)st->base_address, buf, count * 2);
-
-	return 0;
-}
-
-static const struct ad7606_bus_ops ad7606_par8_bops = {
-	.read_block = ad7606_par8_read_block,
-};
-
-static int ad7606_par_probe(struct platform_device *pdev)
-{
-	const struct platform_device_id *id = platform_get_device_id(pdev);
-	struct resource *res;
-	void __iomem *addr;
-	resource_size_t remap_size;
-	int irq;
-
-	irq = platform_get_irq(pdev, 0);
-	if (irq < 0) {
-		dev_err(&pdev->dev, "no irq: %d\n", irq);
-		return irq;
-	}
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	addr = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(addr))
-		return PTR_ERR(addr);
-
-	remap_size = resource_size(res);
-
-	return ad7606_probe(&pdev->dev, irq, addr,
-			    id->name, id->driver_data,
-			    remap_size > 1 ? &ad7606_par16_bops :
-			    &ad7606_par8_bops);
-}
-
-static const struct platform_device_id ad7606_driver_ids[] = {
-	{ .name	= "ad7605-4", .driver_data = ID_AD7605_4, },
-	{ .name	= "ad7606-4", .driver_data = ID_AD7606_4, },
-	{ .name	= "ad7606-6", .driver_data = ID_AD7606_6, },
-	{ .name	= "ad7606-8", .driver_data = ID_AD7606_8, },
-	{ }
-};
-MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
-
-static const struct of_device_id ad7606_of_match[] = {
-	{ .compatible = "adi,ad7605-4" },
-	{ .compatible = "adi,ad7606-4" },
-	{ .compatible = "adi,ad7606-6" },
-	{ .compatible = "adi,ad7606-8" },
-	{ },
-};
-MODULE_DEVICE_TABLE(of, ad7606_of_match);
-
-static struct platform_driver ad7606_driver = {
-	.probe = ad7606_par_probe,
-	.id_table = ad7606_driver_ids,
-	.driver = {
-		.name = "ad7606",
-		.pm = AD7606_PM_OPS,
-		.of_match_table = ad7606_of_match,
-	},
-};
-module_platform_driver(ad7606_driver);
-
-MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
-MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
deleted file mode 100644
index b628389..0000000
--- a/drivers/staging/iio/adc/ad7606_spi.c
+++ /dev/null
@@ -1,82 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * AD7606 SPI ADC driver
- *
- * Copyright 2011 Analog Devices Inc.
- */
-
-#include <linux/module.h>
-#include <linux/spi/spi.h>
-#include <linux/types.h>
-#include <linux/err.h>
-
-#include <linux/iio/iio.h>
-#include "ad7606.h"
-
-#define MAX_SPI_FREQ_HZ		23500000	/* VDRIVE above 4.75 V */
-
-static int ad7606_spi_read_block(struct device *dev,
-				 int count, void *buf)
-{
-	struct spi_device *spi = to_spi_device(dev);
-	int i, ret;
-	unsigned short *data = buf;
-	__be16 *bdata = buf;
-
-	ret = spi_read(spi, buf, count * 2);
-	if (ret < 0) {
-		dev_err(&spi->dev, "SPI read error\n");
-		return ret;
-	}
-
-	for (i = 0; i < count; i++)
-		data[i] = be16_to_cpu(bdata[i]);
-
-	return 0;
-}
-
-static const struct ad7606_bus_ops ad7606_spi_bops = {
-	.read_block = ad7606_spi_read_block,
-};
-
-static int ad7606_spi_probe(struct spi_device *spi)
-{
-	const struct spi_device_id *id = spi_get_device_id(spi);
-
-	return ad7606_probe(&spi->dev, spi->irq, NULL,
-			    id->name, id->driver_data,
-			    &ad7606_spi_bops);
-}
-
-static const struct spi_device_id ad7606_id_table[] = {
-	{ "ad7605-4", ID_AD7605_4 },
-	{ "ad7606-4", ID_AD7606_4 },
-	{ "ad7606-6", ID_AD7606_6 },
-	{ "ad7606-8", ID_AD7606_8 },
-	{}
-};
-MODULE_DEVICE_TABLE(spi, ad7606_id_table);
-
-static const struct of_device_id ad7606_of_match[] = {
-	{ .compatible = "adi,ad7605-4" },
-	{ .compatible = "adi,ad7606-4" },
-	{ .compatible = "adi,ad7606-6" },
-	{ .compatible = "adi,ad7606-8" },
-	{ },
-};
-MODULE_DEVICE_TABLE(of, ad7606_of_match);
-
-static struct spi_driver ad7606_driver = {
-	.driver = {
-		.name = "ad7606",
-		.of_match_table = ad7606_of_match,
-		.pm = AD7606_PM_OPS,
-	},
-	.probe = ad7606_spi_probe,
-	.id_table = ad7606_id_table,
-};
-module_spi_driver(ad7606_driver);
-
-MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
-MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL");
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 11/11] dt-bindings: iio: adc: Add docs for AD7606 ADC
  2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
                   ` (9 preceding siblings ...)
  2018-12-13 12:46 ` [PATCH 10/11] staging: iio: adc: ad7606: Move out of staging Stefan Popa
@ 2018-12-13 12:46 ` Stefan Popa
  2018-12-16 13:58   ` Jonathan Cameron
  10 siblings, 1 reply; 26+ messages in thread
From: Stefan Popa @ 2018-12-13 12:46 UTC (permalink / raw)
  To: jic23, robh+dt, mark.rutland
  Cc: Stefan Popa, Michael.Hennerich, knaack.h, lars, pmeerw, gregkh,
	linux-kernel, linux-iio, devel, stefan.popa

Document support for AD7606 Analog to Digital Converter.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 .../devicetree/bindings/iio/adc/adi,ad7606.txt     | 65 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
new file mode 100644
index 0000000..d7b6241
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
@@ -0,0 +1,65 @@
+Analog Devices AD7606 Simultaneous Sampling ADC
+
+Required properties for the AD7606:
+
+- compatible: Must be one of
+	* "adi,ad7605-4"
+	* "adi,ad7606-8"
+	* "adi,ad7606-6"
+	* "adi,ad7606-4"
+- reg: SPI chip select number for the device
+- spi-max-frequency: Max SPI frequency to use
+	see: Documentation/devicetree/bindings/spi/spi-bus.txt
+- spi-cpha: See Documentation/devicetree/bindings/spi/spi-bus.txt
+- avcc-supply: phandle to the Avcc power supply
+- interrupts: IRQ line for the ADC
+	see: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+- adi,conversion-start-gpios: must be the device tree identifier of the CONVST pin.
+		  This logic input is used to initiate conversions on the analog
+		  input channels. As the line is active high, it should be marked
+		  GPIO_ACTIVE_HIGH.
+
+Optional properties:
+
+- reset-gpios: must be the device tree identifier of the RESET pin. If specified,
+	       it will be asserted during driver probe. As the line is active high,
+	       it should be marked GPIO_ACTIVE_HIGH.
+- standby-gpios: must be the device tree identifier of the STBY pin. This pin is used
+		to place the AD7606 into one of two power-down modes, Standby mode or
+		Shutdown mode. As the line is active low, it should be marked
+		GPIO_ACTIVE_LOW.
+- adi,first-data-gpios: must be the device tree identifier of the FRSTDATA pin.
+		    The FRSTDATA output indicates when the first channel, V1, is
+		    being read back on either the parallel, byte or serial interface.
+		    As the line is active high, it should be marked GPIO_ACTIVE_HIGH.
+- adi,range-gpios: must be the device tree identifier of the RANGE pin. The polarity on
+	      this pin determines the input range of the analog input channels. If
+	      this pin is tied to a logic high, the analog input range is ±10V for
+	      all channels. If this pin is tied to a logic low, the analog input range
+	      is ±5V for all channels. As the line is active high, it should be marked
+	      GPIO_ACTIVE_HIGH.
+- adi,oversampling-ratio-gpios: must be the device tree identifier of the over-sampling
+				mode pins. As the line is active high, it should be marked
+				GPIO_ACTIVE_HIGH.
+
+Example:
+
+	adc@0 {
+		compatible = "adi,ad7606-8";
+		reg = <0>;
+		spi-max-frequency = <1000000>;
+		spi-cpol;
+
+		avcc-supply = <&adc_vref>;
+
+		interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+		interrupt-parent = <&gpio>;
+
+		adi,conversion-start-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
+		reset-gpios = <&gpio 27 GPIO_ACTIVE_HIGH>;
+		adi,first-data-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>;
+		adi,oversampling-ratio-gpios = <&gpio 18 GPIO_ACTIVE_HIGH
+						&gpio 23 GPIO_ACTIVE_HIGH
+						&gpio 26 GPIO_ACTIVE_HIGH>;
+		standby-gpios = <&gpio 24 GPIO_ACTIVE_LOW>;
+	};
diff --git a/MAINTAINERS b/MAINTAINERS
index 7256ce6..798e9a2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -859,6 +859,7 @@ L:	linux-iio@vger.kernel.org
 W:	http://ez.analog.com/community/linux-device-drivers
 S:	Supported
 F:	drivers/iio/adc/ad7606.c
+F:	Documentation/devicetree/bindings/iio/adc/ad7606.txt
 
 ANALOG DEVICES INC AD9389B DRIVER
 M:	Hans Verkuil <hans.verkuil@cisco.com>
-- 
2.7.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 02/11] staging: iio: adc: ad7606: Use SPDX identifier
  2018-12-13 12:46 ` [PATCH 02/11] staging: iio: adc: ad7606: Use SPDX identifier Stefan Popa
@ 2018-12-13 13:21   ` Dan Carpenter
  0 siblings, 0 replies; 26+ messages in thread
From: Dan Carpenter @ 2018-12-13 13:21 UTC (permalink / raw)
  To: Stefan Popa
  Cc: jic23, robh+dt, mark.rutland, devel, lars, Michael.Hennerich,
	linux-iio, gregkh, linux-kernel, pmeerw, knaack.h, stefan.popa

On Thu, Dec 13, 2018 at 02:46:14PM +0200, Stefan Popa wrote:
> This patch replaces the license text at the top of ad7606 driver files
> and instead adds SPDX GPL-2.0+ license identifier.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
> ---
>  drivers/staging/iio/adc/ad7606.c     | 5 ++---
>  drivers/staging/iio/adc/ad7606.h     | 3 +--
>  drivers/staging/iio/adc/ad7606_par.c | 5 ++---
>  drivers/staging/iio/adc/ad7606_spi.c | 5 ++---
>  4 files changed, 7 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
> index 7308fa8..aa5ab1e 100644
> --- a/drivers/staging/iio/adc/ad7606.c
> +++ b/drivers/staging/iio/adc/ad7606.c
> @@ -1,9 +1,8 @@
> +// SPDX-License-Identifier: GPL-2.0+
>  /*
>   * AD7606 SPI ADC driver
>   *
>   * Copyright 2011 Analog Devices Inc.
> - *
> - * Licensed under the GPL-2.

You've changed the license from 2 to 2+.  That's literally breaking the
law.  As in country laws with lawsuits and fines and what not.  Please
be very careful with this stuff.

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq
  2018-12-13 12:46 ` [PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq Stefan Popa
@ 2018-12-13 13:28   ` Dan Carpenter
  2018-12-16 13:49   ` Jonathan Cameron
  1 sibling, 0 replies; 26+ messages in thread
From: Dan Carpenter @ 2018-12-13 13:28 UTC (permalink / raw)
  To: Stefan Popa
  Cc: jic23, robh+dt, mark.rutland, devel, lars, Michael.Hennerich,
	linux-iio, gregkh, linux-kernel, pmeerw, knaack.h, stefan.popa

On Thu, Dec 13, 2018 at 02:46:17PM +0200, Stefan Popa wrote:
> +static int ad7606_buffer_predisable(struct iio_dev *indio_dev)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	reinit_completion(&st->completion);
> +	gpiod_set_value(st->gpio_convst, 1);
> +	ret = wait_for_completion_timeout(&st->completion,
> +					  msecs_to_jiffies(1000));

We don't use this "ret".  It will introduce a set but not used warning
on new GCCs or static checkers or something.

> +	gpiod_set_value(st->gpio_convst, 0);
> +
> +	return iio_triggered_buffer_predisable(indio_dev);
> +}

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 01/11] staging: iio: adc: ad7606: Simplify the Kconfing menu
  2018-12-13 12:46 ` [PATCH 01/11] staging: iio: adc: ad7606: Simplify the Kconfing menu Stefan Popa
@ 2018-12-13 15:37   ` Rob Herring
  0 siblings, 0 replies; 26+ messages in thread
From: Rob Herring @ 2018-12-13 15:37 UTC (permalink / raw)
  To: Stefan Popa
  Cc: Jonathan Cameron, Mark Rutland, Michael Hennerich,
	Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald,
	Greg Kroah-Hartman, linux-kernel, linux-iio, devel, Stefan Popa

On Thu, Dec 13, 2018 at 8:18 AM Stefan Popa <stefan.popa@analog.com> wrote:
>
> There is no point in having three menu entries that can be selected
> individually. Instead, the SPI and parallel interfaces should select
> AD7606.
>
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
> ---
>  drivers/staging/iio/adc/Kconfig | 24 +++++++++---------------
>  1 file changed, 9 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index fc23059..af1bad8 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -4,35 +4,29 @@
>  menu "Analog to digital converters"
>
>  config AD7606
> -       tristate "Analog Devices AD7606 ADC driver"
> +       tristate
>         depends on GPIOLIB || COMPILE_TEST
>         depends on HAS_IOMEM
>         select IIO_BUFFER
>         select IIO_TRIGGERED_BUFFER
> -       help
> -         Say yes here to build support for Analog Devices:
> -         ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
> -
> -         To compile this driver as a module, choose M here: the
> -         module will be called ad7606.
>
>  config AD7606_IFACE_PARALLEL
> -       tristate "parallel interface support"
> -       depends on AD7606
> +       tristate "Analog Devices AD7606 ADC driver with parallel interface support"
> +       select AD7606

I don't think this works because the depends on for AD7606 may not be
satisfied. Moving the HAS_IOMEM here would help and either drop
GPIOLIB or move that too.

Rob

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 03/11] staging: iio: adc: ad7606: Use wait-for-completion handler
  2018-12-13 12:46 ` [PATCH 03/11] staging: iio: adc: ad7606: Use wait-for-completion handler Stefan Popa
@ 2018-12-16 13:41   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-12-16 13:41 UTC (permalink / raw)
  To: Stefan Popa
  Cc: robh+dt, mark.rutland, Michael.Hennerich, knaack.h, lars, pmeerw,
	gregkh, linux-kernel, linux-iio, devel, stefan.popa

On Thu, 13 Dec 2018 14:46:15 +0200
Stefan Popa <stefan.popa@analog.com> wrote:

> This patch replaces the use of wait_event_interruptible() with
> wait_for_completion_timeout() when reading the result of a single
> conversion. In this way, if the interrupt never occurs, the program will
> not remain blocked.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Looks good and not related to the previous 2 that obviously need
a v2.  I'll cherry pick what I can from the series to minimise
the number that you need to send again.

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/adc/ad7606.c | 14 +++++++-------
>  drivers/staging/iio/adc/ad7606.h |  6 ++----
>  2 files changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
> index aa5ab1e..4b1bc20 100644
> --- a/drivers/staging/iio/adc/ad7606.c
> +++ b/drivers/staging/iio/adc/ad7606.c
> @@ -118,12 +118,13 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
>  	struct ad7606_state *st = iio_priv(indio_dev);
>  	int ret;
>  
> -	st->done = false;
>  	gpiod_set_value(st->gpio_convst, 1);
> -
> -	ret = wait_event_interruptible(st->wq_data_avail, st->done);
> -	if (ret)
> +	ret = wait_for_completion_timeout(&st->completion,
> +					  msecs_to_jiffies(1000));
> +	if (!ret) {
> +		ret = -ETIMEDOUT;
>  		goto error_ret;
> +	}
>  
>  	ret = ad7606_read_samples(st);
>  	if (ret == 0)
> @@ -388,8 +389,7 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
>  	if (iio_buffer_enabled(indio_dev)) {
>  		schedule_work(&st->poll_work);
>  	} else {
> -		st->done = true;
> -		wake_up_interruptible(&st->wq_data_avail);
> +		complete(&st->completion);
>  	}
>  
>  	return IRQ_HANDLED;
> @@ -473,7 +473,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  	indio_dev->channels = st->chip_info->channels;
>  	indio_dev->num_channels = st->chip_info->num_channels;
>  
> -	init_waitqueue_head(&st->wq_data_avail);
> +	init_completion(&st->completion);
>  
>  	ret = ad7606_reset(st);
>  	if (ret)
> diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
> index e365fa0..cf20ca2 100644
> --- a/drivers/staging/iio/adc/ad7606.h
> +++ b/drivers/staging/iio/adc/ad7606.h
> @@ -28,11 +28,9 @@ struct ad7606_chip_info {
>   * @reg		regulator info for the the power supply of the device
>   * @poll_work		work struct for continuously reading data from the device
>   *			into an IIO triggered buffer
> - * @wq_data_avail	wait queue struct for buffer mode
>   * @bops		bus operations (SPI or parallel)
>   * @range		voltage range selection, selects which scale to apply
>   * @oversampling	oversampling selection
> - * @done		marks whether reading data is done
>   * @base_address	address from where to read data in parallel operation
>   * @lock		protect sensor state from concurrent accesses to GPIOs
>   * @gpio_convst	GPIO descriptor for conversion start signal (CONVST)
> @@ -43,6 +41,7 @@ struct ad7606_chip_info {
>   * @gpio_frstdata	GPIO descriptor for reading from device when data
>   *			is being read on the first channel
>   * @gpio_os		GPIO descriptors to control oversampling on the device
> + * @complete		completion to indicate end of conversion
>   * @data		buffer for reading data from the device
>   */
>  
> @@ -51,11 +50,9 @@ struct ad7606_state {
>  	const struct ad7606_chip_info	*chip_info;
>  	struct regulator		*reg;
>  	struct work_struct		poll_work;
> -	wait_queue_head_t		wq_data_avail;
>  	const struct ad7606_bus_ops	*bops;
>  	unsigned int			range;
>  	unsigned int			oversampling;
> -	bool				done;
>  	void __iomem			*base_address;
>  
>  	struct mutex			lock; /* protect sensor state */
> @@ -65,6 +62,7 @@ struct ad7606_state {
>  	struct gpio_desc		*gpio_standby;
>  	struct gpio_desc		*gpio_frstdata;
>  	struct gpio_descs		*gpio_os;
> +	struct completion		completion;
>  
>  	/*
>  	 * DMA (thus cache coherency maintenance) requires the


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 04/11] staging: iio: adc: ad7606: Use devm functions in probe
  2018-12-13 12:46 ` [PATCH 04/11] staging: iio: adc: ad7606: Use devm functions in probe Stefan Popa
@ 2018-12-16 13:43   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-12-16 13:43 UTC (permalink / raw)
  To: Stefan Popa
  Cc: robh+dt, mark.rutland, Michael.Hennerich, knaack.h, lars, pmeerw,
	gregkh, linux-kernel, linux-iio, devel, stefan.popa

On Thu, 13 Dec 2018 14:46:16 +0200
Stefan Popa <stefan.popa@analog.com> wrote:

> Switch to devm version of request_irq, iio_triggered_buffer_setup,
> iio_device_register. To avoid potential ordering issues in probe,
> devm_add_action_or_reset() is used for the regulator_disable(). This
> simplifies the code and decreases the chance of bugs.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Very nice.

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/adc/ad7606.c     | 59 +++++++++++++-----------------------
>  drivers/staging/iio/adc/ad7606.h     |  1 -
>  drivers/staging/iio/adc/ad7606_par.c |  6 ----
>  drivers/staging/iio/adc/ad7606_spi.c |  6 ----
>  4 files changed, 21 insertions(+), 51 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
> index 4b1bc20..7191d51 100644
> --- a/drivers/staging/iio/adc/ad7606.c
> +++ b/drivers/staging/iio/adc/ad7606.c
> @@ -417,6 +417,13 @@ static const struct iio_info ad7606_info_range = {
>  	.attrs = &ad7606_attribute_group_range,
>  };
>  
> +static void ad7606_regulator_disable(void *data)
> +{
> +	struct ad7606_state *st = data;
> +
> +	regulator_disable(st->reg);
> +}
> +
>  int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  		 const char *name, unsigned int id,
>  		 const struct ad7606_bus_ops *bops)
> @@ -430,6 +437,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  		return -ENOMEM;
>  
>  	st = iio_priv(indio_dev);
> +	dev_set_drvdata(dev, indio_dev);
>  
>  	st->dev = dev;
>  	mutex_init(&st->lock);
> @@ -450,11 +458,15 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  		return ret;
>  	}
>  
> +	ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
> +	if (ret)
> +		return ret;
> +
>  	st->chip_info = &ad7606_chip_info_tbl[id];
>  
>  	ret = ad7606_request_gpios(st);
>  	if (ret)
> -		goto error_disable_reg;
> +		return ret;
>  
>  	indio_dev->dev.parent = dev;
>  	if (st->gpio_os) {
> @@ -479,50 +491,21 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  	if (ret)
>  		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
>  
> -	ret = request_irq(irq, ad7606_interrupt, IRQF_TRIGGER_FALLING, name,
> -			  indio_dev);
> -	if (ret)
> -		goto error_disable_reg;
> -
> -	ret = iio_triggered_buffer_setup(indio_dev, &ad7606_trigger_handler,
> -					 NULL, NULL);
> +	ret = devm_request_irq(dev, irq, ad7606_interrupt, IRQF_TRIGGER_FALLING,
> +			       name, indio_dev);
>  	if (ret)
> -		goto error_free_irq;
> +		return ret;
>  
> -	ret = iio_device_register(indio_dev);
> +	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> +					      &ad7606_trigger_handler,
> +					      NULL, NULL);
>  	if (ret)
> -		goto error_unregister_ring;
> -
> -	dev_set_drvdata(dev, indio_dev);
> -
> -	return 0;
> -error_unregister_ring:
> -	iio_triggered_buffer_cleanup(indio_dev);
> -
> -error_free_irq:
> -	free_irq(irq, indio_dev);
> +		return ret;
>  
> -error_disable_reg:
> -	regulator_disable(st->reg);
> -	return ret;
> +	return devm_iio_device_register(dev, indio_dev);
>  }
>  EXPORT_SYMBOL_GPL(ad7606_probe);
>  
> -int ad7606_remove(struct device *dev, int irq)
> -{
> -	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> -	struct ad7606_state *st = iio_priv(indio_dev);
> -
> -	iio_device_unregister(indio_dev);
> -	iio_triggered_buffer_cleanup(indio_dev);
> -
> -	free_irq(irq, indio_dev);
> -	regulator_disable(st->reg);
> -
> -	return 0;
> -}
> -EXPORT_SYMBOL_GPL(ad7606_remove);
> -
>  #ifdef CONFIG_PM_SLEEP
>  
>  static int ad7606_suspend(struct device *dev)
> diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
> index cf20ca2..70486ef 100644
> --- a/drivers/staging/iio/adc/ad7606.h
> +++ b/drivers/staging/iio/adc/ad7606.h
> @@ -84,7 +84,6 @@ struct ad7606_bus_ops {
>  int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  		 const char *name, unsigned int id,
>  		 const struct ad7606_bus_ops *bops);
> -int ad7606_remove(struct device *dev, int irq);
>  
>  enum ad7606_supported_device_ids {
>  	ID_AD7605_4,
> diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
> index db2fede46..6269ee7 100644
> --- a/drivers/staging/iio/adc/ad7606_par.c
> +++ b/drivers/staging/iio/adc/ad7606_par.c
> @@ -71,11 +71,6 @@ static int ad7606_par_probe(struct platform_device *pdev)
>  			    &ad7606_par8_bops);
>  }
>  
> -static int ad7606_par_remove(struct platform_device *pdev)
> -{
> -	return ad7606_remove(&pdev->dev, platform_get_irq(pdev, 0));
> -}
> -
>  static const struct platform_device_id ad7606_driver_ids[] = {
>  	{
>  		.name		= "ad7605-4",
> @@ -97,7 +92,6 @@ MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
>  
>  static struct platform_driver ad7606_driver = {
>  	.probe = ad7606_par_probe,
> -	.remove	= ad7606_par_remove,
>  	.id_table = ad7606_driver_ids,
>  	.driver = {
>  		.name	 = "ad7606",
> diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
> index b6553ce..9291598 100644
> --- a/drivers/staging/iio/adc/ad7606_spi.c
> +++ b/drivers/staging/iio/adc/ad7606_spi.c
> @@ -48,11 +48,6 @@ static int ad7606_spi_probe(struct spi_device *spi)
>  			    &ad7606_spi_bops);
>  }
>  
> -static int ad7606_spi_remove(struct spi_device *spi)
> -{
> -	return ad7606_remove(&spi->dev, spi->irq);
> -}
> -
>  static const struct spi_device_id ad7606_id[] = {
>  	{"ad7605-4", ID_AD7605_4},
>  	{"ad7606-8", ID_AD7606_8},
> @@ -68,7 +63,6 @@ static struct spi_driver ad7606_driver = {
>  		.pm = AD7606_PM_OPS,
>  	},
>  	.probe = ad7606_spi_probe,
> -	.remove = ad7606_spi_remove,
>  	.id_table = ad7606_id,
>  };
>  module_spi_driver(ad7606_driver);


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq
  2018-12-13 12:46 ` [PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq Stefan Popa
  2018-12-13 13:28   ` Dan Carpenter
@ 2018-12-16 13:49   ` Jonathan Cameron
  2018-12-17 10:28     ` Popa, Stefan Serban
  1 sibling, 1 reply; 26+ messages in thread
From: Jonathan Cameron @ 2018-12-16 13:49 UTC (permalink / raw)
  To: Stefan Popa
  Cc: robh+dt, mark.rutland, Michael.Hennerich, knaack.h, lars, pmeerw,
	gregkh, linux-kernel, linux-iio, devel, stefan.popa

On Thu, 13 Dec 2018 14:46:17 +0200
Stefan Popa <stefan.popa@analog.com> wrote:

> This patch replaces the use of a polling ring buffer with a threaded
> interrupt.
> 
> Enabling the buffer sets the CONVST signal to high. When the rising edge
> of the CONVST is applied, BUSY signal goes logic high and transitions low
> at the end of the entire conversion process. The falling edge of the BUSY
> signal triggers the interrupt.
> 
> ad7606_trigger_handler() is used as bottom half of the poll function.
> It reads data from the device and stores it in the internal buffer.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
I'd like a little more info as comments in this one. See below.
Which is another way of saying I have no idea what is going on :)

Thanks,

Jonathan.

> ---
>  drivers/staging/iio/adc/ad7606.c | 116 +++++++++++++++++++++++++++++----------
>  drivers/staging/iio/adc/ad7606.h |   6 +-
>  2 files changed, 89 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
> index 7191d51..13aeeec 100644
> --- a/drivers/staging/iio/adc/ad7606.c
> +++ b/drivers/staging/iio/adc/ad7606.c
> @@ -21,6 +21,7 @@
>  #include <linux/iio/sysfs.h>
>  #include <linux/iio/buffer.h>
>  #include <linux/iio/trigger_consumer.h>
> +#include <linux/iio/trigger.h>
>  #include <linux/iio/triggered_buffer.h>
>  
>  #include "ad7606.h"
> @@ -81,36 +82,24 @@ static int ad7606_read_samples(struct ad7606_state *st)
>  static irqreturn_t ad7606_trigger_handler(int irq, void *p)
>  {
>  	struct iio_poll_func *pf = p;
> -	struct ad7606_state *st = iio_priv(pf->indio_dev);
> -
> -	gpiod_set_value(st->gpio_convst, 1);
> -
> -	return IRQ_HANDLED;
> -}
> -
> -/**
> - * ad7606_poll_bh_to_ring() bh of trigger launched polling to ring buffer
> - * @work_s:	the work struct through which this was scheduled
> - *
> - * Currently there is no option in this driver to disable the saving of
> - * timestamps within the ring.
> - * I think the one copy of this at a time was to avoid problems if the
> - * trigger was set far too high and the reads then locked up the computer.
> - **/
> -static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
> -{
> -	struct ad7606_state *st = container_of(work_s, struct ad7606_state,
> -						poll_work);
> -	struct iio_dev *indio_dev = iio_priv_to_dev(st);
> +	struct iio_dev *indio_dev = pf->indio_dev;
> +	struct ad7606_state *st = iio_priv(indio_dev);
>  	int ret;
>  
> +	mutex_lock(&st->lock);
> +
>  	ret = ad7606_read_samples(st);
>  	if (ret == 0)
>  		iio_push_to_buffers_with_timestamp(indio_dev, st->data,
>  						   iio_get_time_ns(indio_dev));
>  
> -	gpiod_set_value(st->gpio_convst, 0);
>  	iio_trigger_notify_done(indio_dev->trig);
> +	/* The rising edge of the CONVST signal starts a new conversion. */
> +	gpiod_set_value(st->gpio_convst, 1);
> +
> +	mutex_unlock(&st->lock);
> +
> +	return IRQ_HANDLED;
>  }
>  
>  static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
> @@ -378,8 +367,11 @@ static int ad7606_request_gpios(struct ad7606_state *st)
>  	return PTR_ERR_OR_ZERO(st->gpio_os);
>  }
>  
> -/**
> - *  Interrupt handler
> +/*
> + * The BUSY signal indicates when conversions are in progress, so when a rising
> + * edge of CONVST is applied, BUSY goes logic high and transitions low at the
> + * end of the entire conversion process. The falling edge of the BUSY signal
> + * triggers this interrupt.
>   */
>  static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
>  {
> @@ -387,7 +379,8 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
>  	struct ad7606_state *st = iio_priv(indio_dev);
>  
>  	if (iio_buffer_enabled(indio_dev)) {
> -		schedule_work(&st->poll_work);
> +		gpiod_set_value(st->gpio_convst, 0);
> +		iio_trigger_poll_chained(st->trig);
>  	} else {
>  		complete(&st->completion);
>  	}
> @@ -395,26 +388,74 @@ static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
>  	return IRQ_HANDLED;
>  };
>  
> +static int ad7606_validate_trigger(struct iio_dev *indio_dev,
> +				   struct iio_trigger *trig)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	if (st->trig != trig)
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
> +static int ad7606_buffer_postenable(struct iio_dev *indio_dev)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	iio_triggered_buffer_postenable(indio_dev);
> +	gpiod_set_value(st->gpio_convst, 1);
> +
> +	return 0;
> +}
> +
> +static int ad7606_buffer_predisable(struct iio_dev *indio_dev)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	reinit_completion(&st->completion);
> +	gpiod_set_value(st->gpio_convst, 1);
> +	ret = wait_for_completion_timeout(&st->completion,
> +					  msecs_to_jiffies(1000));

Along with Dan's comment. I'd like to see a comment here on what
is actually going on.  Not immediately obvious a conversion should
be triggered to disable the buffer...

I'll guess there is a race against the normal handler that we
are closing with this dance, but that race needs explaining.

> +	gpiod_set_value(st->gpio_convst, 0);
> +
> +	return iio_triggered_buffer_predisable(indio_dev);
> +}
> +
> +static const struct iio_buffer_setup_ops ad7606_buffer_ops = {
> +	.postenable = &ad7606_buffer_postenable,
> +	.predisable = &ad7606_buffer_predisable,
> +};
> +
>  static const struct iio_info ad7606_info_no_os_or_range = {
>  	.read_raw = &ad7606_read_raw,
> +	.validate_trigger = &ad7606_validate_trigger,
>  };
>  
>  static const struct iio_info ad7606_info_os_and_range = {
>  	.read_raw = &ad7606_read_raw,
>  	.write_raw = &ad7606_write_raw,
>  	.attrs = &ad7606_attribute_group_os_and_range,
> +	.validate_trigger = &ad7606_validate_trigger,
>  };
>  
>  static const struct iio_info ad7606_info_os = {
>  	.read_raw = &ad7606_read_raw,
>  	.write_raw = &ad7606_write_raw,
>  	.attrs = &ad7606_attribute_group_os,
> +	.validate_trigger = &ad7606_validate_trigger,
>  };
>  
>  static const struct iio_info ad7606_info_range = {
>  	.read_raw = &ad7606_read_raw,
>  	.write_raw = &ad7606_write_raw,
>  	.attrs = &ad7606_attribute_group_range,
> +	.validate_trigger = &ad7606_validate_trigger,
> +};
> +
> +static const struct iio_trigger_ops ad7606_trigger_ops = {
> +	.validate_device = iio_trigger_validate_own_device,
>  };
>  
>  static void ad7606_regulator_disable(void *data)
> @@ -446,7 +487,6 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  	/* tied to logic low, analog input range is +/- 5V */
>  	st->range = 0;
>  	st->oversampling = 1;
> -	INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring);
>  
>  	st->reg = devm_regulator_get(dev, "avcc");
>  	if (IS_ERR(st->reg))
> @@ -491,14 +531,32 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  	if (ret)
>  		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
>  
> -	ret = devm_request_irq(dev, irq, ad7606_interrupt, IRQF_TRIGGER_FALLING,
> -			       name, indio_dev);
> +	st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> +					  indio_dev->name, indio_dev->id);
> +	if (!st->trig)
> +		return -ENOMEM;
> +
> +	st->trig->ops = &ad7606_trigger_ops;
> +	st->trig->dev.parent = dev;
> +	iio_trigger_set_drvdata(st->trig, indio_dev);
> +	ret = devm_iio_trigger_register(dev, st->trig);
> +	if (ret)
> +		return ret;
> +
> +	indio_dev->trig = iio_trigger_get(st->trig);
> +
> +	ret = devm_request_threaded_irq(dev, irq,
> +					NULL,
> +					&ad7606_interrupt,
> +					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
> +					name, indio_dev);
>  	if (ret)
>  		return ret;
>  
>  	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> +					      &iio_pollfunc_store_time,
>  					      &ad7606_trigger_handler,
> -					      NULL, NULL);
> +					      &ad7606_buffer_ops);
>  	if (ret)
>  		return ret;
>  
> diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
> index 70486ef..b238e9b 100644
> --- a/drivers/staging/iio/adc/ad7606.h
> +++ b/drivers/staging/iio/adc/ad7606.h
> @@ -26,8 +26,6 @@ struct ad7606_chip_info {
>   * @dev		pointer to kernel device
>   * @chip_info		entry in the table of chips that describes this device
>   * @reg		regulator info for the the power supply of the device
> - * @poll_work		work struct for continuously reading data from the device
> - *			into an IIO triggered buffer
>   * @bops		bus operations (SPI or parallel)
>   * @range		voltage range selection, selects which scale to apply
>   * @oversampling	oversampling selection
> @@ -42,14 +40,13 @@ struct ad7606_chip_info {
>   *			is being read on the first channel
>   * @gpio_os		GPIO descriptors to control oversampling on the device
>   * @complete		completion to indicate end of conversion
> + * @trig		The IIO trigger associated with the device.
>   * @data		buffer for reading data from the device
>   */
> -
>  struct ad7606_state {
>  	struct device			*dev;
>  	const struct ad7606_chip_info	*chip_info;
>  	struct regulator		*reg;
> -	struct work_struct		poll_work;
>  	const struct ad7606_bus_ops	*bops;
>  	unsigned int			range;
>  	unsigned int			oversampling;
> @@ -62,6 +59,7 @@ struct ad7606_state {
>  	struct gpio_desc		*gpio_standby;
>  	struct gpio_desc		*gpio_frstdata;
>  	struct gpio_descs		*gpio_os;
> +	struct iio_trigger		*trig;
>  	struct completion		completion;
>  
>  	/*


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 06/11] staging: iio: adc: ad7606: Use find_closest() macro
  2018-12-13 12:46 ` [PATCH 06/11] staging: iio: adc: ad7606: Use find_closest() macro Stefan Popa
@ 2018-12-16 13:51   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-12-16 13:51 UTC (permalink / raw)
  To: Stefan Popa
  Cc: robh+dt, mark.rutland, Michael.Hennerich, knaack.h, lars, pmeerw,
	gregkh, linux-kernel, linux-iio, devel, stefan.popa

On Thu, 13 Dec 2018 14:46:18 +0200
Stefan Popa <stefan.popa@analog.com> wrote:

> When looking for the available scale or oversampling ratio, it is better
> to use the find_closest() macro. This simplifies the code and also does
> not require an exact value to be entered from the user space.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Nice little cleanup.

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/adc/ad7606.c | 58 +++++++++++++++-------------------------
>  1 file changed, 22 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
> index 13aeeec..0925379 100644
> --- a/drivers/staging/iio/adc/ad7606.c
> +++ b/drivers/staging/iio/adc/ad7606.c
> @@ -16,6 +16,7 @@
>  #include <linux/delay.h>
>  #include <linux/sched.h>
>  #include <linux/module.h>
> +#include <linux/util_macros.h>
>  
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
> @@ -30,8 +31,12 @@
>   * Scales are computed as 5000/32768 and 10000/32768 respectively,
>   * so that when applied to the raw values they provide mV values
>   */
> -static const unsigned int scale_avail[2][2] = {
> -	{0, 152588}, {0, 305176}
> +static const unsigned int scale_avail[2] = {
> +	152588, 305176
> +};
> +
> +static const unsigned int ad7606_oversampling_avail[7] = {
> +	1, 2, 4, 8, 16, 32, 64,
>  };
>  
>  static int ad7606_reset(struct ad7606_state *st)
> @@ -148,8 +153,8 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
>  		*val = (short)ret;
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_SCALE:
> -		*val = scale_avail[st->range][0];
> -		*val2 = scale_avail[st->range][1];
> +		*val = 0;
> +		*val2 = scale_avail[st->range];
>  		return IIO_VAL_INT_PLUS_MICRO;
>  	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
>  		*val = st->oversampling;
> @@ -165,8 +170,8 @@ static ssize_t in_voltage_scale_available_show(struct device *dev,
>  	int i, len = 0;
>  
>  	for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
> -		len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06u ",
> -				 scale_avail[i][0], scale_avail[i][1]);
> +		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
> +				 scale_avail[i]);
>  
>  	buf[len - 1] = '\n';
>  
> @@ -175,18 +180,6 @@ static ssize_t in_voltage_scale_available_show(struct device *dev,
>  
>  static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
>  
> -static int ad7606_oversampling_get_index(unsigned int val)
> -{
> -	unsigned char supported[] = {1, 2, 4, 8, 16, 32, 64};
> -	int i;
> -
> -	for (i = 0; i < ARRAY_SIZE(supported); i++)
> -		if (val == supported[i])
> -			return i;
> -
> -	return -EINVAL;
> -}
> -
>  static int ad7606_write_raw(struct iio_dev *indio_dev,
>  			    struct iio_chan_spec const *chan,
>  			    int val,
> @@ -195,36 +188,29 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
>  {
>  	struct ad7606_state *st = iio_priv(indio_dev);
>  	DECLARE_BITMAP(values, 3);
> -	int ret, i;
> +	int i;
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_SCALE:
> -		ret = -EINVAL;
>  		mutex_lock(&st->lock);
> -		for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
> -			if (val2 == scale_avail[i][1]) {
> -				gpiod_set_value(st->gpio_range, i);
> -				st->range = i;
> -
> -				ret = 0;
> -				break;
> -			}
> +		i = find_closest(val2, scale_avail, ARRAY_SIZE(scale_avail));
> +		gpiod_set_value(st->gpio_range, i);
> +		st->range = i;
>  		mutex_unlock(&st->lock);
>  
> -		return ret;
> +		return 0;
>  	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
>  		if (val2)
>  			return -EINVAL;
> -		ret = ad7606_oversampling_get_index(val);
> -		if (ret < 0)
> -			return ret;
> +		i = find_closest(val, ad7606_oversampling_avail,
> +				 ARRAY_SIZE(ad7606_oversampling_avail));
>  
> -		values[0] = ret;
> +		values[0] = i;
>  
>  		mutex_lock(&st->lock);
> -		gpiod_set_array_value(3, st->gpio_os->desc, st->gpio_os->info,
> -				      values);
> -		st->oversampling = val;
> +		gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
> +				      st->gpio_os->info, values);
> +		st->oversampling = ad7606_oversampling_avail[i];
>  		mutex_unlock(&st->lock);
>  
>  		return 0;


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 07/11] staging: iio: adc: ad7606: Use vendor prefix for DT properties
  2018-12-13 12:46 ` [PATCH 07/11] staging: iio: adc: ad7606: Use vendor prefix for DT properties Stefan Popa
@ 2018-12-16 13:53   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-12-16 13:53 UTC (permalink / raw)
  To: Stefan Popa
  Cc: robh+dt, mark.rutland, Michael.Hennerich, knaack.h, lars, pmeerw,
	gregkh, linux-kernel, linux-iio, devel, stefan.popa

On Thu, 13 Dec 2018 14:46:19 +0200
Stefan Popa <stefan.popa@analog.com> wrote:

> The 'adi' vendor prefix needs to be added to conversion-start, range,
> first-data and oversampling-ratio properties.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/adc/ad7606.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
> index 0925379..3355301 100644
> --- a/drivers/staging/iio/adc/ad7606.c
> +++ b/drivers/staging/iio/adc/ad7606.c
> @@ -322,7 +322,7 @@ static int ad7606_request_gpios(struct ad7606_state *st)
>  {
>  	struct device *dev = st->dev;
>  
> -	st->gpio_convst = devm_gpiod_get(dev, "conversion-start",
> +	st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start",
>  					 GPIOD_OUT_LOW);
>  	if (IS_ERR(st->gpio_convst))
>  		return PTR_ERR(st->gpio_convst);
> @@ -331,7 +331,8 @@ static int ad7606_request_gpios(struct ad7606_state *st)
>  	if (IS_ERR(st->gpio_reset))
>  		return PTR_ERR(st->gpio_reset);
>  
> -	st->gpio_range = devm_gpiod_get_optional(dev, "range", GPIOD_OUT_LOW);
> +	st->gpio_range = devm_gpiod_get_optional(dev, "adi,range",
> +						 GPIOD_OUT_LOW);
>  	if (IS_ERR(st->gpio_range))
>  		return PTR_ERR(st->gpio_range);
>  
> @@ -340,7 +341,7 @@ static int ad7606_request_gpios(struct ad7606_state *st)
>  	if (IS_ERR(st->gpio_standby))
>  		return PTR_ERR(st->gpio_standby);
>  
> -	st->gpio_frstdata = devm_gpiod_get_optional(dev, "first-data",
> +	st->gpio_frstdata = devm_gpiod_get_optional(dev, "adi,first-data",
>  						    GPIOD_IN);
>  	if (IS_ERR(st->gpio_frstdata))
>  		return PTR_ERR(st->gpio_frstdata);
> @@ -348,7 +349,8 @@ static int ad7606_request_gpios(struct ad7606_state *st)
>  	if (!st->chip_info->has_oversampling)
>  		return 0;
>  
> -	st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio",
> +	st->gpio_os = devm_gpiod_get_array_optional(dev,
> +						    "adi,oversampling-ratio",
>  						    GPIOD_OUT_LOW);
>  	return PTR_ERR_OR_ZERO(st->gpio_os);
>  }


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 08/11] staging: iio: adc: ad7606: Add OF device ID table
  2018-12-13 12:46 ` [PATCH 08/11] staging: iio: adc: ad7606: Add OF device ID table Stefan Popa
@ 2018-12-16 13:54   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-12-16 13:54 UTC (permalink / raw)
  To: Stefan Popa
  Cc: robh+dt, mark.rutland, Michael.Hennerich, knaack.h, lars, pmeerw,
	gregkh, linux-kernel, linux-iio, devel, stefan.popa

On Thu, 13 Dec 2018 14:46:20 +0200
Stefan Popa <stefan.popa@analog.com> wrote:

> The driver does not have a struct of_device_id table, but supported
> devices are registered via Device Trees. This patch adds and OF device
> ID table.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Applied.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/adc/ad7606_par.c | 10 ++++++++++
>  drivers/staging/iio/adc/ad7606_spi.c | 10 ++++++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
> index 6269ee7..ac0c7b0 100644
> --- a/drivers/staging/iio/adc/ad7606_par.c
> +++ b/drivers/staging/iio/adc/ad7606_par.c
> @@ -90,12 +90,22 @@ static const struct platform_device_id ad7606_driver_ids[] = {
>  
>  MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
>  
> +static const struct of_device_id ad7606_of_match[] = {
> +	{ .compatible = "adi,ad7605-4" },
> +	{ .compatible = "adi,ad7606-4" },
> +	{ .compatible = "adi,ad7606-6" },
> +	{ .compatible = "adi,ad7606-8" },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, ad7606_of_match);
> +
>  static struct platform_driver ad7606_driver = {
>  	.probe = ad7606_par_probe,
>  	.id_table = ad7606_driver_ids,
>  	.driver = {
>  		.name	 = "ad7606",
>  		.pm	 = AD7606_PM_OPS,
> +		.of_match_table = ad7606_of_match,
>  	},
>  };
>  
> diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
> index 9291598..2608d34 100644
> --- a/drivers/staging/iio/adc/ad7606_spi.c
> +++ b/drivers/staging/iio/adc/ad7606_spi.c
> @@ -57,9 +57,19 @@ static const struct spi_device_id ad7606_id[] = {
>  };
>  MODULE_DEVICE_TABLE(spi, ad7606_id);
>  
> +static const struct of_device_id ad7606_of_match[] = {
> +	{ .compatible = "adi,ad7605-4" },
> +	{ .compatible = "adi,ad7606-4" },
> +	{ .compatible = "adi,ad7606-6" },
> +	{ .compatible = "adi,ad7606-8" },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, ad7606_of_match);
> +
>  static struct spi_driver ad7606_driver = {
>  	.driver = {
>  		.name = "ad7606",
> +		.of_match_table = ad7606_of_match,
>  		.pm = AD7606_PM_OPS,
>  	},
>  	.probe = ad7606_spi_probe,


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 09/11] staging: iio: adc: ad7606: Misc style fixes (no functional change)
  2018-12-13 12:46 ` [PATCH 09/11] staging: iio: adc: ad7606: Misc style fixes (no functional change) Stefan Popa
@ 2018-12-16 13:56   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-12-16 13:56 UTC (permalink / raw)
  To: Stefan Popa
  Cc: robh+dt, mark.rutland, Michael.Hennerich, knaack.h, lars, pmeerw,
	gregkh, linux-kernel, linux-iio, devel, stefan.popa

On Thu, 13 Dec 2018 14:46:21 +0200
Stefan Popa <stefan.popa@analog.com> wrote:

> * Placed includes in alphabetical order
> * Added brackets around num and mask through out for AD760X_CHANNEL
> * Used single line comments where needed
> * Removed extra lines and spaces
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Looks fine, but unsurprisingly doesn't apply given I haven't taken all
the precursors.  Will pick up in v2.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/adc/ad7606.c     | 27 ++++++++++++---------------
>  drivers/staging/iio/adc/ad7606.h     |  1 -
>  drivers/staging/iio/adc/ad7606_par.c | 27 ++++++++-------------------
>  drivers/staging/iio/adc/ad7606_spi.c | 16 ++++++++--------
>  4 files changed, 28 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
> index 3355301..5733760 100644
> --- a/drivers/staging/iio/adc/ad7606.c
> +++ b/drivers/staging/iio/adc/ad7606.c
> @@ -5,25 +5,25 @@
>   * Copyright 2011 Analog Devices Inc.
>   */
>  
> -#include <linux/interrupt.h>
> +#include <linux/delay.h>
>  #include <linux/device.h>
> -#include <linux/kernel.h>
> -#include <linux/slab.h>
> -#include <linux/sysfs.h>
> -#include <linux/regulator/consumer.h>
>  #include <linux/err.h>
>  #include <linux/gpio/consumer.h>
> -#include <linux/delay.h>
> -#include <linux/sched.h>
> +#include <linux/interrupt.h>
> +#include <linux/kernel.h>
>  #include <linux/module.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/sched.h>
> +#include <linux/slab.h>
> +#include <linux/sysfs.h>
>  #include <linux/util_macros.h>
>  
>  #include <linux/iio/iio.h>
> -#include <linux/iio/sysfs.h>
>  #include <linux/iio/buffer.h>
> -#include <linux/iio/trigger_consumer.h>
> +#include <linux/iio/sysfs.h>
>  #include <linux/iio/trigger.h>
>  #include <linux/iio/triggered_buffer.h>
> +#include <linux/iio/trigger_consumer.h>
>  
>  #include "ad7606.h"
>  
> @@ -249,8 +249,7 @@ static const struct attribute_group ad7606_attribute_group_range = {
>  	.attrs = ad7606_attributes_range,
>  };
>  
> -#define AD760X_CHANNEL(num, mask)				\
> -	{							\
> +#define AD760X_CHANNEL(num, mask) {				\
>  		.type = IIO_VOLTAGE,				\
>  		.indexed = 1,					\
>  		.channel = num,					\
> @@ -265,7 +264,7 @@ static const struct attribute_group ad7606_attribute_group_range = {
>  			.storagebits = 16,			\
>  			.endianness = IIO_CPU,			\
>  		},						\
> -	}
> +}
>  
>  #define AD7605_CHANNEL(num)	\
>  	AD760X_CHANNEL(num, 0)
> @@ -294,9 +293,7 @@ static const struct iio_chan_spec ad7606_channels[] = {
>  };
>  
>  static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
> -	/*
> -	 * More devices added in future
> -	 */
> +	/* More devices added in future */
>  	[ID_AD7605_4] = {
>  		.channels = ad7605_channels,
>  		.num_channels = 5,
> diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
> index b238e9b..40433af 100644
> --- a/drivers/staging/iio/adc/ad7606.h
> +++ b/drivers/staging/iio/adc/ad7606.h
> @@ -14,7 +14,6 @@
>   * @num_channels:	number of channels
>   * @has_oversampling:   whether the device has oversampling support
>   */
> -
>  struct ad7606_chip_info {
>  	const struct iio_chan_spec	*channels;
>  	unsigned int			num_channels;
> diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
> index ac0c7b0..32c7069 100644
> --- a/drivers/staging/iio/adc/ad7606_par.c
> +++ b/drivers/staging/iio/adc/ad7606_par.c
> @@ -26,7 +26,7 @@ static int ad7606_par16_read_block(struct device *dev,
>  }
>  
>  static const struct ad7606_bus_ops ad7606_par16_bops = {
> -	.read_block	= ad7606_par16_read_block,
> +	.read_block = ad7606_par16_read_block,
>  };
>  
>  static int ad7606_par8_read_block(struct device *dev,
> @@ -41,7 +41,7 @@ static int ad7606_par8_read_block(struct device *dev,
>  }
>  
>  static const struct ad7606_bus_ops ad7606_par8_bops = {
> -	.read_block	= ad7606_par8_read_block,
> +	.read_block = ad7606_par8_read_block,
>  };
>  
>  static int ad7606_par_probe(struct platform_device *pdev)
> @@ -72,22 +72,12 @@ static int ad7606_par_probe(struct platform_device *pdev)
>  }
>  
>  static const struct platform_device_id ad7606_driver_ids[] = {
> -	{
> -		.name		= "ad7605-4",
> -		.driver_data	= ID_AD7605_4,
> -	}, {
> -		.name		= "ad7606-8",
> -		.driver_data	= ID_AD7606_8,
> -	}, {
> -		.name		= "ad7606-6",
> -		.driver_data	= ID_AD7606_6,
> -	}, {
> -		.name		= "ad7606-4",
> -		.driver_data	= ID_AD7606_4,
> -	},
> +	{ .name	= "ad7605-4", .driver_data = ID_AD7605_4, },
> +	{ .name	= "ad7606-4", .driver_data = ID_AD7606_4, },
> +	{ .name	= "ad7606-6", .driver_data = ID_AD7606_6, },
> +	{ .name	= "ad7606-8", .driver_data = ID_AD7606_8, },
>  	{ }
>  };
> -
>  MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
>  
>  static const struct of_device_id ad7606_of_match[] = {
> @@ -103,12 +93,11 @@ static struct platform_driver ad7606_driver = {
>  	.probe = ad7606_par_probe,
>  	.id_table = ad7606_driver_ids,
>  	.driver = {
> -		.name	 = "ad7606",
> -		.pm	 = AD7606_PM_OPS,
> +		.name = "ad7606",
> +		.pm = AD7606_PM_OPS,
>  		.of_match_table = ad7606_of_match,
>  	},
>  };
> -
>  module_platform_driver(ad7606_driver);
>  
>  MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
> diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
> index 2608d34..b628389 100644
> --- a/drivers/staging/iio/adc/ad7606_spi.c
> +++ b/drivers/staging/iio/adc/ad7606_spi.c
> @@ -36,7 +36,7 @@ static int ad7606_spi_read_block(struct device *dev,
>  }
>  
>  static const struct ad7606_bus_ops ad7606_spi_bops = {
> -	.read_block	= ad7606_spi_read_block,
> +	.read_block = ad7606_spi_read_block,
>  };
>  
>  static int ad7606_spi_probe(struct spi_device *spi)
> @@ -48,14 +48,14 @@ static int ad7606_spi_probe(struct spi_device *spi)
>  			    &ad7606_spi_bops);
>  }
>  
> -static const struct spi_device_id ad7606_id[] = {
> -	{"ad7605-4", ID_AD7605_4},
> -	{"ad7606-8", ID_AD7606_8},
> -	{"ad7606-6", ID_AD7606_6},
> -	{"ad7606-4", ID_AD7606_4},
> +static const struct spi_device_id ad7606_id_table[] = {
> +	{ "ad7605-4", ID_AD7605_4 },
> +	{ "ad7606-4", ID_AD7606_4 },
> +	{ "ad7606-6", ID_AD7606_6 },
> +	{ "ad7606-8", ID_AD7606_8 },
>  	{}
>  };
> -MODULE_DEVICE_TABLE(spi, ad7606_id);
> +MODULE_DEVICE_TABLE(spi, ad7606_id_table);
>  
>  static const struct of_device_id ad7606_of_match[] = {
>  	{ .compatible = "adi,ad7605-4" },
> @@ -73,7 +73,7 @@ static struct spi_driver ad7606_driver = {
>  		.pm = AD7606_PM_OPS,
>  	},
>  	.probe = ad7606_spi_probe,
> -	.id_table = ad7606_id,
> +	.id_table = ad7606_id_table,
>  };
>  module_spi_driver(ad7606_driver);
>  


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 11/11] dt-bindings: iio: adc: Add docs for AD7606 ADC
  2018-12-13 12:46 ` [PATCH 11/11] dt-bindings: iio: adc: Add docs for AD7606 ADC Stefan Popa
@ 2018-12-16 13:58   ` Jonathan Cameron
  0 siblings, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-12-16 13:58 UTC (permalink / raw)
  To: Stefan Popa
  Cc: robh+dt, mark.rutland, Michael.Hennerich, knaack.h, lars, pmeerw,
	gregkh, linux-kernel, linux-iio, devel, stefan.popa

On Thu, 13 Dec 2018 14:46:23 +0200
Stefan Popa <stefan.popa@analog.com> wrote:

> Document support for AD7606 Analog to Digital Converter.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
> Reviewed-by: Rob Herring <robh@kernel.org>
Will have to wait on this as the MAINTAINERS bit obviously isn't there yet.
Otherwise I would have just added it now.  Oh well, v2.


Thanks,

Jonathan

> ---
>  .../devicetree/bindings/iio/adc/adi,ad7606.txt     | 65 ++++++++++++++++++++++
>  MAINTAINERS                                        |  1 +
>  2 files changed, 66 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
> 
> diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
> new file mode 100644
> index 0000000..d7b6241
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
> @@ -0,0 +1,65 @@
> +Analog Devices AD7606 Simultaneous Sampling ADC
> +
> +Required properties for the AD7606:
> +
> +- compatible: Must be one of
> +	* "adi,ad7605-4"
> +	* "adi,ad7606-8"
> +	* "adi,ad7606-6"
> +	* "adi,ad7606-4"
> +- reg: SPI chip select number for the device
> +- spi-max-frequency: Max SPI frequency to use
> +	see: Documentation/devicetree/bindings/spi/spi-bus.txt
> +- spi-cpha: See Documentation/devicetree/bindings/spi/spi-bus.txt
> +- avcc-supply: phandle to the Avcc power supply
> +- interrupts: IRQ line for the ADC
> +	see: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
> +- adi,conversion-start-gpios: must be the device tree identifier of the CONVST pin.
> +		  This logic input is used to initiate conversions on the analog
> +		  input channels. As the line is active high, it should be marked
> +		  GPIO_ACTIVE_HIGH.
> +
> +Optional properties:
> +
> +- reset-gpios: must be the device tree identifier of the RESET pin. If specified,
> +	       it will be asserted during driver probe. As the line is active high,
> +	       it should be marked GPIO_ACTIVE_HIGH.
> +- standby-gpios: must be the device tree identifier of the STBY pin. This pin is used
> +		to place the AD7606 into one of two power-down modes, Standby mode or
> +		Shutdown mode. As the line is active low, it should be marked
> +		GPIO_ACTIVE_LOW.
> +- adi,first-data-gpios: must be the device tree identifier of the FRSTDATA pin.
> +		    The FRSTDATA output indicates when the first channel, V1, is
> +		    being read back on either the parallel, byte or serial interface.
> +		    As the line is active high, it should be marked GPIO_ACTIVE_HIGH.
> +- adi,range-gpios: must be the device tree identifier of the RANGE pin. The polarity on
> +	      this pin determines the input range of the analog input channels. If
> +	      this pin is tied to a logic high, the analog input range is ±10V for
> +	      all channels. If this pin is tied to a logic low, the analog input range
> +	      is ±5V for all channels. As the line is active high, it should be marked
> +	      GPIO_ACTIVE_HIGH.
> +- adi,oversampling-ratio-gpios: must be the device tree identifier of the over-sampling
> +				mode pins. As the line is active high, it should be marked
> +				GPIO_ACTIVE_HIGH.
> +
> +Example:
> +
> +	adc@0 {
> +		compatible = "adi,ad7606-8";
> +		reg = <0>;
> +		spi-max-frequency = <1000000>;
> +		spi-cpol;
> +
> +		avcc-supply = <&adc_vref>;
> +
> +		interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
> +		interrupt-parent = <&gpio>;
> +
> +		adi,conversion-start-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
> +		reset-gpios = <&gpio 27 GPIO_ACTIVE_HIGH>;
> +		adi,first-data-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>;
> +		adi,oversampling-ratio-gpios = <&gpio 18 GPIO_ACTIVE_HIGH
> +						&gpio 23 GPIO_ACTIVE_HIGH
> +						&gpio 26 GPIO_ACTIVE_HIGH>;
> +		standby-gpios = <&gpio 24 GPIO_ACTIVE_LOW>;
> +	};
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 7256ce6..798e9a2 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -859,6 +859,7 @@ L:	linux-iio@vger.kernel.org
>  W:	http://ez.analog.com/community/linux-device-drivers
>  S:	Supported
>  F:	drivers/iio/adc/ad7606.c
> +F:	Documentation/devicetree/bindings/iio/adc/ad7606.txt
>  
>  ANALOG DEVICES INC AD9389B DRIVER
>  M:	Hans Verkuil <hans.verkuil@cisco.com>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 10/11] staging: iio: adc: ad7606: Move out of staging
  2018-12-13 12:46 ` [PATCH 10/11] staging: iio: adc: ad7606: Move out of staging Stefan Popa
@ 2018-12-16 14:14   ` Jonathan Cameron
  2018-12-20 19:45   ` kbuild test robot
  1 sibling, 0 replies; 26+ messages in thread
From: Jonathan Cameron @ 2018-12-16 14:14 UTC (permalink / raw)
  To: Stefan Popa
  Cc: robh+dt, mark.rutland, Michael.Hennerich, knaack.h, lars, pmeerw,
	gregkh, linux-kernel, linux-iio, devel, stefan.popa

On Thu, 13 Dec 2018 14:46:22 +0200
Stefan Popa <stefan.popa@analog.com> wrote:

> Move ad7606 ADC driver out of staging and into the mainline.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Other than the things already mentioned in earlier patches, looks good to
me.

Thanks

Jonathan

> ---
>  MAINTAINERS                          |   7 +
>  drivers/iio/adc/Kconfig              |  28 ++
>  drivers/iio/adc/Makefile             |   3 +
>  drivers/iio/adc/ad7606.c             | 588 +++++++++++++++++++++++++++++++++++
>  drivers/iio/adc/ad7606.h             |  99 ++++++
>  drivers/iio/adc/ad7606_par.c         | 105 +++++++
>  drivers/iio/adc/ad7606_spi.c         |  82 +++++
>  drivers/staging/iio/adc/Kconfig      |  28 --
>  drivers/staging/iio/adc/Makefile     |   4 -
>  drivers/staging/iio/adc/ad7606.c     | 588 -----------------------------------
>  drivers/staging/iio/adc/ad7606.h     |  99 ------
>  drivers/staging/iio/adc/ad7606_par.c | 105 -------
>  drivers/staging/iio/adc/ad7606_spi.c |  82 -----
>  13 files changed, 912 insertions(+), 906 deletions(-)
>  create mode 100644 drivers/iio/adc/ad7606.c
>  create mode 100644 drivers/iio/adc/ad7606.h
>  create mode 100644 drivers/iio/adc/ad7606_par.c
>  create mode 100644 drivers/iio/adc/ad7606_spi.c
>  delete mode 100644 drivers/staging/iio/adc/ad7606.c
>  delete mode 100644 drivers/staging/iio/adc/ad7606.h
>  delete mode 100644 drivers/staging/iio/adc/ad7606_par.c
>  delete mode 100644 drivers/staging/iio/adc/ad7606_spi.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index d904229..7256ce6 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -853,6 +853,13 @@ S:	Supported
>  F:	drivers/iio/adc/ad7124.c
>  F:	Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
>  
> +ANALOG DEVICES INC AD7606 DRIVER
> +M:	Stefan Popa <stefan.popa@analog.com>
> +L:	linux-iio@vger.kernel.org
> +W:	http://ez.analog.com/community/linux-device-drivers
> +S:	Supported
> +F:	drivers/iio/adc/ad7606.c
> +
>  ANALOG DEVICES INC AD9389B DRIVER
>  M:	Hans Verkuil <hans.verkuil@cisco.com>
>  L:	linux-media@vger.kernel.org
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index da9644b..9c0b50b 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -69,6 +69,34 @@ config AD7476
>  	  To compile this driver as a module, choose M here: the
>  	  module will be called ad7476.
>  
> +config AD7606
> +	tristate
> +	depends on GPIOLIB || COMPILE_TEST
> +	depends on HAS_IOMEM
> +	select IIO_BUFFER
> +	select IIO_TRIGGERED_BUFFER
> +
> +config AD7606_IFACE_PARALLEL
> +	tristate "Analog Devices AD7606 ADC driver with parallel interface support"
> +	select AD7606
> +	help
> +	  Say yes here to build parallel interface support for Analog Devices:
> +	  ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
> +
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called ad7606_parallel.
> +
> +config AD7606_IFACE_SPI
> +	tristate "Analog Devices AD7606 ADC driver with spi interface support"
> +	depends on SPI
> +	select AD7606
> +	help
> +	  Say yes here to build spi interface support for Analog Devices:
> +	  ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
> +
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called ad7606_spi.
> +
>  config AD7766
>  	tristate "Analog Devices AD7766/AD7767 ADC driver"
>  	depends on SPI_MASTER
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index 07df37f..ea50313 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -11,6 +11,9 @@ obj-$(CONFIG_AD7291) += ad7291.o
>  obj-$(CONFIG_AD7298) += ad7298.o
>  obj-$(CONFIG_AD7923) += ad7923.o
>  obj-$(CONFIG_AD7476) += ad7476.o
> +obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
> +obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
> +obj-$(CONFIG_AD7606) += ad7606.o
>  obj-$(CONFIG_AD7766) += ad7766.o
>  obj-$(CONFIG_AD7791) += ad7791.o
>  obj-$(CONFIG_AD7793) += ad7793.o
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> new file mode 100644
> index 0000000..5733760
> --- /dev/null
> +++ b/drivers/iio/adc/ad7606.c
> @@ -0,0 +1,588 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * AD7606 SPI ADC driver
> + *
> + * Copyright 2011 Analog Devices Inc.
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/interrupt.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/sched.h>
> +#include <linux/slab.h>
> +#include <linux/sysfs.h>
> +#include <linux/util_macros.h>
> +
> +#include <linux/iio/iio.h>
> +#include <linux/iio/buffer.h>
> +#include <linux/iio/sysfs.h>
> +#include <linux/iio/trigger.h>
> +#include <linux/iio/triggered_buffer.h>
> +#include <linux/iio/trigger_consumer.h>
> +
> +#include "ad7606.h"
> +
> +/*
> + * Scales are computed as 5000/32768 and 10000/32768 respectively,
> + * so that when applied to the raw values they provide mV values
> + */
> +static const unsigned int scale_avail[2] = {
> +	152588, 305176
> +};
> +
> +static const unsigned int ad7606_oversampling_avail[7] = {
> +	1, 2, 4, 8, 16, 32, 64,
> +};
> +
> +static int ad7606_reset(struct ad7606_state *st)
> +{
> +	if (st->gpio_reset) {
> +		gpiod_set_value(st->gpio_reset, 1);
> +		ndelay(100); /* t_reset >= 100ns */
> +		gpiod_set_value(st->gpio_reset, 0);
> +		return 0;
> +	}
> +
> +	return -ENODEV;
> +}
> +
> +static int ad7606_read_samples(struct ad7606_state *st)
> +{
> +	unsigned int num = st->chip_info->num_channels;
> +	u16 *data = st->data;
> +	int ret;
> +
> +	/*
> +	 * The frstdata signal is set to high while and after reading the sample
> +	 * of the first channel and low for all other channels. This can be used
> +	 * to check that the incoming data is correctly aligned. During normal
> +	 * operation the data should never become unaligned, but some glitch or
> +	 * electrostatic discharge might cause an extra read or clock cycle.
> +	 * Monitoring the frstdata signal allows to recover from such failure
> +	 * situations.
> +	 */
> +
> +	if (st->gpio_frstdata) {
> +		ret = st->bops->read_block(st->dev, 1, data);
> +		if (ret)
> +			return ret;
> +
> +		if (!gpiod_get_value(st->gpio_frstdata)) {
> +			ad7606_reset(st);
> +			return -EIO;
> +		}
> +
> +		data++;
> +		num--;
> +	}
> +
> +	return st->bops->read_block(st->dev, num, data);
> +}
> +
> +static irqreturn_t ad7606_trigger_handler(int irq, void *p)
> +{
> +	struct iio_poll_func *pf = p;
> +	struct iio_dev *indio_dev = pf->indio_dev;
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	mutex_lock(&st->lock);
> +
> +	ret = ad7606_read_samples(st);
> +	if (ret == 0)
> +		iio_push_to_buffers_with_timestamp(indio_dev, st->data,
> +						   iio_get_time_ns(indio_dev));
> +
> +	iio_trigger_notify_done(indio_dev->trig);
> +	/* The rising edge of the CONVST signal starts a new conversion. */
> +	gpiod_set_value(st->gpio_convst, 1);
> +
> +	mutex_unlock(&st->lock);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	gpiod_set_value(st->gpio_convst, 1);
> +	ret = wait_for_completion_timeout(&st->completion,
> +					  msecs_to_jiffies(1000));
> +	if (!ret) {
> +		ret = -ETIMEDOUT;
> +		goto error_ret;
> +	}
> +
> +	ret = ad7606_read_samples(st);
> +	if (ret == 0)
> +		ret = st->data[ch];
> +
> +error_ret:
> +	gpiod_set_value(st->gpio_convst, 0);
> +
> +	return ret;
> +}
> +
> +static int ad7606_read_raw(struct iio_dev *indio_dev,
> +			   struct iio_chan_spec const *chan,
> +			   int *val,
> +			   int *val2,
> +			   long m)
> +{
> +	int ret;
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	switch (m) {
> +	case IIO_CHAN_INFO_RAW:
> +		ret = iio_device_claim_direct_mode(indio_dev);
> +		if (ret)
> +			return ret;
> +
> +		ret = ad7606_scan_direct(indio_dev, chan->address);
> +		iio_device_release_direct_mode(indio_dev);
> +
> +		if (ret < 0)
> +			return ret;
> +		*val = (short)ret;
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_SCALE:
> +		*val = 0;
> +		*val2 = scale_avail[st->range];
> +		return IIO_VAL_INT_PLUS_MICRO;
> +	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> +		*val = st->oversampling;
> +		return IIO_VAL_INT;
> +	}
> +	return -EINVAL;
> +}
> +
> +static ssize_t in_voltage_scale_available_show(struct device *dev,
> +					       struct device_attribute *attr,
> +					       char *buf)
> +{
> +	int i, len = 0;
> +
> +	for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
> +		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
> +				 scale_avail[i]);
> +
> +	buf[len - 1] = '\n';
> +
> +	return len;
> +}
> +
> +static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
> +
> +static int ad7606_write_raw(struct iio_dev *indio_dev,
> +			    struct iio_chan_spec const *chan,
> +			    int val,
> +			    int val2,
> +			    long mask)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +	DECLARE_BITMAP(values, 3);
> +	int i;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_SCALE:
> +		mutex_lock(&st->lock);
> +		i = find_closest(val2, scale_avail, ARRAY_SIZE(scale_avail));
> +		gpiod_set_value(st->gpio_range, i);
> +		st->range = i;
> +		mutex_unlock(&st->lock);
> +
> +		return 0;
> +	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> +		if (val2)
> +			return -EINVAL;
> +		i = find_closest(val, ad7606_oversampling_avail,
> +				 ARRAY_SIZE(ad7606_oversampling_avail));
> +
> +		values[0] = i;
> +
> +		mutex_lock(&st->lock);
> +		gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
> +				      st->gpio_os->info, values);
> +		st->oversampling = ad7606_oversampling_avail[i];
> +		mutex_unlock(&st->lock);
> +
> +		return 0;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static IIO_CONST_ATTR(oversampling_ratio_available, "1 2 4 8 16 32 64");
> +
> +static struct attribute *ad7606_attributes_os_and_range[] = {
> +	&iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
> +	&iio_const_attr_oversampling_ratio_available.dev_attr.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group ad7606_attribute_group_os_and_range = {
> +	.attrs = ad7606_attributes_os_and_range,
> +};
> +
> +static struct attribute *ad7606_attributes_os[] = {
> +	&iio_const_attr_oversampling_ratio_available.dev_attr.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group ad7606_attribute_group_os = {
> +	.attrs = ad7606_attributes_os,
> +};
> +
> +static struct attribute *ad7606_attributes_range[] = {
> +	&iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group ad7606_attribute_group_range = {
> +	.attrs = ad7606_attributes_range,
> +};
> +
> +#define AD760X_CHANNEL(num, mask) {				\
> +		.type = IIO_VOLTAGE,				\
> +		.indexed = 1,					\
> +		.channel = num,					\
> +		.address = num,					\
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
> +		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
> +		.info_mask_shared_by_all = mask,		\
> +		.scan_index = num,				\
> +		.scan_type = {					\
> +			.sign = 's',				\
> +			.realbits = 16,				\
> +			.storagebits = 16,			\
> +			.endianness = IIO_CPU,			\
> +		},						\
> +}
> +
> +#define AD7605_CHANNEL(num)	\
> +	AD760X_CHANNEL(num, 0)
> +
> +#define AD7606_CHANNEL(num)	\
> +	AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
> +
> +static const struct iio_chan_spec ad7605_channels[] = {
> +	IIO_CHAN_SOFT_TIMESTAMP(4),
> +	AD7605_CHANNEL(0),
> +	AD7605_CHANNEL(1),
> +	AD7605_CHANNEL(2),
> +	AD7605_CHANNEL(3),
> +};
> +
> +static const struct iio_chan_spec ad7606_channels[] = {
> +	IIO_CHAN_SOFT_TIMESTAMP(8),
> +	AD7606_CHANNEL(0),
> +	AD7606_CHANNEL(1),
> +	AD7606_CHANNEL(2),
> +	AD7606_CHANNEL(3),
> +	AD7606_CHANNEL(4),
> +	AD7606_CHANNEL(5),
> +	AD7606_CHANNEL(6),
> +	AD7606_CHANNEL(7),
> +};
> +
> +static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
> +	/* More devices added in future */
> +	[ID_AD7605_4] = {
> +		.channels = ad7605_channels,
> +		.num_channels = 5,
> +	},
> +	[ID_AD7606_8] = {
> +		.channels = ad7606_channels,
> +		.num_channels = 9,
> +		.has_oversampling = true,
> +	},
> +	[ID_AD7606_6] = {
> +		.channels = ad7606_channels,
> +		.num_channels = 7,
> +		.has_oversampling = true,
> +	},
> +	[ID_AD7606_4] = {
> +		.channels = ad7606_channels,
> +		.num_channels = 5,
> +		.has_oversampling = true,
> +	},
> +};
> +
> +static int ad7606_request_gpios(struct ad7606_state *st)
> +{
> +	struct device *dev = st->dev;
> +
> +	st->gpio_convst = devm_gpiod_get(dev, "adi,conversion-start",
> +					 GPIOD_OUT_LOW);
> +	if (IS_ERR(st->gpio_convst))
> +		return PTR_ERR(st->gpio_convst);
> +
> +	st->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> +	if (IS_ERR(st->gpio_reset))
> +		return PTR_ERR(st->gpio_reset);
> +
> +	st->gpio_range = devm_gpiod_get_optional(dev, "adi,range",
> +						 GPIOD_OUT_LOW);
> +	if (IS_ERR(st->gpio_range))
> +		return PTR_ERR(st->gpio_range);
> +
> +	st->gpio_standby = devm_gpiod_get_optional(dev, "standby",
> +						   GPIOD_OUT_HIGH);
> +	if (IS_ERR(st->gpio_standby))
> +		return PTR_ERR(st->gpio_standby);
> +
> +	st->gpio_frstdata = devm_gpiod_get_optional(dev, "adi,first-data",
> +						    GPIOD_IN);
> +	if (IS_ERR(st->gpio_frstdata))
> +		return PTR_ERR(st->gpio_frstdata);
> +
> +	if (!st->chip_info->has_oversampling)
> +		return 0;
> +
> +	st->gpio_os = devm_gpiod_get_array_optional(dev,
> +						    "adi,oversampling-ratio",
> +						    GPIOD_OUT_LOW);
> +	return PTR_ERR_OR_ZERO(st->gpio_os);
> +}
> +
> +/*
> + * The BUSY signal indicates when conversions are in progress, so when a rising
> + * edge of CONVST is applied, BUSY goes logic high and transitions low at the
> + * end of the entire conversion process. The falling edge of the BUSY signal
> + * triggers this interrupt.
> + */
> +static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
> +{
> +	struct iio_dev *indio_dev = dev_id;
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	if (iio_buffer_enabled(indio_dev)) {
> +		gpiod_set_value(st->gpio_convst, 0);
> +		iio_trigger_poll_chained(st->trig);
> +	} else {
> +		complete(&st->completion);
> +	}
> +
> +	return IRQ_HANDLED;
> +};
> +
> +static int ad7606_validate_trigger(struct iio_dev *indio_dev,
> +				   struct iio_trigger *trig)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	if (st->trig != trig)
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
> +static int ad7606_buffer_postenable(struct iio_dev *indio_dev)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	iio_triggered_buffer_postenable(indio_dev);
> +	gpiod_set_value(st->gpio_convst, 1);
> +
> +	return 0;
> +}
> +
> +static int ad7606_buffer_predisable(struct iio_dev *indio_dev)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	reinit_completion(&st->completion);
> +	gpiod_set_value(st->gpio_convst, 1);
> +	ret = wait_for_completion_timeout(&st->completion,
> +					  msecs_to_jiffies(1000));
> +	gpiod_set_value(st->gpio_convst, 0);
> +
> +	return iio_triggered_buffer_predisable(indio_dev);
> +}
> +
> +static const struct iio_buffer_setup_ops ad7606_buffer_ops = {
> +	.postenable = &ad7606_buffer_postenable,
> +	.predisable = &ad7606_buffer_predisable,
> +};
> +
> +static const struct iio_info ad7606_info_no_os_or_range = {
> +	.read_raw = &ad7606_read_raw,
> +	.validate_trigger = &ad7606_validate_trigger,
> +};
> +
> +static const struct iio_info ad7606_info_os_and_range = {
> +	.read_raw = &ad7606_read_raw,
> +	.write_raw = &ad7606_write_raw,
> +	.attrs = &ad7606_attribute_group_os_and_range,
> +	.validate_trigger = &ad7606_validate_trigger,
> +};
> +
> +static const struct iio_info ad7606_info_os = {
> +	.read_raw = &ad7606_read_raw,
> +	.write_raw = &ad7606_write_raw,
> +	.attrs = &ad7606_attribute_group_os,
> +	.validate_trigger = &ad7606_validate_trigger,
> +};
> +
> +static const struct iio_info ad7606_info_range = {
> +	.read_raw = &ad7606_read_raw,
> +	.write_raw = &ad7606_write_raw,
> +	.attrs = &ad7606_attribute_group_range,
> +	.validate_trigger = &ad7606_validate_trigger,
> +};
> +
> +static const struct iio_trigger_ops ad7606_trigger_ops = {
> +	.validate_device = iio_trigger_validate_own_device,
> +};
> +
> +static void ad7606_regulator_disable(void *data)
> +{
> +	struct ad7606_state *st = data;
> +
> +	regulator_disable(st->reg);
> +}
> +
> +int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
> +		 const char *name, unsigned int id,
> +		 const struct ad7606_bus_ops *bops)
> +{
> +	struct ad7606_state *st;
> +	int ret;
> +	struct iio_dev *indio_dev;
> +
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
> +	if (!indio_dev)
> +		return -ENOMEM;
> +
> +	st = iio_priv(indio_dev);
> +	dev_set_drvdata(dev, indio_dev);
> +
> +	st->dev = dev;
> +	mutex_init(&st->lock);
> +	st->bops = bops;
> +	st->base_address = base_address;
> +	/* tied to logic low, analog input range is +/- 5V */
> +	st->range = 0;
> +	st->oversampling = 1;
> +
> +	st->reg = devm_regulator_get(dev, "avcc");
> +	if (IS_ERR(st->reg))
> +		return PTR_ERR(st->reg);
> +
> +	ret = regulator_enable(st->reg);
> +	if (ret) {
> +		dev_err(dev, "Failed to enable specified AVcc supply\n");
> +		return ret;
> +	}
> +
> +	ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
> +	if (ret)
> +		return ret;
> +
> +	st->chip_info = &ad7606_chip_info_tbl[id];
> +
> +	ret = ad7606_request_gpios(st);
> +	if (ret)
> +		return ret;
> +
> +	indio_dev->dev.parent = dev;
> +	if (st->gpio_os) {
> +		if (st->gpio_range)
> +			indio_dev->info = &ad7606_info_os_and_range;
> +		else
> +			indio_dev->info = &ad7606_info_os;
> +	} else {
> +		if (st->gpio_range)
> +			indio_dev->info = &ad7606_info_range;
> +		else
> +			indio_dev->info = &ad7606_info_no_os_or_range;
> +	}
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +	indio_dev->name = name;
> +	indio_dev->channels = st->chip_info->channels;
> +	indio_dev->num_channels = st->chip_info->num_channels;
> +
> +	init_completion(&st->completion);
> +
> +	ret = ad7606_reset(st);
> +	if (ret)
> +		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
> +
> +	st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> +					  indio_dev->name, indio_dev->id);
> +	if (!st->trig)
> +		return -ENOMEM;
> +
> +	st->trig->ops = &ad7606_trigger_ops;
> +	st->trig->dev.parent = dev;
> +	iio_trigger_set_drvdata(st->trig, indio_dev);
> +	ret = devm_iio_trigger_register(dev, st->trig);
> +	if (ret)
> +		return ret;
> +
> +	indio_dev->trig = iio_trigger_get(st->trig);
> +
> +	ret = devm_request_threaded_irq(dev, irq,
> +					NULL,
> +					&ad7606_interrupt,
> +					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
> +					name, indio_dev);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> +					      &iio_pollfunc_store_time,
> +					      &ad7606_trigger_handler,
> +					      &ad7606_buffer_ops);
> +	if (ret)
> +		return ret;
> +
> +	return devm_iio_device_register(dev, indio_dev);
> +}
> +EXPORT_SYMBOL_GPL(ad7606_probe);
> +
> +#ifdef CONFIG_PM_SLEEP
> +
> +static int ad7606_suspend(struct device *dev)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	if (st->gpio_standby) {
> +		gpiod_set_value(st->gpio_range, 1);
> +		gpiod_set_value(st->gpio_standby, 0);
> +	}
> +
> +	return 0;
> +}
> +
> +static int ad7606_resume(struct device *dev)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	if (st->gpio_standby) {
> +		gpiod_set_value(st->gpio_range, st->range);
> +		gpiod_set_value(st->gpio_standby, 1);
> +		ad7606_reset(st);
> +	}
> +
> +	return 0;
> +}
> +
> +SIMPLE_DEV_PM_OPS(ad7606_pm_ops, ad7606_suspend, ad7606_resume);
> +EXPORT_SYMBOL_GPL(ad7606_pm_ops);
> +
> +#endif
> +
> +MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
> +MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
> new file mode 100644
> index 0000000..40433af
> --- /dev/null
> +++ b/drivers/iio/adc/ad7606.h
> @@ -0,0 +1,99 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * AD7606 ADC driver
> + *
> + * Copyright 2011 Analog Devices Inc.
> + */
> +
> +#ifndef IIO_ADC_AD7606_H_
> +#define IIO_ADC_AD7606_H_
> +
> +/**
> + * struct ad7606_chip_info - chip specific information
> + * @channels:		channel specification
> + * @num_channels:	number of channels
> + * @has_oversampling:   whether the device has oversampling support
> + */
> +struct ad7606_chip_info {
> +	const struct iio_chan_spec	*channels;
> +	unsigned int			num_channels;
> +	bool				has_oversampling;
> +};
> +
> +/**
> + * struct ad7606_state - driver instance specific data
> + * @dev		pointer to kernel device
> + * @chip_info		entry in the table of chips that describes this device
> + * @reg		regulator info for the the power supply of the device
> + * @bops		bus operations (SPI or parallel)
> + * @range		voltage range selection, selects which scale to apply
> + * @oversampling	oversampling selection
> + * @base_address	address from where to read data in parallel operation
> + * @lock		protect sensor state from concurrent accesses to GPIOs
> + * @gpio_convst	GPIO descriptor for conversion start signal (CONVST)
> + * @gpio_reset		GPIO descriptor for device hard-reset
> + * @gpio_range		GPIO descriptor for range selection
> + * @gpio_standby	GPIO descriptor for stand-by signal (STBY),
> + *			controls power-down mode of device
> + * @gpio_frstdata	GPIO descriptor for reading from device when data
> + *			is being read on the first channel
> + * @gpio_os		GPIO descriptors to control oversampling on the device
> + * @complete		completion to indicate end of conversion
> + * @trig		The IIO trigger associated with the device.
> + * @data		buffer for reading data from the device
> + */
> +struct ad7606_state {
> +	struct device			*dev;
> +	const struct ad7606_chip_info	*chip_info;
> +	struct regulator		*reg;
> +	const struct ad7606_bus_ops	*bops;
> +	unsigned int			range;
> +	unsigned int			oversampling;
> +	void __iomem			*base_address;
> +
> +	struct mutex			lock; /* protect sensor state */
> +	struct gpio_desc		*gpio_convst;
> +	struct gpio_desc		*gpio_reset;
> +	struct gpio_desc		*gpio_range;
> +	struct gpio_desc		*gpio_standby;
> +	struct gpio_desc		*gpio_frstdata;
> +	struct gpio_descs		*gpio_os;
> +	struct iio_trigger		*trig;
> +	struct completion		completion;
> +
> +	/*
> +	 * DMA (thus cache coherency maintenance) requires the
> +	 * transfer buffers to live in their own cache lines.
> +	 * 8 * 16-bit samples + 64-bit timestamp
> +	 */
> +	unsigned short			data[12] ____cacheline_aligned;
> +};
> +
> +/**
> + * struct ad7606_bus_ops - driver bus operations
> + * @read_block		function pointer for reading blocks of data
> + */
> +struct ad7606_bus_ops {
> +	/* more methods added in future? */
> +	int (*read_block)(struct device *dev, int num, void *data);
> +};
> +
> +int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
> +		 const char *name, unsigned int id,
> +		 const struct ad7606_bus_ops *bops);
> +
> +enum ad7606_supported_device_ids {
> +	ID_AD7605_4,
> +	ID_AD7606_8,
> +	ID_AD7606_6,
> +	ID_AD7606_4
> +};
> +
> +#ifdef CONFIG_PM_SLEEP
> +extern const struct dev_pm_ops ad7606_pm_ops;
> +#define AD7606_PM_OPS (&ad7606_pm_ops)
> +#else
> +#define AD7606_PM_OPS NULL
> +#endif
> +
> +#endif /* IIO_ADC_AD7606_H_ */
> diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c
> new file mode 100644
> index 0000000..32c7069
> --- /dev/null
> +++ b/drivers/iio/adc/ad7606_par.c
> @@ -0,0 +1,105 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * AD7606 Parallel Interface ADC driver
> + *
> + * Copyright 2011 Analog Devices Inc.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/types.h>
> +#include <linux/err.h>
> +#include <linux/io.h>
> +
> +#include <linux/iio/iio.h>
> +#include "ad7606.h"
> +
> +static int ad7606_par16_read_block(struct device *dev,
> +				   int count, void *buf)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	insw((unsigned long)st->base_address, buf, count);
> +
> +	return 0;
> +}
> +
> +static const struct ad7606_bus_ops ad7606_par16_bops = {
> +	.read_block = ad7606_par16_read_block,
> +};
> +
> +static int ad7606_par8_read_block(struct device *dev,
> +				  int count, void *buf)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	insb((unsigned long)st->base_address, buf, count * 2);
> +
> +	return 0;
> +}
> +
> +static const struct ad7606_bus_ops ad7606_par8_bops = {
> +	.read_block = ad7606_par8_read_block,
> +};
> +
> +static int ad7606_par_probe(struct platform_device *pdev)
> +{
> +	const struct platform_device_id *id = platform_get_device_id(pdev);
> +	struct resource *res;
> +	void __iomem *addr;
> +	resource_size_t remap_size;
> +	int irq;
> +
> +	irq = platform_get_irq(pdev, 0);
> +	if (irq < 0) {
> +		dev_err(&pdev->dev, "no irq: %d\n", irq);
> +		return irq;
> +	}
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	addr = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(addr))
> +		return PTR_ERR(addr);
> +
> +	remap_size = resource_size(res);
> +
> +	return ad7606_probe(&pdev->dev, irq, addr,
> +			    id->name, id->driver_data,
> +			    remap_size > 1 ? &ad7606_par16_bops :
> +			    &ad7606_par8_bops);
> +}
> +
> +static const struct platform_device_id ad7606_driver_ids[] = {
> +	{ .name	= "ad7605-4", .driver_data = ID_AD7605_4, },
> +	{ .name	= "ad7606-4", .driver_data = ID_AD7606_4, },
> +	{ .name	= "ad7606-6", .driver_data = ID_AD7606_6, },
> +	{ .name	= "ad7606-8", .driver_data = ID_AD7606_8, },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
> +
> +static const struct of_device_id ad7606_of_match[] = {
> +	{ .compatible = "adi,ad7605-4" },
> +	{ .compatible = "adi,ad7606-4" },
> +	{ .compatible = "adi,ad7606-6" },
> +	{ .compatible = "adi,ad7606-8" },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, ad7606_of_match);
> +
> +static struct platform_driver ad7606_driver = {
> +	.probe = ad7606_par_probe,
> +	.id_table = ad7606_driver_ids,
> +	.driver = {
> +		.name = "ad7606",
> +		.pm = AD7606_PM_OPS,
> +		.of_match_table = ad7606_of_match,
> +	},
> +};
> +module_platform_driver(ad7606_driver);
> +
> +MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
> +MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
> new file mode 100644
> index 0000000..b628389
> --- /dev/null
> +++ b/drivers/iio/adc/ad7606_spi.c
> @@ -0,0 +1,82 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * AD7606 SPI ADC driver
> + *
> + * Copyright 2011 Analog Devices Inc.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/spi/spi.h>
> +#include <linux/types.h>
> +#include <linux/err.h>
> +
> +#include <linux/iio/iio.h>
> +#include "ad7606.h"
> +
> +#define MAX_SPI_FREQ_HZ		23500000	/* VDRIVE above 4.75 V */
> +
> +static int ad7606_spi_read_block(struct device *dev,
> +				 int count, void *buf)
> +{
> +	struct spi_device *spi = to_spi_device(dev);
> +	int i, ret;
> +	unsigned short *data = buf;
> +	__be16 *bdata = buf;
> +
> +	ret = spi_read(spi, buf, count * 2);
> +	if (ret < 0) {
> +		dev_err(&spi->dev, "SPI read error\n");
> +		return ret;
> +	}
> +
> +	for (i = 0; i < count; i++)
> +		data[i] = be16_to_cpu(bdata[i]);
> +
> +	return 0;
> +}
> +
> +static const struct ad7606_bus_ops ad7606_spi_bops = {
> +	.read_block = ad7606_spi_read_block,
> +};
> +
> +static int ad7606_spi_probe(struct spi_device *spi)
> +{
> +	const struct spi_device_id *id = spi_get_device_id(spi);
> +
> +	return ad7606_probe(&spi->dev, spi->irq, NULL,
> +			    id->name, id->driver_data,
> +			    &ad7606_spi_bops);
> +}
> +
> +static const struct spi_device_id ad7606_id_table[] = {
> +	{ "ad7605-4", ID_AD7605_4 },
> +	{ "ad7606-4", ID_AD7606_4 },
> +	{ "ad7606-6", ID_AD7606_6 },
> +	{ "ad7606-8", ID_AD7606_8 },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(spi, ad7606_id_table);
> +
> +static const struct of_device_id ad7606_of_match[] = {
> +	{ .compatible = "adi,ad7605-4" },
> +	{ .compatible = "adi,ad7606-4" },
> +	{ .compatible = "adi,ad7606-6" },
> +	{ .compatible = "adi,ad7606-8" },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, ad7606_of_match);
> +
> +static struct spi_driver ad7606_driver = {
> +	.driver = {
> +		.name = "ad7606",
> +		.of_match_table = ad7606_of_match,
> +		.pm = AD7606_PM_OPS,
> +	},
> +	.probe = ad7606_spi_probe,
> +	.id_table = ad7606_id_table,
> +};
> +module_spi_driver(ad7606_driver);
> +
> +MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
> +MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
> +MODULE_LICENSE("GPL");

Removed the rest as I'm assuming this is a straight move now!

Thanks,

Joanthan


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq
  2018-12-16 13:49   ` Jonathan Cameron
@ 2018-12-17 10:28     ` Popa, Stefan Serban
  0 siblings, 0 replies; 26+ messages in thread
From: Popa, Stefan Serban @ 2018-12-17 10:28 UTC (permalink / raw)
  To: jic23
  Cc: linux-kernel, robh+dt, knaack.h, lars, Hennerich, Michael,
	linux-iio, devel, mark.rutland, pmeerw, stefan.popa, gregkh

On Du, 2018-12-16 at 13:49 +0000, Jonathan Cameron wrote:
> On Thu, 13 Dec 2018 14:46:17 +0200
> Stefan Popa <stefan.popa@analog.com> wrote:
> 
> > 
> > This patch replaces the use of a polling ring buffer with a threaded
> > interrupt.
> > 
> > Enabling the buffer sets the CONVST signal to high. When the rising
> > edge
> > of the CONVST is applied, BUSY signal goes logic high and transitions
> > low
> > at the end of the entire conversion process. The falling edge of the
> > BUSY
> > signal triggers the interrupt.
> > 
> > ad7606_trigger_handler() is used as bottom half of the poll function.
> > It reads data from the device and stores it in the internal buffer.
> > 
> > Signed-off-by: Stefan Popa <stefan.popa@analog.com>
> I'd like a little more info as comments in this one. See below.
> Which is another way of saying I have no idea what is going on :)
> 
> Thanks,
> 
> Jonathan.
> 

Hi Jonathan,
Thank you for the review. It turns out that there is no reason to trigger a
conversion before disabling the buffer. I will remove it in v2.

Thank you!
-Stefan

> > 
> > ---
> >  drivers/staging/iio/adc/ad7606.c | 116 +++++++++++++++++++++++++++++
> > ----------
> >  drivers/staging/iio/adc/ad7606.h |   6 +-
> >  2 files changed, 89 insertions(+), 33 deletions(-)
> > 
> > diff --git a/drivers/staging/iio/adc/ad7606.c
> > b/drivers/staging/iio/adc/ad7606.c
> > index 7191d51..13aeeec 100644
> > --- a/drivers/staging/iio/adc/ad7606.c
> > +++ b/drivers/staging/iio/adc/ad7606.c
> > @@ -21,6 +21,7 @@
> >  #include <linux/iio/sysfs.h>
> >  #include <linux/iio/buffer.h>
> >  #include <linux/iio/trigger_consumer.h>
> > +#include <linux/iio/trigger.h>
> >  #include <linux/iio/triggered_buffer.h>
> >  
> >  #include "ad7606.h"
> > @@ -81,36 +82,24 @@ static int ad7606_read_samples(struct ad7606_state
> > *st)
> >  static irqreturn_t ad7606_trigger_handler(int irq, void *p)
> >  {
> >  	struct iio_poll_func *pf = p;
> > -	struct ad7606_state *st = iio_priv(pf->indio_dev);
> > -
> > -	gpiod_set_value(st->gpio_convst, 1);
> > -
> > -	return IRQ_HANDLED;
> > -}
> > -
> > -/**
> > - * ad7606_poll_bh_to_ring() bh of trigger launched polling to ring
> > buffer
> > - * @work_s:	the work struct through which this was scheduled
> > - *
> > - * Currently there is no option in this driver to disable the saving
> > of
> > - * timestamps within the ring.
> > - * I think the one copy of this at a time was to avoid problems if the
> > - * trigger was set far too high and the reads then locked up the
> > computer.
> > - **/
> > -static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
> > -{
> > -	struct ad7606_state *st = container_of(work_s, struct
> > ad7606_state,
> > -						poll_work);
> > -	struct iio_dev *indio_dev = iio_priv_to_dev(st);
> > +	struct iio_dev *indio_dev = pf->indio_dev;
> > +	struct ad7606_state *st = iio_priv(indio_dev);
> >  	int ret;
> >  
> > +	mutex_lock(&st->lock);
> > +
> >  	ret = ad7606_read_samples(st);
> >  	if (ret == 0)
> >  		iio_push_to_buffers_with_timestamp(indio_dev, st-
> > >data,
> >  						   iio_get_time_ns(ind
> > io_dev));
> >  
> > -	gpiod_set_value(st->gpio_convst, 0);
> >  	iio_trigger_notify_done(indio_dev->trig);
> > +	/* The rising edge of the CONVST signal starts a new
> > conversion. */
> > +	gpiod_set_value(st->gpio_convst, 1);
> > +
> > +	mutex_unlock(&st->lock);
> > +
> > +	return IRQ_HANDLED;
> >  }
> >  
> >  static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int
> > ch)
> > @@ -378,8 +367,11 @@ static int ad7606_request_gpios(struct
> > ad7606_state *st)
> >  	return PTR_ERR_OR_ZERO(st->gpio_os);
> >  }
> >  
> > -/**
> > - *  Interrupt handler
> > +/*
> > + * The BUSY signal indicates when conversions are in progress, so when
> > a rising
> > + * edge of CONVST is applied, BUSY goes logic high and transitions low
> > at the
> > + * end of the entire conversion process. The falling edge of the BUSY
> > signal
> > + * triggers this interrupt.
> >   */
> >  static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
> >  {
> > @@ -387,7 +379,8 @@ static irqreturn_t ad7606_interrupt(int irq, void
> > *dev_id)
> >  	struct ad7606_state *st = iio_priv(indio_dev);
> >  
> >  	if (iio_buffer_enabled(indio_dev)) {
> > -		schedule_work(&st->poll_work);
> > +		gpiod_set_value(st->gpio_convst, 0);
> > +		iio_trigger_poll_chained(st->trig);
> >  	} else {
> >  		complete(&st->completion);
> >  	}
> > @@ -395,26 +388,74 @@ static irqreturn_t ad7606_interrupt(int irq, void
> > *dev_id)
> >  	return IRQ_HANDLED;
> >  };
> >  
> > +static int ad7606_validate_trigger(struct iio_dev *indio_dev,
> > +				   struct iio_trigger *trig)
> > +{
> > +	struct ad7606_state *st = iio_priv(indio_dev);
> > +
> > +	if (st->trig != trig)
> > +		return -EINVAL;
> > +
> > +	return 0;
> > +}
> > +
> > +static int ad7606_buffer_postenable(struct iio_dev *indio_dev)
> > +{
> > +	struct ad7606_state *st = iio_priv(indio_dev);
> > +
> > +	iio_triggered_buffer_postenable(indio_dev);
> > +	gpiod_set_value(st->gpio_convst, 1);
> > +
> > +	return 0;
> > +}
> > +
> > +static int ad7606_buffer_predisable(struct iio_dev *indio_dev)
> > +{
> > +	struct ad7606_state *st = iio_priv(indio_dev);
> > +	int ret;
> > +
> > +	reinit_completion(&st->completion);
> > +	gpiod_set_value(st->gpio_convst, 1);
> > +	ret = wait_for_completion_timeout(&st->completion,
> > +					  msecs_to_jiffies(1000));
> Along with Dan's comment. I'd like to see a comment here on what
> is actually going on.  Not immediately obvious a conversion should
> be triggered to disable the buffer...
> 
> I'll guess there is a race against the normal handler that we
> are closing with this dance, but that race needs explaining.
> 
> > 
> > +	gpiod_set_value(st->gpio_convst, 0);
> > +
> > +	return iio_triggered_buffer_predisable(indio_dev);
> > +}
> > +
> > +static const struct iio_buffer_setup_ops ad7606_buffer_ops = {
> > +	.postenable = &ad7606_buffer_postenable,
> > +	.predisable = &ad7606_buffer_predisable,
> > +};
> > +
> >  static const struct iio_info ad7606_info_no_os_or_range = {
> >  	.read_raw = &ad7606_read_raw,
> > +	.validate_trigger = &ad7606_validate_trigger,
> >  };
> >  
> >  static const struct iio_info ad7606_info_os_and_range = {
> >  	.read_raw = &ad7606_read_raw,
> >  	.write_raw = &ad7606_write_raw,
> >  	.attrs = &ad7606_attribute_group_os_and_range,
> > +	.validate_trigger = &ad7606_validate_trigger,
> >  };
> >  
> >  static const struct iio_info ad7606_info_os = {
> >  	.read_raw = &ad7606_read_raw,
> >  	.write_raw = &ad7606_write_raw,
> >  	.attrs = &ad7606_attribute_group_os,
> > +	.validate_trigger = &ad7606_validate_trigger,
> >  };
> >  
> >  static const struct iio_info ad7606_info_range = {
> >  	.read_raw = &ad7606_read_raw,
> >  	.write_raw = &ad7606_write_raw,
> >  	.attrs = &ad7606_attribute_group_range,
> > +	.validate_trigger = &ad7606_validate_trigger,
> > +};
> > +
> > +static const struct iio_trigger_ops ad7606_trigger_ops = {
> > +	.validate_device = iio_trigger_validate_own_device,
> >  };
> >  
> >  static void ad7606_regulator_disable(void *data)
> > @@ -446,7 +487,6 @@ int ad7606_probe(struct device *dev, int irq, void
> > __iomem *base_address,
> >  	/* tied to logic low, analog input range is +/- 5V */
> >  	st->range = 0;
> >  	st->oversampling = 1;
> > -	INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring);
> >  
> >  	st->reg = devm_regulator_get(dev, "avcc");
> >  	if (IS_ERR(st->reg))
> > @@ -491,14 +531,32 @@ int ad7606_probe(struct device *dev, int irq,
> > void __iomem *base_address,
> >  	if (ret)
> >  		dev_warn(st->dev, "failed to RESET: no RESET GPIO
> > specified\n");
> >  
> > -	ret = devm_request_irq(dev, irq, ad7606_interrupt,
> > IRQF_TRIGGER_FALLING,
> > -			       name, indio_dev);
> > +	st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> > +					  indio_dev->name, indio_dev-
> > >id);
> > +	if (!st->trig)
> > +		return -ENOMEM;
> > +
> > +	st->trig->ops = &ad7606_trigger_ops;
> > +	st->trig->dev.parent = dev;
> > +	iio_trigger_set_drvdata(st->trig, indio_dev);
> > +	ret = devm_iio_trigger_register(dev, st->trig);
> > +	if (ret)
> > +		return ret;
> > +
> > +	indio_dev->trig = iio_trigger_get(st->trig);
> > +
> > +	ret = devm_request_threaded_irq(dev, irq,
> > +					NULL,
> > +					&ad7606_interrupt,
> > +					IRQF_TRIGGER_FALLING |
> > IRQF_ONESHOT,
> > +					name, indio_dev);
> >  	if (ret)
> >  		return ret;
> >  
> >  	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> > +					      &iio_pollfunc_store_time
> > ,
> >  					      &ad7606_trigger_handler,
> > -					      NULL, NULL);
> > +					      &ad7606_buffer_ops);
> >  	if (ret)
> >  		return ret;
> >  
> > diff --git a/drivers/staging/iio/adc/ad7606.h
> > b/drivers/staging/iio/adc/ad7606.h
> > index 70486ef..b238e9b 100644
> > --- a/drivers/staging/iio/adc/ad7606.h
> > +++ b/drivers/staging/iio/adc/ad7606.h
> > @@ -26,8 +26,6 @@ struct ad7606_chip_info {
> >   * @dev		pointer to kernel device
> >   * @chip_info		entry in the table of chips that
> > describes this device
> >   * @reg		regulator info for the the power supply of the
> > device
> > - * @poll_work		work struct for continuously reading data
> > from the device
> > - *			into an IIO triggered buffer
> >   * @bops		bus operations (SPI or parallel)
> >   * @range		voltage range selection, selects which scale
> > to apply
> >   * @oversampling	oversampling selection
> > @@ -42,14 +40,13 @@ struct ad7606_chip_info {
> >   *			is being read on the first channel
> >   * @gpio_os		GPIO descriptors to control oversampling on
> > the device
> >   * @complete		completion to indicate end of conversion
> > + * @trig		The IIO trigger associated with the device.
> >   * @data		buffer for reading data from the device
> >   */
> > -
> >  struct ad7606_state {
> >  	struct device			*dev;
> >  	const struct ad7606_chip_info	*chip_info;
> >  	struct regulator		*reg;
> > -	struct work_struct		poll_work;
> >  	const struct ad7606_bus_ops	*bops;
> >  	unsigned int			range;
> >  	unsigned int			oversampling;
> > @@ -62,6 +59,7 @@ struct ad7606_state {
> >  	struct gpio_desc		*gpio_standby;
> >  	struct gpio_desc		*gpio_frstdata;
> >  	struct gpio_descs		*gpio_os;
> > +	struct iio_trigger		*trig;
> >  	struct completion		completion;
> >  
> >  	/*
^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 10/11] staging: iio: adc: ad7606: Move out of staging
  2018-12-13 12:46 ` [PATCH 10/11] staging: iio: adc: ad7606: Move out of staging Stefan Popa
  2018-12-16 14:14   ` Jonathan Cameron
@ 2018-12-20 19:45   ` kbuild test robot
  1 sibling, 0 replies; 26+ messages in thread
From: kbuild test robot @ 2018-12-20 19:45 UTC (permalink / raw)
  To: Stefan Popa
  Cc: kbuild-all, jic23, robh+dt, mark.rutland, Stefan Popa,
	Michael.Hennerich, knaack.h, lars, pmeerw, gregkh, linux-kernel,
	linux-iio, devel, stefan.popa

[-- Attachment #1: Type: text/plain, Size: 880 bytes --]

Hi Stefan,

I love your patch! Yet something to improve:

[auto build test ERROR on iio/togreg]
[cannot apply to v4.20-rc7]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Stefan-Popa/staging-iio-adc-ad7606-Simplify-the-Kconfing-menu/20181216-132154
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: um-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=um 

All errors (new ones prefixed by >>):

>> ERROR: "devm_ioremap_resource" [drivers/iio/adc/ad7606_par.ko] undefined!

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 20472 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, back to index

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13 12:46 [PATCH 00/11] staging: iio: ad7606: Move out of staging Stefan Popa
2018-12-13 12:46 ` [PATCH 01/11] staging: iio: adc: ad7606: Simplify the Kconfing menu Stefan Popa
2018-12-13 15:37   ` Rob Herring
2018-12-13 12:46 ` [PATCH 02/11] staging: iio: adc: ad7606: Use SPDX identifier Stefan Popa
2018-12-13 13:21   ` Dan Carpenter
2018-12-13 12:46 ` [PATCH 03/11] staging: iio: adc: ad7606: Use wait-for-completion handler Stefan Popa
2018-12-16 13:41   ` Jonathan Cameron
2018-12-13 12:46 ` [PATCH 04/11] staging: iio: adc: ad7606: Use devm functions in probe Stefan Popa
2018-12-16 13:43   ` Jonathan Cameron
2018-12-13 12:46 ` [PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq Stefan Popa
2018-12-13 13:28   ` Dan Carpenter
2018-12-16 13:49   ` Jonathan Cameron
2018-12-17 10:28     ` Popa, Stefan Serban
2018-12-13 12:46 ` [PATCH 06/11] staging: iio: adc: ad7606: Use find_closest() macro Stefan Popa
2018-12-16 13:51   ` Jonathan Cameron
2018-12-13 12:46 ` [PATCH 07/11] staging: iio: adc: ad7606: Use vendor prefix for DT properties Stefan Popa
2018-12-16 13:53   ` Jonathan Cameron
2018-12-13 12:46 ` [PATCH 08/11] staging: iio: adc: ad7606: Add OF device ID table Stefan Popa
2018-12-16 13:54   ` Jonathan Cameron
2018-12-13 12:46 ` [PATCH 09/11] staging: iio: adc: ad7606: Misc style fixes (no functional change) Stefan Popa
2018-12-16 13:56   ` Jonathan Cameron
2018-12-13 12:46 ` [PATCH 10/11] staging: iio: adc: ad7606: Move out of staging Stefan Popa
2018-12-16 14:14   ` Jonathan Cameron
2018-12-20 19:45   ` kbuild test robot
2018-12-13 12:46 ` [PATCH 11/11] dt-bindings: iio: adc: Add docs for AD7606 ADC Stefan Popa
2018-12-16 13:58   ` Jonathan Cameron

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox