diff options
Diffstat (limited to 'drivers/hwmon/it87.c')
-rw-r--r-- | drivers/hwmon/it87.c | 918 |
1 files changed, 479 insertions, 439 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index d32aa354cbdf..117d66fcded6 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -203,6 +203,8 @@ static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 }; | |||
203 | static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 }; | 203 | static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 }; |
204 | static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 }; | 204 | static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 }; |
205 | static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 }; | 205 | static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 }; |
206 | static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 }; | ||
207 | |||
206 | #define IT87_REG_FAN_MAIN_CTRL 0x13 | 208 | #define IT87_REG_FAN_MAIN_CTRL 0x13 |
207 | #define IT87_REG_FAN_CTL 0x14 | 209 | #define IT87_REG_FAN_CTL 0x14 |
208 | #define IT87_REG_PWM(nr) (0x15 + (nr)) | 210 | #define IT87_REG_PWM(nr) (0x15 + (nr)) |
@@ -226,6 +228,83 @@ static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 }; | |||
226 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) | 228 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) |
227 | #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) | 229 | #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) |
228 | 230 | ||
231 | struct it87_devices { | ||
232 | const char *name; | ||
233 | u16 features; | ||
234 | u8 peci_mask; | ||
235 | u8 old_peci_mask; | ||
236 | }; | ||
237 | |||
238 | #define FEAT_12MV_ADC (1 << 0) | ||
239 | #define FEAT_NEWER_AUTOPWM (1 << 1) | ||
240 | #define FEAT_OLD_AUTOPWM (1 << 2) | ||
241 | #define FEAT_16BIT_FANS (1 << 3) | ||
242 | #define FEAT_TEMP_OFFSET (1 << 4) | ||
243 | #define FEAT_TEMP_PECI (1 << 5) | ||
244 | #define FEAT_TEMP_OLD_PECI (1 << 6) | ||
245 | |||
246 | static const struct it87_devices it87_devices[] = { | ||
247 | [it87] = { | ||
248 | .name = "it87", | ||
249 | .features = FEAT_OLD_AUTOPWM, /* may need to overwrite */ | ||
250 | }, | ||
251 | [it8712] = { | ||
252 | .name = "it8712", | ||
253 | .features = FEAT_OLD_AUTOPWM, /* may need to overwrite */ | ||
254 | }, | ||
255 | [it8716] = { | ||
256 | .name = "it8716", | ||
257 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET, | ||
258 | }, | ||
259 | [it8718] = { | ||
260 | .name = "it8718", | ||
261 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | ||
262 | | FEAT_TEMP_OLD_PECI, | ||
263 | .old_peci_mask = 0x4, | ||
264 | }, | ||
265 | [it8720] = { | ||
266 | .name = "it8720", | ||
267 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | ||
268 | | FEAT_TEMP_OLD_PECI, | ||
269 | .old_peci_mask = 0x4, | ||
270 | }, | ||
271 | [it8721] = { | ||
272 | .name = "it8721", | ||
273 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS | ||
274 | | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI, | ||
275 | .peci_mask = 0x05, | ||
276 | .old_peci_mask = 0x02, /* Actually reports PCH */ | ||
277 | }, | ||
278 | [it8728] = { | ||
279 | .name = "it8728", | ||
280 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS | ||
281 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI, | ||
282 | .peci_mask = 0x07, | ||
283 | }, | ||
284 | [it8782] = { | ||
285 | .name = "it8782", | ||
286 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | ||
287 | | FEAT_TEMP_OLD_PECI, | ||
288 | .old_peci_mask = 0x4, | ||
289 | }, | ||
290 | [it8783] = { | ||
291 | .name = "it8783", | ||
292 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | ||
293 | | FEAT_TEMP_OLD_PECI, | ||
294 | .old_peci_mask = 0x4, | ||
295 | }, | ||
296 | }; | ||
297 | |||
298 | #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS) | ||
299 | #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC) | ||
300 | #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM) | ||
301 | #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM) | ||
302 | #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET) | ||
303 | #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \ | ||
304 | ((data)->peci_mask & (1 << nr))) | ||
305 | #define has_temp_old_peci(data, nr) \ | ||
306 | (((data)->features & FEAT_TEMP_OLD_PECI) && \ | ||
307 | ((data)->old_peci_mask & (1 << nr))) | ||
229 | 308 | ||
230 | struct it87_sio_data { | 309 | struct it87_sio_data { |
231 | enum chips type; | 310 | enum chips type; |
@@ -249,7 +328,9 @@ struct it87_sio_data { | |||
249 | struct it87_data { | 328 | struct it87_data { |
250 | struct device *hwmon_dev; | 329 | struct device *hwmon_dev; |
251 | enum chips type; | 330 | enum chips type; |
252 | u8 revision; | 331 | u16 features; |
332 | u8 peci_mask; | ||
333 | u8 old_peci_mask; | ||
253 | 334 | ||
254 | unsigned short addr; | 335 | unsigned short addr; |
255 | const char *name; | 336 | const char *name; |
@@ -258,17 +339,13 @@ struct it87_data { | |||
258 | unsigned long last_updated; /* In jiffies */ | 339 | unsigned long last_updated; /* In jiffies */ |
259 | 340 | ||
260 | u16 in_scaled; /* Internal voltage sensors are scaled */ | 341 | u16 in_scaled; /* Internal voltage sensors are scaled */ |
261 | u8 in[9]; /* Register value */ | 342 | u8 in[9][3]; /* [nr][0]=in, [1]=min, [2]=max */ |
262 | u8 in_max[8]; /* Register value */ | ||
263 | u8 in_min[8]; /* Register value */ | ||
264 | u8 has_fan; /* Bitfield, fans enabled */ | 343 | u8 has_fan; /* Bitfield, fans enabled */ |
265 | u16 fan[5]; /* Register values, possibly combined */ | 344 | u16 fan[5][2]; /* Register values, [nr][0]=fan, [1]=min */ |
266 | u16 fan_min[5]; /* Register values, possibly combined */ | ||
267 | u8 has_temp; /* Bitfield, temp sensors enabled */ | 345 | u8 has_temp; /* Bitfield, temp sensors enabled */ |
268 | s8 temp[3]; /* Register value */ | 346 | s8 temp[3][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */ |
269 | s8 temp_high[3]; /* Register value */ | 347 | u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */ |
270 | s8 temp_low[3]; /* Register value */ | 348 | u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */ |
271 | u8 sensor; /* Register value */ | ||
272 | u8 fan_div[3]; /* Register encoding, shifted right */ | 349 | u8 fan_div[3]; /* Register encoding, shifted right */ |
273 | u8 vid; /* Register encoding, combined */ | 350 | u8 vid; /* Register encoding, combined */ |
274 | u8 vrm; | 351 | u8 vrm; |
@@ -296,26 +373,6 @@ struct it87_data { | |||
296 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ | 373 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ |
297 | }; | 374 | }; |
298 | 375 | ||
299 | static inline int has_12mv_adc(const struct it87_data *data) | ||
300 | { | ||
301 | /* | ||
302 | * IT8721F and later have a 12 mV ADC, also with internal scaling | ||
303 | * on selected inputs. | ||
304 | */ | ||
305 | return data->type == it8721 | ||
306 | || data->type == it8728; | ||
307 | } | ||
308 | |||
309 | static inline int has_newer_autopwm(const struct it87_data *data) | ||
310 | { | ||
311 | /* | ||
312 | * IT8721F and later have separate registers for the temperature | ||
313 | * mapping and the manual duty cycle. | ||
314 | */ | ||
315 | return data->type == it8721 | ||
316 | || data->type == it8728; | ||
317 | } | ||
318 | |||
319 | static int adc_lsb(const struct it87_data *data, int nr) | 376 | static int adc_lsb(const struct it87_data *data, int nr) |
320 | { | 377 | { |
321 | int lsb = has_12mv_adc(data) ? 12 : 16; | 378 | int lsb = has_12mv_adc(data) ? 12 : 16; |
@@ -398,35 +455,6 @@ static const unsigned int pwm_freq[8] = { | |||
398 | 750000 / 128, | 455 | 750000 / 128, |
399 | }; | 456 | }; |
400 | 457 | ||
401 | static inline int has_16bit_fans(const struct it87_data *data) | ||
402 | { | ||
403 | /* | ||
404 | * IT8705F Datasheet 0.4.1, 3h == Version G. | ||
405 | * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J. | ||
406 | * These are the first revisions with 16-bit tachometer support. | ||
407 | */ | ||
408 | return (data->type == it87 && data->revision >= 0x03) | ||
409 | || (data->type == it8712 && data->revision >= 0x08) | ||
410 | || data->type == it8716 | ||
411 | || data->type == it8718 | ||
412 | || data->type == it8720 | ||
413 | || data->type == it8721 | ||
414 | || data->type == it8728 | ||
415 | || data->type == it8782 | ||
416 | || data->type == it8783; | ||
417 | } | ||
418 | |||
419 | static inline int has_old_autopwm(const struct it87_data *data) | ||
420 | { | ||
421 | /* | ||
422 | * The old automatic fan speed control interface is implemented | ||
423 | * by IT8705F chips up to revision F and IT8712F chips up to | ||
424 | * revision G. | ||
425 | */ | ||
426 | return (data->type == it87 && data->revision < 0x03) | ||
427 | || (data->type == it8712 && data->revision < 0x08); | ||
428 | } | ||
429 | |||
430 | static int it87_probe(struct platform_device *pdev); | 458 | static int it87_probe(struct platform_device *pdev); |
431 | static int it87_remove(struct platform_device *pdev); | 459 | static int it87_remove(struct platform_device *pdev); |
432 | 460 | ||
@@ -447,59 +475,22 @@ static struct platform_driver it87_driver = { | |||
447 | }; | 475 | }; |
448 | 476 | ||
449 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, | 477 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
450 | char *buf) | 478 | char *buf) |
451 | { | ||
452 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
453 | int nr = sensor_attr->index; | ||
454 | |||
455 | struct it87_data *data = it87_update_device(dev); | ||
456 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr])); | ||
457 | } | ||
458 | |||
459 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, | ||
460 | char *buf) | ||
461 | { | 479 | { |
462 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 480 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
463 | int nr = sensor_attr->index; | 481 | int nr = sattr->nr; |
482 | int index = sattr->index; | ||
464 | 483 | ||
465 | struct it87_data *data = it87_update_device(dev); | 484 | struct it87_data *data = it87_update_device(dev); |
466 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in_min[nr])); | 485 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index])); |
467 | } | 486 | } |
468 | 487 | ||
469 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, | 488 | static ssize_t set_in(struct device *dev, struct device_attribute *attr, |
470 | char *buf) | 489 | const char *buf, size_t count) |
471 | { | ||
472 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
473 | int nr = sensor_attr->index; | ||
474 | |||
475 | struct it87_data *data = it87_update_device(dev); | ||
476 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in_max[nr])); | ||
477 | } | ||
478 | |||
479 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | ||
480 | const char *buf, size_t count) | ||
481 | { | ||
482 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
483 | int nr = sensor_attr->index; | ||
484 | |||
485 | struct it87_data *data = dev_get_drvdata(dev); | ||
486 | unsigned long val; | ||
487 | |||
488 | if (kstrtoul(buf, 10, &val) < 0) | ||
489 | return -EINVAL; | ||
490 | |||
491 | mutex_lock(&data->update_lock); | ||
492 | data->in_min[nr] = in_to_reg(data, nr, val); | ||
493 | it87_write_value(data, IT87_REG_VIN_MIN(nr), | ||
494 | data->in_min[nr]); | ||
495 | mutex_unlock(&data->update_lock); | ||
496 | return count; | ||
497 | } | ||
498 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | ||
499 | const char *buf, size_t count) | ||
500 | { | 490 | { |
501 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 491 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
502 | int nr = sensor_attr->index; | 492 | int nr = sattr->nr; |
493 | int index = sattr->index; | ||
503 | 494 | ||
504 | struct it87_data *data = dev_get_drvdata(dev); | 495 | struct it87_data *data = dev_get_drvdata(dev); |
505 | unsigned long val; | 496 | unsigned long val; |
@@ -508,140 +499,167 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
508 | return -EINVAL; | 499 | return -EINVAL; |
509 | 500 | ||
510 | mutex_lock(&data->update_lock); | 501 | mutex_lock(&data->update_lock); |
511 | data->in_max[nr] = in_to_reg(data, nr, val); | 502 | data->in[nr][index] = in_to_reg(data, nr, val); |
512 | it87_write_value(data, IT87_REG_VIN_MAX(nr), | 503 | it87_write_value(data, |
513 | data->in_max[nr]); | 504 | index == 1 ? IT87_REG_VIN_MIN(nr) |
505 | : IT87_REG_VIN_MAX(nr), | ||
506 | data->in[nr][index]); | ||
514 | mutex_unlock(&data->update_lock); | 507 | mutex_unlock(&data->update_lock); |
515 | return count; | 508 | return count; |
516 | } | 509 | } |
517 | 510 | ||
518 | #define show_in_offset(offset) \ | 511 | static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0); |
519 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ | 512 | static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in, |
520 | show_in, NULL, offset); | 513 | 0, 1); |
521 | 514 | static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in, | |
522 | #define limit_in_offset(offset) \ | 515 | 0, 2); |
523 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | 516 | |
524 | show_in_min, set_in_min, offset); \ | 517 | static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0); |
525 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | 518 | static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in, |
526 | show_in_max, set_in_max, offset); | 519 | 1, 1); |
527 | 520 | static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in, | |
528 | show_in_offset(0); | 521 | 1, 2); |
529 | limit_in_offset(0); | 522 | |
530 | show_in_offset(1); | 523 | static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0); |
531 | limit_in_offset(1); | 524 | static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in, |
532 | show_in_offset(2); | 525 | 2, 1); |
533 | limit_in_offset(2); | 526 | static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in, |
534 | show_in_offset(3); | 527 | 2, 2); |
535 | limit_in_offset(3); | 528 | |
536 | show_in_offset(4); | 529 | static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0); |
537 | limit_in_offset(4); | 530 | static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in, |
538 | show_in_offset(5); | 531 | 3, 1); |
539 | limit_in_offset(5); | 532 | static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in, |
540 | show_in_offset(6); | 533 | 3, 2); |
541 | limit_in_offset(6); | 534 | |
542 | show_in_offset(7); | 535 | static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0); |
543 | limit_in_offset(7); | 536 | static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in, |
544 | show_in_offset(8); | 537 | 4, 1); |
538 | static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in, | ||
539 | 4, 2); | ||
540 | |||
541 | static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0); | ||
542 | static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in, | ||
543 | 5, 1); | ||
544 | static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in, | ||
545 | 5, 2); | ||
546 | |||
547 | static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0); | ||
548 | static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in, | ||
549 | 6, 1); | ||
550 | static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in, | ||
551 | 6, 2); | ||
552 | |||
553 | static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0); | ||
554 | static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in, | ||
555 | 7, 1); | ||
556 | static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in, | ||
557 | 7, 2); | ||
558 | |||
559 | static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0); | ||
545 | 560 | ||
546 | /* 3 temperatures */ | 561 | /* 3 temperatures */ |
547 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | 562 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
548 | char *buf) | 563 | char *buf) |
549 | { | 564 | { |
550 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 565 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
551 | int nr = sensor_attr->index; | 566 | int nr = sattr->nr; |
552 | 567 | int index = sattr->index; | |
553 | struct it87_data *data = it87_update_device(dev); | 568 | struct it87_data *data = it87_update_device(dev); |
554 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); | ||
555 | } | ||
556 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, | ||
557 | char *buf) | ||
558 | { | ||
559 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
560 | int nr = sensor_attr->index; | ||
561 | 569 | ||
562 | struct it87_data *data = it87_update_device(dev); | 570 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index])); |
563 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); | ||
564 | } | 571 | } |
565 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, | ||
566 | char *buf) | ||
567 | { | ||
568 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
569 | int nr = sensor_attr->index; | ||
570 | 572 | ||
571 | struct it87_data *data = it87_update_device(dev); | 573 | static ssize_t set_temp(struct device *dev, struct device_attribute *attr, |
572 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])); | 574 | const char *buf, size_t count) |
573 | } | ||
574 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | ||
575 | const char *buf, size_t count) | ||
576 | { | 575 | { |
577 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 576 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
578 | int nr = sensor_attr->index; | 577 | int nr = sattr->nr; |
579 | 578 | int index = sattr->index; | |
580 | struct it87_data *data = dev_get_drvdata(dev); | 579 | struct it87_data *data = dev_get_drvdata(dev); |
581 | long val; | 580 | long val; |
581 | u8 reg, regval; | ||
582 | 582 | ||
583 | if (kstrtol(buf, 10, &val) < 0) | 583 | if (kstrtol(buf, 10, &val) < 0) |
584 | return -EINVAL; | 584 | return -EINVAL; |
585 | 585 | ||
586 | mutex_lock(&data->update_lock); | 586 | mutex_lock(&data->update_lock); |
587 | data->temp_high[nr] = TEMP_TO_REG(val); | ||
588 | it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); | ||
589 | mutex_unlock(&data->update_lock); | ||
590 | return count; | ||
591 | } | ||
592 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | ||
593 | const char *buf, size_t count) | ||
594 | { | ||
595 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
596 | int nr = sensor_attr->index; | ||
597 | 587 | ||
598 | struct it87_data *data = dev_get_drvdata(dev); | 588 | switch (index) { |
599 | long val; | 589 | default: |
600 | 590 | case 1: | |
601 | if (kstrtol(buf, 10, &val) < 0) | 591 | reg = IT87_REG_TEMP_LOW(nr); |
602 | return -EINVAL; | 592 | break; |
593 | case 2: | ||
594 | reg = IT87_REG_TEMP_HIGH(nr); | ||
595 | break; | ||
596 | case 3: | ||
597 | regval = it87_read_value(data, IT87_REG_BEEP_ENABLE); | ||
598 | if (!(regval & 0x80)) { | ||
599 | regval |= 0x80; | ||
600 | it87_write_value(data, IT87_REG_BEEP_ENABLE, regval); | ||
601 | } | ||
602 | data->valid = 0; | ||
603 | reg = IT87_REG_TEMP_OFFSET[nr]; | ||
604 | break; | ||
605 | } | ||
603 | 606 | ||
604 | mutex_lock(&data->update_lock); | 607 | data->temp[nr][index] = TEMP_TO_REG(val); |
605 | data->temp_low[nr] = TEMP_TO_REG(val); | 608 | it87_write_value(data, reg, data->temp[nr][index]); |
606 | it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); | ||
607 | mutex_unlock(&data->update_lock); | 609 | mutex_unlock(&data->update_lock); |
608 | return count; | 610 | return count; |
609 | } | 611 | } |
610 | #define show_temp_offset(offset) \ | 612 | |
611 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ | 613 | static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0); |
612 | show_temp, NULL, offset - 1); \ | 614 | static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
613 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ | 615 | 0, 1); |
614 | show_temp_max, set_temp_max, offset - 1); \ | 616 | static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
615 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ | 617 | 0, 2); |
616 | show_temp_min, set_temp_min, offset - 1); | 618 | static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp, |
617 | 619 | set_temp, 0, 3); | |
618 | show_temp_offset(1); | 620 | static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0); |
619 | show_temp_offset(2); | 621 | static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
620 | show_temp_offset(3); | 622 | 1, 1); |
621 | 623 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp, | |
622 | static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, | 624 | 1, 2); |
623 | char *buf) | 625 | static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp, |
626 | set_temp, 1, 3); | ||
627 | static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0); | ||
628 | static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp, | ||
629 | 2, 1); | ||
630 | static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp, | ||
631 | 2, 2); | ||
632 | static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp, | ||
633 | set_temp, 2, 3); | ||
634 | |||
635 | static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr, | ||
636 | char *buf) | ||
624 | { | 637 | { |
625 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 638 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
626 | int nr = sensor_attr->index; | 639 | int nr = sensor_attr->index; |
627 | struct it87_data *data = it87_update_device(dev); | 640 | struct it87_data *data = it87_update_device(dev); |
628 | u8 reg = data->sensor; /* In case value is updated while used */ | 641 | u8 reg = data->sensor; /* In case value is updated while used */ |
642 | u8 extra = data->extra; | ||
629 | 643 | ||
644 | if ((has_temp_peci(data, nr) && (reg >> 6 == nr + 1)) | ||
645 | || (has_temp_old_peci(data, nr) && (extra & 0x80))) | ||
646 | return sprintf(buf, "6\n"); /* Intel PECI */ | ||
630 | if (reg & (1 << nr)) | 647 | if (reg & (1 << nr)) |
631 | return sprintf(buf, "3\n"); /* thermal diode */ | 648 | return sprintf(buf, "3\n"); /* thermal diode */ |
632 | if (reg & (8 << nr)) | 649 | if (reg & (8 << nr)) |
633 | return sprintf(buf, "4\n"); /* thermistor */ | 650 | return sprintf(buf, "4\n"); /* thermistor */ |
634 | return sprintf(buf, "0\n"); /* disabled */ | 651 | return sprintf(buf, "0\n"); /* disabled */ |
635 | } | 652 | } |
636 | static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, | 653 | |
637 | const char *buf, size_t count) | 654 | static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr, |
655 | const char *buf, size_t count) | ||
638 | { | 656 | { |
639 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 657 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
640 | int nr = sensor_attr->index; | 658 | int nr = sensor_attr->index; |
641 | 659 | ||
642 | struct it87_data *data = dev_get_drvdata(dev); | 660 | struct it87_data *data = dev_get_drvdata(dev); |
643 | long val; | 661 | long val; |
644 | u8 reg; | 662 | u8 reg, extra; |
645 | 663 | ||
646 | if (kstrtol(buf, 10, &val) < 0) | 664 | if (kstrtol(buf, 10, &val) < 0) |
647 | return -EINVAL; | 665 | return -EINVAL; |
@@ -649,33 +667,45 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, | |||
649 | reg = it87_read_value(data, IT87_REG_TEMP_ENABLE); | 667 | reg = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
650 | reg &= ~(1 << nr); | 668 | reg &= ~(1 << nr); |
651 | reg &= ~(8 << nr); | 669 | reg &= ~(8 << nr); |
670 | if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6)) | ||
671 | reg &= 0x3f; | ||
672 | extra = it87_read_value(data, IT87_REG_TEMP_EXTRA); | ||
673 | if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6)) | ||
674 | extra &= 0x7f; | ||
652 | if (val == 2) { /* backwards compatibility */ | 675 | if (val == 2) { /* backwards compatibility */ |
653 | dev_warn(dev, "Sensor type 2 is deprecated, please use 4 " | 676 | dev_warn(dev, |
654 | "instead\n"); | 677 | "Sensor type 2 is deprecated, please use 4 instead\n"); |
655 | val = 4; | 678 | val = 4; |
656 | } | 679 | } |
657 | /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ | 680 | /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */ |
658 | if (val == 3) | 681 | if (val == 3) |
659 | reg |= 1 << nr; | 682 | reg |= 1 << nr; |
660 | else if (val == 4) | 683 | else if (val == 4) |
661 | reg |= 8 << nr; | 684 | reg |= 8 << nr; |
685 | else if (has_temp_peci(data, nr) && val == 6) | ||
686 | reg |= (nr + 1) << 6; | ||
687 | else if (has_temp_old_peci(data, nr) && val == 6) | ||
688 | extra |= 0x80; | ||
662 | else if (val != 0) | 689 | else if (val != 0) |
663 | return -EINVAL; | 690 | return -EINVAL; |
664 | 691 | ||
665 | mutex_lock(&data->update_lock); | 692 | mutex_lock(&data->update_lock); |
666 | data->sensor = reg; | 693 | data->sensor = reg; |
694 | data->extra = extra; | ||
667 | it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); | 695 | it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); |
696 | if (has_temp_old_peci(data, nr)) | ||
697 | it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra); | ||
668 | data->valid = 0; /* Force cache refresh */ | 698 | data->valid = 0; /* Force cache refresh */ |
669 | mutex_unlock(&data->update_lock); | 699 | mutex_unlock(&data->update_lock); |
670 | return count; | 700 | return count; |
671 | } | 701 | } |
672 | #define show_sensor_offset(offset) \ | ||
673 | static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ | ||
674 | show_sensor, set_sensor, offset - 1); | ||
675 | 702 | ||
676 | show_sensor_offset(1); | 703 | static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type, |
677 | show_sensor_offset(2); | 704 | set_temp_type, 0); |
678 | show_sensor_offset(3); | 705 | static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type, |
706 | set_temp_type, 1); | ||
707 | static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type, | ||
708 | set_temp_type, 2); | ||
679 | 709 | ||
680 | /* 3 Fans */ | 710 | /* 3 Fans */ |
681 | 711 | ||
@@ -692,25 +722,21 @@ static int pwm_mode(const struct it87_data *data, int nr) | |||
692 | } | 722 | } |
693 | 723 | ||
694 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, | 724 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
695 | char *buf) | 725 | char *buf) |
696 | { | 726 | { |
697 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 727 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
698 | int nr = sensor_attr->index; | 728 | int nr = sattr->nr; |
699 | 729 | int index = sattr->index; | |
730 | int speed; | ||
700 | struct it87_data *data = it87_update_device(dev); | 731 | struct it87_data *data = it87_update_device(dev); |
701 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], | ||
702 | DIV_FROM_REG(data->fan_div[nr]))); | ||
703 | } | ||
704 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, | ||
705 | char *buf) | ||
706 | { | ||
707 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
708 | int nr = sensor_attr->index; | ||
709 | 732 | ||
710 | struct it87_data *data = it87_update_device(dev); | 733 | speed = has_16bit_fans(data) ? |
711 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], | 734 | FAN16_FROM_REG(data->fan[nr][index]) : |
712 | DIV_FROM_REG(data->fan_div[nr]))); | 735 | FAN_FROM_REG(data->fan[nr][index], |
736 | DIV_FROM_REG(data->fan_div[nr])); | ||
737 | return sprintf(buf, "%d\n", speed); | ||
713 | } | 738 | } |
739 | |||
714 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, | 740 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
715 | char *buf) | 741 | char *buf) |
716 | { | 742 | { |
@@ -747,11 +773,13 @@ static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, | |||
747 | 773 | ||
748 | return sprintf(buf, "%u\n", pwm_freq[index]); | 774 | return sprintf(buf, "%u\n", pwm_freq[index]); |
749 | } | 775 | } |
750 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 776 | |
751 | const char *buf, size_t count) | 777 | static ssize_t set_fan(struct device *dev, struct device_attribute *attr, |
778 | const char *buf, size_t count) | ||
752 | { | 779 | { |
753 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 780 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
754 | int nr = sensor_attr->index; | 781 | int nr = sattr->nr; |
782 | int index = sattr->index; | ||
755 | 783 | ||
756 | struct it87_data *data = dev_get_drvdata(dev); | 784 | struct it87_data *data = dev_get_drvdata(dev); |
757 | long val; | 785 | long val; |
@@ -761,24 +789,36 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
761 | return -EINVAL; | 789 | return -EINVAL; |
762 | 790 | ||
763 | mutex_lock(&data->update_lock); | 791 | mutex_lock(&data->update_lock); |
764 | reg = it87_read_value(data, IT87_REG_FAN_DIV); | 792 | |
765 | switch (nr) { | 793 | if (has_16bit_fans(data)) { |
766 | case 0: | 794 | data->fan[nr][index] = FAN16_TO_REG(val); |
767 | data->fan_div[nr] = reg & 0x07; | 795 | it87_write_value(data, IT87_REG_FAN_MIN[nr], |
768 | break; | 796 | data->fan[nr][index] & 0xff); |
769 | case 1: | 797 | it87_write_value(data, IT87_REG_FANX_MIN[nr], |
770 | data->fan_div[nr] = (reg >> 3) & 0x07; | 798 | data->fan[nr][index] >> 8); |
771 | break; | 799 | } else { |
772 | case 2: | 800 | reg = it87_read_value(data, IT87_REG_FAN_DIV); |
773 | data->fan_div[nr] = (reg & 0x40) ? 3 : 1; | 801 | switch (nr) { |
774 | break; | 802 | case 0: |
803 | data->fan_div[nr] = reg & 0x07; | ||
804 | break; | ||
805 | case 1: | ||
806 | data->fan_div[nr] = (reg >> 3) & 0x07; | ||
807 | break; | ||
808 | case 2: | ||
809 | data->fan_div[nr] = (reg & 0x40) ? 3 : 1; | ||
810 | break; | ||
811 | } | ||
812 | data->fan[nr][index] = | ||
813 | FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | ||
814 | it87_write_value(data, IT87_REG_FAN_MIN[nr], | ||
815 | data->fan[nr][index]); | ||
775 | } | 816 | } |
776 | 817 | ||
777 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | ||
778 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]); | ||
779 | mutex_unlock(&data->update_lock); | 818 | mutex_unlock(&data->update_lock); |
780 | return count; | 819 | return count; |
781 | } | 820 | } |
821 | |||
782 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 822 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
783 | const char *buf, size_t count) | 823 | const char *buf, size_t count) |
784 | { | 824 | { |
@@ -797,7 +837,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
797 | old = it87_read_value(data, IT87_REG_FAN_DIV); | 837 | old = it87_read_value(data, IT87_REG_FAN_DIV); |
798 | 838 | ||
799 | /* Save fan min limit */ | 839 | /* Save fan min limit */ |
800 | min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); | 840 | min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr])); |
801 | 841 | ||
802 | switch (nr) { | 842 | switch (nr) { |
803 | case 0: | 843 | case 0: |
@@ -818,8 +858,8 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
818 | it87_write_value(data, IT87_REG_FAN_DIV, val); | 858 | it87_write_value(data, IT87_REG_FAN_DIV, val); |
819 | 859 | ||
820 | /* Restore fan min limit */ | 860 | /* Restore fan min limit */ |
821 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 861 | data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
822 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]); | 862 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]); |
823 | 863 | ||
824 | mutex_unlock(&data->update_lock); | 864 | mutex_unlock(&data->update_lock); |
825 | return count; | 865 | return count; |
@@ -843,8 +883,8 @@ static int check_trip_points(struct device *dev, int nr) | |||
843 | } | 883 | } |
844 | 884 | ||
845 | if (err) { | 885 | if (err) { |
846 | dev_err(dev, "Inconsistent trip points, not switching to " | 886 | dev_err(dev, |
847 | "automatic mode\n"); | 887 | "Inconsistent trip points, not switching to automatic mode\n"); |
848 | dev_err(dev, "Adjust the trip points and try again\n"); | 888 | dev_err(dev, "Adjust the trip points and try again\n"); |
849 | } | 889 | } |
850 | return err; | 890 | return err; |
@@ -1092,118 +1132,106 @@ static ssize_t set_auto_temp(struct device *dev, | |||
1092 | return count; | 1132 | return count; |
1093 | } | 1133 | } |
1094 | 1134 | ||
1095 | #define show_fan_offset(offset) \ | 1135 | static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0); |
1096 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ | 1136 | static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
1097 | show_fan, NULL, offset - 1); \ | 1137 | 0, 1); |
1098 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | 1138 | static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div, |
1099 | show_fan_min, set_fan_min, offset - 1); \ | 1139 | set_fan_div, 0); |
1100 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ | 1140 | |
1101 | show_fan_div, set_fan_div, offset - 1); | 1141 | static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0); |
1102 | 1142 | static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan, | |
1103 | show_fan_offset(1); | 1143 | 1, 1); |
1104 | show_fan_offset(2); | 1144 | static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div, |
1105 | show_fan_offset(3); | 1145 | set_fan_div, 1); |
1106 | 1146 | ||
1107 | #define show_pwm_offset(offset) \ | 1147 | static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0); |
1108 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ | 1148 | static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
1109 | show_pwm_enable, set_pwm_enable, offset - 1); \ | 1149 | 2, 1); |
1110 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ | 1150 | static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div, |
1111 | show_pwm, set_pwm, offset - 1); \ | 1151 | set_fan_div, 2); |
1112 | static DEVICE_ATTR(pwm##offset##_freq, \ | 1152 | |
1113 | (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \ | 1153 | static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0); |
1114 | show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \ | 1154 | static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
1115 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \ | 1155 | 3, 1); |
1116 | S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \ | 1156 | |
1117 | offset - 1); \ | 1157 | static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0); |
1118 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \ | 1158 | static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
1119 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ | 1159 | 4, 1); |
1120 | offset - 1, 0); \ | 1160 | |
1121 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \ | 1161 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, |
1122 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ | 1162 | show_pwm_enable, set_pwm_enable, 0); |
1123 | offset - 1, 1); \ | 1163 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0); |
1124 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \ | 1164 | static DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq); |
1125 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ | 1165 | static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR, |
1126 | offset - 1, 2); \ | 1166 | show_pwm_temp_map, set_pwm_temp_map, 0); |
1127 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \ | 1167 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR, |
1128 | S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \ | 1168 | show_auto_pwm, set_auto_pwm, 0, 0); |
1129 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \ | 1169 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR, |
1130 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ | 1170 | show_auto_pwm, set_auto_pwm, 0, 1); |
1131 | offset - 1, 1); \ | 1171 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR, |
1132 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \ | 1172 | show_auto_pwm, set_auto_pwm, 0, 2); |
1133 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ | 1173 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO, |
1134 | offset - 1, 0); \ | 1174 | show_auto_pwm, NULL, 0, 3); |
1135 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \ | 1175 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR, |
1136 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ | 1176 | show_auto_temp, set_auto_temp, 0, 1); |
1137 | offset - 1, 2); \ | 1177 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, |
1138 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \ | 1178 | show_auto_temp, set_auto_temp, 0, 0); |
1139 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ | 1179 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR, |
1140 | offset - 1, 3); \ | 1180 | show_auto_temp, set_auto_temp, 0, 2); |
1141 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \ | 1181 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR, |
1142 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ | 1182 | show_auto_temp, set_auto_temp, 0, 3); |
1143 | offset - 1, 4); | 1183 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR, |
1144 | 1184 | show_auto_temp, set_auto_temp, 0, 4); | |
1145 | show_pwm_offset(1); | 1185 | |
1146 | show_pwm_offset(2); | 1186 | static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, |
1147 | show_pwm_offset(3); | 1187 | show_pwm_enable, set_pwm_enable, 1); |
1148 | 1188 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1); | |
1149 | /* A different set of callbacks for 16-bit fans */ | 1189 | static DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, NULL); |
1150 | static ssize_t show_fan16(struct device *dev, struct device_attribute *attr, | 1190 | static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR, |
1151 | char *buf) | 1191 | show_pwm_temp_map, set_pwm_temp_map, 1); |
1152 | { | 1192 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR, |
1153 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 1193 | show_auto_pwm, set_auto_pwm, 1, 0); |
1154 | int nr = sensor_attr->index; | 1194 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR, |
1155 | struct it87_data *data = it87_update_device(dev); | 1195 | show_auto_pwm, set_auto_pwm, 1, 1); |
1156 | return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr])); | 1196 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR, |
1157 | } | 1197 | show_auto_pwm, set_auto_pwm, 1, 2); |
1158 | 1198 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO, | |
1159 | static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr, | 1199 | show_auto_pwm, NULL, 1, 3); |
1160 | char *buf) | 1200 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR, |
1161 | { | 1201 | show_auto_temp, set_auto_temp, 1, 1); |
1162 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 1202 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, |
1163 | int nr = sensor_attr->index; | 1203 | show_auto_temp, set_auto_temp, 1, 0); |
1164 | struct it87_data *data = it87_update_device(dev); | 1204 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR, |
1165 | return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr])); | 1205 | show_auto_temp, set_auto_temp, 1, 2); |
1166 | } | 1206 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR, |
1167 | 1207 | show_auto_temp, set_auto_temp, 1, 3); | |
1168 | static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr, | 1208 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR, |
1169 | const char *buf, size_t count) | 1209 | show_auto_temp, set_auto_temp, 1, 4); |
1170 | { | 1210 | |
1171 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 1211 | static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, |
1172 | int nr = sensor_attr->index; | 1212 | show_pwm_enable, set_pwm_enable, 2); |
1173 | struct it87_data *data = dev_get_drvdata(dev); | 1213 | static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2); |
1174 | long val; | 1214 | static DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL); |
1175 | 1215 | static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR, | |
1176 | if (kstrtol(buf, 10, &val) < 0) | 1216 | show_pwm_temp_map, set_pwm_temp_map, 2); |
1177 | return -EINVAL; | 1217 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR, |
1178 | 1218 | show_auto_pwm, set_auto_pwm, 2, 0); | |
1179 | mutex_lock(&data->update_lock); | 1219 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, |
1180 | data->fan_min[nr] = FAN16_TO_REG(val); | 1220 | show_auto_pwm, set_auto_pwm, 2, 1); |
1181 | it87_write_value(data, IT87_REG_FAN_MIN[nr], | 1221 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR, |
1182 | data->fan_min[nr] & 0xff); | 1222 | show_auto_pwm, set_auto_pwm, 2, 2); |
1183 | it87_write_value(data, IT87_REG_FANX_MIN[nr], | 1223 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO, |
1184 | data->fan_min[nr] >> 8); | 1224 | show_auto_pwm, NULL, 2, 3); |
1185 | mutex_unlock(&data->update_lock); | 1225 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR, |
1186 | return count; | 1226 | show_auto_temp, set_auto_temp, 2, 1); |
1187 | } | 1227 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, |
1188 | 1228 | show_auto_temp, set_auto_temp, 2, 0); | |
1189 | /* | 1229 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR, |
1190 | * We want to use the same sysfs file names as 8-bit fans, but we need | 1230 | show_auto_temp, set_auto_temp, 2, 2); |
1191 | * different variable names, so we have to use SENSOR_ATTR instead of | 1231 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR, |
1192 | * SENSOR_DEVICE_ATTR. | 1232 | show_auto_temp, set_auto_temp, 2, 3); |
1193 | */ | 1233 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR, |
1194 | #define show_fan16_offset(offset) \ | 1234 | show_auto_temp, set_auto_temp, 2, 4); |
1195 | static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \ | ||
1196 | = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \ | ||
1197 | show_fan16, NULL, offset - 1); \ | ||
1198 | static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \ | ||
1199 | = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | ||
1200 | show_fan16_min, set_fan16_min, offset - 1) | ||
1201 | |||
1202 | show_fan16_offset(1); | ||
1203 | show_fan16_offset(2); | ||
1204 | show_fan16_offset(3); | ||
1205 | show_fan16_offset(4); | ||
1206 | show_fan16_offset(5); | ||
1207 | 1235 | ||
1208 | /* Alarms */ | 1236 | /* Alarms */ |
1209 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, | 1237 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, |
@@ -1471,6 +1499,12 @@ static const struct attribute_group it87_group_temp[3] = { | |||
1471 | { .attrs = it87_attributes_temp[2] }, | 1499 | { .attrs = it87_attributes_temp[2] }, |
1472 | }; | 1500 | }; |
1473 | 1501 | ||
1502 | static struct attribute *it87_attributes_temp_offset[] = { | ||
1503 | &sensor_dev_attr_temp1_offset.dev_attr.attr, | ||
1504 | &sensor_dev_attr_temp2_offset.dev_attr.attr, | ||
1505 | &sensor_dev_attr_temp3_offset.dev_attr.attr, | ||
1506 | }; | ||
1507 | |||
1474 | static struct attribute *it87_attributes[] = { | 1508 | static struct attribute *it87_attributes[] = { |
1475 | &dev_attr_alarms.attr, | 1509 | &dev_attr_alarms.attr, |
1476 | &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, | 1510 | &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, |
@@ -1500,73 +1534,47 @@ static struct attribute *it87_attributes_temp_beep[] = { | |||
1500 | &sensor_dev_attr_temp3_beep.dev_attr.attr, | 1534 | &sensor_dev_attr_temp3_beep.dev_attr.attr, |
1501 | }; | 1535 | }; |
1502 | 1536 | ||
1503 | static struct attribute *it87_attributes_fan16[5][3+1] = { { | 1537 | static struct attribute *it87_attributes_fan[5][3+1] = { { |
1504 | &sensor_dev_attr_fan1_input16.dev_attr.attr, | 1538 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
1505 | &sensor_dev_attr_fan1_min16.dev_attr.attr, | 1539 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
1506 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, | 1540 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
1507 | NULL | 1541 | NULL |
1508 | }, { | 1542 | }, { |
1509 | &sensor_dev_attr_fan2_input16.dev_attr.attr, | 1543 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
1510 | &sensor_dev_attr_fan2_min16.dev_attr.attr, | 1544 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
1511 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, | 1545 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
1512 | NULL | 1546 | NULL |
1513 | }, { | 1547 | }, { |
1514 | &sensor_dev_attr_fan3_input16.dev_attr.attr, | 1548 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
1515 | &sensor_dev_attr_fan3_min16.dev_attr.attr, | 1549 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
1516 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, | 1550 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
1517 | NULL | 1551 | NULL |
1518 | }, { | 1552 | }, { |
1519 | &sensor_dev_attr_fan4_input16.dev_attr.attr, | 1553 | &sensor_dev_attr_fan4_input.dev_attr.attr, |
1520 | &sensor_dev_attr_fan4_min16.dev_attr.attr, | 1554 | &sensor_dev_attr_fan4_min.dev_attr.attr, |
1521 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, | 1555 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
1522 | NULL | 1556 | NULL |
1523 | }, { | 1557 | }, { |
1524 | &sensor_dev_attr_fan5_input16.dev_attr.attr, | 1558 | &sensor_dev_attr_fan5_input.dev_attr.attr, |
1525 | &sensor_dev_attr_fan5_min16.dev_attr.attr, | 1559 | &sensor_dev_attr_fan5_min.dev_attr.attr, |
1526 | &sensor_dev_attr_fan5_alarm.dev_attr.attr, | 1560 | &sensor_dev_attr_fan5_alarm.dev_attr.attr, |
1527 | NULL | 1561 | NULL |
1528 | } }; | 1562 | } }; |
1529 | 1563 | ||
1530 | static const struct attribute_group it87_group_fan16[5] = { | 1564 | static const struct attribute_group it87_group_fan[5] = { |
1531 | { .attrs = it87_attributes_fan16[0] }, | 1565 | { .attrs = it87_attributes_fan[0] }, |
1532 | { .attrs = it87_attributes_fan16[1] }, | 1566 | { .attrs = it87_attributes_fan[1] }, |
1533 | { .attrs = it87_attributes_fan16[2] }, | 1567 | { .attrs = it87_attributes_fan[2] }, |
1534 | { .attrs = it87_attributes_fan16[3] }, | 1568 | { .attrs = it87_attributes_fan[3] }, |
1535 | { .attrs = it87_attributes_fan16[4] }, | 1569 | { .attrs = it87_attributes_fan[4] }, |
1536 | }; | 1570 | }; |
1537 | 1571 | ||
1538 | static struct attribute *it87_attributes_fan[3][4+1] = { { | 1572 | static const struct attribute *it87_attributes_fan_div[] = { |
1539 | &sensor_dev_attr_fan1_input.dev_attr.attr, | ||
1540 | &sensor_dev_attr_fan1_min.dev_attr.attr, | ||
1541 | &sensor_dev_attr_fan1_div.dev_attr.attr, | 1573 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
1542 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, | ||
1543 | NULL | ||
1544 | }, { | ||
1545 | &sensor_dev_attr_fan2_input.dev_attr.attr, | ||
1546 | &sensor_dev_attr_fan2_min.dev_attr.attr, | ||
1547 | &sensor_dev_attr_fan2_div.dev_attr.attr, | 1574 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
1548 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, | ||
1549 | NULL | ||
1550 | }, { | ||
1551 | &sensor_dev_attr_fan3_input.dev_attr.attr, | ||
1552 | &sensor_dev_attr_fan3_min.dev_attr.attr, | ||
1553 | &sensor_dev_attr_fan3_div.dev_attr.attr, | 1575 | &sensor_dev_attr_fan3_div.dev_attr.attr, |
1554 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, | ||
1555 | NULL | ||
1556 | } }; | ||
1557 | |||
1558 | static const struct attribute_group it87_group_fan[3] = { | ||
1559 | { .attrs = it87_attributes_fan[0] }, | ||
1560 | { .attrs = it87_attributes_fan[1] }, | ||
1561 | { .attrs = it87_attributes_fan[2] }, | ||
1562 | }; | 1576 | }; |
1563 | 1577 | ||
1564 | static const struct attribute_group * | ||
1565 | it87_get_fan_group(const struct it87_data *data) | ||
1566 | { | ||
1567 | return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan; | ||
1568 | } | ||
1569 | |||
1570 | static struct attribute *it87_attributes_pwm[3][4+1] = { { | 1578 | static struct attribute *it87_attributes_pwm[3][4+1] = { { |
1571 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, | 1579 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
1572 | &sensor_dev_attr_pwm1.dev_attr.attr, | 1580 | &sensor_dev_attr_pwm1.dev_attr.attr, |
@@ -1925,7 +1933,6 @@ static void it87_remove_files(struct device *dev) | |||
1925 | { | 1933 | { |
1926 | struct it87_data *data = platform_get_drvdata(pdev); | 1934 | struct it87_data *data = platform_get_drvdata(pdev); |
1927 | struct it87_sio_data *sio_data = dev->platform_data; | 1935 | struct it87_sio_data *sio_data = dev->platform_data; |
1928 | const struct attribute_group *fan_group = it87_get_fan_group(data); | ||
1929 | int i; | 1936 | int i; |
1930 | 1937 | ||
1931 | sysfs_remove_group(&dev->kobj, &it87_group); | 1938 | sysfs_remove_group(&dev->kobj, &it87_group); |
@@ -1941,6 +1948,9 @@ static void it87_remove_files(struct device *dev) | |||
1941 | if (!(data->has_temp & (1 << i))) | 1948 | if (!(data->has_temp & (1 << i))) |
1942 | continue; | 1949 | continue; |
1943 | sysfs_remove_group(&dev->kobj, &it87_group_temp[i]); | 1950 | sysfs_remove_group(&dev->kobj, &it87_group_temp[i]); |
1951 | if (has_temp_offset(data)) | ||
1952 | sysfs_remove_file(&dev->kobj, | ||
1953 | it87_attributes_temp_offset[i]); | ||
1944 | if (sio_data->beep_pin) | 1954 | if (sio_data->beep_pin) |
1945 | sysfs_remove_file(&dev->kobj, | 1955 | sysfs_remove_file(&dev->kobj, |
1946 | it87_attributes_temp_beep[i]); | 1956 | it87_attributes_temp_beep[i]); |
@@ -1948,10 +1958,13 @@ static void it87_remove_files(struct device *dev) | |||
1948 | for (i = 0; i < 5; i++) { | 1958 | for (i = 0; i < 5; i++) { |
1949 | if (!(data->has_fan & (1 << i))) | 1959 | if (!(data->has_fan & (1 << i))) |
1950 | continue; | 1960 | continue; |
1951 | sysfs_remove_group(&dev->kobj, &fan_group[i]); | 1961 | sysfs_remove_group(&dev->kobj, &it87_group_fan[i]); |
1952 | if (sio_data->beep_pin) | 1962 | if (sio_data->beep_pin) |
1953 | sysfs_remove_file(&dev->kobj, | 1963 | sysfs_remove_file(&dev->kobj, |
1954 | it87_attributes_fan_beep[i]); | 1964 | it87_attributes_fan_beep[i]); |
1965 | if (i < 3 && !has_16bit_fans(data)) | ||
1966 | sysfs_remove_file(&dev->kobj, | ||
1967 | it87_attributes_fan_div[i]); | ||
1955 | } | 1968 | } |
1956 | for (i = 0; i < 3; i++) { | 1969 | for (i = 0; i < 3; i++) { |
1957 | if (sio_data->skip_pwm & (1 << 0)) | 1970 | if (sio_data->skip_pwm & (1 << 0)) |
@@ -1972,21 +1985,9 @@ static int it87_probe(struct platform_device *pdev) | |||
1972 | struct resource *res; | 1985 | struct resource *res; |
1973 | struct device *dev = &pdev->dev; | 1986 | struct device *dev = &pdev->dev; |
1974 | struct it87_sio_data *sio_data = dev->platform_data; | 1987 | struct it87_sio_data *sio_data = dev->platform_data; |
1975 | const struct attribute_group *fan_group; | ||
1976 | int err = 0, i; | 1988 | int err = 0, i; |
1977 | int enable_pwm_interface; | 1989 | int enable_pwm_interface; |
1978 | int fan_beep_need_rw; | 1990 | int fan_beep_need_rw; |
1979 | static const char * const names[] = { | ||
1980 | "it87", | ||
1981 | "it8712", | ||
1982 | "it8716", | ||
1983 | "it8718", | ||
1984 | "it8720", | ||
1985 | "it8721", | ||
1986 | "it8728", | ||
1987 | "it8782", | ||
1988 | "it8783", | ||
1989 | }; | ||
1990 | 1991 | ||
1991 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 1992 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
1992 | if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT, | 1993 | if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT, |
@@ -2003,8 +2004,31 @@ static int it87_probe(struct platform_device *pdev) | |||
2003 | 2004 | ||
2004 | data->addr = res->start; | 2005 | data->addr = res->start; |
2005 | data->type = sio_data->type; | 2006 | data->type = sio_data->type; |
2006 | data->revision = sio_data->revision; | 2007 | data->features = it87_devices[sio_data->type].features; |
2007 | data->name = names[sio_data->type]; | 2008 | data->peci_mask = it87_devices[sio_data->type].peci_mask; |
2009 | data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask; | ||
2010 | data->name = it87_devices[sio_data->type].name; | ||
2011 | /* | ||
2012 | * IT8705F Datasheet 0.4.1, 3h == Version G. | ||
2013 | * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J. | ||
2014 | * These are the first revisions with 16-bit tachometer support. | ||
2015 | */ | ||
2016 | switch (data->type) { | ||
2017 | case it87: | ||
2018 | if (sio_data->revision >= 0x03) { | ||
2019 | data->features &= ~FEAT_OLD_AUTOPWM; | ||
2020 | data->features |= FEAT_16BIT_FANS; | ||
2021 | } | ||
2022 | break; | ||
2023 | case it8712: | ||
2024 | if (sio_data->revision >= 0x08) { | ||
2025 | data->features &= ~FEAT_OLD_AUTOPWM; | ||
2026 | data->features |= FEAT_16BIT_FANS; | ||
2027 | } | ||
2028 | break; | ||
2029 | default: | ||
2030 | break; | ||
2031 | } | ||
2008 | 2032 | ||
2009 | /* Now, we do the remaining detection. */ | 2033 | /* Now, we do the remaining detection. */ |
2010 | if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) | 2034 | if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) |
@@ -2068,6 +2092,12 @@ static int it87_probe(struct platform_device *pdev) | |||
2068 | err = sysfs_create_group(&dev->kobj, &it87_group_temp[i]); | 2092 | err = sysfs_create_group(&dev->kobj, &it87_group_temp[i]); |
2069 | if (err) | 2093 | if (err) |
2070 | goto error; | 2094 | goto error; |
2095 | if (has_temp_offset(data)) { | ||
2096 | err = sysfs_create_file(&dev->kobj, | ||
2097 | it87_attributes_temp_offset[i]); | ||
2098 | if (err) | ||
2099 | goto error; | ||
2100 | } | ||
2071 | if (sio_data->beep_pin) { | 2101 | if (sio_data->beep_pin) { |
2072 | err = sysfs_create_file(&dev->kobj, | 2102 | err = sysfs_create_file(&dev->kobj, |
2073 | it87_attributes_temp_beep[i]); | 2103 | it87_attributes_temp_beep[i]); |
@@ -2077,15 +2107,21 @@ static int it87_probe(struct platform_device *pdev) | |||
2077 | } | 2107 | } |
2078 | 2108 | ||
2079 | /* Do not create fan files for disabled fans */ | 2109 | /* Do not create fan files for disabled fans */ |
2080 | fan_group = it87_get_fan_group(data); | ||
2081 | fan_beep_need_rw = 1; | 2110 | fan_beep_need_rw = 1; |
2082 | for (i = 0; i < 5; i++) { | 2111 | for (i = 0; i < 5; i++) { |
2083 | if (!(data->has_fan & (1 << i))) | 2112 | if (!(data->has_fan & (1 << i))) |
2084 | continue; | 2113 | continue; |
2085 | err = sysfs_create_group(&dev->kobj, &fan_group[i]); | 2114 | err = sysfs_create_group(&dev->kobj, &it87_group_fan[i]); |
2086 | if (err) | 2115 | if (err) |
2087 | goto error; | 2116 | goto error; |
2088 | 2117 | ||
2118 | if (i < 3 && !has_16bit_fans(data)) { | ||
2119 | err = sysfs_create_file(&dev->kobj, | ||
2120 | it87_attributes_fan_div[i]); | ||
2121 | if (err) | ||
2122 | goto error; | ||
2123 | } | ||
2124 | |||
2089 | if (sio_data->beep_pin) { | 2125 | if (sio_data->beep_pin) { |
2090 | err = sysfs_create_file(&dev->kobj, | 2126 | err = sysfs_create_file(&dev->kobj, |
2091 | it87_attributes_fan_beep[i]); | 2127 | it87_attributes_fan_beep[i]); |
@@ -2221,8 +2257,8 @@ static int it87_check_pwm(struct device *dev) | |||
2221 | * PWM interface). | 2257 | * PWM interface). |
2222 | */ | 2258 | */ |
2223 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { | 2259 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { |
2224 | dev_info(dev, "Reconfiguring PWM to " | 2260 | dev_info(dev, |
2225 | "active high polarity\n"); | 2261 | "Reconfiguring PWM to active high polarity\n"); |
2226 | it87_write_value(data, IT87_REG_FAN_CTL, | 2262 | it87_write_value(data, IT87_REG_FAN_CTL, |
2227 | tmp | 0x87); | 2263 | tmp | 0x87); |
2228 | for (i = 0; i < 3; i++) | 2264 | for (i = 0; i < 3; i++) |
@@ -2232,16 +2268,16 @@ static int it87_check_pwm(struct device *dev) | |||
2232 | return 1; | 2268 | return 1; |
2233 | } | 2269 | } |
2234 | 2270 | ||
2235 | dev_info(dev, "PWM configuration is " | 2271 | dev_info(dev, |
2236 | "too broken to be fixed\n"); | 2272 | "PWM configuration is too broken to be fixed\n"); |
2237 | } | 2273 | } |
2238 | 2274 | ||
2239 | dev_info(dev, "Detected broken BIOS " | 2275 | dev_info(dev, |
2240 | "defaults, disabling PWM interface\n"); | 2276 | "Detected broken BIOS defaults, disabling PWM interface\n"); |
2241 | return 0; | 2277 | return 0; |
2242 | } else if (fix_pwm_polarity) { | 2278 | } else if (fix_pwm_polarity) { |
2243 | dev_info(dev, "PWM configuration looks " | 2279 | dev_info(dev, |
2244 | "sane, won't touch\n"); | 2280 | "PWM configuration looks sane, won't touch\n"); |
2245 | } | 2281 | } |
2246 | 2282 | ||
2247 | return 1; | 2283 | return 1; |
@@ -2389,42 +2425,46 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
2389 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); | 2425 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); |
2390 | } | 2426 | } |
2391 | for (i = 0; i <= 7; i++) { | 2427 | for (i = 0; i <= 7; i++) { |
2392 | data->in[i] = | 2428 | data->in[i][0] = |
2393 | it87_read_value(data, IT87_REG_VIN(i)); | 2429 | it87_read_value(data, IT87_REG_VIN(i)); |
2394 | data->in_min[i] = | 2430 | data->in[i][1] = |
2395 | it87_read_value(data, IT87_REG_VIN_MIN(i)); | 2431 | it87_read_value(data, IT87_REG_VIN_MIN(i)); |
2396 | data->in_max[i] = | 2432 | data->in[i][2] = |
2397 | it87_read_value(data, IT87_REG_VIN_MAX(i)); | 2433 | it87_read_value(data, IT87_REG_VIN_MAX(i)); |
2398 | } | 2434 | } |
2399 | /* in8 (battery) has no limit registers */ | 2435 | /* in8 (battery) has no limit registers */ |
2400 | data->in[8] = it87_read_value(data, IT87_REG_VIN(8)); | 2436 | data->in[8][0] = it87_read_value(data, IT87_REG_VIN(8)); |
2401 | 2437 | ||
2402 | for (i = 0; i < 5; i++) { | 2438 | for (i = 0; i < 5; i++) { |
2403 | /* Skip disabled fans */ | 2439 | /* Skip disabled fans */ |
2404 | if (!(data->has_fan & (1 << i))) | 2440 | if (!(data->has_fan & (1 << i))) |
2405 | continue; | 2441 | continue; |
2406 | 2442 | ||
2407 | data->fan_min[i] = | 2443 | data->fan[i][1] = |
2408 | it87_read_value(data, IT87_REG_FAN_MIN[i]); | 2444 | it87_read_value(data, IT87_REG_FAN_MIN[i]); |
2409 | data->fan[i] = it87_read_value(data, | 2445 | data->fan[i][0] = it87_read_value(data, |
2410 | IT87_REG_FAN[i]); | 2446 | IT87_REG_FAN[i]); |
2411 | /* Add high byte if in 16-bit mode */ | 2447 | /* Add high byte if in 16-bit mode */ |
2412 | if (has_16bit_fans(data)) { | 2448 | if (has_16bit_fans(data)) { |
2413 | data->fan[i] |= it87_read_value(data, | 2449 | data->fan[i][0] |= it87_read_value(data, |
2414 | IT87_REG_FANX[i]) << 8; | 2450 | IT87_REG_FANX[i]) << 8; |
2415 | data->fan_min[i] |= it87_read_value(data, | 2451 | data->fan[i][1] |= it87_read_value(data, |
2416 | IT87_REG_FANX_MIN[i]) << 8; | 2452 | IT87_REG_FANX_MIN[i]) << 8; |
2417 | } | 2453 | } |
2418 | } | 2454 | } |
2419 | for (i = 0; i < 3; i++) { | 2455 | for (i = 0; i < 3; i++) { |
2420 | if (!(data->has_temp & (1 << i))) | 2456 | if (!(data->has_temp & (1 << i))) |
2421 | continue; | 2457 | continue; |
2422 | data->temp[i] = | 2458 | data->temp[i][0] = |
2423 | it87_read_value(data, IT87_REG_TEMP(i)); | 2459 | it87_read_value(data, IT87_REG_TEMP(i)); |
2424 | data->temp_high[i] = | 2460 | data->temp[i][1] = |
2425 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); | ||
2426 | data->temp_low[i] = | ||
2427 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); | 2461 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); |
2462 | data->temp[i][2] = | ||
2463 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); | ||
2464 | if (has_temp_offset(data)) | ||
2465 | data->temp[i][3] = | ||
2466 | it87_read_value(data, | ||
2467 | IT87_REG_TEMP_OFFSET[i]); | ||
2428 | } | 2468 | } |
2429 | 2469 | ||
2430 | /* Newer chips don't have clock dividers */ | 2470 | /* Newer chips don't have clock dividers */ |
@@ -2448,6 +2488,7 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
2448 | it87_update_pwm_ctrl(data, i); | 2488 | it87_update_pwm_ctrl(data, i); |
2449 | 2489 | ||
2450 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); | 2490 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
2491 | data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA); | ||
2451 | /* | 2492 | /* |
2452 | * The IT8705F does not have VID capability. | 2493 | * The IT8705F does not have VID capability. |
2453 | * The IT8718F and later don't use IT87_REG_VID for the | 2494 | * The IT8718F and later don't use IT87_REG_VID for the |
@@ -2549,8 +2590,7 @@ static void __exit sm_it87_exit(void) | |||
2549 | } | 2590 | } |
2550 | 2591 | ||
2551 | 2592 | ||
2552 | MODULE_AUTHOR("Chris Gauthron, " | 2593 | MODULE_AUTHOR("Chris Gauthron, Jean Delvare <khali@linux-fr.org>"); |
2553 | "Jean Delvare <khali@linux-fr.org>"); | ||
2554 | MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver"); | 2594 | MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver"); |
2555 | module_param(update_vbat, bool, 0); | 2595 | module_param(update_vbat, bool, 0); |
2556 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); | 2596 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); |