Commit cda0b2af authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:adt7310 move to current event handling

Another driver that has two event lines, but pushes all events out
the same chrdev. Probably needs a rethink.
Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 9c6b6ba8
...@@ -7,15 +7,12 @@ ...@@ -7,15 +7,12 @@
*/ */
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/workqueue.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/rtc.h>
#include "../iio.h" #include "../iio.h"
#include "../sysfs.h" #include "../sysfs.h"
...@@ -85,8 +82,6 @@ struct adt7310_chip_info { ...@@ -85,8 +82,6 @@ struct adt7310_chip_info {
const char *name; const char *name;
struct spi_device *spi_dev; struct spi_device *spi_dev;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct work_struct thresh_work;
s64 last_timestamp;
u8 config; u8 config;
}; };
...@@ -413,45 +408,33 @@ static const struct attribute_group adt7310_attribute_group = { ...@@ -413,45 +408,33 @@ static const struct attribute_group adt7310_attribute_group = {
#define IIO_EVENT_CODE_ADT7310_BELLOW_ALARM IIO_BUFFER_EVENT_CODE(1) #define IIO_EVENT_CODE_ADT7310_BELLOW_ALARM IIO_BUFFER_EVENT_CODE(1)
#define IIO_EVENT_CODE_ADT7310_ABOVE_CRIT IIO_BUFFER_EVENT_CODE(2) #define IIO_EVENT_CODE_ADT7310_ABOVE_CRIT IIO_BUFFER_EVENT_CODE(2)
static void adt7310_interrupt_bh(struct work_struct *work_s) static irqreturn_t adt7310_event_handler(int irq, void *private)
{ {
struct adt7310_chip_info *chip = struct iio_dev *indio_dev = private;
container_of(work_s, struct adt7310_chip_info, thresh_work); struct adt7310_chip_info *chip = iio_dev_get_devdata(indio_dev);
s64 timestamp = iio_get_time_ns();
u8 status; u8 status;
int ret;
if (adt7310_spi_read_byte(chip, ADT7310_STATUS, &status)) ret = adt7310_spi_read_byte(chip, ADT7310_STATUS, &status);
return; if (ret)
return ret;
if (status & ADT7310_STAT_T_HIGH) if (status & ADT7310_STAT_T_HIGH)
iio_push_event(chip->indio_dev, 0, iio_push_event(indio_dev, 0,
IIO_EVENT_CODE_ADT7310_ABOVE_ALARM, IIO_EVENT_CODE_ADT7310_ABOVE_ALARM,
chip->last_timestamp); timestamp);
if (status & ADT7310_STAT_T_LOW) if (status & ADT7310_STAT_T_LOW)
iio_push_event(chip->indio_dev, 0, iio_push_event(indio_dev, 0,
IIO_EVENT_CODE_ADT7310_BELLOW_ALARM, IIO_EVENT_CODE_ADT7310_BELLOW_ALARM,
chip->last_timestamp); timestamp);
if (status & ADT7310_STAT_T_CRIT) if (status & ADT7310_STAT_T_CRIT)
iio_push_event(chip->indio_dev, 0, iio_push_event(indio_dev, 0,
IIO_EVENT_CODE_ADT7310_ABOVE_CRIT, IIO_EVENT_CODE_ADT7310_ABOVE_CRIT,
chip->last_timestamp); timestamp);
} return IRQ_HANDLED;
static int adt7310_interrupt(struct iio_dev *dev_info,
int index,
s64 timestamp,
int no_test)
{
struct adt7310_chip_info *chip = dev_info->dev_data;
chip->last_timestamp = timestamp;
schedule_work(&chip->thresh_work);
return 0;
} }
IIO_EVENT_SH(adt7310, &adt7310_interrupt);
IIO_EVENT_SH(adt7310_ct, &adt7310_interrupt);
static ssize_t adt7310_show_event_mode(struct device *dev, static ssize_t adt7310_show_event_mode(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
...@@ -729,45 +712,51 @@ static inline ssize_t adt7310_set_t_hyst(struct device *dev, ...@@ -729,45 +712,51 @@ static inline ssize_t adt7310_set_t_hyst(struct device *dev,
return len; return len;
} }
IIO_EVENT_ATTR_SH(event_mode, iio_event_adt7310, static IIO_DEVICE_ATTR(event_mode,
adt7310_show_event_mode, adt7310_set_event_mode, 0); S_IRUGO | S_IWUSR,
IIO_EVENT_ATTR_SH(available_event_modes, iio_event_adt7310, adt7310_show_event_mode, adt7310_set_event_mode, 0);
adt7310_show_available_event_modes, NULL, 0); static IIO_DEVICE_ATTR(available_event_modes,
IIO_EVENT_ATTR_SH(fault_queue, iio_event_adt7310, S_IRUGO | S_IWUSR,
adt7310_show_fault_queue, adt7310_set_fault_queue, 0); adt7310_show_available_event_modes, NULL, 0);
IIO_EVENT_ATTR_SH(t_alarm_high, iio_event_adt7310, static IIO_DEVICE_ATTR(fault_queue,
adt7310_show_t_alarm_high, adt7310_set_t_alarm_high, 0); S_IRUGO | S_IWUSR,
IIO_EVENT_ATTR_SH(t_alarm_low, iio_event_adt7310, adt7310_show_fault_queue, adt7310_set_fault_queue, 0);
adt7310_show_t_alarm_low, adt7310_set_t_alarm_low, 0); static IIO_DEVICE_ATTR(t_alarm_high,
IIO_EVENT_ATTR_SH(t_crit, iio_event_adt7310_ct, S_IRUGO | S_IWUSR,
adt7310_show_t_crit, adt7310_set_t_crit, 0); adt7310_show_t_alarm_high, adt7310_set_t_alarm_high, 0);
IIO_EVENT_ATTR_SH(t_hyst, iio_event_adt7310, static IIO_DEVICE_ATTR(t_alarm_low,
adt7310_show_t_hyst, adt7310_set_t_hyst, 0); S_IRUGO | S_IWUSR,
adt7310_show_t_alarm_low, adt7310_set_t_alarm_low, 0);
static IIO_DEVICE_ATTR(t_crit,
S_IRUGO | S_IWUSR,
adt7310_show_t_crit, adt7310_set_t_crit, 0);
static IIO_DEVICE_ATTR(t_hyst,
S_IRUGO | S_IWUSR,
adt7310_show_t_hyst, adt7310_set_t_hyst, 0);
static struct attribute *adt7310_event_int_attributes[] = { static struct attribute *adt7310_event_int_attributes[] = {
&iio_event_attr_event_mode.dev_attr.attr, &iio_dev_attr_event_mode.dev_attr.attr,
&iio_event_attr_available_event_modes.dev_attr.attr, &iio_dev_attr_available_event_modes.dev_attr.attr,
&iio_event_attr_fault_queue.dev_attr.attr, &iio_dev_attr_fault_queue.dev_attr.attr,
&iio_event_attr_t_alarm_high.dev_attr.attr, &iio_dev_attr_t_alarm_high.dev_attr.attr,
&iio_event_attr_t_alarm_low.dev_attr.attr, &iio_dev_attr_t_alarm_low.dev_attr.attr,
&iio_event_attr_t_hyst.dev_attr.attr, &iio_dev_attr_t_hyst.dev_attr.attr,
NULL, NULL,
}; };
static struct attribute *adt7310_event_ct_attributes[] = { static struct attribute *adt7310_event_ct_attributes[] = {
&iio_event_attr_event_mode.dev_attr.attr, &iio_dev_attr_event_mode.dev_attr.attr,
&iio_event_attr_available_event_modes.dev_attr.attr, &iio_dev_attr_available_event_modes.dev_attr.attr,
&iio_event_attr_fault_queue.dev_attr.attr, &iio_dev_attr_fault_queue.dev_attr.attr,
&iio_event_attr_t_crit.dev_attr.attr, &iio_dev_attr_t_crit.dev_attr.attr,
&iio_event_attr_t_hyst.dev_attr.attr, &iio_dev_attr_t_hyst.dev_attr.attr,
NULL, NULL,
}; };
static struct attribute_group adt7310_event_attribute_group[ADT7310_IRQS] = { static struct attribute_group adt7310_event_attribute_group[ADT7310_IRQS] = {
{ {
.attrs = adt7310_event_int_attributes, .attrs = adt7310_event_int_attributes,
}, }, {
{
.attrs = adt7310_event_ct_attributes, .attrs = adt7310_event_ct_attributes,
} }
}; };
...@@ -818,45 +807,29 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev) ...@@ -818,45 +807,29 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev)
irq_flags = adt7310_platform_data[2]; irq_flags = adt7310_platform_data[2];
else else
irq_flags = IRQF_TRIGGER_LOW; irq_flags = IRQF_TRIGGER_LOW;
ret = iio_register_interrupt_line(spi_dev->irq, ret = request_threaded_irq(spi_dev->irq,
chip->indio_dev, NULL,
0, &adt7310_event_handler,
irq_flags, irq_flags,
chip->name); chip->name,
chip->indio_dev);
if (ret) if (ret)
goto error_unreg_dev; goto error_unreg_dev;
/*
* The event handler list element refer to iio_event_adt7310.
* All event attributes bind to the same event handler.
* One event handler can only be added to one event list.
*/
iio_add_event_to_list(&iio_event_adt7310,
&chip->indio_dev->interrupts[0]->ev_list);
} }
/* INT bound temperature alarm event. line 1 */ /* INT bound temperature alarm event. line 1 */
if (adt7310_platform_data[0]) { if (adt7310_platform_data[0]) {
ret = iio_register_interrupt_line(adt7310_platform_data[0], ret = request_threaded_irq(adt7310_platform_data[0],
chip->indio_dev, NULL,
1, &adt7310_event_handler,
adt7310_platform_data[1], adt7310_platform_data[1],
chip->name); chip->name,
chip->indio_dev);
if (ret) if (ret)
goto error_unreg_ct_irq; goto error_unreg_ct_irq;
/*
* The event handler list element refer to iio_event_adt7310.
* All event attributes bind to the same event handler.
* One event handler can only be added to one event list.
*/
iio_add_event_to_list(&iio_event_adt7310_ct,
&chip->indio_dev->interrupts[1]->ev_list);
} }
if (spi_dev->irq && adt7310_platform_data[0]) { if (spi_dev->irq && adt7310_platform_data[0]) {
INIT_WORK(&chip->thresh_work, adt7310_interrupt_bh);
ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config); ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
if (ret) { if (ret) {
ret = -EIO; ret = -EIO;
...@@ -884,9 +857,9 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev) ...@@ -884,9 +857,9 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev)
return 0; return 0;
error_unreg_int_irq: error_unreg_int_irq:
iio_unregister_interrupt_line(chip->indio_dev, 1); free_irq(adt7310_platform_data[0], chip->indio_dev);
error_unreg_ct_irq: error_unreg_ct_irq:
iio_unregister_interrupt_line(chip->indio_dev, 0); free_irq(spi_dev->irq, chip->indio_dev);
error_unreg_dev: error_unreg_dev:
iio_device_unregister(chip->indio_dev); iio_device_unregister(chip->indio_dev);
error_free_dev: error_free_dev:
...@@ -905,9 +878,9 @@ static int __devexit adt7310_remove(struct spi_device *spi_dev) ...@@ -905,9 +878,9 @@ static int __devexit adt7310_remove(struct spi_device *spi_dev)
dev_set_drvdata(&spi_dev->dev, NULL); dev_set_drvdata(&spi_dev->dev, NULL);
if (adt7310_platform_data[0]) if (adt7310_platform_data[0])
iio_unregister_interrupt_line(indio_dev, 1); free_irq(adt7310_platform_data[0], chip->indio_dev);
if (spi_dev->irq) if (spi_dev->irq)
iio_unregister_interrupt_line(indio_dev, 0); free_irq(spi_dev->irq, chip->indio_dev);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
iio_free_device(chip->indio_dev); iio_free_device(chip->indio_dev);
kfree(chip); kfree(chip);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment