aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83627hf.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/w83627hf.c')
-rw-r--r--drivers/hwmon/w83627hf.c155
1 files changed, 57 insertions, 98 deletions
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 20ae425a1980..879d0a6544cc 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -170,20 +170,16 @@ superio_exit(void)
170#define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ 170#define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
171 (0x550 + (nr) - 7)) 171 (0x550 + (nr) - 7))
172 172
173#define W83781D_REG_FAN_MIN(nr) (0x3a + (nr)) 173/* nr:0-2 for fans:1-3 */
174#define W83781D_REG_FAN(nr) (0x27 + (nr)) 174#define W83627HF_REG_FAN_MIN(nr) (0x3b + (nr))
175 175#define W83627HF_REG_FAN(nr) (0x28 + (nr))
176#define W83781D_REG_TEMP2_CONFIG 0x152 176
177#define W83781D_REG_TEMP3_CONFIG 0x252 177#define W83627HF_REG_TEMP2_CONFIG 0x152
178#define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \ 178#define W83627HF_REG_TEMP3_CONFIG 0x252
179 ((nr == 2) ? (0x0150) : \ 179/* these are zero-based, unlike config constants above */
180 (0x27))) 180static const u16 w83627hf_reg_temp[] = { 0x27, 0x150, 0x250 };
181#define W83781D_REG_TEMP_HYST(nr) ((nr == 3) ? (0x253) : \ 181static const u16 w83627hf_reg_temp_hyst[] = { 0x3A, 0x153, 0x253 };
182 ((nr == 2) ? (0x153) : \ 182static const u16 w83627hf_reg_temp_over[] = { 0x39, 0x155, 0x255 };
183 (0x3A)))
184#define W83781D_REG_TEMP_OVER(nr) ((nr == 3) ? (0x255) : \
185 ((nr == 2) ? (0x155) : \
186 (0x39)))
187 183
188#define W83781D_REG_BANK 0x4E 184#define W83781D_REG_BANK 0x4E
189 185
@@ -360,12 +356,9 @@ struct w83627hf_data {
360 u8 in_min[9]; /* Register value */ 356 u8 in_min[9]; /* Register value */
361 u8 fan[3]; /* Register value */ 357 u8 fan[3]; /* Register value */
362 u8 fan_min[3]; /* Register value */ 358 u8 fan_min[3]; /* Register value */
363 u8 temp; 359 u16 temp[3]; /* Register value */
364 u8 temp_max; /* Register value */ 360 u16 temp_max[3]; /* Register value */
365 u8 temp_max_hyst; /* Register value */ 361 u16 temp_max_hyst[3]; /* Register value */
366 u16 temp_add[2]; /* Register value */
367 u16 temp_max_add[2]; /* Register value */
368 u16 temp_max_hyst_add[2]; /* Register value */
369 u8 fan_div[3]; /* Register encoding, shifted right */ 362 u8 fan_div[3]; /* Register encoding, shifted right */
370 u8 vid; /* Register encoding, combined */ 363 u8 vid; /* Register encoding, combined */
371 u32 alarms; /* Register encoding, combined */ 364 u32 alarms; /* Register encoding, combined */
@@ -590,7 +583,7 @@ store_fan_min(struct device *dev, struct device_attribute *devattr,
590 583
591 mutex_lock(&data->update_lock); 584 mutex_lock(&data->update_lock);
592 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 585 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
593 w83627hf_write_value(data, W83781D_REG_FAN_MIN(nr+1), 586 w83627hf_write_value(data, W83627HF_REG_FAN_MIN(nr),
594 data->fan_min[nr]); 587 data->fan_min[nr]);
595 588
596 mutex_unlock(&data->update_lock); 589 mutex_unlock(&data->update_lock);
@@ -611,12 +604,10 @@ show_temp(struct device *dev, struct device_attribute *devattr, char *buf)
611{ 604{
612 int nr = to_sensor_dev_attr(devattr)->index; 605 int nr = to_sensor_dev_attr(devattr)->index;
613 struct w83627hf_data *data = w83627hf_update_device(dev); 606 struct w83627hf_data *data = w83627hf_update_device(dev);
614 if (nr >= 2) { /* TEMP2 and TEMP3 */ 607
615 return sprintf(buf, "%ld\n", 608 u16 tmp = data->temp[nr];
616 (long)LM75_TEMP_FROM_REG(data->temp_add[nr-2])); 609 return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp)
617 } else { /* TEMP1 */ 610 : (long) TEMP_FROM_REG(tmp));
618 return sprintf(buf, "%ld\n", (long)TEMP_FROM_REG(data->temp));
619 }
620} 611}
621 612
622static ssize_t 613static ssize_t
@@ -625,13 +616,10 @@ show_temp_max(struct device *dev, struct device_attribute *devattr,
625{ 616{
626 int nr = to_sensor_dev_attr(devattr)->index; 617 int nr = to_sensor_dev_attr(devattr)->index;
627 struct w83627hf_data *data = w83627hf_update_device(dev); 618 struct w83627hf_data *data = w83627hf_update_device(dev);
628 if (nr >= 2) { /* TEMP2 and TEMP3 */ 619
629 return sprintf(buf, "%ld\n", 620 u16 tmp = data->temp_max[nr];
630 (long)LM75_TEMP_FROM_REG(data->temp_max_add[nr-2])); 621 return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp)
631 } else { /* TEMP1 */ 622 : (long) TEMP_FROM_REG(tmp));
632 return sprintf(buf, "%ld\n",
633 (long)TEMP_FROM_REG(data->temp_max));
634 }
635} 623}
636 624
637static ssize_t 625static ssize_t
@@ -640,13 +628,10 @@ show_temp_max_hyst(struct device *dev, struct device_attribute *devattr,
640{ 628{
641 int nr = to_sensor_dev_attr(devattr)->index; 629 int nr = to_sensor_dev_attr(devattr)->index;
642 struct w83627hf_data *data = w83627hf_update_device(dev); 630 struct w83627hf_data *data = w83627hf_update_device(dev);
643 if (nr >= 2) { /* TEMP2 and TEMP3 */ 631
644 return sprintf(buf, "%ld\n", 632 u16 tmp = data->temp_max_hyst[nr];
645 (long)LM75_TEMP_FROM_REG(data->temp_max_hyst_add[nr-2])); 633 return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp)
646 } else { /* TEMP1 */ 634 : (long) TEMP_FROM_REG(tmp));
647 return sprintf(buf, "%ld\n",
648 (long)TEMP_FROM_REG(data->temp_max_hyst));
649 }
650} 635}
651 636
652static ssize_t 637static ssize_t
@@ -656,18 +641,11 @@ store_temp_max(struct device *dev, struct device_attribute *devattr,
656 int nr = to_sensor_dev_attr(devattr)->index; 641 int nr = to_sensor_dev_attr(devattr)->index;
657 struct w83627hf_data *data = dev_get_drvdata(dev); 642 struct w83627hf_data *data = dev_get_drvdata(dev);
658 long val = simple_strtol(buf, NULL, 10); 643 long val = simple_strtol(buf, NULL, 10);
644 u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val);
659 645
660 mutex_lock(&data->update_lock); 646 mutex_lock(&data->update_lock);
661 647 data->temp_max[nr] = tmp;
662 if (nr >= 2) { /* TEMP2 and TEMP3 */ 648 w83627hf_write_value(data, w83627hf_reg_temp_over[nr], tmp);
663 data->temp_max_add[nr-2] = LM75_TEMP_TO_REG(val);
664 w83627hf_write_value(data, W83781D_REG_TEMP_OVER(nr),
665 data->temp_max_add[nr-2]);
666 } else { /* TEMP1 */
667 data->temp_max = TEMP_TO_REG(val);
668 w83627hf_write_value(data, W83781D_REG_TEMP_OVER(nr),
669 data->temp_max);
670 }
671 mutex_unlock(&data->update_lock); 649 mutex_unlock(&data->update_lock);
672 return count; 650 return count;
673} 651}
@@ -679,29 +657,22 @@ store_temp_max_hyst(struct device *dev, struct device_attribute *devattr,
679 int nr = to_sensor_dev_attr(devattr)->index; 657 int nr = to_sensor_dev_attr(devattr)->index;
680 struct w83627hf_data *data = dev_get_drvdata(dev); 658 struct w83627hf_data *data = dev_get_drvdata(dev);
681 long val = simple_strtol(buf, NULL, 10); 659 long val = simple_strtol(buf, NULL, 10);
660 u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val);
682 661
683 mutex_lock(&data->update_lock); 662 mutex_lock(&data->update_lock);
684 663 data->temp_max_hyst[nr] = tmp;
685 if (nr >= 2) { /* TEMP2 and TEMP3 */ 664 w83627hf_write_value(data, w83627hf_reg_temp_hyst[nr], tmp);
686 data->temp_max_hyst_add[nr-2] = LM75_TEMP_TO_REG(val);
687 w83627hf_write_value(data, W83781D_REG_TEMP_HYST(nr),
688 data->temp_max_hyst_add[nr-2]);
689 } else { /* TEMP1 */
690 data->temp_max_hyst = TEMP_TO_REG(val);
691 w83627hf_write_value(data, W83781D_REG_TEMP_HYST(nr),
692 data->temp_max_hyst);
693 }
694 mutex_unlock(&data->update_lock); 665 mutex_unlock(&data->update_lock);
695 return count; 666 return count;
696} 667}
697 668
698#define sysfs_temp_decl(offset) \ 669#define sysfs_temp_decl(offset) \
699static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ 670static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
700 show_temp, NULL, offset); \ 671 show_temp, NULL, offset - 1); \
701static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO|S_IWUSR, \ 672static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO|S_IWUSR, \
702 show_temp_max, store_temp_max, offset); \ 673 show_temp_max, store_temp_max, offset - 1); \
703static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO|S_IWUSR, \ 674static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO|S_IWUSR, \
704 show_temp_max_hyst, store_temp_max_hyst, offset); 675 show_temp_max_hyst, store_temp_max_hyst, offset - 1);
705 676
706sysfs_temp_decl(1); 677sysfs_temp_decl(1);
707sysfs_temp_decl(2); 678sysfs_temp_decl(2);
@@ -844,7 +815,7 @@ store_fan_div(struct device *dev, struct device_attribute *devattr,
844 815
845 /* Restore fan_min */ 816 /* Restore fan_min */
846 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 817 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
847 w83627hf_write_value(data, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); 818 w83627hf_write_value(data, W83627HF_REG_FAN_MIN(nr), data->fan_min[nr]);
848 819
849 mutex_unlock(&data->update_lock); 820 mutex_unlock(&data->update_lock);
850 return count; 821 return count;
@@ -1170,7 +1141,7 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
1170 struct w83627hf_sio_data *sio_data = dev->platform_data; 1141 struct w83627hf_sio_data *sio_data = dev->platform_data;
1171 struct w83627hf_data *data; 1142 struct w83627hf_data *data;
1172 struct resource *res; 1143 struct resource *res;
1173 int err; 1144 int err, i;
1174 1145
1175 static const char *names[] = { 1146 static const char *names[] = {
1176 "w83627hf", 1147 "w83627hf",
@@ -1204,9 +1175,9 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
1204 w83627hf_init_device(pdev); 1175 w83627hf_init_device(pdev);
1205 1176
1206 /* A few vars need to be filled upon startup */ 1177 /* A few vars need to be filled upon startup */
1207 data->fan_min[0] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(1)); 1178 for (i = 0; i <= 2; i++)
1208 data->fan_min[1] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(2)); 1179 data->fan_min[i] = w83627hf_read_value(
1209 data->fan_min[2] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(3)); 1180 data, W83627HF_REG_FAN_MIN(i));
1210 w83627hf_update_fan_div(data); 1181 w83627hf_update_fan_div(data);
1211 1182
1212 /* Register common device attributes */ 1183 /* Register common device attributes */
@@ -1514,23 +1485,23 @@ static void __devinit w83627hf_init_device(struct platform_device *pdev)
1514 1485
1515 if(init) { 1486 if(init) {
1516 /* Enable temp2 */ 1487 /* Enable temp2 */
1517 tmp = w83627hf_read_value(data, W83781D_REG_TEMP2_CONFIG); 1488 tmp = w83627hf_read_value(data, W83627HF_REG_TEMP2_CONFIG);
1518 if (tmp & 0x01) { 1489 if (tmp & 0x01) {
1519 dev_warn(&pdev->dev, "Enabling temp2, readings " 1490 dev_warn(&pdev->dev, "Enabling temp2, readings "
1520 "might not make sense\n"); 1491 "might not make sense\n");
1521 w83627hf_write_value(data, W83781D_REG_TEMP2_CONFIG, 1492 w83627hf_write_value(data, W83627HF_REG_TEMP2_CONFIG,
1522 tmp & 0xfe); 1493 tmp & 0xfe);
1523 } 1494 }
1524 1495
1525 /* Enable temp3 */ 1496 /* Enable temp3 */
1526 if (type != w83697hf) { 1497 if (type != w83697hf) {
1527 tmp = w83627hf_read_value(data, 1498 tmp = w83627hf_read_value(data,
1528 W83781D_REG_TEMP3_CONFIG); 1499 W83627HF_REG_TEMP3_CONFIG);
1529 if (tmp & 0x01) { 1500 if (tmp & 0x01) {
1530 dev_warn(&pdev->dev, "Enabling temp3, " 1501 dev_warn(&pdev->dev, "Enabling temp3, "
1531 "readings might not make sense\n"); 1502 "readings might not make sense\n");
1532 w83627hf_write_value(data, 1503 w83627hf_write_value(data,
1533 W83781D_REG_TEMP3_CONFIG, tmp & 0xfe); 1504 W83627HF_REG_TEMP3_CONFIG, tmp & 0xfe);
1534 } 1505 }
1535 } 1506 }
1536 } 1507 }
@@ -1563,7 +1534,7 @@ static void w83627hf_update_fan_div(struct w83627hf_data *data)
1563static struct w83627hf_data *w83627hf_update_device(struct device *dev) 1534static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1564{ 1535{
1565 struct w83627hf_data *data = dev_get_drvdata(dev); 1536 struct w83627hf_data *data = dev_get_drvdata(dev);
1566 int i; 1537 int i, num_temps = (data->type == w83697hf) ? 2 : 3;
1567 1538
1568 mutex_lock(&data->update_lock); 1539 mutex_lock(&data->update_lock);
1569 1540
@@ -1584,12 +1555,12 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1584 w83627hf_read_value(data, 1555 w83627hf_read_value(data,
1585 W83781D_REG_IN_MAX(i)); 1556 W83781D_REG_IN_MAX(i));
1586 } 1557 }
1587 for (i = 1; i <= 3; i++) { 1558 for (i = 0; i <= 2; i++) {
1588 data->fan[i - 1] = 1559 data->fan[i] =
1589 w83627hf_read_value(data, W83781D_REG_FAN(i)); 1560 w83627hf_read_value(data, W83627HF_REG_FAN(i));
1590 data->fan_min[i - 1] = 1561 data->fan_min[i] =
1591 w83627hf_read_value(data, 1562 w83627hf_read_value(data,
1592 W83781D_REG_FAN_MIN(i)); 1563 W83627HF_REG_FAN_MIN(i));
1593 } 1564 }
1594 for (i = 0; i <= 2; i++) { 1565 for (i = 0; i <= 2; i++) {
1595 u8 tmp = w83627hf_read_value(data, 1566 u8 tmp = w83627hf_read_value(data,
@@ -1616,25 +1587,13 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1616 break; 1587 break;
1617 } 1588 }
1618 } 1589 }
1619 1590 for (i = 0; i < num_temps; i++) {
1620 data->temp = w83627hf_read_value(data, W83781D_REG_TEMP(1)); 1591 data->temp[i] = w83627hf_read_value(
1621 data->temp_max = 1592 data, w83627hf_reg_temp[i]);
1622 w83627hf_read_value(data, W83781D_REG_TEMP_OVER(1)); 1593 data->temp_max[i] = w83627hf_read_value(
1623 data->temp_max_hyst = 1594 data, w83627hf_reg_temp_over[i]);
1624 w83627hf_read_value(data, W83781D_REG_TEMP_HYST(1)); 1595 data->temp_max_hyst[i] = w83627hf_read_value(
1625 data->temp_add[0] = 1596 data, w83627hf_reg_temp_hyst[i]);
1626 w83627hf_read_value(data, W83781D_REG_TEMP(2));
1627 data->temp_max_add[0] =
1628 w83627hf_read_value(data, W83781D_REG_TEMP_OVER(2));
1629 data->temp_max_hyst_add[0] =
1630 w83627hf_read_value(data, W83781D_REG_TEMP_HYST(2));
1631 if (data->type != w83697hf) {
1632 data->temp_add[1] =
1633 w83627hf_read_value(data, W83781D_REG_TEMP(3));
1634 data->temp_max_add[1] =
1635 w83627hf_read_value(data, W83781D_REG_TEMP_OVER(3));
1636 data->temp_max_hyst_add[1] =
1637 w83627hf_read_value(data, W83781D_REG_TEMP_HYST(3));
1638 } 1597 }
1639 1598
1640 w83627hf_update_fan_div(data); 1599 w83627hf_update_fan_div(data);