diff options
Diffstat (limited to 'drivers/hwmon/pc87360.c')
-rw-r--r-- | drivers/hwmon/pc87360.c | 602 |
1 files changed, 362 insertions, 240 deletions
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c index 3d99b8854d7c..79ba48c8c116 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c | |||
@@ -56,11 +56,11 @@ static u8 confreg[4]; | |||
56 | static int init = 1; | 56 | static int init = 1; |
57 | module_param(init, int, 0); | 57 | module_param(init, int, 0); |
58 | MODULE_PARM_DESC(init, | 58 | MODULE_PARM_DESC(init, |
59 | "Chip initialization level:\n" | 59 | "Chip initialization level:\n" |
60 | " 0: None\n" | 60 | " 0: None\n" |
61 | "*1: Forcibly enable internal voltage and temperature channels, except in9\n" | 61 | "*1: Forcibly enable internal voltage and temperature channels, except in9\n" |
62 | " 2: Forcibly enable all voltage and temperature channels, except in9\n" | 62 | " 2: Forcibly enable all voltage and temperature channels, except in9\n" |
63 | " 3: Forcibly enable all voltage and temperature channels, including in9"); | 63 | " 3: Forcibly enable all voltage and temperature channels, including in9"); |
64 | 64 | ||
65 | static unsigned short force_id; | 65 | static unsigned short force_id; |
66 | module_param(force_id, ushort, 0); | 66 | module_param(force_id, ushort, 0); |
@@ -88,19 +88,19 @@ static const u8 logdev[LDNI_MAX] = { FSCM, VLM, TMS }; | |||
88 | static inline void superio_outb(int sioaddr, int reg, int val) | 88 | static inline void superio_outb(int sioaddr, int reg, int val) |
89 | { | 89 | { |
90 | outb(reg, sioaddr); | 90 | outb(reg, sioaddr); |
91 | outb(val, sioaddr+1); | 91 | outb(val, sioaddr + 1); |
92 | } | 92 | } |
93 | 93 | ||
94 | static inline int superio_inb(int sioaddr, int reg) | 94 | static inline int superio_inb(int sioaddr, int reg) |
95 | { | 95 | { |
96 | outb(reg, sioaddr); | 96 | outb(reg, sioaddr); |
97 | return inb(sioaddr+1); | 97 | return inb(sioaddr + 1); |
98 | } | 98 | } |
99 | 99 | ||
100 | static inline void superio_exit(int sioaddr) | 100 | static inline void superio_exit(int sioaddr) |
101 | { | 101 | { |
102 | outb(0x02, sioaddr); | 102 | outb(0x02, sioaddr); |
103 | outb(0x02, sioaddr+1); | 103 | outb(0x02, sioaddr + 1); |
104 | } | 104 | } |
105 | 105 | ||
106 | /* | 106 | /* |
@@ -122,18 +122,18 @@ static inline void superio_exit(int sioaddr) | |||
122 | #define PC87360_REG_FAN(nr) (0x07 + 3 * (nr)) | 122 | #define PC87360_REG_FAN(nr) (0x07 + 3 * (nr)) |
123 | #define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr)) | 123 | #define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr)) |
124 | 124 | ||
125 | #define FAN_FROM_REG(val,div) ((val) == 0 ? 0: \ | 125 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : \ |
126 | 480000 / ((val)*(div))) | 126 | 480000 / ((val) * (div))) |
127 | #define FAN_TO_REG(val,div) ((val) <= 100 ? 0 : \ | 127 | #define FAN_TO_REG(val, div) ((val) <= 100 ? 0 : \ |
128 | 480000 / ((val)*(div))) | 128 | 480000 / ((val) * (div))) |
129 | #define FAN_DIV_FROM_REG(val) (1 << ((val >> 5) & 0x03)) | 129 | #define FAN_DIV_FROM_REG(val) (1 << (((val) >> 5) & 0x03)) |
130 | #define FAN_STATUS_FROM_REG(val) ((val) & 0x07) | 130 | #define FAN_STATUS_FROM_REG(val) ((val) & 0x07) |
131 | 131 | ||
132 | #define FAN_CONFIG_MONITOR(val,nr) (((val) >> (2 + nr * 3)) & 1) | 132 | #define FAN_CONFIG_MONITOR(val, nr) (((val) >> (2 + (nr) * 3)) & 1) |
133 | #define FAN_CONFIG_CONTROL(val,nr) (((val) >> (3 + nr * 3)) & 1) | 133 | #define FAN_CONFIG_CONTROL(val, nr) (((val) >> (3 + (nr) * 3)) & 1) |
134 | #define FAN_CONFIG_INVERT(val,nr) (((val) >> (4 + nr * 3)) & 1) | 134 | #define FAN_CONFIG_INVERT(val, nr) (((val) >> (4 + (nr) * 3)) & 1) |
135 | 135 | ||
136 | #define PWM_FROM_REG(val,inv) ((inv) ? 255 - (val) : (val)) | 136 | #define PWM_FROM_REG(val, inv) ((inv) ? 255 - (val) : (val)) |
137 | static inline u8 PWM_TO_REG(int val, int inv) | 137 | static inline u8 PWM_TO_REG(int val, int inv) |
138 | { | 138 | { |
139 | if (inv) | 139 | if (inv) |
@@ -159,10 +159,10 @@ static inline u8 PWM_TO_REG(int val, int inv) | |||
159 | #define PC87365_REG_IN_ALARMS2 0x01 | 159 | #define PC87365_REG_IN_ALARMS2 0x01 |
160 | #define PC87365_REG_VID 0x06 | 160 | #define PC87365_REG_VID 0x06 |
161 | 161 | ||
162 | #define IN_FROM_REG(val,ref) (((val) * (ref) + 128) / 256) | 162 | #define IN_FROM_REG(val, ref) (((val) * (ref) + 128) / 256) |
163 | #define IN_TO_REG(val,ref) ((val) < 0 ? 0 : \ | 163 | #define IN_TO_REG(val, ref) ((val) < 0 ? 0 : \ |
164 | (val)*256 >= (ref)*255 ? 255: \ | 164 | (val) * 256 >= (ref) * 255 ? 255 : \ |
165 | ((val) * 256 + (ref)/2) / (ref)) | 165 | ((val) * 256 + (ref) / 2) / (ref)) |
166 | 166 | ||
167 | /* | 167 | /* |
168 | * Temperature registers and conversions | 168 | * Temperature registers and conversions |
@@ -255,43 +255,54 @@ static struct platform_driver pc87360_driver = { | |||
255 | * Sysfs stuff | 255 | * Sysfs stuff |
256 | */ | 256 | */ |
257 | 257 | ||
258 | static ssize_t show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf) | 258 | static ssize_t show_fan_input(struct device *dev, |
259 | struct device_attribute *devattr, char *buf) | ||
259 | { | 260 | { |
260 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 261 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
261 | struct pc87360_data *data = pc87360_update_device(dev); | 262 | struct pc87360_data *data = pc87360_update_device(dev); |
262 | return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index], | 263 | return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index], |
263 | FAN_DIV_FROM_REG(data->fan_status[attr->index]))); | 264 | FAN_DIV_FROM_REG(data->fan_status[attr->index]))); |
264 | } | 265 | } |
265 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf) | 266 | static ssize_t show_fan_min(struct device *dev, |
267 | struct device_attribute *devattr, char *buf) | ||
266 | { | 268 | { |
267 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 269 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
268 | struct pc87360_data *data = pc87360_update_device(dev); | 270 | struct pc87360_data *data = pc87360_update_device(dev); |
269 | return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index], | 271 | return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index], |
270 | FAN_DIV_FROM_REG(data->fan_status[attr->index]))); | 272 | FAN_DIV_FROM_REG(data->fan_status[attr->index]))); |
271 | } | 273 | } |
272 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) | 274 | static ssize_t show_fan_div(struct device *dev, |
275 | struct device_attribute *devattr, char *buf) | ||
273 | { | 276 | { |
274 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 277 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
275 | struct pc87360_data *data = pc87360_update_device(dev); | 278 | struct pc87360_data *data = pc87360_update_device(dev); |
276 | return sprintf(buf, "%u\n", | 279 | return sprintf(buf, "%u\n", |
277 | FAN_DIV_FROM_REG(data->fan_status[attr->index])); | 280 | FAN_DIV_FROM_REG(data->fan_status[attr->index])); |
278 | } | 281 | } |
279 | static ssize_t show_fan_status(struct device *dev, struct device_attribute *devattr, char *buf) | 282 | static ssize_t show_fan_status(struct device *dev, |
283 | struct device_attribute *devattr, char *buf) | ||
280 | { | 284 | { |
281 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 285 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
282 | struct pc87360_data *data = pc87360_update_device(dev); | 286 | struct pc87360_data *data = pc87360_update_device(dev); |
283 | return sprintf(buf, "%u\n", | 287 | return sprintf(buf, "%u\n", |
284 | FAN_STATUS_FROM_REG(data->fan_status[attr->index])); | 288 | FAN_STATUS_FROM_REG(data->fan_status[attr->index])); |
285 | } | 289 | } |
286 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, | 290 | static ssize_t set_fan_min(struct device *dev, |
291 | struct device_attribute *devattr, const char *buf, | ||
287 | size_t count) | 292 | size_t count) |
288 | { | 293 | { |
289 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 294 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
290 | struct pc87360_data *data = dev_get_drvdata(dev); | 295 | struct pc87360_data *data = dev_get_drvdata(dev); |
291 | long fan_min = simple_strtol(buf, NULL, 10); | 296 | long fan_min; |
297 | int err; | ||
298 | |||
299 | err = kstrtol(buf, 10, &fan_min); | ||
300 | if (err) | ||
301 | return err; | ||
292 | 302 | ||
293 | mutex_lock(&data->update_lock); | 303 | mutex_lock(&data->update_lock); |
294 | fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index])); | 304 | fan_min = FAN_TO_REG(fan_min, |
305 | FAN_DIV_FROM_REG(data->fan_status[attr->index])); | ||
295 | 306 | ||
296 | /* If it wouldn't fit, change clock divisor */ | 307 | /* If it wouldn't fit, change clock divisor */ |
297 | while (fan_min > 255 | 308 | while (fan_min > 255 |
@@ -301,11 +312,13 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, | |||
301 | data->fan_status[attr->index] += 0x20; | 312 | data->fan_status[attr->index] += 0x20; |
302 | } | 313 | } |
303 | data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min; | 314 | data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min; |
304 | pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(attr->index), | 315 | pc87360_write_value(data, LD_FAN, NO_BANK, |
316 | PC87360_REG_FAN_MIN(attr->index), | ||
305 | data->fan_min[attr->index]); | 317 | data->fan_min[attr->index]); |
306 | 318 | ||
307 | /* Write new divider, preserve alarm bits */ | 319 | /* Write new divider, preserve alarm bits */ |
308 | pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index), | 320 | pc87360_write_value(data, LD_FAN, NO_BANK, |
321 | PC87360_REG_FAN_STATUS(attr->index), | ||
309 | data->fan_status[attr->index] & 0xF9); | 322 | data->fan_status[attr->index] & 0xF9); |
310 | mutex_unlock(&data->update_lock); | 323 | mutex_unlock(&data->update_lock); |
311 | 324 | ||
@@ -333,13 +346,16 @@ static struct sensor_device_attribute fan_min[] = { | |||
333 | SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2), | 346 | SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2), |
334 | }; | 347 | }; |
335 | 348 | ||
336 | #define FAN_UNIT_ATTRS(X) \ | 349 | #define FAN_UNIT_ATTRS(X) \ |
337 | &fan_input[X].dev_attr.attr, \ | 350 | { &fan_input[X].dev_attr.attr, \ |
338 | &fan_status[X].dev_attr.attr, \ | 351 | &fan_status[X].dev_attr.attr, \ |
339 | &fan_div[X].dev_attr.attr, \ | 352 | &fan_div[X].dev_attr.attr, \ |
340 | &fan_min[X].dev_attr.attr | 353 | &fan_min[X].dev_attr.attr, \ |
354 | NULL \ | ||
355 | } | ||
341 | 356 | ||
342 | static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) | 357 | static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, |
358 | char *buf) | ||
343 | { | 359 | { |
344 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 360 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
345 | struct pc87360_data *data = pc87360_update_device(dev); | 361 | struct pc87360_data *data = pc87360_update_device(dev); |
@@ -348,12 +364,17 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, ch | |||
348 | FAN_CONFIG_INVERT(data->fan_conf, | 364 | FAN_CONFIG_INVERT(data->fan_conf, |
349 | attr->index))); | 365 | attr->index))); |
350 | } | 366 | } |
351 | static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf, | 367 | static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, |
352 | size_t count) | 368 | const char *buf, size_t count) |
353 | { | 369 | { |
354 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 370 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
355 | struct pc87360_data *data = dev_get_drvdata(dev); | 371 | struct pc87360_data *data = dev_get_drvdata(dev); |
356 | long val = simple_strtol(buf, NULL, 10); | 372 | long val; |
373 | int err; | ||
374 | |||
375 | err = kstrtol(buf, 10, &val); | ||
376 | if (err) | ||
377 | return err; | ||
357 | 378 | ||
358 | mutex_lock(&data->update_lock); | 379 | mutex_lock(&data->update_lock); |
359 | data->pwm[attr->index] = PWM_TO_REG(val, | 380 | data->pwm[attr->index] = PWM_TO_REG(val, |
@@ -370,52 +391,60 @@ static struct sensor_device_attribute pwm[] = { | |||
370 | SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2), | 391 | SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2), |
371 | }; | 392 | }; |
372 | 393 | ||
373 | static struct attribute * pc8736x_fan_attr_array[] = { | 394 | static struct attribute *pc8736x_fan_attr[][5] = { |
374 | FAN_UNIT_ATTRS(0), | 395 | FAN_UNIT_ATTRS(0), |
375 | FAN_UNIT_ATTRS(1), | 396 | FAN_UNIT_ATTRS(1), |
376 | FAN_UNIT_ATTRS(2), | 397 | FAN_UNIT_ATTRS(2) |
377 | &pwm[0].dev_attr.attr, | ||
378 | &pwm[1].dev_attr.attr, | ||
379 | &pwm[2].dev_attr.attr, | ||
380 | NULL | ||
381 | }; | 398 | }; |
382 | static const struct attribute_group pc8736x_fan_group = { | 399 | |
383 | .attrs = pc8736x_fan_attr_array, | 400 | static const struct attribute_group pc8736x_fan_attr_group[] = { |
401 | { .attrs = pc8736x_fan_attr[0], }, | ||
402 | { .attrs = pc8736x_fan_attr[1], }, | ||
403 | { .attrs = pc8736x_fan_attr[2], }, | ||
384 | }; | 404 | }; |
385 | 405 | ||
386 | static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf) | 406 | static ssize_t show_in_input(struct device *dev, |
407 | struct device_attribute *devattr, char *buf) | ||
387 | { | 408 | { |
388 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 409 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
389 | struct pc87360_data *data = pc87360_update_device(dev); | 410 | struct pc87360_data *data = pc87360_update_device(dev); |
390 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], | 411 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], |
391 | data->in_vref)); | 412 | data->in_vref)); |
392 | } | 413 | } |
393 | static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf) | 414 | static ssize_t show_in_min(struct device *dev, |
415 | struct device_attribute *devattr, char *buf) | ||
394 | { | 416 | { |
395 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 417 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
396 | struct pc87360_data *data = pc87360_update_device(dev); | 418 | struct pc87360_data *data = pc87360_update_device(dev); |
397 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], | 419 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], |
398 | data->in_vref)); | 420 | data->in_vref)); |
399 | } | 421 | } |
400 | static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf) | 422 | static ssize_t show_in_max(struct device *dev, |
423 | struct device_attribute *devattr, char *buf) | ||
401 | { | 424 | { |
402 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 425 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
403 | struct pc87360_data *data = pc87360_update_device(dev); | 426 | struct pc87360_data *data = pc87360_update_device(dev); |
404 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], | 427 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], |
405 | data->in_vref)); | 428 | data->in_vref)); |
406 | } | 429 | } |
407 | static ssize_t show_in_status(struct device *dev, struct device_attribute *devattr, char *buf) | 430 | static ssize_t show_in_status(struct device *dev, |
431 | struct device_attribute *devattr, char *buf) | ||
408 | { | 432 | { |
409 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 433 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
410 | struct pc87360_data *data = pc87360_update_device(dev); | 434 | struct pc87360_data *data = pc87360_update_device(dev); |
411 | return sprintf(buf, "%u\n", data->in_status[attr->index]); | 435 | return sprintf(buf, "%u\n", data->in_status[attr->index]); |
412 | } | 436 | } |
413 | static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf, | 437 | static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, |
414 | size_t count) | 438 | const char *buf, size_t count) |
415 | { | 439 | { |
416 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 440 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
417 | struct pc87360_data *data = dev_get_drvdata(dev); | 441 | struct pc87360_data *data = dev_get_drvdata(dev); |
418 | long val = simple_strtol(buf, NULL, 10); | 442 | long val; |
443 | int err; | ||
444 | |||
445 | err = kstrtol(buf, 10, &val); | ||
446 | if (err) | ||
447 | return err; | ||
419 | 448 | ||
420 | mutex_lock(&data->update_lock); | 449 | mutex_lock(&data->update_lock); |
421 | data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); | 450 | data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); |
@@ -424,12 +453,17 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, | |||
424 | mutex_unlock(&data->update_lock); | 453 | mutex_unlock(&data->update_lock); |
425 | return count; | 454 | return count; |
426 | } | 455 | } |
427 | static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, | 456 | static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, |
428 | size_t count) | 457 | const char *buf, size_t count) |
429 | { | 458 | { |
430 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 459 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
431 | struct pc87360_data *data = dev_get_drvdata(dev); | 460 | struct pc87360_data *data = dev_get_drvdata(dev); |
432 | long val = simple_strtol(buf, NULL, 10); | 461 | long val; |
462 | int err; | ||
463 | |||
464 | err = kstrtol(buf, 10, &val); | ||
465 | if (err) | ||
466 | return err; | ||
433 | 467 | ||
434 | mutex_lock(&data->update_lock); | 468 | mutex_lock(&data->update_lock); |
435 | data->in_max[attr->index] = IN_TO_REG(val, | 469 | data->in_max[attr->index] = IN_TO_REG(val, |
@@ -498,9 +532,11 @@ static struct sensor_device_attribute in_max[] = { | |||
498 | #define CHAN_ALM_MAX 0x04 /* max limit exceeded */ | 532 | #define CHAN_ALM_MAX 0x04 /* max limit exceeded */ |
499 | #define TEMP_ALM_CRIT 0x08 /* temp crit exceeded (temp only) */ | 533 | #define TEMP_ALM_CRIT 0x08 /* temp crit exceeded (temp only) */ |
500 | 534 | ||
501 | /* show_in_min/max_alarm() reads data from the per-channel status | 535 | /* |
502 | register (sec 11.5.12), not the vin event status registers (sec | 536 | * show_in_min/max_alarm() reads data from the per-channel status |
503 | 11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms) */ | 537 | * register (sec 11.5.12), not the vin event status registers (sec |
538 | * 11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms) | ||
539 | */ | ||
504 | 540 | ||
505 | static ssize_t show_in_min_alarm(struct device *dev, | 541 | static ssize_t show_in_min_alarm(struct device *dev, |
506 | struct device_attribute *devattr, char *buf) | 542 | struct device_attribute *devattr, char *buf) |
@@ -554,27 +590,38 @@ static struct sensor_device_attribute in_max_alarm[] = { | |||
554 | &in_min_alarm[X].dev_attr.attr, \ | 590 | &in_min_alarm[X].dev_attr.attr, \ |
555 | &in_max_alarm[X].dev_attr.attr | 591 | &in_max_alarm[X].dev_attr.attr |
556 | 592 | ||
557 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) | 593 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, |
594 | char *buf) | ||
558 | { | 595 | { |
559 | struct pc87360_data *data = pc87360_update_device(dev); | 596 | struct pc87360_data *data = pc87360_update_device(dev); |
560 | return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); | 597 | return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); |
561 | } | 598 | } |
562 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); | 599 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); |
563 | 600 | ||
564 | static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) | 601 | static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, |
602 | char *buf) | ||
565 | { | 603 | { |
566 | struct pc87360_data *data = dev_get_drvdata(dev); | 604 | struct pc87360_data *data = dev_get_drvdata(dev); |
567 | return sprintf(buf, "%u\n", data->vrm); | 605 | return sprintf(buf, "%u\n", data->vrm); |
568 | } | 606 | } |
569 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 607 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, |
608 | const char *buf, size_t count) | ||
570 | { | 609 | { |
571 | struct pc87360_data *data = dev_get_drvdata(dev); | 610 | struct pc87360_data *data = dev_get_drvdata(dev); |
572 | data->vrm = simple_strtoul(buf, NULL, 10); | 611 | unsigned long val; |
612 | int err; | ||
613 | |||
614 | err = kstrtoul(buf, 10, &val); | ||
615 | if (err) | ||
616 | return err; | ||
617 | |||
618 | data->vrm = val; | ||
573 | return count; | 619 | return count; |
574 | } | 620 | } |
575 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); | 621 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); |
576 | 622 | ||
577 | static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 623 | static ssize_t show_in_alarms(struct device *dev, |
624 | struct device_attribute *attr, char *buf) | ||
578 | { | 625 | { |
579 | struct pc87360_data *data = pc87360_update_device(dev); | 626 | struct pc87360_data *data = pc87360_update_device(dev); |
580 | return sprintf(buf, "%u\n", data->in_alarms); | 627 | return sprintf(buf, "%u\n", data->in_alarms); |
@@ -602,46 +649,58 @@ static const struct attribute_group pc8736x_vin_group = { | |||
602 | .attrs = pc8736x_vin_attr_array, | 649 | .attrs = pc8736x_vin_attr_array, |
603 | }; | 650 | }; |
604 | 651 | ||
605 | static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf) | 652 | static ssize_t show_therm_input(struct device *dev, |
653 | struct device_attribute *devattr, char *buf) | ||
606 | { | 654 | { |
607 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 655 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
608 | struct pc87360_data *data = pc87360_update_device(dev); | 656 | struct pc87360_data *data = pc87360_update_device(dev); |
609 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], | 657 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], |
610 | data->in_vref)); | 658 | data->in_vref)); |
611 | } | 659 | } |
612 | static ssize_t show_therm_min(struct device *dev, struct device_attribute *devattr, char *buf) | 660 | static ssize_t show_therm_min(struct device *dev, |
661 | struct device_attribute *devattr, char *buf) | ||
613 | { | 662 | { |
614 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 663 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
615 | struct pc87360_data *data = pc87360_update_device(dev); | 664 | struct pc87360_data *data = pc87360_update_device(dev); |
616 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], | 665 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], |
617 | data->in_vref)); | 666 | data->in_vref)); |
618 | } | 667 | } |
619 | static ssize_t show_therm_max(struct device *dev, struct device_attribute *devattr, char *buf) | 668 | static ssize_t show_therm_max(struct device *dev, |
669 | struct device_attribute *devattr, char *buf) | ||
620 | { | 670 | { |
621 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 671 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
622 | struct pc87360_data *data = pc87360_update_device(dev); | 672 | struct pc87360_data *data = pc87360_update_device(dev); |
623 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], | 673 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], |
624 | data->in_vref)); | 674 | data->in_vref)); |
625 | } | 675 | } |
626 | static ssize_t show_therm_crit(struct device *dev, struct device_attribute *devattr, char *buf) | 676 | static ssize_t show_therm_crit(struct device *dev, |
677 | struct device_attribute *devattr, char *buf) | ||
627 | { | 678 | { |
628 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 679 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
629 | struct pc87360_data *data = pc87360_update_device(dev); | 680 | struct pc87360_data *data = pc87360_update_device(dev); |
630 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11], | 681 | return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11], |
631 | data->in_vref)); | 682 | data->in_vref)); |
632 | } | 683 | } |
633 | static ssize_t show_therm_status(struct device *dev, struct device_attribute *devattr, char *buf) | 684 | static ssize_t show_therm_status(struct device *dev, |
685 | struct device_attribute *devattr, char *buf) | ||
634 | { | 686 | { |
635 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 687 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
636 | struct pc87360_data *data = pc87360_update_device(dev); | 688 | struct pc87360_data *data = pc87360_update_device(dev); |
637 | return sprintf(buf, "%u\n", data->in_status[attr->index]); | 689 | return sprintf(buf, "%u\n", data->in_status[attr->index]); |
638 | } | 690 | } |
639 | static ssize_t set_therm_min(struct device *dev, struct device_attribute *devattr, const char *buf, | 691 | |
640 | size_t count) | 692 | static ssize_t set_therm_min(struct device *dev, |
693 | struct device_attribute *devattr, | ||
694 | const char *buf, size_t count) | ||
641 | { | 695 | { |
642 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 696 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
643 | struct pc87360_data *data = dev_get_drvdata(dev); | 697 | struct pc87360_data *data = dev_get_drvdata(dev); |
644 | long val = simple_strtol(buf, NULL, 10); | 698 | long val; |
699 | int err; | ||
700 | |||
701 | err = kstrtol(buf, 10, &val); | ||
702 | if (err) | ||
703 | return err; | ||
645 | 704 | ||
646 | mutex_lock(&data->update_lock); | 705 | mutex_lock(&data->update_lock); |
647 | data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); | 706 | data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); |
@@ -650,12 +709,19 @@ static ssize_t set_therm_min(struct device *dev, struct device_attribute *devatt | |||
650 | mutex_unlock(&data->update_lock); | 709 | mutex_unlock(&data->update_lock); |
651 | return count; | 710 | return count; |
652 | } | 711 | } |
653 | static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf, | 712 | |
654 | size_t count) | 713 | static ssize_t set_therm_max(struct device *dev, |
714 | struct device_attribute *devattr, | ||
715 | const char *buf, size_t count) | ||
655 | { | 716 | { |
656 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 717 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
657 | struct pc87360_data *data = dev_get_drvdata(dev); | 718 | struct pc87360_data *data = dev_get_drvdata(dev); |
658 | long val = simple_strtol(buf, NULL, 10); | 719 | long val; |
720 | int err; | ||
721 | |||
722 | err = kstrtol(buf, 10, &val); | ||
723 | if (err) | ||
724 | return err; | ||
659 | 725 | ||
660 | mutex_lock(&data->update_lock); | 726 | mutex_lock(&data->update_lock); |
661 | data->in_max[attr->index] = IN_TO_REG(val, data->in_vref); | 727 | data->in_max[attr->index] = IN_TO_REG(val, data->in_vref); |
@@ -664,12 +730,18 @@ static ssize_t set_therm_max(struct device *dev, struct device_attribute *devatt | |||
664 | mutex_unlock(&data->update_lock); | 730 | mutex_unlock(&data->update_lock); |
665 | return count; | 731 | return count; |
666 | } | 732 | } |
667 | static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf, | 733 | static ssize_t set_therm_crit(struct device *dev, |
668 | size_t count) | 734 | struct device_attribute *devattr, |
735 | const char *buf, size_t count) | ||
669 | { | 736 | { |
670 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 737 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
671 | struct pc87360_data *data = dev_get_drvdata(dev); | 738 | struct pc87360_data *data = dev_get_drvdata(dev); |
672 | long val = simple_strtol(buf, NULL, 10); | 739 | long val; |
740 | int err; | ||
741 | |||
742 | err = kstrtol(buf, 10, &val); | ||
743 | if (err) | ||
744 | return err; | ||
673 | 745 | ||
674 | mutex_lock(&data->update_lock); | 746 | mutex_lock(&data->update_lock); |
675 | data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref); | 747 | data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref); |
@@ -679,46 +751,49 @@ static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devat | |||
679 | return count; | 751 | return count; |
680 | } | 752 | } |
681 | 753 | ||
682 | /* the +11 term below reflects the fact that VLM units 11,12,13 are | 754 | /* |
683 | used in the chip to measure voltage across the thermistors | 755 | * the +11 term below reflects the fact that VLM units 11,12,13 are |
684 | */ | 756 | * used in the chip to measure voltage across the thermistors |
757 | */ | ||
685 | static struct sensor_device_attribute therm_input[] = { | 758 | static struct sensor_device_attribute therm_input[] = { |
686 | SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0+11), | 759 | SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0 + 11), |
687 | SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1+11), | 760 | SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1 + 11), |
688 | SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2+11), | 761 | SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2 + 11), |
689 | }; | 762 | }; |
690 | static struct sensor_device_attribute therm_status[] = { | 763 | static struct sensor_device_attribute therm_status[] = { |
691 | SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0+11), | 764 | SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0 + 11), |
692 | SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1+11), | 765 | SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1 + 11), |
693 | SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2+11), | 766 | SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2 + 11), |
694 | }; | 767 | }; |
695 | static struct sensor_device_attribute therm_min[] = { | 768 | static struct sensor_device_attribute therm_min[] = { |
696 | SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR, | 769 | SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR, |
697 | show_therm_min, set_therm_min, 0+11), | 770 | show_therm_min, set_therm_min, 0 + 11), |
698 | SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR, | 771 | SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR, |
699 | show_therm_min, set_therm_min, 1+11), | 772 | show_therm_min, set_therm_min, 1 + 11), |
700 | SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR, | 773 | SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR, |
701 | show_therm_min, set_therm_min, 2+11), | 774 | show_therm_min, set_therm_min, 2 + 11), |
702 | }; | 775 | }; |
703 | static struct sensor_device_attribute therm_max[] = { | 776 | static struct sensor_device_attribute therm_max[] = { |
704 | SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR, | 777 | SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR, |
705 | show_therm_max, set_therm_max, 0+11), | 778 | show_therm_max, set_therm_max, 0 + 11), |
706 | SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR, | 779 | SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR, |
707 | show_therm_max, set_therm_max, 1+11), | 780 | show_therm_max, set_therm_max, 1 + 11), |
708 | SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR, | 781 | SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR, |
709 | show_therm_max, set_therm_max, 2+11), | 782 | show_therm_max, set_therm_max, 2 + 11), |
710 | }; | 783 | }; |
711 | static struct sensor_device_attribute therm_crit[] = { | 784 | static struct sensor_device_attribute therm_crit[] = { |
712 | SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR, | 785 | SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR, |
713 | show_therm_crit, set_therm_crit, 0+11), | 786 | show_therm_crit, set_therm_crit, 0 + 11), |
714 | SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR, | 787 | SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR, |
715 | show_therm_crit, set_therm_crit, 1+11), | 788 | show_therm_crit, set_therm_crit, 1 + 11), |
716 | SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR, | 789 | SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR, |
717 | show_therm_crit, set_therm_crit, 2+11), | 790 | show_therm_crit, set_therm_crit, 2 + 11), |
718 | }; | 791 | }; |
719 | 792 | ||
720 | /* show_therm_min/max_alarm() reads data from the per-channel voltage | 793 | /* |
721 | status register (sec 11.5.12) */ | 794 | * show_therm_min/max_alarm() reads data from the per-channel voltage |
795 | * status register (sec 11.5.12) | ||
796 | */ | ||
722 | 797 | ||
723 | static ssize_t show_therm_min_alarm(struct device *dev, | 798 | static ssize_t show_therm_min_alarm(struct device *dev, |
724 | struct device_attribute *devattr, char *buf) | 799 | struct device_attribute *devattr, char *buf) |
@@ -747,27 +822,27 @@ static ssize_t show_therm_crit_alarm(struct device *dev, | |||
747 | 822 | ||
748 | static struct sensor_device_attribute therm_min_alarm[] = { | 823 | static struct sensor_device_attribute therm_min_alarm[] = { |
749 | SENSOR_ATTR(temp4_min_alarm, S_IRUGO, | 824 | SENSOR_ATTR(temp4_min_alarm, S_IRUGO, |
750 | show_therm_min_alarm, NULL, 0+11), | 825 | show_therm_min_alarm, NULL, 0 + 11), |
751 | SENSOR_ATTR(temp5_min_alarm, S_IRUGO, | 826 | SENSOR_ATTR(temp5_min_alarm, S_IRUGO, |
752 | show_therm_min_alarm, NULL, 1+11), | 827 | show_therm_min_alarm, NULL, 1 + 11), |
753 | SENSOR_ATTR(temp6_min_alarm, S_IRUGO, | 828 | SENSOR_ATTR(temp6_min_alarm, S_IRUGO, |
754 | show_therm_min_alarm, NULL, 2+11), | 829 | show_therm_min_alarm, NULL, 2 + 11), |
755 | }; | 830 | }; |
756 | static struct sensor_device_attribute therm_max_alarm[] = { | 831 | static struct sensor_device_attribute therm_max_alarm[] = { |
757 | SENSOR_ATTR(temp4_max_alarm, S_IRUGO, | 832 | SENSOR_ATTR(temp4_max_alarm, S_IRUGO, |
758 | show_therm_max_alarm, NULL, 0+11), | 833 | show_therm_max_alarm, NULL, 0 + 11), |
759 | SENSOR_ATTR(temp5_max_alarm, S_IRUGO, | 834 | SENSOR_ATTR(temp5_max_alarm, S_IRUGO, |
760 | show_therm_max_alarm, NULL, 1+11), | 835 | show_therm_max_alarm, NULL, 1 + 11), |
761 | SENSOR_ATTR(temp6_max_alarm, S_IRUGO, | 836 | SENSOR_ATTR(temp6_max_alarm, S_IRUGO, |
762 | show_therm_max_alarm, NULL, 2+11), | 837 | show_therm_max_alarm, NULL, 2 + 11), |
763 | }; | 838 | }; |
764 | static struct sensor_device_attribute therm_crit_alarm[] = { | 839 | static struct sensor_device_attribute therm_crit_alarm[] = { |
765 | SENSOR_ATTR(temp4_crit_alarm, S_IRUGO, | 840 | SENSOR_ATTR(temp4_crit_alarm, S_IRUGO, |
766 | show_therm_crit_alarm, NULL, 0+11), | 841 | show_therm_crit_alarm, NULL, 0 + 11), |
767 | SENSOR_ATTR(temp5_crit_alarm, S_IRUGO, | 842 | SENSOR_ATTR(temp5_crit_alarm, S_IRUGO, |
768 | show_therm_crit_alarm, NULL, 1+11), | 843 | show_therm_crit_alarm, NULL, 1 + 11), |
769 | SENSOR_ATTR(temp6_crit_alarm, S_IRUGO, | 844 | SENSOR_ATTR(temp6_crit_alarm, S_IRUGO, |
770 | show_therm_crit_alarm, NULL, 2+11), | 845 | show_therm_crit_alarm, NULL, 2 + 11), |
771 | }; | 846 | }; |
772 | 847 | ||
773 | #define THERM_UNIT_ATTRS(X) \ | 848 | #define THERM_UNIT_ATTRS(X) \ |
@@ -780,7 +855,7 @@ static struct sensor_device_attribute therm_crit_alarm[] = { | |||
780 | &therm_max_alarm[X].dev_attr.attr, \ | 855 | &therm_max_alarm[X].dev_attr.attr, \ |
781 | &therm_crit_alarm[X].dev_attr.attr | 856 | &therm_crit_alarm[X].dev_attr.attr |
782 | 857 | ||
783 | static struct attribute * pc8736x_therm_attr_array[] = { | 858 | static struct attribute *pc8736x_therm_attr_array[] = { |
784 | THERM_UNIT_ATTRS(0), | 859 | THERM_UNIT_ATTRS(0), |
785 | THERM_UNIT_ATTRS(1), | 860 | THERM_UNIT_ATTRS(1), |
786 | THERM_UNIT_ATTRS(2), | 861 | THERM_UNIT_ATTRS(2), |
@@ -790,42 +865,59 @@ static const struct attribute_group pc8736x_therm_group = { | |||
790 | .attrs = pc8736x_therm_attr_array, | 865 | .attrs = pc8736x_therm_attr_array, |
791 | }; | 866 | }; |
792 | 867 | ||
793 | static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf) | 868 | static ssize_t show_temp_input(struct device *dev, |
869 | struct device_attribute *devattr, char *buf) | ||
794 | { | 870 | { |
795 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 871 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
796 | struct pc87360_data *data = pc87360_update_device(dev); | 872 | struct pc87360_data *data = pc87360_update_device(dev); |
797 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])); | 873 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])); |
798 | } | 874 | } |
799 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf) | 875 | |
876 | static ssize_t show_temp_min(struct device *dev, | ||
877 | struct device_attribute *devattr, char *buf) | ||
800 | { | 878 | { |
801 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 879 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
802 | struct pc87360_data *data = pc87360_update_device(dev); | 880 | struct pc87360_data *data = pc87360_update_device(dev); |
803 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index])); | 881 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index])); |
804 | } | 882 | } |
805 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf) | 883 | |
884 | static ssize_t show_temp_max(struct device *dev, | ||
885 | struct device_attribute *devattr, char *buf) | ||
806 | { | 886 | { |
807 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 887 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
808 | struct pc87360_data *data = pc87360_update_device(dev); | 888 | struct pc87360_data *data = pc87360_update_device(dev); |
809 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index])); | 889 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index])); |
810 | } | 890 | } |
811 | static ssize_t show_temp_crit(struct device *dev, struct device_attribute *devattr, char *buf) | 891 | |
892 | static ssize_t show_temp_crit(struct device *dev, | ||
893 | struct device_attribute *devattr, char *buf) | ||
812 | { | 894 | { |
813 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 895 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
814 | struct pc87360_data *data = pc87360_update_device(dev); | 896 | struct pc87360_data *data = pc87360_update_device(dev); |
815 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[attr->index])); | 897 | return sprintf(buf, "%d\n", |
898 | TEMP_FROM_REG(data->temp_crit[attr->index])); | ||
816 | } | 899 | } |
817 | static ssize_t show_temp_status(struct device *dev, struct device_attribute *devattr, char *buf) | 900 | |
901 | static ssize_t show_temp_status(struct device *dev, | ||
902 | struct device_attribute *devattr, char *buf) | ||
818 | { | 903 | { |
819 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 904 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
820 | struct pc87360_data *data = pc87360_update_device(dev); | 905 | struct pc87360_data *data = pc87360_update_device(dev); |
821 | return sprintf(buf, "%d\n", data->temp_status[attr->index]); | 906 | return sprintf(buf, "%d\n", data->temp_status[attr->index]); |
822 | } | 907 | } |
823 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf, | 908 | |
824 | size_t count) | 909 | static ssize_t set_temp_min(struct device *dev, |
910 | struct device_attribute *devattr, | ||
911 | const char *buf, size_t count) | ||
825 | { | 912 | { |
826 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 913 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
827 | struct pc87360_data *data = dev_get_drvdata(dev); | 914 | struct pc87360_data *data = dev_get_drvdata(dev); |
828 | long val = simple_strtol(buf, NULL, 10); | 915 | long val; |
916 | int err; | ||
917 | |||
918 | err = kstrtol(buf, 10, &val); | ||
919 | if (err) | ||
920 | return err; | ||
829 | 921 | ||
830 | mutex_lock(&data->update_lock); | 922 | mutex_lock(&data->update_lock); |
831 | data->temp_min[attr->index] = TEMP_TO_REG(val); | 923 | data->temp_min[attr->index] = TEMP_TO_REG(val); |
@@ -834,12 +926,19 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr | |||
834 | mutex_unlock(&data->update_lock); | 926 | mutex_unlock(&data->update_lock); |
835 | return count; | 927 | return count; |
836 | } | 928 | } |
837 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, | 929 | |
838 | size_t count) | 930 | static ssize_t set_temp_max(struct device *dev, |
931 | struct device_attribute *devattr, | ||
932 | const char *buf, size_t count) | ||
839 | { | 933 | { |
840 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 934 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
841 | struct pc87360_data *data = dev_get_drvdata(dev); | 935 | struct pc87360_data *data = dev_get_drvdata(dev); |
842 | long val = simple_strtol(buf, NULL, 10); | 936 | long val; |
937 | int err; | ||
938 | |||
939 | err = kstrtol(buf, 10, &val); | ||
940 | if (err) | ||
941 | return err; | ||
843 | 942 | ||
844 | mutex_lock(&data->update_lock); | 943 | mutex_lock(&data->update_lock); |
845 | data->temp_max[attr->index] = TEMP_TO_REG(val); | 944 | data->temp_max[attr->index] = TEMP_TO_REG(val); |
@@ -848,12 +947,19 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr | |||
848 | mutex_unlock(&data->update_lock); | 947 | mutex_unlock(&data->update_lock); |
849 | return count; | 948 | return count; |
850 | } | 949 | } |
851 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf, | 950 | |
852 | size_t count) | 951 | static ssize_t set_temp_crit(struct device *dev, |
952 | struct device_attribute *devattr, const char *buf, | ||
953 | size_t count) | ||
853 | { | 954 | { |
854 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 955 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
855 | struct pc87360_data *data = dev_get_drvdata(dev); | 956 | struct pc87360_data *data = dev_get_drvdata(dev); |
856 | long val = simple_strtol(buf, NULL, 10); | 957 | long val; |
958 | int err; | ||
959 | |||
960 | err = kstrtol(buf, 10, &val); | ||
961 | if (err) | ||
962 | return err; | ||
857 | 963 | ||
858 | mutex_lock(&data->update_lock); | 964 | mutex_lock(&data->update_lock); |
859 | data->temp_crit[attr->index] = TEMP_TO_REG(val); | 965 | data->temp_crit[attr->index] = TEMP_TO_REG(val); |
@@ -898,16 +1004,20 @@ static struct sensor_device_attribute temp_crit[] = { | |||
898 | show_temp_crit, set_temp_crit, 2), | 1004 | show_temp_crit, set_temp_crit, 2), |
899 | }; | 1005 | }; |
900 | 1006 | ||
901 | static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 1007 | static ssize_t show_temp_alarms(struct device *dev, |
1008 | struct device_attribute *attr, char *buf) | ||
902 | { | 1009 | { |
903 | struct pc87360_data *data = pc87360_update_device(dev); | 1010 | struct pc87360_data *data = pc87360_update_device(dev); |
904 | return sprintf(buf, "%u\n", data->temp_alarms); | 1011 | return sprintf(buf, "%u\n", data->temp_alarms); |
905 | } | 1012 | } |
1013 | |||
906 | static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); | 1014 | static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); |
907 | 1015 | ||
908 | /* show_temp_min/max_alarm() reads data from the per-channel status | 1016 | /* |
909 | register (sec 12.3.7), not the temp event status registers (sec | 1017 | * show_temp_min/max_alarm() reads data from the per-channel status |
910 | 12.3.2) that show_temp_alarm() reads (via data->temp_alarms) */ | 1018 | * register (sec 12.3.7), not the temp event status registers (sec |
1019 | * 12.3.2) that show_temp_alarm() reads (via data->temp_alarms) | ||
1020 | */ | ||
911 | 1021 | ||
912 | static ssize_t show_temp_min_alarm(struct device *dev, | 1022 | static ssize_t show_temp_min_alarm(struct device *dev, |
913 | struct device_attribute *devattr, char *buf) | 1023 | struct device_attribute *devattr, char *buf) |
@@ -917,6 +1027,7 @@ static ssize_t show_temp_min_alarm(struct device *dev, | |||
917 | 1027 | ||
918 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN)); | 1028 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN)); |
919 | } | 1029 | } |
1030 | |||
920 | static ssize_t show_temp_max_alarm(struct device *dev, | 1031 | static ssize_t show_temp_max_alarm(struct device *dev, |
921 | struct device_attribute *devattr, char *buf) | 1032 | struct device_attribute *devattr, char *buf) |
922 | { | 1033 | { |
@@ -925,6 +1036,7 @@ static ssize_t show_temp_max_alarm(struct device *dev, | |||
925 | 1036 | ||
926 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX)); | 1037 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX)); |
927 | } | 1038 | } |
1039 | |||
928 | static ssize_t show_temp_crit_alarm(struct device *dev, | 1040 | static ssize_t show_temp_crit_alarm(struct device *dev, |
929 | struct device_attribute *devattr, char *buf) | 1041 | struct device_attribute *devattr, char *buf) |
930 | { | 1042 | { |
@@ -939,11 +1051,13 @@ static struct sensor_device_attribute temp_min_alarm[] = { | |||
939 | SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 1), | 1051 | SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 1), |
940 | SENSOR_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 2), | 1052 | SENSOR_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 2), |
941 | }; | 1053 | }; |
1054 | |||
942 | static struct sensor_device_attribute temp_max_alarm[] = { | 1055 | static struct sensor_device_attribute temp_max_alarm[] = { |
943 | SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 0), | 1056 | SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 0), |
944 | SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 1), | 1057 | SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 1), |
945 | SENSOR_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 2), | 1058 | SENSOR_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 2), |
946 | }; | 1059 | }; |
1060 | |||
947 | static struct sensor_device_attribute temp_crit_alarm[] = { | 1061 | static struct sensor_device_attribute temp_crit_alarm[] = { |
948 | SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 0), | 1062 | SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 0), |
949 | SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 1), | 1063 | SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 1), |
@@ -965,27 +1079,29 @@ static struct sensor_device_attribute temp_fault[] = { | |||
965 | SENSOR_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2), | 1079 | SENSOR_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2), |
966 | }; | 1080 | }; |
967 | 1081 | ||
968 | #define TEMP_UNIT_ATTRS(X) \ | 1082 | #define TEMP_UNIT_ATTRS(X) \ |
969 | &temp_input[X].dev_attr.attr, \ | 1083 | { &temp_input[X].dev_attr.attr, \ |
970 | &temp_status[X].dev_attr.attr, \ | 1084 | &temp_status[X].dev_attr.attr, \ |
971 | &temp_min[X].dev_attr.attr, \ | 1085 | &temp_min[X].dev_attr.attr, \ |
972 | &temp_max[X].dev_attr.attr, \ | 1086 | &temp_max[X].dev_attr.attr, \ |
973 | &temp_crit[X].dev_attr.attr, \ | 1087 | &temp_crit[X].dev_attr.attr, \ |
974 | &temp_min_alarm[X].dev_attr.attr, \ | 1088 | &temp_min_alarm[X].dev_attr.attr, \ |
975 | &temp_max_alarm[X].dev_attr.attr, \ | 1089 | &temp_max_alarm[X].dev_attr.attr, \ |
976 | &temp_crit_alarm[X].dev_attr.attr, \ | 1090 | &temp_crit_alarm[X].dev_attr.attr, \ |
977 | &temp_fault[X].dev_attr.attr | 1091 | &temp_fault[X].dev_attr.attr, \ |
978 | 1092 | NULL \ | |
979 | static struct attribute * pc8736x_temp_attr_array[] = { | 1093 | } |
1094 | |||
1095 | static struct attribute *pc8736x_temp_attr[][10] = { | ||
980 | TEMP_UNIT_ATTRS(0), | 1096 | TEMP_UNIT_ATTRS(0), |
981 | TEMP_UNIT_ATTRS(1), | 1097 | TEMP_UNIT_ATTRS(1), |
982 | TEMP_UNIT_ATTRS(2), | 1098 | TEMP_UNIT_ATTRS(2) |
983 | /* include the few miscellaneous atts here */ | ||
984 | &dev_attr_alarms_temp.attr, | ||
985 | NULL | ||
986 | }; | 1099 | }; |
987 | static const struct attribute_group pc8736x_temp_group = { | 1100 | |
988 | .attrs = pc8736x_temp_attr_array, | 1101 | static const struct attribute_group pc8736x_temp_attr_group[] = { |
1102 | { .attrs = pc8736x_temp_attr[0] }, | ||
1103 | { .attrs = pc8736x_temp_attr[1] }, | ||
1104 | { .attrs = pc8736x_temp_attr[2] } | ||
989 | }; | 1105 | }; |
990 | 1106 | ||
991 | static ssize_t show_name(struct device *dev, | 1107 | static ssize_t show_name(struct device *dev, |
@@ -994,13 +1110,15 @@ static ssize_t show_name(struct device *dev, | |||
994 | struct pc87360_data *data = dev_get_drvdata(dev); | 1110 | struct pc87360_data *data = dev_get_drvdata(dev); |
995 | return sprintf(buf, "%s\n", data->name); | 1111 | return sprintf(buf, "%s\n", data->name); |
996 | } | 1112 | } |
1113 | |||
997 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | 1114 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
998 | 1115 | ||
999 | /* | 1116 | /* |
1000 | * Device detection, registration and update | 1117 | * Device detection, registration and update |
1001 | */ | 1118 | */ |
1002 | 1119 | ||
1003 | static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses) | 1120 | static int __init pc87360_find(int sioaddr, u8 *devid, |
1121 | unsigned short *addresses) | ||
1004 | { | 1122 | { |
1005 | u16 val; | 1123 | u16 val; |
1006 | int i; | 1124 | int i; |
@@ -1047,7 +1165,7 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses | |||
1047 | 1165 | ||
1048 | addresses[i] = val; | 1166 | addresses[i] = val; |
1049 | 1167 | ||
1050 | if (i==0) { /* Fans */ | 1168 | if (i == 0) { /* Fans */ |
1051 | confreg[0] = superio_inb(sioaddr, 0xF0); | 1169 | confreg[0] = superio_inb(sioaddr, 0xF0); |
1052 | confreg[1] = superio_inb(sioaddr, 0xF1); | 1170 | confreg[1] = superio_inb(sioaddr, 0xF1); |
1053 | 1171 | ||
@@ -1060,12 +1178,14 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses | |||
1060 | pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3, | 1178 | pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3, |
1061 | confreg[1] & 1, (confreg[1] >> 1) & 1, | 1179 | confreg[1] & 1, (confreg[1] >> 1) & 1, |
1062 | (confreg[1] >> 2) & 1); | 1180 | (confreg[1] >> 2) & 1); |
1063 | } else if (i==1) { /* Voltages */ | 1181 | } else if (i == 1) { /* Voltages */ |
1064 | /* Are we using thermistors? */ | 1182 | /* Are we using thermistors? */ |
1065 | if (*devid == 0xE9) { /* PC87366 */ | 1183 | if (*devid == 0xE9) { /* PC87366 */ |
1066 | /* These registers are not logical-device | 1184 | /* |
1067 | specific, just that we won't need them if | 1185 | * These registers are not logical-device |
1068 | we don't use the VLM device */ | 1186 | * specific, just that we won't need them if |
1187 | * we don't use the VLM device | ||
1188 | */ | ||
1069 | confreg[2] = superio_inb(sioaddr, 0x2B); | 1189 | confreg[2] = superio_inb(sioaddr, 0x2B); |
1070 | confreg[3] = superio_inb(sioaddr, 0x25); | 1190 | confreg[3] = superio_inb(sioaddr, 0x25); |
1071 | 1191 | ||
@@ -1085,6 +1205,22 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses | |||
1085 | return 0; | 1205 | return 0; |
1086 | } | 1206 | } |
1087 | 1207 | ||
1208 | static void pc87360_remove_files(struct device *dev) | ||
1209 | { | ||
1210 | int i; | ||
1211 | |||
1212 | device_remove_file(dev, &dev_attr_name); | ||
1213 | device_remove_file(dev, &dev_attr_alarms_temp); | ||
1214 | for (i = 0; i < ARRAY_SIZE(pc8736x_temp_attr_group); i++) | ||
1215 | sysfs_remove_group(&dev->kobj, &pc8736x_temp_attr_group[i]); | ||
1216 | for (i = 0; i < ARRAY_SIZE(pc8736x_fan_attr_group); i++) { | ||
1217 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_attr_group[i]); | ||
1218 | device_remove_file(dev, &pwm[i].dev_attr); | ||
1219 | } | ||
1220 | sysfs_remove_group(&dev->kobj, &pc8736x_therm_group); | ||
1221 | sysfs_remove_group(&dev->kobj, &pc8736x_vin_group); | ||
1222 | } | ||
1223 | |||
1088 | static int __devinit pc87360_probe(struct platform_device *pdev) | 1224 | static int __devinit pc87360_probe(struct platform_device *pdev) |
1089 | { | 1225 | { |
1090 | int i; | 1226 | int i; |
@@ -1094,7 +1230,8 @@ static int __devinit pc87360_probe(struct platform_device *pdev) | |||
1094 | int use_thermistors = 0; | 1230 | int use_thermistors = 0; |
1095 | struct device *dev = &pdev->dev; | 1231 | struct device *dev = &pdev->dev; |
1096 | 1232 | ||
1097 | if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL))) | 1233 | data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL); |
1234 | if (!data) | ||
1098 | return -ENOMEM; | 1235 | return -ENOMEM; |
1099 | 1236 | ||
1100 | data->fannr = 2; | 1237 | data->fannr = 2; |
@@ -1130,9 +1267,10 @@ static int __devinit pc87360_probe(struct platform_device *pdev) | |||
1130 | platform_set_drvdata(pdev, data); | 1267 | platform_set_drvdata(pdev, data); |
1131 | 1268 | ||
1132 | for (i = 0; i < LDNI_MAX; i++) { | 1269 | for (i = 0; i < LDNI_MAX; i++) { |
1133 | if (((data->address[i] = extra_isa[i])) | 1270 | data->address[i] = extra_isa[i]; |
1271 | if (data->address[i] | ||
1134 | && !request_region(extra_isa[i], PC87360_EXTENT, | 1272 | && !request_region(extra_isa[i], PC87360_EXTENT, |
1135 | pc87360_driver.driver.name)) { | 1273 | pc87360_driver.driver.name)) { |
1136 | dev_err(dev, "Region 0x%x-0x%x already " | 1274 | dev_err(dev, "Region 0x%x-0x%x already " |
1137 | "in use!\n", extra_isa[i], | 1275 | "in use!\n", extra_isa[i], |
1138 | extra_isa[i]+PC87360_EXTENT-1); | 1276 | extra_isa[i]+PC87360_EXTENT-1); |
@@ -1147,9 +1285,11 @@ static int __devinit pc87360_probe(struct platform_device *pdev) | |||
1147 | if (data->fannr) | 1285 | if (data->fannr) |
1148 | data->fan_conf = confreg[0] | (confreg[1] << 8); | 1286 | data->fan_conf = confreg[0] | (confreg[1] << 8); |
1149 | 1287 | ||
1150 | /* Use the correct reference voltage | 1288 | /* |
1151 | Unless both the VLM and the TMS logical devices agree to | 1289 | * Use the correct reference voltage |
1152 | use an external Vref, the internal one is used. */ | 1290 | * Unless both the VLM and the TMS logical devices agree to |
1291 | * use an external Vref, the internal one is used. | ||
1292 | */ | ||
1153 | if (data->innr) { | 1293 | if (data->innr) { |
1154 | i = pc87360_read_value(data, LD_IN, NO_BANK, | 1294 | i = pc87360_read_value(data, LD_IN, NO_BANK, |
1155 | PC87365_REG_IN_CONFIG); | 1295 | PC87365_REG_IN_CONFIG); |
@@ -1182,62 +1322,48 @@ static int __devinit pc87360_probe(struct platform_device *pdev) | |||
1182 | 1322 | ||
1183 | /* Register all-or-nothing sysfs groups */ | 1323 | /* Register all-or-nothing sysfs groups */ |
1184 | 1324 | ||
1185 | if (data->innr && | 1325 | if (data->innr) { |
1186 | (err = sysfs_create_group(&dev->kobj, | 1326 | err = sysfs_create_group(&dev->kobj, &pc8736x_vin_group); |
1187 | &pc8736x_vin_group))) | 1327 | if (err) |
1188 | goto ERROR3; | 1328 | goto ERROR3; |
1329 | } | ||
1189 | 1330 | ||
1190 | if (data->innr == 14 && | 1331 | if (data->innr == 14) { |
1191 | (err = sysfs_create_group(&dev->kobj, | 1332 | err = sysfs_create_group(&dev->kobj, &pc8736x_therm_group); |
1192 | &pc8736x_therm_group))) | 1333 | if (err) |
1193 | goto ERROR3; | 1334 | goto ERROR3; |
1335 | } | ||
1194 | 1336 | ||
1195 | /* create device attr-files for varying sysfs groups */ | 1337 | /* create device attr-files for varying sysfs groups */ |
1196 | 1338 | ||
1197 | if (data->tempnr) { | 1339 | if (data->tempnr) { |
1198 | for (i = 0; i < data->tempnr; i++) { | 1340 | for (i = 0; i < data->tempnr; i++) { |
1199 | if ((err = device_create_file(dev, | 1341 | err = sysfs_create_group(&dev->kobj, |
1200 | &temp_input[i].dev_attr)) | 1342 | &pc8736x_temp_attr_group[i]); |
1201 | || (err = device_create_file(dev, | 1343 | if (err) |
1202 | &temp_min[i].dev_attr)) | ||
1203 | || (err = device_create_file(dev, | ||
1204 | &temp_max[i].dev_attr)) | ||
1205 | || (err = device_create_file(dev, | ||
1206 | &temp_crit[i].dev_attr)) | ||
1207 | || (err = device_create_file(dev, | ||
1208 | &temp_status[i].dev_attr)) | ||
1209 | || (err = device_create_file(dev, | ||
1210 | &temp_min_alarm[i].dev_attr)) | ||
1211 | || (err = device_create_file(dev, | ||
1212 | &temp_max_alarm[i].dev_attr)) | ||
1213 | || (err = device_create_file(dev, | ||
1214 | &temp_crit_alarm[i].dev_attr)) | ||
1215 | || (err = device_create_file(dev, | ||
1216 | &temp_fault[i].dev_attr))) | ||
1217 | goto ERROR3; | 1344 | goto ERROR3; |
1218 | } | 1345 | } |
1219 | if ((err = device_create_file(dev, &dev_attr_alarms_temp))) | 1346 | err = device_create_file(dev, &dev_attr_alarms_temp); |
1347 | if (err) | ||
1220 | goto ERROR3; | 1348 | goto ERROR3; |
1221 | } | 1349 | } |
1222 | 1350 | ||
1223 | for (i = 0; i < data->fannr; i++) { | 1351 | for (i = 0; i < data->fannr; i++) { |
1224 | if (FAN_CONFIG_MONITOR(data->fan_conf, i) | 1352 | if (FAN_CONFIG_MONITOR(data->fan_conf, i)) { |
1225 | && ((err = device_create_file(dev, | 1353 | err = sysfs_create_group(&dev->kobj, |
1226 | &fan_input[i].dev_attr)) | 1354 | &pc8736x_fan_attr_group[i]); |
1227 | || (err = device_create_file(dev, | 1355 | if (err) |
1228 | &fan_min[i].dev_attr)) | 1356 | goto ERROR3; |
1229 | || (err = device_create_file(dev, | 1357 | } |
1230 | &fan_div[i].dev_attr)) | 1358 | if (FAN_CONFIG_CONTROL(data->fan_conf, i)) { |
1231 | || (err = device_create_file(dev, | 1359 | err = device_create_file(dev, &pwm[i].dev_attr); |
1232 | &fan_status[i].dev_attr)))) | 1360 | if (err) |
1233 | goto ERROR3; | 1361 | goto ERROR3; |
1234 | 1362 | } | |
1235 | if (FAN_CONFIG_CONTROL(data->fan_conf, i) | ||
1236 | && (err = device_create_file(dev, &pwm[i].dev_attr))) | ||
1237 | goto ERROR3; | ||
1238 | } | 1363 | } |
1239 | 1364 | ||
1240 | if ((err = device_create_file(dev, &dev_attr_name))) | 1365 | err = device_create_file(dev, &dev_attr_name); |
1366 | if (err) | ||
1241 | goto ERROR3; | 1367 | goto ERROR3; |
1242 | 1368 | ||
1243 | data->hwmon_dev = hwmon_device_register(dev); | 1369 | data->hwmon_dev = hwmon_device_register(dev); |
@@ -1248,16 +1374,10 @@ static int __devinit pc87360_probe(struct platform_device *pdev) | |||
1248 | return 0; | 1374 | return 0; |
1249 | 1375 | ||
1250 | ERROR3: | 1376 | ERROR3: |
1251 | device_remove_file(dev, &dev_attr_name); | 1377 | pc87360_remove_files(dev); |
1252 | /* can still remove groups whose members were added individually */ | ||
1253 | sysfs_remove_group(&dev->kobj, &pc8736x_temp_group); | ||
1254 | sysfs_remove_group(&dev->kobj, &pc8736x_fan_group); | ||
1255 | sysfs_remove_group(&dev->kobj, &pc8736x_therm_group); | ||
1256 | sysfs_remove_group(&dev->kobj, &pc8736x_vin_group); | ||
1257 | for (i = 0; i < 3; i++) { | 1378 | for (i = 0; i < 3; i++) { |
1258 | if (data->address[i]) { | 1379 | if (data->address[i]) |
1259 | release_region(data->address[i], PC87360_EXTENT); | 1380 | release_region(data->address[i], PC87360_EXTENT); |
1260 | } | ||
1261 | } | 1381 | } |
1262 | ERROR1: | 1382 | ERROR1: |
1263 | kfree(data); | 1383 | kfree(data); |
@@ -1270,25 +1390,20 @@ static int __devexit pc87360_remove(struct platform_device *pdev) | |||
1270 | int i; | 1390 | int i; |
1271 | 1391 | ||
1272 | hwmon_device_unregister(data->hwmon_dev); | 1392 | hwmon_device_unregister(data->hwmon_dev); |
1273 | 1393 | pc87360_remove_files(&pdev->dev); | |
1274 | device_remove_file(&pdev->dev, &dev_attr_name); | ||
1275 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_temp_group); | ||
1276 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_group); | ||
1277 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_therm_group); | ||
1278 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_vin_group); | ||
1279 | |||
1280 | for (i = 0; i < 3; i++) { | 1394 | for (i = 0; i < 3; i++) { |
1281 | if (data->address[i]) { | 1395 | if (data->address[i]) |
1282 | release_region(data->address[i], PC87360_EXTENT); | 1396 | release_region(data->address[i], PC87360_EXTENT); |
1283 | } | ||
1284 | } | 1397 | } |
1285 | kfree(data); | 1398 | kfree(data); |
1286 | 1399 | ||
1287 | return 0; | 1400 | return 0; |
1288 | } | 1401 | } |
1289 | 1402 | ||
1290 | /* ldi is the logical device index | 1403 | /* |
1291 | bank is for voltages and temperatures only */ | 1404 | * ldi is the logical device index |
1405 | * bank is for voltages and temperatures only | ||
1406 | */ | ||
1292 | static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, | 1407 | static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, |
1293 | u8 reg) | 1408 | u8 reg) |
1294 | { | 1409 | { |
@@ -1359,8 +1474,10 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1359 | } | 1474 | } |
1360 | } | 1475 | } |
1361 | 1476 | ||
1362 | /* We can't blindly trust the Super-I/O space configuration bit, | 1477 | /* |
1363 | most BIOS won't set it properly */ | 1478 | * We can't blindly trust the Super-I/O space configuration bit, |
1479 | * most BIOS won't set it properly | ||
1480 | */ | ||
1364 | dev_dbg(&pdev->dev, "bios thermistors:%d\n", use_thermistors); | 1481 | dev_dbg(&pdev->dev, "bios thermistors:%d\n", use_thermistors); |
1365 | for (i = 11; i < data->innr; i++) { | 1482 | for (i = 11; i < data->innr; i++) { |
1366 | reg = pc87360_read_value(data, LD_IN, i, | 1483 | reg = pc87360_read_value(data, LD_IN, i, |
@@ -1375,12 +1492,12 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1375 | for (; i < data->tempnr; i++) { | 1492 | for (; i < data->tempnr; i++) { |
1376 | reg = pc87360_read_value(data, LD_TEMP, i, | 1493 | reg = pc87360_read_value(data, LD_TEMP, i, |
1377 | PC87365_REG_TEMP_STATUS); | 1494 | PC87365_REG_TEMP_STATUS); |
1378 | dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i+1, reg); | 1495 | dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i + 1, reg); |
1379 | if (init >= init_temp[i]) { | 1496 | if (init >= init_temp[i]) { |
1380 | /* Forcibly enable temperature channel */ | 1497 | /* Forcibly enable temperature channel */ |
1381 | if (!(reg & CHAN_ENA)) { | 1498 | if (!(reg & CHAN_ENA)) { |
1382 | dev_dbg(&pdev->dev, "Forcibly " | 1499 | dev_dbg(&pdev->dev, |
1383 | "enabling temp%d\n", i+1); | 1500 | "Forcibly enabling temp%d\n", i + 1); |
1384 | pc87360_write_value(data, LD_TEMP, i, | 1501 | pc87360_write_value(data, LD_TEMP, i, |
1385 | PC87365_REG_TEMP_STATUS, | 1502 | PC87365_REG_TEMP_STATUS, |
1386 | 0xCF); | 1503 | 0xCF); |
@@ -1391,14 +1508,16 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1391 | if (use_thermistors) { | 1508 | if (use_thermistors) { |
1392 | for (i = 11; i < data->innr; i++) { | 1509 | for (i = 11; i < data->innr; i++) { |
1393 | if (init >= init_in[i]) { | 1510 | if (init >= init_in[i]) { |
1394 | /* The pin may already be used by thermal | 1511 | /* |
1395 | diodes */ | 1512 | * The pin may already be used by thermal |
1513 | * diodes | ||
1514 | */ | ||
1396 | reg = pc87360_read_value(data, LD_TEMP, | 1515 | reg = pc87360_read_value(data, LD_TEMP, |
1397 | (i-11)/2, PC87365_REG_TEMP_STATUS); | 1516 | (i - 11) / 2, PC87365_REG_TEMP_STATUS); |
1398 | if (reg & CHAN_ENA) { | 1517 | if (reg & CHAN_ENA) { |
1399 | dev_dbg(&pdev->dev, "Skipping " | 1518 | dev_dbg(&pdev->dev, |
1400 | "temp%d, pin already in use " | 1519 | "Skipping temp%d, pin already in use by temp%d\n", |
1401 | "by temp%d\n", i-7, (i-11)/2); | 1520 | i - 7, (i - 11) / 2); |
1402 | continue; | 1521 | continue; |
1403 | } | 1522 | } |
1404 | 1523 | ||
@@ -1406,8 +1525,9 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1406 | reg = pc87360_read_value(data, LD_IN, i, | 1525 | reg = pc87360_read_value(data, LD_IN, i, |
1407 | PC87365_REG_IN_STATUS); | 1526 | PC87365_REG_IN_STATUS); |
1408 | if (!(reg & CHAN_ENA)) { | 1527 | if (!(reg & CHAN_ENA)) { |
1409 | dev_dbg(&pdev->dev, "Forcibly " | 1528 | dev_dbg(&pdev->dev, |
1410 | "enabling temp%d\n", i-7); | 1529 | "Forcibly enabling temp%d\n", |
1530 | i - 7); | ||
1411 | pc87360_write_value(data, LD_IN, i, | 1531 | pc87360_write_value(data, LD_IN, i, |
1412 | PC87365_REG_TEMP_STATUS, | 1532 | PC87365_REG_TEMP_STATUS, |
1413 | (reg & 0x60) | 0x8F); | 1533 | (reg & 0x60) | 0x8F); |
@@ -1421,8 +1541,8 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1421 | PC87365_REG_IN_CONFIG); | 1541 | PC87365_REG_IN_CONFIG); |
1422 | dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg); | 1542 | dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg); |
1423 | if (reg & CHAN_ENA) { | 1543 | if (reg & CHAN_ENA) { |
1424 | dev_dbg(&pdev->dev, "Forcibly " | 1544 | dev_dbg(&pdev->dev, |
1425 | "enabling monitoring (VLM)\n"); | 1545 | "Forcibly enabling monitoring (VLM)\n"); |
1426 | pc87360_write_value(data, LD_IN, NO_BANK, | 1546 | pc87360_write_value(data, LD_IN, NO_BANK, |
1427 | PC87365_REG_IN_CONFIG, | 1547 | PC87365_REG_IN_CONFIG, |
1428 | reg & 0xFE); | 1548 | reg & 0xFE); |
@@ -1434,8 +1554,8 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1434 | PC87365_REG_TEMP_CONFIG); | 1554 | PC87365_REG_TEMP_CONFIG); |
1435 | dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg); | 1555 | dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg); |
1436 | if (reg & CHAN_ENA) { | 1556 | if (reg & CHAN_ENA) { |
1437 | dev_dbg(&pdev->dev, "Forcibly enabling " | 1557 | dev_dbg(&pdev->dev, |
1438 | "monitoring (TMS)\n"); | 1558 | "Forcibly enabling monitoring (TMS)\n"); |
1439 | pc87360_write_value(data, LD_TEMP, NO_BANK, | 1559 | pc87360_write_value(data, LD_TEMP, NO_BANK, |
1440 | PC87365_REG_TEMP_CONFIG, | 1560 | PC87365_REG_TEMP_CONFIG, |
1441 | reg & 0xFE); | 1561 | reg & 0xFE); |
@@ -1444,10 +1564,12 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1444 | if (init >= 2) { | 1564 | if (init >= 2) { |
1445 | /* Chip config as documented by National Semi. */ | 1565 | /* Chip config as documented by National Semi. */ |
1446 | pc87360_write_value(data, LD_TEMP, 0xF, 0xA, 0x08); | 1566 | pc87360_write_value(data, LD_TEMP, 0xF, 0xA, 0x08); |
1447 | /* We voluntarily omit the bank here, in case the | 1567 | /* |
1448 | sequence itself matters. It shouldn't be a problem, | 1568 | * We voluntarily omit the bank here, in case the |
1449 | since nobody else is supposed to access the | 1569 | * sequence itself matters. It shouldn't be a problem, |
1450 | device at that point. */ | 1570 | * since nobody else is supposed to access the |
1571 | * device at that point. | ||
1572 | */ | ||
1451 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xB, 0x04); | 1573 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xB, 0x04); |
1452 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xC, 0x35); | 1574 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xC, 0x35); |
1453 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xD, 0x05); | 1575 | pc87360_write_value(data, LD_TEMP, NO_BANK, 0xD, 0x05); |
@@ -1470,7 +1592,7 @@ static void pc87360_autodiv(struct device *dev, int nr) | |||
1470 | data->fan[nr] >>= 1; | 1592 | data->fan[nr] >>= 1; |
1471 | dev_dbg(dev, "Increasing " | 1593 | dev_dbg(dev, "Increasing " |
1472 | "clock divider to %d for fan %d\n", | 1594 | "clock divider to %d for fan %d\n", |
1473 | FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1); | 1595 | FAN_DIV_FROM_REG(data->fan_status[nr]), nr + 1); |
1474 | } | 1596 | } |
1475 | } else { | 1597 | } else { |
1476 | /* Decrease clock divider if possible */ | 1598 | /* Decrease clock divider if possible */ |
@@ -1483,7 +1605,7 @@ static void pc87360_autodiv(struct device *dev, int nr) | |||
1483 | dev_dbg(dev, "Decreasing " | 1605 | dev_dbg(dev, "Decreasing " |
1484 | "clock divider to %d for fan %d\n", | 1606 | "clock divider to %d for fan %d\n", |
1485 | FAN_DIV_FROM_REG(data->fan_status[nr]), | 1607 | FAN_DIV_FROM_REG(data->fan_status[nr]), |
1486 | nr+1); | 1608 | nr + 1); |
1487 | } | 1609 | } |
1488 | } | 1610 | } |
1489 | 1611 | ||