summaryrefslogtreecommitdiff
path: root/drivers/staging/iio/adc/ad7291.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/iio/adc/ad7291.c')
-rw-r--r--drivers/staging/iio/adc/ad7291.c502
1 files changed, 185 insertions, 317 deletions
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index 34041a72aa52..1be3453479b7 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -8,14 +8,12 @@
#include <linux/interrupt.h>
#include <linux/gpio.h>
-#include <linux/workqueue.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <linux/list.h>
#include <linux/i2c.h>
-#include <linux/rtc.h>
#include "../iio.h"
#include "../sysfs.h"
@@ -62,11 +60,8 @@
*/
struct ad7291_chip_info {
- const char *name;
struct i2c_client *client;
struct iio_dev *indio_dev;
- struct work_struct thresh_work;
- s64 last_timestamp;
u16 command;
u8 channels; /* Active voltage channels */
};
@@ -438,17 +433,6 @@ static IIO_DEVICE_ATTR(channel_mask, S_IRUGO | S_IWUSR,
ad7291_store_channel_mask,
0);
-static ssize_t ad7291_show_name(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct ad7291_chip_info *chip = dev_info->dev_data;
- return sprintf(buf, "%s\n", chip->name);
-}
-
-static IIO_DEVICE_ATTR(name, S_IRUGO, ad7291_show_name, NULL, 0);
-
static struct attribute *ad7291_attributes[] = {
&iio_dev_attr_available_modes.dev_attr.attr,
&iio_dev_attr_mode.dev_attr.attr,
@@ -459,7 +443,6 @@ static struct attribute *ad7291_attributes[] = {
&iio_dev_attr_t_average.dev_attr.attr,
&iio_dev_attr_voltage.dev_attr.attr,
&iio_dev_attr_channel_mask.dev_attr.attr,
- &iio_dev_attr_name.dev_attr.attr,
NULL,
};
@@ -471,28 +454,23 @@ static const struct attribute_group ad7291_attribute_group = {
* temperature bound events
*/
-#define IIO_EVENT_CODE_AD7291_T_SENSE_HIGH IIO_BUFFER_EVENT_CODE(0)
-#define IIO_EVENT_CODE_AD7291_T_SENSE_LOW IIO_BUFFER_EVENT_CODE(1)
-#define IIO_EVENT_CODE_AD7291_T_AVG_HIGH IIO_BUFFER_EVENT_CODE(2)
-#define IIO_EVENT_CODE_AD7291_T_AVG_LOW IIO_BUFFER_EVENT_CODE(3)
-#define IIO_EVENT_CODE_AD7291_VOLTAGE_BASE IIO_BUFFER_EVENT_CODE(4)
-
-static void ad7291_interrupt_bh(struct work_struct *work_s)
+static irqreturn_t ad7291_event_handler(int irq, void *private)
{
- struct ad7291_chip_info *chip =
- container_of(work_s, struct ad7291_chip_info, thresh_work);
+ struct iio_dev *indio_dev = private;
+ struct ad7291_chip_info *chip = iio_dev_get_devdata(private);
u16 t_status, v_status;
u16 command;
int i;
+ s64 timestamp = iio_get_time_ns();
if (ad7291_i2c_read(chip, AD7291_T_ALERT_STATUS, &t_status))
- return;
+ return IRQ_HANDLED;
if (ad7291_i2c_read(chip, AD7291_VOLTAGE_ALERT_STATUS, &v_status))
- return;
+ return IRQ_HANDLED;
if (!(t_status || v_status))
- return;
+ return IRQ_HANDLED;
command = chip->command | AD7291_ALART_CLEAR;
ad7291_i2c_write(chip, AD7291_COMMAND, command);
@@ -500,50 +478,67 @@ static void ad7291_interrupt_bh(struct work_struct *work_s)
command = chip->command & ~AD7291_ALART_CLEAR;
ad7291_i2c_write(chip, AD7291_COMMAND, command);
- enable_irq(chip->client->irq);
-
- for (i = 0; i < 4; i++) {
- if (t_status & (1 << i))
- iio_push_event(chip->indio_dev, 0,
- IIO_EVENT_CODE_AD7291_T_SENSE_HIGH + i,
- chip->last_timestamp);
- }
-
- for (i = 0; i < AD7291_VOLTAGE_LIMIT_COUNT*2; i++) {
+ if (t_status & (1 << 0))
+ iio_push_event(indio_dev, 0,
+ IIO_UNMOD_EVENT_CODE(IIO_TEMP,
+ 0,
+ IIO_EV_TYPE_THRESH,
+ IIO_EV_DIR_FALLING),
+ timestamp);
+ if (t_status & (1 << 1))
+ iio_push_event(indio_dev, 0,
+ IIO_UNMOD_EVENT_CODE(IIO_TEMP,
+ 0,
+ IIO_EV_TYPE_THRESH,
+ IIO_EV_DIR_RISING),
+ timestamp);
+ if (t_status & (1 << 2))
+ iio_push_event(indio_dev, 0,
+ IIO_UNMOD_EVENT_CODE(IIO_TEMP,
+ 0,
+ IIO_EV_TYPE_THRESH,
+ IIO_EV_DIR_FALLING),
+ timestamp);
+ if (t_status & (1 << 3))
+ iio_push_event(indio_dev, 0,
+ IIO_UNMOD_EVENT_CODE(IIO_TEMP,
+ 0,
+ IIO_EV_TYPE_THRESH,
+ IIO_EV_DIR_RISING),
+ timestamp);
+
+ for (i = 0; i < AD7291_VOLTAGE_LIMIT_COUNT*2; i += 2) {
if (v_status & (1 << i))
- iio_push_event(chip->indio_dev, 0,
- IIO_EVENT_CODE_AD7291_VOLTAGE_BASE + i,
- chip->last_timestamp);
+ iio_push_event(indio_dev, 0,
+ IIO_UNMOD_EVENT_CODE(IIO_IN,
+ i/2,
+ IIO_EV_TYPE_THRESH,
+ IIO_EV_DIR_FALLING),
+ timestamp);
+ if (v_status & (1 << (i + 1)))
+ iio_push_event(indio_dev, 0,
+ IIO_UNMOD_EVENT_CODE(IIO_IN,
+ i/2,
+ IIO_EV_TYPE_THRESH,
+ IIO_EV_DIR_RISING),
+ timestamp);
}
-}
-
-static int ad7291_interrupt(struct iio_dev *dev_info,
- int index,
- s64 timestamp,
- int no_test)
-{
- struct ad7291_chip_info *chip = dev_info->dev_data;
-
- chip->last_timestamp = timestamp;
- schedule_work(&chip->thresh_work);
- return 0;
+ return IRQ_HANDLED;
}
-IIO_EVENT_SH(ad7291, &ad7291_interrupt);
-
static inline ssize_t ad7291_show_t_bound(struct device *dev,
struct device_attribute *attr,
- u8 bound_reg,
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
struct ad7291_chip_info *chip = dev_info->dev_data;
+ struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
u16 data;
char sign = ' ';
int ret;
- ret = ad7291_i2c_read(chip, bound_reg, &data);
+ ret = ad7291_i2c_read(chip, this_attr->address, &data);
if (ret)
return -EIO;
@@ -561,12 +556,12 @@ static inline ssize_t ad7291_show_t_bound(struct device *dev,
static inline ssize_t ad7291_set_t_bound(struct device *dev,
struct device_attribute *attr,
- u8 bound_reg,
const char *buf,
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
struct ad7291_chip_info *chip = dev_info->dev_data;
+ struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
long tmp1, tmp2;
u16 data;
char *pos;
@@ -600,64 +595,13 @@ static inline ssize_t ad7291_set_t_bound(struct device *dev,
/* convert positive value to supplyment */
data = (AD7291_T_VALUE_SIGN << 1) - data;
- ret = ad7291_i2c_write(chip, bound_reg, data);
+ ret = ad7291_i2c_write(chip, this_attr->address, data);
if (ret)
return -EIO;
return ret;
}
-static ssize_t ad7291_show_t_sense_high(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- return ad7291_show_t_bound(dev, attr,
- AD7291_T_SENSE_HIGH, buf);
-}
-
-static inline ssize_t ad7291_set_t_sense_high(struct device *dev,
- struct device_attribute *attr,
- const char *buf,
- size_t len)
-{
- return ad7291_set_t_bound(dev, attr,
- AD7291_T_SENSE_HIGH, buf, len);
-}
-
-static ssize_t ad7291_show_t_sense_low(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- return ad7291_show_t_bound(dev, attr,
- AD7291_T_SENSE_LOW, buf);
-}
-
-static inline ssize_t ad7291_set_t_sense_low(struct device *dev,
- struct device_attribute *attr,
- const char *buf,
- size_t len)
-{
- return ad7291_set_t_bound(dev, attr,
- AD7291_T_SENSE_LOW, buf, len);
-}
-
-static ssize_t ad7291_show_t_sense_hyst(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- return ad7291_show_t_bound(dev, attr,
- AD7291_T_SENSE_HYST, buf);
-}
-
-static inline ssize_t ad7291_set_t_sense_hyst(struct device *dev,
- struct device_attribute *attr,
- const char *buf,
- size_t len)
-{
- return ad7291_set_t_bound(dev, attr,
- AD7291_T_SENSE_HYST, buf, len);
-}
-
static inline ssize_t ad7291_show_v_bound(struct device *dev,
struct device_attribute *attr,
u8 bound_reg,
@@ -712,191 +656,121 @@ static inline ssize_t ad7291_set_v_bound(struct device *dev,
return ret;
}
-static int ad7291_get_voltage_limit_regs(const char *channel)
-{
- int index;
-
- if (strlen(channel) < 3 && channel[0] != 'v')
- return -EINVAL;
-
- index = channel[1] - '0';
- if (index >= AD7291_VOLTAGE_LIMIT_COUNT)
- return -EINVAL;
-
- return index;
-}
-
-static ssize_t ad7291_show_voltage_high(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- int regs;
-
- regs = ad7291_get_voltage_limit_regs(attr->attr.name);
-
- if (regs < 0)
- return regs;
-
- return ad7291_show_t_bound(dev, attr, regs, buf);
-}
-
-static inline ssize_t ad7291_set_voltage_high(struct device *dev,
- struct device_attribute *attr,
- const char *buf,
- size_t len)
-{
- int regs;
-
- regs = ad7291_get_voltage_limit_regs(attr->attr.name);
-
- if (regs < 0)
- return regs;
-
- return ad7291_set_t_bound(dev, attr, regs, buf, len);
-}
-
-static ssize_t ad7291_show_voltage_low(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- int regs;
-
- regs = ad7291_get_voltage_limit_regs(attr->attr.name);
-
- if (regs < 0)
- return regs;
-
- return ad7291_show_t_bound(dev, attr, regs+1, buf);
-}
-
-static inline ssize_t ad7291_set_voltage_low(struct device *dev,
- struct device_attribute *attr,
- const char *buf,
- size_t len)
-{
- int regs;
-
- regs = ad7291_get_voltage_limit_regs(attr->attr.name);
-
- if (regs < 0)
- return regs;
-
- return ad7291_set_t_bound(dev, attr, regs+1, buf, len);
-}
-
-static ssize_t ad7291_show_voltage_hyst(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- int regs;
-
- regs = ad7291_get_voltage_limit_regs(attr->attr.name);
-
- if (regs < 0)
- return regs;
-
- return ad7291_show_t_bound(dev, attr, regs+2, buf);
-}
-
-static inline ssize_t ad7291_set_voltage_hyst(struct device *dev,
- struct device_attribute *attr,
- const char *buf,
- size_t len)
-{
- int regs;
-
- regs = ad7291_get_voltage_limit_regs(attr->attr.name);
-
- if (regs < 0)
- return regs;
-
- return ad7291_set_t_bound(dev, attr, regs+2, buf, len);
-}
-
-IIO_EVENT_ATTR_SH(t_sense_high, iio_event_ad7291,
- ad7291_show_t_sense_high, ad7291_set_t_sense_high, 0);
-IIO_EVENT_ATTR_SH(t_sense_low, iio_event_ad7291,
- ad7291_show_t_sense_low, ad7291_set_t_sense_low, 0);
-IIO_EVENT_ATTR_SH(t_sense_hyst, iio_event_ad7291,
- ad7291_show_t_sense_hyst, ad7291_set_t_sense_hyst, 0);
-
-IIO_EVENT_ATTR_SH(v0_high, iio_event_ad7291,
- ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
-IIO_EVENT_ATTR_SH(v0_low, iio_event_ad7291,
- ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
-IIO_EVENT_ATTR_SH(v0_hyst, iio_event_ad7291,
- ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
-IIO_EVENT_ATTR_SH(v1_high, iio_event_ad7291,
- ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
-IIO_EVENT_ATTR_SH(v1_low, iio_event_ad7291,
- ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
-IIO_EVENT_ATTR_SH(v1_hyst, iio_event_ad7291,
- ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
-IIO_EVENT_ATTR_SH(v2_high, iio_event_ad7291,
- ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
-IIO_EVENT_ATTR_SH(v2_low, iio_event_ad7291,
- ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
-IIO_EVENT_ATTR_SH(v2_hyst, iio_event_ad7291,
- ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
-IIO_EVENT_ATTR_SH(v3_high, iio_event_ad7291,
- ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
-IIO_EVENT_ATTR_SH(v3_low, iio_event_ad7291,
- ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
-IIO_EVENT_ATTR_SH(v3_hyst, iio_event_ad7291,
- ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
-IIO_EVENT_ATTR_SH(v4_high, iio_event_ad7291,
- ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
-IIO_EVENT_ATTR_SH(v4_low, iio_event_ad7291,
- ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
-IIO_EVENT_ATTR_SH(v4_hyst, iio_event_ad7291,
- ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
-IIO_EVENT_ATTR_SH(v5_high, iio_event_ad7291,
- ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
-IIO_EVENT_ATTR_SH(v5_low, iio_event_ad7291,
- ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
-IIO_EVENT_ATTR_SH(v5_hyst, iio_event_ad7291,
- ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
-IIO_EVENT_ATTR_SH(v6_high, iio_event_ad7291,
- ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
-IIO_EVENT_ATTR_SH(v6_low, iio_event_ad7291,
- ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
-IIO_EVENT_ATTR_SH(v6_hyst, iio_event_ad7291,
- ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
-IIO_EVENT_ATTR_SH(v7_high, iio_event_ad7291,
- ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
-IIO_EVENT_ATTR_SH(v7_low, iio_event_ad7291,
- ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
-IIO_EVENT_ATTR_SH(v7_hyst, iio_event_ad7291,
- ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
+static IIO_DEVICE_ATTR(t_sense_high_value,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound,
+ AD7291_T_SENSE_HIGH);
+static IIO_DEVICE_ATTR(t_sense_low_value,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound,
+ AD7291_T_SENSE_LOW);
+static IIO_DEVICE_ATTR(t_sense_hyst_value,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound,
+ AD7291_T_SENSE_HYST);
+static IIO_DEVICE_ATTR(v0_high,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x04);
+static IIO_DEVICE_ATTR(v0_low,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x05);
+static IIO_DEVICE_ATTR(v0_hyst,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x06);
+static IIO_DEVICE_ATTR(v1_high,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x07);
+static IIO_DEVICE_ATTR(v1_low,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x08);
+static IIO_DEVICE_ATTR(v1_hyst,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x09);
+static IIO_DEVICE_ATTR(v2_high,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x0A);
+static IIO_DEVICE_ATTR(v2_low,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x0B);
+static IIO_DEVICE_ATTR(v2_hyst,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x0C);
+static IIO_DEVICE_ATTR(v3_high,
+ S_IRUGO | S_IWUSR,
+ /* Datasheet suggests this one and this one only
+ has the registers in different order */
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x0E);
+static IIO_DEVICE_ATTR(v3_low,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x0D);
+static IIO_DEVICE_ATTR(v3_hyst,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x0F);
+static IIO_DEVICE_ATTR(v4_high,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x10);
+static IIO_DEVICE_ATTR(v4_low,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x11);
+static IIO_DEVICE_ATTR(v4_hyst,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x12);
+static IIO_DEVICE_ATTR(v5_high,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x13);
+static IIO_DEVICE_ATTR(v5_low,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x14);
+static IIO_DEVICE_ATTR(v5_hyst,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x15);
+static IIO_DEVICE_ATTR(v6_high,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x16);
+static IIO_DEVICE_ATTR(v6_low,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x17);
+static IIO_DEVICE_ATTR(v6_hyst,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x18);
+static IIO_DEVICE_ATTR(v7_high,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x19);
+static IIO_DEVICE_ATTR(v7_low,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x1A);
+static IIO_DEVICE_ATTR(v7_hyst,
+ S_IRUGO | S_IWUSR,
+ ad7291_show_t_bound, ad7291_set_t_bound, 0x1B);
static struct attribute *ad7291_event_attributes[] = {
- &iio_event_attr_t_sense_high.dev_attr.attr,
- &iio_event_attr_t_sense_low.dev_attr.attr,
- &iio_event_attr_t_sense_hyst.dev_attr.attr,
- &iio_event_attr_v0_high.dev_attr.attr,
- &iio_event_attr_v0_low.dev_attr.attr,
- &iio_event_attr_v0_hyst.dev_attr.attr,
- &iio_event_attr_v1_high.dev_attr.attr,
- &iio_event_attr_v1_low.dev_attr.attr,
- &iio_event_attr_v1_hyst.dev_attr.attr,
- &iio_event_attr_v2_high.dev_attr.attr,
- &iio_event_attr_v2_low.dev_attr.attr,
- &iio_event_attr_v2_hyst.dev_attr.attr,
- &iio_event_attr_v3_high.dev_attr.attr,
- &iio_event_attr_v3_low.dev_attr.attr,
- &iio_event_attr_v3_hyst.dev_attr.attr,
- &iio_event_attr_v4_high.dev_attr.attr,
- &iio_event_attr_v4_low.dev_attr.attr,
- &iio_event_attr_v4_hyst.dev_attr.attr,
- &iio_event_attr_v5_high.dev_attr.attr,
- &iio_event_attr_v5_low.dev_attr.attr,
- &iio_event_attr_v5_hyst.dev_attr.attr,
- &iio_event_attr_v6_high.dev_attr.attr,
- &iio_event_attr_v6_low.dev_attr.attr,
- &iio_event_attr_v6_hyst.dev_attr.attr,
- &iio_event_attr_v7_high.dev_attr.attr,
- &iio_event_attr_v7_low.dev_attr.attr,
- &iio_event_attr_v7_hyst.dev_attr.attr,
+ &iio_dev_attr_t_sense_high_value.dev_attr.attr,
+ &iio_dev_attr_t_sense_low_value.dev_attr.attr,
+ &iio_dev_attr_t_sense_hyst_value.dev_attr.attr,
+ &iio_dev_attr_v0_high.dev_attr.attr,
+ &iio_dev_attr_v0_low.dev_attr.attr,
+ &iio_dev_attr_v0_hyst.dev_attr.attr,
+ &iio_dev_attr_v1_high.dev_attr.attr,
+ &iio_dev_attr_v1_low.dev_attr.attr,
+ &iio_dev_attr_v1_hyst.dev_attr.attr,
+ &iio_dev_attr_v2_high.dev_attr.attr,
+ &iio_dev_attr_v2_low.dev_attr.attr,
+ &iio_dev_attr_v2_hyst.dev_attr.attr,
+ &iio_dev_attr_v3_high.dev_attr.attr,
+ &iio_dev_attr_v3_low.dev_attr.attr,
+ &iio_dev_attr_v3_hyst.dev_attr.attr,
+ &iio_dev_attr_v4_high.dev_attr.attr,
+ &iio_dev_attr_v4_low.dev_attr.attr,
+ &iio_dev_attr_v4_hyst.dev_attr.attr,
+ &iio_dev_attr_v5_high.dev_attr.attr,
+ &iio_dev_attr_v5_low.dev_attr.attr,
+ &iio_dev_attr_v5_hyst.dev_attr.attr,
+ &iio_dev_attr_v6_high.dev_attr.attr,
+ &iio_dev_attr_v6_low.dev_attr.attr,
+ &iio_dev_attr_v6_hyst.dev_attr.attr,
+ &iio_dev_attr_v7_high.dev_attr.attr,
+ &iio_dev_attr_v7_low.dev_attr.attr,
+ &iio_dev_attr_v7_hyst.dev_attr.attr,
NULL,
};
@@ -904,6 +778,12 @@ static struct attribute_group ad7291_event_attribute_group = {
.attrs = ad7291_event_attributes,
};
+static const struct iio_info ad7291_info = {
+ .attrs = &ad7291_attribute_group,
+ .num_interrupt_lines = 1,
+ .event_attrs = &ad7291_event_attribute_group,
+};
+
/*
* device probe and remove
*/
@@ -923,21 +803,18 @@ static int __devinit ad7291_probe(struct i2c_client *client,
i2c_set_clientdata(client, chip);
chip->client = client;
- chip->name = id->name;
chip->command = AD7291_NOISE_DELAY | AD7291_T_SENSE_MASK;
- chip->indio_dev = iio_allocate_device();
+ chip->indio_dev = iio_allocate_device(0);
if (chip->indio_dev == NULL) {
ret = -ENOMEM;
goto error_free_chip;
}
+ chip->indio_dev->name = id->name;
chip->indio_dev->dev.parent = &client->dev;
- chip->indio_dev->attrs = &ad7291_attribute_group;
- chip->indio_dev->event_attrs = &ad7291_event_attribute_group;
+ chip->indio_dev->info = &ad7291_info;
chip->indio_dev->dev_data = (void *)chip;
- chip->indio_dev->driver_module = THIS_MODULE;
- chip->indio_dev->num_interrupt_lines = 1;
chip->indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(chip->indio_dev);
@@ -945,24 +822,15 @@ static int __devinit ad7291_probe(struct i2c_client *client,
goto error_free_dev;
if (client->irq > 0) {
- ret = iio_register_interrupt_line(client->irq,
- chip->indio_dev,
- 0,
- IRQF_TRIGGER_LOW,
- chip->name);
+ ret = request_threaded_irq(client->irq,
+ NULL,
+ &ad7291_event_handler,
+ IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+ id->name,
+ chip->indio_dev);
if (ret)
goto error_unreg_dev;
- /*
- * The event handler list element refer to iio_event_ad7291.
- * All event attributes bind to the same event handler.
- * So, only register event handler once.
- */
- iio_add_event_to_list(&iio_event_ad7291,
- &chip->indio_dev->interrupts[0]->ev_list);
-
- INIT_WORK(&chip->thresh_work, ad7291_interrupt_bh);
-
/* set irq polarity low level */
chip->command |= AD7291_ALART_POLARITY;
}
@@ -979,7 +847,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
return 0;
error_unreg_irq:
- iio_unregister_interrupt_line(chip->indio_dev, 0);
+ free_irq(client->irq, chip->indio_dev);
error_unreg_dev:
iio_device_unregister(chip->indio_dev);
error_free_dev:
@@ -996,7 +864,7 @@ static int __devexit ad7291_remove(struct i2c_client *client)
struct iio_dev *indio_dev = chip->indio_dev;
if (client->irq)
- iio_unregister_interrupt_line(indio_dev, 0);
+ free_irq(client->irq, chip->indio_dev);
iio_device_unregister(indio_dev);
iio_free_device(chip->indio_dev);
kfree(chip);