aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83627hf.c
diff options
context:
space:
mode:
authorJim Cromie <jim.cromie@gmail.com>2007-10-14 19:10:52 -0400
committerMark M. Hoffman <mhoffman@lightlink.com>2007-11-08 08:42:45 -0500
commitdf48ed804f44a040e990976b537efc1e133c74d8 (patch)
tree8d3a0324b795cfebb7409db9a89960069de44bc5 /drivers/hwmon/w83627hf.c
parent38fb56a223be9ec860e69e723d32c95fd70ad0b8 (diff)
hwmon: (w83627hf) hoist nr-1 offset out of show-store-temp-X
This hoists nr-1 offset out of (show|store)_temp_*(.*) callbacks, and into SENSOR_DEVICE_ATTRs for sysfs tempN_X files. It also combines temp[1] and temp_add[2] (array) fields in w83627hf_data into 3 elem arrays, which simplifies special-case handling of nr, allowing simplification of callback bodies and rerolling a flattened loop in w83627hf_update_device(struct device *dev). The array conversion changes temp[1] from u8 to u16, but this was happening implicitly via the helper functions anyway. Signed-off-by: Jim Cromie <jim.cromie@gmail.com> Acked-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon/w83627hf.c')
-rw-r--r--drivers/hwmon/w83627hf.c126
1 files changed, 42 insertions, 84 deletions
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 20ae425a1980..410f10687cc4 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -173,17 +173,12 @@ superio_exit(void)
173#define W83781D_REG_FAN_MIN(nr) (0x3a + (nr)) 173#define W83781D_REG_FAN_MIN(nr) (0x3a + (nr))
174#define W83781D_REG_FAN(nr) (0x27 + (nr)) 174#define W83781D_REG_FAN(nr) (0x27 + (nr))
175 175
176#define W83781D_REG_TEMP2_CONFIG 0x152 176#define W83627HF_REG_TEMP2_CONFIG 0x152
177#define W83781D_REG_TEMP3_CONFIG 0x252 177#define W83627HF_REG_TEMP3_CONFIG 0x252
178#define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \ 178/* these are zero-based, unlike config constants above */
179 ((nr == 2) ? (0x0150) : \ 179static const u16 w83627hf_reg_temp[] = { 0x27, 0x150, 0x250 };
180 (0x27))) 180static const u16 w83627hf_reg_temp_hyst[] = { 0x3A, 0x153, 0x253 };
181#define W83781D_REG_TEMP_HYST(nr) ((nr == 3) ? (0x253) : \ 181static const u16 w83627hf_reg_temp_over[] = { 0x39, 0x155, 0x255 };
182 ((nr == 2) ? (0x153) : \
183 (0x3A)))
184#define W83781D_REG_TEMP_OVER(nr) ((nr == 3) ? (0x255) : \
185 ((nr == 2) ? (0x155) : \
186 (0x39)))
187 182
188#define W83781D_REG_BANK 0x4E 183#define W83781D_REG_BANK 0x4E
189 184
@@ -360,12 +355,9 @@ struct w83627hf_data {
360 u8 in_min[9]; /* Register value */ 355 u8 in_min[9]; /* Register value */
361 u8 fan[3]; /* Register value */ 356 u8 fan[3]; /* Register value */
362 u8 fan_min[3]; /* Register value */ 357 u8 fan_min[3]; /* Register value */
363 u8 temp; 358 u16 temp[3]; /* Register value */
364 u8 temp_max; /* Register value */ 359 u16 temp_max[3]; /* Register value */
365 u8 temp_max_hyst; /* Register value */ 360 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 */ 361 u8 fan_div[3]; /* Register encoding, shifted right */
370 u8 vid; /* Register encoding, combined */ 362 u8 vid; /* Register encoding, combined */
371 u32 alarms; /* Register encoding, combined */ 363 u32 alarms; /* Register encoding, combined */
@@ -611,12 +603,10 @@ show_temp(struct device *dev, struct device_attribute *devattr, char *buf)
611{ 603{
612 int nr = to_sensor_dev_attr(devattr)->index; 604 int nr = to_sensor_dev_attr(devattr)->index;
613 struct w83627hf_data *data = w83627hf_update_device(dev); 605 struct w83627hf_data *data = w83627hf_update_device(dev);
614 if (nr >= 2) { /* TEMP2 and TEMP3 */ 606
615 return sprintf(buf, "%ld\n", 607 u16 tmp = data->temp[nr];
616 (long)LM75_TEMP_FROM_REG(data->temp_add[nr-2])); 608 return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp)
617 } else { /* TEMP1 */ 609 : (long) TEMP_FROM_REG(tmp));
618 return sprintf(buf, "%ld\n", (long)TEMP_FROM_REG(data->temp));
619 }
620} 610}
621 611
622static ssize_t 612static ssize_t
@@ -625,13 +615,10 @@ show_temp_max(struct device *dev, struct device_attribute *devattr,
625{ 615{
626 int nr = to_sensor_dev_attr(devattr)->index; 616 int nr = to_sensor_dev_attr(devattr)->index;
627 struct w83627hf_data *data = w83627hf_update_device(dev); 617 struct w83627hf_data *data = w83627hf_update_device(dev);
628 if (nr >= 2) { /* TEMP2 and TEMP3 */ 618
629 return sprintf(buf, "%ld\n", 619 u16 tmp = data->temp_max[nr];
630 (long)LM75_TEMP_FROM_REG(data->temp_max_add[nr-2])); 620 return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp)
631 } else { /* TEMP1 */ 621 : (long) TEMP_FROM_REG(tmp));
632 return sprintf(buf, "%ld\n",
633 (long)TEMP_FROM_REG(data->temp_max));
634 }
635} 622}
636 623
637static ssize_t 624static ssize_t
@@ -640,13 +627,10 @@ show_temp_max_hyst(struct device *dev, struct device_attribute *devattr,
640{ 627{
641 int nr = to_sensor_dev_attr(devattr)->index; 628 int nr = to_sensor_dev_attr(devattr)->index;
642 struct w83627hf_data *data = w83627hf_update_device(dev); 629 struct w83627hf_data *data = w83627hf_update_device(dev);
643 if (nr >= 2) { /* TEMP2 and TEMP3 */ 630
644 return sprintf(buf, "%ld\n", 631 u16 tmp = data->temp_max_hyst[nr];
645 (long)LM75_TEMP_FROM_REG(data->temp_max_hyst_add[nr-2])); 632 return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp)
646 } else { /* TEMP1 */ 633 : (long) TEMP_FROM_REG(tmp));
647 return sprintf(buf, "%ld\n",
648 (long)TEMP_FROM_REG(data->temp_max_hyst));
649 }
650} 634}
651 635
652static ssize_t 636static ssize_t
@@ -656,18 +640,11 @@ store_temp_max(struct device *dev, struct device_attribute *devattr,
656 int nr = to_sensor_dev_attr(devattr)->index; 640 int nr = to_sensor_dev_attr(devattr)->index;
657 struct w83627hf_data *data = dev_get_drvdata(dev); 641 struct w83627hf_data *data = dev_get_drvdata(dev);
658 long val = simple_strtol(buf, NULL, 10); 642 long val = simple_strtol(buf, NULL, 10);
643 u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val);
659 644
660 mutex_lock(&data->update_lock); 645 mutex_lock(&data->update_lock);
661 646 data->temp_max[nr] = tmp;
662 if (nr >= 2) { /* TEMP2 and TEMP3 */ 647 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); 648 mutex_unlock(&data->update_lock);
672 return count; 649 return count;
673} 650}
@@ -679,29 +656,22 @@ store_temp_max_hyst(struct device *dev, struct device_attribute *devattr,
679 int nr = to_sensor_dev_attr(devattr)->index; 656 int nr = to_sensor_dev_attr(devattr)->index;
680 struct w83627hf_data *data = dev_get_drvdata(dev); 657 struct w83627hf_data *data = dev_get_drvdata(dev);
681 long val = simple_strtol(buf, NULL, 10); 658 long val = simple_strtol(buf, NULL, 10);
659 u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val);
682 660
683 mutex_lock(&data->update_lock); 661 mutex_lock(&data->update_lock);
684 662 data->temp_max_hyst[nr] = tmp;
685 if (nr >= 2) { /* TEMP2 and TEMP3 */ 663 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); 664 mutex_unlock(&data->update_lock);
695 return count; 665 return count;
696} 666}
697 667
698#define sysfs_temp_decl(offset) \ 668#define sysfs_temp_decl(offset) \
699static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ 669static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
700 show_temp, NULL, offset); \ 670 show_temp, NULL, offset - 1); \
701static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO|S_IWUSR, \ 671static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO|S_IWUSR, \
702 show_temp_max, store_temp_max, offset); \ 672 show_temp_max, store_temp_max, offset - 1); \
703static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO|S_IWUSR, \ 673static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO|S_IWUSR, \
704 show_temp_max_hyst, store_temp_max_hyst, offset); 674 show_temp_max_hyst, store_temp_max_hyst, offset - 1);
705 675
706sysfs_temp_decl(1); 676sysfs_temp_decl(1);
707sysfs_temp_decl(2); 677sysfs_temp_decl(2);
@@ -1514,23 +1484,23 @@ static void __devinit w83627hf_init_device(struct platform_device *pdev)
1514 1484
1515 if(init) { 1485 if(init) {
1516 /* Enable temp2 */ 1486 /* Enable temp2 */
1517 tmp = w83627hf_read_value(data, W83781D_REG_TEMP2_CONFIG); 1487 tmp = w83627hf_read_value(data, W83627HF_REG_TEMP2_CONFIG);
1518 if (tmp & 0x01) { 1488 if (tmp & 0x01) {
1519 dev_warn(&pdev->dev, "Enabling temp2, readings " 1489 dev_warn(&pdev->dev, "Enabling temp2, readings "
1520 "might not make sense\n"); 1490 "might not make sense\n");
1521 w83627hf_write_value(data, W83781D_REG_TEMP2_CONFIG, 1491 w83627hf_write_value(data, W83627HF_REG_TEMP2_CONFIG,
1522 tmp & 0xfe); 1492 tmp & 0xfe);
1523 } 1493 }
1524 1494
1525 /* Enable temp3 */ 1495 /* Enable temp3 */
1526 if (type != w83697hf) { 1496 if (type != w83697hf) {
1527 tmp = w83627hf_read_value(data, 1497 tmp = w83627hf_read_value(data,
1528 W83781D_REG_TEMP3_CONFIG); 1498 W83627HF_REG_TEMP3_CONFIG);
1529 if (tmp & 0x01) { 1499 if (tmp & 0x01) {
1530 dev_warn(&pdev->dev, "Enabling temp3, " 1500 dev_warn(&pdev->dev, "Enabling temp3, "
1531 "readings might not make sense\n"); 1501 "readings might not make sense\n");
1532 w83627hf_write_value(data, 1502 w83627hf_write_value(data,
1533 W83781D_REG_TEMP3_CONFIG, tmp & 0xfe); 1503 W83627HF_REG_TEMP3_CONFIG, tmp & 0xfe);
1534 } 1504 }
1535 } 1505 }
1536 } 1506 }
@@ -1563,7 +1533,7 @@ static void w83627hf_update_fan_div(struct w83627hf_data *data)
1563static struct w83627hf_data *w83627hf_update_device(struct device *dev) 1533static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1564{ 1534{
1565 struct w83627hf_data *data = dev_get_drvdata(dev); 1535 struct w83627hf_data *data = dev_get_drvdata(dev);
1566 int i; 1536 int i, num_temps = (data->type == w83697hf) ? 2 : 3;
1567 1537
1568 mutex_lock(&data->update_lock); 1538 mutex_lock(&data->update_lock);
1569 1539
@@ -1616,25 +1586,13 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1616 break; 1586 break;
1617 } 1587 }
1618 } 1588 }
1619 1589 for (i = 0; i < num_temps; i++) {
1620 data->temp = w83627hf_read_value(data, W83781D_REG_TEMP(1)); 1590 data->temp[i] = w83627hf_read_value(
1621 data->temp_max = 1591 data, w83627hf_reg_temp[i]);
1622 w83627hf_read_value(data, W83781D_REG_TEMP_OVER(1)); 1592 data->temp_max[i] = w83627hf_read_value(
1623 data->temp_max_hyst = 1593 data, w83627hf_reg_temp_over[i]);
1624 w83627hf_read_value(data, W83781D_REG_TEMP_HYST(1)); 1594 data->temp_max_hyst[i] = w83627hf_read_value(
1625 data->temp_add[0] = 1595 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 } 1596 }
1639 1597
1640 w83627hf_update_fan_div(data); 1598 w83627hf_update_fan_div(data);