Commit 2d45771e6ea79f56a7d85e448f702f60ef86c228

Authored by Jean Delvare
Committed by Greg Kroah-Hartman
1 parent 51bd563393

hwmon: Add individual alarm files to 4 drivers

hwmon: Add individual alarm files to 4 drivers

Add individual sysfs files for all f71805f, lm63, lm83 and lm90 alarm
and fault conditions. This is a requirement for the planned
chip-independent libsensors. Almost all other hwmon drivers will need
the same improvement.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 4 changed files with 151 additions and 14 deletions Side-by-side Diff

drivers/hwmon/f71805f.c
1 1 /*
2 2 * f71805f.c - driver for the Fintek F71805F/FG Super-I/O chip integrated
3 3 * hardware monitoring features
4   - * Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
  4 + * Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
5 5 *
6 6 * The F71805F/FG is a LPC Super-I/O chip made by Fintek. It integrates
7 7 * complete hardware monitoring features: voltage, fan and temperature
... ... @@ -147,7 +147,7 @@
147 147 u8 temp_high[3];
148 148 u8 temp_hyst[3];
149 149 u8 temp_mode;
150   - u8 alarms[3];
  150 + unsigned long alarms;
151 151 };
152 152  
153 153 static inline long in_from_reg(u8 reg)
... ... @@ -311,10 +311,9 @@
311 311 data->temp[nr] = f71805f_read8(data,
312 312 F71805F_REG_TEMP(nr));
313 313 }
314   - for (nr = 0; nr < 3; nr++) {
315   - data->alarms[nr] = f71805f_read8(data,
316   - F71805F_REG_STATUS(nr));
317   - }
  314 + data->alarms = f71805f_read8(data, F71805F_REG_STATUS(0))
  315 + + (f71805f_read8(data, F71805F_REG_STATUS(1)) << 8)
  316 + + (f71805f_read8(data, F71805F_REG_STATUS(2)) << 16);
318 317  
319 318 data->last_updated = jiffies;
320 319 data->valid = 1;
... ... @@ -557,8 +556,7 @@
557 556 {
558 557 struct f71805f_data *data = f71805f_update_device(dev);
559 558  
560   - return sprintf(buf, "%d\n", data->alarms[0] |
561   - ((data->alarms[1] & 0x01) << 8));
  559 + return sprintf(buf, "%lu\n", data->alarms & 0x1ff);
562 560 }
563 561  
564 562 static ssize_t show_alarms_fan(struct device *dev, struct device_attribute
... ... @@ -566,7 +564,7 @@
566 564 {
567 565 struct f71805f_data *data = f71805f_update_device(dev);
568 566  
569   - return sprintf(buf, "%d\n", data->alarms[2] & 0x07);
  567 + return sprintf(buf, "%lu\n", (data->alarms >> 16) & 0x07);
570 568 }
571 569  
572 570 static ssize_t show_alarms_temp(struct device *dev, struct device_attribute
573 571  
... ... @@ -574,9 +572,19 @@
574 572 {
575 573 struct f71805f_data *data = f71805f_update_device(dev);
576 574  
577   - return sprintf(buf, "%d\n", (data->alarms[1] >> 3) & 0x07);
  575 + return sprintf(buf, "%lu\n", (data->alarms >> 11) & 0x07);
578 576 }
579 577  
  578 +static ssize_t show_alarm(struct device *dev, struct device_attribute
  579 + *devattr, char *buf)
  580 +{
  581 + struct f71805f_data *data = f71805f_update_device(dev);
  582 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  583 + int bitnr = attr->index;
  584 +
  585 + return sprintf(buf, "%lu\n", (data->alarms >> bitnr) & 1);
  586 +}
  587 +
580 588 static ssize_t show_name(struct device *dev, struct device_attribute
581 589 *devattr, char *buf)
582 590 {
583 591  
584 592  
585 593  
... ... @@ -655,18 +663,34 @@
655 663 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
656 664 show_temp_hyst, set_temp_hyst, 2),
657 665 SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
  666 +
  667 + SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0),
  668 + SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1),
  669 + SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2),
  670 + SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3),
  671 + SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4),
  672 + SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5),
  673 + SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6),
  674 + SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7),
  675 + SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8),
  676 + SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 11),
  677 + SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 12),
  678 + SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13),
658 679 };
659 680  
660 681 static struct sensor_device_attribute f71805f_fan_attr[] = {
661 682 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0),
662 683 SENSOR_ATTR(fan1_min, S_IRUGO | S_IWUSR,
663 684 show_fan_min, set_fan_min, 0),
  685 + SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16),
664 686 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1),
665 687 SENSOR_ATTR(fan2_min, S_IRUGO | S_IWUSR,
666 688 show_fan_min, set_fan_min, 1),
  689 + SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17),
667 690 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2),
668 691 SENSOR_ATTR(fan3_min, S_IRUGO | S_IWUSR,
669 692 show_fan_min, set_fan_min, 2),
  693 + SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18),
670 694 };
671 695  
672 696 /*
... ... @@ -737,7 +761,7 @@
737 761 goto exit_class;
738 762 }
739 763 for (i = 0; i < ARRAY_SIZE(f71805f_fan_attr); i++) {
740   - if (!(data->fan_enabled & (1 << (i / 2))))
  764 + if (!(data->fan_enabled & (1 << (i / 3))))
741 765 continue;
742 766 err = device_create_file(&pdev->dev,
743 767 &f71805f_fan_attr[i].dev_attr);
drivers/hwmon/lm63.c
1 1 /*
2 2 * lm63.c - driver for the National Semiconductor LM63 temperature sensor
3 3 * with integrated fan control
4   - * Copyright (C) 2004-2005 Jean Delvare <khali@linux-fr.org>
  4 + * Copyright (C) 2004-2006 Jean Delvare <khali@linux-fr.org>
5 5 * Based on the lm90 driver.
6 6 *
7 7 * The LM63 is a sensor chip made by National Semiconductor. It measures
... ... @@ -330,6 +330,16 @@
330 330 return sprintf(buf, "%u\n", data->alarms);
331 331 }
332 332  
  333 +static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr,
  334 + char *buf)
  335 +{
  336 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  337 + struct lm63_data *data = lm63_update_device(dev);
  338 + int bitnr = attr->index;
  339 +
  340 + return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
  341 +}
  342 +
333 343 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
334 344 static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan,
335 345 set_fan, 1);
... ... @@ -350,6 +360,14 @@
350 360 static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst,
351 361 set_temp2_crit_hyst);
352 362  
  363 +/* Individual alarm files */
  364 +static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
  365 +static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
  366 +static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2);
  367 +static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
  368 +static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
  369 +static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
  370 +/* Raw alarm file for compatibility */
353 371 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
354 372  
355 373 /*
... ... @@ -449,6 +467,8 @@
449 467 &sensor_dev_attr_fan1_input.dev_attr);
450 468 device_create_file(&new_client->dev,
451 469 &sensor_dev_attr_fan1_min.dev_attr);
  470 + device_create_file(&new_client->dev,
  471 + &sensor_dev_attr_fan1_min_alarm.dev_attr);
452 472 }
453 473 device_create_file(&new_client->dev, &dev_attr_pwm1);
454 474 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
... ... @@ -465,6 +485,17 @@
465 485 device_create_file(&new_client->dev,
466 486 &sensor_dev_attr_temp2_crit.dev_attr);
467 487 device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
  488 +
  489 + device_create_file(&new_client->dev,
  490 + &sensor_dev_attr_temp2_input_fault.dev_attr);
  491 + device_create_file(&new_client->dev,
  492 + &sensor_dev_attr_temp2_min_alarm.dev_attr);
  493 + device_create_file(&new_client->dev,
  494 + &sensor_dev_attr_temp1_max_alarm.dev_attr);
  495 + device_create_file(&new_client->dev,
  496 + &sensor_dev_attr_temp2_max_alarm.dev_attr);
  497 + device_create_file(&new_client->dev,
  498 + &sensor_dev_attr_temp2_crit_alarm.dev_attr);
468 499 device_create_file(&new_client->dev, &dev_attr_alarms);
469 500  
470 501 return 0;
drivers/hwmon/lm83.c
1 1 /*
2 2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware
3 3 * monitoring
4   - * Copyright (C) 2003-2005 Jean Delvare <khali@linux-fr.org>
  4 + * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org>
5 5 *
6 6 * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is
7 7 * a sensor chip made by National Semiconductor. It reports up to four
... ... @@ -191,6 +191,16 @@
191 191 return sprintf(buf, "%d\n", data->alarms);
192 192 }
193 193  
  194 +static ssize_t show_alarm(struct device *dev, struct device_attribute
  195 + *devattr, char *buf)
  196 +{
  197 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  198 + struct lm83_data *data = lm83_update_device(dev);
  199 + int bitnr = attr->index;
  200 +
  201 + return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
  202 +}
  203 +
194 204 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
195 205 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
196 206 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
... ... @@ -208,6 +218,20 @@
208 218 static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp,
209 219 set_temp, 8);
210 220 static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp, NULL, 8);
  221 +
  222 +/* Individual alarm files */
  223 +static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
  224 +static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
  225 +static SENSOR_DEVICE_ATTR(temp3_input_fault, S_IRUGO, show_alarm, NULL, 2);
  226 +static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4);
  227 +static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
  228 +static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 8);
  229 +static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO, show_alarm, NULL, 9);
  230 +static SENSOR_DEVICE_ATTR(temp4_input_fault, S_IRUGO, show_alarm, NULL, 10);
  231 +static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 12);
  232 +static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 13);
  233 +static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 15);
  234 +/* Raw alarm file for compatibility */
211 235 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
212 236  
213 237 /*
... ... @@ -350,6 +374,16 @@
350 374 device_create_file(&new_client->dev,
351 375 &sensor_dev_attr_temp3_crit.dev_attr);
352 376  
  377 + device_create_file(&new_client->dev,
  378 + &sensor_dev_attr_temp3_input_fault.dev_attr);
  379 + device_create_file(&new_client->dev,
  380 + &sensor_dev_attr_temp1_max_alarm.dev_attr);
  381 + device_create_file(&new_client->dev,
  382 + &sensor_dev_attr_temp3_max_alarm.dev_attr);
  383 + device_create_file(&new_client->dev,
  384 + &sensor_dev_attr_temp1_crit_alarm.dev_attr);
  385 + device_create_file(&new_client->dev,
  386 + &sensor_dev_attr_temp3_crit_alarm.dev_attr);
353 387 device_create_file(&new_client->dev, &dev_attr_alarms);
354 388  
355 389 if (kind == lm83) {
... ... @@ -367,6 +401,19 @@
367 401 &sensor_dev_attr_temp2_crit.dev_attr);
368 402 device_create_file(&new_client->dev,
369 403 &sensor_dev_attr_temp4_crit.dev_attr);
  404 +
  405 + device_create_file(&new_client->dev,
  406 + &sensor_dev_attr_temp2_input_fault.dev_attr);
  407 + device_create_file(&new_client->dev,
  408 + &sensor_dev_attr_temp4_input_fault.dev_attr);
  409 + device_create_file(&new_client->dev,
  410 + &sensor_dev_attr_temp2_max_alarm.dev_attr);
  411 + device_create_file(&new_client->dev,
  412 + &sensor_dev_attr_temp4_max_alarm.dev_attr);
  413 + device_create_file(&new_client->dev,
  414 + &sensor_dev_attr_temp2_crit_alarm.dev_attr);
  415 + device_create_file(&new_client->dev,
  416 + &sensor_dev_attr_temp4_crit_alarm.dev_attr);
370 417 }
371 418  
372 419 return 0;
drivers/hwmon/lm90.c
1 1 /*
2 2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
3 3 * monitoring
4   - * Copyright (C) 2003-2005 Jean Delvare <khali@linux-fr.org>
  4 + * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org>
5 5 *
6 6 * Based on the lm83 driver. The LM90 is a sensor chip made by National
7 7 * Semiconductor. It reports up to two temperatures (its own plus up to
... ... @@ -327,6 +327,16 @@
327 327 return sprintf(buf, "%d\n", data->alarms);
328 328 }
329 329  
  330 +static ssize_t show_alarm(struct device *dev, struct device_attribute
  331 + *devattr, char *buf)
  332 +{
  333 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  334 + struct lm90_data *data = lm90_update_device(dev);
  335 + int bitnr = attr->index;
  336 +
  337 + return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
  338 +}
  339 +
330 340 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp8, NULL, 0);
331 341 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0);
332 342 static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8,
... ... @@ -344,6 +354,16 @@
344 354 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
345 355 set_temphyst, 3);
346 356 static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4);
  357 +
  358 +/* Individual alarm files */
  359 +static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
  360 +static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
  361 +static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2);
  362 +static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
  363 +static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
  364 +static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5);
  365 +static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
  366 +/* Raw alarm file for compatibility */
347 367 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
348 368  
349 369 /* pec used for ADM1032 only */
... ... @@ -595,6 +615,21 @@
595 615 &sensor_dev_attr_temp1_crit_hyst.dev_attr);
596 616 device_create_file(&new_client->dev,
597 617 &sensor_dev_attr_temp2_crit_hyst.dev_attr);
  618 +
  619 + device_create_file(&new_client->dev,
  620 + &sensor_dev_attr_temp2_input_fault.dev_attr);
  621 + device_create_file(&new_client->dev,
  622 + &sensor_dev_attr_temp1_min_alarm.dev_attr);
  623 + device_create_file(&new_client->dev,
  624 + &sensor_dev_attr_temp2_min_alarm.dev_attr);
  625 + device_create_file(&new_client->dev,
  626 + &sensor_dev_attr_temp1_max_alarm.dev_attr);
  627 + device_create_file(&new_client->dev,
  628 + &sensor_dev_attr_temp2_max_alarm.dev_attr);
  629 + device_create_file(&new_client->dev,
  630 + &sensor_dev_attr_temp1_crit_alarm.dev_attr);
  631 + device_create_file(&new_client->dev,
  632 + &sensor_dev_attr_temp2_crit_alarm.dev_attr);
598 633 device_create_file(&new_client->dev, &dev_attr_alarms);
599 634  
600 635 if (new_client->flags & I2C_CLIENT_PEC)