aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/gl520sm.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-07 22:15:38 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-07 22:15:38 -0500
commitd7511ec8115487ccea2ce93bf58d5e5cd2c1c0a3 (patch)
treee428f9438a563f1fa77479e9c9c4ef8b2e451a8b /drivers/hwmon/gl520sm.c
parent0b61a2ba5dfd1620731e717d686e6ade657fd975 (diff)
parente84542f5db655d1ce7b4890832f0e5d19aae965d (diff)
Merge branch 'release' of git://lm-sensors.org/kernel/mhoffman/hwmon-2.6
* 'release' of git://lm-sensors.org/kernel/mhoffman/hwmon-2.6: (59 commits) hwmon: (lm80) Add individual alarm files hwmon: (lm80) De-macro the sysfs callbacks hwmon: (lm80) Various cleanups hwmon: (w83627hf) Refactor beep enable handling hwmon: (w83627hf) Add individual alarm and beep files hwmon: (w83627hf) Enable VBAT monitoring hwmon: (w83627ehf) The W83627DHG has 8 VID pins hwmon: (asb100) Add individual alarm files hwmon: (asb100) De-macro the sysfs callbacks hwmon: (asb100) Various cleanups hwmon: VRM is not written to registers hwmon: (dme1737) fix Super-IO device ID override hwmon: (dme1737) fix divide-by-0 hwmon: (abituguru3) Add AUX4 fan input for Abit IP35 Pro hwmon: Add support for Texas Instruments/Burr-Brown ADS7828 hwmon: (adm9240) Add individual alarm files hwmon: (lm77) Add individual alarm files hwmon: Discard useless I2C driver IDs hwmon: (lm85) Make the pwmN_enable files writable hwmon: (lm85) Return standard values in pwmN_enable ...
Diffstat (limited to 'drivers/hwmon/gl520sm.c')
-rw-r--r--drivers/hwmon/gl520sm.c648
1 files changed, 389 insertions, 259 deletions
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index 2d39d8fc2389..03ecdc334764 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -27,6 +27,7 @@
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/hwmon-sysfs.h>
30#include <linux/hwmon-vid.h> 31#include <linux/hwmon-vid.h>
31#include <linux/err.h> 32#include <linux/err.h>
32#include <linux/mutex.h> 33#include <linux/mutex.h>
@@ -43,9 +44,9 @@ static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
43/* Insmod parameters */ 44/* Insmod parameters */
44I2C_CLIENT_INSMOD_1(gl520sm); 45I2C_CLIENT_INSMOD_1(gl520sm);
45 46
46/* Many GL520 constants specified below 47/* Many GL520 constants specified below
47One of the inputs can be configured as either temp or voltage. 48One of the inputs can be configured as either temp or voltage.
48That's why _TEMP2 and _IN4 access the same register 49That's why _TEMP2 and _IN4 access the same register
49*/ 50*/
50 51
51/* The GL520 registers */ 52/* The GL520 registers */
@@ -56,37 +57,14 @@ That's why _TEMP2 and _IN4 access the same register
56 57
57#define GL520_REG_VID_INPUT 0x02 58#define GL520_REG_VID_INPUT 0x02
58 59
59#define GL520_REG_IN0_INPUT 0x15 60static const u8 GL520_REG_IN_INPUT[] = { 0x15, 0x14, 0x13, 0x0d, 0x0e };
60#define GL520_REG_IN0_LIMIT 0x0c 61static const u8 GL520_REG_IN_LIMIT[] = { 0x0c, 0x09, 0x0a, 0x0b };
61#define GL520_REG_IN0_MIN GL520_REG_IN0_LIMIT 62static const u8 GL520_REG_IN_MIN[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x18 };
62#define GL520_REG_IN0_MAX GL520_REG_IN0_LIMIT 63static const u8 GL520_REG_IN_MAX[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x17 };
63 64
64#define GL520_REG_IN1_INPUT 0x14 65static const u8 GL520_REG_TEMP_INPUT[] = { 0x04, 0x0e };
65#define GL520_REG_IN1_LIMIT 0x09 66static const u8 GL520_REG_TEMP_MAX[] = { 0x05, 0x17 };
66#define GL520_REG_IN1_MIN GL520_REG_IN1_LIMIT 67static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 };
67#define GL520_REG_IN1_MAX GL520_REG_IN1_LIMIT
68
69#define GL520_REG_IN2_INPUT 0x13
70#define GL520_REG_IN2_LIMIT 0x0a
71#define GL520_REG_IN2_MIN GL520_REG_IN2_LIMIT
72#define GL520_REG_IN2_MAX GL520_REG_IN2_LIMIT
73
74#define GL520_REG_IN3_INPUT 0x0d
75#define GL520_REG_IN3_LIMIT 0x0b
76#define GL520_REG_IN3_MIN GL520_REG_IN3_LIMIT
77#define GL520_REG_IN3_MAX GL520_REG_IN3_LIMIT
78
79#define GL520_REG_IN4_INPUT 0x0e
80#define GL520_REG_IN4_MAX 0x17
81#define GL520_REG_IN4_MIN 0x18
82
83#define GL520_REG_TEMP1_INPUT 0x04
84#define GL520_REG_TEMP1_MAX 0x05
85#define GL520_REG_TEMP1_MAX_HYST 0x06
86
87#define GL520_REG_TEMP2_INPUT 0x0e
88#define GL520_REG_TEMP2_MAX 0x17
89#define GL520_REG_TEMP2_MAX_HYST 0x18
90 68
91#define GL520_REG_FAN_INPUT 0x07 69#define GL520_REG_FAN_INPUT 0x07
92#define GL520_REG_FAN_MIN 0x08 70#define GL520_REG_FAN_MIN 0x08
@@ -114,7 +92,6 @@ static struct i2c_driver gl520_driver = {
114 .driver = { 92 .driver = {
115 .name = "gl520sm", 93 .name = "gl520sm",
116 }, 94 },
117 .id = I2C_DRIVERID_GL520,
118 .attach_adapter = gl520_attach_adapter, 95 .attach_adapter = gl520_attach_adapter,
119 .detach_client = gl520_detach_client, 96 .detach_client = gl520_detach_client,
120}; 97};
@@ -150,93 +127,13 @@ struct gl520_data {
150 * Sysfs stuff 127 * Sysfs stuff
151 */ 128 */
152 129
153#define sysfs_r(type, n, item, reg) \ 130static ssize_t get_cpu_vid(struct device *dev, struct device_attribute *attr,
154static ssize_t get_##type##item (struct gl520_data *, char *, int); \ 131 char *buf)
155static ssize_t get_##type##n##item (struct device *, struct device_attribute *attr, char *); \
156static ssize_t get_##type##n##item (struct device *dev, struct device_attribute *attr, char *buf) \
157{ \
158 struct gl520_data *data = gl520_update_device(dev); \
159 return get_##type##item(data, buf, (n)); \
160}
161
162#define sysfs_w(type, n, item, reg) \
163static ssize_t set_##type##item (struct i2c_client *, struct gl520_data *, const char *, size_t, int, int); \
164static ssize_t set_##type##n##item (struct device *, struct device_attribute *attr, const char *, size_t); \
165static ssize_t set_##type##n##item (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
166{ \
167 struct i2c_client *client = to_i2c_client(dev); \
168 struct gl520_data *data = i2c_get_clientdata(client); \
169 return set_##type##item(client, data, buf, count, (n), reg); \
170}
171
172#define sysfs_rw_n(type, n, item, reg) \
173sysfs_r(type, n, item, reg) \
174sysfs_w(type, n, item, reg) \
175static DEVICE_ATTR(type##n##item, S_IRUGO | S_IWUSR, get_##type##n##item, set_##type##n##item);
176
177#define sysfs_ro_n(type, n, item, reg) \
178sysfs_r(type, n, item, reg) \
179static DEVICE_ATTR(type##n##item, S_IRUGO, get_##type##n##item, NULL);
180
181#define sysfs_rw(type, item, reg) \
182sysfs_r(type, 0, item, reg) \
183sysfs_w(type, 0, item, reg) \
184static DEVICE_ATTR(type##item, S_IRUGO | S_IWUSR, get_##type##0##item, set_##type##0##item);
185
186#define sysfs_ro(type, item, reg) \
187sysfs_r(type, 0, item, reg) \
188static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL);
189
190
191#define sysfs_vid(n) \
192sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
193
194#define sysfs_in(n) \
195sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \
196sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \
197sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \
198
199#define sysfs_fan(n) \
200sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
201sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \
202sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV)
203
204#define sysfs_fan_off(n) \
205sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \
206
207#define sysfs_temp(n) \
208sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \
209sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \
210sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST)
211
212#define sysfs_alarms() \
213sysfs_ro(alarms, , GL520_REG_ALARMS) \
214sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \
215sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK)
216
217
218sysfs_vid(0)
219
220sysfs_in(0)
221sysfs_in(1)
222sysfs_in(2)
223sysfs_in(3)
224sysfs_in(4)
225
226sysfs_fan(1)
227sysfs_fan(2)
228sysfs_fan_off(1)
229
230sysfs_temp(1)
231sysfs_temp(2)
232
233sysfs_alarms()
234
235
236static ssize_t get_cpu_vid(struct gl520_data *data, char *buf, int n)
237{ 132{
133 struct gl520_data *data = gl520_update_device(dev);
238 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); 134 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
239} 135}
136static DEVICE_ATTR(cpu0_vid, S_IRUGO, get_cpu_vid, NULL);
240 137
241#define VDD_FROM_REG(val) (((val)*95+2)/4) 138#define VDD_FROM_REG(val) (((val)*95+2)/4)
242#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255)) 139#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255))
@@ -244,8 +141,11 @@ static ssize_t get_cpu_vid(struct gl520_data *data, char *buf, int n)
244#define IN_FROM_REG(val) ((val)*19) 141#define IN_FROM_REG(val) ((val)*19)
245#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255)) 142#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255))
246 143
247static ssize_t get_in_input(struct gl520_data *data, char *buf, int n) 144static ssize_t get_in_input(struct device *dev, struct device_attribute *attr,
145 char *buf)
248{ 146{
147 int n = to_sensor_dev_attr(attr)->index;
148 struct gl520_data *data = gl520_update_device(dev);
249 u8 r = data->in_input[n]; 149 u8 r = data->in_input[n];
250 150
251 if (n == 0) 151 if (n == 0)
@@ -254,8 +154,11 @@ static ssize_t get_in_input(struct gl520_data *data, char *buf, int n)
254 return sprintf(buf, "%d\n", IN_FROM_REG(r)); 154 return sprintf(buf, "%d\n", IN_FROM_REG(r));
255} 155}
256 156
257static ssize_t get_in_min(struct gl520_data *data, char *buf, int n) 157static ssize_t get_in_min(struct device *dev, struct device_attribute *attr,
158 char *buf)
258{ 159{
160 int n = to_sensor_dev_attr(attr)->index;
161 struct gl520_data *data = gl520_update_device(dev);
259 u8 r = data->in_min[n]; 162 u8 r = data->in_min[n];
260 163
261 if (n == 0) 164 if (n == 0)
@@ -264,8 +167,11 @@ static ssize_t get_in_min(struct gl520_data *data, char *buf, int n)
264 return sprintf(buf, "%d\n", IN_FROM_REG(r)); 167 return sprintf(buf, "%d\n", IN_FROM_REG(r));
265} 168}
266 169
267static ssize_t get_in_max(struct gl520_data *data, char *buf, int n) 170static ssize_t get_in_max(struct device *dev, struct device_attribute *attr,
171 char *buf)
268{ 172{
173 int n = to_sensor_dev_attr(attr)->index;
174 struct gl520_data *data = gl520_update_device(dev);
269 u8 r = data->in_max[n]; 175 u8 r = data->in_max[n];
270 176
271 if (n == 0) 177 if (n == 0)
@@ -274,8 +180,12 @@ static ssize_t get_in_max(struct gl520_data *data, char *buf, int n)
274 return sprintf(buf, "%d\n", IN_FROM_REG(r)); 180 return sprintf(buf, "%d\n", IN_FROM_REG(r));
275} 181}
276 182
277static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 183static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
184 const char *buf, size_t count)
278{ 185{
186 struct i2c_client *client = to_i2c_client(dev);
187 struct gl520_data *data = i2c_get_clientdata(client);
188 int n = to_sensor_dev_attr(attr)->index;
279 long v = simple_strtol(buf, NULL, 10); 189 long v = simple_strtol(buf, NULL, 10);
280 u8 r; 190 u8 r;
281 191
@@ -289,16 +199,22 @@ static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, co
289 data->in_min[n] = r; 199 data->in_min[n] = r;
290 200
291 if (n < 4) 201 if (n < 4)
292 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r); 202 gl520_write_value(client, GL520_REG_IN_MIN[n],
203 (gl520_read_value(client, GL520_REG_IN_MIN[n])
204 & ~0xff) | r);
293 else 205 else
294 gl520_write_value(client, reg, r); 206 gl520_write_value(client, GL520_REG_IN_MIN[n], r);
295 207
296 mutex_unlock(&data->update_lock); 208 mutex_unlock(&data->update_lock);
297 return count; 209 return count;
298} 210}
299 211
300static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 212static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
213 const char *buf, size_t count)
301{ 214{
215 struct i2c_client *client = to_i2c_client(dev);
216 struct gl520_data *data = i2c_get_clientdata(client);
217 int n = to_sensor_dev_attr(attr)->index;
302 long v = simple_strtol(buf, NULL, 10); 218 long v = simple_strtol(buf, NULL, 10);
303 u8 r; 219 u8 r;
304 220
@@ -312,57 +228,109 @@ static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, co
312 data->in_max[n] = r; 228 data->in_max[n] = r;
313 229
314 if (n < 4) 230 if (n < 4)
315 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8)); 231 gl520_write_value(client, GL520_REG_IN_MAX[n],
232 (gl520_read_value(client, GL520_REG_IN_MAX[n])
233 & ~0xff00) | (r << 8));
316 else 234 else
317 gl520_write_value(client, reg, r); 235 gl520_write_value(client, GL520_REG_IN_MAX[n], r);
318 236
319 mutex_unlock(&data->update_lock); 237 mutex_unlock(&data->update_lock);
320 return count; 238 return count;
321} 239}
322 240
241static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, get_in_input, NULL, 0);
242static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, get_in_input, NULL, 1);
243static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, get_in_input, NULL, 2);
244static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, get_in_input, NULL, 3);
245static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, get_in_input, NULL, 4);
246static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
247 get_in_min, set_in_min, 0);
248static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR,
249 get_in_min, set_in_min, 1);
250static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR,
251 get_in_min, set_in_min, 2);
252static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO | S_IWUSR,
253 get_in_min, set_in_min, 3);
254static SENSOR_DEVICE_ATTR(in4_min, S_IRUGO | S_IWUSR,
255 get_in_min, set_in_min, 4);
256static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
257 get_in_max, set_in_max, 0);
258static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR,
259 get_in_max, set_in_max, 1);
260static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR,
261 get_in_max, set_in_max, 2);
262static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO | S_IWUSR,
263 get_in_max, set_in_max, 3);
264static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR,
265 get_in_max, set_in_max, 4);
266
323#define DIV_FROM_REG(val) (1 << (val)) 267#define DIV_FROM_REG(val) (1 << (val))
324#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val) << (div)))) 268#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val) << (div))))
325#define FAN_TO_REG(val,div) ((val)<=0?0:SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, 255)); 269#define FAN_TO_REG(val,div) ((val)<=0?0:SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, 255));
326 270
327static ssize_t get_fan_input(struct gl520_data *data, char *buf, int n) 271static ssize_t get_fan_input(struct device *dev, struct device_attribute *attr,
272 char *buf)
328{ 273{
329 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n - 1], data->fan_div[n - 1])); 274 int n = to_sensor_dev_attr(attr)->index;
275 struct gl520_data *data = gl520_update_device(dev);
276
277 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n],
278 data->fan_div[n]));
330} 279}
331 280
332static ssize_t get_fan_min(struct gl520_data *data, char *buf, int n) 281static ssize_t get_fan_min(struct device *dev, struct device_attribute *attr,
282 char *buf)
333{ 283{
334 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n - 1], data->fan_div[n - 1])); 284 int n = to_sensor_dev_attr(attr)->index;
285 struct gl520_data *data = gl520_update_device(dev);
286
287 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n],
288 data->fan_div[n]));
335} 289}
336 290
337static ssize_t get_fan_div(struct gl520_data *data, char *buf, int n) 291static ssize_t get_fan_div(struct device *dev, struct device_attribute *attr,
292 char *buf)
338{ 293{
339 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n - 1])); 294 int n = to_sensor_dev_attr(attr)->index;
295 struct gl520_data *data = gl520_update_device(dev);
296
297 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n]));
340} 298}
341 299
342static ssize_t get_fan_off(struct gl520_data *data, char *buf, int n) 300static ssize_t get_fan_off(struct device *dev, struct device_attribute *attr,
301 char *buf)
343{ 302{
303 struct gl520_data *data = gl520_update_device(dev);
344 return sprintf(buf, "%d\n", data->fan_off); 304 return sprintf(buf, "%d\n", data->fan_off);
345} 305}
346 306
347static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 307static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
308 const char *buf, size_t count)
348{ 309{
310 struct i2c_client *client = to_i2c_client(dev);
311 struct gl520_data *data = i2c_get_clientdata(client);
312 int n = to_sensor_dev_attr(attr)->index;
349 unsigned long v = simple_strtoul(buf, NULL, 10); 313 unsigned long v = simple_strtoul(buf, NULL, 10);
350 u8 r; 314 u8 r;
351 315
352 mutex_lock(&data->update_lock); 316 mutex_lock(&data->update_lock);
353 r = FAN_TO_REG(v, data->fan_div[n - 1]); 317 r = FAN_TO_REG(v, data->fan_div[n]);
354 data->fan_min[n - 1] = r; 318 data->fan_min[n] = r;
355 319
356 if (n == 1) 320 if (n == 0)
357 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8)); 321 gl520_write_value(client, GL520_REG_FAN_MIN,
322 (gl520_read_value(client, GL520_REG_FAN_MIN)
323 & ~0xff00) | (r << 8));
358 else 324 else
359 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r); 325 gl520_write_value(client, GL520_REG_FAN_MIN,
326 (gl520_read_value(client, GL520_REG_FAN_MIN)
327 & ~0xff) | r);
360 328
361 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); 329 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
362 if (data->fan_min[n - 1] == 0) 330 if (data->fan_min[n] == 0)
363 data->alarm_mask &= (n == 1) ? ~0x20 : ~0x40; 331 data->alarm_mask &= (n == 0) ? ~0x20 : ~0x40;
364 else 332 else
365 data->alarm_mask |= (n == 1) ? 0x20 : 0x40; 333 data->alarm_mask |= (n == 0) ? 0x20 : 0x40;
366 data->beep_mask &= data->alarm_mask; 334 data->beep_mask &= data->alarm_mask;
367 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); 335 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
368 336
@@ -370,8 +338,12 @@ static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, c
370 return count; 338 return count;
371} 339}
372 340
373static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 341static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
342 const char *buf, size_t count)
374{ 343{
344 struct i2c_client *client = to_i2c_client(dev);
345 struct gl520_data *data = i2c_get_clientdata(client);
346 int n = to_sensor_dev_attr(attr)->index;
375 unsigned long v = simple_strtoul(buf, NULL, 10); 347 unsigned long v = simple_strtoul(buf, NULL, 10);
376 u8 r; 348 u8 r;
377 349
@@ -386,133 +358,282 @@ static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, c
386 } 358 }
387 359
388 mutex_lock(&data->update_lock); 360 mutex_lock(&data->update_lock);
389 data->fan_div[n - 1] = r; 361 data->fan_div[n] = r;
390 362
391 if (n == 1) 363 if (n == 0)
392 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xc0) | (r << 6)); 364 gl520_write_value(client, GL520_REG_FAN_DIV,
365 (gl520_read_value(client, GL520_REG_FAN_DIV)
366 & ~0xc0) | (r << 6));
393 else 367 else
394 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x30) | (r << 4)); 368 gl520_write_value(client, GL520_REG_FAN_DIV,
369 (gl520_read_value(client, GL520_REG_FAN_DIV)
370 & ~0x30) | (r << 4));
395 371
396 mutex_unlock(&data->update_lock); 372 mutex_unlock(&data->update_lock);
397 return count; 373 return count;
398} 374}
399 375
400static ssize_t set_fan_off(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 376static ssize_t set_fan_off(struct device *dev, struct device_attribute *attr,
377 const char *buf, size_t count)
401{ 378{
379 struct i2c_client *client = to_i2c_client(dev);
380 struct gl520_data *data = i2c_get_clientdata(client);
402 u8 r = simple_strtoul(buf, NULL, 10)?1:0; 381 u8 r = simple_strtoul(buf, NULL, 10)?1:0;
403 382
404 mutex_lock(&data->update_lock); 383 mutex_lock(&data->update_lock);
405 data->fan_off = r; 384 data->fan_off = r;
406 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x0c) | (r << 2)); 385 gl520_write_value(client, GL520_REG_FAN_OFF,
386 (gl520_read_value(client, GL520_REG_FAN_OFF)
387 & ~0x0c) | (r << 2));
407 mutex_unlock(&data->update_lock); 388 mutex_unlock(&data->update_lock);
408 return count; 389 return count;
409} 390}
410 391
392static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, get_fan_input, NULL, 0);
393static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, get_fan_input, NULL, 1);
394static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
395 get_fan_min, set_fan_min, 0);
396static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
397 get_fan_min, set_fan_min, 1);
398static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
399 get_fan_div, set_fan_div, 0);
400static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
401 get_fan_div, set_fan_div, 1);
402static DEVICE_ATTR(fan1_off, S_IRUGO | S_IWUSR,
403 get_fan_off, set_fan_off);
404
411#define TEMP_FROM_REG(val) (((val) - 130) * 1000) 405#define TEMP_FROM_REG(val) (((val) - 130) * 1000)
412#define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0?(val)-500:(val)+500) / 1000)+130),0,255)) 406#define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0?(val)-500:(val)+500) / 1000)+130),0,255))
413 407
414static ssize_t get_temp_input(struct gl520_data *data, char *buf, int n) 408static ssize_t get_temp_input(struct device *dev, struct device_attribute *attr,
409 char *buf)
415{ 410{
416 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n - 1])); 411 int n = to_sensor_dev_attr(attr)->index;
412 struct gl520_data *data = gl520_update_device(dev);
413
414 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n]));
417} 415}
418 416
419static ssize_t get_temp_max(struct gl520_data *data, char *buf, int n) 417static ssize_t get_temp_max(struct device *dev, struct device_attribute *attr,
418 char *buf)
420{ 419{
421 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n - 1])); 420 int n = to_sensor_dev_attr(attr)->index;
421 struct gl520_data *data = gl520_update_device(dev);
422
423 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n]));
422} 424}
423 425
424static ssize_t get_temp_max_hyst(struct gl520_data *data, char *buf, int n) 426static ssize_t get_temp_max_hyst(struct device *dev, struct device_attribute
427 *attr, char *buf)
425{ 428{
426 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n - 1])); 429 int n = to_sensor_dev_attr(attr)->index;
430 struct gl520_data *data = gl520_update_device(dev);
431
432 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n]));
427} 433}
428 434
429static ssize_t set_temp_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 435static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
436 const char *buf, size_t count)
430{ 437{
438 struct i2c_client *client = to_i2c_client(dev);
439 struct gl520_data *data = i2c_get_clientdata(client);
440 int n = to_sensor_dev_attr(attr)->index;
431 long v = simple_strtol(buf, NULL, 10); 441 long v = simple_strtol(buf, NULL, 10);
432 442
433 mutex_lock(&data->update_lock); 443 mutex_lock(&data->update_lock);
434 data->temp_max[n - 1] = TEMP_TO_REG(v); 444 data->temp_max[n] = TEMP_TO_REG(v);
435 gl520_write_value(client, reg, data->temp_max[n - 1]); 445 gl520_write_value(client, GL520_REG_TEMP_MAX[n], data->temp_max[n]);
436 mutex_unlock(&data->update_lock); 446 mutex_unlock(&data->update_lock);
437 return count; 447 return count;
438} 448}
439 449
440static ssize_t set_temp_max_hyst(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 450static ssize_t set_temp_max_hyst(struct device *dev, struct device_attribute
451 *attr, const char *buf, size_t count)
441{ 452{
453 struct i2c_client *client = to_i2c_client(dev);
454 struct gl520_data *data = i2c_get_clientdata(client);
455 int n = to_sensor_dev_attr(attr)->index;
442 long v = simple_strtol(buf, NULL, 10); 456 long v = simple_strtol(buf, NULL, 10);
443 457
444 mutex_lock(&data->update_lock); 458 mutex_lock(&data->update_lock);
445 data->temp_max_hyst[n - 1] = TEMP_TO_REG(v); 459 data->temp_max_hyst[n] = TEMP_TO_REG(v);
446 gl520_write_value(client, reg, data->temp_max_hyst[n - 1]); 460 gl520_write_value(client, GL520_REG_TEMP_MAX_HYST[n],
461 data->temp_max_hyst[n]);
447 mutex_unlock(&data->update_lock); 462 mutex_unlock(&data->update_lock);
448 return count; 463 return count;
449} 464}
450 465
451static ssize_t get_alarms(struct gl520_data *data, char *buf, int n) 466static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, get_temp_input, NULL, 0);
467static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, get_temp_input, NULL, 1);
468static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
469 get_temp_max, set_temp_max, 0);
470static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR,
471 get_temp_max, set_temp_max, 1);
472static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
473 get_temp_max_hyst, set_temp_max_hyst, 0);
474static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
475 get_temp_max_hyst, set_temp_max_hyst, 1);
476
477static ssize_t get_alarms(struct device *dev, struct device_attribute *attr,
478 char *buf)
452{ 479{
480 struct gl520_data *data = gl520_update_device(dev);
453 return sprintf(buf, "%d\n", data->alarms); 481 return sprintf(buf, "%d\n", data->alarms);
454} 482}
455 483
456static ssize_t get_beep_enable(struct gl520_data *data, char *buf, int n) 484static ssize_t get_beep_enable(struct device *dev, struct device_attribute
485 *attr, char *buf)
457{ 486{
487 struct gl520_data *data = gl520_update_device(dev);
458 return sprintf(buf, "%d\n", data->beep_enable); 488 return sprintf(buf, "%d\n", data->beep_enable);
459} 489}
460 490
461static ssize_t get_beep_mask(struct gl520_data *data, char *buf, int n) 491static ssize_t get_beep_mask(struct device *dev, struct device_attribute *attr,
492 char *buf)
462{ 493{
494 struct gl520_data *data = gl520_update_device(dev);
463 return sprintf(buf, "%d\n", data->beep_mask); 495 return sprintf(buf, "%d\n", data->beep_mask);
464} 496}
465 497
466static ssize_t set_beep_enable(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 498static ssize_t set_beep_enable(struct device *dev, struct device_attribute
499 *attr, const char *buf, size_t count)
467{ 500{
501 struct i2c_client *client = to_i2c_client(dev);
502 struct gl520_data *data = i2c_get_clientdata(client);
468 u8 r = simple_strtoul(buf, NULL, 10)?0:1; 503 u8 r = simple_strtoul(buf, NULL, 10)?0:1;
469 504
470 mutex_lock(&data->update_lock); 505 mutex_lock(&data->update_lock);
471 data->beep_enable = !r; 506 data->beep_enable = !r;
472 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x04) | (r << 2)); 507 gl520_write_value(client, GL520_REG_BEEP_ENABLE,
508 (gl520_read_value(client, GL520_REG_BEEP_ENABLE)
509 & ~0x04) | (r << 2));
473 mutex_unlock(&data->update_lock); 510 mutex_unlock(&data->update_lock);
474 return count; 511 return count;
475} 512}
476 513
477static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 514static ssize_t set_beep_mask(struct device *dev, struct device_attribute *attr,
515 const char *buf, size_t count)
478{ 516{
517 struct i2c_client *client = to_i2c_client(dev);
518 struct gl520_data *data = i2c_get_clientdata(client);
479 u8 r = simple_strtoul(buf, NULL, 10); 519 u8 r = simple_strtoul(buf, NULL, 10);
480 520
481 mutex_lock(&data->update_lock); 521 mutex_lock(&data->update_lock);
482 r &= data->alarm_mask; 522 r &= data->alarm_mask;
483 data->beep_mask = r; 523 data->beep_mask = r;
484 gl520_write_value(client, reg, r); 524 gl520_write_value(client, GL520_REG_BEEP_MASK, r);
525 mutex_unlock(&data->update_lock);
526 return count;
527}
528
529static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL);
530static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
531 get_beep_enable, set_beep_enable);
532static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
533 get_beep_mask, set_beep_mask);
534
535static ssize_t get_alarm(struct device *dev, struct device_attribute *attr,
536 char *buf)
537{
538 int bit_nr = to_sensor_dev_attr(attr)->index;
539 struct gl520_data *data = gl520_update_device(dev);
540
541 return sprintf(buf, "%d\n", (data->alarms >> bit_nr) & 1);
542}
543
544static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, get_alarm, NULL, 0);
545static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, get_alarm, NULL, 1);
546static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, get_alarm, NULL, 2);
547static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, get_alarm, NULL, 3);
548static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, get_alarm, NULL, 4);
549static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, get_alarm, NULL, 5);
550static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, get_alarm, NULL, 6);
551static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, get_alarm, NULL, 7);
552static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, get_alarm, NULL, 7);
553
554static ssize_t get_beep(struct device *dev, struct device_attribute *attr,
555 char *buf)
556{
557 int bitnr = to_sensor_dev_attr(attr)->index;
558 struct gl520_data *data = gl520_update_device(dev);
559
560 return sprintf(buf, "%d\n", (data->beep_mask >> bitnr) & 1);
561}
562
563static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
564 const char *buf, size_t count)
565{
566 struct i2c_client *client = to_i2c_client(dev);
567 struct gl520_data *data = i2c_get_clientdata(client);
568 int bitnr = to_sensor_dev_attr(attr)->index;
569 unsigned long bit;
570
571 bit = simple_strtoul(buf, NULL, 10);
572 if (bit & ~1)
573 return -EINVAL;
574
575 mutex_lock(&data->update_lock);
576 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
577 if (bit)
578 data->beep_mask |= (1 << bitnr);
579 else
580 data->beep_mask &= ~(1 << bitnr);
581 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
485 mutex_unlock(&data->update_lock); 582 mutex_unlock(&data->update_lock);
486 return count; 583 return count;
487} 584}
488 585
586static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 0);
587static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 1);
588static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 2);
589static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 3);
590static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 4);
591static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 5);
592static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 6);
593static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 7);
594static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 7);
595
489static struct attribute *gl520_attributes[] = { 596static struct attribute *gl520_attributes[] = {
490 &dev_attr_cpu0_vid.attr, 597 &dev_attr_cpu0_vid.attr,
491 598
492 &dev_attr_in0_input.attr, 599 &sensor_dev_attr_in0_input.dev_attr.attr,
493 &dev_attr_in0_min.attr, 600 &sensor_dev_attr_in0_min.dev_attr.attr,
494 &dev_attr_in0_max.attr, 601 &sensor_dev_attr_in0_max.dev_attr.attr,
495 &dev_attr_in1_input.attr, 602 &sensor_dev_attr_in0_alarm.dev_attr.attr,
496 &dev_attr_in1_min.attr, 603 &sensor_dev_attr_in0_beep.dev_attr.attr,
497 &dev_attr_in1_max.attr, 604 &sensor_dev_attr_in1_input.dev_attr.attr,
498 &dev_attr_in2_input.attr, 605 &sensor_dev_attr_in1_min.dev_attr.attr,
499 &dev_attr_in2_min.attr, 606 &sensor_dev_attr_in1_max.dev_attr.attr,
500 &dev_attr_in2_max.attr, 607 &sensor_dev_attr_in1_alarm.dev_attr.attr,
501 &dev_attr_in3_input.attr, 608 &sensor_dev_attr_in1_beep.dev_attr.attr,
502 &dev_attr_in3_min.attr, 609 &sensor_dev_attr_in2_input.dev_attr.attr,
503 &dev_attr_in3_max.attr, 610 &sensor_dev_attr_in2_min.dev_attr.attr,
504 611 &sensor_dev_attr_in2_max.dev_attr.attr,
505 &dev_attr_fan1_input.attr, 612 &sensor_dev_attr_in2_alarm.dev_attr.attr,
506 &dev_attr_fan1_min.attr, 613 &sensor_dev_attr_in2_beep.dev_attr.attr,
507 &dev_attr_fan1_div.attr, 614 &sensor_dev_attr_in3_input.dev_attr.attr,
615 &sensor_dev_attr_in3_min.dev_attr.attr,
616 &sensor_dev_attr_in3_max.dev_attr.attr,
617 &sensor_dev_attr_in3_alarm.dev_attr.attr,
618 &sensor_dev_attr_in3_beep.dev_attr.attr,
619
620 &sensor_dev_attr_fan1_input.dev_attr.attr,
621 &sensor_dev_attr_fan1_min.dev_attr.attr,
622 &sensor_dev_attr_fan1_div.dev_attr.attr,
623 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
624 &sensor_dev_attr_fan1_beep.dev_attr.attr,
508 &dev_attr_fan1_off.attr, 625 &dev_attr_fan1_off.attr,
509 &dev_attr_fan2_input.attr, 626 &sensor_dev_attr_fan2_input.dev_attr.attr,
510 &dev_attr_fan2_min.attr, 627 &sensor_dev_attr_fan2_min.dev_attr.attr,
511 &dev_attr_fan2_div.attr, 628 &sensor_dev_attr_fan2_div.dev_attr.attr,
512 629 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
513 &dev_attr_temp1_input.attr, 630 &sensor_dev_attr_fan2_beep.dev_attr.attr,
514 &dev_attr_temp1_max.attr, 631
515 &dev_attr_temp1_max_hyst.attr, 632 &sensor_dev_attr_temp1_input.dev_attr.attr,
633 &sensor_dev_attr_temp1_max.dev_attr.attr,
634 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
635 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
636 &sensor_dev_attr_temp1_beep.dev_attr.attr,
516 637
517 &dev_attr_alarms.attr, 638 &dev_attr_alarms.attr,
518 &dev_attr_beep_enable.attr, 639 &dev_attr_beep_enable.attr,
@@ -525,13 +646,17 @@ static const struct attribute_group gl520_group = {
525}; 646};
526 647
527static struct attribute *gl520_attributes_opt[] = { 648static struct attribute *gl520_attributes_opt[] = {
528 &dev_attr_in4_input.attr, 649 &sensor_dev_attr_in4_input.dev_attr.attr,
529 &dev_attr_in4_min.attr, 650 &sensor_dev_attr_in4_min.dev_attr.attr,
530 &dev_attr_in4_max.attr, 651 &sensor_dev_attr_in4_max.dev_attr.attr,
531 652 &sensor_dev_attr_in4_alarm.dev_attr.attr,
532 &dev_attr_temp2_input.attr, 653 &sensor_dev_attr_in4_beep.dev_attr.attr,
533 &dev_attr_temp2_max.attr, 654
534 &dev_attr_temp2_max_hyst.attr, 655 &sensor_dev_attr_temp2_input.dev_attr.attr,
656 &sensor_dev_attr_temp2_max.dev_attr.attr,
657 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
658 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
659 &sensor_dev_attr_temp2_beep.dev_attr.attr,
535 NULL 660 NULL
536}; 661};
537 662
@@ -553,7 +678,7 @@ static int gl520_attach_adapter(struct i2c_adapter *adapter)
553 678
554static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) 679static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
555{ 680{
556 struct i2c_client *new_client; 681 struct i2c_client *client;
557 struct gl520_data *data; 682 struct gl520_data *data;
558 int err = 0; 683 int err = 0;
559 684
@@ -570,59 +695,65 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
570 goto exit; 695 goto exit;
571 } 696 }
572 697
573 new_client = &data->client; 698 client = &data->client;
574 i2c_set_clientdata(new_client, data); 699 i2c_set_clientdata(client, data);
575 new_client->addr = address; 700 client->addr = address;
576 new_client->adapter = adapter; 701 client->adapter = adapter;
577 new_client->driver = &gl520_driver; 702 client->driver = &gl520_driver;
578 new_client->flags = 0;
579 703
580 /* Determine the chip type. */ 704 /* Determine the chip type. */
581 if (kind < 0) { 705 if (kind < 0) {
582 if ((gl520_read_value(new_client, GL520_REG_CHIP_ID) != 0x20) || 706 if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) ||
583 ((gl520_read_value(new_client, GL520_REG_REVISION) & 0x7f) != 0x00) || 707 ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
584 ((gl520_read_value(new_client, GL520_REG_CONF) & 0x80) != 0x00)) { 708 ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) {
585 dev_dbg(&new_client->dev, "Unknown chip type, skipping\n"); 709 dev_dbg(&client->dev, "Unknown chip type, skipping\n");
586 goto exit_free; 710 goto exit_free;
587 } 711 }
588 } 712 }
589 713
590 /* Fill in the remaining client fields */ 714 /* Fill in the remaining client fields */
591 strlcpy(new_client->name, "gl520sm", I2C_NAME_SIZE); 715 strlcpy(client->name, "gl520sm", I2C_NAME_SIZE);
592 data->valid = 0;
593 mutex_init(&data->update_lock); 716 mutex_init(&data->update_lock);
594 717
595 /* Tell the I2C layer a new client has arrived */ 718 /* Tell the I2C layer a new client has arrived */
596 if ((err = i2c_attach_client(new_client))) 719 if ((err = i2c_attach_client(client)))
597 goto exit_free; 720 goto exit_free;
598 721
599 /* Initialize the GL520SM chip */ 722 /* Initialize the GL520SM chip */
600 gl520_init_client(new_client); 723 gl520_init_client(client);
601 724
602 /* Register sysfs hooks */ 725 /* Register sysfs hooks */
603 if ((err = sysfs_create_group(&new_client->dev.kobj, &gl520_group))) 726 if ((err = sysfs_create_group(&client->dev.kobj, &gl520_group)))
604 goto exit_detach; 727 goto exit_detach;
605 728
606 if (data->two_temps) { 729 if (data->two_temps) {
607 if ((err = device_create_file(&new_client->dev, 730 if ((err = device_create_file(&client->dev,
608 &dev_attr_temp2_input)) 731 &sensor_dev_attr_temp2_input.dev_attr))
609 || (err = device_create_file(&new_client->dev, 732 || (err = device_create_file(&client->dev,
610 &dev_attr_temp2_max)) 733 &sensor_dev_attr_temp2_max.dev_attr))
611 || (err = device_create_file(&new_client->dev, 734 || (err = device_create_file(&client->dev,
612 &dev_attr_temp2_max_hyst))) 735 &sensor_dev_attr_temp2_max_hyst.dev_attr))
736 || (err = device_create_file(&client->dev,
737 &sensor_dev_attr_temp2_alarm.dev_attr))
738 || (err = device_create_file(&client->dev,
739 &sensor_dev_attr_temp2_beep.dev_attr)))
613 goto exit_remove_files; 740 goto exit_remove_files;
614 } else { 741 } else {
615 if ((err = device_create_file(&new_client->dev, 742 if ((err = device_create_file(&client->dev,
616 &dev_attr_in4_input)) 743 &sensor_dev_attr_in4_input.dev_attr))
617 || (err = device_create_file(&new_client->dev, 744 || (err = device_create_file(&client->dev,
618 &dev_attr_in4_min)) 745 &sensor_dev_attr_in4_min.dev_attr))
619 || (err = device_create_file(&new_client->dev, 746 || (err = device_create_file(&client->dev,
620 &dev_attr_in4_max))) 747 &sensor_dev_attr_in4_max.dev_attr))
748 || (err = device_create_file(&client->dev,
749 &sensor_dev_attr_in4_alarm.dev_attr))
750 || (err = device_create_file(&client->dev,
751 &sensor_dev_attr_in4_beep.dev_attr)))
621 goto exit_remove_files; 752 goto exit_remove_files;
622 } 753 }
623 754
624 755
625 data->hwmon_dev = hwmon_device_register(&new_client->dev); 756 data->hwmon_dev = hwmon_device_register(&client->dev);
626 if (IS_ERR(data->hwmon_dev)) { 757 if (IS_ERR(data->hwmon_dev)) {
627 err = PTR_ERR(data->hwmon_dev); 758 err = PTR_ERR(data->hwmon_dev);
628 goto exit_remove_files; 759 goto exit_remove_files;
@@ -631,10 +762,10 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
631 return 0; 762 return 0;
632 763
633exit_remove_files: 764exit_remove_files:
634 sysfs_remove_group(&new_client->dev.kobj, &gl520_group); 765 sysfs_remove_group(&client->dev.kobj, &gl520_group);
635 sysfs_remove_group(&new_client->dev.kobj, &gl520_group_opt); 766 sysfs_remove_group(&client->dev.kobj, &gl520_group_opt);
636exit_detach: 767exit_detach:
637 i2c_detach_client(new_client); 768 i2c_detach_client(client);
638exit_free: 769exit_free:
639 kfree(data); 770 kfree(data);
640exit: 771exit:
@@ -697,7 +828,7 @@ static int gl520_detach_client(struct i2c_client *client)
697} 828}
698 829
699 830
700/* Registers 0x07 to 0x0c are word-sized, others are byte-sized 831/* Registers 0x07 to 0x0c are word-sized, others are byte-sized
701 GL520 uses a high-byte first convention */ 832 GL520 uses a high-byte first convention */
702static int gl520_read_value(struct i2c_client *client, u8 reg) 833static int gl520_read_value(struct i2c_client *client, u8 reg)
703{ 834{
@@ -720,7 +851,7 @@ static struct gl520_data *gl520_update_device(struct device *dev)
720{ 851{
721 struct i2c_client *client = to_i2c_client(dev); 852 struct i2c_client *client = to_i2c_client(dev);
722 struct gl520_data *data = i2c_get_clientdata(client); 853 struct gl520_data *data = i2c_get_clientdata(client);
723 int val; 854 int val, i;
724 855
725 mutex_lock(&data->update_lock); 856 mutex_lock(&data->update_lock);
726 857
@@ -732,18 +863,13 @@ static struct gl520_data *gl520_update_device(struct device *dev)
732 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); 863 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
733 data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f; 864 data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f;
734 865
735 val = gl520_read_value(client, GL520_REG_IN0_LIMIT); 866 for (i = 0; i < 4; i++) {
736 data->in_min[0] = val & 0xff; 867 data->in_input[i] = gl520_read_value(client,
737 data->in_max[0] = (val >> 8) & 0xff; 868 GL520_REG_IN_INPUT[i]);
738 val = gl520_read_value(client, GL520_REG_IN1_LIMIT); 869 val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]);
739 data->in_min[1] = val & 0xff; 870 data->in_min[i] = val & 0xff;
740 data->in_max[1] = (val >> 8) & 0xff; 871 data->in_max[i] = (val >> 8) & 0xff;
741 val = gl520_read_value(client, GL520_REG_IN2_LIMIT); 872 }
742 data->in_min[2] = val & 0xff;
743 data->in_max[2] = (val >> 8) & 0xff;
744 val = gl520_read_value(client, GL520_REG_IN3_LIMIT);
745 data->in_min[3] = val & 0xff;
746 data->in_max[3] = (val >> 8) & 0xff;
747 873
748 val = gl520_read_value(client, GL520_REG_FAN_INPUT); 874 val = gl520_read_value(client, GL520_REG_FAN_INPUT);
749 data->fan_input[0] = (val >> 8) & 0xff; 875 data->fan_input[0] = (val >> 8) & 0xff;
@@ -753,9 +879,12 @@ static struct gl520_data *gl520_update_device(struct device *dev)
753 data->fan_min[0] = (val >> 8) & 0xff; 879 data->fan_min[0] = (val >> 8) & 0xff;
754 data->fan_min[1] = val & 0xff; 880 data->fan_min[1] = val & 0xff;
755 881
756 data->temp_input[0] = gl520_read_value(client, GL520_REG_TEMP1_INPUT); 882 data->temp_input[0] = gl520_read_value(client,
757 data->temp_max[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX); 883 GL520_REG_TEMP_INPUT[0]);
758 data->temp_max_hyst[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX_HYST); 884 data->temp_max[0] = gl520_read_value(client,
885 GL520_REG_TEMP_MAX[0]);
886 data->temp_max_hyst[0] = gl520_read_value(client,
887 GL520_REG_TEMP_MAX_HYST[0]);
759 888
760 val = gl520_read_value(client, GL520_REG_FAN_DIV); 889 val = gl520_read_value(client, GL520_REG_FAN_DIV);
761 data->fan_div[0] = (val >> 6) & 0x03; 890 data->fan_div[0] = (val >> 6) & 0x03;
@@ -767,20 +896,21 @@ static struct gl520_data *gl520_update_device(struct device *dev)
767 val = gl520_read_value(client, GL520_REG_CONF); 896 val = gl520_read_value(client, GL520_REG_CONF);
768 data->beep_enable = !((val >> 2) & 1); 897 data->beep_enable = !((val >> 2) & 1);
769 898
770 data->in_input[0] = gl520_read_value(client, GL520_REG_IN0_INPUT);
771 data->in_input[1] = gl520_read_value(client, GL520_REG_IN1_INPUT);
772 data->in_input[2] = gl520_read_value(client, GL520_REG_IN2_INPUT);
773 data->in_input[3] = gl520_read_value(client, GL520_REG_IN3_INPUT);
774
775 /* Temp1 and Vin4 are the same input */ 899 /* Temp1 and Vin4 are the same input */
776 if (data->two_temps) { 900 if (data->two_temps) {
777 data->temp_input[1] = gl520_read_value(client, GL520_REG_TEMP2_INPUT); 901 data->temp_input[1] = gl520_read_value(client,
778 data->temp_max[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX); 902 GL520_REG_TEMP_INPUT[1]);
779 data->temp_max_hyst[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX_HYST); 903 data->temp_max[1] = gl520_read_value(client,
904 GL520_REG_TEMP_MAX[1]);
905 data->temp_max_hyst[1] = gl520_read_value(client,
906 GL520_REG_TEMP_MAX_HYST[1]);
780 } else { 907 } else {
781 data->in_input[4] = gl520_read_value(client, GL520_REG_IN4_INPUT); 908 data->in_input[4] = gl520_read_value(client,
782 data->in_min[4] = gl520_read_value(client, GL520_REG_IN4_MIN); 909 GL520_REG_IN_INPUT[4]);
783 data->in_max[4] = gl520_read_value(client, GL520_REG_IN4_MAX); 910 data->in_min[4] = gl520_read_value(client,
911 GL520_REG_IN_MIN[4]);
912 data->in_max[4] = gl520_read_value(client,
913 GL520_REG_IN_MAX[4]);
784 } 914 }
785 915
786 data->last_updated = jiffies; 916 data->last_updated = jiffies;