blob: d38b9ede3abd1851b72d47ba0088678d01ecffb4 [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 */
Jean Delvare6722fea2007-10-07 12:25:46 +020057static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
58 0x2e, 0x2f, I2C_CLIENT_END };
Jean Delvare2d8672c2005-07-19 23:56:35 +020059static unsigned short isa_address = 0x290;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61/* Insmod parameters */
Jean Delvaref4b50262005-07-31 21:49:03 +020062I2C_CLIENT_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
64 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
65
Jean Delvarefabddcd2006-02-05 23:26:51 +010066static int reset;
67module_param(reset, bool, 0);
68MODULE_PARM_DESC(reset, "Set to one to reset chip on load");
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070static int init = 1;
71module_param(init, bool, 0);
72MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
73
74/* Constants specified below */
75
76/* Length of ISA address segment */
77#define W83781D_EXTENT 8
78
79/* Where are the ISA address/data registers relative to the base address */
80#define W83781D_ADDR_REG_OFFSET 5
81#define W83781D_DATA_REG_OFFSET 6
82
Jean Delvare34875332007-05-08 17:22:03 +020083/* The device registers */
84/* in nr from 0 to 8 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \
86 (0x554 + (((nr) - 7) * 2)))
87#define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \
88 (0x555 + (((nr) - 7) * 2)))
89#define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
90 (0x550 + (nr) - 7))
91
Jean Delvare34875332007-05-08 17:22:03 +020092/* fan nr from 0 to 2 */
93#define W83781D_REG_FAN_MIN(nr) (0x3b + (nr))
94#define W83781D_REG_FAN(nr) (0x28 + (nr))
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96#define W83781D_REG_BANK 0x4E
97#define W83781D_REG_TEMP2_CONFIG 0x152
98#define W83781D_REG_TEMP3_CONFIG 0x252
Jean Delvare34875332007-05-08 17:22:03 +020099/* temp nr from 1 to 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \
101 ((nr == 2) ? (0x0150) : \
102 (0x27)))
103#define W83781D_REG_TEMP_HYST(nr) ((nr == 3) ? (0x253) : \
104 ((nr == 2) ? (0x153) : \
105 (0x3A)))
106#define W83781D_REG_TEMP_OVER(nr) ((nr == 3) ? (0x255) : \
107 ((nr == 2) ? (0x155) : \
108 (0x39)))
109
110#define W83781D_REG_CONFIG 0x40
Jean Delvarec7f5d7e2006-02-05 23:13:48 +0100111
112/* Interrupt status (W83781D, AS99127F) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define W83781D_REG_ALARM1 0x41
114#define W83781D_REG_ALARM2 0x42
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Jean Delvarec7f5d7e2006-02-05 23:13:48 +0100116/* Real-time status (W83782D, W83783S, W83627HF) */
117#define W83782D_REG_ALARM1 0x459
118#define W83782D_REG_ALARM2 0x45A
119#define W83782D_REG_ALARM3 0x45B
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#define W83781D_REG_BEEP_CONFIG 0x4D
122#define W83781D_REG_BEEP_INTS1 0x56
123#define W83781D_REG_BEEP_INTS2 0x57
124#define W83781D_REG_BEEP_INTS3 0x453 /* not on W83781D */
125
126#define W83781D_REG_VID_FANDIV 0x47
127
128#define W83781D_REG_CHIPID 0x49
129#define W83781D_REG_WCHIPID 0x58
130#define W83781D_REG_CHIPMAN 0x4F
131#define W83781D_REG_PIN 0x4B
132
133/* 782D/783S only */
134#define W83781D_REG_VBAT 0x5D
135
136/* PWM 782D (1-4) and 783S (1-2) only */
Jean Delvare34875332007-05-08 17:22:03 +0200137static const u8 W83781D_REG_PWM[] = { 0x5B, 0x5A, 0x5E, 0x5F };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#define W83781D_REG_PWMCLK12 0x5C
139#define W83781D_REG_PWMCLK34 0x45C
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141#define W83781D_REG_I2C_ADDR 0x48
142#define W83781D_REG_I2C_SUBADDR 0x4A
143
144/* The following are undocumented in the data sheets however we
145 received the information in an email from Winbond tech support */
146/* Sensor selection - not on 781d */
147#define W83781D_REG_SCFG1 0x5D
148static const u8 BIT_SCFG1[] = { 0x02, 0x04, 0x08 };
149
150#define W83781D_REG_SCFG2 0x59
151static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
152
153#define W83781D_DEFAULT_BETA 3435
154
155/* RT Table registers */
156#define W83781D_REG_RT_IDX 0x50
157#define W83781D_REG_RT_VAL 0x51
158
Jean Delvare474d00a2007-05-08 17:22:03 +0200159/* Conversions */
160#define IN_TO_REG(val) SENSORS_LIMIT(((val) + 8) / 16, 0, 255)
161#define IN_FROM_REG(val) ((val) * 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163static inline u8
164FAN_TO_REG(long rpm, int div)
165{
166 if (rpm == 0)
167 return 255;
168 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
169 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
170}
171
Jean Delvare474d00a2007-05-08 17:22:03 +0200172static inline long
173FAN_FROM_REG(u8 val, int div)
174{
175 if (val == 0)
176 return -1;
177 if (val == 255)
178 return 0;
179 return 1350000 / (val * div);
180}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Jean Delvare474d00a2007-05-08 17:22:03 +0200182#define TEMP_TO_REG(val) SENSORS_LIMIT((val) / 1000, -127, 128)
183#define TEMP_FROM_REG(val) ((val) * 1000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \
186 (val) ^ 0x7fff : (val))
187#define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \
188 (~(val)) & 0x7fff : (val) & 0xffffff)
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190#define DIV_FROM_REG(val) (1 << (val))
191
192static inline u8
193DIV_TO_REG(long val, enum chips type)
194{
195 int i;
196 val = SENSORS_LIMIT(val, 1,
197 ((type == w83781d
198 || type == as99127f) ? 8 : 128)) >> 1;
Grant Coadyabc01922005-05-12 13:41:51 +1000199 for (i = 0; i < 7; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 if (val == 0)
201 break;
202 val >>= 1;
203 }
Jean Delvare474d00a2007-05-08 17:22:03 +0200204 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
207/* There are some complications in a module like this. First off, W83781D chips
208 may be both present on the SMBus and the ISA bus, and we have to handle
209 those cases separately at some places. Second, there might be several
210 W83781D chips available (well, actually, that is probably never done; but
211 it is a clean illustration of how to handle a case like that). Finally,
212 a specific chip may be attached to *both* ISA and SMBus, and we would
213 not like to detect it double. Fortunately, in the case of the W83781D at
214 least, a register tells us what SMBus address we are on, so that helps
215 a bit - except if there could be more than one SMBus. Groan. No solution
216 for this yet. */
217
Jean Delvare7666c132007-05-08 17:22:02 +0200218/* For ISA chips, we abuse the i2c_client addr and name fields. We also use
219 the driver field to differentiate between I2C and ISA chips. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220struct w83781d_data {
221 struct i2c_client client;
Tony Jones1beeffe2007-08-20 13:46:20 -0700222 struct device *hwmon_dev;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100223 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 enum chips type;
225
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100226 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 char valid; /* !=0 if following fields are valid */
228 unsigned long last_updated; /* In jiffies */
229
230 struct i2c_client *lm75[2]; /* for secondary I2C addresses */
231 /* array of 2 pointers to subclients */
232
233 u8 in[9]; /* Register value - 8 & 9 for 782D only */
234 u8 in_max[9]; /* Register value - 8 & 9 for 782D only */
235 u8 in_min[9]; /* Register value - 8 & 9 for 782D only */
236 u8 fan[3]; /* Register value */
237 u8 fan_min[3]; /* Register value */
Jean Delvare474d00a2007-05-08 17:22:03 +0200238 s8 temp; /* Register value */
239 s8 temp_max; /* Register value */
240 s8 temp_max_hyst; /* Register value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 u16 temp_add[2]; /* Register value */
242 u16 temp_max_add[2]; /* Register value */
243 u16 temp_max_hyst_add[2]; /* Register value */
244 u8 fan_div[3]; /* Register encoding, shifted right */
245 u8 vid; /* Register encoding, combined */
246 u32 alarms; /* Register encoding, combined */
247 u32 beep_mask; /* Register encoding, combined */
248 u8 beep_enable; /* Boolean */
249 u8 pwm[4]; /* Register value */
Jean Delvare34875332007-05-08 17:22:03 +0200250 u8 pwm2_enable; /* Boolean */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 u16 sens[3]; /* 782D/783S only.
252 1 = pentium diode; 2 = 3904 diode;
Jean Delvareb26f9332007-08-16 14:30:01 +0200253 4 = thermistor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 u8 vrm;
255};
256
257static int w83781d_attach_adapter(struct i2c_adapter *adapter);
258static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind);
259static int w83781d_detach_client(struct i2c_client *client);
260
Jean Delvare7666c132007-05-08 17:22:02 +0200261static int __devinit w83781d_isa_probe(struct platform_device *pdev);
262static int __devexit w83781d_isa_remove(struct platform_device *pdev);
263
Jean Delvare31b8dc42007-05-08 17:22:03 +0200264static int w83781d_read_value(struct w83781d_data *data, u16 reg);
265static int w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266static struct w83781d_data *w83781d_update_device(struct device *dev);
Jean Delvare7666c132007-05-08 17:22:02 +0200267static void w83781d_init_device(struct device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269static struct i2c_driver w83781d_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100270 .driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100271 .name = "w83781d",
272 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 .id = I2C_DRIVERID_W83781D,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 .attach_adapter = w83781d_attach_adapter,
275 .detach_client = w83781d_detach_client,
276};
277
Jean Delvare7666c132007-05-08 17:22:02 +0200278static struct platform_driver w83781d_isa_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100279 .driver = {
Jean Delvare87218842006-09-03 22:36:14 +0200280 .owner = THIS_MODULE,
Jean Delvare7666c132007-05-08 17:22:02 +0200281 .name = "w83781d",
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100282 },
Jean Delvare7666c132007-05-08 17:22:02 +0200283 .probe = w83781d_isa_probe,
284 .remove = w83781d_isa_remove,
Jean Delvarefde09502005-07-19 23:51:07 +0200285};
286
287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288/* following are the sysfs callback functions */
289#define show_in_reg(reg) \
Jean Delvare34875332007-05-08 17:22:03 +0200290static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
291 char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{ \
Jean Delvare34875332007-05-08 17:22:03 +0200293 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 struct w83781d_data *data = w83781d_update_device(dev); \
Jean Delvare34875332007-05-08 17:22:03 +0200295 return sprintf(buf, "%ld\n", \
296 (long)IN_FROM_REG(data->reg[attr->index])); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298show_in_reg(in);
299show_in_reg(in_min);
300show_in_reg(in_max);
301
302#define store_in_reg(REG, reg) \
Jean Delvare34875332007-05-08 17:22:03 +0200303static ssize_t store_in_##reg (struct device *dev, struct device_attribute \
304 *da, const char *buf, size_t count) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{ \
Jean Delvare34875332007-05-08 17:22:03 +0200306 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
Jean Delvare7666c132007-05-08 17:22:02 +0200307 struct w83781d_data *data = dev_get_drvdata(dev); \
Jean Delvare34875332007-05-08 17:22:03 +0200308 int nr = attr->index; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 u32 val; \
310 \
Jean Delvare474d00a2007-05-08 17:22:03 +0200311 val = simple_strtoul(buf, NULL, 10); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 \
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100313 mutex_lock(&data->update_lock); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 data->in_##reg[nr] = IN_TO_REG(val); \
Jean Delvare31b8dc42007-05-08 17:22:03 +0200315 w83781d_write_value(data, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 \
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100317 mutex_unlock(&data->update_lock); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return count; \
319}
320store_in_reg(MIN, min);
321store_in_reg(MAX, max);
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#define sysfs_in_offsets(offset) \
Jean Delvare34875332007-05-08 17:22:03 +0200324static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
325 show_in, NULL, offset); \
326static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
327 show_in_min, store_in_min, offset); \
328static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
329 show_in_max, store_in_max, offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331sysfs_in_offsets(0);
332sysfs_in_offsets(1);
333sysfs_in_offsets(2);
334sysfs_in_offsets(3);
335sysfs_in_offsets(4);
336sysfs_in_offsets(5);
337sysfs_in_offsets(6);
338sysfs_in_offsets(7);
339sysfs_in_offsets(8);
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#define show_fan_reg(reg) \
Jean Delvare34875332007-05-08 17:22:03 +0200342static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
343 char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{ \
Jean Delvare34875332007-05-08 17:22:03 +0200345 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 struct w83781d_data *data = w83781d_update_device(dev); \
347 return sprintf(buf,"%ld\n", \
Jean Delvare34875332007-05-08 17:22:03 +0200348 FAN_FROM_REG(data->reg[attr->index], \
349 DIV_FROM_REG(data->fan_div[attr->index]))); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351show_fan_reg(fan);
352show_fan_reg(fan_min);
353
354static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200355store_fan_min(struct device *dev, struct device_attribute *da,
356 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Jean Delvare34875332007-05-08 17:22:03 +0200358 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Jean Delvare7666c132007-05-08 17:22:02 +0200359 struct w83781d_data *data = dev_get_drvdata(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200360 int nr = attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 u32 val;
362
363 val = simple_strtoul(buf, NULL, 10);
364
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100365 mutex_lock(&data->update_lock);
Jean Delvare34875332007-05-08 17:22:03 +0200366 data->fan_min[nr] =
367 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvare31b8dc42007-05-08 17:22:03 +0200368 w83781d_write_value(data, W83781D_REG_FAN_MIN(nr),
Jean Delvare34875332007-05-08 17:22:03 +0200369 data->fan_min[nr]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100371 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 return count;
373}
374
Jean Delvare34875332007-05-08 17:22:03 +0200375static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
376static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
377 show_fan_min, store_fan_min, 0);
378static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
379static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
380 show_fan_min, store_fan_min, 1);
381static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
382static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR,
383 show_fan_min, store_fan_min, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define show_temp_reg(reg) \
Jean Delvare34875332007-05-08 17:22:03 +0200386static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
387 char *buf) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{ \
Jean Delvare34875332007-05-08 17:22:03 +0200389 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 struct w83781d_data *data = w83781d_update_device(dev); \
Jean Delvare34875332007-05-08 17:22:03 +0200391 int nr = attr->index; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
393 return sprintf(buf,"%d\n", \
394 LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \
395 } else { /* TEMP1 */ \
396 return sprintf(buf,"%ld\n", (long)TEMP_FROM_REG(data->reg)); \
397 } \
398}
399show_temp_reg(temp);
400show_temp_reg(temp_max);
401show_temp_reg(temp_max_hyst);
402
403#define store_temp_reg(REG, reg) \
Jean Delvare34875332007-05-08 17:22:03 +0200404static ssize_t store_temp_##reg (struct device *dev, \
405 struct device_attribute *da, const char *buf, size_t count) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{ \
Jean Delvare34875332007-05-08 17:22:03 +0200407 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
Jean Delvare7666c132007-05-08 17:22:02 +0200408 struct w83781d_data *data = dev_get_drvdata(dev); \
Jean Delvare34875332007-05-08 17:22:03 +0200409 int nr = attr->index; \
Christian Hohnstaedt5bfedac2007-08-16 11:40:10 +0200410 long val; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 \
412 val = simple_strtol(buf, NULL, 10); \
413 \
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100414 mutex_lock(&data->update_lock); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 \
416 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
417 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
Jean Delvare31b8dc42007-05-08 17:22:03 +0200418 w83781d_write_value(data, W83781D_REG_TEMP_##REG(nr), \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 data->temp_##reg##_add[nr-2]); \
420 } else { /* TEMP1 */ \
421 data->temp_##reg = TEMP_TO_REG(val); \
Jean Delvare31b8dc42007-05-08 17:22:03 +0200422 w83781d_write_value(data, W83781D_REG_TEMP_##REG(nr), \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 data->temp_##reg); \
424 } \
425 \
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100426 mutex_unlock(&data->update_lock); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 return count; \
428}
429store_temp_reg(OVER, max);
430store_temp_reg(HYST, max_hyst);
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define sysfs_temp_offsets(offset) \
Jean Delvare34875332007-05-08 17:22:03 +0200433static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
434 show_temp, NULL, offset); \
435static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
436 show_temp_max, store_temp_max, offset); \
437static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
438 show_temp_max_hyst, store_temp_max_hyst, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440sysfs_temp_offsets(1);
441sysfs_temp_offsets(2);
442sysfs_temp_offsets(3);
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400445show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
447 struct w83781d_data *data = w83781d_update_device(dev);
448 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
449}
450
Jim Cromie311ce2e2006-09-24 21:22:52 +0200451static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400454show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Jean Delvare90d66192007-10-08 18:24:35 +0200456 struct w83781d_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 return sprintf(buf, "%ld\n", (long) data->vrm);
458}
459
460static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400461store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
Jean Delvare7666c132007-05-08 17:22:02 +0200463 struct w83781d_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 u32 val;
465
466 val = simple_strtoul(buf, NULL, 10);
467 data->vrm = val;
468
469 return count;
470}
471
Jim Cromie311ce2e2006-09-24 21:22:52 +0200472static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400475show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
477 struct w83781d_data *data = w83781d_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +0200478 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
Jim Cromie311ce2e2006-09-24 21:22:52 +0200481static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
482
Jean Delvare7d4a1372007-10-08 18:29:43 +0200483static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
484 char *buf)
485{
486 struct w83781d_data *data = w83781d_update_device(dev);
487 int bitnr = to_sensor_dev_attr(attr)->index;
488 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
489}
490
491/* The W83781D has a single alarm bit for temp2 and temp3 */
492static ssize_t show_temp3_alarm(struct device *dev,
493 struct device_attribute *attr, char *buf)
494{
495 struct w83781d_data *data = w83781d_update_device(dev);
496 int bitnr = (data->type == w83781d) ? 5 : 13;
497 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
498}
499
500static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
501static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
502static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
503static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
504static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
505static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
506static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 10);
507static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16);
508static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17);
509static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
510static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
511static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
512static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
513static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
514static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_temp3_alarm, NULL, 0);
515
Yani Ioannoue404e272005-05-17 06:42:58 -0400516static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
518 struct w83781d_data *data = w83781d_update_device(dev);
519 return sprintf(buf, "%ld\n",
520 (long)BEEP_MASK_FROM_REG(data->beep_mask, data->type));
521}
Yani Ioannoue404e272005-05-17 06:42:58 -0400522static ssize_t show_beep_enable (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
524 struct w83781d_data *data = w83781d_update_device(dev);
Jean Delvare474d00a2007-05-08 17:22:03 +0200525 return sprintf(buf, "%ld\n", (long)data->beep_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526}
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200529store_beep_mask(struct device *dev, struct device_attribute *attr,
530 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Jean Delvare7666c132007-05-08 17:22:02 +0200532 struct w83781d_data *data = dev_get_drvdata(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200533 u32 val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 val = simple_strtoul(buf, NULL, 10);
536
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100537 mutex_lock(&data->update_lock);
Jean Delvare34875332007-05-08 17:22:03 +0200538 data->beep_mask = BEEP_MASK_TO_REG(val, data->type);
539 w83781d_write_value(data, W83781D_REG_BEEP_INTS1,
540 data->beep_mask & 0xff);
Jean Delvare31b8dc42007-05-08 17:22:03 +0200541 w83781d_write_value(data, W83781D_REG_BEEP_INTS2,
Jean Delvare34875332007-05-08 17:22:03 +0200542 ((data->beep_mask >> 8) & 0x7f)
543 | data->beep_enable << 7);
544 if (data->type != w83781d && data->type != as99127f) {
545 w83781d_write_value(data, W83781D_REG_BEEP_INTS3,
546 ((data->beep_mask) >> 16) & 0xff);
547 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100548 mutex_unlock(&data->update_lock);
Jean Delvare34875332007-05-08 17:22:03 +0200549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 return count;
551}
552
Jean Delvare34875332007-05-08 17:22:03 +0200553static ssize_t
554store_beep_enable(struct device *dev, struct device_attribute *attr,
555 const char *buf, size_t count)
556{
557 struct w83781d_data *data = dev_get_drvdata(dev);
558 u32 val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Jean Delvare34875332007-05-08 17:22:03 +0200560 val = simple_strtoul(buf, NULL, 10);
561 if (val != 0 && val != 1)
562 return -EINVAL;
563
564 mutex_lock(&data->update_lock);
565 data->beep_enable = val;
566 val = w83781d_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f;
567 val |= data->beep_enable << 7;
568 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, val);
569 mutex_unlock(&data->update_lock);
570
571 return count;
572}
573
574static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
575 show_beep_mask, store_beep_mask);
576static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
577 show_beep_enable, store_beep_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Jean Delvare7d4a1372007-10-08 18:29:43 +0200579static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
580 char *buf)
581{
582 struct w83781d_data *data = w83781d_update_device(dev);
583 int bitnr = to_sensor_dev_attr(attr)->index;
584 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
585}
586
587static ssize_t
588store_beep(struct device *dev, struct device_attribute *attr,
589 const char *buf, size_t count)
590{
591 struct w83781d_data *data = dev_get_drvdata(dev);
592 int bitnr = to_sensor_dev_attr(attr)->index;
593 unsigned long bit;
594 u8 reg;
595
596 bit = simple_strtoul(buf, NULL, 10);
597 if (bit & ~1)
598 return -EINVAL;
599
600 mutex_lock(&data->update_lock);
601 if (bit)
602 data->beep_mask |= (1 << bitnr);
603 else
604 data->beep_mask &= ~(1 << bitnr);
605
606 if (bitnr < 8) {
607 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
608 if (bit)
609 reg |= (1 << bitnr);
610 else
611 reg &= ~(1 << bitnr);
612 w83781d_write_value(data, W83781D_REG_BEEP_INTS1, reg);
613 } else if (bitnr < 16) {
614 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
615 if (bit)
616 reg |= (1 << (bitnr - 8));
617 else
618 reg &= ~(1 << (bitnr - 8));
619 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, reg);
620 } else {
621 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS3);
622 if (bit)
623 reg |= (1 << (bitnr - 16));
624 else
625 reg &= ~(1 << (bitnr - 16));
626 w83781d_write_value(data, W83781D_REG_BEEP_INTS3, reg);
627 }
628 mutex_unlock(&data->update_lock);
629
630 return count;
631}
632
633/* The W83781D has a single beep bit for temp2 and temp3 */
634static ssize_t show_temp3_beep(struct device *dev,
635 struct device_attribute *attr, char *buf)
636{
637 struct w83781d_data *data = w83781d_update_device(dev);
638 int bitnr = (data->type == w83781d) ? 5 : 13;
639 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
640}
641
642static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
643 show_beep, store_beep, 0);
644static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR,
645 show_beep, store_beep, 1);
646static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR,
647 show_beep, store_beep, 2);
648static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR,
649 show_beep, store_beep, 3);
650static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR,
651 show_beep, store_beep, 8);
652static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO | S_IWUSR,
653 show_beep, store_beep, 9);
654static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO | S_IWUSR,
655 show_beep, store_beep, 10);
656static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO | S_IWUSR,
657 show_beep, store_beep, 16);
658static SENSOR_DEVICE_ATTR(in8_beep, S_IRUGO | S_IWUSR,
659 show_beep, store_beep, 17);
660static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR,
661 show_beep, store_beep, 6);
662static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR,
663 show_beep, store_beep, 7);
664static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO | S_IWUSR,
665 show_beep, store_beep, 11);
666static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
667 show_beep, store_beep, 4);
668static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR,
669 show_beep, store_beep, 5);
670static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO,
671 show_temp3_beep, store_beep, 13);
672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200674show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
Jean Delvare34875332007-05-08 17:22:03 +0200676 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 struct w83781d_data *data = w83781d_update_device(dev);
678 return sprintf(buf, "%ld\n",
Jean Delvare34875332007-05-08 17:22:03 +0200679 (long) DIV_FROM_REG(data->fan_div[attr->index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
681
682/* Note: we save and restore the fan minimum here, because its value is
683 determined in part by the fan divisor. This follows the principle of
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200684 least surprise; the user doesn't expect the fan minimum to change just
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 because the divisor changed. */
686static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200687store_fan_div(struct device *dev, struct device_attribute *da,
688 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689{
Jean Delvare34875332007-05-08 17:22:03 +0200690 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Jean Delvare7666c132007-05-08 17:22:02 +0200691 struct w83781d_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 unsigned long min;
Jean Delvare34875332007-05-08 17:22:03 +0200693 int nr = attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 u8 reg;
695 unsigned long val = simple_strtoul(buf, NULL, 10);
696
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100697 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 /* Save fan_min */
700 min = FAN_FROM_REG(data->fan_min[nr],
701 DIV_FROM_REG(data->fan_div[nr]));
702
703 data->fan_div[nr] = DIV_TO_REG(val, data->type);
704
Jean Delvare31b8dc42007-05-08 17:22:03 +0200705 reg = (w83781d_read_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 & (nr==0 ? 0xcf : 0x3f))
707 | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6));
Jean Delvare31b8dc42007-05-08 17:22:03 +0200708 w83781d_write_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710 /* w83781d and as99127f don't have extended divisor bits */
711 if (data->type != w83781d && data->type != as99127f) {
Jean Delvare31b8dc42007-05-08 17:22:03 +0200712 reg = (w83781d_read_value(data, W83781D_REG_VBAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 & ~(1 << (5 + nr)))
714 | ((data->fan_div[nr] & 0x04) << (3 + nr));
Jean Delvare31b8dc42007-05-08 17:22:03 +0200715 w83781d_write_value(data, W83781D_REG_VBAT, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 }
717
718 /* Restore fan_min */
719 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvare34875332007-05-08 17:22:03 +0200720 w83781d_write_value(data, W83781D_REG_FAN_MIN(nr), data->fan_min[nr]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100722 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 return count;
724}
725
Jean Delvare34875332007-05-08 17:22:03 +0200726static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
727 show_fan_div, store_fan_div, 0);
728static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
729 show_fan_div, store_fan_div, 1);
730static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR,
731 show_fan_div, store_fan_div, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200734show_pwm(struct device *dev, struct device_attribute *da, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Jean Delvare34875332007-05-08 17:22:03 +0200736 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 struct w83781d_data *data = w83781d_update_device(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200738 return sprintf(buf, "%d\n", (int)data->pwm[attr->index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739}
740
741static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200742show_pwm2_enable(struct device *dev, struct device_attribute *da, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743{
744 struct w83781d_data *data = w83781d_update_device(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200745 return sprintf(buf, "%d\n", (int)data->pwm2_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746}
747
748static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200749store_pwm(struct device *dev, struct device_attribute *da, const char *buf,
750 size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
Jean Delvare34875332007-05-08 17:22:03 +0200752 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Jean Delvare7666c132007-05-08 17:22:02 +0200753 struct w83781d_data *data = dev_get_drvdata(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200754 int nr = attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 u32 val;
756
757 val = simple_strtoul(buf, NULL, 10);
758
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100759 mutex_lock(&data->update_lock);
Jean Delvare34875332007-05-08 17:22:03 +0200760 data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
761 w83781d_write_value(data, W83781D_REG_PWM[nr], data->pwm[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100762 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 return count;
764}
765
766static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200767store_pwm2_enable(struct device *dev, struct device_attribute *da,
768 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
Jean Delvare7666c132007-05-08 17:22:02 +0200770 struct w83781d_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 u32 val, reg;
772
773 val = simple_strtoul(buf, NULL, 10);
774
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100775 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777 switch (val) {
778 case 0:
779 case 1:
Jean Delvare31b8dc42007-05-08 17:22:03 +0200780 reg = w83781d_read_value(data, W83781D_REG_PWMCLK12);
781 w83781d_write_value(data, W83781D_REG_PWMCLK12,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 (reg & 0xf7) | (val << 3));
783
Jean Delvare31b8dc42007-05-08 17:22:03 +0200784 reg = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
785 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 (reg & 0xef) | (!val << 4));
787
Jean Delvare34875332007-05-08 17:22:03 +0200788 data->pwm2_enable = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 break;
790
791 default:
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100792 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 return -EINVAL;
794 }
795
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100796 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 return count;
798}
799
Jean Delvare34875332007-05-08 17:22:03 +0200800static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0);
801static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 1);
802static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 2);
803static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 3);
804/* only PWM2 can be enabled/disabled */
805static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
806 show_pwm2_enable, store_pwm2_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200809show_sensor(struct device *dev, struct device_attribute *da, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Jean Delvare34875332007-05-08 17:22:03 +0200811 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 struct w83781d_data *data = w83781d_update_device(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200813 return sprintf(buf, "%d\n", (int)data->sens[attr->index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814}
815
816static ssize_t
Jean Delvare34875332007-05-08 17:22:03 +0200817store_sensor(struct device *dev, struct device_attribute *da,
818 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819{
Jean Delvare34875332007-05-08 17:22:03 +0200820 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
Jean Delvare7666c132007-05-08 17:22:02 +0200821 struct w83781d_data *data = dev_get_drvdata(dev);
Jean Delvare34875332007-05-08 17:22:03 +0200822 int nr = attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 u32 val, tmp;
824
825 val = simple_strtoul(buf, NULL, 10);
826
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100827 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 switch (val) {
830 case 1: /* PII/Celeron diode */
Jean Delvare31b8dc42007-05-08 17:22:03 +0200831 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
832 w83781d_write_value(data, W83781D_REG_SCFG1,
Jean Delvare34875332007-05-08 17:22:03 +0200833 tmp | BIT_SCFG1[nr]);
Jean Delvare31b8dc42007-05-08 17:22:03 +0200834 tmp = w83781d_read_value(data, W83781D_REG_SCFG2);
835 w83781d_write_value(data, W83781D_REG_SCFG2,
Jean Delvare34875332007-05-08 17:22:03 +0200836 tmp | BIT_SCFG2[nr]);
837 data->sens[nr] = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 break;
839 case 2: /* 3904 */
Jean Delvare31b8dc42007-05-08 17:22:03 +0200840 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
841 w83781d_write_value(data, W83781D_REG_SCFG1,
Jean Delvare34875332007-05-08 17:22:03 +0200842 tmp | BIT_SCFG1[nr]);
Jean Delvare31b8dc42007-05-08 17:22:03 +0200843 tmp = w83781d_read_value(data, W83781D_REG_SCFG2);
844 w83781d_write_value(data, W83781D_REG_SCFG2,
Jean Delvare34875332007-05-08 17:22:03 +0200845 tmp & ~BIT_SCFG2[nr]);
846 data->sens[nr] = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 break;
Jean Delvareb26f9332007-08-16 14:30:01 +0200848 case W83781D_DEFAULT_BETA:
849 dev_warn(dev, "Sensor type %d is deprecated, please use 4 "
850 "instead\n", W83781D_DEFAULT_BETA);
851 /* fall through */
852 case 4: /* thermistor */
Jean Delvare31b8dc42007-05-08 17:22:03 +0200853 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
854 w83781d_write_value(data, W83781D_REG_SCFG1,
Jean Delvare34875332007-05-08 17:22:03 +0200855 tmp & ~BIT_SCFG1[nr]);
856 data->sens[nr] = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 break;
858 default:
Jean Delvareb26f9332007-08-16 14:30:01 +0200859 dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or 4\n",
860 (long) val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 break;
862 }
863
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100864 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 return count;
866}
867
Jean Delvare34875332007-05-08 17:22:03 +0200868static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
869 show_sensor, store_sensor, 0);
870static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
Mark M. Hoffman393cdad2007-08-09 08:12:46 -0400871 show_sensor, store_sensor, 1);
Jean Delvare34875332007-05-08 17:22:03 +0200872static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
Mark M. Hoffman393cdad2007-08-09 08:12:46 -0400873 show_sensor, store_sensor, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Jean Delvare7666c132007-05-08 17:22:02 +0200875/* I2C devices get this name attribute automatically, but for ISA devices
876 we must create it by ourselves. */
877static ssize_t
878show_name(struct device *dev, struct device_attribute *devattr, char *buf)
879{
880 struct w83781d_data *data = dev_get_drvdata(dev);
881 return sprintf(buf, "%s\n", data->client.name);
882}
883static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885/* This function is called when:
886 * w83781d_driver is inserted (when this module is loaded), for each
887 available adapter
888 * when a new adapter is inserted (and w83781d_driver is still present) */
889static int
890w83781d_attach_adapter(struct i2c_adapter *adapter)
891{
892 if (!(adapter->class & I2C_CLASS_HWMON))
893 return 0;
Jean Delvare2ed2dc32005-07-31 21:42:02 +0200894 return i2c_probe(adapter, &addr_data, w83781d_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895}
896
897/* Assumes that adapter is of I2C, not ISA variety.
898 * OTHERWISE DON'T CALL THIS
899 */
900static int
901w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
902 struct i2c_client *new_client)
903{
904 int i, val1 = 0, id;
905 int err;
906 const char *client_name = "";
907 struct w83781d_data *data = i2c_get_clientdata(new_client);
908
Deepak Saxenaba9c2e82005-10-17 23:08:32 +0200909 data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 if (!(data->lm75[0])) {
911 err = -ENOMEM;
912 goto ERROR_SC_0;
913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 id = i2c_adapter_id(adapter);
916
917 if (force_subclients[0] == id && force_subclients[1] == address) {
918 for (i = 2; i <= 3; i++) {
919 if (force_subclients[i] < 0x48 ||
920 force_subclients[i] > 0x4f) {
921 dev_err(&new_client->dev, "Invalid subclient "
922 "address %d; must be 0x48-0x4f\n",
923 force_subclients[i]);
924 err = -EINVAL;
925 goto ERROR_SC_1;
926 }
927 }
Jean Delvare31b8dc42007-05-08 17:22:03 +0200928 w83781d_write_value(data, W83781D_REG_I2C_SUBADDR,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 (force_subclients[2] & 0x07) |
930 ((force_subclients[3] & 0x07) << 4));
931 data->lm75[0]->addr = force_subclients[2];
932 } else {
Jean Delvare31b8dc42007-05-08 17:22:03 +0200933 val1 = w83781d_read_value(data, W83781D_REG_I2C_SUBADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 data->lm75[0]->addr = 0x48 + (val1 & 0x07);
935 }
936
937 if (kind != w83783s) {
Deepak Saxenaba9c2e82005-10-17 23:08:32 +0200938 data->lm75[1] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 if (!(data->lm75[1])) {
940 err = -ENOMEM;
941 goto ERROR_SC_1;
942 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
944 if (force_subclients[0] == id &&
945 force_subclients[1] == address) {
946 data->lm75[1]->addr = force_subclients[3];
947 } else {
948 data->lm75[1]->addr = 0x48 + ((val1 >> 4) & 0x07);
949 }
950 if (data->lm75[0]->addr == data->lm75[1]->addr) {
951 dev_err(&new_client->dev,
952 "Duplicate addresses 0x%x for subclients.\n",
953 data->lm75[0]->addr);
954 err = -EBUSY;
955 goto ERROR_SC_2;
956 }
957 }
958
959 if (kind == w83781d)
960 client_name = "w83781d subclient";
961 else if (kind == w83782d)
962 client_name = "w83782d subclient";
963 else if (kind == w83783s)
964 client_name = "w83783s subclient";
965 else if (kind == w83627hf)
966 client_name = "w83627hf subclient";
967 else if (kind == as99127f)
968 client_name = "as99127f subclient";
969
970 for (i = 0; i <= 1; i++) {
971 /* store all data in w83781d */
972 i2c_set_clientdata(data->lm75[i], NULL);
973 data->lm75[i]->adapter = adapter;
974 data->lm75[i]->driver = &w83781d_driver;
975 data->lm75[i]->flags = 0;
976 strlcpy(data->lm75[i]->name, client_name,
977 I2C_NAME_SIZE);
978 if ((err = i2c_attach_client(data->lm75[i]))) {
979 dev_err(&new_client->dev, "Subclient %d "
980 "registration at address 0x%x "
981 "failed.\n", i, data->lm75[i]->addr);
982 if (i == 1)
983 goto ERROR_SC_3;
984 goto ERROR_SC_2;
985 }
986 if (kind == w83783s)
987 break;
988 }
989
990 return 0;
991
992/* Undo inits in case of errors */
993ERROR_SC_3:
994 i2c_detach_client(data->lm75[0]);
995ERROR_SC_2:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800996 kfree(data->lm75[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997ERROR_SC_1:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800998 kfree(data->lm75[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999ERROR_SC_0:
1000 return err;
1001}
1002
Jean Delvare34875332007-05-08 17:22:03 +02001003#define IN_UNIT_ATTRS(X) \
1004 &sensor_dev_attr_in##X##_input.dev_attr.attr, \
1005 &sensor_dev_attr_in##X##_min.dev_attr.attr, \
Jean Delvare7d4a1372007-10-08 18:29:43 +02001006 &sensor_dev_attr_in##X##_max.dev_attr.attr, \
1007 &sensor_dev_attr_in##X##_alarm.dev_attr.attr, \
1008 &sensor_dev_attr_in##X##_beep.dev_attr.attr
Jim Cromie311ce2e2006-09-24 21:22:52 +02001009
Jean Delvare34875332007-05-08 17:22:03 +02001010#define FAN_UNIT_ATTRS(X) \
1011 &sensor_dev_attr_fan##X##_input.dev_attr.attr, \
1012 &sensor_dev_attr_fan##X##_min.dev_attr.attr, \
Jean Delvare7d4a1372007-10-08 18:29:43 +02001013 &sensor_dev_attr_fan##X##_div.dev_attr.attr, \
1014 &sensor_dev_attr_fan##X##_alarm.dev_attr.attr, \
1015 &sensor_dev_attr_fan##X##_beep.dev_attr.attr
Jim Cromie311ce2e2006-09-24 21:22:52 +02001016
Jean Delvare34875332007-05-08 17:22:03 +02001017#define TEMP_UNIT_ATTRS(X) \
1018 &sensor_dev_attr_temp##X##_input.dev_attr.attr, \
1019 &sensor_dev_attr_temp##X##_max.dev_attr.attr, \
Jean Delvare7d4a1372007-10-08 18:29:43 +02001020 &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr, \
1021 &sensor_dev_attr_temp##X##_alarm.dev_attr.attr, \
1022 &sensor_dev_attr_temp##X##_beep.dev_attr.attr
Jim Cromie311ce2e2006-09-24 21:22:52 +02001023
1024static struct attribute* w83781d_attributes[] = {
1025 IN_UNIT_ATTRS(0),
1026 IN_UNIT_ATTRS(2),
1027 IN_UNIT_ATTRS(3),
1028 IN_UNIT_ATTRS(4),
1029 IN_UNIT_ATTRS(5),
1030 IN_UNIT_ATTRS(6),
1031 FAN_UNIT_ATTRS(1),
1032 FAN_UNIT_ATTRS(2),
1033 FAN_UNIT_ATTRS(3),
1034 TEMP_UNIT_ATTRS(1),
1035 TEMP_UNIT_ATTRS(2),
1036 &dev_attr_cpu0_vid.attr,
1037 &dev_attr_vrm.attr,
1038 &dev_attr_alarms.attr,
1039 &dev_attr_beep_mask.attr,
1040 &dev_attr_beep_enable.attr,
1041 NULL
1042};
1043static const struct attribute_group w83781d_group = {
1044 .attrs = w83781d_attributes,
1045};
1046
1047static struct attribute *w83781d_attributes_opt[] = {
1048 IN_UNIT_ATTRS(1),
1049 IN_UNIT_ATTRS(7),
1050 IN_UNIT_ATTRS(8),
1051 TEMP_UNIT_ATTRS(3),
Jean Delvare34875332007-05-08 17:22:03 +02001052 &sensor_dev_attr_pwm1.dev_attr.attr,
1053 &sensor_dev_attr_pwm2.dev_attr.attr,
1054 &sensor_dev_attr_pwm3.dev_attr.attr,
1055 &sensor_dev_attr_pwm4.dev_attr.attr,
Jim Cromie311ce2e2006-09-24 21:22:52 +02001056 &dev_attr_pwm2_enable.attr,
Jean Delvare34875332007-05-08 17:22:03 +02001057 &sensor_dev_attr_temp1_type.dev_attr.attr,
1058 &sensor_dev_attr_temp2_type.dev_attr.attr,
1059 &sensor_dev_attr_temp3_type.dev_attr.attr,
Jim Cromie311ce2e2006-09-24 21:22:52 +02001060 NULL
1061};
1062static const struct attribute_group w83781d_group_opt = {
1063 .attrs = w83781d_attributes_opt,
1064};
1065
Jean Delvare7666c132007-05-08 17:22:02 +02001066/* No clean up is done on error, it's up to the caller */
1067static int
1068w83781d_create_files(struct device *dev, int kind, int is_isa)
1069{
1070 int err;
1071
1072 if ((err = sysfs_create_group(&dev->kobj, &w83781d_group)))
1073 return err;
1074
1075 if (kind != w83783s) {
Jean Delvare34875332007-05-08 17:22:03 +02001076 if ((err = device_create_file(dev,
1077 &sensor_dev_attr_in1_input.dev_attr))
1078 || (err = device_create_file(dev,
1079 &sensor_dev_attr_in1_min.dev_attr))
1080 || (err = device_create_file(dev,
Jean Delvare7d4a1372007-10-08 18:29:43 +02001081 &sensor_dev_attr_in1_max.dev_attr))
1082 || (err = device_create_file(dev,
1083 &sensor_dev_attr_in1_alarm.dev_attr))
1084 || (err = device_create_file(dev,
1085 &sensor_dev_attr_in1_beep.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001086 return err;
1087 }
1088 if (kind != as99127f && kind != w83781d && kind != w83783s) {
Jean Delvare34875332007-05-08 17:22:03 +02001089 if ((err = device_create_file(dev,
1090 &sensor_dev_attr_in7_input.dev_attr))
1091 || (err = device_create_file(dev,
1092 &sensor_dev_attr_in7_min.dev_attr))
1093 || (err = device_create_file(dev,
1094 &sensor_dev_attr_in7_max.dev_attr))
1095 || (err = device_create_file(dev,
Jean Delvare7d4a1372007-10-08 18:29:43 +02001096 &sensor_dev_attr_in7_alarm.dev_attr))
1097 || (err = device_create_file(dev,
1098 &sensor_dev_attr_in7_beep.dev_attr))
1099 || (err = device_create_file(dev,
Jean Delvare34875332007-05-08 17:22:03 +02001100 &sensor_dev_attr_in8_input.dev_attr))
1101 || (err = device_create_file(dev,
1102 &sensor_dev_attr_in8_min.dev_attr))
1103 || (err = device_create_file(dev,
Jean Delvare7d4a1372007-10-08 18:29:43 +02001104 &sensor_dev_attr_in8_max.dev_attr))
1105 || (err = device_create_file(dev,
1106 &sensor_dev_attr_in8_alarm.dev_attr))
1107 || (err = device_create_file(dev,
1108 &sensor_dev_attr_in8_beep.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001109 return err;
1110 }
1111 if (kind != w83783s) {
Jean Delvare34875332007-05-08 17:22:03 +02001112 if ((err = device_create_file(dev,
1113 &sensor_dev_attr_temp3_input.dev_attr))
Jean Delvare7666c132007-05-08 17:22:02 +02001114 || (err = device_create_file(dev,
Jean Delvare34875332007-05-08 17:22:03 +02001115 &sensor_dev_attr_temp3_max.dev_attr))
1116 || (err = device_create_file(dev,
Jean Delvare7d4a1372007-10-08 18:29:43 +02001117 &sensor_dev_attr_temp3_max_hyst.dev_attr))
1118 || (err = device_create_file(dev,
1119 &sensor_dev_attr_temp3_alarm.dev_attr))
1120 || (err = device_create_file(dev,
1121 &sensor_dev_attr_temp3_beep.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001122 return err;
Jean Delvare7d4a1372007-10-08 18:29:43 +02001123
Jean Delvare7768aa72007-10-25 13:11:01 +02001124 if (kind != w83781d) {
Jean Delvare7d4a1372007-10-08 18:29:43 +02001125 err = sysfs_chmod_file(&dev->kobj,
1126 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1127 S_IRUGO | S_IWUSR);
1128 if (err)
1129 return err;
Jean Delvare7768aa72007-10-25 13:11:01 +02001130 }
Jean Delvare7666c132007-05-08 17:22:02 +02001131 }
1132
1133 if (kind != w83781d && kind != as99127f) {
Jean Delvare34875332007-05-08 17:22:03 +02001134 if ((err = device_create_file(dev,
1135 &sensor_dev_attr_pwm1.dev_attr))
1136 || (err = device_create_file(dev,
1137 &sensor_dev_attr_pwm2.dev_attr))
Jean Delvare7666c132007-05-08 17:22:02 +02001138 || (err = device_create_file(dev, &dev_attr_pwm2_enable)))
1139 return err;
1140 }
1141 if (kind == w83782d && !is_isa) {
Jean Delvare34875332007-05-08 17:22:03 +02001142 if ((err = device_create_file(dev,
1143 &sensor_dev_attr_pwm3.dev_attr))
1144 || (err = device_create_file(dev,
1145 &sensor_dev_attr_pwm4.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001146 return err;
1147 }
1148
1149 if (kind != as99127f && kind != w83781d) {
Jean Delvare34875332007-05-08 17:22:03 +02001150 if ((err = device_create_file(dev,
1151 &sensor_dev_attr_temp1_type.dev_attr))
Jean Delvare7666c132007-05-08 17:22:02 +02001152 || (err = device_create_file(dev,
Jean Delvare34875332007-05-08 17:22:03 +02001153 &sensor_dev_attr_temp2_type.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001154 return err;
1155 if (kind != w83783s) {
1156 if ((err = device_create_file(dev,
Jean Delvare34875332007-05-08 17:22:03 +02001157 &sensor_dev_attr_temp3_type.dev_attr)))
Jean Delvare7666c132007-05-08 17:22:02 +02001158 return err;
1159 }
1160 }
1161
1162 if (is_isa) {
1163 err = device_create_file(&pdev->dev, &dev_attr_name);
1164 if (err)
1165 return err;
1166 }
1167
1168 return 0;
1169}
1170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171static int
1172w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1173{
Jean Delvare7666c132007-05-08 17:22:02 +02001174 int val1 = 0, val2;
Jim Cromie311ce2e2006-09-24 21:22:52 +02001175 struct i2c_client *client;
1176 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 struct w83781d_data *data;
1178 int err;
1179 const char *client_name = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 enum vendor { winbond, asus } vendid;
1181
Jean Delvare7666c132007-05-08 17:22:02 +02001182 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 err = -EINVAL;
Jean Delvare7666c132007-05-08 17:22:02 +02001184 goto ERROR1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 }
1186
1187 /* OK. For now, we presume we have a valid client. We now create the
1188 client structure, even though we cannot fill it completely yet.
1189 But it allows us to access w83781d_{read,write}_value. */
1190
Deepak Saxenaba9c2e82005-10-17 23:08:32 +02001191 if (!(data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 err = -ENOMEM;
1193 goto ERROR1;
1194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Jim Cromie311ce2e2006-09-24 21:22:52 +02001196 client = &data->client;
1197 i2c_set_clientdata(client, data);
1198 client->addr = address;
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001199 mutex_init(&data->lock);
Jim Cromie311ce2e2006-09-24 21:22:52 +02001200 client->adapter = adapter;
Jean Delvare7666c132007-05-08 17:22:02 +02001201 client->driver = &w83781d_driver;
Jim Cromie311ce2e2006-09-24 21:22:52 +02001202 dev = &client->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
1204 /* Now, we do the remaining detection. */
1205
1206 /* The w8378?d may be stuck in some other bank than bank 0. This may
1207 make reading other information impossible. Specify a force=... or
1208 force_*=... parameter, and the Winbond will be reset to the right
1209 bank. */
1210 if (kind < 0) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001211 if (w83781d_read_value(data, W83781D_REG_CONFIG) & 0x80) {
Jean Delvarebd452e62006-10-13 17:03:42 +02001212 dev_dbg(&adapter->dev, "Detection of w83781d chip "
1213 "failed at step 3\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 err = -ENODEV;
1215 goto ERROR2;
1216 }
Jean Delvare31b8dc42007-05-08 17:22:03 +02001217 val1 = w83781d_read_value(data, W83781D_REG_BANK);
1218 val2 = w83781d_read_value(data, W83781D_REG_CHIPMAN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 /* Check for Winbond or Asus ID if in bank 0 */
1220 if ((!(val1 & 0x07)) &&
1221 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3))
1222 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) {
Jean Delvarebd452e62006-10-13 17:03:42 +02001223 dev_dbg(&adapter->dev, "Detection of w83781d chip "
1224 "failed at step 4\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 err = -ENODEV;
1226 goto ERROR2;
1227 }
1228 /* If Winbond SMBus, check address at 0x48.
1229 Asus doesn't support, except for as99127f rev.2 */
Jean Delvare7666c132007-05-08 17:22:02 +02001230 if ((!(val1 & 0x80) && (val2 == 0xa3)) ||
1231 ((val1 & 0x80) && (val2 == 0x5c))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 if (w83781d_read_value
Jean Delvare31b8dc42007-05-08 17:22:03 +02001233 (data, W83781D_REG_I2C_ADDR) != address) {
Jean Delvarebd452e62006-10-13 17:03:42 +02001234 dev_dbg(&adapter->dev, "Detection of w83781d "
1235 "chip failed at step 5\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 err = -ENODEV;
1237 goto ERROR2;
1238 }
1239 }
1240 }
1241
1242 /* We have either had a force parameter, or we have already detected the
1243 Winbond. Put it now into bank 0 and Vendor ID High Byte */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001244 w83781d_write_value(data, W83781D_REG_BANK,
1245 (w83781d_read_value(data, W83781D_REG_BANK)
Jim Cromie311ce2e2006-09-24 21:22:52 +02001246 & 0x78) | 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
1248 /* Determine the chip type. */
1249 if (kind <= 0) {
1250 /* get vendor ID */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001251 val2 = w83781d_read_value(data, W83781D_REG_CHIPMAN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 if (val2 == 0x5c)
1253 vendid = winbond;
1254 else if (val2 == 0x12)
1255 vendid = asus;
1256 else {
Jean Delvarebd452e62006-10-13 17:03:42 +02001257 dev_dbg(&adapter->dev, "w83781d chip vendor is "
1258 "neither Winbond nor Asus\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 err = -ENODEV;
1260 goto ERROR2;
1261 }
1262
Jean Delvare31b8dc42007-05-08 17:22:03 +02001263 val1 = w83781d_read_value(data, W83781D_REG_WCHIPID);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)
1265 kind = w83781d;
1266 else if (val1 == 0x30 && vendid == winbond)
1267 kind = w83782d;
Jean Delvare7666c132007-05-08 17:22:02 +02001268 else if (val1 == 0x40 && vendid == winbond && address == 0x2d)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 kind = w83783s;
Jean Delvare7c7a5302005-06-16 19:24:14 +02001270 else if (val1 == 0x21 && vendid == winbond)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 kind = w83627hf;
Jean Delvare6722fea2007-10-07 12:25:46 +02001272 else if (val1 == 0x31)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 kind = as99127f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 else {
1275 if (kind == 0)
Jean Delvarebd452e62006-10-13 17:03:42 +02001276 dev_warn(&adapter->dev, "Ignoring 'force' "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 "parameter for unknown chip at "
Jean Delvarebd452e62006-10-13 17:03:42 +02001278 "address 0x%02x\n", address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 err = -EINVAL;
1280 goto ERROR2;
1281 }
1282 }
1283
1284 if (kind == w83781d) {
1285 client_name = "w83781d";
1286 } else if (kind == w83782d) {
1287 client_name = "w83782d";
1288 } else if (kind == w83783s) {
1289 client_name = "w83783s";
1290 } else if (kind == w83627hf) {
Jean Delvare7c7a5302005-06-16 19:24:14 +02001291 client_name = "w83627hf";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 } else if (kind == as99127f) {
1293 client_name = "as99127f";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 }
1295
1296 /* Fill in the remaining client fields and put into the global list */
Jim Cromie311ce2e2006-09-24 21:22:52 +02001297 strlcpy(client->name, client_name, I2C_NAME_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 data->type = kind;
1299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 /* Tell the I2C layer a new client has arrived */
Jim Cromie311ce2e2006-09-24 21:22:52 +02001301 if ((err = i2c_attach_client(client)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 goto ERROR2;
1303
1304 /* attach secondary i2c lm75-like clients */
Jean Delvare7666c132007-05-08 17:22:02 +02001305 if ((err = w83781d_detect_subclients(adapter, address,
1306 kind, client)))
1307 goto ERROR3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
1309 /* Initialize the chip */
Jean Delvare7666c132007-05-08 17:22:02 +02001310 w83781d_init_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
1312 /* Register sysfs hooks */
Jean Delvare7666c132007-05-08 17:22:02 +02001313 err = w83781d_create_files(dev, kind, 0);
1314 if (err)
Jim Cromie311ce2e2006-09-24 21:22:52 +02001315 goto ERROR4;
1316
Tony Jones1beeffe2007-08-20 13:46:20 -07001317 data->hwmon_dev = hwmon_device_register(dev);
1318 if (IS_ERR(data->hwmon_dev)) {
1319 err = PTR_ERR(data->hwmon_dev);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001320 goto ERROR4;
1321 }
1322
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 return 0;
1324
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001325ERROR4:
Jim Cromie311ce2e2006-09-24 21:22:52 +02001326 sysfs_remove_group(&dev->kobj, &w83781d_group);
1327 sysfs_remove_group(&dev->kobj, &w83781d_group_opt);
1328
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001329 if (data->lm75[1]) {
1330 i2c_detach_client(data->lm75[1]);
1331 kfree(data->lm75[1]);
1332 }
1333 if (data->lm75[0]) {
1334 i2c_detach_client(data->lm75[0]);
1335 kfree(data->lm75[0]);
1336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337ERROR3:
Jim Cromie311ce2e2006-09-24 21:22:52 +02001338 i2c_detach_client(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339ERROR2:
1340 kfree(data);
1341ERROR1:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 return err;
1343}
1344
1345static int
1346w83781d_detach_client(struct i2c_client *client)
1347{
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001348 struct w83781d_data *data = i2c_get_clientdata(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 int err;
1350
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001351 /* main client */
Jim Cromie311ce2e2006-09-24 21:22:52 +02001352 if (data) {
Tony Jones1beeffe2007-08-20 13:46:20 -07001353 hwmon_device_unregister(data->hwmon_dev);
Jim Cromie311ce2e2006-09-24 21:22:52 +02001354 sysfs_remove_group(&client->dev.kobj, &w83781d_group);
1355 sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt);
1356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Jean Delvare7bef5592005-07-27 22:14:49 +02001358 if ((err = i2c_detach_client(client)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001361 /* main client */
1362 if (data)
1363 kfree(data);
1364
1365 /* subclient */
1366 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 kfree(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369 return 0;
1370}
1371
Jean Delvare7666c132007-05-08 17:22:02 +02001372static int __devinit
1373w83781d_isa_probe(struct platform_device *pdev)
1374{
1375 int err, reg;
1376 struct w83781d_data *data;
1377 struct resource *res;
1378 const char *name;
1379
1380 /* Reserve the ISA region */
1381 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1382 if (!request_region(res->start, W83781D_EXTENT, "w83781d")) {
1383 err = -EBUSY;
1384 goto exit;
1385 }
1386
1387 if (!(data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
1388 err = -ENOMEM;
1389 goto exit_release_region;
1390 }
1391 mutex_init(&data->lock);
1392 data->client.addr = res->start;
1393 i2c_set_clientdata(&data->client, data);
1394 platform_set_drvdata(pdev, data);
1395
Jean Delvare31b8dc42007-05-08 17:22:03 +02001396 reg = w83781d_read_value(data, W83781D_REG_WCHIPID);
Jean Delvare7666c132007-05-08 17:22:02 +02001397 switch (reg) {
1398 case 0x21:
1399 data->type = w83627hf;
1400 name = "w83627hf";
1401 break;
1402 case 0x30:
1403 data->type = w83782d;
1404 name = "w83782d";
1405 break;
1406 default:
1407 data->type = w83781d;
1408 name = "w83781d";
1409 }
1410 strlcpy(data->client.name, name, I2C_NAME_SIZE);
1411
1412 /* Initialize the W83781D chip */
1413 w83781d_init_device(&pdev->dev);
1414
1415 /* Register sysfs hooks */
1416 err = w83781d_create_files(&pdev->dev, data->type, 1);
1417 if (err)
1418 goto exit_remove_files;
1419
Tony Jones1beeffe2007-08-20 13:46:20 -07001420 data->hwmon_dev = hwmon_device_register(&pdev->dev);
1421 if (IS_ERR(data->hwmon_dev)) {
1422 err = PTR_ERR(data->hwmon_dev);
Jean Delvare7666c132007-05-08 17:22:02 +02001423 goto exit_remove_files;
1424 }
1425
1426 return 0;
1427
1428 exit_remove_files:
1429 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
1430 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1431 device_remove_file(&pdev->dev, &dev_attr_name);
1432 kfree(data);
1433 exit_release_region:
1434 release_region(res->start, W83781D_EXTENT);
1435 exit:
1436 return err;
1437}
1438
1439static int __devexit
1440w83781d_isa_remove(struct platform_device *pdev)
1441{
1442 struct w83781d_data *data = platform_get_drvdata(pdev);
1443
Tony Jones1beeffe2007-08-20 13:46:20 -07001444 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare7666c132007-05-08 17:22:02 +02001445 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
1446 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1447 device_remove_file(&pdev->dev, &dev_attr_name);
1448 release_region(data->client.addr, W83781D_EXTENT);
1449 kfree(data);
1450
1451 return 0;
1452}
1453
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454/* The SMBus locks itself, usually, but nothing may access the Winbond between
1455 bank switches. ISA access must always be locked explicitly!
1456 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1457 would slow down the W83781D access and should not be necessary.
1458 There are some ugly typecasts here, but the good news is - they should
1459 nowhere else be necessary! */
1460static int
Jean Delvare31b8dc42007-05-08 17:22:03 +02001461w83781d_read_value(struct w83781d_data *data, u16 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
Jean Delvare31b8dc42007-05-08 17:22:03 +02001463 struct i2c_client *client = &data->client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 int res, word_sized, bank;
1465 struct i2c_client *cl;
1466
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001467 mutex_lock(&data->lock);
Jean Delvare7666c132007-05-08 17:22:02 +02001468 if (!client->driver) { /* ISA device */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 word_sized = (((reg & 0xff00) == 0x100)
1470 || ((reg & 0xff00) == 0x200))
1471 && (((reg & 0x00ff) == 0x50)
1472 || ((reg & 0x00ff) == 0x53)
1473 || ((reg & 0x00ff) == 0x55));
1474 if (reg & 0xff00) {
1475 outb_p(W83781D_REG_BANK,
1476 client->addr + W83781D_ADDR_REG_OFFSET);
1477 outb_p(reg >> 8,
1478 client->addr + W83781D_DATA_REG_OFFSET);
1479 }
1480 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET);
1481 res = inb_p(client->addr + W83781D_DATA_REG_OFFSET);
1482 if (word_sized) {
1483 outb_p((reg & 0xff) + 1,
1484 client->addr + W83781D_ADDR_REG_OFFSET);
1485 res =
1486 (res << 8) + inb_p(client->addr +
1487 W83781D_DATA_REG_OFFSET);
1488 }
1489 if (reg & 0xff00) {
1490 outb_p(W83781D_REG_BANK,
1491 client->addr + W83781D_ADDR_REG_OFFSET);
1492 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1493 }
1494 } else {
1495 bank = (reg >> 8) & 0x0f;
1496 if (bank > 2)
1497 /* switch banks */
1498 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1499 bank);
1500 if (bank == 0 || bank > 2) {
1501 res = i2c_smbus_read_byte_data(client, reg & 0xff);
1502 } else {
1503 /* switch to subclient */
1504 cl = data->lm75[bank - 1];
1505 /* convert from ISA to LM75 I2C addresses */
1506 switch (reg & 0xff) {
1507 case 0x50: /* TEMP */
1508 res = swab16(i2c_smbus_read_word_data(cl, 0));
1509 break;
1510 case 0x52: /* CONFIG */
1511 res = i2c_smbus_read_byte_data(cl, 1);
1512 break;
1513 case 0x53: /* HYST */
1514 res = swab16(i2c_smbus_read_word_data(cl, 2));
1515 break;
1516 case 0x55: /* OVER */
1517 default:
1518 res = swab16(i2c_smbus_read_word_data(cl, 3));
1519 break;
1520 }
1521 }
1522 if (bank > 2)
1523 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1524 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001525 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 return res;
1527}
1528
1529static int
Jean Delvare31b8dc42007-05-08 17:22:03 +02001530w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
Jean Delvare31b8dc42007-05-08 17:22:03 +02001532 struct i2c_client *client = &data->client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 int word_sized, bank;
1534 struct i2c_client *cl;
1535
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001536 mutex_lock(&data->lock);
Jean Delvare7666c132007-05-08 17:22:02 +02001537 if (!client->driver) { /* ISA device */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 word_sized = (((reg & 0xff00) == 0x100)
1539 || ((reg & 0xff00) == 0x200))
1540 && (((reg & 0x00ff) == 0x53)
1541 || ((reg & 0x00ff) == 0x55));
1542 if (reg & 0xff00) {
1543 outb_p(W83781D_REG_BANK,
1544 client->addr + W83781D_ADDR_REG_OFFSET);
1545 outb_p(reg >> 8,
1546 client->addr + W83781D_DATA_REG_OFFSET);
1547 }
1548 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET);
1549 if (word_sized) {
1550 outb_p(value >> 8,
1551 client->addr + W83781D_DATA_REG_OFFSET);
1552 outb_p((reg & 0xff) + 1,
1553 client->addr + W83781D_ADDR_REG_OFFSET);
1554 }
1555 outb_p(value & 0xff, client->addr + W83781D_DATA_REG_OFFSET);
1556 if (reg & 0xff00) {
1557 outb_p(W83781D_REG_BANK,
1558 client->addr + W83781D_ADDR_REG_OFFSET);
1559 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1560 }
1561 } else {
1562 bank = (reg >> 8) & 0x0f;
1563 if (bank > 2)
1564 /* switch banks */
1565 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1566 bank);
1567 if (bank == 0 || bank > 2) {
1568 i2c_smbus_write_byte_data(client, reg & 0xff,
1569 value & 0xff);
1570 } else {
1571 /* switch to subclient */
1572 cl = data->lm75[bank - 1];
1573 /* convert from ISA to LM75 I2C addresses */
1574 switch (reg & 0xff) {
1575 case 0x52: /* CONFIG */
1576 i2c_smbus_write_byte_data(cl, 1, value & 0xff);
1577 break;
1578 case 0x53: /* HYST */
1579 i2c_smbus_write_word_data(cl, 2, swab16(value));
1580 break;
1581 case 0x55: /* OVER */
1582 i2c_smbus_write_word_data(cl, 3, swab16(value));
1583 break;
1584 }
1585 }
1586 if (bank > 2)
1587 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1588 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001589 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 return 0;
1591}
1592
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593static void
Jean Delvare7666c132007-05-08 17:22:02 +02001594w83781d_init_device(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595{
Jean Delvare7666c132007-05-08 17:22:02 +02001596 struct w83781d_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 int i, p;
1598 int type = data->type;
1599 u8 tmp;
1600
Jean Delvaref5f8d382007-05-08 17:22:03 +02001601 if (type == w83627hf)
1602 dev_info(dev, "The W83627HF chip is better supported by the "
1603 "w83627hf driver, support will be dropped from the "
1604 "w83781d driver soon\n");
1605
Jean Delvarefabddcd2006-02-05 23:26:51 +01001606 if (reset && type != as99127f) { /* this resets registers we don't have
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 documentation for on the as99127f */
Jean Delvarefabddcd2006-02-05 23:26:51 +01001608 /* Resetting the chip has been the default for a long time,
1609 but it causes the BIOS initializations (fan clock dividers,
1610 thermal sensor types...) to be lost, so it is now optional.
1611 It might even go away if nobody reports it as being useful,
1612 as I see very little reason why this would be needed at
1613 all. */
Jean Delvare7666c132007-05-08 17:22:02 +02001614 dev_info(dev, "If reset=1 solved a problem you were "
Jean Delvarefabddcd2006-02-05 23:26:51 +01001615 "having, please report!\n");
1616
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 /* save these registers */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001618 i = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
1619 p = w83781d_read_value(data, W83781D_REG_PWMCLK12);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 /* Reset all except Watchdog values and last conversion values
1621 This sets fan-divs to 2, among others */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001622 w83781d_write_value(data, W83781D_REG_CONFIG, 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 /* Restore the registers and disable power-on abnormal beep.
1624 This saves FAN 1/2/3 input/output values set by BIOS. */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001625 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80);
1626 w83781d_write_value(data, W83781D_REG_PWMCLK12, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 /* Disable master beep-enable (reset turns it on).
1628 Individual beep_mask should be reset to off but for some reason
1629 disabling this bit helps some people not get beeped */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001630 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 }
1632
Jean Delvarefabddcd2006-02-05 23:26:51 +01001633 /* Disable power-on abnormal beep, as advised by the datasheet.
1634 Already done if reset=1. */
1635 if (init && !reset && type != as99127f) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001636 i = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
1637 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80);
Jean Delvarefabddcd2006-02-05 23:26:51 +01001638 }
1639
Jean Delvare303760b2005-07-31 21:52:01 +02001640 data->vrm = vid_which_vrm();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
1642 if ((type != w83781d) && (type != as99127f)) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001643 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 for (i = 1; i <= 3; i++) {
1645 if (!(tmp & BIT_SCFG1[i - 1])) {
Jean Delvareb26f9332007-08-16 14:30:01 +02001646 data->sens[i - 1] = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 } else {
1648 if (w83781d_read_value
Jean Delvare31b8dc42007-05-08 17:22:03 +02001649 (data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 W83781D_REG_SCFG2) & BIT_SCFG2[i - 1])
1651 data->sens[i - 1] = 1;
1652 else
1653 data->sens[i - 1] = 2;
1654 }
Jean Delvare7c7a5302005-06-16 19:24:14 +02001655 if (type == w83783s && i == 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 break;
1657 }
1658 }
1659
1660 if (init && type != as99127f) {
1661 /* Enable temp2 */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001662 tmp = w83781d_read_value(data, W83781D_REG_TEMP2_CONFIG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 if (tmp & 0x01) {
Jean Delvare7666c132007-05-08 17:22:02 +02001664 dev_warn(dev, "Enabling temp2, readings "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 "might not make sense\n");
Jean Delvare31b8dc42007-05-08 17:22:03 +02001666 w83781d_write_value(data, W83781D_REG_TEMP2_CONFIG,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 tmp & 0xfe);
1668 }
1669
1670 /* Enable temp3 */
Jean Delvare7c7a5302005-06-16 19:24:14 +02001671 if (type != w83783s) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001672 tmp = w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 W83781D_REG_TEMP3_CONFIG);
1674 if (tmp & 0x01) {
Jean Delvare7666c132007-05-08 17:22:02 +02001675 dev_warn(dev, "Enabling temp3, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 "readings might not make sense\n");
Jean Delvare31b8dc42007-05-08 17:22:03 +02001677 w83781d_write_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 W83781D_REG_TEMP3_CONFIG, tmp & 0xfe);
1679 }
1680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 }
1682
1683 /* Start monitoring */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001684 w83781d_write_value(data, W83781D_REG_CONFIG,
1685 (w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 W83781D_REG_CONFIG) & 0xf7)
1687 | 0x01);
Jean Delvare7666c132007-05-08 17:22:02 +02001688
1689 /* A few vars need to be filled upon startup */
Jean Delvare34875332007-05-08 17:22:03 +02001690 for (i = 0; i < 3; i++) {
1691 data->fan_min[i] = w83781d_read_value(data,
Jean Delvare7666c132007-05-08 17:22:02 +02001692 W83781D_REG_FAN_MIN(i));
1693 }
Jean Delvare7666c132007-05-08 17:22:02 +02001694
1695 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696}
1697
1698static struct w83781d_data *w83781d_update_device(struct device *dev)
1699{
Jean Delvare7666c132007-05-08 17:22:02 +02001700 struct w83781d_data *data = dev_get_drvdata(dev);
1701 struct i2c_client *client = &data->client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 int i;
1703
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001704 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
1706 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1707 || !data->valid) {
1708 dev_dbg(dev, "Starting device update\n");
1709
1710 for (i = 0; i <= 8; i++) {
Jean Delvare7c7a5302005-06-16 19:24:14 +02001711 if (data->type == w83783s && i == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 continue; /* 783S has no in1 */
1713 data->in[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001714 w83781d_read_value(data, W83781D_REG_IN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 data->in_min[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001716 w83781d_read_value(data, W83781D_REG_IN_MIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 data->in_max[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001718 w83781d_read_value(data, W83781D_REG_IN_MAX(i));
Jean Delvare7c7a5302005-06-16 19:24:14 +02001719 if ((data->type != w83782d)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 && (data->type != w83627hf) && (i == 6))
1721 break;
1722 }
Jean Delvare34875332007-05-08 17:22:03 +02001723 for (i = 0; i < 3; i++) {
1724 data->fan[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001725 w83781d_read_value(data, W83781D_REG_FAN(i));
Jean Delvare34875332007-05-08 17:22:03 +02001726 data->fan_min[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001727 w83781d_read_value(data, W83781D_REG_FAN_MIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 }
1729 if (data->type != w83781d && data->type != as99127f) {
Jean Delvare34875332007-05-08 17:22:03 +02001730 for (i = 0; i < 4; i++) {
1731 data->pwm[i] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001732 w83781d_read_value(data,
Jean Delvare34875332007-05-08 17:22:03 +02001733 W83781D_REG_PWM[i]);
Jean Delvare7666c132007-05-08 17:22:02 +02001734 if ((data->type != w83782d || !client->driver)
Jean Delvare34875332007-05-08 17:22:03 +02001735 && i == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 break;
1737 }
1738 /* Only PWM2 can be disabled */
Jean Delvare34875332007-05-08 17:22:03 +02001739 data->pwm2_enable = (w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 W83781D_REG_PWMCLK12) & 0x08) >> 3;
1741 }
1742
Jean Delvare31b8dc42007-05-08 17:22:03 +02001743 data->temp = w83781d_read_value(data, W83781D_REG_TEMP(1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 data->temp_max =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001745 w83781d_read_value(data, W83781D_REG_TEMP_OVER(1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 data->temp_max_hyst =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001747 w83781d_read_value(data, W83781D_REG_TEMP_HYST(1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 data->temp_add[0] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001749 w83781d_read_value(data, W83781D_REG_TEMP(2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 data->temp_max_add[0] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001751 w83781d_read_value(data, W83781D_REG_TEMP_OVER(2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 data->temp_max_hyst_add[0] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001753 w83781d_read_value(data, W83781D_REG_TEMP_HYST(2));
Jean Delvare7c7a5302005-06-16 19:24:14 +02001754 if (data->type != w83783s) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 data->temp_add[1] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001756 w83781d_read_value(data, W83781D_REG_TEMP(3));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 data->temp_max_add[1] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001758 w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 W83781D_REG_TEMP_OVER(3));
1760 data->temp_max_hyst_add[1] =
Jean Delvare31b8dc42007-05-08 17:22:03 +02001761 w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 W83781D_REG_TEMP_HYST(3));
1763 }
Jean Delvare31b8dc42007-05-08 17:22:03 +02001764 i = w83781d_read_value(data, W83781D_REG_VID_FANDIV);
Jean Delvare7c7a5302005-06-16 19:24:14 +02001765 data->vid = i & 0x0f;
Jean Delvare31b8dc42007-05-08 17:22:03 +02001766 data->vid |= (w83781d_read_value(data,
Jean Delvare7c7a5302005-06-16 19:24:14 +02001767 W83781D_REG_CHIPID) & 0x01) << 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 data->fan_div[0] = (i >> 4) & 0x03;
1769 data->fan_div[1] = (i >> 6) & 0x03;
Jean Delvare31b8dc42007-05-08 17:22:03 +02001770 data->fan_div[2] = (w83781d_read_value(data,
Jean Delvare7c7a5302005-06-16 19:24:14 +02001771 W83781D_REG_PIN) >> 6) & 0x03;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 if ((data->type != w83781d) && (data->type != as99127f)) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001773 i = w83781d_read_value(data, W83781D_REG_VBAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 data->fan_div[0] |= (i >> 3) & 0x04;
1775 data->fan_div[1] |= (i >> 4) & 0x04;
Jean Delvare7c7a5302005-06-16 19:24:14 +02001776 data->fan_div[2] |= (i >> 5) & 0x04;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 if ((data->type == w83782d) || (data->type == w83627hf)) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001779 data->alarms = w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001780 W83782D_REG_ALARM1)
Jean Delvare31b8dc42007-05-08 17:22:03 +02001781 | (w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001782 W83782D_REG_ALARM2) << 8)
Jean Delvare31b8dc42007-05-08 17:22:03 +02001783 | (w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001784 W83782D_REG_ALARM3) << 16);
1785 } else if (data->type == w83783s) {
Jean Delvare31b8dc42007-05-08 17:22:03 +02001786 data->alarms = w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001787 W83782D_REG_ALARM1)
Jean Delvare31b8dc42007-05-08 17:22:03 +02001788 | (w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001789 W83782D_REG_ALARM2) << 8);
1790 } else {
1791 /* No real-time status registers, fall back to
1792 interrupt status registers */
Jean Delvare31b8dc42007-05-08 17:22:03 +02001793 data->alarms = w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001794 W83781D_REG_ALARM1)
Jean Delvare31b8dc42007-05-08 17:22:03 +02001795 | (w83781d_read_value(data,
Jean Delvarec7f5d7e2006-02-05 23:13:48 +01001796 W83781D_REG_ALARM2) << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 }
Jean Delvare31b8dc42007-05-08 17:22:03 +02001798 i = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 data->beep_enable = i >> 7;
1800 data->beep_mask = ((i & 0x7f) << 8) +
Jean Delvare31b8dc42007-05-08 17:22:03 +02001801 w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 if ((data->type != w83781d) && (data->type != as99127f)) {
1803 data->beep_mask |=
Jean Delvare31b8dc42007-05-08 17:22:03 +02001804 w83781d_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 W83781D_REG_BEEP_INTS3) << 16;
1806 }
1807 data->last_updated = jiffies;
1808 data->valid = 1;
1809 }
1810
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001811 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
1813 return data;
1814}
1815
Jean Delvare7666c132007-05-08 17:22:02 +02001816/* return 1 if a supported chip is found, 0 otherwise */
1817static int __init
1818w83781d_isa_found(unsigned short address)
1819{
1820 int val, save, found = 0;
1821
1822 if (!request_region(address, W83781D_EXTENT, "w83781d"))
1823 return 0;
1824
1825#define REALLY_SLOW_IO
1826 /* We need the timeouts for at least some W83781D-like
1827 chips. But only if we read 'undefined' registers. */
1828 val = inb_p(address + 1);
1829 if (inb_p(address + 2) != val
1830 || inb_p(address + 3) != val
1831 || inb_p(address + 7) != val) {
1832 pr_debug("w83781d: Detection failed at step 1\n");
1833 goto release;
1834 }
1835#undef REALLY_SLOW_IO
1836
1837 /* We should be able to change the 7 LSB of the address port. The
1838 MSB (busy flag) should be clear initially, set after the write. */
1839 save = inb_p(address + W83781D_ADDR_REG_OFFSET);
1840 if (save & 0x80) {
1841 pr_debug("w83781d: Detection failed at step 2\n");
1842 goto release;
1843 }
1844 val = ~save & 0x7f;
1845 outb_p(val, address + W83781D_ADDR_REG_OFFSET);
1846 if (inb_p(address + W83781D_ADDR_REG_OFFSET) != (val | 0x80)) {
1847 outb_p(save, address + W83781D_ADDR_REG_OFFSET);
1848 pr_debug("w83781d: Detection failed at step 3\n");
1849 goto release;
1850 }
1851
1852 /* We found a device, now see if it could be a W83781D */
1853 outb_p(W83781D_REG_CONFIG, address + W83781D_ADDR_REG_OFFSET);
1854 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1855 if (val & 0x80) {
1856 pr_debug("w83781d: Detection failed at step 4\n");
1857 goto release;
1858 }
1859 outb_p(W83781D_REG_BANK, address + W83781D_ADDR_REG_OFFSET);
1860 save = inb_p(address + W83781D_DATA_REG_OFFSET);
1861 outb_p(W83781D_REG_CHIPMAN, address + W83781D_ADDR_REG_OFFSET);
1862 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1863 if ((!(save & 0x80) && (val != 0xa3))
1864 || ((save & 0x80) && (val != 0x5c))) {
1865 pr_debug("w83781d: Detection failed at step 5\n");
1866 goto release;
1867 }
1868 outb_p(W83781D_REG_I2C_ADDR, address + W83781D_ADDR_REG_OFFSET);
1869 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1870 if (val < 0x03 || val > 0x77) { /* Not a valid I2C address */
1871 pr_debug("w83781d: Detection failed at step 6\n");
1872 goto release;
1873 }
1874
1875 /* The busy flag should be clear again */
1876 if (inb_p(address + W83781D_ADDR_REG_OFFSET) & 0x80) {
1877 pr_debug("w83781d: Detection failed at step 7\n");
1878 goto release;
1879 }
1880
1881 /* Determine the chip type */
1882 outb_p(W83781D_REG_BANK, address + W83781D_ADDR_REG_OFFSET);
1883 save = inb_p(address + W83781D_DATA_REG_OFFSET);
1884 outb_p(save & 0xf8, address + W83781D_DATA_REG_OFFSET);
1885 outb_p(W83781D_REG_WCHIPID, address + W83781D_ADDR_REG_OFFSET);
1886 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1887 if ((val & 0xfe) == 0x10 /* W83781D */
1888 || val == 0x30 /* W83782D */
1889 || val == 0x21) /* W83627HF */
1890 found = 1;
1891
1892 if (found)
1893 pr_info("w83781d: Found a %s chip at %#x\n",
1894 val == 0x21 ? "W83627HF" :
1895 val == 0x30 ? "W83782D" : "W83781D", (int)address);
1896
1897 release:
1898 release_region(address, W83781D_EXTENT);
1899 return found;
1900}
1901
1902static int __init
1903w83781d_isa_device_add(unsigned short address)
1904{
1905 struct resource res = {
1906 .start = address,
Jean Delvare15bde2f2007-08-29 10:39:57 +02001907 .end = address + W83781D_EXTENT - 1,
Jean Delvare7666c132007-05-08 17:22:02 +02001908 .name = "w83781d",
1909 .flags = IORESOURCE_IO,
1910 };
1911 int err;
1912
1913 pdev = platform_device_alloc("w83781d", address);
1914 if (!pdev) {
1915 err = -ENOMEM;
1916 printk(KERN_ERR "w83781d: Device allocation failed\n");
1917 goto exit;
1918 }
1919
1920 err = platform_device_add_resources(pdev, &res, 1);
1921 if (err) {
1922 printk(KERN_ERR "w83781d: Device resource addition failed "
1923 "(%d)\n", err);
1924 goto exit_device_put;
1925 }
1926
1927 err = platform_device_add(pdev);
1928 if (err) {
1929 printk(KERN_ERR "w83781d: Device addition failed (%d)\n",
1930 err);
1931 goto exit_device_put;
1932 }
1933
1934 return 0;
1935
1936 exit_device_put:
1937 platform_device_put(pdev);
1938 exit:
1939 pdev = NULL;
1940 return err;
1941}
1942
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943static int __init
1944sensors_w83781d_init(void)
1945{
Jean Delvarefde09502005-07-19 23:51:07 +02001946 int res;
1947
1948 res = i2c_add_driver(&w83781d_driver);
1949 if (res)
Jean Delvare7666c132007-05-08 17:22:02 +02001950 goto exit;
Jean Delvarefde09502005-07-19 23:51:07 +02001951
Jean Delvare7666c132007-05-08 17:22:02 +02001952 if (w83781d_isa_found(isa_address)) {
1953 res = platform_driver_register(&w83781d_isa_driver);
1954 if (res)
1955 goto exit_unreg_i2c_driver;
1956
1957 /* Sets global pdev as a side effect */
1958 res = w83781d_isa_device_add(isa_address);
1959 if (res)
1960 goto exit_unreg_isa_driver;
1961 }
Jean Delvarefde09502005-07-19 23:51:07 +02001962
1963 return 0;
Jean Delvare7666c132007-05-08 17:22:02 +02001964
1965 exit_unreg_isa_driver:
1966 platform_driver_unregister(&w83781d_isa_driver);
1967 exit_unreg_i2c_driver:
1968 i2c_del_driver(&w83781d_driver);
1969 exit:
1970 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971}
1972
1973static void __exit
1974sensors_w83781d_exit(void)
1975{
Jean Delvare7666c132007-05-08 17:22:02 +02001976 if (pdev) {
1977 platform_device_unregister(pdev);
1978 platform_driver_unregister(&w83781d_isa_driver);
1979 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 i2c_del_driver(&w83781d_driver);
1981}
1982
1983MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
1984 "Philip Edelbrock <phil@netroedge.com>, "
1985 "and Mark Studebaker <mdsxyz123@yahoo.com>");
1986MODULE_DESCRIPTION("W83781D driver");
1987MODULE_LICENSE("GPL");
1988
1989module_init(sensors_w83781d_init);
1990module_exit(sensors_w83781d_exit);