aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio/adc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/iio/adc')
-rw-r--r--drivers/staging/iio/adc/Kconfig34
-rw-r--r--drivers/staging/iio/adc/Makefile4
-rw-r--r--drivers/staging/iio/adc/ad7280a.c243
-rw-r--r--drivers/staging/iio/adc/ad7606.c563
-rw-r--r--drivers/staging/iio/adc/ad7606.h106
-rw-r--r--drivers/staging/iio/adc/ad7606_par.c113
-rw-r--r--drivers/staging/iio/adc/ad7606_spi.c79
-rw-r--r--drivers/staging/iio/adc/ad7816.c7
8 files changed, 161 insertions, 988 deletions
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index fc23059f1673..7a93d3a5c113 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -3,40 +3,6 @@
#
menu "Analog to digital converters"
-config AD7606
- tristate "Analog Devices AD7606 ADC driver"
- 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
- help
- Say yes here to include parallel interface support on the AD7606
- ADC driver.
-
- 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
- depends on SPI
- help
- Say yes here to include parallel interface support on the AD7606
- ADC driver.
-
- To compile this driver as a module, choose M here: the
- module will be called ad7606_spi.
-
config AD7780
tristate "Analog Devices AD7780 and similar ADCs driver"
depends on SPI
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index ebe83c1ad362..7a421088ff82 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -3,10 +3,6 @@
# Makefile for industrial I/O ADC drivers
#
-obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
-obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
-obj-$(CONFIG_AD7606) += ad7606.o
-
obj-$(CONFIG_AD7780) += ad7780.o
obj-$(CONFIG_AD7816) += ad7816.o
obj-$(CONFIG_AD7192) += ad7192.o
diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index 14f6a3ced060..d9df12665176 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -97,6 +97,10 @@
#define AD7280A_NUM_CH (AD7280A_AUX_ADC_6 - \
AD7280A_CELL_VOLTAGE_1 + 1)
+#define AD7280A_CALC_VOLTAGE_CHAN_NUM(d, c) ((d * AD7280A_CELLS_PER_DEV) + c)
+#define AD7280A_CALC_TEMP_CHAN_NUM(d, c) ((d * AD7280A_CELLS_PER_DEV) + \
+ c - AD7280A_CELLS_PER_DEV)
+
#define AD7280A_DEVADDR_MASTER 0
#define AD7280A_DEVADDR_ALL 0x1F
/* 5-bit device address is sent LSB first */
@@ -496,72 +500,171 @@ static const struct attribute_group ad7280_attrs_group = {
.attrs = ad7280_attributes,
};
+static void ad7280_voltage_channel_init(struct iio_chan_spec *chan, int i)
+{
+ chan->type = IIO_VOLTAGE;
+ chan->differential = 1;
+ chan->channel = i;
+ chan->channel2 = chan->channel + 1;
+}
+
+static void ad7280_temp_channel_init(struct iio_chan_spec *chan, int i)
+{
+ chan->type = IIO_TEMP;
+ chan->channel = i;
+}
+
+static void ad7280_common_fields_init(struct iio_chan_spec *chan, int addr,
+ int cnt)
+{
+ chan->indexed = 1;
+ chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
+ chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE);
+ chan->address = addr;
+ chan->scan_index = cnt;
+ chan->scan_type.sign = 'u';
+ chan->scan_type.realbits = 12;
+ chan->scan_type.storagebits = 32;
+}
+
+static void ad7280_total_voltage_channel_init(struct iio_chan_spec *chan,
+ int cnt, int dev)
+{
+ chan->type = IIO_VOLTAGE;
+ chan->differential = 1;
+ chan->channel = 0;
+ chan->channel2 = dev * AD7280A_CELLS_PER_DEV;
+ chan->address = AD7280A_ALL_CELLS;
+ chan->indexed = 1;
+ chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
+ chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE);
+ chan->scan_index = cnt;
+ chan->scan_type.sign = 'u';
+ chan->scan_type.realbits = 32;
+ chan->scan_type.storagebits = 32;
+}
+
+static void ad7280_timestamp_channel_init(struct iio_chan_spec *chan, int cnt)
+{
+ chan->type = IIO_TIMESTAMP;
+ chan->channel = -1;
+ chan->scan_index = cnt;
+ chan->scan_type.sign = 's';
+ chan->scan_type.realbits = 64;
+ chan->scan_type.storagebits = 64;
+}
+
+static void ad7280_init_dev_channels(struct ad7280_state *st, int dev, int *cnt)
+{
+ int addr, ch, i;
+ struct iio_chan_spec *chan;
+
+ for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_AUX_ADC_6; ch++) {
+ chan = &st->channels[*cnt];
+
+ if (ch < AD7280A_AUX_ADC_1) {
+ i = AD7280A_CALC_VOLTAGE_CHAN_NUM(dev, ch);
+ ad7280_voltage_channel_init(chan, i);
+ } else {
+ i = AD7280A_CALC_TEMP_CHAN_NUM(dev, ch);
+ ad7280_temp_channel_init(chan, i);
+ }
+
+ addr = ad7280a_devaddr(dev) << 8 | ch;
+ ad7280_common_fields_init(chan, addr, *cnt);
+
+ (*cnt)++;
+ }
+}
+
static int ad7280_channel_init(struct ad7280_state *st)
{
- int dev, ch, cnt;
+ int dev, cnt = 0;
st->channels = devm_kcalloc(&st->spi->dev, (st->slave_num + 1) * 12 + 2,
sizeof(*st->channels), GFP_KERNEL);
if (!st->channels)
return -ENOMEM;
- for (dev = 0, cnt = 0; dev <= st->slave_num; dev++)
- for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_AUX_ADC_6;
- ch++, cnt++) {
- if (ch < AD7280A_AUX_ADC_1) {
- st->channels[cnt].type = IIO_VOLTAGE;
- st->channels[cnt].differential = 1;
- st->channels[cnt].channel = (dev * 6) + ch;
- st->channels[cnt].channel2 =
- st->channels[cnt].channel + 1;
- } else {
- st->channels[cnt].type = IIO_TEMP;
- st->channels[cnt].channel = (dev * 6) + ch - 6;
- }
- st->channels[cnt].indexed = 1;
- st->channels[cnt].info_mask_separate =
- BIT(IIO_CHAN_INFO_RAW);
- st->channels[cnt].info_mask_shared_by_type =
- BIT(IIO_CHAN_INFO_SCALE);
- st->channels[cnt].address =
- ad7280a_devaddr(dev) << 8 | ch;
- st->channels[cnt].scan_index = cnt;
- st->channels[cnt].scan_type.sign = 'u';
- st->channels[cnt].scan_type.realbits = 12;
- st->channels[cnt].scan_type.storagebits = 32;
- st->channels[cnt].scan_type.shift = 0;
- }
+ for (dev = 0; dev <= st->slave_num; dev++)
+ ad7280_init_dev_channels(st, dev, &cnt);
- st->channels[cnt].type = IIO_VOLTAGE;
- st->channels[cnt].differential = 1;
- st->channels[cnt].channel = 0;
- st->channels[cnt].channel2 = dev * 6;
- st->channels[cnt].address = AD7280A_ALL_CELLS;
- st->channels[cnt].indexed = 1;
- st->channels[cnt].info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
- st->channels[cnt].info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE);
- st->channels[cnt].scan_index = cnt;
- st->channels[cnt].scan_type.sign = 'u';
- st->channels[cnt].scan_type.realbits = 32;
- st->channels[cnt].scan_type.storagebits = 32;
- st->channels[cnt].scan_type.shift = 0;
+ ad7280_total_voltage_channel_init(&st->channels[cnt], cnt, dev);
cnt++;
- st->channels[cnt].type = IIO_TIMESTAMP;
- st->channels[cnt].channel = -1;
- st->channels[cnt].scan_index = cnt;
- st->channels[cnt].scan_type.sign = 's';
- st->channels[cnt].scan_type.realbits = 64;
- st->channels[cnt].scan_type.storagebits = 64;
- st->channels[cnt].scan_type.shift = 0;
+ ad7280_timestamp_channel_init(&st->channels[cnt], cnt);
return cnt + 1;
}
-static int ad7280_attr_init(struct ad7280_state *st)
+static int ad7280_balance_switch_attr_init(struct iio_dev_attr *attr,
+ struct device *dev, int addr, int i)
{
- int dev, ch, cnt;
- unsigned int index;
+ attr->address = addr;
+ attr->dev_attr.attr.mode = 0644;
+ attr->dev_attr.show = ad7280_show_balance_sw;
+ attr->dev_attr.store = ad7280_store_balance_sw;
+ attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
+ "in%d-in%d_balance_switch_en",
+ i, i + 1);
+ if (!attr->dev_attr.attr.name)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static int ad7280_balance_timer_attr_init(struct iio_dev_attr *attr,
+ struct device *dev, int addr, int i)
+{
+ attr->address = addr;
+ attr->dev_attr.attr.mode = 0644;
+ attr->dev_attr.show = ad7280_show_balance_timer;
+ attr->dev_attr.store = ad7280_store_balance_timer;
+ attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL,
+ "in%d-in%d_balance_timer",
+ i, i + 1);
+ if (!attr->dev_attr.attr.name)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static int ad7280_init_dev_attrs(struct ad7280_state *st, int dev, int *cnt)
+{
+ int addr, ch, i, ret;
struct iio_dev_attr *iio_attr;
+ struct device *sdev = &st->spi->dev;
+
+ for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_CELL_VOLTAGE_6; ch++) {
+ iio_attr = &st->iio_attr[*cnt];
+ addr = ad7280a_devaddr(dev) << 8 | ch;
+ i = dev * AD7280A_CELLS_PER_DEV + ch;
+
+ ret = ad7280_balance_switch_attr_init(iio_attr, sdev, addr, i);
+ if (ret < 0)
+ return ret;
+
+ ad7280_attributes[*cnt] = &iio_attr->dev_attr.attr;
+
+ (*cnt)++;
+ iio_attr = &st->iio_attr[*cnt];
+ addr = ad7280a_devaddr(dev) << 8 | (AD7280A_CB1_TIMER + ch);
+
+ ret = ad7280_balance_timer_attr_init(iio_attr, sdev, addr, i);
+ if (ret < 0)
+ return ret;
+
+ ad7280_attributes[*cnt] = &iio_attr->dev_attr.attr;
+ (*cnt)++;
+ }
+
+ ad7280_attributes[*cnt] = NULL;
+
+ return 0;
+}
+
+static int ad7280_attr_init(struct ad7280_state *st)
+{
+ int dev, cnt = 0, ret;
st->iio_attr = devm_kcalloc(&st->spi->dev, 2, sizeof(*st->iio_attr) *
(st->slave_num + 1) * AD7280A_CELLS_PER_DEV,
@@ -569,41 +672,11 @@ static int ad7280_attr_init(struct ad7280_state *st)
if (!st->iio_attr)
return -ENOMEM;
- for (dev = 0, cnt = 0; dev <= st->slave_num; dev++)
- for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_CELL_VOLTAGE_6;
- ch++, cnt++) {
- iio_attr = &st->iio_attr[cnt];
- index = dev * AD7280A_CELLS_PER_DEV + ch;
- iio_attr->address = ad7280a_devaddr(dev) << 8 | ch;
- iio_attr->dev_attr.attr.mode = 0644;
- iio_attr->dev_attr.show = ad7280_show_balance_sw;
- iio_attr->dev_attr.store = ad7280_store_balance_sw;
- iio_attr->dev_attr.attr.name =
- devm_kasprintf(&st->spi->dev, GFP_KERNEL,
- "in%d-in%d_balance_switch_en",
- index, index + 1);
- if (!iio_attr->dev_attr.attr.name)
- return -ENOMEM;
-
- ad7280_attributes[cnt] = &iio_attr->dev_attr.attr;
- cnt++;
- iio_attr = &st->iio_attr[cnt];
- iio_attr->address = ad7280a_devaddr(dev) << 8 |
- (AD7280A_CB1_TIMER + ch);
- iio_attr->dev_attr.attr.mode = 0644;
- iio_attr->dev_attr.show = ad7280_show_balance_timer;
- iio_attr->dev_attr.store = ad7280_store_balance_timer;
- iio_attr->dev_attr.attr.name =
- devm_kasprintf(&st->spi->dev, GFP_KERNEL,
- "in%d-in%d_balance_timer",
- index, index + 1);
- if (!iio_attr->dev_attr.attr.name)
- return -ENOMEM;
-
- ad7280_attributes[cnt] = &iio_attr->dev_attr.attr;
- }
-
- ad7280_attributes[cnt] = NULL;
+ for (dev = 0; dev <= st->slave_num; dev++) {
+ ret = ad7280_init_dev_attrs(st, dev, &cnt);
+ if (ret < 0)
+ return ret;
+ }
return 0;
}
diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
deleted file mode 100644
index 7308fa8fbb4c..000000000000
--- a/drivers/staging/iio/adc/ad7606.c
+++ /dev/null
@@ -1,563 +0,0 @@
-/*
- * AD7606 SPI ADC driver
- *
- * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
- */
-
-#include <linux/interrupt.h>
-#include <linux/device.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/sysfs.h>
-#include <linux/regulator/consumer.h>
-#include <linux/err.h>
-#include <linux/gpio/consumer.h>
-#include <linux/delay.h>
-#include <linux/sched.h>
-#include <linux/module.h>
-
-#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
-#include <linux/iio/buffer.h>
-#include <linux/iio/trigger_consumer.h>
-#include <linux/iio/triggered_buffer.h>
-
-#include "ad7606.h"
-
-/*
- * Scales are computed as 5000/32768 and 10000/32768 respectively,
- * so that when applied to the raw values they provide mV values
- */
-static const unsigned int scale_avail[2][2] = {
- {0, 152588}, {0, 305176}
-};
-
-static int ad7606_reset(struct ad7606_state *st)
-{
- if (st->gpio_reset) {
- gpiod_set_value(st->gpio_reset, 1);
- ndelay(100); /* t_reset >= 100ns */
- gpiod_set_value(st->gpio_reset, 0);
- return 0;
- }
-
- return -ENODEV;
-}
-
-static int ad7606_read_samples(struct ad7606_state *st)
-{
- unsigned int num = st->chip_info->num_channels;
- u16 *data = st->data;
- int ret;
-
- /*
- * The frstdata signal is set to high while and after reading the sample
- * of the first channel and low for all other channels. This can be used
- * to check that the incoming data is correctly aligned. During normal
- * operation the data should never become unaligned, but some glitch or
- * electrostatic discharge might cause an extra read or clock cycle.
- * Monitoring the frstdata signal allows to recover from such failure
- * situations.
- */
-
- if (st->gpio_frstdata) {
- ret = st->bops->read_block(st->dev, 1, data);
- if (ret)
- return ret;
-
- if (!gpiod_get_value(st->gpio_frstdata)) {
- ad7606_reset(st);
- return -EIO;
- }
-
- data++;
- num--;
- }
-
- return st->bops->read_block(st->dev, num, data);
-}
-
-static irqreturn_t ad7606_trigger_handler(int irq, void *p)
-{
- struct iio_poll_func *pf = p;
- struct 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);
- int ret;
-
- 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);
-}
-
-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)
- goto error_ret;
-
- ret = ad7606_read_samples(st);
- if (ret == 0)
- ret = st->data[ch];
-
-error_ret:
- gpiod_set_value(st->gpio_convst, 0);
-
- return ret;
-}
-
-static int ad7606_read_raw(struct iio_dev *indio_dev,
- struct iio_chan_spec const *chan,
- int *val,
- int *val2,
- long m)
-{
- int ret;
- struct ad7606_state *st = iio_priv(indio_dev);
-
- switch (m) {
- case IIO_CHAN_INFO_RAW:
- ret = iio_device_claim_direct_mode(indio_dev);
- if (ret)
- return ret;
-
- ret = ad7606_scan_direct(indio_dev, chan->address);
- iio_device_release_direct_mode(indio_dev);
-
- if (ret < 0)
- return ret;
- *val = (short)ret;
- return IIO_VAL_INT;
- case IIO_CHAN_INFO_SCALE:
- *val = scale_avail[st->range][0];
- *val2 = scale_avail[st->range][1];
- return IIO_VAL_INT_PLUS_MICRO;
- case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
- *val = st->oversampling;
- return IIO_VAL_INT;
- }
- return -EINVAL;
-}
-
-static ssize_t in_voltage_scale_available_show(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- int i, len = 0;
-
- for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
- len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06u ",
- scale_avail[i][0], scale_avail[i][1]);
-
- buf[len - 1] = '\n';
-
- return len;
-}
-
-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,
- int val2,
- long mask)
-{
- struct ad7606_state *st = iio_priv(indio_dev);
- DECLARE_BITMAP(values, 3);
- int ret, i;
-
- switch (mask) {
- case IIO_CHAN_INFO_SCALE:
- ret = -EINVAL;
- mutex_lock(&st->lock);
- for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
- if (val2 == scale_avail[i][1]) {
- gpiod_set_value(st->gpio_range, i);
- st->range = i;
-
- ret = 0;
- break;
- }
- mutex_unlock(&st->lock);
-
- return ret;
- case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
- if (val2)
- return -EINVAL;
- ret = ad7606_oversampling_get_index(val);
- if (ret < 0)
- return ret;
-
- values[0] = ret;
-
- mutex_lock(&st->lock);
- gpiod_set_array_value(3, st->gpio_os->desc, st->gpio_os->info,
- values);
- st->oversampling = val;
- mutex_unlock(&st->lock);
-
- return 0;
- default:
- return -EINVAL;
- }
-}
-
-static IIO_CONST_ATTR(oversampling_ratio_available, "1 2 4 8 16 32 64");
-
-static struct attribute *ad7606_attributes_os_and_range[] = {
- &iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
- &iio_const_attr_oversampling_ratio_available.dev_attr.attr,
- NULL,
-};
-
-static const struct attribute_group ad7606_attribute_group_os_and_range = {
- .attrs = ad7606_attributes_os_and_range,
-};
-
-static struct attribute *ad7606_attributes_os[] = {
- &iio_const_attr_oversampling_ratio_available.dev_attr.attr,
- NULL,
-};
-
-static const struct attribute_group ad7606_attribute_group_os = {
- .attrs = ad7606_attributes_os,
-};
-
-static struct attribute *ad7606_attributes_range[] = {
- &iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
- NULL,
-};
-
-static const struct attribute_group ad7606_attribute_group_range = {
- .attrs = ad7606_attributes_range,
-};
-
-#define AD760X_CHANNEL(num, mask) \
- { \
- .type = IIO_VOLTAGE, \
- .indexed = 1, \
- .channel = num, \
- .address = num, \
- .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
- .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
- .info_mask_shared_by_all = mask, \
- .scan_index = num, \
- .scan_type = { \
- .sign = 's', \
- .realbits = 16, \
- .storagebits = 16, \
- .endianness = IIO_CPU, \
- }, \
- }
-
-#define AD7605_CHANNEL(num) \
- AD760X_CHANNEL(num, 0)
-
-#define AD7606_CHANNEL(num) \
- AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
-
-static const struct iio_chan_spec ad7605_channels[] = {
- IIO_CHAN_SOFT_TIMESTAMP(4),
- AD7605_CHANNEL(0),
- AD7605_CHANNEL(1),
- AD7605_CHANNEL(2),
- AD7605_CHANNEL(3),
-};
-
-static const struct iio_chan_spec ad7606_channels[] = {
- IIO_CHAN_SOFT_TIMESTAMP(8),
- AD7606_CHANNEL(0),
- AD7606_CHANNEL(1),
- AD7606_CHANNEL(2),
- AD7606_CHANNEL(3),
- AD7606_CHANNEL(4),
- AD7606_CHANNEL(5),
- AD7606_CHANNEL(6),
- AD7606_CHANNEL(7),
-};
-
-static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
- /*
- * More devices added in future
- */
- [ID_AD7605_4] = {
- .channels = ad7605_channels,
- .num_channels = 5,
- },
- [ID_AD7606_8] = {
- .channels = ad7606_channels,
- .num_channels = 9,
- .has_oversampling = true,
- },
- [ID_AD7606_6] = {
- .channels = ad7606_channels,
- .num_channels = 7,
- .has_oversampling = true,
- },
- [ID_AD7606_4] = {
- .channels = ad7606_channels,
- .num_channels = 5,
- .has_oversampling = true,
- },
-};
-
-static int ad7606_request_gpios(struct ad7606_state *st)
-{
- struct device *dev = st->dev;
-
- st->gpio_convst = devm_gpiod_get(dev, "conversion-start",
- GPIOD_OUT_LOW);
- if (IS_ERR(st->gpio_convst))
- return PTR_ERR(st->gpio_convst);
-
- st->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
- if (IS_ERR(st->gpio_reset))
- return PTR_ERR(st->gpio_reset);
-
- st->gpio_range = devm_gpiod_get_optional(dev, "range", GPIOD_OUT_LOW);
- if (IS_ERR(st->gpio_range))
- return PTR_ERR(st->gpio_range);
-
- st->gpio_standby = devm_gpiod_get_optional(dev, "standby",
- GPIOD_OUT_HIGH);
- if (IS_ERR(st->gpio_standby))
- return PTR_ERR(st->gpio_standby);
-
- st->gpio_frstdata = devm_gpiod_get_optional(dev, "first-data",
- GPIOD_IN);
- if (IS_ERR(st->gpio_frstdata))
- return PTR_ERR(st->gpio_frstdata);
-
- if (!st->chip_info->has_oversampling)
- return 0;
-
- st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio",
- GPIOD_OUT_LOW);
- return PTR_ERR_OR_ZERO(st->gpio_os);
-}
-
-/**
- * Interrupt handler
- */
-static irqreturn_t ad7606_interrupt(int irq, void *dev_id)
-{
- struct iio_dev *indio_dev = dev_id;
- struct ad7606_state *st = iio_priv(indio_dev);
-
- if (iio_buffer_enabled(indio_dev)) {
- schedule_work(&st->poll_work);
- } else {
- st->done = true;
- wake_up_interruptible(&st->wq_data_avail);
- }
-
- return IRQ_HANDLED;
-};
-
-static const struct iio_info ad7606_info_no_os_or_range = {
- .read_raw = &ad7606_read_raw,
-};
-
-static const struct iio_info ad7606_info_os_and_range = {
- .read_raw = &ad7606_read_raw,
- .write_raw = &ad7606_write_raw,
- .attrs = &ad7606_attribute_group_os_and_range,
-};
-
-static const struct iio_info ad7606_info_os = {
- .read_raw = &ad7606_read_raw,
- .write_raw = &ad7606_write_raw,
- .attrs = &ad7606_attribute_group_os,
-};
-
-static const struct iio_info ad7606_info_range = {
- .read_raw = &ad7606_read_raw,
- .write_raw = &ad7606_write_raw,
- .attrs = &ad7606_attribute_group_range,
-};
-
-int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
- const char *name, unsigned int id,
- const struct ad7606_bus_ops *bops)
-{
- struct ad7606_state *st;
- int ret;
- struct iio_dev *indio_dev;
-
- indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
- if (!indio_dev)
- return -ENOMEM;
-
- st = iio_priv(indio_dev);
-
- st->dev = dev;
- mutex_init(&st->lock);
- st->bops = bops;
- st->base_address = base_address;
- /* tied to logic low, analog input range is +/- 5V */
- st->range = 0;
- st->oversampling = 1;
- INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring);
-
- st->reg = devm_regulator_get(dev, "avcc");
- if (IS_ERR(st->reg))
- return PTR_ERR(st->reg);
-
- ret = regulator_enable(st->reg);
- if (ret) {
- dev_err(dev, "Failed to enable specified AVcc supply\n");
- return ret;
- }
-
- st->chip_info = &ad7606_chip_info_tbl[id];
-
- ret = ad7606_request_gpios(st);
- if (ret)
- goto error_disable_reg;
-
- indio_dev->dev.parent = dev;
- if (st->gpio_os) {
- if (st->gpio_range)
- indio_dev->info = &ad7606_info_os_and_range;
- else
- indio_dev->info = &ad7606_info_os;
- } else {
- if (st->gpio_range)
- indio_dev->info = &ad7606_info_range;
- else
- indio_dev->info = &ad7606_info_no_os_or_range;
- }
- indio_dev->modes = INDIO_DIRECT_MODE;
- indio_dev->name = name;
- indio_dev->channels = st->chip_info->channels;
- indio_dev->num_channels = st->chip_info->num_channels;
-
- init_waitqueue_head(&st->wq_data_avail);
-
- ret = ad7606_reset(st);
- if (ret)
- dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
-
- ret = request_irq(irq, ad7606_interrupt, IRQF_TRIGGER_FALLING, name,
- indio_dev);
- if (ret)
- goto error_disable_reg;
-
- ret = iio_triggered_buffer_setup(indio_dev, &ad7606_trigger_handler,
- NULL, NULL);
- if (ret)
- goto error_free_irq;
-
- ret = iio_device_register(indio_dev);
- 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);
-
-error_disable_reg:
- regulator_disable(st->reg);
- return ret;
-}
-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)
-{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ad7606_state *st = iio_priv(indio_dev);
-
- if (st->gpio_standby) {
- gpiod_set_value(st->gpio_range, 1);
- gpiod_set_value(st->gpio_standby, 0);
- }
-
- return 0;
-}
-
-static int ad7606_resume(struct device *dev)
-{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ad7606_state *st = iio_priv(indio_dev);
-
- if (st->gpio_standby) {
- gpiod_set_value(st->gpio_range, st->range);
- gpiod_set_value(st->gpio_standby, 1);
- ad7606_reset(st);
- }
-
- return 0;
-}
-
-SIMPLE_DEV_PM_OPS(ad7606_pm_ops, ad7606_suspend, ad7606_resume);
-EXPORT_SYMBOL_GPL(ad7606_pm_ops);
-
-#endif
-
-MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
-MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
deleted file mode 100644
index 86188054b60b..000000000000
--- a/drivers/staging/iio/adc/ad7606.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * AD7606 ADC driver
- *
- * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
- */
-
-#ifndef IIO_ADC_AD7606_H_
-#define IIO_ADC_AD7606_H_
-
-/**
- * struct ad7606_chip_info - chip specific information
- * @channels: channel specification
- * @num_channels: number of channels
- * @has_oversampling: whether the device has oversampling support
- */
-
-struct ad7606_chip_info {
- const struct iio_chan_spec *channels;
- unsigned int num_channels;
- bool has_oversampling;
-};
-
-/**
- * struct ad7606_state - driver instance specific data
- * @dev pointer to kernel device
- * @chip_info entry in the table of chips that describes this device
- * @reg regulator info for the the power supply of the device
- * @poll_work work struct for continuously reading data from the device
- * into an IIO triggered buffer
- * @wq_data_avail wait queue struct for buffer mode
- * @bops bus operations (SPI or parallel)
- * @range voltage range selection, selects which scale to apply
- * @oversampling oversampling selection
- * @done marks whether reading data is done
- * @base_address address from where to read data in parallel operation
- * @lock protect sensor state from concurrent accesses to GPIOs
- * @gpio_convst GPIO descriptor for conversion start signal (CONVST)
- * @gpio_reset GPIO descriptor for device hard-reset
- * @gpio_range GPIO descriptor for range selection
- * @gpio_standby GPIO descriptor for stand-by signal (STBY),
- * controls power-down mode of device
- * @gpio_frstdata GPIO descriptor for reading from device when data
- * is being read on the first channel
- * @gpio_os GPIO descriptors to control oversampling on the device
- * @data buffer for reading data from the device
- */
-
-struct ad7606_state {
- struct device *dev;
- const struct ad7606_chip_info *chip_info;
- struct regulator *reg;
- struct work_struct poll_work;
- wait_queue_head_t wq_data_avail;
- const struct ad7606_bus_ops *bops;
- unsigned int range;
- unsigned int oversampling;
- bool done;
- void __iomem *base_address;
-
- struct mutex lock; /* protect sensor state */
- struct gpio_desc *gpio_convst;
- struct gpio_desc *gpio_reset;
- struct gpio_desc *gpio_range;
- struct gpio_desc *gpio_standby;
- struct gpio_desc *gpio_frstdata;
- struct gpio_descs *gpio_os;
-
- /*
- * DMA (thus cache coherency maintenance) requires the
- * transfer buffers to live in their own cache lines.
- * 8 * 16-bit samples + 64-bit timestamp
- */
- unsigned short data[12] ____cacheline_aligned;
-};
-
-/**
- * struct ad7606_bus_ops - driver bus operations
- * @read_block function pointer for reading blocks of data
- */
-struct ad7606_bus_ops {
- /* more methods added in future? */
- int (*read_block)(struct device *dev, int num, void *data);
-};
-
-int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
- const char *name, unsigned int id,
- const struct ad7606_bus_ops *bops);
-int ad7606_remove(struct device *dev, int irq);
-
-enum ad7606_supported_device_ids {
- ID_AD7605_4,
- ID_AD7606_8,
- ID_AD7606_6,
- ID_AD7606_4
-};
-
-#ifdef CONFIG_PM_SLEEP
-extern const struct dev_pm_ops ad7606_pm_ops;
-#define AD7606_PM_OPS (&ad7606_pm_ops)
-#else
-#define AD7606_PM_OPS NULL
-#endif
-
-#endif /* IIO_ADC_AD7606_H_ */
diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
deleted file mode 100644
index 8bd86e727b02..000000000000
--- a/drivers/staging/iio/adc/ad7606_par.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * AD7606 Parallel Interface ADC driver
- *
- * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/types.h>
-#include <linux/err.h>
-#include <linux/io.h>
-
-#include <linux/iio/iio.h>
-#include "ad7606.h"
-
-static int ad7606_par16_read_block(struct device *dev,
- int count, void *buf)
-{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ad7606_state *st = iio_priv(indio_dev);
-
- insw((unsigned long)st->base_address, buf, count);
-
- return 0;
-}
-
-static const struct ad7606_bus_ops ad7606_par16_bops = {
- .read_block = ad7606_par16_read_block,
-};
-
-static int ad7606_par8_read_block(struct device *dev,
- int count, void *buf)
-{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ad7606_state *st = iio_priv(indio_dev);
-
- insb((unsigned long)st->base_address, buf, count * 2);
-
- return 0;
-}
-
-static const struct ad7606_bus_ops ad7606_par8_bops = {
- .read_block = ad7606_par8_read_block,
-};
-
-static int ad7606_par_probe(struct platform_device *pdev)
-{
- const struct platform_device_id *id = platform_get_device_id(pdev);
- struct resource *res;
- void __iomem *addr;
- resource_size_t remap_size;
- int irq;
-
- irq = platform_get_irq(pdev, 0);
- if (irq < 0) {
- dev_err(&pdev->dev, "no irq: %d\n", irq);
- return irq;
- }
-
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- addr = devm_ioremap_resource(&pdev->dev, res);
- if (IS_ERR(addr))
- return PTR_ERR(addr);
-
- remap_size = resource_size(res);
-
- return ad7606_probe(&pdev->dev, irq, addr,
- id->name, id->driver_data,
- remap_size > 1 ? &ad7606_par16_bops :
- &ad7606_par8_bops);
-}
-
-static int ad7606_par_remove(struct platform_device *pdev)
-{
- return ad7606_remove(&pdev->dev, platform_get_irq(pdev, 0));
-}
-
-static const struct platform_device_id ad7606_driver_ids[] = {
- {
- .name = "ad7605-4",
- .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,
- },
- { }
-};
-
-MODULE_DEVICE_TABLE(platform, ad7606_driver_ids);
-
-static struct platform_driver ad7606_driver = {
- .probe = ad7606_par_probe,
- .remove = ad7606_par_remove,
- .id_table = ad7606_driver_ids,
- .driver = {
- .name = "ad7606",
- .pm = AD7606_PM_OPS,
- },
-};
-
-module_platform_driver(ad7606_driver);
-
-MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
-MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
deleted file mode 100644
index b76ca5a8c059..000000000000
--- a/drivers/staging/iio/adc/ad7606_spi.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * AD7606 SPI ADC driver
- *
- * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
- */
-
-#include <linux/module.h>
-#include <linux/spi/spi.h>
-#include <linux/types.h>
-#include <linux/err.h>
-
-#include <linux/iio/iio.h>
-#include "ad7606.h"
-
-#define MAX_SPI_FREQ_HZ 23500000 /* VDRIVE above 4.75 V */
-
-static int ad7606_spi_read_block(struct device *dev,
- int count, void *buf)
-{
- struct spi_device *spi = to_spi_device(dev);
- int i, ret;
- unsigned short *data = buf;
- __be16 *bdata = buf;
-
- ret = spi_read(spi, buf, count * 2);
- if (ret < 0) {
- dev_err(&spi->dev, "SPI read error\n");
- return ret;
- }
-
- for (i = 0; i < count; i++)
- data[i] = be16_to_cpu(bdata[i]);
-
- return 0;
-}
-
-static const struct ad7606_bus_ops ad7606_spi_bops = {
- .read_block = ad7606_spi_read_block,
-};
-
-static int ad7606_spi_probe(struct spi_device *spi)
-{
- const struct spi_device_id *id = spi_get_device_id(spi);
-
- return ad7606_probe(&spi->dev, spi->irq, NULL,
- id->name, id->driver_data,
- &ad7606_spi_bops);
-}
-
-static int ad7606_spi_remove(struct spi_device *spi)
-{
- return ad7606_remove(&spi->dev, spi->irq);
-}
-
-static const struct spi_device_id ad7606_id[] = {
- {"ad7605-4", ID_AD7605_4},
- {"ad7606-8", ID_AD7606_8},
- {"ad7606-6", ID_AD7606_6},
- {"ad7606-4", ID_AD7606_4},
- {}
-};
-MODULE_DEVICE_TABLE(spi, ad7606_id);
-
-static struct spi_driver ad7606_driver = {
- .driver = {
- .name = "ad7606",
- .pm = AD7606_PM_OPS,
- },
- .probe = ad7606_spi_probe,
- .remove = ad7606_spi_remove,
- .id_table = ad7606_id,
-};
-module_spi_driver(ad7606_driver);
-
-MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
-MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
-MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index 5209651a1b25..ee50e7296795 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -65,7 +65,7 @@ enum ad7816_type {
static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)
{
struct spi_device *spi_dev = chip->spi_dev;
- int ret = 0;
+ int ret;
__be16 buf;
gpiod_set_value(chip->rdwr_pin, 1);
@@ -106,7 +106,7 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)
static int ad7816_spi_write(struct ad7816_chip_info *chip, u8 data)
{
struct spi_device *spi_dev = chip->spi_dev;
- int ret = 0;
+ int ret;
gpiod_set_value(chip->rdwr_pin, 1);
gpiod_set_value(chip->rdwr_pin, 0);
@@ -354,8 +354,7 @@ static int ad7816_probe(struct spi_device *spi_dev)
{
struct ad7816_chip_info *chip;
struct iio_dev *indio_dev;
- int ret = 0;
- int i;
+ int i, ret;
indio_dev = devm_iio_device_alloc(&spi_dev->dev, sizeof(*chip));
if (!indio_dev)