diff options
Diffstat (limited to 'drivers/hwmon/lm78.c')
-rw-r--r-- | drivers/hwmon/lm78.c | 662 |
1 files changed, 395 insertions, 267 deletions
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c index 886786c3391..9fb572f03ba 100644 --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c | |||
@@ -2,6 +2,7 @@ | |||
2 | lm78.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | lm78.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | monitoring | 3 | monitoring |
4 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> | 4 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
5 | Copyright (c) 2007 Jean Delvare <khali@linux-fr.org> | ||
5 | 6 | ||
6 | This program is free software; you can redistribute it and/or modify | 7 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 8 | it under the terms of the GNU General Public License as published by |
@@ -23,13 +24,18 @@ | |||
23 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
24 | #include <linux/jiffies.h> | 25 | #include <linux/jiffies.h> |
25 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
26 | #include <linux/i2c-isa.h> | 27 | #include <linux/platform_device.h> |
28 | #include <linux/ioport.h> | ||
27 | #include <linux/hwmon.h> | 29 | #include <linux/hwmon.h> |
28 | #include <linux/hwmon-vid.h> | 30 | #include <linux/hwmon-vid.h> |
31 | #include <linux/hwmon-sysfs.h> | ||
29 | #include <linux/err.h> | 32 | #include <linux/err.h> |
30 | #include <linux/mutex.h> | 33 | #include <linux/mutex.h> |
31 | #include <asm/io.h> | 34 | #include <asm/io.h> |
32 | 35 | ||
36 | /* ISA device, if found */ | ||
37 | static struct platform_device *pdev; | ||
38 | |||
33 | /* Addresses to scan */ | 39 | /* Addresses to scan */ |
34 | static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, | 40 | static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, |
35 | 0x25, 0x26, 0x27, 0x28, 0x29, | 41 | 0x25, 0x26, 0x27, 0x28, 0x29, |
@@ -121,12 +127,8 @@ static inline int TEMP_FROM_REG(s8 val) | |||
121 | a bit - except if there could be more than one SMBus. Groan. No solution | 127 | a bit - except if there could be more than one SMBus. Groan. No solution |
122 | for this yet. */ | 128 | for this yet. */ |
123 | 129 | ||
124 | /* This module may seem overly long and complicated. In fact, it is not so | 130 | /* For ISA chips, we abuse the i2c_client addr and name fields. We also use |
125 | bad. Quite a lot of bookkeeping is done. A real driver can often cut | 131 | the driver field to differentiate between I2C and ISA chips. */ |
126 | some corners. */ | ||
127 | |||
128 | /* For each registered chip, we need to keep some data in memory. | ||
129 | The structure is dynamically allocated. */ | ||
130 | struct lm78_data { | 132 | struct lm78_data { |
131 | struct i2c_client client; | 133 | struct i2c_client client; |
132 | struct class_device *class_dev; | 134 | struct class_device *class_dev; |
@@ -152,14 +154,16 @@ struct lm78_data { | |||
152 | 154 | ||
153 | 155 | ||
154 | static int lm78_attach_adapter(struct i2c_adapter *adapter); | 156 | static int lm78_attach_adapter(struct i2c_adapter *adapter); |
155 | static int lm78_isa_attach_adapter(struct i2c_adapter *adapter); | ||
156 | static int lm78_detect(struct i2c_adapter *adapter, int address, int kind); | 157 | static int lm78_detect(struct i2c_adapter *adapter, int address, int kind); |
157 | static int lm78_detach_client(struct i2c_client *client); | 158 | static int lm78_detach_client(struct i2c_client *client); |
158 | 159 | ||
159 | static int lm78_read_value(struct i2c_client *client, u8 reg); | 160 | static int __devinit lm78_isa_probe(struct platform_device *pdev); |
160 | static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value); | 161 | static int __devexit lm78_isa_remove(struct platform_device *pdev); |
162 | |||
163 | static int lm78_read_value(struct lm78_data *data, u8 reg); | ||
164 | static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value); | ||
161 | static struct lm78_data *lm78_update_device(struct device *dev); | 165 | static struct lm78_data *lm78_update_device(struct device *dev); |
162 | static void lm78_init_client(struct i2c_client *client); | 166 | static void lm78_init_device(struct lm78_data *data); |
163 | 167 | ||
164 | 168 | ||
165 | static struct i2c_driver lm78_driver = { | 169 | static struct i2c_driver lm78_driver = { |
@@ -171,95 +175,78 @@ static struct i2c_driver lm78_driver = { | |||
171 | .detach_client = lm78_detach_client, | 175 | .detach_client = lm78_detach_client, |
172 | }; | 176 | }; |
173 | 177 | ||
174 | static struct i2c_driver lm78_isa_driver = { | 178 | static struct platform_driver lm78_isa_driver = { |
175 | .driver = { | 179 | .driver = { |
176 | .owner = THIS_MODULE, | 180 | .owner = THIS_MODULE, |
177 | .name = "lm78-isa", | 181 | .name = "lm78", |
178 | }, | 182 | }, |
179 | .attach_adapter = lm78_isa_attach_adapter, | 183 | .probe = lm78_isa_probe, |
180 | .detach_client = lm78_detach_client, | 184 | .remove = lm78_isa_remove, |
181 | }; | 185 | }; |
182 | 186 | ||
183 | 187 | ||
184 | /* 7 Voltages */ | 188 | /* 7 Voltages */ |
185 | static ssize_t show_in(struct device *dev, char *buf, int nr) | 189 | static ssize_t show_in(struct device *dev, struct device_attribute *da, |
190 | char *buf) | ||
186 | { | 191 | { |
192 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
187 | struct lm78_data *data = lm78_update_device(dev); | 193 | struct lm78_data *data = lm78_update_device(dev); |
188 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); | 194 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[attr->index])); |
189 | } | 195 | } |
190 | 196 | ||
191 | static ssize_t show_in_min(struct device *dev, char *buf, int nr) | 197 | static ssize_t show_in_min(struct device *dev, struct device_attribute *da, |
198 | char *buf) | ||
192 | { | 199 | { |
200 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
193 | struct lm78_data *data = lm78_update_device(dev); | 201 | struct lm78_data *data = lm78_update_device(dev); |
194 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); | 202 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[attr->index])); |
195 | } | 203 | } |
196 | 204 | ||
197 | static ssize_t show_in_max(struct device *dev, char *buf, int nr) | 205 | static ssize_t show_in_max(struct device *dev, struct device_attribute *da, |
206 | char *buf) | ||
198 | { | 207 | { |
208 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
199 | struct lm78_data *data = lm78_update_device(dev); | 209 | struct lm78_data *data = lm78_update_device(dev); |
200 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); | 210 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[attr->index])); |
201 | } | 211 | } |
202 | 212 | ||
203 | static ssize_t set_in_min(struct device *dev, const char *buf, | 213 | static ssize_t set_in_min(struct device *dev, struct device_attribute *da, |
204 | size_t count, int nr) | 214 | const char *buf, size_t count) |
205 | { | 215 | { |
206 | struct i2c_client *client = to_i2c_client(dev); | 216 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
207 | struct lm78_data *data = i2c_get_clientdata(client); | 217 | struct lm78_data *data = dev_get_drvdata(dev); |
208 | unsigned long val = simple_strtoul(buf, NULL, 10); | 218 | unsigned long val = simple_strtoul(buf, NULL, 10); |
219 | int nr = attr->index; | ||
209 | 220 | ||
210 | mutex_lock(&data->update_lock); | 221 | mutex_lock(&data->update_lock); |
211 | data->in_min[nr] = IN_TO_REG(val); | 222 | data->in_min[nr] = IN_TO_REG(val); |
212 | lm78_write_value(client, LM78_REG_IN_MIN(nr), data->in_min[nr]); | 223 | lm78_write_value(data, LM78_REG_IN_MIN(nr), data->in_min[nr]); |
213 | mutex_unlock(&data->update_lock); | 224 | mutex_unlock(&data->update_lock); |
214 | return count; | 225 | return count; |
215 | } | 226 | } |
216 | 227 | ||
217 | static ssize_t set_in_max(struct device *dev, const char *buf, | 228 | static ssize_t set_in_max(struct device *dev, struct device_attribute *da, |
218 | size_t count, int nr) | 229 | const char *buf, size_t count) |
219 | { | 230 | { |
220 | struct i2c_client *client = to_i2c_client(dev); | 231 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
221 | struct lm78_data *data = i2c_get_clientdata(client); | 232 | struct lm78_data *data = dev_get_drvdata(dev); |
222 | unsigned long val = simple_strtoul(buf, NULL, 10); | 233 | unsigned long val = simple_strtoul(buf, NULL, 10); |
234 | int nr = attr->index; | ||
223 | 235 | ||
224 | mutex_lock(&data->update_lock); | 236 | mutex_lock(&data->update_lock); |
225 | data->in_max[nr] = IN_TO_REG(val); | 237 | data->in_max[nr] = IN_TO_REG(val); |
226 | lm78_write_value(client, LM78_REG_IN_MAX(nr), data->in_max[nr]); | 238 | lm78_write_value(data, LM78_REG_IN_MAX(nr), data->in_max[nr]); |
227 | mutex_unlock(&data->update_lock); | 239 | mutex_unlock(&data->update_lock); |
228 | return count; | 240 | return count; |
229 | } | 241 | } |
230 | 242 | ||
231 | #define show_in_offset(offset) \ | 243 | #define show_in_offset(offset) \ |
232 | static ssize_t \ | 244 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
233 | show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 245 | show_in, NULL, offset); \ |
234 | { \ | 246 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
235 | return show_in(dev, buf, offset); \ | 247 | show_in_min, set_in_min, offset); \ |
236 | } \ | 248 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
237 | static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ | 249 | show_in_max, set_in_max, offset); |
238 | show_in##offset, NULL); \ | ||
239 | static ssize_t \ | ||
240 | show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
241 | { \ | ||
242 | return show_in_min(dev, buf, offset); \ | ||
243 | } \ | ||
244 | static ssize_t \ | ||
245 | show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
246 | { \ | ||
247 | return show_in_max(dev, buf, offset); \ | ||
248 | } \ | ||
249 | static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
250 | const char *buf, size_t count) \ | ||
251 | { \ | ||
252 | return set_in_min(dev, buf, count, offset); \ | ||
253 | } \ | ||
254 | static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \ | ||
255 | const char *buf, size_t count) \ | ||
256 | { \ | ||
257 | return set_in_max(dev, buf, count, offset); \ | ||
258 | } \ | ||
259 | static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | ||
260 | show_in##offset##_min, set_in##offset##_min); \ | ||
261 | static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | ||
262 | show_in##offset##_max, set_in##offset##_max); | ||
263 | 250 | ||
264 | show_in_offset(0); | 251 | show_in_offset(0); |
265 | show_in_offset(1); | 252 | show_in_offset(1); |
@@ -270,46 +257,49 @@ show_in_offset(5); | |||
270 | show_in_offset(6); | 257 | show_in_offset(6); |
271 | 258 | ||
272 | /* Temperature */ | 259 | /* Temperature */ |
273 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf) | 260 | static ssize_t show_temp(struct device *dev, struct device_attribute *da, |
261 | char *buf) | ||
274 | { | 262 | { |
275 | struct lm78_data *data = lm78_update_device(dev); | 263 | struct lm78_data *data = lm78_update_device(dev); |
276 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); | 264 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); |
277 | } | 265 | } |
278 | 266 | ||
279 | static ssize_t show_temp_over(struct device *dev, struct device_attribute *attr, char *buf) | 267 | static ssize_t show_temp_over(struct device *dev, struct device_attribute *da, |
268 | char *buf) | ||
280 | { | 269 | { |
281 | struct lm78_data *data = lm78_update_device(dev); | 270 | struct lm78_data *data = lm78_update_device(dev); |
282 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over)); | 271 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over)); |
283 | } | 272 | } |
284 | 273 | ||
285 | static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 274 | static ssize_t set_temp_over(struct device *dev, struct device_attribute *da, |
275 | const char *buf, size_t count) | ||
286 | { | 276 | { |
287 | struct i2c_client *client = to_i2c_client(dev); | 277 | struct lm78_data *data = dev_get_drvdata(dev); |
288 | struct lm78_data *data = i2c_get_clientdata(client); | ||
289 | long val = simple_strtol(buf, NULL, 10); | 278 | long val = simple_strtol(buf, NULL, 10); |
290 | 279 | ||
291 | mutex_lock(&data->update_lock); | 280 | mutex_lock(&data->update_lock); |
292 | data->temp_over = TEMP_TO_REG(val); | 281 | data->temp_over = TEMP_TO_REG(val); |
293 | lm78_write_value(client, LM78_REG_TEMP_OVER, data->temp_over); | 282 | lm78_write_value(data, LM78_REG_TEMP_OVER, data->temp_over); |
294 | mutex_unlock(&data->update_lock); | 283 | mutex_unlock(&data->update_lock); |
295 | return count; | 284 | return count; |
296 | } | 285 | } |
297 | 286 | ||
298 | static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *attr, char *buf) | 287 | static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *da, |
288 | char *buf) | ||
299 | { | 289 | { |
300 | struct lm78_data *data = lm78_update_device(dev); | 290 | struct lm78_data *data = lm78_update_device(dev); |
301 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst)); | 291 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst)); |
302 | } | 292 | } |
303 | 293 | ||
304 | static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 294 | static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *da, |
295 | const char *buf, size_t count) | ||
305 | { | 296 | { |
306 | struct i2c_client *client = to_i2c_client(dev); | 297 | struct lm78_data *data = dev_get_drvdata(dev); |
307 | struct lm78_data *data = i2c_get_clientdata(client); | ||
308 | long val = simple_strtol(buf, NULL, 10); | 298 | long val = simple_strtol(buf, NULL, 10); |
309 | 299 | ||
310 | mutex_lock(&data->update_lock); | 300 | mutex_lock(&data->update_lock); |
311 | data->temp_hyst = TEMP_TO_REG(val); | 301 | data->temp_hyst = TEMP_TO_REG(val); |
312 | lm78_write_value(client, LM78_REG_TEMP_HYST, data->temp_hyst); | 302 | lm78_write_value(data, LM78_REG_TEMP_HYST, data->temp_hyst); |
313 | mutex_unlock(&data->update_lock); | 303 | mutex_unlock(&data->update_lock); |
314 | return count; | 304 | return count; |
315 | } | 305 | } |
@@ -321,49 +311,59 @@ static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, | |||
321 | show_temp_hyst, set_temp_hyst); | 311 | show_temp_hyst, set_temp_hyst); |
322 | 312 | ||
323 | /* 3 Fans */ | 313 | /* 3 Fans */ |
324 | static ssize_t show_fan(struct device *dev, char *buf, int nr) | 314 | static ssize_t show_fan(struct device *dev, struct device_attribute *da, |
315 | char *buf) | ||
325 | { | 316 | { |
317 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
326 | struct lm78_data *data = lm78_update_device(dev); | 318 | struct lm78_data *data = lm78_update_device(dev); |
319 | int nr = attr->index; | ||
327 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], | 320 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
328 | DIV_FROM_REG(data->fan_div[nr])) ); | 321 | DIV_FROM_REG(data->fan_div[nr])) ); |
329 | } | 322 | } |
330 | 323 | ||
331 | static ssize_t show_fan_min(struct device *dev, char *buf, int nr) | 324 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, |
325 | char *buf) | ||
332 | { | 326 | { |
327 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
333 | struct lm78_data *data = lm78_update_device(dev); | 328 | struct lm78_data *data = lm78_update_device(dev); |
329 | int nr = attr->index; | ||
334 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], | 330 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], |
335 | DIV_FROM_REG(data->fan_div[nr])) ); | 331 | DIV_FROM_REG(data->fan_div[nr])) ); |
336 | } | 332 | } |
337 | 333 | ||
338 | static ssize_t set_fan_min(struct device *dev, const char *buf, | 334 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, |
339 | size_t count, int nr) | 335 | const char *buf, size_t count) |
340 | { | 336 | { |
341 | struct i2c_client *client = to_i2c_client(dev); | 337 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
342 | struct lm78_data *data = i2c_get_clientdata(client); | 338 | struct lm78_data *data = dev_get_drvdata(dev); |
339 | int nr = attr->index; | ||
343 | unsigned long val = simple_strtoul(buf, NULL, 10); | 340 | unsigned long val = simple_strtoul(buf, NULL, 10); |
344 | 341 | ||
345 | mutex_lock(&data->update_lock); | 342 | mutex_lock(&data->update_lock); |
346 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 343 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
347 | lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]); | 344 | lm78_write_value(data, LM78_REG_FAN_MIN(nr), data->fan_min[nr]); |
348 | mutex_unlock(&data->update_lock); | 345 | mutex_unlock(&data->update_lock); |
349 | return count; | 346 | return count; |
350 | } | 347 | } |
351 | 348 | ||
352 | static ssize_t show_fan_div(struct device *dev, char *buf, int nr) | 349 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *da, |
350 | char *buf) | ||
353 | { | 351 | { |
352 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
354 | struct lm78_data *data = lm78_update_device(dev); | 353 | struct lm78_data *data = lm78_update_device(dev); |
355 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); | 354 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index])); |
356 | } | 355 | } |
357 | 356 | ||
358 | /* Note: we save and restore the fan minimum here, because its value is | 357 | /* Note: we save and restore the fan minimum here, because its value is |
359 | determined in part by the fan divisor. This follows the principle of | 358 | determined in part by the fan divisor. This follows the principle of |
360 | least surprise; the user doesn't expect the fan minimum to change just | 359 | least surprise; the user doesn't expect the fan minimum to change just |
361 | because the divisor changed. */ | 360 | because the divisor changed. */ |
362 | static ssize_t set_fan_div(struct device *dev, const char *buf, | 361 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, |
363 | size_t count, int nr) | 362 | const char *buf, size_t count) |
364 | { | 363 | { |
365 | struct i2c_client *client = to_i2c_client(dev); | 364 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
366 | struct lm78_data *data = i2c_get_clientdata(client); | 365 | struct lm78_data *data = dev_get_drvdata(dev); |
366 | int nr = attr->index; | ||
367 | unsigned long val = simple_strtoul(buf, NULL, 10); | 367 | unsigned long val = simple_strtoul(buf, NULL, 10); |
368 | unsigned long min; | 368 | unsigned long min; |
369 | u8 reg; | 369 | u8 reg; |
@@ -378,13 +378,13 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
378 | case 4: data->fan_div[nr] = 2; break; | 378 | case 4: data->fan_div[nr] = 2; break; |
379 | case 8: data->fan_div[nr] = 3; break; | 379 | case 8: data->fan_div[nr] = 3; break; |
380 | default: | 380 | default: |
381 | dev_err(&client->dev, "fan_div value %ld not " | 381 | dev_err(dev, "fan_div value %ld not " |
382 | "supported. Choose one of 1, 2, 4 or 8!\n", val); | 382 | "supported. Choose one of 1, 2, 4 or 8!\n", val); |
383 | mutex_unlock(&data->update_lock); | 383 | mutex_unlock(&data->update_lock); |
384 | return -EINVAL; | 384 | return -EINVAL; |
385 | } | 385 | } |
386 | 386 | ||
387 | reg = lm78_read_value(client, LM78_REG_VID_FANDIV); | 387 | reg = lm78_read_value(data, LM78_REG_VID_FANDIV); |
388 | switch (nr) { | 388 | switch (nr) { |
389 | case 0: | 389 | case 0: |
390 | reg = (reg & 0xcf) | (data->fan_div[nr] << 4); | 390 | reg = (reg & 0xcf) | (data->fan_div[nr] << 4); |
@@ -393,63 +393,36 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
393 | reg = (reg & 0x3f) | (data->fan_div[nr] << 6); | 393 | reg = (reg & 0x3f) | (data->fan_div[nr] << 6); |
394 | break; | 394 | break; |
395 | } | 395 | } |
396 | lm78_write_value(client, LM78_REG_VID_FANDIV, reg); | 396 | lm78_write_value(data, LM78_REG_VID_FANDIV, reg); |
397 | 397 | ||
398 | data->fan_min[nr] = | 398 | data->fan_min[nr] = |
399 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 399 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
400 | lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]); | 400 | lm78_write_value(data, LM78_REG_FAN_MIN(nr), data->fan_min[nr]); |
401 | mutex_unlock(&data->update_lock); | 401 | mutex_unlock(&data->update_lock); |
402 | 402 | ||
403 | return count; | 403 | return count; |
404 | } | 404 | } |
405 | 405 | ||
406 | #define show_fan_offset(offset) \ | 406 | #define show_fan_offset(offset) \ |
407 | static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 407 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
408 | { \ | 408 | show_fan, NULL, offset - 1); \ |
409 | return show_fan(dev, buf, offset - 1); \ | 409 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
410 | } \ | 410 | show_fan_min, set_fan_min, offset - 1); |
411 | static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
412 | { \ | ||
413 | return show_fan_min(dev, buf, offset - 1); \ | ||
414 | } \ | ||
415 | static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
416 | { \ | ||
417 | return show_fan_div(dev, buf, offset - 1); \ | ||
418 | } \ | ||
419 | static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
420 | const char *buf, size_t count) \ | ||
421 | { \ | ||
422 | return set_fan_min(dev, buf, count, offset - 1); \ | ||
423 | } \ | ||
424 | static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\ | ||
425 | static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | ||
426 | show_fan_##offset##_min, set_fan_##offset##_min); | ||
427 | |||
428 | static ssize_t set_fan_1_div(struct device *dev, struct device_attribute *attr, const char *buf, | ||
429 | size_t count) | ||
430 | { | ||
431 | return set_fan_div(dev, buf, count, 0) ; | ||
432 | } | ||
433 | |||
434 | static ssize_t set_fan_2_div(struct device *dev, struct device_attribute *attr, const char *buf, | ||
435 | size_t count) | ||
436 | { | ||
437 | return set_fan_div(dev, buf, count, 1) ; | ||
438 | } | ||
439 | 411 | ||
440 | show_fan_offset(1); | 412 | show_fan_offset(1); |
441 | show_fan_offset(2); | 413 | show_fan_offset(2); |
442 | show_fan_offset(3); | 414 | show_fan_offset(3); |
443 | 415 | ||
444 | /* Fan 3 divisor is locked in H/W */ | 416 | /* Fan 3 divisor is locked in H/W */ |
445 | static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, | 417 | static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, |
446 | show_fan_1_div, set_fan_1_div); | 418 | show_fan_div, set_fan_div, 0); |
447 | static DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, | 419 | static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, |
448 | show_fan_2_div, set_fan_2_div); | 420 | show_fan_div, set_fan_div, 1); |
449 | static DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_3_div, NULL); | 421 | static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2); |
450 | 422 | ||
451 | /* VID */ | 423 | /* VID */ |
452 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) | 424 | static ssize_t show_vid(struct device *dev, struct device_attribute *da, |
425 | char *buf) | ||
453 | { | 426 | { |
454 | struct lm78_data *data = lm78_update_device(dev); | 427 | struct lm78_data *data = lm78_update_device(dev); |
455 | return sprintf(buf, "%d\n", vid_from_reg(data->vid, 82)); | 428 | return sprintf(buf, "%d\n", vid_from_reg(data->vid, 82)); |
@@ -457,7 +430,8 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char | |||
457 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); | 430 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); |
458 | 431 | ||
459 | /* Alarms */ | 432 | /* Alarms */ |
460 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 433 | static ssize_t show_alarms(struct device *dev, struct device_attribute *da, |
434 | char *buf) | ||
461 | { | 435 | { |
462 | struct lm78_data *data = lm78_update_device(dev); | 436 | struct lm78_data *data = lm78_update_device(dev); |
463 | return sprintf(buf, "%u\n", data->alarms); | 437 | return sprintf(buf, "%u\n", data->alarms); |
@@ -475,45 +449,40 @@ static int lm78_attach_adapter(struct i2c_adapter *adapter) | |||
475 | return i2c_probe(adapter, &addr_data, lm78_detect); | 449 | return i2c_probe(adapter, &addr_data, lm78_detect); |
476 | } | 450 | } |
477 | 451 | ||
478 | static int lm78_isa_attach_adapter(struct i2c_adapter *adapter) | ||
479 | { | ||
480 | return lm78_detect(adapter, isa_address, -1); | ||
481 | } | ||
482 | |||
483 | static struct attribute *lm78_attributes[] = { | 452 | static struct attribute *lm78_attributes[] = { |
484 | &dev_attr_in0_input.attr, | 453 | &sensor_dev_attr_in0_input.dev_attr.attr, |
485 | &dev_attr_in0_min.attr, | 454 | &sensor_dev_attr_in0_min.dev_attr.attr, |
486 | &dev_attr_in0_max.attr, | 455 | &sensor_dev_attr_in0_max.dev_attr.attr, |
487 | &dev_attr_in1_input.attr, | 456 | &sensor_dev_attr_in1_input.dev_attr.attr, |
488 | &dev_attr_in1_min.attr, | 457 | &sensor_dev_attr_in1_min.dev_attr.attr, |
489 | &dev_attr_in1_max.attr, | 458 | &sensor_dev_attr_in1_max.dev_attr.attr, |
490 | &dev_attr_in2_input.attr, | 459 | &sensor_dev_attr_in2_input.dev_attr.attr, |
491 | &dev_attr_in2_min.attr, | 460 | &sensor_dev_attr_in2_min.dev_attr.attr, |
492 | &dev_attr_in2_max.attr, | 461 | &sensor_dev_attr_in2_max.dev_attr.attr, |
493 | &dev_attr_in3_input.attr, | 462 | &sensor_dev_attr_in3_input.dev_attr.attr, |
494 | &dev_attr_in3_min.attr, | 463 | &sensor_dev_attr_in3_min.dev_attr.attr, |
495 | &dev_attr_in3_max.attr, | 464 | &sensor_dev_attr_in3_max.dev_attr.attr, |
496 | &dev_attr_in4_input.attr, | 465 | &sensor_dev_attr_in4_input.dev_attr.attr, |
497 | &dev_attr_in4_min.attr, | 466 | &sensor_dev_attr_in4_min.dev_attr.attr, |
498 | &dev_attr_in4_max.attr, | 467 | &sensor_dev_attr_in4_max.dev_attr.attr, |
499 | &dev_attr_in5_input.attr, | 468 | &sensor_dev_attr_in5_input.dev_attr.attr, |
500 | &dev_attr_in5_min.attr, | 469 | &sensor_dev_attr_in5_min.dev_attr.attr, |
501 | &dev_attr_in5_max.attr, | 470 | &sensor_dev_attr_in5_max.dev_attr.attr, |
502 | &dev_attr_in6_input.attr, | 471 | &sensor_dev_attr_in6_input.dev_attr.attr, |
503 | &dev_attr_in6_min.attr, | 472 | &sensor_dev_attr_in6_min.dev_attr.attr, |
504 | &dev_attr_in6_max.attr, | 473 | &sensor_dev_attr_in6_max.dev_attr.attr, |
505 | &dev_attr_temp1_input.attr, | 474 | &dev_attr_temp1_input.attr, |
506 | &dev_attr_temp1_max.attr, | 475 | &dev_attr_temp1_max.attr, |
507 | &dev_attr_temp1_max_hyst.attr, | 476 | &dev_attr_temp1_max_hyst.attr, |
508 | &dev_attr_fan1_input.attr, | 477 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
509 | &dev_attr_fan1_min.attr, | 478 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
510 | &dev_attr_fan1_div.attr, | 479 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
511 | &dev_attr_fan2_input.attr, | 480 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
512 | &dev_attr_fan2_min.attr, | 481 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
513 | &dev_attr_fan2_div.attr, | 482 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
514 | &dev_attr_fan3_input.attr, | 483 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
515 | &dev_attr_fan3_min.attr, | 484 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
516 | &dev_attr_fan3_div.attr, | 485 | &sensor_dev_attr_fan3_div.dev_attr.attr, |
517 | &dev_attr_alarms.attr, | 486 | &dev_attr_alarms.attr, |
518 | &dev_attr_cpu0_vid.attr, | 487 | &dev_attr_cpu0_vid.attr, |
519 | 488 | ||
@@ -524,6 +493,17 @@ static const struct attribute_group lm78_group = { | |||
524 | .attrs = lm78_attributes, | 493 | .attrs = lm78_attributes, |
525 | }; | 494 | }; |
526 | 495 | ||
496 | /* I2C devices get this name attribute automatically, but for ISA devices | ||
497 | we must create it by ourselves. */ | ||
498 | static ssize_t show_name(struct device *dev, struct device_attribute | ||
499 | *devattr, char *buf) | ||
500 | { | ||
501 | struct lm78_data *data = dev_get_drvdata(dev); | ||
502 | |||
503 | return sprintf(buf, "%s\n", data->client.name); | ||
504 | } | ||
505 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
506 | |||
527 | /* This function is called by i2c_probe */ | 507 | /* This function is called by i2c_probe */ |
528 | static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) | 508 | static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) |
529 | { | 509 | { |
@@ -531,54 +511,10 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) | |||
531 | struct i2c_client *new_client; | 511 | struct i2c_client *new_client; |
532 | struct lm78_data *data; | 512 | struct lm78_data *data; |
533 | const char *client_name = ""; | 513 | const char *client_name = ""; |
534 | int is_isa = i2c_is_isa_adapter(adapter); | ||
535 | 514 | ||
536 | if (!is_isa && | 515 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
537 | !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | ||
538 | err = -ENODEV; | 516 | err = -ENODEV; |
539 | goto ERROR0; | 517 | goto ERROR1; |
540 | } | ||
541 | |||
542 | /* Reserve the ISA region */ | ||
543 | if (is_isa) | ||
544 | if (!request_region(address, LM78_EXTENT, | ||
545 | lm78_isa_driver.driver.name)) { | ||
546 | err = -EBUSY; | ||
547 | goto ERROR0; | ||
548 | } | ||
549 | |||
550 | /* Probe whether there is anything available on this address. Already | ||
551 | done for SMBus clients */ | ||
552 | if (kind < 0) { | ||
553 | if (is_isa) { | ||
554 | |||
555 | #define REALLY_SLOW_IO | ||
556 | /* We need the timeouts for at least some LM78-like | ||
557 | chips. But only if we read 'undefined' registers. */ | ||
558 | i = inb_p(address + 1); | ||
559 | if (inb_p(address + 2) != i) { | ||
560 | err = -ENODEV; | ||
561 | goto ERROR1; | ||
562 | } | ||
563 | if (inb_p(address + 3) != i) { | ||
564 | err = -ENODEV; | ||
565 | goto ERROR1; | ||
566 | } | ||
567 | if (inb_p(address + 7) != i) { | ||
568 | err = -ENODEV; | ||
569 | goto ERROR1; | ||
570 | } | ||
571 | #undef REALLY_SLOW_IO | ||
572 | |||
573 | /* Let's just hope nothing breaks here */ | ||
574 | i = inb_p(address + 5) & 0x7f; | ||
575 | outb_p(~i & 0x7f, address + 5); | ||
576 | if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) { | ||
577 | outb_p(i, address + 5); | ||
578 | err = -ENODEV; | ||
579 | goto ERROR1; | ||
580 | } | ||
581 | } | ||
582 | } | 518 | } |
583 | 519 | ||
584 | /* OK. For now, we presume we have a valid client. We now create the | 520 | /* OK. For now, we presume we have a valid client. We now create the |
@@ -591,22 +527,19 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) | |||
591 | } | 527 | } |
592 | 528 | ||
593 | new_client = &data->client; | 529 | new_client = &data->client; |
594 | if (is_isa) | ||
595 | mutex_init(&data->lock); | ||
596 | i2c_set_clientdata(new_client, data); | 530 | i2c_set_clientdata(new_client, data); |
597 | new_client->addr = address; | 531 | new_client->addr = address; |
598 | new_client->adapter = adapter; | 532 | new_client->adapter = adapter; |
599 | new_client->driver = is_isa ? &lm78_isa_driver : &lm78_driver; | 533 | new_client->driver = &lm78_driver; |
600 | new_client->flags = 0; | ||
601 | 534 | ||
602 | /* Now, we do the remaining detection. */ | 535 | /* Now, we do the remaining detection. */ |
603 | if (kind < 0) { | 536 | if (kind < 0) { |
604 | if (lm78_read_value(new_client, LM78_REG_CONFIG) & 0x80) { | 537 | if (lm78_read_value(data, LM78_REG_CONFIG) & 0x80) { |
605 | err = -ENODEV; | 538 | err = -ENODEV; |
606 | goto ERROR2; | 539 | goto ERROR2; |
607 | } | 540 | } |
608 | if (!is_isa && (lm78_read_value( | 541 | if (lm78_read_value(data, LM78_REG_I2C_ADDR) != |
609 | new_client, LM78_REG_I2C_ADDR) != address)) { | 542 | address) { |
610 | err = -ENODEV; | 543 | err = -ENODEV; |
611 | goto ERROR2; | 544 | goto ERROR2; |
612 | } | 545 | } |
@@ -614,7 +547,7 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) | |||
614 | 547 | ||
615 | /* Determine the chip type. */ | 548 | /* Determine the chip type. */ |
616 | if (kind <= 0) { | 549 | if (kind <= 0) { |
617 | i = lm78_read_value(new_client, LM78_REG_CHIPID); | 550 | i = lm78_read_value(data, LM78_REG_CHIPID); |
618 | if (i == 0x00 || i == 0x20 /* LM78 */ | 551 | if (i == 0x00 || i == 0x20 /* LM78 */ |
619 | || i == 0x40) /* LM78-J */ | 552 | || i == 0x40) /* LM78-J */ |
620 | kind = lm78; | 553 | kind = lm78; |
@@ -641,21 +574,12 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) | |||
641 | strlcpy(new_client->name, client_name, I2C_NAME_SIZE); | 574 | strlcpy(new_client->name, client_name, I2C_NAME_SIZE); |
642 | data->type = kind; | 575 | data->type = kind; |
643 | 576 | ||
644 | data->valid = 0; | ||
645 | mutex_init(&data->update_lock); | ||
646 | |||
647 | /* Tell the I2C layer a new client has arrived */ | 577 | /* Tell the I2C layer a new client has arrived */ |
648 | if ((err = i2c_attach_client(new_client))) | 578 | if ((err = i2c_attach_client(new_client))) |
649 | goto ERROR2; | 579 | goto ERROR2; |
650 | 580 | ||
651 | /* Initialize the LM78 chip */ | 581 | /* Initialize the LM78 chip */ |
652 | lm78_init_client(new_client); | 582 | lm78_init_device(data); |
653 | |||
654 | /* A few vars need to be filled upon startup */ | ||
655 | for (i = 0; i < 3; i++) { | ||
656 | data->fan_min[i] = lm78_read_value(new_client, | ||
657 | LM78_REG_FAN_MIN(i)); | ||
658 | } | ||
659 | 583 | ||
660 | /* Register sysfs hooks */ | 584 | /* Register sysfs hooks */ |
661 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm78_group))) | 585 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm78_group))) |
@@ -676,9 +600,6 @@ ERROR3: | |||
676 | ERROR2: | 600 | ERROR2: |
677 | kfree(data); | 601 | kfree(data); |
678 | ERROR1: | 602 | ERROR1: |
679 | if (is_isa) | ||
680 | release_region(address, LM78_EXTENT); | ||
681 | ERROR0: | ||
682 | return err; | 603 | return err; |
683 | } | 604 | } |
684 | 605 | ||
@@ -693,9 +614,77 @@ static int lm78_detach_client(struct i2c_client *client) | |||
693 | if ((err = i2c_detach_client(client))) | 614 | if ((err = i2c_detach_client(client))) |
694 | return err; | 615 | return err; |
695 | 616 | ||
696 | if(i2c_is_isa_client(client)) | 617 | kfree(data); |
697 | release_region(client->addr, LM78_EXTENT); | 618 | |
619 | return 0; | ||
620 | } | ||
621 | |||
622 | static int __devinit lm78_isa_probe(struct platform_device *pdev) | ||
623 | { | ||
624 | int err; | ||
625 | struct lm78_data *data; | ||
626 | struct resource *res; | ||
627 | const char *name; | ||
628 | |||
629 | /* Reserve the ISA region */ | ||
630 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
631 | if (!request_region(res->start, LM78_EXTENT, "lm78")) { | ||
632 | err = -EBUSY; | ||
633 | goto exit; | ||
634 | } | ||
635 | |||
636 | if (!(data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL))) { | ||
637 | err = -ENOMEM; | ||
638 | goto exit_release_region; | ||
639 | } | ||
640 | mutex_init(&data->lock); | ||
641 | data->client.addr = res->start; | ||
642 | i2c_set_clientdata(&data->client, data); | ||
643 | platform_set_drvdata(pdev, data); | ||
644 | |||
645 | if (lm78_read_value(data, LM78_REG_CHIPID) & 0x80) { | ||
646 | data->type = lm79; | ||
647 | name = "lm79"; | ||
648 | } else { | ||
649 | data->type = lm78; | ||
650 | name = "lm78"; | ||
651 | } | ||
652 | strlcpy(data->client.name, name, I2C_NAME_SIZE); | ||
653 | |||
654 | /* Initialize the LM78 chip */ | ||
655 | lm78_init_device(data); | ||
656 | |||
657 | /* Register sysfs hooks */ | ||
658 | if ((err = sysfs_create_group(&pdev->dev.kobj, &lm78_group)) | ||
659 | || (err = device_create_file(&pdev->dev, &dev_attr_name))) | ||
660 | goto exit_remove_files; | ||
661 | |||
662 | data->class_dev = hwmon_device_register(&pdev->dev); | ||
663 | if (IS_ERR(data->class_dev)) { | ||
664 | err = PTR_ERR(data->class_dev); | ||
665 | goto exit_remove_files; | ||
666 | } | ||
667 | |||
668 | return 0; | ||
669 | |||
670 | exit_remove_files: | ||
671 | sysfs_remove_group(&pdev->dev.kobj, &lm78_group); | ||
672 | device_remove_file(&pdev->dev, &dev_attr_name); | ||
673 | kfree(data); | ||
674 | exit_release_region: | ||
675 | release_region(res->start, LM78_EXTENT); | ||
676 | exit: | ||
677 | return err; | ||
678 | } | ||
679 | |||
680 | static int __devexit lm78_isa_remove(struct platform_device *pdev) | ||
681 | { | ||
682 | struct lm78_data *data = platform_get_drvdata(pdev); | ||
698 | 683 | ||
684 | hwmon_device_unregister(data->class_dev); | ||
685 | sysfs_remove_group(&pdev->dev.kobj, &lm78_group); | ||
686 | device_remove_file(&pdev->dev, &dev_attr_name); | ||
687 | release_region(data->client.addr, LM78_EXTENT); | ||
699 | kfree(data); | 688 | kfree(data); |
700 | 689 | ||
701 | return 0; | 690 | return 0; |
@@ -706,11 +695,12 @@ static int lm78_detach_client(struct i2c_client *client) | |||
706 | separately. | 695 | separately. |
707 | We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks, | 696 | We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks, |
708 | would slow down the LM78 access and should not be necessary. */ | 697 | would slow down the LM78 access and should not be necessary. */ |
709 | static int lm78_read_value(struct i2c_client *client, u8 reg) | 698 | static int lm78_read_value(struct lm78_data *data, u8 reg) |
710 | { | 699 | { |
711 | int res; | 700 | struct i2c_client *client = &data->client; |
712 | if (i2c_is_isa_client(client)) { | 701 | |
713 | struct lm78_data *data = i2c_get_clientdata(client); | 702 | if (!client->driver) { /* ISA device */ |
703 | int res; | ||
714 | mutex_lock(&data->lock); | 704 | mutex_lock(&data->lock); |
715 | outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); | 705 | outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); |
716 | res = inb_p(client->addr + LM78_DATA_REG_OFFSET); | 706 | res = inb_p(client->addr + LM78_DATA_REG_OFFSET); |
@@ -727,10 +717,11 @@ static int lm78_read_value(struct i2c_client *client, u8 reg) | |||
727 | would slow down the LM78 access and should not be necessary. | 717 | would slow down the LM78 access and should not be necessary. |
728 | There are some ugly typecasts here, but the good new is - they should | 718 | There are some ugly typecasts here, but the good new is - they should |
729 | nowhere else be necessary! */ | 719 | nowhere else be necessary! */ |
730 | static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value) | 720 | static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value) |
731 | { | 721 | { |
732 | if (i2c_is_isa_client(client)) { | 722 | struct i2c_client *client = &data->client; |
733 | struct lm78_data *data = i2c_get_clientdata(client); | 723 | |
724 | if (!client->driver) { /* ISA device */ | ||
734 | mutex_lock(&data->lock); | 725 | mutex_lock(&data->lock); |
735 | outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); | 726 | outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); |
736 | outb_p(value, client->addr + LM78_DATA_REG_OFFSET); | 727 | outb_p(value, client->addr + LM78_DATA_REG_OFFSET); |
@@ -740,20 +731,29 @@ static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value) | |||
740 | return i2c_smbus_write_byte_data(client, reg, value); | 731 | return i2c_smbus_write_byte_data(client, reg, value); |
741 | } | 732 | } |
742 | 733 | ||
743 | static void lm78_init_client(struct i2c_client *client) | 734 | static void lm78_init_device(struct lm78_data *data) |
744 | { | 735 | { |
745 | u8 config = lm78_read_value(client, LM78_REG_CONFIG); | 736 | u8 config; |
737 | int i; | ||
746 | 738 | ||
747 | /* Start monitoring */ | 739 | /* Start monitoring */ |
748 | if (!(config & 0x01)) | 740 | config = lm78_read_value(data, LM78_REG_CONFIG); |
749 | lm78_write_value(client, LM78_REG_CONFIG, | 741 | if ((config & 0x09) != 0x01) |
742 | lm78_write_value(data, LM78_REG_CONFIG, | ||
750 | (config & 0xf7) | 0x01); | 743 | (config & 0xf7) | 0x01); |
744 | |||
745 | /* A few vars need to be filled upon startup */ | ||
746 | for (i = 0; i < 3; i++) { | ||
747 | data->fan_min[i] = lm78_read_value(data, | ||
748 | LM78_REG_FAN_MIN(i)); | ||
749 | } | ||
750 | |||
751 | mutex_init(&data->update_lock); | ||
751 | } | 752 | } |
752 | 753 | ||
753 | static struct lm78_data *lm78_update_device(struct device *dev) | 754 | static struct lm78_data *lm78_update_device(struct device *dev) |
754 | { | 755 | { |
755 | struct i2c_client *client = to_i2c_client(dev); | 756 | struct lm78_data *data = dev_get_drvdata(dev); |
756 | struct lm78_data *data = i2c_get_clientdata(client); | ||
757 | int i; | 757 | int i; |
758 | 758 | ||
759 | mutex_lock(&data->update_lock); | 759 | mutex_lock(&data->update_lock); |
@@ -761,39 +761,39 @@ static struct lm78_data *lm78_update_device(struct device *dev) | |||
761 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 761 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
762 | || !data->valid) { | 762 | || !data->valid) { |
763 | 763 | ||
764 | dev_dbg(&client->dev, "Starting lm78 update\n"); | 764 | dev_dbg(dev, "Starting lm78 update\n"); |
765 | 765 | ||
766 | for (i = 0; i <= 6; i++) { | 766 | for (i = 0; i <= 6; i++) { |
767 | data->in[i] = | 767 | data->in[i] = |
768 | lm78_read_value(client, LM78_REG_IN(i)); | 768 | lm78_read_value(data, LM78_REG_IN(i)); |
769 | data->in_min[i] = | 769 | data->in_min[i] = |
770 | lm78_read_value(client, LM78_REG_IN_MIN(i)); | 770 | lm78_read_value(data, LM78_REG_IN_MIN(i)); |
771 | data->in_max[i] = | 771 | data->in_max[i] = |
772 | lm78_read_value(client, LM78_REG_IN_MAX(i)); | 772 | lm78_read_value(data, LM78_REG_IN_MAX(i)); |
773 | } | 773 | } |
774 | for (i = 0; i < 3; i++) { | 774 | for (i = 0; i < 3; i++) { |
775 | data->fan[i] = | 775 | data->fan[i] = |
776 | lm78_read_value(client, LM78_REG_FAN(i)); | 776 | lm78_read_value(data, LM78_REG_FAN(i)); |
777 | data->fan_min[i] = | 777 | data->fan_min[i] = |
778 | lm78_read_value(client, LM78_REG_FAN_MIN(i)); | 778 | lm78_read_value(data, LM78_REG_FAN_MIN(i)); |
779 | } | 779 | } |
780 | data->temp = lm78_read_value(client, LM78_REG_TEMP); | 780 | data->temp = lm78_read_value(data, LM78_REG_TEMP); |
781 | data->temp_over = | 781 | data->temp_over = |
782 | lm78_read_value(client, LM78_REG_TEMP_OVER); | 782 | lm78_read_value(data, LM78_REG_TEMP_OVER); |
783 | data->temp_hyst = | 783 | data->temp_hyst = |
784 | lm78_read_value(client, LM78_REG_TEMP_HYST); | 784 | lm78_read_value(data, LM78_REG_TEMP_HYST); |
785 | i = lm78_read_value(client, LM78_REG_VID_FANDIV); | 785 | i = lm78_read_value(data, LM78_REG_VID_FANDIV); |
786 | data->vid = i & 0x0f; | 786 | data->vid = i & 0x0f; |
787 | if (data->type == lm79) | 787 | if (data->type == lm79) |
788 | data->vid |= | 788 | data->vid |= |
789 | (lm78_read_value(client, LM78_REG_CHIPID) & | 789 | (lm78_read_value(data, LM78_REG_CHIPID) & |
790 | 0x01) << 4; | 790 | 0x01) << 4; |
791 | else | 791 | else |
792 | data->vid |= 0x10; | 792 | data->vid |= 0x10; |
793 | data->fan_div[0] = (i >> 4) & 0x03; | 793 | data->fan_div[0] = (i >> 4) & 0x03; |
794 | data->fan_div[1] = i >> 6; | 794 | data->fan_div[1] = i >> 6; |
795 | data->alarms = lm78_read_value(client, LM78_REG_ALARM1) + | 795 | data->alarms = lm78_read_value(data, LM78_REG_ALARM1) + |
796 | (lm78_read_value(client, LM78_REG_ALARM2) << 8); | 796 | (lm78_read_value(data, LM78_REG_ALARM2) << 8); |
797 | data->last_updated = jiffies; | 797 | data->last_updated = jiffies; |
798 | data->valid = 1; | 798 | data->valid = 1; |
799 | 799 | ||
@@ -805,26 +805,154 @@ static struct lm78_data *lm78_update_device(struct device *dev) | |||
805 | return data; | 805 | return data; |
806 | } | 806 | } |
807 | 807 | ||
808 | /* return 1 if a supported chip is found, 0 otherwise */ | ||
809 | static int __init lm78_isa_found(unsigned short address) | ||
810 | { | ||
811 | int val, save, found = 0; | ||
812 | |||
813 | if (!request_region(address, LM78_EXTENT, "lm78")) | ||
814 | return 0; | ||
815 | |||
816 | #define REALLY_SLOW_IO | ||
817 | /* We need the timeouts for at least some LM78-like | ||
818 | chips. But only if we read 'undefined' registers. */ | ||
819 | val = inb_p(address + 1); | ||
820 | if (inb_p(address + 2) != val | ||
821 | || inb_p(address + 3) != val | ||
822 | || inb_p(address + 7) != val) | ||
823 | goto release; | ||
824 | #undef REALLY_SLOW_IO | ||
825 | |||
826 | /* We should be able to change the 7 LSB of the address port. The | ||
827 | MSB (busy flag) should be clear initially, set after the write. */ | ||
828 | save = inb_p(address + LM78_ADDR_REG_OFFSET); | ||
829 | if (save & 0x80) | ||
830 | goto release; | ||
831 | val = ~save & 0x7f; | ||
832 | outb_p(val, address + LM78_ADDR_REG_OFFSET); | ||
833 | if (inb_p(address + LM78_ADDR_REG_OFFSET) != (val | 0x80)) { | ||
834 | outb_p(save, address + LM78_ADDR_REG_OFFSET); | ||
835 | goto release; | ||
836 | } | ||
837 | |||
838 | /* We found a device, now see if it could be an LM78 */ | ||
839 | outb_p(LM78_REG_CONFIG, address + LM78_ADDR_REG_OFFSET); | ||
840 | val = inb_p(address + LM78_DATA_REG_OFFSET); | ||
841 | if (val & 0x80) | ||
842 | goto release; | ||
843 | outb_p(LM78_REG_I2C_ADDR, address + LM78_ADDR_REG_OFFSET); | ||
844 | val = inb_p(address + LM78_DATA_REG_OFFSET); | ||
845 | if (val < 0x03 || val > 0x77) /* Not a valid I2C address */ | ||
846 | goto release; | ||
847 | |||
848 | /* The busy flag should be clear again */ | ||
849 | if (inb_p(address + LM78_ADDR_REG_OFFSET) & 0x80) | ||
850 | goto release; | ||
851 | |||
852 | /* Explicitly prevent the misdetection of Winbond chips */ | ||
853 | outb_p(0x4f, address + LM78_ADDR_REG_OFFSET); | ||
854 | val = inb_p(address + LM78_DATA_REG_OFFSET); | ||
855 | if (val == 0xa3 || val == 0x5c) | ||
856 | goto release; | ||
857 | |||
858 | /* Explicitly prevent the misdetection of ITE chips */ | ||
859 | outb_p(0x58, address + LM78_ADDR_REG_OFFSET); | ||
860 | val = inb_p(address + LM78_DATA_REG_OFFSET); | ||
861 | if (val == 0x90) | ||
862 | goto release; | ||
863 | |||
864 | /* Determine the chip type */ | ||
865 | outb_p(LM78_REG_CHIPID, address + LM78_ADDR_REG_OFFSET); | ||
866 | val = inb_p(address + LM78_DATA_REG_OFFSET); | ||
867 | if (val == 0x00 /* LM78 */ | ||
868 | || val == 0x40 /* LM78-J */ | ||
869 | || (val & 0xfe) == 0xc0) /* LM79 */ | ||
870 | found = 1; | ||
871 | |||
872 | if (found) | ||
873 | pr_info("lm78: Found an %s chip at %#x\n", | ||
874 | val & 0x80 ? "LM79" : "LM78", (int)address); | ||
875 | |||
876 | release: | ||
877 | release_region(address, LM78_EXTENT); | ||
878 | return found; | ||
879 | } | ||
880 | |||
881 | static int __init lm78_isa_device_add(unsigned short address) | ||
882 | { | ||
883 | struct resource res = { | ||
884 | .start = address, | ||
885 | .end = address + LM78_EXTENT, | ||
886 | .name = "lm78", | ||
887 | .flags = IORESOURCE_IO, | ||
888 | }; | ||
889 | int err; | ||
890 | |||
891 | pdev = platform_device_alloc("lm78", address); | ||
892 | if (!pdev) { | ||
893 | err = -ENOMEM; | ||
894 | printk(KERN_ERR "lm78: Device allocation failed\n"); | ||
895 | goto exit; | ||
896 | } | ||
897 | |||
898 | err = platform_device_add_resources(pdev, &res, 1); | ||
899 | if (err) { | ||
900 | printk(KERN_ERR "lm78: Device resource addition failed " | ||
901 | "(%d)\n", err); | ||
902 | goto exit_device_put; | ||
903 | } | ||
904 | |||
905 | err = platform_device_add(pdev); | ||
906 | if (err) { | ||
907 | printk(KERN_ERR "lm78: Device addition failed (%d)\n", | ||
908 | err); | ||
909 | goto exit_device_put; | ||
910 | } | ||
911 | |||
912 | return 0; | ||
913 | |||
914 | exit_device_put: | ||
915 | platform_device_put(pdev); | ||
916 | exit: | ||
917 | pdev = NULL; | ||
918 | return err; | ||
919 | } | ||
920 | |||
808 | static int __init sm_lm78_init(void) | 921 | static int __init sm_lm78_init(void) |
809 | { | 922 | { |
810 | int res; | 923 | int res; |
811 | 924 | ||
812 | res = i2c_add_driver(&lm78_driver); | 925 | res = i2c_add_driver(&lm78_driver); |
813 | if (res) | 926 | if (res) |
814 | return res; | 927 | goto exit; |
815 | 928 | ||
816 | /* Don't exit if this one fails, we still want the I2C variants | 929 | if (lm78_isa_found(isa_address)) { |
817 | to work! */ | 930 | res = platform_driver_register(&lm78_isa_driver); |
818 | if (i2c_isa_add_driver(&lm78_isa_driver)) | 931 | if (res) |
819 | isa_address = 0; | 932 | goto exit_unreg_i2c_driver; |
933 | |||
934 | /* Sets global pdev as a side effect */ | ||
935 | res = lm78_isa_device_add(isa_address); | ||
936 | if (res) | ||
937 | goto exit_unreg_isa_driver; | ||
938 | } | ||
820 | 939 | ||
821 | return 0; | 940 | return 0; |
941 | |||
942 | exit_unreg_isa_driver: | ||
943 | platform_driver_unregister(&lm78_isa_driver); | ||
944 | exit_unreg_i2c_driver: | ||
945 | i2c_del_driver(&lm78_driver); | ||
946 | exit: | ||
947 | return res; | ||
822 | } | 948 | } |
823 | 949 | ||
824 | static void __exit sm_lm78_exit(void) | 950 | static void __exit sm_lm78_exit(void) |
825 | { | 951 | { |
826 | if (isa_address) | 952 | if (pdev) { |
827 | i2c_isa_del_driver(&lm78_isa_driver); | 953 | platform_device_unregister(pdev); |
954 | platform_driver_unregister(&lm78_isa_driver); | ||
955 | } | ||
828 | i2c_del_driver(&lm78_driver); | 956 | i2c_del_driver(&lm78_driver); |
829 | } | 957 | } |
830 | 958 | ||