aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Grandegger <wg@grandegger.com>2008-10-17 11:51:19 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-10-17 11:51:19 -0400
commit0217eae3a825d551b99991bc30555c3daeb0a4df (patch)
treebe8ca795bacbb9aba2d8af19ac2211a93e5ff30e
parent360782dde00a2e6e7d9fd57535f90934707ab8a8 (diff)
hwmon: (w83781d) Use new style driver binding
This patch modifies the w83781d driver to use new style driver binding. Substantial code modifications are required to deal with the new interface, especially legacy device detection. [JD: largely edited to make the patch smaller and to get the driver to work again on ISA devices.] Signed-off-by: Wolfgang Grandegger <wg@grandegger.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
-rw-r--r--drivers/hwmon/w83781d.c309
1 files changed, 134 insertions, 175 deletions
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 50580c883053..d4d1b859d4f1 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -199,7 +199,7 @@ DIV_TO_REG(long val, enum chips type)
199} 199}
200 200
201struct w83781d_data { 201struct w83781d_data {
202 struct i2c_client client; 202 struct i2c_client *client;
203 struct device *hwmon_dev; 203 struct device *hwmon_dev;
204 struct mutex lock; 204 struct mutex lock;
205 enum chips type; 205 enum chips type;
@@ -241,23 +241,11 @@ struct w83781d_data {
241static struct w83781d_data *w83781d_data_if_isa(void); 241static struct w83781d_data *w83781d_data_if_isa(void);
242static int w83781d_alias_detect(struct i2c_client *client, u8 chipid); 242static int w83781d_alias_detect(struct i2c_client *client, u8 chipid);
243 243
244static int w83781d_attach_adapter(struct i2c_adapter *adapter);
245static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind);
246static int w83781d_detach_client(struct i2c_client *client);
247
248static int w83781d_read_value(struct w83781d_data *data, u16 reg); 244static int w83781d_read_value(struct w83781d_data *data, u16 reg);
249static int w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value); 245static int w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value);
250static struct w83781d_data *w83781d_update_device(struct device *dev); 246static struct w83781d_data *w83781d_update_device(struct device *dev);
251static void w83781d_init_device(struct device *dev); 247static void w83781d_init_device(struct device *dev);
252 248
253static struct i2c_driver w83781d_driver = {
254 .driver = {
255 .name = "w83781d",
256 },
257 .attach_adapter = w83781d_attach_adapter,
258 .detach_client = w83781d_detach_client,
259};
260
261/* following are the sysfs callback functions */ 249/* following are the sysfs callback functions */
262#define show_in_reg(reg) \ 250#define show_in_reg(reg) \
263static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \ 251static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
@@ -819,46 +807,19 @@ static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
819static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, 807static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
820 show_sensor, store_sensor, 2); 808 show_sensor, store_sensor, 2);
821 809
822/* This function is called when:
823 * w83781d_driver is inserted (when this module is loaded), for each
824 available adapter
825 * when a new adapter is inserted (and w83781d_driver is still present)
826 We block updates of the ISA device to minimize the risk of concurrent
827 access to the same W83781D chip through different interfaces. */
828static int
829w83781d_attach_adapter(struct i2c_adapter *adapter)
830{
831 struct w83781d_data *data = w83781d_data_if_isa();
832 int err;
833
834 if (!(adapter->class & I2C_CLASS_HWMON))
835 return 0;
836
837 if (data)
838 mutex_lock(&data->update_lock);
839 err = i2c_probe(adapter, &addr_data, w83781d_detect);
840 if (data)
841 mutex_unlock(&data->update_lock);
842 return err;
843}
844
845/* Assumes that adapter is of I2C, not ISA variety. 810/* Assumes that adapter is of I2C, not ISA variety.
846 * OTHERWISE DON'T CALL THIS 811 * OTHERWISE DON'T CALL THIS
847 */ 812 */
848static int 813static int
849w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, 814w83781d_detect_subclients(struct i2c_client *new_client)
850 struct i2c_client *new_client)
851{ 815{
852 int i, val1 = 0, id; 816 int i, val1 = 0, id;
853 int err; 817 int err;
854 const char *client_name = ""; 818 int address = new_client->addr;
819 unsigned short sc_addr[2];
820 struct i2c_adapter *adapter = new_client->adapter;
855 struct w83781d_data *data = i2c_get_clientdata(new_client); 821 struct w83781d_data *data = i2c_get_clientdata(new_client);
856 822 enum chips kind = data->type;
857 data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
858 if (!(data->lm75[0])) {
859 err = -ENOMEM;
860 goto ERROR_SC_0;
861 }
862 823
863 id = i2c_adapter_id(adapter); 824 id = i2c_adapter_id(adapter);
864 825
@@ -876,55 +837,35 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
876 w83781d_write_value(data, W83781D_REG_I2C_SUBADDR, 837 w83781d_write_value(data, W83781D_REG_I2C_SUBADDR,
877 (force_subclients[2] & 0x07) | 838 (force_subclients[2] & 0x07) |
878 ((force_subclients[3] & 0x07) << 4)); 839 ((force_subclients[3] & 0x07) << 4));
879 data->lm75[0]->addr = force_subclients[2]; 840 sc_addr[0] = force_subclients[2];
880 } else { 841 } else {
881 val1 = w83781d_read_value(data, W83781D_REG_I2C_SUBADDR); 842 val1 = w83781d_read_value(data, W83781D_REG_I2C_SUBADDR);
882 data->lm75[0]->addr = 0x48 + (val1 & 0x07); 843 sc_addr[0] = 0x48 + (val1 & 0x07);
883 } 844 }
884 845
885 if (kind != w83783s) { 846 if (kind != w83783s) {
886 data->lm75[1] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
887 if (!(data->lm75[1])) {
888 err = -ENOMEM;
889 goto ERROR_SC_1;
890 }
891
892 if (force_subclients[0] == id && 847 if (force_subclients[0] == id &&
893 force_subclients[1] == address) { 848 force_subclients[1] == address) {
894 data->lm75[1]->addr = force_subclients[3]; 849 sc_addr[1] = force_subclients[3];
895 } else { 850 } else {
896 data->lm75[1]->addr = 0x48 + ((val1 >> 4) & 0x07); 851 sc_addr[1] = 0x48 + ((val1 >> 4) & 0x07);
897 } 852 }
898 if (data->lm75[0]->addr == data->lm75[1]->addr) { 853 if (sc_addr[0] == sc_addr[1]) {
899 dev_err(&new_client->dev, 854 dev_err(&new_client->dev,
900 "Duplicate addresses 0x%x for subclients.\n", 855 "Duplicate addresses 0x%x for subclients.\n",
901 data->lm75[0]->addr); 856 sc_addr[0]);
902 err = -EBUSY; 857 err = -EBUSY;
903 goto ERROR_SC_2; 858 goto ERROR_SC_2;
904 } 859 }
905 } 860 }
906 861
907 if (kind == w83781d)
908 client_name = "w83781d subclient";
909 else if (kind == w83782d)
910 client_name = "w83782d subclient";
911 else if (kind == w83783s)
912 client_name = "w83783s subclient";
913 else if (kind == as99127f)
914 client_name = "as99127f subclient";
915
916 for (i = 0; i <= 1; i++) { 862 for (i = 0; i <= 1; i++) {
917 /* store all data in w83781d */ 863 data->lm75[i] = i2c_new_dummy(adapter, sc_addr[i]);
918 i2c_set_clientdata(data->lm75[i], NULL); 864 if (!data->lm75[i]) {
919 data->lm75[i]->adapter = adapter;
920 data->lm75[i]->driver = &w83781d_driver;
921 data->lm75[i]->flags = 0;
922 strlcpy(data->lm75[i]->name, client_name,
923 I2C_NAME_SIZE);
924 if ((err = i2c_attach_client(data->lm75[i]))) {
925 dev_err(&new_client->dev, "Subclient %d " 865 dev_err(&new_client->dev, "Subclient %d "
926 "registration at address 0x%x " 866 "registration at address 0x%x "
927 "failed.\n", i, data->lm75[i]->addr); 867 "failed.\n", i, sc_addr[i]);
868 err = -ENOMEM;
928 if (i == 1) 869 if (i == 1)
929 goto ERROR_SC_3; 870 goto ERROR_SC_3;
930 goto ERROR_SC_2; 871 goto ERROR_SC_2;
@@ -937,12 +878,9 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
937 878
938/* Undo inits in case of errors */ 879/* Undo inits in case of errors */
939ERROR_SC_3: 880ERROR_SC_3:
940 i2c_detach_client(data->lm75[0]); 881 i2c_unregister_device(data->lm75[0]);
941ERROR_SC_2: 882ERROR_SC_2:
942 kfree(data->lm75[1]);
943ERROR_SC_1: 883ERROR_SC_1:
944 kfree(data->lm75[0]);
945ERROR_SC_0:
946 return err; 884 return err;
947} 885}
948 886
@@ -1108,87 +1046,71 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
1108 return 0; 1046 return 0;
1109} 1047}
1110 1048
1049/* Return 0 if detection is successful, -ENODEV otherwise */
1111static int 1050static int
1112w83781d_detect(struct i2c_adapter *adapter, int address, int kind) 1051w83781d_detect(struct i2c_client *client, int kind,
1052 struct i2c_board_info *info)
1113{ 1053{
1114 int val1 = 0, val2; 1054 int val1 = 0, val2;
1115 struct i2c_client *client; 1055 struct w83781d_data *isa = w83781d_data_if_isa();
1116 struct device *dev; 1056 struct i2c_adapter *adapter = client->adapter;
1117 struct w83781d_data *data; 1057 int address = client->addr;
1118 int err;
1119 const char *client_name = ""; 1058 const char *client_name = "";
1120 enum vendor { winbond, asus } vendid; 1059 enum vendor { winbond, asus } vendid;
1121 1060
1122 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1061 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1123 err = -EINVAL; 1062 return -ENODEV;
1124 goto ERROR1;
1125 }
1126
1127 /* OK. For now, we presume we have a valid client. We now create the
1128 client structure, even though we cannot fill it completely yet.
1129 But it allows us to access w83781d_{read,write}_value. */
1130
1131 if (!(data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
1132 err = -ENOMEM;
1133 goto ERROR1;
1134 }
1135
1136 client = &data->client;
1137 i2c_set_clientdata(client, data);
1138 client->addr = address;
1139 mutex_init(&data->lock);
1140 client->adapter = adapter;
1141 client->driver = &w83781d_driver;
1142 dev = &client->dev;
1143 1063
1144 /* Now, we do the remaining detection. */ 1064 /* We block updates of the ISA device to minimize the risk of
1065 concurrent access to the same W83781D chip through different
1066 interfaces. */
1067 if (isa)
1068 mutex_lock(&isa->update_lock);
1145 1069
1146 /* The w8378?d may be stuck in some other bank than bank 0. This may 1070 /* The w8378?d may be stuck in some other bank than bank 0. This may
1147 make reading other information impossible. Specify a force=... or 1071 make reading other information impossible. Specify a force=... or
1148 force_*=... parameter, and the Winbond will be reset to the right 1072 force_*=... parameter, and the Winbond will be reset to the right
1149 bank. */ 1073 bank. */
1150 if (kind < 0) { 1074 if (kind < 0) {
1151 if (w83781d_read_value(data, W83781D_REG_CONFIG) & 0x80) { 1075 if (i2c_smbus_read_byte_data
1076 (client, W83781D_REG_CONFIG) & 0x80) {
1152 dev_dbg(&adapter->dev, "Detection of w83781d chip " 1077 dev_dbg(&adapter->dev, "Detection of w83781d chip "
1153 "failed at step 3\n"); 1078 "failed at step 3\n");
1154 err = -ENODEV; 1079 goto err_nodev;
1155 goto ERROR2;
1156 } 1080 }
1157 val1 = w83781d_read_value(data, W83781D_REG_BANK); 1081 val1 = i2c_smbus_read_byte_data(client, W83781D_REG_BANK);
1158 val2 = w83781d_read_value(data, W83781D_REG_CHIPMAN); 1082 val2 = i2c_smbus_read_byte_data(client, W83781D_REG_CHIPMAN);
1159 /* Check for Winbond or Asus ID if in bank 0 */ 1083 /* Check for Winbond or Asus ID if in bank 0 */
1160 if ((!(val1 & 0x07)) && 1084 if ((!(val1 & 0x07)) &&
1161 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3)) 1085 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3))
1162 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) { 1086 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) {
1163 dev_dbg(&adapter->dev, "Detection of w83781d chip " 1087 dev_dbg(&adapter->dev, "Detection of w83781d chip "
1164 "failed at step 4\n"); 1088 "failed at step 4\n");
1165 err = -ENODEV; 1089 goto err_nodev;
1166 goto ERROR2;
1167 } 1090 }
1168 /* If Winbond SMBus, check address at 0x48. 1091 /* If Winbond SMBus, check address at 0x48.
1169 Asus doesn't support, except for as99127f rev.2 */ 1092 Asus doesn't support, except for as99127f rev.2 */
1170 if ((!(val1 & 0x80) && (val2 == 0xa3)) || 1093 if ((!(val1 & 0x80) && (val2 == 0xa3)) ||
1171 ((val1 & 0x80) && (val2 == 0x5c))) { 1094 ((val1 & 0x80) && (val2 == 0x5c))) {
1172 if (w83781d_read_value 1095 if (i2c_smbus_read_byte_data
1173 (data, W83781D_REG_I2C_ADDR) != address) { 1096 (client, W83781D_REG_I2C_ADDR) != address) {
1174 dev_dbg(&adapter->dev, "Detection of w83781d " 1097 dev_dbg(&adapter->dev, "Detection of w83781d "
1175 "chip failed at step 5\n"); 1098 "chip failed at step 5\n");
1176 err = -ENODEV; 1099 goto err_nodev;
1177 goto ERROR2;
1178 } 1100 }
1179 } 1101 }
1180 } 1102 }
1181 1103
1182 /* We have either had a force parameter, or we have already detected the 1104 /* We have either had a force parameter, or we have already detected the
1183 Winbond. Put it now into bank 0 and Vendor ID High Byte */ 1105 Winbond. Put it now into bank 0 and Vendor ID High Byte */
1184 w83781d_write_value(data, W83781D_REG_BANK, 1106 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1185 (w83781d_read_value(data, W83781D_REG_BANK) 1107 (i2c_smbus_read_byte_data(client, W83781D_REG_BANK)
1186 & 0x78) | 0x80); 1108 & 0x78) | 0x80);
1187 1109
1188 /* Determine the chip type. */ 1110 /* Determine the chip type. */
1189 if (kind <= 0) { 1111 if (kind <= 0) {
1190 /* get vendor ID */ 1112 /* get vendor ID */
1191 val2 = w83781d_read_value(data, W83781D_REG_CHIPMAN); 1113 val2 = i2c_smbus_read_byte_data(client, W83781D_REG_CHIPMAN);
1192 if (val2 == 0x5c) 1114 if (val2 == 0x5c)
1193 vendid = winbond; 1115 vendid = winbond;
1194 else if (val2 == 0x12) 1116 else if (val2 == 0x12)
@@ -1196,11 +1118,10 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1196 else { 1118 else {
1197 dev_dbg(&adapter->dev, "w83781d chip vendor is " 1119 dev_dbg(&adapter->dev, "w83781d chip vendor is "
1198 "neither Winbond nor Asus\n"); 1120 "neither Winbond nor Asus\n");
1199 err = -ENODEV; 1121 goto err_nodev;
1200 goto ERROR2;
1201 } 1122 }
1202 1123
1203 val1 = w83781d_read_value(data, W83781D_REG_WCHIPID); 1124 val1 = i2c_smbus_read_byte_data(client, W83781D_REG_WCHIPID);
1204 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond) 1125 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)
1205 kind = w83781d; 1126 kind = w83781d;
1206 else if (val1 == 0x30 && vendid == winbond) 1127 else if (val1 == 0x30 && vendid == winbond)
@@ -1214,19 +1135,20 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1214 dev_warn(&adapter->dev, "Ignoring 'force' " 1135 dev_warn(&adapter->dev, "Ignoring 'force' "
1215 "parameter for unknown chip at " 1136 "parameter for unknown chip at "
1216 "address 0x%02x\n", address); 1137 "address 0x%02x\n", address);
1217 err = -EINVAL; 1138 goto err_nodev;
1218 goto ERROR2;
1219 } 1139 }
1220 1140
1221 if ((kind == w83781d || kind == w83782d) 1141 if ((kind == w83781d || kind == w83782d)
1222 && w83781d_alias_detect(client, val1)) { 1142 && w83781d_alias_detect(client, val1)) {
1223 dev_dbg(&adapter->dev, "Device at 0x%02x appears to " 1143 dev_dbg(&adapter->dev, "Device at 0x%02x appears to "
1224 "be the same as ISA device\n", address); 1144 "be the same as ISA device\n", address);
1225 err = -ENODEV; 1145 goto err_nodev;
1226 goto ERROR2;
1227 } 1146 }
1228 } 1147 }
1229 1148
1149 if (isa)
1150 mutex_unlock(&isa->update_lock);
1151
1230 if (kind == w83781d) { 1152 if (kind == w83781d) {
1231 client_name = "w83781d"; 1153 client_name = "w83781d";
1232 } else if (kind == w83782d) { 1154 } else if (kind == w83782d) {
@@ -1237,24 +1159,46 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1237 client_name = "as99127f"; 1159 client_name = "as99127f";
1238 } 1160 }
1239 1161
1240 /* Fill in the remaining client fields and put into the global list */ 1162 strlcpy(info->type, client_name, I2C_NAME_SIZE);
1241 strlcpy(client->name, client_name, I2C_NAME_SIZE);
1242 data->type = kind;
1243 1163
1244 /* Tell the I2C layer a new client has arrived */ 1164 return 0;
1245 if ((err = i2c_attach_client(client))) 1165
1246 goto ERROR2; 1166 err_nodev:
1167 if (isa)
1168 mutex_unlock(&isa->update_lock);
1169 return -ENODEV;
1170}
1171
1172static int
1173w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id)
1174{
1175 struct device *dev = &client->dev;
1176 struct w83781d_data *data;
1177 int err;
1178
1179 data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL);
1180 if (!data) {
1181 err = -ENOMEM;
1182 goto ERROR1;
1183 }
1184
1185 i2c_set_clientdata(client, data);
1186 mutex_init(&data->lock);
1187 mutex_init(&data->update_lock);
1188
1189 data->type = id->driver_data;
1190 data->client = client;
1247 1191
1248 /* attach secondary i2c lm75-like clients */ 1192 /* attach secondary i2c lm75-like clients */
1249 if ((err = w83781d_detect_subclients(adapter, address, 1193 err = w83781d_detect_subclients(client);
1250 kind, client))) 1194 if (err)
1251 goto ERROR3; 1195 goto ERROR3;
1252 1196
1253 /* Initialize the chip */ 1197 /* Initialize the chip */
1254 w83781d_init_device(dev); 1198 w83781d_init_device(dev);
1255 1199
1256 /* Register sysfs hooks */ 1200 /* Register sysfs hooks */
1257 err = w83781d_create_files(dev, kind, 0); 1201 err = w83781d_create_files(dev, data->type, 0);
1258 if (err) 1202 if (err)
1259 goto ERROR4; 1203 goto ERROR4;
1260 1204
@@ -1270,45 +1214,35 @@ ERROR4:
1270 sysfs_remove_group(&dev->kobj, &w83781d_group); 1214 sysfs_remove_group(&dev->kobj, &w83781d_group);
1271 sysfs_remove_group(&dev->kobj, &w83781d_group_opt); 1215 sysfs_remove_group(&dev->kobj, &w83781d_group_opt);
1272 1216
1273 if (data->lm75[1]) { 1217 if (data->lm75[0])
1274 i2c_detach_client(data->lm75[1]); 1218 i2c_unregister_device(data->lm75[0]);
1275 kfree(data->lm75[1]); 1219 if (data->lm75[1])
1276 } 1220 i2c_unregister_device(data->lm75[1]);
1277 if (data->lm75[0]) {
1278 i2c_detach_client(data->lm75[0]);
1279 kfree(data->lm75[0]);
1280 }
1281ERROR3: 1221ERROR3:
1282 i2c_detach_client(client); 1222 i2c_set_clientdata(client, NULL);
1283ERROR2:
1284 kfree(data); 1223 kfree(data);
1285ERROR1: 1224ERROR1:
1286 return err; 1225 return err;
1287} 1226}
1288 1227
1289static int 1228static int
1290w83781d_detach_client(struct i2c_client *client) 1229w83781d_remove(struct i2c_client *client)
1291{ 1230{
1292 struct w83781d_data *data = i2c_get_clientdata(client); 1231 struct w83781d_data *data = i2c_get_clientdata(client);
1293 int err; 1232 struct device *dev = &client->dev;
1294 1233
1295 /* main client */ 1234 hwmon_device_unregister(data->hwmon_dev);
1296 if (data) {
1297 hwmon_device_unregister(data->hwmon_dev);
1298 sysfs_remove_group(&client->dev.kobj, &w83781d_group);
1299 sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt);
1300 }
1301 1235
1302 if ((err = i2c_detach_client(client))) 1236 sysfs_remove_group(&dev->kobj, &w83781d_group);
1303 return err; 1237 sysfs_remove_group(&dev->kobj, &w83781d_group_opt);
1304 1238
1305 /* main client */ 1239 if (data->lm75[0])
1306 if (data) 1240 i2c_unregister_device(data->lm75[0]);
1307 kfree(data); 1241 if (data->lm75[1])
1242 i2c_unregister_device(data->lm75[1]);
1308 1243
1309 /* subclient */ 1244 i2c_set_clientdata(client, NULL);
1310 else 1245 kfree(data);
1311 kfree(client);
1312 1246
1313 return 0; 1247 return 0;
1314} 1248}
@@ -1316,7 +1250,7 @@ w83781d_detach_client(struct i2c_client *client)
1316static int 1250static int
1317w83781d_read_value_i2c(struct w83781d_data *data, u16 reg) 1251w83781d_read_value_i2c(struct w83781d_data *data, u16 reg)
1318{ 1252{
1319 struct i2c_client *client = &data->client; 1253 struct i2c_client *client = data->client;
1320 int res, bank; 1254 int res, bank;
1321 struct i2c_client *cl; 1255 struct i2c_client *cl;
1322 1256
@@ -1356,7 +1290,7 @@ w83781d_read_value_i2c(struct w83781d_data *data, u16 reg)
1356static int 1290static int
1357w83781d_write_value_i2c(struct w83781d_data *data, u16 reg, u16 value) 1291w83781d_write_value_i2c(struct w83781d_data *data, u16 reg, u16 value)
1358{ 1292{
1359 struct i2c_client *client = &data->client; 1293 struct i2c_client *client = data->client;
1360 int bank; 1294 int bank;
1361 struct i2c_client *cl; 1295 struct i2c_client *cl;
1362 1296
@@ -1493,7 +1427,7 @@ w83781d_init_device(struct device *dev)
1493static struct w83781d_data *w83781d_update_device(struct device *dev) 1427static struct w83781d_data *w83781d_update_device(struct device *dev)
1494{ 1428{
1495 struct w83781d_data *data = dev_get_drvdata(dev); 1429 struct w83781d_data *data = dev_get_drvdata(dev);
1496 struct i2c_client *client = &data->client; 1430 struct i2c_client *client = data->client;
1497 int i; 1431 int i;
1498 1432
1499 mutex_lock(&data->update_lock); 1433 mutex_lock(&data->update_lock);
@@ -1606,6 +1540,30 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1606 return data; 1540 return data;
1607} 1541}
1608 1542
1543static const struct i2c_device_id w83781d_ids[] = {
1544 { "w83781d", w83781d, },
1545 { "w83782d", w83782d, },
1546 { "w83783s", w83783s, },
1547 { "as99127f", as99127f },
1548 { /* LIST END */ }
1549};
1550MODULE_DEVICE_TABLE(i2c, w83781d_ids);
1551
1552static struct i2c_driver w83781d_driver = {
1553 .class = I2C_CLASS_HWMON,
1554 .driver = {
1555 .name = "w83781d",
1556 },
1557 .probe = w83781d_probe,
1558 .remove = w83781d_remove,
1559 .id_table = w83781d_ids,
1560 .detect = w83781d_detect,
1561 .address_data = &addr_data,
1562};
1563
1564/*
1565 * ISA related code
1566 */
1609#ifdef CONFIG_ISA 1567#ifdef CONFIG_ISA
1610 1568
1611/* ISA device, if found */ 1569/* ISA device, if found */
@@ -1631,13 +1589,12 @@ static struct w83781d_data *w83781d_data_if_isa(void)
1631/* Returns 1 if the I2C chip appears to be an alias of the ISA chip */ 1589/* Returns 1 if the I2C chip appears to be an alias of the ISA chip */
1632static int w83781d_alias_detect(struct i2c_client *client, u8 chipid) 1590static int w83781d_alias_detect(struct i2c_client *client, u8 chipid)
1633{ 1591{
1634 struct w83781d_data *i2c, *isa; 1592 struct w83781d_data *isa;
1635 int i; 1593 int i;
1636 1594
1637 if (!pdev) /* No ISA chip */ 1595 if (!pdev) /* No ISA chip */
1638 return 0; 1596 return 0;
1639 1597
1640 i2c = i2c_get_clientdata(client);
1641 isa = platform_get_drvdata(pdev); 1598 isa = platform_get_drvdata(pdev);
1642 1599
1643 if (w83781d_read_value(isa, W83781D_REG_I2C_ADDR) != client->addr) 1600 if (w83781d_read_value(isa, W83781D_REG_I2C_ADDR) != client->addr)
@@ -1648,14 +1605,16 @@ static int w83781d_alias_detect(struct i2c_client *client, u8 chipid)
1648 /* We compare all the limit registers, the config register and the 1605 /* We compare all the limit registers, the config register and the
1649 * interrupt mask registers */ 1606 * interrupt mask registers */
1650 for (i = 0x2b; i <= 0x3d; i++) { 1607 for (i = 0x2b; i <= 0x3d; i++) {
1651 if (w83781d_read_value(isa, i) != w83781d_read_value(i2c, i)) 1608 if (w83781d_read_value(isa, i) !=
1609 i2c_smbus_read_byte_data(client, i))
1652 return 0; 1610 return 0;
1653 } 1611 }
1654 if (w83781d_read_value(isa, W83781D_REG_CONFIG) != 1612 if (w83781d_read_value(isa, W83781D_REG_CONFIG) !=
1655 w83781d_read_value(i2c, W83781D_REG_CONFIG)) 1613 i2c_smbus_read_byte_data(client, W83781D_REG_CONFIG))
1656 return 0; 1614 return 0;
1657 for (i = 0x43; i <= 0x46; i++) { 1615 for (i = 0x43; i <= 0x46; i++) {
1658 if (w83781d_read_value(isa, i) != w83781d_read_value(i2c, i)) 1616 if (w83781d_read_value(isa, i) !=
1617 i2c_smbus_read_byte_data(client, i))
1659 return 0; 1618 return 0;
1660 } 1619 }
1661 1620
@@ -1734,11 +1693,11 @@ w83781d_write_value_isa(struct w83781d_data *data, u16 reg, u16 value)
1734static int 1693static int
1735w83781d_read_value(struct w83781d_data *data, u16 reg) 1694w83781d_read_value(struct w83781d_data *data, u16 reg)
1736{ 1695{
1737 struct i2c_client *client = &data->client; 1696 struct i2c_client *client = data->client;
1738 int res; 1697 int res;
1739 1698
1740 mutex_lock(&data->lock); 1699 mutex_lock(&data->lock);
1741 if (client->driver) 1700 if (client)
1742 res = w83781d_read_value_i2c(data, reg); 1701 res = w83781d_read_value_i2c(data, reg);
1743 else 1702 else
1744 res = w83781d_read_value_isa(data, reg); 1703 res = w83781d_read_value_isa(data, reg);
@@ -1749,10 +1708,10 @@ w83781d_read_value(struct w83781d_data *data, u16 reg)
1749static int 1708static int
1750w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value) 1709w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value)
1751{ 1710{
1752 struct i2c_client *client = &data->client; 1711 struct i2c_client *client = data->client;
1753 1712
1754 mutex_lock(&data->lock); 1713 mutex_lock(&data->lock);
1755 if (client->driver) 1714 if (client)
1756 w83781d_write_value_i2c(data, reg, value); 1715 w83781d_write_value_i2c(data, reg, value);
1757 else 1716 else
1758 w83781d_write_value_isa(data, reg, value); 1717 w83781d_write_value_isa(data, reg, value);