2 w83781d.c - Part of lm_sensors, Linux kernel modules for hardware
4 Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>,
6 and Mark Studebaker <mdsxyz123@yahoo.com>
7 Copyright (c) 2007 - 2008 Jean Delvare <khali@linux-fr.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 Supports following chips:
27 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
28 as99127f 7 3 0 3 0x31 0x12c3 yes no
29 as99127f rev.2 (type_name = as99127f) 0x31 0x5ca3 yes no
30 w83781d 7 3 0 3 0x10-1 0x5ca3 yes yes
31 w83782d 9 3 2-4 3 0x30 0x5ca3 yes yes
32 w83783s 5-6 3 2 1-2 0x40 0x5ca3 yes no
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/slab.h>
39 #include <linux/jiffies.h>
40 #include <linux/i2c.h>
41 #include <linux/hwmon.h>
42 #include <linux/hwmon-vid.h>
43 #include <linux/hwmon-sysfs.h>
44 #include <linux/sysfs.h>
45 #include <linux/err.h>
46 #include <linux/mutex.h>
49 #include <linux/platform_device.h>
50 #include <linux/ioport.h>
56 /* Addresses to scan */
57 static const unsigned short normal_i2c
[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
58 0x2e, 0x2f, I2C_CLIENT_END
};
60 enum chips
{ w83781d
, w83782d
, w83783s
, as99127f
};
62 /* Insmod parameters */
63 static unsigned short force_subclients
[4];
64 module_param_array(force_subclients
, short, NULL
, 0);
65 MODULE_PARM_DESC(force_subclients
, "List of subclient addresses: "
66 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
69 module_param(reset
, bool, 0);
70 MODULE_PARM_DESC(reset
, "Set to one to reset chip on load");
73 module_param(init
, bool, 0);
74 MODULE_PARM_DESC(init
, "Set to zero to bypass chip initialization");
76 /* Constants specified below */
78 /* Length of ISA address segment */
79 #define W83781D_EXTENT 8
81 /* Where are the ISA address/data registers relative to the base address */
82 #define W83781D_ADDR_REG_OFFSET 5
83 #define W83781D_DATA_REG_OFFSET 6
85 /* The device registers */
86 /* in nr from 0 to 8 */
87 #define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \
88 (0x554 + (((nr) - 7) * 2)))
89 #define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \
90 (0x555 + (((nr) - 7) * 2)))
91 #define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
94 /* fan nr from 0 to 2 */
95 #define W83781D_REG_FAN_MIN(nr) (0x3b + (nr))
96 #define W83781D_REG_FAN(nr) (0x28 + (nr))
98 #define W83781D_REG_BANK 0x4E
99 #define W83781D_REG_TEMP2_CONFIG 0x152
100 #define W83781D_REG_TEMP3_CONFIG 0x252
101 /* temp nr from 1 to 3 */
102 #define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \
103 ((nr == 2) ? (0x0150) : \
105 #define W83781D_REG_TEMP_HYST(nr) ((nr == 3) ? (0x253) : \
106 ((nr == 2) ? (0x153) : \
108 #define W83781D_REG_TEMP_OVER(nr) ((nr == 3) ? (0x255) : \
109 ((nr == 2) ? (0x155) : \
112 #define W83781D_REG_CONFIG 0x40
114 /* Interrupt status (W83781D, AS99127F) */
115 #define W83781D_REG_ALARM1 0x41
116 #define W83781D_REG_ALARM2 0x42
118 /* Real-time status (W83782D, W83783S) */
119 #define W83782D_REG_ALARM1 0x459
120 #define W83782D_REG_ALARM2 0x45A
121 #define W83782D_REG_ALARM3 0x45B
123 #define W83781D_REG_BEEP_CONFIG 0x4D
124 #define W83781D_REG_BEEP_INTS1 0x56
125 #define W83781D_REG_BEEP_INTS2 0x57
126 #define W83781D_REG_BEEP_INTS3 0x453 /* not on W83781D */
128 #define W83781D_REG_VID_FANDIV 0x47
130 #define W83781D_REG_CHIPID 0x49
131 #define W83781D_REG_WCHIPID 0x58
132 #define W83781D_REG_CHIPMAN 0x4F
133 #define W83781D_REG_PIN 0x4B
136 #define W83781D_REG_VBAT 0x5D
138 /* PWM 782D (1-4) and 783S (1-2) only */
139 static const u8 W83781D_REG_PWM
[] = { 0x5B, 0x5A, 0x5E, 0x5F };
140 #define W83781D_REG_PWMCLK12 0x5C
141 #define W83781D_REG_PWMCLK34 0x45C
143 #define W83781D_REG_I2C_ADDR 0x48
144 #define W83781D_REG_I2C_SUBADDR 0x4A
146 /* The following are undocumented in the data sheets however we
147 received the information in an email from Winbond tech support */
148 /* Sensor selection - not on 781d */
149 #define W83781D_REG_SCFG1 0x5D
150 static const u8 BIT_SCFG1
[] = { 0x02, 0x04, 0x08 };
152 #define W83781D_REG_SCFG2 0x59
153 static const u8 BIT_SCFG2
[] = { 0x10, 0x20, 0x40 };
155 #define W83781D_DEFAULT_BETA 3435
158 #define IN_TO_REG(val) SENSORS_LIMIT(((val) + 8) / 16, 0, 255)
159 #define IN_FROM_REG(val) ((val) * 16)
162 FAN_TO_REG(long rpm
, int div
)
166 rpm
= SENSORS_LIMIT(rpm
, 1, 1000000);
167 return SENSORS_LIMIT((1350000 + rpm
* div
/ 2) / (rpm
* div
), 1, 254);
171 FAN_FROM_REG(u8 val
, int div
)
177 return 1350000 / (val
* div
);
180 #define TEMP_TO_REG(val) SENSORS_LIMIT((val) / 1000, -127, 128)
181 #define TEMP_FROM_REG(val) ((val) * 1000)
183 #define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \
184 (~(val)) & 0x7fff : (val) & 0xff7fff)
185 #define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \
186 (~(val)) & 0x7fff : (val) & 0xff7fff)
188 #define DIV_FROM_REG(val) (1 << (val))
191 DIV_TO_REG(long val
, enum chips type
)
194 val
= SENSORS_LIMIT(val
, 1,
196 || type
== as99127f
) ? 8 : 128)) >> 1;
197 for (i
= 0; i
< 7; i
++) {
205 struct w83781d_data
{
206 struct i2c_client
*client
;
207 struct device
*hwmon_dev
;
211 /* For ISA device only */
215 struct mutex update_lock
;
216 char valid
; /* !=0 if following fields are valid */
217 unsigned long last_updated
; /* In jiffies */
219 struct i2c_client
*lm75
[2]; /* for secondary I2C addresses */
220 /* array of 2 pointers to subclients */
222 u8 in
[9]; /* Register value - 8 & 9 for 782D only */
223 u8 in_max
[9]; /* Register value - 8 & 9 for 782D only */
224 u8 in_min
[9]; /* Register value - 8 & 9 for 782D only */
225 u8 fan
[3]; /* Register value */
226 u8 fan_min
[3]; /* Register value */
227 s8 temp
; /* Register value */
228 s8 temp_max
; /* Register value */
229 s8 temp_max_hyst
; /* Register value */
230 u16 temp_add
[2]; /* Register value */
231 u16 temp_max_add
[2]; /* Register value */
232 u16 temp_max_hyst_add
[2]; /* Register value */
233 u8 fan_div
[3]; /* Register encoding, shifted right */
234 u8 vid
; /* Register encoding, combined */
235 u32 alarms
; /* Register encoding, combined */
236 u32 beep_mask
; /* Register encoding, combined */
237 u8 pwm
[4]; /* Register value */
238 u8 pwm2_enable
; /* Boolean */
239 u16 sens
[3]; /* 782D/783S only.
240 1 = pentium diode; 2 = 3904 diode;
245 static struct w83781d_data
*w83781d_data_if_isa(void);
246 static int w83781d_alias_detect(struct i2c_client
*client
, u8 chipid
);
248 static int w83781d_read_value(struct w83781d_data
*data
, u16 reg
);
249 static int w83781d_write_value(struct w83781d_data
*data
, u16 reg
, u16 value
);
250 static struct w83781d_data
*w83781d_update_device(struct device
*dev
);
251 static void w83781d_init_device(struct device
*dev
);
253 /* following are the sysfs callback functions */
254 #define show_in_reg(reg) \
255 static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
258 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
259 struct w83781d_data *data = w83781d_update_device(dev); \
260 return sprintf(buf, "%ld\n", \
261 (long)IN_FROM_REG(data->reg[attr->index])); \
267 #define store_in_reg(REG, reg) \
268 static ssize_t store_in_##reg (struct device *dev, struct device_attribute \
269 *da, const char *buf, size_t count) \
271 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
272 struct w83781d_data *data = dev_get_drvdata(dev); \
273 int nr = attr->index; \
276 val = simple_strtoul(buf, NULL, 10); \
278 mutex_lock(&data->update_lock); \
279 data->in_##reg[nr] = IN_TO_REG(val); \
280 w83781d_write_value(data, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \
282 mutex_unlock(&data->update_lock); \
285 store_in_reg(MIN
, min
);
286 store_in_reg(MAX
, max
);
288 #define sysfs_in_offsets(offset) \
289 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
290 show_in, NULL, offset); \
291 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
292 show_in_min, store_in_min, offset); \
293 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
294 show_in_max, store_in_max, offset)
306 #define show_fan_reg(reg) \
307 static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
310 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
311 struct w83781d_data *data = w83781d_update_device(dev); \
312 return sprintf(buf,"%ld\n", \
313 FAN_FROM_REG(data->reg[attr->index], \
314 DIV_FROM_REG(data->fan_div[attr->index]))); \
317 show_fan_reg(fan_min
);
320 store_fan_min(struct device
*dev
, struct device_attribute
*da
,
321 const char *buf
, size_t count
)
323 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(da
);
324 struct w83781d_data
*data
= dev_get_drvdata(dev
);
325 int nr
= attr
->index
;
328 val
= simple_strtoul(buf
, NULL
, 10);
330 mutex_lock(&data
->update_lock
);
332 FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
333 w83781d_write_value(data
, W83781D_REG_FAN_MIN(nr
),
336 mutex_unlock(&data
->update_lock
);
340 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0);
341 static SENSOR_DEVICE_ATTR(fan1_min
, S_IRUGO
| S_IWUSR
,
342 show_fan_min
, store_fan_min
, 0);
343 static SENSOR_DEVICE_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1);
344 static SENSOR_DEVICE_ATTR(fan2_min
, S_IRUGO
| S_IWUSR
,
345 show_fan_min
, store_fan_min
, 1);
346 static SENSOR_DEVICE_ATTR(fan3_input
, S_IRUGO
, show_fan
, NULL
, 2);
347 static SENSOR_DEVICE_ATTR(fan3_min
, S_IRUGO
| S_IWUSR
,
348 show_fan_min
, store_fan_min
, 2);
350 #define show_temp_reg(reg) \
351 static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
354 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
355 struct w83781d_data *data = w83781d_update_device(dev); \
356 int nr = attr->index; \
357 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
358 return sprintf(buf,"%d\n", \
359 LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \
360 } else { /* TEMP1 */ \
361 return sprintf(buf,"%ld\n", (long)TEMP_FROM_REG(data->reg)); \
365 show_temp_reg(temp_max
);
366 show_temp_reg(temp_max_hyst
);
368 #define store_temp_reg(REG, reg) \
369 static ssize_t store_temp_##reg (struct device *dev, \
370 struct device_attribute *da, const char *buf, size_t count) \
372 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
373 struct w83781d_data *data = dev_get_drvdata(dev); \
374 int nr = attr->index; \
377 val = simple_strtol(buf, NULL, 10); \
379 mutex_lock(&data->update_lock); \
381 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
382 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
383 w83781d_write_value(data, W83781D_REG_TEMP_##REG(nr), \
384 data->temp_##reg##_add[nr-2]); \
385 } else { /* TEMP1 */ \
386 data->temp_##reg = TEMP_TO_REG(val); \
387 w83781d_write_value(data, W83781D_REG_TEMP_##REG(nr), \
391 mutex_unlock(&data->update_lock); \
394 store_temp_reg(OVER
, max
);
395 store_temp_reg(HYST
, max_hyst
);
397 #define sysfs_temp_offsets(offset) \
398 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
399 show_temp, NULL, offset); \
400 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
401 show_temp_max, store_temp_max, offset); \
402 static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
403 show_temp_max_hyst, store_temp_max_hyst, offset);
405 sysfs_temp_offsets(1);
406 sysfs_temp_offsets(2);
407 sysfs_temp_offsets(3);
410 show_vid_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
412 struct w83781d_data
*data
= w83781d_update_device(dev
);
413 return sprintf(buf
, "%ld\n", (long) vid_from_reg(data
->vid
, data
->vrm
));
416 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid_reg
, NULL
);
419 show_vrm_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
421 struct w83781d_data
*data
= dev_get_drvdata(dev
);
422 return sprintf(buf
, "%ld\n", (long) data
->vrm
);
426 store_vrm_reg(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
428 struct w83781d_data
*data
= dev_get_drvdata(dev
);
431 val
= simple_strtoul(buf
, NULL
, 10);
437 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm_reg
, store_vrm_reg
);
440 show_alarms_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
442 struct w83781d_data
*data
= w83781d_update_device(dev
);
443 return sprintf(buf
, "%u\n", data
->alarms
);
446 static DEVICE_ATTR(alarms
, S_IRUGO
, show_alarms_reg
, NULL
);
448 static ssize_t
show_alarm(struct device
*dev
, struct device_attribute
*attr
,
451 struct w83781d_data
*data
= w83781d_update_device(dev
);
452 int bitnr
= to_sensor_dev_attr(attr
)->index
;
453 return sprintf(buf
, "%u\n", (data
->alarms
>> bitnr
) & 1);
456 /* The W83781D has a single alarm bit for temp2 and temp3 */
457 static ssize_t
show_temp3_alarm(struct device
*dev
,
458 struct device_attribute
*attr
, char *buf
)
460 struct w83781d_data
*data
= w83781d_update_device(dev
);
461 int bitnr
= (data
->type
== w83781d
) ? 5 : 13;
462 return sprintf(buf
, "%u\n", (data
->alarms
>> bitnr
) & 1);
465 static SENSOR_DEVICE_ATTR(in0_alarm
, S_IRUGO
, show_alarm
, NULL
, 0);
466 static SENSOR_DEVICE_ATTR(in1_alarm
, S_IRUGO
, show_alarm
, NULL
, 1);
467 static SENSOR_DEVICE_ATTR(in2_alarm
, S_IRUGO
, show_alarm
, NULL
, 2);
468 static SENSOR_DEVICE_ATTR(in3_alarm
, S_IRUGO
, show_alarm
, NULL
, 3);
469 static SENSOR_DEVICE_ATTR(in4_alarm
, S_IRUGO
, show_alarm
, NULL
, 8);
470 static SENSOR_DEVICE_ATTR(in5_alarm
, S_IRUGO
, show_alarm
, NULL
, 9);
471 static SENSOR_DEVICE_ATTR(in6_alarm
, S_IRUGO
, show_alarm
, NULL
, 10);
472 static SENSOR_DEVICE_ATTR(in7_alarm
, S_IRUGO
, show_alarm
, NULL
, 16);
473 static SENSOR_DEVICE_ATTR(in8_alarm
, S_IRUGO
, show_alarm
, NULL
, 17);
474 static SENSOR_DEVICE_ATTR(fan1_alarm
, S_IRUGO
, show_alarm
, NULL
, 6);
475 static SENSOR_DEVICE_ATTR(fan2_alarm
, S_IRUGO
, show_alarm
, NULL
, 7);
476 static SENSOR_DEVICE_ATTR(fan3_alarm
, S_IRUGO
, show_alarm
, NULL
, 11);
477 static SENSOR_DEVICE_ATTR(temp1_alarm
, S_IRUGO
, show_alarm
, NULL
, 4);
478 static SENSOR_DEVICE_ATTR(temp2_alarm
, S_IRUGO
, show_alarm
, NULL
, 5);
479 static SENSOR_DEVICE_ATTR(temp3_alarm
, S_IRUGO
, show_temp3_alarm
, NULL
, 0);
481 static ssize_t
show_beep_mask (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
483 struct w83781d_data
*data
= w83781d_update_device(dev
);
484 return sprintf(buf
, "%ld\n",
485 (long)BEEP_MASK_FROM_REG(data
->beep_mask
, data
->type
));
489 store_beep_mask(struct device
*dev
, struct device_attribute
*attr
,
490 const char *buf
, size_t count
)
492 struct w83781d_data
*data
= dev_get_drvdata(dev
);
495 val
= simple_strtoul(buf
, NULL
, 10);
497 mutex_lock(&data
->update_lock
);
498 data
->beep_mask
&= 0x8000; /* preserve beep enable */
499 data
->beep_mask
|= BEEP_MASK_TO_REG(val
, data
->type
);
500 w83781d_write_value(data
, W83781D_REG_BEEP_INTS1
,
501 data
->beep_mask
& 0xff);
502 w83781d_write_value(data
, W83781D_REG_BEEP_INTS2
,
503 (data
->beep_mask
>> 8) & 0xff);
504 if (data
->type
!= w83781d
&& data
->type
!= as99127f
) {
505 w83781d_write_value(data
, W83781D_REG_BEEP_INTS3
,
506 ((data
->beep_mask
) >> 16) & 0xff);
508 mutex_unlock(&data
->update_lock
);
513 static DEVICE_ATTR(beep_mask
, S_IRUGO
| S_IWUSR
,
514 show_beep_mask
, store_beep_mask
);
516 static ssize_t
show_beep(struct device
*dev
, struct device_attribute
*attr
,
519 struct w83781d_data
*data
= w83781d_update_device(dev
);
520 int bitnr
= to_sensor_dev_attr(attr
)->index
;
521 return sprintf(buf
, "%u\n", (data
->beep_mask
>> bitnr
) & 1);
525 store_beep(struct device
*dev
, struct device_attribute
*attr
,
526 const char *buf
, size_t count
)
528 struct w83781d_data
*data
= dev_get_drvdata(dev
);
529 int bitnr
= to_sensor_dev_attr(attr
)->index
;
533 bit
= simple_strtoul(buf
, NULL
, 10);
537 mutex_lock(&data
->update_lock
);
539 data
->beep_mask
|= (1 << bitnr
);
541 data
->beep_mask
&= ~(1 << bitnr
);
544 reg
= w83781d_read_value(data
, W83781D_REG_BEEP_INTS1
);
548 reg
&= ~(1 << bitnr
);
549 w83781d_write_value(data
, W83781D_REG_BEEP_INTS1
, reg
);
550 } else if (bitnr
< 16) {
551 reg
= w83781d_read_value(data
, W83781D_REG_BEEP_INTS2
);
553 reg
|= (1 << (bitnr
- 8));
555 reg
&= ~(1 << (bitnr
- 8));
556 w83781d_write_value(data
, W83781D_REG_BEEP_INTS2
, reg
);
558 reg
= w83781d_read_value(data
, W83781D_REG_BEEP_INTS3
);
560 reg
|= (1 << (bitnr
- 16));
562 reg
&= ~(1 << (bitnr
- 16));
563 w83781d_write_value(data
, W83781D_REG_BEEP_INTS3
, reg
);
565 mutex_unlock(&data
->update_lock
);
570 /* The W83781D has a single beep bit for temp2 and temp3 */
571 static ssize_t
show_temp3_beep(struct device
*dev
,
572 struct device_attribute
*attr
, char *buf
)
574 struct w83781d_data
*data
= w83781d_update_device(dev
);
575 int bitnr
= (data
->type
== w83781d
) ? 5 : 13;
576 return sprintf(buf
, "%u\n", (data
->beep_mask
>> bitnr
) & 1);
579 static SENSOR_DEVICE_ATTR(in0_beep
, S_IRUGO
| S_IWUSR
,
580 show_beep
, store_beep
, 0);
581 static SENSOR_DEVICE_ATTR(in1_beep
, S_IRUGO
| S_IWUSR
,
582 show_beep
, store_beep
, 1);
583 static SENSOR_DEVICE_ATTR(in2_beep
, S_IRUGO
| S_IWUSR
,
584 show_beep
, store_beep
, 2);
585 static SENSOR_DEVICE_ATTR(in3_beep
, S_IRUGO
| S_IWUSR
,
586 show_beep
, store_beep
, 3);
587 static SENSOR_DEVICE_ATTR(in4_beep
, S_IRUGO
| S_IWUSR
,
588 show_beep
, store_beep
, 8);
589 static SENSOR_DEVICE_ATTR(in5_beep
, S_IRUGO
| S_IWUSR
,
590 show_beep
, store_beep
, 9);
591 static SENSOR_DEVICE_ATTR(in6_beep
, S_IRUGO
| S_IWUSR
,
592 show_beep
, store_beep
, 10);
593 static SENSOR_DEVICE_ATTR(in7_beep
, S_IRUGO
| S_IWUSR
,
594 show_beep
, store_beep
, 16);
595 static SENSOR_DEVICE_ATTR(in8_beep
, S_IRUGO
| S_IWUSR
,
596 show_beep
, store_beep
, 17);
597 static SENSOR_DEVICE_ATTR(fan1_beep
, S_IRUGO
| S_IWUSR
,
598 show_beep
, store_beep
, 6);
599 static SENSOR_DEVICE_ATTR(fan2_beep
, S_IRUGO
| S_IWUSR
,
600 show_beep
, store_beep
, 7);
601 static SENSOR_DEVICE_ATTR(fan3_beep
, S_IRUGO
| S_IWUSR
,
602 show_beep
, store_beep
, 11);
603 static SENSOR_DEVICE_ATTR(temp1_beep
, S_IRUGO
| S_IWUSR
,
604 show_beep
, store_beep
, 4);
605 static SENSOR_DEVICE_ATTR(temp2_beep
, S_IRUGO
| S_IWUSR
,
606 show_beep
, store_beep
, 5);
607 static SENSOR_DEVICE_ATTR(temp3_beep
, S_IRUGO
,
608 show_temp3_beep
, store_beep
, 13);
609 static SENSOR_DEVICE_ATTR(beep_enable
, S_IRUGO
| S_IWUSR
,
610 show_beep
, store_beep
, 15);
613 show_fan_div(struct device
*dev
, struct device_attribute
*da
, char *buf
)
615 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(da
);
616 struct w83781d_data
*data
= w83781d_update_device(dev
);
617 return sprintf(buf
, "%ld\n",
618 (long) DIV_FROM_REG(data
->fan_div
[attr
->index
]));
621 /* Note: we save and restore the fan minimum here, because its value is
622 determined in part by the fan divisor. This follows the principle of
623 least surprise; the user doesn't expect the fan minimum to change just
624 because the divisor changed. */
626 store_fan_div(struct device
*dev
, struct device_attribute
*da
,
627 const char *buf
, size_t count
)
629 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(da
);
630 struct w83781d_data
*data
= dev_get_drvdata(dev
);
632 int nr
= attr
->index
;
634 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
636 mutex_lock(&data
->update_lock
);
639 min
= FAN_FROM_REG(data
->fan_min
[nr
],
640 DIV_FROM_REG(data
->fan_div
[nr
]));
642 data
->fan_div
[nr
] = DIV_TO_REG(val
, data
->type
);
644 reg
= (w83781d_read_value(data
, nr
==2 ? W83781D_REG_PIN
: W83781D_REG_VID_FANDIV
)
645 & (nr
==0 ? 0xcf : 0x3f))
646 | ((data
->fan_div
[nr
] & 0x03) << (nr
==0 ? 4 : 6));
647 w83781d_write_value(data
, nr
==2 ? W83781D_REG_PIN
: W83781D_REG_VID_FANDIV
, reg
);
649 /* w83781d and as99127f don't have extended divisor bits */
650 if (data
->type
!= w83781d
&& data
->type
!= as99127f
) {
651 reg
= (w83781d_read_value(data
, W83781D_REG_VBAT
)
653 | ((data
->fan_div
[nr
] & 0x04) << (3 + nr
));
654 w83781d_write_value(data
, W83781D_REG_VBAT
, reg
);
657 /* Restore fan_min */
658 data
->fan_min
[nr
] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
659 w83781d_write_value(data
, W83781D_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
661 mutex_unlock(&data
->update_lock
);
665 static SENSOR_DEVICE_ATTR(fan1_div
, S_IRUGO
| S_IWUSR
,
666 show_fan_div
, store_fan_div
, 0);
667 static SENSOR_DEVICE_ATTR(fan2_div
, S_IRUGO
| S_IWUSR
,
668 show_fan_div
, store_fan_div
, 1);
669 static SENSOR_DEVICE_ATTR(fan3_div
, S_IRUGO
| S_IWUSR
,
670 show_fan_div
, store_fan_div
, 2);
673 show_pwm(struct device
*dev
, struct device_attribute
*da
, char *buf
)
675 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(da
);
676 struct w83781d_data
*data
= w83781d_update_device(dev
);
677 return sprintf(buf
, "%d\n", (int)data
->pwm
[attr
->index
]);
681 show_pwm2_enable(struct device
*dev
, struct device_attribute
*da
, char *buf
)
683 struct w83781d_data
*data
= w83781d_update_device(dev
);
684 return sprintf(buf
, "%d\n", (int)data
->pwm2_enable
);
688 store_pwm(struct device
*dev
, struct device_attribute
*da
, const char *buf
,
691 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(da
);
692 struct w83781d_data
*data
= dev_get_drvdata(dev
);
693 int nr
= attr
->index
;
696 val
= simple_strtoul(buf
, NULL
, 10);
698 mutex_lock(&data
->update_lock
);
699 data
->pwm
[nr
] = SENSORS_LIMIT(val
, 0, 255);
700 w83781d_write_value(data
, W83781D_REG_PWM
[nr
], data
->pwm
[nr
]);
701 mutex_unlock(&data
->update_lock
);
706 store_pwm2_enable(struct device
*dev
, struct device_attribute
*da
,
707 const char *buf
, size_t count
)
709 struct w83781d_data
*data
= dev_get_drvdata(dev
);
712 val
= simple_strtoul(buf
, NULL
, 10);
714 mutex_lock(&data
->update_lock
);
719 reg
= w83781d_read_value(data
, W83781D_REG_PWMCLK12
);
720 w83781d_write_value(data
, W83781D_REG_PWMCLK12
,
721 (reg
& 0xf7) | (val
<< 3));
723 reg
= w83781d_read_value(data
, W83781D_REG_BEEP_CONFIG
);
724 w83781d_write_value(data
, W83781D_REG_BEEP_CONFIG
,
725 (reg
& 0xef) | (!val
<< 4));
727 data
->pwm2_enable
= val
;
731 mutex_unlock(&data
->update_lock
);
735 mutex_unlock(&data
->update_lock
);
739 static SENSOR_DEVICE_ATTR(pwm1
, S_IRUGO
| S_IWUSR
, show_pwm
, store_pwm
, 0);
740 static SENSOR_DEVICE_ATTR(pwm2
, S_IRUGO
| S_IWUSR
, show_pwm
, store_pwm
, 1);
741 static SENSOR_DEVICE_ATTR(pwm3
, S_IRUGO
| S_IWUSR
, show_pwm
, store_pwm
, 2);
742 static SENSOR_DEVICE_ATTR(pwm4
, S_IRUGO
| S_IWUSR
, show_pwm
, store_pwm
, 3);
743 /* only PWM2 can be enabled/disabled */
744 static DEVICE_ATTR(pwm2_enable
, S_IRUGO
| S_IWUSR
,
745 show_pwm2_enable
, store_pwm2_enable
);
748 show_sensor(struct device
*dev
, struct device_attribute
*da
, char *buf
)
750 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(da
);
751 struct w83781d_data
*data
= w83781d_update_device(dev
);
752 return sprintf(buf
, "%d\n", (int)data
->sens
[attr
->index
]);
756 store_sensor(struct device
*dev
, struct device_attribute
*da
,
757 const char *buf
, size_t count
)
759 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(da
);
760 struct w83781d_data
*data
= dev_get_drvdata(dev
);
761 int nr
= attr
->index
;
764 val
= simple_strtoul(buf
, NULL
, 10);
766 mutex_lock(&data
->update_lock
);
769 case 1: /* PII/Celeron diode */
770 tmp
= w83781d_read_value(data
, W83781D_REG_SCFG1
);
771 w83781d_write_value(data
, W83781D_REG_SCFG1
,
772 tmp
| BIT_SCFG1
[nr
]);
773 tmp
= w83781d_read_value(data
, W83781D_REG_SCFG2
);
774 w83781d_write_value(data
, W83781D_REG_SCFG2
,
775 tmp
| BIT_SCFG2
[nr
]);
776 data
->sens
[nr
] = val
;
779 tmp
= w83781d_read_value(data
, W83781D_REG_SCFG1
);
780 w83781d_write_value(data
, W83781D_REG_SCFG1
,
781 tmp
| BIT_SCFG1
[nr
]);
782 tmp
= w83781d_read_value(data
, W83781D_REG_SCFG2
);
783 w83781d_write_value(data
, W83781D_REG_SCFG2
,
784 tmp
& ~BIT_SCFG2
[nr
]);
785 data
->sens
[nr
] = val
;
787 case W83781D_DEFAULT_BETA
:
788 dev_warn(dev
, "Sensor type %d is deprecated, please use 4 "
789 "instead\n", W83781D_DEFAULT_BETA
);
791 case 4: /* thermistor */
792 tmp
= w83781d_read_value(data
, W83781D_REG_SCFG1
);
793 w83781d_write_value(data
, W83781D_REG_SCFG1
,
794 tmp
& ~BIT_SCFG1
[nr
]);
795 data
->sens
[nr
] = val
;
798 dev_err(dev
, "Invalid sensor type %ld; must be 1, 2, or 4\n",
803 mutex_unlock(&data
->update_lock
);
807 static SENSOR_DEVICE_ATTR(temp1_type
, S_IRUGO
| S_IWUSR
,
808 show_sensor
, store_sensor
, 0);
809 static SENSOR_DEVICE_ATTR(temp2_type
, S_IRUGO
| S_IWUSR
,
810 show_sensor
, store_sensor
, 1);
811 static SENSOR_DEVICE_ATTR(temp3_type
, S_IRUGO
| S_IWUSR
,
812 show_sensor
, store_sensor
, 2);
814 /* Assumes that adapter is of I2C, not ISA variety.
815 * OTHERWISE DON'T CALL THIS
818 w83781d_detect_subclients(struct i2c_client
*new_client
)
822 int address
= new_client
->addr
;
823 unsigned short sc_addr
[2];
824 struct i2c_adapter
*adapter
= new_client
->adapter
;
825 struct w83781d_data
*data
= i2c_get_clientdata(new_client
);
826 enum chips kind
= data
->type
;
828 id
= i2c_adapter_id(adapter
);
830 if (force_subclients
[0] == id
&& force_subclients
[1] == address
) {
831 for (i
= 2; i
<= 3; i
++) {
832 if (force_subclients
[i
] < 0x48 ||
833 force_subclients
[i
] > 0x4f) {
834 dev_err(&new_client
->dev
, "Invalid subclient "
835 "address %d; must be 0x48-0x4f\n",
836 force_subclients
[i
]);
841 w83781d_write_value(data
, W83781D_REG_I2C_SUBADDR
,
842 (force_subclients
[2] & 0x07) |
843 ((force_subclients
[3] & 0x07) << 4));
844 sc_addr
[0] = force_subclients
[2];
846 val1
= w83781d_read_value(data
, W83781D_REG_I2C_SUBADDR
);
847 sc_addr
[0] = 0x48 + (val1
& 0x07);
850 if (kind
!= w83783s
) {
851 if (force_subclients
[0] == id
&&
852 force_subclients
[1] == address
) {
853 sc_addr
[1] = force_subclients
[3];
855 sc_addr
[1] = 0x48 + ((val1
>> 4) & 0x07);
857 if (sc_addr
[0] == sc_addr
[1]) {
858 dev_err(&new_client
->dev
,
859 "Duplicate addresses 0x%x for subclients.\n",
866 for (i
= 0; i
<= 1; i
++) {
867 data
->lm75
[i
] = i2c_new_dummy(adapter
, sc_addr
[i
]);
868 if (!data
->lm75
[i
]) {
869 dev_err(&new_client
->dev
, "Subclient %d "
870 "registration at address 0x%x "
871 "failed.\n", i
, sc_addr
[i
]);
883 /* Undo inits in case of errors */
885 i2c_unregister_device(data
->lm75
[0]);
891 #define IN_UNIT_ATTRS(X) \
892 &sensor_dev_attr_in##X##_input.dev_attr.attr, \
893 &sensor_dev_attr_in##X##_min.dev_attr.attr, \
894 &sensor_dev_attr_in##X##_max.dev_attr.attr, \
895 &sensor_dev_attr_in##X##_alarm.dev_attr.attr, \
896 &sensor_dev_attr_in##X##_beep.dev_attr.attr
898 #define FAN_UNIT_ATTRS(X) \
899 &sensor_dev_attr_fan##X##_input.dev_attr.attr, \
900 &sensor_dev_attr_fan##X##_min.dev_attr.attr, \
901 &sensor_dev_attr_fan##X##_div.dev_attr.attr, \
902 &sensor_dev_attr_fan##X##_alarm.dev_attr.attr, \
903 &sensor_dev_attr_fan##X##_beep.dev_attr.attr
905 #define TEMP_UNIT_ATTRS(X) \
906 &sensor_dev_attr_temp##X##_input.dev_attr.attr, \
907 &sensor_dev_attr_temp##X##_max.dev_attr.attr, \
908 &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr, \
909 &sensor_dev_attr_temp##X##_alarm.dev_attr.attr, \
910 &sensor_dev_attr_temp##X##_beep.dev_attr.attr
912 static struct attribute
* w83781d_attributes
[] = {
924 &dev_attr_cpu0_vid
.attr
,
926 &dev_attr_alarms
.attr
,
927 &dev_attr_beep_mask
.attr
,
928 &sensor_dev_attr_beep_enable
.dev_attr
.attr
,
931 static const struct attribute_group w83781d_group
= {
932 .attrs
= w83781d_attributes
,
935 static struct attribute
*w83781d_attributes_opt
[] = {
940 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
941 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
942 &sensor_dev_attr_pwm3
.dev_attr
.attr
,
943 &sensor_dev_attr_pwm4
.dev_attr
.attr
,
944 &dev_attr_pwm2_enable
.attr
,
945 &sensor_dev_attr_temp1_type
.dev_attr
.attr
,
946 &sensor_dev_attr_temp2_type
.dev_attr
.attr
,
947 &sensor_dev_attr_temp3_type
.dev_attr
.attr
,
950 static const struct attribute_group w83781d_group_opt
= {
951 .attrs
= w83781d_attributes_opt
,
954 /* No clean up is done on error, it's up to the caller */
956 w83781d_create_files(struct device
*dev
, int kind
, int is_isa
)
960 if ((err
= sysfs_create_group(&dev
->kobj
, &w83781d_group
)))
963 if (kind
!= w83783s
) {
964 if ((err
= device_create_file(dev
,
965 &sensor_dev_attr_in1_input
.dev_attr
))
966 || (err
= device_create_file(dev
,
967 &sensor_dev_attr_in1_min
.dev_attr
))
968 || (err
= device_create_file(dev
,
969 &sensor_dev_attr_in1_max
.dev_attr
))
970 || (err
= device_create_file(dev
,
971 &sensor_dev_attr_in1_alarm
.dev_attr
))
972 || (err
= device_create_file(dev
,
973 &sensor_dev_attr_in1_beep
.dev_attr
)))
976 if (kind
!= as99127f
&& kind
!= w83781d
&& kind
!= w83783s
) {
977 if ((err
= device_create_file(dev
,
978 &sensor_dev_attr_in7_input
.dev_attr
))
979 || (err
= device_create_file(dev
,
980 &sensor_dev_attr_in7_min
.dev_attr
))
981 || (err
= device_create_file(dev
,
982 &sensor_dev_attr_in7_max
.dev_attr
))
983 || (err
= device_create_file(dev
,
984 &sensor_dev_attr_in7_alarm
.dev_attr
))
985 || (err
= device_create_file(dev
,
986 &sensor_dev_attr_in7_beep
.dev_attr
))
987 || (err
= device_create_file(dev
,
988 &sensor_dev_attr_in8_input
.dev_attr
))
989 || (err
= device_create_file(dev
,
990 &sensor_dev_attr_in8_min
.dev_attr
))
991 || (err
= device_create_file(dev
,
992 &sensor_dev_attr_in8_max
.dev_attr
))
993 || (err
= device_create_file(dev
,
994 &sensor_dev_attr_in8_alarm
.dev_attr
))
995 || (err
= device_create_file(dev
,
996 &sensor_dev_attr_in8_beep
.dev_attr
)))
999 if (kind
!= w83783s
) {
1000 if ((err
= device_create_file(dev
,
1001 &sensor_dev_attr_temp3_input
.dev_attr
))
1002 || (err
= device_create_file(dev
,
1003 &sensor_dev_attr_temp3_max
.dev_attr
))
1004 || (err
= device_create_file(dev
,
1005 &sensor_dev_attr_temp3_max_hyst
.dev_attr
))
1006 || (err
= device_create_file(dev
,
1007 &sensor_dev_attr_temp3_alarm
.dev_attr
))
1008 || (err
= device_create_file(dev
,
1009 &sensor_dev_attr_temp3_beep
.dev_attr
)))
1012 if (kind
!= w83781d
) {
1013 err
= sysfs_chmod_file(&dev
->kobj
,
1014 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
1021 if (kind
!= w83781d
&& kind
!= as99127f
) {
1022 if ((err
= device_create_file(dev
,
1023 &sensor_dev_attr_pwm1
.dev_attr
))
1024 || (err
= device_create_file(dev
,
1025 &sensor_dev_attr_pwm2
.dev_attr
))
1026 || (err
= device_create_file(dev
, &dev_attr_pwm2_enable
)))
1029 if (kind
== w83782d
&& !is_isa
) {
1030 if ((err
= device_create_file(dev
,
1031 &sensor_dev_attr_pwm3
.dev_attr
))
1032 || (err
= device_create_file(dev
,
1033 &sensor_dev_attr_pwm4
.dev_attr
)))
1037 if (kind
!= as99127f
&& kind
!= w83781d
) {
1038 if ((err
= device_create_file(dev
,
1039 &sensor_dev_attr_temp1_type
.dev_attr
))
1040 || (err
= device_create_file(dev
,
1041 &sensor_dev_attr_temp2_type
.dev_attr
)))
1043 if (kind
!= w83783s
) {
1044 if ((err
= device_create_file(dev
,
1045 &sensor_dev_attr_temp3_type
.dev_attr
)))
1053 /* Return 0 if detection is successful, -ENODEV otherwise */
1055 w83781d_detect(struct i2c_client
*client
, struct i2c_board_info
*info
)
1058 struct w83781d_data
*isa
= w83781d_data_if_isa();
1059 struct i2c_adapter
*adapter
= client
->adapter
;
1060 int address
= client
->addr
;
1061 const char *client_name
;
1062 enum vendor
{ winbond
, asus
} vendid
;
1064 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
1067 /* We block updates of the ISA device to minimize the risk of
1068 concurrent access to the same W83781D chip through different
1071 mutex_lock(&isa
->update_lock
);
1073 if (i2c_smbus_read_byte_data(client
, W83781D_REG_CONFIG
) & 0x80) {
1074 dev_dbg(&adapter
->dev
,
1075 "Detection of w83781d chip failed at step 3\n");
1079 val1
= i2c_smbus_read_byte_data(client
, W83781D_REG_BANK
);
1080 val2
= i2c_smbus_read_byte_data(client
, W83781D_REG_CHIPMAN
);
1081 /* Check for Winbond or Asus ID if in bank 0 */
1082 if (!(val1
& 0x07) &&
1083 ((!(val1
& 0x80) && val2
!= 0xa3 && val2
!= 0xc3) ||
1084 ( (val1
& 0x80) && val2
!= 0x5c && val2
!= 0x12))) {
1085 dev_dbg(&adapter
->dev
,
1086 "Detection of w83781d chip failed at step 4\n");
1089 /* If Winbond SMBus, check address at 0x48.
1090 Asus doesn't support, except for as99127f rev.2 */
1091 if ((!(val1
& 0x80) && val2
== 0xa3) ||
1092 ( (val1
& 0x80) && val2
== 0x5c)) {
1093 if (i2c_smbus_read_byte_data(client
, W83781D_REG_I2C_ADDR
)
1095 dev_dbg(&adapter
->dev
,
1096 "Detection of w83781d chip failed at step 5\n");
1101 /* Put it now into bank 0 and Vendor ID High Byte */
1102 i2c_smbus_write_byte_data(client
, W83781D_REG_BANK
,
1103 (i2c_smbus_read_byte_data(client
, W83781D_REG_BANK
)
1106 /* Get the vendor ID */
1107 val2
= i2c_smbus_read_byte_data(client
, W83781D_REG_CHIPMAN
);
1110 else if (val2
== 0x12)
1113 dev_dbg(&adapter
->dev
,
1114 "w83781d chip vendor is neither Winbond nor Asus\n");
1118 /* Determine the chip type. */
1119 val1
= i2c_smbus_read_byte_data(client
, W83781D_REG_WCHIPID
);
1120 if ((val1
== 0x10 || val1
== 0x11) && vendid
== winbond
)
1121 client_name
= "w83781d";
1122 else if (val1
== 0x30 && vendid
== winbond
)
1123 client_name
= "w83782d";
1124 else if (val1
== 0x40 && vendid
== winbond
&& address
== 0x2d)
1125 client_name
= "w83783s";
1126 else if (val1
== 0x31)
1127 client_name
= "as99127f";
1131 if (val1
<= 0x30 && w83781d_alias_detect(client
, val1
)) {
1132 dev_dbg(&adapter
->dev
, "Device at 0x%02x appears to "
1133 "be the same as ISA device\n", address
);
1138 mutex_unlock(&isa
->update_lock
);
1140 strlcpy(info
->type
, client_name
, I2C_NAME_SIZE
);
1146 mutex_unlock(&isa
->update_lock
);
1151 w83781d_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
1153 struct device
*dev
= &client
->dev
;
1154 struct w83781d_data
*data
;
1157 data
= kzalloc(sizeof(struct w83781d_data
), GFP_KERNEL
);
1163 i2c_set_clientdata(client
, data
);
1164 mutex_init(&data
->lock
);
1165 mutex_init(&data
->update_lock
);
1167 data
->type
= id
->driver_data
;
1168 data
->client
= client
;
1170 /* attach secondary i2c lm75-like clients */
1171 err
= w83781d_detect_subclients(client
);
1175 /* Initialize the chip */
1176 w83781d_init_device(dev
);
1178 /* Register sysfs hooks */
1179 err
= w83781d_create_files(dev
, data
->type
, 0);
1183 data
->hwmon_dev
= hwmon_device_register(dev
);
1184 if (IS_ERR(data
->hwmon_dev
)) {
1185 err
= PTR_ERR(data
->hwmon_dev
);
1192 sysfs_remove_group(&dev
->kobj
, &w83781d_group
);
1193 sysfs_remove_group(&dev
->kobj
, &w83781d_group_opt
);
1196 i2c_unregister_device(data
->lm75
[0]);
1198 i2c_unregister_device(data
->lm75
[1]);
1206 w83781d_remove(struct i2c_client
*client
)
1208 struct w83781d_data
*data
= i2c_get_clientdata(client
);
1209 struct device
*dev
= &client
->dev
;
1211 hwmon_device_unregister(data
->hwmon_dev
);
1213 sysfs_remove_group(&dev
->kobj
, &w83781d_group
);
1214 sysfs_remove_group(&dev
->kobj
, &w83781d_group_opt
);
1217 i2c_unregister_device(data
->lm75
[0]);
1219 i2c_unregister_device(data
->lm75
[1]);
1227 w83781d_read_value_i2c(struct w83781d_data
*data
, u16 reg
)
1229 struct i2c_client
*client
= data
->client
;
1231 struct i2c_client
*cl
;
1233 bank
= (reg
>> 8) & 0x0f;
1236 i2c_smbus_write_byte_data(client
, W83781D_REG_BANK
,
1238 if (bank
== 0 || bank
> 2) {
1239 res
= i2c_smbus_read_byte_data(client
, reg
& 0xff);
1241 /* switch to subclient */
1242 cl
= data
->lm75
[bank
- 1];
1243 /* convert from ISA to LM75 I2C addresses */
1244 switch (reg
& 0xff) {
1245 case 0x50: /* TEMP */
1246 res
= swab16(i2c_smbus_read_word_data(cl
, 0));
1248 case 0x52: /* CONFIG */
1249 res
= i2c_smbus_read_byte_data(cl
, 1);
1251 case 0x53: /* HYST */
1252 res
= swab16(i2c_smbus_read_word_data(cl
, 2));
1254 case 0x55: /* OVER */
1256 res
= swab16(i2c_smbus_read_word_data(cl
, 3));
1261 i2c_smbus_write_byte_data(client
, W83781D_REG_BANK
, 0);
1267 w83781d_write_value_i2c(struct w83781d_data
*data
, u16 reg
, u16 value
)
1269 struct i2c_client
*client
= data
->client
;
1271 struct i2c_client
*cl
;
1273 bank
= (reg
>> 8) & 0x0f;
1276 i2c_smbus_write_byte_data(client
, W83781D_REG_BANK
,
1278 if (bank
== 0 || bank
> 2) {
1279 i2c_smbus_write_byte_data(client
, reg
& 0xff,
1282 /* switch to subclient */
1283 cl
= data
->lm75
[bank
- 1];
1284 /* convert from ISA to LM75 I2C addresses */
1285 switch (reg
& 0xff) {
1286 case 0x52: /* CONFIG */
1287 i2c_smbus_write_byte_data(cl
, 1, value
& 0xff);
1289 case 0x53: /* HYST */
1290 i2c_smbus_write_word_data(cl
, 2, swab16(value
));
1292 case 0x55: /* OVER */
1293 i2c_smbus_write_word_data(cl
, 3, swab16(value
));
1298 i2c_smbus_write_byte_data(client
, W83781D_REG_BANK
, 0);
1304 w83781d_init_device(struct device
*dev
)
1306 struct w83781d_data
*data
= dev_get_drvdata(dev
);
1308 int type
= data
->type
;
1311 if (reset
&& type
!= as99127f
) { /* this resets registers we don't have
1312 documentation for on the as99127f */
1313 /* Resetting the chip has been the default for a long time,
1314 but it causes the BIOS initializations (fan clock dividers,
1315 thermal sensor types...) to be lost, so it is now optional.
1316 It might even go away if nobody reports it as being useful,
1317 as I see very little reason why this would be needed at
1319 dev_info(dev
, "If reset=1 solved a problem you were "
1320 "having, please report!\n");
1322 /* save these registers */
1323 i
= w83781d_read_value(data
, W83781D_REG_BEEP_CONFIG
);
1324 p
= w83781d_read_value(data
, W83781D_REG_PWMCLK12
);
1325 /* Reset all except Watchdog values and last conversion values
1326 This sets fan-divs to 2, among others */
1327 w83781d_write_value(data
, W83781D_REG_CONFIG
, 0x80);
1328 /* Restore the registers and disable power-on abnormal beep.
1329 This saves FAN 1/2/3 input/output values set by BIOS. */
1330 w83781d_write_value(data
, W83781D_REG_BEEP_CONFIG
, i
| 0x80);
1331 w83781d_write_value(data
, W83781D_REG_PWMCLK12
, p
);
1332 /* Disable master beep-enable (reset turns it on).
1333 Individual beep_mask should be reset to off but for some reason
1334 disabling this bit helps some people not get beeped */
1335 w83781d_write_value(data
, W83781D_REG_BEEP_INTS2
, 0);
1338 /* Disable power-on abnormal beep, as advised by the datasheet.
1339 Already done if reset=1. */
1340 if (init
&& !reset
&& type
!= as99127f
) {
1341 i
= w83781d_read_value(data
, W83781D_REG_BEEP_CONFIG
);
1342 w83781d_write_value(data
, W83781D_REG_BEEP_CONFIG
, i
| 0x80);
1345 data
->vrm
= vid_which_vrm();
1347 if ((type
!= w83781d
) && (type
!= as99127f
)) {
1348 tmp
= w83781d_read_value(data
, W83781D_REG_SCFG1
);
1349 for (i
= 1; i
<= 3; i
++) {
1350 if (!(tmp
& BIT_SCFG1
[i
- 1])) {
1351 data
->sens
[i
- 1] = 4;
1353 if (w83781d_read_value
1355 W83781D_REG_SCFG2
) & BIT_SCFG2
[i
- 1])
1356 data
->sens
[i
- 1] = 1;
1358 data
->sens
[i
- 1] = 2;
1360 if (type
== w83783s
&& i
== 2)
1365 if (init
&& type
!= as99127f
) {
1367 tmp
= w83781d_read_value(data
, W83781D_REG_TEMP2_CONFIG
);
1369 dev_warn(dev
, "Enabling temp2, readings "
1370 "might not make sense\n");
1371 w83781d_write_value(data
, W83781D_REG_TEMP2_CONFIG
,
1376 if (type
!= w83783s
) {
1377 tmp
= w83781d_read_value(data
,
1378 W83781D_REG_TEMP3_CONFIG
);
1380 dev_warn(dev
, "Enabling temp3, "
1381 "readings might not make sense\n");
1382 w83781d_write_value(data
,
1383 W83781D_REG_TEMP3_CONFIG
, tmp
& 0xfe);
1388 /* Start monitoring */
1389 w83781d_write_value(data
, W83781D_REG_CONFIG
,
1390 (w83781d_read_value(data
,
1391 W83781D_REG_CONFIG
) & 0xf7)
1394 /* A few vars need to be filled upon startup */
1395 for (i
= 0; i
< 3; i
++) {
1396 data
->fan_min
[i
] = w83781d_read_value(data
,
1397 W83781D_REG_FAN_MIN(i
));
1400 mutex_init(&data
->update_lock
);
1403 static struct w83781d_data
*w83781d_update_device(struct device
*dev
)
1405 struct w83781d_data
*data
= dev_get_drvdata(dev
);
1406 struct i2c_client
*client
= data
->client
;
1409 mutex_lock(&data
->update_lock
);
1411 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
1413 dev_dbg(dev
, "Starting device update\n");
1415 for (i
= 0; i
<= 8; i
++) {
1416 if (data
->type
== w83783s
&& i
== 1)
1417 continue; /* 783S has no in1 */
1419 w83781d_read_value(data
, W83781D_REG_IN(i
));
1421 w83781d_read_value(data
, W83781D_REG_IN_MIN(i
));
1423 w83781d_read_value(data
, W83781D_REG_IN_MAX(i
));
1424 if ((data
->type
!= w83782d
) && (i
== 6))
1427 for (i
= 0; i
< 3; i
++) {
1429 w83781d_read_value(data
, W83781D_REG_FAN(i
));
1431 w83781d_read_value(data
, W83781D_REG_FAN_MIN(i
));
1433 if (data
->type
!= w83781d
&& data
->type
!= as99127f
) {
1434 for (i
= 0; i
< 4; i
++) {
1436 w83781d_read_value(data
,
1437 W83781D_REG_PWM
[i
]);
1438 /* Only W83782D on SMBus has PWM3 and PWM4 */
1439 if ((data
->type
!= w83782d
|| !client
)
1443 /* Only PWM2 can be disabled */
1444 data
->pwm2_enable
= (w83781d_read_value(data
,
1445 W83781D_REG_PWMCLK12
) & 0x08) >> 3;
1448 data
->temp
= w83781d_read_value(data
, W83781D_REG_TEMP(1));
1450 w83781d_read_value(data
, W83781D_REG_TEMP_OVER(1));
1451 data
->temp_max_hyst
=
1452 w83781d_read_value(data
, W83781D_REG_TEMP_HYST(1));
1454 w83781d_read_value(data
, W83781D_REG_TEMP(2));
1455 data
->temp_max_add
[0] =
1456 w83781d_read_value(data
, W83781D_REG_TEMP_OVER(2));
1457 data
->temp_max_hyst_add
[0] =
1458 w83781d_read_value(data
, W83781D_REG_TEMP_HYST(2));
1459 if (data
->type
!= w83783s
) {
1461 w83781d_read_value(data
, W83781D_REG_TEMP(3));
1462 data
->temp_max_add
[1] =
1463 w83781d_read_value(data
,
1464 W83781D_REG_TEMP_OVER(3));
1465 data
->temp_max_hyst_add
[1] =
1466 w83781d_read_value(data
,
1467 W83781D_REG_TEMP_HYST(3));
1469 i
= w83781d_read_value(data
, W83781D_REG_VID_FANDIV
);
1470 data
->vid
= i
& 0x0f;
1471 data
->vid
|= (w83781d_read_value(data
,
1472 W83781D_REG_CHIPID
) & 0x01) << 4;
1473 data
->fan_div
[0] = (i
>> 4) & 0x03;
1474 data
->fan_div
[1] = (i
>> 6) & 0x03;
1475 data
->fan_div
[2] = (w83781d_read_value(data
,
1476 W83781D_REG_PIN
) >> 6) & 0x03;
1477 if ((data
->type
!= w83781d
) && (data
->type
!= as99127f
)) {
1478 i
= w83781d_read_value(data
, W83781D_REG_VBAT
);
1479 data
->fan_div
[0] |= (i
>> 3) & 0x04;
1480 data
->fan_div
[1] |= (i
>> 4) & 0x04;
1481 data
->fan_div
[2] |= (i
>> 5) & 0x04;
1483 if (data
->type
== w83782d
) {
1484 data
->alarms
= w83781d_read_value(data
,
1486 | (w83781d_read_value(data
,
1487 W83782D_REG_ALARM2
) << 8)
1488 | (w83781d_read_value(data
,
1489 W83782D_REG_ALARM3
) << 16);
1490 } else if (data
->type
== w83783s
) {
1491 data
->alarms
= w83781d_read_value(data
,
1493 | (w83781d_read_value(data
,
1494 W83782D_REG_ALARM2
) << 8);
1496 /* No real-time status registers, fall back to
1497 interrupt status registers */
1498 data
->alarms
= w83781d_read_value(data
,
1500 | (w83781d_read_value(data
,
1501 W83781D_REG_ALARM2
) << 8);
1503 i
= w83781d_read_value(data
, W83781D_REG_BEEP_INTS2
);
1504 data
->beep_mask
= (i
<< 8) +
1505 w83781d_read_value(data
, W83781D_REG_BEEP_INTS1
);
1506 if ((data
->type
!= w83781d
) && (data
->type
!= as99127f
)) {
1508 w83781d_read_value(data
,
1509 W83781D_REG_BEEP_INTS3
) << 16;
1511 data
->last_updated
= jiffies
;
1515 mutex_unlock(&data
->update_lock
);
1520 static const struct i2c_device_id w83781d_ids
[] = {
1521 { "w83781d", w83781d
, },
1522 { "w83782d", w83782d
, },
1523 { "w83783s", w83783s
, },
1524 { "as99127f", as99127f
},
1527 MODULE_DEVICE_TABLE(i2c
, w83781d_ids
);
1529 static struct i2c_driver w83781d_driver
= {
1530 .class = I2C_CLASS_HWMON
,
1534 .probe
= w83781d_probe
,
1535 .remove
= w83781d_remove
,
1536 .id_table
= w83781d_ids
,
1537 .detect
= w83781d_detect
,
1538 .address_list
= normal_i2c
,
1546 /* ISA device, if found */
1547 static struct platform_device
*pdev
;
1549 static unsigned short isa_address
= 0x290;
1551 /* I2C devices get this name attribute automatically, but for ISA devices
1552 we must create it by ourselves. */
1554 show_name(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
1556 struct w83781d_data
*data
= dev_get_drvdata(dev
);
1557 return sprintf(buf
, "%s\n", data
->name
);
1559 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
1561 static struct w83781d_data
*w83781d_data_if_isa(void)
1563 return pdev
? platform_get_drvdata(pdev
) : NULL
;
1566 /* Returns 1 if the I2C chip appears to be an alias of the ISA chip */
1567 static int w83781d_alias_detect(struct i2c_client
*client
, u8 chipid
)
1569 struct w83781d_data
*isa
;
1572 if (!pdev
) /* No ISA chip */
1575 isa
= platform_get_drvdata(pdev
);
1577 if (w83781d_read_value(isa
, W83781D_REG_I2C_ADDR
) != client
->addr
)
1578 return 0; /* Address doesn't match */
1579 if (w83781d_read_value(isa
, W83781D_REG_WCHIPID
) != chipid
)
1580 return 0; /* Chip type doesn't match */
1582 /* We compare all the limit registers, the config register and the
1583 * interrupt mask registers */
1584 for (i
= 0x2b; i
<= 0x3d; i
++) {
1585 if (w83781d_read_value(isa
, i
) !=
1586 i2c_smbus_read_byte_data(client
, i
))
1589 if (w83781d_read_value(isa
, W83781D_REG_CONFIG
) !=
1590 i2c_smbus_read_byte_data(client
, W83781D_REG_CONFIG
))
1592 for (i
= 0x43; i
<= 0x46; i
++) {
1593 if (w83781d_read_value(isa
, i
) !=
1594 i2c_smbus_read_byte_data(client
, i
))
1602 w83781d_read_value_isa(struct w83781d_data
*data
, u16 reg
)
1604 int word_sized
, res
;
1606 word_sized
= (((reg
& 0xff00) == 0x100)
1607 || ((reg
& 0xff00) == 0x200))
1608 && (((reg
& 0x00ff) == 0x50)
1609 || ((reg
& 0x00ff) == 0x53)
1610 || ((reg
& 0x00ff) == 0x55));
1612 outb_p(W83781D_REG_BANK
,
1613 data
->isa_addr
+ W83781D_ADDR_REG_OFFSET
);
1615 data
->isa_addr
+ W83781D_DATA_REG_OFFSET
);
1617 outb_p(reg
& 0xff, data
->isa_addr
+ W83781D_ADDR_REG_OFFSET
);
1618 res
= inb_p(data
->isa_addr
+ W83781D_DATA_REG_OFFSET
);
1620 outb_p((reg
& 0xff) + 1,
1621 data
->isa_addr
+ W83781D_ADDR_REG_OFFSET
);
1623 (res
<< 8) + inb_p(data
->isa_addr
+
1624 W83781D_DATA_REG_OFFSET
);
1627 outb_p(W83781D_REG_BANK
,
1628 data
->isa_addr
+ W83781D_ADDR_REG_OFFSET
);
1629 outb_p(0, data
->isa_addr
+ W83781D_DATA_REG_OFFSET
);
1635 w83781d_write_value_isa(struct w83781d_data
*data
, u16 reg
, u16 value
)
1639 word_sized
= (((reg
& 0xff00) == 0x100)
1640 || ((reg
& 0xff00) == 0x200))
1641 && (((reg
& 0x00ff) == 0x53)
1642 || ((reg
& 0x00ff) == 0x55));
1644 outb_p(W83781D_REG_BANK
,
1645 data
->isa_addr
+ W83781D_ADDR_REG_OFFSET
);
1647 data
->isa_addr
+ W83781D_DATA_REG_OFFSET
);
1649 outb_p(reg
& 0xff, data
->isa_addr
+ W83781D_ADDR_REG_OFFSET
);
1652 data
->isa_addr
+ W83781D_DATA_REG_OFFSET
);
1653 outb_p((reg
& 0xff) + 1,
1654 data
->isa_addr
+ W83781D_ADDR_REG_OFFSET
);
1656 outb_p(value
& 0xff, data
->isa_addr
+ W83781D_DATA_REG_OFFSET
);
1658 outb_p(W83781D_REG_BANK
,
1659 data
->isa_addr
+ W83781D_ADDR_REG_OFFSET
);
1660 outb_p(0, data
->isa_addr
+ W83781D_DATA_REG_OFFSET
);
1664 /* The SMBus locks itself, usually, but nothing may access the Winbond between
1665 bank switches. ISA access must always be locked explicitly!
1666 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1667 would slow down the W83781D access and should not be necessary.
1668 There are some ugly typecasts here, but the good news is - they should
1669 nowhere else be necessary! */
1671 w83781d_read_value(struct w83781d_data
*data
, u16 reg
)
1673 struct i2c_client
*client
= data
->client
;
1676 mutex_lock(&data
->lock
);
1678 res
= w83781d_read_value_i2c(data
, reg
);
1680 res
= w83781d_read_value_isa(data
, reg
);
1681 mutex_unlock(&data
->lock
);
1686 w83781d_write_value(struct w83781d_data
*data
, u16 reg
, u16 value
)
1688 struct i2c_client
*client
= data
->client
;
1690 mutex_lock(&data
->lock
);
1692 w83781d_write_value_i2c(data
, reg
, value
);
1694 w83781d_write_value_isa(data
, reg
, value
);
1695 mutex_unlock(&data
->lock
);
1699 static int __devinit
1700 w83781d_isa_probe(struct platform_device
*pdev
)
1703 struct w83781d_data
*data
;
1704 struct resource
*res
;
1706 /* Reserve the ISA region */
1707 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
1708 if (!request_region(res
->start
+ W83781D_ADDR_REG_OFFSET
, 2,
1714 data
= kzalloc(sizeof(struct w83781d_data
), GFP_KERNEL
);
1717 goto exit_release_region
;
1719 mutex_init(&data
->lock
);
1720 data
->isa_addr
= res
->start
;
1721 platform_set_drvdata(pdev
, data
);
1723 reg
= w83781d_read_value(data
, W83781D_REG_WCHIPID
);
1726 data
->type
= w83782d
;
1727 data
->name
= "w83782d";
1730 data
->type
= w83781d
;
1731 data
->name
= "w83781d";
1734 /* Initialize the W83781D chip */
1735 w83781d_init_device(&pdev
->dev
);
1737 /* Register sysfs hooks */
1738 err
= w83781d_create_files(&pdev
->dev
, data
->type
, 1);
1740 goto exit_remove_files
;
1742 err
= device_create_file(&pdev
->dev
, &dev_attr_name
);
1744 goto exit_remove_files
;
1746 data
->hwmon_dev
= hwmon_device_register(&pdev
->dev
);
1747 if (IS_ERR(data
->hwmon_dev
)) {
1748 err
= PTR_ERR(data
->hwmon_dev
);
1749 goto exit_remove_files
;
1755 sysfs_remove_group(&pdev
->dev
.kobj
, &w83781d_group
);
1756 sysfs_remove_group(&pdev
->dev
.kobj
, &w83781d_group_opt
);
1757 device_remove_file(&pdev
->dev
, &dev_attr_name
);
1759 exit_release_region
:
1760 release_region(res
->start
+ W83781D_ADDR_REG_OFFSET
, 2);
1765 static int __devexit
1766 w83781d_isa_remove(struct platform_device
*pdev
)
1768 struct w83781d_data
*data
= platform_get_drvdata(pdev
);
1770 hwmon_device_unregister(data
->hwmon_dev
);
1771 sysfs_remove_group(&pdev
->dev
.kobj
, &w83781d_group
);
1772 sysfs_remove_group(&pdev
->dev
.kobj
, &w83781d_group_opt
);
1773 device_remove_file(&pdev
->dev
, &dev_attr_name
);
1774 release_region(data
->isa_addr
+ W83781D_ADDR_REG_OFFSET
, 2);
1780 static struct platform_driver w83781d_isa_driver
= {
1782 .owner
= THIS_MODULE
,
1785 .probe
= w83781d_isa_probe
,
1786 .remove
= __devexit_p(w83781d_isa_remove
),
1789 /* return 1 if a supported chip is found, 0 otherwise */
1791 w83781d_isa_found(unsigned short address
)
1793 int val
, save
, found
= 0;
1796 /* Some boards declare base+0 to base+7 as a PNP device, some base+4
1797 * to base+7 and some base+5 to base+6. So we better request each port
1798 * individually for the probing phase. */
1799 for (port
= address
; port
< address
+ W83781D_EXTENT
; port
++) {
1800 if (!request_region(port
, 1, "w83781d")) {
1801 pr_debug("w83781d: Failed to request port 0x%x\n",
1807 #define REALLY_SLOW_IO
1808 /* We need the timeouts for at least some W83781D-like
1809 chips. But only if we read 'undefined' registers. */
1810 val
= inb_p(address
+ 1);
1811 if (inb_p(address
+ 2) != val
1812 || inb_p(address
+ 3) != val
1813 || inb_p(address
+ 7) != val
) {
1814 pr_debug("w83781d: Detection failed at step 1\n");
1817 #undef REALLY_SLOW_IO
1819 /* We should be able to change the 7 LSB of the address port. The
1820 MSB (busy flag) should be clear initially, set after the write. */
1821 save
= inb_p(address
+ W83781D_ADDR_REG_OFFSET
);
1823 pr_debug("w83781d: Detection failed at step 2\n");
1827 outb_p(val
, address
+ W83781D_ADDR_REG_OFFSET
);
1828 if (inb_p(address
+ W83781D_ADDR_REG_OFFSET
) != (val
| 0x80)) {
1829 outb_p(save
, address
+ W83781D_ADDR_REG_OFFSET
);
1830 pr_debug("w83781d: Detection failed at step 3\n");
1834 /* We found a device, now see if it could be a W83781D */
1835 outb_p(W83781D_REG_CONFIG
, address
+ W83781D_ADDR_REG_OFFSET
);
1836 val
= inb_p(address
+ W83781D_DATA_REG_OFFSET
);
1838 pr_debug("w83781d: Detection failed at step 4\n");
1841 outb_p(W83781D_REG_BANK
, address
+ W83781D_ADDR_REG_OFFSET
);
1842 save
= inb_p(address
+ W83781D_DATA_REG_OFFSET
);
1843 outb_p(W83781D_REG_CHIPMAN
, address
+ W83781D_ADDR_REG_OFFSET
);
1844 val
= inb_p(address
+ W83781D_DATA_REG_OFFSET
);
1845 if ((!(save
& 0x80) && (val
!= 0xa3))
1846 || ((save
& 0x80) && (val
!= 0x5c))) {
1847 pr_debug("w83781d: Detection failed at step 5\n");
1850 outb_p(W83781D_REG_I2C_ADDR
, address
+ W83781D_ADDR_REG_OFFSET
);
1851 val
= inb_p(address
+ W83781D_DATA_REG_OFFSET
);
1852 if (val
< 0x03 || val
> 0x77) { /* Not a valid I2C address */
1853 pr_debug("w83781d: Detection failed at step 6\n");
1857 /* The busy flag should be clear again */
1858 if (inb_p(address
+ W83781D_ADDR_REG_OFFSET
) & 0x80) {
1859 pr_debug("w83781d: Detection failed at step 7\n");
1863 /* Determine the chip type */
1864 outb_p(W83781D_REG_BANK
, address
+ W83781D_ADDR_REG_OFFSET
);
1865 save
= inb_p(address
+ W83781D_DATA_REG_OFFSET
);
1866 outb_p(save
& 0xf8, address
+ W83781D_DATA_REG_OFFSET
);
1867 outb_p(W83781D_REG_WCHIPID
, address
+ W83781D_ADDR_REG_OFFSET
);
1868 val
= inb_p(address
+ W83781D_DATA_REG_OFFSET
);
1869 if ((val
& 0xfe) == 0x10 /* W83781D */
1870 || val
== 0x30) /* W83782D */
1874 pr_info("w83781d: Found a %s chip at %#x\n",
1875 val
== 0x30 ? "W83782D" : "W83781D", (int)address
);
1878 for (port
--; port
>= address
; port
--)
1879 release_region(port
, 1);
1884 w83781d_isa_device_add(unsigned short address
)
1886 struct resource res
= {
1888 .end
= address
+ W83781D_EXTENT
- 1,
1890 .flags
= IORESOURCE_IO
,
1894 pdev
= platform_device_alloc("w83781d", address
);
1897 printk(KERN_ERR
"w83781d: Device allocation failed\n");
1901 err
= platform_device_add_resources(pdev
, &res
, 1);
1903 printk(KERN_ERR
"w83781d: Device resource addition failed "
1905 goto exit_device_put
;
1908 err
= platform_device_add(pdev
);
1910 printk(KERN_ERR
"w83781d: Device addition failed (%d)\n",
1912 goto exit_device_put
;
1918 platform_device_put(pdev
);
1925 w83781d_isa_register(void)
1929 if (w83781d_isa_found(isa_address
)) {
1930 res
= platform_driver_register(&w83781d_isa_driver
);
1934 /* Sets global pdev as a side effect */
1935 res
= w83781d_isa_device_add(isa_address
);
1937 goto exit_unreg_isa_driver
;
1942 exit_unreg_isa_driver
:
1943 platform_driver_unregister(&w83781d_isa_driver
);
1949 w83781d_isa_unregister(void)
1952 platform_device_unregister(pdev
);
1953 platform_driver_unregister(&w83781d_isa_driver
);
1956 #else /* !CONFIG_ISA */
1958 static struct w83781d_data
*w83781d_data_if_isa(void)
1964 w83781d_alias_detect(struct i2c_client
*client
, u8 chipid
)
1970 w83781d_read_value(struct w83781d_data
*data
, u16 reg
)
1974 mutex_lock(&data
->lock
);
1975 res
= w83781d_read_value_i2c(data
, reg
);
1976 mutex_unlock(&data
->lock
);
1982 w83781d_write_value(struct w83781d_data
*data
, u16 reg
, u16 value
)
1984 mutex_lock(&data
->lock
);
1985 w83781d_write_value_i2c(data
, reg
, value
);
1986 mutex_unlock(&data
->lock
);
1992 w83781d_isa_register(void)
1998 w83781d_isa_unregister(void)
2001 #endif /* CONFIG_ISA */
2004 sensors_w83781d_init(void)
2008 /* We register the ISA device first, so that we can skip the
2009 * registration of an I2C interface to the same device. */
2010 res
= w83781d_isa_register();
2014 res
= i2c_add_driver(&w83781d_driver
);
2016 goto exit_unreg_isa
;
2021 w83781d_isa_unregister();
2027 sensors_w83781d_exit(void)
2029 w83781d_isa_unregister();
2030 i2c_del_driver(&w83781d_driver
);
2033 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
2034 "Philip Edelbrock <phil@netroedge.com>, "
2035 "and Mark Studebaker <mdsxyz123@yahoo.com>");
2036 MODULE_DESCRIPTION("W83781D driver");
2037 MODULE_LICENSE("GPL");
2039 module_init(sensors_w83781d_init
);
2040 module_exit(sensors_w83781d_exit
);