summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adt7x10.c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-03-12 11:38:47 +0100
committerGuenter Roeck <linux@roeck-us.net>2013-04-07 21:16:38 -0700
commit4b5e536b0e948b5c756aa1d57218371c242f768d (patch)
tree2550bb81ab1b0712f190f030c7cead7fc74e7aa8 /drivers/hwmon/adt7x10.c
parent51c2a4871c1b47255ff8d74f0a86b2a0defff319 (diff)
downloadtalos-op-linux-4b5e536b0e948b5c756aa1d57218371c242f768d.tar.gz
talos-op-linux-4b5e536b0e948b5c756aa1d57218371c242f768d.zip
hwmon: (adt7x10) Add alarm interrupt support
This allows an userspace application to poll() on the alarm files to get notified in case of a temperature threshold event. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/adt7x10.c')
-rw-r--r--drivers/hwmon/adt7x10.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/drivers/hwmon/adt7x10.c b/drivers/hwmon/adt7x10.c
index 84b3dfc1c1cd..98141f483165 100644
--- a/drivers/hwmon/adt7x10.c
+++ b/drivers/hwmon/adt7x10.c
@@ -30,6 +30,7 @@
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/delay.h>
+#include <linux/interrupt.h>
#include "adt7x10.h"
@@ -112,6 +113,25 @@ static const u8 ADT7X10_REG_TEMP[4] = {
ADT7X10_T_CRIT, /* critical */
};
+static irqreturn_t adt7x10_irq_handler(int irq, void *private)
+{
+ struct device *dev = private;
+ int status;
+
+ status = adt7x10_read_byte(dev, ADT7X10_STATUS);
+ if (status < 0)
+ return IRQ_HANDLED;
+
+ if (status & ADT7X10_STAT_T_HIGH)
+ sysfs_notify(&dev->kobj, NULL, "temp1_max_alarm");
+ if (status & ADT7X10_STAT_T_LOW)
+ sysfs_notify(&dev->kobj, NULL, "temp1_min_alarm");
+ if (status & ADT7X10_STAT_T_CRIT)
+ sysfs_notify(&dev->kobj, NULL, "temp1_crit_alarm");
+
+ return IRQ_HANDLED;
+}
+
static int adt7x10_temp_ready(struct device *dev)
{
int i, status;
@@ -359,7 +379,7 @@ static const struct attribute_group adt7x10_group = {
.attrs = adt7x10_attributes,
};
-int adt7x10_probe(struct device *dev, const char *name,
+int adt7x10_probe(struct device *dev, const char *name, int irq,
const struct adt7x10_ops *ops)
{
struct adt7x10_data *data;
@@ -387,8 +407,10 @@ int adt7x10_probe(struct device *dev, const char *name,
* Set to 16 bit resolution, continous conversion and comparator mode.
*/
data->config = data->oldconfig;
- data->config &= ~ADT7X10_MODE_MASK;
+ data->config &= ~(ADT7X10_MODE_MASK | ADT7X10_CT_POLARITY |
+ ADT7X10_INT_POLARITY);
data->config |= ADT7X10_FULL | ADT7X10_RESOLUTION | ADT7X10_EVENT_MODE;
+
if (data->config != data->oldconfig) {
ret = adt7x10_write_byte(dev, ADT7X10_CONFIG, data->config);
if (ret)
@@ -422,8 +444,18 @@ int adt7x10_probe(struct device *dev, const char *name,
goto exit_remove_name;
}
+ if (irq > 0) {
+ ret = request_threaded_irq(irq, NULL, adt7x10_irq_handler,
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+ dev_name(dev), dev);
+ if (ret)
+ goto exit_hwmon_device_unregister;
+ }
+
return 0;
+exit_hwmon_device_unregister:
+ hwmon_device_unregister(data->hwmon_dev);
exit_remove_name:
if (name)
device_remove_file(dev, &dev_attr_name);
@@ -435,10 +467,13 @@ exit_restore:
}
EXPORT_SYMBOL_GPL(adt7x10_probe);
-int adt7x10_remove(struct device *dev)
+int adt7x10_remove(struct device *dev, int irq)
{
struct adt7x10_data *data = dev_get_drvdata(dev);
+ if (irq > 0)
+ free_irq(irq, dev);
+
hwmon_device_unregister(data->hwmon_dev);
if (data->name)
device_remove_file(dev, &dev_attr_name);
OpenPOWER on IntegriCloud