blob: e0fa7520400d8c565f0b7c77034a6c0e35cf4a1a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 w83781d.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>,
Jean Delvare7666c132007-05-08 17:22:02 +02005 Philip Edelbrock <phil@netroedge.com>,
6 and Mark Studebaker <mdsxyz123@yahoo.com>
7 Copyright (c) 2007 Jean Delvare <khali@linux-fr.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
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.
13
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.
18
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.
22*/
23
24/*
25 Supports following chips:
26
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 w83627hf 9 3 2 3 0x21 0x5ca3 yes yes(LPC)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 w83782d 9 3 2-4 3 0x30 0x5ca3 yes yes
33 w83783s 5-6 3 2 1-2 0x40 0x5ca3 yes no
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35*/
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/module.h>
38#include <linux/init.h>
39#include <linux/slab.h>
40#include <linux/jiffies.h>
41#include <linux/i2c.h>
Jean Delvare7666c132007-05-08 17:22:02 +020042#include <linux/platform_device.h>
43#include <linux/ioport.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040044#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020045#include <linux/hwmon-vid.h>
Jean Delvare34875332007-05-08 17:22:03 +020046#include <linux/hwmon-sysfs.h>
Jim Cromie311ce2e2006-09-24 21:22:52 +020047#include <linux/sysfs.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040048#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010049#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <asm/io.h>
51#include "lm75.h"
52
Jean Delvare7666c132007-05-08 17:22:02 +020053/* ISA device, if found */
54static struct platform_device *pdev;
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/* Addresses to scan */
57static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
58 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
59 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
Jean Delvare2d8672c2005-07-19 23:56:35 +020060static unsigned short isa_address = 0x290;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62/* Insmod parameters */
Jean Delvaref4b50262005-07-31 21:49:03 +020063I2C_CLIENT_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
65 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
66
Jean Delvarefabddcd2006-02-05 23:26:51 +010067static int reset;
68module_param(reset, bool, 0);
69MODULE_PARM_DESC(reset, "Set to one to reset chip on load");
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071static int init = 1;
72module_param(init, bool, 0);
73MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
74
75/* Constants specified below */
76
77/* Length of ISA address segment */
78#define W83781D_EXTENT 8
79
80/* Where are the ISA address/data registers relative to the base address */
81#define W83781D_ADDR_REG_OFFSET 5
82#define W83781D_DATA_REG_OFFSET 6
83
Jean Delvare34875332007-05-08 17:22:03 +020084/* The device registers */
85/* in nr from 0 to 8 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \
87 (0x554 + (((nr) - 7) * 2)))
88#define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \
89 (0x555 + (((nr) - 7) * 2)))
90#define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
91 (0x550 + (nr) - 7))
92
Jean Delvare34875332007-05-08 17:22:03 +020093/* fan nr from 0 to 2 */
94#define W83781D_REG_FAN_MIN(nr) (0x3b + (nr))
95#define W83781D_REG_FAN(nr) (0x28 + (nr))
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97#define W83781D_REG_BANK 0x4E
98#define W83781D_REG_TEMP2_CONFIG 0x152
99#define W83781D_REG_TEMP3_CONFIG 0x252
Jean Delvare34875332007-05-08 17:22:03 +0200100/* temp nr from 1 to 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \
102 ((nr == 2) ? (0x0150) : \
103 (0x27)))
104#define W83781D_REG_TEMP_HYST(nr) ((nr == 3) ? (0x253) : \
105 ((nr == 2) ? (0x153) : \
106 (0x3A)))
107#define W83781D_REG_TEMP_OVER(nr) ((nr == 3) ? (0x255) : \
108 ((nr == 2) ? (0x155) : \
109 (0x39)))
110
111#define W83781D_REG_CONFIG 0x40
Jean Delvarec7f5d7e2006-02-05 23:13:48 +0100112
113/* Interrupt status (W83781D, AS99127F) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define W83781D_REG_ALARM1 0x41
115#define W83781D_REG_ALARM2 0x42
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Jean Delvarec7f5d7e2006-02-05 23:13:48 +0100117/* Real-time status (W83782D, W83783S, W83627HF) */
118#define W83782D_REG_ALARM1 0x459
119#define W83782D_REG_ALARM2 0x45A
120#define W83782D_REG_ALARM3 0x45B
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#define W83781D_REG_BEEP_CONFIG 0x4D
123#define W83781D_REG_BEEP_INTS1 0x56
124#define W83781D_REG_BEEP_INTS2 0x57
125#define W83781D_REG_BEEP_INTS3 0x453 /* not on W83781D */
126
127#define W83781D_REG_VID_FANDIV 0x47
128
129#define W83781D_REG_CHIPID 0x49
130#define W83781D_REG_WCHIPID 0x58
131#define W83781D_REG_CHIPMAN 0x4F
132#define W83781D_REG_PIN 0x4B
133
134/* 782D/783S only */
135#define W83781D_REG_VBAT 0x5D
136
137/* PWM 782D (1-4) and 783S (1-2) only */
Jean Delvare34875332007-05-08 17:22:03 +0200138static const u8 W83781D_REG_PWM[] = { 0x5B, 0x5A, 0x5E, 0x5F };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define W83781D_REG_PWMCLK12 0x5C
140#define W83781D_REG_PWMCLK34 0x45C
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142#define W83781D_REG_I2C_ADDR 0x48
143#define W83781D_REG_I2C_SUBADDR 0x4A
144
145/* The following are undocumented in the data sheets however we
146 received the information in an email from Winbond tech support */
147/* Sensor selection - not on 781d */
148#define W83781D_REG_SCFG1 0x5D
149static const u8 BIT_SCFG1[] = { 0x02, 0x04, 0x08 };
150
151#define W83781D_REG_SCFG2 0x59
152static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
153
154#define W83781D_DEFAULT_BETA 3435
155
156/* RT Table registers */
157#define W83781D_REG_RT_IDX 0x50
158#define W83781D_REG_RT_VAL 0x51
159
Jean Delvare474d00a2007-05-08 17:22:03 +0200160/* Conversions */
161#define IN_TO_REG(val) SENSORS_LIMIT(((val) + 8) / 16, 0, 255)
162#define IN_FROM_REG(val) ((val) * 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164static inline u8
165FAN_TO_REG(long rpm, int div)
166{
167 if (rpm == 0)
168 return 255;
169 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
170 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
171}
172
Jean Delvare474d00a2007-05-08 17:22:03 +0200173static inline long
174FAN_FROM_REG(u8 val, int div)
175{
176 if (val == 0)
177 return -1;
178 if (val == 255)
179 return 0;
180 return 1350000 / (val * div);
181}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Jean Delvare474d00a2007-05-08 17:22:03 +0200183#define TEMP_TO_REG(val) SENSORS_LIMIT((val) / 1000, -127, 128)
184#define TEMP_FROM_REG(val) ((val) * 1000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186#define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \
187 (val) ^ 0x7fff : (val))
188#define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \
189 (~(val)) & 0x7fff : (val) & 0xffffff)
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#define DIV_FROM_REG(val) (1 << (val))
192
193static inline u8
194DIV_TO_REG(long val, enum chips type)
195{
196 int i;
197 val = SENSORS_LIMIT(val, 1,
198 ((type == w83781d
199 || type == as99127f) ? 8 : 128)) >> 1;
Grant Coadyabc01922005-05-12 13:41:51 +1000200 for (i = 0; i < 7; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 if (val == 0)
202 break;
203 val >>= 1;
204 }
Jean Delvare474d00a2007-05-08 17:22:03 +0200205 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207
208/* There are some complications in a module like this. First off, W83781D chips
209 may be both present on the SMBus and the ISA bus, and we have to handle
210 those cases separately at some places. Second, there might be several
211 W83781D chips available (well, actually, that is probably never done; but
212 it is a clean illustration of how to handle a case like that). Finally,
213 a specific chip may be attached to *both* ISA and SMBus, and we would
214 not like to detect it double. Fortunately, in the case of the W83781D at
215 least, a register tells us what SMBus address we are on, so that helps
216 a bit - except if there could be more than one SMBus. Groan. No solution
217 for this yet. */
218
Jean Delvare7666c132007-05-08 17:22:02 +0200219/* For ISA chips, we abuse the i2c_client addr and name fields. We also use
220 the driver field to differentiate between I2C and ISA chips. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221struct w83781d_data {
222 struct i2c_client client;
Tony Jones1beeffe2007-08-20 13:46:20 -0700223 struct device *hwmon_dev;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100224 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 enum chips type;
226
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100227 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 char valid; /* !=0 if following fields are valid */
229 unsigned long last_updated; /* In jiffies */
230
231 struct i2c_client *lm75[2]; /* for secondary I2C addresses */
232 /* array of 2 pointers to subclients */
233
234 u8 in[9]; /* Register value - 8 & 9 for 782D only */
235 u8 in_max[9]; /* Register value - 8 & 9 for 782D only */
236 u8 in_min[9]; /* Register value - 8 & 9 for 782D only */
237 u8 fan[3]; /* Register value */
238 u8 fan_min[3]; /* Register value */
Jean Delvare474d00a2007-05-08 17:22:03 +0200239 s8 temp; /* Register value */
240 s8 temp_max; /* Register value */
241 s8 temp_max_hyst; /* Register value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 u16 temp_add[2]; /* Register value */
243 u16 temp_max_add[2]; /* Register value */
244 u16 temp_max_hyst_add[2]; /* Register value */
245 u8 fan_div[3]; /* Register encoding, shifted right */
246 u8 vid; /* Register encoding, combined */
247 u32 alarms; /* Register encoding, combined */
248 u32 beep_mask; /* Register encoding, combined */
249 u8 beep_enable; /* Boolean */
250 u8 pwm[4]; /* Register value */
Jean Delvare34875332007-05-08 17:22:03 +0200251 u8 pwm2_enable; /* Boolean */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 u16 sens[3]; /* 782D/783S only.
253 1 = pentium diode; 2 = 3904 diode;
Jean Delvareb26f9332007-08-16 14:30:01 +0200254 4 = thermistor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 u8 vrm;
256};
257
258static int w83781d_attach_adapter(struct i2c_adapter *adapter);
259static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind);
260static int w83781d_detach_client(struct i2c_client *client);
261
Jean Delvare7666c132007-05-08 17:22:02 +0200262static int __devinit w83781d_isa_probe(struct platform_device *pdev);
263static int __devexit w83781d_isa_remove(struct platform_device *pdev);
264
Jean Delvare31b8dc42007-05-08 17:22:03 +0200265static int w83781d_read_value(struct w83781d_data *data, u16 reg);
266static int w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267static struct w83781d_data *w83781d_update_device(struct device *dev);
Jean Delvare7666c132007-05-08 17:22:02 +0200268static void w83781d_init_device(struct device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270static struct i2c_driver w83781d_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100271 .driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100272 .name = "w83781d",
273 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 .id = I2C_DRIVERID_W83781D,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 .attach_adapter = w83781d_attach_adapter,
276 .detach_client = w83781d_detach_client,
277};
278
Jean Delvare7666c132007-05-08 17:22:02 +0200279static struct platform_driver w83781d_isa_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100280 .driver = {
Jean Delvare87218842006-09-03 22:36:14 +0200281 .owner = THIS_MODULE,
Jean Delvare7666c132007-05-08 17:22:02 +0200282 .name = "w83781d",
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100283 },
Jean Delvare7666c132007-05-08 17:22:02 +0200284 .probe = w83781d_isa_probe,
285 .remove = w83781d_isa_remove,
Jean Delvarefde09502005-07-19 23:51:07 +0200286};
287
288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289/* following are the sysfs callback functions */
290#define show_in_reg(reg) \
Jean Delvare34875332007-05-08 17:22:03 +0200291static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
292 char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{ \
Jean Delvare34875332007-05-08 17:22:03 +0200294 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 struct w83781d_data *data = w83781d_update_device(dev); \
Jean Delvare34875332007-05-08 17:22:03 +0200296 return sprintf(buf, "%ld\n", \
297 (long)IN_FROM_REG(data->reg[attr->index])); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299show_in_reg(in);
300show_in_reg(in_min);
301show_in_reg(in_max);
302
303#define store_in_reg(REG, reg) \
Jean Delvare34875332007-05-08 17:22:03 +0200304static ssize_t store_in_##reg (struct device *dev, struct device_attribute \
305 *da, const char *buf, size_t count) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{ \
Jean Delvare34875332007-05-08 17:22:03 +0200307 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
Jean Delvare7666c132007-05-08 17:22:02 +0200308 struct w83781d_data *data = dev_get_drvdata(dev); \
Jean Delvare34875332007-05-08 17:22:03 +0200309 int nr = attr->index; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 u32 val; \
311 \
Jean Delvare474d00a2007-05-08 17:22:03 +0200312 val = simple_strtoul(buf, NULL, 10); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 \
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100314 mutex_lock(&data->update_lock); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 data->in_##reg[nr] = IN_TO_REG(val); \
Jean Delvare31b8dc42007-05-08 17:22:03 +0200316 w83781d_write_value(data, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 \
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100318 mutex_unlock(&data->update_lock); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return count; \
320}
321store_in_reg(MIN, min);
322store_in_reg(MAX, max);
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#define sysfs_in_offsets(offset) \
Jean Delvare34875332007-05-08 17:22:03 +0200325static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
326 show_in, NULL, offset); \
327static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
328 show_in_min, store_in_min, offset); \
329static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
330 show_in_max, store_in_max, offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332sysfs_in_offsets(0);
333sysfs_in_offsets(1);
334sysfs_in_offsets(2);
335sysfs_in_offsets(3);
336sysfs_in_offsets(4);
337sysfs_in_offsets(5);
338sysfs_in_offsets(6);
339sysfs_in_offsets(7);
340sysfs_in_offsets(8);
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#define show_fan_reg(reg) \
Jean Delvare34875332007-05-08 17:22:03 +0200343static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
344 char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{ \
Jean Delvare34875332007-05-08 17:22:03 +0200346 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 struct w83781d_data *data = w83781d_update_device(dev); \
348 return sprintf(buf,"%ld\n", \
Jean Delvare34875332007-05-08 17:22:03 +0200349 FAN_FROM_REG(data->reg[attr->index], \
350 DIV_FROM_REG(data->fan_div[attr->index]))); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352show_fan_reg(fan);
353show_fan_reg(fan_min);
354
355static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200356store_fan_min(struct device *dev, struct device_attribute *da,
357 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Jean Delvare34875332007-05-08 17:22:03 +0200359 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Jean Delvare7666c132007-05-08 17:22:02 +0200360 struct w83781d_data *data = dev_get_drvdata(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200361 int nr = attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 u32 val;
363
364 val = simple_strtoul(buf, NULL, 10);
365
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100366 mutex_lock(&data->update_lock);
Jean Delvare34875332007-05-08 17:22:03 +0200367 data->fan_min[nr] =
368 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvare31b8dc42007-05-08 17:22:03 +0200369 w83781d_write_value(data, W83781D_REG_FAN_MIN(nr),
Jean Delvare34875332007-05-08 17:22:03 +0200370 data->fan_min[nr]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100372 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 return count;
374}
375
Jean Delvare34875332007-05-08 17:22:03 +0200376static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
377static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
378 show_fan_min, store_fan_min, 0);
379static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
380static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
381 show_fan_min, store_fan_min, 1);
382static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
383static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR,
384 show_fan_min, store_fan_min, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386#define show_temp_reg(reg) \
Jean Delvare34875332007-05-08 17:22:03 +0200387static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
388 char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{ \
Jean Delvare34875332007-05-08 17:22:03 +0200390 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 struct w83781d_data *data = w83781d_update_device(dev); \
Jean Delvare34875332007-05-08 17:22:03 +0200392 int nr = attr->index; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
394 return sprintf(buf,"%d\n", \
395 LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \
396 } else { /* TEMP1 */ \
397 return sprintf(buf,"%ld\n", (long)TEMP_FROM_REG(data->reg)); \
398 } \
399}
400show_temp_reg(temp);
401show_temp_reg(temp_max);
402show_temp_reg(temp_max_hyst);
403
404#define store_temp_reg(REG, reg) \
Jean Delvare34875332007-05-08 17:22:03 +0200405static ssize_t store_temp_##reg (struct device *dev, \
406 struct device_attribute *da, const char *buf, size_t count) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{ \
Jean Delvare34875332007-05-08 17:22:03 +0200408 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
Jean Delvare7666c132007-05-08 17:22:02 +0200409 struct w83781d_data *data = dev_get_drvdata(dev); \
Jean Delvare34875332007-05-08 17:22:03 +0200410 int nr = attr->index; \
Christian Hohnstaedt5bfedac2007-08-16 11:40:10 +0200411 long val; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 \
413 val = simple_strtol(buf, NULL, 10); \
414 \
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100415 mutex_lock(&data->update_lock); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 \
417 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
418 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
Jean Delvare31b8dc42007-05-08 17:22:03 +0200419 w83781d_write_value(data, W83781D_REG_TEMP_##REG(nr), \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 data->temp_##reg##_add[nr-2]); \
421 } else { /* TEMP1 */ \
422 data->temp_##reg = TEMP_TO_REG(val); \
Jean Delvare31b8dc42007-05-08 17:22:03 +0200423 w83781d_write_value(data, W83781D_REG_TEMP_##REG(nr), \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 data->temp_##reg); \
425 } \
426 \
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100427 mutex_unlock(&data->update_lock); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 return count; \
429}
430store_temp_reg(OVER, max);
431store_temp_reg(HYST, max_hyst);
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define sysfs_temp_offsets(offset) \
Jean Delvare34875332007-05-08 17:22:03 +0200434static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
435 show_temp, NULL, offset); \
436static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
437 show_temp_max, store_temp_max, offset); \
438static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
439 show_temp_max_hyst, store_temp_max_hyst, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441sysfs_temp_offsets(1);
442sysfs_temp_offsets(2);
443sysfs_temp_offsets(3);
444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400446show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
448 struct w83781d_data *data = w83781d_update_device(dev);
449 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
450}
451
Jim Cromie311ce2e2006-09-24 21:22:52 +0200452static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400455show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
Jean Delvare90d66192007-10-08 18:24:35 +0200457 struct w83781d_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return sprintf(buf, "%ld\n", (long) data->vrm);
459}
460
461static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400462store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Jean Delvare7666c132007-05-08 17:22:02 +0200464 struct w83781d_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 u32 val;
466
467 val = simple_strtoul(buf, NULL, 10);
468 data->vrm = val;
469
470 return count;
471}
472
Jim Cromie311ce2e2006-09-24 21:22:52 +0200473static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400476show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
478 struct w83781d_data *data = w83781d_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +0200479 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
Jim Cromie311ce2e2006-09-24 21:22:52 +0200482static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
483
Jean Delvare7d4a1372007-10-08 18:29:43 +0200484static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
485 char *buf)
486{
487 struct w83781d_data *data = w83781d_update_device(dev);
488 int bitnr = to_sensor_dev_attr(attr)->index;
489 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
490}
491
492/* The W83781D has a single alarm bit for temp2 and temp3 */
493static ssize_t show_temp3_alarm(struct device *dev,
494 struct device_attribute *attr, char *buf)
495{
496 struct w83781d_data *data = w83781d_update_device(dev);
497 int bitnr = (data->type == w83781d) ? 5 : 13;
498 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
499}
500
501static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
502static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
503static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
504static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
505static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
506static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
507static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 10);
508static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16);
509static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17);
510static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
511static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
512static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
513static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
514static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
515static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_temp3_alarm, NULL, 0);
516
Yani Ioannoue404e272005-05-17 06:42:58 -0400517static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
519 struct w83781d_data *data = w83781d_update_device(dev);
520 return sprintf(buf, "%ld\n",
521 (long)BEEP_MASK_FROM_REG(data->beep_mask, data->type));
522}
Yani Ioannoue404e272005-05-17 06:42:58 -0400523static ssize_t show_beep_enable (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
525 struct w83781d_data *data = w83781d_update_device(dev);
Jean Delvare474d00a2007-05-08 17:22:03 +0200526 return sprintf(buf, "%ld\n", (long)data->beep_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527}
528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200530store_beep_mask(struct device *dev, struct device_attribute *attr,
531 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Jean Delvare7666c132007-05-08 17:22:02 +0200533 struct w83781d_data *data = dev_get_drvdata(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200534 u32 val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 val = simple_strtoul(buf, NULL, 10);
537
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100538 mutex_lock(&data->update_lock);
Jean Delvare34875332007-05-08 17:22:03 +0200539 data->beep_mask = BEEP_MASK_TO_REG(val, data->type);
540 w83781d_write_value(data, W83781D_REG_BEEP_INTS1,
541 data->beep_mask & 0xff);
Jean Delvare31b8dc42007-05-08 17:22:03 +0200542 w83781d_write_value(data, W83781D_REG_BEEP_INTS2,
Jean Delvare34875332007-05-08 17:22:03 +0200543 ((data->beep_mask >> 8) & 0x7f)
544 | data->beep_enable << 7);
545 if (data->type != w83781d && data->type != as99127f) {
546 w83781d_write_value(data, W83781D_REG_BEEP_INTS3,
547 ((data->beep_mask) >> 16) & 0xff);
548 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100549 mutex_unlock(&data->update_lock);
Jean Delvare34875332007-05-08 17:22:03 +0200550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 return count;
552}
553
Jean Delvare34875332007-05-08 17:22:03 +0200554static ssize_t
555store_beep_enable(struct device *dev, struct device_attribute *attr,
556 const char *buf, size_t count)
557{
558 struct w83781d_data *data = dev_get_drvdata(dev);
559 u32 val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Jean Delvare34875332007-05-08 17:22:03 +0200561 val = simple_strtoul(buf, NULL, 10);
562 if (val != 0 && val != 1)
563 return -EINVAL;
564
565 mutex_lock(&data->update_lock);
566 data->beep_enable = val;
567 val = w83781d_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f;
568 val |= data->beep_enable << 7;
569 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, val);
570 mutex_unlock(&data->update_lock);
571
572 return count;
573}
574
575static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
576 show_beep_mask, store_beep_mask);
577static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
578 show_beep_enable, store_beep_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Jean Delvare7d4a1372007-10-08 18:29:43 +0200580static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
581 char *buf)
582{
583 struct w83781d_data *data = w83781d_update_device(dev);
584 int bitnr = to_sensor_dev_attr(attr)->index;
585 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
586}
587
588static ssize_t
589store_beep(struct device *dev, struct device_attribute *attr,
590 const char *buf, size_t count)
591{
592 struct w83781d_data *data = dev_get_drvdata(dev);
593 int bitnr = to_sensor_dev_attr(attr)->index;
594 unsigned long bit;
595 u8 reg;
596
597 bit = simple_strtoul(buf, NULL, 10);
598 if (bit & ~1)
599 return -EINVAL;
600
601 mutex_lock(&data->update_lock);
602 if (bit)
603 data->beep_mask |= (1 << bitnr);
604 else
605 data->beep_mask &= ~(1 << bitnr);
606
607 if (bitnr < 8) {
608 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
609 if (bit)
610 reg |= (1 << bitnr);
611 else
612 reg &= ~(1 << bitnr);
613 w83781d_write_value(data, W83781D_REG_BEEP_INTS1, reg);
614 } else if (bitnr < 16) {
615 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
616 if (bit)
617 reg |= (1 << (bitnr - 8));
618 else
619 reg &= ~(1 << (bitnr - 8));
620 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, reg);
621 } else {
622 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS3);
623 if (bit)
624 reg |= (1 << (bitnr - 16));
625 else
626 reg &= ~(1 << (bitnr - 16));
627 w83781d_write_value(data, W83781D_REG_BEEP_INTS3, reg);
628 }
629 mutex_unlock(&data->update_lock);
630
631 return count;
632}
633
634/* The W83781D has a single beep bit for temp2 and temp3 */
635static ssize_t show_temp3_beep(struct device *dev,
636 struct device_attribute *attr, char *buf)
637{
638 struct w83781d_data *data = w83781d_update_device(dev);
639 int bitnr = (data->type == w83781d) ? 5 : 13;
640 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
641}
642
643static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
644 show_beep, store_beep, 0);
645static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR,
646 show_beep, store_beep, 1);
647static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR,
648 show_beep, store_beep, 2);
649static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR,
650 show_beep, store_beep, 3);
651static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR,
652 show_beep, store_beep, 8);
653static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO | S_IWUSR,
654 show_beep, store_beep, 9);
655static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO | S_IWUSR,
656 show_beep, store_beep, 10);
657static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO | S_IWUSR,
658 show_beep, store_beep, 16);
659static SENSOR_DEVICE_ATTR(in8_beep, S_IRUGO | S_IWUSR,
660 show_beep, store_beep, 17);
661static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR,
662 show_beep, store_beep, 6);
663static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR,
664 show_beep, store_beep, 7);
665static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO | S_IWUSR,
666 show_beep, store_beep, 11);
667static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
668 show_beep, store_beep, 4);
669static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR,
670 show_beep, store_beep, 5);
671static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO,
672 show_temp3_beep, store_beep, 13);
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200675show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
Jean Delvare34875332007-05-08 17:22:03 +0200677 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 struct w83781d_data *data = w83781d_update_device(dev);
679 return sprintf(buf, "%ld\n",
Jean Delvare34875332007-05-08 17:22:03 +0200680 (long) DIV_FROM_REG(data->fan_div[attr->index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
683/* Note: we save and restore the fan minimum here, because its value is
684 determined in part by the fan divisor. This follows the principle of
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200685 least surprise; the user doesn't expect the fan minimum to change just
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 because the divisor changed. */
687static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200688store_fan_div(struct device *dev, struct device_attribute *da,
689 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Jean Delvare34875332007-05-08 17:22:03 +0200691 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Jean Delvare7666c132007-05-08 17:22:02 +0200692 struct w83781d_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 unsigned long min;
Jean Delvare34875332007-05-08 17:22:03 +0200694 int nr = attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 u8 reg;
696 unsigned long val = simple_strtoul(buf, NULL, 10);
697
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100698 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 /* Save fan_min */
701 min = FAN_FROM_REG(data->fan_min[nr],
702 DIV_FROM_REG(data->fan_div[nr]));
703
704 data->fan_div[nr] = DIV_TO_REG(val, data->type);
705
Jean Delvare31b8dc42007-05-08 17:22:03 +0200706 reg = (w83781d_read_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 & (nr==0 ? 0xcf : 0x3f))
708 | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6));
Jean Delvare31b8dc42007-05-08 17:22:03 +0200709 w83781d_write_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711 /* w83781d and as99127f don't have extended divisor bits */
712 if (data->type != w83781d && data->type != as99127f) {
Jean Delvare31b8dc42007-05-08 17:22:03 +0200713 reg = (w83781d_read_value(data, W83781D_REG_VBAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 & ~(1 << (5 + nr)))
715 | ((data->fan_div[nr] & 0x04) << (3 + nr));
Jean Delvare31b8dc42007-05-08 17:22:03 +0200716 w83781d_write_value(data, W83781D_REG_VBAT, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
718
719 /* Restore fan_min */
720 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvare34875332007-05-08 17:22:03 +0200721 w83781d_write_value(data, W83781D_REG_FAN_MIN(nr), data->fan_min[nr]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100723 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 return count;
725}
726
Jean Delvare34875332007-05-08 17:22:03 +0200727static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
728 show_fan_div, store_fan_div, 0);
729static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
730 show_fan_div, store_fan_div, 1);
731static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR,
732 show_fan_div, store_fan_div, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200735show_pwm(struct device *dev, struct device_attribute *da, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
Jean Delvare34875332007-05-08 17:22:03 +0200737 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 struct w83781d_data *data = w83781d_update_device(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200739 return sprintf(buf, "%d\n", (int)data->pwm[attr->index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740}
741
742static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200743show_pwm2_enable(struct device *dev, struct device_attribute *da, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744{
745 struct w83781d_data *data = w83781d_update_device(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200746 return sprintf(buf, "%d\n", (int)data->pwm2_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747}
748
749static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200750store_pwm(struct device *dev, struct device_attribute *da, const char *buf,
751 size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752{
Jean Delvare34875332007-05-08 17:22:03 +0200753 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Jean Delvare7666c132007-05-08 17:22:02 +0200754 struct w83781d_data *data = dev_get_drvdata(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200755 int nr = attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 u32 val;
757
758 val = simple_strtoul(buf, NULL, 10);
759
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100760 mutex_lock(&data->update_lock);
Jean Delvare34875332007-05-08 17:22:03 +0200761 data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
762 w83781d_write_value(data, W83781D_REG_PWM[nr], data->pwm[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100763 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 return count;
765}
766
767static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200768store_pwm2_enable(struct device *dev, struct device_attribute *da,
769 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
Jean Delvare7666c132007-05-08 17:22:02 +0200771 struct w83781d_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 u32 val, reg;
773
774 val = simple_strtoul(buf, NULL, 10);
775
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100776 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 switch (val) {
779 case 0:
780 case 1:
Jean Delvare31b8dc42007-05-08 17:22:03 +0200781 reg = w83781d_read_value(data, W83781D_REG_PWMCLK12);
782 w83781d_write_value(data, W83781D_REG_PWMCLK12,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 (reg & 0xf7) | (val << 3));
784
Jean Delvare31b8dc42007-05-08 17:22:03 +0200785 reg = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
786 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 (reg & 0xef) | (!val << 4));
788
Jean Delvare34875332007-05-08 17:22:03 +0200789 data->pwm2_enable = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 break;
791
792 default:
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100793 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 return -EINVAL;
795 }
796
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100797 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 return count;
799}
800
Jean Delvare34875332007-05-08 17:22:03 +0200801static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0);
802static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 1);
803static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 2);
804static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 3);
805/* only PWM2 can be enabled/disabled */
806static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
807 show_pwm2_enable, store_pwm2_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200810show_sensor(struct device *dev, struct device_attribute *da, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
Jean Delvare34875332007-05-08 17:22:03 +0200812 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 struct w83781d_data *data = w83781d_update_device(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200814 return sprintf(buf, "%d\n", (int)data->sens[attr->index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815}
816
817static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200818store_sensor(struct device *dev, struct device_attribute *da,
819 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Jean Delvare34875332007-05-08 17:22:03 +0200821 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Jean Delvare7666c132007-05-08 17:22:02 +0200822 struct w83781d_data *data = dev_get_drvdata(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200823 int nr = attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 u32 val, tmp;
825
826 val = simple_strtoul(buf, NULL, 10);
827
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100828 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 switch (val) {
831 case 1: /* PII/Celeron diode */
Jean Delvare31b8dc42007-05-08 17:22:03 +0200832 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
833 w83781d_write_value(data, W83781D_REG_SCFG1,
Jean Delvare34875332007-05-08 17:22:03 +0200834 tmp | BIT_SCFG1[nr]);
Jean Delvare31b8dc42007-05-08 17:22:03 +0200835 tmp = w83781d_read_value(data, W83781D_REG_SCFG2);
836 w83781d_write_value(data, W83781D_REG_SCFG2,
Jean Delvare34875332007-05-08 17:22:03 +0200837 tmp | BIT_SCFG2[nr]);
838 data->sens[nr] = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 break;
840 case 2: /* 3904 */
Jean Delvare31b8dc42007-05-08 17:22:03 +0200841 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
842 w83781d_write_value(data, W83781D_REG_SCFG1,
Jean Delvare34875332007-05-08 17:22:03 +0200843 tmp | BIT_SCFG1[nr]);
Jean Delvare31b8dc42007-05-08 17:22:03 +0200844 tmp = w83781d_read_value(data, W83781D_REG_SCFG2);
845 w83781d_write_value(data, W83781D_REG_SCFG2,
Jean Delvare34875332007-05-08 17:22:03 +0200846 tmp & ~BIT_SCFG2[nr]);
847 data->sens[nr] = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 break;
Jean Delvareb26f9332007-08-16 14:30:01 +0200849 case W83781D_DEFAULT_BETA:
850 dev_warn(dev, "Sensor type %d is deprecated, please use 4 "
851 "instead\n", W83781D_DEFAULT_BETA);
852 /* fall through */
853 case 4: /* thermistor */
Jean Delvare31b8dc42007-05-08 17:22:03 +0200854 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
855 w83781d_write_value(data, W83781D_REG_SCFG1,
Jean Delvare34875332007-05-08 17:22:03 +0200856 tmp & ~BIT_SCFG1[nr]);
857 data->sens[nr] = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 break;
859 default:
Jean Delvareb26f9332007-08-16 14:30:01 +0200860 dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or 4\n",
861 (long) val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 break;
863 }
864
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100865 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 return count;
867}
868
Jean Delvare34875332007-05-08 17:22:03 +0200869static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
870 show_sensor, store_sensor, 0);
871static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
Mark M. Hoffman393cdad2007-08-09 08:12:46 -0400872 show_sensor, store_sensor, 1);
Jean Delvare34875332007-05-08 17:22:03 +0200873static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
Mark M. Hoffman393cdad2007-08-09 08:12:46 -0400874 show_sensor, store_sensor, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Jean Delvare7666c132007-05-08 17:22:02 +0200876/* I2C devices get this name attribute automatically, but for ISA devices
877 we must create it by ourselves. */
878static ssize_t
879show_name(struct device *dev, struct device_attribute *devattr, char *buf)
880{
881 struct w83781d_data *data = dev_get_drvdata(dev);
882 return sprintf(buf, "%s\n", data->client.name);
883}
884static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886/* This function is called when:
887 * w83781d_driver is inserted (when this module is loaded), for each
888 available adapter
889 * when a new adapter is inserted (and w83781d_driver is still present) */
890static int
891w83781d_attach_adapter(struct i2c_adapter *adapter)
892{
893 if (!(adapter->class & I2C_CLASS_HWMON))
894 return 0;
Jean Delvare2ed2dc32005-07-31 21:42:02 +0200895 return i2c_probe(adapter, &addr_data, w83781d_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}
897
898/* Assumes that adapter is of I2C, not ISA variety.
899 * OTHERWISE DON'T CALL THIS
900 */
901static int
902w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
903 struct i2c_client *new_client)
904{
905 int i, val1 = 0, id;
906 int err;
907 const char *client_name = "";
908 struct w83781d_data *data = i2c_get_clientdata(new_client);
909
Deepak Saxenaba9c2e82005-10-17 23:08:32 +0200910 data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 if (!(data->lm75[0])) {
912 err = -ENOMEM;
913 goto ERROR_SC_0;
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 id = i2c_adapter_id(adapter);
917
918 if (force_subclients[0] == id && force_subclients[1] == address) {
919 for (i = 2; i <= 3; i++) {
920 if (force_subclients[i] < 0x48 ||
921 force_subclients[i] > 0x4f) {
922 dev_err(&new_client->dev, "Invalid subclient "
923 "address %d; must be 0x48-0x4f\n",
924 force_subclients[i]);
925 err = -EINVAL;
926 goto ERROR_SC_1;
927 }
928 }
Jean Delvare31b8dc42007-05-08 17:22:03 +0200929 w83781d_write_value(data, W83781D_REG_I2C_SUBADDR,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 (force_subclients[2] & 0x07) |
931 ((force_subclients[3] & 0x07) << 4));
932 data->lm75[0]->addr = force_subclients[2];
933 } else {
Jean Delvare31b8dc42007-05-08 17:22:03 +0200934 val1 = w83781d_read_value(data, W83781D_REG_I2C_SUBADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 data->lm75[0]->addr = 0x48 + (val1 & 0x07);
936 }
937
938 if (kind != w83783s) {
Deepak Saxenaba9c2e82005-10-17 23:08:32 +0200939 data->lm75[1] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 if (!(data->lm75[1])) {
941 err = -ENOMEM;
942 goto ERROR_SC_1;
943 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
945 if (force_subclients[0] == id &&
946 force_subclients[1] == address) {
947 data->lm75[1]->addr = force_subclients[3];
948 } else {
949 data->lm75[1]->addr = 0x48 + ((val1 >> 4) & 0x07);
950 }
951 if (data->lm75[0]->addr == data->lm75[1]->addr) {
952 dev_err(&new_client->dev,
953 "Duplicate addresses 0x%x for subclients.\n",
954 data->lm75[0]->addr);
955 err = -EBUSY;
956 goto ERROR_SC_2;
957 }
958 }
959
960 if (kind == w83781d)
961 client_name = "w83781d subclient";
962 else if (kind == w83782d)
963 client_name = "w83782d subclient";
964 else if (kind == w83783s)
965 client_name = "w83783s subclient";
966 else if (kind == w83627hf)
967 client_name = "w83627hf subclient";
968 else if (kind == as99127f)
969 client_name = "as99127f subclient";
970
971 for (i = 0; i <= 1; i++) {
972 /* store all data in w83781d */
973 i2c_set_clientdata(data->lm75[i], NULL);
974 data->lm75[i]->adapter = adapter;
975 data->lm75[i]->driver = &w83781d_driver;
976 data->lm75[i]->flags = 0;
977 strlcpy(data->lm75[i]->name, client_name,
978 I2C_NAME_SIZE);
979 if ((err = i2c_attach_client(data->lm75[i]))) {
980 dev_err(&new_client->dev, "Subclient %d "
981 "registration at address 0x%x "
982 "failed.\n", i, data->lm75[i]->addr);
983 if (i == 1)
984 goto ERROR_SC_3;
985 goto ERROR_SC_2;
986 }
987 if (kind == w83783s)
988 break;
989 }
990
991 return 0;
992
993/* Undo inits in case of errors */
994ERROR_SC_3:
995 i2c_detach_client(data->lm75[0]);
996ERROR_SC_2:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800997 kfree(data->lm75[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998ERROR_SC_1:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800999 kfree(data->lm75[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000ERROR_SC_0:
1001 return err;
1002}
1003
Jean Delvare34875332007-05-08 17:22:03 +02001004#define IN_UNIT_ATTRS(X) \
1005 &sensor_dev_attr_in##X##_input.dev_attr.attr, \
1006 &sensor_dev_attr_in##X##_min.dev_attr.attr, \
Jean Delvare7d4a1372007-10-08 18:29:43 +02001007 &sensor_dev_attr_in##X##_max.dev_attr.attr, \
1008 &sensor_dev_attr_in##X##_alarm.dev_attr.attr, \
1009 &sensor_dev_attr_in##X##_beep.dev_attr.attr
Jim Cromie311ce2e2006-09-24 21:22:52 +02001010
Jean Delvare34875332007-05-08 17:22:03 +02001011#define FAN_UNIT_ATTRS(X) \
1012 &sensor_dev_attr_fan##X##_input.dev_attr.attr, \
1013 &sensor_dev_attr_fan##X##_min.dev_attr.attr, \
Jean Delvare7d4a1372007-10-08 18:29:43 +02001014 &sensor_dev_attr_fan##X##_div.dev_attr.attr, \
1015 &sensor_dev_attr_fan##X##_alarm.dev_attr.attr, \
1016 &sensor_dev_attr_fan##X##_beep.dev_attr.attr
Jim Cromie311ce2e2006-09-24 21:22:52 +02001017
Jean Delvare34875332007-05-08 17:22:03 +02001018#define TEMP_UNIT_ATTRS(X) \
1019 &sensor_dev_attr_temp##X##_input.dev_attr.attr, \
1020 &sensor_dev_attr_temp##X##_max.dev_attr.attr, \
Jean Delvare7d4a1372007-10-08 18:29:43 +02001021 &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr, \
1022 &sensor_dev_attr_temp##X##_alarm.dev_attr.attr, \
1023 &sensor_dev_attr_temp##X##_beep.dev_attr.attr
Jim Cromie311ce2e2006-09-24 21:22:52 +02001024
1025static struct attribute* w83781d_attributes[] = {
1026 IN_UNIT_ATTRS(0),
1027 IN_UNIT_ATTRS(2),
1028 IN_UNIT_ATTRS(3),
1029 IN_UNIT_ATTRS(4),
1030 IN_UNIT_ATTRS(5),
1031 IN_UNIT_ATTRS(6),
1032 FAN_UNIT_ATTRS(1),
1033 FAN_UNIT_ATTRS(2),
1034 FAN_UNIT_ATTRS(3),
1035 TEMP_UNIT_ATTRS(1),
1036 TEMP_UNIT_ATTRS(2),
1037 &dev_attr_cpu0_vid.attr,
1038 &dev_attr_vrm.attr,
1039 &dev_attr_alarms.attr,
1040 &dev_attr_beep_mask.attr,
1041 &dev_attr_beep_enable.attr,
1042 NULL
1043};
1044static const struct attribute_group w83781d_group = {
1045 .attrs = w83781d_attributes,
1046};
1047
1048static struct attribute *w83781d_attributes_opt[] = {
1049 IN_UNIT_ATTRS(1),
1050 IN_UNIT_ATTRS(7),
1051 IN_UNIT_ATTRS(8),
1052 TEMP_UNIT_ATTRS(3),
Jean Delvare34875332007-05-08 17:22:03 +02001053 &sensor_dev_attr_pwm1.dev_attr.attr,
1054 &sensor_dev_attr_pwm2.dev_attr.attr,
1055 &sensor_dev_attr_pwm3.dev_attr.attr,
1056 &sensor_dev_attr_pwm4.dev_attr.attr,
Jim Cromie311ce2e2006-09-24 21:22:52 +02001057 &dev_attr_pwm2_enable.attr,
Jean Delvare34875332007-05-08 17:22:03 +02001058 &sensor_dev_attr_temp1_type.dev_attr.attr,
1059 &sensor_dev_attr_temp2_type.dev_attr.attr,
1060 &sensor_dev_attr_temp3_type.dev_attr.attr,
Jim Cromie311ce2e2006-09-24 21:22:52 +02001061 NULL
1062};
1063static const struct attribute_group w83781d_group_opt = {
1064 .attrs = w83781d_attributes_opt,
1065};
1066
Jean Delvare7666c132007-05-08 17:22:02 +02001067/* No clean up is done on error, it's up to the caller */
1068static int
1069w83781d_create_files(struct device *dev, int kind, int is_isa)
1070{
1071 int err;
1072
1073 if ((err = sysfs_create_group(&dev->kobj, &w83781d_group)))
1074 return err;
1075
1076 if (kind != w83783s) {
Jean Delvare34875332007-05-08 17:22:03 +02001077 if ((err = device_create_file(dev,
1078 &sensor_dev_attr_in1_input.dev_attr))
1079 || (err = device_create_file(dev,
1080 &sensor_dev_attr_in1_min.dev_attr))
1081 || (err = device_create_file(dev,
Jean Delvare7d4a1372007-10-08 18:29:43 +02001082 &sensor_dev_attr_in1_max.dev_attr))
1083 || (err = device_create_file(dev,
1084 &sensor_dev_attr_in1_alarm.dev_attr))
1085 || (err = device_create_file(dev,
1086 &sensor_dev_attr_in1_beep.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001087 return err;
1088 }
1089 if (kind != as99127f && kind != w83781d && kind != w83783s) {
Jean Delvare34875332007-05-08 17:22:03 +02001090 if ((err = device_create_file(dev,
1091 &sensor_dev_attr_in7_input.dev_attr))
1092 || (err = device_create_file(dev,
1093 &sensor_dev_attr_in7_min.dev_attr))
1094 || (err = device_create_file(dev,
1095 &sensor_dev_attr_in7_max.dev_attr))
1096 || (err = device_create_file(dev,
Jean Delvare7d4a1372007-10-08 18:29:43 +02001097 &sensor_dev_attr_in7_alarm.dev_attr))
1098 || (err = device_create_file(dev,
1099 &sensor_dev_attr_in7_beep.dev_attr))
1100 || (err = device_create_file(dev,
Jean Delvare34875332007-05-08 17:22:03 +02001101 &sensor_dev_attr_in8_input.dev_attr))
1102 || (err = device_create_file(dev,
1103 &sensor_dev_attr_in8_min.dev_attr))
1104 || (err = device_create_file(dev,
Jean Delvare7d4a1372007-10-08 18:29:43 +02001105 &sensor_dev_attr_in8_max.dev_attr))
1106 || (err = device_create_file(dev,
1107 &sensor_dev_attr_in8_alarm.dev_attr))
1108 || (err = device_create_file(dev,
1109 &sensor_dev_attr_in8_beep.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001110 return err;
1111 }
1112 if (kind != w83783s) {
Jean Delvare34875332007-05-08 17:22:03 +02001113 if ((err = device_create_file(dev,
1114 &sensor_dev_attr_temp3_input.dev_attr))
Jean Delvare7666c132007-05-08 17:22:02 +02001115 || (err = device_create_file(dev,
Jean Delvare34875332007-05-08 17:22:03 +02001116 &sensor_dev_attr_temp3_max.dev_attr))
1117 || (err = device_create_file(dev,
Jean Delvare7d4a1372007-10-08 18:29:43 +02001118 &sensor_dev_attr_temp3_max_hyst.dev_attr))
1119 || (err = device_create_file(dev,
1120 &sensor_dev_attr_temp3_alarm.dev_attr))
1121 || (err = device_create_file(dev,
1122 &sensor_dev_attr_temp3_beep.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001123 return err;
Jean Delvare7d4a1372007-10-08 18:29:43 +02001124
Jean Delvare7768aa72007-10-25 13:11:01 +02001125 if (kind != w83781d) {
Jean Delvare7d4a1372007-10-08 18:29:43 +02001126 err = sysfs_chmod_file(&dev->kobj,
1127 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1128 S_IRUGO | S_IWUSR);
1129 if (err)
1130 return err;
Jean Delvare7768aa72007-10-25 13:11:01 +02001131 }
Jean Delvare7666c132007-05-08 17:22:02 +02001132 }
1133
1134 if (kind != w83781d && kind != as99127f) {
Jean Delvare34875332007-05-08 17:22:03 +02001135 if ((err = device_create_file(dev,
1136 &sensor_dev_attr_pwm1.dev_attr))
1137 || (err = device_create_file(dev,
1138 &sensor_dev_attr_pwm2.dev_attr))
Jean Delvare7666c132007-05-08 17:22:02 +02001139 || (err = device_create_file(dev, &dev_attr_pwm2_enable)))
1140 return err;
1141 }
1142 if (kind == w83782d && !is_isa) {
Jean Delvare34875332007-05-08 17:22:03 +02001143 if ((err = device_create_file(dev,
1144 &sensor_dev_attr_pwm3.dev_attr))
1145 || (err = device_create_file(dev,
1146 &sensor_dev_attr_pwm4.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001147 return err;
1148 }
1149
1150 if (kind != as99127f && kind != w83781d) {
Jean Delvare34875332007-05-08 17:22:03 +02001151 if ((err = device_create_file(dev,
1152 &sensor_dev_attr_temp1_type.dev_attr))
Jean Delvare7666c132007-05-08 17:22:02 +02001153 || (err = device_create_file(dev,
Jean Delvare34875332007-05-08 17:22:03 +02001154 &sensor_dev_attr_temp2_type.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001155 return err;
1156 if (kind != w83783s) {
1157 if ((err = device_create_file(dev,
Jean Delvare34875332007-05-08 17:22:03 +02001158 &sensor_dev_attr_temp3_type.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001159 return err;
1160 }
1161 }
1162
1163 if (is_isa) {
1164 err = device_create_file(&pdev->dev, &dev_attr_name);
1165 if (err)
1166 return err;
1167 }
1168
1169 return 0;
1170}
1171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172static int
1173w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1174{
Jean Delvare7666c132007-05-08 17:22:02 +02001175 int val1 = 0, val2;
Jim Cromie311ce2e2006-09-24 21:22:52 +02001176 struct i2c_client *client;
1177 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 struct w83781d_data *data;
1179 int err;
1180 const char *client_name = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 enum vendor { winbond, asus } vendid;
1182
Jean Delvare7666c132007-05-08 17:22:02 +02001183 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 err = -EINVAL;
Jean Delvare7666c132007-05-08 17:22:02 +02001185 goto ERROR1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 }
1187
1188 /* OK. For now, we presume we have a valid client. We now create the
1189 client structure, even though we cannot fill it completely yet.
1190 But it allows us to access w83781d_{read,write}_value. */
1191
Deepak Saxenaba9c2e82005-10-17 23:08:32 +02001192 if (!(data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 err = -ENOMEM;
1194 goto ERROR1;
1195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Jim Cromie311ce2e2006-09-24 21:22:52 +02001197 client = &data->client;
1198 i2c_set_clientdata(client, data);
1199 client->addr = address;
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001200 mutex_init(&data->lock);
Jim Cromie311ce2e2006-09-24 21:22:52 +02001201 client->adapter = adapter;
Jean Delvare7666c132007-05-08 17:22:02 +02001202 client->driver = &w83781d_driver;
Jim Cromie311ce2e2006-09-24 21:22:52 +02001203 dev = &client->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
1205 /* Now, we do the remaining detection. */
1206
1207 /* The w8378?d may be stuck in some other bank than bank 0. This may
1208 make reading other information impossible. Specify a force=... or
1209 force_*=... parameter, and the Winbond will be reset to the right
1210 bank. */
1211 if (kind < 0) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001212 if (w83781d_read_value(data, W83781D_REG_CONFIG) & 0x80) {
Jean Delvarebd452e62006-10-13 17:03:42 +02001213 dev_dbg(&adapter->dev, "Detection of w83781d chip "
1214 "failed at step 3\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 err = -ENODEV;
1216 goto ERROR2;
1217 }
Jean Delvare31b8dc42007-05-08 17:22:03 +02001218 val1 = w83781d_read_value(data, W83781D_REG_BANK);
1219 val2 = w83781d_read_value(data, W83781D_REG_CHIPMAN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 /* Check for Winbond or Asus ID if in bank 0 */
1221 if ((!(val1 & 0x07)) &&
1222 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3))
1223 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) {
Jean Delvarebd452e62006-10-13 17:03:42 +02001224 dev_dbg(&adapter->dev, "Detection of w83781d chip "
1225 "failed at step 4\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 err = -ENODEV;
1227 goto ERROR2;
1228 }
1229 /* If Winbond SMBus, check address at 0x48.
1230 Asus doesn't support, except for as99127f rev.2 */
Jean Delvare7666c132007-05-08 17:22:02 +02001231 if ((!(val1 & 0x80) && (val2 == 0xa3)) ||
1232 ((val1 & 0x80) && (val2 == 0x5c))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 if (w83781d_read_value
Jean Delvare31b8dc42007-05-08 17:22:03 +02001234 (data, W83781D_REG_I2C_ADDR) != address) {
Jean Delvarebd452e62006-10-13 17:03:42 +02001235 dev_dbg(&adapter->dev, "Detection of w83781d "
1236 "chip failed at step 5\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 err = -ENODEV;
1238 goto ERROR2;
1239 }
1240 }
1241 }
1242
1243 /* We have either had a force parameter, or we have already detected the
1244 Winbond. Put it now into bank 0 and Vendor ID High Byte */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001245 w83781d_write_value(data, W83781D_REG_BANK,
1246 (w83781d_read_value(data, W83781D_REG_BANK)
Jim Cromie311ce2e2006-09-24 21:22:52 +02001247 & 0x78) | 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249 /* Determine the chip type. */
1250 if (kind <= 0) {
1251 /* get vendor ID */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001252 val2 = w83781d_read_value(data, W83781D_REG_CHIPMAN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 if (val2 == 0x5c)
1254 vendid = winbond;
1255 else if (val2 == 0x12)
1256 vendid = asus;
1257 else {
Jean Delvarebd452e62006-10-13 17:03:42 +02001258 dev_dbg(&adapter->dev, "w83781d chip vendor is "
1259 "neither Winbond nor Asus\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 err = -ENODEV;
1261 goto ERROR2;
1262 }
1263
Jean Delvare31b8dc42007-05-08 17:22:03 +02001264 val1 = w83781d_read_value(data, W83781D_REG_WCHIPID);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)
1266 kind = w83781d;
1267 else if (val1 == 0x30 && vendid == winbond)
1268 kind = w83782d;
Jean Delvare7666c132007-05-08 17:22:02 +02001269 else if (val1 == 0x40 && vendid == winbond && address == 0x2d)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 kind = w83783s;
Jean Delvare7c7a5302005-06-16 19:24:14 +02001271 else if (val1 == 0x21 && vendid == winbond)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 kind = w83627hf;
Jean Delvare7666c132007-05-08 17:22:02 +02001273 else if (val1 == 0x31 && address >= 0x28)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 kind = as99127f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 else {
1276 if (kind == 0)
Jean Delvarebd452e62006-10-13 17:03:42 +02001277 dev_warn(&adapter->dev, "Ignoring 'force' "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 "parameter for unknown chip at "
Jean Delvarebd452e62006-10-13 17:03:42 +02001279 "address 0x%02x\n", address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 err = -EINVAL;
1281 goto ERROR2;
1282 }
1283 }
1284
1285 if (kind == w83781d) {
1286 client_name = "w83781d";
1287 } else if (kind == w83782d) {
1288 client_name = "w83782d";
1289 } else if (kind == w83783s) {
1290 client_name = "w83783s";
1291 } else if (kind == w83627hf) {
Jean Delvare7c7a5302005-06-16 19:24:14 +02001292 client_name = "w83627hf";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 } else if (kind == as99127f) {
1294 client_name = "as99127f";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 }
1296
1297 /* Fill in the remaining client fields and put into the global list */
Jim Cromie311ce2e2006-09-24 21:22:52 +02001298 strlcpy(client->name, client_name, I2C_NAME_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 data->type = kind;
1300
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 /* Tell the I2C layer a new client has arrived */
Jim Cromie311ce2e2006-09-24 21:22:52 +02001302 if ((err = i2c_attach_client(client)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 goto ERROR2;
1304
1305 /* attach secondary i2c lm75-like clients */
Jean Delvare7666c132007-05-08 17:22:02 +02001306 if ((err = w83781d_detect_subclients(adapter, address,
1307 kind, client)))
1308 goto ERROR3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
1310 /* Initialize the chip */
Jean Delvare7666c132007-05-08 17:22:02 +02001311 w83781d_init_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
1313 /* Register sysfs hooks */
Jean Delvare7666c132007-05-08 17:22:02 +02001314 err = w83781d_create_files(dev, kind, 0);
1315 if (err)
Jim Cromie311ce2e2006-09-24 21:22:52 +02001316 goto ERROR4;
1317
Tony Jones1beeffe2007-08-20 13:46:20 -07001318 data->hwmon_dev = hwmon_device_register(dev);
1319 if (IS_ERR(data->hwmon_dev)) {
1320 err = PTR_ERR(data->hwmon_dev);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001321 goto ERROR4;
1322 }
1323
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 return 0;
1325
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001326ERROR4:
Jim Cromie311ce2e2006-09-24 21:22:52 +02001327 sysfs_remove_group(&dev->kobj, &w83781d_group);
1328 sysfs_remove_group(&dev->kobj, &w83781d_group_opt);
1329
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001330 if (data->lm75[1]) {
1331 i2c_detach_client(data->lm75[1]);
1332 kfree(data->lm75[1]);
1333 }
1334 if (data->lm75[0]) {
1335 i2c_detach_client(data->lm75[0]);
1336 kfree(data->lm75[0]);
1337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338ERROR3:
Jim Cromie311ce2e2006-09-24 21:22:52 +02001339 i2c_detach_client(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340ERROR2:
1341 kfree(data);
1342ERROR1:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 return err;
1344}
1345
1346static int
1347w83781d_detach_client(struct i2c_client *client)
1348{
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001349 struct w83781d_data *data = i2c_get_clientdata(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 int err;
1351
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001352 /* main client */
Jim Cromie311ce2e2006-09-24 21:22:52 +02001353 if (data) {
Tony Jones1beeffe2007-08-20 13:46:20 -07001354 hwmon_device_unregister(data->hwmon_dev);
Jim Cromie311ce2e2006-09-24 21:22:52 +02001355 sysfs_remove_group(&client->dev.kobj, &w83781d_group);
1356 sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt);
1357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
Jean Delvare7bef5592005-07-27 22:14:49 +02001359 if ((err = i2c_detach_client(client)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001362 /* main client */
1363 if (data)
1364 kfree(data);
1365
1366 /* subclient */
1367 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 kfree(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
1370 return 0;
1371}
1372
Jean Delvare7666c132007-05-08 17:22:02 +02001373static int __devinit
1374w83781d_isa_probe(struct platform_device *pdev)
1375{
1376 int err, reg;
1377 struct w83781d_data *data;
1378 struct resource *res;
1379 const char *name;
1380
1381 /* Reserve the ISA region */
1382 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1383 if (!request_region(res->start, W83781D_EXTENT, "w83781d")) {
1384 err = -EBUSY;
1385 goto exit;
1386 }
1387
1388 if (!(data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
1389 err = -ENOMEM;
1390 goto exit_release_region;
1391 }
1392 mutex_init(&data->lock);
1393 data->client.addr = res->start;
1394 i2c_set_clientdata(&data->client, data);
1395 platform_set_drvdata(pdev, data);
1396
Jean Delvare31b8dc42007-05-08 17:22:03 +02001397 reg = w83781d_read_value(data, W83781D_REG_WCHIPID);
Jean Delvare7666c132007-05-08 17:22:02 +02001398 switch (reg) {
1399 case 0x21:
1400 data->type = w83627hf;
1401 name = "w83627hf";
1402 break;
1403 case 0x30:
1404 data->type = w83782d;
1405 name = "w83782d";
1406 break;
1407 default:
1408 data->type = w83781d;
1409 name = "w83781d";
1410 }
1411 strlcpy(data->client.name, name, I2C_NAME_SIZE);
1412
1413 /* Initialize the W83781D chip */
1414 w83781d_init_device(&pdev->dev);
1415
1416 /* Register sysfs hooks */
1417 err = w83781d_create_files(&pdev->dev, data->type, 1);
1418 if (err)
1419 goto exit_remove_files;
1420
Tony Jones1beeffe2007-08-20 13:46:20 -07001421 data->hwmon_dev = hwmon_device_register(&pdev->dev);
1422 if (IS_ERR(data->hwmon_dev)) {
1423 err = PTR_ERR(data->hwmon_dev);
Jean Delvare7666c132007-05-08 17:22:02 +02001424 goto exit_remove_files;
1425 }
1426
1427 return 0;
1428
1429 exit_remove_files:
1430 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
1431 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1432 device_remove_file(&pdev->dev, &dev_attr_name);
1433 kfree(data);
1434 exit_release_region:
1435 release_region(res->start, W83781D_EXTENT);
1436 exit:
1437 return err;
1438}
1439
1440static int __devexit
1441w83781d_isa_remove(struct platform_device *pdev)
1442{
1443 struct w83781d_data *data = platform_get_drvdata(pdev);
1444
Tony Jones1beeffe2007-08-20 13:46:20 -07001445 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare7666c132007-05-08 17:22:02 +02001446 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
1447 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1448 device_remove_file(&pdev->dev, &dev_attr_name);
1449 release_region(data->client.addr, W83781D_EXTENT);
1450 kfree(data);
1451
1452 return 0;
1453}
1454
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455/* The SMBus locks itself, usually, but nothing may access the Winbond between
1456 bank switches. ISA access must always be locked explicitly!
1457 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1458 would slow down the W83781D access and should not be necessary.
1459 There are some ugly typecasts here, but the good news is - they should
1460 nowhere else be necessary! */
1461static int
Jean Delvare31b8dc42007-05-08 17:22:03 +02001462w83781d_read_value(struct w83781d_data *data, u16 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463{
Jean Delvare31b8dc42007-05-08 17:22:03 +02001464 struct i2c_client *client = &data->client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 int res, word_sized, bank;
1466 struct i2c_client *cl;
1467
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001468 mutex_lock(&data->lock);
Jean Delvare7666c132007-05-08 17:22:02 +02001469 if (!client->driver) { /* ISA device */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 word_sized = (((reg & 0xff00) == 0x100)
1471 || ((reg & 0xff00) == 0x200))
1472 && (((reg & 0x00ff) == 0x50)
1473 || ((reg & 0x00ff) == 0x53)
1474 || ((reg & 0x00ff) == 0x55));
1475 if (reg & 0xff00) {
1476 outb_p(W83781D_REG_BANK,
1477 client->addr + W83781D_ADDR_REG_OFFSET);
1478 outb_p(reg >> 8,
1479 client->addr + W83781D_DATA_REG_OFFSET);
1480 }
1481 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET);
1482 res = inb_p(client->addr + W83781D_DATA_REG_OFFSET);
1483 if (word_sized) {
1484 outb_p((reg & 0xff) + 1,
1485 client->addr + W83781D_ADDR_REG_OFFSET);
1486 res =
1487 (res << 8) + inb_p(client->addr +
1488 W83781D_DATA_REG_OFFSET);
1489 }
1490 if (reg & 0xff00) {
1491 outb_p(W83781D_REG_BANK,
1492 client->addr + W83781D_ADDR_REG_OFFSET);
1493 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1494 }
1495 } else {
1496 bank = (reg >> 8) & 0x0f;
1497 if (bank > 2)
1498 /* switch banks */
1499 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1500 bank);
1501 if (bank == 0 || bank > 2) {
1502 res = i2c_smbus_read_byte_data(client, reg & 0xff);
1503 } else {
1504 /* switch to subclient */
1505 cl = data->lm75[bank - 1];
1506 /* convert from ISA to LM75 I2C addresses */
1507 switch (reg & 0xff) {
1508 case 0x50: /* TEMP */
1509 res = swab16(i2c_smbus_read_word_data(cl, 0));
1510 break;
1511 case 0x52: /* CONFIG */
1512 res = i2c_smbus_read_byte_data(cl, 1);
1513 break;
1514 case 0x53: /* HYST */
1515 res = swab16(i2c_smbus_read_word_data(cl, 2));
1516 break;
1517 case 0x55: /* OVER */
1518 default:
1519 res = swab16(i2c_smbus_read_word_data(cl, 3));
1520 break;
1521 }
1522 }
1523 if (bank > 2)
1524 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1525 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001526 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 return res;
1528}
1529
1530static int
Jean Delvare31b8dc42007-05-08 17:22:03 +02001531w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
Jean Delvare31b8dc42007-05-08 17:22:03 +02001533 struct i2c_client *client = &data->client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 int word_sized, bank;
1535 struct i2c_client *cl;
1536
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001537 mutex_lock(&data->lock);
Jean Delvare7666c132007-05-08 17:22:02 +02001538 if (!client->driver) { /* ISA device */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 word_sized = (((reg & 0xff00) == 0x100)
1540 || ((reg & 0xff00) == 0x200))
1541 && (((reg & 0x00ff) == 0x53)
1542 || ((reg & 0x00ff) == 0x55));
1543 if (reg & 0xff00) {
1544 outb_p(W83781D_REG_BANK,
1545 client->addr + W83781D_ADDR_REG_OFFSET);
1546 outb_p(reg >> 8,
1547 client->addr + W83781D_DATA_REG_OFFSET);
1548 }
1549 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET);
1550 if (word_sized) {
1551 outb_p(value >> 8,
1552 client->addr + W83781D_DATA_REG_OFFSET);
1553 outb_p((reg & 0xff) + 1,
1554 client->addr + W83781D_ADDR_REG_OFFSET);
1555 }
1556 outb_p(value & 0xff, client->addr + W83781D_DATA_REG_OFFSET);
1557 if (reg & 0xff00) {
1558 outb_p(W83781D_REG_BANK,
1559 client->addr + W83781D_ADDR_REG_OFFSET);
1560 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1561 }
1562 } else {
1563 bank = (reg >> 8) & 0x0f;
1564 if (bank > 2)
1565 /* switch banks */
1566 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1567 bank);
1568 if (bank == 0 || bank > 2) {
1569 i2c_smbus_write_byte_data(client, reg & 0xff,
1570 value & 0xff);
1571 } else {
1572 /* switch to subclient */
1573 cl = data->lm75[bank - 1];
1574 /* convert from ISA to LM75 I2C addresses */
1575 switch (reg & 0xff) {
1576 case 0x52: /* CONFIG */
1577 i2c_smbus_write_byte_data(cl, 1, value & 0xff);
1578 break;
1579 case 0x53: /* HYST */
1580 i2c_smbus_write_word_data(cl, 2, swab16(value));
1581 break;
1582 case 0x55: /* OVER */
1583 i2c_smbus_write_word_data(cl, 3, swab16(value));
1584 break;
1585 }
1586 }
1587 if (bank > 2)
1588 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1589 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001590 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 return 0;
1592}
1593
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594static void
Jean Delvare7666c132007-05-08 17:22:02 +02001595w83781d_init_device(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596{
Jean Delvare7666c132007-05-08 17:22:02 +02001597 struct w83781d_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 int i, p;
1599 int type = data->type;
1600 u8 tmp;
1601
Jean Delvaref5f8d382007-05-08 17:22:03 +02001602 if (type == w83627hf)
1603 dev_info(dev, "The W83627HF chip is better supported by the "
1604 "w83627hf driver, support will be dropped from the "
1605 "w83781d driver soon\n");
1606
Jean Delvarefabddcd2006-02-05 23:26:51 +01001607 if (reset && type != as99127f) { /* this resets registers we don't have
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 documentation for on the as99127f */
Jean Delvarefabddcd2006-02-05 23:26:51 +01001609 /* Resetting the chip has been the default for a long time,
1610 but it causes the BIOS initializations (fan clock dividers,
1611 thermal sensor types...) to be lost, so it is now optional.
1612 It might even go away if nobody reports it as being useful,
1613 as I see very little reason why this would be needed at
1614 all. */
Jean Delvare7666c132007-05-08 17:22:02 +02001615 dev_info(dev, "If reset=1 solved a problem you were "
Jean Delvarefabddcd2006-02-05 23:26:51 +01001616 "having, please report!\n");
1617
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 /* save these registers */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001619 i = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
1620 p = w83781d_read_value(data, W83781D_REG_PWMCLK12);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 /* Reset all except Watchdog values and last conversion values
1622 This sets fan-divs to 2, among others */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001623 w83781d_write_value(data, W83781D_REG_CONFIG, 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 /* Restore the registers and disable power-on abnormal beep.
1625 This saves FAN 1/2/3 input/output values set by BIOS. */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001626 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80);
1627 w83781d_write_value(data, W83781D_REG_PWMCLK12, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 /* Disable master beep-enable (reset turns it on).
1629 Individual beep_mask should be reset to off but for some reason
1630 disabling this bit helps some people not get beeped */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001631 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 }
1633
Jean Delvarefabddcd2006-02-05 23:26:51 +01001634 /* Disable power-on abnormal beep, as advised by the datasheet.
1635 Already done if reset=1. */
1636 if (init && !reset && type != as99127f) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001637 i = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
1638 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80);
Jean Delvarefabddcd2006-02-05 23:26:51 +01001639 }
1640
Jean Delvare303760b2005-07-31 21:52:01 +02001641 data->vrm = vid_which_vrm();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642
1643 if ((type != w83781d) && (type != as99127f)) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001644 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 for (i = 1; i <= 3; i++) {
1646 if (!(tmp & BIT_SCFG1[i - 1])) {
Jean Delvareb26f9332007-08-16 14:30:01 +02001647 data->sens[i - 1] = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 } else {
1649 if (w83781d_read_value
Jean Delvare31b8dc42007-05-08 17:22:03 +02001650 (data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 W83781D_REG_SCFG2) & BIT_SCFG2[i - 1])
1652 data->sens[i - 1] = 1;
1653 else
1654 data->sens[i - 1] = 2;
1655 }
Jean Delvare7c7a5302005-06-16 19:24:14 +02001656 if (type == w83783s && i == 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 break;
1658 }
1659 }
1660
1661 if (init && type != as99127f) {
1662 /* Enable temp2 */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001663 tmp = w83781d_read_value(data, W83781D_REG_TEMP2_CONFIG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 if (tmp & 0x01) {
Jean Delvare7666c132007-05-08 17:22:02 +02001665 dev_warn(dev, "Enabling temp2, readings "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 "might not make sense\n");
Jean Delvare31b8dc42007-05-08 17:22:03 +02001667 w83781d_write_value(data, W83781D_REG_TEMP2_CONFIG,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 tmp & 0xfe);
1669 }
1670
1671 /* Enable temp3 */
Jean Delvare7c7a5302005-06-16 19:24:14 +02001672 if (type != w83783s) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001673 tmp = w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 W83781D_REG_TEMP3_CONFIG);
1675 if (tmp & 0x01) {
Jean Delvare7666c132007-05-08 17:22:02 +02001676 dev_warn(dev, "Enabling temp3, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 "readings might not make sense\n");
Jean Delvare31b8dc42007-05-08 17:22:03 +02001678 w83781d_write_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 W83781D_REG_TEMP3_CONFIG, tmp & 0xfe);
1680 }
1681 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 }
1683
1684 /* Start monitoring */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001685 w83781d_write_value(data, W83781D_REG_CONFIG,
1686 (w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 W83781D_REG_CONFIG) & 0xf7)
1688 | 0x01);
Jean Delvare7666c132007-05-08 17:22:02 +02001689
1690 /* A few vars need to be filled upon startup */
Jean Delvare34875332007-05-08 17:22:03 +02001691 for (i = 0; i < 3; i++) {
1692 data->fan_min[i] = w83781d_read_value(data,
Jean Delvare7666c132007-05-08 17:22:02 +02001693 W83781D_REG_FAN_MIN(i));
1694 }
Jean Delvare7666c132007-05-08 17:22:02 +02001695
1696 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697}
1698
1699static struct w83781d_data *w83781d_update_device(struct device *dev)
1700{
Jean Delvare7666c132007-05-08 17:22:02 +02001701 struct w83781d_data *data = dev_get_drvdata(dev);
1702 struct i2c_client *client = &data->client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 int i;
1704
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001705 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
1707 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1708 || !data->valid) {
1709 dev_dbg(dev, "Starting device update\n");
1710
1711 for (i = 0; i <= 8; i++) {
Jean Delvare7c7a5302005-06-16 19:24:14 +02001712 if (data->type == w83783s && i == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 continue; /* 783S has no in1 */
1714 data->in[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001715 w83781d_read_value(data, W83781D_REG_IN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 data->in_min[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001717 w83781d_read_value(data, W83781D_REG_IN_MIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 data->in_max[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001719 w83781d_read_value(data, W83781D_REG_IN_MAX(i));
Jean Delvare7c7a5302005-06-16 19:24:14 +02001720 if ((data->type != w83782d)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 && (data->type != w83627hf) && (i == 6))
1722 break;
1723 }
Jean Delvare34875332007-05-08 17:22:03 +02001724 for (i = 0; i < 3; i++) {
1725 data->fan[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001726 w83781d_read_value(data, W83781D_REG_FAN(i));
Jean Delvare34875332007-05-08 17:22:03 +02001727 data->fan_min[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001728 w83781d_read_value(data, W83781D_REG_FAN_MIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 }
1730 if (data->type != w83781d && data->type != as99127f) {
Jean Delvare34875332007-05-08 17:22:03 +02001731 for (i = 0; i < 4; i++) {
1732 data->pwm[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001733 w83781d_read_value(data,
Jean Delvare34875332007-05-08 17:22:03 +02001734 W83781D_REG_PWM[i]);
Jean Delvare7666c132007-05-08 17:22:02 +02001735 if ((data->type != w83782d || !client->driver)
Jean Delvare34875332007-05-08 17:22:03 +02001736 && i == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 break;
1738 }
1739 /* Only PWM2 can be disabled */
Jean Delvare34875332007-05-08 17:22:03 +02001740 data->pwm2_enable = (w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 W83781D_REG_PWMCLK12) & 0x08) >> 3;
1742 }
1743
Jean Delvare31b8dc42007-05-08 17:22:03 +02001744 data->temp = w83781d_read_value(data, W83781D_REG_TEMP(1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 data->temp_max =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001746 w83781d_read_value(data, W83781D_REG_TEMP_OVER(1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 data->temp_max_hyst =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001748 w83781d_read_value(data, W83781D_REG_TEMP_HYST(1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 data->temp_add[0] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001750 w83781d_read_value(data, W83781D_REG_TEMP(2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 data->temp_max_add[0] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001752 w83781d_read_value(data, W83781D_REG_TEMP_OVER(2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 data->temp_max_hyst_add[0] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001754 w83781d_read_value(data, W83781D_REG_TEMP_HYST(2));
Jean Delvare7c7a5302005-06-16 19:24:14 +02001755 if (data->type != w83783s) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 data->temp_add[1] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001757 w83781d_read_value(data, W83781D_REG_TEMP(3));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 data->temp_max_add[1] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001759 w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 W83781D_REG_TEMP_OVER(3));
1761 data->temp_max_hyst_add[1] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001762 w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 W83781D_REG_TEMP_HYST(3));
1764 }
Jean Delvare31b8dc42007-05-08 17:22:03 +02001765 i = w83781d_read_value(data, W83781D_REG_VID_FANDIV);
Jean Delvare7c7a5302005-06-16 19:24:14 +02001766 data->vid = i & 0x0f;
Jean Delvare31b8dc42007-05-08 17:22:03 +02001767 data->vid |= (w83781d_read_value(data,
Jean Delvare7c7a5302005-06-16 19:24:14 +02001768 W83781D_REG_CHIPID) & 0x01) << 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 data->fan_div[0] = (i >> 4) & 0x03;
1770 data->fan_div[1] = (i >> 6) & 0x03;
Jean Delvare31b8dc42007-05-08 17:22:03 +02001771 data->fan_div[2] = (w83781d_read_value(data,
Jean Delvare7c7a5302005-06-16 19:24:14 +02001772 W83781D_REG_PIN) >> 6) & 0x03;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 if ((data->type != w83781d) && (data->type != as99127f)) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001774 i = w83781d_read_value(data, W83781D_REG_VBAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 data->fan_div[0] |= (i >> 3) & 0x04;
1776 data->fan_div[1] |= (i >> 4) & 0x04;
Jean Delvare7c7a5302005-06-16 19:24:14 +02001777 data->fan_div[2] |= (i >> 5) & 0x04;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 if ((data->type == w83782d) || (data->type == w83627hf)) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001780 data->alarms = w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001781 W83782D_REG_ALARM1)
Jean Delvare31b8dc42007-05-08 17:22:03 +02001782 | (w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001783 W83782D_REG_ALARM2) << 8)
Jean Delvare31b8dc42007-05-08 17:22:03 +02001784 | (w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001785 W83782D_REG_ALARM3) << 16);
1786 } else if (data->type == w83783s) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001787 data->alarms = w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001788 W83782D_REG_ALARM1)
Jean Delvare31b8dc42007-05-08 17:22:03 +02001789 | (w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001790 W83782D_REG_ALARM2) << 8);
1791 } else {
1792 /* No real-time status registers, fall back to
1793 interrupt status registers */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001794 data->alarms = w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001795 W83781D_REG_ALARM1)
Jean Delvare31b8dc42007-05-08 17:22:03 +02001796 | (w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001797 W83781D_REG_ALARM2) << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 }
Jean Delvare31b8dc42007-05-08 17:22:03 +02001799 i = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 data->beep_enable = i >> 7;
1801 data->beep_mask = ((i & 0x7f) << 8) +
Jean Delvare31b8dc42007-05-08 17:22:03 +02001802 w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 if ((data->type != w83781d) && (data->type != as99127f)) {
1804 data->beep_mask |=
Jean Delvare31b8dc42007-05-08 17:22:03 +02001805 w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 W83781D_REG_BEEP_INTS3) << 16;
1807 }
1808 data->last_updated = jiffies;
1809 data->valid = 1;
1810 }
1811
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001812 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813
1814 return data;
1815}
1816
Jean Delvare7666c132007-05-08 17:22:02 +02001817/* return 1 if a supported chip is found, 0 otherwise */
1818static int __init
1819w83781d_isa_found(unsigned short address)
1820{
1821 int val, save, found = 0;
1822
1823 if (!request_region(address, W83781D_EXTENT, "w83781d"))
1824 return 0;
1825
1826#define REALLY_SLOW_IO
1827 /* We need the timeouts for at least some W83781D-like
1828 chips. But only if we read 'undefined' registers. */
1829 val = inb_p(address + 1);
1830 if (inb_p(address + 2) != val
1831 || inb_p(address + 3) != val
1832 || inb_p(address + 7) != val) {
1833 pr_debug("w83781d: Detection failed at step 1\n");
1834 goto release;
1835 }
1836#undef REALLY_SLOW_IO
1837
1838 /* We should be able to change the 7 LSB of the address port. The
1839 MSB (busy flag) should be clear initially, set after the write. */
1840 save = inb_p(address + W83781D_ADDR_REG_OFFSET);
1841 if (save & 0x80) {
1842 pr_debug("w83781d: Detection failed at step 2\n");
1843 goto release;
1844 }
1845 val = ~save & 0x7f;
1846 outb_p(val, address + W83781D_ADDR_REG_OFFSET);
1847 if (inb_p(address + W83781D_ADDR_REG_OFFSET) != (val | 0x80)) {
1848 outb_p(save, address + W83781D_ADDR_REG_OFFSET);
1849 pr_debug("w83781d: Detection failed at step 3\n");
1850 goto release;
1851 }
1852
1853 /* We found a device, now see if it could be a W83781D */
1854 outb_p(W83781D_REG_CONFIG, address + W83781D_ADDR_REG_OFFSET);
1855 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1856 if (val & 0x80) {
1857 pr_debug("w83781d: Detection failed at step 4\n");
1858 goto release;
1859 }
1860 outb_p(W83781D_REG_BANK, address + W83781D_ADDR_REG_OFFSET);
1861 save = inb_p(address + W83781D_DATA_REG_OFFSET);
1862 outb_p(W83781D_REG_CHIPMAN, address + W83781D_ADDR_REG_OFFSET);
1863 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1864 if ((!(save & 0x80) && (val != 0xa3))
1865 || ((save & 0x80) && (val != 0x5c))) {
1866 pr_debug("w83781d: Detection failed at step 5\n");
1867 goto release;
1868 }
1869 outb_p(W83781D_REG_I2C_ADDR, address + W83781D_ADDR_REG_OFFSET);
1870 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1871 if (val < 0x03 || val > 0x77) { /* Not a valid I2C address */
1872 pr_debug("w83781d: Detection failed at step 6\n");
1873 goto release;
1874 }
1875
1876 /* The busy flag should be clear again */
1877 if (inb_p(address + W83781D_ADDR_REG_OFFSET) & 0x80) {
1878 pr_debug("w83781d: Detection failed at step 7\n");
1879 goto release;
1880 }
1881
1882 /* Determine the chip type */
1883 outb_p(W83781D_REG_BANK, address + W83781D_ADDR_REG_OFFSET);
1884 save = inb_p(address + W83781D_DATA_REG_OFFSET);
1885 outb_p(save & 0xf8, address + W83781D_DATA_REG_OFFSET);
1886 outb_p(W83781D_REG_WCHIPID, address + W83781D_ADDR_REG_OFFSET);
1887 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1888 if ((val & 0xfe) == 0x10 /* W83781D */
1889 || val == 0x30 /* W83782D */
1890 || val == 0x21) /* W83627HF */
1891 found = 1;
1892
1893 if (found)
1894 pr_info("w83781d: Found a %s chip at %#x\n",
1895 val == 0x21 ? "W83627HF" :
1896 val == 0x30 ? "W83782D" : "W83781D", (int)address);
1897
1898 release:
1899 release_region(address, W83781D_EXTENT);
1900 return found;
1901}
1902
1903static int __init
1904w83781d_isa_device_add(unsigned short address)
1905{
1906 struct resource res = {
1907 .start = address,
Jean Delvare15bde2f2007-08-29 10:39:57 +02001908 .end = address + W83781D_EXTENT - 1,
Jean Delvare7666c132007-05-08 17:22:02 +02001909 .name = "w83781d",
1910 .flags = IORESOURCE_IO,
1911 };
1912 int err;
1913
1914 pdev = platform_device_alloc("w83781d", address);
1915 if (!pdev) {
1916 err = -ENOMEM;
1917 printk(KERN_ERR "w83781d: Device allocation failed\n");
1918 goto exit;
1919 }
1920
1921 err = platform_device_add_resources(pdev, &res, 1);
1922 if (err) {
1923 printk(KERN_ERR "w83781d: Device resource addition failed "
1924 "(%d)\n", err);
1925 goto exit_device_put;
1926 }
1927
1928 err = platform_device_add(pdev);
1929 if (err) {
1930 printk(KERN_ERR "w83781d: Device addition failed (%d)\n",
1931 err);
1932 goto exit_device_put;
1933 }
1934
1935 return 0;
1936
1937 exit_device_put:
1938 platform_device_put(pdev);
1939 exit:
1940 pdev = NULL;
1941 return err;
1942}
1943
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944static int __init
1945sensors_w83781d_init(void)
1946{
Jean Delvarefde09502005-07-19 23:51:07 +02001947 int res;
1948
1949 res = i2c_add_driver(&w83781d_driver);
1950 if (res)
Jean Delvare7666c132007-05-08 17:22:02 +02001951 goto exit;
Jean Delvarefde09502005-07-19 23:51:07 +02001952
Jean Delvare7666c132007-05-08 17:22:02 +02001953 if (w83781d_isa_found(isa_address)) {
1954 res = platform_driver_register(&w83781d_isa_driver);
1955 if (res)
1956 goto exit_unreg_i2c_driver;
1957
1958 /* Sets global pdev as a side effect */
1959 res = w83781d_isa_device_add(isa_address);
1960 if (res)
1961 goto exit_unreg_isa_driver;
1962 }
Jean Delvarefde09502005-07-19 23:51:07 +02001963
1964 return 0;
Jean Delvare7666c132007-05-08 17:22:02 +02001965
1966 exit_unreg_isa_driver:
1967 platform_driver_unregister(&w83781d_isa_driver);
1968 exit_unreg_i2c_driver:
1969 i2c_del_driver(&w83781d_driver);
1970 exit:
1971 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972}
1973
1974static void __exit
1975sensors_w83781d_exit(void)
1976{
Jean Delvare7666c132007-05-08 17:22:02 +02001977 if (pdev) {
1978 platform_device_unregister(pdev);
1979 platform_driver_unregister(&w83781d_isa_driver);
1980 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 i2c_del_driver(&w83781d_driver);
1982}
1983
1984MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
1985 "Philip Edelbrock <phil@netroedge.com>, "
1986 "and Mark Studebaker <mdsxyz123@yahoo.com>");
1987MODULE_DESCRIPTION("W83781D driver");
1988MODULE_LICENSE("GPL");
1989
1990module_init(sensors_w83781d_init);
1991module_exit(sensors_w83781d_exit);