aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/dme1737.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/dme1737.c')
-rw-r--r--drivers/hwmon/dme1737.c954
1 files changed, 641 insertions, 313 deletions
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index e9cbc727664d..a878c98e252e 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -1,12 +1,12 @@
1/* 1/*
2 * dme1737.c - driver for the SMSC DME1737 and Asus A8000 Super-I/O chips 2 * dme1737.c - Driver for the SMSC DME1737, Asus A8000, and SMSC SCH311x
3 * integrated hardware monitoring features. 3 * Super-I/O chips integrated hardware monitoring features.
4 * Copyright (c) 2007 Juerg Haefliger <juergh@gmail.com> 4 * Copyright (c) 2007 Juerg Haefliger <juergh@gmail.com>
5 * 5 *
6 * This driver is based on the LM85 driver. The hardware monitoring 6 * This driver is an I2C/ISA hybrid, meaning that it uses the I2C bus to access
7 * capabilities of the DME1737 are very similar to the LM85 with some 7 * the chip registers if a DME1737 (or A8000) is found and the ISA bus if a
8 * additional features. Even though the DME1737 is a Super-I/O chip, the 8 * SCH311x chip is found. Both types of chips have very similar hardware
9 * hardware monitoring registers are only accessible via SMBus. 9 * monitoring capabilities but differ in the way they can be accessed.
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/jiffies.h> 29#include <linux/jiffies.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/platform_device.h>
31#include <linux/hwmon.h> 32#include <linux/hwmon.h>
32#include <linux/hwmon-sysfs.h> 33#include <linux/hwmon-sysfs.h>
33#include <linux/hwmon-vid.h> 34#include <linux/hwmon-vid.h>
@@ -35,6 +36,9 @@
35#include <linux/mutex.h> 36#include <linux/mutex.h>
36#include <asm/io.h> 37#include <asm/io.h>
37 38
39/* ISA device, if found */
40static struct platform_device *pdev;
41
38/* Module load parameters */ 42/* Module load parameters */
39static int force_start; 43static int force_start;
40module_param(force_start, bool, 0); 44module_param(force_start, bool, 0);
@@ -133,6 +137,7 @@ static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6};
133static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23}; 137static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
134 138
135/* Miscellaneous registers */ 139/* Miscellaneous registers */
140#define DME1737_REG_DEVICE 0x3d
136#define DME1737_REG_COMPANY 0x3e 141#define DME1737_REG_COMPANY 0x3e
137#define DME1737_REG_VERSTEP 0x3f 142#define DME1737_REG_VERSTEP 0x3f
138#define DME1737_REG_CONFIG 0x40 143#define DME1737_REG_CONFIG 0x40
@@ -148,14 +153,20 @@ static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
148#define DME1737_COMPANY_SMSC 0x5c 153#define DME1737_COMPANY_SMSC 0x5c
149#define DME1737_VERSTEP 0x88 154#define DME1737_VERSTEP 0x88
150#define DME1737_VERSTEP_MASK 0xf8 155#define DME1737_VERSTEP_MASK 0xf8
156#define SCH311X_DEVICE 0x8c
157
158/* Length of ISA address segment */
159#define DME1737_EXTENT 2
151 160
152/* --------------------------------------------------------------------- 161/* ---------------------------------------------------------------------
153 * Data structures and manipulation thereof 162 * Data structures and manipulation thereof
154 * --------------------------------------------------------------------- */ 163 * --------------------------------------------------------------------- */
155 164
165/* For ISA chips, we abuse the i2c_client addr and name fields. We also use
166 the driver field to differentiate between I2C and ISA chips. */
156struct dme1737_data { 167struct dme1737_data {
157 struct i2c_client client; 168 struct i2c_client client;
158 struct class_device *class_dev; 169 struct device *hwmon_dev;
159 170
160 struct mutex update_lock; 171 struct mutex update_lock;
161 int valid; /* !=0 if following fields are valid */ 172 int valid; /* !=0 if following fields are valid */
@@ -465,27 +476,48 @@ static inline int PWM_OFF_TO_REG(int val, int ix, int reg)
465 476
466/* --------------------------------------------------------------------- 477/* ---------------------------------------------------------------------
467 * Device I/O access 478 * Device I/O access
479 *
480 * ISA access is performed through an index/data register pair and needs to
481 * be protected by a mutex during runtime (not required for initialization).
482 * We use data->update_lock for this and need to ensure that we acquire it
483 * before calling dme1737_read or dme1737_write.
468 * --------------------------------------------------------------------- */ 484 * --------------------------------------------------------------------- */
469 485
470static u8 dme1737_read(struct i2c_client *client, u8 reg) 486static u8 dme1737_read(struct i2c_client *client, u8 reg)
471{ 487{
472 s32 val = i2c_smbus_read_byte_data(client, reg); 488 s32 val;
489
490 if (client->driver) { /* I2C device */
491 val = i2c_smbus_read_byte_data(client, reg);
473 492
474 if (val < 0) { 493 if (val < 0) {
475 dev_warn(&client->dev, "Read from register 0x%02x failed! " 494 dev_warn(&client->dev, "Read from register "
476 "Please report to the driver maintainer.\n", reg); 495 "0x%02x failed! Please report to the driver "
496 "maintainer.\n", reg);
497 }
498 } else { /* ISA device */
499 outb(reg, client->addr);
500 val = inb(client->addr + 1);
477 } 501 }
478 502
479 return val; 503 return val;
480} 504}
481 505
482static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 value) 506static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val)
483{ 507{
484 s32 res = i2c_smbus_write_byte_data(client, reg, value); 508 s32 res = 0;
509
510 if (client->driver) { /* I2C device */
511 res = i2c_smbus_write_byte_data(client, reg, val);
485 512
486 if (res < 0) { 513 if (res < 0) {
487 dev_warn(&client->dev, "Write to register 0x%02x failed! " 514 dev_warn(&client->dev, "Write to register "
488 "Please report to the driver maintainer.\n", reg); 515 "0x%02x failed! Please report to the driver "
516 "maintainer.\n", reg);
517 }
518 } else { /* ISA device */
519 outb(reg, client->addr);
520 outb(val, client->addr + 1);
489 } 521 }
490 522
491 return res; 523 return res;
@@ -493,8 +525,8 @@ static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 value)
493 525
494static struct dme1737_data *dme1737_update_device(struct device *dev) 526static struct dme1737_data *dme1737_update_device(struct device *dev)
495{ 527{
496 struct i2c_client *client = to_i2c_client(dev); 528 struct dme1737_data *data = dev_get_drvdata(dev);
497 struct dme1737_data *data = i2c_get_clientdata(client); 529 struct i2c_client *client = &data->client;
498 int ix; 530 int ix;
499 u8 lsb[5]; 531 u8 lsb[5];
500 532
@@ -630,6 +662,24 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
630 DME1737_REG_ALARM3) << 16; 662 DME1737_REG_ALARM3) << 16;
631 } 663 }
632 664
665 /* The ISA chips require explicit clearing of alarm bits.
666 * Don't worry, an alarm will come back if the condition
667 * that causes it still exists */
668 if (!client->driver) {
669 if (data->alarms & 0xff0000) {
670 dme1737_write(client, DME1737_REG_ALARM3,
671 0xff);
672 }
673 if (data->alarms & 0xff00) {
674 dme1737_write(client, DME1737_REG_ALARM2,
675 0xff);
676 }
677 if (data->alarms & 0xff) {
678 dme1737_write(client, DME1737_REG_ALARM1,
679 0xff);
680 }
681 }
682
633 data->last_update = jiffies; 683 data->last_update = jiffies;
634 data->valid = 1; 684 data->valid = 1;
635 } 685 }
@@ -674,7 +724,7 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
674 break; 724 break;
675 default: 725 default:
676 res = 0; 726 res = 0;
677 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 727 dev_dbg(dev, "Unknown function %d.\n", fn);
678 } 728 }
679 729
680 return sprintf(buf, "%d\n", res); 730 return sprintf(buf, "%d\n", res);
@@ -683,8 +733,8 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
683static ssize_t set_in(struct device *dev, struct device_attribute *attr, 733static ssize_t set_in(struct device *dev, struct device_attribute *attr,
684 const char *buf, size_t count) 734 const char *buf, size_t count)
685{ 735{
686 struct i2c_client *client = to_i2c_client(dev); 736 struct dme1737_data *data = dev_get_drvdata(dev);
687 struct dme1737_data *data = i2c_get_clientdata(client); 737 struct i2c_client *client = &data->client;
688 struct sensor_device_attribute_2 738 struct sensor_device_attribute_2
689 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 739 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
690 int ix = sensor_attr_2->index; 740 int ix = sensor_attr_2->index;
@@ -704,7 +754,7 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
704 data->in_max[ix]); 754 data->in_max[ix]);
705 break; 755 break;
706 default: 756 default:
707 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 757 dev_dbg(dev, "Unknown function %d.\n", fn);
708 } 758 }
709 mutex_unlock(&data->update_lock); 759 mutex_unlock(&data->update_lock);
710 760
@@ -754,7 +804,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
754 break; 804 break;
755 default: 805 default:
756 res = 0; 806 res = 0;
757 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 807 dev_dbg(dev, "Unknown function %d.\n", fn);
758 } 808 }
759 809
760 return sprintf(buf, "%d\n", res); 810 return sprintf(buf, "%d\n", res);
@@ -763,8 +813,8 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
763static ssize_t set_temp(struct device *dev, struct device_attribute *attr, 813static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
764 const char *buf, size_t count) 814 const char *buf, size_t count)
765{ 815{
766 struct i2c_client *client = to_i2c_client(dev); 816 struct dme1737_data *data = dev_get_drvdata(dev);
767 struct dme1737_data *data = i2c_get_clientdata(client); 817 struct i2c_client *client = &data->client;
768 struct sensor_device_attribute_2 818 struct sensor_device_attribute_2
769 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 819 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
770 int ix = sensor_attr_2->index; 820 int ix = sensor_attr_2->index;
@@ -789,7 +839,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
789 data->temp_offset[ix]); 839 data->temp_offset[ix]);
790 break; 840 break;
791 default: 841 default:
792 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 842 dev_dbg(dev, "Unknown function %d.\n", fn);
793 } 843 }
794 mutex_unlock(&data->update_lock); 844 mutex_unlock(&data->update_lock);
795 845
@@ -843,7 +893,7 @@ static ssize_t show_zone(struct device *dev, struct device_attribute *attr,
843 break; 893 break;
844 default: 894 default:
845 res = 0; 895 res = 0;
846 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 896 dev_dbg(dev, "Unknown function %d.\n", fn);
847 } 897 }
848 898
849 return sprintf(buf, "%d\n", res); 899 return sprintf(buf, "%d\n", res);
@@ -852,8 +902,8 @@ static ssize_t show_zone(struct device *dev, struct device_attribute *attr,
852static ssize_t set_zone(struct device *dev, struct device_attribute *attr, 902static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
853 const char *buf, size_t count) 903 const char *buf, size_t count)
854{ 904{
855 struct i2c_client *client = to_i2c_client(dev); 905 struct dme1737_data *data = dev_get_drvdata(dev);
856 struct dme1737_data *data = i2c_get_clientdata(client); 906 struct i2c_client *client = &data->client;
857 struct sensor_device_attribute_2 907 struct sensor_device_attribute_2
858 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 908 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
859 int ix = sensor_attr_2->index; 909 int ix = sensor_attr_2->index;
@@ -898,7 +948,7 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
898 data->zone_abs[ix]); 948 data->zone_abs[ix]);
899 break; 949 break;
900 default: 950 default:
901 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 951 dev_dbg(dev, "Unknown function %d.\n", fn);
902 } 952 }
903 mutex_unlock(&data->update_lock); 953 mutex_unlock(&data->update_lock);
904 954
@@ -950,7 +1000,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
950 break; 1000 break;
951 default: 1001 default:
952 res = 0; 1002 res = 0;
953 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 1003 dev_dbg(dev, "Unknown function %d.\n", fn);
954 } 1004 }
955 1005
956 return sprintf(buf, "%d\n", res); 1006 return sprintf(buf, "%d\n", res);
@@ -959,8 +1009,8 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
959static ssize_t set_fan(struct device *dev, struct device_attribute *attr, 1009static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
960 const char *buf, size_t count) 1010 const char *buf, size_t count)
961{ 1011{
962 struct i2c_client *client = to_i2c_client(dev); 1012 struct dme1737_data *data = dev_get_drvdata(dev);
963 struct dme1737_data *data = i2c_get_clientdata(client); 1013 struct i2c_client *client = &data->client;
964 struct sensor_device_attribute_2 1014 struct sensor_device_attribute_2
965 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1015 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
966 int ix = sensor_attr_2->index; 1016 int ix = sensor_attr_2->index;
@@ -995,7 +1045,7 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
995 /* Only valid for fan[1-4] */ 1045 /* Only valid for fan[1-4] */
996 if (!(val == 1 || val == 2 || val == 4)) { 1046 if (!(val == 1 || val == 2 || val == 4)) {
997 count = -EINVAL; 1047 count = -EINVAL;
998 dev_warn(&client->dev, "Fan type value %ld not " 1048 dev_warn(dev, "Fan type value %ld not "
999 "supported. Choose one of 1, 2, or 4.\n", 1049 "supported. Choose one of 1, 2, or 4.\n",
1000 val); 1050 val);
1001 goto exit; 1051 goto exit;
@@ -1006,7 +1056,7 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1006 data->fan_opt[ix]); 1056 data->fan_opt[ix]);
1007 break; 1057 break;
1008 default: 1058 default:
1009 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 1059 dev_dbg(dev, "Unknown function %d.\n", fn);
1010 } 1060 }
1011exit: 1061exit:
1012 mutex_unlock(&data->update_lock); 1062 mutex_unlock(&data->update_lock);
@@ -1086,20 +1136,20 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1086 break; 1136 break;
1087 default: 1137 default:
1088 res = 0; 1138 res = 0;
1089 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 1139 dev_dbg(dev, "Unknown function %d.\n", fn);
1090 } 1140 }
1091 1141
1092 return sprintf(buf, "%d\n", res); 1142 return sprintf(buf, "%d\n", res);
1093} 1143}
1094 1144
1095static struct attribute *dme1737_attr_pwm[]; 1145static struct attribute *dme1737_attr_pwm[];
1096static void dme1737_chmod_file(struct i2c_client*, struct attribute*, mode_t); 1146static void dme1737_chmod_file(struct device*, struct attribute*, mode_t);
1097 1147
1098static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, 1148static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1099 const char *buf, size_t count) 1149 const char *buf, size_t count)
1100{ 1150{
1101 struct i2c_client *client = to_i2c_client(dev); 1151 struct dme1737_data *data = dev_get_drvdata(dev);
1102 struct dme1737_data *data = i2c_get_clientdata(client); 1152 struct i2c_client *client = &data->client;
1103 struct sensor_device_attribute_2 1153 struct sensor_device_attribute_2
1104 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1154 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1105 int ix = sensor_attr_2->index; 1155 int ix = sensor_attr_2->index;
@@ -1122,7 +1172,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1122 /* Only valid for pwm[1-3] */ 1172 /* Only valid for pwm[1-3] */
1123 if (val < 0 || val > 2) { 1173 if (val < 0 || val > 2) {
1124 count = -EINVAL; 1174 count = -EINVAL;
1125 dev_warn(&client->dev, "PWM enable %ld not " 1175 dev_warn(dev, "PWM enable %ld not "
1126 "supported. Choose one of 0, 1, or 2.\n", 1176 "supported. Choose one of 0, 1, or 2.\n",
1127 val); 1177 val);
1128 goto exit; 1178 goto exit;
@@ -1156,7 +1206,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1156 switch (val) { 1206 switch (val) {
1157 case 0: 1207 case 0:
1158 /* Change permissions of pwm[ix] to read-only */ 1208 /* Change permissions of pwm[ix] to read-only */
1159 dme1737_chmod_file(client, dme1737_attr_pwm[ix], 1209 dme1737_chmod_file(dev, dme1737_attr_pwm[ix],
1160 S_IRUGO); 1210 S_IRUGO);
1161 /* Turn fan fully on */ 1211 /* Turn fan fully on */
1162 data->pwm_config[ix] = PWM_EN_TO_REG(0, 1212 data->pwm_config[ix] = PWM_EN_TO_REG(0,
@@ -1171,12 +1221,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1171 dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1221 dme1737_write(client, DME1737_REG_PWM_CONFIG(ix),
1172 data->pwm_config[ix]); 1222 data->pwm_config[ix]);
1173 /* Change permissions of pwm[ix] to read-writeable */ 1223 /* Change permissions of pwm[ix] to read-writeable */
1174 dme1737_chmod_file(client, dme1737_attr_pwm[ix], 1224 dme1737_chmod_file(dev, dme1737_attr_pwm[ix],
1175 S_IRUGO | S_IWUSR); 1225 S_IRUGO | S_IWUSR);
1176 break; 1226 break;
1177 case 2: 1227 case 2:
1178 /* Change permissions of pwm[ix] to read-only */ 1228 /* Change permissions of pwm[ix] to read-only */
1179 dme1737_chmod_file(client, dme1737_attr_pwm[ix], 1229 dme1737_chmod_file(dev, dme1737_attr_pwm[ix],
1180 S_IRUGO); 1230 S_IRUGO);
1181 /* Turn on auto mode using the saved zone channel 1231 /* Turn on auto mode using the saved zone channel
1182 * assignment */ 1232 * assignment */
@@ -1223,7 +1273,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1223 if (!(val == 1 || val == 2 || val == 4 || 1273 if (!(val == 1 || val == 2 || val == 4 ||
1224 val == 6 || val == 7)) { 1274 val == 6 || val == 7)) {
1225 count = -EINVAL; 1275 count = -EINVAL;
1226 dev_warn(&client->dev, "PWM auto channels zone %ld " 1276 dev_warn(dev, "PWM auto channels zone %ld "
1227 "not supported. Choose one of 1, 2, 4, 6, " 1277 "not supported. Choose one of 1, 2, 4, 6, "
1228 "or 7.\n", val); 1278 "or 7.\n", val);
1229 goto exit; 1279 goto exit;
@@ -1257,12 +1307,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1257 data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, 1307 data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix,
1258 dme1737_read(client, 1308 dme1737_read(client,
1259 DME1737_REG_PWM_RR(0))); 1309 DME1737_REG_PWM_RR(0)));
1260
1261 } else { 1310 } else {
1262 data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, 1311 data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix,
1263 dme1737_read(client, 1312 dme1737_read(client,
1264 DME1737_REG_PWM_RR(0))); 1313 DME1737_REG_PWM_RR(0)));
1265
1266 } 1314 }
1267 dme1737_write(client, DME1737_REG_PWM_RR(0), 1315 dme1737_write(client, DME1737_REG_PWM_RR(0),
1268 data->pwm_rr[0]); 1316 data->pwm_rr[0]);
@@ -1274,7 +1322,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1274 data->pwm_min[ix]); 1322 data->pwm_min[ix]);
1275 break; 1323 break;
1276 default: 1324 default:
1277 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); 1325 dev_dbg(dev, "Unknown function %d.\n", fn);
1278 } 1326 }
1279exit: 1327exit:
1280 mutex_unlock(&data->update_lock); 1328 mutex_unlock(&data->update_lock);
@@ -1298,8 +1346,7 @@ static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
1298static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, 1346static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
1299 const char *buf, size_t count) 1347 const char *buf, size_t count)
1300{ 1348{
1301 struct i2c_client *client = to_i2c_client(dev); 1349 struct dme1737_data *data = dev_get_drvdata(dev);
1302 struct dme1737_data *data = i2c_get_clientdata(client);
1303 long val = simple_strtol(buf, NULL, 10); 1350 long val = simple_strtol(buf, NULL, 10);
1304 1351
1305 data->vrm = val; 1352 data->vrm = val;
@@ -1314,6 +1361,14 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
1314 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); 1361 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
1315} 1362}
1316 1363
1364static ssize_t show_name(struct device *dev, struct device_attribute *attr,
1365 char *buf)
1366{
1367 struct dme1737_data *data = dev_get_drvdata(dev);
1368
1369 return sprintf(buf, "%s\n", data->client.name);
1370}
1371
1317/* --------------------------------------------------------------------- 1372/* ---------------------------------------------------------------------
1318 * Sysfs device attribute defines and structs 1373 * Sysfs device attribute defines and structs
1319 * --------------------------------------------------------------------- */ 1374 * --------------------------------------------------------------------- */
@@ -1322,13 +1377,13 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
1322 1377
1323#define SENSOR_DEVICE_ATTR_IN(ix) \ 1378#define SENSOR_DEVICE_ATTR_IN(ix) \
1324static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \ 1379static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \
1325 show_in, NULL, SYS_IN_INPUT, ix); \ 1380 show_in, NULL, SYS_IN_INPUT, ix); \
1326static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \ 1381static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \
1327 show_in, set_in, SYS_IN_MIN, ix); \ 1382 show_in, set_in, SYS_IN_MIN, ix); \
1328static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \ 1383static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \
1329 show_in, set_in, SYS_IN_MAX, ix); \ 1384 show_in, set_in, SYS_IN_MAX, ix); \
1330static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \ 1385static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \
1331 show_in, NULL, SYS_IN_ALARM, ix) 1386 show_in, NULL, SYS_IN_ALARM, ix)
1332 1387
1333SENSOR_DEVICE_ATTR_IN(0); 1388SENSOR_DEVICE_ATTR_IN(0);
1334SENSOR_DEVICE_ATTR_IN(1); 1389SENSOR_DEVICE_ATTR_IN(1);
@@ -1342,17 +1397,17 @@ SENSOR_DEVICE_ATTR_IN(6);
1342 1397
1343#define SENSOR_DEVICE_ATTR_TEMP(ix) \ 1398#define SENSOR_DEVICE_ATTR_TEMP(ix) \
1344static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \ 1399static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \
1345 show_temp, NULL, SYS_TEMP_INPUT, ix-1); \ 1400 show_temp, NULL, SYS_TEMP_INPUT, ix-1); \
1346static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \ 1401static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \
1347 show_temp, set_temp, SYS_TEMP_MIN, ix-1); \ 1402 show_temp, set_temp, SYS_TEMP_MIN, ix-1); \
1348static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \ 1403static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \
1349 show_temp, set_temp, SYS_TEMP_MAX, ix-1); \ 1404 show_temp, set_temp, SYS_TEMP_MAX, ix-1); \
1350static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \ 1405static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \
1351 show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \ 1406 show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \
1352static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \ 1407static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \
1353 show_temp, NULL, SYS_TEMP_ALARM, ix-1); \ 1408 show_temp, NULL, SYS_TEMP_ALARM, ix-1); \
1354static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \ 1409static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \
1355 show_temp, NULL, SYS_TEMP_FAULT, ix-1) 1410 show_temp, NULL, SYS_TEMP_FAULT, ix-1)
1356 1411
1357SENSOR_DEVICE_ATTR_TEMP(1); 1412SENSOR_DEVICE_ATTR_TEMP(1);
1358SENSOR_DEVICE_ATTR_TEMP(2); 1413SENSOR_DEVICE_ATTR_TEMP(2);
@@ -1362,15 +1417,15 @@ SENSOR_DEVICE_ATTR_TEMP(3);
1362 1417
1363#define SENSOR_DEVICE_ATTR_ZONE(ix) \ 1418#define SENSOR_DEVICE_ATTR_ZONE(ix) \
1364static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \ 1419static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \
1365 show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \ 1420 show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \
1366static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \ 1421static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \
1367 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \ 1422 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \
1368static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \ 1423static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \
1369 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \ 1424 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \
1370static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \ 1425static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \
1371 show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \ 1426 show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \
1372static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \ 1427static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \
1373 show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1) 1428 show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1)
1374 1429
1375SENSOR_DEVICE_ATTR_ZONE(1); 1430SENSOR_DEVICE_ATTR_ZONE(1);
1376SENSOR_DEVICE_ATTR_ZONE(2); 1431SENSOR_DEVICE_ATTR_ZONE(2);
@@ -1380,13 +1435,13 @@ SENSOR_DEVICE_ATTR_ZONE(3);
1380 1435
1381#define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \ 1436#define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \
1382static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ 1437static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \
1383 show_fan, NULL, SYS_FAN_INPUT, ix-1); \ 1438 show_fan, NULL, SYS_FAN_INPUT, ix-1); \
1384static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ 1439static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
1385 show_fan, set_fan, SYS_FAN_MIN, ix-1); \ 1440 show_fan, set_fan, SYS_FAN_MIN, ix-1); \
1386static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ 1441static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \
1387 show_fan, NULL, SYS_FAN_ALARM, ix-1); \ 1442 show_fan, NULL, SYS_FAN_ALARM, ix-1); \
1388static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \ 1443static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \
1389 show_fan, set_fan, SYS_FAN_TYPE, ix-1) 1444 show_fan, set_fan, SYS_FAN_TYPE, ix-1)
1390 1445
1391SENSOR_DEVICE_ATTR_FAN_1TO4(1); 1446SENSOR_DEVICE_ATTR_FAN_1TO4(1);
1392SENSOR_DEVICE_ATTR_FAN_1TO4(2); 1447SENSOR_DEVICE_ATTR_FAN_1TO4(2);
@@ -1397,13 +1452,13 @@ SENSOR_DEVICE_ATTR_FAN_1TO4(4);
1397 1452
1398#define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \ 1453#define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \
1399static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ 1454static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \
1400 show_fan, NULL, SYS_FAN_INPUT, ix-1); \ 1455 show_fan, NULL, SYS_FAN_INPUT, ix-1); \
1401static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ 1456static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
1402 show_fan, set_fan, SYS_FAN_MIN, ix-1); \ 1457 show_fan, set_fan, SYS_FAN_MIN, ix-1); \
1403static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ 1458static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \
1404 show_fan, NULL, SYS_FAN_ALARM, ix-1); \ 1459 show_fan, NULL, SYS_FAN_ALARM, ix-1); \
1405static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \ 1460static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \
1406 show_fan, set_fan, SYS_FAN_MAX, ix-1) 1461 show_fan, set_fan, SYS_FAN_MAX, ix-1)
1407 1462
1408SENSOR_DEVICE_ATTR_FAN_5TO6(5); 1463SENSOR_DEVICE_ATTR_FAN_5TO6(5);
1409SENSOR_DEVICE_ATTR_FAN_5TO6(6); 1464SENSOR_DEVICE_ATTR_FAN_5TO6(6);
@@ -1412,21 +1467,21 @@ SENSOR_DEVICE_ATTR_FAN_5TO6(6);
1412 1467
1413#define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \ 1468#define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \
1414static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \ 1469static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \
1415 show_pwm, set_pwm, SYS_PWM, ix-1); \ 1470 show_pwm, set_pwm, SYS_PWM, ix-1); \
1416static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \ 1471static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \
1417 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ 1472 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1418static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ 1473static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
1419 show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \ 1474 show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \
1420static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \ 1475static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \
1421 show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \ 1476 show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \
1422static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \ 1477static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \
1423 show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \ 1478 show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \
1424static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \ 1479static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \
1425 show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \ 1480 show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \
1426static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \ 1481static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \
1427 show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \ 1482 show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \
1428static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \ 1483static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \
1429 show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1) 1484 show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1)
1430 1485
1431SENSOR_DEVICE_ATTR_PWM_1TO3(1); 1486SENSOR_DEVICE_ATTR_PWM_1TO3(1);
1432SENSOR_DEVICE_ATTR_PWM_1TO3(2); 1487SENSOR_DEVICE_ATTR_PWM_1TO3(2);
@@ -1436,11 +1491,11 @@ SENSOR_DEVICE_ATTR_PWM_1TO3(3);
1436 1491
1437#define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \ 1492#define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \
1438static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \ 1493static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \
1439 show_pwm, set_pwm, SYS_PWM, ix-1); \ 1494 show_pwm, set_pwm, SYS_PWM, ix-1); \
1440static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \ 1495static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \
1441 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ 1496 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1442static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ 1497static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
1443 show_pwm, NULL, SYS_PWM_ENABLE, ix-1) 1498 show_pwm, NULL, SYS_PWM_ENABLE, ix-1)
1444 1499
1445SENSOR_DEVICE_ATTR_PWM_5TO6(5); 1500SENSOR_DEVICE_ATTR_PWM_5TO6(5);
1446SENSOR_DEVICE_ATTR_PWM_5TO6(6); 1501SENSOR_DEVICE_ATTR_PWM_5TO6(6);
@@ -1449,6 +1504,7 @@ SENSOR_DEVICE_ATTR_PWM_5TO6(6);
1449 1504
1450static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 1505static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
1451static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 1506static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
1507static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); /* for ISA devices */
1452 1508
1453#define SENSOR_DEV_ATTR_IN(ix) \ 1509#define SENSOR_DEV_ATTR_IN(ix) \
1454&sensor_dev_attr_in##ix##_input.dev_attr.attr, \ 1510&sensor_dev_attr_in##ix##_input.dev_attr.attr, \
@@ -1519,53 +1575,53 @@ SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix), \
1519 * permissions are created read-only and write permissions are added or removed 1575 * permissions are created read-only and write permissions are added or removed
1520 * on the fly when required */ 1576 * on the fly when required */
1521static struct attribute *dme1737_attr[] ={ 1577static struct attribute *dme1737_attr[] ={
1522 /* Voltages */ 1578 /* Voltages */
1523 SENSOR_DEV_ATTR_IN(0), 1579 SENSOR_DEV_ATTR_IN(0),
1524 SENSOR_DEV_ATTR_IN(1), 1580 SENSOR_DEV_ATTR_IN(1),
1525 SENSOR_DEV_ATTR_IN(2), 1581 SENSOR_DEV_ATTR_IN(2),
1526 SENSOR_DEV_ATTR_IN(3), 1582 SENSOR_DEV_ATTR_IN(3),
1527 SENSOR_DEV_ATTR_IN(4), 1583 SENSOR_DEV_ATTR_IN(4),
1528 SENSOR_DEV_ATTR_IN(5), 1584 SENSOR_DEV_ATTR_IN(5),
1529 SENSOR_DEV_ATTR_IN(6), 1585 SENSOR_DEV_ATTR_IN(6),
1530 /* Temperatures */ 1586 /* Temperatures */
1531 SENSOR_DEV_ATTR_TEMP(1), 1587 SENSOR_DEV_ATTR_TEMP(1),
1532 SENSOR_DEV_ATTR_TEMP(2), 1588 SENSOR_DEV_ATTR_TEMP(2),
1533 SENSOR_DEV_ATTR_TEMP(3), 1589 SENSOR_DEV_ATTR_TEMP(3),
1534 /* Zones */ 1590 /* Zones */
1535 SENSOR_DEV_ATTR_ZONE(1), 1591 SENSOR_DEV_ATTR_ZONE(1),
1536 SENSOR_DEV_ATTR_ZONE(2), 1592 SENSOR_DEV_ATTR_ZONE(2),
1537 SENSOR_DEV_ATTR_ZONE(3), 1593 SENSOR_DEV_ATTR_ZONE(3),
1538 /* Misc */ 1594 /* Misc */
1539 &dev_attr_vrm.attr, 1595 &dev_attr_vrm.attr,
1540 &dev_attr_cpu0_vid.attr, 1596 &dev_attr_cpu0_vid.attr,
1541 NULL 1597 NULL
1542}; 1598};
1543 1599
1544static const struct attribute_group dme1737_group = { 1600static const struct attribute_group dme1737_group = {
1545 .attrs = dme1737_attr, 1601 .attrs = dme1737_attr,
1546}; 1602};
1547 1603
1548/* The following structs hold the PWM attributes, some of which are optional. 1604/* The following structs hold the PWM attributes, some of which are optional.
1549 * Their creation depends on the chip configuration which is determined during 1605 * Their creation depends on the chip configuration which is determined during
1550 * module load. */ 1606 * module load. */
1551static struct attribute *dme1737_attr_pwm1[] = { 1607static struct attribute *dme1737_attr_pwm1[] = {
1552 SENSOR_DEV_ATTR_PWM_1TO3(1), 1608 SENSOR_DEV_ATTR_PWM_1TO3(1),
1553 NULL 1609 NULL
1554}; 1610};
1555static struct attribute *dme1737_attr_pwm2[] = { 1611static struct attribute *dme1737_attr_pwm2[] = {
1556 SENSOR_DEV_ATTR_PWM_1TO3(2), 1612 SENSOR_DEV_ATTR_PWM_1TO3(2),
1557 NULL 1613 NULL
1558}; 1614};
1559static struct attribute *dme1737_attr_pwm3[] = { 1615static struct attribute *dme1737_attr_pwm3[] = {
1560 SENSOR_DEV_ATTR_PWM_1TO3(3), 1616 SENSOR_DEV_ATTR_PWM_1TO3(3),
1561 NULL 1617 NULL
1562}; 1618};
1563static struct attribute *dme1737_attr_pwm5[] = { 1619static struct attribute *dme1737_attr_pwm5[] = {
1564 SENSOR_DEV_ATTR_PWM_5TO6(5), 1620 SENSOR_DEV_ATTR_PWM_5TO6(5),
1565 NULL 1621 NULL
1566}; 1622};
1567static struct attribute *dme1737_attr_pwm6[] = { 1623static struct attribute *dme1737_attr_pwm6[] = {
1568 SENSOR_DEV_ATTR_PWM_5TO6(6), 1624 SENSOR_DEV_ATTR_PWM_5TO6(6),
1569 NULL 1625 NULL
1570}; 1626};
1571 1627
@@ -1582,27 +1638,27 @@ static const struct attribute_group dme1737_pwm_group[] = {
1582 * Their creation depends on the chip configuration which is determined during 1638 * Their creation depends on the chip configuration which is determined during
1583 * module load. */ 1639 * module load. */
1584static struct attribute *dme1737_attr_fan1[] = { 1640static struct attribute *dme1737_attr_fan1[] = {
1585 SENSOR_DEV_ATTR_FAN_1TO4(1), 1641 SENSOR_DEV_ATTR_FAN_1TO4(1),
1586 NULL 1642 NULL
1587}; 1643};
1588static struct attribute *dme1737_attr_fan2[] = { 1644static struct attribute *dme1737_attr_fan2[] = {
1589 SENSOR_DEV_ATTR_FAN_1TO4(2), 1645 SENSOR_DEV_ATTR_FAN_1TO4(2),
1590 NULL 1646 NULL
1591}; 1647};
1592static struct attribute *dme1737_attr_fan3[] = { 1648static struct attribute *dme1737_attr_fan3[] = {
1593 SENSOR_DEV_ATTR_FAN_1TO4(3), 1649 SENSOR_DEV_ATTR_FAN_1TO4(3),
1594 NULL 1650 NULL
1595}; 1651};
1596static struct attribute *dme1737_attr_fan4[] = { 1652static struct attribute *dme1737_attr_fan4[] = {
1597 SENSOR_DEV_ATTR_FAN_1TO4(4), 1653 SENSOR_DEV_ATTR_FAN_1TO4(4),
1598 NULL 1654 NULL
1599}; 1655};
1600static struct attribute *dme1737_attr_fan5[] = { 1656static struct attribute *dme1737_attr_fan5[] = {
1601 SENSOR_DEV_ATTR_FAN_5TO6(5), 1657 SENSOR_DEV_ATTR_FAN_5TO6(5),
1602 NULL 1658 NULL
1603}; 1659};
1604static struct attribute *dme1737_attr_fan6[] = { 1660static struct attribute *dme1737_attr_fan6[] = {
1605 SENSOR_DEV_ATTR_FAN_5TO6(6), 1661 SENSOR_DEV_ATTR_FAN_5TO6(6),
1606 NULL 1662 NULL
1607}; 1663};
1608 1664
@@ -1637,23 +1693,23 @@ static const struct attribute_group dme1737_lock_group = {
1637 * writeable if the chip is *not* locked and the respective PWM is available. 1693 * writeable if the chip is *not* locked and the respective PWM is available.
1638 * Otherwise they stay read-only. */ 1694 * Otherwise they stay read-only. */
1639static struct attribute *dme1737_attr_pwm1_lock[] = { 1695static struct attribute *dme1737_attr_pwm1_lock[] = {
1640 SENSOR_DEV_ATTR_PWM_1TO3_LOCK(1), 1696 SENSOR_DEV_ATTR_PWM_1TO3_LOCK(1),
1641 NULL 1697 NULL
1642}; 1698};
1643static struct attribute *dme1737_attr_pwm2_lock[] = { 1699static struct attribute *dme1737_attr_pwm2_lock[] = {
1644 SENSOR_DEV_ATTR_PWM_1TO3_LOCK(2), 1700 SENSOR_DEV_ATTR_PWM_1TO3_LOCK(2),
1645 NULL 1701 NULL
1646}; 1702};
1647static struct attribute *dme1737_attr_pwm3_lock[] = { 1703static struct attribute *dme1737_attr_pwm3_lock[] = {
1648 SENSOR_DEV_ATTR_PWM_1TO3_LOCK(3), 1704 SENSOR_DEV_ATTR_PWM_1TO3_LOCK(3),
1649 NULL 1705 NULL
1650}; 1706};
1651static struct attribute *dme1737_attr_pwm5_lock[] = { 1707static struct attribute *dme1737_attr_pwm5_lock[] = {
1652 SENSOR_DEV_ATTR_PWM_5TO6_LOCK(5), 1708 SENSOR_DEV_ATTR_PWM_5TO6_LOCK(5),
1653 NULL 1709 NULL
1654}; 1710};
1655static struct attribute *dme1737_attr_pwm6_lock[] = { 1711static struct attribute *dme1737_attr_pwm6_lock[] = {
1656 SENSOR_DEV_ATTR_PWM_5TO6_LOCK(6), 1712 SENSOR_DEV_ATTR_PWM_5TO6_LOCK(6),
1657 NULL 1713 NULL
1658}; 1714};
1659 1715
@@ -1678,6 +1734,16 @@ static struct attribute *dme1737_attr_pwm[] = {
1678 * Super-IO functions 1734 * Super-IO functions
1679 * --------------------------------------------------------------------- */ 1735 * --------------------------------------------------------------------- */
1680 1736
1737static inline void dme1737_sio_enter(int sio_cip)
1738{
1739 outb(0x55, sio_cip);
1740}
1741
1742static inline void dme1737_sio_exit(int sio_cip)
1743{
1744 outb(0xaa, sio_cip);
1745}
1746
1681static inline int dme1737_sio_inb(int sio_cip, int reg) 1747static inline int dme1737_sio_inb(int sio_cip, int reg)
1682{ 1748{
1683 outb(reg, sio_cip); 1749 outb(reg, sio_cip);
@@ -1690,136 +1756,196 @@ static inline void dme1737_sio_outb(int sio_cip, int reg, int val)
1690 outb(val, sio_cip + 1); 1756 outb(val, sio_cip + 1);
1691} 1757}
1692 1758
1693static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client) 1759/* ---------------------------------------------------------------------
1760 * Device initialization
1761 * --------------------------------------------------------------------- */
1762
1763static int dme1737_i2c_get_features(int, struct dme1737_data*);
1764
1765static void dme1737_chmod_file(struct device *dev,
1766 struct attribute *attr, mode_t mode)
1694{ 1767{
1695 struct dme1737_data *data = i2c_get_clientdata(client); 1768 if (sysfs_chmod_file(&dev->kobj, attr, mode)) {
1696 int err = 0, reg; 1769 dev_warn(dev, "Failed to change permissions of %s.\n",
1697 u16 addr; 1770 attr->name);
1771 }
1772}
1698 1773
1699 /* Enter configuration mode */ 1774static void dme1737_chmod_group(struct device *dev,
1700 outb(0x55, sio_cip); 1775 const struct attribute_group *group,
1776 mode_t mode)
1777{
1778 struct attribute **attr;
1701 1779
1702 /* Check device ID 1780 for (attr = group->attrs; *attr; attr++) {
1703 * The DME1737 can return either 0x78 or 0x77 as its device ID. */ 1781 dme1737_chmod_file(dev, *attr, mode);
1704 reg = dme1737_sio_inb(sio_cip, 0x20);
1705 if (!(reg == 0x77 || reg == 0x78)) {
1706 err = -ENODEV;
1707 goto exit;
1708 } 1782 }
1783}
1709 1784
1710 /* Select logical device A (runtime registers) */ 1785static void dme1737_remove_files(struct device *dev)
1711 dme1737_sio_outb(sio_cip, 0x07, 0x0a); 1786{
1787 struct dme1737_data *data = dev_get_drvdata(dev);
1788 int ix;
1712 1789
1713 /* Get the base address of the runtime registers */ 1790 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
1714 if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | 1791 if (data->has_fan & (1 << ix)) {
1715 dme1737_sio_inb(sio_cip, 0x61))) { 1792 sysfs_remove_group(&dev->kobj,
1716 err = -ENODEV; 1793 &dme1737_fan_group[ix]);
1717 goto exit; 1794 }
1718 } 1795 }
1719 1796
1720 /* Read the runtime registers to determine which optional features 1797 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
1721 * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set 1798 if (data->has_pwm & (1 << ix)) {
1722 * to '10' if the respective feature is enabled. */ 1799 sysfs_remove_group(&dev->kobj,
1723 if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ 1800 &dme1737_pwm_group[ix]);
1724 data->has_fan |= (1 << 5); 1801 }
1725 } 1802 }
1726 if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */ 1803
1727 data->has_pwm |= (1 << 5); 1804 sysfs_remove_group(&dev->kobj, &dme1737_group);
1805
1806 if (!data->client.driver) {
1807 sysfs_remove_file(&dev->kobj, &dev_attr_name.attr);
1728 } 1808 }
1729 if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */ 1809}
1730 data->has_fan |= (1 << 4); 1810
1811static int dme1737_create_files(struct device *dev)
1812{
1813 struct dme1737_data *data = dev_get_drvdata(dev);
1814 int err, ix;
1815
1816 /* Create a name attribute for ISA devices */
1817 if (!data->client.driver &&
1818 (err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr))) {
1819 goto exit;
1731 } 1820 }
1732 if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */ 1821
1733 data->has_pwm |= (1 << 4); 1822 /* Create standard sysfs attributes */
1823 if ((err = sysfs_create_group(&dev->kobj, &dme1737_group))) {
1824 goto exit_remove;
1734 } 1825 }
1735 1826
1736exit: 1827 /* Create fan sysfs attributes */
1737 /* Exit configuration mode */ 1828 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
1738 outb(0xaa, sio_cip); 1829 if (data->has_fan & (1 << ix)) {
1830 if ((err = sysfs_create_group(&dev->kobj,
1831 &dme1737_fan_group[ix]))) {
1832 goto exit_remove;
1833 }
1834 }
1835 }
1739 1836
1740 return err; 1837 /* Create PWM sysfs attributes */
1741} 1838 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
1839 if (data->has_pwm & (1 << ix)) {
1840 if ((err = sysfs_create_group(&dev->kobj,
1841 &dme1737_pwm_group[ix]))) {
1842 goto exit_remove;
1843 }
1844 }
1845 }
1742 1846
1743/* --------------------------------------------------------------------- 1847 /* Inform if the device is locked. Otherwise change the permissions of
1744 * Device detection, registration and initialization 1848 * selected attributes from read-only to read-writeable. */
1745 * --------------------------------------------------------------------- */ 1849 if (data->config & 0x02) {
1850 dev_info(dev, "Device is locked. Some attributes "
1851 "will be read-only.\n");
1852 } else {
1853 /* Change permissions of standard attributes */
1854 dme1737_chmod_group(dev, &dme1737_lock_group,
1855 S_IRUGO | S_IWUSR);
1746 1856
1747static struct i2c_driver dme1737_driver; 1857 /* Change permissions of PWM attributes */
1858 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_lock_group); ix++) {
1859 if (data->has_pwm & (1 << ix)) {
1860 dme1737_chmod_group(dev,
1861 &dme1737_pwm_lock_group[ix],
1862 S_IRUGO | S_IWUSR);
1863 }
1864 }
1748 1865
1749static void dme1737_chmod_file(struct i2c_client *client, 1866 /* Change permissions of pwm[1-3] if in manual mode */
1750 struct attribute *attr, mode_t mode) 1867 for (ix = 0; ix < 3; ix++) {
1751{ 1868 if ((data->has_pwm & (1 << ix)) &&
1752 if (sysfs_chmod_file(&client->dev.kobj, attr, mode)) { 1869 (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) {
1753 dev_warn(&client->dev, "Failed to change permissions of %s.\n", 1870 dme1737_chmod_file(dev,
1754 attr->name); 1871 dme1737_attr_pwm[ix],
1872 S_IRUGO | S_IWUSR);
1873 }
1874 }
1755 } 1875 }
1756}
1757 1876
1758static void dme1737_chmod_group(struct i2c_client *client, 1877 return 0;
1759 const struct attribute_group *group,
1760 mode_t mode)
1761{
1762 struct attribute **attr;
1763 1878
1764 for (attr = group->attrs; *attr; attr++) { 1879exit_remove:
1765 dme1737_chmod_file(client, *attr, mode); 1880 dme1737_remove_files(dev);
1766 } 1881exit:
1882 return err;
1767} 1883}
1768 1884
1769static int dme1737_init_client(struct i2c_client *client) 1885static int dme1737_init_device(struct device *dev)
1770{ 1886{
1771 struct dme1737_data *data = i2c_get_clientdata(client); 1887 struct dme1737_data *data = dev_get_drvdata(dev);
1888 struct i2c_client *client = &data->client;
1772 int ix; 1889 int ix;
1773 u8 reg; 1890 u8 reg;
1774 1891
1775 data->config = dme1737_read(client, DME1737_REG_CONFIG); 1892 data->config = dme1737_read(client, DME1737_REG_CONFIG);
1776 /* Inform if part is not monitoring/started */ 1893 /* Inform if part is not monitoring/started */
1777 if (!(data->config & 0x01)) { 1894 if (!(data->config & 0x01)) {
1778 if (!force_start) { 1895 if (!force_start) {
1779 dev_err(&client->dev, "Device is not monitoring. " 1896 dev_err(dev, "Device is not monitoring. "
1780 "Use the force_start load parameter to " 1897 "Use the force_start load parameter to "
1781 "override.\n"); 1898 "override.\n");
1782 return -EFAULT; 1899 return -EFAULT;
1783 } 1900 }
1784 1901
1785 /* Force monitoring */ 1902 /* Force monitoring */
1786 data->config |= 0x01; 1903 data->config |= 0x01;
1787 dme1737_write(client, DME1737_REG_CONFIG, data->config); 1904 dme1737_write(client, DME1737_REG_CONFIG, data->config);
1788 } 1905 }
1789 /* Inform if part is not ready */ 1906 /* Inform if part is not ready */
1790 if (!(data->config & 0x04)) { 1907 if (!(data->config & 0x04)) {
1791 dev_err(&client->dev, "Device is not ready.\n"); 1908 dev_err(dev, "Device is not ready.\n");
1792 return -EFAULT; 1909 return -EFAULT;
1793 } 1910 }
1794 1911
1795 data->config2 = dme1737_read(client, DME1737_REG_CONFIG2); 1912 /* Determine which optional fan and pwm features are enabled/present */
1796 /* Check if optional fan3 input is enabled */ 1913 if (client->driver) { /* I2C chip */
1797 if (data->config2 & 0x04) { 1914 data->config2 = dme1737_read(client, DME1737_REG_CONFIG2);
1798 data->has_fan |= (1 << 2); 1915 /* Check if optional fan3 input is enabled */
1799 } 1916 if (data->config2 & 0x04) {
1917 data->has_fan |= (1 << 2);
1918 }
1800 1919
1801 /* Fan4 and pwm3 are only available if the client's I2C address 1920 /* Fan4 and pwm3 are only available if the client's I2C address
1802 * is the default 0x2e. Otherwise the I/Os associated with these 1921 * is the default 0x2e. Otherwise the I/Os associated with
1803 * functions are used for addr enable/select. */ 1922 * these functions are used for addr enable/select. */
1804 if (client->addr == 0x2e) { 1923 if (data->client.addr == 0x2e) {
1805 data->has_fan |= (1 << 3); 1924 data->has_fan |= (1 << 3);
1806 data->has_pwm |= (1 << 2); 1925 data->has_pwm |= (1 << 2);
1807 } 1926 }
1808 1927
1809 /* Determine if the optional fan[5-6] and/or pwm[5-6] are enabled. 1928 /* Determine which of the optional fan[5-6] and pwm[5-6]
1810 * For this, we need to query the runtime registers through the 1929 * features are enabled. For this, we need to query the runtime
1811 * Super-IO LPC interface. Try both config ports 0x2e and 0x4e. */ 1930 * registers through the Super-IO LPC interface. Try both
1812 if (dme1737_sio_get_features(0x2e, client) && 1931 * config ports 0x2e and 0x4e. */
1813 dme1737_sio_get_features(0x4e, client)) { 1932 if (dme1737_i2c_get_features(0x2e, data) &&
1814 dev_warn(&client->dev, "Failed to query Super-IO for optional " 1933 dme1737_i2c_get_features(0x4e, data)) {
1815 "features.\n"); 1934 dev_warn(dev, "Failed to query Super-IO for optional "
1935 "features.\n");
1936 }
1937 } else { /* ISA chip */
1938 /* Fan3 and pwm3 are always available. Fan[4-5] and pwm[5-6]
1939 * don't exist in the ISA chip. */
1940 data->has_fan |= (1 << 2);
1941 data->has_pwm |= (1 << 2);
1816 } 1942 }
1817 1943
1818 /* Fan1, fan2, pwm1, and pwm2 are always present */ 1944 /* Fan1, fan2, pwm1, and pwm2 are always present */
1819 data->has_fan |= 0x03; 1945 data->has_fan |= 0x03;
1820 data->has_pwm |= 0x03; 1946 data->has_pwm |= 0x03;
1821 1947
1822 dev_info(&client->dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " 1948 dev_info(dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, "
1823 "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", 1949 "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n",
1824 (data->has_pwm & (1 << 2)) ? "yes" : "no", 1950 (data->has_pwm & (1 << 2)) ? "yes" : "no",
1825 (data->has_pwm & (1 << 4)) ? "yes" : "no", 1951 (data->has_pwm & (1 << 4)) ? "yes" : "no",
@@ -1831,13 +1957,19 @@ static int dme1737_init_client(struct i2c_client *client)
1831 1957
1832 reg = dme1737_read(client, DME1737_REG_TACH_PWM); 1958 reg = dme1737_read(client, DME1737_REG_TACH_PWM);
1833 /* Inform if fan-to-pwm mapping differs from the default */ 1959 /* Inform if fan-to-pwm mapping differs from the default */
1834 if (reg != 0xa4) { 1960 if (client->driver && reg != 0xa4) { /* I2C chip */
1835 dev_warn(&client->dev, "Non-standard fan to pwm mapping: " 1961 dev_warn(dev, "Non-standard fan to pwm mapping: "
1836 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " 1962 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, "
1837 "fan4->pwm%d. Please report to the driver " 1963 "fan4->pwm%d. Please report to the driver "
1838 "maintainer.\n", 1964 "maintainer.\n",
1839 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1, 1965 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1,
1840 ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1); 1966 ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1);
1967 } else if (!client->driver && reg != 0x24) { /* ISA chip */
1968 dev_warn(dev, "Non-standard fan to pwm mapping: "
1969 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. "
1970 "Please report to the driver maintainer.\n",
1971 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1,
1972 ((reg >> 4) & 0x03) + 1);
1841 } 1973 }
1842 1974
1843 /* Switch pwm[1-3] to manual mode if they are currently disabled and 1975 /* Switch pwm[1-3] to manual mode if they are currently disabled and
@@ -1849,7 +1981,7 @@ static int dme1737_init_client(struct i2c_client *client)
1849 DME1737_REG_PWM_CONFIG(ix)); 1981 DME1737_REG_PWM_CONFIG(ix));
1850 if ((data->has_pwm & (1 << ix)) && 1982 if ((data->has_pwm & (1 << ix)) &&
1851 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { 1983 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) {
1852 dev_info(&client->dev, "Switching pwm%d to " 1984 dev_info(dev, "Switching pwm%d to "
1853 "manual mode.\n", ix + 1); 1985 "manual mode.\n", ix + 1);
1854 data->pwm_config[ix] = PWM_EN_TO_REG(1, 1986 data->pwm_config[ix] = PWM_EN_TO_REG(1,
1855 data->pwm_config[ix]); 1987 data->pwm_config[ix]);
@@ -1872,13 +2004,67 @@ static int dme1737_init_client(struct i2c_client *client)
1872 return 0; 2004 return 0;
1873} 2005}
1874 2006
1875static int dme1737_detect(struct i2c_adapter *adapter, int address, 2007/* ---------------------------------------------------------------------
1876 int kind) 2008 * I2C device detection and registration
2009 * --------------------------------------------------------------------- */
2010
2011static struct i2c_driver dme1737_i2c_driver;
2012
2013static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
2014{
2015 int err = 0, reg;
2016 u16 addr;
2017
2018 dme1737_sio_enter(sio_cip);
2019
2020 /* Check device ID
2021 * The DME1737 can return either 0x78 or 0x77 as its device ID. */
2022 reg = dme1737_sio_inb(sio_cip, 0x20);
2023 if (!(reg == 0x77 || reg == 0x78)) {
2024 err = -ENODEV;
2025 goto exit;
2026 }
2027
2028 /* Select logical device A (runtime registers) */
2029 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
2030
2031 /* Get the base address of the runtime registers */
2032 if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
2033 dme1737_sio_inb(sio_cip, 0x61))) {
2034 err = -ENODEV;
2035 goto exit;
2036 }
2037
2038 /* Read the runtime registers to determine which optional features
2039 * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set
2040 * to '10' if the respective feature is enabled. */
2041 if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */
2042 data->has_fan |= (1 << 5);
2043 }
2044 if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */
2045 data->has_pwm |= (1 << 5);
2046 }
2047 if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */
2048 data->has_fan |= (1 << 4);
2049 }
2050 if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */
2051 data->has_pwm |= (1 << 4);
2052 }
2053
2054exit:
2055 dme1737_sio_exit(sio_cip);
2056
2057 return err;
2058}
2059
2060static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
2061 int kind)
1877{ 2062{
1878 u8 company, verstep = 0; 2063 u8 company, verstep = 0;
1879 struct i2c_client *client; 2064 struct i2c_client *client;
1880 struct dme1737_data *data; 2065 struct dme1737_data *data;
1881 int ix, err = 0; 2066 struct device *dev;
2067 int err = 0;
1882 const char *name; 2068 const char *name;
1883 2069
1884 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 2070 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
@@ -1894,7 +2080,8 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address,
1894 i2c_set_clientdata(client, data); 2080 i2c_set_clientdata(client, data);
1895 client->addr = address; 2081 client->addr = address;
1896 client->adapter = adapter; 2082 client->adapter = adapter;
1897 client->driver = &dme1737_driver; 2083 client->driver = &dme1737_i2c_driver;
2084 dev = &client->dev;
1898 2085
1899 /* A negative kind means that the driver was loaded with no force 2086 /* A negative kind means that the driver was loaded with no force
1900 * parameter (default), so we must identify the chip. */ 2087 * parameter (default), so we must identify the chip. */
@@ -1922,92 +2109,33 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address,
1922 goto exit_kfree; 2109 goto exit_kfree;
1923 } 2110 }
1924 2111
2112 dev_info(dev, "Found a DME1737 chip at 0x%02x (rev 0x%02x).\n",
2113 client->addr, verstep);
2114
1925 /* Initialize the DME1737 chip */ 2115 /* Initialize the DME1737 chip */
1926 if ((err = dme1737_init_client(client))) { 2116 if ((err = dme1737_init_device(dev))) {
2117 dev_err(dev, "Failed to initialize device.\n");
1927 goto exit_detach; 2118 goto exit_detach;
1928 } 2119 }
1929 2120
1930 /* Create standard sysfs attributes */ 2121 /* Create sysfs files */
1931 if ((err = sysfs_create_group(&client->dev.kobj, &dme1737_group))) { 2122 if ((err = dme1737_create_files(dev))) {
1932 goto exit_detach; 2123 dev_err(dev, "Failed to create sysfs files.\n");
1933 } 2124 goto exit_detach;
1934
1935 /* Create fan sysfs attributes */
1936 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
1937 if (data->has_fan & (1 << ix)) {
1938 if ((err = sysfs_create_group(&client->dev.kobj,
1939 &dme1737_fan_group[ix]))) {
1940 goto exit_remove;
1941 }
1942 }
1943 }
1944
1945 /* Create PWM sysfs attributes */
1946 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
1947 if (data->has_pwm & (1 << ix)) {
1948 if ((err = sysfs_create_group(&client->dev.kobj,
1949 &dme1737_pwm_group[ix]))) {
1950 goto exit_remove;
1951 }
1952 }
1953 }
1954
1955 /* Inform if the device is locked. Otherwise change the permissions of
1956 * selected attributes from read-only to read-writeable. */
1957 if (data->config & 0x02) {
1958 dev_info(&client->dev, "Device is locked. Some attributes "
1959 "will be read-only.\n");
1960 } else {
1961 /* Change permissions of standard attributes */
1962 dme1737_chmod_group(client, &dme1737_lock_group,
1963 S_IRUGO | S_IWUSR);
1964
1965 /* Change permissions of PWM attributes */
1966 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_lock_group); ix++) {
1967 if (data->has_pwm & (1 << ix)) {
1968 dme1737_chmod_group(client,
1969 &dme1737_pwm_lock_group[ix],
1970 S_IRUGO | S_IWUSR);
1971 }
1972 }
1973
1974 /* Change permissions of pwm[1-3] if in manual mode */
1975 for (ix = 0; ix < 3; ix++) {
1976 if ((data->has_pwm & (1 << ix)) &&
1977 (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) {
1978 dme1737_chmod_file(client,
1979 dme1737_attr_pwm[ix],
1980 S_IRUGO | S_IWUSR);
1981 }
1982 }
1983 } 2125 }
1984 2126
1985 /* Register device */ 2127 /* Register device */
1986 data->class_dev = hwmon_device_register(&client->dev); 2128 data->hwmon_dev = hwmon_device_register(dev);
1987 if (IS_ERR(data->class_dev)) { 2129 if (IS_ERR(data->hwmon_dev)) {
1988 err = PTR_ERR(data->class_dev); 2130 dev_err(dev, "Failed to register device.\n");
2131 err = PTR_ERR(data->hwmon_dev);
1989 goto exit_remove; 2132 goto exit_remove;
1990 } 2133 }
1991 2134
1992 dev_info(&adapter->dev, "Found a DME1737 chip at 0x%02x "
1993 "(rev 0x%02x)\n", client->addr, verstep);
1994
1995 return 0; 2135 return 0;
1996 2136
1997exit_remove: 2137exit_remove:
1998 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { 2138 dme1737_remove_files(dev);
1999 if (data->has_fan & (1 << ix)) {
2000 sysfs_remove_group(&client->dev.kobj,
2001 &dme1737_fan_group[ix]);
2002 }
2003 }
2004 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
2005 if (data->has_pwm & (1 << ix)) {
2006 sysfs_remove_group(&client->dev.kobj,
2007 &dme1737_pwm_group[ix]);
2008 }
2009 }
2010 sysfs_remove_group(&client->dev.kobj, &dme1737_group);
2011exit_detach: 2139exit_detach:
2012 i2c_detach_client(client); 2140 i2c_detach_client(client);
2013exit_kfree: 2141exit_kfree:
@@ -2016,60 +2144,260 @@ exit:
2016 return err; 2144 return err;
2017} 2145}
2018 2146
2019static int dme1737_attach_adapter(struct i2c_adapter *adapter) 2147static int dme1737_i2c_attach_adapter(struct i2c_adapter *adapter)
2020{ 2148{
2021 if (!(adapter->class & I2C_CLASS_HWMON)) { 2149 if (!(adapter->class & I2C_CLASS_HWMON)) {
2022 return 0; 2150 return 0;
2023 } 2151 }
2024 2152
2025 return i2c_probe(adapter, &addr_data, dme1737_detect); 2153 return i2c_probe(adapter, &addr_data, dme1737_i2c_detect);
2026} 2154}
2027 2155
2028static int dme1737_detach_client(struct i2c_client *client) 2156static int dme1737_i2c_detach_client(struct i2c_client *client)
2029{ 2157{
2030 struct dme1737_data *data = i2c_get_clientdata(client); 2158 struct dme1737_data *data = i2c_get_clientdata(client);
2031 int ix, err; 2159 int err;
2032 2160
2033 hwmon_device_unregister(data->class_dev); 2161 hwmon_device_unregister(data->hwmon_dev);
2162 dme1737_remove_files(&client->dev);
2034 2163
2035 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { 2164 if ((err = i2c_detach_client(client))) {
2036 if (data->has_fan & (1 << ix)) { 2165 return err;
2037 sysfs_remove_group(&client->dev.kobj,
2038 &dme1737_fan_group[ix]);
2039 }
2040 } 2166 }
2041 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { 2167
2042 if (data->has_pwm & (1 << ix)) { 2168 kfree(data);
2043 sysfs_remove_group(&client->dev.kobj, 2169 return 0;
2044 &dme1737_pwm_group[ix]); 2170}
2045 } 2171
2172static struct i2c_driver dme1737_i2c_driver = {
2173 .driver = {
2174 .name = "dme1737",
2175 },
2176 .attach_adapter = dme1737_i2c_attach_adapter,
2177 .detach_client = dme1737_i2c_detach_client,
2178};
2179
2180/* ---------------------------------------------------------------------
2181 * ISA device detection and registration
2182 * --------------------------------------------------------------------- */
2183
2184static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr)
2185{
2186 int err = 0, reg;
2187 unsigned short base_addr;
2188
2189 dme1737_sio_enter(sio_cip);
2190
2191 /* Check device ID
2192 * We currently know about SCH3112 (0x7c), SCH3114 (0x7d), and
2193 * SCH3116 (0x7f). */
2194 reg = dme1737_sio_inb(sio_cip, 0x20);
2195 if (!(reg == 0x7c || reg == 0x7d || reg == 0x7f)) {
2196 err = -ENODEV;
2197 goto exit;
2046 } 2198 }
2047 sysfs_remove_group(&client->dev.kobj, &dme1737_group);
2048 2199
2049 if ((err = i2c_detach_client(client))) { 2200 /* Select logical device A (runtime registers) */
2050 return err; 2201 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
2202
2203 /* Get the base address of the runtime registers */
2204 if (!(base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
2205 dme1737_sio_inb(sio_cip, 0x61))) {
2206 printk(KERN_ERR "dme1737: Base address not set.\n");
2207 err = -ENODEV;
2208 goto exit;
2209 }
2210
2211 /* Access to the hwmon registers is through an index/data register
2212 * pair located at offset 0x70/0x71. */
2213 *addr = base_addr + 0x70;
2214
2215exit:
2216 dme1737_sio_exit(sio_cip);
2217 return err;
2218}
2219
2220static int __init dme1737_isa_device_add(unsigned short addr)
2221{
2222 struct resource res = {
2223 .start = addr,
2224 .end = addr + DME1737_EXTENT - 1,
2225 .name = "dme1737",
2226 .flags = IORESOURCE_IO,
2227 };
2228 int err;
2229
2230 if (!(pdev = platform_device_alloc("dme1737", addr))) {
2231 printk(KERN_ERR "dme1737: Failed to allocate device.\n");
2232 err = -ENOMEM;
2233 goto exit;
2234 }
2235
2236 if ((err = platform_device_add_resources(pdev, &res, 1))) {
2237 printk(KERN_ERR "dme1737: Failed to add device resource "
2238 "(err = %d).\n", err);
2239 goto exit_device_put;
2240 }
2241
2242 if ((err = platform_device_add(pdev))) {
2243 printk(KERN_ERR "dme1737: Failed to add device (err = %d).\n",
2244 err);
2245 goto exit_device_put;
2246 }
2247
2248 return 0;
2249
2250exit_device_put:
2251 platform_device_put(pdev);
2252 pdev = NULL;
2253exit:
2254 return err;
2255}
2256
2257static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2258{
2259 u8 company, device;
2260 struct resource *res;
2261 struct i2c_client *client;
2262 struct dme1737_data *data;
2263 struct device *dev = &pdev->dev;
2264 int err;
2265
2266 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
2267 if (!request_region(res->start, DME1737_EXTENT, "dme1737")) {
2268 dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n",
2269 (unsigned short)res->start,
2270 (unsigned short)res->start + DME1737_EXTENT - 1);
2271 err = -EBUSY;
2272 goto exit;
2273 }
2274
2275 if (!(data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL))) {
2276 err = -ENOMEM;
2277 goto exit_release_region;
2278 }
2279
2280 client = &data->client;
2281 i2c_set_clientdata(client, data);
2282 client->addr = res->start;
2283 platform_set_drvdata(pdev, data);
2284
2285 company = dme1737_read(client, DME1737_REG_COMPANY);
2286 device = dme1737_read(client, DME1737_REG_DEVICE);
2287
2288 if (!((company == DME1737_COMPANY_SMSC) &&
2289 (device == SCH311X_DEVICE))) {
2290 err = -ENODEV;
2291 goto exit_kfree;
2292 }
2293
2294 /* Fill in the remaining client fields and initialize the mutex */
2295 strlcpy(client->name, "sch311x", I2C_NAME_SIZE);
2296 mutex_init(&data->update_lock);
2297
2298 dev_info(dev, "Found a SCH311x chip at 0x%04x\n", client->addr);
2299
2300 /* Initialize the chip */
2301 if ((err = dme1737_init_device(dev))) {
2302 dev_err(dev, "Failed to initialize device.\n");
2303 goto exit_kfree;
2051 } 2304 }
2052 2305
2306 /* Create sysfs files */
2307 if ((err = dme1737_create_files(dev))) {
2308 dev_err(dev, "Failed to create sysfs files.\n");
2309 goto exit_kfree;
2310 }
2311
2312 /* Register device */
2313 data->hwmon_dev = hwmon_device_register(dev);
2314 if (IS_ERR(data->hwmon_dev)) {
2315 dev_err(dev, "Failed to register device.\n");
2316 err = PTR_ERR(data->hwmon_dev);
2317 goto exit_remove_files;
2318 }
2319
2320 return 0;
2321
2322exit_remove_files:
2323 dme1737_remove_files(dev);
2324exit_kfree:
2325 platform_set_drvdata(pdev, NULL);
2326 kfree(data);
2327exit_release_region:
2328 release_region(res->start, DME1737_EXTENT);
2329exit:
2330 return err;
2331}
2332
2333static int __devexit dme1737_isa_remove(struct platform_device *pdev)
2334{
2335 struct dme1737_data *data = platform_get_drvdata(pdev);
2336
2337 hwmon_device_unregister(data->hwmon_dev);
2338 dme1737_remove_files(&pdev->dev);
2339 release_region(data->client.addr, DME1737_EXTENT);
2340 platform_set_drvdata(pdev, NULL);
2053 kfree(data); 2341 kfree(data);
2342
2054 return 0; 2343 return 0;
2055} 2344}
2056 2345
2057static struct i2c_driver dme1737_driver = { 2346static struct platform_driver dme1737_isa_driver = {
2058 .driver = { 2347 .driver = {
2348 .owner = THIS_MODULE,
2059 .name = "dme1737", 2349 .name = "dme1737",
2060 }, 2350 },
2061 .attach_adapter = dme1737_attach_adapter, 2351 .probe = dme1737_isa_probe,
2062 .detach_client = dme1737_detach_client, 2352 .remove = __devexit_p(dme1737_isa_remove),
2063}; 2353};
2064 2354
2355/* ---------------------------------------------------------------------
2356 * Module initialization and cleanup
2357 * --------------------------------------------------------------------- */
2358
2065static int __init dme1737_init(void) 2359static int __init dme1737_init(void)
2066{ 2360{
2067 return i2c_add_driver(&dme1737_driver); 2361 int err;
2362 unsigned short addr;
2363
2364 if ((err = i2c_add_driver(&dme1737_i2c_driver))) {
2365 goto exit;
2366 }
2367
2368 if (dme1737_isa_detect(0x2e, &addr) &&
2369 dme1737_isa_detect(0x4e, &addr)) {
2370 /* Return 0 if we didn't find an ISA device */
2371 return 0;
2372 }
2373
2374 if ((err = platform_driver_register(&dme1737_isa_driver))) {
2375 goto exit_del_i2c_driver;
2376 }
2377
2378 /* Sets global pdev as a side effect */
2379 if ((err = dme1737_isa_device_add(addr))) {
2380 goto exit_del_isa_driver;
2381 }
2382
2383 return 0;
2384
2385exit_del_isa_driver:
2386 platform_driver_unregister(&dme1737_isa_driver);
2387exit_del_i2c_driver:
2388 i2c_del_driver(&dme1737_i2c_driver);
2389exit:
2390 return err;
2068} 2391}
2069 2392
2070static void __exit dme1737_exit(void) 2393static void __exit dme1737_exit(void)
2071{ 2394{
2072 i2c_del_driver(&dme1737_driver); 2395 if (pdev) {
2396 platform_device_unregister(pdev);
2397 platform_driver_unregister(&dme1737_isa_driver);
2398 }
2399
2400 i2c_del_driver(&dme1737_i2c_driver);
2073} 2401}
2074 2402
2075MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>"); 2403MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>");