summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/staging/iio/adc/ad799x_core.c142
1 files changed, 82 insertions, 60 deletions
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index dd279ce..c56181f 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -235,6 +235,61 @@ error_ret_mutex:
return ret ? ret : len;
}
+static int ad799x_read_event_config(struct iio_dev *dev_info,
+ 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)
@@ -309,72 +364,24 @@ static irqreturn_t ad799x_event_handler(int irq, void *private)
return IRQ_HANDLED;
}
-static IIO_DEVICE_ATTR(in_voltage0_thresh_low_value,
- S_IRUGO | S_IWUSR,
- ad799x_read_channel_config,
- ad799x_write_channel_config,
- AD7998_DATALOW_CH1_REG);
-
-static IIO_DEVICE_ATTR(in_voltage0_thresh_high_value,
- S_IRUGO | S_IWUSR,
- ad799x_read_channel_config,
- ad799x_write_channel_config,
- AD7998_DATAHIGH_CH1_REG);
-
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(in_voltage1_thresh_low_value,
- S_IRUGO | S_IWUSR,
- ad799x_read_channel_config,
- ad799x_write_channel_config,
- AD7998_DATALOW_CH2_REG);
-
-static IIO_DEVICE_ATTR(in_voltage1_thresh_high_value,
- S_IRUGO | S_IWUSR,
- ad799x_read_channel_config,
- ad799x_write_channel_config,
- AD7998_DATAHIGH_CH2_REG);
-
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(in_voltage2_thresh_low_value,
- S_IRUGO | S_IWUSR,
- ad799x_read_channel_config,
- ad799x_write_channel_config,
- AD7998_DATALOW_CH3_REG);
-
-static IIO_DEVICE_ATTR(in_voltage2_thresh_high_value,
- S_IRUGO | S_IWUSR,
- ad799x_read_channel_config,
- ad799x_write_channel_config,
- AD7998_DATAHIGH_CH3_REG);
-
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(in_voltage3_thresh_low_value,
- S_IRUGO | S_IWUSR,
- ad799x_read_channel_config,
- ad799x_write_channel_config,
- AD7998_DATALOW_CH4_REG);
-
-static IIO_DEVICE_ATTR(in_voltage3_thresh_high_value,
- S_IRUGO | S_IWUSR,
- ad799x_read_channel_config,
- ad799x_write_channel_config,
- AD7998_DATAHIGH_CH4_REG);
-
static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
S_IRUGO | S_IWUSR,
ad799x_read_channel_config,
@@ -387,17 +394,9 @@ 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_in_voltage0_thresh_low_value.dev_attr.attr,
- &iio_dev_attr_in_voltage0_thresh_high_value.dev_attr.attr,
&iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
- &iio_dev_attr_in_voltage1_thresh_low_value.dev_attr.attr,
- &iio_dev_attr_in_voltage1_thresh_high_value.dev_attr.attr,
&iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
- &iio_dev_attr_in_voltage2_thresh_low_value.dev_attr.attr,
- &iio_dev_attr_in_voltage2_thresh_high_value.dev_attr.attr,
&iio_dev_attr_in_voltage2_thresh_both_hyst_raw.dev_attr.attr,
- &iio_dev_attr_in_voltage3_thresh_low_value.dev_attr.attr,
- &iio_dev_attr_in_voltage3_thresh_high_value.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,
@@ -410,11 +409,7 @@ static struct attribute_group ad7993_4_7_8_event_attrs_group = {
};
static struct attribute *ad7992_event_attributes[] = {
- &iio_dev_attr_in_voltage0_thresh_low_value.dev_attr.attr,
- &iio_dev_attr_in_voltage0_thresh_high_value.dev_attr.attr,
&iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
- &iio_dev_attr_in_voltage1_thresh_low_value.dev_attr.attr,
- &iio_dev_attr_in_voltage1_thresh_high_value.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,
@@ -434,15 +429,24 @@ static const struct iio_info ad7991_info = {
static const struct iio_info ad7992_info = {
.read_raw = &ad799x_read_raw,
.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,
.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 = {
@@ -573,6 +577,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 0,
.scan_index = 0,
.scan_type = IIO_ST('u', 12, 16, 0),
+ .event_mask = AD799X_EV_MASK,
},
[1] = {
.type = IIO_VOLTAGE,
@@ -581,6 +586,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 1,
.scan_index = 1,
.scan_type = IIO_ST('u', 12, 16, 0),
+ .event_mask = AD799X_EV_MASK,
},
[2] = IIO_CHAN_SOFT_TIMESTAMP(2),
},
@@ -598,6 +604,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 0,
.scan_index = 0,
.scan_type = IIO_ST('u', 10, 16, 2),
+ .event_mask = AD799X_EV_MASK,
},
[1] = {
.type = IIO_VOLTAGE,
@@ -606,6 +613,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 1,
.scan_index = 1,
.scan_type = IIO_ST('u', 10, 16, 2),
+ .event_mask = AD799X_EV_MASK,
},
[2] = {
.type = IIO_VOLTAGE,
@@ -614,6 +622,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 2,
.scan_index = 2,
.scan_type = IIO_ST('u', 10, 16, 2),
+ .event_mask = AD799X_EV_MASK,
},
[3] = {
.type = IIO_VOLTAGE,
@@ -622,6 +631,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 3,
.scan_index = 3,
.scan_type = IIO_ST('u', 10, 16, 2),
+ .event_mask = AD799X_EV_MASK,
},
[4] = IIO_CHAN_SOFT_TIMESTAMP(4),
},
@@ -639,6 +649,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 0,
.scan_index = 0,
.scan_type = IIO_ST('u', 12, 16, 0),
+ .event_mask = AD799X_EV_MASK,
},
[1] = {
.type = IIO_VOLTAGE,
@@ -647,6 +658,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 1,
.scan_index = 1,
.scan_type = IIO_ST('u', 12, 16, 0),
+ .event_mask = AD799X_EV_MASK,
},
[2] = {
.type = IIO_VOLTAGE,
@@ -655,6 +667,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 2,
.scan_index = 2,
.scan_type = IIO_ST('u', 12, 16, 0),
+ .event_mask = AD799X_EV_MASK,
},
[3] = {
.type = IIO_VOLTAGE,
@@ -663,6 +676,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 3,
.scan_index = 3,
.scan_type = IIO_ST('u', 12, 16, 0),
+ .event_mask = AD799X_EV_MASK,
},
[4] = IIO_CHAN_SOFT_TIMESTAMP(4),
},
@@ -680,6 +694,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 0,
.scan_index = 0,
.scan_type = IIO_ST('u', 10, 16, 2),
+ .event_mask = AD799X_EV_MASK,
},
[1] = {
.type = IIO_VOLTAGE,
@@ -688,6 +703,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 1,
.scan_index = 1,
.scan_type = IIO_ST('u', 10, 16, 2),
+ .event_mask = AD799X_EV_MASK,
},
[2] = {
.type = IIO_VOLTAGE,
@@ -696,6 +712,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 2,
.scan_index = 2,
.scan_type = IIO_ST('u', 10, 16, 2),
+ .event_mask = AD799X_EV_MASK,
},
[3] = {
.type = IIO_VOLTAGE,
@@ -704,6 +721,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 3,
.scan_index = 3,
.scan_type = IIO_ST('u', 10, 16, 2),
+ .event_mask = AD799X_EV_MASK,
},
[4] = {
.type = IIO_VOLTAGE,
@@ -753,6 +771,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 0,
.scan_index = 0,
.scan_type = IIO_ST('u', 12, 16, 0),
+ .event_mask = AD799X_EV_MASK,
},
[1] = {
.type = IIO_VOLTAGE,
@@ -761,6 +780,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 1,
.scan_index = 1,
.scan_type = IIO_ST('u', 12, 16, 0),
+ .event_mask = AD799X_EV_MASK,
},
[2] = {
.type = IIO_VOLTAGE,
@@ -769,6 +789,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 2,
.scan_index = 2,
.scan_type = IIO_ST('u', 12, 16, 0),
+ .event_mask = AD799X_EV_MASK,
},
[3] = {
.type = IIO_VOLTAGE,
@@ -777,6 +798,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
.address = 3,
.scan_index = 3,
.scan_type = IIO_ST('u', 12, 16, 0),
+ .event_mask = AD799X_EV_MASK,
},
[4] = {
.type = IIO_VOLTAGE,