mirror of https://gitee.com/openkylin/linux.git
staging:iio:adc:adt75 old to new event handling conversion
Another one where the events are 'unusual'. Still left sorting that out for another day. Untested changes Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
4f2c1b02b9
commit
1142f709e6
|
@ -7,15 +7,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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/i2c.h>
|
#include <linux/i2c.h>
|
||||||
#include <linux/rtc.h>
|
|
||||||
|
|
||||||
#include "../iio.h"
|
#include "../iio.h"
|
||||||
#include "../sysfs.h"
|
#include "../sysfs.h"
|
||||||
|
@ -57,8 +53,6 @@ struct adt75_chip_info {
|
||||||
const char *name;
|
const char *name;
|
||||||
struct i2c_client *client;
|
struct i2c_client *client;
|
||||||
struct iio_dev *indio_dev;
|
struct iio_dev *indio_dev;
|
||||||
struct work_struct thresh_work;
|
|
||||||
s64 last_timestamp;
|
|
||||||
u8 config;
|
u8 config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -279,33 +273,15 @@ static const struct attribute_group adt75_attribute_group = {
|
||||||
|
|
||||||
#define IIO_EVENT_CODE_ADT75_OTI IIO_BUFFER_EVENT_CODE(0)
|
#define IIO_EVENT_CODE_ADT75_OTI IIO_BUFFER_EVENT_CODE(0)
|
||||||
|
|
||||||
static void adt75_interrupt_bh(struct work_struct *work_s)
|
static irqreturn_t adt75_event_handler(int irq, void *private)
|
||||||
{
|
{
|
||||||
struct adt75_chip_info *chip =
|
iio_push_event(private, 0,
|
||||||
container_of(work_s, struct adt75_chip_info, thresh_work);
|
IIO_EVENT_CODE_ADT75_OTI,
|
||||||
|
iio_get_time_ns());
|
||||||
|
|
||||||
enable_irq(chip->client->irq);
|
return IRQ_HANDLED;
|
||||||
|
|
||||||
iio_push_event(chip->indio_dev, 0,
|
|
||||||
IIO_EVENT_CODE_ADT75_OTI,
|
|
||||||
chip->last_timestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int adt75_interrupt(struct iio_dev *dev_info,
|
|
||||||
int index,
|
|
||||||
s64 timestamp,
|
|
||||||
int no_test)
|
|
||||||
{
|
|
||||||
struct adt75_chip_info *chip = dev_info->dev_data;
|
|
||||||
|
|
||||||
chip->last_timestamp = timestamp;
|
|
||||||
schedule_work(&chip->thresh_work);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
IIO_EVENT_SH(adt75, &adt75_interrupt);
|
|
||||||
|
|
||||||
static ssize_t adt75_show_oti_mode(struct device *dev,
|
static ssize_t adt75_show_oti_mode(struct device *dev,
|
||||||
struct device_attribute *attr,
|
struct device_attribute *attr,
|
||||||
char *buf)
|
char *buf)
|
||||||
|
@ -458,16 +434,16 @@ static ssize_t adt75_set_fault_queue(struct device *dev,
|
||||||
}
|
}
|
||||||
static inline ssize_t adt75_show_t_bound(struct device *dev,
|
static inline ssize_t adt75_show_t_bound(struct device *dev,
|
||||||
struct device_attribute *attr,
|
struct device_attribute *attr,
|
||||||
u8 bound_reg,
|
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
|
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
||||||
struct iio_dev *dev_info = dev_get_drvdata(dev);
|
struct iio_dev *dev_info = dev_get_drvdata(dev);
|
||||||
struct adt75_chip_info *chip = dev_info->dev_data;
|
struct adt75_chip_info *chip = dev_info->dev_data;
|
||||||
u16 data;
|
u16 data;
|
||||||
char sign = ' ';
|
char sign = ' ';
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = adt75_i2c_read(chip, bound_reg, (u8 *)&data);
|
ret = adt75_i2c_read(chip, this_attr->address, (u8 *)&data);
|
||||||
if (ret)
|
if (ret)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
|
@ -485,10 +461,10 @@ static inline ssize_t adt75_show_t_bound(struct device *dev,
|
||||||
|
|
||||||
static inline ssize_t adt75_set_t_bound(struct device *dev,
|
static inline ssize_t adt75_set_t_bound(struct device *dev,
|
||||||
struct device_attribute *attr,
|
struct device_attribute *attr,
|
||||||
u8 bound_reg,
|
|
||||||
const char *buf,
|
const char *buf,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
|
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
||||||
struct iio_dev *dev_info = dev_get_drvdata(dev);
|
struct iio_dev *dev_info = dev_get_drvdata(dev);
|
||||||
struct adt75_chip_info *chip = dev_info->dev_data;
|
struct adt75_chip_info *chip = dev_info->dev_data;
|
||||||
long tmp1, tmp2;
|
long tmp1, tmp2;
|
||||||
|
@ -525,67 +501,42 @@ static inline ssize_t adt75_set_t_bound(struct device *dev,
|
||||||
data <<= ADT75_VALUE_OFFSET;
|
data <<= ADT75_VALUE_OFFSET;
|
||||||
data = swab16(data);
|
data = swab16(data);
|
||||||
|
|
||||||
ret = adt75_i2c_write(chip, bound_reg, (u8)data);
|
ret = adt75_i2c_write(chip, this_attr->address, (u8)data);
|
||||||
if (ret)
|
if (ret)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t adt75_show_t_os(struct device *dev,
|
|
||||||
struct device_attribute *attr,
|
|
||||||
char *buf)
|
|
||||||
{
|
|
||||||
return adt75_show_t_bound(dev, attr,
|
|
||||||
ADT75_T_OS, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline ssize_t adt75_set_t_os(struct device *dev,
|
static IIO_DEVICE_ATTR(oti_mode,
|
||||||
struct device_attribute *attr,
|
S_IRUGO | S_IWUSR,
|
||||||
const char *buf,
|
adt75_show_oti_mode, adt75_set_oti_mode, 0);
|
||||||
size_t len)
|
static IIO_DEVICE_ATTR(available_oti_modes,
|
||||||
{
|
S_IRUGO,
|
||||||
return adt75_set_t_bound(dev, attr,
|
adt75_show_available_oti_modes, NULL, 0);
|
||||||
ADT75_T_OS, buf, len);
|
static IIO_DEVICE_ATTR(smbus_alart,
|
||||||
}
|
S_IRUGO | S_IWUSR,
|
||||||
|
adt75_show_smbus_alart, adt75_set_smbus_alart, 0);
|
||||||
static ssize_t adt75_show_t_hyst(struct device *dev,
|
static IIO_DEVICE_ATTR(fault_queue,
|
||||||
struct device_attribute *attr,
|
S_IRUGO | S_IWUSR,
|
||||||
char *buf)
|
adt75_show_fault_queue, adt75_set_fault_queue, 0);
|
||||||
{
|
static IIO_DEVICE_ATTR(t_os_value,
|
||||||
return adt75_show_t_bound(dev, attr,
|
S_IRUGO | S_IWUSR,
|
||||||
ADT75_T_HYST, buf);
|
adt75_show_t_bound, adt75_set_t_bound,
|
||||||
}
|
ADT75_T_OS);
|
||||||
|
static IIO_DEVICE_ATTR(t_hyst_value,
|
||||||
static inline ssize_t adt75_set_t_hyst(struct device *dev,
|
S_IRUGO | S_IWUSR,
|
||||||
struct device_attribute *attr,
|
adt75_show_t_bound, adt75_set_t_bound,
|
||||||
const char *buf,
|
ADT75_T_HYST);
|
||||||
size_t len)
|
|
||||||
{
|
|
||||||
return adt75_set_t_bound(dev, attr,
|
|
||||||
ADT75_T_HYST, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
IIO_EVENT_ATTR_SH(oti_mode, iio_event_adt75,
|
|
||||||
adt75_show_oti_mode, adt75_set_oti_mode, 0);
|
|
||||||
IIO_EVENT_ATTR_SH(available_oti_modes, iio_event_adt75,
|
|
||||||
adt75_show_available_oti_modes, NULL, 0);
|
|
||||||
IIO_EVENT_ATTR_SH(smbus_alart, iio_event_adt75,
|
|
||||||
adt75_show_smbus_alart, adt75_set_smbus_alart, 0);
|
|
||||||
IIO_EVENT_ATTR_SH(fault_queue, iio_event_adt75,
|
|
||||||
adt75_show_fault_queue, adt75_set_fault_queue, 0);
|
|
||||||
IIO_EVENT_ATTR_SH(t_os, iio_event_adt75,
|
|
||||||
adt75_show_t_os, adt75_set_t_os, 0);
|
|
||||||
IIO_EVENT_ATTR_SH(t_hyst, iio_event_adt75,
|
|
||||||
adt75_show_t_hyst, adt75_set_t_hyst, 0);
|
|
||||||
|
|
||||||
static struct attribute *adt75_event_attributes[] = {
|
static struct attribute *adt75_event_attributes[] = {
|
||||||
&iio_event_attr_oti_mode.dev_attr.attr,
|
&iio_dev_attr_oti_mode.dev_attr.attr,
|
||||||
&iio_event_attr_available_oti_modes.dev_attr.attr,
|
&iio_dev_attr_available_oti_modes.dev_attr.attr,
|
||||||
&iio_event_attr_smbus_alart.dev_attr.attr,
|
&iio_dev_attr_smbus_alart.dev_attr.attr,
|
||||||
&iio_event_attr_fault_queue.dev_attr.attr,
|
&iio_dev_attr_fault_queue.dev_attr.attr,
|
||||||
&iio_event_attr_t_os.dev_attr.attr,
|
&iio_dev_attr_t_os_value.dev_attr.attr,
|
||||||
&iio_event_attr_t_hyst.dev_attr.attr,
|
&iio_dev_attr_t_hyst_value.dev_attr.attr,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -633,24 +584,15 @@ static int __devinit adt75_probe(struct i2c_client *client,
|
||||||
goto error_free_dev;
|
goto error_free_dev;
|
||||||
|
|
||||||
if (client->irq > 0) {
|
if (client->irq > 0) {
|
||||||
ret = iio_register_interrupt_line(client->irq,
|
ret = request_threaded_irq(client->irq,
|
||||||
chip->indio_dev,
|
NULL,
|
||||||
0,
|
&adt75_event_handler,
|
||||||
IRQF_TRIGGER_LOW,
|
IRQF_TRIGGER_LOW,
|
||||||
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_adt75.
|
|
||||||
* All event attributes bind to the same event handler.
|
|
||||||
* So, only register event handler once.
|
|
||||||
*/
|
|
||||||
iio_add_event_to_list(&iio_event_adt75,
|
|
||||||
&chip->indio_dev->interrupts[0]->ev_list);
|
|
||||||
|
|
||||||
INIT_WORK(&chip->thresh_work, adt75_interrupt_bh);
|
|
||||||
|
|
||||||
ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
|
ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
|
@ -672,7 +614,7 @@ static int __devinit adt75_probe(struct i2c_client *client,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
error_unreg_irq:
|
error_unreg_irq:
|
||||||
iio_unregister_interrupt_line(chip->indio_dev, 0);
|
free_irq(client->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:
|
||||||
|
@ -689,7 +631,7 @@ static int __devexit adt75_remove(struct i2c_client *client)
|
||||||
struct iio_dev *indio_dev = chip->indio_dev;
|
struct iio_dev *indio_dev = chip->indio_dev;
|
||||||
|
|
||||||
if (client->irq)
|
if (client->irq)
|
||||||
iio_unregister_interrupt_line(indio_dev, 0);
|
free_irq(client->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);
|
||||||
|
|
Loading…
Reference in New Issue