iwmc3200wifi: Implement cfg80211 PMKSA API
[linux/fpc-iii.git] / drivers / hwmon / adt7475.c
blobb5a95193c694a44f5c142cd9e5d1fd52c10b93b6
1 /*
2 * adt7475 - Thermal sensor driver for the ADT7475 chip and derivatives
3 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc.
4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
5 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com>
7 * Derived from the lm83 driver by Jean Delvare
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/i2c.h>
18 #include <linux/hwmon.h>
19 #include <linux/hwmon-sysfs.h>
20 #include <linux/err.h>
22 /* Indexes for the sysfs hooks */
24 #define INPUT 0
25 #define MIN 1
26 #define MAX 2
27 #define CONTROL 3
28 #define OFFSET 3
29 #define AUTOMIN 4
30 #define THERM 5
31 #define HYSTERSIS 6
33 /* These are unique identifiers for the sysfs functions - unlike the
34 numbers above, these are not also indexes into an array
37 #define ALARM 9
38 #define FAULT 10
40 /* 7475 Common Registers */
42 #define REG_VOLTAGE_BASE 0x21
43 #define REG_TEMP_BASE 0x25
44 #define REG_TACH_BASE 0x28
45 #define REG_PWM_BASE 0x30
46 #define REG_PWM_MAX_BASE 0x38
48 #define REG_DEVID 0x3D
49 #define REG_VENDID 0x3E
51 #define REG_STATUS1 0x41
52 #define REG_STATUS2 0x42
54 #define REG_VOLTAGE_MIN_BASE 0x46
55 #define REG_VOLTAGE_MAX_BASE 0x47
57 #define REG_TEMP_MIN_BASE 0x4E
58 #define REG_TEMP_MAX_BASE 0x4F
60 #define REG_TACH_MIN_BASE 0x54
62 #define REG_PWM_CONFIG_BASE 0x5C
64 #define REG_TEMP_TRANGE_BASE 0x5F
66 #define REG_PWM_MIN_BASE 0x64
68 #define REG_TEMP_TMIN_BASE 0x67
69 #define REG_TEMP_THERM_BASE 0x6A
71 #define REG_REMOTE1_HYSTERSIS 0x6D
72 #define REG_REMOTE2_HYSTERSIS 0x6E
74 #define REG_TEMP_OFFSET_BASE 0x70
76 #define REG_EXTEND1 0x76
77 #define REG_EXTEND2 0x77
78 #define REG_CONFIG5 0x7C
80 #define CONFIG5_TWOSCOMP 0x01
81 #define CONFIG5_TEMPOFFSET 0x02
83 /* ADT7475 Settings */
85 #define ADT7475_VOLTAGE_COUNT 2
86 #define ADT7475_TEMP_COUNT 3
87 #define ADT7475_TACH_COUNT 4
88 #define ADT7475_PWM_COUNT 3
90 /* Macro to read the registers */
92 #define adt7475_read(reg) i2c_smbus_read_byte_data(client, (reg))
94 /* Macros to easily index the registers */
96 #define TACH_REG(idx) (REG_TACH_BASE + ((idx) * 2))
97 #define TACH_MIN_REG(idx) (REG_TACH_MIN_BASE + ((idx) * 2))
99 #define PWM_REG(idx) (REG_PWM_BASE + (idx))
100 #define PWM_MAX_REG(idx) (REG_PWM_MAX_BASE + (idx))
101 #define PWM_MIN_REG(idx) (REG_PWM_MIN_BASE + (idx))
102 #define PWM_CONFIG_REG(idx) (REG_PWM_CONFIG_BASE + (idx))
104 #define VOLTAGE_REG(idx) (REG_VOLTAGE_BASE + (idx))
105 #define VOLTAGE_MIN_REG(idx) (REG_VOLTAGE_MIN_BASE + ((idx) * 2))
106 #define VOLTAGE_MAX_REG(idx) (REG_VOLTAGE_MAX_BASE + ((idx) * 2))
108 #define TEMP_REG(idx) (REG_TEMP_BASE + (idx))
109 #define TEMP_MIN_REG(idx) (REG_TEMP_MIN_BASE + ((idx) * 2))
110 #define TEMP_MAX_REG(idx) (REG_TEMP_MAX_BASE + ((idx) * 2))
111 #define TEMP_TMIN_REG(idx) (REG_TEMP_TMIN_BASE + (idx))
112 #define TEMP_THERM_REG(idx) (REG_TEMP_THERM_BASE + (idx))
113 #define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx))
114 #define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx))
116 static unsigned short normal_i2c[] = { 0x2e, I2C_CLIENT_END };
118 I2C_CLIENT_INSMOD_1(adt7475);
120 static const struct i2c_device_id adt7475_id[] = {
121 { "adt7475", adt7475 },
124 MODULE_DEVICE_TABLE(i2c, adt7475_id);
126 struct adt7475_data {
127 struct device *hwmon_dev;
128 struct mutex lock;
130 unsigned long measure_updated;
131 unsigned long limits_updated;
132 char valid;
134 u8 config5;
135 u16 alarms;
136 u16 voltage[3][3];
137 u16 temp[7][3];
138 u16 tach[2][4];
139 u8 pwm[4][3];
140 u8 range[3];
141 u8 pwmctl[3];
142 u8 pwmchan[3];
145 static struct i2c_driver adt7475_driver;
146 static struct adt7475_data *adt7475_update_device(struct device *dev);
147 static void adt7475_read_hystersis(struct i2c_client *client);
148 static void adt7475_read_pwm(struct i2c_client *client, int index);
150 /* Given a temp value, convert it to register value */
152 static inline u16 temp2reg(struct adt7475_data *data, long val)
154 u16 ret;
156 if (!(data->config5 & CONFIG5_TWOSCOMP)) {
157 val = SENSORS_LIMIT(val, -64000, 191000);
158 ret = (val + 64500) / 1000;
159 } else {
160 val = SENSORS_LIMIT(val, -128000, 127000);
161 if (val < -500)
162 ret = (256500 + val) / 1000;
163 else
164 ret = (val + 500) / 1000;
167 return ret << 2;
170 /* Given a register value, convert it to a real temp value */
172 static inline int reg2temp(struct adt7475_data *data, u16 reg)
174 if (data->config5 & CONFIG5_TWOSCOMP) {
175 if (reg >= 512)
176 return (reg - 1024) * 250;
177 else
178 return reg * 250;
179 } else
180 return (reg - 256) * 250;
183 static inline int tach2rpm(u16 tach)
185 if (tach == 0 || tach == 0xFFFF)
186 return 0;
188 return (90000 * 60) / tach;
191 static inline u16 rpm2tach(unsigned long rpm)
193 if (rpm == 0)
194 return 0;
196 return SENSORS_LIMIT((90000 * 60) / rpm, 1, 0xFFFF);
199 static inline int reg2vcc(u16 reg)
201 return (4296 * reg) / 1000;
204 static inline int reg2vccp(u16 reg)
206 return (2929 * reg) / 1000;
209 static inline u16 vcc2reg(long vcc)
211 vcc = SENSORS_LIMIT(vcc, 0, 4396);
212 return (vcc * 1000) / 4296;
215 static inline u16 vccp2reg(long vcc)
217 vcc = SENSORS_LIMIT(vcc, 0, 2998);
218 return (vcc * 1000) / 2929;
221 static u16 adt7475_read_word(struct i2c_client *client, int reg)
223 u16 val;
225 val = i2c_smbus_read_byte_data(client, reg);
226 val |= (i2c_smbus_read_byte_data(client, reg + 1) << 8);
228 return val;
231 static void adt7475_write_word(struct i2c_client *client, int reg, u16 val)
233 i2c_smbus_write_byte_data(client, reg + 1, val >> 8);
234 i2c_smbus_write_byte_data(client, reg, val & 0xFF);
237 /* Find the nearest value in a table - used for pwm frequency and
238 auto temp range */
239 static int find_nearest(long val, const int *array, int size)
241 int i;
243 if (val < array[0])
244 return 0;
246 if (val > array[size - 1])
247 return size - 1;
249 for (i = 0; i < size - 1; i++) {
250 int a, b;
252 if (val > array[i + 1])
253 continue;
255 a = val - array[i];
256 b = array[i + 1] - val;
258 return (a <= b) ? i : i + 1;
261 return 0;
264 static ssize_t show_voltage(struct device *dev, struct device_attribute *attr,
265 char *buf)
267 struct adt7475_data *data = adt7475_update_device(dev);
268 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
269 unsigned short val;
271 switch (sattr->nr) {
272 case ALARM:
273 return sprintf(buf, "%d\n",
274 (data->alarms >> (sattr->index + 1)) & 1);
275 default:
276 val = data->voltage[sattr->nr][sattr->index];
277 return sprintf(buf, "%d\n",
278 sattr->index ==
279 0 ? reg2vccp(val) : reg2vcc(val));
283 static ssize_t set_voltage(struct device *dev, struct device_attribute *attr,
284 const char *buf, size_t count)
287 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
288 struct i2c_client *client = to_i2c_client(dev);
289 struct adt7475_data *data = i2c_get_clientdata(client);
290 unsigned char reg;
291 long val;
293 if (strict_strtol(buf, 10, &val))
294 return -EINVAL;
296 mutex_lock(&data->lock);
298 data->voltage[sattr->nr][sattr->index] =
299 sattr->index ? vcc2reg(val) : vccp2reg(val);
301 if (sattr->nr == MIN)
302 reg = VOLTAGE_MIN_REG(sattr->index);
303 else
304 reg = VOLTAGE_MAX_REG(sattr->index);
306 i2c_smbus_write_byte_data(client, reg,
307 data->voltage[sattr->nr][sattr->index] >> 2);
308 mutex_unlock(&data->lock);
310 return count;
313 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
314 char *buf)
316 struct adt7475_data *data = adt7475_update_device(dev);
317 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
318 int out;
320 switch (sattr->nr) {
321 case HYSTERSIS:
322 mutex_lock(&data->lock);
323 out = data->temp[sattr->nr][sattr->index];
324 if (sattr->index != 1)
325 out = (out >> 4) & 0xF;
326 else
327 out = (out & 0xF);
328 /* Show the value as an absolute number tied to
329 * THERM */
330 out = reg2temp(data, data->temp[THERM][sattr->index]) -
331 out * 1000;
332 mutex_unlock(&data->lock);
333 break;
335 case OFFSET:
336 /* Offset is always 2's complement, regardless of the
337 * setting in CONFIG5 */
338 mutex_lock(&data->lock);
339 out = (s8)data->temp[sattr->nr][sattr->index];
340 if (data->config5 & CONFIG5_TEMPOFFSET)
341 out *= 1000;
342 else
343 out *= 500;
344 mutex_unlock(&data->lock);
345 break;
347 case ALARM:
348 out = (data->alarms >> (sattr->index + 4)) & 1;
349 break;
351 case FAULT:
352 /* Note - only for remote1 and remote2 */
353 out = !!(data->alarms & (sattr->index ? 0x8000 : 0x4000));
354 break;
356 default:
357 /* All other temp values are in the configured format */
358 out = reg2temp(data, data->temp[sattr->nr][sattr->index]);
361 return sprintf(buf, "%d\n", out);
364 static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
365 const char *buf, size_t count)
367 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
368 struct i2c_client *client = to_i2c_client(dev);
369 struct adt7475_data *data = i2c_get_clientdata(client);
370 unsigned char reg = 0;
371 u8 out;
372 int temp;
373 long val;
375 if (strict_strtol(buf, 10, &val))
376 return -EINVAL;
378 mutex_lock(&data->lock);
380 /* We need the config register in all cases for temp <-> reg conv. */
381 data->config5 = adt7475_read(REG_CONFIG5);
383 switch (sattr->nr) {
384 case OFFSET:
385 if (data->config5 & CONFIG5_TEMPOFFSET) {
386 val = SENSORS_LIMIT(val, -63000, 127000);
387 out = data->temp[OFFSET][sattr->index] = val / 1000;
388 } else {
389 val = SENSORS_LIMIT(val, -63000, 64000);
390 out = data->temp[OFFSET][sattr->index] = val / 500;
392 break;
394 case HYSTERSIS:
395 /* The value will be given as an absolute value, turn it
396 into an offset based on THERM */
398 /* Read fresh THERM and HYSTERSIS values from the chip */
399 data->temp[THERM][sattr->index] =
400 adt7475_read(TEMP_THERM_REG(sattr->index)) << 2;
401 adt7475_read_hystersis(client);
403 temp = reg2temp(data, data->temp[THERM][sattr->index]);
404 val = SENSORS_LIMIT(val, temp - 15000, temp);
405 val = (temp - val) / 1000;
407 if (sattr->index != 1) {
408 data->temp[HYSTERSIS][sattr->index] &= 0xF0;
409 data->temp[HYSTERSIS][sattr->index] |= (val & 0xF) << 4;
410 } else {
411 data->temp[HYSTERSIS][sattr->index] &= 0x0F;
412 data->temp[HYSTERSIS][sattr->index] |= (val & 0xF);
415 out = data->temp[HYSTERSIS][sattr->index];
416 break;
418 default:
419 data->temp[sattr->nr][sattr->index] = temp2reg(data, val);
421 /* We maintain an extra 2 digits of precision for simplicity
422 * - shift those back off before writing the value */
423 out = (u8) (data->temp[sattr->nr][sattr->index] >> 2);
426 switch (sattr->nr) {
427 case MIN:
428 reg = TEMP_MIN_REG(sattr->index);
429 break;
430 case MAX:
431 reg = TEMP_MAX_REG(sattr->index);
432 break;
433 case OFFSET:
434 reg = TEMP_OFFSET_REG(sattr->index);
435 break;
436 case AUTOMIN:
437 reg = TEMP_TMIN_REG(sattr->index);
438 break;
439 case THERM:
440 reg = TEMP_THERM_REG(sattr->index);
441 break;
442 case HYSTERSIS:
443 if (sattr->index != 2)
444 reg = REG_REMOTE1_HYSTERSIS;
445 else
446 reg = REG_REMOTE2_HYSTERSIS;
448 break;
451 i2c_smbus_write_byte_data(client, reg, out);
453 mutex_unlock(&data->lock);
454 return count;
457 /* Table of autorange values - the user will write the value in millidegrees,
458 and we'll convert it */
459 static const int autorange_table[] = {
460 2000, 2500, 3330, 4000, 5000, 6670, 8000,
461 10000, 13330, 16000, 20000, 26670, 32000, 40000,
462 53330, 80000
465 static ssize_t show_point2(struct device *dev, struct device_attribute *attr,
466 char *buf)
468 struct adt7475_data *data = adt7475_update_device(dev);
469 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
470 int out, val;
472 mutex_lock(&data->lock);
473 out = (data->range[sattr->index] >> 4) & 0x0F;
474 val = reg2temp(data, data->temp[AUTOMIN][sattr->index]);
475 mutex_unlock(&data->lock);
477 return sprintf(buf, "%d\n", val + autorange_table[out]);
480 static ssize_t set_point2(struct device *dev, struct device_attribute *attr,
481 const char *buf, size_t count)
483 struct i2c_client *client = to_i2c_client(dev);
484 struct adt7475_data *data = i2c_get_clientdata(client);
485 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
486 int temp;
487 long val;
489 if (strict_strtol(buf, 10, &val))
490 return -EINVAL;
492 mutex_lock(&data->lock);
494 /* Get a fresh copy of the needed registers */
495 data->config5 = adt7475_read(REG_CONFIG5);
496 data->temp[AUTOMIN][sattr->index] =
497 adt7475_read(TEMP_TMIN_REG(sattr->index)) << 2;
498 data->range[sattr->index] =
499 adt7475_read(TEMP_TRANGE_REG(sattr->index));
501 /* The user will write an absolute value, so subtract the start point
502 to figure the range */
503 temp = reg2temp(data, data->temp[AUTOMIN][sattr->index]);
504 val = SENSORS_LIMIT(val, temp + autorange_table[0],
505 temp + autorange_table[ARRAY_SIZE(autorange_table) - 1]);
506 val -= temp;
508 /* Find the nearest table entry to what the user wrote */
509 val = find_nearest(val, autorange_table, ARRAY_SIZE(autorange_table));
511 data->range[sattr->index] &= ~0xF0;
512 data->range[sattr->index] |= val << 4;
514 i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index),
515 data->range[sattr->index]);
517 mutex_unlock(&data->lock);
518 return count;
521 static ssize_t show_tach(struct device *dev, struct device_attribute *attr,
522 char *buf)
524 struct adt7475_data *data = adt7475_update_device(dev);
525 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
526 int out;
528 if (sattr->nr == ALARM)
529 out = (data->alarms >> (sattr->index + 10)) & 1;
530 else
531 out = tach2rpm(data->tach[sattr->nr][sattr->index]);
533 return sprintf(buf, "%d\n", out);
536 static ssize_t set_tach(struct device *dev, struct device_attribute *attr,
537 const char *buf, size_t count)
540 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
541 struct i2c_client *client = to_i2c_client(dev);
542 struct adt7475_data *data = i2c_get_clientdata(client);
543 unsigned long val;
545 if (strict_strtoul(buf, 10, &val))
546 return -EINVAL;
548 mutex_lock(&data->lock);
550 data->tach[MIN][sattr->index] = rpm2tach(val);
552 adt7475_write_word(client, TACH_MIN_REG(sattr->index),
553 data->tach[MIN][sattr->index]);
555 mutex_unlock(&data->lock);
556 return count;
559 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
560 char *buf)
562 struct adt7475_data *data = adt7475_update_device(dev);
563 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
565 return sprintf(buf, "%d\n", data->pwm[sattr->nr][sattr->index]);
568 static ssize_t show_pwmchan(struct device *dev, struct device_attribute *attr,
569 char *buf)
571 struct adt7475_data *data = adt7475_update_device(dev);
572 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
574 return sprintf(buf, "%d\n", data->pwmchan[sattr->index]);
577 static ssize_t show_pwmctrl(struct device *dev, struct device_attribute *attr,
578 char *buf)
580 struct adt7475_data *data = adt7475_update_device(dev);
581 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
583 return sprintf(buf, "%d\n", data->pwmctl[sattr->index]);
586 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
587 const char *buf, size_t count)
590 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
591 struct i2c_client *client = to_i2c_client(dev);
592 struct adt7475_data *data = i2c_get_clientdata(client);
593 unsigned char reg = 0;
594 long val;
596 if (strict_strtol(buf, 10, &val))
597 return -EINVAL;
599 mutex_lock(&data->lock);
601 switch (sattr->nr) {
602 case INPUT:
603 /* Get a fresh value for CONTROL */
604 data->pwm[CONTROL][sattr->index] =
605 adt7475_read(PWM_CONFIG_REG(sattr->index));
607 /* If we are not in manual mode, then we shouldn't allow
608 * the user to set the pwm speed */
609 if (((data->pwm[CONTROL][sattr->index] >> 5) & 7) != 7) {
610 mutex_unlock(&data->lock);
611 return count;
614 reg = PWM_REG(sattr->index);
615 break;
617 case MIN:
618 reg = PWM_MIN_REG(sattr->index);
619 break;
621 case MAX:
622 reg = PWM_MAX_REG(sattr->index);
623 break;
626 data->pwm[sattr->nr][sattr->index] = SENSORS_LIMIT(val, 0, 0xFF);
627 i2c_smbus_write_byte_data(client, reg,
628 data->pwm[sattr->nr][sattr->index]);
630 mutex_unlock(&data->lock);
632 return count;
635 /* Called by set_pwmctrl and set_pwmchan */
637 static int hw_set_pwm(struct i2c_client *client, int index,
638 unsigned int pwmctl, unsigned int pwmchan)
640 struct adt7475_data *data = i2c_get_clientdata(client);
641 long val = 0;
643 switch (pwmctl) {
644 case 0:
645 val = 0x03; /* Run at full speed */
646 break;
647 case 1:
648 val = 0x07; /* Manual mode */
649 break;
650 case 2:
651 switch (pwmchan) {
652 case 1:
653 /* Remote1 controls PWM */
654 val = 0x00;
655 break;
656 case 2:
657 /* local controls PWM */
658 val = 0x01;
659 break;
660 case 4:
661 /* remote2 controls PWM */
662 val = 0x02;
663 break;
664 case 6:
665 /* local/remote2 control PWM */
666 val = 0x05;
667 break;
668 case 7:
669 /* All three control PWM */
670 val = 0x06;
671 break;
672 default:
673 return -EINVAL;
675 break;
676 default:
677 return -EINVAL;
680 data->pwmctl[index] = pwmctl;
681 data->pwmchan[index] = pwmchan;
683 data->pwm[CONTROL][index] &= ~0xE0;
684 data->pwm[CONTROL][index] |= (val & 7) << 5;
686 i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index),
687 data->pwm[CONTROL][index]);
689 return 0;
692 static ssize_t set_pwmchan(struct device *dev, struct device_attribute *attr,
693 const char *buf, size_t count)
695 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
696 struct i2c_client *client = to_i2c_client(dev);
697 struct adt7475_data *data = i2c_get_clientdata(client);
698 int r;
699 long val;
701 if (strict_strtol(buf, 10, &val))
702 return -EINVAL;
704 mutex_lock(&data->lock);
705 /* Read Modify Write PWM values */
706 adt7475_read_pwm(client, sattr->index);
707 r = hw_set_pwm(client, sattr->index, data->pwmctl[sattr->index], val);
708 if (r)
709 count = r;
710 mutex_unlock(&data->lock);
712 return count;
715 static ssize_t set_pwmctrl(struct device *dev, struct device_attribute *attr,
716 const char *buf, size_t count)
718 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
719 struct i2c_client *client = to_i2c_client(dev);
720 struct adt7475_data *data = i2c_get_clientdata(client);
721 int r;
722 long val;
724 if (strict_strtol(buf, 10, &val))
725 return -EINVAL;
727 mutex_lock(&data->lock);
728 /* Read Modify Write PWM values */
729 adt7475_read_pwm(client, sattr->index);
730 r = hw_set_pwm(client, sattr->index, val, data->pwmchan[sattr->index]);
731 if (r)
732 count = r;
733 mutex_unlock(&data->lock);
735 return count;
738 /* List of frequencies for the PWM */
739 static const int pwmfreq_table[] = {
740 11, 14, 22, 29, 35, 44, 58, 88
743 static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
744 char *buf)
746 struct adt7475_data *data = adt7475_update_device(dev);
747 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
749 return sprintf(buf, "%d\n",
750 pwmfreq_table[data->range[sattr->index] & 7]);
753 static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
754 const char *buf, size_t count)
756 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
757 struct i2c_client *client = to_i2c_client(dev);
758 struct adt7475_data *data = i2c_get_clientdata(client);
759 int out;
760 long val;
762 if (strict_strtol(buf, 10, &val))
763 return -EINVAL;
765 out = find_nearest(val, pwmfreq_table, ARRAY_SIZE(pwmfreq_table));
767 mutex_lock(&data->lock);
769 data->range[sattr->index] =
770 adt7475_read(TEMP_TRANGE_REG(sattr->index));
771 data->range[sattr->index] &= ~7;
772 data->range[sattr->index] |= out;
774 i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index),
775 data->range[sattr->index]);
777 mutex_unlock(&data->lock);
778 return count;
781 static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_voltage, NULL, INPUT, 0);
782 static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_voltage,
783 set_voltage, MAX, 0);
784 static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_voltage,
785 set_voltage, MIN, 0);
786 static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, show_voltage, NULL, ALARM, 0);
787 static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_voltage, NULL, INPUT, 1);
788 static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_voltage,
789 set_voltage, MAX, 1);
790 static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_voltage,
791 set_voltage, MIN, 1);
792 static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_voltage, NULL, ALARM, 1);
793 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, INPUT, 0);
794 static SENSOR_DEVICE_ATTR_2(temp1_alarm, S_IRUGO, show_temp, NULL, ALARM, 0);
795 static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_temp, NULL, FAULT, 0);
796 static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
797 MAX, 0);
798 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
799 MIN, 0);
800 static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
801 set_temp, OFFSET, 0);
802 static SENSOR_DEVICE_ATTR_2(temp1_auto_point1_temp, S_IRUGO | S_IWUSR,
803 show_temp, set_temp, AUTOMIN, 0);
804 static SENSOR_DEVICE_ATTR_2(temp1_auto_point2_temp, S_IRUGO | S_IWUSR,
805 show_point2, set_point2, 0, 0);
806 static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
807 THERM, 0);
808 static SENSOR_DEVICE_ATTR_2(temp1_crit_hyst, S_IRUGO | S_IWUSR, show_temp,
809 set_temp, HYSTERSIS, 0);
810 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, INPUT, 1);
811 static SENSOR_DEVICE_ATTR_2(temp2_alarm, S_IRUGO, show_temp, NULL, ALARM, 1);
812 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
813 MAX, 1);
814 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
815 MIN, 1);
816 static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
817 set_temp, OFFSET, 1);
818 static SENSOR_DEVICE_ATTR_2(temp2_auto_point1_temp, S_IRUGO | S_IWUSR,
819 show_temp, set_temp, AUTOMIN, 1);
820 static SENSOR_DEVICE_ATTR_2(temp2_auto_point2_temp, S_IRUGO | S_IWUSR,
821 show_point2, set_point2, 0, 1);
822 static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
823 THERM, 1);
824 static SENSOR_DEVICE_ATTR_2(temp2_crit_hyst, S_IRUGO | S_IWUSR, show_temp,
825 set_temp, HYSTERSIS, 1);
826 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, INPUT, 2);
827 static SENSOR_DEVICE_ATTR_2(temp3_alarm, S_IRUGO, show_temp, NULL, ALARM, 2);
828 static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_temp, NULL, FAULT, 2);
829 static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
830 MAX, 2);
831 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
832 MIN, 2);
833 static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
834 set_temp, OFFSET, 2);
835 static SENSOR_DEVICE_ATTR_2(temp3_auto_point1_temp, S_IRUGO | S_IWUSR,
836 show_temp, set_temp, AUTOMIN, 2);
837 static SENSOR_DEVICE_ATTR_2(temp3_auto_point2_temp, S_IRUGO | S_IWUSR,
838 show_point2, set_point2, 0, 2);
839 static SENSOR_DEVICE_ATTR_2(temp3_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
840 THERM, 2);
841 static SENSOR_DEVICE_ATTR_2(temp3_crit_hyst, S_IRUGO | S_IWUSR, show_temp,
842 set_temp, HYSTERSIS, 2);
843 static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_tach, NULL, INPUT, 0);
844 static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
845 MIN, 0);
846 static SENSOR_DEVICE_ATTR_2(fan1_alarm, S_IRUGO, show_tach, NULL, ALARM, 0);
847 static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_tach, NULL, INPUT, 1);
848 static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
849 MIN, 1);
850 static SENSOR_DEVICE_ATTR_2(fan2_alarm, S_IRUGO, show_tach, NULL, ALARM, 1);
851 static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_tach, NULL, INPUT, 2);
852 static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
853 MIN, 2);
854 static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_tach, NULL, ALARM, 2);
855 static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_tach, NULL, INPUT, 3);
856 static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_tach, set_tach,
857 MIN, 3);
858 static SENSOR_DEVICE_ATTR_2(fan4_alarm, S_IRUGO, show_tach, NULL, ALARM, 3);
859 static SENSOR_DEVICE_ATTR_2(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT,
861 static SENSOR_DEVICE_ATTR_2(pwm1_freq, S_IRUGO | S_IWUSR, show_pwmfreq,
862 set_pwmfreq, INPUT, 0);
863 static SENSOR_DEVICE_ATTR_2(pwm1_enable, S_IRUGO | S_IWUSR, show_pwmctrl,
864 set_pwmctrl, INPUT, 0);
865 static SENSOR_DEVICE_ATTR_2(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR,
866 show_pwmchan, set_pwmchan, INPUT, 0);
867 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
868 set_pwm, MIN, 0);
869 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
870 set_pwm, MAX, 0);
871 static SENSOR_DEVICE_ATTR_2(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT,
873 static SENSOR_DEVICE_ATTR_2(pwm2_freq, S_IRUGO | S_IWUSR, show_pwmfreq,
874 set_pwmfreq, INPUT, 1);
875 static SENSOR_DEVICE_ATTR_2(pwm2_enable, S_IRUGO | S_IWUSR, show_pwmctrl,
876 set_pwmctrl, INPUT, 1);
877 static SENSOR_DEVICE_ATTR_2(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR,
878 show_pwmchan, set_pwmchan, INPUT, 1);
879 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
880 set_pwm, MIN, 1);
881 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
882 set_pwm, MAX, 1);
883 static SENSOR_DEVICE_ATTR_2(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, INPUT,
885 static SENSOR_DEVICE_ATTR_2(pwm3_freq, S_IRUGO | S_IWUSR, show_pwmfreq,
886 set_pwmfreq, INPUT, 2);
887 static SENSOR_DEVICE_ATTR_2(pwm3_enable, S_IRUGO | S_IWUSR, show_pwmctrl,
888 set_pwmctrl, INPUT, 2);
889 static SENSOR_DEVICE_ATTR_2(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR,
890 show_pwmchan, set_pwmchan, INPUT, 2);
891 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
892 set_pwm, MIN, 2);
893 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
894 set_pwm, MAX, 2);
896 static struct attribute *adt7475_attrs[] = {
897 &sensor_dev_attr_in1_input.dev_attr.attr,
898 &sensor_dev_attr_in1_max.dev_attr.attr,
899 &sensor_dev_attr_in1_min.dev_attr.attr,
900 &sensor_dev_attr_in1_alarm.dev_attr.attr,
901 &sensor_dev_attr_in2_input.dev_attr.attr,
902 &sensor_dev_attr_in2_max.dev_attr.attr,
903 &sensor_dev_attr_in2_min.dev_attr.attr,
904 &sensor_dev_attr_in2_alarm.dev_attr.attr,
905 &sensor_dev_attr_temp1_input.dev_attr.attr,
906 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
907 &sensor_dev_attr_temp1_fault.dev_attr.attr,
908 &sensor_dev_attr_temp1_max.dev_attr.attr,
909 &sensor_dev_attr_temp1_min.dev_attr.attr,
910 &sensor_dev_attr_temp1_offset.dev_attr.attr,
911 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
912 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
913 &sensor_dev_attr_temp1_crit.dev_attr.attr,
914 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
915 &sensor_dev_attr_temp2_input.dev_attr.attr,
916 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
917 &sensor_dev_attr_temp2_max.dev_attr.attr,
918 &sensor_dev_attr_temp2_min.dev_attr.attr,
919 &sensor_dev_attr_temp2_offset.dev_attr.attr,
920 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
921 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
922 &sensor_dev_attr_temp2_crit.dev_attr.attr,
923 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
924 &sensor_dev_attr_temp3_input.dev_attr.attr,
925 &sensor_dev_attr_temp3_fault.dev_attr.attr,
926 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
927 &sensor_dev_attr_temp3_max.dev_attr.attr,
928 &sensor_dev_attr_temp3_min.dev_attr.attr,
929 &sensor_dev_attr_temp3_offset.dev_attr.attr,
930 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
931 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
932 &sensor_dev_attr_temp3_crit.dev_attr.attr,
933 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
934 &sensor_dev_attr_fan1_input.dev_attr.attr,
935 &sensor_dev_attr_fan1_min.dev_attr.attr,
936 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
937 &sensor_dev_attr_fan2_input.dev_attr.attr,
938 &sensor_dev_attr_fan2_min.dev_attr.attr,
939 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
940 &sensor_dev_attr_fan3_input.dev_attr.attr,
941 &sensor_dev_attr_fan3_min.dev_attr.attr,
942 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
943 &sensor_dev_attr_fan4_input.dev_attr.attr,
944 &sensor_dev_attr_fan4_min.dev_attr.attr,
945 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
946 &sensor_dev_attr_pwm1.dev_attr.attr,
947 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
948 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
949 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
950 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
951 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
952 &sensor_dev_attr_pwm2.dev_attr.attr,
953 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
954 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
955 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
956 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
957 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
958 &sensor_dev_attr_pwm3.dev_attr.attr,
959 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
960 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
961 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
962 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
963 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
964 NULL,
967 struct attribute_group adt7475_attr_group = { .attrs = adt7475_attrs };
969 static int adt7475_detect(struct i2c_client *client, int kind,
970 struct i2c_board_info *info)
972 struct i2c_adapter *adapter = client->adapter;
974 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
975 return -ENODEV;
977 if (kind <= 0) {
978 if (adt7475_read(REG_VENDID) != 0x41 ||
979 adt7475_read(REG_DEVID) != 0x75) {
980 dev_err(&adapter->dev,
981 "Couldn't detect a adt7475 part at 0x%02x\n",
982 (unsigned int)client->addr);
983 return -ENODEV;
987 strlcpy(info->type, adt7475_id[0].name, I2C_NAME_SIZE);
989 return 0;
992 static int adt7475_probe(struct i2c_client *client,
993 const struct i2c_device_id *id)
995 struct adt7475_data *data;
996 int i, ret = 0;
998 data = kzalloc(sizeof(*data), GFP_KERNEL);
999 if (data == NULL)
1000 return -ENOMEM;
1002 mutex_init(&data->lock);
1003 i2c_set_clientdata(client, data);
1005 /* Call adt7475_read_pwm for all pwm's as this will reprogram any
1006 pwm's which are disabled to manual mode with 0% duty cycle */
1007 for (i = 0; i < ADT7475_PWM_COUNT; i++)
1008 adt7475_read_pwm(client, i);
1010 ret = sysfs_create_group(&client->dev.kobj, &adt7475_attr_group);
1011 if (ret)
1012 goto efree;
1014 data->hwmon_dev = hwmon_device_register(&client->dev);
1015 if (IS_ERR(data->hwmon_dev)) {
1016 ret = PTR_ERR(data->hwmon_dev);
1017 goto eremove;
1020 return 0;
1022 eremove:
1023 sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group);
1024 efree:
1025 kfree(data);
1026 return ret;
1029 static int adt7475_remove(struct i2c_client *client)
1031 struct adt7475_data *data = i2c_get_clientdata(client);
1033 hwmon_device_unregister(data->hwmon_dev);
1034 sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group);
1035 kfree(data);
1037 return 0;
1040 static struct i2c_driver adt7475_driver = {
1041 .class = I2C_CLASS_HWMON,
1042 .driver = {
1043 .name = "adt7475",
1045 .probe = adt7475_probe,
1046 .remove = adt7475_remove,
1047 .id_table = adt7475_id,
1048 .detect = adt7475_detect,
1049 .address_data = &addr_data,
1052 static void adt7475_read_hystersis(struct i2c_client *client)
1054 struct adt7475_data *data = i2c_get_clientdata(client);
1056 data->temp[HYSTERSIS][0] = (u16) adt7475_read(REG_REMOTE1_HYSTERSIS);
1057 data->temp[HYSTERSIS][1] = data->temp[HYSTERSIS][0];
1058 data->temp[HYSTERSIS][2] = (u16) adt7475_read(REG_REMOTE2_HYSTERSIS);
1061 static void adt7475_read_pwm(struct i2c_client *client, int index)
1063 struct adt7475_data *data = i2c_get_clientdata(client);
1064 unsigned int v;
1066 data->pwm[CONTROL][index] = adt7475_read(PWM_CONFIG_REG(index));
1068 /* Figure out the internal value for pwmctrl and pwmchan
1069 based on the current settings */
1070 v = (data->pwm[CONTROL][index] >> 5) & 7;
1072 if (v == 3)
1073 data->pwmctl[index] = 0;
1074 else if (v == 7)
1075 data->pwmctl[index] = 1;
1076 else if (v == 4) {
1077 /* The fan is disabled - we don't want to
1078 support that, so change to manual mode and
1079 set the duty cycle to 0 instead
1081 data->pwm[INPUT][index] = 0;
1082 data->pwm[CONTROL][index] &= ~0xE0;
1083 data->pwm[CONTROL][index] |= (7 << 5);
1085 i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index),
1086 data->pwm[INPUT][index]);
1088 i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index),
1089 data->pwm[CONTROL][index]);
1091 data->pwmctl[index] = 1;
1092 } else {
1093 data->pwmctl[index] = 2;
1095 switch (v) {
1096 case 0:
1097 data->pwmchan[index] = 1;
1098 break;
1099 case 1:
1100 data->pwmchan[index] = 2;
1101 break;
1102 case 2:
1103 data->pwmchan[index] = 4;
1104 break;
1105 case 5:
1106 data->pwmchan[index] = 6;
1107 break;
1108 case 6:
1109 data->pwmchan[index] = 7;
1110 break;
1115 static struct adt7475_data *adt7475_update_device(struct device *dev)
1117 struct i2c_client *client = to_i2c_client(dev);
1118 struct adt7475_data *data = i2c_get_clientdata(client);
1119 u8 ext;
1120 int i;
1122 mutex_lock(&data->lock);
1124 /* Measurement values update every 2 seconds */
1125 if (time_after(jiffies, data->measure_updated + HZ * 2) ||
1126 !data->valid) {
1127 data->alarms = adt7475_read(REG_STATUS2) << 8;
1128 data->alarms |= adt7475_read(REG_STATUS1);
1130 ext = adt7475_read(REG_EXTEND1);
1131 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++)
1132 data->voltage[INPUT][i] =
1133 (adt7475_read(VOLTAGE_REG(i)) << 2) |
1134 ((ext >> ((i + 1) * 2)) & 3);
1136 ext = adt7475_read(REG_EXTEND2);
1137 for (i = 0; i < ADT7475_TEMP_COUNT; i++)
1138 data->temp[INPUT][i] =
1139 (adt7475_read(TEMP_REG(i)) << 2) |
1140 ((ext >> ((i + 1) * 2)) & 3);
1142 for (i = 0; i < ADT7475_TACH_COUNT; i++)
1143 data->tach[INPUT][i] =
1144 adt7475_read_word(client, TACH_REG(i));
1146 /* Updated by hw when in auto mode */
1147 for (i = 0; i < ADT7475_PWM_COUNT; i++)
1148 data->pwm[INPUT][i] = adt7475_read(PWM_REG(i));
1150 data->measure_updated = jiffies;
1153 /* Limits and settings, should never change update every 60 seconds */
1154 if (time_after(jiffies, data->limits_updated + HZ * 60) ||
1155 !data->valid) {
1156 data->config5 = adt7475_read(REG_CONFIG5);
1158 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) {
1159 /* Adjust values so they match the input precision */
1160 data->voltage[MIN][i] =
1161 adt7475_read(VOLTAGE_MIN_REG(i)) << 2;
1162 data->voltage[MAX][i] =
1163 adt7475_read(VOLTAGE_MAX_REG(i)) << 2;
1166 for (i = 0; i < ADT7475_TEMP_COUNT; i++) {
1167 /* Adjust values so they match the input precision */
1168 data->temp[MIN][i] =
1169 adt7475_read(TEMP_MIN_REG(i)) << 2;
1170 data->temp[MAX][i] =
1171 adt7475_read(TEMP_MAX_REG(i)) << 2;
1172 data->temp[AUTOMIN][i] =
1173 adt7475_read(TEMP_TMIN_REG(i)) << 2;
1174 data->temp[THERM][i] =
1175 adt7475_read(TEMP_THERM_REG(i)) << 2;
1176 data->temp[OFFSET][i] =
1177 adt7475_read(TEMP_OFFSET_REG(i));
1179 adt7475_read_hystersis(client);
1181 for (i = 0; i < ADT7475_TACH_COUNT; i++)
1182 data->tach[MIN][i] =
1183 adt7475_read_word(client, TACH_MIN_REG(i));
1185 for (i = 0; i < ADT7475_PWM_COUNT; i++) {
1186 data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i));
1187 data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i));
1188 /* Set the channel and control information */
1189 adt7475_read_pwm(client, i);
1192 data->range[0] = adt7475_read(TEMP_TRANGE_REG(0));
1193 data->range[1] = adt7475_read(TEMP_TRANGE_REG(1));
1194 data->range[2] = adt7475_read(TEMP_TRANGE_REG(2));
1196 data->limits_updated = jiffies;
1197 data->valid = 1;
1200 mutex_unlock(&data->lock);
1202 return data;
1205 static int __init sensors_adt7475_init(void)
1207 return i2c_add_driver(&adt7475_driver);
1210 static void __exit sensors_adt7475_exit(void)
1212 i2c_del_driver(&adt7475_driver);
1215 MODULE_AUTHOR("Advanced Micro Devices, Inc");
1216 MODULE_DESCRIPTION("adt7475 driver");
1217 MODULE_LICENSE("GPL");
1219 module_init(sensors_adt7475_init);
1220 module_exit(sensors_adt7475_exit);