[PATCH v2 3/3] iio: accel: adxl372: Perform a reset at start up

2019-09-10 Thread Stefan Popa
We need to perform a reset a start up to make sure that the chip is in a
consistent state. This reset also disables all the interrupts which
should only be enabled together with the iio buffer. Not doing this, was
sometimes causing unwanted interrupts to trigger.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Instead of disabling the interrupts, now this patch performs
  a software reset.

 drivers/iio/accel/adxl372.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index 33edca8..8a00528 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -575,6 +575,14 @@ static int adxl372_setup(struct adxl372_state *st)
return -ENODEV;
}
 
+   /*
+* Perform a software reset to make sure the device is in a consistent
+* state after start up.
+*/
+   ret = regmap_write(st->regmap, ADXL372_RESET, ADXL372_RESET_CODE);
+   if (ret < 0)
+   return ret;
+
ret = adxl372_set_op_mode(st, ADXL372_STANDBY);
if (ret < 0)
return ret;
-- 
2.7.4



[PATCH v2 2/3] iio: accel: adxl372: Fix push to buffers lost samples

2019-09-10 Thread Stefan Popa
One in two sample sets was lost by multiplying fifo_set_size with
sizeof(u16). Also, the double number of available samples were pushed to
the iio buffers.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Nothing changed.

 drivers/iio/accel/adxl372.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index 7de5e1b..33edca8 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -553,8 +553,7 @@ static irqreturn_t adxl372_trigger_handler(int irq, void  
*p)
goto err;
 
/* Each sample is 2 bytes */
-   for (i = 0; i < fifo_entries * sizeof(u16);
-i += st->fifo_set_size * sizeof(u16))
+   for (i = 0; i < fifo_entries; i += st->fifo_set_size)
iio_push_to_buffers(indio_dev, >fifo_buf[i]);
}
 err:
-- 
2.7.4



[PATCH v2 1/3] iio: accel: adxl372: Fix/remove limitation for FIFO samples

2019-09-10 Thread Stefan Popa
Currently, the driver sets the FIFO_SAMPLES register with the number of
sample sets (maximum of 170 for 3 axis data, 256 for 2-axis and 512 for
single axis). However, the FIFO_SAMPLES register should store the number
of samples, regardless of how the FIFO format is configured.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- st->watermark needs to store the number of sample sets, 
  the total number of samples is computed in
  adxl372_configure_fifo() func.

 drivers/iio/accel/adxl372.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index 055227cb..7de5e1b 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -474,12 +474,17 @@ static int adxl372_configure_fifo(struct adxl372_state 
*st)
if (ret < 0)
return ret;
 
-   fifo_samples = st->watermark & 0xFF;
+   /*
+* watermak stores the number of sets; we need to write the FIFO
+* registers with the number of samples
+*/
+   fifo_samples = (st->watermark * st->fifo_set_size);
fifo_ctl = ADXL372_FIFO_CTL_FORMAT_MODE(st->fifo_format) |
   ADXL372_FIFO_CTL_MODE_MODE(st->fifo_mode) |
-  ADXL372_FIFO_CTL_SAMPLES_MODE(st->watermark);
+  ADXL372_FIFO_CTL_SAMPLES_MODE(fifo_samples);
 
-   ret = regmap_write(st->regmap, ADXL372_FIFO_SAMPLES, fifo_samples);
+   ret = regmap_write(st->regmap,
+  ADXL372_FIFO_SAMPLES, fifo_samples & 0xFF);
if (ret < 0)
return ret;
 
-- 
2.7.4



[PATCH 3/3] iio: accel: adxl372: Make sure interrupts are disabled

2019-09-03 Thread Stefan Popa
This patch disables the adxl372 interrupts at setup. The interrupts
should be enabled together with the iio buffer. Not doing this, might
cause an unwanted interrupt to trigger without being able to properly
clear it.

Signed-off-by: Stefan Popa 
---
 drivers/iio/accel/adxl372.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index 72d3f45..77651f4 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -609,6 +609,10 @@ static int adxl372_setup(struct adxl372_state *st)
if (ret < 0)
return ret;
 
+   ret = adxl372_set_interrupts(st, 0, 0);
+   if (ret < 0)
+   return ret;
+
/* Set the mode of operation to full bandwidth measurement mode */
return adxl372_set_op_mode(st, ADXL372_FULL_BW_MEASUREMENT);
 }
-- 
2.7.4



[PATCH 2/3] iio: accel: adxl372: Fix push to buffers lost samples

2019-09-03 Thread Stefan Popa
One in two sample sets was lost by multiplying fifo_set_size with
sizeof(u16). Also, the double number of available samples were pushed to
the iio buffers.

Signed-off-by: Stefan Popa 
---
 drivers/iio/accel/adxl372.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index adec37b..72d3f45 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -548,8 +548,7 @@ static irqreturn_t adxl372_trigger_handler(int irq, void  
*p)
goto err;
 
/* Each sample is 2 bytes */
-   for (i = 0; i < fifo_entries * sizeof(u16);
-i += st->fifo_set_size * sizeof(u16))
+   for (i = 0; i < fifo_entries; i += st->fifo_set_size)
iio_push_to_buffers(indio_dev, >fifo_buf[i]);
}
 err:
-- 
2.7.4



[PATCH 1/3] iio: accel: adxl372: Fix/remove limitation for FIFO samples

2019-09-03 Thread Stefan Popa
Currently, the driver sets the FIFO_SAMPLES register with the number of
sample sets (maximum of 170 for 3 axis data, 256 for 2-axis and 512 for
single axis). However, the FIFO_SAMPLES register should store the number
of samples, regardless of how the FIFO format is configured.

Signed-off-by: Stefan Popa 
---
 drivers/iio/accel/adxl372.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index 055227cb..adec37b 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -805,15 +805,6 @@ static int adxl372_buffer_postenable(struct iio_dev 
*indio_dev)
st->fifo_format = adxl372_axis_lookup_table[i].fifo_format;
st->fifo_set_size = bitmap_weight(indio_dev->active_scan_mask,
  indio_dev->masklength);
-   /*
-* The 512 FIFO samples can be allotted in several ways, such as:
-* 170 sample sets of concurrent 3-axis data
-* 256 sample sets of concurrent 2-axis data (user selectable)
-* 512 sample sets of single-axis data
-*/
-   if ((st->watermark * st->fifo_set_size) > ADXL372_FIFO_SIZE)
-   st->watermark = (ADXL372_FIFO_SIZE  / st->fifo_set_size);
-
st->fifo_mode = ADXL372_FIFO_STREAMED;
 
ret = adxl372_configure_fifo(st);
-- 
2.7.4



[PATCH 1/4] dt-bindings: iio: frequency: Use dt-schema for clock-names

2019-06-24 Thread Stefan Popa
Dt-schema can be used for clock-names property.

Signed-off-by: Stefan Popa 
---
 Documentation/devicetree/bindings/iio/frequency/adf4371.yaml | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml 
b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
index d7adf074..8a2a8f6 100644
--- a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
+++ b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
@@ -27,9 +27,8 @@ properties:
 maxItems: 1
 
   clock-names:
-description:
-  Must be "clkin"
-maxItems: 1
+items:
+  - clkin
 
 required:
   - compatible
-- 
2.7.4



[PATCH 2/4] iio: frequency: adf4371: Add support for ADF4372 PLL

2019-06-24 Thread Stefan Popa
The ADF4372 is part of the same family with ADF4371, the main difference
is that it has only 3 channels instead of 4, as the frequency quadrupler
is missing. As a result, the ADF4372 allows frequencies from 62.5 MHz to
16 GHz to be generated.

Datasheet:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4372.pdf

Signed-off-by: Stefan Popa 
---
 drivers/iio/frequency/Kconfig   |  6 +++---
 drivers/iio/frequency/adf4371.c | 31 ---
 2 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/frequency/Kconfig b/drivers/iio/frequency/Kconfig
index e4a921f..353914b 100644
--- a/drivers/iio/frequency/Kconfig
+++ b/drivers/iio/frequency/Kconfig
@@ -39,12 +39,12 @@ config ADF4350
  module will be called adf4350.
 
 config ADF4371
-   tristate "Analog Devices ADF4371 Wideband Synthesizer"
+   tristate "Analog Devices ADF4371/ADF4372 Wideband Synthesizers"
depends on SPI
select REGMAP_SPI
help
- Say yes here to build support for Analog Devices  ADF4371
- Wideband Synthesizer. The driver provides direct access via sysfs.
+ Say yes here to build support for Analog Devices ADF4371 and ADF4372
+ Wideband Synthesizers. The driver provides direct access via sysfs.
 
  To compile this driver as a module, choose M here: the
  module will be called adf4371.
diff --git a/drivers/iio/frequency/adf4371.c b/drivers/iio/frequency/adf4371.c
index d8c414b..f874219 100644
--- a/drivers/iio/frequency/adf4371.c
+++ b/drivers/iio/frequency/adf4371.c
@@ -87,6 +87,11 @@ enum {
ADF4371_CH_RF32
 };
 
+enum adf4371_variant {
+   ADF4371,
+   ADF4372
+};
+
 struct adf4371_pwrdown {
unsigned int reg;
unsigned int bit;
@@ -140,6 +145,11 @@ static const struct regmap_config adf4371_regmap_config = {
.read_flag_mask = BIT(7),
 };
 
+struct adf4371_chip_info {
+   unsigned int num_channels;
+   const struct iio_chan_spec *channels;
+};
+
 struct adf4371_state {
struct spi_device *spi;
struct regmap *regmap;
@@ -152,6 +162,7 @@ struct adf4371_state {
 * writes.
 */
struct mutex lock;
+   const struct adf4371_chip_info *chip_info;
unsigned long clkin_freq;
unsigned long fpfd;
unsigned int integer;
@@ -429,6 +440,17 @@ static const struct iio_chan_spec adf4371_chan[] = {
ADF4371_CHANNEL(ADF4371_CH_RF32),
 };
 
+static const struct adf4371_chip_info adf4371_chip_info[] = {
+   [ADF4371] = {
+   .channels = adf4371_chan,
+   .num_channels = 4,
+   },
+   [ADF4372] = {
+   .channels = adf4371_chan,
+   .num_channels = 3,
+   }
+};
+
 static int adf4371_reg_access(struct iio_dev *indio_dev,
  unsigned int reg,
  unsigned int writeval,
@@ -537,12 +559,13 @@ static int adf4371_probe(struct spi_device *spi)
st->regmap = regmap;
mutex_init(>lock);
 
+   st->chip_info = _chip_info[id->driver_data];
indio_dev->dev.parent = >dev;
indio_dev->name = id->name;
indio_dev->info = _info;
indio_dev->modes = INDIO_DIRECT_MODE;
-   indio_dev->channels = adf4371_chan;
-   indio_dev->num_channels = ARRAY_SIZE(adf4371_chan);
+   indio_dev->channels = st->chip_info->channels;
+   indio_dev->num_channels = st->chip_info->num_channels;
 
st->clkin = devm_clk_get(>dev, "clkin");
if (IS_ERR(st->clkin))
@@ -568,13 +591,15 @@ static int adf4371_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id adf4371_id_table[] = {
-   { "adf4371", 0 },
+   { "adf4371", ADF4371 },
+   { "adf4372", ADF4372 },
{}
 };
 MODULE_DEVICE_TABLE(spi, adf4371_id_table);
 
 static const struct of_device_id adf4371_of_match[] = {
{ .compatible = "adi,adf4371" },
+   { .compatible = "adi,adf4372" },
{ },
 };
 MODULE_DEVICE_TABLE(of, adf4371_of_match);
-- 
2.7.4



[PATCH 4/4] iio: frequency: adf4371: Add support for output stage mute

2019-06-24 Thread Stefan Popa
Another feature of the ADF4371/ADF4372 is that the supply current to the
RF8P and RF8N output stage can shut down until the ADF4371 achieves lock
as measured by the digital lock detect circuitry. The mute to lock
detect bit (MUTE_LD) in REG25 enables this function.

Signed-off-by: Stefan Popa 
---
 .../devicetree/bindings/iio/frequency/adf4371.yaml  |  6 ++
 drivers/iio/frequency/adf4371.c | 13 +
 2 files changed, 19 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml 
b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
index a268a9d..6db8742 100644
--- a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
+++ b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
@@ -32,6 +32,12 @@ properties:
 items:
   - clkin
 
+  adi,mute-till-lock-en:
+description:
+  If this property is present, then the supply current to RF8P and RF8N
+  output stage will shut down until the ADF4371/ADF4372 achieves lock as
+  measured by the digital lock detect circuitry.
+
 required:
   - compatible
   - reg
diff --git a/drivers/iio/frequency/adf4371.c b/drivers/iio/frequency/adf4371.c
index f874219..e48f15c 100644
--- a/drivers/iio/frequency/adf4371.c
+++ b/drivers/iio/frequency/adf4371.c
@@ -45,6 +45,10 @@
 #define ADF4371_RF_DIV_SEL_MSK GENMASK(6, 4)
 #define ADF4371_RF_DIV_SEL(x)  FIELD_PREP(ADF4371_RF_DIV_SEL_MSK, x)
 
+/* ADF4371_REG25 */
+#define ADF4371_MUTE_LD_MSKBIT(7)
+#define ADF4371_MUTE_LD(x) FIELD_PREP(ADF4371_MUTE_LD_MSK, x)
+
 /* ADF4371_REG32 */
 #define ADF4371_TIMEOUT_MSKGENMASK(1, 0)
 #define ADF4371_TIMEOUT(x) FIELD_PREP(ADF4371_TIMEOUT_MSK, x)
@@ -484,6 +488,15 @@ static int adf4371_setup(struct adf4371_state *st)
if (ret < 0)
return ret;
 
+   /* Mute to Lock Detect */
+   if (device_property_read_bool(>spi->dev, "adi,mute-till-lock-en")) {
+   ret = regmap_update_bits(st->regmap, ADF4371_REG(0x25),
+ADF4371_MUTE_LD_MSK,
+ADF4371_MUTE_LD(1));
+   if (ret < 0)
+   return ret;
+   }
+
/* Set address in ascending order, so the bulk_write() will work */
ret = regmap_update_bits(st->regmap, ADF4371_REG(0x0),
 ADF4371_ADDR_ASC_MSK | ADF4371_ADDR_ASC_R_MSK,
-- 
2.7.4



[PATCH 3/4] dt-bindings: iio: frequency: Add ADF4372 PLL documentation

2019-06-24 Thread Stefan Popa
Document support for ADF4372 SPI Wideband Synthesizer.

Signed-off-by: Stefan Popa 
---
 Documentation/devicetree/bindings/iio/frequency/adf4371.yaml | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml 
b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
index 8a2a8f6..a268a9d 100644
--- a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
+++ b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
@@ -4,19 +4,21 @@
 $id: http://devicetree.org/schemas/iio/frequency/adf4371.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Analog Devices ADF4371 Wideband Synthesizer
+title: Analog Devices ADF4371/ADF4372 Wideband Synthesizers
 
 maintainers:
   - Popa Stefan 
 
 description: |
-  Analog Devices ADF4371 SPI Wideband Synthesizer
+  Analog Devices ADF4371/ADF4372 SPI Wideband Synthesizers
   
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf
+  
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4372.pdf
 
 properties:
   compatible:
 enum:
   - adi,adf4371
+  - adi,adf4372
 
   reg:
 maxItems: 1
-- 
2.7.4



[PATCH v6 1/2] iio: frequency: adf4371: Add support for ADF4371 PLL

2019-06-04 Thread Stefan Popa
The ADF4371 is a frequency synthesizer with an integrated voltage
controlled oscillator (VCO) for phase-locked loops (PLLs). The ADF4371
has an integrated VCO with a fundamental output frequency ranging from
4000 MHz to 8000 MHz. In addition, the VCO frequency is connected to
divide by 1, 2, 4, 8, 16, 32, or 64 circuits that allows the user to
generate radio frequency (RF) output frequencies as low as 62.5 MHz at
RF8x. A frequency multiplier at RF16x generates from 8 GHz to 16 GHz. A
frequency quadrupler generates frequencies from 16 GHz to 32 GHz at RF32x.
RFAUX8x duplicates the frequency range of RF8x or permits direct access to
the VCO output.

The driver takes the reference input frequency from the device tree and
uses it to calculate and maximize the PFD frequency (frequency of the phase
frequency detector). The PFD frequency is further used to calculate the
timeouts: synthesizer lock, VCO band selection, automatic level
calibration (ALC) and PLL settling time.

This initial driver exposes the attributes for setting the frequency and
enabling/disabling the different adf4371 channels.

Datasheet:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added a new sysfs-bus-iio-frequency-adf4371 file which documents the 
ABI
  changes.
- Modified the ADF4371_REG() macro to take the reg values in hex as 
params
- ADF4371_MAX_MODULUS2 macro is now defined as BIT(14)
- regmap_bulk_write() can do DMA directly, so the buffer was forced into
  it's own cacheline.
- Fixed the multi line comment style.
Changes in v3:
- out_altvoltageY_frequency and out_altvoltageY_powerdown attributes are
  treated as normal indexed channels.
- out_altvoltageY_name attribute was added, from which the datasheet 
names
  of the channels can be read.
- Added more information in the documentation.
- Documented the use of mutex lock.
- As part of adf4371_write(), used a bool variable for power down and a
  64 bit variable for the frequency.
Changes in v4:
- Misc style fixes.
Changes in v5:
- Added st->spi = spi; line of code in probe and fixing possible NULL
  pointer dereference.
Changes in v6:
- Channel RF8AUX was accidentally duplicated.

 .../ABI/testing/sysfs-bus-iio-frequency-adf4371|  44 ++
 drivers/iio/frequency/Kconfig  |  10 +
 drivers/iio/frequency/Makefile |   1 +
 drivers/iio/frequency/adf4371.c| 594 +
 4 files changed, 649 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
 create mode 100644 drivers/iio/frequency/adf4371.c

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371 
b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
new file mode 100644
index 000..302de64
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
@@ -0,0 +1,44 @@
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Stores the PLL frequency in Hz for channel Y.
+   Reading returns the actual frequency in Hz.
+   The ADF4371 has an integrated VCO with fundamendal output
+   frequency ranging from 40 Hz 80 Hz.
+
+   out_altvoltage0_frequency:
+   A divide by 1, 2, 4, 8, 16, 32 or circuit generates
+   frequencies from 6250 Hz to 80 Hz.
+   out_altvoltage1_frequency:
+   This channel duplicates the channel 0 frequency
+   out_altvoltage2_frequency:
+   A frequency doubler generates frequencies from
+   80 Hz to 160 Hz.
+   out_altvoltage3_frequency:
+   A frequency quadrupler generates frequencies from
+   160 Hz to 320 Hz.
+
+   Note: writes to one of the channels will affect the frequency of
+   all the other channels, since it involves changing the VCO
+   fundamental output frequency.
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_name
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Reading returns the datasheet name for channel Y:
+
+   out_altvoltage0_name: RF8x
+   out_altvoltage1_name: RFAUX8x
+   out_altvoltage2_name: RF16x
+   out_altvoltage3_name: RF32x
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_powerdown
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   This attribute allows the user to power down the PLL and it's
+   RFOut buff

[PATCH v6 2/2] dt-bindings: iio: frequency: Add docs for ADF4371 PLL

2019-06-04 Thread Stefan Popa
Document support for Analog Devices ADF4371 SPI Wideband Synthesizer.

Signed-off-by: Stefan Popa 
Reviewed-by: Rob Herring 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Nothing changed.
Changes in v4:
- Nothing changed.
Changes in v5:
- Nothing changed.
Changes in v6:
- Nothing changed.

 .../devicetree/bindings/iio/frequency/adf4371.yaml | 54 ++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/frequency/adf4371.yaml

diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml 
b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
new file mode 100644
index 000..d7adf074
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/frequency/adf4371.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADF4371 Wideband Synthesizer
+
+maintainers:
+  - Popa Stefan 
+
+description: |
+  Analog Devices ADF4371 SPI Wideband Synthesizer
+  
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,adf4371
+
+  reg:
+maxItems: 1
+
+  clocks:
+description:
+  Definition of the external clock (see clock/clock-bindings.txt)
+maxItems: 1
+
+  clock-names:
+description:
+  Must be "clkin"
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+examples:
+  - |
+spi0 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+frequency@0 {
+compatible = "adi,adf4371";
+reg = <0>;
+spi-max-frequency = <100>;
+clocks = <_clkin>;
+clock-names = "clkin";
+};
+};
+...
-- 
2.7.4



[PATCH v5 1/2] iio: frequency: adf4371: Add support for ADF4371 PLL

2019-06-04 Thread Stefan Popa
The ADF4371 is a frequency synthesizer with an integrated voltage
controlled oscillator (VCO) for phase-locked loops (PLLs). The ADF4371
has an integrated VCO with a fundamental output frequency ranging from
4000 MHz to 8000 MHz. In addition, the VCO frequency is connected to
divide by 1, 2, 4, 8, 16, 32, or 64 circuits that allows the user to
generate radio frequency (RF) output frequencies as low as 62.5 MHz at
RF8x. A frequency multiplier at RF16x generates from 8 GHz to 16 GHz. A
frequency quadrupler generates frequencies from 16 GHz to 32 GHz at RF32x.
RFAUX8x duplicates the frequency range of RF8x or permits direct access to
the VCO output.

The driver takes the reference input frequency from the device tree and
uses it to calculate and maximize the PFD frequency (frequency of the phase
frequency detector). The PFD frequency is further used to calculate the
timeouts: synthesizer lock, VCO band selection, automatic level
calibration (ALC) and PLL settling time.

This initial driver exposes the attributes for setting the frequency and
enabling/disabling the different adf4371 channels.

Datasheet:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added a new sysfs-bus-iio-frequency-adf4371 file which documents the 
ABI
  changes.
- Modified the ADF4371_REG() macro to take the reg values in hex as 
params
- ADF4371_MAX_MODULUS2 macro is now defined as BIT(14)
- regmap_bulk_write() can do DMA directly, so the buffer was forced into
  it's own cacheline.
- Fixed the multi line comment style.
Changes in v3:
- out_altvoltageY_frequency and out_altvoltageY_powerdown attributes are
  treated as normal indexed channels.
- out_altvoltageY_name attribute was added, from which the datasheet 
names
  of the channels can be read.
- Added more information in the documentation.
- Documented the use of mutex lock.
- As part of adf4371_write(), used a bool variable for power down and a
  64 bit variable for the frequency.
Changes in v4:
- Misc style fixes.
Changes in v5:
- Added st->spi = spi; line of code in probe and fixing possible NULL
  pointer dereference.

 .../ABI/testing/sysfs-bus-iio-frequency-adf4371|  44 ++
 drivers/iio/frequency/Kconfig  |  10 +
 drivers/iio/frequency/Makefile |   1 +
 drivers/iio/frequency/adf4371.c| 595 +
 4 files changed, 650 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
 create mode 100644 drivers/iio/frequency/adf4371.c

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371 
b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
new file mode 100644
index 000..302de64
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
@@ -0,0 +1,44 @@
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Stores the PLL frequency in Hz for channel Y.
+   Reading returns the actual frequency in Hz.
+   The ADF4371 has an integrated VCO with fundamendal output
+   frequency ranging from 40 Hz 80 Hz.
+
+   out_altvoltage0_frequency:
+   A divide by 1, 2, 4, 8, 16, 32 or circuit generates
+   frequencies from 6250 Hz to 80 Hz.
+   out_altvoltage1_frequency:
+   This channel duplicates the channel 0 frequency
+   out_altvoltage2_frequency:
+   A frequency doubler generates frequencies from
+   80 Hz to 160 Hz.
+   out_altvoltage3_frequency:
+   A frequency quadrupler generates frequencies from
+   160 Hz to 320 Hz.
+
+   Note: writes to one of the channels will affect the frequency of
+   all the other channels, since it involves changing the VCO
+   fundamental output frequency.
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_name
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Reading returns the datasheet name for channel Y:
+
+   out_altvoltage0_name: RF8x
+   out_altvoltage1_name: RFAUX8x
+   out_altvoltage2_name: RF16x
+   out_altvoltage3_name: RF32x
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_powerdown
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   This attribute allows the user to power down the PLL and it's
+   RFOut buffers.
+   Writing 1 causes the specified channel to po

[PATCH v5 2/2] dt-bindings: iio: frequency: Add docs for ADF4371 PLL

2019-06-04 Thread Stefan Popa
Document support for Analog Devices ADF4371 SPI Wideband Synthesizer.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Nothing changed.
Changes in v4:
- Nothing changed.
Changes in v5:
- Nothing changed.

 .../devicetree/bindings/iio/frequency/adf4371.yaml | 54 ++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/frequency/adf4371.yaml

diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml 
b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
new file mode 100644
index 000..d7adf074
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/frequency/adf4371.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADF4371 Wideband Synthesizer
+
+maintainers:
+  - Popa Stefan 
+
+description: |
+  Analog Devices ADF4371 SPI Wideband Synthesizer
+  
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,adf4371
+
+  reg:
+maxItems: 1
+
+  clocks:
+description:
+  Definition of the external clock (see clock/clock-bindings.txt)
+maxItems: 1
+
+  clock-names:
+description:
+  Must be "clkin"
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+examples:
+  - |
+spi0 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+frequency@0 {
+compatible = "adi,adf4371";
+reg = <0>;
+spi-max-frequency = <100>;
+clocks = <_clkin>;
+clock-names = "clkin";
+};
+};
+...
-- 
2.7.4



[PATCH v4 1/2] iio: frequency: adf4371: Add support for ADF4371 PLL

2019-05-29 Thread Stefan Popa
The ADF4371 is a frequency synthesizer with an integrated voltage
controlled oscillator (VCO) for phase-locked loops (PLLs). The ADF4371
has an integrated VCO with a fundamental output frequency ranging from
4000 MHz to 8000 MHz. In addition, the VCO frequency is connected to
divide by 1, 2, 4, 8, 16, 32, or 64 circuits that allows the user to
generate radio frequency (RF) output frequencies as low as 62.5 MHz at
RF8x. A frequency multiplier at RF16x generates from 8 GHz to 16 GHz. A
frequency quadrupler generates frequencies from 16 GHz to 32 GHz at RF32x.
RFAUX8x duplicates the frequency range of RF8x or permits direct access to
the VCO output.

The driver takes the reference input frequency from the device tree and
uses it to calculate and maximize the PFD frequency (frequency of the phase
frequency detector). The PFD frequency is further used to calculate the
timeouts: synthesizer lock, VCO band selection, automatic level
calibration (ALC) and PLL settling time.

This initial driver exposes the attributes for setting the frequency and
enabling/disabling the different adf4371 channels.

Datasheet:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added a new sysfs-bus-iio-frequency-adf4371 file which documents the 
ABI
  changes.
- Modified the ADF4371_REG() macro to take the reg values in hex as 
params
- ADF4371_MAX_MODULUS2 macro is now defined as BIT(14)
- regmap_bulk_write() can do DMA directly, so the buffer was forced into
  it's own cacheline.
- Fixed the multi line comment style.
Changes in v3:
- out_altvoltageY_frequency and out_altvoltageY_powerdown attributes are
  treated as normal indexed channels.
- out_altvoltageY_name attribute was added, from which the datasheet 
names
  of the channels can be read.
- Added more information in the documentation.
- Documented the use of mutex lock.
- As part of adf4371_write(), used a bool variable for power down and a
  64 bit variable for the frequency.
Changes in v4:
- Misc style fixes.

 .../ABI/testing/sysfs-bus-iio-frequency-adf4371|  44 ++
 drivers/iio/frequency/Kconfig  |  10 +
 drivers/iio/frequency/Makefile |   1 +
 drivers/iio/frequency/adf4371.c| 594 +
 4 files changed, 649 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
 create mode 100644 drivers/iio/frequency/adf4371.c

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371 
b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
new file mode 100644
index 000..302de64
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
@@ -0,0 +1,44 @@
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Stores the PLL frequency in Hz for channel Y.
+   Reading returns the actual frequency in Hz.
+   The ADF4371 has an integrated VCO with fundamendal output
+   frequency ranging from 40 Hz 80 Hz.
+
+   out_altvoltage0_frequency:
+   A divide by 1, 2, 4, 8, 16, 32 or circuit generates
+   frequencies from 6250 Hz to 80 Hz.
+   out_altvoltage1_frequency:
+   This channel duplicates the channel 0 frequency
+   out_altvoltage2_frequency:
+   A frequency doubler generates frequencies from
+   80 Hz to 160 Hz.
+   out_altvoltage3_frequency:
+   A frequency quadrupler generates frequencies from
+   160 Hz to 320 Hz.
+
+   Note: writes to one of the channels will affect the frequency of
+   all the other channels, since it involves changing the VCO
+   fundamental output frequency.
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_name
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Reading returns the datasheet name for channel Y:
+
+   out_altvoltage0_name: RF8x
+   out_altvoltage1_name: RFAUX8x
+   out_altvoltage2_name: RF16x
+   out_altvoltage3_name: RF32x
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_powerdown
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   This attribute allows the user to power down the PLL and it's
+   RFOut buffers.
+   Writing 1 causes the specified channel to power down.
+   Clearing returns to normal operation.
diff --git a/drivers/iio/frequency/Kconfig b/drivers/iio/frequency

[PATCH v4 2/2] dt-bindings: iio: frequency: Add docs for ADF4371 PLL

2019-05-29 Thread Stefan Popa
Document support for Analog Devices ADF4371 SPI Wideband Synthesizer.

Signed-off-by: Stefan Popa 
Reviewed-by: Rob Herring 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Nothing changed.
Changes in v4:
- Nothing changed.

 .../devicetree/bindings/iio/frequency/adf4371.yaml | 54 ++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/frequency/adf4371.yaml

diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml 
b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
new file mode 100644
index 000..d7adf074
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/frequency/adf4371.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADF4371 Wideband Synthesizer
+
+maintainers:
+  - Popa Stefan 
+
+description: |
+  Analog Devices ADF4371 SPI Wideband Synthesizer
+  
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,adf4371
+
+  reg:
+maxItems: 1
+
+  clocks:
+description:
+  Definition of the external clock (see clock/clock-bindings.txt)
+maxItems: 1
+
+  clock-names:
+description:
+  Must be "clkin"
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+examples:
+  - |
+spi0 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+frequency@0 {
+compatible = "adi,adf4371";
+reg = <0>;
+spi-max-frequency = <100>;
+clocks = <_clkin>;
+clock-names = "clkin";
+};
+};
+...
-- 
2.7.4



[PATCH v3 2/2] dt-bindings: iio: frequency: Add docs for ADF4371 PLL

2019-05-28 Thread Stefan Popa
Document support for Analog Devices ADF4371 SPI Wideband Synthesizer.

Signed-off-by: Stefan Popa 
Reviewed-by: Rob Herring 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Nothing changed.

 .../devicetree/bindings/iio/frequency/adf4371.yaml | 54 ++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/frequency/adf4371.yaml

diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml 
b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
new file mode 100644
index 000..d7adf074
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/frequency/adf4371.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADF4371 Wideband Synthesizer
+
+maintainers:
+  - Popa Stefan 
+
+description: |
+  Analog Devices ADF4371 SPI Wideband Synthesizer
+  
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,adf4371
+
+  reg:
+maxItems: 1
+
+  clocks:
+description:
+  Definition of the external clock (see clock/clock-bindings.txt)
+maxItems: 1
+
+  clock-names:
+description:
+  Must be "clkin"
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+examples:
+  - |
+spi0 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+frequency@0 {
+compatible = "adi,adf4371";
+reg = <0>;
+spi-max-frequency = <100>;
+clocks = <_clkin>;
+clock-names = "clkin";
+};
+};
+...
-- 
2.7.4



[PATCH v3 1/2] iio: frequency: adf4371: Add support for ADF4371 PLL

2019-05-28 Thread Stefan Popa
The ADF4371 is a frequency synthesizer with an integrated voltage
controlled oscillator (VCO) for phase-locked loops (PLLs). The ADF4371
has an integrated VCO with a fundamental output frequency ranging from
4000 MHz to 8000 MHz. In addition, the VCO frequency is connected to
divide by 1, 2, 4, 8, 16, 32, or 64 circuits that allows the user to
generate radio frequency (RF) output frequencies as low as 62.5 MHz at
RF8x. A frequency multiplier at RF16x generates from 8 GHz to 16 GHz. A
frequency quadrupler generates frequencies from 16 GHz to 32 GHz at RF32x.
RFAUX8x duplicates the frequency range of RF8x or permits direct access to
the VCO output.

The driver takes the reference input frequency from the device tree and
uses it to calculate and maximize the PFD frequency (frequency of the phase
frequency detector). The PFD frequency is further used to calculate the
timeouts: synthesizer lock, VCO band selection, automatic level
calibration (ALC) and PLL settling time.

This initial driver exposes the attributes for setting the frequency and
enabling/disabling the different adf4371 channels.

Datasheet:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added a new sysfs-bus-iio-frequency-adf4371 file which documents the 
ABI
  changes.
- Modified the ADF4371_REG() macro to take the reg values in hex as 
params
- ADF4371_MAX_MODULUS2 macro is now defined as BIT(14)
- regmap_bulk_write() can do DMA directly, so the buffer was forced into
  it's own cacheline.
- Fixed the multi line comment style.
Changes in v3:
- out_altvoltageY_frequency and out_altvoltageY_powerdown attributes are
  treated as normal indexed channels.
- out_altvoltageY_name attribute was added, from which the datasheet 
names
  of the channels can be read.
- Added more information in the documentation.
- Documented the use of mutex lock.
- As part of adf4371_write(), used a bool variable for power down and a
  64 bit variable for the frequency.

 .../ABI/testing/sysfs-bus-iio-frequency-adf4371|  44 ++
 drivers/iio/frequency/Kconfig  |  10 +
 drivers/iio/frequency/Makefile |   1 +
 drivers/iio/frequency/adf4371.c| 591 +
 4 files changed, 646 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
 create mode 100644 drivers/iio/frequency/adf4371.c

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371 
b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
new file mode 100644
index 000..f380bbf
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
@@ -0,0 +1,44 @@
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Stores the PLL frequency in Hz for channel Y.
+   Reading returns the actual frequency in Hz.
+   The ADF4371 has an integrated VCO with fundamendal output
+   frequency ranging from 40 Hz 80 Hz.
+
+   out_altvoltage0_frequency:
+   A divide by 1, 2, 4, 8, 16, 32 or circuit generates
+   frequencies from 6250 Hz to 80 Hz.
+   out_altvoltage1_frequency:
+   A frequency doubler generates frequencies from
+   80 Hz to 160 Hz.
+   out_altvoltage2_frequency:
+   A frequency quadrupler generates frequencies from
+   160 Hz to 320 Hz.
+   out_altvoltage3_frequency:
+   This channel duplicates the channel 0 frequency
+
+   Note: writes to one of the channels will affect the frequency of
+   all the other channels, since it involves changing the VCO
+   fundamental output frequency.
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_name
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Reading returns the datasheet name for channel Y:
+
+   out_altvoltage0_name: RF8x
+   out_altvoltage1_name: RF16x
+   out_altvoltage2_name: RF32x
+   out_altvoltage3_name: RFAUX8x
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_powerdown
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   This attribute allows the user to power down the PLL and it's
+   RFOut buffers.
+   Writing 1 causes the specified channel to power down.
+   Clearing returns to normal operation.
diff --git a/drivers/iio/frequency/Kconfig b/drivers/iio/frequency/Kconfig
index dc5e0b7..e4a921f 100644

[PATCH v2 2/2] dt-bindings: iio: frequency: Add docs for ADF4371 PLL

2019-05-24 Thread Stefan Popa
Document support for Analog Devices ADF4371 SPI Wideband Synthesizer.

Signed-off-by: Stefan Popa 
Reviewed-by: Rob Herring 
---
Changes in v2:
- Nothing changed

 .../devicetree/bindings/iio/frequency/adf4371.yaml | 54 ++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/frequency/adf4371.yaml

diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml 
b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
new file mode 100644
index 000..d7adf074
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/frequency/adf4371.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADF4371 Wideband Synthesizer
+
+maintainers:
+  - Popa Stefan 
+
+description: |
+  Analog Devices ADF4371 SPI Wideband Synthesizer
+  
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,adf4371
+
+  reg:
+maxItems: 1
+
+  clocks:
+description:
+  Definition of the external clock (see clock/clock-bindings.txt)
+maxItems: 1
+
+  clock-names:
+description:
+  Must be "clkin"
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+examples:
+  - |
+spi0 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+frequency@0 {
+compatible = "adi,adf4371";
+reg = <0>;
+spi-max-frequency = <100>;
+clocks = <_clkin>;
+clock-names = "clkin";
+};
+};
+...
-- 
2.7.4



[PATCH v2 1/2] iio: frequency: adf4371: Add support for ADF4371 PLL

2019-05-24 Thread Stefan Popa
The ADF4371 is a frequency synthesizer with an integrated voltage
controlled oscillator (VCO) for phase-locked loops (PLLs). The ADF4371
has an integrated VCO with a fundamental output frequency ranging from
4000 MHz to 8000 MHz. In addition, the VCO frequency is connected to
divide by 1, 2, 4, 8, 16, 32, or 64 circuits that allows the user to
generate radio frequency (RF) output frequencies as low as 62.5 MHz at
RF8x. A frequency multiplier at RF16x generates from 8 GHz to 16 GHz. A
frequency quadrupler generates frequencies from 16 GHz to 32 GHz at RF32x.
RFAUX8x duplicates the frequency range of RF8x or permits direct access to
the VCO output.

The driver takes the reference input frequency from the device tree and
uses it to calculate and maximize the PFD frequency (frequency of the phase
frequency detector). The PFD frequency is further used to calculate the
timeouts: synthesizer lock, VCO band selection, automatic level
calibration (ALC) and PLL settling time.

This initial driver exposes the attributes for setting the frequency and
enabling/disabling the different adf4371 channels.

Datasheet:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added a new sysfs-bus-iio-frequency-adf4371 file which documents the 
ABI
  changes.
- Modified the ADF4371_REG() macro to take the reg values in hex as 
params
- ADF4371_MAX_MODULUS2 macro is now defined as BIT(14)
- regmap_bulk_write() can't do DMA directly, so the buffer was forced 
into
  it's own cacheline.
- Fixed the multi line comment style.

 .../ABI/testing/sysfs-bus-iio-frequency-adf4371|  33 ++
 drivers/iio/frequency/Kconfig  |  10 +
 drivers/iio/frequency/Makefile |   1 +
 drivers/iio/frequency/adf4371.c| 572 +
 4 files changed, 616 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
 create mode 100644 drivers/iio/frequency/adf4371.c

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371 
b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
new file mode 100644
index 000..37733eb
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-frequency-adf4371
@@ -0,0 +1,33 @@
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltage_rf8_frequency
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltage_rfaux8_frequency
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Stores the PLL frequency in Hz for channels RF8x and RFAUX8x 
respectively.
+   Reading returns the actual frequency in Hz. RF output frequency 
range
+   for this channels: 6250 Hz to 80 Hz. RFAUX8x 
duplicates the frequency
+   range of RF8x or permits direct access to the VCO output.
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltage_rf16_frequency
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Stores the PLL frequency in Hz for channel RF16x. Reading 
returns the actual
+   frequency in Hz. RF16 generates frequencies from 80 Hz 
to 160 Hz
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltage_rf32_frequency
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   Stores the PLL frequency in Hz for channel RF32x. Reading 
returns the actual
+   frequency in Hz. RF32x generates frequencies from 160 
Hz to 320 Hz
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltage_rf8_powerdown
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltage_rfaux8_powerdown
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltage_rf16_powerdown
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltage_rf32_powerdown
+KernelVersion:
+Contact:   linux-...@vger.kernel.org
+Description:
+   This attribute allows the user to power down the PLL and it's 
RFOut buffers.
+   Writing 1 causes the specified channel to power down. Clearing 
returns to normal operation.
diff --git a/drivers/iio/frequency/Kconfig b/drivers/iio/frequency/Kconfig
index dc5e0b7..e4a921f 100644
--- a/drivers/iio/frequency/Kconfig
+++ b/drivers/iio/frequency/Kconfig
@@ -38,5 +38,15 @@ config ADF4350
  To compile this driver as a module, choose M here: the
  module will be called adf4350.
 
+config ADF4371
+   tristate "Analog Devices ADF4371 Wideband Synthesizer"
+   depends on SPI
+   select REGMAP_SPI
+   help
+ Say yes here to build support for Analog Devices  ADF4371
+ Wideband Synthesizer. The driver provides direct access via sysfs.
+
+ To compile this driver as a module, choose M here: the
+ module will be called adf4371.
 endmenu
 endmenu
diff --git a/drivers/iio

[PATCH 1/2] iio: frequency: adf4371: Add support for ADF4371 PLL

2019-05-15 Thread Stefan Popa
The ADF4371 is a frequency synthesizer with an integrated voltage
controlled oscillator (VCO) for phase-locked loops (PLLs). The ADF4371
has an integrated VCO with a fundamental output frequency ranging from
4000 MHz to 8000 MHz. In addition, the VCO frequency is connected to
divide by 1, 2, 4, 8, 16, 32, or 64 circuits that allows the user to
generate radio frequency (RF) output frequencies as low as 62.5 MHz at
RF8x. A frequency multiplier at RF16x generates from 8 GHz to 16 GHz. A
frequency quadrupler generates frequencies from 16 GHz to 32 GHz at RF32x.
RFAUX8x duplicates the frequency range of RF8x or permits direct access to
the VCO output.

The driver takes the reference input frequency from the device tree and
uses it to calculate and maximize the PFD frequency (frequency of the phase
frequency detector). The PFD frequency is further used to calculate the
timeouts: synthesizer lock, VCO band selection, automatic level
calibration (ALC) and PLL settling time.

This initial driver exposes the attributes for setting the frequency and
enabling/disabling the different adf4371 channels.

Datasheet:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf

Signed-off-by: Stefan Popa 
---
 drivers/iio/frequency/Kconfig   |  10 +
 drivers/iio/frequency/Makefile  |   1 +
 drivers/iio/frequency/adf4371.c | 573 
 3 files changed, 584 insertions(+)
 create mode 100644 drivers/iio/frequency/adf4371.c

diff --git a/drivers/iio/frequency/Kconfig b/drivers/iio/frequency/Kconfig
index dc5e0b7..e4a921f 100644
--- a/drivers/iio/frequency/Kconfig
+++ b/drivers/iio/frequency/Kconfig
@@ -38,5 +38,15 @@ config ADF4350
  To compile this driver as a module, choose M here: the
  module will be called adf4350.
 
+config ADF4371
+   tristate "Analog Devices ADF4371 Wideband Synthesizer"
+   depends on SPI
+   select REGMAP_SPI
+   help
+ Say yes here to build support for Analog Devices  ADF4371
+ Wideband Synthesizer. The driver provides direct access via sysfs.
+
+ To compile this driver as a module, choose M here: the
+ module will be called adf4371.
 endmenu
 endmenu
diff --git a/drivers/iio/frequency/Makefile b/drivers/iio/frequency/Makefile
index 2bca03f..2ddda77 100644
--- a/drivers/iio/frequency/Makefile
+++ b/drivers/iio/frequency/Makefile
@@ -5,3 +5,4 @@
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AD9523) += ad9523.o
 obj-$(CONFIG_ADF4350) += adf4350.o
+obj-$(CONFIG_ADF4371) += adf4371.o
diff --git a/drivers/iio/frequency/adf4371.c b/drivers/iio/frequency/adf4371.c
new file mode 100644
index 000..fd968d5
--- /dev/null
+++ b/drivers/iio/frequency/adf4371.c
@@ -0,0 +1,573 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices ADF4371 SPI Wideband Synthesizer driver
+ *
+ * Copyright 2019 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/* Registers address macro */
+#define ADF4371_REG(x) (0x ## x)
+
+/* ADF4371_REG0 */
+#define ADF4371_ADDR_ASC_MSK   BIT(2)
+#define ADF4371_ADDR_ASC(x)FIELD_PREP(ADF4371_ADDR_ASC_MSK, x)
+#define ADF4371_ADDR_ASC_R_MSK BIT(5)
+#define ADF4371_ADDR_ASC_R(x)  FIELD_PREP(ADF4371_ADDR_ASC_R_MSK, x)
+#define ADF4371_RESET_CMD  0x81
+
+/* ADF4371_REG17 */
+#define ADF4371_FRAC2WORD_L_MSKGENMASK(7, 1)
+#define ADF4371_FRAC2WORD_L(x) FIELD_PREP(ADF4371_FRAC2WORD_L_MSK, x)
+#define ADF4371_FRAC1WORD_MSK  BIT(0)
+#define ADF4371_FRAC1WORD(x)   FIELD_PREP(ADF4371_FRAC1WORD_MSK, x)
+
+/* ADF4371_REG18 */
+#define ADF4371_FRAC2WORD_H_MSKGENMASK(6, 0)
+#define ADF4371_FRAC2WORD_H(x) FIELD_PREP(ADF4371_FRAC2WORD_H_MSK, x)
+
+/* ADF4371_REG1A */
+#define ADF4371_MOD2WORD_MSK   GENMASK(5, 0)
+#define ADF4371_MOD2WORD(x)FIELD_PREP(ADF4371_MOD2WORD_MSK, x)
+
+/* ADF4371_REG24 */
+#define ADF4371_RF_DIV_SEL_MSK GENMASK(6, 4)
+#define ADF4371_RF_DIV_SEL(x)  FIELD_PREP(ADF4371_RF_DIV_SEL_MSK, x)
+
+/* ADF4371_REG32 */
+#define ADF4371_TIMEOUT_MSKGENMASK(1, 0)
+#define ADF4371_TIMEOUT(x) FIELD_PREP(ADF4371_TIMEOUT_MSK, x)
+
+/* ADF4371_REG34 */
+#define ADF4371_VCO_ALC_TOUT_MSK   GENMASK(4, 0)
+#define ADF4371_VCO_ALC_TOUT(x)
FIELD_PREP(ADF4371_VCO_ALC_TOUT_MSK, x)
+
+/* Specifications */
+#define ADF4371_MIN_VCO_FREQ   40ULL /* 4000 MHz */
+#define ADF4371_MAX_VCO_FREQ   80ULL /* 8000 MHz */
+#define ADF4371_MAX_OUT_RF8_FREQ   ADF4371_MAX_VCO_FREQ /* Hz */
+#define ADF4371_MIN_OUT_RF8_FREQ   (ADF4371_MIN_VCO_FREQ / 64) /* Hz */
+#define ADF4371_MAX_OUT_RF16_FREQ  (ADF4371_MAX_VCO_FREQ * 2) /* Hz */
+#define ADF4371_MIN_OUT_RF16_FREQ  (ADF4371_MIN_VCO_FREQ * 2) /* Hz *

[PATCH 2/2] dt-bindings: iio: frequency: Add docs for ADF4371 PLL

2019-05-15 Thread Stefan Popa
Document support for Analog Devices ADF4371 SPI Wideband Synthesizer.

Signed-off-by: Stefan Popa 
---
 .../devicetree/bindings/iio/frequency/adf4371.yaml | 54 ++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/frequency/adf4371.yaml

diff --git a/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml 
b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
new file mode 100644
index 000..d7adf074
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/frequency/adf4371.yaml
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/frequency/adf4371.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADF4371 Wideband Synthesizer
+
+maintainers:
+  - Popa Stefan 
+
+description: |
+  Analog Devices ADF4371 SPI Wideband Synthesizer
+  
https://www.analog.com/media/en/technical-documentation/data-sheets/adf4371.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,adf4371
+
+  reg:
+maxItems: 1
+
+  clocks:
+description:
+  Definition of the external clock (see clock/clock-bindings.txt)
+maxItems: 1
+
+  clock-names:
+description:
+  Must be "clkin"
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+examples:
+  - |
+spi0 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+frequency@0 {
+compatible = "adi,adf4371";
+reg = <0>;
+spi-max-frequency = <100>;
+clocks = <_clkin>;
+clock-names = "clkin";
+};
+};
+...
-- 
2.7.4



[PATCH v2] MAINTAINERS: Fix the link to ad7606 dt-bindings

2019-03-26 Thread Stefan Popa
The devicetree bindings documentation for ad7606 should also include
the vendor prefix: ad7606.txt -> adi,ad7606.txt

Fixes: 6e33a125df66 ("dt-bindings: iio: adc: Add docs for AD7606 ADC")
Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added Fixes tag

 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index ff2c2f2..4f81cdc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -860,7 +860,7 @@ L:  linux-...@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
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
 
 ANALOG DEVICES INC AD7768-1 DRIVER
 M:     Stefan Popa 
-- 
2.7.4



[PATCH] MAINTAINERS: Fix the link to ad7606 dt-bindings

2019-03-26 Thread Stefan Popa
The devicetree bindings documentation for ad7606 should also include
the vendor prefix: ad7606.txt -> adi,ad7606.txt

Signed-off-by: Stefan Popa 
---
 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index ff2c2f2..4f81cdc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -860,7 +860,7 @@ L:  linux-...@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
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
 
 ANALOG DEVICES INC AD7768-1 DRIVER
 M:     Stefan Popa 
-- 
2.7.4



[PATCH v2 2/2] dt-bindings: iio: imu: adis16480: Document external clock

2019-03-11 Thread Stefan Popa
Add documentation for optional use of external clock. All devices
supported by this driver can work with an external clock in sync mode.
Another mode, called Pulse Per Second (PPS) is supported only by adis1649x
devices. The mode is selected by using the "clock-names" property.

The pin which is used as external clock input is selected by using a
custom optional property called "adi,ext-clk-pin". If this field is left
empty, DIO2 is assigned as default external clock input pin.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Mentioned that both "clocks" and "clock-names" fields should be left
  empty for internal clock to be used.

 .../devicetree/bindings/iio/imu/adi,adis16480.txt  | 36 ++
 1 file changed, 36 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt 
b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
index 39ab016..ed7783f 100644
--- a/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
+++ b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
@@ -34,6 +34,39 @@ Optional properties:
signal.
 - reset-gpios: must be the device tree identifier of the RESET pin. As the line
is active low, it should be marked GPIO_ACTIVE_LOW.
+- clocks: phandle to the external clock. Should be set according to
+   "clock-names".
+   If this field is left empty together with the "clock-names" field, then
+   the internal clock is used.
+- clock-names: The name of the external clock to be used. Valid values are:
+   * sync: In sync mode, the internal clock is disabled and the frequency
+   of the external clock signal establishes therate of data
+   collection and processing. See Fig 14 and 15 in the datasheet.
+   The clock-frequency must be:
+   * 3000 to 4500 Hz for adis1649x devices.
+   * 700 to 2400 Hz for adis1648x devices.
+   * pps: In Pulse Per Second (PPS) Mode, the rate of data collection and
+  production is equal to the product of the external clock
+  frequency and the scale factor in the SYNC_SCALE register, see
+  Table 154 in the datasheet.
+  The clock-frequency must be:
+  * 1 to 128 Hz for adis1649x devices.
+  * This mode is not supported by adis1648x devices.
+   If this field is left empty together with the "clocks" field, then the
+   internal clock is used.
+- adi,ext-clk-pin: The DIOx line to be used as an external clock input.
+   Valid values are:
+   * DIO1
+   * DIO2
+   * DIO3
+   * DIO4
+   Each DIOx pin supports only one function at a time (data ready line
+   selection or external clock input). When a single pin has two
+   two assignments, the enable bit for the lower priority function
+   automatically resets to zero (disabling the lower priority function).
+   Data ready has highest priority.
+   If this field is left empty, DIO2 is assigned as default external clock
+   input pin.
 
 Example:
 
@@ -46,4 +79,7 @@ Example:
interrupts = <25 IRQF_TRIGGER_FALLING>;
interrupt-parent = <>;
interrupt-names = "DIO2";
+   clocks = <_sync>;
+   clock-names = "sync";
+   adi,ext-clk-pin = "DIO1";
};
-- 
2.7.4



[PATCH v2 1/2] iio: imu: adis16480: Add support for external clock

2019-03-11 Thread Stefan Popa
Inertial sensor data collection and processing can be controlled by
configuring one of the DIOx lines as an external clock input. This
option is available for all devices supported by this driver. However,
only adis1649x devices support different modes for the external clock.

Sync mode is supported by all devices. In this mode, the output data
rate is equal with the clock frequency divided by DEC_RATE + 1. This
mode of calculation is similar with the case when the internal clock is
used.

Pulse Per Second (PPS) Mode, is only supported by adis1649x devices. In
this mode, the output data rate is equal to the product of the external
clock frequency and the scale factor in the SYNC_SCALE register.

This patch uses the "clock-names" property to enable the external clock
in one of the two supported modes: "sync" or "pps". This property is
optional. If it is not specified, the internal clock is used.

This patch also offers the option to select the DIOx line to be used as
an external clock input via the custom "adi,ext-clk-pin" property. If this
field is left empty, DIO2 is assigned as default external clock input pin.
Each DIOx pin supports only one function at a time (data ready line
selection or external clock input).

Signed-off-by: Stefan Popa 
---
Changes in v2:
- used ADIS16480_DRDY_SEL() macro when checking for external clock
  input pin.

 drivers/iio/imu/adis16480.c | 186 ++--
 1 file changed, 179 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 28cece3..ab137c1 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -9,6 +9,7 @@
  *
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -99,6 +100,12 @@
 #define ADIS16480_REG_FIRM_DM  ADIS16480_REG(0x03, 0x7A)
 #define ADIS16480_REG_FIRM_Y   ADIS16480_REG(0x03, 0x7C)
 
+/*
+ * External clock scaling in PPS mode.
+ * Available only for ADIS1649x devices
+ */
+#define ADIS16495_REG_SYNC_SCALE   ADIS16480_REG(0x03, 0x10)
+
 #define ADIS16480_REG_SERIAL_NUM   ADIS16480_REG(0x04, 0x20)
 
 /* Each filter coefficent bank spans two pages */
@@ -116,6 +123,12 @@
 #define ADIS16480_DRDY_POL(x)  FIELD_PREP(ADIS16480_DRDY_POL_MSK, x)
 #define ADIS16480_DRDY_EN_MSK  BIT(3)
 #define ADIS16480_DRDY_EN(x)   FIELD_PREP(ADIS16480_DRDY_EN_MSK, x)
+#define ADIS16480_SYNC_SEL_MSK GENMASK(5, 4)
+#define ADIS16480_SYNC_SEL(x)  FIELD_PREP(ADIS16480_SYNC_SEL_MSK, x)
+#define ADIS16480_SYNC_EN_MSK  BIT(7)
+#define ADIS16480_SYNC_EN(x)   FIELD_PREP(ADIS16480_SYNC_EN_MSK, x)
+#define ADIS16480_SYNC_MODE_MSKBIT(8)
+#define ADIS16480_SYNC_MODE(x) FIELD_PREP(ADIS16480_SYNC_MODE_MSK, x)
 
 struct adis16480_chip_info {
unsigned int num_channels;
@@ -128,6 +141,7 @@ struct adis16480_chip_info {
unsigned int int_clk;
unsigned int max_dec_rate;
const unsigned int *filter_freqs;
+   bool has_pps_clk_mode;
 };
 
 enum adis16480_int_pin {
@@ -137,10 +151,19 @@ enum adis16480_int_pin {
ADIS16480_PIN_DIO4
 };
 
+enum adis16480_clock_mode {
+   ADIS16480_CLK_SYNC,
+   ADIS16480_CLK_PPS,
+   ADIS16480_CLK_INT
+};
+
 struct adis16480 {
const struct adis16480_chip_info *chip_info;
 
struct adis adis;
+   struct clk *ext_clk;
+   enum adis16480_clock_mode clk_mode;
+   unsigned int clk_freq;
 };
 
 static const char * const adis16480_int_pin_names[4] = {
@@ -296,20 +319,34 @@ static int adis16480_debugfs_init(struct iio_dev 
*indio_dev)
 static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2)
 {
struct adis16480 *st = iio_priv(indio_dev);
-   unsigned int t;
+   unsigned int t, reg;
 
t =  val * 1000 + val2 / 1000;
if (t <= 0)
return -EINVAL;
 
-   t = st->chip_info->int_clk / t;
+   /*
+* When using PPS mode, the rate of data collection is equal to the
+* product of the external clock frequency and the scale factor in the
+* SYNC_SCALE register.
+* When using sync mode, or internal clock, the output data rate is
+* equal with  the clock frequency divided by DEC_RATE + 1.
+*/
+   if (st->clk_mode == ADIS16480_CLK_PPS) {
+   t = t / st->clk_freq;
+   reg = ADIS16495_REG_SYNC_SCALE;
+   } else {
+   t = st->clk_freq / t;
+   reg = ADIS16480_REG_DEC_RATE;
+   }
+
if (t > st->chip_info->max_dec_rate)
t = st->chip_info->max_dec_rate;
 
-   if (t != 0)
+   if ((t != 0) && (st->clk_mode != ADIS16480_CLK_PPS))
t--;
 
-   return adis_write_reg_16(>adis, ADIS16480_REG_DEC_RATE, t);
+   return adis_write_reg_16(>adis, reg, t);
 }
 

[PATCH 2/2] dt-bindings: iio: imu: adis16480: Document external clock

2019-03-07 Thread Stefan Popa
Add documentation for optional use of external clock. All devices
supported by this driver can work with an external clock in sync mode.
Another mode, called Pulse Per Second (PPS) is supported only by adis1649x
devices. The mode is selected by using the "clock-names" property.

The pin which is used as external clock input is selected by using a
custom optional property called "adi,ext-clk-pin". If this field is left
empty, DIO2 is assigned as default external clock input pin.

Signed-off-by: Stefan Popa 
---
 .../devicetree/bindings/iio/imu/adi,adis16480.txt  | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt 
b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
index 39ab016..9e2fcd4 100644
--- a/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
+++ b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
@@ -34,6 +34,37 @@ Optional properties:
signal.
 - reset-gpios: must be the device tree identifier of the RESET pin. As the line
is active low, it should be marked GPIO_ACTIVE_LOW.
+- clocks: phandle to the external clock. Should be set according to
+   "clock-names".
+   If this field is left empty, the internal clock is used.
+- clock-names: The name of the external clock to be used. Valid values are:
+   * sync: In sync mode, the internal clock is disabled and the frequency
+   of the external clock signal establishes therate of data
+   collection and processing. See Fig 14 and 15 in the datasheet.
+   The clock-frequency must be:
+   * 3000 to 4500 Hz for adis1649x devices.
+   * 700 to 2400 Hz for adis1648x devices.
+   * pps: In Pulse Per Second (PPS) Mode, the rate of data collection and
+  production is equal to the product of the external clock
+  frequency and the scale factor in the SYNC_SCALE register, see
+  Table 154 in the datasheet.
+  The clock-frequency must be:
+  * 1 to 128 Hz for adis1649x devices.
+  * This mode is not supported by adis1648x devices.
+   If this field is left empty, the internal clock is used.
+- adi,ext-clk-pin: The DIOx line to be used as an external clock input.
+   Valid values are:
+   * DIO1
+   * DIO2
+   * DIO3
+   * DIO4
+   Each DIOx pin supports only one function at a time (data ready line
+   selection or external clock input). When a single pin has two
+   two assignments, the enable bit for the lower priority function
+   automatically resets to zero (disabling the lower priority function).
+   Data ready has highest priority.
+   If this field is left empty, DIO2 is assigned as default external clock
+   input pin.
 
 Example:
 
@@ -46,4 +77,7 @@ Example:
interrupts = <25 IRQF_TRIGGER_FALLING>;
interrupt-parent = <>;
interrupt-names = "DIO2";
+   clocks = <_sync>;
+   clock-names = "sync";
+   adi,ext-clk-pin = "DIO1";
};
-- 
2.7.4



[PATCH 1/2] iio: imu: adis16480: Add support for external clock

2019-03-07 Thread Stefan Popa
Inertial sensor data collection and processing can be controlled by
configuring one of the DIOx lines as an external clock input. This
option is available for all devices supported by this driver. However,
only adis1649x devices support different modes for the external clock.

Sync mode is supported by all devices. In this mode, the output data
rate is equal with the clock frequency divided by DEC_RATE + 1. This
mode of calculation is similar with the case when the internal clock is
used.

Pulse Per Second (PPS) Mode, is only supported by adis1649x devices. In
this mode, the output data rate is equal to the product of the external
clock frequency and the scale factor in the SYNC_SCALE register.

This patch uses the "clock-names" property to enable the external clock
in one of the two supported modes: "sync" or "pps". This property is
optional. If it is not specified, the internal clock is used.

This patch also offers the option to select the DIOx line to be used as
an external clock input via the custom "adi,ext-clk-pin" property. If this
field is left empty, DIO2 is assigned as default external clock input pin.
Each DIOx pin supports only one function at a time (data ready line
selection or external clock input).

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 186 ++--
 1 file changed, 179 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 28cece3..3a93a85 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -9,6 +9,7 @@
  *
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -99,6 +100,12 @@
 #define ADIS16480_REG_FIRM_DM  ADIS16480_REG(0x03, 0x7A)
 #define ADIS16480_REG_FIRM_Y   ADIS16480_REG(0x03, 0x7C)
 
+/*
+ * External clock scaling in PPS mode.
+ * Available only for ADIS1649x devices
+ */
+#define ADIS16495_REG_SYNC_SCALE   ADIS16480_REG(0x03, 0x10)
+
 #define ADIS16480_REG_SERIAL_NUM   ADIS16480_REG(0x04, 0x20)
 
 /* Each filter coefficent bank spans two pages */
@@ -116,6 +123,12 @@
 #define ADIS16480_DRDY_POL(x)  FIELD_PREP(ADIS16480_DRDY_POL_MSK, x)
 #define ADIS16480_DRDY_EN_MSK  BIT(3)
 #define ADIS16480_DRDY_EN(x)   FIELD_PREP(ADIS16480_DRDY_EN_MSK, x)
+#define ADIS16480_SYNC_SEL_MSK GENMASK(5, 4)
+#define ADIS16480_SYNC_SEL(x)  FIELD_PREP(ADIS16480_SYNC_SEL_MSK, x)
+#define ADIS16480_SYNC_EN_MSK  BIT(7)
+#define ADIS16480_SYNC_EN(x)   FIELD_PREP(ADIS16480_SYNC_EN_MSK, x)
+#define ADIS16480_SYNC_MODE_MSKBIT(8)
+#define ADIS16480_SYNC_MODE(x) FIELD_PREP(ADIS16480_SYNC_MODE_MSK, x)
 
 struct adis16480_chip_info {
unsigned int num_channels;
@@ -128,6 +141,7 @@ struct adis16480_chip_info {
unsigned int int_clk;
unsigned int max_dec_rate;
const unsigned int *filter_freqs;
+   bool has_pps_clk_mode;
 };
 
 enum adis16480_int_pin {
@@ -137,10 +151,19 @@ enum adis16480_int_pin {
ADIS16480_PIN_DIO4
 };
 
+enum adis16480_clock_mode {
+   ADIS16480_CLK_SYNC,
+   ADIS16480_CLK_PPS,
+   ADIS16480_CLK_INT
+};
+
 struct adis16480 {
const struct adis16480_chip_info *chip_info;
 
struct adis adis;
+   struct clk *ext_clk;
+   enum adis16480_clock_mode clk_mode;
+   unsigned int clk_freq;
 };
 
 static const char * const adis16480_int_pin_names[4] = {
@@ -296,20 +319,34 @@ static int adis16480_debugfs_init(struct iio_dev 
*indio_dev)
 static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2)
 {
struct adis16480 *st = iio_priv(indio_dev);
-   unsigned int t;
+   unsigned int t, reg;
 
t =  val * 1000 + val2 / 1000;
if (t <= 0)
return -EINVAL;
 
-   t = st->chip_info->int_clk / t;
+   /*
+* When using PPS mode, the rate of data collection is equal to the
+* product of the external clock frequency and the scale factor in the
+* SYNC_SCALE register.
+* When using sync mode, or internal clock, the output data rate is
+* equal with  the clock frequency divided by DEC_RATE + 1.
+*/
+   if (st->clk_mode == ADIS16480_CLK_PPS) {
+   t = t / st->clk_freq;
+   reg = ADIS16495_REG_SYNC_SCALE;
+   } else {
+   t = st->clk_freq / t;
+   reg = ADIS16480_REG_DEC_RATE;
+   }
+
if (t > st->chip_info->max_dec_rate)
t = st->chip_info->max_dec_rate;
 
-   if (t != 0)
+   if ((t != 0) && (st->clk_mode != ADIS16480_CLK_PPS))
t--;
 
-   return adis_write_reg_16(>adis, ADIS16480_REG_DEC_RATE, t);
+   return adis_write_reg_16(>adis, reg, t);
 }
 
 static int adis16480_get_freq(struct iio_dev *indio_dev, int *val, int *val2)
@@ -318,12 +355,29 @@ static 

[PATCH v3 7/7] iio: imu: adis16480: Add docs for ADIS16480 IMU

2019-02-27 Thread Stefan Popa
Document support for ADIS16480 Inertial Measurement Unit.

Signed-off-by: Stefan Popa 
Reviewed-by: Rob Herring 
---
 .../devicetree/bindings/iio/imu/adi,adis16480.txt  | 49 ++
 MAINTAINERS|  1 +
 2 files changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt

diff --git a/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt 
b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
new file mode 100644
index 000..39ab016
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
@@ -0,0 +1,49 @@
+
+Analog Devices ADIS16480 and similar IMUs
+
+Required properties for the ADIS16480:
+
+- compatible: Must be one of
+   * "adi,adis16375"
+   * "adi,adis16480"
+   * "adi,adis16485"
+   * "adi,adis16488"
+   * "adi,adis16495-1"
+   * "adi,adis16495-2"
+   * "adi,adis16495-3"
+   * "adi,adis16497-1"
+   * "adi,adis16497-2"
+   * "adi,adis16497-3"
+- 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
+- spi-cpol: See Documentation/devicetree/bindings/spi/spi-bus.txt
+- interrupts: interrupt mapping for IRQ, accepted values are:
+   * IRQF_TRIGGER_RISING
+   * IRQF_TRIGGER_FALLING
+
+Optional properties:
+
+- interrupt-names: Data ready line selection. Valid values are:
+   * DIO1
+   * DIO2
+   * DIO3
+   * DIO4
+   If this field is left empty, DIO1 is assigned as default data ready
+   signal.
+- reset-gpios: must be the device tree identifier of the RESET pin. As the line
+   is active low, it should be marked GPIO_ACTIVE_LOW.
+
+Example:
+
+   imu@0 {
+   compatible = "adi,adis16495-1";
+   reg = <0>;
+   spi-max-frequency = <320>;
+   spi-cpol;
+   spi-cpha;
+   interrupts = <25 IRQF_TRIGGER_FALLING>;
+   interrupt-parent = <>;
+   interrupt-names = "DIO2";
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index e4091ac..beecd1e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -942,6 +942,7 @@ F:  drivers/dma/dma-axi-dmac.c
 ANALOG DEVICES INC IIO DRIVERS
 M: Lars-Peter Clausen 
 M: Michael Hennerich 
+M: Stefan Popa 
 W: http://wiki.analog.com/
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
-- 
2.7.4



[PATCH v3 6/7] iio: imu: adis16480: Add support for ADIS1649x family of devices

2019-02-27 Thread Stefan Popa
The ADIS16495 and ADIS16497 are inertial systems that include a triaxis
gyroscope and a triaxis accelerometer. The serial peripheral interface
(SPI) provide a simple interface for data collection and configuration
control. The devices are similar to ADIS16475, ADIS16480, ADIS16485 and
ADIS16488, the main differences are highlighted below:

* The temperature data scale is 0.00565 C/LSB for ADIS16475 and ADIS1648x
  devices, while for ADIS1649x 0.0125 C/LSB.

* ADIS1649x devices support different gyroscope measurement ranges which
  are dependent on the dash number (-1, -2, -3), see Table 24 in the
  ADIS16495 datasheet. However, the ADIS16497 gyroscopes have the same
  scale as ADIS16495.

* ADIS16495 devices support the acceleration maximum range of 8g, while
  ADIS16497 devices go up to 40g.

* The internal clock for ADIS1649x devices is 4.25 kSPS. The sampling
  frequency is calculated by applying a decimation rate which can take a
  maximum value of 4250.

* ADIS1649x devices support different default filter frequencies.

Datasheets:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adis16495.pdf
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adis16497.pdf

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 97 +
 1 file changed, 97 insertions(+)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index c90375d..28cece3 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -453,6 +453,13 @@ static const unsigned int adis16480_def_filter_freqs[] = {
63,
 };
 
+static const unsigned int adis16495_def_filter_freqs[] = {
+   300,
+   100,
+   300,
+   100,
+};
+
 static const unsigned int ad16480_filter_data[][2] = {
[ADIS16480_SCAN_GYRO_X] = { ADIS16480_REG_FILTER_BNK0, 0 },
[ADIS16480_SCAN_GYRO_Y] = { ADIS16480_REG_FILTER_BNK0, 3 },
@@ -713,6 +720,12 @@ enum adis16480_variant {
ADIS16480,
ADIS16485,
ADIS16488,
+   ADIS16495_1,
+   ADIS16495_2,
+   ADIS16495_3,
+   ADIS16497_1,
+   ADIS16497_2,
+   ADIS16497_3,
 };
 
 static const struct adis16480_chip_info adis16480_chip_info[] = {
@@ -769,6 +782,78 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.max_dec_rate = 2048,
.filter_freqs = adis16480_def_filter_freqs,
},
+   [ADIS16495_1] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 125,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 8,
+   .temp_scale = 12500, /* 12.5 milli degree Celsius */
+   .int_clk = 425,
+   .max_dec_rate = 4250,
+   .filter_freqs = adis16495_def_filter_freqs,
+   },
+   [ADIS16495_2] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(18000),
+   .gyro_max_scale = 450,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 8,
+   .temp_scale = 12500, /* 12.5 milli degree Celsius */
+   .int_clk = 425,
+   .max_dec_rate = 4250,
+   .filter_freqs = adis16495_def_filter_freqs,
+   },
+   [ADIS16495_3] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 2000,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 8,
+   .temp_scale = 12500, /* 12.5 milli degree Celsius */
+   .int_clk = 425,
+   .max_dec_rate = 4250,
+   .filter_freqs = adis16495_def_filter_freqs,
+   },
+   [ADIS16497_1] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 125,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 40,
+   .temp_scale = 12500, /* 12.5 milli degree Celsius */
+   .int_clk = 425,
+   .max_dec_rate = 4250,
+   .filter_freqs = adis16495_def_filter_freqs,
+   },
+   [ADIS16497_2] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(18000),
+   .gyro_max_scale = 450,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 40

[PATCH v3 5/7] iio: imu: adis16480: Deal with filter freq in a generic way

2019-02-27 Thread Stefan Popa
When setting the filter frequency, the driver looks into the
adis16480_def_filter_freqs table for the best match. Pass this table to
the chip_info struct since future devices will need to use a different
table.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 92abc95..c90375d 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -127,6 +127,7 @@ struct adis16480_chip_info {
unsigned int temp_scale;
unsigned int int_clk;
unsigned int max_dec_rate;
+   const unsigned int *filter_freqs;
 };
 
 enum adis16480_int_pin {
@@ -483,7 +484,7 @@ static int adis16480_get_filter_freq(struct iio_dev 
*indio_dev,
if (!(val & enable_mask))
*freq = 0;
else
-   *freq = adis16480_def_filter_freqs[(val >> offset) & 0x3];
+   *freq = st->chip_info->filter_freqs[(val >> offset) & 0x3];
 
return IIO_VAL_INT;
 }
@@ -510,10 +511,10 @@ static int adis16480_set_filter_freq(struct iio_dev 
*indio_dev,
val &= ~enable_mask;
} else {
best_freq = 0;
-   best_diff = 310;
+   best_diff = st->chip_info->filter_freqs[0];
for (i = 0; i < ARRAY_SIZE(adis16480_def_filter_freqs); i++) {
-   if (adis16480_def_filter_freqs[i] >= freq) {
-   diff = adis16480_def_filter_freqs[i] - freq;
+   if (st->chip_info->filter_freqs[i] >= freq) {
+   diff = st->chip_info->filter_freqs[i] - freq;
if (diff < best_diff) {
best_diff = diff;
best_freq = i;
@@ -730,6 +731,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 246,
.max_dec_rate = 2048,
+   .filter_freqs = adis16480_def_filter_freqs,
},
[ADIS16480] = {
.channels = adis16480_channels,
@@ -741,6 +743,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 246,
.max_dec_rate = 2048,
+   .filter_freqs = adis16480_def_filter_freqs,
},
[ADIS16485] = {
.channels = adis16485_channels,
@@ -752,6 +755,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 246,
.max_dec_rate = 2048,
+   .filter_freqs = adis16480_def_filter_freqs,
},
[ADIS16488] = {
.channels = adis16480_channels,
@@ -763,6 +767,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 246,
.max_dec_rate = 2048,
+   .filter_freqs = adis16480_def_filter_freqs,
},
 };
 
-- 
2.7.4



[PATCH v3 4/7] iio: imu: adis16480: Calculate the sampling frequency in a generic way

2019-02-27 Thread Stefan Popa
The adis1648x devices have an internal clock of 2.46 kSPS. The sampling
frequency is calculated by applying a decimation rate which can take the
maximum value of 2047.

Although all adis1648x devices are similar in this regard, devices that
will use this feature will be added in the future.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 5a2864a..92abc95 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -125,6 +125,8 @@ struct adis16480_chip_info {
unsigned int accel_max_val;
unsigned int accel_max_scale;
unsigned int temp_scale;
+   unsigned int int_clk;
+   unsigned int max_dec_rate;
 };
 
 enum adis16480_int_pin {
@@ -299,9 +301,9 @@ static int adis16480_set_freq(struct iio_dev *indio_dev, 
int val, int val2)
if (t <= 0)
return -EINVAL;
 
-   t = 246 / t;
-   if (t > 2048)
-   t = 2048;
+   t = st->chip_info->int_clk / t;
+   if (t > st->chip_info->max_dec_rate)
+   t = st->chip_info->max_dec_rate;
 
if (t != 0)
t--;
@@ -320,7 +322,7 @@ static int adis16480_get_freq(struct iio_dev *indio_dev, 
int *val, int *val2)
if (ret < 0)
return ret;
 
-   freq = 246 / (t + 1);
+   freq = st->chip_info->int_clk / (t + 1);
*val = freq / 1000;
*val2 = (freq % 1000) * 1000;
 
@@ -726,6 +728,8 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.accel_max_val = IIO_M_S_2_TO_G(21973),
.accel_max_scale = 18,
.temp_scale = 5650, /* 5.65 milli degree Celsius */
+   .int_clk = 246,
+   .max_dec_rate = 2048,
},
[ADIS16480] = {
.channels = adis16480_channels,
@@ -735,6 +739,8 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.accel_max_val = IIO_M_S_2_TO_G(12500),
.accel_max_scale = 10,
.temp_scale = 5650, /* 5.65 milli degree Celsius */
+   .int_clk = 246,
+   .max_dec_rate = 2048,
},
[ADIS16485] = {
.channels = adis16485_channels,
@@ -744,6 +750,8 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.accel_max_val = IIO_M_S_2_TO_G(2),
.accel_max_scale = 5,
.temp_scale = 5650, /* 5.65 milli degree Celsius */
+   .int_clk = 246,
+   .max_dec_rate = 2048,
},
[ADIS16488] = {
.channels = adis16480_channels,
@@ -753,6 +761,8 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.accel_max_val = IIO_M_S_2_TO_G(22500),
.accel_max_scale = 18,
.temp_scale = 5650, /* 5.65 milli degree Celsius */
+   .int_clk = 246,
+   .max_dec_rate = 2048,
},
 };
 
-- 
2.7.4



[PATCH v3 2/7] iio: imu: adis16480: Add OF device ID table

2019-02-27 Thread Stefan Popa
The driver does not have a struct of_device_id table, but supported
devices are registered via Device Trees. This patch adds OF device ID
table.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 98a23ac..150d814 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -991,9 +991,19 @@ static const struct spi_device_id adis16480_ids[] = {
 };
 MODULE_DEVICE_TABLE(spi, adis16480_ids);
 
+static const struct of_device_id adis16480_of_match[] = {
+   { .compatible = "adi,adis16375" },
+   { .compatible = "adi,adis16480" },
+   { .compatible = "adi,adis16485" },
+   { .compatible = "adi,adis16488" },
+   { },
+};
+MODULE_DEVICE_TABLE(of, adis16480_of_match);
+
 static struct spi_driver adis16480_driver = {
.driver = {
.name = "adis16480",
+   .of_match_table = adis16480_of_match,
},
.id_table = adis16480_ids,
.probe = adis16480_probe,
-- 
2.7.4



[PATCH v3 3/7] iio: imu: adis16480: Treat temperature scale in a generic way

2019-02-27 Thread Stefan Popa
All supported devices provide internal temperature measurement from -40 C
to +85 C, with +25 C representing value 0x00.

This patch treats the temperature scale in a generic way, similar to the
accelerometer and gyroscope scales. So far, there are no temperature max
scale differences between the supported devices. However, devices that
will make use of this feature will be added in the future.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 150d814..5a2864a 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -124,6 +124,7 @@ struct adis16480_chip_info {
unsigned int gyro_max_scale;
unsigned int accel_max_val;
unsigned int accel_max_scale;
+   unsigned int temp_scale;
 };
 
 enum adis16480_int_pin {
@@ -530,6 +531,7 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan, int *val, int *val2, long info)
 {
struct adis16480 *st = iio_priv(indio_dev);
+   unsigned int temp;
 
switch (info) {
case IIO_CHAN_INFO_RAW:
@@ -549,8 +551,13 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
*val2 = 100; /* 0.0001 gauss */
return IIO_VAL_INT_PLUS_MICRO;
case IIO_TEMP:
-   *val = 5;
-   *val2 = 65; /* 5.65 milli degree Celsius */
+   /*
+* +85 degrees Celsius = temp_max_scale
+* +25 degrees Celsius = 0
+* LSB, 25 degrees Celsius  = 60 / temp_max_scale
+*/
+   *val = st->chip_info->temp_scale / 1000;
+   *val2 = (st->chip_info->temp_scale % 1000) * 1000;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_PRESSURE:
*val = 0;
@@ -561,7 +568,8 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
}
case IIO_CHAN_INFO_OFFSET:
/* Only the temperature channel has a offset */
-   *val = 4425; /* 25 degree Celsius = 0x */
+   temp = 25 * 100LL; /* 25 degree Celsius = 0x */
+   *val = DIV_ROUND_CLOSEST_ULL(temp, st->chip_info->temp_scale);
return IIO_VAL_INT;
case IIO_CHAN_INFO_CALIBBIAS:
return adis16480_get_calibbias(indio_dev, chan, val);
@@ -717,6 +725,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 300,
.accel_max_val = IIO_M_S_2_TO_G(21973),
.accel_max_scale = 18,
+   .temp_scale = 5650, /* 5.65 milli degree Celsius */
},
[ADIS16480] = {
.channels = adis16480_channels,
@@ -725,6 +734,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(12500),
.accel_max_scale = 10,
+   .temp_scale = 5650, /* 5.65 milli degree Celsius */
},
[ADIS16485] = {
.channels = adis16485_channels,
@@ -733,6 +743,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(2),
.accel_max_scale = 5,
+   .temp_scale = 5650, /* 5.65 milli degree Celsius */
},
[ADIS16488] = {
.channels = adis16480_channels,
@@ -741,6 +752,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(22500),
.accel_max_scale = 18,
+   .temp_scale = 5650, /* 5.65 milli degree Celsius */
},
 };
 
-- 
2.7.4



[PATCH v3 0/7] iio: imu: adis16480: Add support for ADIS1649x family of devices

2019-02-27 Thread Stefan Popa
This series has as main goal to add support for ADIS1649x family of devices as
part of the already existing adis16480, but on the way it also deals with some
outstanding items:

* Make drdy pin configurable
* Add OF device ID table
* Deal with the temperature max scale in a generic way
* Deal with sampling and filter freq in a generic way
* Add missing docs

Changes in v3:
Patch 1, 2, 3:
- Nothing changed
Patch 4, 5:
- Added to this series
Patch 6:
- Added support for sampling and filter freq
Patch 7:
- Nothing changed

Changes in v2:
Patch 1:
- use DIO1 pin as default data ready signal instead of DIO2.
Patch 2:
- nothing changed.
Patch 3, 4:
- give the scale directly in the adis16480_chip_info struct.
Patch 5: 
- document the use of DIO1 pin as default data ready signal.

Stefan Popa (7):
  iio: imu: adis16480: Add support for configurable drdy indicator
  iio: imu: adis16480: Add OF device ID table
  iio: imu: adis16480: Treat temperature scale in a generic way
  iio: imu: adis16480: Calculate the sampling frequency in a generic way
  iio: imu: adis16480: Deal with filter freq in a generic way
  iio: imu: adis16480: Add support for ADIS1649x family of devices
  iio: imu: adis16480: Add docs for ADIS16480 IMU

 .../devicetree/bindings/iio/imu/adi,adis16480.txt  |  49 
 MAINTAINERS|   1 +
 drivers/iio/imu/adis16480.c| 253 +++--
 3 files changed, 290 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt

-- 
2.7.4



[PATCH v3 1/7] iio: imu: adis16480: Add support for configurable drdy indicator

2019-02-27 Thread Stefan Popa
The FNCTIO_CTRL register provides configuration control for each I/O pin
(DIO1, DIO2, DIO3 and DIO4).

This patch adds the option to configure each DIOx pin as data ready
indicator with positive or negative polarity by reading the 'interrupts'
and 'interrupt-names' properties from the devicetree. The
'interrupt-names' property is optional, if it is not specified, then the
DIO1 pin is used as default data ready signal.

Although the factory default assigns DIO2 as data ready signal, in the
versions previous this patch, DIO1 pin was used. We should leave this
configuration as is, since some devices might be expecting the interrupt
on the wrong physical pin.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 97 -
 1 file changed, 95 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index a27fe20..98a23ac 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -9,6 +9,8 @@
  *
  */
 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -107,6 +109,14 @@
 #define ADIS16480_FIR_COEF_C(x)
ADIS16480_FIR_COEF(0x09, (x))
 #define ADIS16480_FIR_COEF_D(x)
ADIS16480_FIR_COEF(0x0B, (x))
 
+/* ADIS16480_REG_FNCTIO_CTRL */
+#define ADIS16480_DRDY_SEL_MSK GENMASK(1, 0)
+#define ADIS16480_DRDY_SEL(x)  FIELD_PREP(ADIS16480_DRDY_SEL_MSK, x)
+#define ADIS16480_DRDY_POL_MSK BIT(2)
+#define ADIS16480_DRDY_POL(x)  FIELD_PREP(ADIS16480_DRDY_POL_MSK, x)
+#define ADIS16480_DRDY_EN_MSK  BIT(3)
+#define ADIS16480_DRDY_EN(x)   FIELD_PREP(ADIS16480_DRDY_EN_MSK, x)
+
 struct adis16480_chip_info {
unsigned int num_channels;
const struct iio_chan_spec *channels;
@@ -116,12 +126,26 @@ struct adis16480_chip_info {
unsigned int accel_max_scale;
 };
 
+enum adis16480_int_pin {
+   ADIS16480_PIN_DIO1,
+   ADIS16480_PIN_DIO2,
+   ADIS16480_PIN_DIO3,
+   ADIS16480_PIN_DIO4
+};
+
 struct adis16480 {
const struct adis16480_chip_info *chip_info;
 
struct adis adis;
 };
 
+static const char * const adis16480_int_pin_names[4] = {
+   [ADIS16480_PIN_DIO1] = "DIO1",
+   [ADIS16480_PIN_DIO2] = "DIO2",
+   [ADIS16480_PIN_DIO3] = "DIO3",
+   [ADIS16480_PIN_DIO4] = "DIO4",
+};
+
 #ifdef CONFIG_DEBUG_FS
 
 static ssize_t adis16480_show_firmware_revision(struct file *file,
@@ -741,8 +765,17 @@ static int adis16480_stop_device(struct iio_dev *indio_dev)
 
 static int adis16480_enable_irq(struct adis *adis, bool enable)
 {
-   return adis_write_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL,
-   enable ? BIT(3) : 0);
+   uint16_t val;
+   int ret;
+
+   ret = adis_read_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL, );
+   if (ret < 0)
+   return ret;
+
+   val &= ~ADIS16480_DRDY_EN_MSK;
+   val |= ADIS16480_DRDY_EN(enable);
+
+   return adis_write_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL, val);
 }
 
 static int adis16480_initial_setup(struct iio_dev *indio_dev)
@@ -826,6 +859,62 @@ static const struct adis_data adis16480_data = {
.enable_irq = adis16480_enable_irq,
 };
 
+static int adis16480_config_irq_pin(struct device_node *of_node,
+   struct adis16480 *st)
+{
+   struct irq_data *desc;
+   enum adis16480_int_pin pin;
+   unsigned int irq_type;
+   uint16_t val;
+   int i, irq = 0;
+
+   desc = irq_get_irq_data(st->adis.spi->irq);
+   if (!desc) {
+   dev_err(>adis.spi->dev, "Could not find IRQ %d\n", irq);
+   return -EINVAL;
+   }
+
+   /* Disable data ready since the default after reset is on */
+   val = ADIS16480_DRDY_EN(0);
+
+   /*
+* Get the interrupt from the devicetre by reading the interrupt-names
+* property. If it is not specified, use DIO1 pin as default.
+* According to the datasheet, the factory default assigns DIO2 as data
+* ready signal. However, in the previous versions of the driver, DIO1
+* pin was used. So, we should leave it as is since some devices might
+* be expecting the interrupt on the wrong physical pin.
+*/
+   pin = ADIS16480_PIN_DIO1;
+   for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) {
+   irq = of_irq_get_byname(of_node, adis16480_int_pin_names[i]);
+   if (irq > 0) {
+   pin = i;
+   break;
+   }
+   }
+
+   val |= ADIS16480_DRDY_SEL(pin);
+
+   /*
+* Get the interrupt line behaviour. The data ready polarity can be
+* configured as positive or negative, corresponding to
+* IRQF_TRIGGER_RISING or IRQF_TRIGGER_FALLING respectively.
+*/
+   irq_type = irqd_get_trigger_type(desc);
+   if (irq_type == IRQF_

[PATCH v2 5/5] iio: imu: adis16480: Add docs for ADIS16480 IMU

2019-02-21 Thread Stefan Popa
Document support for ADIS16480 Inertial Measurement Unit.

Signed-off-by: Stefan Popa 
---
 .../devicetree/bindings/iio/imu/adi,adis16480.txt  | 49 ++
 MAINTAINERS|  1 +
 2 files changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt

diff --git a/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt 
b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
new file mode 100644
index 000..39ab016
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
@@ -0,0 +1,49 @@
+
+Analog Devices ADIS16480 and similar IMUs
+
+Required properties for the ADIS16480:
+
+- compatible: Must be one of
+   * "adi,adis16375"
+   * "adi,adis16480"
+   * "adi,adis16485"
+   * "adi,adis16488"
+   * "adi,adis16495-1"
+   * "adi,adis16495-2"
+   * "adi,adis16495-3"
+   * "adi,adis16497-1"
+   * "adi,adis16497-2"
+   * "adi,adis16497-3"
+- 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
+- spi-cpol: See Documentation/devicetree/bindings/spi/spi-bus.txt
+- interrupts: interrupt mapping for IRQ, accepted values are:
+   * IRQF_TRIGGER_RISING
+   * IRQF_TRIGGER_FALLING
+
+Optional properties:
+
+- interrupt-names: Data ready line selection. Valid values are:
+   * DIO1
+   * DIO2
+   * DIO3
+   * DIO4
+   If this field is left empty, DIO1 is assigned as default data ready
+   signal.
+- reset-gpios: must be the device tree identifier of the RESET pin. As the line
+   is active low, it should be marked GPIO_ACTIVE_LOW.
+
+Example:
+
+   imu@0 {
+   compatible = "adi,adis16495-1";
+   reg = <0>;
+   spi-max-frequency = <320>;
+   spi-cpol;
+   spi-cpha;
+   interrupts = <25 IRQF_TRIGGER_FALLING>;
+   interrupt-parent = <>;
+   interrupt-names = "DIO2";
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index e4091ac..beecd1e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -942,6 +942,7 @@ F:  drivers/dma/dma-axi-dmac.c
 ANALOG DEVICES INC IIO DRIVERS
 M: Lars-Peter Clausen 
 M: Michael Hennerich 
+M: Stefan Popa 
 W: http://wiki.analog.com/
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
-- 
2.7.4



[PATCH v2 3/5] iio: imu: adis16480: Treat temperature scale in a generic way

2019-02-21 Thread Stefan Popa
All supported devices provide internal temperature measurement from -40 C
to +85 C, with +25 C representing value 0x00.

This patch treats the temperature scale in a generic way, similar to the
accelerometer and gyroscope scales. So far, there are no temperature max
scale differences between the supported devices. However, devices that
will make use of this feature will be added in the future.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 150d814..5a2864a 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -124,6 +124,7 @@ struct adis16480_chip_info {
unsigned int gyro_max_scale;
unsigned int accel_max_val;
unsigned int accel_max_scale;
+   unsigned int temp_scale;
 };
 
 enum adis16480_int_pin {
@@ -530,6 +531,7 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan, int *val, int *val2, long info)
 {
struct adis16480 *st = iio_priv(indio_dev);
+   unsigned int temp;
 
switch (info) {
case IIO_CHAN_INFO_RAW:
@@ -549,8 +551,13 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
*val2 = 100; /* 0.0001 gauss */
return IIO_VAL_INT_PLUS_MICRO;
case IIO_TEMP:
-   *val = 5;
-   *val2 = 65; /* 5.65 milli degree Celsius */
+   /*
+* +85 degrees Celsius = temp_max_scale
+* +25 degrees Celsius = 0
+* LSB, 25 degrees Celsius  = 60 / temp_max_scale
+*/
+   *val = st->chip_info->temp_scale / 1000;
+   *val2 = (st->chip_info->temp_scale % 1000) * 1000;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_PRESSURE:
*val = 0;
@@ -561,7 +568,8 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
}
case IIO_CHAN_INFO_OFFSET:
/* Only the temperature channel has a offset */
-   *val = 4425; /* 25 degree Celsius = 0x */
+   temp = 25 * 100LL; /* 25 degree Celsius = 0x */
+   *val = DIV_ROUND_CLOSEST_ULL(temp, st->chip_info->temp_scale);
return IIO_VAL_INT;
case IIO_CHAN_INFO_CALIBBIAS:
return adis16480_get_calibbias(indio_dev, chan, val);
@@ -717,6 +725,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 300,
.accel_max_val = IIO_M_S_2_TO_G(21973),
.accel_max_scale = 18,
+   .temp_scale = 5650, /* 5.65 milli degree Celsius */
},
[ADIS16480] = {
.channels = adis16480_channels,
@@ -725,6 +734,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(12500),
.accel_max_scale = 10,
+   .temp_scale = 5650, /* 5.65 milli degree Celsius */
},
[ADIS16485] = {
.channels = adis16485_channels,
@@ -733,6 +743,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(2),
.accel_max_scale = 5,
+   .temp_scale = 5650, /* 5.65 milli degree Celsius */
},
[ADIS16488] = {
.channels = adis16480_channels,
@@ -741,6 +752,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(22500),
.accel_max_scale = 18,
+   .temp_scale = 5650, /* 5.65 milli degree Celsius */
},
 };
 
-- 
2.7.4



[PATCH v2 1/5] iio: imu: adis16480: Add support for configurable drdy indicator

2019-02-21 Thread Stefan Popa
The FNCTIO_CTRL register provides configuration control for each I/O pin
(DIO1, DIO2, DIO3 and DIO4).

This patch adds the option to configure each DIOx pin as data ready
indicator with positive or negative polarity by reading the 'interrupts'
and 'interrupt-names' properties from the devicetree. The
'interrupt-names' property is optional, if it is not specified, then the
DIO1 pin is used as default data ready signal.

Although the factory default assigns DIO2 as data ready signal, in the
versions previous this patch, DIO1 pin was used. We should leave this
configuration as is, since some devices might be expecting the interrupt
on the wrong physical pin.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 97 -
 1 file changed, 95 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index a27fe20..98a23ac 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -9,6 +9,8 @@
  *
  */
 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -107,6 +109,14 @@
 #define ADIS16480_FIR_COEF_C(x)
ADIS16480_FIR_COEF(0x09, (x))
 #define ADIS16480_FIR_COEF_D(x)
ADIS16480_FIR_COEF(0x0B, (x))
 
+/* ADIS16480_REG_FNCTIO_CTRL */
+#define ADIS16480_DRDY_SEL_MSK GENMASK(1, 0)
+#define ADIS16480_DRDY_SEL(x)  FIELD_PREP(ADIS16480_DRDY_SEL_MSK, x)
+#define ADIS16480_DRDY_POL_MSK BIT(2)
+#define ADIS16480_DRDY_POL(x)  FIELD_PREP(ADIS16480_DRDY_POL_MSK, x)
+#define ADIS16480_DRDY_EN_MSK  BIT(3)
+#define ADIS16480_DRDY_EN(x)   FIELD_PREP(ADIS16480_DRDY_EN_MSK, x)
+
 struct adis16480_chip_info {
unsigned int num_channels;
const struct iio_chan_spec *channels;
@@ -116,12 +126,26 @@ struct adis16480_chip_info {
unsigned int accel_max_scale;
 };
 
+enum adis16480_int_pin {
+   ADIS16480_PIN_DIO1,
+   ADIS16480_PIN_DIO2,
+   ADIS16480_PIN_DIO3,
+   ADIS16480_PIN_DIO4
+};
+
 struct adis16480 {
const struct adis16480_chip_info *chip_info;
 
struct adis adis;
 };
 
+static const char * const adis16480_int_pin_names[4] = {
+   [ADIS16480_PIN_DIO1] = "DIO1",
+   [ADIS16480_PIN_DIO2] = "DIO2",
+   [ADIS16480_PIN_DIO3] = "DIO3",
+   [ADIS16480_PIN_DIO4] = "DIO4",
+};
+
 #ifdef CONFIG_DEBUG_FS
 
 static ssize_t adis16480_show_firmware_revision(struct file *file,
@@ -741,8 +765,17 @@ static int adis16480_stop_device(struct iio_dev *indio_dev)
 
 static int adis16480_enable_irq(struct adis *adis, bool enable)
 {
-   return adis_write_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL,
-   enable ? BIT(3) : 0);
+   uint16_t val;
+   int ret;
+
+   ret = adis_read_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL, );
+   if (ret < 0)
+   return ret;
+
+   val &= ~ADIS16480_DRDY_EN_MSK;
+   val |= ADIS16480_DRDY_EN(enable);
+
+   return adis_write_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL, val);
 }
 
 static int adis16480_initial_setup(struct iio_dev *indio_dev)
@@ -826,6 +859,62 @@ static const struct adis_data adis16480_data = {
.enable_irq = adis16480_enable_irq,
 };
 
+static int adis16480_config_irq_pin(struct device_node *of_node,
+   struct adis16480 *st)
+{
+   struct irq_data *desc;
+   enum adis16480_int_pin pin;
+   unsigned int irq_type;
+   uint16_t val;
+   int i, irq = 0;
+
+   desc = irq_get_irq_data(st->adis.spi->irq);
+   if (!desc) {
+   dev_err(>adis.spi->dev, "Could not find IRQ %d\n", irq);
+   return -EINVAL;
+   }
+
+   /* Disable data ready since the default after reset is on */
+   val = ADIS16480_DRDY_EN(0);
+
+   /*
+* Get the interrupt from the devicetre by reading the interrupt-names
+* property. If it is not specified, use DIO1 pin as default.
+* According to the datasheet, the factory default assigns DIO2 as data
+* ready signal. However, in the previous versions of the driver, DIO1
+* pin was used. So, we should leave it as is since some devices might
+* be expecting the interrupt on the wrong physical pin.
+*/
+   pin = ADIS16480_PIN_DIO1;
+   for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) {
+   irq = of_irq_get_byname(of_node, adis16480_int_pin_names[i]);
+   if (irq > 0) {
+   pin = i;
+   break;
+   }
+   }
+
+   val |= ADIS16480_DRDY_SEL(pin);
+
+   /*
+* Get the interrupt line behaviour. The data ready polarity can be
+* configured as positive or negative, corresponding to
+* IRQF_TRIGGER_RISING or IRQF_TRIGGER_FALLING respectively.
+*/
+   irq_type = irqd_get_trigger_type(desc);
+   if (irq_type == IRQF_

[PATCH v2 4/5] iio: imu: adis16480: Add support for ADIS1649x family of devices

2019-02-21 Thread Stefan Popa
The ADIS16495 and ADIS16497 are inertial systems that include a triaxis
gyroscope and a triaxis accelerometer. The serial peripheral interface
(SPI) provide a simple interface for data collection and configuration
control. The devices are similar to ADIS16475, ADIS16480, ADIS16485 and
ADIS16488, the main differences are related to range and scale factors.

The temperature data scale is 0.00565 C/LSB for ADIS16475 and ADIS1648x
devices, while for ADIS1649x 0.0125 C/LSB.

Another difference is that ADIS1649x devices support different gyroscope
measurement ranges which are dependent on the dash number (-1, -2, -3),
see Table 24 in the ADIS16495 datasheet. However, the ADIS16497
gyroscopes have the same scale as ADIS16495.

Furthermore, ADIS16495 devices support the acceleration maximum range of
8g, while ADIS16497 devices go up to 40g.

Datasheets:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adis16495.pdf
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adis16497.pdf

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 72 +
 1 file changed, 72 insertions(+)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 5a2864a..313936c 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -710,6 +710,12 @@ enum adis16480_variant {
ADIS16480,
ADIS16485,
ADIS16488,
+   ADIS16495_1,
+   ADIS16495_2,
+   ADIS16495_3,
+   ADIS16497_1,
+   ADIS16497_2,
+   ADIS16497_3,
 };
 
 static const struct adis16480_chip_info adis16480_chip_info[] = {
@@ -754,6 +760,60 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.accel_max_scale = 18,
.temp_scale = 5650, /* 5.65 milli degree Celsius */
},
+   [ADIS16495_1] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 125,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 8,
+   .temp_scale = 12500, /* 12.5 milli degree Celsius */
+   },
+   [ADIS16495_2] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(18000),
+   .gyro_max_scale = 450,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 8,
+   .temp_scale = 12500, /* 12.5 milli degree Celsius */
+   },
+   [ADIS16495_3] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 2000,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 8,
+   .temp_scale = 12500, /* 12.5 milli degree Celsius */
+   },
+   [ADIS16497_1] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 125,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 40,
+   .temp_scale = 12500, /* 12.5 milli degree Celsius */
+   },
+   [ADIS16497_2] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(18000),
+   .gyro_max_scale = 450,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 40,
+   .temp_scale = 12500, /* 12.5 milli degree Celsius */
+   },
+   [ADIS16497_3] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 2000,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 40,
+   .temp_scale = 12500, /* 12.5 milli degree Celsius */
+   },
 };
 
 static const struct iio_info adis16480_info = {
@@ -999,6 +1059,12 @@ static const struct spi_device_id adis16480_ids[] = {
{ "adis16480", ADIS16480 },
{ "adis16485", ADIS16485 },
{ "adis16488", ADIS16488 },
+   { "adis16495-1", ADIS16495_1 },
+   { "adis16495-2", ADIS16495_2 },
+   { "adis16495-3", ADIS16495_3 },
+   { "adis16497-1", ADIS16497_1 },
+   { "adis16497-2", ADIS16497_2 },
+   { "adis16497-3", ADIS16497_3 },
{ }
 };
 MODULE_DEVICE_TABLE(spi, adis16480_ids);
@@ -1008,6 +1074,12 @@ static

[PATCH v2 2/5] iio: imu: adis16480: Add OF device ID table

2019-02-21 Thread Stefan Popa
The driver does not have a struct of_device_id table, but supported
devices are registered via Device Trees. This patch adds OF device ID
table.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 98a23ac..150d814 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -991,9 +991,19 @@ static const struct spi_device_id adis16480_ids[] = {
 };
 MODULE_DEVICE_TABLE(spi, adis16480_ids);
 
+static const struct of_device_id adis16480_of_match[] = {
+   { .compatible = "adi,adis16375" },
+   { .compatible = "adi,adis16480" },
+   { .compatible = "adi,adis16485" },
+   { .compatible = "adi,adis16488" },
+   { },
+};
+MODULE_DEVICE_TABLE(of, adis16480_of_match);
+
 static struct spi_driver adis16480_driver = {
.driver = {
.name = "adis16480",
+   .of_match_table = adis16480_of_match,
},
.id_table = adis16480_ids,
.probe = adis16480_probe,
-- 
2.7.4



[PATCH v2 0/5] iio: imu: adis16480: Add support for ADIS1649x family of devices

2019-02-21 Thread Stefan Popa
This series has as main goal to add support for ADIS1649x family of devices as
part of the already existing adis16480, but on the way it also deals with some
outstanding items:

* Make drdy pin configurable
* Add OF device ID table
* Deal with the temperature max scale in a generic way
* Add missing docs

Changes in v2:
Patch 1:
- use DIO1 pin as default data ready signal instead of DIO2.
Patch 2:
- nothing changed.
Patch 3, 4:
- give the scale directly in the adis16480_chip_info struct.
Patch 5: 
- document the use of DIO1 pin as default data ready signal.

Stefan Popa (5):
  iio: imu: adis16480: Add support for configurable drdy indicator
  iio: imu: adis16480: Add OF device ID table
  iio: imu: adis16480: Treat temperature scale in a generic way
  iio: imu: adis16480: Add support for ADIS1649x family of devices
  iio: imu: adis16480: Add docs for ADIS16480 IMU

 .../devicetree/bindings/iio/imu/adi,adis16480.txt  |  49 +
 MAINTAINERS|   1 +
 drivers/iio/imu/adis16480.c| 197 -
 3 files changed, 242 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt

-- 
2.7.4



[PATCH 6/6] iio: imu: adis16480: Add docs for ADIS16480 IMU

2019-02-19 Thread Stefan Popa
Document support for ADIS16480 Inertial Measurement Unit.

Signed-off-by: Stefan Popa 
---
 .../devicetree/bindings/iio/imu/adi,adis16480.txt  | 49 ++
 MAINTAINERS|  1 +
 2 files changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt

diff --git a/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt 
b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
new file mode 100644
index 000..dacf5f7
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
@@ -0,0 +1,49 @@
+
+Analog Devices ADIS16480 and similar IMUs
+
+Required properties for the ADIS16480:
+
+- compatible: Must be one of
+   * "adi,adis16375"
+   * "adi,adis16480"
+   * "adi,adis16485"
+   * "adi,adis16488"
+   * "adi,adis16495-1"
+   * "adi,adis16495-2"
+   * "adi,adis16495-3"
+   * "adi,adis16497-1"
+   * "adi,adis16497-2"
+   * "adi,adis16497-3"
+- 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
+- spi-cpol: See Documentation/devicetree/bindings/spi/spi-bus.txt
+- interrupts: interrupt mapping for IRQ, accepted values are:
+   * IRQF_TRIGGER_RISING
+   * IRQF_TRIGGER_FALLING
+
+Optional properties:
+
+- interrupt-names: Data ready line selection. Valid values are:
+   * DIO1
+   * DIO2
+   * DIO3
+   * DIO4
+   If this field is left empty, the factory default assigns DIO2 as data
+   ready signal.
+- reset-gpios: must be the device tree identifier of the RESET pin. As the line
+   is active low, it should be marked GPIO_ACTIVE_LOW.
+
+Example:
+
+   imu@0 {
+   compatible = "adi,adis16495-1";
+   reg = <0>;
+   spi-max-frequency = <320>;
+   spi-cpol;
+   spi-cpha;
+   interrupts = <25 IRQF_TRIGGER_FALLING>;
+   interrupt-parent = <>;
+   interrupt-names = "DIO2";
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index e4091ac..beecd1e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -942,6 +942,7 @@ F:  drivers/dma/dma-axi-dmac.c
 ANALOG DEVICES INC IIO DRIVERS
 M: Lars-Peter Clausen 
 M: Michael Hennerich 
+M: Stefan Popa 
 W: http://wiki.analog.com/
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
-- 
2.7.4



[PATCH 4/6] iio: imu: adis16480: Treat temperature scale in a generic way

2019-02-19 Thread Stefan Popa
All supported devices provide internal temperature measurement from -40 C
to +85 C, with +25 C representing value 0x00.

This patch treats the temperature scale in a generic way, similar to the
accelerometer and gyroscope scales. So far, there are no temperature max
scale differences between the supported devices. However, devices that
will make use of this feature will be added in the future.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 7ae71f4..cc53825 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -124,6 +124,7 @@ struct adis16480_chip_info {
unsigned int gyro_max_scale;
unsigned int accel_max_val;
unsigned int accel_max_scale;
+   unsigned int temp_max_scale;
 };
 
 enum adis16480_int_pin {
@@ -530,6 +531,7 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan, int *val, int *val2, long info)
 {
struct adis16480 *st = iio_priv(indio_dev);
+   unsigned int temp, scale;
 
switch (info) {
case IIO_CHAN_INFO_RAW:
@@ -549,8 +551,15 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
*val2 = 100; /* 0.0001 gauss */
return IIO_VAL_INT_PLUS_MICRO;
case IIO_TEMP:
-   *val = 5;
-   *val2 = 65; /* 5.65 milli degree Celsius */
+   /*
+* +85 degrees Celsius = temp_max_scale
+* +25 degrees Celsius = 0
+* LSB, 25 degrees Celsius  = 60 / temp_max_scale
+*/
+   scale = DIV_ROUND_CLOSEST_ULL(60 * 100LL,
+   st->chip_info->temp_max_scale);
+   *val = scale / 1000;
+   *val2 = (scale % 1000) * 1000;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_PRESSURE:
*val = 0;
@@ -561,7 +570,10 @@ static int adis16480_read_raw(struct iio_dev *indio_dev,
}
case IIO_CHAN_INFO_OFFSET:
/* Only the temperature channel has a offset */
-   *val = 4425; /* 25 degree Celsius = 0x */
+   temp = 25 * 100LL; /* 25 degree Celsius = 0x */
+   scale = DIV_ROUND_CLOSEST_ULL(60 * 100LL,
+   st->chip_info->temp_max_scale);
+   *val = DIV_ROUND_CLOSEST_ULL(temp, scale);
return IIO_VAL_INT;
case IIO_CHAN_INFO_CALIBBIAS:
return adis16480_get_calibbias(indio_dev, chan, val);
@@ -717,6 +729,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 300,
.accel_max_val = IIO_M_S_2_TO_G(21973),
.accel_max_scale = 18,
+   .temp_max_scale = 10619,
},
[ADIS16480] = {
.channels = adis16480_channels,
@@ -725,6 +738,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(12500),
.accel_max_scale = 10,
+   .temp_max_scale = 10619,
},
[ADIS16485] = {
.channels = adis16485_channels,
@@ -733,6 +747,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(2),
.accel_max_scale = 5,
+   .temp_max_scale = 10619,
},
[ADIS16488] = {
.channels = adis16480_channels,
@@ -741,6 +756,7 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.gyro_max_scale = 450,
.accel_max_val = IIO_M_S_2_TO_G(22500),
.accel_max_scale = 18,
+   .temp_max_scale = 10619,
},
 };
 
-- 
2.7.4



[PATCH 5/6] iio: imu: adis16480: Add support for ADIS1649x family of devices

2019-02-19 Thread Stefan Popa
The ADIS16495 and ADIS16497 are inertial systems that include a triaxis
gyroscope and a triaxis accelerometer. The serial peripheral interface
(SPI) provide a simple interface for data collection and configuration
control. The devices are similar to ADIS16475, ADIS16480, ADIS16485 and
ADIS16488, the main differences are related to range and scale factors.

The temperature data scale is 0.00565 C/LSB for ADIS16475 and ADIS1648x
devices, while for ADIS1649x 0.0125 C/LSB.

Another difference is that ADIS1649x devices support different gyroscope
measurement ranges which are dependent on the dash number (-1, -2, -3),
see Table 24 in the ADIS16495 datasheet. However, the ADIS16497
gyroscopes have the same scale as ADIS16495.

Furthermore, ADIS16495 devices support the acceleration maximum range of
8g, while ADIS16497 devices go up to 40g.

Datasheets:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adis16495.pdf
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/adis16497.pdf

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 72 +
 1 file changed, 72 insertions(+)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index cc53825..c30acfdb 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -714,6 +714,12 @@ enum adis16480_variant {
ADIS16480,
ADIS16485,
ADIS16488,
+   ADIS16495_1,
+   ADIS16495_2,
+   ADIS16495_3,
+   ADIS16497_1,
+   ADIS16497_2,
+   ADIS16497_3,
 };
 
 static const struct adis16480_chip_info adis16480_chip_info[] = {
@@ -758,6 +764,60 @@ static const struct adis16480_chip_info 
adis16480_chip_info[] = {
.accel_max_scale = 18,
.temp_max_scale = 10619,
},
+   [ADIS16495_1] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 125,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 8,
+   .temp_max_scale = 4800,
+   },
+   [ADIS16495_2] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(18000),
+   .gyro_max_scale = 450,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 8,
+   .temp_max_scale = 4800,
+   },
+   [ADIS16495_3] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 2000,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 8,
+   .temp_max_scale = 4800,
+   },
+   [ADIS16497_1] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 125,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 40,
+   .temp_max_scale = 4800,
+   },
+   [ADIS16497_2] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(18000),
+   .gyro_max_scale = 450,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 40,
+   .temp_max_scale = 4800,
+   },
+   [ADIS16497_3] = {
+   .channels = adis16485_channels,
+   .num_channels = ARRAY_SIZE(adis16485_channels),
+   .gyro_max_val = IIO_RAD_TO_DEGREE(2),
+   .gyro_max_scale = 2000,
+   .accel_max_val = IIO_M_S_2_TO_G(32000),
+   .accel_max_scale = 40,
+   .temp_max_scale = 4800,
+   },
 };
 
 static const struct iio_info adis16480_info = {
@@ -1000,6 +1060,12 @@ static const struct spi_device_id adis16480_ids[] = {
{ "adis16480", ADIS16480 },
{ "adis16485", ADIS16485 },
{ "adis16488", ADIS16488 },
+   { "adis16495-1", ADIS16495_1 },
+   { "adis16495-2", ADIS16495_2 },
+   { "adis16495-3", ADIS16495_3 },
+   { "adis16497-1", ADIS16497_1 },
+   { "adis16497-2", ADIS16497_2 },
+   { "adis16497-3", ADIS16497_3 },
{ }
 };
 MODULE_DEVICE_TABLE(spi, adis16480_ids);
@@ -1009,6 +1075,12 @@ static const struct of_device_id adis16480_of_match[] = {
{ .compatible = "adi,adis16480" },
{ .compatible = "adi,adis16485" },
{ .compatible = "adi,adis16488" },
+   { 

[PATCH 3/6] iio: imu: adis16480: Add OF device ID table

2019-02-19 Thread Stefan Popa
The driver does not have a struct of_device_id table, but supported
devices are registered via Device Trees. This patch adds OF device ID
table.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index 38ba0c1..7ae71f4 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -988,9 +988,19 @@ static const struct spi_device_id adis16480_ids[] = {
 };
 MODULE_DEVICE_TABLE(spi, adis16480_ids);
 
+static const struct of_device_id adis16480_of_match[] = {
+   { .compatible = "adi,adis16375" },
+   { .compatible = "adi,adis16480" },
+   { .compatible = "adi,adis16485" },
+   { .compatible = "adi,adis16488" },
+   { },
+};
+MODULE_DEVICE_TABLE(of, adis16480_of_match);
+
 static struct spi_driver adis16480_driver = {
.driver = {
.name = "adis16480",
+   .of_match_table = adis16480_of_match,
},
.id_table = adis16480_ids,
.probe = adis16480_probe,
-- 
2.7.4



[PATCH 2/6] iio: imu: adis16480: Add support for configurable drdy indicator

2019-02-19 Thread Stefan Popa
The FNCTIO_CTRL register provides configuration control for each I/O pin
(DIO1, DIO2, DIO3 and DIO4).

This patch adds the option to configure each DIOx pin as data ready
indicator with positive or negative polarity by reading the 'interrupts'
and 'interrupt-names' properties from the devicetree. The
'interrupt-names' property is optional, if it is not specified, then the
factory default DIO2 data ready signal is used.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 76 +
 1 file changed, 76 insertions(+)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index d222188..38ba0c1 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -109,6 +110,10 @@
 #define ADIS16480_FIR_COEF_D(x)
ADIS16480_FIR_COEF(0x0B, (x))
 
 /* ADIS16480_REG_FNCTIO_CTRL */
+#define ADIS16480_DRDY_SEL_MSK GENMASK(1, 0)
+#define ADIS16480_DRDY_SEL(x)  FIELD_PREP(ADIS16480_DRDY_SEL_MSK, x)
+#define ADIS16480_DRDY_POL_MSK BIT(2)
+#define ADIS16480_DRDY_POL(x)  FIELD_PREP(ADIS16480_DRDY_POL_MSK, x)
 #define ADIS16480_DRDY_EN_MSK  BIT(3)
 #define ADIS16480_DRDY_EN(x)   FIELD_PREP(ADIS16480_DRDY_EN_MSK, x)
 
@@ -121,12 +126,26 @@ struct adis16480_chip_info {
unsigned int accel_max_scale;
 };
 
+enum adis16480_int_pin {
+   ADIS16480_PIN_DIO1,
+   ADIS16480_PIN_DIO2,
+   ADIS16480_PIN_DIO3,
+   ADIS16480_PIN_DIO4
+};
+
 struct adis16480 {
const struct adis16480_chip_info *chip_info;
 
struct adis adis;
 };
 
+static const char * const adis16480_int_pin_names[4] = {
+   [ADIS16480_PIN_DIO1] = "DIO1",
+   [ADIS16480_PIN_DIO2] = "DIO2",
+   [ADIS16480_PIN_DIO3] = "DIO3",
+   [ADIS16480_PIN_DIO4] = "DIO4",
+};
+
 #ifdef CONFIG_DEBUG_FS
 
 static ssize_t adis16480_show_firmware_revision(struct file *file,
@@ -840,6 +859,59 @@ static const struct adis_data adis16480_data = {
.enable_irq = adis16480_enable_irq,
 };
 
+static int adis16480_config_irq_pin(struct device_node *of_node,
+   struct adis16480 *st)
+{
+   struct irq_data *desc;
+   enum adis16480_int_pin pin;
+   unsigned int irq_type;
+   uint16_t val;
+   int i, irq = 0;
+
+   desc = irq_get_irq_data(st->adis.spi->irq);
+   if (!desc) {
+   dev_err(>adis.spi->dev, "Could not find IRQ %d\n", irq);
+   return -EINVAL;
+   }
+
+   /* Disable data ready */
+   val = ADIS16480_DRDY_EN(0);
+
+   /*
+* Get the interrupt from the devicetre by reading the
+* interrupt-names property. If it is not specified, use
+* the default interrupt on DIO2 pin.
+*/
+   pin = ADIS16480_PIN_DIO2;
+   for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) {
+   irq = of_irq_get_byname(of_node, adis16480_int_pin_names[i]);
+   if (irq > 0) {
+   pin = i;
+   break;
+   }
+   }
+
+   val |= ADIS16480_DRDY_SEL(pin);
+
+   /*
+* Get the interrupt line behaviour. The data ready polarity can be
+* configured as positive or negative, corresponding to
+* IRQF_TRIGGER_RISING or IRQF_TRIGGER_FALLING respectively.
+*/
+   irq_type = irqd_get_trigger_type(desc);
+   if (irq_type == IRQF_TRIGGER_RISING) { /* Default */
+   val |= ADIS16480_DRDY_POL(1);
+   } else if (irq_type == IRQF_TRIGGER_FALLING) {
+   val |= ADIS16480_DRDY_POL(0);
+   } else {
+   dev_err(>adis.spi->dev,
+   "Invalid interrupt type 0x%x specified\n", irq_type);
+   return -EINVAL;
+   }
+   /* Write the data ready configuration to the FNCTIO_CTRL register */
+   return adis_write_reg_16(>adis, ADIS16480_REG_FNCTIO_CTRL, val);
+}
+
 static int adis16480_probe(struct spi_device *spi)
 {
const struct spi_device_id *id = spi_get_device_id(spi);
@@ -867,6 +939,10 @@ static int adis16480_probe(struct spi_device *spi)
if (ret)
return ret;
 
+   ret =  adis16480_config_irq_pin(spi->dev.of_node, st);
+   if (ret)
+   return ret;
+
ret = adis_setup_buffer_and_trigger(>adis, indio_dev, NULL);
if (ret)
return ret;
-- 
2.7.4



[PATCH 1/6] iio: imu: adis16480: Use the default data ready pin configuration

2019-02-19 Thread Stefan Popa
The FNCTIO_CTRL register, Bits[3:0] provide three configuration options
for the data ready function: on/off, polarity, and DIOx line. The
factory default assigns DIO2 as a positive polarity, data ready signal.

The adis16480_enable_irq() function, overwrites this configuration when
it enables/disables the data ready pin by only setting BIT[3].
As a result, the data ready signal becomes DIO1 pin which is assigned as
negative polarity.

This patch reads the FNCTIO_CTRL register and creates a mask, such that
only data ready enable (BIT[3]) will be modified when
adis16480_enable_irq function is called.

Signed-off-by: Stefan Popa 
---
 drivers/iio/imu/adis16480.c | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index a27fe20..d222188 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -9,6 +9,7 @@
  *
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -107,6 +108,10 @@
 #define ADIS16480_FIR_COEF_C(x)
ADIS16480_FIR_COEF(0x09, (x))
 #define ADIS16480_FIR_COEF_D(x)
ADIS16480_FIR_COEF(0x0B, (x))
 
+/* ADIS16480_REG_FNCTIO_CTRL */
+#define ADIS16480_DRDY_EN_MSK  BIT(3)
+#define ADIS16480_DRDY_EN(x)   FIELD_PREP(ADIS16480_DRDY_EN_MSK, x)
+
 struct adis16480_chip_info {
unsigned int num_channels;
const struct iio_chan_spec *channels;
@@ -741,8 +746,17 @@ static int adis16480_stop_device(struct iio_dev *indio_dev)
 
 static int adis16480_enable_irq(struct adis *adis, bool enable)
 {
-   return adis_write_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL,
-   enable ? BIT(3) : 0);
+   uint16_t val;
+   int ret;
+
+   ret = adis_read_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL, );
+   if (ret < 0)
+   return ret;
+
+   val &= ~ADIS16480_DRDY_EN_MSK;
+   val |= ADIS16480_DRDY_EN(enable);
+
+   return adis_write_reg_16(adis, ADIS16480_REG_FNCTIO_CTRL, val);
 }
 
 static int adis16480_initial_setup(struct iio_dev *indio_dev)
-- 
2.7.4



[PATCH 0/6] iio: imu: adis16480: Add support for ADIS1649x family of devices

2019-02-19 Thread Stefan Popa
This series has as main goal to add support for ADIS1649x family of devices as
part of the already existing adis16480, but on the way it also deals with some
outstanding items:

* Make drdy pin configurable
* Add OF device ID table
* Deal with the temperature max scale in a generic way
* Add missing docs

Stefan Popa (6):
  iio: imu: adis16480: Use the default data ready pin configuration
  iio: imu: adis16480: Add support for configurable drdy indicator
  iio: imu: adis16480: Add OF device ID table
  iio: imu: adis16480: Treat temperature scale in a generic way
  iio: imu: adis16480: Add support for ADIS1649x family of devices
  iio: imu: adis16480: Add docs for ADIS16480 IMU

 .../devicetree/bindings/iio/imu/adi,adis16480.txt  |  49 +
 MAINTAINERS|   1 +
 drivers/iio/imu/adis16480.c| 198 -
 3 files changed, 243 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt

-- 
2.7.4



[PATCH] drivers: spi: core: Add optional stall delay between cs_change transfers

2019-02-19 Thread Stefan Popa
From: Michael Hennerich 

Some devices like the ADIS16460 IMU require a stall period between
transfers. The default value of 10us are not enough. Introduce a per
transfer configurable delay.

Signed-off-by: Michael Hennerich 
Signed-off-by: Stefan Popa 
---
 drivers/spi/spi.c   | 3 ++-
 include/linux/spi/spi.h | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 9a7def7..717b92a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1144,7 +1144,8 @@ static int spi_transfer_one_message(struct spi_controller 
*ctlr,
keep_cs = true;
} else {
spi_set_cs(msg->spi, false);
-   udelay(10);
+   udelay(xfer->cs_change_stall_delay_us ?
+  xfer->cs_change_stall_delay_us : 10);
spi_set_cs(msg->spi, true);
}
}
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 314d922..273774c 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -702,6 +702,8 @@ extern void spi_res_release(struct spi_controller *ctlr,
  *  transfer. If 0 the default (from @spi_device) is used.
  * @bits_per_word: select a bits_per_word other than the device default
  *  for this transfer. If 0 the default (from @spi_device) is used.
+ * @cs_change_stall_delay_us: microseconds to delay between cs_change
+ * transfers.
  * @cs_change: affects chipselect after this transfer completes
  * @delay_usecs: microseconds to delay after this transfer before
  * (optionally) changing the chipselect status, then starting
@@ -788,6 +790,7 @@ struct spi_transfer {
 #defineSPI_NBITS_DUAL  0x02 /* 2bits transfer */
 #defineSPI_NBITS_QUAD  0x04 /* 4bits transfer */
u8  bits_per_word;
+   u8  cs_change_stall_delay_us;
u16 delay_usecs;
u32 speed_hz;
u16 word_delay;
-- 
2.7.4



[PATCH] iio: adc: ad7768-1: Add support for setting the sampling frequency

2019-02-04 Thread Stefan Popa
The AD7768-1 core ADC receives a master clock signal (MCLK). The MCLK
frequency combined with the MCLK division and the digital filter
decimation rates, determines the sampling frequency. Along with
MCLK_DIV, the power mode is also configured according to datasheet
recommendations.

>From user space, available sampling frequencies can be read. However,
it is not required for an exact value to be entered, since the driver
will look for the closest available match.

When the device configuration changes (for example, if the filter
decimation rate changes), a SYNC_IN pulse is required.

Signed-off-by: Stefan Popa 
---
 drivers/iio/adc/ad7768-1.c | 202 -
 1 file changed, 199 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
index 78449e9..0d13270 100644
--- a/drivers/iio/adc/ad7768-1.c
+++ b/drivers/iio/adc/ad7768-1.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -59,6 +60,18 @@
 #define AD7768_REG_DIG_DIAG_STATUS 0x30
 #define AD7768_REG_MCLK_COUNTER0x31
 
+/* AD7768_REG_POWER_CLOCK */
+#define AD7768_PWR_MCLK_DIV_MSKGENMASK(5, 4)
+#define AD7768_PWR_MCLK_DIV(x) FIELD_PREP(AD7768_PWR_MCLK_DIV_MSK, x)
+#define AD7768_PWR_PWRMODE_MSK GENMASK(1, 0)
+#define AD7768_PWR_PWRMODE(x)  FIELD_PREP(AD7768_PWR_PWRMODE_MSK, x)
+
+/* AD7768_REG_DIGITAL_FILTER */
+#define AD7768_DIG_FIL_FIL_MSK GENMASK(6, 4)
+#define AD7768_DIG_FIL_FIL(x)  FIELD_PREP(AD7768_DIG_FIL_FIL_MSK, x)
+#define AD7768_DIG_FIL_DEC_MSK GENMASK(2, 0)
+#define AD7768_DIG_FIL_DEC_RATE(x) FIELD_PREP(AD7768_DIG_FIL_DEC_MSK, x)
+
 /* AD7768_REG_CONVERSION */
 #define AD7768_CONV_MODE_MSK   GENMASK(2, 0)
 #define AD7768_CONV_MODE(x)FIELD_PREP(AD7768_CONV_MODE_MSK, x)
@@ -80,11 +93,51 @@ enum ad7768_pwrmode {
AD7768_FAST_MODE = 3
 };
 
+enum ad7768_mclk_div {
+   AD7768_MCLK_DIV_16,
+   AD7768_MCLK_DIV_8,
+   AD7768_MCLK_DIV_4,
+   AD7768_MCLK_DIV_2
+};
+
+enum ad7768_dec_rate {
+   AD7768_DEC_RATE_32 = 0,
+   AD7768_DEC_RATE_64 = 1,
+   AD7768_DEC_RATE_128 = 2,
+   AD7768_DEC_RATE_256 = 3,
+   AD7768_DEC_RATE_512 = 4,
+   AD7768_DEC_RATE_1024 = 5,
+   AD7768_DEC_RATE_8 = 9,
+   AD7768_DEC_RATE_16 = 10
+};
+
+struct ad7768_clk_configuration {
+   enum ad7768_mclk_div mclk_div;
+   enum ad7768_dec_rate dec_rate;
+   unsigned int clk_div;
+   enum ad7768_pwrmode pwrmode;
+};
+
+static const struct ad7768_clk_configuration ad7768_clk_config[] = {
+   { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_8, 16,  AD7768_FAST_MODE },
+   { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_16, 32,  AD7768_FAST_MODE },
+   { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_32, 64, AD7768_FAST_MODE },
+   { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_64, 128, AD7768_FAST_MODE },
+   { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_128, 256, AD7768_FAST_MODE },
+   { AD7768_MCLK_DIV_4, AD7768_DEC_RATE_128, 512, AD7768_MED_MODE },
+   { AD7768_MCLK_DIV_4, AD7768_DEC_RATE_256, 1024, AD7768_MED_MODE },
+   { AD7768_MCLK_DIV_4, AD7768_DEC_RATE_512, 2048, AD7768_MED_MODE },
+   { AD7768_MCLK_DIV_4, AD7768_DEC_RATE_1024, 4096, AD7768_MED_MODE },
+   { AD7768_MCLK_DIV_8, AD7768_DEC_RATE_1024, 8192, AD7768_MED_MODE },
+   { AD7768_MCLK_DIV_16, AD7768_DEC_RATE_1024, 16384, AD7768_ECO_MODE },
+};
+
 static const struct iio_chan_spec ad7768_channels[] = {
{
.type = IIO_VOLTAGE,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+   .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
.indexed = 1,
.channel = 0,
.scan_index = 0,
@@ -102,8 +155,12 @@ struct ad7768_state {
struct spi_device *spi;
struct regulator *vref;
struct mutex lock;
+   struct clk *mclk;
+   unsigned int mclk_freq;
+   unsigned int samp_freq;
struct completion completion;
struct iio_trigger *trig;
+   struct gpio_desc *gpio_sync_in;
/*
 * DMA (thus cache coherency maintenance) requires the
 * transfer buffers to live in their own cache lines.
@@ -210,6 +267,90 @@ static int ad7768_reg_access(struct iio_dev *indio_dev,
return ret;
 }
 
+static int ad7768_set_dig_fil(struct ad7768_state *st,
+ enum ad7768_dec_rate dec_rate)
+{
+   unsigned int mode;
+   int ret;
+
+   if (dec_rate == AD7768_DEC_RATE_8 || dec_rate == AD7768_DEC_RATE_16)
+   mode = AD7768_DIG_FIL_FIL(dec_rate);
+   else
+   mode = AD7768_DIG_FIL_DEC_RATE(dec_rate);
+
+   ret = ad7768_spi_reg_write(st, AD7768_REG_DIGITAL_FILTER, mode);
+   if (ret < 0)
+   return ret;
+
+   /* A sync-in pulse is required

[PATCH v2] drivers: iio: dac: Fix wrong license for ADI drivers

2019-02-04 Thread Stefan Popa
Analog Devices drivers are typically GPL v2 only. This patch fixes the
inconsistencies between the module license and SPDX.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Modified only the drivers with inconsistencies.

 drivers/iio/dac/ad5686-spi.c | 2 +-
 drivers/iio/dac/ad5686.c | 2 +-
 drivers/iio/dac/ad5686.h | 2 +-
 drivers/iio/dac/ad5696-i2c.c | 2 +-
 drivers/iio/dac/ad5758.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c
index 4d857c8..0188ded 100644
--- a/drivers/iio/dac/ad5686-spi.c
+++ b/drivers/iio/dac/ad5686-spi.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5672R, AD5674R, AD5676, AD5676R, AD5679R,
  * AD5681R, AD5682R, AD5683, AD5683R, AD5684,
diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 6dd2759..e06b29c 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5686R, AD5685R, AD5684R Digital to analog converters  driver
  *
diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h
index 4c3e171..70a7799 100644
--- a/drivers/iio/dac/ad5686.h
+++ b/drivers/iio/dac/ad5686.h
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * This file is part of AD5686 DAC driver
  *
diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c
index 7350d98..ccf794c 100644
--- a/drivers/iio/dac/ad5696-i2c.c
+++ b/drivers/iio/dac/ad5696-i2c.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5671R, AD5675R, AD5691R, AD5692R, AD5693, AD5693R,
  * AD5694, AD5694R, AD5695R, AD5696, AD5696R
diff --git a/drivers/iio/dac/ad5758.c b/drivers/iio/dac/ad5758.c
index ef41f12..2bdf1b0 100644
--- a/drivers/iio/dac/ad5758.c
+++ b/drivers/iio/dac/ad5758.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5758 Digital to analog converters driver
  *
-- 
2.7.4



[PATCH] drivers: iio: Fix wrong license for ADI drivers

2019-02-01 Thread Stefan Popa
Analog Devices drivers are typically GPL v2 only. This patch fixes the
inconsistencies between the module license and SPDX.

Signed-off-by: Stefan Popa 
---
 drivers/iio/accel/adxl372.c | 4 ++--
 drivers/iio/accel/adxl372.h | 2 +-
 drivers/iio/accel/adxl372_i2c.c | 4 ++--
 drivers/iio/accel/adxl372_spi.c | 4 ++--
 drivers/iio/adc/ad7124.c| 4 ++--
 drivers/iio/dac/ad5686-spi.c| 2 +-
 drivers/iio/dac/ad5686.c| 2 +-
 drivers/iio/dac/ad5686.h| 2 +-
 drivers/iio/dac/ad5696-i2c.c| 2 +-
 drivers/iio/dac/ad5758.c| 2 +-
 10 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index 3b84cb2..c735b4c 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * ADXL372 3-Axis Digital Accelerometer core driver
  *
@@ -972,4 +972,4 @@ EXPORT_SYMBOL_GPL(adxl372_probe);
 
 MODULE_AUTHOR("Stefan Popa ");
 MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer driver");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/adxl372.h b/drivers/iio/accel/adxl372.h
index 80a0aa9..967fddd 100644
--- a/drivers/iio/accel/adxl372.h
+++ b/drivers/iio/accel/adxl372.h
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * ADXL372 3-Axis Digital Accelerometer
  *
diff --git a/drivers/iio/accel/adxl372_i2c.c b/drivers/iio/accel/adxl372_i2c.c
index e1affe4..f242fb1b 100644
--- a/drivers/iio/accel/adxl372_i2c.c
+++ b/drivers/iio/accel/adxl372_i2c.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * ADXL372 3-Axis Digital Accelerometer I2C driver
  *
@@ -58,4 +58,4 @@ module_i2c_driver(adxl372_i2c_driver);
 
 MODULE_AUTHOR("Stefan Popa ");
 MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer I2C driver");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/adxl372_spi.c b/drivers/iio/accel/adxl372_spi.c
index e14e655..d486d0b 100644
--- a/drivers/iio/accel/adxl372_spi.c
+++ b/drivers/iio/accel/adxl372_spi.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * ADXL372 3-Axis Digital Accelerometer SPI driver
  *
@@ -49,4 +49,4 @@ module_spi_driver(adxl372_spi_driver);
 
 MODULE_AUTHOR("Stefan Popa ");
 MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer SPI driver");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 7d5e531..9dcbfbc 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD7124 SPI ADC driver
  *
@@ -681,4 +681,4 @@ module_spi_driver(ad71124_driver);
 
 MODULE_AUTHOR("Stefan Popa ");
 MODULE_DESCRIPTION("Analog Devices AD7124 SPI driver");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c
index 4d857c8..0188ded 100644
--- a/drivers/iio/dac/ad5686-spi.c
+++ b/drivers/iio/dac/ad5686-spi.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5672R, AD5674R, AD5676, AD5676R, AD5679R,
  * AD5681R, AD5682R, AD5683, AD5683R, AD5684,
diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 6dd2759..e06b29c 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5686R, AD5685R, AD5684R Digital to analog converters  driver
  *
diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h
index 4c3e171..70a7799 100644
--- a/drivers/iio/dac/ad5686.h
+++ b/drivers/iio/dac/ad5686.h
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * This file is part of AD5686 DAC driver
  *
diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c
index 7350d98..ccf794c 100644
--- a/drivers/iio/dac/ad5696-i2c.c
+++ b/drivers/iio/dac/ad5696-i2c.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5671R, AD5675R, AD5691R, AD5692R, AD5693, AD5693R,
  * AD5694, AD5694R, AD5695R, AD5696, AD5696R
diff --git a/drivers/iio/dac/ad5758.c b/drivers/iio/dac/ad5758.c
index ef41f12..2bdf1b0 100644
--- a/drivers/iio/dac/ad5758.c
+++ b/drivers/iio/dac/ad5758.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5758 Digital to analog converters driver
  *
-- 
2.7.4



[PATCH v3 1/2] iio: adc: Add AD7768-1 ADC basic support

2019-01-31 Thread Stefan Popa
The ad7768-1 is a single channel, precision 24-bit analog to digital
converter (ADC).

This basic patch configures the device in fast mode, with 32 kSPS and
leaves the default sinc5 filter.

Two data conversion modes are made available. When data is retrieved by
using the read_raw attribute, one shot single conversion mode is set.
The continuous conversion mode is enabled when the triggered buffer
mechanism is used. To assure correct data retrieval, the driver waits
for the interrupt triggered by the low to high transition of the DRDY
pin.

Datasheets:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7768-1.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added values to all the elements of ad7768_pwrmode enum.
- Removed the ad7768_ids enum, as the driver supports only one device.
- Added a new data union which is part of the ad7768_state struct. This 
  union, now includes a d8 field.
- Used spi_write_then_read() in ad7768_spi_reg_read().
- Called spi_read() instead of spi_sync_transfer() in 
ad7768_trigger_handler().
- Used the devm_request_irq() instead of devm_request_threaded_irq(); 
called
  iio_trigger_poll() instead of iio_trigger_poll_chained().
Changes in v3:
- Changed module license from GPL to GPL v2

 MAINTAINERS|   7 +
 drivers/iio/adc/Kconfig|  13 ++
 drivers/iio/adc/Makefile   |   1 +
 drivers/iio/adc/ad7768-1.c | 459 +
 4 files changed, 480 insertions(+)
 create mode 100644 drivers/iio/adc/ad7768-1.c

diff --git a/MAINTAINERS b/MAINTAINERS
index d039f66..3ba3811 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -862,6 +862,13 @@ S: Supported
 F: drivers/iio/adc/ad7606.c
 F: Documentation/devicetree/bindings/iio/adc/ad7606.txt
 
+ANALOG DEVICES INC AD7768-1 DRIVER
+M: Stefan Popa 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7768-1.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index f3cc7a3..6c19dfe 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -108,6 +108,19 @@ config AD7766
  To compile this driver as a module, choose M here: the module will be
  called ad7766.
 
+config AD7768_1
+   tristate "Analog Devices AD7768-1 ADC driver"
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Analog Devices AD7768-1 SPI
+ simultaneously sampling sigma-delta analog to digital converter (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7768-1.
+
 config AD7791
tristate "Analog Devices AD7791 ADC driver"
depends on SPI
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index ea50313..9d50f7b 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -15,6 +15,7 @@ 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_AD7768_1) += ad7768-1.o
 obj-$(CONFIG_AD7791) += ad7791.o
 obj-$(CONFIG_AD7793) += ad7793.o
 obj-$(CONFIG_AD7887) += ad7887.o
diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
new file mode 100644
index 000..78449e9
--- /dev/null
+++ b/drivers/iio/adc/ad7768-1.c
@@ -0,0 +1,459 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices AD7768-1 SPI ADC driver
+ *
+ * Copyright 2017 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* AD7768 registers definition */
+#define AD7768_REG_CHIP_TYPE   0x3
+#define AD7768_REG_PROD_ID_L   0x4
+#define AD7768_REG_PROD_ID_H   0x5
+#define AD7768_REG_CHIP_GRADE  0x6
+#define AD7768_REG_SCRATCH_PAD 0x0A
+#define AD7768_REG_VENDOR_L0x0C
+#define AD7768_REG_VENDOR_H0x0D
+#define AD7768_REG_INTERFACE_FORMAT0x14
+#define AD7768_REG_POWER_CLOCK 0x15
+#define AD7768_REG_ANALOG  0x16
+#define AD7768_REG_ANALOG2 0x17
+#define AD7768_REG_CONVERSION  0x18
+#define AD7768_REG_DIGITAL_FILTER  0x19
+#define AD7768_REG_SINC3_DEC_RATE_MSB  0x1A
+#define AD7768_REG_SINC3_DEC_RATE_LSB  0x1B
+#define AD7768_REG_DUTY_CYCLE_RATIO0x1C
+#define AD7768_REG_SYNC_RESET  0x1D
+#define AD7768_REG_GPIO_CONTROL0x1E
+#define AD7768_REG_GPIO_WRITE  0x1F
+#define AD7768_REG_GPIO_READ   0x20
+#define AD7768_REG_OFFSET_HI   0x21
+#define AD7768_REG_OFFS

[PATCH v3 2/2] dt-bindings: iio: adc: Add docs for AD7768-1

2019-01-31 Thread Stefan Popa
Document support for AD7768-1 Analog to Digital Converter.

Signed-off-by: Stefan Popa 
Reviewed-by: Rob Herring 
---
Changes in v2:
- Added information regarding the simultaneous sampling of the SYNC-IN 
pin
- Added the reset-gpios in the binding.
Changes in v3:
- Nothing changed

 .../devicetree/bindings/iio/adc/adi,ad7768-1.txt   | 41 ++
 MAINTAINERS|  1 +
 2 files changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt 
b/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
new file mode 100644
index 000..9f5b88c
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
@@ -0,0 +1,41 @@
+Analog Devices AD7768-1 ADC device driver
+
+Required properties for the AD7768-1:
+
+- compatible: Must be "adi,ad7768-1"
+- reg: SPI chip select number for the device
+- spi-max-frequency: Max SPI frequency to use
+   see: Documentation/devicetree/bindings/spi/spi-bus.txt
+- clocks: phandle to the master clock (mclk)
+   see: Documentation/devicetree/bindings/clock/clock-bindings.txt
+- clock-names: Must be "mclk".
+- interrupts: IRQ line for the ADC
+   see: 
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+- vref-supply: vref supply can be used as reference for conversion
+- adi,sync-in-gpios: must be the device tree identifier of the SYNC-IN pin. 
Enables
+   synchronization of multiple devices that require simultaneous sampling.
+   A pulse is always required if the configuration is changed in any way, 
for example
+   if the filter decimation rate changes. As the line is active low, it 
should
+   be marked GPIO_ACTIVE_LOW.
+
+Optional properties:
+
+ - reset-gpios : GPIO spec for the RESET pin. If specified, it will be 
asserted during
+   driver probe. As the line is active low, it should be marked 
GPIO_ACTIVE_LOW.
+
+Example:
+
+   adc@0 {
+   compatible = "adi,ad7768-1";
+   reg = <0>;
+   spi-max-frequency = <200>;
+   spi-cpol;
+   spi-cpha;
+   vref-supply = <_vref>;
+   interrupts = <25 IRQ_TYPE_EDGE_RISING>;
+   interrupt-parent = <>;
+   adi,sync-in-gpios = < 22 GPIO_ACTIVE_LOW>;
+   reset-gpios = < 27 GPIO_ACTIVE_LOW>;
+   clocks = <_mclk>;
+   clock-names = "mclk";
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 3ba3811..e5613b6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -868,6 +868,7 @@ L:  linux-...@vger.kernel.org
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
 F: drivers/iio/adc/ad7768-1.c
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
 
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
-- 
2.7.4



[PATCH v2 2/2] dt-bindings: iio: adc: Add docs for AD7768-1

2019-01-15 Thread Stefan Popa
Document support for AD7768-1 Analog to Digital Converter.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added information regarding the simultaneous sampling of the SYNC-IN 
pin
- Added the reset-gpios in the binding.

 .../devicetree/bindings/iio/adc/adi,ad7768-1.txt   | 41 ++
 MAINTAINERS|  1 +
 2 files changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt 
b/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
new file mode 100644
index 000..9f5b88c
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
@@ -0,0 +1,41 @@
+Analog Devices AD7768-1 ADC device driver
+
+Required properties for the AD7768-1:
+
+- compatible: Must be "adi,ad7768-1"
+- reg: SPI chip select number for the device
+- spi-max-frequency: Max SPI frequency to use
+   see: Documentation/devicetree/bindings/spi/spi-bus.txt
+- clocks: phandle to the master clock (mclk)
+   see: Documentation/devicetree/bindings/clock/clock-bindings.txt
+- clock-names: Must be "mclk".
+- interrupts: IRQ line for the ADC
+   see: 
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+- vref-supply: vref supply can be used as reference for conversion
+- adi,sync-in-gpios: must be the device tree identifier of the SYNC-IN pin. 
Enables
+   synchronization of multiple devices that require simultaneous sampling.
+   A pulse is always required if the configuration is changed in any way, 
for example
+   if the filter decimation rate changes. As the line is active low, it 
should
+   be marked GPIO_ACTIVE_LOW.
+
+Optional properties:
+
+ - reset-gpios : GPIO spec for the RESET pin. If specified, it will be 
asserted during
+   driver probe. As the line is active low, it should be marked 
GPIO_ACTIVE_LOW.
+
+Example:
+
+   adc@0 {
+   compatible = "adi,ad7768-1";
+   reg = <0>;
+   spi-max-frequency = <200>;
+   spi-cpol;
+   spi-cpha;
+   vref-supply = <_vref>;
+   interrupts = <25 IRQ_TYPE_EDGE_RISING>;
+   interrupt-parent = <>;
+   adi,sync-in-gpios = < 22 GPIO_ACTIVE_LOW>;
+   reset-gpios = < 27 GPIO_ACTIVE_LOW>;
+   clocks = <_mclk>;
+   clock-names = "mclk";
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 3ba3811..e5613b6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -868,6 +868,7 @@ L:  linux-...@vger.kernel.org
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
 F: drivers/iio/adc/ad7768-1.c
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
 
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
-- 
2.7.4



[PATCH v2 1/2] iio: adc: Add AD7768-1 ADC basic support

2019-01-15 Thread Stefan Popa
The ad7768-1 is a single channel, precision 24-bit analog to digital
converter (ADC).

This basic patch configures the device in fast mode, with 32 kSPS and
leaves the default sinc5 filter.

Two data conversion modes are made available. When data is retrieved by
using the read_raw attribute, one shot single conversion mode is set.
The continuous conversion mode is enabled when the triggered buffer
mechanism is used. To assure correct data retrieval, the driver waits
for the interrupt triggered by the low to high transition of the DRDY
pin.

Datasheets:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7768-1.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added values to all the elements of ad7768_pwrmode enum.
- Removed the ad7768_ids enum, as the driver supports only one device.
- Added a new data union which is part of the ad7768_state struct. This 
  union, now includes a d8 field.
- Used spi_write_then_read() in ad7768_spi_reg_read().
- Called spi_read() instead of spi_sync_transfer() in 
ad7768_trigger_handler().
- Used the devm_request_irq() instead of devm_request_threaded_irq(); 
called
  iio_trigger_poll() instead of iio_trigger_poll_chained().

 MAINTAINERS|   7 +
 drivers/iio/adc/Kconfig|  13 ++
 drivers/iio/adc/Makefile   |   1 +
 drivers/iio/adc/ad7768-1.c | 459 +
 4 files changed, 480 insertions(+)
 create mode 100644 drivers/iio/adc/ad7768-1.c

diff --git a/MAINTAINERS b/MAINTAINERS
index d039f66..3ba3811 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -862,6 +862,13 @@ S: Supported
 F: drivers/iio/adc/ad7606.c
 F: Documentation/devicetree/bindings/iio/adc/ad7606.txt
 
+ANALOG DEVICES INC AD7768-1 DRIVER
+M: Stefan Popa 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7768-1.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index f3cc7a3..6c19dfe 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -108,6 +108,19 @@ config AD7766
  To compile this driver as a module, choose M here: the module will be
  called ad7766.
 
+config AD7768_1
+   tristate "Analog Devices AD7768-1 ADC driver"
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Analog Devices AD7768-1 SPI
+ simultaneously sampling sigma-delta analog to digital converter (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7768-1.
+
 config AD7791
tristate "Analog Devices AD7791 ADC driver"
depends on SPI
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index ea50313..9d50f7b 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -15,6 +15,7 @@ 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_AD7768_1) += ad7768-1.o
 obj-$(CONFIG_AD7791) += ad7791.o
 obj-$(CONFIG_AD7793) += ad7793.o
 obj-$(CONFIG_AD7887) += ad7887.o
diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
new file mode 100644
index 000..fdcb966
--- /dev/null
+++ b/drivers/iio/adc/ad7768-1.c
@@ -0,0 +1,459 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices AD7768-1 SPI ADC driver
+ *
+ * Copyright 2017 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* AD7768 registers definition */
+#define AD7768_REG_CHIP_TYPE   0x3
+#define AD7768_REG_PROD_ID_L   0x4
+#define AD7768_REG_PROD_ID_H   0x5
+#define AD7768_REG_CHIP_GRADE  0x6
+#define AD7768_REG_SCRATCH_PAD 0x0A
+#define AD7768_REG_VENDOR_L0x0C
+#define AD7768_REG_VENDOR_H0x0D
+#define AD7768_REG_INTERFACE_FORMAT0x14
+#define AD7768_REG_POWER_CLOCK 0x15
+#define AD7768_REG_ANALOG  0x16
+#define AD7768_REG_ANALOG2 0x17
+#define AD7768_REG_CONVERSION  0x18
+#define AD7768_REG_DIGITAL_FILTER  0x19
+#define AD7768_REG_SINC3_DEC_RATE_MSB  0x1A
+#define AD7768_REG_SINC3_DEC_RATE_LSB  0x1B
+#define AD7768_REG_DUTY_CYCLE_RATIO0x1C
+#define AD7768_REG_SYNC_RESET  0x1D
+#define AD7768_REG_GPIO_CONTROL0x1E
+#define AD7768_REG_GPIO_WRITE  0x1F
+#define AD7768_REG_GPIO_READ   0x20
+#define AD7768_REG_OFFSET_HI   0x21
+#define AD7768_REG_OFFSET_MID  0x22
+#define AD7768_REG_OFFSET_LO   0x23
+#defin

[PATCH 2/2] dt-bindings: iio: adc: Add docs for AD7768-1

2019-01-07 Thread Stefan Popa
Document support for AD7768-1 Analog to Digital Converter.

Signed-off-by: Stefan Popa 
---
 .../devicetree/bindings/iio/adc/adi,ad7768-1.txt   | 34 ++
 MAINTAINERS|  1 +
 2 files changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt 
b/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
new file mode 100644
index 000..bf619fa8
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
@@ -0,0 +1,34 @@
+Analog Devices AD7768-1 ADC device driver
+
+Required properties for the AD7768-1:
+
+- compatible: Must be "adi,ad7768-1"
+- reg: SPI chip select number for the device
+- spi-max-frequency: Max SPI frequency to use
+   see: Documentation/devicetree/bindings/spi/spi-bus.txt
+- clocks: phandle to the master clock (mclk)
+   see: Documentation/devicetree/bindings/clock/clock-bindings.txt
+- clock-names: Must be "mclk".
+- interrupts: IRQ line for the ADC
+   see: 
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+- vref-supply: vref supply can be used as reference for conversion
+- adi,sync-in-gpios: must be the device tree identifier of the SYNC-IN pin. A 
pulse
+   is always required if the configuration is changed in any way, for 
example
+   if the filter decimation rate changes. As the line is active low, it 
should
+   be marked GPIO_ACTIVE_LOW.
+
+Example:
+
+   adc@0 {
+   compatible = "adi,ad7768-1";
+   reg = <0>;
+   spi-max-frequency = <200>;
+   spi-cpol;
+   spi-cpha;
+   vref-supply = <_vref>;
+   interrupts = <25 IRQ_TYPE_EDGE_RISING>;
+   interrupt-parent = <>;
+   adi,sync-in-gpios = < 22 GPIO_ACTIVE_LOW>;
+   clocks = <_mclk>;
+   clock-names = "mclk";
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 3ba3811..e5613b6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -868,6 +868,7 @@ L:  linux-...@vger.kernel.org
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
 F: drivers/iio/adc/ad7768-1.c
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.txt
 
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
-- 
2.7.4



[PATCH 1/2] iio: adc: Add AD7768-1 ADC basic support

2019-01-07 Thread Stefan Popa
The ad7768-1 is a single channel, precision 24-bit analog to digital
converter (ADC).

This basic patch configures the device in fast mode, with 32 kSPS and
leaves the default sinc5 filter.

Two data conversion modes are made available. When data is retrieved by
using the read_raw attribute, one shot single conversion mode is set.
The continuous conversion mode is enabled when the triggered buffer
mechanism is used. To assure correct data retrieval, the driver waits
for the interrupt triggered by the low to high transition of the DRDY
pin.

Datasheets:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7768-1.pdf

Signed-off-by: Stefan Popa 
---
 MAINTAINERS|   7 +
 drivers/iio/adc/Kconfig|  13 ++
 drivers/iio/adc/Makefile   |   1 +
 drivers/iio/adc/ad7768-1.c | 474 +
 4 files changed, 495 insertions(+)
 create mode 100644 drivers/iio/adc/ad7768-1.c

diff --git a/MAINTAINERS b/MAINTAINERS
index d039f66..3ba3811 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -862,6 +862,13 @@ S: Supported
 F: drivers/iio/adc/ad7606.c
 F: Documentation/devicetree/bindings/iio/adc/ad7606.txt
 
+ANALOG DEVICES INC AD7768-1 DRIVER
+M: Stefan Popa 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7768-1.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index f3cc7a3..6c19dfe 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -108,6 +108,19 @@ config AD7766
  To compile this driver as a module, choose M here: the module will be
  called ad7766.
 
+config AD7768_1
+   tristate "Analog Devices AD7768-1 ADC driver"
+   depends on SPI
+   select IIO_BUFFER
+   select IIO_TRIGGER
+   select IIO_TRIGGERED_BUFFER
+   help
+ Say yes here to build support for Analog Devices AD7768-1 SPI
+ simultaneously sampling sigma-delta analog to digital converter (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7768-1.
+
 config AD7791
tristate "Analog Devices AD7791 ADC driver"
depends on SPI
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index ea50313..9d50f7b 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -15,6 +15,7 @@ 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_AD7768_1) += ad7768-1.o
 obj-$(CONFIG_AD7791) += ad7791.o
 obj-$(CONFIG_AD7793) += ad7793.o
 obj-$(CONFIG_AD7887) += ad7887.o
diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
new file mode 100644
index 000..7ba98d603
--- /dev/null
+++ b/drivers/iio/adc/ad7768-1.c
@@ -0,0 +1,474 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices AD7768-1 SPI ADC driver
+ *
+ * Copyright 2017 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* AD7768 registers definition */
+#define AD7768_REG_CHIP_TYPE   0x3
+#define AD7768_REG_PROD_ID_L   0x4
+#define AD7768_REG_PROD_ID_H   0x5
+#define AD7768_REG_CHIP_GRADE  0x6
+#define AD7768_REG_SCRATCH_PAD 0x0A
+#define AD7768_REG_VENDOR_L0x0C
+#define AD7768_REG_VENDOR_H0x0D
+#define AD7768_REG_INTERFACE_FORMAT0x14
+#define AD7768_REG_POWER_CLOCK 0x15
+#define AD7768_REG_ANALOG  0x16
+#define AD7768_REG_ANALOG2 0x17
+#define AD7768_REG_CONVERSION  0x18
+#define AD7768_REG_DIGITAL_FILTER  0x19
+#define AD7768_REG_SINC3_DEC_RATE_MSB  0x1A
+#define AD7768_REG_SINC3_DEC_RATE_LSB  0x1B
+#define AD7768_REG_DUTY_CYCLE_RATIO0x1C
+#define AD7768_REG_SYNC_RESET  0x1D
+#define AD7768_REG_GPIO_CONTROL0x1E
+#define AD7768_REG_GPIO_WRITE  0x1F
+#define AD7768_REG_GPIO_READ   0x20
+#define AD7768_REG_OFFSET_HI   0x21
+#define AD7768_REG_OFFSET_MID  0x22
+#define AD7768_REG_OFFSET_LO   0x23
+#define AD7768_REG_GAIN_HI 0x24
+#define AD7768_REG_GAIN_MID0x25
+#define AD7768_REG_GAIN_LO 0x26
+#define AD7768_REG_SPI_DIAG_ENABLE 0x28
+#define AD7768_REG_ADC_DIAG_ENABLE 0x29
+#define AD7768_REG_DIG_DIAG_ENABLE 0x2A
+#define AD7768_REG_ADC_DATA0x2C
+#define AD7768_REG_MASTER_STATUS   0x2D
+#define AD7768_REG_SPI_DIAG_STATUS 0x2E
+#define AD7768_REG_ADC_DIAG_STATUS 0x2F
+#define AD7768_REG_DIG_DIAG_STATUS 0x30
+#define AD7768_REG_MCLK_COUNTER0x31
+
+/* AD7768_REG_CONVERSION */
+#define 

[PATCH v2 5/6] staging: iio: adc: ad7606: Move out of staging

2018-12-17 Thread Stefan Popa
Move ad7606 ADC driver out of staging and into the mainline.

Signed-off-by: Stefan Popa 
---
 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  27 ++
 drivers/iio/adc/Makefile |   3 +
 drivers/iio/adc/ad7606.c | 583 +++
 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  |  27 --
 drivers/staging/iio/adc/Makefile |   4 -
 drivers/staging/iio/adc/ad7606.c | 583 ---
 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, 906 insertions(+), 900 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 db9fcf2..bc9f816 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -854,6 +854,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 
+L: linux-...@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 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 7a3ca4e..f3cc7a3 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -69,6 +69,33 @@ config AD7476
  To compile this driver as a module, choose M here: the
  module will be called ad7476.
 
+config AD7606
+   tristate
+   select IIO_BUFFER
+   select IIO_TRIGGERED_BUFFER
+
+config AD7606_IFACE_PARALLEL
+   tristate "Analog Devices AD7606 ADC driver with parallel interface 
support"
+   depends on HAS_IOMEM
+   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 000..32854f1
--- /dev/null
+++ b/drivers/iio/adc/ad7606.c
@@ -0,0 +1,583 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AD7606 SPI ADC driver
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ad7606.h"
+
+/*
+ * Scales are computed as 5000/32768 and 1/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 =

[PATCH v2 0/6] staging: iio: ad7606: Move out of staging

2018-12-17 Thread Stefan Popa
Changes in v2:
Patch 1:
- Moved the HAS_IOMEM under AD7606_IFACE_PARALLEL and dropped GPIOLIB.
Patch 2:
- Used SPDX GPL-2.0 license identifier instead of GPL-2.0+.
Patch 3:
- Before disabling the buffer, there is no need to trigger a conversion.
Patches 4, 5, 6:
- Nothing changed.

Stefan Popa (6):
  staging: iio: adc: ad7606: Simplify the Kconfing menu
  staging: iio: adc: ad7606: Use SPDX identifier
  staging: iio: adc: ad7606: Add support for threaded irq
  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|  27 +
 drivers/iio/adc/Makefile   |   3 +
 drivers/iio/adc/ad7606.c   | 583 +
 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   | 534 ---
 drivers/staging/iio/adc/ad7606.h   | 103 
 drivers/staging/iio/adc/ad7606_par.c   | 117 -
 drivers/staging/iio/adc/ad7606_spi.c   |  83 ---
 14 files changed, 972 insertions(+), 875 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



[PATCH v2 6/6] dt-bindings: iio: adc: Add docs for AD7606 ADC

2018-12-17 Thread Stefan Popa
Document support for AD7606 Analog to Digital Converter.

Signed-off-by: Stefan Popa 
Reviewed-by: Rob Herring 
---
 .../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 000..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 = <100>;
+   spi-cpol;
+
+   avcc-supply = <_vref>;
+
+   interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-parent = <>;
+
+   adi,conversion-start-gpios = < 17 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 27 GPIO_ACTIVE_HIGH>;
+   adi,first-data-gpios = < 22 GPIO_ACTIVE_HIGH>;
+   adi,oversampling-ratio-gpios = < 18 GPIO_ACTIVE_HIGH
+23 GPIO_ACTIVE_HIGH
+26 GPIO_ACTIVE_HIGH>;
+   standby-gpios = < 24 GPIO_ACTIVE_LOW>;
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index bc9f816..d039f66 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -860,6 +860,7 @@ L:  linux-...@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 
-- 
2.7.4



[PATCH v2 4/6] staging: iio: adc: ad7606: Misc style fixes (no functional change)

2018-12-17 Thread 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 
---
 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 5f0712c..32854f1 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 
+#include 
 #include 
-#include 
-#include 
-#include 
-#include 
 #include 
 #include 
-#include 
-#include 
+#include 
+#include 
 #include 
+#include 
+#include 
+#include 
+#include 
 #include 
 
 #include 
-#include 
 #include 
-#include 
+#include 
 #include 
 #include 
+#include 
 
 #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 9a832d2..5d12410 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 intnum_channels;
diff --git a/drivers/staging/iio/adc/ad7606_par.c 
b/drivers/staging/iio/adc/ad7606_par.c
index 2d137b1..df607c7 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,
  

[PATCH v2 3/6] staging: iio: adc: ad7606: Add support for threaded irq

2018-12-17 Thread 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 
---
 drivers/staging/iio/adc/ad7606.c | 111 +--
 drivers/staging/iio/adc/ad7606.h |   6 +--
 2 files changed, 84 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 97b4a83..5f0712c 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "ad7606.h"
@@ -86,36 +87,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(>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(>lock);
+
+   return IRQ_HANDLED;
 }
 
 static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
@@ -366,8 +355,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)
 {
@@ -375,7 +367,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(>poll_work);
+   gpiod_set_value(st->gpio_convst, 0);
+   iio_trigger_poll_chained(st->trig);
} else {
complete(>completion);
}
@@ -383,26 +376,69 @@ 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);
+
+   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 = _buffer_postenable,
+   .predisable = _buffer_predisable,
+};
+
 static const struct iio_info ad7606_info_no_os_or_range = {
.read_raw = _read_raw,
+   .validate_trigger = _validate_trigger,
 };
 
 static const struct iio_info ad7606_info_os_and_range = {
.read_raw = _read_raw,
.write_raw = _write_raw,
.attrs = _attribute_group_os_and_range,
+   .validate_tri

[PATCH v2 2/6] staging: iio: adc: ad7606: Use SPDX identifier

2018-12-17 Thread 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 
---
 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 e1d85b7..97b4a83 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 
@@ -531,4 +530,4 @@ EXPORT_SYMBOL_GPL(ad7606_pm_ops);
 
 MODULE_AUTHOR("Michael Hennerich ");
 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 510a93d..3e12fff 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 da26742..2d137b1 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 
@@ -114,4 +113,4 @@ module_platform_driver(ad7606_driver);
 
 MODULE_AUTHOR("Michael Hennerich ");
 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 e533917..f38f0d6 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 
@@ -80,4 +79,4 @@ module_spi_driver(ad7606_driver);
 
 MODULE_AUTHOR("Michael Hennerich ");
 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL v2");
+MODULE_LICENSE("GPL");
-- 
2.7.4



[PATCH v2 1/6] staging: iio: adc: ad7606: Simplify the Kconfing menu

2018-12-17 Thread 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 
---
 drivers/staging/iio/adc/Kconfig | 27 ++-
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index fc23059..302639a 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -4,35 +4,28 @@
 menu "Analog to digital converters"
 
 config AD7606
-   tristate "Analog Devices AD7606 ADC driver"
-   depends on GPIOLIB || COMPILE_TEST
-   depends on HAS_IOMEM
+   tristate
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"
+   depends on HAS_IOMEM
+   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



[PATCH 02/11] staging: iio: adc: ad7606: Use SPDX identifier

2018-12-13 Thread 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 
---
 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 
@@ -560,4 +559,4 @@ EXPORT_SYMBOL_GPL(ad7606_pm_ops);
 
 MODULE_AUTHOR("Michael Hennerich ");
 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 
@@ -110,4 +109,4 @@ module_platform_driver(ad7606_driver);
 
 MODULE_AUTHOR("Michael Hennerich ");
 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 
@@ -76,4 +75,4 @@ module_spi_driver(ad7606_driver);
 
 MODULE_AUTHOR("Michael Hennerich ");
 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL v2");
+MODULE_LICENSE("GPL");
-- 
2.7.4



[PATCH 10/11] staging: iio: adc: ad7606: Move out of staging

2018-12-13 Thread Stefan Popa
Move ad7606 ADC driver out of staging and into the mainline.

Signed-off-by: Stefan Popa 
---
 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 
+L: linux-...@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 
 L: linux-me...@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 000..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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ad7606.h"
+
+/*
+ * Scales are computed as 5000/32768 and 1/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(struc

[PATCH 11/11] dt-bindings: iio: adc: Add docs for AD7606 ADC

2018-12-13 Thread Stefan Popa
Document support for AD7606 Analog to Digital Converter.

Signed-off-by: Stefan Popa 
Reviewed-by: Rob Herring 
---
 .../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 000..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 = <100>;
+   spi-cpol;
+
+   avcc-supply = <_vref>;
+
+   interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-parent = <>;
+
+   adi,conversion-start-gpios = < 17 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 27 GPIO_ACTIVE_HIGH>;
+   adi,first-data-gpios = < 22 GPIO_ACTIVE_HIGH>;
+   adi,oversampling-ratio-gpios = < 18 GPIO_ACTIVE_HIGH
+23 GPIO_ACTIVE_HIGH
+26 GPIO_ACTIVE_HIGH>;
+   standby-gpios = < 24 GPIO_ACTIVE_LOW>;
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 7256ce6..798e9a2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -859,6 +859,7 @@ L:  linux-...@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 
-- 
2.7.4



[PATCH 08/11] staging: iio: adc: ad7606: Add OF device ID table

2018-12-13 Thread 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 
---
 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



[PATCH 09/11] staging: iio: adc: ad7606: Misc style fixes (no functional change)

2018-12-13 Thread 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 
---
 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 
+#include 
 #include 
-#include 
-#include 
-#include 
-#include 
 #include 
 #include 
-#include 
-#include 
+#include 
+#include 
 #include 
+#include 
+#include 
+#include 
+#include 
 #include 
 
 #include 
-#include 
 #include 
-#include 
+#include 
 #include 
 #include 
+#include 
 
 #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 intnum_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,
  

[PATCH 07/11] staging: iio: adc: ad7606: Use vendor prefix for DT properties

2018-12-13 Thread 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 
---
 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



[PATCH 04/11] staging: iio: adc: ad7606: Use devm functions in probe

2018-12-13 Thread 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 
---
 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 = _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(>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 = _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, _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,
+ _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)
_par8_bops);
 }
 
-static int ad7606_par_remove(struct platform_device *pdev)
-{
-   return ad7606_remove(>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, ad

[PATCH 06/11] staging: iio: adc: ad7606: Use find_closest() macro

2018-12-13 Thread 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 
---
 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 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -30,8 +31,12 @@
  * Scales are computed as 5000/32768 and 1/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(>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(>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(>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(>lock);
 
return 0;
-- 
2.7.4



[PATCH 01/11] staging: iio: adc: ad7606: Simplify the Kconfing menu

2018-12-13 Thread 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 
---
 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



[PATCH 05/11] staging: iio: adc: ad7606: Add support for threaded irq

2018-12-13 Thread 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 
---
 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 
 #include 
 #include 
+#include 
 #include 
 
 #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(>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(>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(>poll_work);
+   gpiod_set_value(st->gpio_convst, 0);
+   iio_trigger_poll_chained(st->trig);
} else {
complete(>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(>completion);
+   gpiod_set_value(st->gpio_convst, 1);
+   ret = wait_for_completion_timeout(>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 = _buffer_postenable,
+   .predisable = _buffer_predisable,
+};
+
 static const struct iio_info ad7606_info_no_os_or_range = {
.read_raw = _read_raw,
+   .val

[PATCH 03/11] staging: iio: adc: ad7606: Use wait-for-completion handler

2018-12-13 Thread 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 
---
 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(>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(>poll_work);
} else {
-   st->done = true;
-   wake_up_interruptible(>wq_data_avail);
+   complete(>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(>wq_data_avail);
+   init_completion(>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 {
  * @regregulator 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_convstGPIO 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_osGPIO 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 intrange;
unsigned intoversampling;
-   booldone;
void __iomem*base_address;
 
struct mutexlock; /* 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



[PATCH 00/11] staging: iio: ad7606: Move out of staging

2018-12-13 Thread 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



[PATCH v4 2/2] dt-bindings: iio: adc: Add docs for AD7606 ADC

2018-12-10 Thread Stefan Popa
Document support for AD7606 Analog to Digital Converter.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- fixed indentation issues.
- used gpios instead of gpio.
- added vendor prefix for conversion-start-gpios, first-data-gpios,
and range-gpios.
Changes in v3:
- Added adi,oversampling-ratio-gpios.
Changes in v4:
- Specified if the gpios are active high or low and set the flag
appropriately.

 .../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 000..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 = <100>;
+   spi-cpol;
+
+   avcc-supply = <_vref>;
+
+   interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-parent = <>;
+
+   adi,conversion-start-gpios = < 17 GPIO_ACTIVE_HIGH>;
+   reset-gpios = < 27 GPIO_ACTIVE_HIGH>;
+   adi,first-data-gpios = < 22 GPIO_ACTIVE_HIGH>;
+   adi,oversampling-ratio-gpios = < 18 GPIO_ACTIVE_HIGH
+23 GPIO_ACTIVE_HIGH
+26 GPIO_ACTIVE_HIGH>;
+   standby-gpios = < 24 GPIO_ACTIVE_LOW>;
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 843545d..6d63db4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -845,6 +845,7 @@ L:  linux-...@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 
-- 
2.7.4



[PATCH v4 1/2] staging: iio: ad7606: Move out of staging

2018-12-10 Thread Stefan Popa
Move ad7606 ADC driver out of staging and into the mainline.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Simplified the Kconfig menu.
- Added SPDX-License-Identifier.
- Ordered the includes alphabetically.
- Used a threaded interrupt.
- Replaced ad7606_poll_bh_to_ring() with ad7606_trigger_handler().
- Used a trigger. 
- Replaced wait_event_interruptible() with 
wait_for_completion_timeout().
- Replaced wake_up_interruptible() with complete().
- Used devm_iio_triggered_buffer_setup().
- Added buffer_ops.
- Used single line comments where needed.
- Removed the gap between docs and struct.
- Added ad7606_of_match[].
Changes in v3:
- Added a comment which offers more information of the way the interrupt
  is triggered.
- Fixed the way a new conversion is triggered.
- endianness = IIO_CPU
- Removed unnecessary mutex locks.
- Removed the buffer_postdisable ops and replaced it with 
buffer_predisable.
- Added a devm_add_action_or_reset() which deals with 
regulator_disable().
- Misc style fixes.
Changes in v4:
- Removed unused fields from the ad7606_state struct.
- Used the find_closest() macro when searching for the available scale
and the oversampling ratios.

 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  |  34 --
 drivers/staging/iio/adc/Makefile |   3 -
 drivers/staging/iio/adc/ad7606.c | 565 -
 drivers/staging/iio/adc/ad7606.h | 106 ---
 drivers/staging/iio/adc/ad7606_par.c | 113 ---
 drivers/staging/iio/adc/ad7606_spi.c |  79 -
 13 files changed, 912 insertions(+), 900 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 f642044..843545d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7606 DRIVER
+M: Stefan Popa 
+L: linux-...@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 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..c3f61c9 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -58,6 +58,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 a6e6a0b..b734f4f 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -8,6 +8,9 @@ obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
+obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
+obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
+obj-$(CONFIG_AD7606) += ad7606.o
 obj-$(C

[PATCH v3 1/2] staging: iio: ad7606: Move out of staging

2018-11-29 Thread Stefan Popa
Move ad7606 ADC driver out of staging and into the mainline.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Simplified the Kconfig menu.
- Added SPDX-License-Identifier.
- Ordered the includes alphabetically.
- Used a threaded interrupt.
- Replaced ad7606_poll_bh_to_ring() with ad7606_trigger_handler().
- Used a trigger. 
- Replaced wait_event_interruptible() with 
wait_for_completion_timeout().
- Replaced wake_up_interruptible() with complete().
- Used devm_iio_triggered_buffer_setup().
- Added buffer_ops.
- Used single line comments where needed.
- Removed the gap between docs and struct.
- Added ad7606_of_match[].
Changes in v3:
- Added a comment which offers more information of the way the interrupt
  is triggered.
- Fixed the way a new conversion is triggered.
- endianness = IIO_CPU
- Removed unnecessary mutex locks.
- Removed the buffer_postdisable ops and replaced it with 
buffer_predisable.
- Added a devm_add_action_or_reset() which deals with 
regulator_disable().
- Misc style fixes.

 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  28 ++
 drivers/iio/adc/Makefile |   3 +
 drivers/iio/adc/ad7606.c | 605 +++
 drivers/iio/adc/ad7606.h | 106 ++
 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 |   3 -
 drivers/staging/iio/adc/ad7606.c | 565 
 drivers/staging/iio/adc/ad7606.h | 106 --
 drivers/staging/iio/adc/ad7606_par.c | 113 ---
 drivers/staging/iio/adc/ad7606_spi.c |  79 -
 13 files changed, 936 insertions(+), 900 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 f642044..843545d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7606 DRIVER
+M: Stefan Popa 
+L: linux-...@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 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..c3f61c9 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -58,6 +58,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 a6e6a0b..b734f4f 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -8,6 +8,9 @@ obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
+obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
+obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
+obj-$(CONFIG_AD7606) += ad7606.o
 obj-$(CONFIG_AD7923) += ad7923.o
 obj-$(CONFIG_AD7476) += ad7476.o
 obj-$(CONFIG_AD7766) += ad7766.o
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
new file mode 100644
index 00

[PATCH v3 2/2] dt-bindings: iio: adc: Add docs for AD7606 ADC

2018-11-29 Thread Stefan Popa
Document support for AD7606 Analog to Digital Converter.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- fixed indentation issues.
- used gpios instead of gpio.
- added vendor prefix for conversion-start-gpios, first-data-gpios,
and range-gpios.
Changes in v3:
- Added adi,oversampling-ratio-gpios.

 .../devicetree/bindings/iio/adc/adi,ad7606.txt | 54 ++
 MAINTAINERS|  1 +
 2 files changed, 55 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 000..02fae23
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
@@ -0,0 +1,54 @@
+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.
+
+Optional properties:
+
+- reset-gpios: must be the device tree identifier of the RESET pin. If 
specified,
+  it will be asserted during driver probe.
+- 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.
+- 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.
+- 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.
+
+Example:
+
+   adc@0 {
+   compatible = "adi,ad7606-8";
+   reg = <0>;
+   spi-max-frequency = <100>;
+   spi-cpol;
+
+   avcc-supply = <_vref>;
+
+   interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-parent = <>;
+
+   adi,conversion-start-gpios = < 17 0>;
+   reset-gpios = < 27 0>;
+   adi,first-data-gpios = < 22 0>;
+   standby-gpios = < 24 0>;
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 843545d..6d63db4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -845,6 +845,7 @@ L:  linux-...@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 
-- 
2.7.4



[PATCH v3 2/2] dt-bindings: iio: adc: Add docs for AD7606 ADC

2018-11-29 Thread Stefan Popa
Document support for AD7606 Analog to Digital Converter.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- fixed indentation issues.
- used gpios instead of gpio.
- added vendor prefix for conversion-start-gpios, first-data-gpios,
and range-gpios.
Changes in v3:
- Added adi,oversampling-ratio-gpios.

 .../devicetree/bindings/iio/adc/adi,ad7606.txt | 54 ++
 MAINTAINERS|  1 +
 2 files changed, 55 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 000..02fae23
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
@@ -0,0 +1,54 @@
+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.
+
+Optional properties:
+
+- reset-gpios: must be the device tree identifier of the RESET pin. If 
specified,
+  it will be asserted during driver probe.
+- 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.
+- 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.
+- 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.
+
+Example:
+
+   adc@0 {
+   compatible = "adi,ad7606-8";
+   reg = <0>;
+   spi-max-frequency = <100>;
+   spi-cpol;
+
+   avcc-supply = <_vref>;
+
+   interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-parent = <>;
+
+   adi,conversion-start-gpios = < 17 0>;
+   reset-gpios = < 27 0>;
+   adi,first-data-gpios = < 22 0>;
+   standby-gpios = < 24 0>;
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 843545d..6d63db4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -845,6 +845,7 @@ L:  linux-...@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 
-- 
2.7.4



[PATCH v3 1/2] staging: iio: ad7606: Move out of staging

2018-11-29 Thread Stefan Popa
Move ad7606 ADC driver out of staging and into the mainline.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Simplified the Kconfig menu.
- Added SPDX-License-Identifier.
- Ordered the includes alphabetically.
- Used a threaded interrupt.
- Replaced ad7606_poll_bh_to_ring() with ad7606_trigger_handler().
- Used a trigger. 
- Replaced wait_event_interruptible() with 
wait_for_completion_timeout().
- Replaced wake_up_interruptible() with complete().
- Used devm_iio_triggered_buffer_setup().
- Added buffer_ops.
- Used single line comments where needed.
- Removed the gap between docs and struct.
- Added ad7606_of_match[].
Changes in v3:
- Added a comment which offers more information of the way the interrupt
  is triggered.
- Fixed the way a new conversion is triggered.
- endianness = IIO_CPU
- Removed unnecessary mutex locks.
- Removed the buffer_postdisable ops and replaced it with 
buffer_predisable.
- Added a devm_add_action_or_reset() which deals with 
regulator_disable().
- Misc style fixes.

 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  28 ++
 drivers/iio/adc/Makefile |   3 +
 drivers/iio/adc/ad7606.c | 605 +++
 drivers/iio/adc/ad7606.h | 106 ++
 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 |   3 -
 drivers/staging/iio/adc/ad7606.c | 565 
 drivers/staging/iio/adc/ad7606.h | 106 --
 drivers/staging/iio/adc/ad7606_par.c | 113 ---
 drivers/staging/iio/adc/ad7606_spi.c |  79 -
 13 files changed, 936 insertions(+), 900 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 f642044..843545d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7606 DRIVER
+M: Stefan Popa 
+L: linux-...@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 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..c3f61c9 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -58,6 +58,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 a6e6a0b..b734f4f 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -8,6 +8,9 @@ obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
+obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
+obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
+obj-$(CONFIG_AD7606) += ad7606.o
 obj-$(CONFIG_AD7923) += ad7923.o
 obj-$(CONFIG_AD7476) += ad7476.o
 obj-$(CONFIG_AD7766) += ad7766.o
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
new file mode 100644
index 00

[PATCH v2 2/2] dt-bindings: iio: adc: Add docs for AD7606 ADC

2018-11-20 Thread Stefan Popa
Document support for AD7606 Analog to Digital Converter.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- fixed indentation issues.
- used gpios instead of gpio.
- added vendor prefix for conversion-start-gpios, first-data-gpios,
and range-gpios.

 .../devicetree/bindings/iio/adc/adi,ad7606.txt | 54 ++
 MAINTAINERS|  1 +
 2 files changed, 55 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 000..02fae23
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
@@ -0,0 +1,54 @@
+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.
+
+Optional properties:
+
+- reset-gpios: must be the device tree identifier of the RESET pin. If 
specified,
+  it will be asserted during driver probe.
+- 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.
+- 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.
+- 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.
+
+Example:
+
+   adc@0 {
+   compatible = "adi,ad7606-8";
+   reg = <0>;
+   spi-max-frequency = <100>;
+   spi-cpol;
+
+   avcc-supply = <_vref>;
+
+   interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-parent = <>;
+
+   adi,conversion-start-gpios = < 17 0>;
+   reset-gpios = < 27 0>;
+   adi,first-data-gpios = < 22 0>;
+   standby-gpios = < 24 0>;
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 843545d..6d63db4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -845,6 +845,7 @@ L:  linux-...@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 
-- 
2.7.4



[PATCH v2 2/2] dt-bindings: iio: adc: Add docs for AD7606 ADC

2018-11-20 Thread Stefan Popa
Document support for AD7606 Analog to Digital Converter.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- fixed indentation issues.
- used gpios instead of gpio.
- added vendor prefix for conversion-start-gpios, first-data-gpios,
and range-gpios.

 .../devicetree/bindings/iio/adc/adi,ad7606.txt | 54 ++
 MAINTAINERS|  1 +
 2 files changed, 55 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 000..02fae23
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.txt
@@ -0,0 +1,54 @@
+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.
+
+Optional properties:
+
+- reset-gpios: must be the device tree identifier of the RESET pin. If 
specified,
+  it will be asserted during driver probe.
+- 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.
+- 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.
+- 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.
+
+Example:
+
+   adc@0 {
+   compatible = "adi,ad7606-8";
+   reg = <0>;
+   spi-max-frequency = <100>;
+   spi-cpol;
+
+   avcc-supply = <_vref>;
+
+   interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+   interrupt-parent = <>;
+
+   adi,conversion-start-gpios = < 17 0>;
+   reset-gpios = < 27 0>;
+   adi,first-data-gpios = < 22 0>;
+   standby-gpios = < 24 0>;
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 843545d..6d63db4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -845,6 +845,7 @@ L:  linux-...@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 
-- 
2.7.4



[PATCH v2 1/2] staging: iio: ad7606: Move out of staging

2018-11-20 Thread Stefan Popa
Move ad7606 ADC driver out of staging and into the mainline.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Simplified the Kconfig menu.
- Added SPDX-License-Identifier.
- Ordered the includes alphabetically.
- Used a threaded interrupt.
- Replaced ad7606_poll_bh_to_ring() with ad7606_trigger_handler().
- Used a trigger. 
- Replaced wait_event_interruptible() with 
wait_for_completion_timeout().
- Replaced wake_up_interruptible() with complete().
- Used devm_iio_triggered_buffer_setup().
- Added buffer_ops.
- Used single line comments where needed.
- Removed the gap between docs and struct.
- Added ad7606_of_match[].

 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  28 ++
 drivers/iio/adc/Makefile |   3 +
 drivers/iio/adc/ad7606.c | 608 +++
 drivers/iio/adc/ad7606.h | 107 ++
 drivers/iio/adc/ad7606_par.c | 110 +++
 drivers/iio/adc/ad7606_spi.c |  88 +
 drivers/staging/iio/adc/Kconfig  |  34 --
 drivers/staging/iio/adc/Makefile |   3 -
 drivers/staging/iio/adc/ad7606.c | 565 
 drivers/staging/iio/adc/ad7606.h | 106 --
 drivers/staging/iio/adc/ad7606_par.c | 113 ---
 drivers/staging/iio/adc/ad7606_spi.c |  79 -
 13 files changed, 951 insertions(+), 900 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 f642044..843545d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7606 DRIVER
+M: Stefan Popa 
+L: linux-...@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 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..c3f61c9 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -58,6 +58,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 a6e6a0b..b734f4f 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -8,6 +8,9 @@ obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
+obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
+obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
+obj-$(CONFIG_AD7606) += ad7606.o
 obj-$(CONFIG_AD7923) += ad7923.o
 obj-$(CONFIG_AD7476) += ad7476.o
 obj-$(CONFIG_AD7766) += ad7766.o
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
new file mode 100644
index 000..4e09635
--- /dev/null
+++ b/drivers/iio/adc/ad7606.c
@@ -0,0 +1,608 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7606 SPI ADC driver
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ad7606.h"
+
+/*
+ * Scales are computed as 5000/32

[PATCH v2 1/2] staging: iio: ad7606: Move out of staging

2018-11-20 Thread Stefan Popa
Move ad7606 ADC driver out of staging and into the mainline.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Simplified the Kconfig menu.
- Added SPDX-License-Identifier.
- Ordered the includes alphabetically.
- Used a threaded interrupt.
- Replaced ad7606_poll_bh_to_ring() with ad7606_trigger_handler().
- Used a trigger. 
- Replaced wait_event_interruptible() with 
wait_for_completion_timeout().
- Replaced wake_up_interruptible() with complete().
- Used devm_iio_triggered_buffer_setup().
- Added buffer_ops.
- Used single line comments where needed.
- Removed the gap between docs and struct.
- Added ad7606_of_match[].

 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  28 ++
 drivers/iio/adc/Makefile |   3 +
 drivers/iio/adc/ad7606.c | 608 +++
 drivers/iio/adc/ad7606.h | 107 ++
 drivers/iio/adc/ad7606_par.c | 110 +++
 drivers/iio/adc/ad7606_spi.c |  88 +
 drivers/staging/iio/adc/Kconfig  |  34 --
 drivers/staging/iio/adc/Makefile |   3 -
 drivers/staging/iio/adc/ad7606.c | 565 
 drivers/staging/iio/adc/ad7606.h | 106 --
 drivers/staging/iio/adc/ad7606_par.c | 113 ---
 drivers/staging/iio/adc/ad7606_spi.c |  79 -
 13 files changed, 951 insertions(+), 900 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 f642044..843545d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7606 DRIVER
+M: Stefan Popa 
+L: linux-...@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 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..c3f61c9 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -58,6 +58,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 a6e6a0b..b734f4f 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -8,6 +8,9 @@ obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
+obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
+obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
+obj-$(CONFIG_AD7606) += ad7606.o
 obj-$(CONFIG_AD7923) += ad7923.o
 obj-$(CONFIG_AD7476) += ad7476.o
 obj-$(CONFIG_AD7766) += ad7766.o
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
new file mode 100644
index 000..4e09635
--- /dev/null
+++ b/drivers/iio/adc/ad7606.c
@@ -0,0 +1,608 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7606 SPI ADC driver
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ad7606.h"
+
+/*
+ * Scales are computed as 5000/32

[PATCH v5 3/4] iio: adc: Add ad7124 support

2018-11-13 Thread Stefan Popa
The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta ADCs
with 24-bit precision and reference.

Three power modes are available which in turn affect the output data rate:
 * Full power: 9.38 SPS to 19,200 SPS
 * Mid power: 2.34 SPS to 4800 SPS
 * Low power: 1.17 SPS to 2400 SPS

The ad7124-4 can be configured to have four differential inputs, while
ad7124-8 can have 8. Moreover, ad7124 also supports per channel
configuration. Each configuration consists of gain, reference source,
output data rate and bipolar/unipolar configuration.

Datasheets:
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-4.pdf
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Removed channel, address, scan_index and shift fields from
  ad7124_channel_template.
- Added a sanity check for val2 in ad7124_write_raw().
- Used the "reg" property to get the channel address and 
"adi,diff-channels"
  for the differential pins. The "adi,channel-number" property was 
removed.
- When calling regulator_get_optional, the probe is given up in case of 
error,
  but continues in case of -ENODEV.
- clk_disable_unprepare() is called before 
ad_sd_cleanup_buffer_and_trigger
  in ad7124_remove().
Changes in v4:
- Added the .shift and .endianness fields as part of the 
ad7124_channel_template.
- Made the gain configurable from the user space.
- Removed the odr_hz and gain properties from the DT.
- Used the bipolar and diff-channels properties defined in the new 
adc.txt doc.
- Misc style fixes.
Changes in v5:
- Fixed the way the offset is determined.
- Dropped the hardware gain.
- Added a scale_available attribute.
- The scale can be set from user space.
- In ad7124_read_raw(), the gain in applied to *val2.
  
 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  11 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7124.c | 686 +++
 4 files changed, 705 insertions(+)
 create mode 100644 drivers/iio/adc/ad7124.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f642044..3a1bfcb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7124 DRIVER
+M: Stefan Popa 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7124.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..148a10f 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
 
+config AD7124
+   tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
+   depends on SPI_MASTER
+   select AD_SIGMA_DELTA
+   help
+ Say yes here to build support for Analog Devices AD7124-4 and AD7124-8
+ SPI analog to digital converters (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7124.
+
 config AD7266
tristate "Analog Devices AD7265/AD7266 ADC driver"
depends on SPI_MASTER
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index a6e6a0b..76168b2 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -5,6 +5,7 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
+obj-$(CONFIG_AD7124) += ad7124.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
new file mode 100644
index 000..187675e
--- /dev/null
+++ b/drivers/iio/adc/ad7124.c
@@ -0,0 +1,686 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7124 SPI ADC driver
+ *
+ * Copyright 2018 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* AD7124 registers */
+#define AD7124_COMMS   0x00
+#define AD7124_STATUS  0x00
+#define AD7124_ADC_CONTROL 0x01
+#define AD7124_DATA0x02
+#define AD7124_IO_CONTROL_10x03
+#define AD7124_IO_CONTROL_20x04
+#define AD7124_ID  0x05
+#define AD7124_ERROR   0x06
+#define AD7124_ERROR_EN0x07
+#define AD7124_MCLK_COUNT  0x08
+#define AD7124_CHANNEL(x) 

[PATCH v5 3/4] iio: adc: Add ad7124 support

2018-11-13 Thread Stefan Popa
The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta ADCs
with 24-bit precision and reference.

Three power modes are available which in turn affect the output data rate:
 * Full power: 9.38 SPS to 19,200 SPS
 * Mid power: 2.34 SPS to 4800 SPS
 * Low power: 1.17 SPS to 2400 SPS

The ad7124-4 can be configured to have four differential inputs, while
ad7124-8 can have 8. Moreover, ad7124 also supports per channel
configuration. Each configuration consists of gain, reference source,
output data rate and bipolar/unipolar configuration.

Datasheets:
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-4.pdf
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Removed channel, address, scan_index and shift fields from
  ad7124_channel_template.
- Added a sanity check for val2 in ad7124_write_raw().
- Used the "reg" property to get the channel address and 
"adi,diff-channels"
  for the differential pins. The "adi,channel-number" property was 
removed.
- When calling regulator_get_optional, the probe is given up in case of 
error,
  but continues in case of -ENODEV.
- clk_disable_unprepare() is called before 
ad_sd_cleanup_buffer_and_trigger
  in ad7124_remove().
Changes in v4:
- Added the .shift and .endianness fields as part of the 
ad7124_channel_template.
- Made the gain configurable from the user space.
- Removed the odr_hz and gain properties from the DT.
- Used the bipolar and diff-channels properties defined in the new 
adc.txt doc.
- Misc style fixes.
Changes in v5:
- Fixed the way the offset is determined.
- Dropped the hardware gain.
- Added a scale_available attribute.
- The scale can be set from user space.
- In ad7124_read_raw(), the gain in applied to *val2.
  
 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  11 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7124.c | 686 +++
 4 files changed, 705 insertions(+)
 create mode 100644 drivers/iio/adc/ad7124.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f642044..3a1bfcb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7124 DRIVER
+M: Stefan Popa 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7124.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..148a10f 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
 
+config AD7124
+   tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
+   depends on SPI_MASTER
+   select AD_SIGMA_DELTA
+   help
+ Say yes here to build support for Analog Devices AD7124-4 and AD7124-8
+ SPI analog to digital converters (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7124.
+
 config AD7266
tristate "Analog Devices AD7265/AD7266 ADC driver"
depends on SPI_MASTER
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index a6e6a0b..76168b2 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -5,6 +5,7 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
+obj-$(CONFIG_AD7124) += ad7124.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
new file mode 100644
index 000..187675e
--- /dev/null
+++ b/drivers/iio/adc/ad7124.c
@@ -0,0 +1,686 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7124 SPI ADC driver
+ *
+ * Copyright 2018 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* AD7124 registers */
+#define AD7124_COMMS   0x00
+#define AD7124_STATUS  0x00
+#define AD7124_ADC_CONTROL 0x01
+#define AD7124_DATA0x02
+#define AD7124_IO_CONTROL_10x03
+#define AD7124_IO_CONTROL_20x04
+#define AD7124_ID  0x05
+#define AD7124_ERROR   0x06
+#define AD7124_ERROR_EN0x07
+#define AD7124_MCLK_COUNT  0x08
+#define AD7124_CHANNEL(x) 

[PATCH v5 4/4] dt-bindings: iio: adc: Add docs for ad7124

2018-11-13 Thread Stefan Popa
Add support for Analog Devices AD7124 4-channels and 8-channels ADC.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Removed the "adi,channels" property.
- Used the "reg" property to get the channel number and 
"adi,diff-channels"
  for the differential pins. The "adi,channel-number" property was 
removed.
- adi,bipolar is of boolean type.
Changes in v4:
- Used the bipolar and diff-channels properties defined in the new 
adc.txt doc.
Changes in v5:
- Removed the gain and odr properties from the example.

 .../devicetree/bindings/iio/adc/adi,ad7124.txt | 75 ++
 MAINTAINERS|  1 +
 2 files changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt 
b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
new file mode 100644
index 000..416273d
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
@@ -0,0 +1,75 @@
+Analog Devices AD7124 ADC device driver
+
+Required properties for the AD7124:
+   - compatible: Must be one of "adi,ad7124-4" or "adi,ad7124-8"
+   - reg: SPI chip select number for the device
+   - spi-max-frequency: Max SPI frequency to use
+   see: Documentation/devicetree/bindings/spi/spi-bus.txt
+   - clocks: phandle to the master clock (mclk)
+   see: Documentation/devicetree/bindings/clock/clock-bindings.txt
+   - clock-names: Must be "mclk".
+   - interrupts: IRQ line for the ADC
+   see: 
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+
+ Required properties:
+   * #address-cells: Must be 1.
+   * #size-cells: Must be 0.
+
+ Subnode(s) represent the external channels which are connected to the 
ADC.
+ Each subnode represents one channel and has the following properties:
+   Required properties:
+   * reg: The channel number. It can have up to 4 channels 
on ad7124-4
+ and 8 channels on ad7124-8, numbered from 0 to 15.
+   * diff-channels: see: 
Documentation/devicetree/bindings/iio/adc/adc.txt
+
+   Optional properties:
+   * bipolar: see: 
Documentation/devicetree/bindings/iio/adc/adc.txt
+   * adi,reference-select: Select the reference source to 
use when
+ converting on the the specific channel. Valid values 
are:
+ 0: REFIN1(+)/REFIN1(−).
+ 1: REFIN2(+)/REFIN2(−).
+ 3: AVDD
+ If this field is left empty, internal reference is 
selected.
+
+Optional properties:
+   - refin1-supply: refin1 supply can be used as reference for conversion.
+   - refin2-supply: refin2 supply can be used as reference for conversion.
+   - avdd-supply: avdd supply can be used as reference for conversion.
+
+Example:
+   adc@0 {
+   compatible = "adi,ad7124-4";
+   reg = <0>;
+   spi-max-frequency = <500>;
+   interrupts = <25 2>;
+   interrupt-parent = <>;
+   refin1-supply = <_vref>;
+   clocks = <_mclk>;
+   clock-names = "mclk";
+
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   channel@0 {
+   reg = <0>;
+   diff-channels = <0 1>;
+   adi,reference-select = <0>;
+   };
+
+   channel@1 {
+   reg = <1>;
+   bipolar;
+   diff-channels = <2 3>;
+   adi,reference-select = <0>;
+   };
+
+   channel@2 {
+   reg = <2>;
+   diff-channels = <4 5>;
+   };
+
+   channel@3 {
+   reg = <3>;
+   diff-channels = <6 7>;
+   };
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 3a1bfcb..f2fa508 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -845,6 +845,7 @@ L:  linux-...@vger.kernel.org
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
 F: drivers/iio/adc/ad7124.c
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
 
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
-- 
2.7.4



[PATCH v5 4/4] dt-bindings: iio: adc: Add docs for ad7124

2018-11-13 Thread Stefan Popa
Add support for Analog Devices AD7124 4-channels and 8-channels ADC.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Removed the "adi,channels" property.
- Used the "reg" property to get the channel number and 
"adi,diff-channels"
  for the differential pins. The "adi,channel-number" property was 
removed.
- adi,bipolar is of boolean type.
Changes in v4:
- Used the bipolar and diff-channels properties defined in the new 
adc.txt doc.
Changes in v5:
- Removed the gain and odr properties from the example.

 .../devicetree/bindings/iio/adc/adi,ad7124.txt | 75 ++
 MAINTAINERS|  1 +
 2 files changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt 
b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
new file mode 100644
index 000..416273d
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
@@ -0,0 +1,75 @@
+Analog Devices AD7124 ADC device driver
+
+Required properties for the AD7124:
+   - compatible: Must be one of "adi,ad7124-4" or "adi,ad7124-8"
+   - reg: SPI chip select number for the device
+   - spi-max-frequency: Max SPI frequency to use
+   see: Documentation/devicetree/bindings/spi/spi-bus.txt
+   - clocks: phandle to the master clock (mclk)
+   see: Documentation/devicetree/bindings/clock/clock-bindings.txt
+   - clock-names: Must be "mclk".
+   - interrupts: IRQ line for the ADC
+   see: 
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+
+ Required properties:
+   * #address-cells: Must be 1.
+   * #size-cells: Must be 0.
+
+ Subnode(s) represent the external channels which are connected to the 
ADC.
+ Each subnode represents one channel and has the following properties:
+   Required properties:
+   * reg: The channel number. It can have up to 4 channels 
on ad7124-4
+ and 8 channels on ad7124-8, numbered from 0 to 15.
+   * diff-channels: see: 
Documentation/devicetree/bindings/iio/adc/adc.txt
+
+   Optional properties:
+   * bipolar: see: 
Documentation/devicetree/bindings/iio/adc/adc.txt
+   * adi,reference-select: Select the reference source to 
use when
+ converting on the the specific channel. Valid values 
are:
+ 0: REFIN1(+)/REFIN1(−).
+ 1: REFIN2(+)/REFIN2(−).
+ 3: AVDD
+ If this field is left empty, internal reference is 
selected.
+
+Optional properties:
+   - refin1-supply: refin1 supply can be used as reference for conversion.
+   - refin2-supply: refin2 supply can be used as reference for conversion.
+   - avdd-supply: avdd supply can be used as reference for conversion.
+
+Example:
+   adc@0 {
+   compatible = "adi,ad7124-4";
+   reg = <0>;
+   spi-max-frequency = <500>;
+   interrupts = <25 2>;
+   interrupt-parent = <>;
+   refin1-supply = <_vref>;
+   clocks = <_mclk>;
+   clock-names = "mclk";
+
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   channel@0 {
+   reg = <0>;
+   diff-channels = <0 1>;
+   adi,reference-select = <0>;
+   };
+
+   channel@1 {
+   reg = <1>;
+   bipolar;
+   diff-channels = <2 3>;
+   adi,reference-select = <0>;
+   };
+
+   channel@2 {
+   reg = <2>;
+   diff-channels = <4 5>;
+   };
+
+   channel@3 {
+   reg = <3>;
+   diff-channels = <6 7>;
+   };
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 3a1bfcb..f2fa508 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -845,6 +845,7 @@ L:  linux-...@vger.kernel.org
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
 F: drivers/iio/adc/ad7124.c
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
 
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
-- 
2.7.4



[PATCH v5 2/4] dt-bindings: iio: adc: Add common ADCs properties to a separate file

2018-11-13 Thread Stefan Popa
There are several ADC drivers that depend on the same device tree
bindings. Rather than continue to duplicate the properties, this patch
adds a common adc binding document that can be referenced. For beginning,
only two properties are documented.

Signed-off-by: Stefan Popa 
---
Changes in v2, v3:
- N/A.
Changes in v4:
- Added this commit.
Changes in v5:
- Nothing changed.

 Documentation/devicetree/bindings/iio/adc/adc.txt | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adc.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adc.txt 
b/Documentation/devicetree/bindings/iio/adc/adc.txt
new file mode 100644
index 000..5bbaa33
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adc.txt
@@ -0,0 +1,23 @@
+Common ADCs properties
+
+Optional properties for child nodes:
+- bipolar : Boolean, if set the channel is used in bipolar mode.
+- diff-channels : Differential channels muxed for this ADC. The first value
+   specifies the positive input pin, the second value the negative
+   input pin.
+
+Example:
+   adc@0 {
+   compatible = "some,adc";
+   ...
+   channel@0 {
+   bipolar;
+   diff-channels = <0 1>;
+   ...
+   };
+
+   channel@1 {
+   diff-channels = <2 3>;
+   ...
+   };
+   };
-- 
2.7.4



[PATCH v5 1/4] iio: ad_sigma_delta: Allow to provide custom data register address

2018-11-13 Thread Stefan Popa
From: Lars-Peter Clausen 

Some newer devices from the Sigma-Delta ADC family do have their data
register at a different address than the current default address. Add a
parameter to the ad_sigma_delta_info struct which allows to override the
default address.

Signed-off-by: Lars-Peter Clausen 
Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added this commit.
Changes in v3:
- Nothing changed.
Changes in v4:
- Nothing changed.
Changes in v5:
- Nothing changed.

 drivers/iio/adc/ad_sigma_delta.c   | 22 +-
 include/linux/iio/adc/ad_sigma_delta.h |  3 +++
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index fc95107..ff5f2da 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -278,6 +278,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev 
*indio_dev,
 {
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
unsigned int sample, raw_sample;
+   unsigned int data_reg;
int ret = 0;
 
if (iio_buffer_enabled(indio_dev))
@@ -305,7 +306,12 @@ int ad_sigma_delta_single_conversion(struct iio_dev 
*indio_dev,
if (ret < 0)
goto out;
 
-   ret = ad_sd_read_reg(sigma_delta, AD_SD_REG_DATA,
+   if (sigma_delta->info->data_reg != 0)
+   data_reg = sigma_delta->info->data_reg;
+   else
+   data_reg = AD_SD_REG_DATA;
+
+   ret = ad_sd_read_reg(sigma_delta, data_reg,
DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift, 
8),
_sample);
 
@@ -392,6 +398,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
struct iio_dev *indio_dev = pf->indio_dev;
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
unsigned int reg_size;
+   unsigned int data_reg;
uint8_t data[16];
int ret;
 
@@ -401,18 +408,23 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
indio_dev->channels[0].scan_type.shift;
reg_size = DIV_ROUND_UP(reg_size, 8);
 
+   if (sigma_delta->info->data_reg != 0)
+   data_reg = sigma_delta->info->data_reg;
+   else
+   data_reg = AD_SD_REG_DATA;
+
switch (reg_size) {
case 4:
case 2:
case 1:
-   ret = ad_sd_read_reg_raw(sigma_delta, AD_SD_REG_DATA,
-   reg_size, [0]);
+   ret = ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size,
+   [0]);
break;
case 3:
/* We store 24 bit samples in a 32 bit word. Keep the upper
 * byte set to zero. */
-   ret = ad_sd_read_reg_raw(sigma_delta, AD_SD_REG_DATA,
-   reg_size, [1]);
+   ret = ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size,
+   [1]);
break;
}
 
diff --git a/include/linux/iio/adc/ad_sigma_delta.h 
b/include/linux/iio/adc/ad_sigma_delta.h
index 730ead1..7e84351 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -39,6 +39,8 @@ struct iio_dev;
  * if there is just one read-only sample data shift register.
  * @addr_shift: Shift of the register address in the communications register.
  * @read_mask: Mask for the communications register having the read bit set.
+ * @data_reg: Address of the data register, if 0 the default address of 0x3 
will
+ *   be used.
  */
 struct ad_sigma_delta_info {
int (*set_channel)(struct ad_sigma_delta *, unsigned int channel);
@@ -47,6 +49,7 @@ struct ad_sigma_delta_info {
bool has_registers;
unsigned int addr_shift;
unsigned int read_mask;
+   unsigned int data_reg;
 };
 
 /**
-- 
2.7.4



[PATCH v5 2/4] dt-bindings: iio: adc: Add common ADCs properties to a separate file

2018-11-13 Thread Stefan Popa
There are several ADC drivers that depend on the same device tree
bindings. Rather than continue to duplicate the properties, this patch
adds a common adc binding document that can be referenced. For beginning,
only two properties are documented.

Signed-off-by: Stefan Popa 
---
Changes in v2, v3:
- N/A.
Changes in v4:
- Added this commit.
Changes in v5:
- Nothing changed.

 Documentation/devicetree/bindings/iio/adc/adc.txt | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adc.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adc.txt 
b/Documentation/devicetree/bindings/iio/adc/adc.txt
new file mode 100644
index 000..5bbaa33
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adc.txt
@@ -0,0 +1,23 @@
+Common ADCs properties
+
+Optional properties for child nodes:
+- bipolar : Boolean, if set the channel is used in bipolar mode.
+- diff-channels : Differential channels muxed for this ADC. The first value
+   specifies the positive input pin, the second value the negative
+   input pin.
+
+Example:
+   adc@0 {
+   compatible = "some,adc";
+   ...
+   channel@0 {
+   bipolar;
+   diff-channels = <0 1>;
+   ...
+   };
+
+   channel@1 {
+   diff-channels = <2 3>;
+   ...
+   };
+   };
-- 
2.7.4



[PATCH v5 1/4] iio: ad_sigma_delta: Allow to provide custom data register address

2018-11-13 Thread Stefan Popa
From: Lars-Peter Clausen 

Some newer devices from the Sigma-Delta ADC family do have their data
register at a different address than the current default address. Add a
parameter to the ad_sigma_delta_info struct which allows to override the
default address.

Signed-off-by: Lars-Peter Clausen 
Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added this commit.
Changes in v3:
- Nothing changed.
Changes in v4:
- Nothing changed.
Changes in v5:
- Nothing changed.

 drivers/iio/adc/ad_sigma_delta.c   | 22 +-
 include/linux/iio/adc/ad_sigma_delta.h |  3 +++
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index fc95107..ff5f2da 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -278,6 +278,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev 
*indio_dev,
 {
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
unsigned int sample, raw_sample;
+   unsigned int data_reg;
int ret = 0;
 
if (iio_buffer_enabled(indio_dev))
@@ -305,7 +306,12 @@ int ad_sigma_delta_single_conversion(struct iio_dev 
*indio_dev,
if (ret < 0)
goto out;
 
-   ret = ad_sd_read_reg(sigma_delta, AD_SD_REG_DATA,
+   if (sigma_delta->info->data_reg != 0)
+   data_reg = sigma_delta->info->data_reg;
+   else
+   data_reg = AD_SD_REG_DATA;
+
+   ret = ad_sd_read_reg(sigma_delta, data_reg,
DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift, 
8),
_sample);
 
@@ -392,6 +398,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
struct iio_dev *indio_dev = pf->indio_dev;
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
unsigned int reg_size;
+   unsigned int data_reg;
uint8_t data[16];
int ret;
 
@@ -401,18 +408,23 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
indio_dev->channels[0].scan_type.shift;
reg_size = DIV_ROUND_UP(reg_size, 8);
 
+   if (sigma_delta->info->data_reg != 0)
+   data_reg = sigma_delta->info->data_reg;
+   else
+   data_reg = AD_SD_REG_DATA;
+
switch (reg_size) {
case 4:
case 2:
case 1:
-   ret = ad_sd_read_reg_raw(sigma_delta, AD_SD_REG_DATA,
-   reg_size, [0]);
+   ret = ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size,
+   [0]);
break;
case 3:
/* We store 24 bit samples in a 32 bit word. Keep the upper
 * byte set to zero. */
-   ret = ad_sd_read_reg_raw(sigma_delta, AD_SD_REG_DATA,
-   reg_size, [1]);
+   ret = ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size,
+   [1]);
break;
}
 
diff --git a/include/linux/iio/adc/ad_sigma_delta.h 
b/include/linux/iio/adc/ad_sigma_delta.h
index 730ead1..7e84351 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -39,6 +39,8 @@ struct iio_dev;
  * if there is just one read-only sample data shift register.
  * @addr_shift: Shift of the register address in the communications register.
  * @read_mask: Mask for the communications register having the read bit set.
+ * @data_reg: Address of the data register, if 0 the default address of 0x3 
will
+ *   be used.
  */
 struct ad_sigma_delta_info {
int (*set_channel)(struct ad_sigma_delta *, unsigned int channel);
@@ -47,6 +49,7 @@ struct ad_sigma_delta_info {
bool has_registers;
unsigned int addr_shift;
unsigned int read_mask;
+   unsigned int data_reg;
 };
 
 /**
-- 
2.7.4



[PATCH v4 4/4] dt-bindings: iio: adc: Add docs for ad7124

2018-11-09 Thread Stefan Popa
Add support for Analog Devices AD7124 4-channels and 8-channels ADC.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Removed the "adi,channels" property.
- Used the "reg" property to get the channel number and 
"adi,diff-channels"
  for the differential pins. The "adi,channel-number" property was 
removed.
- adi,bipolar is of boolean type.
Changes in v4:
- Used the bipolar and diff-channels properties defined in the new 
adc.txt doc.

 .../devicetree/bindings/iio/adc/adi,ad7124.txt | 81 ++
 MAINTAINERS|  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt 
b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
new file mode 100644
index 000..fa0c43b
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
@@ -0,0 +1,81 @@
+Analog Devices AD7124 ADC device driver
+
+Required properties for the AD7124:
+   - compatible: Must be one of "adi,ad7124-4" or "adi,ad7124-8"
+   - reg: SPI chip select number for the device
+   - spi-max-frequency: Max SPI frequency to use
+   see: Documentation/devicetree/bindings/spi/spi-bus.txt
+   - clocks: phandle to the master clock (mclk)
+   see: Documentation/devicetree/bindings/clock/clock-bindings.txt
+   - clock-names: Must be "mclk".
+   - interrupts: IRQ line for the ADC
+   see: 
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+
+ Required properties:
+   * #address-cells: Must be 1.
+   * #size-cells: Must be 0.
+
+ Subnode(s) represent the external channels which are connected to the 
ADC.
+ Each subnode represents one channel and has the following properties:
+   Required properties:
+   * reg: The channel number. It can have up to 4 channels 
on ad7124-4
+ and 8 channels on ad7124-8, numbered from 0 to 15.
+   * diff-channels: see: 
Documentation/devicetree/bindings/iio/adc/adc.txt
+
+   Optional properties:
+   * bipolar: see: 
Documentation/devicetree/bindings/iio/adc/adc.txt
+   * adi,reference-select: Select the reference source to 
use when
+ converting on the the specific channel. Valid values 
are:
+ 0: REFIN1(+)/REFIN1(−).
+ 1: REFIN2(+)/REFIN2(−).
+ 3: AVDD
+ If this field is left empty, internal reference is 
selected.
+
+Optional properties:
+   - refin1-supply: refin1 supply can be used as reference for conversion.
+   - refin2-supply: refin2 supply can be used as reference for conversion.
+   - avdd-supply: avdd supply can be used as reference for conversion.
+
+Example:
+   adc@0 {
+   compatible = "adi,ad7124-4";
+   reg = <0>;
+   spi-max-frequency = <500>;
+   interrupts = <25 2>;
+   interrupt-parent = <>;
+   refin1-supply = <_vref>;
+   clocks = <_mclk>;
+   clock-names = "mclk";
+
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   channel@0 {
+   reg = <0>;
+   adi,diff-channels = <0 1>;
+   adi,reference-select = <0>;
+   adi,gain = <2>;
+   adi,odr-hz = <10>;
+   };
+
+   channel@1 {
+   reg = <1>;
+   adi,bipolar;
+   adi,diff-channels = <2 3>;
+   adi,reference-select = <0>;
+   adi,gain = <4>;
+   adi,odr-hz = <50>;
+   };
+
+   channel@2 {
+   reg = <2>;
+   adi,diff-channels = <4 5>;
+   adi,gain = <128>;
+   adi,odr-hz = <19200>;
+   };
+
+   channel@3 {
+   reg = <3>;
+   adi,diff-channels = <6 7>;
+   };
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 3a1bfcb..f2fa508 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -845,6 +845,7 @@ L:  linux-...@vger.kernel.org
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
 F: drivers/iio/adc/ad7124.c
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
 
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
-- 
2.7.4



[PATCH v4 4/4] dt-bindings: iio: adc: Add docs for ad7124

2018-11-09 Thread Stefan Popa
Add support for Analog Devices AD7124 4-channels and 8-channels ADC.

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Removed the "adi,channels" property.
- Used the "reg" property to get the channel number and 
"adi,diff-channels"
  for the differential pins. The "adi,channel-number" property was 
removed.
- adi,bipolar is of boolean type.
Changes in v4:
- Used the bipolar and diff-channels properties defined in the new 
adc.txt doc.

 .../devicetree/bindings/iio/adc/adi,ad7124.txt | 81 ++
 MAINTAINERS|  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt 
b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
new file mode 100644
index 000..fa0c43b
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
@@ -0,0 +1,81 @@
+Analog Devices AD7124 ADC device driver
+
+Required properties for the AD7124:
+   - compatible: Must be one of "adi,ad7124-4" or "adi,ad7124-8"
+   - reg: SPI chip select number for the device
+   - spi-max-frequency: Max SPI frequency to use
+   see: Documentation/devicetree/bindings/spi/spi-bus.txt
+   - clocks: phandle to the master clock (mclk)
+   see: Documentation/devicetree/bindings/clock/clock-bindings.txt
+   - clock-names: Must be "mclk".
+   - interrupts: IRQ line for the ADC
+   see: 
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+
+ Required properties:
+   * #address-cells: Must be 1.
+   * #size-cells: Must be 0.
+
+ Subnode(s) represent the external channels which are connected to the 
ADC.
+ Each subnode represents one channel and has the following properties:
+   Required properties:
+   * reg: The channel number. It can have up to 4 channels 
on ad7124-4
+ and 8 channels on ad7124-8, numbered from 0 to 15.
+   * diff-channels: see: 
Documentation/devicetree/bindings/iio/adc/adc.txt
+
+   Optional properties:
+   * bipolar: see: 
Documentation/devicetree/bindings/iio/adc/adc.txt
+   * adi,reference-select: Select the reference source to 
use when
+ converting on the the specific channel. Valid values 
are:
+ 0: REFIN1(+)/REFIN1(−).
+ 1: REFIN2(+)/REFIN2(−).
+ 3: AVDD
+ If this field is left empty, internal reference is 
selected.
+
+Optional properties:
+   - refin1-supply: refin1 supply can be used as reference for conversion.
+   - refin2-supply: refin2 supply can be used as reference for conversion.
+   - avdd-supply: avdd supply can be used as reference for conversion.
+
+Example:
+   adc@0 {
+   compatible = "adi,ad7124-4";
+   reg = <0>;
+   spi-max-frequency = <500>;
+   interrupts = <25 2>;
+   interrupt-parent = <>;
+   refin1-supply = <_vref>;
+   clocks = <_mclk>;
+   clock-names = "mclk";
+
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   channel@0 {
+   reg = <0>;
+   adi,diff-channels = <0 1>;
+   adi,reference-select = <0>;
+   adi,gain = <2>;
+   adi,odr-hz = <10>;
+   };
+
+   channel@1 {
+   reg = <1>;
+   adi,bipolar;
+   adi,diff-channels = <2 3>;
+   adi,reference-select = <0>;
+   adi,gain = <4>;
+   adi,odr-hz = <50>;
+   };
+
+   channel@2 {
+   reg = <2>;
+   adi,diff-channels = <4 5>;
+   adi,gain = <128>;
+   adi,odr-hz = <19200>;
+   };
+
+   channel@3 {
+   reg = <3>;
+   adi,diff-channels = <6 7>;
+   };
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 3a1bfcb..f2fa508 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -845,6 +845,7 @@ L:  linux-...@vger.kernel.org
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
 F: drivers/iio/adc/ad7124.c
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
 
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
-- 
2.7.4



[PATCH v4 3/4] iio: adc: Add ad7124 support

2018-11-09 Thread Stefan Popa
The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta ADCs
with 24-bit precision and reference.

Three power modes are available which in turn affect the output data rate:
 * Full power: 9.38 SPS to 19,200 SPS
 * Mid power: 2.34 SPS to 4800 SPS
 * Low power: 1.17 SPS to 2400 SPS

The ad7124-4 can be configured to have four differential inputs, while
ad7124-8 can have 8. Moreover, ad7124 also supports per channel
configuration. Each configuration consists of gain, reference source,
output data rate and bipolar/unipolar configuration.

Datasheets:
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-4.pdf
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Removed channel, address, scan_index and shift fields from
  ad7124_channel_template.
- Added a sanity check for val2 in ad7124_write_raw().
- Used the "reg" property to get the channel address and 
"adi,diff-channels"
  for the differential pins. The "adi,channel-number" property was 
removed.
- When calling regulator_get_optional, the probe is given up in case of 
error,
  but continues in case of -ENODEV.
- clk_disable_unprepare() is called before 
ad_sd_cleanup_buffer_and_trigger
  in ad7124_remove().
Changes in v4:
- Added the .shift and .endianness fields as part of the 
ad7124_channel_template.
- Made the gain configurable from the user space.
- Removed the odr_hz and gain properties from the DT.
- Used the bipolar and diff-channels properties defined in the new 
adc.txt doc.
- Misc style fixes.

 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  11 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7124.c | 676 +++
 4 files changed, 695 insertions(+)
 create mode 100644 drivers/iio/adc/ad7124.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f642044..3a1bfcb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7124 DRIVER
+M: Stefan Popa 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7124.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..148a10f 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
 
+config AD7124
+   tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
+   depends on SPI_MASTER
+   select AD_SIGMA_DELTA
+   help
+ Say yes here to build support for Analog Devices AD7124-4 and AD7124-8
+ SPI analog to digital converters (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7124.
+
 config AD7266
tristate "Analog Devices AD7265/AD7266 ADC driver"
depends on SPI_MASTER
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index a6e6a0b..76168b2 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -5,6 +5,7 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
+obj-$(CONFIG_AD7124) += ad7124.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
new file mode 100644
index 000..64d2aa7
--- /dev/null
+++ b/drivers/iio/adc/ad7124.c
@@ -0,0 +1,676 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7124 SPI ADC driver
+ *
+ * Copyright 2018 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* AD7124 registers */
+#define AD7124_COMMS   0x00
+#define AD7124_STATUS  0x00
+#define AD7124_ADC_CONTROL 0x01
+#define AD7124_DATA0x02
+#define AD7124_IO_CONTROL_10x03
+#define AD7124_IO_CONTROL_20x04
+#define AD7124_ID  0x05
+#define AD7124_ERROR   0x06
+#define AD7124_ERROR_EN0x07
+#define AD7124_MCLK_COUNT  0x08
+#define AD7124_CHANNEL(x)  (0x09 + (x))
+#define AD7124_CONFIG(x)   (0x19 + (x))
+#define AD7124_FILTER(x)   (0x21 + (x))
+#define AD7124_OFFSET(x)   (0x29 + (x))
+#define AD7124_GAIN(x) (0x31 + (x))
+
+/* AD7124_STATU

[PATCH v4 3/4] iio: adc: Add ad7124 support

2018-11-09 Thread Stefan Popa
The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta ADCs
with 24-bit precision and reference.

Three power modes are available which in turn affect the output data rate:
 * Full power: 9.38 SPS to 19,200 SPS
 * Mid power: 2.34 SPS to 4800 SPS
 * Low power: 1.17 SPS to 2400 SPS

The ad7124-4 can be configured to have four differential inputs, while
ad7124-8 can have 8. Moreover, ad7124 also supports per channel
configuration. Each configuration consists of gain, reference source,
output data rate and bipolar/unipolar configuration.

Datasheets:
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-4.pdf
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Nothing changed.
Changes in v3:
- Removed channel, address, scan_index and shift fields from
  ad7124_channel_template.
- Added a sanity check for val2 in ad7124_write_raw().
- Used the "reg" property to get the channel address and 
"adi,diff-channels"
  for the differential pins. The "adi,channel-number" property was 
removed.
- When calling regulator_get_optional, the probe is given up in case of 
error,
  but continues in case of -ENODEV.
- clk_disable_unprepare() is called before 
ad_sd_cleanup_buffer_and_trigger
  in ad7124_remove().
Changes in v4:
- Added the .shift and .endianness fields as part of the 
ad7124_channel_template.
- Made the gain configurable from the user space.
- Removed the odr_hz and gain properties from the DT.
- Used the bipolar and diff-channels properties defined in the new 
adc.txt doc.
- Misc style fixes.

 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  11 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7124.c | 676 +++
 4 files changed, 695 insertions(+)
 create mode 100644 drivers/iio/adc/ad7124.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f642044..3a1bfcb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7124 DRIVER
+M: Stefan Popa 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7124.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..148a10f 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
 
+config AD7124
+   tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
+   depends on SPI_MASTER
+   select AD_SIGMA_DELTA
+   help
+ Say yes here to build support for Analog Devices AD7124-4 and AD7124-8
+ SPI analog to digital converters (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7124.
+
 config AD7266
tristate "Analog Devices AD7265/AD7266 ADC driver"
depends on SPI_MASTER
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index a6e6a0b..76168b2 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -5,6 +5,7 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
+obj-$(CONFIG_AD7124) += ad7124.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
new file mode 100644
index 000..64d2aa7
--- /dev/null
+++ b/drivers/iio/adc/ad7124.c
@@ -0,0 +1,676 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7124 SPI ADC driver
+ *
+ * Copyright 2018 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* AD7124 registers */
+#define AD7124_COMMS   0x00
+#define AD7124_STATUS  0x00
+#define AD7124_ADC_CONTROL 0x01
+#define AD7124_DATA0x02
+#define AD7124_IO_CONTROL_10x03
+#define AD7124_IO_CONTROL_20x04
+#define AD7124_ID  0x05
+#define AD7124_ERROR   0x06
+#define AD7124_ERROR_EN0x07
+#define AD7124_MCLK_COUNT  0x08
+#define AD7124_CHANNEL(x)  (0x09 + (x))
+#define AD7124_CONFIG(x)   (0x19 + (x))
+#define AD7124_FILTER(x)   (0x21 + (x))
+#define AD7124_OFFSET(x)   (0x29 + (x))
+#define AD7124_GAIN(x) (0x31 + (x))
+
+/* AD7124_STATU

  1   2   3   4   >