1 // SPDX-License-Identifier: GPL-2.0-only
3 * adt7475 - Thermal sensor driver for the ADT7475 chip and derivatives
4 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc.
5 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
6 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com>
7 * Copyright (C) 2009 Jean Delvare <jdelvare@suse.de>
9 * Derived from the lm83 driver by Jean Delvare
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
15 #include <linux/i2c.h>
16 #include <linux/hwmon.h>
17 #include <linux/hwmon-sysfs.h>
18 #include <linux/hwmon-vid.h>
19 #include <linux/err.h>
20 #include <linux/jiffies.h>
22 #include <linux/util_macros.h>
24 #include <dt-bindings/pwm/pwm.h>
26 /* Indexes for the sysfs hooks */
37 * These are unique identifiers for the sysfs functions - unlike the
38 * numbers above, these are not also indexes into an array
45 /* 7475 Common Registers */
47 #define REG_DEVREV2 0x12 /* ADT7490 only */
48 #define REG_IMON 0x1D /* ADT7490 only */
50 #define REG_VTT 0x1E /* ADT7490 only */
51 #define REG_EXTEND3 0x1F /* ADT7490 only */
53 #define REG_VOLTAGE_BASE 0x20
54 #define REG_TEMP_BASE 0x25
55 #define REG_TACH_BASE 0x28
56 #define REG_PWM_BASE 0x30
57 #define REG_PWM_MAX_BASE 0x38
59 #define REG_DEVID 0x3D
60 #define REG_VENDID 0x3E
61 #define REG_DEVID2 0x3F
63 #define REG_CONFIG1 0x40
65 #define REG_STATUS1 0x41
66 #define REG_STATUS2 0x42
68 #define REG_VID 0x43 /* ADT7476 only */
70 #define REG_VOLTAGE_MIN_BASE 0x44
71 #define REG_VOLTAGE_MAX_BASE 0x45
73 #define REG_TEMP_MIN_BASE 0x4E
74 #define REG_TEMP_MAX_BASE 0x4F
76 #define REG_TACH_MIN_BASE 0x54
78 #define REG_PWM_CONFIG_BASE 0x5C
80 #define REG_TEMP_TRANGE_BASE 0x5F
82 #define REG_ENHANCE_ACOUSTICS1 0x62
83 #define REG_ENHANCE_ACOUSTICS2 0x63
85 #define REG_PWM_MIN_BASE 0x64
87 #define REG_TEMP_TMIN_BASE 0x67
88 #define REG_TEMP_THERM_BASE 0x6A
90 #define REG_REMOTE1_HYSTERSIS 0x6D
91 #define REG_REMOTE2_HYSTERSIS 0x6E
93 #define REG_TEMP_OFFSET_BASE 0x70
95 #define REG_CONFIG2 0x73
97 #define REG_EXTEND1 0x76
98 #define REG_EXTEND2 0x77
100 #define REG_CONFIG3 0x78
101 #define REG_CONFIG5 0x7C
102 #define REG_CONFIG4 0x7D
104 #define REG_STATUS4 0x81 /* ADT7490 only */
106 #define REG_VTT_MIN 0x84 /* ADT7490 only */
107 #define REG_VTT_MAX 0x86 /* ADT7490 only */
109 #define REG_IMON_MIN 0x85 /* ADT7490 only */
110 #define REG_IMON_MAX 0x87 /* ADT7490 only */
112 #define VID_VIDSEL 0x80 /* ADT7476 only */
114 #define CONFIG2_ATTN 0x20
116 #define CONFIG3_SMBALERT 0x01
117 #define CONFIG3_THERM 0x02
119 #define CONFIG4_PINFUNC 0x03
120 #define CONFIG4_THERM 0x01
121 #define CONFIG4_SMBALERT 0x02
122 #define CONFIG4_MAXDUTY 0x08
123 #define CONFIG4_ATTN_IN10 0x30
124 #define CONFIG4_ATTN_IN43 0xC0
126 #define CONFIG5_TWOSCOMP 0x01
127 #define CONFIG5_TEMPOFFSET 0x02
128 #define CONFIG5_VIDGPIO 0x10 /* ADT7476 only */
130 /* ADT7475 Settings */
132 #define ADT7475_VOLTAGE_COUNT 5 /* Not counting Vtt or Imon */
133 #define ADT7475_TEMP_COUNT 3
134 #define ADT7475_TACH_COUNT 4
135 #define ADT7475_PWM_COUNT 3
137 /* Macro to read the registers */
139 #define adt7475_read(reg) i2c_smbus_read_byte_data(client, (reg))
141 /* Macros to easily index the registers */
143 #define TACH_REG(idx) (REG_TACH_BASE + ((idx) * 2))
144 #define TACH_MIN_REG(idx) (REG_TACH_MIN_BASE + ((idx) * 2))
146 #define PWM_REG(idx) (REG_PWM_BASE + (idx))
147 #define PWM_MAX_REG(idx) (REG_PWM_MAX_BASE + (idx))
148 #define PWM_MIN_REG(idx) (REG_PWM_MIN_BASE + (idx))
149 #define PWM_CONFIG_REG(idx) (REG_PWM_CONFIG_BASE + (idx))
151 #define VOLTAGE_REG(idx) (REG_VOLTAGE_BASE + (idx))
152 #define VOLTAGE_MIN_REG(idx) (REG_VOLTAGE_MIN_BASE + ((idx) * 2))
153 #define VOLTAGE_MAX_REG(idx) (REG_VOLTAGE_MAX_BASE + ((idx) * 2))
155 #define TEMP_REG(idx) (REG_TEMP_BASE + (idx))
156 #define TEMP_MIN_REG(idx) (REG_TEMP_MIN_BASE + ((idx) * 2))
157 #define TEMP_MAX_REG(idx) (REG_TEMP_MAX_BASE + ((idx) * 2))
158 #define TEMP_TMIN_REG(idx) (REG_TEMP_TMIN_BASE + (idx))
159 #define TEMP_THERM_REG(idx) (REG_TEMP_THERM_BASE + (idx))
160 #define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx))
161 #define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx))
163 static const unsigned short normal_i2c
[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END
};
165 enum chips
{ adt7473
, adt7475
, adt7476
, adt7490
};
167 static const struct i2c_device_id adt7475_id
[] = {
168 { "adt7473", adt7473
},
169 { "adt7475", adt7475
},
170 { "adt7476", adt7476
},
171 { "adt7490", adt7490
},
174 MODULE_DEVICE_TABLE(i2c
, adt7475_id
);
176 static const struct of_device_id __maybe_unused adt7475_of_match
[] = {
178 .compatible
= "adi,adt7473",
179 .data
= (void *)adt7473
182 .compatible
= "adi,adt7475",
183 .data
= (void *)adt7475
186 .compatible
= "adi,adt7476",
187 .data
= (void *)adt7476
190 .compatible
= "adi,adt7490",
191 .data
= (void *)adt7490
195 MODULE_DEVICE_TABLE(of
, adt7475_of_match
);
197 struct adt7475_data
{
198 struct i2c_client
*client
;
201 unsigned long measure_updated
;
208 u8 bypass_attn
; /* Bypass voltage attenuator */
224 const struct attribute_group
*groups
[10];
227 static struct i2c_driver adt7475_driver
;
228 static struct adt7475_data
*adt7475_update_device(struct device
*dev
);
229 static void adt7475_read_hystersis(struct i2c_client
*client
);
230 static void adt7475_read_pwm(struct i2c_client
*client
, int index
);
232 /* Given a temp value, convert it to register value */
234 static inline u16
temp2reg(struct adt7475_data
*data
, long val
)
238 if (!(data
->config5
& CONFIG5_TWOSCOMP
)) {
239 val
= clamp_val(val
, -64000, 191000);
240 ret
= (val
+ 64500) / 1000;
242 val
= clamp_val(val
, -128000, 127000);
244 ret
= (256500 + val
) / 1000;
246 ret
= (val
+ 500) / 1000;
252 /* Given a register value, convert it to a real temp value */
254 static inline int reg2temp(struct adt7475_data
*data
, u16 reg
)
256 if (data
->config5
& CONFIG5_TWOSCOMP
) {
258 return (reg
- 1024) * 250;
262 return (reg
- 256) * 250;
265 static inline int tach2rpm(u16 tach
)
267 if (tach
== 0 || tach
== 0xFFFF)
270 return (90000 * 60) / tach
;
273 static inline u16
rpm2tach(unsigned long rpm
)
278 return clamp_val((90000 * 60) / rpm
, 1, 0xFFFF);
281 /* Scaling factors for voltage inputs, taken from the ADT7490 datasheet */
282 static const int adt7473_in_scaling
[ADT7475_VOLTAGE_COUNT
+ 2][2] = {
283 { 45, 94 }, /* +2.5V */
284 { 175, 525 }, /* Vccp */
285 { 68, 71 }, /* Vcc */
286 { 93, 47 }, /* +5V */
287 { 120, 20 }, /* +12V */
288 { 45, 45 }, /* Vtt */
289 { 45, 45 }, /* Imon */
292 static inline int reg2volt(int channel
, u16 reg
, u8 bypass_attn
)
294 const int *r
= adt7473_in_scaling
[channel
];
296 if (bypass_attn
& (1 << channel
))
297 return DIV_ROUND_CLOSEST(reg
* 2250, 1024);
298 return DIV_ROUND_CLOSEST(reg
* (r
[0] + r
[1]) * 2250, r
[1] * 1024);
301 static inline u16
volt2reg(int channel
, long volt
, u8 bypass_attn
)
303 const int *r
= adt7473_in_scaling
[channel
];
306 if (bypass_attn
& (1 << channel
))
307 reg
= DIV_ROUND_CLOSEST(volt
* 1024, 2250);
309 reg
= DIV_ROUND_CLOSEST(volt
* r
[1] * 1024,
310 (r
[0] + r
[1]) * 2250);
311 return clamp_val(reg
, 0, 1023) & (0xff << 2);
314 static int adt7475_read_word(struct i2c_client
*client
, int reg
)
318 val1
= i2c_smbus_read_byte_data(client
, reg
);
321 val2
= i2c_smbus_read_byte_data(client
, reg
+ 1);
325 return val1
| (val2
<< 8);
328 static void adt7475_write_word(struct i2c_client
*client
, int reg
, u16 val
)
330 i2c_smbus_write_byte_data(client
, reg
+ 1, val
>> 8);
331 i2c_smbus_write_byte_data(client
, reg
, val
& 0xFF);
334 static ssize_t
voltage_show(struct device
*dev
, struct device_attribute
*attr
,
337 struct adt7475_data
*data
= adt7475_update_device(dev
);
338 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
342 return PTR_ERR(data
);
346 return sprintf(buf
, "%d\n",
347 (data
->alarms
>> sattr
->index
) & 1);
349 val
= data
->voltage
[sattr
->nr
][sattr
->index
];
350 return sprintf(buf
, "%d\n",
351 reg2volt(sattr
->index
, val
, data
->bypass_attn
));
355 static ssize_t
voltage_store(struct device
*dev
,
356 struct device_attribute
*attr
, const char *buf
,
360 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
361 struct adt7475_data
*data
= dev_get_drvdata(dev
);
362 struct i2c_client
*client
= data
->client
;
366 if (kstrtol(buf
, 10, &val
))
369 mutex_lock(&data
->lock
);
371 data
->voltage
[sattr
->nr
][sattr
->index
] =
372 volt2reg(sattr
->index
, val
, data
->bypass_attn
);
374 if (sattr
->index
< ADT7475_VOLTAGE_COUNT
) {
375 if (sattr
->nr
== MIN
)
376 reg
= VOLTAGE_MIN_REG(sattr
->index
);
378 reg
= VOLTAGE_MAX_REG(sattr
->index
);
379 } else if (sattr
->index
== 5) {
380 if (sattr
->nr
== MIN
)
385 if (sattr
->nr
== MIN
)
391 i2c_smbus_write_byte_data(client
, reg
,
392 data
->voltage
[sattr
->nr
][sattr
->index
] >> 2);
393 mutex_unlock(&data
->lock
);
398 static ssize_t
temp_show(struct device
*dev
, struct device_attribute
*attr
,
401 struct adt7475_data
*data
= adt7475_update_device(dev
);
402 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
406 return PTR_ERR(data
);
410 mutex_lock(&data
->lock
);
411 out
= data
->temp
[sattr
->nr
][sattr
->index
];
412 if (sattr
->index
!= 1)
413 out
= (out
>> 4) & 0xF;
417 * Show the value as an absolute number tied to
420 out
= reg2temp(data
, data
->temp
[THERM
][sattr
->index
]) -
422 mutex_unlock(&data
->lock
);
427 * Offset is always 2's complement, regardless of the
430 mutex_lock(&data
->lock
);
431 out
= (s8
)data
->temp
[sattr
->nr
][sattr
->index
];
432 if (data
->config5
& CONFIG5_TEMPOFFSET
)
436 mutex_unlock(&data
->lock
);
440 out
= (data
->alarms
>> (sattr
->index
+ 4)) & 1;
444 /* Note - only for remote1 and remote2 */
445 out
= !!(data
->alarms
& (sattr
->index
? 0x8000 : 0x4000));
449 /* All other temp values are in the configured format */
450 out
= reg2temp(data
, data
->temp
[sattr
->nr
][sattr
->index
]);
453 return sprintf(buf
, "%d\n", out
);
456 static ssize_t
temp_store(struct device
*dev
, struct device_attribute
*attr
,
457 const char *buf
, size_t count
)
459 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
460 struct adt7475_data
*data
= dev_get_drvdata(dev
);
461 struct i2c_client
*client
= data
->client
;
462 unsigned char reg
= 0;
467 if (kstrtol(buf
, 10, &val
))
470 mutex_lock(&data
->lock
);
472 /* We need the config register in all cases for temp <-> reg conv. */
473 data
->config5
= adt7475_read(REG_CONFIG5
);
477 if (data
->config5
& CONFIG5_TEMPOFFSET
) {
478 val
= clamp_val(val
, -63000, 127000);
479 out
= data
->temp
[OFFSET
][sattr
->index
] = val
/ 1000;
481 val
= clamp_val(val
, -63000, 64000);
482 out
= data
->temp
[OFFSET
][sattr
->index
] = val
/ 500;
488 * The value will be given as an absolute value, turn it
489 * into an offset based on THERM
492 /* Read fresh THERM and HYSTERSIS values from the chip */
493 data
->temp
[THERM
][sattr
->index
] =
494 adt7475_read(TEMP_THERM_REG(sattr
->index
)) << 2;
495 adt7475_read_hystersis(client
);
497 temp
= reg2temp(data
, data
->temp
[THERM
][sattr
->index
]);
498 val
= clamp_val(val
, temp
- 15000, temp
);
499 val
= (temp
- val
) / 1000;
501 if (sattr
->index
!= 1) {
502 data
->temp
[HYSTERSIS
][sattr
->index
] &= 0x0F;
503 data
->temp
[HYSTERSIS
][sattr
->index
] |= (val
& 0xF) << 4;
505 data
->temp
[HYSTERSIS
][sattr
->index
] &= 0xF0;
506 data
->temp
[HYSTERSIS
][sattr
->index
] |= (val
& 0xF);
509 out
= data
->temp
[HYSTERSIS
][sattr
->index
];
513 data
->temp
[sattr
->nr
][sattr
->index
] = temp2reg(data
, val
);
516 * We maintain an extra 2 digits of precision for simplicity
517 * - shift those back off before writing the value
519 out
= (u8
) (data
->temp
[sattr
->nr
][sattr
->index
] >> 2);
524 reg
= TEMP_MIN_REG(sattr
->index
);
527 reg
= TEMP_MAX_REG(sattr
->index
);
530 reg
= TEMP_OFFSET_REG(sattr
->index
);
533 reg
= TEMP_TMIN_REG(sattr
->index
);
536 reg
= TEMP_THERM_REG(sattr
->index
);
539 if (sattr
->index
!= 2)
540 reg
= REG_REMOTE1_HYSTERSIS
;
542 reg
= REG_REMOTE2_HYSTERSIS
;
547 i2c_smbus_write_byte_data(client
, reg
, out
);
549 mutex_unlock(&data
->lock
);
553 /* Assuming CONFIG6[SLOW] is 0 */
554 static const int ad7475_st_map
[] = {
555 37500, 18800, 12500, 7500, 4700, 3100, 1600, 800,
558 static ssize_t
temp_st_show(struct device
*dev
, struct device_attribute
*attr
,
561 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
562 struct adt7475_data
*data
= dev_get_drvdata(dev
);
565 switch (sattr
->index
) {
567 val
= data
->enh_acoustics
[0] & 0xf;
570 val
= data
->enh_acoustics
[1] & 0xf;
574 val
= (data
->enh_acoustics
[1] >> 4) & 0xf;
579 return sprintf(buf
, "%d\n", ad7475_st_map
[val
& 0x7]);
581 return sprintf(buf
, "0\n");
584 static ssize_t
temp_st_store(struct device
*dev
,
585 struct device_attribute
*attr
, const char *buf
,
588 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
589 struct adt7475_data
*data
= dev_get_drvdata(dev
);
590 struct i2c_client
*client
= data
->client
;
595 if (kstrtoul(buf
, 10, &val
))
598 switch (sattr
->index
) {
600 reg
= REG_ENHANCE_ACOUSTICS1
;
605 reg
= REG_ENHANCE_ACOUSTICS2
;
611 reg
= REG_ENHANCE_ACOUSTICS2
;
618 val
= find_closest_descending(val
, ad7475_st_map
,
619 ARRAY_SIZE(ad7475_st_map
));
623 mutex_lock(&data
->lock
);
625 data
->enh_acoustics
[idx
] &= ~(0xf << shift
);
626 data
->enh_acoustics
[idx
] |= (val
<< shift
);
628 i2c_smbus_write_byte_data(client
, reg
, data
->enh_acoustics
[idx
]);
630 mutex_unlock(&data
->lock
);
636 * Table of autorange values - the user will write the value in millidegrees,
637 * and we'll convert it
639 static const int autorange_table
[] = {
640 2000, 2500, 3330, 4000, 5000, 6670, 8000,
641 10000, 13330, 16000, 20000, 26670, 32000, 40000,
645 static ssize_t
point2_show(struct device
*dev
, struct device_attribute
*attr
,
648 struct adt7475_data
*data
= adt7475_update_device(dev
);
649 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
653 return PTR_ERR(data
);
655 mutex_lock(&data
->lock
);
656 out
= (data
->range
[sattr
->index
] >> 4) & 0x0F;
657 val
= reg2temp(data
, data
->temp
[AUTOMIN
][sattr
->index
]);
658 mutex_unlock(&data
->lock
);
660 return sprintf(buf
, "%d\n", val
+ autorange_table
[out
]);
663 static ssize_t
point2_store(struct device
*dev
, struct device_attribute
*attr
,
664 const char *buf
, size_t count
)
666 struct adt7475_data
*data
= dev_get_drvdata(dev
);
667 struct i2c_client
*client
= data
->client
;
668 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
672 if (kstrtol(buf
, 10, &val
))
675 mutex_lock(&data
->lock
);
677 /* Get a fresh copy of the needed registers */
678 data
->config5
= adt7475_read(REG_CONFIG5
);
679 data
->temp
[AUTOMIN
][sattr
->index
] =
680 adt7475_read(TEMP_TMIN_REG(sattr
->index
)) << 2;
681 data
->range
[sattr
->index
] =
682 adt7475_read(TEMP_TRANGE_REG(sattr
->index
));
685 * The user will write an absolute value, so subtract the start point
686 * to figure the range
688 temp
= reg2temp(data
, data
->temp
[AUTOMIN
][sattr
->index
]);
689 val
= clamp_val(val
, temp
+ autorange_table
[0],
690 temp
+ autorange_table
[ARRAY_SIZE(autorange_table
) - 1]);
693 /* Find the nearest table entry to what the user wrote */
694 val
= find_closest(val
, autorange_table
, ARRAY_SIZE(autorange_table
));
696 data
->range
[sattr
->index
] &= ~0xF0;
697 data
->range
[sattr
->index
] |= val
<< 4;
699 i2c_smbus_write_byte_data(client
, TEMP_TRANGE_REG(sattr
->index
),
700 data
->range
[sattr
->index
]);
702 mutex_unlock(&data
->lock
);
706 static ssize_t
tach_show(struct device
*dev
, struct device_attribute
*attr
,
709 struct adt7475_data
*data
= adt7475_update_device(dev
);
710 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
714 return PTR_ERR(data
);
716 if (sattr
->nr
== ALARM
)
717 out
= (data
->alarms
>> (sattr
->index
+ 10)) & 1;
719 out
= tach2rpm(data
->tach
[sattr
->nr
][sattr
->index
]);
721 return sprintf(buf
, "%d\n", out
);
724 static ssize_t
tach_store(struct device
*dev
, struct device_attribute
*attr
,
725 const char *buf
, size_t count
)
728 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
729 struct adt7475_data
*data
= dev_get_drvdata(dev
);
730 struct i2c_client
*client
= data
->client
;
733 if (kstrtoul(buf
, 10, &val
))
736 mutex_lock(&data
->lock
);
738 data
->tach
[MIN
][sattr
->index
] = rpm2tach(val
);
740 adt7475_write_word(client
, TACH_MIN_REG(sattr
->index
),
741 data
->tach
[MIN
][sattr
->index
]);
743 mutex_unlock(&data
->lock
);
747 static ssize_t
pwm_show(struct device
*dev
, struct device_attribute
*attr
,
750 struct adt7475_data
*data
= adt7475_update_device(dev
);
751 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
754 return PTR_ERR(data
);
756 return sprintf(buf
, "%d\n", data
->pwm
[sattr
->nr
][sattr
->index
]);
759 static ssize_t
pwmchan_show(struct device
*dev
, struct device_attribute
*attr
,
762 struct adt7475_data
*data
= adt7475_update_device(dev
);
763 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
766 return PTR_ERR(data
);
768 return sprintf(buf
, "%d\n", data
->pwmchan
[sattr
->index
]);
771 static ssize_t
pwmctrl_show(struct device
*dev
, struct device_attribute
*attr
,
774 struct adt7475_data
*data
= adt7475_update_device(dev
);
775 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
778 return PTR_ERR(data
);
780 return sprintf(buf
, "%d\n", data
->pwmctl
[sattr
->index
]);
783 static ssize_t
pwm_store(struct device
*dev
, struct device_attribute
*attr
,
784 const char *buf
, size_t count
)
787 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
788 struct adt7475_data
*data
= dev_get_drvdata(dev
);
789 struct i2c_client
*client
= data
->client
;
790 unsigned char reg
= 0;
793 if (kstrtol(buf
, 10, &val
))
796 mutex_lock(&data
->lock
);
800 /* Get a fresh value for CONTROL */
801 data
->pwm
[CONTROL
][sattr
->index
] =
802 adt7475_read(PWM_CONFIG_REG(sattr
->index
));
805 * If we are not in manual mode, then we shouldn't allow
806 * the user to set the pwm speed
808 if (((data
->pwm
[CONTROL
][sattr
->index
] >> 5) & 7) != 7) {
809 mutex_unlock(&data
->lock
);
813 reg
= PWM_REG(sattr
->index
);
817 reg
= PWM_MIN_REG(sattr
->index
);
821 reg
= PWM_MAX_REG(sattr
->index
);
825 data
->pwm
[sattr
->nr
][sattr
->index
] = clamp_val(val
, 0, 0xFF);
826 i2c_smbus_write_byte_data(client
, reg
,
827 data
->pwm
[sattr
->nr
][sattr
->index
]);
828 mutex_unlock(&data
->lock
);
833 static ssize_t
stall_disable_show(struct device
*dev
,
834 struct device_attribute
*attr
, char *buf
)
836 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
837 struct adt7475_data
*data
= dev_get_drvdata(dev
);
839 u8 mask
= BIT(5 + sattr
->index
);
841 return sprintf(buf
, "%d\n", !!(data
->enh_acoustics
[0] & mask
));
844 static ssize_t
stall_disable_store(struct device
*dev
,
845 struct device_attribute
*attr
,
846 const char *buf
, size_t count
)
848 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
849 struct adt7475_data
*data
= dev_get_drvdata(dev
);
850 struct i2c_client
*client
= data
->client
;
852 u8 mask
= BIT(5 + sattr
->index
);
854 if (kstrtol(buf
, 10, &val
))
857 mutex_lock(&data
->lock
);
859 data
->enh_acoustics
[0] &= ~mask
;
861 data
->enh_acoustics
[0] |= mask
;
863 i2c_smbus_write_byte_data(client
, REG_ENHANCE_ACOUSTICS1
,
864 data
->enh_acoustics
[0]);
866 mutex_unlock(&data
->lock
);
871 /* Called by set_pwmctrl and set_pwmchan */
873 static int hw_set_pwm(struct i2c_client
*client
, int index
,
874 unsigned int pwmctl
, unsigned int pwmchan
)
876 struct adt7475_data
*data
= i2c_get_clientdata(client
);
881 val
= 0x03; /* Run at full speed */
884 val
= 0x07; /* Manual mode */
889 /* Remote1 controls PWM */
893 /* local controls PWM */
897 /* remote2 controls PWM */
901 /* local/remote2 control PWM */
905 /* All three control PWM */
916 data
->pwmctl
[index
] = pwmctl
;
917 data
->pwmchan
[index
] = pwmchan
;
919 data
->pwm
[CONTROL
][index
] &= ~0xE0;
920 data
->pwm
[CONTROL
][index
] |= (val
& 7) << 5;
922 i2c_smbus_write_byte_data(client
, PWM_CONFIG_REG(index
),
923 data
->pwm
[CONTROL
][index
]);
928 static ssize_t
pwmchan_store(struct device
*dev
,
929 struct device_attribute
*attr
, const char *buf
,
932 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
933 struct adt7475_data
*data
= dev_get_drvdata(dev
);
934 struct i2c_client
*client
= data
->client
;
938 if (kstrtol(buf
, 10, &val
))
941 mutex_lock(&data
->lock
);
942 /* Read Modify Write PWM values */
943 adt7475_read_pwm(client
, sattr
->index
);
944 r
= hw_set_pwm(client
, sattr
->index
, data
->pwmctl
[sattr
->index
], val
);
947 mutex_unlock(&data
->lock
);
952 static ssize_t
pwmctrl_store(struct device
*dev
,
953 struct device_attribute
*attr
, const char *buf
,
956 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
957 struct adt7475_data
*data
= dev_get_drvdata(dev
);
958 struct i2c_client
*client
= data
->client
;
962 if (kstrtol(buf
, 10, &val
))
965 mutex_lock(&data
->lock
);
966 /* Read Modify Write PWM values */
967 adt7475_read_pwm(client
, sattr
->index
);
968 r
= hw_set_pwm(client
, sattr
->index
, val
, data
->pwmchan
[sattr
->index
]);
971 mutex_unlock(&data
->lock
);
976 /* List of frequencies for the PWM */
977 static const int pwmfreq_table
[] = {
978 11, 14, 22, 29, 35, 44, 58, 88, 22500
981 static ssize_t
pwmfreq_show(struct device
*dev
, struct device_attribute
*attr
,
984 struct adt7475_data
*data
= adt7475_update_device(dev
);
985 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
989 return PTR_ERR(data
);
990 idx
= clamp_val(data
->range
[sattr
->index
] & 0xf, 0,
991 ARRAY_SIZE(pwmfreq_table
) - 1);
993 return sprintf(buf
, "%d\n", pwmfreq_table
[idx
]);
996 static ssize_t
pwmfreq_store(struct device
*dev
,
997 struct device_attribute
*attr
, const char *buf
,
1000 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
1001 struct adt7475_data
*data
= dev_get_drvdata(dev
);
1002 struct i2c_client
*client
= data
->client
;
1006 if (kstrtol(buf
, 10, &val
))
1009 out
= find_closest(val
, pwmfreq_table
, ARRAY_SIZE(pwmfreq_table
));
1011 mutex_lock(&data
->lock
);
1013 data
->range
[sattr
->index
] =
1014 adt7475_read(TEMP_TRANGE_REG(sattr
->index
));
1015 data
->range
[sattr
->index
] &= ~0xf;
1016 data
->range
[sattr
->index
] |= out
;
1018 i2c_smbus_write_byte_data(client
, TEMP_TRANGE_REG(sattr
->index
),
1019 data
->range
[sattr
->index
]);
1021 mutex_unlock(&data
->lock
);
1025 static ssize_t
pwm_use_point2_pwm_at_crit_show(struct device
*dev
,
1026 struct device_attribute
*devattr
,
1029 struct adt7475_data
*data
= adt7475_update_device(dev
);
1032 return PTR_ERR(data
);
1034 return sprintf(buf
, "%d\n", !!(data
->config4
& CONFIG4_MAXDUTY
));
1037 static ssize_t
pwm_use_point2_pwm_at_crit_store(struct device
*dev
,
1038 struct device_attribute
*devattr
,
1039 const char *buf
, size_t count
)
1041 struct adt7475_data
*data
= dev_get_drvdata(dev
);
1042 struct i2c_client
*client
= data
->client
;
1045 if (kstrtol(buf
, 10, &val
))
1047 if (val
!= 0 && val
!= 1)
1050 mutex_lock(&data
->lock
);
1051 data
->config4
= i2c_smbus_read_byte_data(client
, REG_CONFIG4
);
1053 data
->config4
|= CONFIG4_MAXDUTY
;
1055 data
->config4
&= ~CONFIG4_MAXDUTY
;
1056 i2c_smbus_write_byte_data(client
, REG_CONFIG4
, data
->config4
);
1057 mutex_unlock(&data
->lock
);
1062 static ssize_t
vrm_show(struct device
*dev
, struct device_attribute
*devattr
,
1065 struct adt7475_data
*data
= dev_get_drvdata(dev
);
1066 return sprintf(buf
, "%d\n", (int)data
->vrm
);
1069 static ssize_t
vrm_store(struct device
*dev
, struct device_attribute
*devattr
,
1070 const char *buf
, size_t count
)
1072 struct adt7475_data
*data
= dev_get_drvdata(dev
);
1075 if (kstrtol(buf
, 10, &val
))
1077 if (val
< 0 || val
> 255)
1084 static ssize_t
cpu0_vid_show(struct device
*dev
,
1085 struct device_attribute
*devattr
, char *buf
)
1087 struct adt7475_data
*data
= adt7475_update_device(dev
);
1090 return PTR_ERR(data
);
1092 return sprintf(buf
, "%d\n", vid_from_reg(data
->vid
, data
->vrm
));
1095 static SENSOR_DEVICE_ATTR_2_RO(in0_input
, voltage
, INPUT
, 0);
1096 static SENSOR_DEVICE_ATTR_2_RW(in0_max
, voltage
, MAX
, 0);
1097 static SENSOR_DEVICE_ATTR_2_RW(in0_min
, voltage
, MIN
, 0);
1098 static SENSOR_DEVICE_ATTR_2_RO(in0_alarm
, voltage
, ALARM
, 0);
1099 static SENSOR_DEVICE_ATTR_2_RO(in1_input
, voltage
, INPUT
, 1);
1100 static SENSOR_DEVICE_ATTR_2_RW(in1_max
, voltage
, MAX
, 1);
1101 static SENSOR_DEVICE_ATTR_2_RW(in1_min
, voltage
, MIN
, 1);
1102 static SENSOR_DEVICE_ATTR_2_RO(in1_alarm
, voltage
, ALARM
, 1);
1103 static SENSOR_DEVICE_ATTR_2_RO(in2_input
, voltage
, INPUT
, 2);
1104 static SENSOR_DEVICE_ATTR_2_RW(in2_max
, voltage
, MAX
, 2);
1105 static SENSOR_DEVICE_ATTR_2_RW(in2_min
, voltage
, MIN
, 2);
1106 static SENSOR_DEVICE_ATTR_2_RO(in2_alarm
, voltage
, ALARM
, 2);
1107 static SENSOR_DEVICE_ATTR_2_RO(in3_input
, voltage
, INPUT
, 3);
1108 static SENSOR_DEVICE_ATTR_2_RW(in3_max
, voltage
, MAX
, 3);
1109 static SENSOR_DEVICE_ATTR_2_RW(in3_min
, voltage
, MIN
, 3);
1110 static SENSOR_DEVICE_ATTR_2_RO(in3_alarm
, voltage
, ALARM
, 3);
1111 static SENSOR_DEVICE_ATTR_2_RO(in4_input
, voltage
, INPUT
, 4);
1112 static SENSOR_DEVICE_ATTR_2_RW(in4_max
, voltage
, MAX
, 4);
1113 static SENSOR_DEVICE_ATTR_2_RW(in4_min
, voltage
, MIN
, 4);
1114 static SENSOR_DEVICE_ATTR_2_RO(in4_alarm
, voltage
, ALARM
, 8);
1115 static SENSOR_DEVICE_ATTR_2_RO(in5_input
, voltage
, INPUT
, 5);
1116 static SENSOR_DEVICE_ATTR_2_RW(in5_max
, voltage
, MAX
, 5);
1117 static SENSOR_DEVICE_ATTR_2_RW(in5_min
, voltage
, MIN
, 5);
1118 static SENSOR_DEVICE_ATTR_2_RO(in5_alarm
, voltage
, ALARM
, 31);
1119 static SENSOR_DEVICE_ATTR_2_RO(in6_input
, voltage
, INPUT
, 6);
1120 static SENSOR_DEVICE_ATTR_2_RW(in6_max
, voltage
, MAX
, 6);
1121 static SENSOR_DEVICE_ATTR_2_RW(in6_min
, voltage
, MIN
, 6);
1122 static SENSOR_DEVICE_ATTR_2_RO(in6_alarm
, voltage
, ALARM
, 30);
1123 static SENSOR_DEVICE_ATTR_2_RO(temp1_input
, temp
, INPUT
, 0);
1124 static SENSOR_DEVICE_ATTR_2_RO(temp1_alarm
, temp
, ALARM
, 0);
1125 static SENSOR_DEVICE_ATTR_2_RO(temp1_fault
, temp
, FAULT
, 0);
1126 static SENSOR_DEVICE_ATTR_2_RW(temp1_max
, temp
, MAX
, 0);
1127 static SENSOR_DEVICE_ATTR_2_RW(temp1_min
, temp
, MIN
, 0);
1128 static SENSOR_DEVICE_ATTR_2_RW(temp1_offset
, temp
, OFFSET
, 0);
1129 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_point1_temp
, temp
, AUTOMIN
, 0);
1130 static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_point2_temp
, point2
, 0, 0);
1131 static SENSOR_DEVICE_ATTR_2_RW(temp1_crit
, temp
, THERM
, 0);
1132 static SENSOR_DEVICE_ATTR_2_RW(temp1_crit_hyst
, temp
, HYSTERSIS
, 0);
1133 static SENSOR_DEVICE_ATTR_2_RW(temp1_smoothing
, temp_st
, 0, 0);
1134 static SENSOR_DEVICE_ATTR_2_RO(temp2_input
, temp
, INPUT
, 1);
1135 static SENSOR_DEVICE_ATTR_2_RO(temp2_alarm
, temp
, ALARM
, 1);
1136 static SENSOR_DEVICE_ATTR_2_RW(temp2_max
, temp
, MAX
, 1);
1137 static SENSOR_DEVICE_ATTR_2_RW(temp2_min
, temp
, MIN
, 1);
1138 static SENSOR_DEVICE_ATTR_2_RW(temp2_offset
, temp
, OFFSET
, 1);
1139 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_point1_temp
, temp
, AUTOMIN
, 1);
1140 static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_point2_temp
, point2
, 0, 1);
1141 static SENSOR_DEVICE_ATTR_2_RW(temp2_crit
, temp
, THERM
, 1);
1142 static SENSOR_DEVICE_ATTR_2_RW(temp2_crit_hyst
, temp
, HYSTERSIS
, 1);
1143 static SENSOR_DEVICE_ATTR_2_RW(temp2_smoothing
, temp_st
, 0, 1);
1144 static SENSOR_DEVICE_ATTR_2_RO(temp3_input
, temp
, INPUT
, 2);
1145 static SENSOR_DEVICE_ATTR_2_RO(temp3_alarm
, temp
, ALARM
, 2);
1146 static SENSOR_DEVICE_ATTR_2_RO(temp3_fault
, temp
, FAULT
, 2);
1147 static SENSOR_DEVICE_ATTR_2_RW(temp3_max
, temp
, MAX
, 2);
1148 static SENSOR_DEVICE_ATTR_2_RW(temp3_min
, temp
, MIN
, 2);
1149 static SENSOR_DEVICE_ATTR_2_RW(temp3_offset
, temp
, OFFSET
, 2);
1150 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_point1_temp
, temp
, AUTOMIN
, 2);
1151 static SENSOR_DEVICE_ATTR_2_RW(temp3_auto_point2_temp
, point2
, 0, 2);
1152 static SENSOR_DEVICE_ATTR_2_RW(temp3_crit
, temp
, THERM
, 2);
1153 static SENSOR_DEVICE_ATTR_2_RW(temp3_crit_hyst
, temp
, HYSTERSIS
, 2);
1154 static SENSOR_DEVICE_ATTR_2_RW(temp3_smoothing
, temp_st
, 0, 2);
1155 static SENSOR_DEVICE_ATTR_2_RO(fan1_input
, tach
, INPUT
, 0);
1156 static SENSOR_DEVICE_ATTR_2_RW(fan1_min
, tach
, MIN
, 0);
1157 static SENSOR_DEVICE_ATTR_2_RO(fan1_alarm
, tach
, ALARM
, 0);
1158 static SENSOR_DEVICE_ATTR_2_RO(fan2_input
, tach
, INPUT
, 1);
1159 static SENSOR_DEVICE_ATTR_2_RW(fan2_min
, tach
, MIN
, 1);
1160 static SENSOR_DEVICE_ATTR_2_RO(fan2_alarm
, tach
, ALARM
, 1);
1161 static SENSOR_DEVICE_ATTR_2_RO(fan3_input
, tach
, INPUT
, 2);
1162 static SENSOR_DEVICE_ATTR_2_RW(fan3_min
, tach
, MIN
, 2);
1163 static SENSOR_DEVICE_ATTR_2_RO(fan3_alarm
, tach
, ALARM
, 2);
1164 static SENSOR_DEVICE_ATTR_2_RO(fan4_input
, tach
, INPUT
, 3);
1165 static SENSOR_DEVICE_ATTR_2_RW(fan4_min
, tach
, MIN
, 3);
1166 static SENSOR_DEVICE_ATTR_2_RO(fan4_alarm
, tach
, ALARM
, 3);
1167 static SENSOR_DEVICE_ATTR_2_RW(pwm1
, pwm
, INPUT
, 0);
1168 static SENSOR_DEVICE_ATTR_2_RW(pwm1_freq
, pwmfreq
, INPUT
, 0);
1169 static SENSOR_DEVICE_ATTR_2_RW(pwm1_enable
, pwmctrl
, INPUT
, 0);
1170 static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_channels_temp
, pwmchan
, INPUT
, 0);
1171 static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point1_pwm
, pwm
, MIN
, 0);
1172 static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point2_pwm
, pwm
, MAX
, 0);
1173 static SENSOR_DEVICE_ATTR_2_RW(pwm1_stall_disable
, stall_disable
, 0, 0);
1174 static SENSOR_DEVICE_ATTR_2_RW(pwm2
, pwm
, INPUT
, 1);
1175 static SENSOR_DEVICE_ATTR_2_RW(pwm2_freq
, pwmfreq
, INPUT
, 1);
1176 static SENSOR_DEVICE_ATTR_2_RW(pwm2_enable
, pwmctrl
, INPUT
, 1);
1177 static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_channels_temp
, pwmchan
, INPUT
, 1);
1178 static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point1_pwm
, pwm
, MIN
, 1);
1179 static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point2_pwm
, pwm
, MAX
, 1);
1180 static SENSOR_DEVICE_ATTR_2_RW(pwm2_stall_disable
, stall_disable
, 0, 1);
1181 static SENSOR_DEVICE_ATTR_2_RW(pwm3
, pwm
, INPUT
, 2);
1182 static SENSOR_DEVICE_ATTR_2_RW(pwm3_freq
, pwmfreq
, INPUT
, 2);
1183 static SENSOR_DEVICE_ATTR_2_RW(pwm3_enable
, pwmctrl
, INPUT
, 2);
1184 static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_channels_temp
, pwmchan
, INPUT
, 2);
1185 static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point1_pwm
, pwm
, MIN
, 2);
1186 static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point2_pwm
, pwm
, MAX
, 2);
1187 static SENSOR_DEVICE_ATTR_2_RW(pwm3_stall_disable
, stall_disable
, 0, 2);
1189 /* Non-standard name, might need revisiting */
1190 static DEVICE_ATTR_RW(pwm_use_point2_pwm_at_crit
);
1192 static DEVICE_ATTR_RW(vrm
);
1193 static DEVICE_ATTR_RO(cpu0_vid
);
1195 static struct attribute
*adt7475_attrs
[] = {
1196 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
1197 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
1198 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
1199 &sensor_dev_attr_in1_alarm
.dev_attr
.attr
,
1200 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
1201 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
1202 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
1203 &sensor_dev_attr_in2_alarm
.dev_attr
.attr
,
1204 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
1205 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
1206 &sensor_dev_attr_temp1_fault
.dev_attr
.attr
,
1207 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
1208 &sensor_dev_attr_temp1_min
.dev_attr
.attr
,
1209 &sensor_dev_attr_temp1_offset
.dev_attr
.attr
,
1210 &sensor_dev_attr_temp1_auto_point1_temp
.dev_attr
.attr
,
1211 &sensor_dev_attr_temp1_auto_point2_temp
.dev_attr
.attr
,
1212 &sensor_dev_attr_temp1_crit
.dev_attr
.attr
,
1213 &sensor_dev_attr_temp1_crit_hyst
.dev_attr
.attr
,
1214 &sensor_dev_attr_temp1_smoothing
.dev_attr
.attr
,
1215 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
1216 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
1217 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
1218 &sensor_dev_attr_temp2_min
.dev_attr
.attr
,
1219 &sensor_dev_attr_temp2_offset
.dev_attr
.attr
,
1220 &sensor_dev_attr_temp2_auto_point1_temp
.dev_attr
.attr
,
1221 &sensor_dev_attr_temp2_auto_point2_temp
.dev_attr
.attr
,
1222 &sensor_dev_attr_temp2_crit
.dev_attr
.attr
,
1223 &sensor_dev_attr_temp2_crit_hyst
.dev_attr
.attr
,
1224 &sensor_dev_attr_temp2_smoothing
.dev_attr
.attr
,
1225 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
1226 &sensor_dev_attr_temp3_fault
.dev_attr
.attr
,
1227 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
1228 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
1229 &sensor_dev_attr_temp3_min
.dev_attr
.attr
,
1230 &sensor_dev_attr_temp3_offset
.dev_attr
.attr
,
1231 &sensor_dev_attr_temp3_auto_point1_temp
.dev_attr
.attr
,
1232 &sensor_dev_attr_temp3_auto_point2_temp
.dev_attr
.attr
,
1233 &sensor_dev_attr_temp3_crit
.dev_attr
.attr
,
1234 &sensor_dev_attr_temp3_crit_hyst
.dev_attr
.attr
,
1235 &sensor_dev_attr_temp3_smoothing
.dev_attr
.attr
,
1236 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
1237 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
1238 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
1239 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
1240 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
1241 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
1242 &sensor_dev_attr_fan3_input
.dev_attr
.attr
,
1243 &sensor_dev_attr_fan3_min
.dev_attr
.attr
,
1244 &sensor_dev_attr_fan3_alarm
.dev_attr
.attr
,
1245 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
1246 &sensor_dev_attr_pwm1_freq
.dev_attr
.attr
,
1247 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
1248 &sensor_dev_attr_pwm1_auto_channels_temp
.dev_attr
.attr
,
1249 &sensor_dev_attr_pwm1_auto_point1_pwm
.dev_attr
.attr
,
1250 &sensor_dev_attr_pwm1_auto_point2_pwm
.dev_attr
.attr
,
1251 &sensor_dev_attr_pwm1_stall_disable
.dev_attr
.attr
,
1252 &sensor_dev_attr_pwm3
.dev_attr
.attr
,
1253 &sensor_dev_attr_pwm3_freq
.dev_attr
.attr
,
1254 &sensor_dev_attr_pwm3_enable
.dev_attr
.attr
,
1255 &sensor_dev_attr_pwm3_auto_channels_temp
.dev_attr
.attr
,
1256 &sensor_dev_attr_pwm3_auto_point1_pwm
.dev_attr
.attr
,
1257 &sensor_dev_attr_pwm3_auto_point2_pwm
.dev_attr
.attr
,
1258 &sensor_dev_attr_pwm3_stall_disable
.dev_attr
.attr
,
1259 &dev_attr_pwm_use_point2_pwm_at_crit
.attr
,
1263 static struct attribute
*fan4_attrs
[] = {
1264 &sensor_dev_attr_fan4_input
.dev_attr
.attr
,
1265 &sensor_dev_attr_fan4_min
.dev_attr
.attr
,
1266 &sensor_dev_attr_fan4_alarm
.dev_attr
.attr
,
1270 static struct attribute
*pwm2_attrs
[] = {
1271 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
1272 &sensor_dev_attr_pwm2_freq
.dev_attr
.attr
,
1273 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
1274 &sensor_dev_attr_pwm2_auto_channels_temp
.dev_attr
.attr
,
1275 &sensor_dev_attr_pwm2_auto_point1_pwm
.dev_attr
.attr
,
1276 &sensor_dev_attr_pwm2_auto_point2_pwm
.dev_attr
.attr
,
1277 &sensor_dev_attr_pwm2_stall_disable
.dev_attr
.attr
,
1281 static struct attribute
*in0_attrs
[] = {
1282 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
1283 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
1284 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
1285 &sensor_dev_attr_in0_alarm
.dev_attr
.attr
,
1289 static struct attribute
*in3_attrs
[] = {
1290 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
1291 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
1292 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
1293 &sensor_dev_attr_in3_alarm
.dev_attr
.attr
,
1297 static struct attribute
*in4_attrs
[] = {
1298 &sensor_dev_attr_in4_input
.dev_attr
.attr
,
1299 &sensor_dev_attr_in4_max
.dev_attr
.attr
,
1300 &sensor_dev_attr_in4_min
.dev_attr
.attr
,
1301 &sensor_dev_attr_in4_alarm
.dev_attr
.attr
,
1305 static struct attribute
*in5_attrs
[] = {
1306 &sensor_dev_attr_in5_input
.dev_attr
.attr
,
1307 &sensor_dev_attr_in5_max
.dev_attr
.attr
,
1308 &sensor_dev_attr_in5_min
.dev_attr
.attr
,
1309 &sensor_dev_attr_in5_alarm
.dev_attr
.attr
,
1313 static struct attribute
*in6_attrs
[] = {
1314 &sensor_dev_attr_in6_input
.dev_attr
.attr
,
1315 &sensor_dev_attr_in6_max
.dev_attr
.attr
,
1316 &sensor_dev_attr_in6_min
.dev_attr
.attr
,
1317 &sensor_dev_attr_in6_alarm
.dev_attr
.attr
,
1321 static struct attribute
*vid_attrs
[] = {
1322 &dev_attr_cpu0_vid
.attr
,
1327 static const struct attribute_group adt7475_attr_group
= { .attrs
= adt7475_attrs
};
1328 static const struct attribute_group fan4_attr_group
= { .attrs
= fan4_attrs
};
1329 static const struct attribute_group pwm2_attr_group
= { .attrs
= pwm2_attrs
};
1330 static const struct attribute_group in0_attr_group
= { .attrs
= in0_attrs
};
1331 static const struct attribute_group in3_attr_group
= { .attrs
= in3_attrs
};
1332 static const struct attribute_group in4_attr_group
= { .attrs
= in4_attrs
};
1333 static const struct attribute_group in5_attr_group
= { .attrs
= in5_attrs
};
1334 static const struct attribute_group in6_attr_group
= { .attrs
= in6_attrs
};
1335 static const struct attribute_group vid_attr_group
= { .attrs
= vid_attrs
};
1337 static int adt7475_detect(struct i2c_client
*client
,
1338 struct i2c_board_info
*info
)
1340 struct i2c_adapter
*adapter
= client
->adapter
;
1341 int vendid
, devid
, devid2
;
1344 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
1347 vendid
= adt7475_read(REG_VENDID
);
1348 devid2
= adt7475_read(REG_DEVID2
);
1349 if (vendid
!= 0x41 || /* Analog Devices */
1350 (devid2
& 0xf8) != 0x68)
1353 devid
= adt7475_read(REG_DEVID
);
1356 else if (devid
== 0x75 && client
->addr
== 0x2e)
1358 else if (devid
== 0x76)
1360 else if ((devid2
& 0xfc) == 0x6c)
1363 dev_dbg(&adapter
->dev
,
1364 "Couldn't detect an ADT7473/75/76/90 part at "
1365 "0x%02x\n", (unsigned int)client
->addr
);
1369 strscpy(info
->type
, name
, I2C_NAME_SIZE
);
1374 static int adt7475_update_limits(struct i2c_client
*client
)
1376 struct adt7475_data
*data
= i2c_get_clientdata(client
);
1380 ret
= adt7475_read(REG_CONFIG4
);
1383 data
->config4
= ret
;
1385 ret
= adt7475_read(REG_CONFIG5
);
1388 data
->config5
= ret
;
1390 for (i
= 0; i
< ADT7475_VOLTAGE_COUNT
; i
++) {
1391 if (!(data
->has_voltage
& (1 << i
)))
1393 /* Adjust values so they match the input precision */
1394 ret
= adt7475_read(VOLTAGE_MIN_REG(i
));
1397 data
->voltage
[MIN
][i
] = ret
<< 2;
1399 ret
= adt7475_read(VOLTAGE_MAX_REG(i
));
1402 data
->voltage
[MAX
][i
] = ret
<< 2;
1405 if (data
->has_voltage
& (1 << 5)) {
1406 ret
= adt7475_read(REG_VTT_MIN
);
1409 data
->voltage
[MIN
][5] = ret
<< 2;
1411 ret
= adt7475_read(REG_VTT_MAX
);
1414 data
->voltage
[MAX
][5] = ret
<< 2;
1417 if (data
->has_voltage
& (1 << 6)) {
1418 ret
= adt7475_read(REG_IMON_MIN
);
1421 data
->voltage
[MIN
][6] = ret
<< 2;
1423 ret
= adt7475_read(REG_IMON_MAX
);
1426 data
->voltage
[MAX
][6] = ret
<< 2;
1429 for (i
= 0; i
< ADT7475_TEMP_COUNT
; i
++) {
1430 /* Adjust values so they match the input precision */
1431 ret
= adt7475_read(TEMP_MIN_REG(i
));
1434 data
->temp
[MIN
][i
] = ret
<< 2;
1436 ret
= adt7475_read(TEMP_MAX_REG(i
));
1439 data
->temp
[MAX
][i
] = ret
<< 2;
1441 ret
= adt7475_read(TEMP_TMIN_REG(i
));
1444 data
->temp
[AUTOMIN
][i
] = ret
<< 2;
1446 ret
= adt7475_read(TEMP_THERM_REG(i
));
1449 data
->temp
[THERM
][i
] = ret
<< 2;
1451 ret
= adt7475_read(TEMP_OFFSET_REG(i
));
1454 data
->temp
[OFFSET
][i
] = ret
;
1456 adt7475_read_hystersis(client
);
1458 for (i
= 0; i
< ADT7475_TACH_COUNT
; i
++) {
1459 if (i
== 3 && !data
->has_fan4
)
1461 ret
= adt7475_read_word(client
, TACH_MIN_REG(i
));
1464 data
->tach
[MIN
][i
] = ret
;
1467 for (i
= 0; i
< ADT7475_PWM_COUNT
; i
++) {
1468 if (i
== 1 && !data
->has_pwm2
)
1470 ret
= adt7475_read(PWM_MAX_REG(i
));
1473 data
->pwm
[MAX
][i
] = ret
;
1475 ret
= adt7475_read(PWM_MIN_REG(i
));
1478 data
->pwm
[MIN
][i
] = ret
;
1479 /* Set the channel and control information */
1480 adt7475_read_pwm(client
, i
);
1483 ret
= adt7475_read(TEMP_TRANGE_REG(0));
1486 data
->range
[0] = ret
;
1488 ret
= adt7475_read(TEMP_TRANGE_REG(1));
1491 data
->range
[1] = ret
;
1493 ret
= adt7475_read(TEMP_TRANGE_REG(2));
1496 data
->range
[2] = ret
;
1501 static int load_config3(const struct i2c_client
*client
, const char *propname
)
1503 const char *function
;
1507 ret
= device_property_read_string(&client
->dev
, propname
, &function
);
1509 ret
= adt7475_read(REG_CONFIG3
);
1513 config3
= ret
& ~CONFIG3_SMBALERT
;
1514 if (!strcmp("pwm2", function
))
1516 else if (!strcmp("smbalert#", function
))
1517 config3
|= CONFIG3_SMBALERT
;
1521 return i2c_smbus_write_byte_data(client
, REG_CONFIG3
, config3
);
1527 static int load_config4(const struct i2c_client
*client
, const char *propname
)
1529 const char *function
;
1533 ret
= device_property_read_string(&client
->dev
, propname
, &function
);
1535 ret
= adt7475_read(REG_CONFIG4
);
1539 config4
= ret
& ~CONFIG4_PINFUNC
;
1541 if (!strcmp("tach4", function
))
1543 else if (!strcmp("therm#", function
))
1544 config4
|= CONFIG4_THERM
;
1545 else if (!strcmp("smbalert#", function
))
1546 config4
|= CONFIG4_SMBALERT
;
1547 else if (!strcmp("gpio", function
))
1548 config4
|= CONFIG4_PINFUNC
;
1552 return i2c_smbus_write_byte_data(client
, REG_CONFIG4
, config4
);
1558 static int load_config(const struct i2c_client
*client
, enum chips chip
)
1561 const char *prop1
, *prop2
;
1566 prop1
= "adi,pin5-function";
1567 prop2
= "adi,pin9-function";
1571 prop1
= "adi,pin10-function";
1572 prop2
= "adi,pin14-function";
1576 err
= load_config3(client
, prop1
);
1578 dev_err(&client
->dev
, "failed to configure %s\n", prop1
);
1582 err
= load_config4(client
, prop2
);
1584 dev_err(&client
->dev
, "failed to configure %s\n", prop2
);
1591 static int set_property_bit(const struct i2c_client
*client
, char *property
,
1592 u8
*config
, u8 bit_index
)
1595 int ret
= device_property_read_u32(&client
->dev
, property
,
1600 *config
|= (1 << bit_index
);
1602 *config
&= ~(1 << bit_index
);
1608 static int load_attenuators(const struct i2c_client
*client
, enum chips chip
,
1609 struct adt7475_data
*data
)
1614 set_property_bit(client
, "adi,bypass-attenuator-in0",
1616 set_property_bit(client
, "adi,bypass-attenuator-in1",
1618 set_property_bit(client
, "adi,bypass-attenuator-in3",
1620 set_property_bit(client
, "adi,bypass-attenuator-in4",
1623 return i2c_smbus_write_byte_data(client
, REG_CONFIG4
,
1627 set_property_bit(client
, "adi,bypass-attenuator-in1",
1630 return i2c_smbus_write_byte_data(client
, REG_CONFIG2
,
1637 static int adt7475_set_pwm_polarity(struct i2c_client
*client
)
1639 u32 states
[ADT7475_PWM_COUNT
];
1643 ret
= device_property_read_u32_array(&client
->dev
,
1644 "adi,pwm-active-state", states
,
1645 ARRAY_SIZE(states
));
1649 for (i
= 0; i
< ADT7475_PWM_COUNT
; i
++) {
1650 ret
= adt7475_read(PWM_CONFIG_REG(i
));
1659 ret
= i2c_smbus_write_byte_data(client
, PWM_CONFIG_REG(i
), val
);
1667 struct adt7475_pwm_config
{
1674 static int _adt7475_pwm_properties_parse_args(u32 args
[4], struct adt7475_pwm_config
*cfg
)
1682 freq_hz
= 1000000000UL / args
[1];
1683 if (args
[3] >= args
[1])
1686 duty
= div_u64(255ULL * args
[3], args
[1]);
1688 cfg
->index
= args
[0];
1689 cfg
->freq
= find_closest(freq_hz
, pwmfreq_table
, ARRAY_SIZE(pwmfreq_table
));
1690 cfg
->flags
= args
[2];
1696 static int adt7475_pwm_properties_parse_reference_args(struct fwnode_handle
*fwnode
,
1697 struct adt7475_pwm_config
*cfg
)
1700 struct fwnode_reference_args rargs
= {};
1703 ret
= fwnode_property_get_reference_args(fwnode
, "pwms", "#pwm-cells", 0, 0, &rargs
);
1707 if (rargs
.nargs
!= 4) {
1708 fwnode_handle_put(rargs
.fwnode
);
1712 for (i
= 0; i
< 4; i
++)
1713 args
[i
] = rargs
.args
[i
];
1715 ret
= _adt7475_pwm_properties_parse_args(args
, cfg
);
1717 fwnode_handle_put(rargs
.fwnode
);
1722 static int adt7475_pwm_properties_parse_args(struct fwnode_handle
*fwnode
,
1723 struct adt7475_pwm_config
*cfg
)
1728 ret
= fwnode_property_read_u32_array(fwnode
, "pwms", args
, ARRAY_SIZE(args
));
1732 return _adt7475_pwm_properties_parse_args(args
, cfg
);
1735 static int adt7475_fan_pwm_config(struct i2c_client
*client
)
1737 struct adt7475_data
*data
= i2c_get_clientdata(client
);
1738 struct adt7475_pwm_config cfg
= {};
1741 device_for_each_child_node_scoped(&client
->dev
, child
) {
1742 if (!fwnode_property_present(child
, "pwms"))
1745 if (is_of_node(child
))
1746 ret
= adt7475_pwm_properties_parse_reference_args(child
, &cfg
);
1748 ret
= adt7475_pwm_properties_parse_args(child
, &cfg
);
1750 if (cfg
.index
>= ADT7475_PWM_COUNT
)
1753 ret
= adt7475_read(PWM_CONFIG_REG(cfg
.index
));
1756 data
->pwm
[CONTROL
][cfg
.index
] = ret
;
1757 if (cfg
.flags
& PWM_POLARITY_INVERTED
)
1758 data
->pwm
[CONTROL
][cfg
.index
] |= BIT(4);
1760 data
->pwm
[CONTROL
][cfg
.index
] &= ~BIT(4);
1762 /* Force to manual mode so PWM values take effect */
1763 data
->pwm
[CONTROL
][cfg
.index
] &= ~0xE0;
1764 data
->pwm
[CONTROL
][cfg
.index
] |= 0x07 << 5;
1766 ret
= i2c_smbus_write_byte_data(client
, PWM_CONFIG_REG(cfg
.index
),
1767 data
->pwm
[CONTROL
][cfg
.index
]);
1771 data
->pwm
[INPUT
][cfg
.index
] = cfg
.duty
;
1772 ret
= i2c_smbus_write_byte_data(client
, PWM_REG(cfg
.index
),
1773 data
->pwm
[INPUT
][cfg
.index
]);
1777 data
->range
[cfg
.index
] = adt7475_read(TEMP_TRANGE_REG(cfg
.index
));
1778 data
->range
[cfg
.index
] &= ~0xf;
1779 data
->range
[cfg
.index
] |= cfg
.freq
;
1781 ret
= i2c_smbus_write_byte_data(client
, TEMP_TRANGE_REG(cfg
.index
),
1782 data
->range
[cfg
.index
]);
1790 static int adt7475_probe(struct i2c_client
*client
)
1793 static const char * const names
[] = {
1794 [adt7473
] = "ADT7473",
1795 [adt7475
] = "ADT7475",
1796 [adt7476
] = "ADT7476",
1797 [adt7490
] = "ADT7490",
1800 struct adt7475_data
*data
;
1801 struct device
*hwmon_dev
;
1802 int i
, ret
= 0, revision
, group_num
= 0;
1805 data
= devm_kzalloc(&client
->dev
, sizeof(*data
), GFP_KERNEL
);
1809 mutex_init(&data
->lock
);
1810 data
->client
= client
;
1811 i2c_set_clientdata(client
, data
);
1813 chip
= (uintptr_t)i2c_get_match_data(client
);
1815 /* Initialize device-specific values */
1818 data
->has_voltage
= 0x0e; /* in1 to in3 */
1819 revision
= adt7475_read(REG_DEVID2
) & 0x07;
1822 data
->has_voltage
= 0x7e; /* in1 to in6 */
1823 revision
= adt7475_read(REG_DEVID2
) & 0x03;
1824 if (revision
== 0x03)
1825 revision
+= adt7475_read(REG_DEVREV2
);
1828 data
->has_voltage
= 0x06; /* in1, in2 */
1829 revision
= adt7475_read(REG_DEVID2
) & 0x07;
1832 ret
= load_config(client
, chip
);
1836 config3
= adt7475_read(REG_CONFIG3
);
1837 /* Pin PWM2 may alternatively be used for ALERT output */
1838 if (!(config3
& CONFIG3_SMBALERT
))
1840 /* Meaning of this bit is inverted for the ADT7473-1 */
1841 if (chip
== adt7473
&& revision
>= 1)
1842 data
->has_pwm2
= !data
->has_pwm2
;
1844 data
->config4
= adt7475_read(REG_CONFIG4
);
1845 /* Pin TACH4 may alternatively be used for THERM */
1846 if ((data
->config4
& CONFIG4_PINFUNC
) == 0x0)
1850 * THERM configuration is more complex on the ADT7476 and ADT7490,
1851 * because 2 different pins (TACH4 and +2.5 Vin) can be used for
1854 if (chip
== adt7490
) {
1855 if ((data
->config4
& CONFIG4_PINFUNC
) == 0x1 &&
1856 !(config3
& CONFIG3_THERM
))
1859 if (chip
== adt7476
|| chip
== adt7490
) {
1860 if (!(config3
& CONFIG3_THERM
) ||
1861 (data
->config4
& CONFIG4_PINFUNC
) == 0x1)
1862 data
->has_voltage
|= (1 << 0); /* in0 */
1866 * On the ADT7476, the +12V input pin may instead be used as VID5,
1867 * and VID pins may alternatively be used as GPIO
1869 if (chip
== adt7476
) {
1870 u8 vid
= adt7475_read(REG_VID
);
1871 if (!(vid
& VID_VIDSEL
))
1872 data
->has_voltage
|= (1 << 4); /* in4 */
1874 data
->has_vid
= !(adt7475_read(REG_CONFIG5
) & CONFIG5_VIDGPIO
);
1877 /* Voltage attenuators can be bypassed, globally or individually */
1878 data
->config2
= adt7475_read(REG_CONFIG2
);
1879 ret
= load_attenuators(client
, chip
, data
);
1881 dev_warn(&client
->dev
, "Error configuring attenuator bypass\n");
1883 if (data
->config2
& CONFIG2_ATTN
) {
1884 data
->bypass_attn
= (0x3 << 3) | 0x3;
1886 data
->bypass_attn
= ((data
->config4
& CONFIG4_ATTN_IN10
) >> 4) |
1887 ((data
->config4
& CONFIG4_ATTN_IN43
) >> 3);
1889 data
->bypass_attn
&= data
->has_voltage
;
1892 * Call adt7475_read_pwm for all pwm's as this will reprogram any
1893 * pwm's which are disabled to manual mode with 0% duty cycle
1895 for (i
= 0; i
< ADT7475_PWM_COUNT
; i
++)
1896 adt7475_read_pwm(client
, i
);
1898 ret
= adt7475_set_pwm_polarity(client
);
1899 if (ret
&& ret
!= -EINVAL
)
1900 dev_warn(&client
->dev
, "Error configuring pwm polarity\n");
1902 ret
= adt7475_fan_pwm_config(client
);
1904 dev_warn(&client
->dev
, "Error %d configuring fan/pwm\n", ret
);
1906 /* Start monitoring */
1910 i2c_smbus_write_byte_data(client
, REG_CONFIG1
,
1911 adt7475_read(REG_CONFIG1
) | 0x01);
1917 data
->groups
[group_num
++] = &adt7475_attr_group
;
1919 /* Features that can be disabled individually */
1920 if (data
->has_fan4
) {
1921 data
->groups
[group_num
++] = &fan4_attr_group
;
1923 if (data
->has_pwm2
) {
1924 data
->groups
[group_num
++] = &pwm2_attr_group
;
1926 if (data
->has_voltage
& (1 << 0)) {
1927 data
->groups
[group_num
++] = &in0_attr_group
;
1929 if (data
->has_voltage
& (1 << 3)) {
1930 data
->groups
[group_num
++] = &in3_attr_group
;
1932 if (data
->has_voltage
& (1 << 4)) {
1933 data
->groups
[group_num
++] = &in4_attr_group
;
1935 if (data
->has_voltage
& (1 << 5)) {
1936 data
->groups
[group_num
++] = &in5_attr_group
;
1938 if (data
->has_voltage
& (1 << 6)) {
1939 data
->groups
[group_num
++] = &in6_attr_group
;
1941 if (data
->has_vid
) {
1942 data
->vrm
= vid_which_vrm();
1943 data
->groups
[group_num
] = &vid_attr_group
;
1946 /* register device with all the acquired attributes */
1947 hwmon_dev
= devm_hwmon_device_register_with_groups(&client
->dev
,
1951 if (IS_ERR(hwmon_dev
)) {
1952 ret
= PTR_ERR(hwmon_dev
);
1956 dev_info(&client
->dev
, "%s device, revision %d\n",
1957 names
[chip
], revision
);
1958 if ((data
->has_voltage
& 0x11) || data
->has_fan4
|| data
->has_pwm2
)
1959 dev_info(&client
->dev
, "Optional features:%s%s%s%s%s\n",
1960 (data
->has_voltage
& (1 << 0)) ? " in0" : "",
1961 (data
->has_voltage
& (1 << 4)) ? " in4" : "",
1962 data
->has_fan4
? " fan4" : "",
1963 data
->has_pwm2
? " pwm2" : "",
1964 data
->has_vid
? " vid" : "");
1965 if (data
->bypass_attn
)
1966 dev_info(&client
->dev
, "Bypassing attenuators on:%s%s%s%s\n",
1967 (data
->bypass_attn
& (1 << 0)) ? " in0" : "",
1968 (data
->bypass_attn
& (1 << 1)) ? " in1" : "",
1969 (data
->bypass_attn
& (1 << 3)) ? " in3" : "",
1970 (data
->bypass_attn
& (1 << 4)) ? " in4" : "");
1972 /* Limits and settings, should never change update more than once */
1973 ret
= adt7475_update_limits(client
);
1980 static struct i2c_driver adt7475_driver
= {
1981 .class = I2C_CLASS_HWMON
,
1984 .of_match_table
= of_match_ptr(adt7475_of_match
),
1986 .probe
= adt7475_probe
,
1987 .id_table
= adt7475_id
,
1988 .detect
= adt7475_detect
,
1989 .address_list
= normal_i2c
,
1992 static void adt7475_read_hystersis(struct i2c_client
*client
)
1994 struct adt7475_data
*data
= i2c_get_clientdata(client
);
1996 data
->temp
[HYSTERSIS
][0] = (u16
) adt7475_read(REG_REMOTE1_HYSTERSIS
);
1997 data
->temp
[HYSTERSIS
][1] = data
->temp
[HYSTERSIS
][0];
1998 data
->temp
[HYSTERSIS
][2] = (u16
) adt7475_read(REG_REMOTE2_HYSTERSIS
);
2001 static void adt7475_read_pwm(struct i2c_client
*client
, int index
)
2003 struct adt7475_data
*data
= i2c_get_clientdata(client
);
2006 data
->pwm
[CONTROL
][index
] = adt7475_read(PWM_CONFIG_REG(index
));
2009 * Figure out the internal value for pwmctrl and pwmchan
2010 * based on the current settings
2012 v
= (data
->pwm
[CONTROL
][index
] >> 5) & 7;
2015 data
->pwmctl
[index
] = 0;
2017 data
->pwmctl
[index
] = 1;
2020 * The fan is disabled - we don't want to
2021 * support that, so change to manual mode and
2022 * set the duty cycle to 0 instead
2024 data
->pwm
[INPUT
][index
] = 0;
2025 data
->pwm
[CONTROL
][index
] &= ~0xE0;
2026 data
->pwm
[CONTROL
][index
] |= (7 << 5);
2028 i2c_smbus_write_byte_data(client
, PWM_REG(index
),
2029 data
->pwm
[INPUT
][index
]);
2031 i2c_smbus_write_byte_data(client
, PWM_CONFIG_REG(index
),
2032 data
->pwm
[CONTROL
][index
]);
2034 data
->pwmctl
[index
] = 1;
2036 data
->pwmctl
[index
] = 2;
2040 data
->pwmchan
[index
] = 1;
2043 data
->pwmchan
[index
] = 2;
2046 data
->pwmchan
[index
] = 4;
2049 data
->pwmchan
[index
] = 6;
2052 data
->pwmchan
[index
] = 7;
2058 static int adt7475_update_measure(struct device
*dev
)
2060 struct adt7475_data
*data
= dev_get_drvdata(dev
);
2061 struct i2c_client
*client
= data
->client
;
2066 ret
= adt7475_read(REG_STATUS2
);
2069 data
->alarms
= ret
<< 8;
2071 ret
= adt7475_read(REG_STATUS1
);
2074 data
->alarms
|= ret
;
2076 ret
= adt7475_read(REG_EXTEND2
);
2082 ret
= adt7475_read(REG_EXTEND1
);
2088 for (i
= 0; i
< ADT7475_VOLTAGE_COUNT
; i
++) {
2089 if (!(data
->has_voltage
& (1 << i
)))
2091 ret
= adt7475_read(VOLTAGE_REG(i
));
2094 data
->voltage
[INPUT
][i
] =
2096 ((ext
>> (i
* 2)) & 3);
2099 for (i
= 0; i
< ADT7475_TEMP_COUNT
; i
++) {
2100 ret
= adt7475_read(TEMP_REG(i
));
2103 data
->temp
[INPUT
][i
] =
2105 ((ext
>> ((i
+ 5) * 2)) & 3);
2108 if (data
->has_voltage
& (1 << 5)) {
2109 ret
= adt7475_read(REG_STATUS4
);
2112 data
->alarms
|= ret
<< 24;
2114 ret
= adt7475_read(REG_EXTEND3
);
2119 ret
= adt7475_read(REG_VTT
);
2122 data
->voltage
[INPUT
][5] = ret
<< 2 |
2126 if (data
->has_voltage
& (1 << 6)) {
2127 ret
= adt7475_read(REG_STATUS4
);
2130 data
->alarms
|= ret
<< 24;
2132 ret
= adt7475_read(REG_EXTEND3
);
2137 ret
= adt7475_read(REG_IMON
);
2140 data
->voltage
[INPUT
][6] = ret
<< 2 |
2144 for (i
= 0; i
< ADT7475_TACH_COUNT
; i
++) {
2145 if (i
== 3 && !data
->has_fan4
)
2147 ret
= adt7475_read_word(client
, TACH_REG(i
));
2150 data
->tach
[INPUT
][i
] = ret
;
2153 /* Updated by hw when in auto mode */
2154 for (i
= 0; i
< ADT7475_PWM_COUNT
; i
++) {
2155 if (i
== 1 && !data
->has_pwm2
)
2157 ret
= adt7475_read(PWM_REG(i
));
2160 data
->pwm
[INPUT
][i
] = ret
;
2163 if (data
->has_vid
) {
2164 ret
= adt7475_read(REG_VID
);
2167 data
->vid
= ret
& 0x3f;
2173 static struct adt7475_data
*adt7475_update_device(struct device
*dev
)
2175 struct adt7475_data
*data
= dev_get_drvdata(dev
);
2178 mutex_lock(&data
->lock
);
2180 /* Measurement values update every 2 seconds */
2181 if (time_after(jiffies
, data
->measure_updated
+ HZ
* 2) ||
2183 ret
= adt7475_update_measure(dev
);
2185 data
->valid
= false;
2186 mutex_unlock(&data
->lock
);
2187 return ERR_PTR(ret
);
2189 data
->measure_updated
= jiffies
;
2193 mutex_unlock(&data
->lock
);
2198 module_i2c_driver(adt7475_driver
);
2200 MODULE_AUTHOR("Advanced Micro Devices, Inc");
2201 MODULE_DESCRIPTION("adt7475 driver");
2202 MODULE_LICENSE("GPL");