Commit 0de2b244800b2c0d88d0a85bbe4a0b95fee13332

Authored by Jean Delvare
Committed by Jean Delvare
1 parent f790674d3f

hwmon: (adm9240) Implement the standard intrusion detection interface

We have a standard intrusion detection interface now, drivers should
implement it. I've left the old interface in place for the time being,
with a deprecation warning, it will be removed later.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>

Showing 2 changed files with 30 additions and 4 deletions Side-by-side Diff

Documentation/hwmon/adm9240
... ... @@ -155,7 +155,7 @@
155 155 The ADM9240 provides an internal open drain on this line, and may output
156 156 a 20 ms active low pulse to reset an external Chassis Intrusion latch.
157 157  
158   -Clear the CI latch by writing value 1 to the sysfs chassis_clear file.
  158 +Clear the CI latch by writing value 0 to the sysfs intrusion0_alarm file.
159 159  
160 160 Alarm flags reported as 16-bit word
161 161  
drivers/hwmon/adm9240.c
... ... @@ -20,7 +20,7 @@
20 20 * Alarms 16-bit map of active alarms
21 21 * Analog Out 0..1250 mV output
22 22 *
23   - * Chassis Intrusion: clear CI latch with 'echo 1 > chassis_clear'
  23 + * Chassis Intrusion: clear CI latch with 'echo 0 > intrusion0_alarm'
24 24 *
25 25 * Test hardware: Intel SE440BX-2 desktop motherboard --Grant
26 26 *
27 27  
... ... @@ -476,13 +476,16 @@
476 476 static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
477 477  
478 478 /* chassis_clear */
479   -static ssize_t chassis_clear(struct device *dev,
  479 +static ssize_t chassis_clear_legacy(struct device *dev,
480 480 struct device_attribute *attr,
481 481 const char *buf, size_t count)
482 482 {
483 483 struct i2c_client *client = to_i2c_client(dev);
484 484 unsigned long val = simple_strtol(buf, NULL, 10);
485 485  
  486 + dev_warn(dev, "Attribute chassis_clear is deprecated, "
  487 + "use intrusion0_alarm instead\n");
  488 +
486 489 if (val == 1) {
487 490 i2c_smbus_write_byte_data(client,
488 491 ADM9240_REG_CHASSIS_CLEAR, 0x80);
489 492  
... ... @@ -490,8 +493,30 @@
490 493 }
491 494 return count;
492 495 }
493   -static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear);
  496 +static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear_legacy);
494 497  
  498 +static ssize_t chassis_clear(struct device *dev,
  499 + struct device_attribute *attr,
  500 + const char *buf, size_t count)
  501 +{
  502 + struct i2c_client *client = to_i2c_client(dev);
  503 + struct adm9240_data *data = i2c_get_clientdata(client);
  504 + unsigned long val;
  505 +
  506 + if (strict_strtoul(buf, 10, &val) || val != 0)
  507 + return -EINVAL;
  508 +
  509 + mutex_lock(&data->update_lock);
  510 + i2c_smbus_write_byte_data(client, ADM9240_REG_CHASSIS_CLEAR, 0x80);
  511 + data->valid = 0; /* Force cache refresh */
  512 + mutex_unlock(&data->update_lock);
  513 + dev_dbg(&client->dev, "chassis intrusion latch cleared\n");
  514 +
  515 + return count;
  516 +}
  517 +static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm,
  518 + chassis_clear, 12);
  519 +
495 520 static struct attribute *adm9240_attributes[] = {
496 521 &sensor_dev_attr_in0_input.dev_attr.attr,
497 522 &sensor_dev_attr_in0_min.dev_attr.attr,
... ... @@ -532,6 +557,7 @@
532 557 &dev_attr_alarms.attr,
533 558 &dev_attr_aout_output.attr,
534 559 &dev_attr_chassis_clear.attr,
  560 + &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
535 561 &dev_attr_cpu0_vid.attr,
536 562 NULL
537 563 };