diff options
Diffstat (limited to 'drivers/staging/iio/adc/ad799x_core.c')
-rw-r--r-- | drivers/staging/iio/adc/ad799x_core.c | 744 |
1 files changed, 448 insertions, 296 deletions
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c index 92cfe2e..ee6cd79 100644 --- a/drivers/staging/iio/adc/ad799x_core.c +++ b/drivers/staging/iio/adc/ad799x_core.c @@ -31,12 +31,12 @@ #include <linux/slab.h> #include <linux/types.h> #include <linux/err.h> +#include <linux/module.h> #include "../iio.h" #include "../sysfs.h" +#include "../buffer_generic.h" -#include "../ring_generic.h" -#include "adc.h" #include "ad799x.h" /* @@ -136,49 +136,56 @@ static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch) return rxbuf; } -static int ad799x_read_raw(struct iio_dev *dev_info, +static int ad799x_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long m) { int ret; - struct ad799x_state *st = iio_priv(dev_info); + struct ad799x_state *st = iio_priv(indio_dev); unsigned int scale_uv; switch (m) { case 0: - mutex_lock(&dev_info->mlock); - if (iio_ring_enabled(dev_info)) - ret = ad799x_single_channel_from_ring(st, - 1 << chan->address); + mutex_lock(&indio_dev->mlock); + if (iio_buffer_enabled(indio_dev)) + ret = ad799x_single_channel_from_ring(indio_dev, + chan->scan_index); else - ret = ad799x_scan_direct(st, chan->address); - mutex_unlock(&dev_info->mlock); + ret = ad799x_scan_direct(st, chan->scan_index); + mutex_unlock(&indio_dev->mlock); if (ret < 0) return ret; - *val = (ret >> st->chip_info->channel[0].scan_type.shift) & - RES_MASK(st->chip_info->channel[0].scan_type.realbits); + *val = (ret >> chan->scan_type.shift) & + RES_MASK(chan->scan_type.realbits); return IIO_VAL_INT; case (1 << IIO_CHAN_INFO_SCALE_SHARED): - scale_uv = (st->int_vref_mv * 1000) - >> st->chip_info->channel[0].scan_type.realbits; + scale_uv = (st->int_vref_mv * 1000) >> chan->scan_type.realbits; *val = scale_uv / 1000; *val2 = (scale_uv % 1000) * 1000; return IIO_VAL_INT_PLUS_MICRO; } return -EINVAL; } - +static const unsigned int ad7998_frequencies[] = { + [AD7998_CYC_DIS] = 0, + [AD7998_CYC_TCONF_32] = 15625, + [AD7998_CYC_TCONF_64] = 7812, + [AD7998_CYC_TCONF_128] = 3906, + [AD7998_CYC_TCONF_512] = 976, + [AD7998_CYC_TCONF_1024] = 488, + [AD7998_CYC_TCONF_2048] = 244, +}; static ssize_t ad799x_read_frequency(struct device *dev, struct device_attribute *attr, char *buf) { - struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad799x_state *st = iio_priv(dev_info); + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct ad799x_state *st = iio_priv(indio_dev); - int ret, len = 0; + int ret; u8 val; ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &val); if (ret) @@ -186,33 +193,7 @@ static ssize_t ad799x_read_frequency(struct device *dev, val &= AD7998_CYC_MASK; - switch (val) { - case AD7998_CYC_DIS: - len = sprintf(buf, "0\n"); - break; - case AD7998_CYC_TCONF_32: - len = sprintf(buf, "15625\n"); - break; - case AD7998_CYC_TCONF_64: - len = sprintf(buf, "7812\n"); - break; - case AD7998_CYC_TCONF_128: - len = sprintf(buf, "3906\n"); - break; - case AD7998_CYC_TCONF_256: - len = sprintf(buf, "1953\n"); - break; - case AD7998_CYC_TCONF_512: - len = sprintf(buf, "976\n"); - break; - case AD7998_CYC_TCONF_1024: - len = sprintf(buf, "488\n"); - break; - case AD7998_CYC_TCONF_2048: - len = sprintf(buf, "244\n"); - break; - } - return len; + return sprintf(buf, "%u\n", ad7998_frequencies[val]); } static ssize_t ad799x_write_frequency(struct device *dev, @@ -220,68 +201,101 @@ static ssize_t ad799x_write_frequency(struct device *dev, const char *buf, size_t len) { - struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad799x_state *st = iio_priv(dev_info); + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct ad799x_state *st = iio_priv(indio_dev); long val; - int ret; + int ret, i; u8 t; ret = strict_strtol(buf, 10, &val); if (ret) return ret; - mutex_lock(&dev_info->mlock); + mutex_lock(&indio_dev->mlock); ret = ad799x_i2c_read8(st, AD7998_CYCLE_TMR_REG, &t); if (ret) goto error_ret_mutex; /* Wipe the bits clean */ t &= ~AD7998_CYC_MASK; - switch (val) { - case 15625: - t |= AD7998_CYC_TCONF_32; - break; - case 7812: - t |= AD7998_CYC_TCONF_64; - break; - case 3906: - t |= AD7998_CYC_TCONF_128; - break; - case 1953: - t |= AD7998_CYC_TCONF_256; - break; - case 976: - t |= AD7998_CYC_TCONF_512; - break; - case 488: - t |= AD7998_CYC_TCONF_1024; - break; - case 244: - t |= AD7998_CYC_TCONF_2048; - break; - case 0: - t |= AD7998_CYC_DIS; - break; - default: + for (i = 0; i < ARRAY_SIZE(ad7998_frequencies); i++) + if (val == ad7998_frequencies[i]) + break; + if (i == ARRAY_SIZE(ad7998_frequencies)) { ret = -EINVAL; goto error_ret_mutex; } - + t |= i; ret = ad799x_i2c_write8(st, AD7998_CYCLE_TMR_REG, t); error_ret_mutex: - mutex_unlock(&dev_info->mlock); + mutex_unlock(&indio_dev->mlock); return ret ? ret : len; } +static int ad799x_read_event_config(struct iio_dev *indio_dev, + u64 event_code) +{ + return 1; +} + +static const u8 ad799x_threshold_addresses[][2] = { + { AD7998_DATALOW_CH1_REG, AD7998_DATAHIGH_CH1_REG }, + { AD7998_DATALOW_CH2_REG, AD7998_DATAHIGH_CH2_REG }, + { AD7998_DATALOW_CH3_REG, AD7998_DATAHIGH_CH3_REG }, + { AD7998_DATALOW_CH4_REG, AD7998_DATAHIGH_CH4_REG }, +}; + +static int ad799x_write_event_value(struct iio_dev *indio_dev, + u64 event_code, + int val) +{ + int ret; + struct ad799x_state *st = iio_priv(indio_dev); + int direction = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == + IIO_EV_DIR_FALLING); + int number = IIO_EVENT_CODE_EXTRACT_NUM(event_code); + + mutex_lock(&indio_dev->mlock); + ret = ad799x_i2c_write16(st, + ad799x_threshold_addresses[number][direction], + val); + mutex_unlock(&indio_dev->mlock); + + return ret; +} + +static int ad799x_read_event_value(struct iio_dev *indio_dev, + u64 event_code, + int *val) +{ + int ret; + struct ad799x_state *st = iio_priv(indio_dev); + int direction = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) == + IIO_EV_DIR_FALLING); + int number = IIO_EVENT_CODE_EXTRACT_NUM(event_code); + u16 valin; + + mutex_lock(&indio_dev->mlock); + ret = ad799x_i2c_read16(st, + ad799x_threshold_addresses[number][direction], + &valin); + mutex_unlock(&indio_dev->mlock); + if (ret < 0) + return ret; + *val = valin; + + return 0; +} + static ssize_t ad799x_read_channel_config(struct device *dev, struct device_attribute *attr, char *buf) { - struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad799x_state *st = iio_priv(dev_info); + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct ad799x_state *st = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); int ret; @@ -298,8 +312,8 @@ static ssize_t ad799x_write_channel_config(struct device *dev, const char *buf, size_t len) { - struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad799x_state *st = iio_priv(dev_info); + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct ad799x_state *st = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); long val; @@ -309,9 +323,9 @@ static ssize_t ad799x_write_channel_config(struct device *dev, if (ret) return ret; - mutex_lock(&dev_info->mlock); + mutex_lock(&indio_dev->mlock); ret = ad799x_i2c_write16(st, this_attr->address, val); - mutex_unlock(&dev_info->mlock); + mutex_unlock(&indio_dev->mlock); return ret ? ret : len; } @@ -334,83 +348,41 @@ static irqreturn_t ad799x_event_handler(int irq, void *private) for (i = 0; i < 8; i++) { if (status & (1 << i)) - iio_push_event(indio_dev, 0, + iio_push_event(indio_dev, i & 0x1 ? - IIO_EVENT_CODE_IN_HIGH_THRESH(i >> 1) : - IIO_EVENT_CODE_IN_LOW_THRESH(i >> 1), + IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, + (i >> 1), + IIO_EV_TYPE_THRESH, + IIO_EV_DIR_RISING) : + IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, + (i >> 1), + IIO_EV_TYPE_THRESH, + IIO_EV_DIR_FALLING), iio_get_time_ns()); } return IRQ_HANDLED; } -static IIO_DEVICE_ATTR(in0_thresh_low_value, - S_IRUGO | S_IWUSR, - ad799x_read_channel_config, - ad799x_write_channel_config, - AD7998_DATALOW_CH1_REG); - -static IIO_DEVICE_ATTR(in0_thresh_high_value, - S_IRUGO | S_IWUSR, - ad799x_read_channel_config, - ad799x_write_channel_config, - AD7998_DATAHIGH_CH1_REG); - -static IIO_DEVICE_ATTR(in0_thresh_both_hyst_raw, +static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad799x_read_channel_config, ad799x_write_channel_config, AD7998_HYST_CH1_REG); -static IIO_DEVICE_ATTR(in1_thresh_low_value, - S_IRUGO | S_IWUSR, - ad799x_read_channel_config, - ad799x_write_channel_config, - AD7998_DATALOW_CH2_REG); - -static IIO_DEVICE_ATTR(in1_thresh_high_value, - S_IRUGO | S_IWUSR, - ad799x_read_channel_config, - ad799x_write_channel_config, - AD7998_DATAHIGH_CH2_REG); - -static IIO_DEVICE_ATTR(in1_thresh_both_hyst_raw, +static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad799x_read_channel_config, ad799x_write_channel_config, AD7998_HYST_CH2_REG); -static IIO_DEVICE_ATTR(in2_thresh_low_value, - S_IRUGO | S_IWUSR, - ad799x_read_channel_config, - ad799x_write_channel_config, - AD7998_DATALOW_CH3_REG); - -static IIO_DEVICE_ATTR(in2_thresh_high_value, - S_IRUGO | S_IWUSR, - ad799x_read_channel_config, - ad799x_write_channel_config, - AD7998_DATAHIGH_CH3_REG); - -static IIO_DEVICE_ATTR(in2_thresh_both_hyst_raw, +static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad799x_read_channel_config, ad799x_write_channel_config, AD7998_HYST_CH3_REG); -static IIO_DEVICE_ATTR(in3_thresh_low_value, - S_IRUGO | S_IWUSR, - ad799x_read_channel_config, - ad799x_write_channel_config, - AD7998_DATALOW_CH4_REG); - -static IIO_DEVICE_ATTR(in3_thresh_high_value, - S_IRUGO | S_IWUSR, - ad799x_read_channel_config, - ad799x_write_channel_config, - AD7998_DATAHIGH_CH4_REG); - -static IIO_DEVICE_ATTR(in3_thresh_both_hyst_raw, +static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw, S_IRUGO | S_IWUSR, ad799x_read_channel_config, ad799x_write_channel_config, @@ -422,18 +394,10 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("15625 7812 3906 1953 976 488 244 0"); static struct attribute *ad7993_4_7_8_event_attributes[] = { - &iio_dev_attr_in0_thresh_low_value.dev_attr.attr, - &iio_dev_attr_in0_thresh_high_value.dev_attr.attr, - &iio_dev_attr_in0_thresh_both_hyst_raw.dev_attr.attr, - &iio_dev_attr_in1_thresh_low_value.dev_attr.attr, - &iio_dev_attr_in1_thresh_high_value.dev_attr.attr, - &iio_dev_attr_in1_thresh_both_hyst_raw.dev_attr.attr, - &iio_dev_attr_in2_thresh_low_value.dev_attr.attr, - &iio_dev_attr_in2_thresh_high_value.dev_attr.attr, - &iio_dev_attr_in2_thresh_both_hyst_raw.dev_attr.attr, - &iio_dev_attr_in3_thresh_low_value.dev_attr.attr, - &iio_dev_attr_in3_thresh_high_value.dev_attr.attr, - &iio_dev_attr_in3_thresh_both_hyst_raw.dev_attr.attr, + &iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr, + &iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr, + &iio_dev_attr_in_voltage2_thresh_both_hyst_raw.dev_attr.attr, + &iio_dev_attr_in_voltage3_thresh_both_hyst_raw.dev_attr.attr, &iio_dev_attr_sampling_frequency.dev_attr.attr, &iio_const_attr_sampling_frequency_available.dev_attr.attr, NULL, @@ -441,15 +405,12 @@ static struct attribute *ad7993_4_7_8_event_attributes[] = { static struct attribute_group ad7993_4_7_8_event_attrs_group = { .attrs = ad7993_4_7_8_event_attributes, + .name = "events", }; static struct attribute *ad7992_event_attributes[] = { - &iio_dev_attr_in0_thresh_low_value.dev_attr.attr, - &iio_dev_attr_in0_thresh_high_value.dev_attr.attr, - &iio_dev_attr_in0_thresh_both_hyst_raw.dev_attr.attr, - &iio_dev_attr_in1_thresh_low_value.dev_attr.attr, - &iio_dev_attr_in1_thresh_high_value.dev_attr.attr, - &iio_dev_attr_in1_thresh_both_hyst_raw.dev_attr.attr, + &iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr, + &iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr, &iio_dev_attr_sampling_frequency.dev_attr.attr, &iio_const_attr_sampling_frequency_available.dev_attr.attr, NULL, @@ -457,6 +418,7 @@ static struct attribute *ad7992_event_attributes[] = { static struct attribute_group ad7992_event_attrs_group = { .attrs = ad7992_event_attributes, + .name = "events", }; static const struct iio_info ad7991_info = { @@ -466,181 +428,374 @@ static const struct iio_info ad7991_info = { static const struct iio_info ad7992_info = { .read_raw = &ad799x_read_raw, - .num_interrupt_lines = 1, .event_attrs = &ad7992_event_attrs_group, + .read_event_config = &ad799x_read_event_config, + .read_event_value = &ad799x_read_event_value, + .write_event_value = &ad799x_write_event_value, .driver_module = THIS_MODULE, }; static const struct iio_info ad7993_4_7_8_info = { .read_raw = &ad799x_read_raw, - .num_interrupt_lines = 1, .event_attrs = &ad7993_4_7_8_event_attrs_group, + .read_event_config = &ad799x_read_event_config, + .read_event_value = &ad799x_read_event_value, + .write_event_value = &ad799x_write_event_value, .driver_module = THIS_MODULE, }; +#define AD799X_EV_MASK (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \ + IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)) + static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { [ad7991] = { - .channel[0] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 0, 0, IIO_ST('u', 12, 16, 0), 0), - .channel[1] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 1, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 1, 1, IIO_ST('u', 12, 16, 0), 0), - .channel[2] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 2, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 2, 2, IIO_ST('u', 12, 16, 0), 0), - .channel[3] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 3, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 3, 3, IIO_ST('u', 12, 16, 0), 0), - .channel[4] = IIO_CHAN_SOFT_TIMESTAMP(4), + .channel = { + [0] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 0, + .scan_index = 0, + .scan_type = IIO_ST('u', 12, 16, 0), + }, + [1] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 1, + .scan_index = 1, + .scan_type = IIO_ST('u', 12, 16, 0), + }, + [2] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 2, + .scan_index = 2, + .scan_type = IIO_ST('u', 12, 16, 0), + }, + [3] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 3, + .scan_index = 3, + .scan_type = IIO_ST('u', 12, 16, 0), + }, + [4] = IIO_CHAN_SOFT_TIMESTAMP(4), + }, .num_channels = 5, .int_vref_mv = 4096, .info = &ad7991_info, }, [ad7995] = { - .channel[0] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 0, 0, IIO_ST('u', 10, 16, 0), 0), - .channel[1] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 1, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 1, 1, IIO_ST('u', 10, 16, 0), 0), - .channel[2] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 2, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 2, 2, IIO_ST('u', 10, 16, 0), 0), - .channel[3] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 3, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 3, 3, IIO_ST('u', 10, 16, 0), 0), - .channel[4] = IIO_CHAN_SOFT_TIMESTAMP(4), + .channel = { + [0] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 0, + .scan_index = 0, + .scan_type = IIO_ST('u', 10, 16, 2), + }, + [1] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 1, + .scan_index = 1, + .scan_type = IIO_ST('u', 10, 16, 2), + }, + [2] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 2, + .scan_index = 2, + .scan_type = IIO_ST('u', 10, 16, 2), + }, + [3] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 3, + .scan_index = 3, + .scan_type = IIO_ST('u', 10, 16, 2), + }, + [4] = IIO_CHAN_SOFT_TIMESTAMP(4), + }, .num_channels = 5, .int_vref_mv = 1024, .info = &ad7991_info, }, [ad7999] = { - .channel[0] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 0, 0, IIO_ST('u', 10, 16, 0), 0), - .channel[1] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 1, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 1, 1, IIO_ST('u', 10, 16, 0), 0), - .channel[2] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 2, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 2, 2, IIO_ST('u', 10, 16, 0), 0), - .channel[3] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 3, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 3, 3, IIO_ST('u', 10, 16, 0), 0), - .channel[4] = IIO_CHAN_SOFT_TIMESTAMP(4), + .channel = { + [0] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 0, + .scan_index = 0, + .scan_type = IIO_ST('u', 8, 16, 4), + }, + [1] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 1, + .scan_index = 1, + .scan_type = IIO_ST('u', 8, 16, 4), + }, + [2] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 2, + .scan_index = 2, + .scan_type = IIO_ST('u', 8, 16, 4), + }, + [3] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 3, + .scan_index = 3, + .scan_type = IIO_ST('u', 8, 16, 4), + }, + [4] = IIO_CHAN_SOFT_TIMESTAMP(4), + }, .num_channels = 5, .int_vref_mv = 1024, .info = &ad7991_info, }, [ad7992] = { - .channel[0] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 0, 0, IIO_ST('u', 12, 16, 0), 0), - .channel[1] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 1, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 1, 1, IIO_ST('u', 12, 16, 0), 0), - .channel[2] = IIO_CHAN_SOFT_TIMESTAMP(2), + .channel = { + [0] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 0, + .scan_index = 0, + .scan_type = IIO_ST('u', 12, 16, 0), + .event_mask = AD799X_EV_MASK, + }, + [1] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 1, + .scan_index = 1, + .scan_type = IIO_ST('u', 12, 16, 0), + .event_mask = AD799X_EV_MASK, + }, + [2] = IIO_CHAN_SOFT_TIMESTAMP(2), + }, .num_channels = 3, .int_vref_mv = 4096, .default_config = AD7998_ALERT_EN, .info = &ad7992_info, }, [ad7993] = { - .channel[0] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 0, 0, IIO_ST('u', 10, 16, 0), 0), - .channel[1] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 1, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 1, 1, IIO_ST('u', 10, 16, 0), 0), - .channel[2] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 2, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 2, 2, IIO_ST('u', 10, 16, 0), 0), - .channel[3] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 3, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 3, 3, IIO_ST('u', 10, 16, 0), 0), - .channel[4] = IIO_CHAN_SOFT_TIMESTAMP(4), + .channel = { + [0] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 0, + .scan_index = 0, + .scan_type = IIO_ST('u', 10, 16, 2), + .event_mask = AD799X_EV_MASK, + }, + [1] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 1, + .scan_index = 1, + .scan_type = IIO_ST('u', 10, 16, 2), + .event_mask = AD799X_EV_MASK, + }, + [2] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 2, + .scan_index = 2, + .scan_type = IIO_ST('u', 10, 16, 2), + .event_mask = AD799X_EV_MASK, + }, + [3] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 3, + .scan_index = 3, + .scan_type = IIO_ST('u', 10, 16, 2), + .event_mask = AD799X_EV_MASK, + }, + [4] = IIO_CHAN_SOFT_TIMESTAMP(4), + }, .num_channels = 5, .int_vref_mv = 1024, .default_config = AD7998_ALERT_EN, .info = &ad7993_4_7_8_info, }, [ad7994] = { - .channel[0] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 0, 0, IIO_ST('u', 12, 16, 0), 0), - .channel[1] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 1, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 1, 1, IIO_ST('u', 12, 16, 0), 0), - .channel[2] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 2, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 2, 2, IIO_ST('u', 12, 16, 0), 0), - .channel[3] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 3, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 3, 3, IIO_ST('u', 12, 16, 0), 0), - .channel[4] = IIO_CHAN_SOFT_TIMESTAMP(4), + .channel = { + [0] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 0, + .scan_index = 0, + .scan_type = IIO_ST('u', 12, 16, 0), + .event_mask = AD799X_EV_MASK, + }, + [1] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 1, + .scan_index = 1, + .scan_type = IIO_ST('u', 12, 16, 0), + .event_mask = AD799X_EV_MASK, + }, + [2] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 2, + .scan_index = 2, + .scan_type = IIO_ST('u', 12, 16, 0), + .event_mask = AD799X_EV_MASK, + }, + [3] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 3, + .scan_index = 3, + .scan_type = IIO_ST('u', 12, 16, 0), + .event_mask = AD799X_EV_MASK, + }, + [4] = IIO_CHAN_SOFT_TIMESTAMP(4), + }, .num_channels = 5, .int_vref_mv = 4096, .default_config = AD7998_ALERT_EN, .info = &ad7993_4_7_8_info, }, [ad7997] = { - .channel[0] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 0, 0, IIO_ST('u', 10, 16, 0), 0), - .channel[1] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 1, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 1, 1, IIO_ST('u', 10, 16, 0), 0), - .channel[2] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 2, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 2, 2, IIO_ST('u', 10, 16, 0), 0), - .channel[3] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 3, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 3, 3, IIO_ST('u', 10, 16, 0), 0), - .channel[4] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 4, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 4, 4, IIO_ST('u', 10, 16, 0), 0), - .channel[5] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 5, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 5, 5, IIO_ST('u', 10, 16, 0), 0), - .channel[6] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 6, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 6, 6, IIO_ST('u', 10, 16, 0), 0), - .channel[7] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 7, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 7, 7, IIO_ST('u', 10, 16, 0), 0), - .channel[8] = IIO_CHAN_SOFT_TIMESTAMP(8), + .channel = { + [0] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 0, + .scan_index = 0, + .scan_type = IIO_ST('u', 10, 16, 2), + .event_mask = AD799X_EV_MASK, + }, + [1] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 1, + .scan_index = 1, + .scan_type = IIO_ST('u', 10, 16, 2), + .event_mask = AD799X_EV_MASK, + }, + [2] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 2, + .scan_index = 2, + .scan_type = IIO_ST('u', 10, 16, 2), + .event_mask = AD799X_EV_MASK, + }, + [3] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 3, + .scan_index = 3, + .scan_type = IIO_ST('u', 10, 16, 2), + .event_mask = AD799X_EV_MASK, + }, + [4] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 4, + .scan_index = 4, + .scan_type = IIO_ST('u', 10, 16, 2), + }, + [5] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 5, + .scan_index = 5, + .scan_type = IIO_ST('u', 10, 16, 2), + }, + [6] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 6, + .scan_index = 6, + .scan_type = IIO_ST('u', 10, 16, 2), + }, + [7] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 7, + .scan_index = 7, + .scan_type = IIO_ST('u', 10, 16, 2), + }, + [8] = IIO_CHAN_SOFT_TIMESTAMP(8), + }, .num_channels = 9, .int_vref_mv = 1024, .default_config = AD7998_ALERT_EN, .info = &ad7993_4_7_8_info, }, [ad7998] = { - .channel[0] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 0, 0, IIO_ST('u', 12, 16, 0), 0), - .channel[1] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 1, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 1, 1, IIO_ST('u', 12, 16, 0), 0), - .channel[2] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 2, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 2, 2, IIO_ST('u', 12, 16, 0), 0), - .channel[3] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 3, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 3, 3, IIO_ST('u', 12, 16, 0), 0), - .channel[4] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 4, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 4, 4, IIO_ST('u', 12, 16, 0), 0), - .channel[5] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 5, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 5, 5, IIO_ST('u', 12, 16, 0), 0), - .channel[6] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 6, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 6, 6, IIO_ST('u', 12, 16, 0), 0), - .channel[7] = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 7, 0, - (1 << IIO_CHAN_INFO_SCALE_SHARED), - 7, 7, IIO_ST('u', 12, 16, 0), 0), - .channel[8] = IIO_CHAN_SOFT_TIMESTAMP(8), + .channel = { + [0] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 0, + .scan_index = 0, + .scan_type = IIO_ST('u', 12, 16, 0), + .event_mask = AD799X_EV_MASK, + }, + [1] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 1, + .scan_index = 1, + .scan_type = IIO_ST('u', 12, 16, 0), + .event_mask = AD799X_EV_MASK, + }, + [2] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 2, + .scan_index = 2, + .scan_type = IIO_ST('u', 12, 16, 0), + .event_mask = AD799X_EV_MASK, + }, + [3] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 3, + .scan_index = 3, + .scan_type = IIO_ST('u', 12, 16, 0), + .event_mask = AD799X_EV_MASK, + }, + [4] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 4, + .scan_index = 4, + .scan_type = IIO_ST('u', 12, 16, 0), + }, + [5] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 5, + .scan_index = 5, + .scan_type = IIO_ST('u', 12, 16, 0), + }, + [6] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 6, + .scan_index = 6, + .scan_type = IIO_ST('u', 12, 16, 0), + }, + [7] = { + .type = IIO_VOLTAGE, + .indexed = 1, + .channel = 7, + .scan_index = 7, + .scan_type = IIO_ST('u', 12, 16, 0), + }, + [8] = IIO_CHAN_SOFT_TIMESTAMP(8), + }, .num_channels = 9, .int_vref_mv = 4096, .default_config = AD7998_ALERT_EN, @@ -651,7 +806,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { static int __devinit ad799x_probe(struct i2c_client *client, const struct i2c_device_id *id) { - int ret, regdone = 0; + int ret; struct ad799x_platform_data *pdata = client->dev.platform_data; struct ad799x_state *st; struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); @@ -685,7 +840,6 @@ static int __devinit ad799x_probe(struct i2c_client *client, indio_dev->dev.parent = &client->dev; indio_dev->name = id->name; indio_dev->info = st->chip_info->info; - indio_dev->name = id->name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = st->chip_info->channel; @@ -695,14 +849,9 @@ static int __devinit ad799x_probe(struct i2c_client *client, if (ret) goto error_disable_reg; - ret = iio_device_register(indio_dev); - if (ret) - goto error_cleanup_ring; - regdone = 1; - - ret = iio_ring_buffer_register_ex(indio_dev->ring, 0, - indio_dev->channels, - indio_dev->num_channels); + ret = iio_buffer_register(indio_dev, + indio_dev->channels, + indio_dev->num_channels); if (ret) goto error_cleanup_ring; @@ -717,9 +866,14 @@ static int __devinit ad799x_probe(struct i2c_client *client, if (ret) goto error_cleanup_ring; } + ret = iio_device_register(indio_dev); + if (ret) + goto error_free_irq; return 0; +error_free_irq: + free_irq(client->irq, indio_dev); error_cleanup_ring: ad799x_ring_cleanup(indio_dev); error_disable_reg: @@ -728,10 +882,7 @@ error_disable_reg: error_put_reg: if (!IS_ERR(st->reg)) regulator_put(st->reg); - if (regdone) - iio_device_unregister(indio_dev); - else - iio_free_device(indio_dev); + iio_free_device(indio_dev); return ret; } @@ -741,16 +892,17 @@ static __devexit int ad799x_remove(struct i2c_client *client) struct iio_dev *indio_dev = i2c_get_clientdata(client); struct ad799x_state *st = iio_priv(indio_dev); + iio_device_unregister(indio_dev); if (client->irq > 0) free_irq(client->irq, indio_dev); - iio_ring_buffer_unregister(indio_dev->ring); + iio_buffer_unregister(indio_dev); ad799x_ring_cleanup(indio_dev); if (!IS_ERR(st->reg)) { regulator_disable(st->reg); regulator_put(st->reg); } - iio_device_unregister(indio_dev); + iio_free_device(indio_dev); return 0; } |