2 * adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
4 * Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
5 * Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
9 * <http://www.onsemi.com/PowerSolutions/product.do?id=ADM1026>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <linux/jiffies.h>
30 #include <linux/i2c.h>
31 #include <linux/hwmon.h>
32 #include <linux/hwmon-sysfs.h>
33 #include <linux/hwmon-vid.h>
34 #include <linux/err.h>
35 #include <linux/mutex.h>
37 /* Addresses to scan */
38 static const unsigned short normal_i2c
[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END
};
40 static int gpio_input
[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
41 -1, -1, -1, -1, -1, -1, -1, -1 };
42 static int gpio_output
[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
43 -1, -1, -1, -1, -1, -1, -1, -1 };
44 static int gpio_inverted
[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
45 -1, -1, -1, -1, -1, -1, -1, -1 };
46 static int gpio_normal
[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
47 -1, -1, -1, -1, -1, -1, -1, -1 };
48 static int gpio_fan
[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
49 module_param_array(gpio_input
, int, NULL
, 0);
50 MODULE_PARM_DESC(gpio_input
, "List of GPIO pins (0-16) to program as inputs");
51 module_param_array(gpio_output
, int, NULL
, 0);
52 MODULE_PARM_DESC(gpio_output
,
53 "List of GPIO pins (0-16) to program as outputs");
54 module_param_array(gpio_inverted
, int, NULL
, 0);
55 MODULE_PARM_DESC(gpio_inverted
,
56 "List of GPIO pins (0-16) to program as inverted");
57 module_param_array(gpio_normal
, int, NULL
, 0);
58 MODULE_PARM_DESC(gpio_normal
,
59 "List of GPIO pins (0-16) to program as normal/non-inverted");
60 module_param_array(gpio_fan
, int, NULL
, 0);
61 MODULE_PARM_DESC(gpio_fan
, "List of GPIO pins (0-7) to program as fan tachs");
63 /* Many ADM1026 constants specified below */
65 /* The ADM1026 registers */
66 #define ADM1026_REG_CONFIG1 0x00
67 #define CFG1_MONITOR 0x01
68 #define CFG1_INT_ENABLE 0x02
69 #define CFG1_INT_CLEAR 0x04
70 #define CFG1_AIN8_9 0x08
71 #define CFG1_THERM_HOT 0x10
72 #define CFG1_DAC_AFC 0x20
73 #define CFG1_PWM_AFC 0x40
74 #define CFG1_RESET 0x80
76 #define ADM1026_REG_CONFIG2 0x01
77 /* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
79 #define ADM1026_REG_CONFIG3 0x07
80 #define CFG3_GPIO16_ENABLE 0x01
81 #define CFG3_CI_CLEAR 0x02
82 #define CFG3_VREF_250 0x04
83 #define CFG3_GPIO16_DIR 0x40
84 #define CFG3_GPIO16_POL 0x80
86 #define ADM1026_REG_E2CONFIG 0x13
87 #define E2CFG_READ 0x01
88 #define E2CFG_WRITE 0x02
89 #define E2CFG_ERASE 0x04
90 #define E2CFG_ROM 0x08
91 #define E2CFG_CLK_EXT 0x80
94 * There are 10 general analog inputs and 7 dedicated inputs
101 * 14 = Vccp (CPU core voltage)
105 static u16 ADM1026_REG_IN
[] = {
106 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
107 0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
108 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
110 static u16 ADM1026_REG_IN_MIN
[] = {
111 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
112 0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
113 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
115 static u16 ADM1026_REG_IN_MAX
[] = {
116 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
117 0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
118 0x43, 0x44, 0x45, 0x46, 0x47
127 static u16 ADM1026_REG_TEMP
[] = { 0x1f, 0x28, 0x29 };
128 static u16 ADM1026_REG_TEMP_MIN
[] = { 0x69, 0x48, 0x49 };
129 static u16 ADM1026_REG_TEMP_MAX
[] = { 0x68, 0x40, 0x41 };
130 static u16 ADM1026_REG_TEMP_TMIN
[] = { 0x10, 0x11, 0x12 };
131 static u16 ADM1026_REG_TEMP_THERM
[] = { 0x0d, 0x0e, 0x0f };
132 static u16 ADM1026_REG_TEMP_OFFSET
[] = { 0x1e, 0x6e, 0x6f };
134 #define ADM1026_REG_FAN(nr) (0x38 + (nr))
135 #define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
136 #define ADM1026_REG_FAN_DIV_0_3 0x02
137 #define ADM1026_REG_FAN_DIV_4_7 0x03
139 #define ADM1026_REG_DAC 0x04
140 #define ADM1026_REG_PWM 0x05
142 #define ADM1026_REG_GPIO_CFG_0_3 0x08
143 #define ADM1026_REG_GPIO_CFG_4_7 0x09
144 #define ADM1026_REG_GPIO_CFG_8_11 0x0a
145 #define ADM1026_REG_GPIO_CFG_12_15 0x0b
146 /* CFG_16 in REG_CFG3 */
147 #define ADM1026_REG_GPIO_STATUS_0_7 0x24
148 #define ADM1026_REG_GPIO_STATUS_8_15 0x25
149 /* STATUS_16 in REG_STATUS4 */
150 #define ADM1026_REG_GPIO_MASK_0_7 0x1c
151 #define ADM1026_REG_GPIO_MASK_8_15 0x1d
152 /* MASK_16 in REG_MASK4 */
154 #define ADM1026_REG_COMPANY 0x16
155 #define ADM1026_REG_VERSTEP 0x17
156 /* These are the recognized values for the above regs */
157 #define ADM1026_COMPANY_ANALOG_DEV 0x41
158 #define ADM1026_VERSTEP_GENERIC 0x40
159 #define ADM1026_VERSTEP_ADM1026 0x44
161 #define ADM1026_REG_MASK1 0x18
162 #define ADM1026_REG_MASK2 0x19
163 #define ADM1026_REG_MASK3 0x1a
164 #define ADM1026_REG_MASK4 0x1b
166 #define ADM1026_REG_STATUS1 0x20
167 #define ADM1026_REG_STATUS2 0x21
168 #define ADM1026_REG_STATUS3 0x22
169 #define ADM1026_REG_STATUS4 0x23
171 #define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
172 #define ADM1026_FAN_CONTROL_TEMP_RANGE 20
173 #define ADM1026_PWM_MAX 255
176 * Conversions. Rounding and limit checking is only done on the TO_REG
177 * variants. Note that you should be a bit careful with which arguments
178 * these macros are called: arguments may be evaluated more than once.
182 * IN are scaled according to built-in resistors. These are the
183 * voltages corresponding to 3/4 of full scale (192 or 0xc0)
184 * NOTE: The -12V input needs an additional factor to account
185 * for the Vref pullup resistor.
186 * NEG12_OFFSET = SCALE * Vref / V-192 - Vref
187 * = 13875 * 2.50 / 1.875 - 2500
190 * The values in this table are based on Table II, page 15 of the
193 static int adm1026_scaling
[] = { /* .001 Volts */
194 2250, 2250, 2250, 2250, 2250, 2250,
195 1875, 1875, 1875, 1875, 3000, 3330,
196 3330, 4995, 2250, 12000, 13875
198 #define NEG12_OFFSET 16000
199 #define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from))
200 #define INS_TO_REG(n, val) \
201 SCALE(clamp_val(val, 0, 255 * adm1026_scaling[n] / 192), \
202 adm1026_scaling[n], 192)
203 #define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n]))
206 * FAN speed is measured using 22.5kHz clock and counts for 2 pulses
207 * and we assume a 2 pulse-per-rev fan tach signal
208 * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
210 #define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \
211 clamp_val(1350000 / ((val) * (div)), \
213 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 0xff ? 0 : \
214 1350000 / ((val) * (div)))
215 #define DIV_FROM_REG(val) (1 << (val))
216 #define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0)
218 /* Temperature is reported in 1 degC increments */
219 #define TEMP_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), \
221 #define TEMP_FROM_REG(val) ((val) * 1000)
222 #define OFFSET_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), \
224 #define OFFSET_FROM_REG(val) ((val) * 1000)
226 #define PWM_TO_REG(val) (clamp_val(val, 0, 255))
227 #define PWM_FROM_REG(val) (val)
229 #define PWM_MIN_TO_REG(val) ((val) & 0xf0)
230 #define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
233 * Analog output is a voltage, and scaled to millivolts. The datasheet
234 * indicates that the DAC could be used to drive the fans, but in our
235 * example board (Arima HDAMA) it isn't connected to the fans at all.
237 #define DAC_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val(val, 0, 2500) * 255, \
239 #define DAC_FROM_REG(val) (((val) * 2500) / 255)
242 * Chip sampling rates
244 * Some sensors are not updated more frequently than once per second
245 * so it doesn't make sense to read them more often than that.
246 * We cache the results and return the saved data if the driver
247 * is called again before a second has elapsed.
249 * Also, there is significant configuration data for this chip
250 * So, we keep the config data up to date in the cache
251 * when it is written and only sample it once every 5 *minutes*
253 #define ADM1026_DATA_INTERVAL (1 * HZ)
254 #define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
257 * We allow for multiple chips in a single system.
259 * For each registered ADM1026, we need to keep state information
260 * at client->data. The adm1026_data structure is dynamically
261 * allocated, when a new client structure is allocated.
270 struct adm1026_data
{
271 struct i2c_client
*client
;
272 const struct attribute_group
*groups
[3];
274 struct mutex update_lock
;
275 int valid
; /* !=0 if following fields are valid */
276 unsigned long last_reading
; /* In jiffies */
277 unsigned long last_config
; /* In jiffies */
279 u8 in
[17]; /* Register value */
280 u8 in_max
[17]; /* Register value */
281 u8 in_min
[17]; /* Register value */
282 s8 temp
[3]; /* Register value */
283 s8 temp_min
[3]; /* Register value */
284 s8 temp_max
[3]; /* Register value */
285 s8 temp_tmin
[3]; /* Register value */
286 s8 temp_crit
[3]; /* Register value */
287 s8 temp_offset
[3]; /* Register value */
288 u8 fan
[8]; /* Register value */
289 u8 fan_min
[8]; /* Register value */
290 u8 fan_div
[8]; /* Decoded value */
291 struct pwm_data pwm1
; /* Pwm control values */
292 u8 vrm
; /* VRM version */
293 u8 analog_out
; /* Register value (DAC) */
294 long alarms
; /* Register encoding, combined */
295 long alarm_mask
; /* Register encoding, combined */
296 long gpio
; /* Register encoding, combined */
297 long gpio_mask
; /* Register encoding, combined */
298 u8 gpio_config
[17]; /* Decoded value */
299 u8 config1
; /* Register value */
300 u8 config2
; /* Register value */
301 u8 config3
; /* Register value */
304 static int adm1026_read_value(struct i2c_client
*client
, u8 reg
)
309 /* "RAM" locations */
310 res
= i2c_smbus_read_byte_data(client
, reg
) & 0xff;
312 /* EEPROM, do nothing */
318 static int adm1026_write_value(struct i2c_client
*client
, u8 reg
, int value
)
323 /* "RAM" locations */
324 res
= i2c_smbus_write_byte_data(client
, reg
, value
);
326 /* EEPROM, do nothing */
332 static struct adm1026_data
*adm1026_update_device(struct device
*dev
)
334 struct adm1026_data
*data
= dev_get_drvdata(dev
);
335 struct i2c_client
*client
= data
->client
;
337 long value
, alarms
, gpio
;
339 mutex_lock(&data
->update_lock
);
341 || time_after(jiffies
,
342 data
->last_reading
+ ADM1026_DATA_INTERVAL
)) {
343 /* Things that change quickly */
344 dev_dbg(&client
->dev
, "Reading sensor values\n");
345 for (i
= 0; i
<= 16; ++i
) {
347 adm1026_read_value(client
, ADM1026_REG_IN
[i
]);
350 for (i
= 0; i
<= 7; ++i
) {
352 adm1026_read_value(client
, ADM1026_REG_FAN(i
));
355 for (i
= 0; i
<= 2; ++i
) {
357 * NOTE: temp[] is s8 and we assume 2's complement
358 * "conversion" in the assignment
361 adm1026_read_value(client
, ADM1026_REG_TEMP
[i
]);
364 data
->pwm1
.pwm
= adm1026_read_value(client
,
366 data
->analog_out
= adm1026_read_value(client
,
368 /* GPIO16 is MSbit of alarms, move it to gpio */
369 alarms
= adm1026_read_value(client
, ADM1026_REG_STATUS4
);
370 gpio
= alarms
& 0x80 ? 0x0100 : 0; /* GPIO16 */
373 alarms
|= adm1026_read_value(client
, ADM1026_REG_STATUS3
);
375 alarms
|= adm1026_read_value(client
, ADM1026_REG_STATUS2
);
377 alarms
|= adm1026_read_value(client
, ADM1026_REG_STATUS1
);
378 data
->alarms
= alarms
;
380 /* Read the GPIO values */
381 gpio
|= adm1026_read_value(client
,
382 ADM1026_REG_GPIO_STATUS_8_15
);
384 gpio
|= adm1026_read_value(client
,
385 ADM1026_REG_GPIO_STATUS_0_7
);
388 data
->last_reading
= jiffies
;
392 time_after(jiffies
, data
->last_config
+ ADM1026_CONFIG_INTERVAL
)) {
393 /* Things that don't change often */
394 dev_dbg(&client
->dev
, "Reading config values\n");
395 for (i
= 0; i
<= 16; ++i
) {
396 data
->in_min
[i
] = adm1026_read_value(client
,
397 ADM1026_REG_IN_MIN
[i
]);
398 data
->in_max
[i
] = adm1026_read_value(client
,
399 ADM1026_REG_IN_MAX
[i
]);
402 value
= adm1026_read_value(client
, ADM1026_REG_FAN_DIV_0_3
)
403 | (adm1026_read_value(client
, ADM1026_REG_FAN_DIV_4_7
)
405 for (i
= 0; i
<= 7; ++i
) {
406 data
->fan_min
[i
] = adm1026_read_value(client
,
407 ADM1026_REG_FAN_MIN(i
));
408 data
->fan_div
[i
] = DIV_FROM_REG(value
& 0x03);
412 for (i
= 0; i
<= 2; ++i
) {
414 * NOTE: temp_xxx[] are s8 and we assume 2's
415 * complement "conversion" in the assignment
417 data
->temp_min
[i
] = adm1026_read_value(client
,
418 ADM1026_REG_TEMP_MIN
[i
]);
419 data
->temp_max
[i
] = adm1026_read_value(client
,
420 ADM1026_REG_TEMP_MAX
[i
]);
421 data
->temp_tmin
[i
] = adm1026_read_value(client
,
422 ADM1026_REG_TEMP_TMIN
[i
]);
423 data
->temp_crit
[i
] = adm1026_read_value(client
,
424 ADM1026_REG_TEMP_THERM
[i
]);
425 data
->temp_offset
[i
] = adm1026_read_value(client
,
426 ADM1026_REG_TEMP_OFFSET
[i
]);
429 /* Read the STATUS/alarm masks */
430 alarms
= adm1026_read_value(client
, ADM1026_REG_MASK4
);
431 gpio
= alarms
& 0x80 ? 0x0100 : 0; /* GPIO16 */
432 alarms
= (alarms
& 0x7f) << 8;
433 alarms
|= adm1026_read_value(client
, ADM1026_REG_MASK3
);
435 alarms
|= adm1026_read_value(client
, ADM1026_REG_MASK2
);
437 alarms
|= adm1026_read_value(client
, ADM1026_REG_MASK1
);
438 data
->alarm_mask
= alarms
;
440 /* Read the GPIO values */
441 gpio
|= adm1026_read_value(client
,
442 ADM1026_REG_GPIO_MASK_8_15
);
444 gpio
|= adm1026_read_value(client
, ADM1026_REG_GPIO_MASK_0_7
);
445 data
->gpio_mask
= gpio
;
447 /* Read various values from CONFIG1 */
448 data
->config1
= adm1026_read_value(client
,
449 ADM1026_REG_CONFIG1
);
450 if (data
->config1
& CFG1_PWM_AFC
) {
451 data
->pwm1
.enable
= 2;
452 data
->pwm1
.auto_pwm_min
=
453 PWM_MIN_FROM_REG(data
->pwm1
.pwm
);
455 /* Read the GPIO config */
456 data
->config2
= adm1026_read_value(client
,
457 ADM1026_REG_CONFIG2
);
458 data
->config3
= adm1026_read_value(client
,
459 ADM1026_REG_CONFIG3
);
460 data
->gpio_config
[16] = (data
->config3
>> 6) & 0x03;
463 for (i
= 0; i
<= 15; ++i
) {
464 if ((i
& 0x03) == 0) {
465 value
= adm1026_read_value(client
,
466 ADM1026_REG_GPIO_CFG_0_3
+ i
/4);
468 data
->gpio_config
[i
] = value
& 0x03;
472 data
->last_config
= jiffies
;
476 mutex_unlock(&data
->update_lock
);
480 static ssize_t
in_show(struct device
*dev
, struct device_attribute
*attr
,
483 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
484 int nr
= sensor_attr
->index
;
485 struct adm1026_data
*data
= adm1026_update_device(dev
);
486 return sprintf(buf
, "%d\n", INS_FROM_REG(nr
, data
->in
[nr
]));
488 static ssize_t
in_min_show(struct device
*dev
, struct device_attribute
*attr
,
491 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
492 int nr
= sensor_attr
->index
;
493 struct adm1026_data
*data
= adm1026_update_device(dev
);
494 return sprintf(buf
, "%d\n", INS_FROM_REG(nr
, data
->in_min
[nr
]));
496 static ssize_t
in_min_store(struct device
*dev
, struct device_attribute
*attr
,
497 const char *buf
, size_t count
)
499 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
500 int nr
= sensor_attr
->index
;
501 struct adm1026_data
*data
= dev_get_drvdata(dev
);
502 struct i2c_client
*client
= data
->client
;
506 err
= kstrtol(buf
, 10, &val
);
510 mutex_lock(&data
->update_lock
);
511 data
->in_min
[nr
] = INS_TO_REG(nr
, val
);
512 adm1026_write_value(client
, ADM1026_REG_IN_MIN
[nr
], data
->in_min
[nr
]);
513 mutex_unlock(&data
->update_lock
);
516 static ssize_t
in_max_show(struct device
*dev
, struct device_attribute
*attr
,
519 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
520 int nr
= sensor_attr
->index
;
521 struct adm1026_data
*data
= adm1026_update_device(dev
);
522 return sprintf(buf
, "%d\n", INS_FROM_REG(nr
, data
->in_max
[nr
]));
524 static ssize_t
in_max_store(struct device
*dev
, struct device_attribute
*attr
,
525 const char *buf
, size_t count
)
527 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
528 int nr
= sensor_attr
->index
;
529 struct adm1026_data
*data
= dev_get_drvdata(dev
);
530 struct i2c_client
*client
= data
->client
;
534 err
= kstrtol(buf
, 10, &val
);
538 mutex_lock(&data
->update_lock
);
539 data
->in_max
[nr
] = INS_TO_REG(nr
, val
);
540 adm1026_write_value(client
, ADM1026_REG_IN_MAX
[nr
], data
->in_max
[nr
]);
541 mutex_unlock(&data
->update_lock
);
545 static SENSOR_DEVICE_ATTR_RO(in0_input
, in
, 0);
546 static SENSOR_DEVICE_ATTR_RW(in0_min
, in_min
, 0);
547 static SENSOR_DEVICE_ATTR_RW(in0_max
, in_max
, 0);
548 static SENSOR_DEVICE_ATTR_RO(in1_input
, in
, 1);
549 static SENSOR_DEVICE_ATTR_RW(in1_min
, in_min
, 1);
550 static SENSOR_DEVICE_ATTR_RW(in1_max
, in_max
, 1);
551 static SENSOR_DEVICE_ATTR_RO(in2_input
, in
, 2);
552 static SENSOR_DEVICE_ATTR_RW(in2_min
, in_min
, 2);
553 static SENSOR_DEVICE_ATTR_RW(in2_max
, in_max
, 2);
554 static SENSOR_DEVICE_ATTR_RO(in3_input
, in
, 3);
555 static SENSOR_DEVICE_ATTR_RW(in3_min
, in_min
, 3);
556 static SENSOR_DEVICE_ATTR_RW(in3_max
, in_max
, 3);
557 static SENSOR_DEVICE_ATTR_RO(in4_input
, in
, 4);
558 static SENSOR_DEVICE_ATTR_RW(in4_min
, in_min
, 4);
559 static SENSOR_DEVICE_ATTR_RW(in4_max
, in_max
, 4);
560 static SENSOR_DEVICE_ATTR_RO(in5_input
, in
, 5);
561 static SENSOR_DEVICE_ATTR_RW(in5_min
, in_min
, 5);
562 static SENSOR_DEVICE_ATTR_RW(in5_max
, in_max
, 5);
563 static SENSOR_DEVICE_ATTR_RO(in6_input
, in
, 6);
564 static SENSOR_DEVICE_ATTR_RW(in6_min
, in_min
, 6);
565 static SENSOR_DEVICE_ATTR_RW(in6_max
, in_max
, 6);
566 static SENSOR_DEVICE_ATTR_RO(in7_input
, in
, 7);
567 static SENSOR_DEVICE_ATTR_RW(in7_min
, in_min
, 7);
568 static SENSOR_DEVICE_ATTR_RW(in7_max
, in_max
, 7);
569 static SENSOR_DEVICE_ATTR_RO(in8_input
, in
, 8);
570 static SENSOR_DEVICE_ATTR_RW(in8_min
, in_min
, 8);
571 static SENSOR_DEVICE_ATTR_RW(in8_max
, in_max
, 8);
572 static SENSOR_DEVICE_ATTR_RO(in9_input
, in
, 9);
573 static SENSOR_DEVICE_ATTR_RW(in9_min
, in_min
, 9);
574 static SENSOR_DEVICE_ATTR_RW(in9_max
, in_max
, 9);
575 static SENSOR_DEVICE_ATTR_RO(in10_input
, in
, 10);
576 static SENSOR_DEVICE_ATTR_RW(in10_min
, in_min
, 10);
577 static SENSOR_DEVICE_ATTR_RW(in10_max
, in_max
, 10);
578 static SENSOR_DEVICE_ATTR_RO(in11_input
, in
, 11);
579 static SENSOR_DEVICE_ATTR_RW(in11_min
, in_min
, 11);
580 static SENSOR_DEVICE_ATTR_RW(in11_max
, in_max
, 11);
581 static SENSOR_DEVICE_ATTR_RO(in12_input
, in
, 12);
582 static SENSOR_DEVICE_ATTR_RW(in12_min
, in_min
, 12);
583 static SENSOR_DEVICE_ATTR_RW(in12_max
, in_max
, 12);
584 static SENSOR_DEVICE_ATTR_RO(in13_input
, in
, 13);
585 static SENSOR_DEVICE_ATTR_RW(in13_min
, in_min
, 13);
586 static SENSOR_DEVICE_ATTR_RW(in13_max
, in_max
, 13);
587 static SENSOR_DEVICE_ATTR_RO(in14_input
, in
, 14);
588 static SENSOR_DEVICE_ATTR_RW(in14_min
, in_min
, 14);
589 static SENSOR_DEVICE_ATTR_RW(in14_max
, in_max
, 14);
590 static SENSOR_DEVICE_ATTR_RO(in15_input
, in
, 15);
591 static SENSOR_DEVICE_ATTR_RW(in15_min
, in_min
, 15);
592 static SENSOR_DEVICE_ATTR_RW(in15_max
, in_max
, 15);
594 static ssize_t
in16_show(struct device
*dev
, struct device_attribute
*attr
,
597 struct adm1026_data
*data
= adm1026_update_device(dev
);
598 return sprintf(buf
, "%d\n", INS_FROM_REG(16, data
->in
[16]) -
601 static ssize_t
in16_min_show(struct device
*dev
,
602 struct device_attribute
*attr
, char *buf
)
604 struct adm1026_data
*data
= adm1026_update_device(dev
);
605 return sprintf(buf
, "%d\n", INS_FROM_REG(16, data
->in_min
[16])
608 static ssize_t
in16_min_store(struct device
*dev
,
609 struct device_attribute
*attr
, const char *buf
,
612 struct adm1026_data
*data
= dev_get_drvdata(dev
);
613 struct i2c_client
*client
= data
->client
;
617 err
= kstrtol(buf
, 10, &val
);
621 mutex_lock(&data
->update_lock
);
622 data
->in_min
[16] = INS_TO_REG(16,
623 clamp_val(val
, INT_MIN
,
624 INT_MAX
- NEG12_OFFSET
) +
626 adm1026_write_value(client
, ADM1026_REG_IN_MIN
[16], data
->in_min
[16]);
627 mutex_unlock(&data
->update_lock
);
630 static ssize_t
in16_max_show(struct device
*dev
,
631 struct device_attribute
*attr
, char *buf
)
633 struct adm1026_data
*data
= adm1026_update_device(dev
);
634 return sprintf(buf
, "%d\n", INS_FROM_REG(16, data
->in_max
[16])
637 static ssize_t
in16_max_store(struct device
*dev
,
638 struct device_attribute
*attr
, const char *buf
,
641 struct adm1026_data
*data
= dev_get_drvdata(dev
);
642 struct i2c_client
*client
= data
->client
;
646 err
= kstrtol(buf
, 10, &val
);
650 mutex_lock(&data
->update_lock
);
651 data
->in_max
[16] = INS_TO_REG(16,
652 clamp_val(val
, INT_MIN
,
653 INT_MAX
- NEG12_OFFSET
) +
655 adm1026_write_value(client
, ADM1026_REG_IN_MAX
[16], data
->in_max
[16]);
656 mutex_unlock(&data
->update_lock
);
660 static SENSOR_DEVICE_ATTR_RO(in16_input
, in16
, 16);
661 static SENSOR_DEVICE_ATTR_RW(in16_min
, in16_min
, 16);
662 static SENSOR_DEVICE_ATTR_RW(in16_max
, in16_max
, 16);
664 /* Now add fan read/write functions */
666 static ssize_t
fan_show(struct device
*dev
, struct device_attribute
*attr
,
669 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
670 int nr
= sensor_attr
->index
;
671 struct adm1026_data
*data
= adm1026_update_device(dev
);
672 return sprintf(buf
, "%d\n", FAN_FROM_REG(data
->fan
[nr
],
675 static ssize_t
fan_min_show(struct device
*dev
, struct device_attribute
*attr
,
678 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
679 int nr
= sensor_attr
->index
;
680 struct adm1026_data
*data
= adm1026_update_device(dev
);
681 return sprintf(buf
, "%d\n", FAN_FROM_REG(data
->fan_min
[nr
],
684 static ssize_t
fan_min_store(struct device
*dev
,
685 struct device_attribute
*attr
, const char *buf
,
688 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
689 int nr
= sensor_attr
->index
;
690 struct adm1026_data
*data
= dev_get_drvdata(dev
);
691 struct i2c_client
*client
= data
->client
;
695 err
= kstrtol(buf
, 10, &val
);
699 mutex_lock(&data
->update_lock
);
700 data
->fan_min
[nr
] = FAN_TO_REG(val
, data
->fan_div
[nr
]);
701 adm1026_write_value(client
, ADM1026_REG_FAN_MIN(nr
),
703 mutex_unlock(&data
->update_lock
);
707 static SENSOR_DEVICE_ATTR_RO(fan1_input
, fan
, 0);
708 static SENSOR_DEVICE_ATTR_RW(fan1_min
, fan_min
, 0);
709 static SENSOR_DEVICE_ATTR_RO(fan2_input
, fan
, 1);
710 static SENSOR_DEVICE_ATTR_RW(fan2_min
, fan_min
, 1);
711 static SENSOR_DEVICE_ATTR_RO(fan3_input
, fan
, 2);
712 static SENSOR_DEVICE_ATTR_RW(fan3_min
, fan_min
, 2);
713 static SENSOR_DEVICE_ATTR_RO(fan4_input
, fan
, 3);
714 static SENSOR_DEVICE_ATTR_RW(fan4_min
, fan_min
, 3);
715 static SENSOR_DEVICE_ATTR_RO(fan5_input
, fan
, 4);
716 static SENSOR_DEVICE_ATTR_RW(fan5_min
, fan_min
, 4);
717 static SENSOR_DEVICE_ATTR_RO(fan6_input
, fan
, 5);
718 static SENSOR_DEVICE_ATTR_RW(fan6_min
, fan_min
, 5);
719 static SENSOR_DEVICE_ATTR_RO(fan7_input
, fan
, 6);
720 static SENSOR_DEVICE_ATTR_RW(fan7_min
, fan_min
, 6);
721 static SENSOR_DEVICE_ATTR_RO(fan8_input
, fan
, 7);
722 static SENSOR_DEVICE_ATTR_RW(fan8_min
, fan_min
, 7);
724 /* Adjust fan_min to account for new fan divisor */
725 static void fixup_fan_min(struct device
*dev
, int fan
, int old_div
)
727 struct adm1026_data
*data
= dev_get_drvdata(dev
);
728 struct i2c_client
*client
= data
->client
;
730 int new_div
= data
->fan_div
[fan
];
732 /* 0 and 0xff are special. Don't adjust them */
733 if (data
->fan_min
[fan
] == 0 || data
->fan_min
[fan
] == 0xff)
736 new_min
= data
->fan_min
[fan
] * old_div
/ new_div
;
737 new_min
= clamp_val(new_min
, 1, 254);
738 data
->fan_min
[fan
] = new_min
;
739 adm1026_write_value(client
, ADM1026_REG_FAN_MIN(fan
), new_min
);
742 /* Now add fan_div read/write functions */
743 static ssize_t
fan_div_show(struct device
*dev
, struct device_attribute
*attr
,
746 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
747 int nr
= sensor_attr
->index
;
748 struct adm1026_data
*data
= adm1026_update_device(dev
);
749 return sprintf(buf
, "%d\n", data
->fan_div
[nr
]);
751 static ssize_t
fan_div_store(struct device
*dev
,
752 struct device_attribute
*attr
, const char *buf
,
755 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
756 int nr
= sensor_attr
->index
;
757 struct adm1026_data
*data
= dev_get_drvdata(dev
);
758 struct i2c_client
*client
= data
->client
;
760 int orig_div
, new_div
;
763 err
= kstrtol(buf
, 10, &val
);
767 new_div
= DIV_TO_REG(val
);
769 mutex_lock(&data
->update_lock
);
770 orig_div
= data
->fan_div
[nr
];
771 data
->fan_div
[nr
] = DIV_FROM_REG(new_div
);
773 if (nr
< 4) { /* 0 <= nr < 4 */
774 adm1026_write_value(client
, ADM1026_REG_FAN_DIV_0_3
,
775 (DIV_TO_REG(data
->fan_div
[0]) << 0) |
776 (DIV_TO_REG(data
->fan_div
[1]) << 2) |
777 (DIV_TO_REG(data
->fan_div
[2]) << 4) |
778 (DIV_TO_REG(data
->fan_div
[3]) << 6));
779 } else { /* 3 < nr < 8 */
780 adm1026_write_value(client
, ADM1026_REG_FAN_DIV_4_7
,
781 (DIV_TO_REG(data
->fan_div
[4]) << 0) |
782 (DIV_TO_REG(data
->fan_div
[5]) << 2) |
783 (DIV_TO_REG(data
->fan_div
[6]) << 4) |
784 (DIV_TO_REG(data
->fan_div
[7]) << 6));
787 if (data
->fan_div
[nr
] != orig_div
)
788 fixup_fan_min(dev
, nr
, orig_div
);
790 mutex_unlock(&data
->update_lock
);
794 static SENSOR_DEVICE_ATTR_RW(fan1_div
, fan_div
, 0);
795 static SENSOR_DEVICE_ATTR_RW(fan2_div
, fan_div
, 1);
796 static SENSOR_DEVICE_ATTR_RW(fan3_div
, fan_div
, 2);
797 static SENSOR_DEVICE_ATTR_RW(fan4_div
, fan_div
, 3);
798 static SENSOR_DEVICE_ATTR_RW(fan5_div
, fan_div
, 4);
799 static SENSOR_DEVICE_ATTR_RW(fan6_div
, fan_div
, 5);
800 static SENSOR_DEVICE_ATTR_RW(fan7_div
, fan_div
, 6);
801 static SENSOR_DEVICE_ATTR_RW(fan8_div
, fan_div
, 7);
804 static ssize_t
temp_show(struct device
*dev
, struct device_attribute
*attr
,
807 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
808 int nr
= sensor_attr
->index
;
809 struct adm1026_data
*data
= adm1026_update_device(dev
);
810 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
]));
812 static ssize_t
temp_min_show(struct device
*dev
,
813 struct device_attribute
*attr
, char *buf
)
815 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
816 int nr
= sensor_attr
->index
;
817 struct adm1026_data
*data
= adm1026_update_device(dev
);
818 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_min
[nr
]));
820 static ssize_t
temp_min_store(struct device
*dev
,
821 struct device_attribute
*attr
, const char *buf
,
824 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
825 int nr
= sensor_attr
->index
;
826 struct adm1026_data
*data
= dev_get_drvdata(dev
);
827 struct i2c_client
*client
= data
->client
;
831 err
= kstrtol(buf
, 10, &val
);
835 mutex_lock(&data
->update_lock
);
836 data
->temp_min
[nr
] = TEMP_TO_REG(val
);
837 adm1026_write_value(client
, ADM1026_REG_TEMP_MIN
[nr
],
839 mutex_unlock(&data
->update_lock
);
842 static ssize_t
temp_max_show(struct device
*dev
,
843 struct device_attribute
*attr
, char *buf
)
845 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
846 int nr
= sensor_attr
->index
;
847 struct adm1026_data
*data
= adm1026_update_device(dev
);
848 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_max
[nr
]));
850 static ssize_t
temp_max_store(struct device
*dev
,
851 struct device_attribute
*attr
, const char *buf
,
854 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
855 int nr
= sensor_attr
->index
;
856 struct adm1026_data
*data
= dev_get_drvdata(dev
);
857 struct i2c_client
*client
= data
->client
;
861 err
= kstrtol(buf
, 10, &val
);
865 mutex_lock(&data
->update_lock
);
866 data
->temp_max
[nr
] = TEMP_TO_REG(val
);
867 adm1026_write_value(client
, ADM1026_REG_TEMP_MAX
[nr
],
869 mutex_unlock(&data
->update_lock
);
873 static SENSOR_DEVICE_ATTR_RO(temp1_input
, temp
, 0);
874 static SENSOR_DEVICE_ATTR_RW(temp1_min
, temp_min
, 0);
875 static SENSOR_DEVICE_ATTR_RW(temp1_max
, temp_max
, 0);
876 static SENSOR_DEVICE_ATTR_RO(temp2_input
, temp
, 1);
877 static SENSOR_DEVICE_ATTR_RW(temp2_min
, temp_min
, 1);
878 static SENSOR_DEVICE_ATTR_RW(temp2_max
, temp_max
, 1);
879 static SENSOR_DEVICE_ATTR_RO(temp3_input
, temp
, 2);
880 static SENSOR_DEVICE_ATTR_RW(temp3_min
, temp_min
, 2);
881 static SENSOR_DEVICE_ATTR_RW(temp3_max
, temp_max
, 2);
883 static ssize_t
temp_offset_show(struct device
*dev
,
884 struct device_attribute
*attr
, char *buf
)
886 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
887 int nr
= sensor_attr
->index
;
888 struct adm1026_data
*data
= adm1026_update_device(dev
);
889 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_offset
[nr
]));
891 static ssize_t
temp_offset_store(struct device
*dev
,
892 struct device_attribute
*attr
,
893 const char *buf
, size_t count
)
895 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
896 int nr
= sensor_attr
->index
;
897 struct adm1026_data
*data
= dev_get_drvdata(dev
);
898 struct i2c_client
*client
= data
->client
;
902 err
= kstrtol(buf
, 10, &val
);
906 mutex_lock(&data
->update_lock
);
907 data
->temp_offset
[nr
] = TEMP_TO_REG(val
);
908 adm1026_write_value(client
, ADM1026_REG_TEMP_OFFSET
[nr
],
909 data
->temp_offset
[nr
]);
910 mutex_unlock(&data
->update_lock
);
914 static SENSOR_DEVICE_ATTR_RW(temp1_offset
, temp_offset
, 0);
915 static SENSOR_DEVICE_ATTR_RW(temp2_offset
, temp_offset
, 1);
916 static SENSOR_DEVICE_ATTR_RW(temp3_offset
, temp_offset
, 2);
918 static ssize_t
temp_auto_point1_temp_hyst_show(struct device
*dev
,
919 struct device_attribute
*attr
,
922 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
923 int nr
= sensor_attr
->index
;
924 struct adm1026_data
*data
= adm1026_update_device(dev
);
925 return sprintf(buf
, "%d\n", TEMP_FROM_REG(
926 ADM1026_FAN_ACTIVATION_TEMP_HYST
+ data
->temp_tmin
[nr
]));
928 static ssize_t
temp_auto_point2_temp_show(struct device
*dev
,
929 struct device_attribute
*attr
,
932 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
933 int nr
= sensor_attr
->index
;
934 struct adm1026_data
*data
= adm1026_update_device(dev
);
935 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_tmin
[nr
] +
936 ADM1026_FAN_CONTROL_TEMP_RANGE
));
938 static ssize_t
temp_auto_point1_temp_show(struct device
*dev
,
939 struct device_attribute
*attr
,
942 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
943 int nr
= sensor_attr
->index
;
944 struct adm1026_data
*data
= adm1026_update_device(dev
);
945 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_tmin
[nr
]));
947 static ssize_t
temp_auto_point1_temp_store(struct device
*dev
,
948 struct device_attribute
*attr
,
949 const char *buf
, size_t count
)
951 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
952 int nr
= sensor_attr
->index
;
953 struct adm1026_data
*data
= dev_get_drvdata(dev
);
954 struct i2c_client
*client
= data
->client
;
958 err
= kstrtol(buf
, 10, &val
);
962 mutex_lock(&data
->update_lock
);
963 data
->temp_tmin
[nr
] = TEMP_TO_REG(val
);
964 adm1026_write_value(client
, ADM1026_REG_TEMP_TMIN
[nr
],
965 data
->temp_tmin
[nr
]);
966 mutex_unlock(&data
->update_lock
);
970 static SENSOR_DEVICE_ATTR_RW(temp1_auto_point1_temp
, temp_auto_point1_temp
, 0);
971 static SENSOR_DEVICE_ATTR_RO(temp1_auto_point1_temp_hyst
,
972 temp_auto_point1_temp_hyst
, 0);
973 static SENSOR_DEVICE_ATTR_RO(temp1_auto_point2_temp
, temp_auto_point2_temp
, 0);
974 static SENSOR_DEVICE_ATTR_RW(temp2_auto_point1_temp
, temp_auto_point1_temp
, 1);
975 static SENSOR_DEVICE_ATTR_RO(temp2_auto_point1_temp_hyst
,
976 temp_auto_point1_temp_hyst
, 1);
977 static SENSOR_DEVICE_ATTR_RO(temp2_auto_point2_temp
, temp_auto_point2_temp
, 1);
978 static SENSOR_DEVICE_ATTR_RW(temp3_auto_point1_temp
, temp_auto_point1_temp
, 2);
979 static SENSOR_DEVICE_ATTR_RO(temp3_auto_point1_temp_hyst
,
980 temp_auto_point1_temp_hyst
, 2);
981 static SENSOR_DEVICE_ATTR_RO(temp3_auto_point2_temp
, temp_auto_point2_temp
, 2);
983 static ssize_t
show_temp_crit_enable(struct device
*dev
,
984 struct device_attribute
*attr
, char *buf
)
986 struct adm1026_data
*data
= adm1026_update_device(dev
);
987 return sprintf(buf
, "%d\n", (data
->config1
& CFG1_THERM_HOT
) >> 4);
989 static ssize_t
set_temp_crit_enable(struct device
*dev
,
990 struct device_attribute
*attr
, const char *buf
, size_t count
)
992 struct adm1026_data
*data
= dev_get_drvdata(dev
);
993 struct i2c_client
*client
= data
->client
;
997 err
= kstrtoul(buf
, 10, &val
);
1004 mutex_lock(&data
->update_lock
);
1005 data
->config1
= (data
->config1
& ~CFG1_THERM_HOT
) | (val
<< 4);
1006 adm1026_write_value(client
, ADM1026_REG_CONFIG1
, data
->config1
);
1007 mutex_unlock(&data
->update_lock
);
1012 static DEVICE_ATTR(temp1_crit_enable
, 0644, show_temp_crit_enable
,
1013 set_temp_crit_enable
);
1014 static DEVICE_ATTR(temp2_crit_enable
, 0644, show_temp_crit_enable
,
1015 set_temp_crit_enable
);
1016 static DEVICE_ATTR(temp3_crit_enable
, 0644, show_temp_crit_enable
,
1017 set_temp_crit_enable
);
1019 static ssize_t
temp_crit_show(struct device
*dev
,
1020 struct device_attribute
*attr
, char *buf
)
1022 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
1023 int nr
= sensor_attr
->index
;
1024 struct adm1026_data
*data
= adm1026_update_device(dev
);
1025 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_crit
[nr
]));
1027 static ssize_t
temp_crit_store(struct device
*dev
,
1028 struct device_attribute
*attr
, const char *buf
,
1031 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
1032 int nr
= sensor_attr
->index
;
1033 struct adm1026_data
*data
= dev_get_drvdata(dev
);
1034 struct i2c_client
*client
= data
->client
;
1038 err
= kstrtol(buf
, 10, &val
);
1042 mutex_lock(&data
->update_lock
);
1043 data
->temp_crit
[nr
] = TEMP_TO_REG(val
);
1044 adm1026_write_value(client
, ADM1026_REG_TEMP_THERM
[nr
],
1045 data
->temp_crit
[nr
]);
1046 mutex_unlock(&data
->update_lock
);
1050 static SENSOR_DEVICE_ATTR_RW(temp1_crit
, temp_crit
, 0);
1051 static SENSOR_DEVICE_ATTR_RW(temp2_crit
, temp_crit
, 1);
1052 static SENSOR_DEVICE_ATTR_RW(temp3_crit
, temp_crit
, 2);
1054 static ssize_t
analog_out_show(struct device
*dev
,
1055 struct device_attribute
*attr
, char *buf
)
1057 struct adm1026_data
*data
= adm1026_update_device(dev
);
1058 return sprintf(buf
, "%d\n", DAC_FROM_REG(data
->analog_out
));
1060 static ssize_t
analog_out_store(struct device
*dev
,
1061 struct device_attribute
*attr
,
1062 const char *buf
, size_t count
)
1064 struct adm1026_data
*data
= dev_get_drvdata(dev
);
1065 struct i2c_client
*client
= data
->client
;
1069 err
= kstrtol(buf
, 10, &val
);
1073 mutex_lock(&data
->update_lock
);
1074 data
->analog_out
= DAC_TO_REG(val
);
1075 adm1026_write_value(client
, ADM1026_REG_DAC
, data
->analog_out
);
1076 mutex_unlock(&data
->update_lock
);
1080 static DEVICE_ATTR_RW(analog_out
);
1082 static ssize_t
cpu0_vid_show(struct device
*dev
,
1083 struct device_attribute
*attr
, char *buf
)
1085 struct adm1026_data
*data
= adm1026_update_device(dev
);
1086 int vid
= (data
->gpio
>> 11) & 0x1f;
1088 dev_dbg(dev
, "Setting VID from GPIO11-15.\n");
1089 return sprintf(buf
, "%d\n", vid_from_reg(vid
, data
->vrm
));
1092 static DEVICE_ATTR_RO(cpu0_vid
);
1094 static ssize_t
vrm_show(struct device
*dev
, struct device_attribute
*attr
,
1097 struct adm1026_data
*data
= dev_get_drvdata(dev
);
1098 return sprintf(buf
, "%d\n", data
->vrm
);
1101 static ssize_t
vrm_store(struct device
*dev
, struct device_attribute
*attr
,
1102 const char *buf
, size_t count
)
1104 struct adm1026_data
*data
= dev_get_drvdata(dev
);
1108 err
= kstrtoul(buf
, 10, &val
);
1119 static DEVICE_ATTR_RW(vrm
);
1121 static ssize_t
alarms_show(struct device
*dev
, struct device_attribute
*attr
,
1124 struct adm1026_data
*data
= adm1026_update_device(dev
);
1125 return sprintf(buf
, "%ld\n", data
->alarms
);
1128 static DEVICE_ATTR_RO(alarms
);
1130 static ssize_t
alarm_show(struct device
*dev
, struct device_attribute
*attr
,
1133 struct adm1026_data
*data
= adm1026_update_device(dev
);
1134 int bitnr
= to_sensor_dev_attr(attr
)->index
;
1135 return sprintf(buf
, "%ld\n", (data
->alarms
>> bitnr
) & 1);
1138 static SENSOR_DEVICE_ATTR_RO(temp2_alarm
, alarm
, 0);
1139 static SENSOR_DEVICE_ATTR_RO(temp3_alarm
, alarm
, 1);
1140 static SENSOR_DEVICE_ATTR_RO(in9_alarm
, alarm
, 1);
1141 static SENSOR_DEVICE_ATTR_RO(in11_alarm
, alarm
, 2);
1142 static SENSOR_DEVICE_ATTR_RO(in12_alarm
, alarm
, 3);
1143 static SENSOR_DEVICE_ATTR_RO(in13_alarm
, alarm
, 4);
1144 static SENSOR_DEVICE_ATTR_RO(in14_alarm
, alarm
, 5);
1145 static SENSOR_DEVICE_ATTR_RO(in15_alarm
, alarm
, 6);
1146 static SENSOR_DEVICE_ATTR_RO(in16_alarm
, alarm
, 7);
1147 static SENSOR_DEVICE_ATTR_RO(in0_alarm
, alarm
, 8);
1148 static SENSOR_DEVICE_ATTR_RO(in1_alarm
, alarm
, 9);
1149 static SENSOR_DEVICE_ATTR_RO(in2_alarm
, alarm
, 10);
1150 static SENSOR_DEVICE_ATTR_RO(in3_alarm
, alarm
, 11);
1151 static SENSOR_DEVICE_ATTR_RO(in4_alarm
, alarm
, 12);
1152 static SENSOR_DEVICE_ATTR_RO(in5_alarm
, alarm
, 13);
1153 static SENSOR_DEVICE_ATTR_RO(in6_alarm
, alarm
, 14);
1154 static SENSOR_DEVICE_ATTR_RO(in7_alarm
, alarm
, 15);
1155 static SENSOR_DEVICE_ATTR_RO(fan1_alarm
, alarm
, 16);
1156 static SENSOR_DEVICE_ATTR_RO(fan2_alarm
, alarm
, 17);
1157 static SENSOR_DEVICE_ATTR_RO(fan3_alarm
, alarm
, 18);
1158 static SENSOR_DEVICE_ATTR_RO(fan4_alarm
, alarm
, 19);
1159 static SENSOR_DEVICE_ATTR_RO(fan5_alarm
, alarm
, 20);
1160 static SENSOR_DEVICE_ATTR_RO(fan6_alarm
, alarm
, 21);
1161 static SENSOR_DEVICE_ATTR_RO(fan7_alarm
, alarm
, 22);
1162 static SENSOR_DEVICE_ATTR_RO(fan8_alarm
, alarm
, 23);
1163 static SENSOR_DEVICE_ATTR_RO(temp1_alarm
, alarm
, 24);
1164 static SENSOR_DEVICE_ATTR_RO(in10_alarm
, alarm
, 25);
1165 static SENSOR_DEVICE_ATTR_RO(in8_alarm
, alarm
, 26);
1167 static ssize_t
alarm_mask_show(struct device
*dev
,
1168 struct device_attribute
*attr
, char *buf
)
1170 struct adm1026_data
*data
= adm1026_update_device(dev
);
1171 return sprintf(buf
, "%ld\n", data
->alarm_mask
);
1173 static ssize_t
alarm_mask_store(struct device
*dev
,
1174 struct device_attribute
*attr
,
1175 const char *buf
, size_t count
)
1177 struct adm1026_data
*data
= dev_get_drvdata(dev
);
1178 struct i2c_client
*client
= data
->client
;
1183 err
= kstrtol(buf
, 10, &val
);
1187 mutex_lock(&data
->update_lock
);
1188 data
->alarm_mask
= val
& 0x7fffffff;
1189 mask
= data
->alarm_mask
1190 | (data
->gpio_mask
& 0x10000 ? 0x80000000 : 0);
1191 adm1026_write_value(client
, ADM1026_REG_MASK1
,
1194 adm1026_write_value(client
, ADM1026_REG_MASK2
,
1197 adm1026_write_value(client
, ADM1026_REG_MASK3
,
1200 adm1026_write_value(client
, ADM1026_REG_MASK4
,
1202 mutex_unlock(&data
->update_lock
);
1206 static DEVICE_ATTR_RW(alarm_mask
);
1208 static ssize_t
gpio_show(struct device
*dev
, struct device_attribute
*attr
,
1211 struct adm1026_data
*data
= adm1026_update_device(dev
);
1212 return sprintf(buf
, "%ld\n", data
->gpio
);
1214 static ssize_t
gpio_store(struct device
*dev
, struct device_attribute
*attr
,
1215 const char *buf
, size_t count
)
1217 struct adm1026_data
*data
= dev_get_drvdata(dev
);
1218 struct i2c_client
*client
= data
->client
;
1223 err
= kstrtol(buf
, 10, &val
);
1227 mutex_lock(&data
->update_lock
);
1228 data
->gpio
= val
& 0x1ffff;
1230 adm1026_write_value(client
, ADM1026_REG_GPIO_STATUS_0_7
, gpio
& 0xff);
1232 adm1026_write_value(client
, ADM1026_REG_GPIO_STATUS_8_15
, gpio
& 0xff);
1233 gpio
= ((gpio
>> 1) & 0x80) | (data
->alarms
>> 24 & 0x7f);
1234 adm1026_write_value(client
, ADM1026_REG_STATUS4
, gpio
& 0xff);
1235 mutex_unlock(&data
->update_lock
);
1239 static DEVICE_ATTR_RW(gpio
);
1241 static ssize_t
gpio_mask_show(struct device
*dev
,
1242 struct device_attribute
*attr
,
1245 struct adm1026_data
*data
= adm1026_update_device(dev
);
1246 return sprintf(buf
, "%ld\n", data
->gpio_mask
);
1248 static ssize_t
gpio_mask_store(struct device
*dev
,
1249 struct device_attribute
*attr
, const char *buf
,
1252 struct adm1026_data
*data
= dev_get_drvdata(dev
);
1253 struct i2c_client
*client
= data
->client
;
1258 err
= kstrtol(buf
, 10, &val
);
1262 mutex_lock(&data
->update_lock
);
1263 data
->gpio_mask
= val
& 0x1ffff;
1264 mask
= data
->gpio_mask
;
1265 adm1026_write_value(client
, ADM1026_REG_GPIO_MASK_0_7
, mask
& 0xff);
1267 adm1026_write_value(client
, ADM1026_REG_GPIO_MASK_8_15
, mask
& 0xff);
1268 mask
= ((mask
>> 1) & 0x80) | (data
->alarm_mask
>> 24 & 0x7f);
1269 adm1026_write_value(client
, ADM1026_REG_MASK1
, mask
& 0xff);
1270 mutex_unlock(&data
->update_lock
);
1274 static DEVICE_ATTR_RW(gpio_mask
);
1276 static ssize_t
pwm1_show(struct device
*dev
, struct device_attribute
*attr
,
1279 struct adm1026_data
*data
= adm1026_update_device(dev
);
1280 return sprintf(buf
, "%d\n", PWM_FROM_REG(data
->pwm1
.pwm
));
1283 static ssize_t
pwm1_store(struct device
*dev
, struct device_attribute
*attr
,
1284 const char *buf
, size_t count
)
1286 struct adm1026_data
*data
= dev_get_drvdata(dev
);
1287 struct i2c_client
*client
= data
->client
;
1289 if (data
->pwm1
.enable
== 1) {
1293 err
= kstrtol(buf
, 10, &val
);
1297 mutex_lock(&data
->update_lock
);
1298 data
->pwm1
.pwm
= PWM_TO_REG(val
);
1299 adm1026_write_value(client
, ADM1026_REG_PWM
, data
->pwm1
.pwm
);
1300 mutex_unlock(&data
->update_lock
);
1305 static ssize_t
temp1_auto_point1_pwm_show(struct device
*dev
,
1306 struct device_attribute
*attr
,
1309 struct adm1026_data
*data
= adm1026_update_device(dev
);
1310 return sprintf(buf
, "%d\n", data
->pwm1
.auto_pwm_min
);
1313 static ssize_t
temp1_auto_point1_pwm_store(struct device
*dev
,
1314 struct device_attribute
*attr
,
1315 const char *buf
, size_t count
)
1317 struct adm1026_data
*data
= dev_get_drvdata(dev
);
1318 struct i2c_client
*client
= data
->client
;
1322 err
= kstrtoul(buf
, 10, &val
);
1326 mutex_lock(&data
->update_lock
);
1327 data
->pwm1
.auto_pwm_min
= clamp_val(val
, 0, 255);
1328 if (data
->pwm1
.enable
== 2) { /* apply immediately */
1329 data
->pwm1
.pwm
= PWM_TO_REG((data
->pwm1
.pwm
& 0x0f) |
1330 PWM_MIN_TO_REG(data
->pwm1
.auto_pwm_min
));
1331 adm1026_write_value(client
, ADM1026_REG_PWM
, data
->pwm1
.pwm
);
1333 mutex_unlock(&data
->update_lock
);
1337 static ssize_t
temp1_auto_point2_pwm_show(struct device
*dev
,
1338 struct device_attribute
*attr
,
1341 return sprintf(buf
, "%d\n", ADM1026_PWM_MAX
);
1344 static ssize_t
pwm1_enable_show(struct device
*dev
,
1345 struct device_attribute
*attr
, char *buf
)
1347 struct adm1026_data
*data
= adm1026_update_device(dev
);
1348 return sprintf(buf
, "%d\n", data
->pwm1
.enable
);
1351 static ssize_t
pwm1_enable_store(struct device
*dev
,
1352 struct device_attribute
*attr
,
1353 const char *buf
, size_t count
)
1355 struct adm1026_data
*data
= dev_get_drvdata(dev
);
1356 struct i2c_client
*client
= data
->client
;
1361 err
= kstrtoul(buf
, 10, &val
);
1368 mutex_lock(&data
->update_lock
);
1369 old_enable
= data
->pwm1
.enable
;
1370 data
->pwm1
.enable
= val
;
1371 data
->config1
= (data
->config1
& ~CFG1_PWM_AFC
)
1372 | ((val
== 2) ? CFG1_PWM_AFC
: 0);
1373 adm1026_write_value(client
, ADM1026_REG_CONFIG1
, data
->config1
);
1374 if (val
== 2) { /* apply pwm1_auto_pwm_min to pwm1 */
1375 data
->pwm1
.pwm
= PWM_TO_REG((data
->pwm1
.pwm
& 0x0f) |
1376 PWM_MIN_TO_REG(data
->pwm1
.auto_pwm_min
));
1377 adm1026_write_value(client
, ADM1026_REG_PWM
, data
->pwm1
.pwm
);
1378 } else if (!((old_enable
== 1) && (val
== 1))) {
1379 /* set pwm to safe value */
1380 data
->pwm1
.pwm
= 255;
1381 adm1026_write_value(client
, ADM1026_REG_PWM
, data
->pwm1
.pwm
);
1383 mutex_unlock(&data
->update_lock
);
1388 /* enable PWM fan control */
1389 static DEVICE_ATTR_RW(pwm1
);
1390 static DEVICE_ATTR(pwm2
, 0644, pwm1_show
, pwm1_store
);
1391 static DEVICE_ATTR(pwm3
, 0644, pwm1_show
, pwm1_store
);
1392 static DEVICE_ATTR_RW(pwm1_enable
);
1393 static DEVICE_ATTR(pwm2_enable
, 0644, pwm1_enable_show
,
1395 static DEVICE_ATTR(pwm3_enable
, 0644, pwm1_enable_show
,
1397 static DEVICE_ATTR_RW(temp1_auto_point1_pwm
);
1398 static DEVICE_ATTR(temp2_auto_point1_pwm
, 0644,
1399 temp1_auto_point1_pwm_show
, temp1_auto_point1_pwm_store
);
1400 static DEVICE_ATTR(temp3_auto_point1_pwm
, 0644,
1401 temp1_auto_point1_pwm_show
, temp1_auto_point1_pwm_store
);
1403 static DEVICE_ATTR_RO(temp1_auto_point2_pwm
);
1404 static DEVICE_ATTR(temp2_auto_point2_pwm
, 0444, temp1_auto_point2_pwm_show
,
1406 static DEVICE_ATTR(temp3_auto_point2_pwm
, 0444, temp1_auto_point2_pwm_show
,
1409 static struct attribute
*adm1026_attributes
[] = {
1410 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
1411 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
1412 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
1413 &sensor_dev_attr_in0_alarm
.dev_attr
.attr
,
1414 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
1415 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
1416 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
1417 &sensor_dev_attr_in1_alarm
.dev_attr
.attr
,
1418 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
1419 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
1420 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
1421 &sensor_dev_attr_in2_alarm
.dev_attr
.attr
,
1422 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
1423 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
1424 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
1425 &sensor_dev_attr_in3_alarm
.dev_attr
.attr
,
1426 &sensor_dev_attr_in4_input
.dev_attr
.attr
,
1427 &sensor_dev_attr_in4_max
.dev_attr
.attr
,
1428 &sensor_dev_attr_in4_min
.dev_attr
.attr
,
1429 &sensor_dev_attr_in4_alarm
.dev_attr
.attr
,
1430 &sensor_dev_attr_in5_input
.dev_attr
.attr
,
1431 &sensor_dev_attr_in5_max
.dev_attr
.attr
,
1432 &sensor_dev_attr_in5_min
.dev_attr
.attr
,
1433 &sensor_dev_attr_in5_alarm
.dev_attr
.attr
,
1434 &sensor_dev_attr_in6_input
.dev_attr
.attr
,
1435 &sensor_dev_attr_in6_max
.dev_attr
.attr
,
1436 &sensor_dev_attr_in6_min
.dev_attr
.attr
,
1437 &sensor_dev_attr_in6_alarm
.dev_attr
.attr
,
1438 &sensor_dev_attr_in7_input
.dev_attr
.attr
,
1439 &sensor_dev_attr_in7_max
.dev_attr
.attr
,
1440 &sensor_dev_attr_in7_min
.dev_attr
.attr
,
1441 &sensor_dev_attr_in7_alarm
.dev_attr
.attr
,
1442 &sensor_dev_attr_in10_input
.dev_attr
.attr
,
1443 &sensor_dev_attr_in10_max
.dev_attr
.attr
,
1444 &sensor_dev_attr_in10_min
.dev_attr
.attr
,
1445 &sensor_dev_attr_in10_alarm
.dev_attr
.attr
,
1446 &sensor_dev_attr_in11_input
.dev_attr
.attr
,
1447 &sensor_dev_attr_in11_max
.dev_attr
.attr
,
1448 &sensor_dev_attr_in11_min
.dev_attr
.attr
,
1449 &sensor_dev_attr_in11_alarm
.dev_attr
.attr
,
1450 &sensor_dev_attr_in12_input
.dev_attr
.attr
,
1451 &sensor_dev_attr_in12_max
.dev_attr
.attr
,
1452 &sensor_dev_attr_in12_min
.dev_attr
.attr
,
1453 &sensor_dev_attr_in12_alarm
.dev_attr
.attr
,
1454 &sensor_dev_attr_in13_input
.dev_attr
.attr
,
1455 &sensor_dev_attr_in13_max
.dev_attr
.attr
,
1456 &sensor_dev_attr_in13_min
.dev_attr
.attr
,
1457 &sensor_dev_attr_in13_alarm
.dev_attr
.attr
,
1458 &sensor_dev_attr_in14_input
.dev_attr
.attr
,
1459 &sensor_dev_attr_in14_max
.dev_attr
.attr
,
1460 &sensor_dev_attr_in14_min
.dev_attr
.attr
,
1461 &sensor_dev_attr_in14_alarm
.dev_attr
.attr
,
1462 &sensor_dev_attr_in15_input
.dev_attr
.attr
,
1463 &sensor_dev_attr_in15_max
.dev_attr
.attr
,
1464 &sensor_dev_attr_in15_min
.dev_attr
.attr
,
1465 &sensor_dev_attr_in15_alarm
.dev_attr
.attr
,
1466 &sensor_dev_attr_in16_input
.dev_attr
.attr
,
1467 &sensor_dev_attr_in16_max
.dev_attr
.attr
,
1468 &sensor_dev_attr_in16_min
.dev_attr
.attr
,
1469 &sensor_dev_attr_in16_alarm
.dev_attr
.attr
,
1470 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
1471 &sensor_dev_attr_fan1_div
.dev_attr
.attr
,
1472 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
1473 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
1474 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
1475 &sensor_dev_attr_fan2_div
.dev_attr
.attr
,
1476 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
1477 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
1478 &sensor_dev_attr_fan3_input
.dev_attr
.attr
,
1479 &sensor_dev_attr_fan3_div
.dev_attr
.attr
,
1480 &sensor_dev_attr_fan3_min
.dev_attr
.attr
,
1481 &sensor_dev_attr_fan3_alarm
.dev_attr
.attr
,
1482 &sensor_dev_attr_fan4_input
.dev_attr
.attr
,
1483 &sensor_dev_attr_fan4_div
.dev_attr
.attr
,
1484 &sensor_dev_attr_fan4_min
.dev_attr
.attr
,
1485 &sensor_dev_attr_fan4_alarm
.dev_attr
.attr
,
1486 &sensor_dev_attr_fan5_input
.dev_attr
.attr
,
1487 &sensor_dev_attr_fan5_div
.dev_attr
.attr
,
1488 &sensor_dev_attr_fan5_min
.dev_attr
.attr
,
1489 &sensor_dev_attr_fan5_alarm
.dev_attr
.attr
,
1490 &sensor_dev_attr_fan6_input
.dev_attr
.attr
,
1491 &sensor_dev_attr_fan6_div
.dev_attr
.attr
,
1492 &sensor_dev_attr_fan6_min
.dev_attr
.attr
,
1493 &sensor_dev_attr_fan6_alarm
.dev_attr
.attr
,
1494 &sensor_dev_attr_fan7_input
.dev_attr
.attr
,
1495 &sensor_dev_attr_fan7_div
.dev_attr
.attr
,
1496 &sensor_dev_attr_fan7_min
.dev_attr
.attr
,
1497 &sensor_dev_attr_fan7_alarm
.dev_attr
.attr
,
1498 &sensor_dev_attr_fan8_input
.dev_attr
.attr
,
1499 &sensor_dev_attr_fan8_div
.dev_attr
.attr
,
1500 &sensor_dev_attr_fan8_min
.dev_attr
.attr
,
1501 &sensor_dev_attr_fan8_alarm
.dev_attr
.attr
,
1502 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
1503 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
1504 &sensor_dev_attr_temp1_min
.dev_attr
.attr
,
1505 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
1506 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
1507 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
1508 &sensor_dev_attr_temp2_min
.dev_attr
.attr
,
1509 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
1510 &sensor_dev_attr_temp1_offset
.dev_attr
.attr
,
1511 &sensor_dev_attr_temp2_offset
.dev_attr
.attr
,
1512 &sensor_dev_attr_temp1_auto_point1_temp
.dev_attr
.attr
,
1513 &sensor_dev_attr_temp2_auto_point1_temp
.dev_attr
.attr
,
1514 &sensor_dev_attr_temp1_auto_point1_temp_hyst
.dev_attr
.attr
,
1515 &sensor_dev_attr_temp2_auto_point1_temp_hyst
.dev_attr
.attr
,
1516 &sensor_dev_attr_temp1_auto_point2_temp
.dev_attr
.attr
,
1517 &sensor_dev_attr_temp2_auto_point2_temp
.dev_attr
.attr
,
1518 &sensor_dev_attr_temp1_crit
.dev_attr
.attr
,
1519 &sensor_dev_attr_temp2_crit
.dev_attr
.attr
,
1520 &dev_attr_temp1_crit_enable
.attr
,
1521 &dev_attr_temp2_crit_enable
.attr
,
1522 &dev_attr_cpu0_vid
.attr
,
1524 &dev_attr_alarms
.attr
,
1525 &dev_attr_alarm_mask
.attr
,
1526 &dev_attr_gpio
.attr
,
1527 &dev_attr_gpio_mask
.attr
,
1528 &dev_attr_pwm1
.attr
,
1529 &dev_attr_pwm2
.attr
,
1530 &dev_attr_pwm3
.attr
,
1531 &dev_attr_pwm1_enable
.attr
,
1532 &dev_attr_pwm2_enable
.attr
,
1533 &dev_attr_pwm3_enable
.attr
,
1534 &dev_attr_temp1_auto_point1_pwm
.attr
,
1535 &dev_attr_temp2_auto_point1_pwm
.attr
,
1536 &dev_attr_temp1_auto_point2_pwm
.attr
,
1537 &dev_attr_temp2_auto_point2_pwm
.attr
,
1538 &dev_attr_analog_out
.attr
,
1542 static const struct attribute_group adm1026_group
= {
1543 .attrs
= adm1026_attributes
,
1546 static struct attribute
*adm1026_attributes_temp3
[] = {
1547 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
1548 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
1549 &sensor_dev_attr_temp3_min
.dev_attr
.attr
,
1550 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
1551 &sensor_dev_attr_temp3_offset
.dev_attr
.attr
,
1552 &sensor_dev_attr_temp3_auto_point1_temp
.dev_attr
.attr
,
1553 &sensor_dev_attr_temp3_auto_point1_temp_hyst
.dev_attr
.attr
,
1554 &sensor_dev_attr_temp3_auto_point2_temp
.dev_attr
.attr
,
1555 &sensor_dev_attr_temp3_crit
.dev_attr
.attr
,
1556 &dev_attr_temp3_crit_enable
.attr
,
1557 &dev_attr_temp3_auto_point1_pwm
.attr
,
1558 &dev_attr_temp3_auto_point2_pwm
.attr
,
1562 static const struct attribute_group adm1026_group_temp3
= {
1563 .attrs
= adm1026_attributes_temp3
,
1566 static struct attribute
*adm1026_attributes_in8_9
[] = {
1567 &sensor_dev_attr_in8_input
.dev_attr
.attr
,
1568 &sensor_dev_attr_in8_max
.dev_attr
.attr
,
1569 &sensor_dev_attr_in8_min
.dev_attr
.attr
,
1570 &sensor_dev_attr_in8_alarm
.dev_attr
.attr
,
1571 &sensor_dev_attr_in9_input
.dev_attr
.attr
,
1572 &sensor_dev_attr_in9_max
.dev_attr
.attr
,
1573 &sensor_dev_attr_in9_min
.dev_attr
.attr
,
1574 &sensor_dev_attr_in9_alarm
.dev_attr
.attr
,
1578 static const struct attribute_group adm1026_group_in8_9
= {
1579 .attrs
= adm1026_attributes_in8_9
,
1582 /* Return 0 if detection is successful, -ENODEV otherwise */
1583 static int adm1026_detect(struct i2c_client
*client
,
1584 struct i2c_board_info
*info
)
1586 struct i2c_adapter
*adapter
= client
->adapter
;
1587 int address
= client
->addr
;
1588 int company
, verstep
;
1590 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
)) {
1591 /* We need to be able to do byte I/O */
1595 /* Now, we do the remaining detection. */
1597 company
= adm1026_read_value(client
, ADM1026_REG_COMPANY
);
1598 verstep
= adm1026_read_value(client
, ADM1026_REG_VERSTEP
);
1600 dev_dbg(&adapter
->dev
,
1601 "Detecting device at %d,0x%02x with COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1602 i2c_adapter_id(client
->adapter
), client
->addr
,
1605 /* Determine the chip type. */
1606 dev_dbg(&adapter
->dev
, "Autodetecting device at %d,0x%02x...\n",
1607 i2c_adapter_id(adapter
), address
);
1608 if (company
== ADM1026_COMPANY_ANALOG_DEV
1609 && verstep
== ADM1026_VERSTEP_ADM1026
) {
1610 /* Analog Devices ADM1026 */
1611 } else if (company
== ADM1026_COMPANY_ANALOG_DEV
1612 && (verstep
& 0xf0) == ADM1026_VERSTEP_GENERIC
) {
1613 dev_err(&adapter
->dev
,
1614 "Unrecognized stepping 0x%02x. Defaulting to ADM1026.\n",
1616 } else if ((verstep
& 0xf0) == ADM1026_VERSTEP_GENERIC
) {
1617 dev_err(&adapter
->dev
,
1618 "Found version/stepping 0x%02x. Assuming generic ADM1026.\n",
1621 dev_dbg(&adapter
->dev
, "Autodetection failed\n");
1622 /* Not an ADM1026... */
1626 strlcpy(info
->type
, "adm1026", I2C_NAME_SIZE
);
1631 static void adm1026_print_gpio(struct i2c_client
*client
)
1633 struct adm1026_data
*data
= i2c_get_clientdata(client
);
1636 dev_dbg(&client
->dev
, "GPIO config is:\n");
1637 for (i
= 0; i
<= 7; ++i
) {
1638 if (data
->config2
& (1 << i
)) {
1639 dev_dbg(&client
->dev
, "\t%sGP%s%d\n",
1640 data
->gpio_config
[i
] & 0x02 ? "" : "!",
1641 data
->gpio_config
[i
] & 0x01 ? "OUT" : "IN",
1644 dev_dbg(&client
->dev
, "\tFAN%d\n", i
);
1647 for (i
= 8; i
<= 15; ++i
) {
1648 dev_dbg(&client
->dev
, "\t%sGP%s%d\n",
1649 data
->gpio_config
[i
] & 0x02 ? "" : "!",
1650 data
->gpio_config
[i
] & 0x01 ? "OUT" : "IN",
1653 if (data
->config3
& CFG3_GPIO16_ENABLE
) {
1654 dev_dbg(&client
->dev
, "\t%sGP%s16\n",
1655 data
->gpio_config
[16] & 0x02 ? "" : "!",
1656 data
->gpio_config
[16] & 0x01 ? "OUT" : "IN");
1658 /* GPIO16 is THERM */
1659 dev_dbg(&client
->dev
, "\tTHERM\n");
1663 static void adm1026_fixup_gpio(struct i2c_client
*client
)
1665 struct adm1026_data
*data
= i2c_get_clientdata(client
);
1669 /* Make the changes requested. */
1671 * We may need to unlock/stop monitoring or soft-reset the
1672 * chip before we can make changes. This hasn't been
1673 * tested much. FIXME
1677 for (i
= 0; i
<= 16; ++i
) {
1678 if (gpio_output
[i
] >= 0 && gpio_output
[i
] <= 16)
1679 data
->gpio_config
[gpio_output
[i
]] |= 0x01;
1680 /* if GPIO0-7 is output, it isn't a FAN tach */
1681 if (gpio_output
[i
] >= 0 && gpio_output
[i
] <= 7)
1682 data
->config2
|= 1 << gpio_output
[i
];
1685 /* Input overrides output */
1686 for (i
= 0; i
<= 16; ++i
) {
1687 if (gpio_input
[i
] >= 0 && gpio_input
[i
] <= 16)
1688 data
->gpio_config
[gpio_input
[i
]] &= ~0x01;
1689 /* if GPIO0-7 is input, it isn't a FAN tach */
1690 if (gpio_input
[i
] >= 0 && gpio_input
[i
] <= 7)
1691 data
->config2
|= 1 << gpio_input
[i
];
1695 for (i
= 0; i
<= 16; ++i
) {
1696 if (gpio_inverted
[i
] >= 0 && gpio_inverted
[i
] <= 16)
1697 data
->gpio_config
[gpio_inverted
[i
]] &= ~0x02;
1700 /* Normal overrides inverted */
1701 for (i
= 0; i
<= 16; ++i
) {
1702 if (gpio_normal
[i
] >= 0 && gpio_normal
[i
] <= 16)
1703 data
->gpio_config
[gpio_normal
[i
]] |= 0x02;
1706 /* Fan overrides input and output */
1707 for (i
= 0; i
<= 7; ++i
) {
1708 if (gpio_fan
[i
] >= 0 && gpio_fan
[i
] <= 7)
1709 data
->config2
&= ~(1 << gpio_fan
[i
]);
1712 /* Write new configs to registers */
1713 adm1026_write_value(client
, ADM1026_REG_CONFIG2
, data
->config2
);
1714 data
->config3
= (data
->config3
& 0x3f)
1715 | ((data
->gpio_config
[16] & 0x03) << 6);
1716 adm1026_write_value(client
, ADM1026_REG_CONFIG3
, data
->config3
);
1717 for (i
= 15, value
= 0; i
>= 0; --i
) {
1719 value
|= data
->gpio_config
[i
] & 0x03;
1720 if ((i
& 0x03) == 0) {
1721 adm1026_write_value(client
,
1722 ADM1026_REG_GPIO_CFG_0_3
+ i
/4,
1728 /* Print the new config */
1729 adm1026_print_gpio(client
);
1732 static void adm1026_init_client(struct i2c_client
*client
)
1735 struct adm1026_data
*data
= i2c_get_clientdata(client
);
1737 dev_dbg(&client
->dev
, "Initializing device\n");
1738 /* Read chip config */
1739 data
->config1
= adm1026_read_value(client
, ADM1026_REG_CONFIG1
);
1740 data
->config2
= adm1026_read_value(client
, ADM1026_REG_CONFIG2
);
1741 data
->config3
= adm1026_read_value(client
, ADM1026_REG_CONFIG3
);
1743 /* Inform user of chip config */
1744 dev_dbg(&client
->dev
, "ADM1026_REG_CONFIG1 is: 0x%02x\n",
1746 if ((data
->config1
& CFG1_MONITOR
) == 0) {
1747 dev_dbg(&client
->dev
,
1748 "Monitoring not currently enabled.\n");
1750 if (data
->config1
& CFG1_INT_ENABLE
) {
1751 dev_dbg(&client
->dev
,
1752 "SMBALERT interrupts are enabled.\n");
1754 if (data
->config1
& CFG1_AIN8_9
) {
1755 dev_dbg(&client
->dev
,
1756 "in8 and in9 enabled. temp3 disabled.\n");
1758 dev_dbg(&client
->dev
,
1759 "temp3 enabled. in8 and in9 disabled.\n");
1761 if (data
->config1
& CFG1_THERM_HOT
) {
1762 dev_dbg(&client
->dev
,
1763 "Automatic THERM, PWM, and temp limits enabled.\n");
1766 if (data
->config3
& CFG3_GPIO16_ENABLE
) {
1767 dev_dbg(&client
->dev
,
1768 "GPIO16 enabled. THERM pin disabled.\n");
1770 dev_dbg(&client
->dev
,
1771 "THERM pin enabled. GPIO16 disabled.\n");
1773 if (data
->config3
& CFG3_VREF_250
)
1774 dev_dbg(&client
->dev
, "Vref is 2.50 Volts.\n");
1776 dev_dbg(&client
->dev
, "Vref is 1.82 Volts.\n");
1777 /* Read and pick apart the existing GPIO configuration */
1779 for (i
= 0; i
<= 15; ++i
) {
1780 if ((i
& 0x03) == 0) {
1781 value
= adm1026_read_value(client
,
1782 ADM1026_REG_GPIO_CFG_0_3
+ i
/ 4);
1784 data
->gpio_config
[i
] = value
& 0x03;
1787 data
->gpio_config
[16] = (data
->config3
>> 6) & 0x03;
1789 /* ... and then print it */
1790 adm1026_print_gpio(client
);
1793 * If the user asks us to reprogram the GPIO config, then
1796 if (gpio_input
[0] != -1 || gpio_output
[0] != -1
1797 || gpio_inverted
[0] != -1 || gpio_normal
[0] != -1
1798 || gpio_fan
[0] != -1) {
1799 adm1026_fixup_gpio(client
);
1803 * WE INTENTIONALLY make no changes to the limits,
1804 * offsets, pwms, fans and zones. If they were
1805 * configured, we don't want to mess with them.
1806 * If they weren't, the default is 100% PWM, no
1807 * control and will suffice until 'sensors -s'
1808 * can be run by the user. We DO set the default
1809 * value for pwm1.auto_pwm_min to its maximum
1810 * so that enabling automatic pwm fan control
1811 * without first setting a value for pwm1.auto_pwm_min
1812 * will not result in potentially dangerous fan speed decrease.
1814 data
->pwm1
.auto_pwm_min
= 255;
1815 /* Start monitoring */
1816 value
= adm1026_read_value(client
, ADM1026_REG_CONFIG1
);
1817 /* Set MONITOR, clear interrupt acknowledge and s/w reset */
1818 value
= (value
| CFG1_MONITOR
) & (~CFG1_INT_CLEAR
& ~CFG1_RESET
);
1819 dev_dbg(&client
->dev
, "Setting CONFIG to: 0x%02x\n", value
);
1820 data
->config1
= value
;
1821 adm1026_write_value(client
, ADM1026_REG_CONFIG1
, value
);
1823 /* initialize fan_div[] to hardware defaults */
1824 value
= adm1026_read_value(client
, ADM1026_REG_FAN_DIV_0_3
) |
1825 (adm1026_read_value(client
, ADM1026_REG_FAN_DIV_4_7
) << 8);
1826 for (i
= 0; i
<= 7; ++i
) {
1827 data
->fan_div
[i
] = DIV_FROM_REG(value
& 0x03);
1832 static int adm1026_probe(struct i2c_client
*client
,
1833 const struct i2c_device_id
*id
)
1835 struct device
*dev
= &client
->dev
;
1836 struct device
*hwmon_dev
;
1837 struct adm1026_data
*data
;
1839 data
= devm_kzalloc(dev
, sizeof(struct adm1026_data
), GFP_KERNEL
);
1843 i2c_set_clientdata(client
, data
);
1844 data
->client
= client
;
1845 mutex_init(&data
->update_lock
);
1847 /* Set the VRM version */
1848 data
->vrm
= vid_which_vrm();
1850 /* Initialize the ADM1026 chip */
1851 adm1026_init_client(client
);
1854 data
->groups
[0] = &adm1026_group
;
1855 if (data
->config1
& CFG1_AIN8_9
)
1856 data
->groups
[1] = &adm1026_group_in8_9
;
1858 data
->groups
[1] = &adm1026_group_temp3
;
1860 hwmon_dev
= devm_hwmon_device_register_with_groups(dev
, client
->name
,
1861 data
, data
->groups
);
1862 return PTR_ERR_OR_ZERO(hwmon_dev
);
1865 static const struct i2c_device_id adm1026_id
[] = {
1869 MODULE_DEVICE_TABLE(i2c
, adm1026_id
);
1871 static struct i2c_driver adm1026_driver
= {
1872 .class = I2C_CLASS_HWMON
,
1876 .probe
= adm1026_probe
,
1877 .id_table
= adm1026_id
,
1878 .detect
= adm1026_detect
,
1879 .address_list
= normal_i2c
,
1882 module_i2c_driver(adm1026_driver
);
1884 MODULE_LICENSE("GPL");
1885 MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1886 "Justin Thiessen <jthiessen@penguincomputing.com>");
1887 MODULE_DESCRIPTION("ADM1026 driver");