diff options
Diffstat (limited to 'drivers/hwmon/w83627ehf.c')
| -rw-r--r-- | drivers/hwmon/w83627ehf.c | 170 |
1 files changed, 166 insertions, 4 deletions
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index b6bd5685fd38..40301bc6ce18 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c | |||
| @@ -30,10 +30,7 @@ | |||
| 30 | Supports the following chips: | 30 | Supports the following chips: |
| 31 | 31 | ||
| 32 | Chip #vin #fan #pwm #temp chip_id man_id | 32 | Chip #vin #fan #pwm #temp chip_id man_id |
| 33 | w83627ehf - 5 - 3 0x88 0x5ca3 | 33 | w83627ehf 10 5 - 3 0x88 0x5ca3 |
| 34 | |||
| 35 | This is a preliminary version of the driver, only supporting the | ||
| 36 | fan and temperature inputs. The chip does much more than that. | ||
| 37 | */ | 34 | */ |
| 38 | 35 | ||
| 39 | #include <linux/module.h> | 36 | #include <linux/module.h> |
| @@ -121,6 +118,14 @@ superio_exit(void) | |||
| 121 | static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 }; | 118 | static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 }; |
| 122 | static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c }; | 119 | static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c }; |
| 123 | 120 | ||
| 121 | /* The W83627EHF registers for nr=7,8,9 are in bank 5 */ | ||
| 122 | #define W83627EHF_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \ | ||
| 123 | (0x554 + (((nr) - 7) * 2))) | ||
| 124 | #define W83627EHF_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \ | ||
| 125 | (0x555 + (((nr) - 7) * 2))) | ||
| 126 | #define W83627EHF_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ | ||
| 127 | (0x550 + (nr) - 7)) | ||
| 128 | |||
| 124 | #define W83627EHF_REG_TEMP1 0x27 | 129 | #define W83627EHF_REG_TEMP1 0x27 |
| 125 | #define W83627EHF_REG_TEMP1_HYST 0x3a | 130 | #define W83627EHF_REG_TEMP1_HYST 0x3a |
| 126 | #define W83627EHF_REG_TEMP1_OVER 0x39 | 131 | #define W83627EHF_REG_TEMP1_OVER 0x39 |
| @@ -136,6 +141,10 @@ static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0x152, 0x252 }; | |||
| 136 | #define W83627EHF_REG_DIODE 0x59 | 141 | #define W83627EHF_REG_DIODE 0x59 |
| 137 | #define W83627EHF_REG_SMI_OVT 0x4C | 142 | #define W83627EHF_REG_SMI_OVT 0x4C |
| 138 | 143 | ||
| 144 | #define W83627EHF_REG_ALARM1 0x459 | ||
| 145 | #define W83627EHF_REG_ALARM2 0x45A | ||
| 146 | #define W83627EHF_REG_ALARM3 0x45B | ||
| 147 | |||
| 139 | /* | 148 | /* |
| 140 | * Conversions | 149 | * Conversions |
| 141 | */ | 150 | */ |
| @@ -172,6 +181,20 @@ temp1_to_reg(int temp) | |||
| 172 | return (temp + 500) / 1000; | 181 | return (temp + 500) / 1000; |
| 173 | } | 182 | } |
| 174 | 183 | ||
| 184 | /* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */ | ||
| 185 | |||
| 186 | static u8 scale_in[10] = { 8, 8, 16, 16, 8, 8, 8, 16, 16, 8 }; | ||
| 187 | |||
| 188 | static inline long in_from_reg(u8 reg, u8 nr) | ||
| 189 | { | ||
| 190 | return reg * scale_in[nr]; | ||
| 191 | } | ||
| 192 | |||
| 193 | static inline u8 in_to_reg(u32 val, u8 nr) | ||
| 194 | { | ||
| 195 | return SENSORS_LIMIT(((val + (scale_in[nr] / 2)) / scale_in[nr]), 0, 255); | ||
| 196 | } | ||
| 197 | |||
| 175 | /* | 198 | /* |
| 176 | * Data structures and manipulation thereof | 199 | * Data structures and manipulation thereof |
| 177 | */ | 200 | */ |
| @@ -186,6 +209,9 @@ struct w83627ehf_data { | |||
| 186 | unsigned long last_updated; /* In jiffies */ | 209 | unsigned long last_updated; /* In jiffies */ |
| 187 | 210 | ||
| 188 | /* Register values */ | 211 | /* Register values */ |
| 212 | u8 in[10]; /* Register value */ | ||
| 213 | u8 in_max[10]; /* Register value */ | ||
| 214 | u8 in_min[10]; /* Register value */ | ||
| 189 | u8 fan[5]; | 215 | u8 fan[5]; |
| 190 | u8 fan_min[5]; | 216 | u8 fan_min[5]; |
| 191 | u8 fan_div[5]; | 217 | u8 fan_div[5]; |
| @@ -196,6 +222,7 @@ struct w83627ehf_data { | |||
| 196 | s16 temp[2]; | 222 | s16 temp[2]; |
| 197 | s16 temp_max[2]; | 223 | s16 temp_max[2]; |
| 198 | s16 temp_max_hyst[2]; | 224 | s16 temp_max_hyst[2]; |
| 225 | u32 alarms; | ||
| 199 | }; | 226 | }; |
| 200 | 227 | ||
| 201 | static inline int is_word_sized(u16 reg) | 228 | static inline int is_word_sized(u16 reg) |
| @@ -349,6 +376,16 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
| 349 | data->fan_div[3] |= (i >> 5) & 0x04; | 376 | data->fan_div[3] |= (i >> 5) & 0x04; |
| 350 | } | 377 | } |
| 351 | 378 | ||
| 379 | /* Measured voltages and limits */ | ||
| 380 | for (i = 0; i < 10; i++) { | ||
| 381 | data->in[i] = w83627ehf_read_value(client, | ||
| 382 | W83627EHF_REG_IN(i)); | ||
| 383 | data->in_min[i] = w83627ehf_read_value(client, | ||
| 384 | W83627EHF_REG_IN_MIN(i)); | ||
| 385 | data->in_max[i] = w83627ehf_read_value(client, | ||
| 386 | W83627EHF_REG_IN_MAX(i)); | ||
| 387 | } | ||
| 388 | |||
| 352 | /* Measured fan speeds and limits */ | 389 | /* Measured fan speeds and limits */ |
| 353 | for (i = 0; i < 5; i++) { | 390 | for (i = 0; i < 5; i++) { |
| 354 | if (!(data->has_fan & (1 << i))) | 391 | if (!(data->has_fan & (1 << i))) |
| @@ -395,6 +432,13 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
| 395 | W83627EHF_REG_TEMP_HYST[i]); | 432 | W83627EHF_REG_TEMP_HYST[i]); |
| 396 | } | 433 | } |
| 397 | 434 | ||
| 435 | data->alarms = w83627ehf_read_value(client, | ||
| 436 | W83627EHF_REG_ALARM1) | | ||
| 437 | (w83627ehf_read_value(client, | ||
| 438 | W83627EHF_REG_ALARM2) << 8) | | ||
| 439 | (w83627ehf_read_value(client, | ||
| 440 | W83627EHF_REG_ALARM3) << 16); | ||
| 441 | |||
| 398 | data->last_updated = jiffies; | 442 | data->last_updated = jiffies; |
| 399 | data->valid = 1; | 443 | data->valid = 1; |
| 400 | } | 444 | } |
| @@ -406,6 +450,109 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
| 406 | /* | 450 | /* |
| 407 | * Sysfs callback functions | 451 | * Sysfs callback functions |
| 408 | */ | 452 | */ |
| 453 | #define show_in_reg(reg) \ | ||
| 454 | static ssize_t \ | ||
| 455 | show_##reg(struct device *dev, struct device_attribute *attr, \ | ||
| 456 | char *buf) \ | ||
| 457 | { \ | ||
| 458 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ | ||
| 459 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ | ||
| 460 | int nr = sensor_attr->index; \ | ||
| 461 | return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr)); \ | ||
| 462 | } | ||
| 463 | show_in_reg(in) | ||
| 464 | show_in_reg(in_min) | ||
| 465 | show_in_reg(in_max) | ||
| 466 | |||
| 467 | #define store_in_reg(REG, reg) \ | ||
| 468 | static ssize_t \ | ||
| 469 | store_in_##reg (struct device *dev, struct device_attribute *attr, \ | ||
| 470 | const char *buf, size_t count) \ | ||
| 471 | { \ | ||
| 472 | struct i2c_client *client = to_i2c_client(dev); \ | ||
| 473 | struct w83627ehf_data *data = i2c_get_clientdata(client); \ | ||
| 474 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ | ||
| 475 | int nr = sensor_attr->index; \ | ||
| 476 | u32 val = simple_strtoul(buf, NULL, 10); \ | ||
| 477 | \ | ||
| 478 | mutex_lock(&data->update_lock); \ | ||
| 479 | data->in_##reg[nr] = in_to_reg(val, nr); \ | ||
| 480 | w83627ehf_write_value(client, W83627EHF_REG_IN_##REG(nr), \ | ||
| 481 | data->in_##reg[nr]); \ | ||
| 482 | mutex_unlock(&data->update_lock); \ | ||
| 483 | return count; \ | ||
| 484 | } | ||
| 485 | |||
| 486 | store_in_reg(MIN, min) | ||
| 487 | store_in_reg(MAX, max) | ||
| 488 | |||
| 489 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 490 | { | ||
| 491 | struct w83627ehf_data *data = w83627ehf_update_device(dev); | ||
| 492 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
| 493 | int nr = sensor_attr->index; | ||
| 494 | return sprintf(buf, "%u\n", (data->alarms >> nr) & 0x01); | ||
| 495 | } | ||
| 496 | |||
| 497 | static struct sensor_device_attribute sda_in_input[] = { | ||
| 498 | SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0), | ||
| 499 | SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1), | ||
| 500 | SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2), | ||
| 501 | SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3), | ||
| 502 | SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4), | ||
| 503 | SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5), | ||
| 504 | SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6), | ||
| 505 | SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7), | ||
| 506 | SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8), | ||
| 507 | SENSOR_ATTR(in9_input, S_IRUGO, show_in, NULL, 9), | ||
| 508 | }; | ||
| 509 | |||
| 510 | static struct sensor_device_attribute sda_in_alarm[] = { | ||
| 511 | SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0), | ||
| 512 | SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1), | ||
| 513 | SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2), | ||
| 514 | SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3), | ||
| 515 | SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8), | ||
| 516 | SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 21), | ||
| 517 | SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 20), | ||
| 518 | SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16), | ||
| 519 | SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17), | ||
| 520 | SENSOR_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 19), | ||
| 521 | }; | ||
| 522 | |||
| 523 | static struct sensor_device_attribute sda_in_min[] = { | ||
| 524 | SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0), | ||
| 525 | SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1), | ||
| 526 | SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2), | ||
| 527 | SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3), | ||
| 528 | SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4), | ||
| 529 | SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5), | ||
| 530 | SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6), | ||
| 531 | SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7), | ||
| 532 | SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8), | ||
| 533 | SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 9), | ||
| 534 | }; | ||
| 535 | |||
| 536 | static struct sensor_device_attribute sda_in_max[] = { | ||
| 537 | SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0), | ||
| 538 | SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1), | ||
| 539 | SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2), | ||
| 540 | SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3), | ||
| 541 | SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4), | ||
| 542 | SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5), | ||
| 543 | SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6), | ||
| 544 | SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7), | ||
| 545 | SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8), | ||
| 546 | SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9), | ||
| 547 | }; | ||
| 548 | |||
| 549 | static void device_create_file_in(struct device *dev, int i) | ||
| 550 | { | ||
| 551 | device_create_file(dev, &sda_in_input[i].dev_attr); | ||
| 552 | device_create_file(dev, &sda_in_alarm[i].dev_attr); | ||
| 553 | device_create_file(dev, &sda_in_min[i].dev_attr); | ||
| 554 | device_create_file(dev, &sda_in_max[i].dev_attr); | ||
| 555 | } | ||
| 409 | 556 | ||
| 410 | #define show_fan_reg(reg) \ | 557 | #define show_fan_reg(reg) \ |
| 411 | static ssize_t \ | 558 | static ssize_t \ |
| @@ -505,6 +652,14 @@ static struct sensor_device_attribute sda_fan_input[] = { | |||
| 505 | SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4), | 652 | SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4), |
| 506 | }; | 653 | }; |
| 507 | 654 | ||
| 655 | static struct sensor_device_attribute sda_fan_alarm[] = { | ||
| 656 | SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6), | ||
| 657 | SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7), | ||
| 658 | SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11), | ||
| 659 | SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 10), | ||
| 660 | SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 23), | ||
| 661 | }; | ||
| 662 | |||
| 508 | static struct sensor_device_attribute sda_fan_min[] = { | 663 | static struct sensor_device_attribute sda_fan_min[] = { |
| 509 | SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, | 664 | SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 510 | store_fan_min, 0), | 665 | store_fan_min, 0), |
| @@ -529,6 +684,7 @@ static struct sensor_device_attribute sda_fan_div[] = { | |||
| 529 | static void device_create_file_fan(struct device *dev, int i) | 684 | static void device_create_file_fan(struct device *dev, int i) |
| 530 | { | 685 | { |
| 531 | device_create_file(dev, &sda_fan_input[i].dev_attr); | 686 | device_create_file(dev, &sda_fan_input[i].dev_attr); |
| 687 | device_create_file(dev, &sda_fan_alarm[i].dev_attr); | ||
| 532 | device_create_file(dev, &sda_fan_div[i].dev_attr); | 688 | device_create_file(dev, &sda_fan_div[i].dev_attr); |
| 533 | device_create_file(dev, &sda_fan_min[i].dev_attr); | 689 | device_create_file(dev, &sda_fan_min[i].dev_attr); |
| 534 | } | 690 | } |
| @@ -616,6 +772,9 @@ static struct sensor_device_attribute sda_temp[] = { | |||
| 616 | store_temp_max_hyst, 0), | 772 | store_temp_max_hyst, 0), |
| 617 | SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, | 773 | SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
| 618 | store_temp_max_hyst, 1), | 774 | store_temp_max_hyst, 1), |
| 775 | SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4), | ||
| 776 | SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5), | ||
| 777 | SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), | ||
| 619 | }; | 778 | }; |
| 620 | 779 | ||
| 621 | /* | 780 | /* |
| @@ -705,6 +864,9 @@ static int w83627ehf_detect(struct i2c_adapter *adapter) | |||
| 705 | goto exit_detach; | 864 | goto exit_detach; |
| 706 | } | 865 | } |
| 707 | 866 | ||
| 867 | for (i = 0; i < 10; i++) | ||
| 868 | device_create_file_in(dev, i); | ||
| 869 | |||
| 708 | for (i = 0; i < 5; i++) { | 870 | for (i = 0; i < 5; i++) { |
| 709 | if (data->has_fan & (1 << i)) | 871 | if (data->has_fan & (1 << i)) |
| 710 | device_create_file_fan(dev, i); | 872 | device_create_file_fan(dev, i); |
