static int adt7310_spi_probe(struct spi_device *spi)
{
- return adt7x10_probe(&spi->dev, spi_get_device_id(spi)->name,
+ return adt7x10_probe(&spi->dev, spi_get_device_id(spi)->name, spi->irq,
&adt7310_spi_ops);
}
static int adt7310_spi_remove(struct spi_device *spi)
{
- return adt7x10_remove(&spi->dev);
+ return adt7x10_remove(&spi->dev, spi->irq);
}
static const struct spi_device_id adt7310_id[] = {
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
return -ENODEV;
- return adt7x10_probe(&client->dev, NULL, &adt7410_i2c_ops);
+ return adt7x10_probe(&client->dev, NULL, client->irq, &adt7410_i2c_ops);
}
static int adt7410_i2c_remove(struct i2c_client *client)
{
- return adt7x10_remove(&client->dev);
+ return adt7x10_remove(&client->dev, client->irq);
}
static const struct i2c_device_id adt7410_ids[] = {
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/delay.h>
+#include <linux/interrupt.h>
#include "adt7x10.h"
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;
.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;
* 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)
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);
}
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);
int (*write_word)(struct device *, u8 reg, u16 data);
};
-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);
-int adt7x10_remove(struct device *dev);
+int adt7x10_remove(struct device *dev, int irq);
#ifdef CONFIG_PM_SLEEP
extern const struct dev_pm_ops adt7x10_dev_pm_ops;