1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * w83627hf.c - Part of lm_sensors, Linux kernel modules for hardware
5 * Copyright (c) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>,
6 * Philip Edelbrock <phil@netroedge.com>,
7 * and Mark Studebaker <mdsxyz123@yahoo.com>
8 * Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org>
9 * Copyright (c) 2007 - 1012 Jean Delvare <jdelvare@suse.de>
13 * Supports following chips:
15 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
16 * w83627hf 9 3 2 3 0x20 0x5ca3 no yes(LPC)
17 * w83627thf 7 3 3 3 0x90 0x5ca3 no yes(LPC)
18 * w83637hf 7 3 3 3 0x80 0x5ca3 no yes(LPC)
19 * w83687thf 7 3 3 3 0x90 0x5ca3 no yes(LPC)
20 * w83697hf 8 2 2 2 0x60 0x5ca3 no yes(LPC)
22 * For other winbond chips, and for i2c support in the above chips,
25 * Note: automatic ("cruise") fan control for 697, 637 & 627thf not
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/jiffies.h>
35 #include <linux/platform_device.h>
36 #include <linux/hwmon.h>
37 #include <linux/hwmon-sysfs.h>
38 #include <linux/hwmon-vid.h>
39 #include <linux/err.h>
40 #include <linux/mutex.h>
41 #include <linux/ioport.h>
42 #include <linux/acpi.h>
46 static struct platform_device
*pdev
;
48 #define DRVNAME "w83627hf"
49 enum chips
{ w83627hf
, w83627thf
, w83697hf
, w83637hf
, w83687thf
};
51 struct w83627hf_sio_data
{
56 static u8 force_i2c
= 0x1f;
57 module_param(force_i2c
, byte
, 0);
58 MODULE_PARM_DESC(force_i2c
,
59 "Initialize the i2c address of the sensors");
62 module_param(init
, bool, 0);
63 MODULE_PARM_DESC(init
, "Set to zero to bypass chip initialization");
65 static unsigned short force_id
;
66 module_param(force_id
, ushort
, 0);
67 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
69 /* modified from kernel/include/traps.c */
70 #define DEV 0x07 /* Register: Logical device select */
72 /* logical device numbers for superio_select (below) */
73 #define W83627HF_LD_FDC 0x00
74 #define W83627HF_LD_PRT 0x01
75 #define W83627HF_LD_UART1 0x02
76 #define W83627HF_LD_UART2 0x03
77 #define W83627HF_LD_KBC 0x05
78 #define W83627HF_LD_CIR 0x06 /* w83627hf only */
79 #define W83627HF_LD_GAME 0x07
80 #define W83627HF_LD_MIDI 0x07
81 #define W83627HF_LD_GPIO1 0x07
82 #define W83627HF_LD_GPIO5 0x07 /* w83627thf only */
83 #define W83627HF_LD_GPIO2 0x08
84 #define W83627HF_LD_GPIO3 0x09
85 #define W83627HF_LD_GPIO4 0x09 /* w83627thf only */
86 #define W83627HF_LD_ACPI 0x0a
87 #define W83627HF_LD_HWM 0x0b
89 #define DEVID 0x20 /* Register: Device ID */
91 #define W83627THF_GPIO5_EN 0x30 /* w83627thf only */
92 #define W83627THF_GPIO5_IOSR 0xf3 /* w83627thf only */
93 #define W83627THF_GPIO5_DR 0xf4 /* w83627thf only */
95 #define W83687THF_VID_EN 0x29 /* w83687thf only */
96 #define W83687THF_VID_CFG 0xF0 /* w83687thf only */
97 #define W83687THF_VID_DATA 0xF1 /* w83687thf only */
100 superio_outb(struct w83627hf_sio_data
*sio
, int reg
, int val
)
102 outb(reg
, sio
->sioaddr
);
103 outb(val
, sio
->sioaddr
+ 1);
107 superio_inb(struct w83627hf_sio_data
*sio
, int reg
)
109 outb(reg
, sio
->sioaddr
);
110 return inb(sio
->sioaddr
+ 1);
114 superio_select(struct w83627hf_sio_data
*sio
, int ld
)
116 outb(DEV
, sio
->sioaddr
);
117 outb(ld
, sio
->sioaddr
+ 1);
121 superio_enter(struct w83627hf_sio_data
*sio
)
123 if (!request_muxed_region(sio
->sioaddr
, 2, DRVNAME
))
126 outb(0x87, sio
->sioaddr
);
127 outb(0x87, sio
->sioaddr
);
133 superio_exit(struct w83627hf_sio_data
*sio
)
135 outb(0xAA, sio
->sioaddr
);
136 release_region(sio
->sioaddr
, 2);
139 #define W627_DEVID 0x52
140 #define W627THF_DEVID 0x82
141 #define W697_DEVID 0x60
142 #define W637_DEVID 0x70
143 #define W687THF_DEVID 0x85
144 #define WINB_ACT_REG 0x30
145 #define WINB_BASE_REG 0x60
146 /* Constants specified below */
148 /* Alignment of the base address */
149 #define WINB_ALIGNMENT ~7
151 /* Offset & size of I/O region we are interested in */
152 #define WINB_REGION_OFFSET 5
153 #define WINB_REGION_SIZE 2
155 /* Where are the sensors address/data registers relative to the region offset */
156 #define W83781D_ADDR_REG_OFFSET 0
157 #define W83781D_DATA_REG_OFFSET 1
159 /* The W83781D registers */
160 /* The W83782D registers for nr=7,8 are in bank 5 */
161 #define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \
162 (0x554 + (((nr) - 7) * 2)))
163 #define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \
164 (0x555 + (((nr) - 7) * 2)))
165 #define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
168 /* nr:0-2 for fans:1-3 */
169 #define W83627HF_REG_FAN_MIN(nr) (0x3b + (nr))
170 #define W83627HF_REG_FAN(nr) (0x28 + (nr))
172 #define W83627HF_REG_TEMP2_CONFIG 0x152
173 #define W83627HF_REG_TEMP3_CONFIG 0x252
174 /* these are zero-based, unlike config constants above */
175 static const u16 w83627hf_reg_temp
[] = { 0x27, 0x150, 0x250 };
176 static const u16 w83627hf_reg_temp_hyst
[] = { 0x3A, 0x153, 0x253 };
177 static const u16 w83627hf_reg_temp_over
[] = { 0x39, 0x155, 0x255 };
179 #define W83781D_REG_BANK 0x4E
181 #define W83781D_REG_CONFIG 0x40
182 #define W83781D_REG_ALARM1 0x459
183 #define W83781D_REG_ALARM2 0x45A
184 #define W83781D_REG_ALARM3 0x45B
186 #define W83781D_REG_BEEP_CONFIG 0x4D
187 #define W83781D_REG_BEEP_INTS1 0x56
188 #define W83781D_REG_BEEP_INTS2 0x57
189 #define W83781D_REG_BEEP_INTS3 0x453
191 #define W83781D_REG_VID_FANDIV 0x47
193 #define W83781D_REG_CHIPID 0x49
194 #define W83781D_REG_WCHIPID 0x58
195 #define W83781D_REG_CHIPMAN 0x4F
196 #define W83781D_REG_PIN 0x4B
198 #define W83781D_REG_VBAT 0x5D
200 #define W83627HF_REG_PWM1 0x5A
201 #define W83627HF_REG_PWM2 0x5B
203 static const u8 W83627THF_REG_PWM_ENABLE
[] = {
204 0x04, /* FAN 1 mode */
205 0x04, /* FAN 2 mode */
206 0x12, /* FAN AUX mode */
208 static const u8 W83627THF_PWM_ENABLE_SHIFT
[] = { 2, 4, 1 };
210 #define W83627THF_REG_PWM1 0x01 /* 697HF/637HF/687THF too */
211 #define W83627THF_REG_PWM2 0x03 /* 697HF/637HF/687THF too */
212 #define W83627THF_REG_PWM3 0x11 /* 637HF/687THF too */
214 #define W83627THF_REG_VRM_OVT_CFG 0x18 /* 637HF/687THF too */
216 static const u8 regpwm_627hf
[] = { W83627HF_REG_PWM1
, W83627HF_REG_PWM2
};
217 static const u8 regpwm
[] = { W83627THF_REG_PWM1
, W83627THF_REG_PWM2
,
218 W83627THF_REG_PWM3
};
219 #define W836X7HF_REG_PWM(type, nr) (((type) == w83627hf) ? \
220 regpwm_627hf[nr] : regpwm[nr])
222 #define W83627HF_REG_PWM_FREQ 0x5C /* Only for the 627HF */
224 #define W83637HF_REG_PWM_FREQ1 0x00 /* 697HF/687THF too */
225 #define W83637HF_REG_PWM_FREQ2 0x02 /* 697HF/687THF too */
226 #define W83637HF_REG_PWM_FREQ3 0x10 /* 687THF too */
228 static const u8 W83637HF_REG_PWM_FREQ
[] = { W83637HF_REG_PWM_FREQ1
,
229 W83637HF_REG_PWM_FREQ2
,
230 W83637HF_REG_PWM_FREQ3
};
232 #define W83627HF_BASE_PWM_FREQ 46870
234 #define W83781D_REG_I2C_ADDR 0x48
235 #define W83781D_REG_I2C_SUBADDR 0x4A
237 /* Sensor selection */
238 #define W83781D_REG_SCFG1 0x5D
239 static const u8 BIT_SCFG1
[] = { 0x02, 0x04, 0x08 };
240 #define W83781D_REG_SCFG2 0x59
241 static const u8 BIT_SCFG2
[] = { 0x10, 0x20, 0x40 };
242 #define W83781D_DEFAULT_BETA 3435
245 * Conversions. Limit checking is only done on the TO_REG
246 * variants. Note that you should be a bit careful with which arguments
247 * these macros are called: arguments may be evaluated more than once.
248 * Fixing this is just not worth it.
250 #define IN_TO_REG(val) (clamp_val((((val) + 8) / 16), 0, 255))
251 #define IN_FROM_REG(val) ((val) * 16)
253 static inline u8
FAN_TO_REG(long rpm
, int div
)
257 rpm
= clamp_val(rpm
, 1, 1000000);
258 return clamp_val((1350000 + rpm
* div
/ 2) / (rpm
* div
), 1, 254);
261 #define TEMP_MIN (-128000)
262 #define TEMP_MAX ( 127000)
265 * TEMP: 0.001C/bit (-128C to +127C)
266 * REG: 1C/bit, two's complement
268 static u8
TEMP_TO_REG(long temp
)
270 int ntemp
= clamp_val(temp
, TEMP_MIN
, TEMP_MAX
);
271 ntemp
+= (ntemp
< 0 ? -500 : 500);
272 return (u8
)(ntemp
/ 1000);
275 static int TEMP_FROM_REG(u8 reg
)
277 return (s8
)reg
* 1000;
280 #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
282 #define PWM_TO_REG(val) (clamp_val((val), 0, 255))
284 static inline unsigned long pwm_freq_from_reg_627hf(u8 reg
)
287 freq
= W83627HF_BASE_PWM_FREQ
>> reg
;
290 static inline u8
pwm_freq_to_reg_627hf(unsigned long val
)
294 * Only 5 dividers (1 2 4 8 16)
295 * Search for the nearest available frequency
297 for (i
= 0; i
< 4; i
++) {
298 if (val
> (((W83627HF_BASE_PWM_FREQ
>> i
) +
299 (W83627HF_BASE_PWM_FREQ
>> (i
+1))) / 2))
305 static inline unsigned long pwm_freq_from_reg(u8 reg
)
307 /* Clock bit 8 -> 180 kHz or 24 MHz */
308 unsigned long clock
= (reg
& 0x80) ? 180000UL : 24000000UL;
311 /* This should not happen but anyway... */
314 return clock
/ (reg
<< 8);
316 static inline u8
pwm_freq_to_reg(unsigned long val
)
318 /* Minimum divider value is 0x01 and maximum is 0x7F */
319 if (val
>= 93750) /* The highest we can do */
321 if (val
>= 720) /* Use 24 MHz clock */
322 return 24000000UL / (val
<< 8);
323 if (val
< 6) /* The lowest we can do */
325 else /* Use 180 kHz clock */
326 return 0x80 | (180000UL / (val
<< 8));
329 #define BEEP_MASK_FROM_REG(val) ((val) & 0xff7fff)
330 #define BEEP_MASK_TO_REG(val) ((val) & 0xff7fff)
332 #define DIV_FROM_REG(val) (1 << (val))
334 static inline u8
DIV_TO_REG(long val
)
337 val
= clamp_val(val
, 1, 128) >> 1;
338 for (i
= 0; i
< 7; i
++) {
347 * For each registered chip, we need to keep some data in memory.
348 * The structure is dynamically allocated.
350 struct w83627hf_data
{
353 struct device
*hwmon_dev
;
357 struct mutex update_lock
;
358 bool valid
; /* true if following fields are valid */
359 unsigned long last_updated
; /* In jiffies */
361 u8 in
[9]; /* Register value */
362 u8 in_max
[9]; /* Register value */
363 u8 in_min
[9]; /* Register value */
364 u8 fan
[3]; /* Register value */
365 u8 fan_min
[3]; /* Register value */
366 u16 temp
[3]; /* Register value */
367 u16 temp_max
[3]; /* Register value */
368 u16 temp_max_hyst
[3]; /* Register value */
369 u8 fan_div
[3]; /* Register encoding, shifted right */
370 u8 vid
; /* Register encoding, combined */
371 u32 alarms
; /* Register encoding, combined */
372 u32 beep_mask
; /* Register encoding, combined */
373 u8 pwm
[3]; /* Register value */
374 u8 pwm_enable
[3]; /* 1 = manual
375 * 2 = thermal cruise (also called SmartFan I)
376 * 3 = fan speed cruise
378 u8 pwm_freq
[3]; /* Register value */
379 u16 sens
[3]; /* 1 = pentium diode; 2 = 3904 diode;
383 u8 vrm_ovt
; /* Register value, 627THF/637HF/687THF only */
386 /* Remember extra register values over suspend/resume */
392 /* Registers 0x50-0x5f are banked */
393 static inline void w83627hf_set_bank(struct w83627hf_data
*data
, u16 reg
)
395 if ((reg
& 0x00f0) == 0x50) {
396 outb_p(W83781D_REG_BANK
, data
->addr
+ W83781D_ADDR_REG_OFFSET
);
397 outb_p(reg
>> 8, data
->addr
+ W83781D_DATA_REG_OFFSET
);
401 /* Not strictly necessary, but play it safe for now */
402 static inline void w83627hf_reset_bank(struct w83627hf_data
*data
, u16 reg
)
405 outb_p(W83781D_REG_BANK
, data
->addr
+ W83781D_ADDR_REG_OFFSET
);
406 outb_p(0, data
->addr
+ W83781D_DATA_REG_OFFSET
);
410 static int w83627hf_read_value(struct w83627hf_data
*data
, u16 reg
)
414 mutex_lock(&data
->lock
);
415 word_sized
= (((reg
& 0xff00) == 0x100)
416 || ((reg
& 0xff00) == 0x200))
417 && (((reg
& 0x00ff) == 0x50)
418 || ((reg
& 0x00ff) == 0x53)
419 || ((reg
& 0x00ff) == 0x55));
420 w83627hf_set_bank(data
, reg
);
421 outb_p(reg
& 0xff, data
->addr
+ W83781D_ADDR_REG_OFFSET
);
422 res
= inb_p(data
->addr
+ W83781D_DATA_REG_OFFSET
);
424 outb_p((reg
& 0xff) + 1,
425 data
->addr
+ W83781D_ADDR_REG_OFFSET
);
427 (res
<< 8) + inb_p(data
->addr
+
428 W83781D_DATA_REG_OFFSET
);
430 w83627hf_reset_bank(data
, reg
);
431 mutex_unlock(&data
->lock
);
435 static int w83627hf_write_value(struct w83627hf_data
*data
, u16 reg
, u16 value
)
439 mutex_lock(&data
->lock
);
440 word_sized
= (((reg
& 0xff00) == 0x100)
441 || ((reg
& 0xff00) == 0x200))
442 && (((reg
& 0x00ff) == 0x53)
443 || ((reg
& 0x00ff) == 0x55));
444 w83627hf_set_bank(data
, reg
);
445 outb_p(reg
& 0xff, data
->addr
+ W83781D_ADDR_REG_OFFSET
);
448 data
->addr
+ W83781D_DATA_REG_OFFSET
);
449 outb_p((reg
& 0xff) + 1,
450 data
->addr
+ W83781D_ADDR_REG_OFFSET
);
453 data
->addr
+ W83781D_DATA_REG_OFFSET
);
454 w83627hf_reset_bank(data
, reg
);
455 mutex_unlock(&data
->lock
);
459 static void w83627hf_update_fan_div(struct w83627hf_data
*data
)
463 reg
= w83627hf_read_value(data
, W83781D_REG_VID_FANDIV
);
464 data
->fan_div
[0] = (reg
>> 4) & 0x03;
465 data
->fan_div
[1] = (reg
>> 6) & 0x03;
466 if (data
->type
!= w83697hf
) {
467 data
->fan_div
[2] = (w83627hf_read_value(data
,
468 W83781D_REG_PIN
) >> 6) & 0x03;
470 reg
= w83627hf_read_value(data
, W83781D_REG_VBAT
);
471 data
->fan_div
[0] |= (reg
>> 3) & 0x04;
472 data
->fan_div
[1] |= (reg
>> 4) & 0x04;
473 if (data
->type
!= w83697hf
)
474 data
->fan_div
[2] |= (reg
>> 5) & 0x04;
477 static struct w83627hf_data
*w83627hf_update_device(struct device
*dev
)
479 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
480 int i
, num_temps
= (data
->type
== w83697hf
) ? 2 : 3;
481 int num_pwms
= (data
->type
== w83697hf
) ? 2 : 3;
483 mutex_lock(&data
->update_lock
);
485 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
487 for (i
= 0; i
<= 8; i
++) {
488 /* skip missing sensors */
489 if (((data
->type
== w83697hf
) && (i
== 1)) ||
490 ((data
->type
!= w83627hf
&& data
->type
!= w83697hf
)
491 && (i
== 5 || i
== 6)))
494 w83627hf_read_value(data
, W83781D_REG_IN(i
));
496 w83627hf_read_value(data
,
497 W83781D_REG_IN_MIN(i
));
499 w83627hf_read_value(data
,
500 W83781D_REG_IN_MAX(i
));
502 for (i
= 0; i
<= 2; i
++) {
504 w83627hf_read_value(data
, W83627HF_REG_FAN(i
));
506 w83627hf_read_value(data
,
507 W83627HF_REG_FAN_MIN(i
));
509 for (i
= 0; i
<= 2; i
++) {
510 u8 tmp
= w83627hf_read_value(data
,
511 W836X7HF_REG_PWM(data
->type
, i
));
512 /* bits 0-3 are reserved in 627THF */
513 if (data
->type
== w83627thf
)
517 (data
->type
== w83627hf
|| data
->type
== w83697hf
))
520 if (data
->type
== w83627hf
) {
521 u8 tmp
= w83627hf_read_value(data
,
522 W83627HF_REG_PWM_FREQ
);
523 data
->pwm_freq
[0] = tmp
& 0x07;
524 data
->pwm_freq
[1] = (tmp
>> 4) & 0x07;
525 } else if (data
->type
!= w83627thf
) {
526 for (i
= 1; i
<= 3; i
++) {
527 data
->pwm_freq
[i
- 1] =
528 w83627hf_read_value(data
,
529 W83637HF_REG_PWM_FREQ
[i
- 1]);
530 if (i
== 2 && (data
->type
== w83697hf
))
534 if (data
->type
!= w83627hf
) {
535 for (i
= 0; i
< num_pwms
; i
++) {
536 u8 tmp
= w83627hf_read_value(data
,
537 W83627THF_REG_PWM_ENABLE
[i
]);
538 data
->pwm_enable
[i
] =
539 ((tmp
>> W83627THF_PWM_ENABLE_SHIFT
[i
])
543 for (i
= 0; i
< num_temps
; i
++) {
544 data
->temp
[i
] = w83627hf_read_value(
545 data
, w83627hf_reg_temp
[i
]);
546 data
->temp_max
[i
] = w83627hf_read_value(
547 data
, w83627hf_reg_temp_over
[i
]);
548 data
->temp_max_hyst
[i
] = w83627hf_read_value(
549 data
, w83627hf_reg_temp_hyst
[i
]);
552 w83627hf_update_fan_div(data
);
555 w83627hf_read_value(data
, W83781D_REG_ALARM1
) |
556 (w83627hf_read_value(data
, W83781D_REG_ALARM2
) << 8) |
557 (w83627hf_read_value(data
, W83781D_REG_ALARM3
) << 16);
558 i
= w83627hf_read_value(data
, W83781D_REG_BEEP_INTS2
);
559 data
->beep_mask
= (i
<< 8) |
560 w83627hf_read_value(data
, W83781D_REG_BEEP_INTS1
) |
561 w83627hf_read_value(data
, W83781D_REG_BEEP_INTS3
) << 16;
562 data
->last_updated
= jiffies
;
566 mutex_unlock(&data
->update_lock
);
572 static int w83627hf_suspend(struct device
*dev
)
574 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
576 mutex_lock(&data
->update_lock
);
577 data
->scfg1
= w83627hf_read_value(data
, W83781D_REG_SCFG1
);
578 data
->scfg2
= w83627hf_read_value(data
, W83781D_REG_SCFG2
);
579 mutex_unlock(&data
->update_lock
);
584 static int w83627hf_resume(struct device
*dev
)
586 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
587 int i
, num_temps
= (data
->type
== w83697hf
) ? 2 : 3;
590 mutex_lock(&data
->update_lock
);
591 for (i
= 0; i
<= 8; i
++) {
592 /* skip missing sensors */
593 if (((data
->type
== w83697hf
) && (i
== 1)) ||
594 ((data
->type
!= w83627hf
&& data
->type
!= w83697hf
)
595 && (i
== 5 || i
== 6)))
597 w83627hf_write_value(data
, W83781D_REG_IN_MAX(i
),
599 w83627hf_write_value(data
, W83781D_REG_IN_MIN(i
),
602 for (i
= 0; i
<= 2; i
++)
603 w83627hf_write_value(data
, W83627HF_REG_FAN_MIN(i
),
605 for (i
= 0; i
< num_temps
; i
++) {
606 w83627hf_write_value(data
, w83627hf_reg_temp_over
[i
],
608 w83627hf_write_value(data
, w83627hf_reg_temp_hyst
[i
],
609 data
->temp_max_hyst
[i
]);
612 /* Fixup BIOS bugs */
613 if (data
->type
== w83627thf
|| data
->type
== w83637hf
||
614 data
->type
== w83687thf
)
615 w83627hf_write_value(data
, W83627THF_REG_VRM_OVT_CFG
,
617 w83627hf_write_value(data
, W83781D_REG_SCFG1
, data
->scfg1
);
618 w83627hf_write_value(data
, W83781D_REG_SCFG2
, data
->scfg2
);
620 /* Force re-reading all values */
622 mutex_unlock(&data
->update_lock
);
627 static const struct dev_pm_ops w83627hf_dev_pm_ops
= {
628 .suspend
= w83627hf_suspend
,
629 .resume
= w83627hf_resume
,
632 #define W83627HF_DEV_PM_OPS (&w83627hf_dev_pm_ops)
634 #define W83627HF_DEV_PM_OPS NULL
635 #endif /* CONFIG_PM */
637 static int w83627thf_read_gpio5(struct platform_device
*pdev
)
639 struct w83627hf_sio_data
*sio_data
= dev_get_platdata(&pdev
->dev
);
642 if (superio_enter(sio_data
)) {
644 * Some other driver reserved the address space for itself.
645 * We don't want to fail driver instantiation because of that,
646 * so display a warning and keep going.
649 "Can not read VID data: Failed to enable SuperIO access\n");
653 superio_select(sio_data
, W83627HF_LD_GPIO5
);
657 /* Make sure these GPIO pins are enabled */
658 if (!(superio_inb(sio_data
, W83627THF_GPIO5_EN
) & (1<<3))) {
659 dev_dbg(&pdev
->dev
, "GPIO5 disabled, no VID function\n");
664 * Make sure the pins are configured for input
665 * There must be at least five (VRM 9), and possibly 6 (VRM 10)
667 sel
= superio_inb(sio_data
, W83627THF_GPIO5_IOSR
) & 0x3f;
668 if ((sel
& 0x1f) != 0x1f) {
669 dev_dbg(&pdev
->dev
, "GPIO5 not configured for VID "
674 dev_info(&pdev
->dev
, "Reading VID from GPIO5\n");
675 res
= superio_inb(sio_data
, W83627THF_GPIO5_DR
) & sel
;
678 superio_exit(sio_data
);
682 static int w83687thf_read_vid(struct platform_device
*pdev
)
684 struct w83627hf_sio_data
*sio_data
= dev_get_platdata(&pdev
->dev
);
687 if (superio_enter(sio_data
)) {
689 * Some other driver reserved the address space for itself.
690 * We don't want to fail driver instantiation because of that,
691 * so display a warning and keep going.
694 "Can not read VID data: Failed to enable SuperIO access\n");
698 superio_select(sio_data
, W83627HF_LD_HWM
);
700 /* Make sure these GPIO pins are enabled */
701 if (!(superio_inb(sio_data
, W83687THF_VID_EN
) & (1 << 2))) {
702 dev_dbg(&pdev
->dev
, "VID disabled, no VID function\n");
706 /* Make sure the pins are configured for input */
707 if (!(superio_inb(sio_data
, W83687THF_VID_CFG
) & (1 << 4))) {
708 dev_dbg(&pdev
->dev
, "VID configured as output, "
709 "no VID function\n");
713 res
= superio_inb(sio_data
, W83687THF_VID_DATA
) & 0x3f;
716 superio_exit(sio_data
);
720 static void w83627hf_init_device(struct platform_device
*pdev
)
722 struct w83627hf_data
*data
= platform_get_drvdata(pdev
);
724 enum chips type
= data
->type
;
727 /* Minimize conflicts with other winbond i2c-only clients... */
728 /* disable i2c subclients... how to disable main i2c client?? */
729 /* force i2c address to relatively uncommon address */
730 if (type
== w83627hf
) {
731 w83627hf_write_value(data
, W83781D_REG_I2C_SUBADDR
, 0x89);
732 w83627hf_write_value(data
, W83781D_REG_I2C_ADDR
, force_i2c
);
735 /* Read VID only once */
736 if (type
== w83627hf
|| type
== w83637hf
) {
737 int lo
= w83627hf_read_value(data
, W83781D_REG_VID_FANDIV
);
738 int hi
= w83627hf_read_value(data
, W83781D_REG_CHIPID
);
739 data
->vid
= (lo
& 0x0f) | ((hi
& 0x01) << 4);
740 } else if (type
== w83627thf
) {
741 data
->vid
= w83627thf_read_gpio5(pdev
);
742 } else if (type
== w83687thf
) {
743 data
->vid
= w83687thf_read_vid(pdev
);
746 /* Read VRM & OVT Config only once */
747 if (type
== w83627thf
|| type
== w83637hf
|| type
== w83687thf
) {
749 w83627hf_read_value(data
, W83627THF_REG_VRM_OVT_CFG
);
752 tmp
= w83627hf_read_value(data
, W83781D_REG_SCFG1
);
753 for (i
= 1; i
<= 3; i
++) {
754 if (!(tmp
& BIT_SCFG1
[i
- 1])) {
755 data
->sens
[i
- 1] = 4;
757 if (w83627hf_read_value
759 W83781D_REG_SCFG2
) & BIT_SCFG2
[i
- 1])
760 data
->sens
[i
- 1] = 1;
762 data
->sens
[i
- 1] = 2;
764 if ((type
== w83697hf
) && (i
== 2))
770 tmp
= w83627hf_read_value(data
, W83627HF_REG_TEMP2_CONFIG
);
772 dev_warn(&pdev
->dev
, "Enabling temp2, readings "
773 "might not make sense\n");
774 w83627hf_write_value(data
, W83627HF_REG_TEMP2_CONFIG
,
779 if (type
!= w83697hf
) {
780 tmp
= w83627hf_read_value(data
,
781 W83627HF_REG_TEMP3_CONFIG
);
783 dev_warn(&pdev
->dev
, "Enabling temp3, "
784 "readings might not make sense\n");
785 w83627hf_write_value(data
,
786 W83627HF_REG_TEMP3_CONFIG
, tmp
& 0xfe);
791 /* Start monitoring */
792 w83627hf_write_value(data
, W83781D_REG_CONFIG
,
793 (w83627hf_read_value(data
,
794 W83781D_REG_CONFIG
) & 0xf7)
797 /* Enable VBAT monitoring if needed */
798 tmp
= w83627hf_read_value(data
, W83781D_REG_VBAT
);
800 w83627hf_write_value(data
, W83781D_REG_VBAT
, tmp
| 0x01);
803 /* use a different set of functions for in0 */
804 static ssize_t
show_in_0(struct w83627hf_data
*data
, char *buf
, u8 reg
)
808 if ((data
->vrm_ovt
& 0x01) &&
809 (w83627thf
== data
->type
|| w83637hf
== data
->type
810 || w83687thf
== data
->type
))
812 /* use VRM9 calculation */
813 in0
= (long)((reg
* 488 + 70000 + 50) / 100);
815 /* use VRM8 (standard) calculation */
816 in0
= (long)IN_FROM_REG(reg
);
818 return sprintf(buf
,"%ld\n", in0
);
821 static ssize_t
in0_input_show(struct device
*dev
,
822 struct device_attribute
*attr
, char *buf
)
824 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
825 return show_in_0(data
, buf
, data
->in
[0]);
827 static DEVICE_ATTR_RO(in0_input
);
829 static ssize_t
in0_min_show(struct device
*dev
, struct device_attribute
*attr
,
832 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
833 return show_in_0(data
, buf
, data
->in_min
[0]);
836 static ssize_t
in0_min_store(struct device
*dev
,
837 struct device_attribute
*attr
, const char *buf
,
840 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
844 err
= kstrtoul(buf
, 10, &val
);
848 mutex_lock(&data
->update_lock
);
850 if ((data
->vrm_ovt
& 0x01) &&
851 (w83627thf
== data
->type
|| w83637hf
== data
->type
852 || w83687thf
== data
->type
))
854 /* use VRM9 calculation */
856 clamp_val(((val
* 100) - 70000 + 244) / 488, 0, 255);
858 /* use VRM8 (standard) calculation */
859 data
->in_min
[0] = IN_TO_REG(val
);
861 w83627hf_write_value(data
, W83781D_REG_IN_MIN(0), data
->in_min
[0]);
862 mutex_unlock(&data
->update_lock
);
866 static DEVICE_ATTR_RW(in0_min
);
868 static ssize_t
in0_max_show(struct device
*dev
, struct device_attribute
*attr
,
871 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
872 return show_in_0(data
, buf
, data
->in_max
[0]);
875 static ssize_t
in0_max_store(struct device
*dev
,
876 struct device_attribute
*attr
, const char *buf
,
879 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
883 err
= kstrtoul(buf
, 10, &val
);
887 mutex_lock(&data
->update_lock
);
889 if ((data
->vrm_ovt
& 0x01) &&
890 (w83627thf
== data
->type
|| w83637hf
== data
->type
891 || w83687thf
== data
->type
))
893 /* use VRM9 calculation */
895 clamp_val(((val
* 100) - 70000 + 244) / 488, 0, 255);
897 /* use VRM8 (standard) calculation */
898 data
->in_max
[0] = IN_TO_REG(val
);
900 w83627hf_write_value(data
, W83781D_REG_IN_MAX(0), data
->in_max
[0]);
901 mutex_unlock(&data
->update_lock
);
905 static DEVICE_ATTR_RW(in0_max
);
908 alarm_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
910 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
911 int bitnr
= to_sensor_dev_attr(attr
)->index
;
912 return sprintf(buf
, "%u\n", (data
->alarms
>> bitnr
) & 1);
915 static SENSOR_DEVICE_ATTR_RO(in0_alarm
, alarm
, 0);
916 static SENSOR_DEVICE_ATTR_RO(in1_alarm
, alarm
, 1);
917 static SENSOR_DEVICE_ATTR_RO(in2_alarm
, alarm
, 2);
918 static SENSOR_DEVICE_ATTR_RO(in3_alarm
, alarm
, 3);
919 static SENSOR_DEVICE_ATTR_RO(in4_alarm
, alarm
, 8);
920 static SENSOR_DEVICE_ATTR_RO(in5_alarm
, alarm
, 9);
921 static SENSOR_DEVICE_ATTR_RO(in6_alarm
, alarm
, 10);
922 static SENSOR_DEVICE_ATTR_RO(in7_alarm
, alarm
, 16);
923 static SENSOR_DEVICE_ATTR_RO(in8_alarm
, alarm
, 17);
924 static SENSOR_DEVICE_ATTR_RO(fan1_alarm
, alarm
, 6);
925 static SENSOR_DEVICE_ATTR_RO(fan2_alarm
, alarm
, 7);
926 static SENSOR_DEVICE_ATTR_RO(fan3_alarm
, alarm
, 11);
927 static SENSOR_DEVICE_ATTR_RO(temp1_alarm
, alarm
, 4);
928 static SENSOR_DEVICE_ATTR_RO(temp2_alarm
, alarm
, 5);
929 static SENSOR_DEVICE_ATTR_RO(temp3_alarm
, alarm
, 13);
932 beep_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
934 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
935 int bitnr
= to_sensor_dev_attr(attr
)->index
;
936 return sprintf(buf
, "%u\n", (data
->beep_mask
>> bitnr
) & 1);
940 beep_store(struct device
*dev
, struct device_attribute
*attr
, const char *buf
,
943 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
944 int bitnr
= to_sensor_dev_attr(attr
)->index
;
949 err
= kstrtoul(buf
, 10, &bit
);
956 mutex_lock(&data
->update_lock
);
958 data
->beep_mask
|= (1 << bitnr
);
960 data
->beep_mask
&= ~(1 << bitnr
);
963 reg
= w83627hf_read_value(data
, W83781D_REG_BEEP_INTS1
);
967 reg
&= ~(1 << bitnr
);
968 w83627hf_write_value(data
, W83781D_REG_BEEP_INTS1
, reg
);
969 } else if (bitnr
< 16) {
970 reg
= w83627hf_read_value(data
, W83781D_REG_BEEP_INTS2
);
972 reg
|= (1 << (bitnr
- 8));
974 reg
&= ~(1 << (bitnr
- 8));
975 w83627hf_write_value(data
, W83781D_REG_BEEP_INTS2
, reg
);
977 reg
= w83627hf_read_value(data
, W83781D_REG_BEEP_INTS3
);
979 reg
|= (1 << (bitnr
- 16));
981 reg
&= ~(1 << (bitnr
- 16));
982 w83627hf_write_value(data
, W83781D_REG_BEEP_INTS3
, reg
);
984 mutex_unlock(&data
->update_lock
);
989 static SENSOR_DEVICE_ATTR_RW(in0_beep
, beep
, 0);
990 static SENSOR_DEVICE_ATTR_RW(in1_beep
, beep
, 1);
991 static SENSOR_DEVICE_ATTR_RW(in2_beep
, beep
, 2);
992 static SENSOR_DEVICE_ATTR_RW(in3_beep
, beep
, 3);
993 static SENSOR_DEVICE_ATTR_RW(in4_beep
, beep
, 8);
994 static SENSOR_DEVICE_ATTR_RW(in5_beep
, beep
, 9);
995 static SENSOR_DEVICE_ATTR_RW(in6_beep
, beep
, 10);
996 static SENSOR_DEVICE_ATTR_RW(in7_beep
, beep
, 16);
997 static SENSOR_DEVICE_ATTR_RW(in8_beep
, beep
, 17);
998 static SENSOR_DEVICE_ATTR_RW(fan1_beep
, beep
, 6);
999 static SENSOR_DEVICE_ATTR_RW(fan2_beep
, beep
, 7);
1000 static SENSOR_DEVICE_ATTR_RW(fan3_beep
, beep
, 11);
1001 static SENSOR_DEVICE_ATTR_RW(temp1_beep
, beep
, 4);
1002 static SENSOR_DEVICE_ATTR_RW(temp2_beep
, beep
, 5);
1003 static SENSOR_DEVICE_ATTR_RW(temp3_beep
, beep
, 13);
1004 static SENSOR_DEVICE_ATTR_RW(beep_enable
, beep
, 15);
1007 in_input_show(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1009 int nr
= to_sensor_dev_attr(devattr
)->index
;
1010 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1011 return sprintf(buf
, "%ld\n", (long)IN_FROM_REG(data
->in
[nr
]));
1015 in_min_show(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1017 int nr
= to_sensor_dev_attr(devattr
)->index
;
1018 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1019 return sprintf(buf
, "%ld\n", (long)IN_FROM_REG(data
->in_min
[nr
]));
1023 in_min_store(struct device
*dev
, struct device_attribute
*devattr
,
1024 const char *buf
, size_t count
)
1026 int nr
= to_sensor_dev_attr(devattr
)->index
;
1027 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1031 err
= kstrtol(buf
, 10, &val
);
1035 mutex_lock(&data
->update_lock
);
1036 data
->in_min
[nr
] = IN_TO_REG(val
);
1037 w83627hf_write_value(data
, W83781D_REG_IN_MIN(nr
), data
->in_min
[nr
]);
1038 mutex_unlock(&data
->update_lock
);
1043 in_max_show(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1045 int nr
= to_sensor_dev_attr(devattr
)->index
;
1046 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1047 return sprintf(buf
, "%ld\n", (long)IN_FROM_REG(data
->in_max
[nr
]));
1051 in_max_store(struct device
*dev
, struct device_attribute
*devattr
,
1052 const char *buf
, size_t count
)
1054 int nr
= to_sensor_dev_attr(devattr
)->index
;
1055 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1059 err
= kstrtol(buf
, 10, &val
);
1063 mutex_lock(&data
->update_lock
);
1064 data
->in_max
[nr
] = IN_TO_REG(val
);
1065 w83627hf_write_value(data
, W83781D_REG_IN_MAX(nr
), data
->in_max
[nr
]);
1066 mutex_unlock(&data
->update_lock
);
1070 static SENSOR_DEVICE_ATTR_RO(in1_input
, in_input
, 1);
1071 static SENSOR_DEVICE_ATTR_RW(in1_min
, in_min
, 1);
1072 static SENSOR_DEVICE_ATTR_RW(in1_max
, in_max
, 1);
1073 static SENSOR_DEVICE_ATTR_RO(in2_input
, in_input
, 2);
1074 static SENSOR_DEVICE_ATTR_RW(in2_min
, in_min
, 2);
1075 static SENSOR_DEVICE_ATTR_RW(in2_max
, in_max
, 2);
1076 static SENSOR_DEVICE_ATTR_RO(in3_input
, in_input
, 3);
1077 static SENSOR_DEVICE_ATTR_RW(in3_min
, in_min
, 3);
1078 static SENSOR_DEVICE_ATTR_RW(in3_max
, in_max
, 3);
1079 static SENSOR_DEVICE_ATTR_RO(in4_input
, in_input
, 4);
1080 static SENSOR_DEVICE_ATTR_RW(in4_min
, in_min
, 4);
1081 static SENSOR_DEVICE_ATTR_RW(in4_max
, in_max
, 4);
1082 static SENSOR_DEVICE_ATTR_RO(in5_input
, in_input
, 5);
1083 static SENSOR_DEVICE_ATTR_RW(in5_min
, in_min
, 5);
1084 static SENSOR_DEVICE_ATTR_RW(in5_max
, in_max
, 5);
1085 static SENSOR_DEVICE_ATTR_RO(in6_input
, in_input
, 6);
1086 static SENSOR_DEVICE_ATTR_RW(in6_min
, in_min
, 6);
1087 static SENSOR_DEVICE_ATTR_RW(in6_max
, in_max
, 6);
1088 static SENSOR_DEVICE_ATTR_RO(in7_input
, in_input
, 7);
1089 static SENSOR_DEVICE_ATTR_RW(in7_min
, in_min
, 7);
1090 static SENSOR_DEVICE_ATTR_RW(in7_max
, in_max
, 7);
1091 static SENSOR_DEVICE_ATTR_RO(in8_input
, in_input
, 8);
1092 static SENSOR_DEVICE_ATTR_RW(in8_min
, in_min
, 8);
1093 static SENSOR_DEVICE_ATTR_RW(in8_max
, in_max
, 8);
1096 fan_input_show(struct device
*dev
, struct device_attribute
*devattr
,
1099 int nr
= to_sensor_dev_attr(devattr
)->index
;
1100 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1101 return sprintf(buf
, "%ld\n", FAN_FROM_REG(data
->fan
[nr
],
1102 (long)DIV_FROM_REG(data
->fan_div
[nr
])));
1106 fan_min_show(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1108 int nr
= to_sensor_dev_attr(devattr
)->index
;
1109 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1110 return sprintf(buf
, "%ld\n", FAN_FROM_REG(data
->fan_min
[nr
],
1111 (long)DIV_FROM_REG(data
->fan_div
[nr
])));
1115 fan_min_store(struct device
*dev
, struct device_attribute
*devattr
,
1116 const char *buf
, size_t count
)
1118 int nr
= to_sensor_dev_attr(devattr
)->index
;
1119 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1123 err
= kstrtoul(buf
, 10, &val
);
1127 mutex_lock(&data
->update_lock
);
1128 data
->fan_min
[nr
] = FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
1129 w83627hf_write_value(data
, W83627HF_REG_FAN_MIN(nr
),
1132 mutex_unlock(&data
->update_lock
);
1136 static SENSOR_DEVICE_ATTR_RO(fan1_input
, fan_input
, 0);
1137 static SENSOR_DEVICE_ATTR_RW(fan1_min
, fan_min
, 0);
1138 static SENSOR_DEVICE_ATTR_RO(fan2_input
, fan_input
, 1);
1139 static SENSOR_DEVICE_ATTR_RW(fan2_min
, fan_min
, 1);
1140 static SENSOR_DEVICE_ATTR_RO(fan3_input
, fan_input
, 2);
1141 static SENSOR_DEVICE_ATTR_RW(fan3_min
, fan_min
, 2);
1144 fan_div_show(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1146 int nr
= to_sensor_dev_attr(devattr
)->index
;
1147 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1148 return sprintf(buf
, "%ld\n",
1149 (long) DIV_FROM_REG(data
->fan_div
[nr
]));
1153 * Note: we save and restore the fan minimum here, because its value is
1154 * determined in part by the fan divisor. This follows the principle of
1155 * least surprise; the user doesn't expect the fan minimum to change just
1156 * because the divisor changed.
1159 fan_div_store(struct device
*dev
, struct device_attribute
*devattr
,
1160 const char *buf
, size_t count
)
1162 int nr
= to_sensor_dev_attr(devattr
)->index
;
1163 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1169 err
= kstrtoul(buf
, 10, &val
);
1173 mutex_lock(&data
->update_lock
);
1176 min
= FAN_FROM_REG(data
->fan_min
[nr
],
1177 DIV_FROM_REG(data
->fan_div
[nr
]));
1179 data
->fan_div
[nr
] = DIV_TO_REG(val
);
1181 reg
= (w83627hf_read_value(data
, nr
==2 ? W83781D_REG_PIN
: W83781D_REG_VID_FANDIV
)
1182 & (nr
==0 ? 0xcf : 0x3f))
1183 | ((data
->fan_div
[nr
] & 0x03) << (nr
==0 ? 4 : 6));
1184 w83627hf_write_value(data
, nr
==2 ? W83781D_REG_PIN
: W83781D_REG_VID_FANDIV
, reg
);
1186 reg
= (w83627hf_read_value(data
, W83781D_REG_VBAT
)
1188 | ((data
->fan_div
[nr
] & 0x04) << (3 + nr
));
1189 w83627hf_write_value(data
, W83781D_REG_VBAT
, reg
);
1191 /* Restore fan_min */
1192 data
->fan_min
[nr
] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
1193 w83627hf_write_value(data
, W83627HF_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
1195 mutex_unlock(&data
->update_lock
);
1199 static SENSOR_DEVICE_ATTR_RW(fan1_div
, fan_div
, 0);
1200 static SENSOR_DEVICE_ATTR_RW(fan2_div
, fan_div
, 1);
1201 static SENSOR_DEVICE_ATTR_RW(fan3_div
, fan_div
, 2);
1204 temp_show(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1206 int nr
= to_sensor_dev_attr(devattr
)->index
;
1207 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1209 u16 tmp
= data
->temp
[nr
];
1210 return sprintf(buf
, "%ld\n", (nr
) ? (long) LM75_TEMP_FROM_REG(tmp
)
1211 : (long) TEMP_FROM_REG(tmp
));
1215 temp_max_show(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1217 int nr
= to_sensor_dev_attr(devattr
)->index
;
1218 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1220 u16 tmp
= data
->temp_max
[nr
];
1221 return sprintf(buf
, "%ld\n", (nr
) ? (long) LM75_TEMP_FROM_REG(tmp
)
1222 : (long) TEMP_FROM_REG(tmp
));
1226 temp_max_store(struct device
*dev
, struct device_attribute
*devattr
,
1227 const char *buf
, size_t count
)
1229 int nr
= to_sensor_dev_attr(devattr
)->index
;
1230 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1235 err
= kstrtol(buf
, 10, &val
);
1239 tmp
= (nr
) ? LM75_TEMP_TO_REG(val
) : TEMP_TO_REG(val
);
1240 mutex_lock(&data
->update_lock
);
1241 data
->temp_max
[nr
] = tmp
;
1242 w83627hf_write_value(data
, w83627hf_reg_temp_over
[nr
], tmp
);
1243 mutex_unlock(&data
->update_lock
);
1248 temp_max_hyst_show(struct device
*dev
, struct device_attribute
*devattr
,
1251 int nr
= to_sensor_dev_attr(devattr
)->index
;
1252 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1254 u16 tmp
= data
->temp_max_hyst
[nr
];
1255 return sprintf(buf
, "%ld\n", (nr
) ? (long) LM75_TEMP_FROM_REG(tmp
)
1256 : (long) TEMP_FROM_REG(tmp
));
1260 temp_max_hyst_store(struct device
*dev
, struct device_attribute
*devattr
,
1261 const char *buf
, size_t count
)
1263 int nr
= to_sensor_dev_attr(devattr
)->index
;
1264 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1269 err
= kstrtol(buf
, 10, &val
);
1273 tmp
= (nr
) ? LM75_TEMP_TO_REG(val
) : TEMP_TO_REG(val
);
1274 mutex_lock(&data
->update_lock
);
1275 data
->temp_max_hyst
[nr
] = tmp
;
1276 w83627hf_write_value(data
, w83627hf_reg_temp_hyst
[nr
], tmp
);
1277 mutex_unlock(&data
->update_lock
);
1281 static SENSOR_DEVICE_ATTR_RO(temp1_input
, temp
, 0);
1282 static SENSOR_DEVICE_ATTR_RW(temp1_max
, temp_max
, 0);
1283 static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst
, temp_max_hyst
, 0);
1284 static SENSOR_DEVICE_ATTR_RO(temp2_input
, temp
, 1);
1285 static SENSOR_DEVICE_ATTR_RW(temp2_max
, temp_max
, 1);
1286 static SENSOR_DEVICE_ATTR_RW(temp2_max_hyst
, temp_max_hyst
, 1);
1287 static SENSOR_DEVICE_ATTR_RO(temp3_input
, temp
, 2);
1288 static SENSOR_DEVICE_ATTR_RW(temp3_max
, temp_max
, 2);
1289 static SENSOR_DEVICE_ATTR_RW(temp3_max_hyst
, temp_max_hyst
, 2);
1292 temp_type_show(struct device
*dev
, struct device_attribute
*devattr
,
1295 int nr
= to_sensor_dev_attr(devattr
)->index
;
1296 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1297 return sprintf(buf
, "%ld\n", (long) data
->sens
[nr
]);
1301 temp_type_store(struct device
*dev
, struct device_attribute
*devattr
,
1302 const char *buf
, size_t count
)
1304 int nr
= to_sensor_dev_attr(devattr
)->index
;
1305 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1310 err
= kstrtoul(buf
, 10, &val
);
1314 mutex_lock(&data
->update_lock
);
1317 case 1: /* PII/Celeron diode */
1318 tmp
= w83627hf_read_value(data
, W83781D_REG_SCFG1
);
1319 w83627hf_write_value(data
, W83781D_REG_SCFG1
,
1320 tmp
| BIT_SCFG1
[nr
]);
1321 tmp
= w83627hf_read_value(data
, W83781D_REG_SCFG2
);
1322 w83627hf_write_value(data
, W83781D_REG_SCFG2
,
1323 tmp
| BIT_SCFG2
[nr
]);
1324 data
->sens
[nr
] = val
;
1327 tmp
= w83627hf_read_value(data
, W83781D_REG_SCFG1
);
1328 w83627hf_write_value(data
, W83781D_REG_SCFG1
,
1329 tmp
| BIT_SCFG1
[nr
]);
1330 tmp
= w83627hf_read_value(data
, W83781D_REG_SCFG2
);
1331 w83627hf_write_value(data
, W83781D_REG_SCFG2
,
1332 tmp
& ~BIT_SCFG2
[nr
]);
1333 data
->sens
[nr
] = val
;
1335 case W83781D_DEFAULT_BETA
:
1336 dev_warn(dev
, "Sensor type %d is deprecated, please use 4 "
1337 "instead\n", W83781D_DEFAULT_BETA
);
1339 case 4: /* thermistor */
1340 tmp
= w83627hf_read_value(data
, W83781D_REG_SCFG1
);
1341 w83627hf_write_value(data
, W83781D_REG_SCFG1
,
1342 tmp
& ~BIT_SCFG1
[nr
]);
1343 data
->sens
[nr
] = val
;
1347 "Invalid sensor type %ld; must be 1, 2, or 4\n",
1352 mutex_unlock(&data
->update_lock
);
1356 static SENSOR_DEVICE_ATTR_RW(temp1_type
, temp_type
, 0);
1357 static SENSOR_DEVICE_ATTR_RW(temp2_type
, temp_type
, 1);
1358 static SENSOR_DEVICE_ATTR_RW(temp3_type
, temp_type
, 2);
1361 alarms_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1363 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1364 return sprintf(buf
, "%ld\n", (long) data
->alarms
);
1366 static DEVICE_ATTR_RO(alarms
);
1368 #define VIN_UNIT_ATTRS(_X_) \
1369 &sensor_dev_attr_in##_X_##_input.dev_attr.attr, \
1370 &sensor_dev_attr_in##_X_##_min.dev_attr.attr, \
1371 &sensor_dev_attr_in##_X_##_max.dev_attr.attr, \
1372 &sensor_dev_attr_in##_X_##_alarm.dev_attr.attr, \
1373 &sensor_dev_attr_in##_X_##_beep.dev_attr.attr
1375 #define FAN_UNIT_ATTRS(_X_) \
1376 &sensor_dev_attr_fan##_X_##_input.dev_attr.attr, \
1377 &sensor_dev_attr_fan##_X_##_min.dev_attr.attr, \
1378 &sensor_dev_attr_fan##_X_##_div.dev_attr.attr, \
1379 &sensor_dev_attr_fan##_X_##_alarm.dev_attr.attr, \
1380 &sensor_dev_attr_fan##_X_##_beep.dev_attr.attr
1382 #define TEMP_UNIT_ATTRS(_X_) \
1383 &sensor_dev_attr_temp##_X_##_input.dev_attr.attr, \
1384 &sensor_dev_attr_temp##_X_##_max.dev_attr.attr, \
1385 &sensor_dev_attr_temp##_X_##_max_hyst.dev_attr.attr, \
1386 &sensor_dev_attr_temp##_X_##_type.dev_attr.attr, \
1387 &sensor_dev_attr_temp##_X_##_alarm.dev_attr.attr, \
1388 &sensor_dev_attr_temp##_X_##_beep.dev_attr.attr
1391 beep_mask_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1393 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1394 return sprintf(buf
, "%ld\n",
1395 (long)BEEP_MASK_FROM_REG(data
->beep_mask
));
1399 beep_mask_store(struct device
*dev
, struct device_attribute
*attr
,
1400 const char *buf
, size_t count
)
1402 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1406 err
= kstrtoul(buf
, 10, &val
);
1410 mutex_lock(&data
->update_lock
);
1412 /* preserve beep enable */
1413 data
->beep_mask
= (data
->beep_mask
& 0x8000)
1414 | BEEP_MASK_TO_REG(val
);
1415 w83627hf_write_value(data
, W83781D_REG_BEEP_INTS1
,
1416 data
->beep_mask
& 0xff);
1417 w83627hf_write_value(data
, W83781D_REG_BEEP_INTS3
,
1418 ((data
->beep_mask
) >> 16) & 0xff);
1419 w83627hf_write_value(data
, W83781D_REG_BEEP_INTS2
,
1420 (data
->beep_mask
>> 8) & 0xff);
1422 mutex_unlock(&data
->update_lock
);
1426 static DEVICE_ATTR_RW(beep_mask
);
1429 pwm_show(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1431 int nr
= to_sensor_dev_attr(devattr
)->index
;
1432 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1433 return sprintf(buf
, "%ld\n", (long) data
->pwm
[nr
]);
1437 pwm_store(struct device
*dev
, struct device_attribute
*devattr
,
1438 const char *buf
, size_t count
)
1440 int nr
= to_sensor_dev_attr(devattr
)->index
;
1441 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1445 err
= kstrtoul(buf
, 10, &val
);
1449 mutex_lock(&data
->update_lock
);
1451 if (data
->type
== w83627thf
) {
1452 /* bits 0-3 are reserved in 627THF */
1453 data
->pwm
[nr
] = PWM_TO_REG(val
) & 0xf0;
1454 w83627hf_write_value(data
,
1455 W836X7HF_REG_PWM(data
->type
, nr
),
1457 (w83627hf_read_value(data
,
1458 W836X7HF_REG_PWM(data
->type
, nr
)) & 0x0f));
1460 data
->pwm
[nr
] = PWM_TO_REG(val
);
1461 w83627hf_write_value(data
,
1462 W836X7HF_REG_PWM(data
->type
, nr
),
1466 mutex_unlock(&data
->update_lock
);
1470 static SENSOR_DEVICE_ATTR_RW(pwm1
, pwm
, 0);
1471 static SENSOR_DEVICE_ATTR_RW(pwm2
, pwm
, 1);
1472 static SENSOR_DEVICE_ATTR_RW(pwm3
, pwm
, 2);
1475 name_show(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1477 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1479 return sprintf(buf
, "%s\n", data
->name
);
1482 static DEVICE_ATTR_RO(name
);
1484 static struct attribute
*w83627hf_attributes
[] = {
1485 &dev_attr_in0_input
.attr
,
1486 &dev_attr_in0_min
.attr
,
1487 &dev_attr_in0_max
.attr
,
1488 &sensor_dev_attr_in0_alarm
.dev_attr
.attr
,
1489 &sensor_dev_attr_in0_beep
.dev_attr
.attr
,
1502 &dev_attr_alarms
.attr
,
1503 &sensor_dev_attr_beep_enable
.dev_attr
.attr
,
1504 &dev_attr_beep_mask
.attr
,
1506 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
1507 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
1508 &dev_attr_name
.attr
,
1512 static const struct attribute_group w83627hf_group
= {
1513 .attrs
= w83627hf_attributes
,
1517 pwm_freq_show(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1519 int nr
= to_sensor_dev_attr(devattr
)->index
;
1520 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1521 if (data
->type
== w83627hf
)
1522 return sprintf(buf
, "%ld\n",
1523 pwm_freq_from_reg_627hf(data
->pwm_freq
[nr
]));
1525 return sprintf(buf
, "%ld\n",
1526 pwm_freq_from_reg(data
->pwm_freq
[nr
]));
1530 pwm_freq_store(struct device
*dev
, struct device_attribute
*devattr
,
1531 const char *buf
, size_t count
)
1533 int nr
= to_sensor_dev_attr(devattr
)->index
;
1534 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1535 static const u8 mask
[]={0xF8, 0x8F};
1539 err
= kstrtoul(buf
, 10, &val
);
1543 mutex_lock(&data
->update_lock
);
1545 if (data
->type
== w83627hf
) {
1546 data
->pwm_freq
[nr
] = pwm_freq_to_reg_627hf(val
);
1547 w83627hf_write_value(data
, W83627HF_REG_PWM_FREQ
,
1548 (data
->pwm_freq
[nr
] << (nr
*4)) |
1549 (w83627hf_read_value(data
,
1550 W83627HF_REG_PWM_FREQ
) & mask
[nr
]));
1552 data
->pwm_freq
[nr
] = pwm_freq_to_reg(val
);
1553 w83627hf_write_value(data
, W83637HF_REG_PWM_FREQ
[nr
],
1554 data
->pwm_freq
[nr
]);
1557 mutex_unlock(&data
->update_lock
);
1561 static SENSOR_DEVICE_ATTR_RW(pwm1_freq
, pwm_freq
, 0);
1562 static SENSOR_DEVICE_ATTR_RW(pwm2_freq
, pwm_freq
, 1);
1563 static SENSOR_DEVICE_ATTR_RW(pwm3_freq
, pwm_freq
, 2);
1566 cpu0_vid_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1568 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1569 return sprintf(buf
, "%ld\n", (long) vid_from_reg(data
->vid
, data
->vrm
));
1572 static DEVICE_ATTR_RO(cpu0_vid
);
1575 vrm_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1577 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1578 return sprintf(buf
, "%ld\n", (long) data
->vrm
);
1582 vrm_store(struct device
*dev
, struct device_attribute
*attr
, const char *buf
,
1585 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1589 err
= kstrtoul(buf
, 10, &val
);
1600 static DEVICE_ATTR_RW(vrm
);
1603 pwm_enable_show(struct device
*dev
, struct device_attribute
*devattr
,
1606 int nr
= to_sensor_dev_attr(devattr
)->index
;
1607 struct w83627hf_data
*data
= w83627hf_update_device(dev
);
1608 return sprintf(buf
, "%d\n", data
->pwm_enable
[nr
]);
1612 pwm_enable_store(struct device
*dev
, struct device_attribute
*devattr
,
1613 const char *buf
, size_t count
)
1615 int nr
= to_sensor_dev_attr(devattr
)->index
;
1616 struct w83627hf_data
*data
= dev_get_drvdata(dev
);
1621 err
= kstrtoul(buf
, 10, &val
);
1625 if (!val
|| val
> 3) /* modes 1, 2 and 3 are supported */
1627 mutex_lock(&data
->update_lock
);
1628 data
->pwm_enable
[nr
] = val
;
1629 reg
= w83627hf_read_value(data
, W83627THF_REG_PWM_ENABLE
[nr
]);
1630 reg
&= ~(0x03 << W83627THF_PWM_ENABLE_SHIFT
[nr
]);
1631 reg
|= (val
- 1) << W83627THF_PWM_ENABLE_SHIFT
[nr
];
1632 w83627hf_write_value(data
, W83627THF_REG_PWM_ENABLE
[nr
], reg
);
1633 mutex_unlock(&data
->update_lock
);
1637 static SENSOR_DEVICE_ATTR_RW(pwm1_enable
, pwm_enable
, 0);
1638 static SENSOR_DEVICE_ATTR_RW(pwm2_enable
, pwm_enable
, 1);
1639 static SENSOR_DEVICE_ATTR_RW(pwm3_enable
, pwm_enable
, 2);
1641 static struct attribute
*w83627hf_attributes_opt
[] = {
1648 &sensor_dev_attr_pwm3
.dev_attr
.attr
,
1650 &sensor_dev_attr_pwm1_freq
.dev_attr
.attr
,
1651 &sensor_dev_attr_pwm2_freq
.dev_attr
.attr
,
1652 &sensor_dev_attr_pwm3_freq
.dev_attr
.attr
,
1654 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
1655 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
1656 &sensor_dev_attr_pwm3_enable
.dev_attr
.attr
,
1661 static const struct attribute_group w83627hf_group_opt
= {
1662 .attrs
= w83627hf_attributes_opt
,
1665 static int w83627hf_probe(struct platform_device
*pdev
)
1667 struct device
*dev
= &pdev
->dev
;
1668 struct w83627hf_sio_data
*sio_data
= dev_get_platdata(dev
);
1669 struct w83627hf_data
*data
;
1670 struct resource
*res
;
1673 static const char *names
[] = {
1681 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
1682 if (!devm_request_region(dev
, res
->start
, WINB_REGION_SIZE
, DRVNAME
)) {
1683 dev_err(dev
, "Failed to request region 0x%lx-0x%lx\n",
1684 (unsigned long)res
->start
,
1685 (unsigned long)(res
->start
+ WINB_REGION_SIZE
- 1));
1689 data
= devm_kzalloc(dev
, sizeof(struct w83627hf_data
), GFP_KERNEL
);
1693 data
->addr
= res
->start
;
1694 data
->type
= sio_data
->type
;
1695 data
->name
= names
[sio_data
->type
];
1696 mutex_init(&data
->lock
);
1697 mutex_init(&data
->update_lock
);
1698 platform_set_drvdata(pdev
, data
);
1700 /* Initialize the chip */
1701 w83627hf_init_device(pdev
);
1703 /* A few vars need to be filled upon startup */
1704 for (i
= 0; i
<= 2; i
++)
1705 data
->fan_min
[i
] = w83627hf_read_value(
1706 data
, W83627HF_REG_FAN_MIN(i
));
1707 w83627hf_update_fan_div(data
);
1709 /* Register common device attributes */
1710 err
= sysfs_create_group(&dev
->kobj
, &w83627hf_group
);
1714 /* Register chip-specific device attributes */
1715 if (data
->type
== w83627hf
|| data
->type
== w83697hf
)
1716 if ((err
= device_create_file(dev
,
1717 &sensor_dev_attr_in5_input
.dev_attr
))
1718 || (err
= device_create_file(dev
,
1719 &sensor_dev_attr_in5_min
.dev_attr
))
1720 || (err
= device_create_file(dev
,
1721 &sensor_dev_attr_in5_max
.dev_attr
))
1722 || (err
= device_create_file(dev
,
1723 &sensor_dev_attr_in5_alarm
.dev_attr
))
1724 || (err
= device_create_file(dev
,
1725 &sensor_dev_attr_in5_beep
.dev_attr
))
1726 || (err
= device_create_file(dev
,
1727 &sensor_dev_attr_in6_input
.dev_attr
))
1728 || (err
= device_create_file(dev
,
1729 &sensor_dev_attr_in6_min
.dev_attr
))
1730 || (err
= device_create_file(dev
,
1731 &sensor_dev_attr_in6_max
.dev_attr
))
1732 || (err
= device_create_file(dev
,
1733 &sensor_dev_attr_in6_alarm
.dev_attr
))
1734 || (err
= device_create_file(dev
,
1735 &sensor_dev_attr_in6_beep
.dev_attr
))
1736 || (err
= device_create_file(dev
,
1737 &sensor_dev_attr_pwm1_freq
.dev_attr
))
1738 || (err
= device_create_file(dev
,
1739 &sensor_dev_attr_pwm2_freq
.dev_attr
)))
1742 if (data
->type
!= w83697hf
)
1743 if ((err
= device_create_file(dev
,
1744 &sensor_dev_attr_in1_input
.dev_attr
))
1745 || (err
= device_create_file(dev
,
1746 &sensor_dev_attr_in1_min
.dev_attr
))
1747 || (err
= device_create_file(dev
,
1748 &sensor_dev_attr_in1_max
.dev_attr
))
1749 || (err
= device_create_file(dev
,
1750 &sensor_dev_attr_in1_alarm
.dev_attr
))
1751 || (err
= device_create_file(dev
,
1752 &sensor_dev_attr_in1_beep
.dev_attr
))
1753 || (err
= device_create_file(dev
,
1754 &sensor_dev_attr_fan3_input
.dev_attr
))
1755 || (err
= device_create_file(dev
,
1756 &sensor_dev_attr_fan3_min
.dev_attr
))
1757 || (err
= device_create_file(dev
,
1758 &sensor_dev_attr_fan3_div
.dev_attr
))
1759 || (err
= device_create_file(dev
,
1760 &sensor_dev_attr_fan3_alarm
.dev_attr
))
1761 || (err
= device_create_file(dev
,
1762 &sensor_dev_attr_fan3_beep
.dev_attr
))
1763 || (err
= device_create_file(dev
,
1764 &sensor_dev_attr_temp3_input
.dev_attr
))
1765 || (err
= device_create_file(dev
,
1766 &sensor_dev_attr_temp3_max
.dev_attr
))
1767 || (err
= device_create_file(dev
,
1768 &sensor_dev_attr_temp3_max_hyst
.dev_attr
))
1769 || (err
= device_create_file(dev
,
1770 &sensor_dev_attr_temp3_alarm
.dev_attr
))
1771 || (err
= device_create_file(dev
,
1772 &sensor_dev_attr_temp3_beep
.dev_attr
))
1773 || (err
= device_create_file(dev
,
1774 &sensor_dev_attr_temp3_type
.dev_attr
)))
1777 if (data
->type
!= w83697hf
&& data
->vid
!= 0xff) {
1778 /* Convert VID to voltage based on VRM */
1779 data
->vrm
= vid_which_vrm();
1781 if ((err
= device_create_file(dev
, &dev_attr_cpu0_vid
))
1782 || (err
= device_create_file(dev
, &dev_attr_vrm
)))
1786 if (data
->type
== w83627thf
|| data
->type
== w83637hf
1787 || data
->type
== w83687thf
) {
1788 err
= device_create_file(dev
, &sensor_dev_attr_pwm3
.dev_attr
);
1793 if (data
->type
== w83637hf
|| data
->type
== w83687thf
)
1794 if ((err
= device_create_file(dev
,
1795 &sensor_dev_attr_pwm1_freq
.dev_attr
))
1796 || (err
= device_create_file(dev
,
1797 &sensor_dev_attr_pwm2_freq
.dev_attr
))
1798 || (err
= device_create_file(dev
,
1799 &sensor_dev_attr_pwm3_freq
.dev_attr
)))
1802 if (data
->type
!= w83627hf
)
1803 if ((err
= device_create_file(dev
,
1804 &sensor_dev_attr_pwm1_enable
.dev_attr
))
1805 || (err
= device_create_file(dev
,
1806 &sensor_dev_attr_pwm2_enable
.dev_attr
)))
1809 if (data
->type
== w83627thf
|| data
->type
== w83637hf
1810 || data
->type
== w83687thf
) {
1811 err
= device_create_file(dev
,
1812 &sensor_dev_attr_pwm3_enable
.dev_attr
);
1817 data
->hwmon_dev
= hwmon_device_register(dev
);
1818 if (IS_ERR(data
->hwmon_dev
)) {
1819 err
= PTR_ERR(data
->hwmon_dev
);
1826 sysfs_remove_group(&dev
->kobj
, &w83627hf_group
);
1827 sysfs_remove_group(&dev
->kobj
, &w83627hf_group_opt
);
1831 static void w83627hf_remove(struct platform_device
*pdev
)
1833 struct w83627hf_data
*data
= platform_get_drvdata(pdev
);
1835 hwmon_device_unregister(data
->hwmon_dev
);
1837 sysfs_remove_group(&pdev
->dev
.kobj
, &w83627hf_group
);
1838 sysfs_remove_group(&pdev
->dev
.kobj
, &w83627hf_group_opt
);
1841 static struct platform_driver w83627hf_driver
= {
1844 .pm
= W83627HF_DEV_PM_OPS
,
1846 .probe
= w83627hf_probe
,
1847 .remove
= w83627hf_remove
,
1850 static int __init
w83627hf_find(int sioaddr
, unsigned short *addr
,
1851 struct w83627hf_sio_data
*sio_data
)
1856 static __initconst
char *const names
[] = {
1864 sio_data
->sioaddr
= sioaddr
;
1865 err
= superio_enter(sio_data
);
1870 val
= force_id
? force_id
: superio_inb(sio_data
, DEVID
);
1873 sio_data
->type
= w83627hf
;
1876 sio_data
->type
= w83627thf
;
1879 sio_data
->type
= w83697hf
;
1882 sio_data
->type
= w83637hf
;
1885 sio_data
->type
= w83687thf
;
1887 case 0xff: /* No device at all */
1890 pr_debug(DRVNAME
": Unsupported chip (DEVID=0x%02x)\n", val
);
1894 superio_select(sio_data
, W83627HF_LD_HWM
);
1895 val
= (superio_inb(sio_data
, WINB_BASE_REG
) << 8) |
1896 superio_inb(sio_data
, WINB_BASE_REG
+ 1);
1897 *addr
= val
& WINB_ALIGNMENT
;
1899 pr_warn("Base address not set, skipping\n");
1903 val
= superio_inb(sio_data
, WINB_ACT_REG
);
1904 if (!(val
& 0x01)) {
1905 pr_warn("Enabling HWM logical device\n");
1906 superio_outb(sio_data
, WINB_ACT_REG
, val
| 0x01);
1910 pr_info(DRVNAME
": Found %s chip at %#x\n",
1911 names
[sio_data
->type
], *addr
);
1914 superio_exit(sio_data
);
1918 static int __init
w83627hf_device_add(unsigned short address
,
1919 const struct w83627hf_sio_data
*sio_data
)
1921 struct resource res
= {
1922 .start
= address
+ WINB_REGION_OFFSET
,
1923 .end
= address
+ WINB_REGION_OFFSET
+ WINB_REGION_SIZE
- 1,
1925 .flags
= IORESOURCE_IO
,
1929 err
= acpi_check_resource_conflict(&res
);
1933 pdev
= platform_device_alloc(DRVNAME
, address
);
1936 pr_err("Device allocation failed\n");
1940 err
= platform_device_add_resources(pdev
, &res
, 1);
1942 pr_err("Device resource addition failed (%d)\n", err
);
1943 goto exit_device_put
;
1946 err
= platform_device_add_data(pdev
, sio_data
,
1947 sizeof(struct w83627hf_sio_data
));
1949 pr_err("Platform data allocation failed\n");
1950 goto exit_device_put
;
1953 err
= platform_device_add(pdev
);
1955 pr_err("Device addition failed (%d)\n", err
);
1956 goto exit_device_put
;
1962 platform_device_put(pdev
);
1967 static int __init
sensors_w83627hf_init(void)
1970 unsigned short address
;
1971 struct w83627hf_sio_data sio_data
;
1973 if (w83627hf_find(0x2e, &address
, &sio_data
)
1974 && w83627hf_find(0x4e, &address
, &sio_data
))
1977 err
= platform_driver_register(&w83627hf_driver
);
1981 /* Sets global pdev as a side effect */
1982 err
= w83627hf_device_add(address
, &sio_data
);
1989 platform_driver_unregister(&w83627hf_driver
);
1994 static void __exit
sensors_w83627hf_exit(void)
1996 platform_device_unregister(pdev
);
1997 platform_driver_unregister(&w83627hf_driver
);
2000 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
2001 "Philip Edelbrock <phil@netroedge.com>, "
2002 "and Mark Studebaker <mdsxyz123@yahoo.com>");
2003 MODULE_DESCRIPTION("W83627HF driver");
2004 MODULE_LICENSE("GPL");
2006 module_init(sensors_w83627hf_init
);
2007 module_exit(sensors_w83627hf_exit
);