diff options
Diffstat (limited to 'drivers/hwmon/gl518sm.c')
-rw-r--r-- | drivers/hwmon/gl518sm.c | 269 |
1 files changed, 181 insertions, 88 deletions
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index bb58d9866a37..3b1ac48fce23 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c | |||
@@ -30,10 +30,6 @@ | |||
30 | * We did not keep that part of the original driver in the Linux 2.6 | 30 | * We did not keep that part of the original driver in the Linux 2.6 |
31 | * version, since it was making the driver significantly more complex | 31 | * version, since it was making the driver significantly more complex |
32 | * with no real benefit. | 32 | * with no real benefit. |
33 | * | ||
34 | * History: | ||
35 | * 2004-01-28 Original port. (Hong-Gunn Chew) | ||
36 | * 2004-01-31 Code review and approval. (Jean Delvare) | ||
37 | */ | 33 | */ |
38 | 34 | ||
39 | #include <linux/module.h> | 35 | #include <linux/module.h> |
@@ -42,6 +38,7 @@ | |||
42 | #include <linux/jiffies.h> | 38 | #include <linux/jiffies.h> |
43 | #include <linux/i2c.h> | 39 | #include <linux/i2c.h> |
44 | #include <linux/hwmon.h> | 40 | #include <linux/hwmon.h> |
41 | #include <linux/hwmon-sysfs.h> | ||
45 | #include <linux/err.h> | 42 | #include <linux/err.h> |
46 | #include <linux/mutex.h> | 43 | #include <linux/mutex.h> |
47 | #include <linux/sysfs.h> | 44 | #include <linux/sysfs.h> |
@@ -99,10 +96,10 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
99 | long rpmdiv; | 96 | long rpmdiv; |
100 | if (rpm == 0) | 97 | if (rpm == 0) |
101 | return 0; | 98 | return 0; |
102 | rpmdiv = SENSORS_LIMIT(rpm, 1, 1920000) * div; | 99 | rpmdiv = SENSORS_LIMIT(rpm, 1, 960000) * div; |
103 | return SENSORS_LIMIT((960000 + rpmdiv / 2) / rpmdiv, 1, 255); | 100 | return SENSORS_LIMIT((480000 + rpmdiv / 2) / rpmdiv, 1, 255); |
104 | } | 101 | } |
105 | #define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (960000/((val)*(div)))) | 102 | #define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val)*(div)))) |
106 | 103 | ||
107 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255)) | 104 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255)) |
108 | #define IN_FROM_REG(val) ((val)*19) | 105 | #define IN_FROM_REG(val) ((val)*19) |
@@ -110,7 +107,6 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
110 | #define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255)) | 107 | #define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255)) |
111 | #define VDD_FROM_REG(val) (((val)*95+2)/4) | 108 | #define VDD_FROM_REG(val) (((val)*95+2)/4) |
112 | 109 | ||
113 | #define DIV_TO_REG(val) ((val)==4?2:(val)==2?1:(val)==1?0:3) | ||
114 | #define DIV_FROM_REG(val) (1 << (val)) | 110 | #define DIV_FROM_REG(val) (1 << (val)) |
115 | 111 | ||
116 | #define BEEP_MASK_TO_REG(val) ((val) & 0x7f & data->alarm_mask) | 112 | #define BEEP_MASK_TO_REG(val) ((val) & 0x7f & data->alarm_mask) |
@@ -129,7 +125,6 @@ struct gl518_data { | |||
129 | u8 voltage_in[4]; /* Register values; [0] = VDD */ | 125 | u8 voltage_in[4]; /* Register values; [0] = VDD */ |
130 | u8 voltage_min[4]; /* Register values; [0] = VDD */ | 126 | u8 voltage_min[4]; /* Register values; [0] = VDD */ |
131 | u8 voltage_max[4]; /* Register values; [0] = VDD */ | 127 | u8 voltage_max[4]; /* Register values; [0] = VDD */ |
132 | u8 iter_voltage_in[4]; /* Register values; [0] = VDD */ | ||
133 | u8 fan_in[2]; | 128 | u8 fan_in[2]; |
134 | u8 fan_min[2]; | 129 | u8 fan_min[2]; |
135 | u8 fan_div[2]; /* Register encoding, shifted right */ | 130 | u8 fan_div[2]; /* Register encoding, shifted right */ |
@@ -138,7 +133,7 @@ struct gl518_data { | |||
138 | u8 temp_max; /* Register values */ | 133 | u8 temp_max; /* Register values */ |
139 | u8 temp_hyst; /* Register values */ | 134 | u8 temp_hyst; /* Register values */ |
140 | u8 alarms; /* Register value */ | 135 | u8 alarms; /* Register value */ |
141 | u8 alarm_mask; /* Register value */ | 136 | u8 alarm_mask; |
142 | u8 beep_mask; /* Register value */ | 137 | u8 beep_mask; /* Register value */ |
143 | u8 beep_enable; /* Boolean */ | 138 | u8 beep_enable; /* Boolean */ |
144 | }; | 139 | }; |
@@ -156,7 +151,6 @@ static struct i2c_driver gl518_driver = { | |||
156 | .driver = { | 151 | .driver = { |
157 | .name = "gl518sm", | 152 | .name = "gl518sm", |
158 | }, | 153 | }, |
159 | .id = I2C_DRIVERID_GL518, | ||
160 | .attach_adapter = gl518_attach_adapter, | 154 | .attach_adapter = gl518_attach_adapter, |
161 | .detach_client = gl518_detach_client, | 155 | .detach_client = gl518_detach_client, |
162 | }; | 156 | }; |
@@ -172,24 +166,10 @@ static ssize_t show_##suffix(struct device *dev, struct device_attribute *attr, | |||
172 | return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \ | 166 | return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \ |
173 | } | 167 | } |
174 | 168 | ||
175 | #define show_fan(suffix, value, index) \ | ||
176 | static ssize_t show_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ | ||
177 | { \ | ||
178 | struct gl518_data *data = gl518_update_device(dev); \ | ||
179 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[index], \ | ||
180 | DIV_FROM_REG(data->fan_div[index]))); \ | ||
181 | } | ||
182 | |||
183 | show(TEMP, temp_input1, temp_in); | 169 | show(TEMP, temp_input1, temp_in); |
184 | show(TEMP, temp_max1, temp_max); | 170 | show(TEMP, temp_max1, temp_max); |
185 | show(TEMP, temp_hyst1, temp_hyst); | 171 | show(TEMP, temp_hyst1, temp_hyst); |
186 | show(BOOL, fan_auto1, fan_auto1); | 172 | show(BOOL, fan_auto1, fan_auto1); |
187 | show_fan(fan_input1, fan_in, 0); | ||
188 | show_fan(fan_input2, fan_in, 1); | ||
189 | show_fan(fan_min1, fan_min, 0); | ||
190 | show_fan(fan_min2, fan_min, 1); | ||
191 | show(DIV, fan_div1, fan_div[0]); | ||
192 | show(DIV, fan_div2, fan_div[1]); | ||
193 | show(VDD, in_input0, voltage_in[0]); | 173 | show(VDD, in_input0, voltage_in[0]); |
194 | show(IN, in_input1, voltage_in[1]); | 174 | show(IN, in_input1, voltage_in[1]); |
195 | show(IN, in_input2, voltage_in[2]); | 175 | show(IN, in_input2, voltage_in[2]); |
@@ -206,6 +186,32 @@ show(RAW, alarms, alarms); | |||
206 | show(BOOL, beep_enable, beep_enable); | 186 | show(BOOL, beep_enable, beep_enable); |
207 | show(BEEP_MASK, beep_mask, beep_mask); | 187 | show(BEEP_MASK, beep_mask, beep_mask); |
208 | 188 | ||
189 | static ssize_t show_fan_input(struct device *dev, | ||
190 | struct device_attribute *attr, char *buf) | ||
191 | { | ||
192 | int nr = to_sensor_dev_attr(attr)->index; | ||
193 | struct gl518_data *data = gl518_update_device(dev); | ||
194 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_in[nr], | ||
195 | DIV_FROM_REG(data->fan_div[nr]))); | ||
196 | } | ||
197 | |||
198 | static ssize_t show_fan_min(struct device *dev, | ||
199 | struct device_attribute *attr, char *buf) | ||
200 | { | ||
201 | int nr = to_sensor_dev_attr(attr)->index; | ||
202 | struct gl518_data *data = gl518_update_device(dev); | ||
203 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], | ||
204 | DIV_FROM_REG(data->fan_div[nr]))); | ||
205 | } | ||
206 | |||
207 | static ssize_t show_fan_div(struct device *dev, | ||
208 | struct device_attribute *attr, char *buf) | ||
209 | { | ||
210 | int nr = to_sensor_dev_attr(attr)->index; | ||
211 | struct gl518_data *data = gl518_update_device(dev); | ||
212 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); | ||
213 | } | ||
214 | |||
209 | #define set(type, suffix, value, reg) \ | 215 | #define set(type, suffix, value, reg) \ |
210 | static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ | 216 | static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ |
211 | size_t count) \ | 217 | size_t count) \ |
@@ -247,8 +253,6 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c | |||
247 | set(TEMP, temp_max1, temp_max, GL518_REG_TEMP_MAX); | 253 | set(TEMP, temp_max1, temp_max, GL518_REG_TEMP_MAX); |
248 | set(TEMP, temp_hyst1, temp_hyst, GL518_REG_TEMP_HYST); | 254 | set(TEMP, temp_hyst1, temp_hyst, GL518_REG_TEMP_HYST); |
249 | set_bits(BOOL, fan_auto1, fan_auto1, GL518_REG_MISC, 0x08, 3); | 255 | set_bits(BOOL, fan_auto1, fan_auto1, GL518_REG_MISC, 0x08, 3); |
250 | set_bits(DIV, fan_div1, fan_div[0], GL518_REG_MISC, 0xc0, 6); | ||
251 | set_bits(DIV, fan_div2, fan_div[1], GL518_REG_MISC, 0x30, 4); | ||
252 | set_low(VDD, in_min0, voltage_min[0], GL518_REG_VDD_LIMIT); | 256 | set_low(VDD, in_min0, voltage_min[0], GL518_REG_VDD_LIMIT); |
253 | set_low(IN, in_min1, voltage_min[1], GL518_REG_VIN1_LIMIT); | 257 | set_low(IN, in_min1, voltage_min[1], GL518_REG_VIN1_LIMIT); |
254 | set_low(IN, in_min2, voltage_min[2], GL518_REG_VIN2_LIMIT); | 258 | set_low(IN, in_min2, voltage_min[2], GL518_REG_VIN2_LIMIT); |
@@ -260,25 +264,27 @@ set_high(IN, in_max3, voltage_max[3], GL518_REG_VIN3_LIMIT); | |||
260 | set_bits(BOOL, beep_enable, beep_enable, GL518_REG_CONF, 0x04, 2); | 264 | set_bits(BOOL, beep_enable, beep_enable, GL518_REG_CONF, 0x04, 2); |
261 | set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM); | 265 | set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM); |
262 | 266 | ||
263 | static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 267 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
268 | const char *buf, size_t count) | ||
264 | { | 269 | { |
265 | struct i2c_client *client = to_i2c_client(dev); | 270 | struct i2c_client *client = to_i2c_client(dev); |
266 | struct gl518_data *data = i2c_get_clientdata(client); | 271 | struct gl518_data *data = i2c_get_clientdata(client); |
272 | int nr = to_sensor_dev_attr(attr)->index; | ||
267 | int regvalue; | 273 | int regvalue; |
268 | unsigned long val = simple_strtoul(buf, NULL, 10); | 274 | unsigned long val = simple_strtoul(buf, NULL, 10); |
269 | 275 | ||
270 | mutex_lock(&data->update_lock); | 276 | mutex_lock(&data->update_lock); |
271 | regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); | 277 | regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); |
272 | data->fan_min[0] = FAN_TO_REG(val, | 278 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
273 | DIV_FROM_REG(data->fan_div[0])); | 279 | regvalue = (regvalue & (0xff << (8 * nr))) |
274 | regvalue = (regvalue & 0x00ff) | (data->fan_min[0] << 8); | 280 | | (data->fan_min[nr] << (8 * (1 - nr))); |
275 | gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue); | 281 | gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue); |
276 | 282 | ||
277 | data->beep_mask = gl518_read_value(client, GL518_REG_ALARM); | 283 | data->beep_mask = gl518_read_value(client, GL518_REG_ALARM); |
278 | if (data->fan_min[0] == 0) | 284 | if (data->fan_min[nr] == 0) |
279 | data->alarm_mask &= ~0x20; | 285 | data->alarm_mask &= ~(0x20 << nr); |
280 | else | 286 | else |
281 | data->alarm_mask |= 0x20; | 287 | data->alarm_mask |= (0x20 << nr); |
282 | data->beep_mask &= data->alarm_mask; | 288 | data->beep_mask &= data->alarm_mask; |
283 | gl518_write_value(client, GL518_REG_ALARM, data->beep_mask); | 289 | gl518_write_value(client, GL518_REG_ALARM, data->beep_mask); |
284 | 290 | ||
@@ -286,28 +292,32 @@ static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, c | |||
286 | return count; | 292 | return count; |
287 | } | 293 | } |
288 | 294 | ||
289 | static ssize_t set_fan_min2(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 295 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
296 | const char *buf, size_t count) | ||
290 | { | 297 | { |
291 | struct i2c_client *client = to_i2c_client(dev); | 298 | struct i2c_client *client = to_i2c_client(dev); |
292 | struct gl518_data *data = i2c_get_clientdata(client); | 299 | struct gl518_data *data = i2c_get_clientdata(client); |
300 | int nr = to_sensor_dev_attr(attr)->index; | ||
293 | int regvalue; | 301 | int regvalue; |
294 | unsigned long val = simple_strtoul(buf, NULL, 10); | 302 | unsigned long val = simple_strtoul(buf, NULL, 10); |
295 | 303 | ||
296 | mutex_lock(&data->update_lock); | 304 | switch (val) { |
297 | regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); | 305 | case 1: val = 0; break; |
298 | data->fan_min[1] = FAN_TO_REG(val, | 306 | case 2: val = 1; break; |
299 | DIV_FROM_REG(data->fan_div[1])); | 307 | case 4: val = 2; break; |
300 | regvalue = (regvalue & 0xff00) | data->fan_min[1]; | 308 | case 8: val = 3; break; |
301 | gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue); | 309 | default: |
302 | 310 | dev_err(dev, "Invalid fan clock divider %lu, choose one " | |
303 | data->beep_mask = gl518_read_value(client, GL518_REG_ALARM); | 311 | "of 1, 2, 4 or 8\n", val); |
304 | if (data->fan_min[1] == 0) | 312 | return -EINVAL; |
305 | data->alarm_mask &= ~0x40; | 313 | } |
306 | else | ||
307 | data->alarm_mask |= 0x40; | ||
308 | data->beep_mask &= data->alarm_mask; | ||
309 | gl518_write_value(client, GL518_REG_ALARM, data->beep_mask); | ||
310 | 314 | ||
315 | mutex_lock(&data->update_lock); | ||
316 | regvalue = gl518_read_value(client, GL518_REG_MISC); | ||
317 | data->fan_div[nr] = val; | ||
318 | regvalue = (regvalue & ~(0xc0 >> (2 * nr))) | ||
319 | | (data->fan_div[nr] << (6 - 2 * nr)); | ||
320 | gl518_write_value(client, GL518_REG_MISC, regvalue); | ||
311 | mutex_unlock(&data->update_lock); | 321 | mutex_unlock(&data->update_lock); |
312 | return count; | 322 | return count; |
313 | } | 323 | } |
@@ -317,12 +327,16 @@ static DEVICE_ATTR(temp1_max, S_IWUSR|S_IRUGO, show_temp_max1, set_temp_max1); | |||
317 | static DEVICE_ATTR(temp1_max_hyst, S_IWUSR|S_IRUGO, | 327 | static DEVICE_ATTR(temp1_max_hyst, S_IWUSR|S_IRUGO, |
318 | show_temp_hyst1, set_temp_hyst1); | 328 | show_temp_hyst1, set_temp_hyst1); |
319 | static DEVICE_ATTR(fan1_auto, S_IWUSR|S_IRUGO, show_fan_auto1, set_fan_auto1); | 329 | static DEVICE_ATTR(fan1_auto, S_IWUSR|S_IRUGO, show_fan_auto1, set_fan_auto1); |
320 | static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input1, NULL); | 330 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0); |
321 | static DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input2, NULL); | 331 | static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1); |
322 | static DEVICE_ATTR(fan1_min, S_IWUSR|S_IRUGO, show_fan_min1, set_fan_min1); | 332 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR|S_IRUGO, |
323 | static DEVICE_ATTR(fan2_min, S_IWUSR|S_IRUGO, show_fan_min2, set_fan_min2); | 333 | show_fan_min, set_fan_min, 0); |
324 | static DEVICE_ATTR(fan1_div, S_IWUSR|S_IRUGO, show_fan_div1, set_fan_div1); | 334 | static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR|S_IRUGO, |
325 | static DEVICE_ATTR(fan2_div, S_IWUSR|S_IRUGO, show_fan_div2, set_fan_div2); | 335 | show_fan_min, set_fan_min, 1); |
336 | static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR|S_IRUGO, | ||
337 | show_fan_div, set_fan_div, 0); | ||
338 | static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR|S_IRUGO, | ||
339 | show_fan_div, set_fan_div, 1); | ||
326 | static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL); | 340 | static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL); |
327 | static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL); | 341 | static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL); |
328 | static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL); | 342 | static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL); |
@@ -341,10 +355,62 @@ static DEVICE_ATTR(beep_enable, S_IWUSR|S_IRUGO, | |||
341 | static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO, | 355 | static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO, |
342 | show_beep_mask, set_beep_mask); | 356 | show_beep_mask, set_beep_mask); |
343 | 357 | ||
358 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, | ||
359 | char *buf) | ||
360 | { | ||
361 | int bitnr = to_sensor_dev_attr(attr)->index; | ||
362 | struct gl518_data *data = gl518_update_device(dev); | ||
363 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); | ||
364 | } | ||
365 | |||
366 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); | ||
367 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); | ||
368 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); | ||
369 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); | ||
370 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); | ||
371 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 5); | ||
372 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 6); | ||
373 | |||
374 | static ssize_t show_beep(struct device *dev, struct device_attribute *attr, | ||
375 | char *buf) | ||
376 | { | ||
377 | int bitnr = to_sensor_dev_attr(attr)->index; | ||
378 | struct gl518_data *data = gl518_update_device(dev); | ||
379 | return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1); | ||
380 | } | ||
381 | |||
382 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, | ||
383 | const char *buf, size_t count) | ||
384 | { | ||
385 | struct i2c_client *client = to_i2c_client(dev); | ||
386 | struct gl518_data *data = i2c_get_clientdata(client); | ||
387 | int bitnr = to_sensor_dev_attr(attr)->index; | ||
388 | unsigned long bit; | ||
389 | |||
390 | bit = simple_strtoul(buf, NULL, 10); | ||
391 | if (bit & ~1) | ||
392 | return -EINVAL; | ||
393 | |||
394 | mutex_lock(&data->update_lock); | ||
395 | data->beep_mask = gl518_read_value(client, GL518_REG_ALARM); | ||
396 | if (bit) | ||
397 | data->beep_mask |= (1 << bitnr); | ||
398 | else | ||
399 | data->beep_mask &= ~(1 << bitnr); | ||
400 | gl518_write_value(client, GL518_REG_ALARM, data->beep_mask); | ||
401 | mutex_unlock(&data->update_lock); | ||
402 | return count; | ||
403 | } | ||
404 | |||
405 | static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 0); | ||
406 | static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 1); | ||
407 | static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 2); | ||
408 | static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 3); | ||
409 | static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 4); | ||
410 | static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 5); | ||
411 | static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 6); | ||
412 | |||
344 | static struct attribute *gl518_attributes[] = { | 413 | static struct attribute *gl518_attributes[] = { |
345 | &dev_attr_in0_input.attr, | ||
346 | &dev_attr_in1_input.attr, | ||
347 | &dev_attr_in2_input.attr, | ||
348 | &dev_attr_in3_input.attr, | 414 | &dev_attr_in3_input.attr, |
349 | &dev_attr_in0_min.attr, | 415 | &dev_attr_in0_min.attr, |
350 | &dev_attr_in1_min.attr, | 416 | &dev_attr_in1_min.attr, |
@@ -354,18 +420,32 @@ static struct attribute *gl518_attributes[] = { | |||
354 | &dev_attr_in1_max.attr, | 420 | &dev_attr_in1_max.attr, |
355 | &dev_attr_in2_max.attr, | 421 | &dev_attr_in2_max.attr, |
356 | &dev_attr_in3_max.attr, | 422 | &dev_attr_in3_max.attr, |
423 | &sensor_dev_attr_in0_alarm.dev_attr.attr, | ||
424 | &sensor_dev_attr_in1_alarm.dev_attr.attr, | ||
425 | &sensor_dev_attr_in2_alarm.dev_attr.attr, | ||
426 | &sensor_dev_attr_in3_alarm.dev_attr.attr, | ||
427 | &sensor_dev_attr_in0_beep.dev_attr.attr, | ||
428 | &sensor_dev_attr_in1_beep.dev_attr.attr, | ||
429 | &sensor_dev_attr_in2_beep.dev_attr.attr, | ||
430 | &sensor_dev_attr_in3_beep.dev_attr.attr, | ||
357 | 431 | ||
358 | &dev_attr_fan1_auto.attr, | 432 | &dev_attr_fan1_auto.attr, |
359 | &dev_attr_fan1_input.attr, | 433 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
360 | &dev_attr_fan2_input.attr, | 434 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
361 | &dev_attr_fan1_min.attr, | 435 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
362 | &dev_attr_fan2_min.attr, | 436 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
363 | &dev_attr_fan1_div.attr, | 437 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
364 | &dev_attr_fan2_div.attr, | 438 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
439 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, | ||
440 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, | ||
441 | &sensor_dev_attr_fan1_beep.dev_attr.attr, | ||
442 | &sensor_dev_attr_fan2_beep.dev_attr.attr, | ||
365 | 443 | ||
366 | &dev_attr_temp1_input.attr, | 444 | &dev_attr_temp1_input.attr, |
367 | &dev_attr_temp1_max.attr, | 445 | &dev_attr_temp1_max.attr, |
368 | &dev_attr_temp1_max_hyst.attr, | 446 | &dev_attr_temp1_max_hyst.attr, |
447 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, | ||
448 | &sensor_dev_attr_temp1_beep.dev_attr.attr, | ||
369 | 449 | ||
370 | &dev_attr_alarms.attr, | 450 | &dev_attr_alarms.attr, |
371 | &dev_attr_beep_enable.attr, | 451 | &dev_attr_beep_enable.attr, |
@@ -377,6 +457,17 @@ static const struct attribute_group gl518_group = { | |||
377 | .attrs = gl518_attributes, | 457 | .attrs = gl518_attributes, |
378 | }; | 458 | }; |
379 | 459 | ||
460 | static struct attribute *gl518_attributes_r80[] = { | ||
461 | &dev_attr_in0_input.attr, | ||
462 | &dev_attr_in1_input.attr, | ||
463 | &dev_attr_in2_input.attr, | ||
464 | NULL | ||
465 | }; | ||
466 | |||
467 | static const struct attribute_group gl518_group_r80 = { | ||
468 | .attrs = gl518_attributes_r80, | ||
469 | }; | ||
470 | |||
380 | /* | 471 | /* |
381 | * Real code | 472 | * Real code |
382 | */ | 473 | */ |
@@ -391,7 +482,7 @@ static int gl518_attach_adapter(struct i2c_adapter *adapter) | |||
391 | static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | 482 | static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) |
392 | { | 483 | { |
393 | int i; | 484 | int i; |
394 | struct i2c_client *new_client; | 485 | struct i2c_client *client; |
395 | struct gl518_data *data; | 486 | struct gl518_data *data; |
396 | int err = 0; | 487 | int err = 0; |
397 | 488 | ||
@@ -408,25 +499,24 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | |||
408 | goto exit; | 499 | goto exit; |
409 | } | 500 | } |
410 | 501 | ||
411 | new_client = &data->client; | 502 | client = &data->client; |
412 | i2c_set_clientdata(new_client, data); | 503 | i2c_set_clientdata(client, data); |
413 | 504 | ||
414 | new_client->addr = address; | 505 | client->addr = address; |
415 | new_client->adapter = adapter; | 506 | client->adapter = adapter; |
416 | new_client->driver = &gl518_driver; | 507 | client->driver = &gl518_driver; |
417 | new_client->flags = 0; | ||
418 | 508 | ||
419 | /* Now, we do the remaining detection. */ | 509 | /* Now, we do the remaining detection. */ |
420 | 510 | ||
421 | if (kind < 0) { | 511 | if (kind < 0) { |
422 | if ((gl518_read_value(new_client, GL518_REG_CHIP_ID) != 0x80) | 512 | if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80) |
423 | || (gl518_read_value(new_client, GL518_REG_CONF) & 0x80)) | 513 | || (gl518_read_value(client, GL518_REG_CONF) & 0x80)) |
424 | goto exit_free; | 514 | goto exit_free; |
425 | } | 515 | } |
426 | 516 | ||
427 | /* Determine the chip type. */ | 517 | /* Determine the chip type. */ |
428 | if (kind <= 0) { | 518 | if (kind <= 0) { |
429 | i = gl518_read_value(new_client, GL518_REG_REVISION); | 519 | i = gl518_read_value(client, GL518_REG_REVISION); |
430 | if (i == 0x00) { | 520 | if (i == 0x00) { |
431 | kind = gl518sm_r00; | 521 | kind = gl518sm_r00; |
432 | } else if (i == 0x80) { | 522 | } else if (i == 0x80) { |
@@ -442,25 +532,27 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | |||
442 | } | 532 | } |
443 | 533 | ||
444 | /* Fill in the remaining client fields */ | 534 | /* Fill in the remaining client fields */ |
445 | strlcpy(new_client->name, "gl518sm", I2C_NAME_SIZE); | 535 | strlcpy(client->name, "gl518sm", I2C_NAME_SIZE); |
446 | data->type = kind; | 536 | data->type = kind; |
447 | data->valid = 0; | ||
448 | mutex_init(&data->update_lock); | 537 | mutex_init(&data->update_lock); |
449 | 538 | ||
450 | /* Tell the I2C layer a new client has arrived */ | 539 | /* Tell the I2C layer a new client has arrived */ |
451 | if ((err = i2c_attach_client(new_client))) | 540 | if ((err = i2c_attach_client(client))) |
452 | goto exit_free; | 541 | goto exit_free; |
453 | 542 | ||
454 | /* Initialize the GL518SM chip */ | 543 | /* Initialize the GL518SM chip */ |
455 | data->alarm_mask = 0xff; | 544 | data->alarm_mask = 0xff; |
456 | data->voltage_in[0]=data->voltage_in[1]=data->voltage_in[2]=0; | 545 | gl518_init_client(client); |
457 | gl518_init_client((struct i2c_client *) new_client); | ||
458 | 546 | ||
459 | /* Register sysfs hooks */ | 547 | /* Register sysfs hooks */ |
460 | if ((err = sysfs_create_group(&new_client->dev.kobj, &gl518_group))) | 548 | if ((err = sysfs_create_group(&client->dev.kobj, &gl518_group))) |
461 | goto exit_detach; | 549 | goto exit_detach; |
550 | if (data->type == gl518sm_r80) | ||
551 | if ((err = sysfs_create_group(&client->dev.kobj, | ||
552 | &gl518_group_r80))) | ||
553 | goto exit_remove_files; | ||
462 | 554 | ||
463 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 555 | data->hwmon_dev = hwmon_device_register(&client->dev); |
464 | if (IS_ERR(data->hwmon_dev)) { | 556 | if (IS_ERR(data->hwmon_dev)) { |
465 | err = PTR_ERR(data->hwmon_dev); | 557 | err = PTR_ERR(data->hwmon_dev); |
466 | goto exit_remove_files; | 558 | goto exit_remove_files; |
@@ -469,9 +561,11 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | |||
469 | return 0; | 561 | return 0; |
470 | 562 | ||
471 | exit_remove_files: | 563 | exit_remove_files: |
472 | sysfs_remove_group(&new_client->dev.kobj, &gl518_group); | 564 | sysfs_remove_group(&client->dev.kobj, &gl518_group); |
565 | if (data->type == gl518sm_r80) | ||
566 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); | ||
473 | exit_detach: | 567 | exit_detach: |
474 | i2c_detach_client(new_client); | 568 | i2c_detach_client(client); |
475 | exit_free: | 569 | exit_free: |
476 | kfree(data); | 570 | kfree(data); |
477 | exit: | 571 | exit: |
@@ -504,6 +598,8 @@ static int gl518_detach_client(struct i2c_client *client) | |||
504 | 598 | ||
505 | hwmon_device_unregister(data->hwmon_dev); | 599 | hwmon_device_unregister(data->hwmon_dev); |
506 | sysfs_remove_group(&client->dev.kobj, &gl518_group); | 600 | sysfs_remove_group(&client->dev.kobj, &gl518_group); |
601 | if (data->type == gl518sm_r80) | ||
602 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); | ||
507 | 603 | ||
508 | if ((err = i2c_detach_client(client))) | 604 | if ((err = i2c_detach_client(client))) |
509 | return err; | 605 | return err; |
@@ -512,9 +608,9 @@ static int gl518_detach_client(struct i2c_client *client) | |||
512 | return 0; | 608 | return 0; |
513 | } | 609 | } |
514 | 610 | ||
515 | /* Registers 0x07 to 0x0c are word-sized, others are byte-sized | 611 | /* Registers 0x07 to 0x0c are word-sized, others are byte-sized |
516 | GL518 uses a high-byte first convention, which is exactly opposite to | 612 | GL518 uses a high-byte first convention, which is exactly opposite to |
517 | the usual practice. */ | 613 | the SMBus standard. */ |
518 | static int gl518_read_value(struct i2c_client *client, u8 reg) | 614 | static int gl518_read_value(struct i2c_client *client, u8 reg) |
519 | { | 615 | { |
520 | if ((reg >= 0x07) && (reg <= 0x0c)) | 616 | if ((reg >= 0x07) && (reg <= 0x0c)) |
@@ -523,9 +619,6 @@ static int gl518_read_value(struct i2c_client *client, u8 reg) | |||
523 | return i2c_smbus_read_byte_data(client, reg); | 619 | return i2c_smbus_read_byte_data(client, reg); |
524 | } | 620 | } |
525 | 621 | ||
526 | /* Registers 0x07 to 0x0c are word-sized, others are byte-sized | ||
527 | GL518 uses a high-byte first convention, which is exactly opposite to | ||
528 | the usual practice. */ | ||
529 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) | 622 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) |
530 | { | 623 | { |
531 | if ((reg >= 0x07) && (reg <= 0x0c)) | 624 | if ((reg >= 0x07) && (reg <= 0x0c)) |