aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm85.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lm85.c')
-rw-r--r--drivers/hwmon/lm85.c704
1 files changed, 345 insertions, 359 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 20a8c648280d..a02480be65f2 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -30,6 +30,7 @@
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/hwmon.h> 31#include <linux/hwmon.h>
32#include <linux/hwmon-vid.h> 32#include <linux/hwmon-vid.h>
33#include <linux/hwmon-sysfs.h>
33#include <linux/err.h> 34#include <linux/err.h>
34#include <linux/mutex.h> 35#include <linux/mutex.h>
35 36
@@ -122,23 +123,6 @@ I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
122#define EMC6D102_REG_EXTEND_ADC3 0x87 123#define EMC6D102_REG_EXTEND_ADC3 0x87
123#define EMC6D102_REG_EXTEND_ADC4 0x88 124#define EMC6D102_REG_EXTEND_ADC4 0x88
124 125
125#define LM85_ALARM_IN0 0x0001
126#define LM85_ALARM_IN1 0x0002
127#define LM85_ALARM_IN2 0x0004
128#define LM85_ALARM_IN3 0x0008
129#define LM85_ALARM_TEMP1 0x0010
130#define LM85_ALARM_TEMP2 0x0020
131#define LM85_ALARM_TEMP3 0x0040
132#define LM85_ALARM_ALARM2 0x0080
133#define LM85_ALARM_IN4 0x0100
134#define LM85_ALARM_RESERVED 0x0200
135#define LM85_ALARM_FAN1 0x0400
136#define LM85_ALARM_FAN2 0x0800
137#define LM85_ALARM_FAN3 0x1000
138#define LM85_ALARM_FAN4 0x2000
139#define LM85_ALARM_TEMP1_FAULT 0x4000
140#define LM85_ALARM_TEMP3_FAULT 0x8000
141
142 126
143/* Conversions. Rounding and limit checking is only done on the TO_REG 127/* Conversions. Rounding and limit checking is only done on the TO_REG
144 variants. Note that you should be a bit careful with which arguments 128 variants. Note that you should be a bit careful with which arguments
@@ -155,22 +139,26 @@ static int lm85_scaling[] = { /* .001 Volts */
155#define INS_TO_REG(n,val) \ 139#define INS_TO_REG(n,val) \
156 SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255) 140 SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255)
157 141
158#define INSEXT_FROM_REG(n,val,ext,scale) \ 142#define INSEXT_FROM_REG(n,val,ext) \
159 SCALE((val)*(scale) + (ext),192*(scale),lm85_scaling[n]) 143 SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
160 144
161#define INS_FROM_REG(n,val) INSEXT_FROM_REG(n,val,0,1) 145#define INS_FROM_REG(n,val) SCALE((val), 192, lm85_scaling[n])
162 146
163/* FAN speed is measured using 90kHz clock */ 147/* FAN speed is measured using 90kHz clock */
164#define FAN_TO_REG(val) (SENSORS_LIMIT( (val)<=0?0: 5400000/(val),0,65534)) 148static inline u16 FAN_TO_REG(unsigned long val)
149{
150 if (!val)
151 return 0xffff;
152 return SENSORS_LIMIT(5400000 / val, 1, 0xfffe);
153}
165#define FAN_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:5400000/(val)) 154#define FAN_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:5400000/(val))
166 155
167/* Temperature is reported in .001 degC increments */ 156/* Temperature is reported in .001 degC increments */
168#define TEMP_TO_REG(val) \ 157#define TEMP_TO_REG(val) \
169 SENSORS_LIMIT(SCALE(val,1000,1),-127,127) 158 SENSORS_LIMIT(SCALE(val,1000,1),-127,127)
170#define TEMPEXT_FROM_REG(val,ext,scale) \ 159#define TEMPEXT_FROM_REG(val,ext) \
171 SCALE((val)*scale + (ext),scale,1000) 160 SCALE(((val) << 4) + (ext), 16, 1000)
172#define TEMP_FROM_REG(val) \ 161#define TEMP_FROM_REG(val) ((val) * 1000)
173 TEMPEXT_FROM_REG(val,0,1)
174 162
175#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255)) 163#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
176#define PWM_FROM_REG(val) (val) 164#define PWM_FROM_REG(val) (val)
@@ -328,7 +316,7 @@ struct lm85_autofan {
328 The structure is dynamically allocated. */ 316 The structure is dynamically allocated. */
329struct lm85_data { 317struct lm85_data {
330 struct i2c_client client; 318 struct i2c_client client;
331 struct class_device *class_dev; 319 struct device *hwmon_dev;
332 enum chips type; 320 enum chips type;
333 321
334 struct mutex update_lock; 322 struct mutex update_lock;
@@ -350,7 +338,6 @@ struct lm85_data {
350 u8 tach_mode; /* Register encoding, combined */ 338 u8 tach_mode; /* Register encoding, combined */
351 u8 temp_ext[3]; /* Decoded values */ 339 u8 temp_ext[3]; /* Decoded values */
352 u8 in_ext[8]; /* Decoded values */ 340 u8 in_ext[8]; /* Decoded values */
353 u8 adc_scale; /* ADC Extended bits scaling factor */
354 u8 fan_ppr; /* Register value */ 341 u8 fan_ppr; /* Register value */
355 u8 smooth[3]; /* Register encoding */ 342 u8 smooth[3]; /* Register encoding */
356 u8 vid; /* Register value */ 343 u8 vid; /* Register value */
@@ -387,22 +374,29 @@ static struct i2c_driver lm85_driver = {
387 374
388 375
389/* 4 Fans */ 376/* 4 Fans */
390static ssize_t show_fan(struct device *dev, char *buf, int nr) 377static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
378 char *buf)
391{ 379{
380 int nr = to_sensor_dev_attr(attr)->index;
392 struct lm85_data *data = lm85_update_device(dev); 381 struct lm85_data *data = lm85_update_device(dev);
393 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr]) ); 382 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr]) );
394} 383}
395static ssize_t show_fan_min(struct device *dev, char *buf, int nr) 384
385static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
386 char *buf)
396{ 387{
388 int nr = to_sensor_dev_attr(attr)->index;
397 struct lm85_data *data = lm85_update_device(dev); 389 struct lm85_data *data = lm85_update_device(dev);
398 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr]) ); 390 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr]) );
399} 391}
400static ssize_t set_fan_min(struct device *dev, const char *buf, 392
401 size_t count, int nr) 393static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
394 const char *buf, size_t count)
402{ 395{
396 int nr = to_sensor_dev_attr(attr)->index;
403 struct i2c_client *client = to_i2c_client(dev); 397 struct i2c_client *client = to_i2c_client(dev);
404 struct lm85_data *data = i2c_get_clientdata(client); 398 struct lm85_data *data = i2c_get_clientdata(client);
405 long val = simple_strtol(buf, NULL, 10); 399 unsigned long val = simple_strtoul(buf, NULL, 10);
406 400
407 mutex_lock(&data->update_lock); 401 mutex_lock(&data->update_lock);
408 data->fan_min[nr] = FAN_TO_REG(val); 402 data->fan_min[nr] = FAN_TO_REG(val);
@@ -412,23 +406,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
412} 406}
413 407
414#define show_fan_offset(offset) \ 408#define show_fan_offset(offset) \
415static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 409static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
416{ \ 410 show_fan, NULL, offset - 1); \
417 return show_fan(dev, buf, offset - 1); \ 411static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
418} \ 412 show_fan_min, set_fan_min, offset - 1)
419static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
420{ \
421 return show_fan_min(dev, buf, offset - 1); \
422} \
423static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \
424 const char *buf, size_t count) \
425{ \
426 return set_fan_min(dev, buf, count, offset - 1); \
427} \
428static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, \
429 NULL); \
430static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
431 show_fan_##offset##_min, set_fan_##offset##_min);
432 413
433show_fan_offset(1); 414show_fan_offset(1);
434show_fan_offset(2); 415show_fan_offset(2);
@@ -457,7 +438,7 @@ static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
457 438
458static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 439static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
459{ 440{
460 struct lm85_data *data = lm85_update_device(dev); 441 struct lm85_data *data = dev_get_drvdata(dev);
461 return sprintf(buf, "%ld\n", (long) data->vrm); 442 return sprintf(buf, "%ld\n", (long) data->vrm);
462} 443}
463 444
@@ -482,16 +463,46 @@ static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr
482 463
483static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 464static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
484 465
466static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
467 char *buf)
468{
469 int nr = to_sensor_dev_attr(attr)->index;
470 struct lm85_data *data = lm85_update_device(dev);
471 return sprintf(buf, "%u\n", (data->alarms >> nr) & 1);
472}
473
474static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
475static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
476static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
477static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
478static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
479static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 18);
480static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 16);
481static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 17);
482static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
483static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
484static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
485static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 6);
486static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15);
487static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10);
488static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11);
489static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 12);
490static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 13);
491
485/* pwm */ 492/* pwm */
486 493
487static ssize_t show_pwm(struct device *dev, char *buf, int nr) 494static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
495 char *buf)
488{ 496{
497 int nr = to_sensor_dev_attr(attr)->index;
489 struct lm85_data *data = lm85_update_device(dev); 498 struct lm85_data *data = lm85_update_device(dev);
490 return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm[nr]) ); 499 return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm[nr]) );
491} 500}
492static ssize_t set_pwm(struct device *dev, const char *buf, 501
493 size_t count, int nr) 502static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
503 const char *buf, size_t count)
494{ 504{
505 int nr = to_sensor_dev_attr(attr)->index;
495 struct i2c_client *client = to_i2c_client(dev); 506 struct i2c_client *client = to_i2c_client(dev);
496 struct lm85_data *data = i2c_get_clientdata(client); 507 struct lm85_data *data = i2c_get_clientdata(client);
497 long val = simple_strtol(buf, NULL, 10); 508 long val = simple_strtol(buf, NULL, 10);
@@ -502,8 +513,11 @@ static ssize_t set_pwm(struct device *dev, const char *buf,
502 mutex_unlock(&data->update_lock); 513 mutex_unlock(&data->update_lock);
503 return count; 514 return count;
504} 515}
505static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr) 516
517static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
518 *attr, char *buf)
506{ 519{
520 int nr = to_sensor_dev_attr(attr)->index;
507 struct lm85_data *data = lm85_update_device(dev); 521 struct lm85_data *data = lm85_update_device(dev);
508 int pwm_zone; 522 int pwm_zone;
509 523
@@ -512,23 +526,10 @@ static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr)
512} 526}
513 527
514#define show_pwm_reg(offset) \ 528#define show_pwm_reg(offset) \
515static ssize_t show_pwm_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 529static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
516{ \ 530 show_pwm, set_pwm, offset - 1); \
517 return show_pwm(dev, buf, offset - 1); \ 531static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO, \
518} \ 532 show_pwm_enable, NULL, offset - 1)
519static ssize_t set_pwm_##offset (struct device *dev, struct device_attribute *attr, \
520 const char *buf, size_t count) \
521{ \
522 return set_pwm(dev, buf, count, offset - 1); \
523} \
524static ssize_t show_pwm_enable##offset (struct device *dev, struct device_attribute *attr, char *buf) \
525{ \
526 return show_pwm_enable(dev, buf, offset - 1); \
527} \
528static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
529 show_pwm_##offset, set_pwm_##offset); \
530static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO, \
531 show_pwm_enable##offset, NULL);
532 533
533show_pwm_reg(1); 534show_pwm_reg(1);
534show_pwm_reg(2); 535show_pwm_reg(2);
@@ -536,22 +537,28 @@ show_pwm_reg(3);
536 537
537/* Voltages */ 538/* Voltages */
538 539
539static ssize_t show_in(struct device *dev, char *buf, int nr) 540static ssize_t show_in(struct device *dev, struct device_attribute *attr,
541 char *buf)
540{ 542{
543 int nr = to_sensor_dev_attr(attr)->index;
541 struct lm85_data *data = lm85_update_device(dev); 544 struct lm85_data *data = lm85_update_device(dev);
542 return sprintf( buf, "%d\n", INSEXT_FROM_REG(nr, 545 return sprintf( buf, "%d\n", INSEXT_FROM_REG(nr,
543 data->in[nr], 546 data->in[nr],
544 data->in_ext[nr], 547 data->in_ext[nr]));
545 data->adc_scale) );
546} 548}
547static ssize_t show_in_min(struct device *dev, char *buf, int nr) 549
550static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
551 char *buf)
548{ 552{
553 int nr = to_sensor_dev_attr(attr)->index;
549 struct lm85_data *data = lm85_update_device(dev); 554 struct lm85_data *data = lm85_update_device(dev);
550 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]) ); 555 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]) );
551} 556}
552static ssize_t set_in_min(struct device *dev, const char *buf, 557
553 size_t count, int nr) 558static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
559 const char *buf, size_t count)
554{ 560{
561 int nr = to_sensor_dev_attr(attr)->index;
555 struct i2c_client *client = to_i2c_client(dev); 562 struct i2c_client *client = to_i2c_client(dev);
556 struct lm85_data *data = i2c_get_clientdata(client); 563 struct lm85_data *data = i2c_get_clientdata(client);
557 long val = simple_strtol(buf, NULL, 10); 564 long val = simple_strtol(buf, NULL, 10);
@@ -562,14 +569,19 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
562 mutex_unlock(&data->update_lock); 569 mutex_unlock(&data->update_lock);
563 return count; 570 return count;
564} 571}
565static ssize_t show_in_max(struct device *dev, char *buf, int nr) 572
573static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
574 char *buf)
566{ 575{
576 int nr = to_sensor_dev_attr(attr)->index;
567 struct lm85_data *data = lm85_update_device(dev); 577 struct lm85_data *data = lm85_update_device(dev);
568 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]) ); 578 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]) );
569} 579}
570static ssize_t set_in_max(struct device *dev, const char *buf, 580
571 size_t count, int nr) 581static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
582 const char *buf, size_t count)
572{ 583{
584 int nr = to_sensor_dev_attr(attr)->index;
573 struct i2c_client *client = to_i2c_client(dev); 585 struct i2c_client *client = to_i2c_client(dev);
574 struct lm85_data *data = i2c_get_clientdata(client); 586 struct lm85_data *data = i2c_get_clientdata(client);
575 long val = simple_strtol(buf, NULL, 10); 587 long val = simple_strtol(buf, NULL, 10);
@@ -580,59 +592,47 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
580 mutex_unlock(&data->update_lock); 592 mutex_unlock(&data->update_lock);
581 return count; 593 return count;
582} 594}
595
583#define show_in_reg(offset) \ 596#define show_in_reg(offset) \
584static ssize_t show_in_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 597static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
585{ \ 598 show_in, NULL, offset); \
586 return show_in(dev, buf, offset); \ 599static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
587} \ 600 show_in_min, set_in_min, offset); \
588static ssize_t show_in_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 601static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
589{ \ 602 show_in_max, set_in_max, offset)
590 return show_in_min(dev, buf, offset); \
591} \
592static ssize_t show_in_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
593{ \
594 return show_in_max(dev, buf, offset); \
595} \
596static ssize_t set_in_##offset##_min (struct device *dev, struct device_attribute *attr, \
597 const char *buf, size_t count) \
598{ \
599 return set_in_min(dev, buf, count, offset); \
600} \
601static ssize_t set_in_##offset##_max (struct device *dev, struct device_attribute *attr, \
602 const char *buf, size_t count) \
603{ \
604 return set_in_max(dev, buf, count, offset); \
605} \
606static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in_##offset, \
607 NULL); \
608static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
609 show_in_##offset##_min, set_in_##offset##_min); \
610static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
611 show_in_##offset##_max, set_in_##offset##_max);
612 603
613show_in_reg(0); 604show_in_reg(0);
614show_in_reg(1); 605show_in_reg(1);
615show_in_reg(2); 606show_in_reg(2);
616show_in_reg(3); 607show_in_reg(3);
617show_in_reg(4); 608show_in_reg(4);
609show_in_reg(5);
610show_in_reg(6);
611show_in_reg(7);
618 612
619/* Temps */ 613/* Temps */
620 614
621static ssize_t show_temp(struct device *dev, char *buf, int nr) 615static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
616 char *buf)
622{ 617{
618 int nr = to_sensor_dev_attr(attr)->index;
623 struct lm85_data *data = lm85_update_device(dev); 619 struct lm85_data *data = lm85_update_device(dev);
624 return sprintf(buf,"%d\n", TEMPEXT_FROM_REG(data->temp[nr], 620 return sprintf(buf,"%d\n", TEMPEXT_FROM_REG(data->temp[nr],
625 data->temp_ext[nr], 621 data->temp_ext[nr]));
626 data->adc_scale) );
627} 622}
628static ssize_t show_temp_min(struct device *dev, char *buf, int nr) 623
624static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
625 char *buf)
629{ 626{
627 int nr = to_sensor_dev_attr(attr)->index;
630 struct lm85_data *data = lm85_update_device(dev); 628 struct lm85_data *data = lm85_update_device(dev);
631 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]) ); 629 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]) );
632} 630}
633static ssize_t set_temp_min(struct device *dev, const char *buf, 631
634 size_t count, int nr) 632static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
633 const char *buf, size_t count)
635{ 634{
635 int nr = to_sensor_dev_attr(attr)->index;
636 struct i2c_client *client = to_i2c_client(dev); 636 struct i2c_client *client = to_i2c_client(dev);
637 struct lm85_data *data = i2c_get_clientdata(client); 637 struct lm85_data *data = i2c_get_clientdata(client);
638 long val = simple_strtol(buf, NULL, 10); 638 long val = simple_strtol(buf, NULL, 10);
@@ -643,14 +643,19 @@ static ssize_t set_temp_min(struct device *dev, const char *buf,
643 mutex_unlock(&data->update_lock); 643 mutex_unlock(&data->update_lock);
644 return count; 644 return count;
645} 645}
646static ssize_t show_temp_max(struct device *dev, char *buf, int nr) 646
647static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
648 char *buf)
647{ 649{
650 int nr = to_sensor_dev_attr(attr)->index;
648 struct lm85_data *data = lm85_update_device(dev); 651 struct lm85_data *data = lm85_update_device(dev);
649 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) ); 652 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) );
650} 653}
651static ssize_t set_temp_max(struct device *dev, const char *buf, 654
652 size_t count, int nr) 655static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
656 const char *buf, size_t count)
653{ 657{
658 int nr = to_sensor_dev_attr(attr)->index;
654 struct i2c_client *client = to_i2c_client(dev); 659 struct i2c_client *client = to_i2c_client(dev);
655 struct lm85_data *data = i2c_get_clientdata(client); 660 struct lm85_data *data = i2c_get_clientdata(client);
656 long val = simple_strtol(buf, NULL, 10); 661 long val = simple_strtol(buf, NULL, 10);
@@ -661,35 +666,14 @@ static ssize_t set_temp_max(struct device *dev, const char *buf,
661 mutex_unlock(&data->update_lock); 666 mutex_unlock(&data->update_lock);
662 return count; 667 return count;
663} 668}
669
664#define show_temp_reg(offset) \ 670#define show_temp_reg(offset) \
665static ssize_t show_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 671static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
666{ \ 672 show_temp, NULL, offset - 1); \
667 return show_temp(dev, buf, offset - 1); \ 673static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
668} \ 674 show_temp_min, set_temp_min, offset - 1); \
669static ssize_t show_temp_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 675static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
670{ \ 676 show_temp_max, set_temp_max, offset - 1);
671 return show_temp_min(dev, buf, offset - 1); \
672} \
673static ssize_t show_temp_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
674{ \
675 return show_temp_max(dev, buf, offset - 1); \
676} \
677static ssize_t set_temp_##offset##_min (struct device *dev, struct device_attribute *attr, \
678 const char *buf, size_t count) \
679{ \
680 return set_temp_min(dev, buf, count, offset - 1); \
681} \
682static ssize_t set_temp_##offset##_max (struct device *dev, struct device_attribute *attr, \
683 const char *buf, size_t count) \
684{ \
685 return set_temp_max(dev, buf, count, offset - 1); \
686} \
687static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, \
688 NULL); \
689static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
690 show_temp_##offset##_min, set_temp_##offset##_min); \
691static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
692 show_temp_##offset##_max, set_temp_##offset##_max);
693 677
694show_temp_reg(1); 678show_temp_reg(1);
695show_temp_reg(2); 679show_temp_reg(2);
@@ -698,14 +682,18 @@ show_temp_reg(3);
698 682
699/* Automatic PWM control */ 683/* Automatic PWM control */
700 684
701static ssize_t show_pwm_auto_channels(struct device *dev, char *buf, int nr) 685static ssize_t show_pwm_auto_channels(struct device *dev,
686 struct device_attribute *attr, char *buf)
702{ 687{
688 int nr = to_sensor_dev_attr(attr)->index;
703 struct lm85_data *data = lm85_update_device(dev); 689 struct lm85_data *data = lm85_update_device(dev);
704 return sprintf(buf,"%d\n", ZONE_FROM_REG(data->autofan[nr].config)); 690 return sprintf(buf,"%d\n", ZONE_FROM_REG(data->autofan[nr].config));
705} 691}
706static ssize_t set_pwm_auto_channels(struct device *dev, const char *buf, 692
707 size_t count, int nr) 693static ssize_t set_pwm_auto_channels(struct device *dev,
694 struct device_attribute *attr, const char *buf, size_t count)
708{ 695{
696 int nr = to_sensor_dev_attr(attr)->index;
709 struct i2c_client *client = to_i2c_client(dev); 697 struct i2c_client *client = to_i2c_client(dev);
710 struct lm85_data *data = i2c_get_clientdata(client); 698 struct lm85_data *data = i2c_get_clientdata(client);
711 long val = simple_strtol(buf, NULL, 10); 699 long val = simple_strtol(buf, NULL, 10);
@@ -718,14 +706,19 @@ static ssize_t set_pwm_auto_channels(struct device *dev, const char *buf,
718 mutex_unlock(&data->update_lock); 706 mutex_unlock(&data->update_lock);
719 return count; 707 return count;
720} 708}
721static ssize_t show_pwm_auto_pwm_min(struct device *dev, char *buf, int nr) 709
710static ssize_t show_pwm_auto_pwm_min(struct device *dev,
711 struct device_attribute *attr, char *buf)
722{ 712{
713 int nr = to_sensor_dev_attr(attr)->index;
723 struct lm85_data *data = lm85_update_device(dev); 714 struct lm85_data *data = lm85_update_device(dev);
724 return sprintf(buf,"%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm)); 715 return sprintf(buf,"%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
725} 716}
726static ssize_t set_pwm_auto_pwm_min(struct device *dev, const char *buf, 717
727 size_t count, int nr) 718static ssize_t set_pwm_auto_pwm_min(struct device *dev,
719 struct device_attribute *attr, const char *buf, size_t count)
728{ 720{
721 int nr = to_sensor_dev_attr(attr)->index;
729 struct i2c_client *client = to_i2c_client(dev); 722 struct i2c_client *client = to_i2c_client(dev);
730 struct lm85_data *data = i2c_get_clientdata(client); 723 struct lm85_data *data = i2c_get_clientdata(client);
731 long val = simple_strtol(buf, NULL, 10); 724 long val = simple_strtol(buf, NULL, 10);
@@ -737,14 +730,19 @@ static ssize_t set_pwm_auto_pwm_min(struct device *dev, const char *buf,
737 mutex_unlock(&data->update_lock); 730 mutex_unlock(&data->update_lock);
738 return count; 731 return count;
739} 732}
740static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, char *buf, int nr) 733
734static ssize_t show_pwm_auto_pwm_minctl(struct device *dev,
735 struct device_attribute *attr, char *buf)
741{ 736{
737 int nr = to_sensor_dev_attr(attr)->index;
742 struct lm85_data *data = lm85_update_device(dev); 738 struct lm85_data *data = lm85_update_device(dev);
743 return sprintf(buf,"%d\n", data->autofan[nr].min_off); 739 return sprintf(buf,"%d\n", data->autofan[nr].min_off);
744} 740}
745static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf, 741
746 size_t count, int nr) 742static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
743 struct device_attribute *attr, const char *buf, size_t count)
747{ 744{
745 int nr = to_sensor_dev_attr(attr)->index;
748 struct i2c_client *client = to_i2c_client(dev); 746 struct i2c_client *client = to_i2c_client(dev);
749 struct lm85_data *data = i2c_get_clientdata(client); 747 struct lm85_data *data = i2c_get_clientdata(client);
750 long val = simple_strtol(buf, NULL, 10); 748 long val = simple_strtol(buf, NULL, 10);
@@ -760,14 +758,19 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf,
760 mutex_unlock(&data->update_lock); 758 mutex_unlock(&data->update_lock);
761 return count; 759 return count;
762} 760}
763static ssize_t show_pwm_auto_pwm_freq(struct device *dev, char *buf, int nr) 761
762static ssize_t show_pwm_auto_pwm_freq(struct device *dev,
763 struct device_attribute *attr, char *buf)
764{ 764{
765 int nr = to_sensor_dev_attr(attr)->index;
765 struct lm85_data *data = lm85_update_device(dev); 766 struct lm85_data *data = lm85_update_device(dev);
766 return sprintf(buf,"%d\n", FREQ_FROM_REG(data->autofan[nr].freq)); 767 return sprintf(buf,"%d\n", FREQ_FROM_REG(data->autofan[nr].freq));
767} 768}
768static ssize_t set_pwm_auto_pwm_freq(struct device *dev, const char *buf, 769
769 size_t count, int nr) 770static ssize_t set_pwm_auto_pwm_freq(struct device *dev,
771 struct device_attribute *attr, const char *buf, size_t count)
770{ 772{
773 int nr = to_sensor_dev_attr(attr)->index;
771 struct i2c_client *client = to_i2c_client(dev); 774 struct i2c_client *client = to_i2c_client(dev);
772 struct lm85_data *data = i2c_get_clientdata(client); 775 struct lm85_data *data = i2c_get_clientdata(client);
773 long val = simple_strtol(buf, NULL, 10); 776 long val = simple_strtol(buf, NULL, 10);
@@ -781,74 +784,40 @@ static ssize_t set_pwm_auto_pwm_freq(struct device *dev, const char *buf,
781 mutex_unlock(&data->update_lock); 784 mutex_unlock(&data->update_lock);
782 return count; 785 return count;
783} 786}
787
784#define pwm_auto(offset) \ 788#define pwm_auto(offset) \
785static ssize_t show_pwm##offset##_auto_channels (struct device *dev, struct device_attribute *attr, \ 789static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \
786 char *buf) \ 790 S_IRUGO | S_IWUSR, show_pwm_auto_channels, \
787{ \ 791 set_pwm_auto_channels, offset - 1); \
788 return show_pwm_auto_channels(dev, buf, offset - 1); \ 792static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \
789} \ 793 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_min, \
790static ssize_t set_pwm##offset##_auto_channels (struct device *dev, struct device_attribute *attr, \ 794 set_pwm_auto_pwm_min, offset - 1); \
791 const char *buf, size_t count) \ 795static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \
792{ \ 796 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \
793 return set_pwm_auto_channels(dev, buf, count, offset - 1); \ 797 set_pwm_auto_pwm_minctl, offset - 1); \
794} \ 798static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_freq, \
795static ssize_t show_pwm##offset##_auto_pwm_min (struct device *dev, struct device_attribute *attr, \ 799 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_freq, \
796 char *buf) \ 800 set_pwm_auto_pwm_freq, offset - 1);
797{ \ 801
798 return show_pwm_auto_pwm_min(dev, buf, offset - 1); \
799} \
800static ssize_t set_pwm##offset##_auto_pwm_min (struct device *dev, struct device_attribute *attr, \
801 const char *buf, size_t count) \
802{ \
803 return set_pwm_auto_pwm_min(dev, buf, count, offset - 1); \
804} \
805static ssize_t show_pwm##offset##_auto_pwm_minctl (struct device *dev, struct device_attribute *attr, \
806 char *buf) \
807{ \
808 return show_pwm_auto_pwm_minctl(dev, buf, offset - 1); \
809} \
810static ssize_t set_pwm##offset##_auto_pwm_minctl (struct device *dev, struct device_attribute *attr, \
811 const char *buf, size_t count) \
812{ \
813 return set_pwm_auto_pwm_minctl(dev, buf, count, offset - 1); \
814} \
815static ssize_t show_pwm##offset##_auto_pwm_freq (struct device *dev, struct device_attribute *attr, \
816 char *buf) \
817{ \
818 return show_pwm_auto_pwm_freq(dev, buf, offset - 1); \
819} \
820static ssize_t set_pwm##offset##_auto_pwm_freq(struct device *dev, struct device_attribute *attr, \
821 const char *buf, size_t count) \
822{ \
823 return set_pwm_auto_pwm_freq(dev, buf, count, offset - 1); \
824} \
825static DEVICE_ATTR(pwm##offset##_auto_channels, S_IRUGO | S_IWUSR, \
826 show_pwm##offset##_auto_channels, \
827 set_pwm##offset##_auto_channels); \
828static DEVICE_ATTR(pwm##offset##_auto_pwm_min, S_IRUGO | S_IWUSR, \
829 show_pwm##offset##_auto_pwm_min, \
830 set_pwm##offset##_auto_pwm_min); \
831static DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, S_IRUGO | S_IWUSR, \
832 show_pwm##offset##_auto_pwm_minctl, \
833 set_pwm##offset##_auto_pwm_minctl); \
834static DEVICE_ATTR(pwm##offset##_auto_pwm_freq, S_IRUGO | S_IWUSR, \
835 show_pwm##offset##_auto_pwm_freq, \
836 set_pwm##offset##_auto_pwm_freq);
837pwm_auto(1); 802pwm_auto(1);
838pwm_auto(2); 803pwm_auto(2);
839pwm_auto(3); 804pwm_auto(3);
840 805
841/* Temperature settings for automatic PWM control */ 806/* Temperature settings for automatic PWM control */
842 807
843static ssize_t show_temp_auto_temp_off(struct device *dev, char *buf, int nr) 808static ssize_t show_temp_auto_temp_off(struct device *dev,
809 struct device_attribute *attr, char *buf)
844{ 810{
811 int nr = to_sensor_dev_attr(attr)->index;
845 struct lm85_data *data = lm85_update_device(dev); 812 struct lm85_data *data = lm85_update_device(dev);
846 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) - 813 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
847 HYST_FROM_REG(data->zone[nr].hyst)); 814 HYST_FROM_REG(data->zone[nr].hyst));
848} 815}
849static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf, 816
850 size_t count, int nr) 817static ssize_t set_temp_auto_temp_off(struct device *dev,
818 struct device_attribute *attr, const char *buf, size_t count)
851{ 819{
820 int nr = to_sensor_dev_attr(attr)->index;
852 struct i2c_client *client = to_i2c_client(dev); 821 struct i2c_client *client = to_i2c_client(dev);
853 struct lm85_data *data = i2c_get_clientdata(client); 822 struct lm85_data *data = i2c_get_clientdata(client);
854 int min; 823 int min;
@@ -871,14 +840,19 @@ static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf,
871 mutex_unlock(&data->update_lock); 840 mutex_unlock(&data->update_lock);
872 return count; 841 return count;
873} 842}
874static ssize_t show_temp_auto_temp_min(struct device *dev, char *buf, int nr) 843
844static ssize_t show_temp_auto_temp_min(struct device *dev,
845 struct device_attribute *attr, char *buf)
875{ 846{
847 int nr = to_sensor_dev_attr(attr)->index;
876 struct lm85_data *data = lm85_update_device(dev); 848 struct lm85_data *data = lm85_update_device(dev);
877 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) ); 849 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) );
878} 850}
879static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf, 851
880 size_t count, int nr) 852static ssize_t set_temp_auto_temp_min(struct device *dev,
853 struct device_attribute *attr, const char *buf, size_t count)
881{ 854{
855 int nr = to_sensor_dev_attr(attr)->index;
882 struct i2c_client *client = to_i2c_client(dev); 856 struct i2c_client *client = to_i2c_client(dev);
883 struct lm85_data *data = i2c_get_clientdata(client); 857 struct lm85_data *data = i2c_get_clientdata(client);
884 long val = simple_strtol(buf, NULL, 10); 858 long val = simple_strtol(buf, NULL, 10);
@@ -913,15 +887,20 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf,
913 mutex_unlock(&data->update_lock); 887 mutex_unlock(&data->update_lock);
914 return count; 888 return count;
915} 889}
916static ssize_t show_temp_auto_temp_max(struct device *dev, char *buf, int nr) 890
891static ssize_t show_temp_auto_temp_max(struct device *dev,
892 struct device_attribute *attr, char *buf)
917{ 893{
894 int nr = to_sensor_dev_attr(attr)->index;
918 struct lm85_data *data = lm85_update_device(dev); 895 struct lm85_data *data = lm85_update_device(dev);
919 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) + 896 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
920 RANGE_FROM_REG(data->zone[nr].range)); 897 RANGE_FROM_REG(data->zone[nr].range));
921} 898}
922static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf, 899
923 size_t count, int nr) 900static ssize_t set_temp_auto_temp_max(struct device *dev,
901 struct device_attribute *attr, const char *buf, size_t count)
924{ 902{
903 int nr = to_sensor_dev_attr(attr)->index;
925 struct i2c_client *client = to_i2c_client(dev); 904 struct i2c_client *client = to_i2c_client(dev);
926 struct lm85_data *data = i2c_get_clientdata(client); 905 struct lm85_data *data = i2c_get_clientdata(client);
927 int min; 906 int min;
@@ -938,14 +917,19 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf,
938 mutex_unlock(&data->update_lock); 917 mutex_unlock(&data->update_lock);
939 return count; 918 return count;
940} 919}
941static ssize_t show_temp_auto_temp_crit(struct device *dev, char *buf, int nr) 920
921static ssize_t show_temp_auto_temp_crit(struct device *dev,
922 struct device_attribute *attr, char *buf)
942{ 923{
924 int nr = to_sensor_dev_attr(attr)->index;
943 struct lm85_data *data = lm85_update_device(dev); 925 struct lm85_data *data = lm85_update_device(dev);
944 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].critical)); 926 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].critical));
945} 927}
946static ssize_t set_temp_auto_temp_crit(struct device *dev, const char *buf, 928
947 size_t count, int nr) 929static ssize_t set_temp_auto_temp_crit(struct device *dev,
930 struct device_attribute *attr,const char *buf, size_t count)
948{ 931{
932 int nr = to_sensor_dev_attr(attr)->index;
949 struct i2c_client *client = to_i2c_client(dev); 933 struct i2c_client *client = to_i2c_client(dev);
950 struct lm85_data *data = i2c_get_clientdata(client); 934 struct lm85_data *data = i2c_get_clientdata(client);
951 long val = simple_strtol(buf, NULL, 10); 935 long val = simple_strtol(buf, NULL, 10);
@@ -957,59 +941,21 @@ static ssize_t set_temp_auto_temp_crit(struct device *dev, const char *buf,
957 mutex_unlock(&data->update_lock); 941 mutex_unlock(&data->update_lock);
958 return count; 942 return count;
959} 943}
944
960#define temp_auto(offset) \ 945#define temp_auto(offset) \
961static ssize_t show_temp##offset##_auto_temp_off (struct device *dev, struct device_attribute *attr, \ 946static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_off, \
962 char *buf) \ 947 S_IRUGO | S_IWUSR, show_temp_auto_temp_off, \
963{ \ 948 set_temp_auto_temp_off, offset - 1); \
964 return show_temp_auto_temp_off(dev, buf, offset - 1); \ 949static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_min, \
965} \ 950 S_IRUGO | S_IWUSR, show_temp_auto_temp_min, \
966static ssize_t set_temp##offset##_auto_temp_off (struct device *dev, struct device_attribute *attr, \ 951 set_temp_auto_temp_min, offset - 1); \
967 const char *buf, size_t count) \ 952static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_max, \
968{ \ 953 S_IRUGO | S_IWUSR, show_temp_auto_temp_max, \
969 return set_temp_auto_temp_off(dev, buf, count, offset - 1); \ 954 set_temp_auto_temp_max, offset - 1); \
970} \ 955static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_crit, \
971static ssize_t show_temp##offset##_auto_temp_min (struct device *dev, struct device_attribute *attr, \ 956 S_IRUGO | S_IWUSR, show_temp_auto_temp_crit, \
972 char *buf) \ 957 set_temp_auto_temp_crit, offset - 1);
973{ \ 958
974 return show_temp_auto_temp_min(dev, buf, offset - 1); \
975} \
976static ssize_t set_temp##offset##_auto_temp_min (struct device *dev, struct device_attribute *attr, \
977 const char *buf, size_t count) \
978{ \
979 return set_temp_auto_temp_min(dev, buf, count, offset - 1); \
980} \
981static ssize_t show_temp##offset##_auto_temp_max (struct device *dev, struct device_attribute *attr, \
982 char *buf) \
983{ \
984 return show_temp_auto_temp_max(dev, buf, offset - 1); \
985} \
986static ssize_t set_temp##offset##_auto_temp_max (struct device *dev, struct device_attribute *attr, \
987 const char *buf, size_t count) \
988{ \
989 return set_temp_auto_temp_max(dev, buf, count, offset - 1); \
990} \
991static ssize_t show_temp##offset##_auto_temp_crit (struct device *dev, struct device_attribute *attr, \
992 char *buf) \
993{ \
994 return show_temp_auto_temp_crit(dev, buf, offset - 1); \
995} \
996static ssize_t set_temp##offset##_auto_temp_crit (struct device *dev, struct device_attribute *attr, \
997 const char *buf, size_t count) \
998{ \
999 return set_temp_auto_temp_crit(dev, buf, count, offset - 1); \
1000} \
1001static DEVICE_ATTR(temp##offset##_auto_temp_off, S_IRUGO | S_IWUSR, \
1002 show_temp##offset##_auto_temp_off, \
1003 set_temp##offset##_auto_temp_off); \
1004static DEVICE_ATTR(temp##offset##_auto_temp_min, S_IRUGO | S_IWUSR, \
1005 show_temp##offset##_auto_temp_min, \
1006 set_temp##offset##_auto_temp_min); \
1007static DEVICE_ATTR(temp##offset##_auto_temp_max, S_IRUGO | S_IWUSR, \
1008 show_temp##offset##_auto_temp_max, \
1009 set_temp##offset##_auto_temp_max); \
1010static DEVICE_ATTR(temp##offset##_auto_temp_crit, S_IRUGO | S_IWUSR, \
1011 show_temp##offset##_auto_temp_crit, \
1012 set_temp##offset##_auto_temp_crit);
1013temp_auto(1); 959temp_auto(1);
1014temp_auto(2); 960temp_auto(2);
1015temp_auto(3); 961temp_auto(3);
@@ -1022,69 +968,87 @@ static int lm85_attach_adapter(struct i2c_adapter *adapter)
1022} 968}
1023 969
1024static struct attribute *lm85_attributes[] = { 970static struct attribute *lm85_attributes[] = {
1025 &dev_attr_fan1_input.attr, 971 &sensor_dev_attr_fan1_input.dev_attr.attr,
1026 &dev_attr_fan2_input.attr, 972 &sensor_dev_attr_fan2_input.dev_attr.attr,
1027 &dev_attr_fan3_input.attr, 973 &sensor_dev_attr_fan3_input.dev_attr.attr,
1028 &dev_attr_fan4_input.attr, 974 &sensor_dev_attr_fan4_input.dev_attr.attr,
1029 &dev_attr_fan1_min.attr, 975 &sensor_dev_attr_fan1_min.dev_attr.attr,
1030 &dev_attr_fan2_min.attr, 976 &sensor_dev_attr_fan2_min.dev_attr.attr,
1031 &dev_attr_fan3_min.attr, 977 &sensor_dev_attr_fan3_min.dev_attr.attr,
1032 &dev_attr_fan4_min.attr, 978 &sensor_dev_attr_fan4_min.dev_attr.attr,
1033 &dev_attr_pwm1.attr, 979 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1034 &dev_attr_pwm2.attr, 980 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1035 &dev_attr_pwm3.attr, 981 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1036 &dev_attr_pwm1_enable.attr, 982 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1037 &dev_attr_pwm2_enable.attr, 983
1038 &dev_attr_pwm3_enable.attr, 984 &sensor_dev_attr_pwm1.dev_attr.attr,
1039 &dev_attr_in0_input.attr, 985 &sensor_dev_attr_pwm2.dev_attr.attr,
1040 &dev_attr_in1_input.attr, 986 &sensor_dev_attr_pwm3.dev_attr.attr,
1041 &dev_attr_in2_input.attr, 987 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1042 &dev_attr_in3_input.attr, 988 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1043 &dev_attr_in0_min.attr, 989 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1044 &dev_attr_in1_min.attr, 990
1045 &dev_attr_in2_min.attr, 991 &sensor_dev_attr_in0_input.dev_attr.attr,
1046 &dev_attr_in3_min.attr, 992 &sensor_dev_attr_in1_input.dev_attr.attr,
1047 &dev_attr_in0_max.attr, 993 &sensor_dev_attr_in2_input.dev_attr.attr,
1048 &dev_attr_in1_max.attr, 994 &sensor_dev_attr_in3_input.dev_attr.attr,
1049 &dev_attr_in2_max.attr, 995 &sensor_dev_attr_in0_min.dev_attr.attr,
1050 &dev_attr_in3_max.attr, 996 &sensor_dev_attr_in1_min.dev_attr.attr,
1051 &dev_attr_temp1_input.attr, 997 &sensor_dev_attr_in2_min.dev_attr.attr,
1052 &dev_attr_temp2_input.attr, 998 &sensor_dev_attr_in3_min.dev_attr.attr,
1053 &dev_attr_temp3_input.attr, 999 &sensor_dev_attr_in0_max.dev_attr.attr,
1054 &dev_attr_temp1_min.attr, 1000 &sensor_dev_attr_in1_max.dev_attr.attr,
1055 &dev_attr_temp2_min.attr, 1001 &sensor_dev_attr_in2_max.dev_attr.attr,
1056 &dev_attr_temp3_min.attr, 1002 &sensor_dev_attr_in3_max.dev_attr.attr,
1057 &dev_attr_temp1_max.attr, 1003 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1058 &dev_attr_temp2_max.attr, 1004 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1059 &dev_attr_temp3_max.attr, 1005 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1006 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1007
1008 &sensor_dev_attr_temp1_input.dev_attr.attr,
1009 &sensor_dev_attr_temp2_input.dev_attr.attr,
1010 &sensor_dev_attr_temp3_input.dev_attr.attr,
1011 &sensor_dev_attr_temp1_min.dev_attr.attr,
1012 &sensor_dev_attr_temp2_min.dev_attr.attr,
1013 &sensor_dev_attr_temp3_min.dev_attr.attr,
1014 &sensor_dev_attr_temp1_max.dev_attr.attr,
1015 &sensor_dev_attr_temp2_max.dev_attr.attr,
1016 &sensor_dev_attr_temp3_max.dev_attr.attr,
1017 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1018 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1019 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1020 &sensor_dev_attr_temp1_fault.dev_attr.attr,
1021 &sensor_dev_attr_temp3_fault.dev_attr.attr,
1022
1023 &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr,
1024 &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr,
1025 &sensor_dev_attr_pwm3_auto_channels.dev_attr.attr,
1026 &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
1027 &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
1028 &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
1029 &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr,
1030 &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr,
1031 &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr,
1032 &sensor_dev_attr_pwm1_auto_pwm_freq.dev_attr.attr,
1033 &sensor_dev_attr_pwm2_auto_pwm_freq.dev_attr.attr,
1034 &sensor_dev_attr_pwm3_auto_pwm_freq.dev_attr.attr,
1035
1036 &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr,
1037 &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr,
1038 &sensor_dev_attr_temp3_auto_temp_off.dev_attr.attr,
1039 &sensor_dev_attr_temp1_auto_temp_min.dev_attr.attr,
1040 &sensor_dev_attr_temp2_auto_temp_min.dev_attr.attr,
1041 &sensor_dev_attr_temp3_auto_temp_min.dev_attr.attr,
1042 &sensor_dev_attr_temp1_auto_temp_max.dev_attr.attr,
1043 &sensor_dev_attr_temp2_auto_temp_max.dev_attr.attr,
1044 &sensor_dev_attr_temp3_auto_temp_max.dev_attr.attr,
1045 &sensor_dev_attr_temp1_auto_temp_crit.dev_attr.attr,
1046 &sensor_dev_attr_temp2_auto_temp_crit.dev_attr.attr,
1047 &sensor_dev_attr_temp3_auto_temp_crit.dev_attr.attr,
1048
1060 &dev_attr_vrm.attr, 1049 &dev_attr_vrm.attr,
1061 &dev_attr_cpu0_vid.attr, 1050 &dev_attr_cpu0_vid.attr,
1062 &dev_attr_alarms.attr, 1051 &dev_attr_alarms.attr,
1063 &dev_attr_pwm1_auto_channels.attr,
1064 &dev_attr_pwm2_auto_channels.attr,
1065 &dev_attr_pwm3_auto_channels.attr,
1066 &dev_attr_pwm1_auto_pwm_min.attr,
1067 &dev_attr_pwm2_auto_pwm_min.attr,
1068 &dev_attr_pwm3_auto_pwm_min.attr,
1069 &dev_attr_pwm1_auto_pwm_minctl.attr,
1070 &dev_attr_pwm2_auto_pwm_minctl.attr,
1071 &dev_attr_pwm3_auto_pwm_minctl.attr,
1072 &dev_attr_pwm1_auto_pwm_freq.attr,
1073 &dev_attr_pwm2_auto_pwm_freq.attr,
1074 &dev_attr_pwm3_auto_pwm_freq.attr,
1075 &dev_attr_temp1_auto_temp_off.attr,
1076 &dev_attr_temp2_auto_temp_off.attr,
1077 &dev_attr_temp3_auto_temp_off.attr,
1078 &dev_attr_temp1_auto_temp_min.attr,
1079 &dev_attr_temp2_auto_temp_min.attr,
1080 &dev_attr_temp3_auto_temp_min.attr,
1081 &dev_attr_temp1_auto_temp_max.attr,
1082 &dev_attr_temp2_auto_temp_max.attr,
1083 &dev_attr_temp3_auto_temp_max.attr,
1084 &dev_attr_temp1_auto_temp_crit.attr,
1085 &dev_attr_temp2_auto_temp_crit.attr,
1086 &dev_attr_temp3_auto_temp_crit.attr,
1087
1088 NULL 1052 NULL
1089}; 1053};
1090 1054
@@ -1092,16 +1056,36 @@ static const struct attribute_group lm85_group = {
1092 .attrs = lm85_attributes, 1056 .attrs = lm85_attributes,
1093}; 1057};
1094 1058
1095static struct attribute *lm85_attributes_opt[] = { 1059static struct attribute *lm85_attributes_in4[] = {
1096 &dev_attr_in4_input.attr, 1060 &sensor_dev_attr_in4_input.dev_attr.attr,
1097 &dev_attr_in4_min.attr, 1061 &sensor_dev_attr_in4_min.dev_attr.attr,
1098 &dev_attr_in4_max.attr, 1062 &sensor_dev_attr_in4_max.dev_attr.attr,
1063 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1064 NULL
1065};
1066
1067static const struct attribute_group lm85_group_in4 = {
1068 .attrs = lm85_attributes_in4,
1069};
1099 1070
1071static struct attribute *lm85_attributes_in567[] = {
1072 &sensor_dev_attr_in5_input.dev_attr.attr,
1073 &sensor_dev_attr_in6_input.dev_attr.attr,
1074 &sensor_dev_attr_in7_input.dev_attr.attr,
1075 &sensor_dev_attr_in5_min.dev_attr.attr,
1076 &sensor_dev_attr_in6_min.dev_attr.attr,
1077 &sensor_dev_attr_in7_min.dev_attr.attr,
1078 &sensor_dev_attr_in5_max.dev_attr.attr,
1079 &sensor_dev_attr_in6_max.dev_attr.attr,
1080 &sensor_dev_attr_in7_max.dev_attr.attr,
1081 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1082 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1083 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1100 NULL 1084 NULL
1101}; 1085};
1102 1086
1103static const struct attribute_group lm85_group_opt = { 1087static const struct attribute_group lm85_group_in567 = {
1104 .attrs = lm85_attributes_opt, 1088 .attrs = lm85_attributes_in567,
1105}; 1089};
1106 1090
1107static int lm85_detect(struct i2c_adapter *adapter, int address, 1091static int lm85_detect(struct i2c_adapter *adapter, int address,
@@ -1249,17 +1233,19 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1249 as a sixth digital VID input rather than an analog input. */ 1233 as a sixth digital VID input rather than an analog input. */
1250 data->vid = lm85_read_value(new_client, LM85_REG_VID); 1234 data->vid = lm85_read_value(new_client, LM85_REG_VID);
1251 if (!(kind == adt7463 && (data->vid & 0x80))) 1235 if (!(kind == adt7463 && (data->vid & 0x80)))
1252 if ((err = device_create_file(&new_client->dev, 1236 if ((err = sysfs_create_group(&new_client->dev.kobj,
1253 &dev_attr_in4_input)) 1237 &lm85_group_in4)))
1254 || (err = device_create_file(&new_client->dev,
1255 &dev_attr_in4_min))
1256 || (err = device_create_file(&new_client->dev,
1257 &dev_attr_in4_max)))
1258 goto ERROR3; 1238 goto ERROR3;
1259 1239
1260 data->class_dev = hwmon_device_register(&new_client->dev); 1240 /* The EMC6D100 has 3 additional voltage inputs */
1261 if (IS_ERR(data->class_dev)) { 1241 if (kind == emc6d100)
1262 err = PTR_ERR(data->class_dev); 1242 if ((err = sysfs_create_group(&new_client->dev.kobj,
1243 &lm85_group_in567)))
1244 goto ERROR3;
1245
1246 data->hwmon_dev = hwmon_device_register(&new_client->dev);
1247 if (IS_ERR(data->hwmon_dev)) {
1248 err = PTR_ERR(data->hwmon_dev);
1263 goto ERROR3; 1249 goto ERROR3;
1264 } 1250 }
1265 1251
@@ -1268,7 +1254,9 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1268 /* Error out and cleanup code */ 1254 /* Error out and cleanup code */
1269 ERROR3: 1255 ERROR3:
1270 sysfs_remove_group(&new_client->dev.kobj, &lm85_group); 1256 sysfs_remove_group(&new_client->dev.kobj, &lm85_group);
1271 sysfs_remove_group(&new_client->dev.kobj, &lm85_group_opt); 1257 sysfs_remove_group(&new_client->dev.kobj, &lm85_group_in4);
1258 if (kind == emc6d100)
1259 sysfs_remove_group(&new_client->dev.kobj, &lm85_group_in567);
1272 ERROR2: 1260 ERROR2:
1273 i2c_detach_client(new_client); 1261 i2c_detach_client(new_client);
1274 ERROR1: 1262 ERROR1:
@@ -1280,9 +1268,11 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1280static int lm85_detach_client(struct i2c_client *client) 1268static int lm85_detach_client(struct i2c_client *client)
1281{ 1269{
1282 struct lm85_data *data = i2c_get_clientdata(client); 1270 struct lm85_data *data = i2c_get_clientdata(client);
1283 hwmon_device_unregister(data->class_dev); 1271 hwmon_device_unregister(data->hwmon_dev);
1284 sysfs_remove_group(&client->dev.kobj, &lm85_group); 1272 sysfs_remove_group(&client->dev.kobj, &lm85_group);
1285 sysfs_remove_group(&client->dev.kobj, &lm85_group_opt); 1273 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
1274 if (data->type == emc6d100)
1275 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
1286 i2c_detach_client(client); 1276 i2c_detach_client(client);
1287 kfree(data); 1277 kfree(data);
1288 return 0; 1278 return 0;
@@ -1405,6 +1395,8 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1405 1395
1406 /* Have to read extended bits first to "freeze" the 1396 /* Have to read extended bits first to "freeze" the
1407 * more significant bits that are read later. 1397 * more significant bits that are read later.
1398 * There are 2 additional resolution bits per channel and we
1399 * have room for 4, so we shift them to the left.
1408 */ 1400 */
1409 if ( (data->type == adm1027) || (data->type == adt7463) ) { 1401 if ( (data->type == adm1027) || (data->type == adt7463) ) {
1410 int ext1 = lm85_read_value(client, 1402 int ext1 = lm85_read_value(client,
@@ -1414,18 +1406,12 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1414 int val = (ext1 << 8) + ext2; 1406 int val = (ext1 << 8) + ext2;
1415 1407
1416 for(i = 0; i <= 4; i++) 1408 for(i = 0; i <= 4; i++)
1417 data->in_ext[i] = (val>>(i * 2))&0x03; 1409 data->in_ext[i] = ((val>>(i * 2))&0x03) << 2;
1418 1410
1419 for(i = 0; i <= 2; i++) 1411 for(i = 0; i <= 2; i++)
1420 data->temp_ext[i] = (val>>((i + 5) * 2))&0x03; 1412 data->temp_ext[i] = (val>>((i + 4) * 2))&0x0c;
1421 } 1413 }
1422 1414
1423 /* adc_scale is 2^(number of LSBs). There are 4 extra bits in
1424 the emc6d102 and 2 in the adt7463 and adm1027. In all
1425 other chips ext is always 0 and the value of scale is
1426 irrelevant. So it is left in 4*/
1427 data->adc_scale = (data->type == emc6d102 ) ? 16 : 4;
1428
1429 data->vid = lm85_read_value(client, LM85_REG_VID); 1415 data->vid = lm85_read_value(client, LM85_REG_VID);
1430 1416
1431 for (i = 0; i <= 3; ++i) { 1417 for (i = 0; i <= 3; ++i) {