aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/hwmon/it8710
-rw-r--r--drivers/hwmon/hwmon-vid.c10
-rw-r--r--drivers/hwmon/hwmon.c26
-rw-r--r--drivers/hwmon/it87.c918
-rw-r--r--drivers/hwmon/w83627ehf.c99
-rw-r--r--drivers/hwmon/w83627hf.c81
6 files changed, 689 insertions, 455 deletions
diff --git a/Documentation/hwmon/it87 b/Documentation/hwmon/it87
index 87850d86c559..8386aadc0a82 100644
--- a/Documentation/hwmon/it87
+++ b/Documentation/hwmon/it87
@@ -209,3 +209,13 @@ doesn't use CPU cycles.
209Trip points must be set properly before switching to automatic fan speed 209Trip points must be set properly before switching to automatic fan speed
210control mode. The driver will perform basic integrity checks before 210control mode. The driver will perform basic integrity checks before
211actually switching to automatic control mode. 211actually switching to automatic control mode.
212
213
214Temperature offset attributes
215-----------------------------
216
217The driver supports temp[1-3]_offset sysfs attributes to adjust the reported
218temperature for thermal diodes or diode-connected thermal transistors.
219If a temperature sensor is configured for thermistors, the attribute values
220are ignored. If the thermal sensor type is Intel PECI, the temperature offset
221must be programmed to the critical CPU temperature.
diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c
index 9f26400713f0..89cfd64b3373 100644
--- a/drivers/hwmon/hwmon-vid.c
+++ b/drivers/hwmon/hwmon-vid.c
@@ -115,6 +115,12 @@ int vid_from_reg(int val, u8 vrm)
115 return (val < 32) ? 1550 - 25 * val 115 return (val < 32) ? 1550 - 25 * val
116 : 775 - (25 * (val - 31)) / 2; 116 : 775 - (25 * (val - 31)) / 2;
117 117
118 case 26: /* AMD family 10h to 15h, serial VID */
119 val &= 0x7f;
120 if (val >= 0x7c)
121 return 0;
122 return DIV_ROUND_CLOSEST(15500 - 125 * val, 10);
123
118 case 91: /* VRM 9.1 */ 124 case 91: /* VRM 9.1 */
119 case 90: /* VRM 9.0 */ 125 case 90: /* VRM 9.0 */
120 val &= 0x1f; 126 val &= 0x1f;
@@ -195,6 +201,10 @@ static struct vrm_model vrm_models[] = {
195 {X86_VENDOR_AMD, 0xF, 0x40, 0x7F, ANY, 24}, /* NPT family 0Fh */ 201 {X86_VENDOR_AMD, 0xF, 0x40, 0x7F, ANY, 24}, /* NPT family 0Fh */
196 {X86_VENDOR_AMD, 0xF, 0x80, ANY, ANY, 25}, /* future fam. 0Fh */ 202 {X86_VENDOR_AMD, 0xF, 0x80, ANY, ANY, 25}, /* future fam. 0Fh */
197 {X86_VENDOR_AMD, 0x10, 0x0, ANY, ANY, 25}, /* NPT family 10h */ 203 {X86_VENDOR_AMD, 0x10, 0x0, ANY, ANY, 25}, /* NPT family 10h */
204 {X86_VENDOR_AMD, 0x11, 0x0, ANY, ANY, 26}, /* family 11h */
205 {X86_VENDOR_AMD, 0x12, 0x0, ANY, ANY, 26}, /* family 12h */
206 {X86_VENDOR_AMD, 0x14, 0x0, ANY, ANY, 26}, /* family 14h */
207 {X86_VENDOR_AMD, 0x15, 0x0, ANY, ANY, 26}, /* family 15h */
198 208
199 {X86_VENDOR_INTEL, 0x6, 0x0, 0x6, ANY, 82}, /* Pentium Pro, 209 {X86_VENDOR_INTEL, 0x6, 0x0, 0x6, ANY, 82}, /* Pentium Pro,
200 * Pentium II, Xeon, 210 * Pentium II, Xeon,
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index c3c471ca202f..646314f7c839 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -84,19 +84,21 @@ static void __init hwmon_pci_quirks(void)
84 84
85 /* Open access to 0x295-0x296 on MSI MS-7031 */ 85 /* Open access to 0x295-0x296 on MSI MS-7031 */
86 sb = pci_get_device(PCI_VENDOR_ID_ATI, 0x436c, NULL); 86 sb = pci_get_device(PCI_VENDOR_ID_ATI, 0x436c, NULL);
87 if (sb && 87 if (sb) {
88 (sb->subsystem_vendor == 0x1462 && /* MSI */ 88 if (sb->subsystem_vendor == 0x1462 && /* MSI */
89 sb->subsystem_device == 0x0031)) { /* MS-7031 */ 89 sb->subsystem_device == 0x0031) { /* MS-7031 */
90 90 pci_read_config_byte(sb, 0x48, &enable);
91 pci_read_config_byte(sb, 0x48, &enable); 91 pci_read_config_word(sb, 0x64, &base);
92 pci_read_config_word(sb, 0x64, &base); 92
93 93 if (base == 0 && !(enable & BIT(2))) {
94 if (base == 0 && !(enable & BIT(2))) { 94 dev_info(&sb->dev,
95 dev_info(&sb->dev, 95 "Opening wide generic port at 0x295\n");
96 "Opening wide generic port at 0x295\n"); 96 pci_write_config_word(sb, 0x64, 0x295);
97 pci_write_config_word(sb, 0x64, 0x295); 97 pci_write_config_byte(sb, 0x48,
98 pci_write_config_byte(sb, 0x48, enable | BIT(2)); 98 enable | BIT(2));
99 }
99 } 100 }
101 pci_dev_put(sb);
100 } 102 }
101#endif 103#endif
102} 104}
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 };
203static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 }; 203static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
204static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 }; 204static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
205static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 }; 205static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
206static 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
231struct 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
246static 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
230struct it87_sio_data { 309struct it87_sio_data {
231 enum chips type; 310 enum chips type;
@@ -249,7 +328,9 @@ struct it87_sio_data {
249struct it87_data { 328struct 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
299static 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
309static 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
319static int adc_lsb(const struct it87_data *data, int nr) 376static 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
401static 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
419static 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
430static int it87_probe(struct platform_device *pdev); 458static int it87_probe(struct platform_device *pdev);
431static int it87_remove(struct platform_device *pdev); 459static int it87_remove(struct platform_device *pdev);
432 460
@@ -447,59 +475,22 @@ static struct platform_driver it87_driver = {
447}; 475};
448 476
449static ssize_t show_in(struct device *dev, struct device_attribute *attr, 477static 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
459static 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
469static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, 488static 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
479static 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}
498static 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) \ 511static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
519static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 512static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
520 show_in, NULL, offset); 513 0, 1);
521 514static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
522#define limit_in_offset(offset) \ 515 0, 2);
523static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 516
524 show_in_min, set_in_min, offset); \ 517static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
525static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 518static 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 520static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
528show_in_offset(0); 521 1, 2);
529limit_in_offset(0); 522
530show_in_offset(1); 523static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
531limit_in_offset(1); 524static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
532show_in_offset(2); 525 2, 1);
533limit_in_offset(2); 526static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
534show_in_offset(3); 527 2, 2);
535limit_in_offset(3); 528
536show_in_offset(4); 529static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
537limit_in_offset(4); 530static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
538show_in_offset(5); 531 3, 1);
539limit_in_offset(5); 532static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
540show_in_offset(6); 533 3, 2);
541limit_in_offset(6); 534
542show_in_offset(7); 535static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
543limit_in_offset(7); 536static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
544show_in_offset(8); 537 4, 1);
538static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
539 4, 2);
540
541static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
542static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
543 5, 1);
544static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
545 5, 2);
546
547static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
548static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
549 6, 1);
550static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
551 6, 2);
552
553static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
554static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
555 7, 1);
556static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
557 7, 2);
558
559static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
545 560
546/* 3 temperatures */ 561/* 3 temperatures */
547static ssize_t show_temp(struct device *dev, struct device_attribute *attr, 562static 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}
556static 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}
565static 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); 573static 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}
574static 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}
592static 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
611static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ 613static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
612 show_temp, NULL, offset - 1); \ 614static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
613static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ 615 0, 1);
614 show_temp_max, set_temp_max, offset - 1); \ 616static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
615static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ 617 0, 2);
616 show_temp_min, set_temp_min, offset - 1); 618static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
617 619 set_temp, 0, 3);
618show_temp_offset(1); 620static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
619show_temp_offset(2); 621static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
620show_temp_offset(3); 622 1, 1);
621 623static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
622static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, 624 1, 2);
623 char *buf) 625static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
626 set_temp, 1, 3);
627static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
628static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
629 2, 1);
630static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
631 2, 2);
632static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
633 set_temp, 2, 3);
634
635static 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}
636static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, 653
637 const char *buf, size_t count) 654static 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) \
673static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
674 show_sensor, set_sensor, offset - 1);
675 702
676show_sensor_offset(1); 703static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
677show_sensor_offset(2); 704 set_temp_type, 0);
678show_sensor_offset(3); 705static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
706 set_temp_type, 1);
707static 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
694static ssize_t show_fan(struct device *dev, struct device_attribute *attr, 724static 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}
704static 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
714static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, 740static 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}
750static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, 776
751 const char *buf, size_t count) 777static 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
782static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, 822static 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) \ 1135static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1096static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 1136static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1097 show_fan, NULL, offset - 1); \ 1137 0, 1);
1098static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 1138static 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);
1100static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ 1140
1101 show_fan_div, set_fan_div, offset - 1); 1141static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1102 1142static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1103show_fan_offset(1); 1143 1, 1);
1104show_fan_offset(2); 1144static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
1105show_fan_offset(3); 1145 set_fan_div, 1);
1106 1146
1107#define show_pwm_offset(offset) \ 1147static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
1108static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ 1148static 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);
1110static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ 1150static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
1111 show_pwm, set_pwm, offset - 1); \ 1151 set_fan_div, 2);
1112static DEVICE_ATTR(pwm##offset##_freq, \ 1152
1113 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \ 1153static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
1114 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \ 1154static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1115static 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); \ 1157static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
1118static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \ 1158static 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
1121static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \ 1161static 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); \ 1163static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
1124static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \ 1164static 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, \ 1165static 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);
1127static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \ 1167static 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);
1129static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \ 1169static 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); \ 1171static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
1132static 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, \ 1173static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
1134 offset - 1, 0); \ 1174 show_auto_pwm, NULL, 0, 3);
1135static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \ 1175static 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); \ 1177static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1138static 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, \ 1179static 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);
1141static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \ 1181static 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); 1183static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
1144 1184 show_auto_temp, set_auto_temp, 0, 4);
1145show_pwm_offset(1); 1185
1146show_pwm_offset(2); 1186static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
1147show_pwm_offset(3); 1187 show_pwm_enable, set_pwm_enable, 1);
1148 1188static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
1149/* A different set of callbacks for 16-bit fans */ 1189static DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, NULL);
1150static ssize_t show_fan16(struct device *dev, struct device_attribute *attr, 1190static 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{ 1192static 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; 1194static 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])); 1196static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
1157} 1197 show_auto_pwm, set_auto_pwm, 1, 2);
1158 1198static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
1159static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr, 1199 show_auto_pwm, NULL, 1, 3);
1160 char *buf) 1200static 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); 1202static 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); 1204static 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} 1206static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
1167 1207 show_auto_temp, set_auto_temp, 1, 3);
1168static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr, 1208static 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); 1211static 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); 1213static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
1174 long val; 1214static DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL);
1175 1215static 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; 1217static 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); 1219static 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], 1221static 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], 1223static 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); 1225static 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} 1227static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1188 1228 show_auto_temp, set_auto_temp, 2, 0);
1189/* 1229static 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 1231static 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 */ 1233static 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);
1195static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
1196 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
1197 show_fan16, NULL, offset - 1); \
1198static 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
1202show_fan16_offset(1);
1203show_fan16_offset(2);
1204show_fan16_offset(3);
1205show_fan16_offset(4);
1206show_fan16_offset(5);
1207 1235
1208/* Alarms */ 1236/* Alarms */
1209static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, 1237static 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
1502static 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
1474static struct attribute *it87_attributes[] = { 1508static 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
1503static struct attribute *it87_attributes_fan16[5][3+1] = { { 1537static 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
1530static const struct attribute_group it87_group_fan16[5] = { 1564static 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
1538static struct attribute *it87_attributes_fan[3][4+1] = { { 1572static 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
1558static 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
1564static const struct attribute_group *
1565it87_get_fan_group(const struct it87_data *data)
1566{
1567 return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan;
1568}
1569
1570static struct attribute *it87_attributes_pwm[3][4+1] = { { 1578static 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
2552MODULE_AUTHOR("Chris Gauthron, " 2593MODULE_AUTHOR("Chris Gauthron, Jean Delvare <khali@linux-fr.org>");
2553 "Jean Delvare <khali@linux-fr.org>");
2554MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver"); 2594MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
2555module_param(update_vbat, bool, 0); 2595module_param(update_vbat, bool, 0);
2556MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); 2596MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 55ac41c05561..0e8ffd6059a0 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * w83627ehf - Driver for the hardware monitoring functionality of 2 * w83627ehf - Driver for the hardware monitoring functionality of
3 * the Winbond W83627EHF Super-I/O chip 3 * the Winbond W83627EHF Super-I/O chip
4 * Copyright (C) 2005-2011 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2005-2012 Jean Delvare <khali@linux-fr.org>
5 * Copyright (C) 2006 Yuan Mu (Winbond), 5 * Copyright (C) 2006 Yuan Mu (Winbond),
6 * Rudolf Marek <r.marek@assembler.cz> 6 * Rudolf Marek <r.marek@assembler.cz>
7 * David Hubbard <david.c.hubbard@gmail.com> 7 * David Hubbard <david.c.hubbard@gmail.com>
@@ -502,6 +502,13 @@ struct w83627ehf_data {
502 u16 have_temp_offset; 502 u16 have_temp_offset;
503 u8 in6_skip:1; 503 u8 in6_skip:1;
504 u8 temp3_val_only:1; 504 u8 temp3_val_only:1;
505
506#ifdef CONFIG_PM
507 /* Remember extra register values over suspend/resume */
508 u8 vbat;
509 u8 fandiv1;
510 u8 fandiv2;
511#endif
505}; 512};
506 513
507struct w83627ehf_sio_data { 514struct w83627ehf_sio_data {
@@ -898,6 +905,8 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
898 data->temp_max_hyst[i] 905 data->temp_max_hyst[i]
899 = w83627ehf_read_temp(data, 906 = w83627ehf_read_temp(data,
900 data->reg_temp_hyst[i]); 907 data->reg_temp_hyst[i]);
908 if (i > 2)
909 continue;
901 if (data->have_temp_offset & (1 << i)) 910 if (data->have_temp_offset & (1 << i))
902 data->temp_offset[i] 911 data->temp_offset[i]
903 = w83627ehf_read_value(data, 912 = w83627ehf_read_value(data,
@@ -2608,10 +2617,98 @@ static int w83627ehf_remove(struct platform_device *pdev)
2608 return 0; 2617 return 0;
2609} 2618}
2610 2619
2620#ifdef CONFIG_PM
2621static int w83627ehf_suspend(struct device *dev)
2622{
2623 struct w83627ehf_data *data = w83627ehf_update_device(dev);
2624 struct w83627ehf_sio_data *sio_data = dev->platform_data;
2625
2626 mutex_lock(&data->update_lock);
2627 data->vbat = w83627ehf_read_value(data, W83627EHF_REG_VBAT);
2628 if (sio_data->kind == nct6775) {
2629 data->fandiv1 = w83627ehf_read_value(data, NCT6775_REG_FANDIV1);
2630 data->fandiv2 = w83627ehf_read_value(data, NCT6775_REG_FANDIV2);
2631 }
2632 mutex_unlock(&data->update_lock);
2633
2634 return 0;
2635}
2636
2637static int w83627ehf_resume(struct device *dev)
2638{
2639 struct w83627ehf_data *data = dev_get_drvdata(dev);
2640 struct w83627ehf_sio_data *sio_data = dev->platform_data;
2641 int i;
2642
2643 mutex_lock(&data->update_lock);
2644 data->bank = 0xff; /* Force initial bank selection */
2645
2646 /* Restore limits */
2647 for (i = 0; i < data->in_num; i++) {
2648 if ((i == 6) && data->in6_skip)
2649 continue;
2650
2651 w83627ehf_write_value(data, W83627EHF_REG_IN_MIN(i),
2652 data->in_min[i]);
2653 w83627ehf_write_value(data, W83627EHF_REG_IN_MAX(i),
2654 data->in_max[i]);
2655 }
2656
2657 for (i = 0; i < 5; i++) {
2658 if (!(data->has_fan_min & (1 << i)))
2659 continue;
2660
2661 w83627ehf_write_value(data, data->REG_FAN_MIN[i],
2662 data->fan_min[i]);
2663 }
2664
2665 for (i = 0; i < NUM_REG_TEMP; i++) {
2666 if (!(data->have_temp & (1 << i)))
2667 continue;
2668
2669 if (data->reg_temp_over[i])
2670 w83627ehf_write_temp(data, data->reg_temp_over[i],
2671 data->temp_max[i]);
2672 if (data->reg_temp_hyst[i])
2673 w83627ehf_write_temp(data, data->reg_temp_hyst[i],
2674 data->temp_max_hyst[i]);
2675 if (i > 2)
2676 continue;
2677 if (data->have_temp_offset & (1 << i))
2678 w83627ehf_write_value(data,
2679 W83627EHF_REG_TEMP_OFFSET[i],
2680 data->temp_offset[i]);
2681 }
2682
2683 /* Restore other settings */
2684 w83627ehf_write_value(data, W83627EHF_REG_VBAT, data->vbat);
2685 if (sio_data->kind == nct6775) {
2686 w83627ehf_write_value(data, NCT6775_REG_FANDIV1, data->fandiv1);
2687 w83627ehf_write_value(data, NCT6775_REG_FANDIV2, data->fandiv2);
2688 }
2689
2690 /* Force re-reading all values */
2691 data->valid = 0;
2692 mutex_unlock(&data->update_lock);
2693
2694 return 0;
2695}
2696
2697static const struct dev_pm_ops w83627ehf_dev_pm_ops = {
2698 .suspend = w83627ehf_suspend,
2699 .resume = w83627ehf_resume,
2700};
2701
2702#define W83627EHF_DEV_PM_OPS (&w83627ehf_dev_pm_ops)
2703#else
2704#define W83627EHF_DEV_PM_OPS NULL
2705#endif /* CONFIG_PM */
2706
2611static struct platform_driver w83627ehf_driver = { 2707static struct platform_driver w83627ehf_driver = {
2612 .driver = { 2708 .driver = {
2613 .owner = THIS_MODULE, 2709 .owner = THIS_MODULE,
2614 .name = DRVNAME, 2710 .name = DRVNAME,
2711 .pm = W83627EHF_DEV_PM_OPS,
2615 }, 2712 },
2616 .probe = w83627ehf_probe, 2713 .probe = w83627ehf_probe,
2617 .remove = w83627ehf_remove, 2714 .remove = w83627ehf_remove,
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 7f68b8309d10..81f486520cea 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -5,7 +5,7 @@
5 * Philip Edelbrock <phil@netroedge.com>, 5 * Philip Edelbrock <phil@netroedge.com>,
6 * and Mark Studebaker <mdsxyz123@yahoo.com> 6 * and Mark Studebaker <mdsxyz123@yahoo.com>
7 * Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org> 7 * Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org>
8 * Copyright (c) 2007 Jean Delvare <khali@linux-fr.org> 8 * Copyright (c) 2007 - 1012 Jean Delvare <khali@linux-fr.org>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
@@ -389,6 +389,12 @@ struct w83627hf_data {
389 */ 389 */
390 u8 vrm; 390 u8 vrm;
391 u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */ 391 u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */
392
393#ifdef CONFIG_PM
394 /* Remember extra register values over suspend/resume */
395 u8 scfg1;
396 u8 scfg2;
397#endif
392}; 398};
393 399
394 400
@@ -401,10 +407,77 @@ static void w83627hf_update_fan_div(struct w83627hf_data *data);
401static struct w83627hf_data *w83627hf_update_device(struct device *dev); 407static struct w83627hf_data *w83627hf_update_device(struct device *dev);
402static void w83627hf_init_device(struct platform_device *pdev); 408static void w83627hf_init_device(struct platform_device *pdev);
403 409
410#ifdef CONFIG_PM
411static int w83627hf_suspend(struct device *dev)
412{
413 struct w83627hf_data *data = w83627hf_update_device(dev);
414
415 mutex_lock(&data->update_lock);
416 data->scfg1 = w83627hf_read_value(data, W83781D_REG_SCFG1);
417 data->scfg2 = w83627hf_read_value(data, W83781D_REG_SCFG2);
418 mutex_unlock(&data->update_lock);
419
420 return 0;
421}
422
423static int w83627hf_resume(struct device *dev)
424{
425 struct w83627hf_data *data = dev_get_drvdata(dev);
426 int i, num_temps = (data->type == w83697hf) ? 2 : 3;
427
428 /* Restore limits */
429 mutex_lock(&data->update_lock);
430 for (i = 0; i <= 8; i++) {
431 /* skip missing sensors */
432 if (((data->type == w83697hf) && (i == 1)) ||
433 ((data->type != w83627hf && data->type != w83697hf)
434 && (i == 5 || i == 6)))
435 continue;
436 w83627hf_write_value(data, W83781D_REG_IN_MAX(i),
437 data->in_max[i]);
438 w83627hf_write_value(data, W83781D_REG_IN_MIN(i),
439 data->in_min[i]);
440 }
441 for (i = 0; i <= 2; i++)
442 w83627hf_write_value(data, W83627HF_REG_FAN_MIN(i),
443 data->fan_min[i]);
444 for (i = 0; i < num_temps; i++) {
445 w83627hf_write_value(data, w83627hf_reg_temp_over[i],
446 data->temp_max[i]);
447 w83627hf_write_value(data, w83627hf_reg_temp_hyst[i],
448 data->temp_max_hyst[i]);
449 }
450
451 /* Fixup BIOS bugs */
452 if (data->type == w83627thf || data->type == w83637hf ||
453 data->type == w83687thf)
454 w83627hf_write_value(data, W83627THF_REG_VRM_OVT_CFG,
455 data->vrm_ovt);
456 w83627hf_write_value(data, W83781D_REG_SCFG1, data->scfg1);
457 w83627hf_write_value(data, W83781D_REG_SCFG2, data->scfg2);
458
459 /* Force re-reading all values */
460 data->valid = 0;
461 mutex_unlock(&data->update_lock);
462
463 return 0;
464}
465
466static const struct dev_pm_ops w83627hf_dev_pm_ops = {
467 .suspend = w83627hf_suspend,
468 .resume = w83627hf_resume,
469};
470
471#define W83627HF_DEV_PM_OPS (&w83627hf_dev_pm_ops)
472#else
473#define W83627HF_DEV_PM_OPS NULL
474#endif /* CONFIG_PM */
475
404static struct platform_driver w83627hf_driver = { 476static struct platform_driver w83627hf_driver = {
405 .driver = { 477 .driver = {
406 .owner = THIS_MODULE, 478 .owner = THIS_MODULE,
407 .name = DRVNAME, 479 .name = DRVNAME,
480 .pm = W83627HF_DEV_PM_OPS,
408 }, 481 },
409 .probe = w83627hf_probe, 482 .probe = w83627hf_probe,
410 .remove = w83627hf_remove, 483 .remove = w83627hf_remove,
@@ -1659,8 +1732,10 @@ static void w83627hf_init_device(struct platform_device *pdev)
1659 /* Minimize conflicts with other winbond i2c-only clients... */ 1732 /* Minimize conflicts with other winbond i2c-only clients... */
1660 /* disable i2c subclients... how to disable main i2c client?? */ 1733 /* disable i2c subclients... how to disable main i2c client?? */
1661 /* force i2c address to relatively uncommon address */ 1734 /* force i2c address to relatively uncommon address */
1662 w83627hf_write_value(data, W83781D_REG_I2C_SUBADDR, 0x89); 1735 if (type == w83627hf) {
1663 w83627hf_write_value(data, W83781D_REG_I2C_ADDR, force_i2c); 1736 w83627hf_write_value(data, W83781D_REG_I2C_SUBADDR, 0x89);
1737 w83627hf_write_value(data, W83781D_REG_I2C_ADDR, force_i2c);
1738 }
1664 1739
1665 /* Read VID only once */ 1740 /* Read VID only once */
1666 if (type == w83627hf || type == w83637hf) { 1741 if (type == w83627hf || type == w83637hf) {