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_REG_PWM34_CFG 0x69
78 #define ADT7470_PWM3_AUTO_MASK 0x40
79 #define ADT7470_PWM4_AUTO_MASK 0x80
80 #define ADT7470_REG_PWM_MIN_BASE_ADDR 0x6A
81 #define ADT7470_REG_PWM_MIN_MAX_ADDR 0x6D
82 #define ADT7470_REG_PWM_TEMP_MIN_BASE_ADDR 0x6E
83 #define ADT7470_REG_PWM_TEMP_MIN_MAX_ADDR 0x71
84 #define ADT7470_REG_ACOUSTICS12 0x75
85 #define ADT7470_REG_ACOUSTICS34 0x76
86 #define ADT7470_REG_DEVICE 0x3D
87 #define ADT7470_REG_VENDOR 0x3E
88 #define ADT7470_REG_REVISION 0x3F
89 #define ADT7470_REG_ALARM1_MASK 0x72
90 #define ADT7470_REG_ALARM2_MASK 0x73
91 #define ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR 0x7C
92 #define ADT7470_REG_PWM_AUTO_TEMP_MAX_ADDR 0x7D
93 #define ADT7470_REG_MAX_ADDR 0x81
95 #define ADT7470_TEMP_COUNT 10
96 #define ADT7470_TEMP_REG(x) (ADT7470_REG_TEMP_BASE_ADDR + (x))
97 #define ADT7470_TEMP_MIN_REG(x) (ADT7470_REG_TEMP_LIMITS_BASE_ADDR + ((x) * 2))
98 #define ADT7470_TEMP_MAX_REG(x) (ADT7470_REG_TEMP_LIMITS_BASE_ADDR + \
101 #define ADT7470_FAN_COUNT 4
102 #define ADT7470_REG_FAN(x) (ADT7470_REG_FAN_BASE_ADDR + ((x) * 2))
103 #define ADT7470_REG_FAN_MIN(x) (ADT7470_REG_FAN_MIN_BASE_ADDR + ((x) * 2))
104 #define ADT7470_REG_FAN_MAX(x) (ADT7470_REG_FAN_MAX_BASE_ADDR + ((x) * 2))
106 #define ADT7470_PWM_COUNT 4
107 #define ADT7470_REG_PWM(x) (ADT7470_REG_PWM_BASE_ADDR + (x))
108 #define ADT7470_REG_PWM_MAX(x) (ADT7470_REG_PWM_MAX_BASE_ADDR + (x))
109 #define ADT7470_REG_PWM_MIN(x) (ADT7470_REG_PWM_MIN_BASE_ADDR + (x))
110 #define ADT7470_REG_PWM_TMIN(x) (ADT7470_REG_PWM_TEMP_MIN_BASE_ADDR + (x))
111 #define ADT7470_REG_PWM_CFG(x) (ADT7470_REG_PWM_CFG_BASE_ADDR + ((x) / 2))
112 #define ADT7470_REG_PWM_AUTO_TEMP(x) (ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR + \
115 #define ALARM2(x) ((x) << 8)
117 #define ADT7470_VENDOR 0x41
118 #define ADT7470_DEVICE 0x70
119 /* datasheet only mentions a revision 2 */
120 #define ADT7470_REVISION 0x02
122 /* "all temps" according to hwmon sysfs interface spec */
123 #define ADT7470_PWM_ALL_TEMPS 0x3FF
125 /* How often do we reread sensors values? (In jiffies) */
126 #define SENSOR_REFRESH_INTERVAL (5 * HZ)
128 /* How often do we reread sensor limit values? (In jiffies) */
129 #define LIMIT_REFRESH_INTERVAL (60 * HZ)
131 /* sleep 1s while gathering temperature data */
132 #define TEMP_COLLECTION_TIME 1000
134 /* datasheet says to divide this number by the fan reading to get fan rpm */
135 #define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
136 #define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
137 #define FAN_PERIOD_INVALID 65535
138 #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
140 #define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor))
142 struct adt7470_data {
143 struct device *hwmon_dev;
144 struct attribute_group attrs;
148 unsigned long sensors_last_updated; /* In jiffies */
149 unsigned long limits_last_updated; /* In jiffies */
151 s8 temp[ADT7470_TEMP_COUNT];
152 s8 temp_min[ADT7470_TEMP_COUNT];
153 s8 temp_max[ADT7470_TEMP_COUNT];
154 u16 fan[ADT7470_FAN_COUNT];
155 u16 fan_min[ADT7470_FAN_COUNT];
156 u16 fan_max[ADT7470_FAN_COUNT];
160 u8 pwm[ADT7470_PWM_COUNT];
161 u8 pwm_max[ADT7470_PWM_COUNT];
162 u8 pwm_automatic[ADT7470_PWM_COUNT];
163 u8 pwm_min[ADT7470_PWM_COUNT];
164 s8 pwm_tmin[ADT7470_PWM_COUNT];
165 u8 pwm_auto_temp[ADT7470_PWM_COUNT];
168 static int adt7470_probe(struct i2c_client *client,
169 const struct i2c_device_id *id);
170 static int adt7470_detect(struct i2c_client *client, int kind,
171 struct i2c_board_info *info);
172 static int adt7470_remove(struct i2c_client *client);
174 static const struct i2c_device_id adt7470_id[] = {
175 { "adt7470", adt7470 },
178 MODULE_DEVICE_TABLE(i2c, adt7470_id);
180 static struct i2c_driver adt7470_driver = {
181 .class = I2C_CLASS_HWMON,
185 .probe = adt7470_probe,
186 .remove = adt7470_remove,
187 .id_table = adt7470_id,
188 .detect = adt7470_detect,
189 .address_data = &addr_data,
193 * 16-bit registers on the ADT7470 are low-byte first. The data sheet says
194 * that the low byte must be read before the high byte.
196 static inline int adt7470_read_word_data(struct i2c_client *client, u8 reg)
199 foo = i2c_smbus_read_byte_data(client, reg);
200 foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8);
204 static inline int adt7470_write_word_data(struct i2c_client *client, u8 reg,
207 return i2c_smbus_write_byte_data(client, reg, value & 0xFF)
208 && i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
211 static void adt7470_init_client(struct i2c_client *client)
213 int reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
216 dev_err(&client->dev, "cannot read configuration register\n");
218 /* start monitoring (and do a self-test) */
219 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, reg | 3);
223 static struct adt7470_data *adt7470_update_device(struct device *dev)
225 struct i2c_client *client = to_i2c_client(dev);
226 struct adt7470_data *data = i2c_get_clientdata(client);
227 unsigned long local_jiffies = jiffies;
231 mutex_lock(&data->lock);
232 if (time_before(local_jiffies, data->sensors_last_updated +
233 SENSOR_REFRESH_INTERVAL)
234 && data->sensors_valid)
235 goto no_sensor_update;
237 /* start reading temperature sensors */
238 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
240 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg);
243 * Delay is 200ms * number of tmp05 sensors. Too bad
244 * there's no way to figure out how many are connected.
245 * For now, assume 1s will work.
247 msleep(TEMP_COLLECTION_TIME);
249 /* done reading temperature sensors */
250 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
252 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg);
254 for (i = 0; i < ADT7470_TEMP_COUNT; i++)
255 data->temp[i] = i2c_smbus_read_byte_data(client,
256 ADT7470_TEMP_REG(i));
258 for (i = 0; i < ADT7470_FAN_COUNT; i++)
259 data->fan[i] = adt7470_read_word_data(client,
262 for (i = 0; i < ADT7470_PWM_COUNT; i++) {
266 data->pwm[i] = i2c_smbus_read_byte_data(client,
270 reg_mask = ADT7470_PWM2_AUTO_MASK;
272 reg_mask = ADT7470_PWM1_AUTO_MASK;
274 reg = ADT7470_REG_PWM_CFG(i);
275 if (i2c_smbus_read_byte_data(client, reg) & reg_mask)
276 data->pwm_automatic[i] = 1;
278 data->pwm_automatic[i] = 0;
280 reg = ADT7470_REG_PWM_AUTO_TEMP(i);
281 cfg = i2c_smbus_read_byte_data(client, reg);
283 data->pwm_auto_temp[i] = cfg >> 4;
285 data->pwm_auto_temp[i] = cfg & 0xF;
288 if (i2c_smbus_read_byte_data(client, ADT7470_REG_CFG) &
290 data->force_pwm_max = 1;
292 data->force_pwm_max = 0;
294 data->alarm = i2c_smbus_read_byte_data(client, ADT7470_REG_ALARM1);
295 if (data->alarm & ADT7470_OOL_ALARM)
296 data->alarm |= ALARM2(i2c_smbus_read_byte_data(client,
297 ADT7470_REG_ALARM2));
298 data->alarms_mask = adt7470_read_word_data(client,
299 ADT7470_REG_ALARM1_MASK);
301 data->sensors_last_updated = local_jiffies;
302 data->sensors_valid = 1;
305 if (time_before(local_jiffies, data->limits_last_updated +
306 LIMIT_REFRESH_INTERVAL)
307 && data->limits_valid)
310 for (i = 0; i < ADT7470_TEMP_COUNT; i++) {
311 data->temp_min[i] = i2c_smbus_read_byte_data(client,
312 ADT7470_TEMP_MIN_REG(i));
313 data->temp_max[i] = i2c_smbus_read_byte_data(client,
314 ADT7470_TEMP_MAX_REG(i));
317 for (i = 0; i < ADT7470_FAN_COUNT; i++) {
318 data->fan_min[i] = adt7470_read_word_data(client,
319 ADT7470_REG_FAN_MIN(i));
320 data->fan_max[i] = adt7470_read_word_data(client,
321 ADT7470_REG_FAN_MAX(i));
324 for (i = 0; i < ADT7470_PWM_COUNT; i++) {
325 data->pwm_max[i] = i2c_smbus_read_byte_data(client,
326 ADT7470_REG_PWM_MAX(i));
327 data->pwm_min[i] = i2c_smbus_read_byte_data(client,
328 ADT7470_REG_PWM_MIN(i));
329 data->pwm_tmin[i] = i2c_smbus_read_byte_data(client,
330 ADT7470_REG_PWM_TMIN(i));
333 data->limits_last_updated = local_jiffies;
334 data->limits_valid = 1;
337 mutex_unlock(&data->lock);
341 static ssize_t show_temp_min(struct device *dev,
342 struct device_attribute *devattr,
345 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
346 struct adt7470_data *data = adt7470_update_device(dev);
347 return sprintf(buf, "%d\n", 1000 * data->temp_min[attr->index]);
350 static ssize_t set_temp_min(struct device *dev,
351 struct device_attribute *devattr,
355 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
356 struct i2c_client *client = to_i2c_client(dev);
357 struct adt7470_data *data = i2c_get_clientdata(client);
360 if (strict_strtol(buf, 10, &temp))
363 temp = ROUND_DIV(temp, 1000);
364 temp = SENSORS_LIMIT(temp, 0, 255);
366 mutex_lock(&data->lock);
367 data->temp_min[attr->index] = temp;
368 i2c_smbus_write_byte_data(client, ADT7470_TEMP_MIN_REG(attr->index),
370 mutex_unlock(&data->lock);
375 static ssize_t show_temp_max(struct device *dev,
376 struct device_attribute *devattr,
379 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
380 struct adt7470_data *data = adt7470_update_device(dev);
381 return sprintf(buf, "%d\n", 1000 * data->temp_max[attr->index]);
384 static ssize_t set_temp_max(struct device *dev,
385 struct device_attribute *devattr,
389 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
390 struct i2c_client *client = to_i2c_client(dev);
391 struct adt7470_data *data = i2c_get_clientdata(client);
394 if (strict_strtol(buf, 10, &temp))
397 temp = ROUND_DIV(temp, 1000);
398 temp = SENSORS_LIMIT(temp, 0, 255);
400 mutex_lock(&data->lock);
401 data->temp_max[attr->index] = temp;
402 i2c_smbus_write_byte_data(client, ADT7470_TEMP_MAX_REG(attr->index),
404 mutex_unlock(&data->lock);
409 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
412 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
413 struct adt7470_data *data = adt7470_update_device(dev);
414 return sprintf(buf, "%d\n", 1000 * data->temp[attr->index]);
417 static ssize_t show_alarm_mask(struct device *dev,
418 struct device_attribute *devattr,
421 struct adt7470_data *data = adt7470_update_device(dev);
423 return sprintf(buf, "%x\n", data->alarms_mask);
426 static ssize_t show_fan_max(struct device *dev,
427 struct device_attribute *devattr,
430 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
431 struct adt7470_data *data = adt7470_update_device(dev);
433 if (FAN_DATA_VALID(data->fan_max[attr->index]))
434 return sprintf(buf, "%d\n",
435 FAN_PERIOD_TO_RPM(data->fan_max[attr->index]));
437 return sprintf(buf, "0\n");
440 static ssize_t set_fan_max(struct device *dev,
441 struct device_attribute *devattr,
442 const char *buf, size_t count)
444 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
445 struct i2c_client *client = to_i2c_client(dev);
446 struct adt7470_data *data = i2c_get_clientdata(client);
449 if (strict_strtol(buf, 10, &temp) || !temp)
452 temp = FAN_RPM_TO_PERIOD(temp);
453 temp = SENSORS_LIMIT(temp, 1, 65534);
455 mutex_lock(&data->lock);
456 data->fan_max[attr->index] = temp;
457 adt7470_write_word_data(client, ADT7470_REG_FAN_MAX(attr->index), temp);
458 mutex_unlock(&data->lock);
463 static ssize_t show_fan_min(struct device *dev,
464 struct device_attribute *devattr,
467 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
468 struct adt7470_data *data = adt7470_update_device(dev);
470 if (FAN_DATA_VALID(data->fan_min[attr->index]))
471 return sprintf(buf, "%d\n",
472 FAN_PERIOD_TO_RPM(data->fan_min[attr->index]));
474 return sprintf(buf, "0\n");
477 static ssize_t set_fan_min(struct device *dev,
478 struct device_attribute *devattr,
479 const char *buf, size_t count)
481 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
482 struct i2c_client *client = to_i2c_client(dev);
483 struct adt7470_data *data = i2c_get_clientdata(client);
486 if (strict_strtol(buf, 10, &temp) || !temp)
489 temp = FAN_RPM_TO_PERIOD(temp);
490 temp = SENSORS_LIMIT(temp, 1, 65534);
492 mutex_lock(&data->lock);
493 data->fan_min[attr->index] = temp;
494 adt7470_write_word_data(client, ADT7470_REG_FAN_MIN(attr->index), temp);
495 mutex_unlock(&data->lock);
500 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
503 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
504 struct adt7470_data *data = adt7470_update_device(dev);
506 if (FAN_DATA_VALID(data->fan[attr->index]))
507 return sprintf(buf, "%d\n",
508 FAN_PERIOD_TO_RPM(data->fan[attr->index]));
510 return sprintf(buf, "0\n");
513 static ssize_t show_force_pwm_max(struct device *dev,
514 struct device_attribute *devattr,
517 struct adt7470_data *data = adt7470_update_device(dev);
518 return sprintf(buf, "%d\n", data->force_pwm_max);
521 static ssize_t set_force_pwm_max(struct device *dev,
522 struct device_attribute *devattr,
526 struct i2c_client *client = to_i2c_client(dev);
527 struct adt7470_data *data = i2c_get_clientdata(client);
531 if (strict_strtol(buf, 10, &temp))
534 mutex_lock(&data->lock);
535 data->force_pwm_max = temp;
536 reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
538 reg |= ADT7470_FSPD_MASK;
540 reg &= ~ADT7470_FSPD_MASK;
541 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, reg);
542 mutex_unlock(&data->lock);
547 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
550 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
551 struct adt7470_data *data = adt7470_update_device(dev);
552 return sprintf(buf, "%d\n", data->pwm[attr->index]);
555 static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
556 const char *buf, size_t count)
558 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
559 struct i2c_client *client = to_i2c_client(dev);
560 struct adt7470_data *data = i2c_get_clientdata(client);
563 if (strict_strtol(buf, 10, &temp))
566 temp = SENSORS_LIMIT(temp, 0, 255);
568 mutex_lock(&data->lock);
569 data->pwm[attr->index] = temp;
570 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM(attr->index), temp);
571 mutex_unlock(&data->lock);
576 static ssize_t show_pwm_max(struct device *dev,
577 struct device_attribute *devattr,
580 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
581 struct adt7470_data *data = adt7470_update_device(dev);
582 return sprintf(buf, "%d\n", data->pwm_max[attr->index]);
585 static ssize_t set_pwm_max(struct device *dev,
586 struct device_attribute *devattr,
590 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
591 struct i2c_client *client = to_i2c_client(dev);
592 struct adt7470_data *data = i2c_get_clientdata(client);
595 if (strict_strtol(buf, 10, &temp))
598 temp = SENSORS_LIMIT(temp, 0, 255);
600 mutex_lock(&data->lock);
601 data->pwm_max[attr->index] = temp;
602 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_MAX(attr->index),
604 mutex_unlock(&data->lock);
609 static ssize_t show_pwm_min(struct device *dev,
610 struct device_attribute *devattr,
613 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
614 struct adt7470_data *data = adt7470_update_device(dev);
615 return sprintf(buf, "%d\n", data->pwm_min[attr->index]);
618 static ssize_t set_pwm_min(struct device *dev,
619 struct device_attribute *devattr,
623 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
624 struct i2c_client *client = to_i2c_client(dev);
625 struct adt7470_data *data = i2c_get_clientdata(client);
628 if (strict_strtol(buf, 10, &temp))
631 temp = SENSORS_LIMIT(temp, 0, 255);
633 mutex_lock(&data->lock);
634 data->pwm_min[attr->index] = temp;
635 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_MIN(attr->index),
637 mutex_unlock(&data->lock);
642 static ssize_t show_pwm_tmax(struct device *dev,
643 struct device_attribute *devattr,
646 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
647 struct adt7470_data *data = adt7470_update_device(dev);
648 /* the datasheet says that tmax = tmin + 20C */
649 return sprintf(buf, "%d\n", 1000 * (20 + data->pwm_tmin[attr->index]));
652 static ssize_t show_pwm_tmin(struct device *dev,
653 struct device_attribute *devattr,
656 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
657 struct adt7470_data *data = adt7470_update_device(dev);
658 return sprintf(buf, "%d\n", 1000 * data->pwm_tmin[attr->index]);
661 static ssize_t set_pwm_tmin(struct device *dev,
662 struct device_attribute *devattr,
666 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
667 struct i2c_client *client = to_i2c_client(dev);
668 struct adt7470_data *data = i2c_get_clientdata(client);
671 if (strict_strtol(buf, 10, &temp))
674 temp = ROUND_DIV(temp, 1000);
675 temp = SENSORS_LIMIT(temp, 0, 255);
677 mutex_lock(&data->lock);
678 data->pwm_tmin[attr->index] = temp;
679 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_TMIN(attr->index),
681 mutex_unlock(&data->lock);
686 static ssize_t show_pwm_auto(struct device *dev,
687 struct device_attribute *devattr,
690 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
691 struct adt7470_data *data = adt7470_update_device(dev);
692 return sprintf(buf, "%d\n", 1 + data->pwm_automatic[attr->index]);
695 static ssize_t set_pwm_auto(struct device *dev,
696 struct device_attribute *devattr,
700 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
701 struct i2c_client *client = to_i2c_client(dev);
702 struct adt7470_data *data = i2c_get_clientdata(client);
703 int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index);
704 int pwm_auto_reg_mask;
708 if (strict_strtol(buf, 10, &temp))
712 pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK;
714 pwm_auto_reg_mask = ADT7470_PWM1_AUTO_MASK;
716 if (temp != 2 && temp != 1)
720 mutex_lock(&data->lock);
721 data->pwm_automatic[attr->index] = temp;
722 reg = i2c_smbus_read_byte_data(client, pwm_auto_reg);
724 reg |= pwm_auto_reg_mask;
726 reg &= ~pwm_auto_reg_mask;
727 i2c_smbus_write_byte_data(client, pwm_auto_reg, reg);
728 mutex_unlock(&data->lock);
733 static ssize_t show_pwm_auto_temp(struct device *dev,
734 struct device_attribute *devattr,
737 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
738 struct adt7470_data *data = adt7470_update_device(dev);
739 u8 ctrl = data->pwm_auto_temp[attr->index];
742 return sprintf(buf, "%d\n", 1 << (ctrl - 1));
744 return sprintf(buf, "%d\n", ADT7470_PWM_ALL_TEMPS);
747 static int cvt_auto_temp(int input)
749 if (input == ADT7470_PWM_ALL_TEMPS)
751 if (input < 1 || !is_power_of_2(input))
753 return ilog2(input) + 1;
756 static ssize_t set_pwm_auto_temp(struct device *dev,
757 struct device_attribute *devattr,
761 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
762 struct i2c_client *client = to_i2c_client(dev);
763 struct adt7470_data *data = i2c_get_clientdata(client);
764 int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index);
768 if (strict_strtol(buf, 10, &temp))
771 temp = cvt_auto_temp(temp);
775 mutex_lock(&data->lock);
776 data->pwm_automatic[attr->index] = temp;
777 reg = i2c_smbus_read_byte_data(client, pwm_auto_reg);
779 if (!(attr->index % 2)) {
781 reg |= (temp << 4) & 0xF0;
787 i2c_smbus_write_byte_data(client, pwm_auto_reg, reg);
788 mutex_unlock(&data->lock);
793 static ssize_t show_alarm(struct device *dev,
794 struct device_attribute *devattr,
797 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
798 struct adt7470_data *data = adt7470_update_device(dev);
800 if (data->alarm & attr->index)
801 return sprintf(buf, "1\n");
803 return sprintf(buf, "0\n");
806 static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
808 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
810 static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
812 static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max,
814 static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max,
816 static SENSOR_DEVICE_ATTR(temp5_max, S_IWUSR | S_IRUGO, show_temp_max,
818 static SENSOR_DEVICE_ATTR(temp6_max, S_IWUSR | S_IRUGO, show_temp_max,
820 static SENSOR_DEVICE_ATTR(temp7_max, S_IWUSR | S_IRUGO, show_temp_max,
822 static SENSOR_DEVICE_ATTR(temp8_max, S_IWUSR | S_IRUGO, show_temp_max,
824 static SENSOR_DEVICE_ATTR(temp9_max, S_IWUSR | S_IRUGO, show_temp_max,
826 static SENSOR_DEVICE_ATTR(temp10_max, S_IWUSR | S_IRUGO, show_temp_max,
829 static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min,
831 static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min,
833 static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min,
835 static SENSOR_DEVICE_ATTR(temp4_min, S_IWUSR | S_IRUGO, show_temp_min,
837 static SENSOR_DEVICE_ATTR(temp5_min, S_IWUSR | S_IRUGO, show_temp_min,
839 static SENSOR_DEVICE_ATTR(temp6_min, S_IWUSR | S_IRUGO, show_temp_min,
841 static SENSOR_DEVICE_ATTR(temp7_min, S_IWUSR | S_IRUGO, show_temp_min,
843 static SENSOR_DEVICE_ATTR(temp8_min, S_IWUSR | S_IRUGO, show_temp_min,
845 static SENSOR_DEVICE_ATTR(temp9_min, S_IWUSR | S_IRUGO, show_temp_min,
847 static SENSOR_DEVICE_ATTR(temp10_min, S_IWUSR | S_IRUGO, show_temp_min,
850 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
851 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
852 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
853 static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
854 static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4);
855 static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, show_temp, NULL, 5);
856 static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO, show_temp, NULL, 6);
857 static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_temp, NULL, 7);
858 static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8);
859 static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_temp, NULL, 9);
861 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
863 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
865 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
867 static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL,
869 static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL,
871 static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL,
873 static SENSOR_DEVICE_ATTR(temp7_alarm, S_IRUGO, show_alarm, NULL,
875 static SENSOR_DEVICE_ATTR(temp8_alarm, S_IRUGO, show_alarm, NULL,
876 ALARM2(ADT7470_R8T_ALARM));
877 static SENSOR_DEVICE_ATTR(temp9_alarm, S_IRUGO, show_alarm, NULL,
878 ALARM2(ADT7470_R9T_ALARM));
879 static SENSOR_DEVICE_ATTR(temp10_alarm, S_IRUGO, show_alarm, NULL,
880 ALARM2(ADT7470_R10T_ALARM));
882 static SENSOR_DEVICE_ATTR(fan1_max, S_IWUSR | S_IRUGO, show_fan_max,
884 static SENSOR_DEVICE_ATTR(fan2_max, S_IWUSR | S_IRUGO, show_fan_max,
886 static SENSOR_DEVICE_ATTR(fan3_max, S_IWUSR | S_IRUGO, show_fan_max,
888 static SENSOR_DEVICE_ATTR(fan4_max, S_IWUSR | S_IRUGO, show_fan_max,
891 static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
893 static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
895 static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min,
897 static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
900 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
901 static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
902 static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
903 static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
905 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL,
906 ALARM2(ADT7470_FAN1_ALARM));
907 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL,
908 ALARM2(ADT7470_FAN2_ALARM));
909 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL,
910 ALARM2(ADT7470_FAN3_ALARM));
911 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL,
912 ALARM2(ADT7470_FAN4_ALARM));
914 static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO,
915 show_force_pwm_max, set_force_pwm_max, 0);
917 static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0);
918 static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1);
919 static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2);
920 static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 3);
922 static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO,
923 show_pwm_min, set_pwm_min, 0);
924 static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO,
925 show_pwm_min, set_pwm_min, 1);
926 static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO,
927 show_pwm_min, set_pwm_min, 2);
928 static SENSOR_DEVICE_ATTR(pwm4_auto_point1_pwm, S_IWUSR | S_IRUGO,
929 show_pwm_min, set_pwm_min, 3);
931 static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO,
932 show_pwm_max, set_pwm_max, 0);
933 static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO,
934 show_pwm_max, set_pwm_max, 1);
935 static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO,
936 show_pwm_max, set_pwm_max, 2);
937 static SENSOR_DEVICE_ATTR(pwm4_auto_point2_pwm, S_IWUSR | S_IRUGO,
938 show_pwm_max, set_pwm_max, 3);
940 static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp, S_IWUSR | S_IRUGO,
941 show_pwm_tmin, set_pwm_tmin, 0);
942 static SENSOR_DEVICE_ATTR(pwm2_auto_point1_temp, S_IWUSR | S_IRUGO,
943 show_pwm_tmin, set_pwm_tmin, 1);
944 static SENSOR_DEVICE_ATTR(pwm3_auto_point1_temp, S_IWUSR | S_IRUGO,
945 show_pwm_tmin, set_pwm_tmin, 2);
946 static SENSOR_DEVICE_ATTR(pwm4_auto_point1_temp, S_IWUSR | S_IRUGO,
947 show_pwm_tmin, set_pwm_tmin, 3);
949 static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp, S_IRUGO, show_pwm_tmax,
951 static SENSOR_DEVICE_ATTR(pwm2_auto_point2_temp, S_IRUGO, show_pwm_tmax,
953 static SENSOR_DEVICE_ATTR(pwm3_auto_point2_temp, S_IRUGO, show_pwm_tmax,
955 static SENSOR_DEVICE_ATTR(pwm4_auto_point2_temp, S_IRUGO, show_pwm_tmax,
958 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
960 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
962 static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
964 static SENSOR_DEVICE_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
967 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO,
968 show_pwm_auto_temp, set_pwm_auto_temp, 0);
969 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO,
970 show_pwm_auto_temp, set_pwm_auto_temp, 1);
971 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO,
972 show_pwm_auto_temp, set_pwm_auto_temp, 2);
973 static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
974 show_pwm_auto_temp, set_pwm_auto_temp, 3);
976 static struct attribute *adt7470_attr[] =
978 &dev_attr_alarm_mask.attr,
979 &sensor_dev_attr_temp1_max.dev_attr.attr,
980 &sensor_dev_attr_temp2_max.dev_attr.attr,
981 &sensor_dev_attr_temp3_max.dev_attr.attr,
982 &sensor_dev_attr_temp4_max.dev_attr.attr,
983 &sensor_dev_attr_temp5_max.dev_attr.attr,
984 &sensor_dev_attr_temp6_max.dev_attr.attr,
985 &sensor_dev_attr_temp7_max.dev_attr.attr,
986 &sensor_dev_attr_temp8_max.dev_attr.attr,
987 &sensor_dev_attr_temp9_max.dev_attr.attr,
988 &sensor_dev_attr_temp10_max.dev_attr.attr,
989 &sensor_dev_attr_temp1_min.dev_attr.attr,
990 &sensor_dev_attr_temp2_min.dev_attr.attr,
991 &sensor_dev_attr_temp3_min.dev_attr.attr,
992 &sensor_dev_attr_temp4_min.dev_attr.attr,
993 &sensor_dev_attr_temp5_min.dev_attr.attr,
994 &sensor_dev_attr_temp6_min.dev_attr.attr,
995 &sensor_dev_attr_temp7_min.dev_attr.attr,
996 &sensor_dev_attr_temp8_min.dev_attr.attr,
997 &sensor_dev_attr_temp9_min.dev_attr.attr,
998 &sensor_dev_attr_temp10_min.dev_attr.attr,
999 &sensor_dev_attr_temp1_input.dev_attr.attr,
1000 &sensor_dev_attr_temp2_input.dev_attr.attr,
1001 &sensor_dev_attr_temp3_input.dev_attr.attr,
1002 &sensor_dev_attr_temp4_input.dev_attr.attr,
1003 &sensor_dev_attr_temp5_input.dev_attr.attr,
1004 &sensor_dev_attr_temp6_input.dev_attr.attr,
1005 &sensor_dev_attr_temp7_input.dev_attr.attr,
1006 &sensor_dev_attr_temp8_input.dev_attr.attr,
1007 &sensor_dev_attr_temp9_input.dev_attr.attr,
1008 &sensor_dev_attr_temp10_input.dev_attr.attr,
1009 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1010 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1011 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1012 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
1013 &sensor_dev_attr_temp5_alarm.dev_attr.attr,
1014 &sensor_dev_attr_temp6_alarm.dev_attr.attr,
1015 &sensor_dev_attr_temp7_alarm.dev_attr.attr,
1016 &sensor_dev_attr_temp8_alarm.dev_attr.attr,
1017 &sensor_dev_attr_temp9_alarm.dev_attr.attr,
1018 &sensor_dev_attr_temp10_alarm.dev_attr.attr,
1019 &sensor_dev_attr_fan1_max.dev_attr.attr,
1020 &sensor_dev_attr_fan2_max.dev_attr.attr,
1021 &sensor_dev_attr_fan3_max.dev_attr.attr,
1022 &sensor_dev_attr_fan4_max.dev_attr.attr,
1023 &sensor_dev_attr_fan1_min.dev_attr.attr,
1024 &sensor_dev_attr_fan2_min.dev_attr.attr,
1025 &sensor_dev_attr_fan3_min.dev_attr.attr,
1026 &sensor_dev_attr_fan4_min.dev_attr.attr,
1027 &sensor_dev_attr_fan1_input.dev_attr.attr,
1028 &sensor_dev_attr_fan2_input.dev_attr.attr,
1029 &sensor_dev_attr_fan3_input.dev_attr.attr,
1030 &sensor_dev_attr_fan4_input.dev_attr.attr,
1031 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1032 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1033 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1034 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1035 &sensor_dev_attr_force_pwm_max.dev_attr.attr,
1036 &sensor_dev_attr_pwm1.dev_attr.attr,
1037 &sensor_dev_attr_pwm2.dev_attr.attr,
1038 &sensor_dev_attr_pwm3.dev_attr.attr,
1039 &sensor_dev_attr_pwm4.dev_attr.attr,
1040 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1041 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1042 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1043 &sensor_dev_attr_pwm4_auto_point1_pwm.dev_attr.attr,
1044 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1045 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1046 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1047 &sensor_dev_attr_pwm4_auto_point2_pwm.dev_attr.attr,
1048 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
1049 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
1050 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
1051 &sensor_dev_attr_pwm4_auto_point1_temp.dev_attr.attr,
1052 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
1053 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
1054 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
1055 &sensor_dev_attr_pwm4_auto_point2_temp.dev_attr.attr,
1056 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1057 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1058 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1059 &sensor_dev_attr_pwm4_enable.dev_attr.attr,
1060 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
1061 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1062 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
1063 &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr,
1067 /* Return 0 if detection is successful, -ENODEV otherwise */
1068 static int adt7470_detect(struct i2c_client *client, int kind,
1069 struct i2c_board_info *info)
1071 struct i2c_adapter *adapter = client->adapter;
1073 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1077 int vendor, device, revision;
1079 vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR);
1080 if (vendor != ADT7470_VENDOR)
1083 device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE);
1084 if (device != ADT7470_DEVICE)
1087 revision = i2c_smbus_read_byte_data(client,
1088 ADT7470_REG_REVISION);
1089 if (revision != ADT7470_REVISION)
1092 dev_dbg(&adapter->dev, "detection forced\n");
1094 strlcpy(info->type, "adt7470", I2C_NAME_SIZE);
1099 static int adt7470_probe(struct i2c_client *client,
1100 const struct i2c_device_id *id)
1102 struct adt7470_data *data;
1105 data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL);
1111 i2c_set_clientdata(client, data);
1112 mutex_init(&data->lock);
1114 dev_info(&client->dev, "%s chip found\n", client->name);
1116 /* Initialize the ADT7470 chip */
1117 adt7470_init_client(client);
1119 /* Register sysfs hooks */
1120 data->attrs.attrs = adt7470_attr;
1121 if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs)))
1124 data->hwmon_dev = hwmon_device_register(&client->dev);
1125 if (IS_ERR(data->hwmon_dev)) {
1126 err = PTR_ERR(data->hwmon_dev);
1133 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1140 static int adt7470_remove(struct i2c_client *client)
1142 struct adt7470_data *data = i2c_get_clientdata(client);
1144 hwmon_device_unregister(data->hwmon_dev);
1145 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1150 static int __init adt7470_init(void)
1152 return i2c_add_driver(&adt7470_driver);
1155 static void __exit adt7470_exit(void)
1157 i2c_del_driver(&adt7470_driver);
1160 MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>");
1161 MODULE_DESCRIPTION("ADT7470 driver");
1162 MODULE_LICENSE("GPL");
1164 module_init(adt7470_init);
1165 module_exit(adt7470_exit);