hwmon: (it87) Add chassis intrusion detection support
authorJean Delvare <khali@linux-fr.org>
Mon, 25 Jul 2011 19:46:10 +0000 (21:46 +0200)
committerJean Delvare <khali@endymion.delvare>
Mon, 25 Jul 2011 19:46:10 +0000 (21:46 +0200)
Add chassis intrusion detection support for all supported devices,
using the standard interface.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Documentation/hwmon/it87
drivers/hwmon/it87.c

index 38425f0f264509289c30af96747e1efb7d70a2f8..6f496a5867324cc5750f90ecd0fd91d3547b554d 100644 (file)
@@ -76,7 +76,8 @@ IT8718F, IT8720F, IT8721F, IT8726F, IT8758E and SiS950 chips.
 These chips are 'Super I/O chips', supporting floppy disks, infrared ports,
 joysticks and other miscellaneous stuff. For hardware monitoring, they
 include an 'environment controller' with 3 temperature sensors, 3 fan
-rotation speed sensors, 8 voltage sensors, and associated alarms.
+rotation speed sensors, 8 voltage sensors, associated alarms, and chassis
+intrusion detection.
 
 The IT8712F and IT8716F additionally feature VID inputs, used to report
 the Vcore voltage of the processor. The early IT8712F have 5 VID pins,
index 5f52477504305e9f679e8d74e6cd4a402808c821..d912649fac5031e6855d2b967ac375d8d702d43e 100644 (file)
@@ -1172,6 +1172,32 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
        struct it87_data *data = it87_update_device(dev);
        return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
 }
+
+static ssize_t clear_intrusion(struct device *dev, struct device_attribute
+               *attr, const char *buf, size_t count)
+{
+       struct it87_data *data = dev_get_drvdata(dev);
+       long val;
+       int config;
+
+       if (strict_strtol(buf, 10, &val) < 0 || val != 0)
+               return -EINVAL;
+
+       mutex_lock(&data->update_lock);
+       config = it87_read_value(data, IT87_REG_CONFIG);
+       if (config < 0) {
+               count = config;
+       } else {
+               config |= 1 << 5;
+               it87_write_value(data, IT87_REG_CONFIG, config);
+               /* Invalidate cache to force re-read */
+               data->valid = 0;
+       }
+       mutex_unlock(&data->update_lock);
+
+       return count;
+}
+
 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
@@ -1188,6 +1214,8 @@ static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
+static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
+                         show_alarm, clear_intrusion, 4);
 
 static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
                char *buf)
@@ -1350,6 +1378,7 @@ static struct attribute *it87_attributes[] = {
        &sensor_dev_attr_temp3_alarm.dev_attr.attr,
 
        &dev_attr_alarms.attr,
+       &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
        &dev_attr_name.attr,
        NULL
 };