blob: c4a1784e3f2b1d3ee374f3b4b21d670fab57a488 [file] [log] [blame]
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001/*
2 * A hwmon driver for the Analog Devices ADT7462
3 * Copyright (C) 2008 IBM
4 *
Darrick J. Wong5407e0512013-08-26 15:42:27 -07005 * Author: Darrick J. Wong <darrick.wong@oracle.com>
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/module.h>
23#include <linux/jiffies.h>
24#include <linux/i2c.h>
25#include <linux/hwmon.h>
26#include <linux/hwmon-sysfs.h>
27#include <linux/err.h>
28#include <linux/mutex.h>
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -080029#include <linux/log2.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -080031
32/* Addresses to scan */
33static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
34
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -080035/* ADT7462 registers */
36#define ADT7462_REG_DEVICE 0x3D
37#define ADT7462_REG_VENDOR 0x3E
38#define ADT7462_REG_REVISION 0x3F
39
40#define ADT7462_REG_MIN_TEMP_BASE_ADDR 0x44
41#define ADT7462_REG_MIN_TEMP_MAX_ADDR 0x47
42#define ADT7462_REG_MAX_TEMP_BASE_ADDR 0x48
43#define ADT7462_REG_MAX_TEMP_MAX_ADDR 0x4B
44#define ADT7462_REG_TEMP_BASE_ADDR 0x88
45#define ADT7462_REG_TEMP_MAX_ADDR 0x8F
46
47#define ADT7462_REG_FAN_BASE_ADDR 0x98
48#define ADT7462_REG_FAN_MAX_ADDR 0x9F
49#define ADT7462_REG_FAN2_BASE_ADDR 0xA2
50#define ADT7462_REG_FAN2_MAX_ADDR 0xA9
51#define ADT7462_REG_FAN_ENABLE 0x07
52#define ADT7462_REG_FAN_MIN_BASE_ADDR 0x78
53#define ADT7462_REG_FAN_MIN_MAX_ADDR 0x7F
54
55#define ADT7462_REG_CFG2 0x02
56#define ADT7462_FSPD_MASK 0x20
57
58#define ADT7462_REG_PWM_BASE_ADDR 0xAA
59#define ADT7462_REG_PWM_MAX_ADDR 0xAD
60#define ADT7462_REG_PWM_MIN_BASE_ADDR 0x28
61#define ADT7462_REG_PWM_MIN_MAX_ADDR 0x2B
62#define ADT7462_REG_PWM_MAX 0x2C
63#define ADT7462_REG_PWM_TEMP_MIN_BASE_ADDR 0x5C
64#define ADT7462_REG_PWM_TEMP_MIN_MAX_ADDR 0x5F
65#define ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR 0x60
66#define ADT7462_REG_PWM_TEMP_RANGE_MAX_ADDR 0x63
Guenter Roeck724cc332012-01-14 13:16:53 -080067#define ADT7462_PWM_HYST_MASK 0x0F
68#define ADT7462_PWM_RANGE_MASK 0xF0
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -080069#define ADT7462_PWM_RANGE_SHIFT 4
70#define ADT7462_REG_PWM_CFG_BASE_ADDR 0x21
71#define ADT7462_REG_PWM_CFG_MAX_ADDR 0x24
72#define ADT7462_PWM_CHANNEL_MASK 0xE0
73#define ADT7462_PWM_CHANNEL_SHIFT 5
74
75#define ADT7462_REG_PIN_CFG_BASE_ADDR 0x10
76#define ADT7462_REG_PIN_CFG_MAX_ADDR 0x13
77#define ADT7462_PIN7_INPUT 0x01 /* cfg0 */
78#define ADT7462_DIODE3_INPUT 0x20
79#define ADT7462_DIODE1_INPUT 0x40
80#define ADT7462_VID_INPUT 0x80
81#define ADT7462_PIN22_INPUT 0x04 /* cfg1 */
82#define ADT7462_PIN21_INPUT 0x08
83#define ADT7462_PIN19_INPUT 0x10
84#define ADT7462_PIN15_INPUT 0x20
85#define ADT7462_PIN13_INPUT 0x40
86#define ADT7462_PIN8_INPUT 0x80
Guenter Roeck724cc332012-01-14 13:16:53 -080087#define ADT7462_PIN23_MASK 0x03
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -080088#define ADT7462_PIN23_SHIFT 0
89#define ADT7462_PIN26_MASK 0x0C /* cfg2 */
90#define ADT7462_PIN26_SHIFT 2
91#define ADT7462_PIN25_MASK 0x30
92#define ADT7462_PIN25_SHIFT 4
93#define ADT7462_PIN24_MASK 0xC0
94#define ADT7462_PIN24_SHIFT 6
95#define ADT7462_PIN26_VOLT_INPUT 0x08
96#define ADT7462_PIN25_VOLT_INPUT 0x20
Roger Blofeldbb595c92010-01-10 20:52:32 +010097#define ADT7462_PIN28_SHIFT 4 /* cfg3 */
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -080098#define ADT7462_PIN28_VOLT 0x5
99
100#define ADT7462_REG_ALARM1 0xB8
Guenter Roeck724cc332012-01-14 13:16:53 -0800101#define ADT7462_LT_ALARM 0x02
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800102#define ADT7462_R1T_ALARM 0x04
103#define ADT7462_R2T_ALARM 0x08
104#define ADT7462_R3T_ALARM 0x10
105#define ADT7462_REG_ALARM2 0xBB
106#define ADT7462_V0_ALARM 0x01
107#define ADT7462_V1_ALARM 0x02
108#define ADT7462_V2_ALARM 0x04
109#define ADT7462_V3_ALARM 0x08
110#define ADT7462_V4_ALARM 0x10
111#define ADT7462_V5_ALARM 0x20
112#define ADT7462_V6_ALARM 0x40
113#define ADT7462_V7_ALARM 0x80
114#define ADT7462_REG_ALARM3 0xBC
115#define ADT7462_V8_ALARM 0x08
116#define ADT7462_V9_ALARM 0x10
117#define ADT7462_V10_ALARM 0x20
118#define ADT7462_V11_ALARM 0x40
119#define ADT7462_V12_ALARM 0x80
120#define ADT7462_REG_ALARM4 0xBD
121#define ADT7462_F0_ALARM 0x01
122#define ADT7462_F1_ALARM 0x02
123#define ADT7462_F2_ALARM 0x04
124#define ADT7462_F3_ALARM 0x08
125#define ADT7462_F4_ALARM 0x10
126#define ADT7462_F5_ALARM 0x20
127#define ADT7462_F6_ALARM 0x40
128#define ADT7462_F7_ALARM 0x80
129#define ADT7462_ALARM1 0x0000
130#define ADT7462_ALARM2 0x0100
131#define ADT7462_ALARM3 0x0200
132#define ADT7462_ALARM4 0x0300
133#define ADT7462_ALARM_REG_SHIFT 8
134#define ADT7462_ALARM_FLAG_MASK 0x0F
135
136#define ADT7462_TEMP_COUNT 4
Guenter Roeck724cc332012-01-14 13:16:53 -0800137#define ADT7462_TEMP_REG(x) (ADT7462_REG_TEMP_BASE_ADDR + ((x) * 2))
138#define ADT7462_TEMP_MIN_REG(x) (ADT7462_REG_MIN_TEMP_BASE_ADDR + (x))
139#define ADT7462_TEMP_MAX_REG(x) (ADT7462_REG_MAX_TEMP_BASE_ADDR + (x))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800140#define TEMP_FRAC_OFFSET 6
141
142#define ADT7462_FAN_COUNT 8
143#define ADT7462_REG_FAN_MIN(x) (ADT7462_REG_FAN_MIN_BASE_ADDR + (x))
144
145#define ADT7462_PWM_COUNT 4
146#define ADT7462_REG_PWM(x) (ADT7462_REG_PWM_BASE_ADDR + (x))
147#define ADT7462_REG_PWM_MIN(x) (ADT7462_REG_PWM_MIN_BASE_ADDR + (x))
148#define ADT7462_REG_PWM_TMIN(x) \
149 (ADT7462_REG_PWM_TEMP_MIN_BASE_ADDR + (x))
150#define ADT7462_REG_PWM_TRANGE(x) \
151 (ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR + (x))
152
153#define ADT7462_PIN_CFG_REG_COUNT 4
154#define ADT7462_REG_PIN_CFG(x) (ADT7462_REG_PIN_CFG_BASE_ADDR + (x))
155#define ADT7462_REG_PWM_CFG(x) (ADT7462_REG_PWM_CFG_BASE_ADDR + (x))
156
157#define ADT7462_ALARM_REG_COUNT 4
158
159/*
160 * The chip can measure 13 different voltage sources:
161 *
162 * 1. +12V1 (pin 7)
163 * 2. Vccp1/+2.5V/+1.8V/+1.5V (pin 23)
164 * 3. +12V3 (pin 22)
165 * 4. +5V (pin 21)
166 * 5. +1.25V/+0.9V (pin 19)
167 * 6. +2.5V/+1.8V (pin 15)
168 * 7. +3.3v (pin 13)
169 * 8. +12V2 (pin 8)
170 * 9. Vbatt/FSB_Vtt (pin 26)
171 * A. +3.3V/+1.2V1 (pin 25)
172 * B. Vccp2/+2.5V/+1.8V/+1.5V (pin 24)
173 * C. +1.5V ICH (only if BOTH pin 28/29 are set to +1.5V)
174 * D. +1.5V 3GPIO (only if BOTH pin 28/29 are set to +1.5V)
175 *
176 * Each of these 13 has a factor to convert raw to voltage. Even better,
177 * the pins can be connected to other sensors (tach/gpio/hot/etc), which
178 * makes the bookkeeping tricky.
179 *
180 * Some, but not all, of these voltages have low/high limits.
181 */
Ray Copeland85f8d3e2010-02-05 19:58:35 +0100182#define ADT7462_VOLT_COUNT 13
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800183
184#define ADT7462_VENDOR 0x41
185#define ADT7462_DEVICE 0x62
186/* datasheet only mentions a revision 4 */
187#define ADT7462_REVISION 0x04
188
189/* How often do we reread sensors values? (In jiffies) */
190#define SENSOR_REFRESH_INTERVAL (2 * HZ)
191
192/* How often do we reread sensor limit values? (In jiffies) */
193#define LIMIT_REFRESH_INTERVAL (60 * HZ)
194
195/* datasheet says to divide this number by the fan reading to get fan rpm */
196#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
197#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
198#define FAN_PERIOD_INVALID 65535
199#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
200
201#define MASK_AND_SHIFT(value, prefix) \
202 (((value) & prefix##_MASK) >> prefix##_SHIFT)
203
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800204struct adt7462_data {
205 struct device *hwmon_dev;
206 struct attribute_group attrs;
207 struct mutex lock;
208 char sensors_valid;
209 char limits_valid;
210 unsigned long sensors_last_updated; /* In jiffies */
211 unsigned long limits_last_updated; /* In jiffies */
212
213 u8 temp[ADT7462_TEMP_COUNT];
214 /* bits 6-7 are quarter pieces of temp */
215 u8 temp_frac[ADT7462_TEMP_COUNT];
216 u8 temp_min[ADT7462_TEMP_COUNT];
217 u8 temp_max[ADT7462_TEMP_COUNT];
218 u16 fan[ADT7462_FAN_COUNT];
219 u8 fan_enabled;
220 u8 fan_min[ADT7462_FAN_COUNT];
221 u8 cfg2;
222 u8 pwm[ADT7462_PWM_COUNT];
223 u8 pin_cfg[ADT7462_PIN_CFG_REG_COUNT];
224 u8 voltages[ADT7462_VOLT_COUNT];
225 u8 volt_max[ADT7462_VOLT_COUNT];
226 u8 volt_min[ADT7462_VOLT_COUNT];
227 u8 pwm_min[ADT7462_PWM_COUNT];
228 u8 pwm_tmin[ADT7462_PWM_COUNT];
229 u8 pwm_trange[ADT7462_PWM_COUNT];
230 u8 pwm_max; /* only one per chip */
231 u8 pwm_cfg[ADT7462_PWM_COUNT];
232 u8 alarms[ADT7462_ALARM_REG_COUNT];
233};
234
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800235/*
236 * 16-bit registers on the ADT7462 are low-byte first. The data sheet says
237 * that the low byte must be read before the high byte.
238 */
239static inline int adt7462_read_word_data(struct i2c_client *client, u8 reg)
240{
241 u16 foo;
242 foo = i2c_smbus_read_byte_data(client, reg);
243 foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8);
244 return foo;
245}
246
247/* For some reason these registers are not contiguous. */
248static int ADT7462_REG_FAN(int fan)
249{
250 if (fan < 4)
251 return ADT7462_REG_FAN_BASE_ADDR + (2 * fan);
252 return ADT7462_REG_FAN2_BASE_ADDR + (2 * (fan - 4));
253}
254
255/* Voltage registers are scattered everywhere */
256static int ADT7462_REG_VOLT_MAX(struct adt7462_data *data, int which)
257{
258 switch (which) {
259 case 0:
260 if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
261 return 0x7C;
262 break;
263 case 1:
264 return 0x69;
265 case 2:
266 if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
267 return 0x7F;
268 break;
269 case 3:
270 if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
271 return 0x7E;
272 break;
273 case 4:
274 if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT))
275 return 0x4B;
276 break;
277 case 5:
278 if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT))
279 return 0x49;
280 break;
281 case 6:
282 if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
283 return 0x68;
284 break;
285 case 7:
286 if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
287 return 0x7D;
288 break;
289 case 8:
290 if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT))
291 return 0x6C;
292 break;
293 case 9:
294 if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT))
295 return 0x6B;
296 break;
297 case 10:
298 return 0x6A;
299 case 11:
300 if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
301 ADT7462_PIN28_VOLT &&
302 !(data->pin_cfg[0] & ADT7462_VID_INPUT))
303 return 0x50;
304 break;
305 case 12:
306 if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
307 ADT7462_PIN28_VOLT &&
308 !(data->pin_cfg[0] & ADT7462_VID_INPUT))
309 return 0x4C;
310 break;
311 }
Dan Carpentera4bf06d2013-08-14 12:45:26 +0300312 return 0;
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800313}
314
315static int ADT7462_REG_VOLT_MIN(struct adt7462_data *data, int which)
316{
317 switch (which) {
318 case 0:
319 if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
320 return 0x6D;
321 break;
322 case 1:
323 return 0x72;
324 case 2:
325 if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
326 return 0x6F;
327 break;
328 case 3:
329 if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
330 return 0x71;
331 break;
332 case 4:
333 if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT))
334 return 0x47;
335 break;
336 case 5:
337 if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT))
338 return 0x45;
339 break;
340 case 6:
341 if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
342 return 0x70;
343 break;
344 case 7:
345 if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
346 return 0x6E;
347 break;
348 case 8:
349 if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT))
350 return 0x75;
351 break;
352 case 9:
353 if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT))
354 return 0x74;
355 break;
356 case 10:
357 return 0x73;
358 case 11:
359 if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
360 ADT7462_PIN28_VOLT &&
361 !(data->pin_cfg[0] & ADT7462_VID_INPUT))
362 return 0x76;
363 break;
364 case 12:
365 if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
366 ADT7462_PIN28_VOLT &&
367 !(data->pin_cfg[0] & ADT7462_VID_INPUT))
368 return 0x77;
369 break;
370 }
Dan Carpentera4bf06d2013-08-14 12:45:26 +0300371 return 0;
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800372}
373
374static int ADT7462_REG_VOLT(struct adt7462_data *data, int which)
375{
376 switch (which) {
377 case 0:
378 if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
379 return 0xA3;
380 break;
381 case 1:
382 return 0x90;
383 case 2:
384 if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
385 return 0xA9;
386 break;
387 case 3:
388 if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
389 return 0xA7;
390 break;
391 case 4:
392 if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT))
393 return 0x8F;
394 break;
395 case 5:
396 if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT))
397 return 0x8B;
398 break;
399 case 6:
400 if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
401 return 0x96;
402 break;
403 case 7:
404 if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
405 return 0xA5;
406 break;
407 case 8:
408 if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT))
409 return 0x93;
410 break;
411 case 9:
412 if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT))
413 return 0x92;
414 break;
415 case 10:
416 return 0x91;
417 case 11:
418 if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
419 ADT7462_PIN28_VOLT &&
420 !(data->pin_cfg[0] & ADT7462_VID_INPUT))
421 return 0x94;
422 break;
423 case 12:
424 if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
425 ADT7462_PIN28_VOLT &&
426 !(data->pin_cfg[0] & ADT7462_VID_INPUT))
427 return 0x95;
428 break;
429 }
430 return -ENODEV;
431}
432
433/* Provide labels for sysfs */
434static const char *voltage_label(struct adt7462_data *data, int which)
435{
436 switch (which) {
437 case 0:
438 if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
439 return "+12V1";
440 break;
441 case 1:
442 switch (MASK_AND_SHIFT(data->pin_cfg[1], ADT7462_PIN23)) {
443 case 0:
444 return "Vccp1";
445 case 1:
446 return "+2.5V";
447 case 2:
448 return "+1.8V";
449 case 3:
450 return "+1.5V";
451 }
452 case 2:
453 if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
454 return "+12V3";
455 break;
456 case 3:
457 if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
458 return "+5V";
459 break;
460 case 4:
461 if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) {
462 if (data->pin_cfg[1] & ADT7462_PIN19_INPUT)
463 return "+0.9V";
464 return "+1.25V";
465 }
466 break;
467 case 5:
468 if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) {
469 if (data->pin_cfg[1] & ADT7462_PIN19_INPUT)
470 return "+1.8V";
471 return "+2.5V";
472 }
473 break;
474 case 6:
475 if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
476 return "+3.3V";
477 break;
478 case 7:
479 if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
480 return "+12V2";
481 break;
482 case 8:
483 switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN26)) {
484 case 0:
485 return "Vbatt";
486 case 1:
487 return "FSB_Vtt";
488 }
489 break;
490 case 9:
491 switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN25)) {
492 case 0:
493 return "+3.3V";
494 case 1:
495 return "+1.2V1";
496 }
497 break;
498 case 10:
499 switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN24)) {
500 case 0:
501 return "Vccp2";
502 case 1:
503 return "+2.5V";
504 case 2:
505 return "+1.8V";
506 case 3:
507 return "+1.5";
508 }
509 case 11:
510 if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
511 ADT7462_PIN28_VOLT &&
512 !(data->pin_cfg[0] & ADT7462_VID_INPUT))
513 return "+1.5V ICH";
514 break;
515 case 12:
516 if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
517 ADT7462_PIN28_VOLT &&
518 !(data->pin_cfg[0] & ADT7462_VID_INPUT))
519 return "+1.5V 3GPIO";
520 break;
521 }
522 return "N/A";
523}
524
525/* Multipliers are actually in uV, not mV. */
526static int voltage_multiplier(struct adt7462_data *data, int which)
527{
528 switch (which) {
529 case 0:
530 if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT))
531 return 62500;
532 break;
533 case 1:
534 switch (MASK_AND_SHIFT(data->pin_cfg[1], ADT7462_PIN23)) {
535 case 0:
536 if (data->pin_cfg[0] & ADT7462_VID_INPUT)
537 return 12500;
538 return 6250;
539 case 1:
540 return 13000;
541 case 2:
542 return 9400;
543 case 3:
544 return 7800;
545 }
546 case 2:
547 if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT))
548 return 62500;
549 break;
550 case 3:
551 if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT))
552 return 26000;
553 break;
554 case 4:
555 if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) {
556 if (data->pin_cfg[1] & ADT7462_PIN19_INPUT)
557 return 4690;
558 return 6500;
559 }
560 break;
561 case 5:
562 if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) {
563 if (data->pin_cfg[1] & ADT7462_PIN15_INPUT)
564 return 9400;
565 return 13000;
566 }
567 break;
568 case 6:
569 if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT))
570 return 17200;
571 break;
572 case 7:
573 if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT))
574 return 62500;
575 break;
576 case 8:
577 switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN26)) {
578 case 0:
579 return 15600;
580 case 1:
581 return 6250;
582 }
583 break;
584 case 9:
585 switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN25)) {
586 case 0:
587 return 17200;
588 case 1:
589 return 6250;
590 }
591 break;
592 case 10:
593 switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN24)) {
594 case 0:
595 return 6250;
596 case 1:
597 return 13000;
598 case 2:
599 return 9400;
600 case 3:
601 return 7800;
602 }
603 case 11:
604 case 12:
605 if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT ==
606 ADT7462_PIN28_VOLT &&
607 !(data->pin_cfg[0] & ADT7462_VID_INPUT))
608 return 7800;
609 }
610 return 0;
611}
612
613static int temp_enabled(struct adt7462_data *data, int which)
614{
615 switch (which) {
616 case 0:
617 case 2:
618 return 1;
619 case 1:
620 if (data->pin_cfg[0] & ADT7462_DIODE1_INPUT)
621 return 1;
622 break;
623 case 3:
624 if (data->pin_cfg[0] & ADT7462_DIODE3_INPUT)
625 return 1;
626 break;
627 }
628 return 0;
629}
630
631static const char *temp_label(struct adt7462_data *data, int which)
632{
633 switch (which) {
634 case 0:
635 return "local";
636 case 1:
637 if (data->pin_cfg[0] & ADT7462_DIODE1_INPUT)
638 return "remote1";
639 break;
640 case 2:
641 return "remote2";
642 case 3:
643 if (data->pin_cfg[0] & ADT7462_DIODE3_INPUT)
644 return "remote3";
645 break;
646 }
647 return "N/A";
648}
649
650/* Map Trange register values to mC */
651#define NUM_TRANGE_VALUES 16
652static const int trange_values[NUM_TRANGE_VALUES] = {
653 2000,
654 2500,
655 3300,
656 4000,
657 5000,
658 6700,
659 8000,
660 10000,
661 13300,
662 16000,
663 20000,
664 26700,
665 32000,
666 40000,
667 53300,
668 80000
669};
670
671static int find_trange_value(int trange)
672{
673 int i;
674
675 for (i = 0; i < NUM_TRANGE_VALUES; i++)
676 if (trange_values[i] == trange)
677 return i;
678
Guenter Roeckbb34c0d2013-09-13 10:38:09 -0700679 return -EINVAL;
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800680}
681
682static struct adt7462_data *adt7462_update_device(struct device *dev)
683{
684 struct i2c_client *client = to_i2c_client(dev);
685 struct adt7462_data *data = i2c_get_clientdata(client);
686 unsigned long local_jiffies = jiffies;
687 int i;
688
689 mutex_lock(&data->lock);
690 if (time_before(local_jiffies, data->sensors_last_updated +
691 SENSOR_REFRESH_INTERVAL)
692 && data->sensors_valid)
693 goto no_sensor_update;
694
695 for (i = 0; i < ADT7462_TEMP_COUNT; i++) {
696 /*
697 * Reading the fractional register locks the integral
698 * register until both have been read.
699 */
700 data->temp_frac[i] = i2c_smbus_read_byte_data(client,
701 ADT7462_TEMP_REG(i));
702 data->temp[i] = i2c_smbus_read_byte_data(client,
703 ADT7462_TEMP_REG(i) + 1);
704 }
705
706 for (i = 0; i < ADT7462_FAN_COUNT; i++)
707 data->fan[i] = adt7462_read_word_data(client,
708 ADT7462_REG_FAN(i));
709
710 data->fan_enabled = i2c_smbus_read_byte_data(client,
711 ADT7462_REG_FAN_ENABLE);
712
713 for (i = 0; i < ADT7462_PWM_COUNT; i++)
714 data->pwm[i] = i2c_smbus_read_byte_data(client,
715 ADT7462_REG_PWM(i));
716
717 for (i = 0; i < ADT7462_PIN_CFG_REG_COUNT; i++)
718 data->pin_cfg[i] = i2c_smbus_read_byte_data(client,
719 ADT7462_REG_PIN_CFG(i));
720
721 for (i = 0; i < ADT7462_VOLT_COUNT; i++) {
722 int reg = ADT7462_REG_VOLT(data, i);
723 if (!reg)
724 data->voltages[i] = 0;
725 else
726 data->voltages[i] = i2c_smbus_read_byte_data(client,
727 reg);
728 }
729
730 data->alarms[0] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM1);
731 data->alarms[1] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM2);
732 data->alarms[2] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM3);
733 data->alarms[3] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM4);
734
735 data->sensors_last_updated = local_jiffies;
736 data->sensors_valid = 1;
737
738no_sensor_update:
739 if (time_before(local_jiffies, data->limits_last_updated +
740 LIMIT_REFRESH_INTERVAL)
741 && data->limits_valid)
742 goto out;
743
744 for (i = 0; i < ADT7462_TEMP_COUNT; i++) {
745 data->temp_min[i] = i2c_smbus_read_byte_data(client,
746 ADT7462_TEMP_MIN_REG(i));
747 data->temp_max[i] = i2c_smbus_read_byte_data(client,
748 ADT7462_TEMP_MAX_REG(i));
749 }
750
751 for (i = 0; i < ADT7462_FAN_COUNT; i++)
752 data->fan_min[i] = i2c_smbus_read_byte_data(client,
753 ADT7462_REG_FAN_MIN(i));
754
755 for (i = 0; i < ADT7462_VOLT_COUNT; i++) {
756 int reg = ADT7462_REG_VOLT_MAX(data, i);
757 data->volt_max[i] =
758 (reg ? i2c_smbus_read_byte_data(client, reg) : 0);
759
760 reg = ADT7462_REG_VOLT_MIN(data, i);
761 data->volt_min[i] =
762 (reg ? i2c_smbus_read_byte_data(client, reg) : 0);
763 }
764
765 for (i = 0; i < ADT7462_PWM_COUNT; i++) {
766 data->pwm_min[i] = i2c_smbus_read_byte_data(client,
767 ADT7462_REG_PWM_MIN(i));
768 data->pwm_tmin[i] = i2c_smbus_read_byte_data(client,
769 ADT7462_REG_PWM_TMIN(i));
770 data->pwm_trange[i] = i2c_smbus_read_byte_data(client,
771 ADT7462_REG_PWM_TRANGE(i));
772 data->pwm_cfg[i] = i2c_smbus_read_byte_data(client,
773 ADT7462_REG_PWM_CFG(i));
774 }
775
776 data->pwm_max = i2c_smbus_read_byte_data(client, ADT7462_REG_PWM_MAX);
777
778 data->cfg2 = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2);
779
780 data->limits_last_updated = local_jiffies;
781 data->limits_valid = 1;
782
783out:
784 mutex_unlock(&data->lock);
785 return data;
786}
787
788static ssize_t show_temp_min(struct device *dev,
789 struct device_attribute *devattr,
790 char *buf)
791{
792 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
793 struct adt7462_data *data = adt7462_update_device(dev);
794
795 if (!temp_enabled(data, attr->index))
796 return sprintf(buf, "0\n");
797
798 return sprintf(buf, "%d\n", 1000 * (data->temp_min[attr->index] - 64));
799}
800
801static ssize_t set_temp_min(struct device *dev,
802 struct device_attribute *devattr,
803 const char *buf,
804 size_t count)
805{
806 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
807 struct i2c_client *client = to_i2c_client(dev);
808 struct adt7462_data *data = i2c_get_clientdata(client);
809 long temp;
810
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100811 if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800812 return -EINVAL;
813
Darrick J. Wong8f8c1fb2009-01-06 14:41:31 -0800814 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
Guenter Roeck2a844c12013-01-09 08:09:34 -0800815 temp = clamp_val(temp, 0, 255);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800816
817 mutex_lock(&data->lock);
818 data->temp_min[attr->index] = temp;
819 i2c_smbus_write_byte_data(client, ADT7462_TEMP_MIN_REG(attr->index),
820 temp);
821 mutex_unlock(&data->lock);
822
823 return count;
824}
825
826static ssize_t show_temp_max(struct device *dev,
827 struct device_attribute *devattr,
828 char *buf)
829{
830 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
831 struct adt7462_data *data = adt7462_update_device(dev);
832
833 if (!temp_enabled(data, attr->index))
834 return sprintf(buf, "0\n");
835
836 return sprintf(buf, "%d\n", 1000 * (data->temp_max[attr->index] - 64));
837}
838
839static ssize_t set_temp_max(struct device *dev,
840 struct device_attribute *devattr,
841 const char *buf,
842 size_t count)
843{
844 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
845 struct i2c_client *client = to_i2c_client(dev);
846 struct adt7462_data *data = i2c_get_clientdata(client);
847 long temp;
848
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100849 if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800850 return -EINVAL;
851
Darrick J. Wong8f8c1fb2009-01-06 14:41:31 -0800852 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
Guenter Roeck2a844c12013-01-09 08:09:34 -0800853 temp = clamp_val(temp, 0, 255);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800854
855 mutex_lock(&data->lock);
856 data->temp_max[attr->index] = temp;
857 i2c_smbus_write_byte_data(client, ADT7462_TEMP_MAX_REG(attr->index),
858 temp);
859 mutex_unlock(&data->lock);
860
861 return count;
862}
863
864static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
865 char *buf)
866{
867 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
868 struct adt7462_data *data = adt7462_update_device(dev);
869 u8 frac = data->temp_frac[attr->index] >> TEMP_FRAC_OFFSET;
870
871 if (!temp_enabled(data, attr->index))
872 return sprintf(buf, "0\n");
873
874 return sprintf(buf, "%d\n", 1000 * (data->temp[attr->index] - 64) +
875 250 * frac);
876}
877
878static ssize_t show_temp_label(struct device *dev,
879 struct device_attribute *devattr,
880 char *buf)
881{
882 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
883 struct adt7462_data *data = adt7462_update_device(dev);
884
885 return sprintf(buf, "%s\n", temp_label(data, attr->index));
886}
887
888static ssize_t show_volt_max(struct device *dev,
889 struct device_attribute *devattr,
890 char *buf)
891{
892 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
893 struct adt7462_data *data = adt7462_update_device(dev);
894 int x = voltage_multiplier(data, attr->index);
895
896 x *= data->volt_max[attr->index];
897 x /= 1000; /* convert from uV to mV */
898
899 return sprintf(buf, "%d\n", x);
900}
901
902static ssize_t set_volt_max(struct device *dev,
903 struct device_attribute *devattr,
904 const char *buf,
905 size_t count)
906{
907 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
908 struct i2c_client *client = to_i2c_client(dev);
909 struct adt7462_data *data = i2c_get_clientdata(client);
910 int x = voltage_multiplier(data, attr->index);
911 long temp;
912
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100913 if (kstrtol(buf, 10, &temp) || !x)
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800914 return -EINVAL;
915
916 temp *= 1000; /* convert mV to uV */
Darrick J. Wong8f8c1fb2009-01-06 14:41:31 -0800917 temp = DIV_ROUND_CLOSEST(temp, x);
Guenter Roeck2a844c12013-01-09 08:09:34 -0800918 temp = clamp_val(temp, 0, 255);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800919
920 mutex_lock(&data->lock);
921 data->volt_max[attr->index] = temp;
922 i2c_smbus_write_byte_data(client,
923 ADT7462_REG_VOLT_MAX(data, attr->index),
924 temp);
925 mutex_unlock(&data->lock);
926
927 return count;
928}
929
930static ssize_t show_volt_min(struct device *dev,
931 struct device_attribute *devattr,
932 char *buf)
933{
934 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
935 struct adt7462_data *data = adt7462_update_device(dev);
936 int x = voltage_multiplier(data, attr->index);
937
938 x *= data->volt_min[attr->index];
939 x /= 1000; /* convert from uV to mV */
940
941 return sprintf(buf, "%d\n", x);
942}
943
944static ssize_t set_volt_min(struct device *dev,
945 struct device_attribute *devattr,
946 const char *buf,
947 size_t count)
948{
949 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
950 struct i2c_client *client = to_i2c_client(dev);
951 struct adt7462_data *data = i2c_get_clientdata(client);
952 int x = voltage_multiplier(data, attr->index);
953 long temp;
954
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100955 if (kstrtol(buf, 10, &temp) || !x)
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800956 return -EINVAL;
957
958 temp *= 1000; /* convert mV to uV */
Darrick J. Wong8f8c1fb2009-01-06 14:41:31 -0800959 temp = DIV_ROUND_CLOSEST(temp, x);
Guenter Roeck2a844c12013-01-09 08:09:34 -0800960 temp = clamp_val(temp, 0, 255);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -0800961
962 mutex_lock(&data->lock);
963 data->volt_min[attr->index] = temp;
964 i2c_smbus_write_byte_data(client,
965 ADT7462_REG_VOLT_MIN(data, attr->index),
966 temp);
967 mutex_unlock(&data->lock);
968
969 return count;
970}
971
972static ssize_t show_voltage(struct device *dev,
973 struct device_attribute *devattr,
974 char *buf)
975{
976 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
977 struct adt7462_data *data = adt7462_update_device(dev);
978 int x = voltage_multiplier(data, attr->index);
979
980 x *= data->voltages[attr->index];
981 x /= 1000; /* convert from uV to mV */
982
983 return sprintf(buf, "%d\n", x);
984}
985
986static ssize_t show_voltage_label(struct device *dev,
987 struct device_attribute *devattr,
988 char *buf)
989{
990 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
991 struct adt7462_data *data = adt7462_update_device(dev);
992
993 return sprintf(buf, "%s\n", voltage_label(data, attr->index));
994}
995
996static ssize_t show_alarm(struct device *dev,
997 struct device_attribute *devattr,
998 char *buf)
999{
1000 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1001 struct adt7462_data *data = adt7462_update_device(dev);
1002 int reg = attr->index >> ADT7462_ALARM_REG_SHIFT;
1003 int mask = attr->index & ADT7462_ALARM_FLAG_MASK;
1004
1005 if (data->alarms[reg] & mask)
1006 return sprintf(buf, "1\n");
1007 else
1008 return sprintf(buf, "0\n");
1009}
1010
1011static int fan_enabled(struct adt7462_data *data, int fan)
1012{
1013 return data->fan_enabled & (1 << fan);
1014}
1015
1016static ssize_t show_fan_min(struct device *dev,
1017 struct device_attribute *devattr,
1018 char *buf)
1019{
1020 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1021 struct adt7462_data *data = adt7462_update_device(dev);
1022 u16 temp;
1023
1024 /* Only the MSB of the min fan period is stored... */
1025 temp = data->fan_min[attr->index];
1026 temp <<= 8;
1027
1028 if (!fan_enabled(data, attr->index) ||
1029 !FAN_DATA_VALID(temp))
1030 return sprintf(buf, "0\n");
1031
1032 return sprintf(buf, "%d\n", FAN_PERIOD_TO_RPM(temp));
1033}
1034
1035static ssize_t set_fan_min(struct device *dev,
1036 struct device_attribute *devattr,
1037 const char *buf, size_t count)
1038{
1039 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1040 struct i2c_client *client = to_i2c_client(dev);
1041 struct adt7462_data *data = i2c_get_clientdata(client);
1042 long temp;
1043
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001044 if (kstrtol(buf, 10, &temp) || !temp ||
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001045 !fan_enabled(data, attr->index))
1046 return -EINVAL;
1047
1048 temp = FAN_RPM_TO_PERIOD(temp);
1049 temp >>= 8;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001050 temp = clamp_val(temp, 1, 255);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001051
1052 mutex_lock(&data->lock);
1053 data->fan_min[attr->index] = temp;
1054 i2c_smbus_write_byte_data(client, ADT7462_REG_FAN_MIN(attr->index),
1055 temp);
1056 mutex_unlock(&data->lock);
1057
1058 return count;
1059}
1060
1061static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
1062 char *buf)
1063{
1064 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1065 struct adt7462_data *data = adt7462_update_device(dev);
1066
1067 if (!fan_enabled(data, attr->index) ||
1068 !FAN_DATA_VALID(data->fan[attr->index]))
1069 return sprintf(buf, "0\n");
1070
1071 return sprintf(buf, "%d\n",
1072 FAN_PERIOD_TO_RPM(data->fan[attr->index]));
1073}
1074
1075static ssize_t show_force_pwm_max(struct device *dev,
1076 struct device_attribute *devattr,
1077 char *buf)
1078{
1079 struct adt7462_data *data = adt7462_update_device(dev);
1080 return sprintf(buf, "%d\n", (data->cfg2 & ADT7462_FSPD_MASK ? 1 : 0));
1081}
1082
1083static ssize_t set_force_pwm_max(struct device *dev,
1084 struct device_attribute *devattr,
1085 const char *buf,
1086 size_t count)
1087{
1088 struct i2c_client *client = to_i2c_client(dev);
1089 struct adt7462_data *data = i2c_get_clientdata(client);
1090 long temp;
1091 u8 reg;
1092
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001093 if (kstrtol(buf, 10, &temp))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001094 return -EINVAL;
1095
1096 mutex_lock(&data->lock);
1097 reg = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2);
1098 if (temp)
1099 reg |= ADT7462_FSPD_MASK;
1100 else
1101 reg &= ~ADT7462_FSPD_MASK;
1102 data->cfg2 = reg;
1103 i2c_smbus_write_byte_data(client, ADT7462_REG_CFG2, reg);
1104 mutex_unlock(&data->lock);
1105
1106 return count;
1107}
1108
1109static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
1110 char *buf)
1111{
1112 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1113 struct adt7462_data *data = adt7462_update_device(dev);
1114 return sprintf(buf, "%d\n", data->pwm[attr->index]);
1115}
1116
1117static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
1118 const char *buf, size_t count)
1119{
1120 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1121 struct i2c_client *client = to_i2c_client(dev);
1122 struct adt7462_data *data = i2c_get_clientdata(client);
1123 long temp;
1124
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001125 if (kstrtol(buf, 10, &temp))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001126 return -EINVAL;
1127
Guenter Roeck2a844c12013-01-09 08:09:34 -08001128 temp = clamp_val(temp, 0, 255);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001129
1130 mutex_lock(&data->lock);
1131 data->pwm[attr->index] = temp;
1132 i2c_smbus_write_byte_data(client, ADT7462_REG_PWM(attr->index), temp);
1133 mutex_unlock(&data->lock);
1134
1135 return count;
1136}
1137
1138static ssize_t show_pwm_max(struct device *dev,
1139 struct device_attribute *devattr,
1140 char *buf)
1141{
1142 struct adt7462_data *data = adt7462_update_device(dev);
1143 return sprintf(buf, "%d\n", data->pwm_max);
1144}
1145
1146static ssize_t set_pwm_max(struct device *dev,
1147 struct device_attribute *devattr,
1148 const char *buf,
1149 size_t count)
1150{
1151 struct i2c_client *client = to_i2c_client(dev);
1152 struct adt7462_data *data = i2c_get_clientdata(client);
1153 long temp;
1154
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001155 if (kstrtol(buf, 10, &temp))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001156 return -EINVAL;
1157
Guenter Roeck2a844c12013-01-09 08:09:34 -08001158 temp = clamp_val(temp, 0, 255);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001159
1160 mutex_lock(&data->lock);
1161 data->pwm_max = temp;
1162 i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_MAX, temp);
1163 mutex_unlock(&data->lock);
1164
1165 return count;
1166}
1167
1168static ssize_t show_pwm_min(struct device *dev,
1169 struct device_attribute *devattr,
1170 char *buf)
1171{
1172 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1173 struct adt7462_data *data = adt7462_update_device(dev);
1174 return sprintf(buf, "%d\n", data->pwm_min[attr->index]);
1175}
1176
1177static ssize_t set_pwm_min(struct device *dev,
1178 struct device_attribute *devattr,
1179 const char *buf,
1180 size_t count)
1181{
1182 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1183 struct i2c_client *client = to_i2c_client(dev);
1184 struct adt7462_data *data = i2c_get_clientdata(client);
1185 long temp;
1186
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001187 if (kstrtol(buf, 10, &temp))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001188 return -EINVAL;
1189
Guenter Roeck2a844c12013-01-09 08:09:34 -08001190 temp = clamp_val(temp, 0, 255);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001191
1192 mutex_lock(&data->lock);
1193 data->pwm_min[attr->index] = temp;
1194 i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_MIN(attr->index),
1195 temp);
1196 mutex_unlock(&data->lock);
1197
1198 return count;
1199}
1200
1201static ssize_t show_pwm_hyst(struct device *dev,
1202 struct device_attribute *devattr,
1203 char *buf)
1204{
1205 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1206 struct adt7462_data *data = adt7462_update_device(dev);
1207 return sprintf(buf, "%d\n", 1000 *
1208 (data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK));
1209}
1210
1211static ssize_t set_pwm_hyst(struct device *dev,
1212 struct device_attribute *devattr,
1213 const char *buf,
1214 size_t count)
1215{
1216 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1217 struct i2c_client *client = to_i2c_client(dev);
1218 struct adt7462_data *data = i2c_get_clientdata(client);
1219 long temp;
1220
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001221 if (kstrtol(buf, 10, &temp))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001222 return -EINVAL;
1223
Darrick J. Wong8f8c1fb2009-01-06 14:41:31 -08001224 temp = DIV_ROUND_CLOSEST(temp, 1000);
Guenter Roeck2a844c12013-01-09 08:09:34 -08001225 temp = clamp_val(temp, 0, 15);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001226
1227 /* package things up */
1228 temp &= ADT7462_PWM_HYST_MASK;
1229 temp |= data->pwm_trange[attr->index] & ADT7462_PWM_RANGE_MASK;
1230
1231 mutex_lock(&data->lock);
1232 data->pwm_trange[attr->index] = temp;
1233 i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TRANGE(attr->index),
1234 temp);
1235 mutex_unlock(&data->lock);
1236
1237 return count;
1238}
1239
1240static ssize_t show_pwm_tmax(struct device *dev,
1241 struct device_attribute *devattr,
1242 char *buf)
1243{
1244 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1245 struct adt7462_data *data = adt7462_update_device(dev);
1246
1247 /* tmax = tmin + trange */
1248 int trange = trange_values[data->pwm_trange[attr->index] >>
1249 ADT7462_PWM_RANGE_SHIFT];
1250 int tmin = (data->pwm_tmin[attr->index] - 64) * 1000;
1251
1252 return sprintf(buf, "%d\n", tmin + trange);
1253}
1254
1255static ssize_t set_pwm_tmax(struct device *dev,
1256 struct device_attribute *devattr,
1257 const char *buf,
1258 size_t count)
1259{
1260 int temp;
1261 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1262 struct i2c_client *client = to_i2c_client(dev);
1263 struct adt7462_data *data = i2c_get_clientdata(client);
1264 int tmin, trange_value;
1265 long trange;
1266
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001267 if (kstrtol(buf, 10, &trange))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001268 return -EINVAL;
1269
1270 /* trange = tmax - tmin */
1271 tmin = (data->pwm_tmin[attr->index] - 64) * 1000;
1272 trange_value = find_trange_value(trange - tmin);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001273 if (trange_value < 0)
Guenter Roeckbb34c0d2013-09-13 10:38:09 -07001274 return trange_value;
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001275
1276 temp = trange_value << ADT7462_PWM_RANGE_SHIFT;
1277 temp |= data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK;
1278
1279 mutex_lock(&data->lock);
1280 data->pwm_trange[attr->index] = temp;
1281 i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TRANGE(attr->index),
1282 temp);
1283 mutex_unlock(&data->lock);
1284
1285 return count;
1286}
1287
1288static ssize_t show_pwm_tmin(struct device *dev,
1289 struct device_attribute *devattr,
1290 char *buf)
1291{
1292 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1293 struct adt7462_data *data = adt7462_update_device(dev);
1294 return sprintf(buf, "%d\n", 1000 * (data->pwm_tmin[attr->index] - 64));
1295}
1296
1297static ssize_t set_pwm_tmin(struct device *dev,
1298 struct device_attribute *devattr,
1299 const char *buf,
1300 size_t count)
1301{
1302 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1303 struct i2c_client *client = to_i2c_client(dev);
1304 struct adt7462_data *data = i2c_get_clientdata(client);
1305 long temp;
1306
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001307 if (kstrtol(buf, 10, &temp))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001308 return -EINVAL;
1309
Darrick J. Wong8f8c1fb2009-01-06 14:41:31 -08001310 temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001311 temp = clamp_val(temp, 0, 255);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001312
1313 mutex_lock(&data->lock);
1314 data->pwm_tmin[attr->index] = temp;
1315 i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TMIN(attr->index),
1316 temp);
1317 mutex_unlock(&data->lock);
1318
1319 return count;
1320}
1321
1322static ssize_t show_pwm_auto(struct device *dev,
1323 struct device_attribute *devattr,
1324 char *buf)
1325{
1326 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1327 struct adt7462_data *data = adt7462_update_device(dev);
1328 int cfg = data->pwm_cfg[attr->index] >> ADT7462_PWM_CHANNEL_SHIFT;
1329
1330 switch (cfg) {
1331 case 4: /* off */
1332 return sprintf(buf, "0\n");
1333 case 7: /* manual */
1334 return sprintf(buf, "1\n");
1335 default: /* automatic */
1336 return sprintf(buf, "2\n");
1337 }
1338}
1339
1340static void set_pwm_channel(struct i2c_client *client,
1341 struct adt7462_data *data,
1342 int which,
1343 int value)
1344{
1345 int temp = data->pwm_cfg[which] & ~ADT7462_PWM_CHANNEL_MASK;
1346 temp |= value << ADT7462_PWM_CHANNEL_SHIFT;
1347
1348 mutex_lock(&data->lock);
1349 data->pwm_cfg[which] = temp;
1350 i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_CFG(which), temp);
1351 mutex_unlock(&data->lock);
1352}
1353
1354static ssize_t set_pwm_auto(struct device *dev,
1355 struct device_attribute *devattr,
1356 const char *buf,
1357 size_t count)
1358{
1359 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1360 struct i2c_client *client = to_i2c_client(dev);
1361 struct adt7462_data *data = i2c_get_clientdata(client);
1362 long temp;
1363
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001364 if (kstrtol(buf, 10, &temp))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001365 return -EINVAL;
1366
1367 switch (temp) {
1368 case 0: /* off */
1369 set_pwm_channel(client, data, attr->index, 4);
1370 return count;
1371 case 1: /* manual */
1372 set_pwm_channel(client, data, attr->index, 7);
1373 return count;
1374 default:
1375 return -EINVAL;
1376 }
1377}
1378
1379static ssize_t show_pwm_auto_temp(struct device *dev,
1380 struct device_attribute *devattr,
1381 char *buf)
1382{
1383 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1384 struct adt7462_data *data = adt7462_update_device(dev);
1385 int channel = data->pwm_cfg[attr->index] >> ADT7462_PWM_CHANNEL_SHIFT;
1386
1387 switch (channel) {
1388 case 0: /* temp[1234] only */
1389 case 1:
1390 case 2:
1391 case 3:
1392 return sprintf(buf, "%d\n", (1 << channel));
1393 case 5: /* temp1 & temp4 */
1394 return sprintf(buf, "9\n");
1395 case 6:
1396 return sprintf(buf, "15\n");
1397 default:
1398 return sprintf(buf, "0\n");
1399 }
1400}
1401
1402static int cvt_auto_temp(int input)
1403{
1404 if (input == 0xF)
1405 return 6;
1406 if (input == 0x9)
1407 return 5;
1408 if (input < 1 || !is_power_of_2(input))
1409 return -EINVAL;
1410 return ilog2(input);
1411}
1412
1413static ssize_t set_pwm_auto_temp(struct device *dev,
1414 struct device_attribute *devattr,
1415 const char *buf,
1416 size_t count)
1417{
1418 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1419 struct i2c_client *client = to_i2c_client(dev);
1420 struct adt7462_data *data = i2c_get_clientdata(client);
1421 long temp;
1422
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001423 if (kstrtol(buf, 10, &temp))
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001424 return -EINVAL;
1425
1426 temp = cvt_auto_temp(temp);
1427 if (temp < 0)
1428 return temp;
1429
1430 set_pwm_channel(client, data, attr->index, temp);
1431
1432 return count;
1433}
1434
1435static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
1436 set_temp_max, 0);
1437static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
1438 set_temp_max, 1);
1439static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max,
1440 set_temp_max, 2);
1441static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max,
1442 set_temp_max, 3);
1443
1444static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min,
1445 set_temp_min, 0);
1446static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min,
1447 set_temp_min, 1);
1448static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min,
1449 set_temp_min, 2);
1450static SENSOR_DEVICE_ATTR(temp4_min, S_IWUSR | S_IRUGO, show_temp_min,
1451 set_temp_min, 3);
1452
1453static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
1454static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
1455static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
1456static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
1457
1458static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_temp_label, NULL, 0);
1459static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_temp_label, NULL, 1);
1460static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, show_temp_label, NULL, 2);
1461static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, show_temp_label, NULL, 3);
1462
1463static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
1464 ADT7462_ALARM1 | ADT7462_LT_ALARM);
1465static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
1466 ADT7462_ALARM1 | ADT7462_R1T_ALARM);
1467static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
1468 ADT7462_ALARM1 | ADT7462_R2T_ALARM);
1469static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL,
1470 ADT7462_ALARM1 | ADT7462_R3T_ALARM);
1471
1472static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_volt_max,
1473 set_volt_max, 0);
1474static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_volt_max,
1475 set_volt_max, 1);
1476static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, show_volt_max,
1477 set_volt_max, 2);
1478static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, show_volt_max,
1479 set_volt_max, 3);
1480static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, show_volt_max,
1481 set_volt_max, 4);
1482static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, show_volt_max,
1483 set_volt_max, 5);
1484static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO, show_volt_max,
1485 set_volt_max, 6);
1486static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO, show_volt_max,
1487 set_volt_max, 7);
1488static SENSOR_DEVICE_ATTR(in9_max, S_IWUSR | S_IRUGO, show_volt_max,
1489 set_volt_max, 8);
1490static SENSOR_DEVICE_ATTR(in10_max, S_IWUSR | S_IRUGO, show_volt_max,
1491 set_volt_max, 9);
1492static SENSOR_DEVICE_ATTR(in11_max, S_IWUSR | S_IRUGO, show_volt_max,
1493 set_volt_max, 10);
1494static SENSOR_DEVICE_ATTR(in12_max, S_IWUSR | S_IRUGO, show_volt_max,
1495 set_volt_max, 11);
1496static SENSOR_DEVICE_ATTR(in13_max, S_IWUSR | S_IRUGO, show_volt_max,
1497 set_volt_max, 12);
1498
1499static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_volt_min,
1500 set_volt_min, 0);
1501static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_volt_min,
1502 set_volt_min, 1);
1503static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, show_volt_min,
1504 set_volt_min, 2);
1505static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, show_volt_min,
1506 set_volt_min, 3);
1507static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, show_volt_min,
1508 set_volt_min, 4);
1509static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, show_volt_min,
1510 set_volt_min, 5);
1511static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO, show_volt_min,
1512 set_volt_min, 6);
1513static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO, show_volt_min,
1514 set_volt_min, 7);
1515static SENSOR_DEVICE_ATTR(in9_min, S_IWUSR | S_IRUGO, show_volt_min,
1516 set_volt_min, 8);
1517static SENSOR_DEVICE_ATTR(in10_min, S_IWUSR | S_IRUGO, show_volt_min,
1518 set_volt_min, 9);
1519static SENSOR_DEVICE_ATTR(in11_min, S_IWUSR | S_IRUGO, show_volt_min,
1520 set_volt_min, 10);
1521static SENSOR_DEVICE_ATTR(in12_min, S_IWUSR | S_IRUGO, show_volt_min,
1522 set_volt_min, 11);
1523static SENSOR_DEVICE_ATTR(in13_min, S_IWUSR | S_IRUGO, show_volt_min,
1524 set_volt_min, 12);
1525
1526static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 0);
1527static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 1);
1528static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_voltage, NULL, 2);
1529static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_voltage, NULL, 3);
1530static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL, 4);
1531static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 5);
1532static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 6);
1533static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_voltage, NULL, 7);
1534static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_voltage, NULL, 8);
1535static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_voltage, NULL, 9);
1536static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_voltage, NULL, 10);
1537static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_voltage, NULL, 11);
1538static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, show_voltage, NULL, 12);
1539
1540static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, show_voltage_label, NULL, 0);
1541static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO, show_voltage_label, NULL, 1);
1542static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_voltage_label, NULL, 2);
1543static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO, show_voltage_label, NULL, 3);
1544static SENSOR_DEVICE_ATTR(in5_label, S_IRUGO, show_voltage_label, NULL, 4);
1545static SENSOR_DEVICE_ATTR(in6_label, S_IRUGO, show_voltage_label, NULL, 5);
1546static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_voltage_label, NULL, 6);
1547static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_voltage_label, NULL, 7);
1548static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_voltage_label, NULL, 8);
1549static SENSOR_DEVICE_ATTR(in10_label, S_IRUGO, show_voltage_label, NULL, 9);
1550static SENSOR_DEVICE_ATTR(in11_label, S_IRUGO, show_voltage_label, NULL, 10);
1551static SENSOR_DEVICE_ATTR(in12_label, S_IRUGO, show_voltage_label, NULL, 11);
1552static SENSOR_DEVICE_ATTR(in13_label, S_IRUGO, show_voltage_label, NULL, 12);
1553
1554static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL,
1555 ADT7462_ALARM2 | ADT7462_V0_ALARM);
1556static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL,
1557 ADT7462_ALARM2 | ADT7462_V7_ALARM);
1558static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL,
1559 ADT7462_ALARM2 | ADT7462_V2_ALARM);
1560static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL,
1561 ADT7462_ALARM2 | ADT7462_V6_ALARM);
1562static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL,
1563 ADT7462_ALARM2 | ADT7462_V5_ALARM);
1564static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL,
1565 ADT7462_ALARM2 | ADT7462_V4_ALARM);
1566static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL,
1567 ADT7462_ALARM2 | ADT7462_V3_ALARM);
1568static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL,
1569 ADT7462_ALARM2 | ADT7462_V1_ALARM);
1570static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL,
1571 ADT7462_ALARM3 | ADT7462_V10_ALARM);
1572static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL,
1573 ADT7462_ALARM3 | ADT7462_V9_ALARM);
1574static SENSOR_DEVICE_ATTR(in11_alarm, S_IRUGO, show_alarm, NULL,
1575 ADT7462_ALARM3 | ADT7462_V8_ALARM);
1576static SENSOR_DEVICE_ATTR(in12_alarm, S_IRUGO, show_alarm, NULL,
1577 ADT7462_ALARM3 | ADT7462_V11_ALARM);
1578static SENSOR_DEVICE_ATTR(in13_alarm, S_IRUGO, show_alarm, NULL,
1579 ADT7462_ALARM3 | ADT7462_V12_ALARM);
1580
1581static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
1582 set_fan_min, 0);
1583static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
1584 set_fan_min, 1);
1585static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min,
1586 set_fan_min, 2);
1587static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
1588 set_fan_min, 3);
1589static SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min,
1590 set_fan_min, 4);
1591static SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO, show_fan_min,
1592 set_fan_min, 5);
1593static SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO, show_fan_min,
1594 set_fan_min, 6);
1595static SENSOR_DEVICE_ATTR(fan8_min, S_IWUSR | S_IRUGO, show_fan_min,
1596 set_fan_min, 7);
1597
1598static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
1599static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
1600static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
1601static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
1602static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4);
1603static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 5);
1604static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 6);
1605static SENSOR_DEVICE_ATTR(fan8_input, S_IRUGO, show_fan, NULL, 7);
1606
1607static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL,
1608 ADT7462_ALARM4 | ADT7462_F0_ALARM);
1609static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL,
1610 ADT7462_ALARM4 | ADT7462_F1_ALARM);
1611static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL,
1612 ADT7462_ALARM4 | ADT7462_F2_ALARM);
1613static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL,
1614 ADT7462_ALARM4 | ADT7462_F3_ALARM);
1615static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL,
1616 ADT7462_ALARM4 | ADT7462_F4_ALARM);
1617static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL,
1618 ADT7462_ALARM4 | ADT7462_F5_ALARM);
1619static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL,
1620 ADT7462_ALARM4 | ADT7462_F6_ALARM);
1621static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO, show_alarm, NULL,
1622 ADT7462_ALARM4 | ADT7462_F7_ALARM);
1623
1624static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO,
1625 show_force_pwm_max, set_force_pwm_max, 0);
1626
1627static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0);
1628static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1);
1629static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2);
1630static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 3);
1631
1632static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO,
1633 show_pwm_min, set_pwm_min, 0);
1634static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO,
1635 show_pwm_min, set_pwm_min, 1);
1636static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO,
1637 show_pwm_min, set_pwm_min, 2);
1638static SENSOR_DEVICE_ATTR(pwm4_auto_point1_pwm, S_IWUSR | S_IRUGO,
1639 show_pwm_min, set_pwm_min, 3);
1640
1641static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO,
1642 show_pwm_max, set_pwm_max, 0);
1643static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO,
1644 show_pwm_max, set_pwm_max, 1);
1645static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO,
1646 show_pwm_max, set_pwm_max, 2);
1647static SENSOR_DEVICE_ATTR(pwm4_auto_point2_pwm, S_IWUSR | S_IRUGO,
1648 show_pwm_max, set_pwm_max, 3);
1649
1650static SENSOR_DEVICE_ATTR(temp1_auto_point1_hyst, S_IWUSR | S_IRUGO,
1651 show_pwm_hyst, set_pwm_hyst, 0);
1652static SENSOR_DEVICE_ATTR(temp2_auto_point1_hyst, S_IWUSR | S_IRUGO,
1653 show_pwm_hyst, set_pwm_hyst, 1);
1654static SENSOR_DEVICE_ATTR(temp3_auto_point1_hyst, S_IWUSR | S_IRUGO,
1655 show_pwm_hyst, set_pwm_hyst, 2);
1656static SENSOR_DEVICE_ATTR(temp4_auto_point1_hyst, S_IWUSR | S_IRUGO,
1657 show_pwm_hyst, set_pwm_hyst, 3);
1658
1659static SENSOR_DEVICE_ATTR(temp1_auto_point2_hyst, S_IWUSR | S_IRUGO,
1660 show_pwm_hyst, set_pwm_hyst, 0);
1661static SENSOR_DEVICE_ATTR(temp2_auto_point2_hyst, S_IWUSR | S_IRUGO,
1662 show_pwm_hyst, set_pwm_hyst, 1);
1663static SENSOR_DEVICE_ATTR(temp3_auto_point2_hyst, S_IWUSR | S_IRUGO,
1664 show_pwm_hyst, set_pwm_hyst, 2);
1665static SENSOR_DEVICE_ATTR(temp4_auto_point2_hyst, S_IWUSR | S_IRUGO,
1666 show_pwm_hyst, set_pwm_hyst, 3);
1667
1668static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp, S_IWUSR | S_IRUGO,
1669 show_pwm_tmin, set_pwm_tmin, 0);
1670static SENSOR_DEVICE_ATTR(temp2_auto_point1_temp, S_IWUSR | S_IRUGO,
1671 show_pwm_tmin, set_pwm_tmin, 1);
1672static SENSOR_DEVICE_ATTR(temp3_auto_point1_temp, S_IWUSR | S_IRUGO,
1673 show_pwm_tmin, set_pwm_tmin, 2);
1674static SENSOR_DEVICE_ATTR(temp4_auto_point1_temp, S_IWUSR | S_IRUGO,
1675 show_pwm_tmin, set_pwm_tmin, 3);
1676
1677static SENSOR_DEVICE_ATTR(temp1_auto_point2_temp, S_IWUSR | S_IRUGO,
1678 show_pwm_tmax, set_pwm_tmax, 0);
1679static SENSOR_DEVICE_ATTR(temp2_auto_point2_temp, S_IWUSR | S_IRUGO,
1680 show_pwm_tmax, set_pwm_tmax, 1);
1681static SENSOR_DEVICE_ATTR(temp3_auto_point2_temp, S_IWUSR | S_IRUGO,
1682 show_pwm_tmax, set_pwm_tmax, 2);
1683static SENSOR_DEVICE_ATTR(temp4_auto_point2_temp, S_IWUSR | S_IRUGO,
1684 show_pwm_tmax, set_pwm_tmax, 3);
1685
1686static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
1687 set_pwm_auto, 0);
1688static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
1689 set_pwm_auto, 1);
1690static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
1691 set_pwm_auto, 2);
1692static SENSOR_DEVICE_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
1693 set_pwm_auto, 3);
1694
1695static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO,
1696 show_pwm_auto_temp, set_pwm_auto_temp, 0);
1697static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO,
1698 show_pwm_auto_temp, set_pwm_auto_temp, 1);
1699static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO,
1700 show_pwm_auto_temp, set_pwm_auto_temp, 2);
1701static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
1702 show_pwm_auto_temp, set_pwm_auto_temp, 3);
1703
Guenter Roeck724cc332012-01-14 13:16:53 -08001704static struct attribute *adt7462_attr[] = {
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001705 &sensor_dev_attr_temp1_max.dev_attr.attr,
1706 &sensor_dev_attr_temp2_max.dev_attr.attr,
1707 &sensor_dev_attr_temp3_max.dev_attr.attr,
1708 &sensor_dev_attr_temp4_max.dev_attr.attr,
1709
1710 &sensor_dev_attr_temp1_min.dev_attr.attr,
1711 &sensor_dev_attr_temp2_min.dev_attr.attr,
1712 &sensor_dev_attr_temp3_min.dev_attr.attr,
1713 &sensor_dev_attr_temp4_min.dev_attr.attr,
1714
1715 &sensor_dev_attr_temp1_input.dev_attr.attr,
1716 &sensor_dev_attr_temp2_input.dev_attr.attr,
1717 &sensor_dev_attr_temp3_input.dev_attr.attr,
1718 &sensor_dev_attr_temp4_input.dev_attr.attr,
1719
1720 &sensor_dev_attr_temp1_label.dev_attr.attr,
1721 &sensor_dev_attr_temp2_label.dev_attr.attr,
1722 &sensor_dev_attr_temp3_label.dev_attr.attr,
1723 &sensor_dev_attr_temp4_label.dev_attr.attr,
1724
1725 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1726 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1727 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1728 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
1729
1730 &sensor_dev_attr_in1_max.dev_attr.attr,
1731 &sensor_dev_attr_in2_max.dev_attr.attr,
1732 &sensor_dev_attr_in3_max.dev_attr.attr,
1733 &sensor_dev_attr_in4_max.dev_attr.attr,
1734 &sensor_dev_attr_in5_max.dev_attr.attr,
1735 &sensor_dev_attr_in6_max.dev_attr.attr,
1736 &sensor_dev_attr_in7_max.dev_attr.attr,
1737 &sensor_dev_attr_in8_max.dev_attr.attr,
1738 &sensor_dev_attr_in9_max.dev_attr.attr,
1739 &sensor_dev_attr_in10_max.dev_attr.attr,
1740 &sensor_dev_attr_in11_max.dev_attr.attr,
1741 &sensor_dev_attr_in12_max.dev_attr.attr,
1742 &sensor_dev_attr_in13_max.dev_attr.attr,
1743
1744 &sensor_dev_attr_in1_min.dev_attr.attr,
1745 &sensor_dev_attr_in2_min.dev_attr.attr,
1746 &sensor_dev_attr_in3_min.dev_attr.attr,
1747 &sensor_dev_attr_in4_min.dev_attr.attr,
1748 &sensor_dev_attr_in5_min.dev_attr.attr,
1749 &sensor_dev_attr_in6_min.dev_attr.attr,
1750 &sensor_dev_attr_in7_min.dev_attr.attr,
1751 &sensor_dev_attr_in8_min.dev_attr.attr,
1752 &sensor_dev_attr_in9_min.dev_attr.attr,
1753 &sensor_dev_attr_in10_min.dev_attr.attr,
1754 &sensor_dev_attr_in11_min.dev_attr.attr,
1755 &sensor_dev_attr_in12_min.dev_attr.attr,
1756 &sensor_dev_attr_in13_min.dev_attr.attr,
1757
1758 &sensor_dev_attr_in1_input.dev_attr.attr,
1759 &sensor_dev_attr_in2_input.dev_attr.attr,
1760 &sensor_dev_attr_in3_input.dev_attr.attr,
1761 &sensor_dev_attr_in4_input.dev_attr.attr,
1762 &sensor_dev_attr_in5_input.dev_attr.attr,
1763 &sensor_dev_attr_in6_input.dev_attr.attr,
1764 &sensor_dev_attr_in7_input.dev_attr.attr,
1765 &sensor_dev_attr_in8_input.dev_attr.attr,
1766 &sensor_dev_attr_in9_input.dev_attr.attr,
1767 &sensor_dev_attr_in10_input.dev_attr.attr,
1768 &sensor_dev_attr_in11_input.dev_attr.attr,
1769 &sensor_dev_attr_in12_input.dev_attr.attr,
1770 &sensor_dev_attr_in13_input.dev_attr.attr,
1771
1772 &sensor_dev_attr_in1_label.dev_attr.attr,
1773 &sensor_dev_attr_in2_label.dev_attr.attr,
1774 &sensor_dev_attr_in3_label.dev_attr.attr,
1775 &sensor_dev_attr_in4_label.dev_attr.attr,
1776 &sensor_dev_attr_in5_label.dev_attr.attr,
1777 &sensor_dev_attr_in6_label.dev_attr.attr,
1778 &sensor_dev_attr_in7_label.dev_attr.attr,
1779 &sensor_dev_attr_in8_label.dev_attr.attr,
1780 &sensor_dev_attr_in9_label.dev_attr.attr,
1781 &sensor_dev_attr_in10_label.dev_attr.attr,
1782 &sensor_dev_attr_in11_label.dev_attr.attr,
1783 &sensor_dev_attr_in12_label.dev_attr.attr,
1784 &sensor_dev_attr_in13_label.dev_attr.attr,
1785
1786 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1787 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1788 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1789 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1790 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1791 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1792 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1793 &sensor_dev_attr_in8_alarm.dev_attr.attr,
1794 &sensor_dev_attr_in9_alarm.dev_attr.attr,
1795 &sensor_dev_attr_in10_alarm.dev_attr.attr,
1796 &sensor_dev_attr_in11_alarm.dev_attr.attr,
1797 &sensor_dev_attr_in12_alarm.dev_attr.attr,
1798 &sensor_dev_attr_in13_alarm.dev_attr.attr,
1799
1800 &sensor_dev_attr_fan1_min.dev_attr.attr,
1801 &sensor_dev_attr_fan2_min.dev_attr.attr,
1802 &sensor_dev_attr_fan3_min.dev_attr.attr,
1803 &sensor_dev_attr_fan4_min.dev_attr.attr,
1804 &sensor_dev_attr_fan5_min.dev_attr.attr,
1805 &sensor_dev_attr_fan6_min.dev_attr.attr,
1806 &sensor_dev_attr_fan7_min.dev_attr.attr,
1807 &sensor_dev_attr_fan8_min.dev_attr.attr,
1808
1809 &sensor_dev_attr_fan1_input.dev_attr.attr,
1810 &sensor_dev_attr_fan2_input.dev_attr.attr,
1811 &sensor_dev_attr_fan3_input.dev_attr.attr,
1812 &sensor_dev_attr_fan4_input.dev_attr.attr,
1813 &sensor_dev_attr_fan5_input.dev_attr.attr,
1814 &sensor_dev_attr_fan6_input.dev_attr.attr,
1815 &sensor_dev_attr_fan7_input.dev_attr.attr,
1816 &sensor_dev_attr_fan8_input.dev_attr.attr,
1817
1818 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1819 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1820 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1821 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1822 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1823 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
1824 &sensor_dev_attr_fan7_alarm.dev_attr.attr,
1825 &sensor_dev_attr_fan8_alarm.dev_attr.attr,
1826
1827 &sensor_dev_attr_force_pwm_max.dev_attr.attr,
1828 &sensor_dev_attr_pwm1.dev_attr.attr,
1829 &sensor_dev_attr_pwm2.dev_attr.attr,
1830 &sensor_dev_attr_pwm3.dev_attr.attr,
1831 &sensor_dev_attr_pwm4.dev_attr.attr,
1832
1833 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1834 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1835 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1836 &sensor_dev_attr_pwm4_auto_point1_pwm.dev_attr.attr,
1837
1838 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1839 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1840 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1841 &sensor_dev_attr_pwm4_auto_point2_pwm.dev_attr.attr,
1842
1843 &sensor_dev_attr_temp1_auto_point1_hyst.dev_attr.attr,
1844 &sensor_dev_attr_temp2_auto_point1_hyst.dev_attr.attr,
1845 &sensor_dev_attr_temp3_auto_point1_hyst.dev_attr.attr,
1846 &sensor_dev_attr_temp4_auto_point1_hyst.dev_attr.attr,
1847
1848 &sensor_dev_attr_temp1_auto_point2_hyst.dev_attr.attr,
1849 &sensor_dev_attr_temp2_auto_point2_hyst.dev_attr.attr,
1850 &sensor_dev_attr_temp3_auto_point2_hyst.dev_attr.attr,
1851 &sensor_dev_attr_temp4_auto_point2_hyst.dev_attr.attr,
1852
1853 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
1854 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
1855 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
1856 &sensor_dev_attr_temp4_auto_point1_temp.dev_attr.attr,
1857
1858 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
1859 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
1860 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
1861 &sensor_dev_attr_temp4_auto_point2_temp.dev_attr.attr,
1862
1863 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1864 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1865 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1866 &sensor_dev_attr_pwm4_enable.dev_attr.attr,
1867
1868 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
1869 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1870 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
1871 &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr,
1872 NULL
1873};
1874
1875/* Return 0 if detection is successful, -ENODEV otherwise */
Jean Delvare310ec792009-12-14 21:17:23 +01001876static int adt7462_detect(struct i2c_client *client,
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001877 struct i2c_board_info *info)
1878{
1879 struct i2c_adapter *adapter = client->adapter;
Jean Delvare52df6442009-12-09 20:35:57 +01001880 int vendor, device, revision;
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001881
1882 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1883 return -ENODEV;
1884
Jean Delvare52df6442009-12-09 20:35:57 +01001885 vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR);
1886 if (vendor != ADT7462_VENDOR)
1887 return -ENODEV;
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001888
Jean Delvare52df6442009-12-09 20:35:57 +01001889 device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE);
1890 if (device != ADT7462_DEVICE)
1891 return -ENODEV;
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001892
Jean Delvare52df6442009-12-09 20:35:57 +01001893 revision = i2c_smbus_read_byte_data(client, ADT7462_REG_REVISION);
1894 if (revision != ADT7462_REVISION)
1895 return -ENODEV;
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001896
1897 strlcpy(info->type, "adt7462", I2C_NAME_SIZE);
1898
1899 return 0;
1900}
1901
1902static int adt7462_probe(struct i2c_client *client,
1903 const struct i2c_device_id *id)
1904{
1905 struct adt7462_data *data;
1906 int err;
1907
Guenter Roeck08808302012-06-02 09:58:01 -07001908 data = devm_kzalloc(&client->dev, sizeof(struct adt7462_data),
1909 GFP_KERNEL);
1910 if (!data)
1911 return -ENOMEM;
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001912
1913 i2c_set_clientdata(client, data);
1914 mutex_init(&data->lock);
1915
1916 dev_info(&client->dev, "%s chip found\n", client->name);
1917
1918 /* Register sysfs hooks */
1919 data->attrs.attrs = adt7462_attr;
1920 err = sysfs_create_group(&client->dev.kobj, &data->attrs);
1921 if (err)
Guenter Roeck08808302012-06-02 09:58:01 -07001922 return err;
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001923
1924 data->hwmon_dev = hwmon_device_register(&client->dev);
1925 if (IS_ERR(data->hwmon_dev)) {
1926 err = PTR_ERR(data->hwmon_dev);
1927 goto exit_remove;
1928 }
1929
1930 return 0;
1931
1932exit_remove:
1933 sysfs_remove_group(&client->dev.kobj, &data->attrs);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001934 return err;
1935}
1936
1937static int adt7462_remove(struct i2c_client *client)
1938{
1939 struct adt7462_data *data = i2c_get_clientdata(client);
1940
1941 hwmon_device_unregister(data->hwmon_dev);
1942 sysfs_remove_group(&client->dev.kobj, &data->attrs);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001943 return 0;
1944}
1945
Axel Lina2cc2422014-07-16 23:09:41 +08001946static const struct i2c_device_id adt7462_id[] = {
1947 { "adt7462", 0 },
1948 { }
1949};
1950MODULE_DEVICE_TABLE(i2c, adt7462_id);
1951
1952static struct i2c_driver adt7462_driver = {
1953 .class = I2C_CLASS_HWMON,
1954 .driver = {
1955 .name = "adt7462",
1956 },
1957 .probe = adt7462_probe,
1958 .remove = adt7462_remove,
1959 .id_table = adt7462_id,
1960 .detect = adt7462_detect,
1961 .address_list = normal_i2c,
1962};
1963
Axel Linf0967ee2012-01-20 15:38:18 +08001964module_i2c_driver(adt7462_driver);
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001965
Darrick J. Wong5407e0512013-08-26 15:42:27 -07001966MODULE_AUTHOR("Darrick J. Wong <darrick.wong@oracle.com>");
Darrick J. Wongc0b4e3a2008-11-12 13:27:03 -08001967MODULE_DESCRIPTION("ADT7462 driver");
1968MODULE_LICENSE("GPL");