aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-01-15 00:49:53 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:26 -0400
commit449a7a0720f2edc84288fb239bca8b2f9366881d (patch)
tree9728faf1aa14c3bf214ad358fed8f5d3dcb0298a /drivers/hwmon
parent8958dfb74a8b8673824d21efabaf565777c549fe (diff)
hwmon: (pc87360) Fix checkpatch issues
Fixed: ERROR: code indent should use tabs where possible ERROR: do not use assignment in if condition ERROR: "foo * bar" should be "foo *bar" ERROR: space required after that ',' (ctx:VxV) ERROR: spaces required around that ':' (ctx:VxE) ERROR: spaces required around that '==' (ctx:VxV) WARNING: braces {} are not necessary for single statement blocks WARNING: line over 80 characters WARNING: please, no space before tabs WARNING: please, no spaces at the start of a line WARNING: simple_strtol is obsolete, use kstrtol instead WARNING: simple_strtoul is obsolete, use kstrtoul instead Not or not all fixed (code complexity): ERROR: Macros with complex values should be enclosed in parenthesis ERROR: do not use assignment in if condition Cc: Jim Cromie <jim.cromie@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/pc87360.c404
1 files changed, 260 insertions, 144 deletions
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index b54637efc879..000499ea5973 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -56,11 +56,11 @@ static u8 confreg[4];
56static int init = 1; 56static int init = 1;
57module_param(init, int, 0); 57module_param(init, int, 0);
58MODULE_PARM_DESC(init, 58MODULE_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
65static unsigned short force_id; 65static unsigned short force_id;
66module_param(force_id, ushort, 0); 66module_param(force_id, ushort, 0);
@@ -88,19 +88,19 @@ static const u8 logdev[LDNI_MAX] = { FSCM, VLM, TMS };
88static inline void superio_outb(int sioaddr, int reg, int val) 88static 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
94static inline int superio_inb(int sioaddr, int reg) 94static 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
100static inline void superio_exit(int sioaddr) 100static 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))
137static inline u8 PWM_TO_REG(int val, int inv) 137static 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
258static ssize_t show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf) 258static 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}
265static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf) 266static 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}
272static ssize_t show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) 274static 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}
279static ssize_t show_fan_status(struct device *dev, struct device_attribute *devattr, char *buf) 282static 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}
286static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, 290static 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
@@ -339,7 +352,8 @@ static struct sensor_device_attribute fan_min[] = {
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
341 354
342static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) 355static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
356 char *buf)
343{ 357{
344 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 358 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
345 struct pc87360_data *data = pc87360_update_device(dev); 359 struct pc87360_data *data = pc87360_update_device(dev);
@@ -348,12 +362,17 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, ch
348 FAN_CONFIG_INVERT(data->fan_conf, 362 FAN_CONFIG_INVERT(data->fan_conf,
349 attr->index))); 363 attr->index)));
350} 364}
351static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf, 365static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
352 size_t count) 366 const char *buf, size_t count)
353{ 367{
354 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 368 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
355 struct pc87360_data *data = dev_get_drvdata(dev); 369 struct pc87360_data *data = dev_get_drvdata(dev);
356 long val = simple_strtol(buf, NULL, 10); 370 long val;
371 int err;
372
373 err = kstrtol(buf, 10, &val);
374 if (err)
375 return err;
357 376
358 mutex_lock(&data->update_lock); 377 mutex_lock(&data->update_lock);
359 data->pwm[attr->index] = PWM_TO_REG(val, 378 data->pwm[attr->index] = PWM_TO_REG(val,
@@ -370,7 +389,7 @@ static struct sensor_device_attribute pwm[] = {
370 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2), 389 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2),
371}; 390};
372 391
373static struct attribute * pc8736x_fan_attr_array[] = { 392static struct attribute *pc8736x_fan_attr_array[] = {
374 FAN_UNIT_ATTRS(0), 393 FAN_UNIT_ATTRS(0),
375 FAN_UNIT_ATTRS(1), 394 FAN_UNIT_ATTRS(1),
376 FAN_UNIT_ATTRS(2), 395 FAN_UNIT_ATTRS(2),
@@ -383,39 +402,48 @@ static const struct attribute_group pc8736x_fan_group = {
383 .attrs = pc8736x_fan_attr_array, 402 .attrs = pc8736x_fan_attr_array,
384}; 403};
385 404
386static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf) 405static ssize_t show_in_input(struct device *dev,
406 struct device_attribute *devattr, char *buf)
387{ 407{
388 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 408 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
389 struct pc87360_data *data = pc87360_update_device(dev); 409 struct pc87360_data *data = pc87360_update_device(dev);
390 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], 410 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],
391 data->in_vref)); 411 data->in_vref));
392} 412}
393static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf) 413static ssize_t show_in_min(struct device *dev,
414 struct device_attribute *devattr, char *buf)
394{ 415{
395 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 416 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
396 struct pc87360_data *data = pc87360_update_device(dev); 417 struct pc87360_data *data = pc87360_update_device(dev);
397 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], 418 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],
398 data->in_vref)); 419 data->in_vref));
399} 420}
400static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf) 421static ssize_t show_in_max(struct device *dev,
422 struct device_attribute *devattr, char *buf)
401{ 423{
402 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 424 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
403 struct pc87360_data *data = pc87360_update_device(dev); 425 struct pc87360_data *data = pc87360_update_device(dev);
404 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], 426 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],
405 data->in_vref)); 427 data->in_vref));
406} 428}
407static ssize_t show_in_status(struct device *dev, struct device_attribute *devattr, char *buf) 429static ssize_t show_in_status(struct device *dev,
430 struct device_attribute *devattr, char *buf)
408{ 431{
409 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 432 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
410 struct pc87360_data *data = pc87360_update_device(dev); 433 struct pc87360_data *data = pc87360_update_device(dev);
411 return sprintf(buf, "%u\n", data->in_status[attr->index]); 434 return sprintf(buf, "%u\n", data->in_status[attr->index]);
412} 435}
413static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf, 436static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr,
414 size_t count) 437 const char *buf, size_t count)
415{ 438{
416 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 439 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
417 struct pc87360_data *data = dev_get_drvdata(dev); 440 struct pc87360_data *data = dev_get_drvdata(dev);
418 long val = simple_strtol(buf, NULL, 10); 441 long val;
442 int err;
443
444 err = kstrtol(buf, 10, &val);
445 if (err)
446 return err;
419 447
420 mutex_lock(&data->update_lock); 448 mutex_lock(&data->update_lock);
421 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); 449 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
@@ -424,12 +452,17 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr,
424 mutex_unlock(&data->update_lock); 452 mutex_unlock(&data->update_lock);
425 return count; 453 return count;
426} 454}
427static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, 455static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr,
428 size_t count) 456 const char *buf, size_t count)
429{ 457{
430 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 458 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
431 struct pc87360_data *data = dev_get_drvdata(dev); 459 struct pc87360_data *data = dev_get_drvdata(dev);
432 long val = simple_strtol(buf, NULL, 10); 460 long val;
461 int err;
462
463 err = kstrtol(buf, 10, &val);
464 if (err)
465 return err;
433 466
434 mutex_lock(&data->update_lock); 467 mutex_lock(&data->update_lock);
435 data->in_max[attr->index] = IN_TO_REG(val, 468 data->in_max[attr->index] = IN_TO_REG(val,
@@ -556,27 +589,38 @@ static struct sensor_device_attribute in_max_alarm[] = {
556 &in_min_alarm[X].dev_attr.attr, \ 589 &in_min_alarm[X].dev_attr.attr, \
557 &in_max_alarm[X].dev_attr.attr 590 &in_max_alarm[X].dev_attr.attr
558 591
559static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 592static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
593 char *buf)
560{ 594{
561 struct pc87360_data *data = pc87360_update_device(dev); 595 struct pc87360_data *data = pc87360_update_device(dev);
562 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); 596 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
563} 597}
564static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 598static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
565 599
566static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 600static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
601 char *buf)
567{ 602{
568 struct pc87360_data *data = dev_get_drvdata(dev); 603 struct pc87360_data *data = dev_get_drvdata(dev);
569 return sprintf(buf, "%u\n", data->vrm); 604 return sprintf(buf, "%u\n", data->vrm);
570} 605}
571static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 606static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
607 const char *buf, size_t count)
572{ 608{
573 struct pc87360_data *data = dev_get_drvdata(dev); 609 struct pc87360_data *data = dev_get_drvdata(dev);
574 data->vrm = simple_strtoul(buf, NULL, 10); 610 unsigned long val;
611 int err;
612
613 err = kstrtoul(buf, 10, &val);
614 if (err)
615 return err;
616
617 data->vrm = val;
575 return count; 618 return count;
576} 619}
577static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 620static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
578 621
579static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf) 622static ssize_t show_in_alarms(struct device *dev,
623 struct device_attribute *attr, char *buf)
580{ 624{
581 struct pc87360_data *data = pc87360_update_device(dev); 625 struct pc87360_data *data = pc87360_update_device(dev);
582 return sprintf(buf, "%u\n", data->in_alarms); 626 return sprintf(buf, "%u\n", data->in_alarms);
@@ -604,46 +648,58 @@ static const struct attribute_group pc8736x_vin_group = {
604 .attrs = pc8736x_vin_attr_array, 648 .attrs = pc8736x_vin_attr_array,
605}; 649};
606 650
607static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf) 651static ssize_t show_therm_input(struct device *dev,
652 struct device_attribute *devattr, char *buf)
608{ 653{
609 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 654 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
610 struct pc87360_data *data = pc87360_update_device(dev); 655 struct pc87360_data *data = pc87360_update_device(dev);
611 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], 656 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],
612 data->in_vref)); 657 data->in_vref));
613} 658}
614static ssize_t show_therm_min(struct device *dev, struct device_attribute *devattr, char *buf) 659static ssize_t show_therm_min(struct device *dev,
660 struct device_attribute *devattr, char *buf)
615{ 661{
616 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 662 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
617 struct pc87360_data *data = pc87360_update_device(dev); 663 struct pc87360_data *data = pc87360_update_device(dev);
618 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], 664 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],
619 data->in_vref)); 665 data->in_vref));
620} 666}
621static ssize_t show_therm_max(struct device *dev, struct device_attribute *devattr, char *buf) 667static ssize_t show_therm_max(struct device *dev,
668 struct device_attribute *devattr, char *buf)
622{ 669{
623 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 670 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
624 struct pc87360_data *data = pc87360_update_device(dev); 671 struct pc87360_data *data = pc87360_update_device(dev);
625 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], 672 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],
626 data->in_vref)); 673 data->in_vref));
627} 674}
628static ssize_t show_therm_crit(struct device *dev, struct device_attribute *devattr, char *buf) 675static ssize_t show_therm_crit(struct device *dev,
676 struct device_attribute *devattr, char *buf)
629{ 677{
630 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 678 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
631 struct pc87360_data *data = pc87360_update_device(dev); 679 struct pc87360_data *data = pc87360_update_device(dev);
632 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11], 680 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11],
633 data->in_vref)); 681 data->in_vref));
634} 682}
635static ssize_t show_therm_status(struct device *dev, struct device_attribute *devattr, char *buf) 683static ssize_t show_therm_status(struct device *dev,
684 struct device_attribute *devattr, char *buf)
636{ 685{
637 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 686 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
638 struct pc87360_data *data = pc87360_update_device(dev); 687 struct pc87360_data *data = pc87360_update_device(dev);
639 return sprintf(buf, "%u\n", data->in_status[attr->index]); 688 return sprintf(buf, "%u\n", data->in_status[attr->index]);
640} 689}
641static ssize_t set_therm_min(struct device *dev, struct device_attribute *devattr, const char *buf, 690
642 size_t count) 691static ssize_t set_therm_min(struct device *dev,
692 struct device_attribute *devattr,
693 const char *buf, size_t count)
643{ 694{
644 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 695 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
645 struct pc87360_data *data = dev_get_drvdata(dev); 696 struct pc87360_data *data = dev_get_drvdata(dev);
646 long val = simple_strtol(buf, NULL, 10); 697 long val;
698 int err;
699
700 err = kstrtol(buf, 10, &val);
701 if (err)
702 return err;
647 703
648 mutex_lock(&data->update_lock); 704 mutex_lock(&data->update_lock);
649 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); 705 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
@@ -652,12 +708,19 @@ static ssize_t set_therm_min(struct device *dev, struct device_attribute *devatt
652 mutex_unlock(&data->update_lock); 708 mutex_unlock(&data->update_lock);
653 return count; 709 return count;
654} 710}
655static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf, 711
656 size_t count) 712static ssize_t set_therm_max(struct device *dev,
713 struct device_attribute *devattr,
714 const char *buf, size_t count)
657{ 715{
658 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 716 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
659 struct pc87360_data *data = dev_get_drvdata(dev); 717 struct pc87360_data *data = dev_get_drvdata(dev);
660 long val = simple_strtol(buf, NULL, 10); 718 long val;
719 int err;
720
721 err = kstrtol(buf, 10, &val);
722 if (err)
723 return err;
661 724
662 mutex_lock(&data->update_lock); 725 mutex_lock(&data->update_lock);
663 data->in_max[attr->index] = IN_TO_REG(val, data->in_vref); 726 data->in_max[attr->index] = IN_TO_REG(val, data->in_vref);
@@ -666,12 +729,18 @@ static ssize_t set_therm_max(struct device *dev, struct device_attribute *devatt
666 mutex_unlock(&data->update_lock); 729 mutex_unlock(&data->update_lock);
667 return count; 730 return count;
668} 731}
669static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf, 732static ssize_t set_therm_crit(struct device *dev,
670 size_t count) 733 struct device_attribute *devattr,
734 const char *buf, size_t count)
671{ 735{
672 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 736 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
673 struct pc87360_data *data = dev_get_drvdata(dev); 737 struct pc87360_data *data = dev_get_drvdata(dev);
674 long val = simple_strtol(buf, NULL, 10); 738 long val;
739 int err;
740
741 err = kstrtol(buf, 10, &val);
742 if (err)
743 return err;
675 744
676 mutex_lock(&data->update_lock); 745 mutex_lock(&data->update_lock);
677 data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref); 746 data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref);
@@ -686,38 +755,38 @@ static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devat
686 * used in the chip to measure voltage across the thermistors 755 * used in the chip to measure voltage across the thermistors
687 */ 756 */
688static struct sensor_device_attribute therm_input[] = { 757static struct sensor_device_attribute therm_input[] = {
689 SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0+11), 758 SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0 + 11),
690 SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1+11), 759 SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1 + 11),
691 SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2+11), 760 SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2 + 11),
692}; 761};
693static struct sensor_device_attribute therm_status[] = { 762static struct sensor_device_attribute therm_status[] = {
694 SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0+11), 763 SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0 + 11),
695 SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1+11), 764 SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1 + 11),
696 SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2+11), 765 SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2 + 11),
697}; 766};
698static struct sensor_device_attribute therm_min[] = { 767static struct sensor_device_attribute therm_min[] = {
699 SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR, 768 SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR,
700 show_therm_min, set_therm_min, 0+11), 769 show_therm_min, set_therm_min, 0 + 11),
701 SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR, 770 SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR,
702 show_therm_min, set_therm_min, 1+11), 771 show_therm_min, set_therm_min, 1 + 11),
703 SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR, 772 SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR,
704 show_therm_min, set_therm_min, 2+11), 773 show_therm_min, set_therm_min, 2 + 11),
705}; 774};
706static struct sensor_device_attribute therm_max[] = { 775static struct sensor_device_attribute therm_max[] = {
707 SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR, 776 SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR,
708 show_therm_max, set_therm_max, 0+11), 777 show_therm_max, set_therm_max, 0 + 11),
709 SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR, 778 SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR,
710 show_therm_max, set_therm_max, 1+11), 779 show_therm_max, set_therm_max, 1 + 11),
711 SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR, 780 SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR,
712 show_therm_max, set_therm_max, 2+11), 781 show_therm_max, set_therm_max, 2 + 11),
713}; 782};
714static struct sensor_device_attribute therm_crit[] = { 783static struct sensor_device_attribute therm_crit[] = {
715 SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR, 784 SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR,
716 show_therm_crit, set_therm_crit, 0+11), 785 show_therm_crit, set_therm_crit, 0 + 11),
717 SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR, 786 SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR,
718 show_therm_crit, set_therm_crit, 1+11), 787 show_therm_crit, set_therm_crit, 1 + 11),
719 SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR, 788 SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR,
720 show_therm_crit, set_therm_crit, 2+11), 789 show_therm_crit, set_therm_crit, 2 + 11),
721}; 790};
722 791
723/* 792/*
@@ -752,27 +821,27 @@ static ssize_t show_therm_crit_alarm(struct device *dev,
752 821
753static struct sensor_device_attribute therm_min_alarm[] = { 822static struct sensor_device_attribute therm_min_alarm[] = {
754 SENSOR_ATTR(temp4_min_alarm, S_IRUGO, 823 SENSOR_ATTR(temp4_min_alarm, S_IRUGO,
755 show_therm_min_alarm, NULL, 0+11), 824 show_therm_min_alarm, NULL, 0 + 11),
756 SENSOR_ATTR(temp5_min_alarm, S_IRUGO, 825 SENSOR_ATTR(temp5_min_alarm, S_IRUGO,
757 show_therm_min_alarm, NULL, 1+11), 826 show_therm_min_alarm, NULL, 1 + 11),
758 SENSOR_ATTR(temp6_min_alarm, S_IRUGO, 827 SENSOR_ATTR(temp6_min_alarm, S_IRUGO,
759 show_therm_min_alarm, NULL, 2+11), 828 show_therm_min_alarm, NULL, 2 + 11),
760}; 829};
761static struct sensor_device_attribute therm_max_alarm[] = { 830static struct sensor_device_attribute therm_max_alarm[] = {
762 SENSOR_ATTR(temp4_max_alarm, S_IRUGO, 831 SENSOR_ATTR(temp4_max_alarm, S_IRUGO,
763 show_therm_max_alarm, NULL, 0+11), 832 show_therm_max_alarm, NULL, 0 + 11),
764 SENSOR_ATTR(temp5_max_alarm, S_IRUGO, 833 SENSOR_ATTR(temp5_max_alarm, S_IRUGO,
765 show_therm_max_alarm, NULL, 1+11), 834 show_therm_max_alarm, NULL, 1 + 11),
766 SENSOR_ATTR(temp6_max_alarm, S_IRUGO, 835 SENSOR_ATTR(temp6_max_alarm, S_IRUGO,
767 show_therm_max_alarm, NULL, 2+11), 836 show_therm_max_alarm, NULL, 2 + 11),
768}; 837};
769static struct sensor_device_attribute therm_crit_alarm[] = { 838static struct sensor_device_attribute therm_crit_alarm[] = {
770 SENSOR_ATTR(temp4_crit_alarm, S_IRUGO, 839 SENSOR_ATTR(temp4_crit_alarm, S_IRUGO,
771 show_therm_crit_alarm, NULL, 0+11), 840 show_therm_crit_alarm, NULL, 0 + 11),
772 SENSOR_ATTR(temp5_crit_alarm, S_IRUGO, 841 SENSOR_ATTR(temp5_crit_alarm, S_IRUGO,
773 show_therm_crit_alarm, NULL, 1+11), 842 show_therm_crit_alarm, NULL, 1 + 11),
774 SENSOR_ATTR(temp6_crit_alarm, S_IRUGO, 843 SENSOR_ATTR(temp6_crit_alarm, S_IRUGO,
775 show_therm_crit_alarm, NULL, 2+11), 844 show_therm_crit_alarm, NULL, 2 + 11),
776}; 845};
777 846
778#define THERM_UNIT_ATTRS(X) \ 847#define THERM_UNIT_ATTRS(X) \
@@ -785,7 +854,7 @@ static struct sensor_device_attribute therm_crit_alarm[] = {
785 &therm_max_alarm[X].dev_attr.attr, \ 854 &therm_max_alarm[X].dev_attr.attr, \
786 &therm_crit_alarm[X].dev_attr.attr 855 &therm_crit_alarm[X].dev_attr.attr
787 856
788static struct attribute * pc8736x_therm_attr_array[] = { 857static struct attribute *pc8736x_therm_attr_array[] = {
789 THERM_UNIT_ATTRS(0), 858 THERM_UNIT_ATTRS(0),
790 THERM_UNIT_ATTRS(1), 859 THERM_UNIT_ATTRS(1),
791 THERM_UNIT_ATTRS(2), 860 THERM_UNIT_ATTRS(2),
@@ -795,42 +864,59 @@ static const struct attribute_group pc8736x_therm_group = {
795 .attrs = pc8736x_therm_attr_array, 864 .attrs = pc8736x_therm_attr_array,
796}; 865};
797 866
798static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf) 867static ssize_t show_temp_input(struct device *dev,
868 struct device_attribute *devattr, char *buf)
799{ 869{
800 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 870 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
801 struct pc87360_data *data = pc87360_update_device(dev); 871 struct pc87360_data *data = pc87360_update_device(dev);
802 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])); 872 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
803} 873}
804static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf) 874
875static ssize_t show_temp_min(struct device *dev,
876 struct device_attribute *devattr, char *buf)
805{ 877{
806 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 878 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
807 struct pc87360_data *data = pc87360_update_device(dev); 879 struct pc87360_data *data = pc87360_update_device(dev);
808 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index])); 880 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index]));
809} 881}
810static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf) 882
883static ssize_t show_temp_max(struct device *dev,
884 struct device_attribute *devattr, char *buf)
811{ 885{
812 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 886 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
813 struct pc87360_data *data = pc87360_update_device(dev); 887 struct pc87360_data *data = pc87360_update_device(dev);
814 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index])); 888 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index]));
815} 889}
816static ssize_t show_temp_crit(struct device *dev, struct device_attribute *devattr, char *buf) 890
891static ssize_t show_temp_crit(struct device *dev,
892 struct device_attribute *devattr, char *buf)
817{ 893{
818 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 894 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
819 struct pc87360_data *data = pc87360_update_device(dev); 895 struct pc87360_data *data = pc87360_update_device(dev);
820 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[attr->index])); 896 return sprintf(buf, "%d\n",
897 TEMP_FROM_REG(data->temp_crit[attr->index]));
821} 898}
822static ssize_t show_temp_status(struct device *dev, struct device_attribute *devattr, char *buf) 899
900static ssize_t show_temp_status(struct device *dev,
901 struct device_attribute *devattr, char *buf)
823{ 902{
824 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 903 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
825 struct pc87360_data *data = pc87360_update_device(dev); 904 struct pc87360_data *data = pc87360_update_device(dev);
826 return sprintf(buf, "%d\n", data->temp_status[attr->index]); 905 return sprintf(buf, "%d\n", data->temp_status[attr->index]);
827} 906}
828static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf, 907
829 size_t count) 908static ssize_t set_temp_min(struct device *dev,
909 struct device_attribute *devattr,
910 const char *buf, size_t count)
830{ 911{
831 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 912 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
832 struct pc87360_data *data = dev_get_drvdata(dev); 913 struct pc87360_data *data = dev_get_drvdata(dev);
833 long val = simple_strtol(buf, NULL, 10); 914 long val;
915 int err;
916
917 err = kstrtol(buf, 10, &val);
918 if (err)
919 return err;
834 920
835 mutex_lock(&data->update_lock); 921 mutex_lock(&data->update_lock);
836 data->temp_min[attr->index] = TEMP_TO_REG(val); 922 data->temp_min[attr->index] = TEMP_TO_REG(val);
@@ -839,12 +925,19 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr
839 mutex_unlock(&data->update_lock); 925 mutex_unlock(&data->update_lock);
840 return count; 926 return count;
841} 927}
842static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, 928
843 size_t count) 929static ssize_t set_temp_max(struct device *dev,
930 struct device_attribute *devattr,
931 const char *buf, size_t count)
844{ 932{
845 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 933 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
846 struct pc87360_data *data = dev_get_drvdata(dev); 934 struct pc87360_data *data = dev_get_drvdata(dev);
847 long val = simple_strtol(buf, NULL, 10); 935 long val;
936 int err;
937
938 err = kstrtol(buf, 10, &val);
939 if (err)
940 return err;
848 941
849 mutex_lock(&data->update_lock); 942 mutex_lock(&data->update_lock);
850 data->temp_max[attr->index] = TEMP_TO_REG(val); 943 data->temp_max[attr->index] = TEMP_TO_REG(val);
@@ -853,12 +946,19 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr
853 mutex_unlock(&data->update_lock); 946 mutex_unlock(&data->update_lock);
854 return count; 947 return count;
855} 948}
856static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf, 949
857 size_t count) 950static ssize_t set_temp_crit(struct device *dev,
951 struct device_attribute *devattr, const char *buf,
952 size_t count)
858{ 953{
859 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 954 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
860 struct pc87360_data *data = dev_get_drvdata(dev); 955 struct pc87360_data *data = dev_get_drvdata(dev);
861 long val = simple_strtol(buf, NULL, 10); 956 long val;
957 int err;
958
959 err = kstrtol(buf, 10, &val);
960 if (err)
961 return err;
862 962
863 mutex_lock(&data->update_lock); 963 mutex_lock(&data->update_lock);
864 data->temp_crit[attr->index] = TEMP_TO_REG(val); 964 data->temp_crit[attr->index] = TEMP_TO_REG(val);
@@ -903,11 +1003,13 @@ static struct sensor_device_attribute temp_crit[] = {
903 show_temp_crit, set_temp_crit, 2), 1003 show_temp_crit, set_temp_crit, 2),
904}; 1004};
905 1005
906static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *attr, char *buf) 1006static ssize_t show_temp_alarms(struct device *dev,
1007 struct device_attribute *attr, char *buf)
907{ 1008{
908 struct pc87360_data *data = pc87360_update_device(dev); 1009 struct pc87360_data *data = pc87360_update_device(dev);
909 return sprintf(buf, "%u\n", data->temp_alarms); 1010 return sprintf(buf, "%u\n", data->temp_alarms);
910} 1011}
1012
911static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); 1013static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL);
912 1014
913/* 1015/*
@@ -924,6 +1026,7 @@ static ssize_t show_temp_min_alarm(struct device *dev,
924 1026
925 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN)); 1027 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN));
926} 1028}
1029
927static ssize_t show_temp_max_alarm(struct device *dev, 1030static ssize_t show_temp_max_alarm(struct device *dev,
928 struct device_attribute *devattr, char *buf) 1031 struct device_attribute *devattr, char *buf)
929{ 1032{
@@ -932,6 +1035,7 @@ static ssize_t show_temp_max_alarm(struct device *dev,
932 1035
933 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX)); 1036 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX));
934} 1037}
1038
935static ssize_t show_temp_crit_alarm(struct device *dev, 1039static ssize_t show_temp_crit_alarm(struct device *dev,
936 struct device_attribute *devattr, char *buf) 1040 struct device_attribute *devattr, char *buf)
937{ 1041{
@@ -946,11 +1050,13 @@ static struct sensor_device_attribute temp_min_alarm[] = {
946 SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 1), 1050 SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 1),
947 SENSOR_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 2), 1051 SENSOR_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 2),
948}; 1052};
1053
949static struct sensor_device_attribute temp_max_alarm[] = { 1054static struct sensor_device_attribute temp_max_alarm[] = {
950 SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 0), 1055 SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 0),
951 SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 1), 1056 SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 1),
952 SENSOR_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 2), 1057 SENSOR_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 2),
953}; 1058};
1059
954static struct sensor_device_attribute temp_crit_alarm[] = { 1060static struct sensor_device_attribute temp_crit_alarm[] = {
955 SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 0), 1061 SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 0),
956 SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 1), 1062 SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 1),
@@ -983,7 +1089,7 @@ static struct sensor_device_attribute temp_fault[] = {
983 &temp_crit_alarm[X].dev_attr.attr, \ 1089 &temp_crit_alarm[X].dev_attr.attr, \
984 &temp_fault[X].dev_attr.attr 1090 &temp_fault[X].dev_attr.attr
985 1091
986static struct attribute * pc8736x_temp_attr_array[] = { 1092static struct attribute *pc8736x_temp_attr_array[] = {
987 TEMP_UNIT_ATTRS(0), 1093 TEMP_UNIT_ATTRS(0),
988 TEMP_UNIT_ATTRS(1), 1094 TEMP_UNIT_ATTRS(1),
989 TEMP_UNIT_ATTRS(2), 1095 TEMP_UNIT_ATTRS(2),
@@ -991,6 +1097,7 @@ static struct attribute * pc8736x_temp_attr_array[] = {
991 &dev_attr_alarms_temp.attr, 1097 &dev_attr_alarms_temp.attr,
992 NULL 1098 NULL
993}; 1099};
1100
994static const struct attribute_group pc8736x_temp_group = { 1101static const struct attribute_group pc8736x_temp_group = {
995 .attrs = pc8736x_temp_attr_array, 1102 .attrs = pc8736x_temp_attr_array,
996}; 1103};
@@ -1001,13 +1108,15 @@ static ssize_t show_name(struct device *dev,
1001 struct pc87360_data *data = dev_get_drvdata(dev); 1108 struct pc87360_data *data = dev_get_drvdata(dev);
1002 return sprintf(buf, "%s\n", data->name); 1109 return sprintf(buf, "%s\n", data->name);
1003} 1110}
1111
1004static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 1112static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1005 1113
1006/* 1114/*
1007 * Device detection, registration and update 1115 * Device detection, registration and update
1008 */ 1116 */
1009 1117
1010static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses) 1118static int __init pc87360_find(int sioaddr, u8 *devid,
1119 unsigned short *addresses)
1011{ 1120{
1012 u16 val; 1121 u16 val;
1013 int i; 1122 int i;
@@ -1054,7 +1163,7 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1054 1163
1055 addresses[i] = val; 1164 addresses[i] = val;
1056 1165
1057 if (i==0) { /* Fans */ 1166 if (i == 0) { /* Fans */
1058 confreg[0] = superio_inb(sioaddr, 0xF0); 1167 confreg[0] = superio_inb(sioaddr, 0xF0);
1059 confreg[1] = superio_inb(sioaddr, 0xF1); 1168 confreg[1] = superio_inb(sioaddr, 0xF1);
1060 1169
@@ -1067,7 +1176,7 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1067 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3, 1176 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3,
1068 confreg[1] & 1, (confreg[1] >> 1) & 1, 1177 confreg[1] & 1, (confreg[1] >> 1) & 1,
1069 (confreg[1] >> 2) & 1); 1178 (confreg[1] >> 2) & 1);
1070 } else if (i==1) { /* Voltages */ 1179 } else if (i == 1) { /* Voltages */
1071 /* Are we using thermistors? */ 1180 /* Are we using thermistors? */
1072 if (*devid == 0xE9) { /* PC87366 */ 1181 if (*devid == 0xE9) { /* PC87366 */
1073 /* 1182 /*
@@ -1103,7 +1212,8 @@ static int __devinit pc87360_probe(struct platform_device *pdev)
1103 int use_thermistors = 0; 1212 int use_thermistors = 0;
1104 struct device *dev = &pdev->dev; 1213 struct device *dev = &pdev->dev;
1105 1214
1106 if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL))) 1215 data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL);
1216 if (!data)
1107 return -ENOMEM; 1217 return -ENOMEM;
1108 1218
1109 data->fannr = 2; 1219 data->fannr = 2;
@@ -1139,9 +1249,10 @@ static int __devinit pc87360_probe(struct platform_device *pdev)
1139 platform_set_drvdata(pdev, data); 1249 platform_set_drvdata(pdev, data);
1140 1250
1141 for (i = 0; i < LDNI_MAX; i++) { 1251 for (i = 0; i < LDNI_MAX; i++) {
1142 if (((data->address[i] = extra_isa[i])) 1252 data->address[i] = extra_isa[i];
1253 if (data->address[i]
1143 && !request_region(extra_isa[i], PC87360_EXTENT, 1254 && !request_region(extra_isa[i], PC87360_EXTENT,
1144 pc87360_driver.driver.name)) { 1255 pc87360_driver.driver.name)) {
1145 dev_err(dev, "Region 0x%x-0x%x already " 1256 dev_err(dev, "Region 0x%x-0x%x already "
1146 "in use!\n", extra_isa[i], 1257 "in use!\n", extra_isa[i],
1147 extra_isa[i]+PC87360_EXTENT-1); 1258 extra_isa[i]+PC87360_EXTENT-1);
@@ -1193,15 +1304,17 @@ static int __devinit pc87360_probe(struct platform_device *pdev)
1193 1304
1194 /* Register all-or-nothing sysfs groups */ 1305 /* Register all-or-nothing sysfs groups */
1195 1306
1196 if (data->innr && 1307 if (data->innr) {
1197 (err = sysfs_create_group(&dev->kobj, 1308 err = sysfs_create_group(&dev->kobj, &pc8736x_vin_group);
1198 &pc8736x_vin_group))) 1309 if (err)
1199 goto ERROR3; 1310 goto ERROR3;
1311 }
1200 1312
1201 if (data->innr == 14 && 1313 if (data->innr == 14) {
1202 (err = sysfs_create_group(&dev->kobj, 1314 err = sysfs_create_group(&dev->kobj, &pc8736x_therm_group);
1203 &pc8736x_therm_group))) 1315 if (err)
1204 goto ERROR3; 1316 goto ERROR3;
1317 }
1205 1318
1206 /* create device attr-files for varying sysfs groups */ 1319 /* create device attr-files for varying sysfs groups */
1207 1320
@@ -1227,7 +1340,8 @@ static int __devinit pc87360_probe(struct platform_device *pdev)
1227 &temp_fault[i].dev_attr))) 1340 &temp_fault[i].dev_attr)))
1228 goto ERROR3; 1341 goto ERROR3;
1229 } 1342 }
1230 if ((err = device_create_file(dev, &dev_attr_alarms_temp))) 1343 err = device_create_file(dev, &dev_attr_alarms_temp);
1344 if (err)
1231 goto ERROR3; 1345 goto ERROR3;
1232 } 1346 }
1233 1347
@@ -1243,12 +1357,15 @@ static int __devinit pc87360_probe(struct platform_device *pdev)
1243 &fan_status[i].dev_attr)))) 1357 &fan_status[i].dev_attr))))
1244 goto ERROR3; 1358 goto ERROR3;
1245 1359
1246 if (FAN_CONFIG_CONTROL(data->fan_conf, i) 1360 if (FAN_CONFIG_CONTROL(data->fan_conf, i)) {
1247 && (err = device_create_file(dev, &pwm[i].dev_attr))) 1361 err = device_create_file(dev, &pwm[i].dev_attr);
1248 goto ERROR3; 1362 if (err)
1363 goto ERROR3;
1364 }
1249 } 1365 }
1250 1366
1251 if ((err = device_create_file(dev, &dev_attr_name))) 1367 err = device_create_file(dev, &dev_attr_name);
1368 if (err)
1252 goto ERROR3; 1369 goto ERROR3;
1253 1370
1254 data->hwmon_dev = hwmon_device_register(dev); 1371 data->hwmon_dev = hwmon_device_register(dev);
@@ -1266,9 +1383,8 @@ ERROR3:
1266 sysfs_remove_group(&dev->kobj, &pc8736x_therm_group); 1383 sysfs_remove_group(&dev->kobj, &pc8736x_therm_group);
1267 sysfs_remove_group(&dev->kobj, &pc8736x_vin_group); 1384 sysfs_remove_group(&dev->kobj, &pc8736x_vin_group);
1268 for (i = 0; i < 3; i++) { 1385 for (i = 0; i < 3; i++) {
1269 if (data->address[i]) { 1386 if (data->address[i])
1270 release_region(data->address[i], PC87360_EXTENT); 1387 release_region(data->address[i], PC87360_EXTENT);
1271 }
1272 } 1388 }
1273ERROR1: 1389ERROR1:
1274 kfree(data); 1390 kfree(data);
@@ -1289,9 +1405,8 @@ static int __devexit pc87360_remove(struct platform_device *pdev)
1289 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_vin_group); 1405 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_vin_group);
1290 1406
1291 for (i = 0; i < 3; i++) { 1407 for (i = 0; i < 3; i++) {
1292 if (data->address[i]) { 1408 if (data->address[i])
1293 release_region(data->address[i], PC87360_EXTENT); 1409 release_region(data->address[i], PC87360_EXTENT);
1294 }
1295 } 1410 }
1296 kfree(data); 1411 kfree(data);
1297 1412
@@ -1390,12 +1505,12 @@ static void pc87360_init_device(struct platform_device *pdev,
1390 for (; i < data->tempnr; i++) { 1505 for (; i < data->tempnr; i++) {
1391 reg = pc87360_read_value(data, LD_TEMP, i, 1506 reg = pc87360_read_value(data, LD_TEMP, i,
1392 PC87365_REG_TEMP_STATUS); 1507 PC87365_REG_TEMP_STATUS);
1393 dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i+1, reg); 1508 dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i + 1, reg);
1394 if (init >= init_temp[i]) { 1509 if (init >= init_temp[i]) {
1395 /* Forcibly enable temperature channel */ 1510 /* Forcibly enable temperature channel */
1396 if (!(reg & CHAN_ENA)) { 1511 if (!(reg & CHAN_ENA)) {
1397 dev_dbg(&pdev->dev, "Forcibly " 1512 dev_dbg(&pdev->dev,
1398 "enabling temp%d\n", i+1); 1513 "Forcibly enabling temp%d\n", i + 1);
1399 pc87360_write_value(data, LD_TEMP, i, 1514 pc87360_write_value(data, LD_TEMP, i,
1400 PC87365_REG_TEMP_STATUS, 1515 PC87365_REG_TEMP_STATUS,
1401 0xCF); 1516 0xCF);
@@ -1411,11 +1526,11 @@ static void pc87360_init_device(struct platform_device *pdev,
1411 * diodes 1526 * diodes
1412 */ 1527 */
1413 reg = pc87360_read_value(data, LD_TEMP, 1528 reg = pc87360_read_value(data, LD_TEMP,
1414 (i-11)/2, PC87365_REG_TEMP_STATUS); 1529 (i - 11) / 2, PC87365_REG_TEMP_STATUS);
1415 if (reg & CHAN_ENA) { 1530 if (reg & CHAN_ENA) {
1416 dev_dbg(&pdev->dev, "Skipping " 1531 dev_dbg(&pdev->dev,
1417 "temp%d, pin already in use " 1532 "Skipping temp%d, pin already in use by temp%d\n",
1418 "by temp%d\n", i-7, (i-11)/2); 1533 i - 7, (i - 11) / 2);
1419 continue; 1534 continue;
1420 } 1535 }
1421 1536
@@ -1423,8 +1538,9 @@ static void pc87360_init_device(struct platform_device *pdev,
1423 reg = pc87360_read_value(data, LD_IN, i, 1538 reg = pc87360_read_value(data, LD_IN, i,
1424 PC87365_REG_IN_STATUS); 1539 PC87365_REG_IN_STATUS);
1425 if (!(reg & CHAN_ENA)) { 1540 if (!(reg & CHAN_ENA)) {
1426 dev_dbg(&pdev->dev, "Forcibly " 1541 dev_dbg(&pdev->dev,
1427 "enabling temp%d\n", i-7); 1542 "Forcibly enabling temp%d\n",
1543 i - 7);
1428 pc87360_write_value(data, LD_IN, i, 1544 pc87360_write_value(data, LD_IN, i,
1429 PC87365_REG_TEMP_STATUS, 1545 PC87365_REG_TEMP_STATUS,
1430 (reg & 0x60) | 0x8F); 1546 (reg & 0x60) | 0x8F);
@@ -1438,8 +1554,8 @@ static void pc87360_init_device(struct platform_device *pdev,
1438 PC87365_REG_IN_CONFIG); 1554 PC87365_REG_IN_CONFIG);
1439 dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg); 1555 dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg);
1440 if (reg & CHAN_ENA) { 1556 if (reg & CHAN_ENA) {
1441 dev_dbg(&pdev->dev, "Forcibly " 1557 dev_dbg(&pdev->dev,
1442 "enabling monitoring (VLM)\n"); 1558 "Forcibly enabling monitoring (VLM)\n");
1443 pc87360_write_value(data, LD_IN, NO_BANK, 1559 pc87360_write_value(data, LD_IN, NO_BANK,
1444 PC87365_REG_IN_CONFIG, 1560 PC87365_REG_IN_CONFIG,
1445 reg & 0xFE); 1561 reg & 0xFE);
@@ -1451,8 +1567,8 @@ static void pc87360_init_device(struct platform_device *pdev,
1451 PC87365_REG_TEMP_CONFIG); 1567 PC87365_REG_TEMP_CONFIG);
1452 dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg); 1568 dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg);
1453 if (reg & CHAN_ENA) { 1569 if (reg & CHAN_ENA) {
1454 dev_dbg(&pdev->dev, "Forcibly enabling " 1570 dev_dbg(&pdev->dev,
1455 "monitoring (TMS)\n"); 1571 "Forcibly enabling monitoring (TMS)\n");
1456 pc87360_write_value(data, LD_TEMP, NO_BANK, 1572 pc87360_write_value(data, LD_TEMP, NO_BANK,
1457 PC87365_REG_TEMP_CONFIG, 1573 PC87365_REG_TEMP_CONFIG,
1458 reg & 0xFE); 1574 reg & 0xFE);
@@ -1489,7 +1605,7 @@ static void pc87360_autodiv(struct device *dev, int nr)
1489 data->fan[nr] >>= 1; 1605 data->fan[nr] >>= 1;
1490 dev_dbg(dev, "Increasing " 1606 dev_dbg(dev, "Increasing "
1491 "clock divider to %d for fan %d\n", 1607 "clock divider to %d for fan %d\n",
1492 FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1); 1608 FAN_DIV_FROM_REG(data->fan_status[nr]), nr + 1);
1493 } 1609 }
1494 } else { 1610 } else {
1495 /* Decrease clock divider if possible */ 1611 /* Decrease clock divider if possible */
@@ -1502,7 +1618,7 @@ static void pc87360_autodiv(struct device *dev, int nr)
1502 dev_dbg(dev, "Decreasing " 1618 dev_dbg(dev, "Decreasing "
1503 "clock divider to %d for fan %d\n", 1619 "clock divider to %d for fan %d\n",
1504 FAN_DIV_FROM_REG(data->fan_status[nr]), 1620 FAN_DIV_FROM_REG(data->fan_status[nr]),
1505 nr+1); 1621 nr + 1);
1506 } 1622 }
1507 } 1623 }
1508 1624