2 * A hwmon driver for the Analog Devices ADT7470
3 * Copyright (C) 2007 IBM
5 * Author: Darrick J. Wong <djwong@us.ibm.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/module.h>
23 #include <linux/jiffies.h>
24 #include <linux/i2c.h>
25 #include <linux/hwmon.h>
26 #include <linux/hwmon-sysfs.h>
27 #include <linux/err.h>
28 #include <linux/mutex.h>
29 #include <linux/delay.h>
30 #include <linux/log2.h>
32 /* Addresses to scan */
33 static const unsigned short normal_i2c
[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END
};
35 /* Insmod parameters */
36 I2C_CLIENT_INSMOD_1(adt7470
);
38 /* ADT7470 registers */
39 #define ADT7470_REG_BASE_ADDR 0x20
40 #define ADT7470_REG_TEMP_BASE_ADDR 0x20
41 #define ADT7470_REG_TEMP_MAX_ADDR 0x29
42 #define ADT7470_REG_FAN_BASE_ADDR 0x2A
43 #define ADT7470_REG_FAN_MAX_ADDR 0x31
44 #define ADT7470_REG_PWM_BASE_ADDR 0x32
45 #define ADT7470_REG_PWM_MAX_ADDR 0x35
46 #define ADT7470_REG_PWM_MAX_BASE_ADDR 0x38
47 #define ADT7470_REG_PWM_MAX_MAX_ADDR 0x3B
48 #define ADT7470_REG_CFG 0x40
49 #define ADT7470_FSPD_MASK 0x04
50 #define ADT7470_REG_ALARM1 0x41
51 #define ADT7470_R1T_ALARM 0x01
52 #define ADT7470_R2T_ALARM 0x02
53 #define ADT7470_R3T_ALARM 0x04
54 #define ADT7470_R4T_ALARM 0x08
55 #define ADT7470_R5T_ALARM 0x10
56 #define ADT7470_R6T_ALARM 0x20
57 #define ADT7470_R7T_ALARM 0x40
58 #define ADT7470_OOL_ALARM 0x80
59 #define ADT7470_REG_ALARM2 0x42
60 #define ADT7470_R8T_ALARM 0x01
61 #define ADT7470_R9T_ALARM 0x02
62 #define ADT7470_R10T_ALARM 0x04
63 #define ADT7470_FAN1_ALARM 0x10
64 #define ADT7470_FAN2_ALARM 0x20
65 #define ADT7470_FAN3_ALARM 0x40
66 #define ADT7470_FAN4_ALARM 0x80
67 #define ADT7470_REG_TEMP_LIMITS_BASE_ADDR 0x44
68 #define ADT7470_REG_TEMP_LIMITS_MAX_ADDR 0x57
69 #define ADT7470_REG_FAN_MIN_BASE_ADDR 0x58
70 #define ADT7470_REG_FAN_MIN_MAX_ADDR 0x5F
71 #define ADT7470_REG_FAN_MAX_BASE_ADDR 0x60
72 #define ADT7470_REG_FAN_MAX_MAX_ADDR 0x67
73 #define ADT7470_REG_PWM_CFG_BASE_ADDR 0x68
74 #define ADT7470_REG_PWM12_CFG 0x68
75 #define ADT7470_PWM2_AUTO_MASK 0x40
76 #define ADT7470_PWM1_AUTO_MASK 0x80
77 #define ADT7470_PWM_AUTO_MASK 0xC0
78 #define ADT7470_REG_PWM34_CFG 0x69
79 #define ADT7470_PWM3_AUTO_MASK 0x40
80 #define ADT7470_PWM4_AUTO_MASK 0x80
81 #define ADT7470_REG_PWM_MIN_BASE_ADDR 0x6A
82 #define ADT7470_REG_PWM_MIN_MAX_ADDR 0x6D
83 #define ADT7470_REG_PWM_TEMP_MIN_BASE_ADDR 0x6E
84 #define ADT7470_REG_PWM_TEMP_MIN_MAX_ADDR 0x71
85 #define ADT7470_REG_ACOUSTICS12 0x75
86 #define ADT7470_REG_ACOUSTICS34 0x76
87 #define ADT7470_REG_DEVICE 0x3D
88 #define ADT7470_REG_VENDOR 0x3E
89 #define ADT7470_REG_REVISION 0x3F
90 #define ADT7470_REG_ALARM1_MASK 0x72
91 #define ADT7470_REG_ALARM2_MASK 0x73
92 #define ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR 0x7C
93 #define ADT7470_REG_PWM_AUTO_TEMP_MAX_ADDR 0x7D
94 #define ADT7470_REG_MAX_ADDR 0x81
96 #define ADT7470_TEMP_COUNT 10
97 #define ADT7470_TEMP_REG(x) (ADT7470_REG_TEMP_BASE_ADDR + (x))
98 #define ADT7470_TEMP_MIN_REG(x) (ADT7470_REG_TEMP_LIMITS_BASE_ADDR + ((x) * 2))
99 #define ADT7470_TEMP_MAX_REG(x) (ADT7470_REG_TEMP_LIMITS_BASE_ADDR + \
102 #define ADT7470_FAN_COUNT 4
103 #define ADT7470_REG_FAN(x) (ADT7470_REG_FAN_BASE_ADDR + ((x) * 2))
104 #define ADT7470_REG_FAN_MIN(x) (ADT7470_REG_FAN_MIN_BASE_ADDR + ((x) * 2))
105 #define ADT7470_REG_FAN_MAX(x) (ADT7470_REG_FAN_MAX_BASE_ADDR + ((x) * 2))
107 #define ADT7470_PWM_COUNT 4
108 #define ADT7470_REG_PWM(x) (ADT7470_REG_PWM_BASE_ADDR + (x))
109 #define ADT7470_REG_PWM_MAX(x) (ADT7470_REG_PWM_MAX_BASE_ADDR + (x))
110 #define ADT7470_REG_PWM_MIN(x) (ADT7470_REG_PWM_MIN_BASE_ADDR + (x))
111 #define ADT7470_REG_PWM_TMIN(x) (ADT7470_REG_PWM_TEMP_MIN_BASE_ADDR + (x))
112 #define ADT7470_REG_PWM_CFG(x) (ADT7470_REG_PWM_CFG_BASE_ADDR + ((x) / 2))
113 #define ADT7470_REG_PWM_AUTO_TEMP(x) (ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR + \
116 #define ALARM2(x) ((x) << 8)
118 #define ADT7470_VENDOR 0x41
119 #define ADT7470_DEVICE 0x70
120 /* datasheet only mentions a revision 2 */
121 #define ADT7470_REVISION 0x02
123 /* "all temps" according to hwmon sysfs interface spec */
124 #define ADT7470_PWM_ALL_TEMPS 0x3FF
126 /* How often do we reread sensors values? (In jiffies) */
127 #define SENSOR_REFRESH_INTERVAL (5 * HZ)
129 /* How often do we reread sensor limit values? (In jiffies) */
130 #define LIMIT_REFRESH_INTERVAL (60 * HZ)
132 /* sleep 1s while gathering temperature data */
133 #define TEMP_COLLECTION_TIME 1000
135 /* datasheet says to divide this number by the fan reading to get fan rpm */
136 #define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
137 #define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
138 #define FAN_PERIOD_INVALID 65535
139 #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
141 struct adt7470_data
{
142 struct device
*hwmon_dev
;
143 struct attribute_group attrs
;
147 unsigned long sensors_last_updated
; /* In jiffies */
148 unsigned long limits_last_updated
; /* In jiffies */
150 s8 temp
[ADT7470_TEMP_COUNT
];
151 s8 temp_min
[ADT7470_TEMP_COUNT
];
152 s8 temp_max
[ADT7470_TEMP_COUNT
];
153 u16 fan
[ADT7470_FAN_COUNT
];
154 u16 fan_min
[ADT7470_FAN_COUNT
];
155 u16 fan_max
[ADT7470_FAN_COUNT
];
159 u8 pwm
[ADT7470_PWM_COUNT
];
160 u8 pwm_max
[ADT7470_PWM_COUNT
];
161 u8 pwm_automatic
[ADT7470_PWM_COUNT
];
162 u8 pwm_min
[ADT7470_PWM_COUNT
];
163 s8 pwm_tmin
[ADT7470_PWM_COUNT
];
164 u8 pwm_auto_temp
[ADT7470_PWM_COUNT
];
167 static int adt7470_probe(struct i2c_client
*client
,
168 const struct i2c_device_id
*id
);
169 static int adt7470_detect(struct i2c_client
*client
, int kind
,
170 struct i2c_board_info
*info
);
171 static int adt7470_remove(struct i2c_client
*client
);
173 static const struct i2c_device_id adt7470_id
[] = {
174 { "adt7470", adt7470
},
177 MODULE_DEVICE_TABLE(i2c
, adt7470_id
);
179 static struct i2c_driver adt7470_driver
= {
180 .class = I2C_CLASS_HWMON
,
184 .probe
= adt7470_probe
,
185 .remove
= adt7470_remove
,
186 .id_table
= adt7470_id
,
187 .detect
= adt7470_detect
,
188 .address_data
= &addr_data
,
192 * 16-bit registers on the ADT7470 are low-byte first. The data sheet says
193 * that the low byte must be read before the high byte.
195 static inline int adt7470_read_word_data(struct i2c_client
*client
, u8 reg
)
198 foo
= i2c_smbus_read_byte_data(client
, reg
);
199 foo
|= ((u16
)i2c_smbus_read_byte_data(client
, reg
+ 1) << 8);
203 static inline int adt7470_write_word_data(struct i2c_client
*client
, u8 reg
,
206 return i2c_smbus_write_byte_data(client
, reg
, value
& 0xFF)
207 && i2c_smbus_write_byte_data(client
, reg
+ 1, value
>> 8);
210 static void adt7470_init_client(struct i2c_client
*client
)
212 int reg
= i2c_smbus_read_byte_data(client
, ADT7470_REG_CFG
);
215 dev_err(&client
->dev
, "cannot read configuration register\n");
217 /* start monitoring (and do a self-test) */
218 i2c_smbus_write_byte_data(client
, ADT7470_REG_CFG
, reg
| 3);
222 static struct adt7470_data
*adt7470_update_device(struct device
*dev
)
224 struct i2c_client
*client
= to_i2c_client(dev
);
225 struct adt7470_data
*data
= i2c_get_clientdata(client
);
226 unsigned long local_jiffies
= jiffies
;
227 u8 cfg
, pwm
[4], pwm_cfg
[2];
230 mutex_lock(&data
->lock
);
231 if (time_before(local_jiffies
, data
->sensors_last_updated
+
232 SENSOR_REFRESH_INTERVAL
)
233 && data
->sensors_valid
)
234 goto no_sensor_update
;
236 /* save pwm[1-4] config register */
237 pwm_cfg
[0] = i2c_smbus_read_byte_data(client
, ADT7470_REG_PWM_CFG(0));
238 pwm_cfg
[1] = i2c_smbus_read_byte_data(client
, ADT7470_REG_PWM_CFG(2));
240 /* set manual pwm to whatever it is set to now */
241 for (i
= 0; i
< ADT7470_FAN_COUNT
; i
++)
242 pwm
[i
] = i2c_smbus_read_byte_data(client
, ADT7470_REG_PWM(i
));
244 /* put pwm in manual mode */
245 i2c_smbus_write_byte_data(client
, ADT7470_REG_PWM_CFG(0),
246 pwm_cfg
[0] & ~(ADT7470_PWM_AUTO_MASK
));
247 i2c_smbus_write_byte_data(client
, ADT7470_REG_PWM_CFG(2),
248 pwm_cfg
[1] & ~(ADT7470_PWM_AUTO_MASK
));
250 /* write pwm control to whatever it was */
251 for (i
= 0; i
< ADT7470_FAN_COUNT
; i
++)
252 i2c_smbus_write_byte_data(client
, ADT7470_REG_PWM(i
), pwm
[i
]);
254 /* start reading temperature sensors */
255 cfg
= i2c_smbus_read_byte_data(client
, ADT7470_REG_CFG
);
257 i2c_smbus_write_byte_data(client
, ADT7470_REG_CFG
, cfg
);
260 * Delay is 200ms * number of tmp05 sensors. Too bad
261 * there's no way to figure out how many are connected.
262 * For now, assume 1s will work.
264 msleep(TEMP_COLLECTION_TIME
);
266 /* done reading temperature sensors */
267 cfg
= i2c_smbus_read_byte_data(client
, ADT7470_REG_CFG
);
269 i2c_smbus_write_byte_data(client
, ADT7470_REG_CFG
, cfg
);
271 /* restore pwm[1-4] config registers */
272 i2c_smbus_write_byte_data(client
, ADT7470_REG_PWM_CFG(0), pwm_cfg
[0]);
273 i2c_smbus_write_byte_data(client
, ADT7470_REG_PWM_CFG(2), pwm_cfg
[1]);
275 for (i
= 0; i
< ADT7470_TEMP_COUNT
; i
++)
276 data
->temp
[i
] = i2c_smbus_read_byte_data(client
,
277 ADT7470_TEMP_REG(i
));
279 for (i
= 0; i
< ADT7470_FAN_COUNT
; i
++)
280 data
->fan
[i
] = adt7470_read_word_data(client
,
283 for (i
= 0; i
< ADT7470_PWM_COUNT
; i
++) {
287 data
->pwm
[i
] = i2c_smbus_read_byte_data(client
,
291 reg_mask
= ADT7470_PWM2_AUTO_MASK
;
293 reg_mask
= ADT7470_PWM1_AUTO_MASK
;
295 reg
= ADT7470_REG_PWM_CFG(i
);
296 if (i2c_smbus_read_byte_data(client
, reg
) & reg_mask
)
297 data
->pwm_automatic
[i
] = 1;
299 data
->pwm_automatic
[i
] = 0;
301 reg
= ADT7470_REG_PWM_AUTO_TEMP(i
);
302 cfg
= i2c_smbus_read_byte_data(client
, reg
);
304 data
->pwm_auto_temp
[i
] = cfg
>> 4;
306 data
->pwm_auto_temp
[i
] = cfg
& 0xF;
309 if (i2c_smbus_read_byte_data(client
, ADT7470_REG_CFG
) &
311 data
->force_pwm_max
= 1;
313 data
->force_pwm_max
= 0;
315 data
->alarm
= i2c_smbus_read_byte_data(client
, ADT7470_REG_ALARM1
);
316 if (data
->alarm
& ADT7470_OOL_ALARM
)
317 data
->alarm
|= ALARM2(i2c_smbus_read_byte_data(client
,
318 ADT7470_REG_ALARM2
));
319 data
->alarms_mask
= adt7470_read_word_data(client
,
320 ADT7470_REG_ALARM1_MASK
);
322 data
->sensors_last_updated
= local_jiffies
;
323 data
->sensors_valid
= 1;
326 if (time_before(local_jiffies
, data
->limits_last_updated
+
327 LIMIT_REFRESH_INTERVAL
)
328 && data
->limits_valid
)
331 for (i
= 0; i
< ADT7470_TEMP_COUNT
; i
++) {
332 data
->temp_min
[i
] = i2c_smbus_read_byte_data(client
,
333 ADT7470_TEMP_MIN_REG(i
));
334 data
->temp_max
[i
] = i2c_smbus_read_byte_data(client
,
335 ADT7470_TEMP_MAX_REG(i
));
338 for (i
= 0; i
< ADT7470_FAN_COUNT
; i
++) {
339 data
->fan_min
[i
] = adt7470_read_word_data(client
,
340 ADT7470_REG_FAN_MIN(i
));
341 data
->fan_max
[i
] = adt7470_read_word_data(client
,
342 ADT7470_REG_FAN_MAX(i
));
345 for (i
= 0; i
< ADT7470_PWM_COUNT
; i
++) {
346 data
->pwm_max
[i
] = i2c_smbus_read_byte_data(client
,
347 ADT7470_REG_PWM_MAX(i
));
348 data
->pwm_min
[i
] = i2c_smbus_read_byte_data(client
,
349 ADT7470_REG_PWM_MIN(i
));
350 data
->pwm_tmin
[i
] = i2c_smbus_read_byte_data(client
,
351 ADT7470_REG_PWM_TMIN(i
));
354 data
->limits_last_updated
= local_jiffies
;
355 data
->limits_valid
= 1;
358 mutex_unlock(&data
->lock
);
362 static ssize_t
show_temp_min(struct device
*dev
,
363 struct device_attribute
*devattr
,
366 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
367 struct adt7470_data
*data
= adt7470_update_device(dev
);
368 return sprintf(buf
, "%d\n", 1000 * data
->temp_min
[attr
->index
]);
371 static ssize_t
set_temp_min(struct device
*dev
,
372 struct device_attribute
*devattr
,
376 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
377 struct i2c_client
*client
= to_i2c_client(dev
);
378 struct adt7470_data
*data
= i2c_get_clientdata(client
);
381 if (strict_strtol(buf
, 10, &temp
))
384 temp
= DIV_ROUND_CLOSEST(temp
, 1000);
385 temp
= SENSORS_LIMIT(temp
, 0, 255);
387 mutex_lock(&data
->lock
);
388 data
->temp_min
[attr
->index
] = temp
;
389 i2c_smbus_write_byte_data(client
, ADT7470_TEMP_MIN_REG(attr
->index
),
391 mutex_unlock(&data
->lock
);
396 static ssize_t
show_temp_max(struct device
*dev
,
397 struct device_attribute
*devattr
,
400 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
401 struct adt7470_data
*data
= adt7470_update_device(dev
);
402 return sprintf(buf
, "%d\n", 1000 * data
->temp_max
[attr
->index
]);
405 static ssize_t
set_temp_max(struct device
*dev
,
406 struct device_attribute
*devattr
,
410 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
411 struct i2c_client
*client
= to_i2c_client(dev
);
412 struct adt7470_data
*data
= i2c_get_clientdata(client
);
415 if (strict_strtol(buf
, 10, &temp
))
418 temp
= DIV_ROUND_CLOSEST(temp
, 1000);
419 temp
= SENSORS_LIMIT(temp
, 0, 255);
421 mutex_lock(&data
->lock
);
422 data
->temp_max
[attr
->index
] = temp
;
423 i2c_smbus_write_byte_data(client
, ADT7470_TEMP_MAX_REG(attr
->index
),
425 mutex_unlock(&data
->lock
);
430 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*devattr
,
433 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
434 struct adt7470_data
*data
= adt7470_update_device(dev
);
435 return sprintf(buf
, "%d\n", 1000 * data
->temp
[attr
->index
]);
438 static ssize_t
show_alarm_mask(struct device
*dev
,
439 struct device_attribute
*devattr
,
442 struct adt7470_data
*data
= adt7470_update_device(dev
);
444 return sprintf(buf
, "%x\n", data
->alarms_mask
);
447 static ssize_t
show_fan_max(struct device
*dev
,
448 struct device_attribute
*devattr
,
451 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
452 struct adt7470_data
*data
= adt7470_update_device(dev
);
454 if (FAN_DATA_VALID(data
->fan_max
[attr
->index
]))
455 return sprintf(buf
, "%d\n",
456 FAN_PERIOD_TO_RPM(data
->fan_max
[attr
->index
]));
458 return sprintf(buf
, "0\n");
461 static ssize_t
set_fan_max(struct device
*dev
,
462 struct device_attribute
*devattr
,
463 const char *buf
, size_t count
)
465 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
466 struct i2c_client
*client
= to_i2c_client(dev
);
467 struct adt7470_data
*data
= i2c_get_clientdata(client
);
470 if (strict_strtol(buf
, 10, &temp
) || !temp
)
473 temp
= FAN_RPM_TO_PERIOD(temp
);
474 temp
= SENSORS_LIMIT(temp
, 1, 65534);
476 mutex_lock(&data
->lock
);
477 data
->fan_max
[attr
->index
] = temp
;
478 adt7470_write_word_data(client
, ADT7470_REG_FAN_MAX(attr
->index
), temp
);
479 mutex_unlock(&data
->lock
);
484 static ssize_t
show_fan_min(struct device
*dev
,
485 struct device_attribute
*devattr
,
488 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
489 struct adt7470_data
*data
= adt7470_update_device(dev
);
491 if (FAN_DATA_VALID(data
->fan_min
[attr
->index
]))
492 return sprintf(buf
, "%d\n",
493 FAN_PERIOD_TO_RPM(data
->fan_min
[attr
->index
]));
495 return sprintf(buf
, "0\n");
498 static ssize_t
set_fan_min(struct device
*dev
,
499 struct device_attribute
*devattr
,
500 const char *buf
, size_t count
)
502 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
503 struct i2c_client
*client
= to_i2c_client(dev
);
504 struct adt7470_data
*data
= i2c_get_clientdata(client
);
507 if (strict_strtol(buf
, 10, &temp
) || !temp
)
510 temp
= FAN_RPM_TO_PERIOD(temp
);
511 temp
= SENSORS_LIMIT(temp
, 1, 65534);
513 mutex_lock(&data
->lock
);
514 data
->fan_min
[attr
->index
] = temp
;
515 adt7470_write_word_data(client
, ADT7470_REG_FAN_MIN(attr
->index
), temp
);
516 mutex_unlock(&data
->lock
);
521 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
524 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
525 struct adt7470_data
*data
= adt7470_update_device(dev
);
527 if (FAN_DATA_VALID(data
->fan
[attr
->index
]))
528 return sprintf(buf
, "%d\n",
529 FAN_PERIOD_TO_RPM(data
->fan
[attr
->index
]));
531 return sprintf(buf
, "0\n");
534 static ssize_t
show_force_pwm_max(struct device
*dev
,
535 struct device_attribute
*devattr
,
538 struct adt7470_data
*data
= adt7470_update_device(dev
);
539 return sprintf(buf
, "%d\n", data
->force_pwm_max
);
542 static ssize_t
set_force_pwm_max(struct device
*dev
,
543 struct device_attribute
*devattr
,
547 struct i2c_client
*client
= to_i2c_client(dev
);
548 struct adt7470_data
*data
= i2c_get_clientdata(client
);
552 if (strict_strtol(buf
, 10, &temp
))
555 mutex_lock(&data
->lock
);
556 data
->force_pwm_max
= temp
;
557 reg
= i2c_smbus_read_byte_data(client
, ADT7470_REG_CFG
);
559 reg
|= ADT7470_FSPD_MASK
;
561 reg
&= ~ADT7470_FSPD_MASK
;
562 i2c_smbus_write_byte_data(client
, ADT7470_REG_CFG
, reg
);
563 mutex_unlock(&data
->lock
);
568 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*devattr
,
571 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
572 struct adt7470_data
*data
= adt7470_update_device(dev
);
573 return sprintf(buf
, "%d\n", data
->pwm
[attr
->index
]);
576 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*devattr
,
577 const char *buf
, size_t count
)
579 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
580 struct i2c_client
*client
= to_i2c_client(dev
);
581 struct adt7470_data
*data
= i2c_get_clientdata(client
);
584 if (strict_strtol(buf
, 10, &temp
))
587 temp
= SENSORS_LIMIT(temp
, 0, 255);
589 mutex_lock(&data
->lock
);
590 data
->pwm
[attr
->index
] = temp
;
591 i2c_smbus_write_byte_data(client
, ADT7470_REG_PWM(attr
->index
), temp
);
592 mutex_unlock(&data
->lock
);
597 static ssize_t
show_pwm_max(struct device
*dev
,
598 struct device_attribute
*devattr
,
601 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
602 struct adt7470_data
*data
= adt7470_update_device(dev
);
603 return sprintf(buf
, "%d\n", data
->pwm_max
[attr
->index
]);
606 static ssize_t
set_pwm_max(struct device
*dev
,
607 struct device_attribute
*devattr
,
611 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
612 struct i2c_client
*client
= to_i2c_client(dev
);
613 struct adt7470_data
*data
= i2c_get_clientdata(client
);
616 if (strict_strtol(buf
, 10, &temp
))
619 temp
= SENSORS_LIMIT(temp
, 0, 255);
621 mutex_lock(&data
->lock
);
622 data
->pwm_max
[attr
->index
] = temp
;
623 i2c_smbus_write_byte_data(client
, ADT7470_REG_PWM_MAX(attr
->index
),
625 mutex_unlock(&data
->lock
);
630 static ssize_t
show_pwm_min(struct device
*dev
,
631 struct device_attribute
*devattr
,
634 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
635 struct adt7470_data
*data
= adt7470_update_device(dev
);
636 return sprintf(buf
, "%d\n", data
->pwm_min
[attr
->index
]);
639 static ssize_t
set_pwm_min(struct device
*dev
,
640 struct device_attribute
*devattr
,
644 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
645 struct i2c_client
*client
= to_i2c_client(dev
);
646 struct adt7470_data
*data
= i2c_get_clientdata(client
);
649 if (strict_strtol(buf
, 10, &temp
))
652 temp
= SENSORS_LIMIT(temp
, 0, 255);
654 mutex_lock(&data
->lock
);
655 data
->pwm_min
[attr
->index
] = temp
;
656 i2c_smbus_write_byte_data(client
, ADT7470_REG_PWM_MIN(attr
->index
),
658 mutex_unlock(&data
->lock
);
663 static ssize_t
show_pwm_tmax(struct device
*dev
,
664 struct device_attribute
*devattr
,
667 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
668 struct adt7470_data
*data
= adt7470_update_device(dev
);
669 /* the datasheet says that tmax = tmin + 20C */
670 return sprintf(buf
, "%d\n", 1000 * (20 + data
->pwm_tmin
[attr
->index
]));
673 static ssize_t
show_pwm_tmin(struct device
*dev
,
674 struct device_attribute
*devattr
,
677 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
678 struct adt7470_data
*data
= adt7470_update_device(dev
);
679 return sprintf(buf
, "%d\n", 1000 * data
->pwm_tmin
[attr
->index
]);
682 static ssize_t
set_pwm_tmin(struct device
*dev
,
683 struct device_attribute
*devattr
,
687 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
688 struct i2c_client
*client
= to_i2c_client(dev
);
689 struct adt7470_data
*data
= i2c_get_clientdata(client
);
692 if (strict_strtol(buf
, 10, &temp
))
695 temp
= DIV_ROUND_CLOSEST(temp
, 1000);
696 temp
= SENSORS_LIMIT(temp
, 0, 255);
698 mutex_lock(&data
->lock
);
699 data
->pwm_tmin
[attr
->index
] = temp
;
700 i2c_smbus_write_byte_data(client
, ADT7470_REG_PWM_TMIN(attr
->index
),
702 mutex_unlock(&data
->lock
);
707 static ssize_t
show_pwm_auto(struct device
*dev
,
708 struct device_attribute
*devattr
,
711 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
712 struct adt7470_data
*data
= adt7470_update_device(dev
);
713 return sprintf(buf
, "%d\n", 1 + data
->pwm_automatic
[attr
->index
]);
716 static ssize_t
set_pwm_auto(struct device
*dev
,
717 struct device_attribute
*devattr
,
721 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
722 struct i2c_client
*client
= to_i2c_client(dev
);
723 struct adt7470_data
*data
= i2c_get_clientdata(client
);
724 int pwm_auto_reg
= ADT7470_REG_PWM_CFG(attr
->index
);
725 int pwm_auto_reg_mask
;
729 if (strict_strtol(buf
, 10, &temp
))
733 pwm_auto_reg_mask
= ADT7470_PWM2_AUTO_MASK
;
735 pwm_auto_reg_mask
= ADT7470_PWM1_AUTO_MASK
;
737 if (temp
!= 2 && temp
!= 1)
741 mutex_lock(&data
->lock
);
742 data
->pwm_automatic
[attr
->index
] = temp
;
743 reg
= i2c_smbus_read_byte_data(client
, pwm_auto_reg
);
745 reg
|= pwm_auto_reg_mask
;
747 reg
&= ~pwm_auto_reg_mask
;
748 i2c_smbus_write_byte_data(client
, pwm_auto_reg
, reg
);
749 mutex_unlock(&data
->lock
);
754 static ssize_t
show_pwm_auto_temp(struct device
*dev
,
755 struct device_attribute
*devattr
,
758 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
759 struct adt7470_data
*data
= adt7470_update_device(dev
);
760 u8 ctrl
= data
->pwm_auto_temp
[attr
->index
];
763 return sprintf(buf
, "%d\n", 1 << (ctrl
- 1));
765 return sprintf(buf
, "%d\n", ADT7470_PWM_ALL_TEMPS
);
768 static int cvt_auto_temp(int input
)
770 if (input
== ADT7470_PWM_ALL_TEMPS
)
772 if (input
< 1 || !is_power_of_2(input
))
774 return ilog2(input
) + 1;
777 static ssize_t
set_pwm_auto_temp(struct device
*dev
,
778 struct device_attribute
*devattr
,
782 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
783 struct i2c_client
*client
= to_i2c_client(dev
);
784 struct adt7470_data
*data
= i2c_get_clientdata(client
);
785 int pwm_auto_reg
= ADT7470_REG_PWM_AUTO_TEMP(attr
->index
);
789 if (strict_strtol(buf
, 10, &temp
))
792 temp
= cvt_auto_temp(temp
);
796 mutex_lock(&data
->lock
);
797 data
->pwm_automatic
[attr
->index
] = temp
;
798 reg
= i2c_smbus_read_byte_data(client
, pwm_auto_reg
);
800 if (!(attr
->index
% 2)) {
802 reg
|= (temp
<< 4) & 0xF0;
808 i2c_smbus_write_byte_data(client
, pwm_auto_reg
, reg
);
809 mutex_unlock(&data
->lock
);
814 static ssize_t
show_alarm(struct device
*dev
,
815 struct device_attribute
*devattr
,
818 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
819 struct adt7470_data
*data
= adt7470_update_device(dev
);
821 if (data
->alarm
& attr
->index
)
822 return sprintf(buf
, "1\n");
824 return sprintf(buf
, "0\n");
827 static DEVICE_ATTR(alarm_mask
, S_IRUGO
, show_alarm_mask
, NULL
);
829 static SENSOR_DEVICE_ATTR(temp1_max
, S_IWUSR
| S_IRUGO
, show_temp_max
,
831 static SENSOR_DEVICE_ATTR(temp2_max
, S_IWUSR
| S_IRUGO
, show_temp_max
,
833 static SENSOR_DEVICE_ATTR(temp3_max
, S_IWUSR
| S_IRUGO
, show_temp_max
,
835 static SENSOR_DEVICE_ATTR(temp4_max
, S_IWUSR
| S_IRUGO
, show_temp_max
,
837 static SENSOR_DEVICE_ATTR(temp5_max
, S_IWUSR
| S_IRUGO
, show_temp_max
,
839 static SENSOR_DEVICE_ATTR(temp6_max
, S_IWUSR
| S_IRUGO
, show_temp_max
,
841 static SENSOR_DEVICE_ATTR(temp7_max
, S_IWUSR
| S_IRUGO
, show_temp_max
,
843 static SENSOR_DEVICE_ATTR(temp8_max
, S_IWUSR
| S_IRUGO
, show_temp_max
,
845 static SENSOR_DEVICE_ATTR(temp9_max
, S_IWUSR
| S_IRUGO
, show_temp_max
,
847 static SENSOR_DEVICE_ATTR(temp10_max
, S_IWUSR
| S_IRUGO
, show_temp_max
,
850 static SENSOR_DEVICE_ATTR(temp1_min
, S_IWUSR
| S_IRUGO
, show_temp_min
,
852 static SENSOR_DEVICE_ATTR(temp2_min
, S_IWUSR
| S_IRUGO
, show_temp_min
,
854 static SENSOR_DEVICE_ATTR(temp3_min
, S_IWUSR
| S_IRUGO
, show_temp_min
,
856 static SENSOR_DEVICE_ATTR(temp4_min
, S_IWUSR
| S_IRUGO
, show_temp_min
,
858 static SENSOR_DEVICE_ATTR(temp5_min
, S_IWUSR
| S_IRUGO
, show_temp_min
,
860 static SENSOR_DEVICE_ATTR(temp6_min
, S_IWUSR
| S_IRUGO
, show_temp_min
,
862 static SENSOR_DEVICE_ATTR(temp7_min
, S_IWUSR
| S_IRUGO
, show_temp_min
,
864 static SENSOR_DEVICE_ATTR(temp8_min
, S_IWUSR
| S_IRUGO
, show_temp_min
,
866 static SENSOR_DEVICE_ATTR(temp9_min
, S_IWUSR
| S_IRUGO
, show_temp_min
,
868 static SENSOR_DEVICE_ATTR(temp10_min
, S_IWUSR
| S_IRUGO
, show_temp_min
,
871 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0);
872 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1);
873 static SENSOR_DEVICE_ATTR(temp3_input
, S_IRUGO
, show_temp
, NULL
, 2);
874 static SENSOR_DEVICE_ATTR(temp4_input
, S_IRUGO
, show_temp
, NULL
, 3);
875 static SENSOR_DEVICE_ATTR(temp5_input
, S_IRUGO
, show_temp
, NULL
, 4);
876 static SENSOR_DEVICE_ATTR(temp6_input
, S_IRUGO
, show_temp
, NULL
, 5);
877 static SENSOR_DEVICE_ATTR(temp7_input
, S_IRUGO
, show_temp
, NULL
, 6);
878 static SENSOR_DEVICE_ATTR(temp8_input
, S_IRUGO
, show_temp
, NULL
, 7);
879 static SENSOR_DEVICE_ATTR(temp9_input
, S_IRUGO
, show_temp
, NULL
, 8);
880 static SENSOR_DEVICE_ATTR(temp10_input
, S_IRUGO
, show_temp
, NULL
, 9);
882 static SENSOR_DEVICE_ATTR(temp1_alarm
, S_IRUGO
, show_alarm
, NULL
,
884 static SENSOR_DEVICE_ATTR(temp2_alarm
, S_IRUGO
, show_alarm
, NULL
,
886 static SENSOR_DEVICE_ATTR(temp3_alarm
, S_IRUGO
, show_alarm
, NULL
,
888 static SENSOR_DEVICE_ATTR(temp4_alarm
, S_IRUGO
, show_alarm
, NULL
,
890 static SENSOR_DEVICE_ATTR(temp5_alarm
, S_IRUGO
, show_alarm
, NULL
,
892 static SENSOR_DEVICE_ATTR(temp6_alarm
, S_IRUGO
, show_alarm
, NULL
,
894 static SENSOR_DEVICE_ATTR(temp7_alarm
, S_IRUGO
, show_alarm
, NULL
,
896 static SENSOR_DEVICE_ATTR(temp8_alarm
, S_IRUGO
, show_alarm
, NULL
,
897 ALARM2(ADT7470_R8T_ALARM
));
898 static SENSOR_DEVICE_ATTR(temp9_alarm
, S_IRUGO
, show_alarm
, NULL
,
899 ALARM2(ADT7470_R9T_ALARM
));
900 static SENSOR_DEVICE_ATTR(temp10_alarm
, S_IRUGO
, show_alarm
, NULL
,
901 ALARM2(ADT7470_R10T_ALARM
));
903 static SENSOR_DEVICE_ATTR(fan1_max
, S_IWUSR
| S_IRUGO
, show_fan_max
,
905 static SENSOR_DEVICE_ATTR(fan2_max
, S_IWUSR
| S_IRUGO
, show_fan_max
,
907 static SENSOR_DEVICE_ATTR(fan3_max
, S_IWUSR
| S_IRUGO
, show_fan_max
,
909 static SENSOR_DEVICE_ATTR(fan4_max
, S_IWUSR
| S_IRUGO
, show_fan_max
,
912 static SENSOR_DEVICE_ATTR(fan1_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
914 static SENSOR_DEVICE_ATTR(fan2_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
916 static SENSOR_DEVICE_ATTR(fan3_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
918 static SENSOR_DEVICE_ATTR(fan4_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
921 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0);
922 static SENSOR_DEVICE_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1);
923 static SENSOR_DEVICE_ATTR(fan3_input
, S_IRUGO
, show_fan
, NULL
, 2);
924 static SENSOR_DEVICE_ATTR(fan4_input
, S_IRUGO
, show_fan
, NULL
, 3);
926 static SENSOR_DEVICE_ATTR(fan1_alarm
, S_IRUGO
, show_alarm
, NULL
,
927 ALARM2(ADT7470_FAN1_ALARM
));
928 static SENSOR_DEVICE_ATTR(fan2_alarm
, S_IRUGO
, show_alarm
, NULL
,
929 ALARM2(ADT7470_FAN2_ALARM
));
930 static SENSOR_DEVICE_ATTR(fan3_alarm
, S_IRUGO
, show_alarm
, NULL
,
931 ALARM2(ADT7470_FAN3_ALARM
));
932 static SENSOR_DEVICE_ATTR(fan4_alarm
, S_IRUGO
, show_alarm
, NULL
,
933 ALARM2(ADT7470_FAN4_ALARM
));
935 static SENSOR_DEVICE_ATTR(force_pwm_max
, S_IWUSR
| S_IRUGO
,
936 show_force_pwm_max
, set_force_pwm_max
, 0);
938 static SENSOR_DEVICE_ATTR(pwm1
, S_IWUSR
| S_IRUGO
, show_pwm
, set_pwm
, 0);
939 static SENSOR_DEVICE_ATTR(pwm2
, S_IWUSR
| S_IRUGO
, show_pwm
, set_pwm
, 1);
940 static SENSOR_DEVICE_ATTR(pwm3
, S_IWUSR
| S_IRUGO
, show_pwm
, set_pwm
, 2);
941 static SENSOR_DEVICE_ATTR(pwm4
, S_IWUSR
| S_IRUGO
, show_pwm
, set_pwm
, 3);
943 static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm
, S_IWUSR
| S_IRUGO
,
944 show_pwm_min
, set_pwm_min
, 0);
945 static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm
, S_IWUSR
| S_IRUGO
,
946 show_pwm_min
, set_pwm_min
, 1);
947 static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm
, S_IWUSR
| S_IRUGO
,
948 show_pwm_min
, set_pwm_min
, 2);
949 static SENSOR_DEVICE_ATTR(pwm4_auto_point1_pwm
, S_IWUSR
| S_IRUGO
,
950 show_pwm_min
, set_pwm_min
, 3);
952 static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm
, S_IWUSR
| S_IRUGO
,
953 show_pwm_max
, set_pwm_max
, 0);
954 static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm
, S_IWUSR
| S_IRUGO
,
955 show_pwm_max
, set_pwm_max
, 1);
956 static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm
, S_IWUSR
| S_IRUGO
,
957 show_pwm_max
, set_pwm_max
, 2);
958 static SENSOR_DEVICE_ATTR(pwm4_auto_point2_pwm
, S_IWUSR
| S_IRUGO
,
959 show_pwm_max
, set_pwm_max
, 3);
961 static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp
, S_IWUSR
| S_IRUGO
,
962 show_pwm_tmin
, set_pwm_tmin
, 0);
963 static SENSOR_DEVICE_ATTR(pwm2_auto_point1_temp
, S_IWUSR
| S_IRUGO
,
964 show_pwm_tmin
, set_pwm_tmin
, 1);
965 static SENSOR_DEVICE_ATTR(pwm3_auto_point1_temp
, S_IWUSR
| S_IRUGO
,
966 show_pwm_tmin
, set_pwm_tmin
, 2);
967 static SENSOR_DEVICE_ATTR(pwm4_auto_point1_temp
, S_IWUSR
| S_IRUGO
,
968 show_pwm_tmin
, set_pwm_tmin
, 3);
970 static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp
, S_IRUGO
, show_pwm_tmax
,
972 static SENSOR_DEVICE_ATTR(pwm2_auto_point2_temp
, S_IRUGO
, show_pwm_tmax
,
974 static SENSOR_DEVICE_ATTR(pwm3_auto_point2_temp
, S_IRUGO
, show_pwm_tmax
,
976 static SENSOR_DEVICE_ATTR(pwm4_auto_point2_temp
, S_IRUGO
, show_pwm_tmax
,
979 static SENSOR_DEVICE_ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
, show_pwm_auto
,
981 static SENSOR_DEVICE_ATTR(pwm2_enable
, S_IWUSR
| S_IRUGO
, show_pwm_auto
,
983 static SENSOR_DEVICE_ATTR(pwm3_enable
, S_IWUSR
| S_IRUGO
, show_pwm_auto
,
985 static SENSOR_DEVICE_ATTR(pwm4_enable
, S_IWUSR
| S_IRUGO
, show_pwm_auto
,
988 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp
, S_IWUSR
| S_IRUGO
,
989 show_pwm_auto_temp
, set_pwm_auto_temp
, 0);
990 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp
, S_IWUSR
| S_IRUGO
,
991 show_pwm_auto_temp
, set_pwm_auto_temp
, 1);
992 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp
, S_IWUSR
| S_IRUGO
,
993 show_pwm_auto_temp
, set_pwm_auto_temp
, 2);
994 static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp
, S_IWUSR
| S_IRUGO
,
995 show_pwm_auto_temp
, set_pwm_auto_temp
, 3);
997 static struct attribute
*adt7470_attr
[] =
999 &dev_attr_alarm_mask
.attr
,
1000 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
1001 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
1002 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
1003 &sensor_dev_attr_temp4_max
.dev_attr
.attr
,
1004 &sensor_dev_attr_temp5_max
.dev_attr
.attr
,
1005 &sensor_dev_attr_temp6_max
.dev_attr
.attr
,
1006 &sensor_dev_attr_temp7_max
.dev_attr
.attr
,
1007 &sensor_dev_attr_temp8_max
.dev_attr
.attr
,
1008 &sensor_dev_attr_temp9_max
.dev_attr
.attr
,
1009 &sensor_dev_attr_temp10_max
.dev_attr
.attr
,
1010 &sensor_dev_attr_temp1_min
.dev_attr
.attr
,
1011 &sensor_dev_attr_temp2_min
.dev_attr
.attr
,
1012 &sensor_dev_attr_temp3_min
.dev_attr
.attr
,
1013 &sensor_dev_attr_temp4_min
.dev_attr
.attr
,
1014 &sensor_dev_attr_temp5_min
.dev_attr
.attr
,
1015 &sensor_dev_attr_temp6_min
.dev_attr
.attr
,
1016 &sensor_dev_attr_temp7_min
.dev_attr
.attr
,
1017 &sensor_dev_attr_temp8_min
.dev_attr
.attr
,
1018 &sensor_dev_attr_temp9_min
.dev_attr
.attr
,
1019 &sensor_dev_attr_temp10_min
.dev_attr
.attr
,
1020 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
1021 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
1022 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
1023 &sensor_dev_attr_temp4_input
.dev_attr
.attr
,
1024 &sensor_dev_attr_temp5_input
.dev_attr
.attr
,
1025 &sensor_dev_attr_temp6_input
.dev_attr
.attr
,
1026 &sensor_dev_attr_temp7_input
.dev_attr
.attr
,
1027 &sensor_dev_attr_temp8_input
.dev_attr
.attr
,
1028 &sensor_dev_attr_temp9_input
.dev_attr
.attr
,
1029 &sensor_dev_attr_temp10_input
.dev_attr
.attr
,
1030 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
1031 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
1032 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
1033 &sensor_dev_attr_temp4_alarm
.dev_attr
.attr
,
1034 &sensor_dev_attr_temp5_alarm
.dev_attr
.attr
,
1035 &sensor_dev_attr_temp6_alarm
.dev_attr
.attr
,
1036 &sensor_dev_attr_temp7_alarm
.dev_attr
.attr
,
1037 &sensor_dev_attr_temp8_alarm
.dev_attr
.attr
,
1038 &sensor_dev_attr_temp9_alarm
.dev_attr
.attr
,
1039 &sensor_dev_attr_temp10_alarm
.dev_attr
.attr
,
1040 &sensor_dev_attr_fan1_max
.dev_attr
.attr
,
1041 &sensor_dev_attr_fan2_max
.dev_attr
.attr
,
1042 &sensor_dev_attr_fan3_max
.dev_attr
.attr
,
1043 &sensor_dev_attr_fan4_max
.dev_attr
.attr
,
1044 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
1045 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
1046 &sensor_dev_attr_fan3_min
.dev_attr
.attr
,
1047 &sensor_dev_attr_fan4_min
.dev_attr
.attr
,
1048 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
1049 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
1050 &sensor_dev_attr_fan3_input
.dev_attr
.attr
,
1051 &sensor_dev_attr_fan4_input
.dev_attr
.attr
,
1052 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
1053 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
1054 &sensor_dev_attr_fan3_alarm
.dev_attr
.attr
,
1055 &sensor_dev_attr_fan4_alarm
.dev_attr
.attr
,
1056 &sensor_dev_attr_force_pwm_max
.dev_attr
.attr
,
1057 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
1058 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
1059 &sensor_dev_attr_pwm3
.dev_attr
.attr
,
1060 &sensor_dev_attr_pwm4
.dev_attr
.attr
,
1061 &sensor_dev_attr_pwm1_auto_point1_pwm
.dev_attr
.attr
,
1062 &sensor_dev_attr_pwm2_auto_point1_pwm
.dev_attr
.attr
,
1063 &sensor_dev_attr_pwm3_auto_point1_pwm
.dev_attr
.attr
,
1064 &sensor_dev_attr_pwm4_auto_point1_pwm
.dev_attr
.attr
,
1065 &sensor_dev_attr_pwm1_auto_point2_pwm
.dev_attr
.attr
,
1066 &sensor_dev_attr_pwm2_auto_point2_pwm
.dev_attr
.attr
,
1067 &sensor_dev_attr_pwm3_auto_point2_pwm
.dev_attr
.attr
,
1068 &sensor_dev_attr_pwm4_auto_point2_pwm
.dev_attr
.attr
,
1069 &sensor_dev_attr_pwm1_auto_point1_temp
.dev_attr
.attr
,
1070 &sensor_dev_attr_pwm2_auto_point1_temp
.dev_attr
.attr
,
1071 &sensor_dev_attr_pwm3_auto_point1_temp
.dev_attr
.attr
,
1072 &sensor_dev_attr_pwm4_auto_point1_temp
.dev_attr
.attr
,
1073 &sensor_dev_attr_pwm1_auto_point2_temp
.dev_attr
.attr
,
1074 &sensor_dev_attr_pwm2_auto_point2_temp
.dev_attr
.attr
,
1075 &sensor_dev_attr_pwm3_auto_point2_temp
.dev_attr
.attr
,
1076 &sensor_dev_attr_pwm4_auto_point2_temp
.dev_attr
.attr
,
1077 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
1078 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
1079 &sensor_dev_attr_pwm3_enable
.dev_attr
.attr
,
1080 &sensor_dev_attr_pwm4_enable
.dev_attr
.attr
,
1081 &sensor_dev_attr_pwm1_auto_channels_temp
.dev_attr
.attr
,
1082 &sensor_dev_attr_pwm2_auto_channels_temp
.dev_attr
.attr
,
1083 &sensor_dev_attr_pwm3_auto_channels_temp
.dev_attr
.attr
,
1084 &sensor_dev_attr_pwm4_auto_channels_temp
.dev_attr
.attr
,
1088 /* Return 0 if detection is successful, -ENODEV otherwise */
1089 static int adt7470_detect(struct i2c_client
*client
, int kind
,
1090 struct i2c_board_info
*info
)
1092 struct i2c_adapter
*adapter
= client
->adapter
;
1094 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
1098 int vendor
, device
, revision
;
1100 vendor
= i2c_smbus_read_byte_data(client
, ADT7470_REG_VENDOR
);
1101 if (vendor
!= ADT7470_VENDOR
)
1104 device
= i2c_smbus_read_byte_data(client
, ADT7470_REG_DEVICE
);
1105 if (device
!= ADT7470_DEVICE
)
1108 revision
= i2c_smbus_read_byte_data(client
,
1109 ADT7470_REG_REVISION
);
1110 if (revision
!= ADT7470_REVISION
)
1113 dev_dbg(&adapter
->dev
, "detection forced\n");
1115 strlcpy(info
->type
, "adt7470", I2C_NAME_SIZE
);
1120 static int adt7470_probe(struct i2c_client
*client
,
1121 const struct i2c_device_id
*id
)
1123 struct adt7470_data
*data
;
1126 data
= kzalloc(sizeof(struct adt7470_data
), GFP_KERNEL
);
1132 i2c_set_clientdata(client
, data
);
1133 mutex_init(&data
->lock
);
1135 dev_info(&client
->dev
, "%s chip found\n", client
->name
);
1137 /* Initialize the ADT7470 chip */
1138 adt7470_init_client(client
);
1140 /* Register sysfs hooks */
1141 data
->attrs
.attrs
= adt7470_attr
;
1142 if ((err
= sysfs_create_group(&client
->dev
.kobj
, &data
->attrs
)))
1145 data
->hwmon_dev
= hwmon_device_register(&client
->dev
);
1146 if (IS_ERR(data
->hwmon_dev
)) {
1147 err
= PTR_ERR(data
->hwmon_dev
);
1154 sysfs_remove_group(&client
->dev
.kobj
, &data
->attrs
);
1161 static int adt7470_remove(struct i2c_client
*client
)
1163 struct adt7470_data
*data
= i2c_get_clientdata(client
);
1165 hwmon_device_unregister(data
->hwmon_dev
);
1166 sysfs_remove_group(&client
->dev
.kobj
, &data
->attrs
);
1171 static int __init
adt7470_init(void)
1173 return i2c_add_driver(&adt7470_driver
);
1176 static void __exit
adt7470_exit(void)
1178 i2c_del_driver(&adt7470_driver
);
1181 MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>");
1182 MODULE_DESCRIPTION("ADT7470 driver");
1183 MODULE_LICENSE("GPL");
1185 module_init(adt7470_init
);
1186 module_exit(adt7470_exit
);