Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC
@ 2019-08-07 13:31 Beniamin Bia
  2019-08-07 13:31 ` [PATCH v2 2/4] MAINTAINERS: Add Beniamin Bia for AD7606 driver Beniamin Bia
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Beniamin Bia @ 2019-08-07 13:31 UTC (permalink / raw)
  To: jic23
  Cc: lars, Michael.Hennerich, knaack.h, pmeerw, gregkh, linux-iio,
	devel, linux-kernel, mark.rutland, robh+dt, devicetree, paulmck,
	mchehab+samsung, linus.walleij, nicolas.ferre, biabeniamin,
	Stefan Popa, Beniamin Bia

From: Stefan Popa <stefan.popa@analog.com>

The AD7606B is a 16-bit ADC that supports simultaneous sampling of 8
channels. It is pin compatible to AD7606, but adds extra modes by
writing to the register map.

The AD7606B can be configured to work in software mode by setting all
oversampling pins to high. This mode is selected by default.
The oversampling ratio is configured from the OS_MODE register (address
0x08) with the addition of OS=128 and OS=256 that were not available in
hardware mode.

The device is configured to output data on a single spi channel, but this
configuration must be done right after restart. That is why the delay was
removed for devices which doesn't require it.

Moreover, in software mode, the range gpio has no longer its function.
Instead, the scale can be configured individually for each channel from
the RANGE_CH registers (address 0x03 to 0x06). Besides the already
supported ±10 V and ±5 V ranges, software mode can also accommodate the
±2.5 V range.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Co-developed-by: Beniamin Bia <beniamin.bia@analog.com>
Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
Acked-by: Jonathan Cameron <jic23@kernel.org>
---
Changes in v2:
-nothing changed

 drivers/iio/adc/ad7606.c     |  13 ++++-
 drivers/iio/adc/ad7606.h     |   4 ++
 drivers/iio/adc/ad7606_spi.c | 107 +++++++++++++++++++++++++++++++++++
 3 files changed, 122 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index ed2d08437e5d..f5ba94c03a8d 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -410,12 +410,19 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
 		.oversampling_avail = ad7606_oversampling_avail,
 		.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
 	},
+	[ID_AD7606B] = {
+		.channels = ad7606_channels,
+		.num_channels = 9,
+		.oversampling_avail = ad7606_oversampling_avail,
+		.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
+	},
 	[ID_AD7616] = {
 		.channels = ad7616_channels,
 		.num_channels = 17,
 		.oversampling_avail = ad7616_oversampling_avail,
 		.oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
 		.os_req_reset = true,
+		.init_delay_ms = 15,
 	},
 };
 
@@ -631,8 +638,10 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
 
 	/* AD7616 requires al least 15ms to reconfigure after a reset */
-	if (msleep_interruptible(15))
-		return -ERESTARTSYS;
+	if (st->chip_info->init_delay_ms) {
+		if (msleep_interruptible(st->chip_info->init_delay_ms))
+			return -ERESTARTSYS;
+	}
 
 	st->write_scale = ad7606_write_scale_hw;
 	st->write_os = ad7606_write_os_hw;
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index eeaaa8b905db..9350ef1f63b5 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -46,6 +46,8 @@
  *			oversampling ratios.
  * @oversampling_num	number of elements stored in oversampling_avail array
  * @os_req_reset	some devices require a reset to update oversampling
+ * @init_delay_ms	required delay in miliseconds for initialization
+ *			after a restart
  */
 struct ad7606_chip_info {
 	const struct iio_chan_spec	*channels;
@@ -53,6 +55,7 @@ struct ad7606_chip_info {
 	const unsigned int		*oversampling_avail;
 	unsigned int			oversampling_num;
 	bool				os_req_reset;
+	unsigned long			init_delay_ms;
 };
 
 /**
@@ -155,6 +158,7 @@ enum ad7606_supported_device_ids {
 	ID_AD7606_8,
 	ID_AD7606_6,
 	ID_AD7606_4,
+	ID_AD7606B,
 	ID_AD7616,
 };
 
diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
index 98ed52b74507..070ee7e31e2c 100644
--- a/drivers/iio/adc/ad7606_spi.c
+++ b/drivers/iio/adc/ad7606_spi.c
@@ -31,6 +31,20 @@
 /* The range of the channel is stored on 2 bits*/
 #define AD7616_RANGE_CH_MSK(ch)		(0b11 << (((ch) & 0b11) * 2))
 #define AD7616_RANGE_CH_MODE(ch, mode)	((mode) << ((((ch) & 0b11)) * 2))
+
+#define AD7606_CONFIGURATION_REGISTER	0x02
+#define AD7606_SINGLE_DOUT		0x0
+
+/*
+ * Range for AD7606B channels are stored in registers starting with address 0x3.
+ * Each register stores range for 2 channels(4 bits per channel).
+ */
+#define AD7606_RANGE_CH_MSK(ch)		(GENMASK(3, 0) << (4 * ((ch) & 0x1)))
+#define AD7606_RANGE_CH_MODE(ch, mode)	\
+	((GENMASK(3, 0) & mode) << (4 * ((ch) & 0x1)))
+#define AD7606_RANGE_CH_ADDR(ch)	(0x03 + ((ch) >> 1))
+#define AD7606_OS_MODE			0x08
+
 static const struct iio_chan_spec ad7616_sw_channels[] = {
 	IIO_CHAN_SOFT_TIMESTAMP(16),
 	AD7616_CHANNEL(0),
@@ -51,6 +65,22 @@ static const struct iio_chan_spec ad7616_sw_channels[] = {
 	AD7616_CHANNEL(15),
 };
 
+static const struct iio_chan_spec ad7606B_sw_channels[] = {
+	IIO_CHAN_SOFT_TIMESTAMP(8),
+	AD7616_CHANNEL(0),
+	AD7616_CHANNEL(1),
+	AD7616_CHANNEL(2),
+	AD7616_CHANNEL(3),
+	AD7616_CHANNEL(4),
+	AD7616_CHANNEL(5),
+	AD7616_CHANNEL(6),
+	AD7616_CHANNEL(7),
+};
+
+static const unsigned int ad7606B_oversampling_avail[9] = {
+	1, 2, 4, 8, 16, 32, 64, 128, 256
+};
+
 static u16 ad7616_spi_rd_wr_cmd(int addr, char isWriteOp)
 {
 	/*
@@ -60,6 +90,16 @@ static u16 ad7616_spi_rd_wr_cmd(int addr, char isWriteOp)
 	return ((addr & 0x7F) << 1) | ((isWriteOp & 0x1) << 7);
 }
 
+static u16 ad7606B_spi_rd_wr_cmd(int addr, char isWriteOp)
+{
+	/*
+	 * The address of register consists of one bit which
+	 * specifies a read command placed bit 6, followed by
+	 * 6 bits of address.
+	 */
+	return (addr & 0x3F) | (((~isWriteOp) & 0x1) << 6);
+}
+
 static int ad7606_spi_read_block(struct device *dev,
 				 int count, void *buf)
 {
@@ -169,6 +209,23 @@ static int ad7616_write_os_sw(struct iio_dev *indio_dev, int val)
 				     AD7616_OS_MASK, val << 2);
 }
 
+static int ad7606_write_scale_sw(struct iio_dev *indio_dev, int ch, int val)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	return ad7606_spi_write_mask(st,
+				     AD7606_RANGE_CH_ADDR(ch),
+				     AD7606_RANGE_CH_MSK(ch),
+				     AD7606_RANGE_CH_MODE(ch, val));
+}
+
+static int ad7606_write_os_sw(struct iio_dev *indio_dev, int val)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+
+	return ad7606_spi_reg_write(st, AD7606_OS_MODE, val);
+}
+
 static int ad7616_sw_mode_config(struct iio_dev *indio_dev)
 {
 	struct ad7606_state *st = iio_priv(indio_dev);
@@ -189,6 +246,42 @@ static int ad7616_sw_mode_config(struct iio_dev *indio_dev)
 			      AD7616_BURST_MODE | AD7616_SEQEN_MODE);
 }
 
+static int ad7606B_sw_mode_config(struct iio_dev *indio_dev)
+{
+	struct ad7606_state *st = iio_priv(indio_dev);
+	unsigned long os[3] = {1};
+
+	/*
+	 * Software mode is enabled when all three oversampling
+	 * pins are set to high. If oversampling gpios are defined
+	 * in the device tree, then they need to be set to high,
+	 * otherwise, they must be hardwired to VDD
+	 */
+	if (st->gpio_os) {
+		gpiod_set_array_value(ARRAY_SIZE(os),
+				      st->gpio_os->desc, st->gpio_os->info, os);
+	}
+	/* OS of 128 and 256 are available only in software mode */
+	st->oversampling_avail = ad7606B_oversampling_avail;
+	st->num_os_ratios = ARRAY_SIZE(ad7606B_oversampling_avail);
+
+	st->write_scale = ad7606_write_scale_sw;
+	st->write_os = &ad7606_write_os_sw;
+
+	/* Configure device spi to output on a single channel */
+	st->bops->reg_write(st,
+			    AD7606_CONFIGURATION_REGISTER,
+			    AD7606_SINGLE_DOUT);
+
+	/*
+	 * Scale can be configured individually for each channel
+	 * in software mode.
+	 */
+	indio_dev->channels = ad7606B_sw_channels;
+
+	return 0;
+}
+
 static const struct ad7606_bus_ops ad7606_spi_bops = {
 	.read_block = ad7606_spi_read_block,
 };
@@ -202,6 +295,15 @@ static const struct ad7606_bus_ops ad7616_spi_bops = {
 	.sw_mode_config = ad7616_sw_mode_config,
 };
 
+static const struct ad7606_bus_ops ad7606B_spi_bops = {
+	.read_block = ad7606_spi_read_block,
+	.reg_read = ad7606_spi_reg_read,
+	.reg_write = ad7606_spi_reg_write,
+	.write_mask = ad7606_spi_write_mask,
+	.rd_wr_cmd = ad7606B_spi_rd_wr_cmd,
+	.sw_mode_config = ad7606B_sw_mode_config,
+};
+
 static int ad7606_spi_probe(struct spi_device *spi)
 {
 	const struct spi_device_id *id = spi_get_device_id(spi);
@@ -211,6 +313,9 @@ static int ad7606_spi_probe(struct spi_device *spi)
 	case ID_AD7616:
 		bops = &ad7616_spi_bops;
 		break;
+	case ID_AD7606B:
+		bops = &ad7606B_spi_bops;
+		break;
 	default:
 		bops = &ad7606_spi_bops;
 		break;
@@ -226,6 +331,7 @@ static const struct spi_device_id ad7606_id_table[] = {
 	{ "ad7606-4", ID_AD7606_4 },
 	{ "ad7606-6", ID_AD7606_6 },
 	{ "ad7606-8", ID_AD7606_8 },
+	{ "ad7606b",  ID_AD7606B },
 	{ "ad7616",   ID_AD7616 },
 	{}
 };
@@ -236,6 +342,7 @@ static const struct of_device_id ad7606_of_match[] = {
 	{ .compatible = "adi,ad7606-4" },
 	{ .compatible = "adi,ad7606-6" },
 	{ .compatible = "adi,ad7606-8" },
+	{ .compatible = "adi,ad7606b" },
 	{ .compatible = "adi,ad7616" },
 	{ },
 };
-- 
2.17.1


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

* [PATCH v2 2/4] MAINTAINERS: Add Beniamin Bia for AD7606 driver
  2019-08-07 13:31 [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC Beniamin Bia
@ 2019-08-07 13:31 ` Beniamin Bia
  2019-08-07 13:31 ` [PATCH v2 3/4] dt-bindings: iio: adc: Migrate AD7606 documentation to yaml Beniamin Bia
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Beniamin Bia @ 2019-08-07 13:31 UTC (permalink / raw)
  To: jic23
  Cc: lars, Michael.Hennerich, knaack.h, pmeerw, gregkh, linux-iio,
	devel, linux-kernel, mark.rutland, robh+dt, devicetree, paulmck,
	mchehab+samsung, linus.walleij, nicolas.ferre, biabeniamin,
	Beniamin Bia

Add Beniamin Bia as maintainer for AD7606 driver.

Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
---
Changes in v2:
-nothing changed

 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index ad498428b38c..052d7a8591fb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -895,6 +895,7 @@ F:	Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
 
 ANALOG DEVICES INC AD7606 DRIVER
 M:	Stefan Popa <stefan.popa@analog.com>
+M:	Beniamin Bia <beniamin.bia@analog.com>
 L:	linux-iio@vger.kernel.org
 W:	http://ez.analog.com/community/linux-device-drivers
 S:	Supported
-- 
2.17.1


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

* [PATCH v2 3/4] dt-bindings: iio: adc: Migrate AD7606 documentation to yaml
  2019-08-07 13:31 [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC Beniamin Bia
  2019-08-07 13:31 ` [PATCH v2 2/4] MAINTAINERS: Add Beniamin Bia for AD7606 driver Beniamin Bia
@ 2019-08-07 13:31 ` Beniamin Bia
  2019-08-07 13:31 ` [PATCH v2 4/4] dt-bindings: iio: adc: Add AD7606B ADC documentation Beniamin Bia
  2019-08-07 16:41 ` [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC Peter Meerwald-Stadler
  3 siblings, 0 replies; 7+ messages in thread
From: Beniamin Bia @ 2019-08-07 13:31 UTC (permalink / raw)
  To: jic23
  Cc: lars, Michael.Hennerich, knaack.h, pmeerw, gregkh, linux-iio,
	devel, linux-kernel, mark.rutland, robh+dt, devicetree, paulmck,
	mchehab+samsung, linus.walleij, nicolas.ferre, biabeniamin,
	Beniamin Bia

The documentation for ad7606 was migrated to yaml.

Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
---
Changes in v2:
-old txt file was deleted

 .../bindings/iio/adc/adi,ad7606.txt           |  66 ---------
 .../bindings/iio/adc/adi,ad7606.yaml          | 134 ++++++++++++++++++
 MAINTAINERS                                   |   2 +-
 3 files changed, 135 insertions(+), 67 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
deleted file mode 100644
index d8652460198e..000000000000
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
+++ /dev/null
@@ -1,66 +0,0 @@
-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"
-	* "adi,ad7616"
-- 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/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
new file mode 100644
index 000000000000..509dbe9c84d2
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
@@ -0,0 +1,134 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7606.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7606 Simultaneous Sampling ADC
+
+maintainers:
+  - Beniamin Bia <beniamin.bia@analog.com>
+  - Stefan Popa <stefan.popa@analog.com>
+
+description: |
+  Analog Devices AD7606 Simultaneous Sampling ADC
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606_7606-6_7606-4.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD7616.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7605-4
+      - adi,ad7606-8
+      - adi,ad7606-6
+      - adi,ad7606-4
+      - adi,ad7616
+
+  reg:
+    maxItems: 1
+
+  spi-cpha: true
+
+  avcc-supply:
+    description:
+      Phandle to the Avcc power supply
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  adi,conversion-start-gpios:
+    description:
+      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.
+    maxItems: 1
+
+  reset-gpios:
+    description:
+      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.
+    maxItems: 1
+
+  standby-gpios:
+    description:
+       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.
+    maxItems: 1
+
+  adi,first-data-gpios:
+    description:
+      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.
+    maxItems: 1
+
+  adi,range-gpios:
+    description:
+      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.
+    maxItems: 1
+
+  adi,oversampling-ratio-gpios:
+    description:
+      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.
+    maxItems: 1
+
+  adi,sw-mode:
+    description:
+      Software mode of operation, so far available only for ad7616.
+      It is enabled when all three oversampling mode pins are connected to
+      high level. The device is configured by the corresponding registers. If the
+      adi,oversampling-ratio-gpios property is defined, then the driver will set the
+      oversampling gpios to high. Otherwise, it is assumed that the pins are hardwired
+      to VDD.
+    maxItems: 1
+    type: boolean
+
+required:
+  - compatible
+  - reg
+  - spi-cpha
+  - avcc-supply
+  - interrupts
+  - adi,conversion-start-gpios
+
+examples:
+  - |
+    spi0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        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>;
+                adi,sw-mode;
+        };
+    };
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 052d7a8591fb..d2e465772071 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -900,7 +900,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/adi,ad7606.txt
+F:	Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
 
 ANALOG DEVICES INC AD7768-1 DRIVER
 M:	Stefan Popa <stefan.popa@analog.com>
-- 
2.17.1


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

* [PATCH v2 4/4] dt-bindings: iio: adc: Add AD7606B ADC documentation
  2019-08-07 13:31 [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC Beniamin Bia
  2019-08-07 13:31 ` [PATCH v2 2/4] MAINTAINERS: Add Beniamin Bia for AD7606 driver Beniamin Bia
  2019-08-07 13:31 ` [PATCH v2 3/4] dt-bindings: iio: adc: Migrate AD7606 documentation to yaml Beniamin Bia
@ 2019-08-07 13:31 ` Beniamin Bia
  2019-08-07 16:41   ` Peter Meerwald-Stadler
  2019-08-07 16:41 ` [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC Peter Meerwald-Stadler
  3 siblings, 1 reply; 7+ messages in thread
From: Beniamin Bia @ 2019-08-07 13:31 UTC (permalink / raw)
  To: jic23
  Cc: lars, Michael.Hennerich, knaack.h, pmeerw, gregkh, linux-iio,
	devel, linux-kernel, mark.rutland, robh+dt, devicetree, paulmck,
	mchehab+samsung, linus.walleij, nicolas.ferre, biabeniamin,
	Beniamin Bia

Documentation for AD7606B Analog to Digital Converter and software
mode was added.

Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
---
Changes in v2:
-nothing changed

 Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
index 509dbe9c84d2..2afe31747a70 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
@@ -13,6 +13,7 @@ maintainers:
 description: |
   Analog Devices AD7606 Simultaneous Sampling ADC
   https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606_7606-6_7606-4.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD7606B.pdf
   https://www.analog.com/media/en/technical-documentation/data-sheets/AD7616.pdf
 
 properties:
@@ -22,6 +23,7 @@ properties:
       - adi,ad7606-8
       - adi,ad7606-6
       - adi,ad7606-4
+      - adi,ad7606b
       - adi,ad7616
 
   reg:
@@ -87,7 +89,7 @@ properties:
 
   adi,sw-mode:
     description:
-      Software mode of operation, so far available only for ad7616.
+      Software mode of operation, so far available only for ad7616 and ad7606B.
       It is enabled when all three oversampling mode pins are connected to
       high level. The device is configured by the corresponding registers. If the
       adi,oversampling-ratio-gpios property is defined, then the driver will set the
-- 
2.17.1


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

* Re: [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC
  2019-08-07 13:31 [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC Beniamin Bia
                   ` (2 preceding siblings ...)
  2019-08-07 13:31 ` [PATCH v2 4/4] dt-bindings: iio: adc: Add AD7606B ADC documentation Beniamin Bia
@ 2019-08-07 16:41 ` Peter Meerwald-Stadler
  2019-08-08 11:30   ` Jonathan Cameron
  3 siblings, 1 reply; 7+ messages in thread
From: Peter Meerwald-Stadler @ 2019-08-07 16:41 UTC (permalink / raw)
  To: Beniamin Bia
  Cc: jic23, Michael.Hennerich, linux-iio, biabeniamin, Stefan Popa

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

On Wed, 7 Aug 2019, Beniamin Bia wrote:

> From: Stefan Popa <stefan.popa@analog.com>

please see some minor comments below

> The AD7606B is a 16-bit ADC that supports simultaneous sampling of 8
> channels. It is pin compatible to AD7606, but adds extra modes by
> writing to the register map.
> 
> The AD7606B can be configured to work in software mode by setting all
> oversampling pins to high. This mode is selected by default.
> The oversampling ratio is configured from the OS_MODE register (address
> 0x08) with the addition of OS=128 and OS=256 that were not available in
> hardware mode.
> 
> The device is configured to output data on a single spi channel, but this
> configuration must be done right after restart. That is why the delay was
> removed for devices which doesn't require it.
> 
> Moreover, in software mode, the range gpio has no longer its function.
> Instead, the scale can be configured individually for each channel from
> the RANGE_CH registers (address 0x03 to 0x06). Besides the already
> supported ±10 V and ±5 V ranges, software mode can also accommodate the
> ±2.5 V range.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
> Co-developed-by: Beniamin Bia <beniamin.bia@analog.com>
> Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
> Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
> Changes in v2:
> -nothing changed
> 
>  drivers/iio/adc/ad7606.c     |  13 ++++-
>  drivers/iio/adc/ad7606.h     |   4 ++
>  drivers/iio/adc/ad7606_spi.c | 107 +++++++++++++++++++++++++++++++++++
>  3 files changed, 122 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index ed2d08437e5d..f5ba94c03a8d 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -410,12 +410,19 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
>  		.oversampling_avail = ad7606_oversampling_avail,
>  		.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
>  	},
> +	[ID_AD7606B] = {
> +		.channels = ad7606_channels,
> +		.num_channels = 9,
> +		.oversampling_avail = ad7606_oversampling_avail,
> +		.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
> +	},
>  	[ID_AD7616] = {
>  		.channels = ad7616_channels,
>  		.num_channels = 17,
>  		.oversampling_avail = ad7616_oversampling_avail,
>  		.oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
>  		.os_req_reset = true,
> +		.init_delay_ms = 15,
>  	},
>  };
>  
> @@ -631,8 +638,10 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
>  
>  	/* AD7616 requires al least 15ms to reconfigure after a reset */
> -	if (msleep_interruptible(15))
> -		return -ERESTARTSYS;
> +	if (st->chip_info->init_delay_ms) {
> +		if (msleep_interruptible(st->chip_info->init_delay_ms))
> +			return -ERESTARTSYS;
> +	}
>  
>  	st->write_scale = ad7606_write_scale_hw;
>  	st->write_os = ad7606_write_os_hw;
> diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
> index eeaaa8b905db..9350ef1f63b5 100644
> --- a/drivers/iio/adc/ad7606.h
> +++ b/drivers/iio/adc/ad7606.h
> @@ -46,6 +46,8 @@
>   *			oversampling ratios.
>   * @oversampling_num	number of elements stored in oversampling_avail array
>   * @os_req_reset	some devices require a reset to update oversampling
> + * @init_delay_ms	required delay in miliseconds for initialization

mil_l_iseconds

> + *			after a restart
>   */
>  struct ad7606_chip_info {
>  	const struct iio_chan_spec	*channels;
> @@ -53,6 +55,7 @@ struct ad7606_chip_info {
>  	const unsigned int		*oversampling_avail;
>  	unsigned int			oversampling_num;
>  	bool				os_req_reset;
> +	unsigned long			init_delay_ms;
>  };
>  
>  /**
> @@ -155,6 +158,7 @@ enum ad7606_supported_device_ids {
>  	ID_AD7606_8,
>  	ID_AD7606_6,
>  	ID_AD7606_4,
> +	ID_AD7606B,
>  	ID_AD7616,
>  };
>  
> diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
> index 98ed52b74507..070ee7e31e2c 100644
> --- a/drivers/iio/adc/ad7606_spi.c
> +++ b/drivers/iio/adc/ad7606_spi.c
> @@ -31,6 +31,20 @@
>  /* The range of the channel is stored on 2 bits*/

space before */
maybe: 'in' instead of 'on'

>  #define AD7616_RANGE_CH_MSK(ch)		(0b11 << (((ch) & 0b11) * 2))
>  #define AD7616_RANGE_CH_MODE(ch, mode)	((mode) << ((((ch) & 0b11)) * 2))
> +
> +#define AD7606_CONFIGURATION_REGISTER	0x02
> +#define AD7606_SINGLE_DOUT		0x0

maybe 0x00?

> +
> +/*
> + * Range for AD7606B channels are stored in registers starting with address 0x3.
> + * Each register stores range for 2 channels(4 bits per channel).
> + */
> +#define AD7606_RANGE_CH_MSK(ch)		(GENMASK(3, 0) << (4 * ((ch) & 0x1)))
> +#define AD7606_RANGE_CH_MODE(ch, mode)	\
> +	((GENMASK(3, 0) & mode) << (4 * ((ch) & 0x1)))
> +#define AD7606_RANGE_CH_ADDR(ch)	(0x03 + ((ch) >> 1))
> +#define AD7606_OS_MODE			0x08
> +
>  static const struct iio_chan_spec ad7616_sw_channels[] = {
>  	IIO_CHAN_SOFT_TIMESTAMP(16),
>  	AD7616_CHANNEL(0),
> @@ -51,6 +65,22 @@ static const struct iio_chan_spec ad7616_sw_channels[] = {
>  	AD7616_CHANNEL(15),
>  };
>  
> +static const struct iio_chan_spec ad7606B_sw_channels[] = {

I find it strange to uppercase the B (but not ad)

> +	IIO_CHAN_SOFT_TIMESTAMP(8),
> +	AD7616_CHANNEL(0),
> +	AD7616_CHANNEL(1),
> +	AD7616_CHANNEL(2),
> +	AD7616_CHANNEL(3),
> +	AD7616_CHANNEL(4),
> +	AD7616_CHANNEL(5),
> +	AD7616_CHANNEL(6),
> +	AD7616_CHANNEL(7),
> +};
> +
> +static const unsigned int ad7606B_oversampling_avail[9] = {
> +	1, 2, 4, 8, 16, 32, 64, 128, 256
> +};
> +
>  static u16 ad7616_spi_rd_wr_cmd(int addr, char isWriteOp)
>  {
>  	/*
> @@ -60,6 +90,16 @@ static u16 ad7616_spi_rd_wr_cmd(int addr, char isWriteOp)
>  	return ((addr & 0x7F) << 1) | ((isWriteOp & 0x1) << 7);
>  }
>  
> +static u16 ad7606B_spi_rd_wr_cmd(int addr, char isWriteOp)

bool isWriteOp?

> +{
> +	/*
> +	 * The address of register consists of one bit which
> +	 * specifies a read command placed bit 6, followed by

placed _in_ bit 6

> +	 * 6 bits of address.
> +	 */
> +	return (addr & 0x3F) | (((~isWriteOp) & 0x1) << 6);
> +}
> +
>  static int ad7606_spi_read_block(struct device *dev,
>  				 int count, void *buf)
>  {
> @@ -169,6 +209,23 @@ static int ad7616_write_os_sw(struct iio_dev *indio_dev, int val)
>  				     AD7616_OS_MASK, val << 2);
>  }
>  
> +static int ad7606_write_scale_sw(struct iio_dev *indio_dev, int ch, int val)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	return ad7606_spi_write_mask(st,
> +				     AD7606_RANGE_CH_ADDR(ch),
> +				     AD7606_RANGE_CH_MSK(ch),
> +				     AD7606_RANGE_CH_MODE(ch, val));
> +}
> +
> +static int ad7606_write_os_sw(struct iio_dev *indio_dev, int val)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +
> +	return ad7606_spi_reg_write(st, AD7606_OS_MODE, val);
> +}
> +
>  static int ad7616_sw_mode_config(struct iio_dev *indio_dev)
>  {
>  	struct ad7606_state *st = iio_priv(indio_dev);
> @@ -189,6 +246,42 @@ static int ad7616_sw_mode_config(struct iio_dev *indio_dev)
>  			      AD7616_BURST_MODE | AD7616_SEQEN_MODE);
>  }
>  
> +static int ad7606B_sw_mode_config(struct iio_dev *indio_dev)
> +{
> +	struct ad7606_state *st = iio_priv(indio_dev);
> +	unsigned long os[3] = {1};
> +
> +	/*
> +	 * Software mode is enabled when all three oversampling
> +	 * pins are set to high. If oversampling gpios are defined
> +	 * in the device tree, then they need to be set to high,
> +	 * otherwise, they must be hardwired to VDD
> +	 */
> +	if (st->gpio_os) {
> +		gpiod_set_array_value(ARRAY_SIZE(os),
> +				      st->gpio_os->desc, st->gpio_os->info, os);
> +	}
> +	/* OS of 128 and 256 are available only in software mode */
> +	st->oversampling_avail = ad7606B_oversampling_avail;
> +	st->num_os_ratios = ARRAY_SIZE(ad7606B_oversampling_avail);
> +
> +	st->write_scale = ad7606_write_scale_sw;
> +	st->write_os = &ad7606_write_os_sw;
> +
> +	/* Configure device spi to output on a single channel */
> +	st->bops->reg_write(st,
> +			    AD7606_CONFIGURATION_REGISTER,
> +			    AD7606_SINGLE_DOUT);
> +
> +	/*
> +	 * Scale can be configured individually for each channel
> +	 * in software mode.
> +	 */
> +	indio_dev->channels = ad7606B_sw_channels;
> +
> +	return 0;
> +}
> +
>  static const struct ad7606_bus_ops ad7606_spi_bops = {
>  	.read_block = ad7606_spi_read_block,
>  };
> @@ -202,6 +295,15 @@ static const struct ad7606_bus_ops ad7616_spi_bops = {
>  	.sw_mode_config = ad7616_sw_mode_config,
>  };
>  
> +static const struct ad7606_bus_ops ad7606B_spi_bops = {
> +	.read_block = ad7606_spi_read_block,
> +	.reg_read = ad7606_spi_reg_read,
> +	.reg_write = ad7606_spi_reg_write,
> +	.write_mask = ad7606_spi_write_mask,
> +	.rd_wr_cmd = ad7606B_spi_rd_wr_cmd,
> +	.sw_mode_config = ad7606B_sw_mode_config,
> +};
> +
>  static int ad7606_spi_probe(struct spi_device *spi)
>  {
>  	const struct spi_device_id *id = spi_get_device_id(spi);
> @@ -211,6 +313,9 @@ static int ad7606_spi_probe(struct spi_device *spi)
>  	case ID_AD7616:
>  		bops = &ad7616_spi_bops;
>  		break;
> +	case ID_AD7606B:
> +		bops = &ad7606B_spi_bops;
> +		break;
>  	default:
>  		bops = &ad7606_spi_bops;
>  		break;
> @@ -226,6 +331,7 @@ static const struct spi_device_id ad7606_id_table[] = {
>  	{ "ad7606-4", ID_AD7606_4 },
>  	{ "ad7606-6", ID_AD7606_6 },
>  	{ "ad7606-8", ID_AD7606_8 },
> +	{ "ad7606b",  ID_AD7606B },
>  	{ "ad7616",   ID_AD7616 },
>  	{}
>  };
> @@ -236,6 +342,7 @@ static const struct of_device_id ad7606_of_match[] = {
>  	{ .compatible = "adi,ad7606-4" },
>  	{ .compatible = "adi,ad7606-6" },
>  	{ .compatible = "adi,ad7606-8" },
> +	{ .compatible = "adi,ad7606b" },
>  	{ .compatible = "adi,ad7616" },
>  	{ },
>  };
> 

-- 

Peter Meerwald-Stadler
Mobile: +43 664 24 44 418

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

* Re: [PATCH v2 4/4] dt-bindings: iio: adc: Add AD7606B ADC documentation
  2019-08-07 13:31 ` [PATCH v2 4/4] dt-bindings: iio: adc: Add AD7606B ADC documentation Beniamin Bia
@ 2019-08-07 16:41   ` Peter Meerwald-Stadler
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Meerwald-Stadler @ 2019-08-07 16:41 UTC (permalink / raw)
  To: Beniamin Bia
  Cc: jic23, lars, Michael.Hennerich, linux-iio, devicetree, biabeniamin

On Wed, 7 Aug 2019, Beniamin Bia wrote:

minor comment below

> Documentation for AD7606B Analog to Digital Converter and software
> mode was added.
> 
> Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
> ---
> Changes in v2:
> -nothing changed
> 
>  Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
> index 509dbe9c84d2..2afe31747a70 100644
> --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
> +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
> @@ -13,6 +13,7 @@ maintainers:
>  description: |
>    Analog Devices AD7606 Simultaneous Sampling ADC
>    https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606_7606-6_7606-4.pdf
> +  https://www.analog.com/media/en/technical-documentation/data-sheets/AD7606B.pdf
>    https://www.analog.com/media/en/technical-documentation/data-sheets/AD7616.pdf
>  
>  properties:
> @@ -22,6 +23,7 @@ properties:
>        - adi,ad7606-8
>        - adi,ad7606-6
>        - adi,ad7606-4
> +      - adi,ad7606b
>        - adi,ad7616
>  
>    reg:
> @@ -87,7 +89,7 @@ properties:
>  
>    adi,sw-mode:
>      description:
> -      Software mode of operation, so far available only for ad7616.
> +      Software mode of operation, so far available only for ad7616 and ad7606B.

how about ad7606b to match the properties above?

>        It is enabled when all three oversampling mode pins are connected to
>        high level. The device is configured by the corresponding registers. If the
>        adi,oversampling-ratio-gpios property is defined, then the driver will set the
> 

-- 

Peter Meerwald-Stadler
Mobile: +43 664 24 44 418

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

* Re: [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC
  2019-08-07 16:41 ` [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC Peter Meerwald-Stadler
@ 2019-08-08 11:30   ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2019-08-08 11:30 UTC (permalink / raw)
  To: Peter Meerwald-Stadler
  Cc: Beniamin Bia, jic23, Michael.Hennerich, linux-iio, biabeniamin,
	Stefan Popa

On Wed, 7 Aug 2019 18:41:40 +0200
Peter Meerwald-Stadler <pmeerw@pmeerw.net> wrote:

> On Wed, 7 Aug 2019, Beniamin Bia wrote:
> 
> > From: Stefan Popa <stefan.popa@analog.com>  
> 
> please see some minor comments below
> 
> > The AD7606B is a 16-bit ADC that supports simultaneous sampling of 8
> > channels. It is pin compatible to AD7606, but adds extra modes by
> > writing to the register map.
> > 
> > The AD7606B can be configured to work in software mode by setting all
> > oversampling pins to high. This mode is selected by default.
> > The oversampling ratio is configured from the OS_MODE register (address
> > 0x08) with the addition of OS=128 and OS=256 that were not available in
> > hardware mode.
> > 
> > The device is configured to output data on a single spi channel, but this
> > configuration must be done right after restart. That is why the delay was
> > removed for devices which doesn't require it.
> > 
> > Moreover, in software mode, the range gpio has no longer its function.
> > Instead, the scale can be configured individually for each channel from
> > the RANGE_CH registers (address 0x03 to 0x06). Besides the already
> > supported ±10 V and ±5 V ranges, software mode can also accommodate the
> > ±2.5 V range.
> > 
> > Signed-off-by: Stefan Popa <stefan.popa@analog.com>
> > Co-developed-by: Beniamin Bia <beniamin.bia@analog.com>
> > Signed-off-by: Beniamin Bia <beniamin.bia@analog.com>
> > Acked-by: Jonathan Cameron <jic23@kernel.org>
> > ---
> > Changes in v2:
> > -nothing changed
> > 
> >  drivers/iio/adc/ad7606.c     |  13 ++++-
> >  drivers/iio/adc/ad7606.h     |   4 ++
> >  drivers/iio/adc/ad7606_spi.c | 107 +++++++++++++++++++++++++++++++++++
> >  3 files changed, 122 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> > index ed2d08437e5d..f5ba94c03a8d 100644
> > --- a/drivers/iio/adc/ad7606.c
> > +++ b/drivers/iio/adc/ad7606.c
> > @@ -410,12 +410,19 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
> >  		.oversampling_avail = ad7606_oversampling_avail,
> >  		.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
> >  	},
> > +	[ID_AD7606B] = {
> > +		.channels = ad7606_channels,
> > +		.num_channels = 9,
> > +		.oversampling_avail = ad7606_oversampling_avail,
> > +		.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
> > +	},
> >  	[ID_AD7616] = {
> >  		.channels = ad7616_channels,
> >  		.num_channels = 17,
> >  		.oversampling_avail = ad7616_oversampling_avail,
> >  		.oversampling_num = ARRAY_SIZE(ad7616_oversampling_avail),
> >  		.os_req_reset = true,
> > +		.init_delay_ms = 15,
> >  	},
> >  };
> >  
> > @@ -631,8 +638,10 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
> >  		dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
> >  
> >  	/* AD7616 requires al least 15ms to reconfigure after a reset */
> > -	if (msleep_interruptible(15))
> > -		return -ERESTARTSYS;
> > +	if (st->chip_info->init_delay_ms) {
> > +		if (msleep_interruptible(st->chip_info->init_delay_ms))
> > +			return -ERESTARTSYS;
> > +	}
> >  
> >  	st->write_scale = ad7606_write_scale_hw;
> >  	st->write_os = ad7606_write_os_hw;
> > diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
> > index eeaaa8b905db..9350ef1f63b5 100644
> > --- a/drivers/iio/adc/ad7606.h
> > +++ b/drivers/iio/adc/ad7606.h
> > @@ -46,6 +46,8 @@
> >   *			oversampling ratios.
> >   * @oversampling_num	number of elements stored in oversampling_avail array
> >   * @os_req_reset	some devices require a reset to update oversampling
> > + * @init_delay_ms	required delay in miliseconds for initialization  
> 
> mil_l_iseconds
> 
> > + *			after a restart
> >   */
> >  struct ad7606_chip_info {
> >  	const struct iio_chan_spec	*channels;
> > @@ -53,6 +55,7 @@ struct ad7606_chip_info {
> >  	const unsigned int		*oversampling_avail;
> >  	unsigned int			oversampling_num;
> >  	bool				os_req_reset;
> > +	unsigned long			init_delay_ms;
> >  };
> >  
> >  /**
> > @@ -155,6 +158,7 @@ enum ad7606_supported_device_ids {
> >  	ID_AD7606_8,
> >  	ID_AD7606_6,
> >  	ID_AD7606_4,
> > +	ID_AD7606B,
> >  	ID_AD7616,
> >  };
> >  
> > diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
> > index 98ed52b74507..070ee7e31e2c 100644
> > --- a/drivers/iio/adc/ad7606_spi.c
> > +++ b/drivers/iio/adc/ad7606_spi.c
> > @@ -31,6 +31,20 @@
> >  /* The range of the channel is stored on 2 bits*/  
> 
> space before */
> maybe: 'in' instead of 'on'
> 
> >  #define AD7616_RANGE_CH_MSK(ch)		(0b11 << (((ch) & 0b11) * 2))
> >  #define AD7616_RANGE_CH_MODE(ch, mode)	((mode) << ((((ch) & 0b11)) * 2))
> > +
> > +#define AD7606_CONFIGURATION_REGISTER	0x02
> > +#define AD7606_SINGLE_DOUT		0x0  
> 
> maybe 0x00?
> 
> > +
> > +/*
> > + * Range for AD7606B channels are stored in registers starting with address 0x3.
> > + * Each register stores range for 2 channels(4 bits per channel).
> > + */
> > +#define AD7606_RANGE_CH_MSK(ch)		(GENMASK(3, 0) << (4 * ((ch) & 0x1)))
> > +#define AD7606_RANGE_CH_MODE(ch, mode)	\
> > +	((GENMASK(3, 0) & mode) << (4 * ((ch) & 0x1)))
> > +#define AD7606_RANGE_CH_ADDR(ch)	(0x03 + ((ch) >> 1))
> > +#define AD7606_OS_MODE			0x08
> > +
> >  static const struct iio_chan_spec ad7616_sw_channels[] = {
> >  	IIO_CHAN_SOFT_TIMESTAMP(16),
> >  	AD7616_CHANNEL(0),
> > @@ -51,6 +65,22 @@ static const struct iio_chan_spec ad7616_sw_channels[] = {
> >  	AD7616_CHANNEL(15),
> >  };
> >  
> > +static const struct iio_chan_spec ad7606B_sw_channels[] = {  
> 
> I find it strange to uppercase the B (but not ad)
> 
> > +	IIO_CHAN_SOFT_TIMESTAMP(8),
> > +	AD7616_CHANNEL(0),
> > +	AD7616_CHANNEL(1),
> > +	AD7616_CHANNEL(2),
> > +	AD7616_CHANNEL(3),
> > +	AD7616_CHANNEL(4),
> > +	AD7616_CHANNEL(5),
> > +	AD7616_CHANNEL(6),
> > +	AD7616_CHANNEL(7),
> > +};
> > +
> > +static const unsigned int ad7606B_oversampling_avail[9] = {
> > +	1, 2, 4, 8, 16, 32, 64, 128, 256
> > +};
> > +
> >  static u16 ad7616_spi_rd_wr_cmd(int addr, char isWriteOp)
> >  {
> >  	/*
> > @@ -60,6 +90,16 @@ static u16 ad7616_spi_rd_wr_cmd(int addr, char isWriteOp)
> >  	return ((addr & 0x7F) << 1) | ((isWriteOp & 0x1) << 7);
> >  }
> >  
> > +static u16 ad7606B_spi_rd_wr_cmd(int addr, char isWriteOp)  
> 
> bool isWriteOp?
Also not camelCase please.

is_write_op

> 
> > +{
> > +	/*
> > +	 * The address of register consists of one bit which
> > +	 * specifies a read command placed bit 6, followed by  
> 
> placed _in_ bit 6
> 
> > +	 * 6 bits of address.
> > +	 */
> > +	return (addr & 0x3F) | (((~isWriteOp) & 0x1) << 6);
> > +}
> > +
> >  static int ad7606_spi_read_block(struct device *dev,
> >  				 int count, void *buf)
> >  {
> > @@ -169,6 +209,23 @@ static int ad7616_write_os_sw(struct iio_dev *indio_dev, int val)
> >  				     AD7616_OS_MASK, val << 2);
> >  }
> >  
> > +static int ad7606_write_scale_sw(struct iio_dev *indio_dev, int ch, int val)
> > +{
> > +	struct ad7606_state *st = iio_priv(indio_dev);
> > +
> > +	return ad7606_spi_write_mask(st,
> > +				     AD7606_RANGE_CH_ADDR(ch),
> > +				     AD7606_RANGE_CH_MSK(ch),
> > +				     AD7606_RANGE_CH_MODE(ch, val));
> > +}
> > +
> > +static int ad7606_write_os_sw(struct iio_dev *indio_dev, int val)
> > +{
> > +	struct ad7606_state *st = iio_priv(indio_dev);
> > +
> > +	return ad7606_spi_reg_write(st, AD7606_OS_MODE, val);
> > +}
> > +
> >  static int ad7616_sw_mode_config(struct iio_dev *indio_dev)
> >  {
> >  	struct ad7606_state *st = iio_priv(indio_dev);
> > @@ -189,6 +246,42 @@ static int ad7616_sw_mode_config(struct iio_dev *indio_dev)
> >  			      AD7616_BURST_MODE | AD7616_SEQEN_MODE);
> >  }
> >  
> > +static int ad7606B_sw_mode_config(struct iio_dev *indio_dev)
> > +{
> > +	struct ad7606_state *st = iio_priv(indio_dev);
> > +	unsigned long os[3] = {1};
> > +
> > +	/*
> > +	 * Software mode is enabled when all three oversampling
> > +	 * pins are set to high. If oversampling gpios are defined
> > +	 * in the device tree, then they need to be set to high,
> > +	 * otherwise, they must be hardwired to VDD
> > +	 */
> > +	if (st->gpio_os) {
> > +		gpiod_set_array_value(ARRAY_SIZE(os),
> > +				      st->gpio_os->desc, st->gpio_os->info, os);
> > +	}
> > +	/* OS of 128 and 256 are available only in software mode */
> > +	st->oversampling_avail = ad7606B_oversampling_avail;
> > +	st->num_os_ratios = ARRAY_SIZE(ad7606B_oversampling_avail);
> > +
> > +	st->write_scale = ad7606_write_scale_sw;
> > +	st->write_os = &ad7606_write_os_sw;
> > +
> > +	/* Configure device spi to output on a single channel */
> > +	st->bops->reg_write(st,
> > +			    AD7606_CONFIGURATION_REGISTER,
> > +			    AD7606_SINGLE_DOUT);
> > +
> > +	/*
> > +	 * Scale can be configured individually for each channel
> > +	 * in software mode.
> > +	 */
> > +	indio_dev->channels = ad7606B_sw_channels;
> > +
> > +	return 0;
> > +}
> > +
> >  static const struct ad7606_bus_ops ad7606_spi_bops = {
> >  	.read_block = ad7606_spi_read_block,
> >  };
> > @@ -202,6 +295,15 @@ static const struct ad7606_bus_ops ad7616_spi_bops = {
> >  	.sw_mode_config = ad7616_sw_mode_config,
> >  };
> >  
> > +static const struct ad7606_bus_ops ad7606B_spi_bops = {
> > +	.read_block = ad7606_spi_read_block,
> > +	.reg_read = ad7606_spi_reg_read,
> > +	.reg_write = ad7606_spi_reg_write,
> > +	.write_mask = ad7606_spi_write_mask,
> > +	.rd_wr_cmd = ad7606B_spi_rd_wr_cmd,
> > +	.sw_mode_config = ad7606B_sw_mode_config,
> > +};
> > +
> >  static int ad7606_spi_probe(struct spi_device *spi)
> >  {
> >  	const struct spi_device_id *id = spi_get_device_id(spi);
> > @@ -211,6 +313,9 @@ static int ad7606_spi_probe(struct spi_device *spi)
> >  	case ID_AD7616:
> >  		bops = &ad7616_spi_bops;
> >  		break;
> > +	case ID_AD7606B:
> > +		bops = &ad7606B_spi_bops;
> > +		break;
> >  	default:
> >  		bops = &ad7606_spi_bops;
> >  		break;
> > @@ -226,6 +331,7 @@ static const struct spi_device_id ad7606_id_table[] = {
> >  	{ "ad7606-4", ID_AD7606_4 },
> >  	{ "ad7606-6", ID_AD7606_6 },
> >  	{ "ad7606-8", ID_AD7606_8 },
> > +	{ "ad7606b",  ID_AD7606B },
> >  	{ "ad7616",   ID_AD7616 },
> >  	{}
> >  };
> > @@ -236,6 +342,7 @@ static const struct of_device_id ad7606_of_match[] = {
> >  	{ .compatible = "adi,ad7606-4" },
> >  	{ .compatible = "adi,ad7606-6" },
> >  	{ .compatible = "adi,ad7606-8" },
> > +	{ .compatible = "adi,ad7606b" },
> >  	{ .compatible = "adi,ad7616" },
> >  	{ },
> >  };
> >   
> 



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

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-07 13:31 [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC Beniamin Bia
2019-08-07 13:31 ` [PATCH v2 2/4] MAINTAINERS: Add Beniamin Bia for AD7606 driver Beniamin Bia
2019-08-07 13:31 ` [PATCH v2 3/4] dt-bindings: iio: adc: Migrate AD7606 documentation to yaml Beniamin Bia
2019-08-07 13:31 ` [PATCH v2 4/4] dt-bindings: iio: adc: Add AD7606B ADC documentation Beniamin Bia
2019-08-07 16:41   ` Peter Meerwald-Stadler
2019-08-07 16:41 ` [PATCH v2 1/4] iio: adc: ad7606: Add support for AD7606B ADC Peter Meerwald-Stadler
2019-08-08 11:30   ` 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