Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Lars-Peter Clausen and committed by
Guenter Roeck
4b5e536b 51c2a487

+44 -9
+2 -2
drivers/hwmon/adt7310.c
··· 90 90 91 91 static int adt7310_spi_probe(struct spi_device *spi) 92 92 { 93 - return adt7x10_probe(&spi->dev, spi_get_device_id(spi)->name, 93 + return adt7x10_probe(&spi->dev, spi_get_device_id(spi)->name, spi->irq, 94 94 &adt7310_spi_ops); 95 95 } 96 96 97 97 static int adt7310_spi_remove(struct spi_device *spi) 98 98 { 99 - return adt7x10_remove(&spi->dev); 99 + return adt7x10_remove(&spi->dev, spi->irq); 100 100 } 101 101 102 102 static const struct spi_device_id adt7310_id[] = {
+2 -2
drivers/hwmon/adt7410.c
··· 47 47 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) 48 48 return -ENODEV; 49 49 50 - return adt7x10_probe(&client->dev, NULL, &adt7410_i2c_ops); 50 + return adt7x10_probe(&client->dev, NULL, client->irq, &adt7410_i2c_ops); 51 51 } 52 52 53 53 static int adt7410_i2c_remove(struct i2c_client *client) 54 54 { 55 - return adt7x10_remove(&client->dev); 55 + return adt7x10_remove(&client->dev, client->irq); 56 56 } 57 57 58 58 static const struct i2c_device_id adt7410_ids[] = {
+38 -3
drivers/hwmon/adt7x10.c
··· 30 30 #include <linux/err.h> 31 31 #include <linux/mutex.h> 32 32 #include <linux/delay.h> 33 + #include <linux/interrupt.h> 33 34 34 35 #include "adt7x10.h" 35 36 ··· 112 111 ADT7X10_T_ALARM_LOW, /* low */ 113 112 ADT7X10_T_CRIT, /* critical */ 114 113 }; 114 + 115 + static irqreturn_t adt7x10_irq_handler(int irq, void *private) 116 + { 117 + struct device *dev = private; 118 + int status; 119 + 120 + status = adt7x10_read_byte(dev, ADT7X10_STATUS); 121 + if (status < 0) 122 + return IRQ_HANDLED; 123 + 124 + if (status & ADT7X10_STAT_T_HIGH) 125 + sysfs_notify(&dev->kobj, NULL, "temp1_max_alarm"); 126 + if (status & ADT7X10_STAT_T_LOW) 127 + sysfs_notify(&dev->kobj, NULL, "temp1_min_alarm"); 128 + if (status & ADT7X10_STAT_T_CRIT) 129 + sysfs_notify(&dev->kobj, NULL, "temp1_crit_alarm"); 130 + 131 + return IRQ_HANDLED; 132 + } 115 133 116 134 static int adt7x10_temp_ready(struct device *dev) 117 135 { ··· 379 359 .attrs = adt7x10_attributes, 380 360 }; 381 361 382 - int adt7x10_probe(struct device *dev, const char *name, 362 + int adt7x10_probe(struct device *dev, const char *name, int irq, 383 363 const struct adt7x10_ops *ops) 384 364 { 385 365 struct adt7x10_data *data; ··· 407 387 * Set to 16 bit resolution, continous conversion and comparator mode. 408 388 */ 409 389 data->config = data->oldconfig; 410 - data->config &= ~ADT7X10_MODE_MASK; 390 + data->config &= ~(ADT7X10_MODE_MASK | ADT7X10_CT_POLARITY | 391 + ADT7X10_INT_POLARITY); 411 392 data->config |= ADT7X10_FULL | ADT7X10_RESOLUTION | ADT7X10_EVENT_MODE; 393 + 412 394 if (data->config != data->oldconfig) { 413 395 ret = adt7x10_write_byte(dev, ADT7X10_CONFIG, data->config); 414 396 if (ret) ··· 444 422 goto exit_remove_name; 445 423 } 446 424 425 + if (irq > 0) { 426 + ret = request_threaded_irq(irq, NULL, adt7x10_irq_handler, 427 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 428 + dev_name(dev), dev); 429 + if (ret) 430 + goto exit_hwmon_device_unregister; 431 + } 432 + 447 433 return 0; 448 434 435 + exit_hwmon_device_unregister: 436 + hwmon_device_unregister(data->hwmon_dev); 449 437 exit_remove_name: 450 438 if (name) 451 439 device_remove_file(dev, &dev_attr_name); ··· 467 435 } 468 436 EXPORT_SYMBOL_GPL(adt7x10_probe); 469 437 470 - int adt7x10_remove(struct device *dev) 438 + int adt7x10_remove(struct device *dev, int irq) 471 439 { 472 440 struct adt7x10_data *data = dev_get_drvdata(dev); 441 + 442 + if (irq > 0) 443 + free_irq(irq, dev); 473 444 474 445 hwmon_device_unregister(data->hwmon_dev); 475 446 if (data->name)
+2 -2
drivers/hwmon/adt7x10.h
··· 23 23 int (*write_word)(struct device *, u8 reg, u16 data); 24 24 }; 25 25 26 - int adt7x10_probe(struct device *dev, const char *name, 26 + int adt7x10_probe(struct device *dev, const char *name, int irq, 27 27 const struct adt7x10_ops *ops); 28 - int adt7x10_remove(struct device *dev); 28 + int adt7x10_remove(struct device *dev, int irq); 29 29 30 30 #ifdef CONFIG_PM_SLEEP 31 31 extern const struct dev_pm_ops adt7x10_dev_pm_ops;