| Linux kernel & device driver programming |
| [ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] |
1 /* 1
2 gl520sm.c - Part of lm_sensors, Linux kern
3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard
5 Kyösti Mälkki
6 Copyright (c) 2005 Maarten Deprez <
7
8 This program is free software; you can red
9 it under the terms of the GNU General Publ
10 the Free Software Foundation; either versi
11 (at your option) any later version.
12
13 This program is distributed in the hope th
14 but WITHOUT ANY WARRANTY; without even the
15 MERCHANTABILITY or FITNESS FOR A PARTICULA
16 GNU General Public License for more detail
17
18 You should have received a copy of the GNU
19 along with this program; if not, write to
20 Foundation, Inc., 675 Mass Ave, Cambridge,
21
22 */
23
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/slab.h>
27 #include <linux/jiffies.h>
28 #include <linux/i2c.h>
29 #include <linux/hwmon.h>
30 #include <linux/hwmon-sysfs.h>
31 #include <linux/hwmon-vid.h>
32 #include <linux/err.h>
33 #include <linux/mutex.h>
34 #include <linux/sysfs.h>
35
36 /* Type of the extra sensor */
37 static unsigned short extra_sensor_type;
38 module_param(extra_sensor_type, ushort, 0);
39 MODULE_PARM_DESC(extra_sensor_type, "Type of e
40
41 /* Addresses to scan */
42 static const unsigned short normal_i2c[] = { 0
43
44 /* Insmod parameters */
45 I2C_CLIENT_INSMOD_1(gl520sm);
46
47 /* Many GL520 constants specified below
48 One of the inputs can be configured as either
49 That's why _TEMP2 and _IN4 access the same reg
50 */
51
52 /* The GL520 registers */
53 #define GL520_REG_CHIP_ID 0x00
54 #define GL520_REG_REVISION 0x01
55 #define GL520_REG_CONF 0x03
56 #define GL520_REG_MASK 0x11
57
58 #define GL520_REG_VID_INPUT 0x02
59
60 static const u8 GL520_REG_IN_INPUT[] = { 0x
61 static const u8 GL520_REG_IN_LIMIT[] = { 0x
62 static const u8 GL520_REG_IN_MIN[] = { 0x
63 static const u8 GL520_REG_IN_MAX[] = { 0x
64
65 static const u8 GL520_REG_TEMP_INPUT[]
66 static const u8 GL520_REG_TEMP_MAX[]
67 static const u8 GL520_REG_TEMP_MAX_HYST[]
68
69 #define GL520_REG_FAN_INPUT 0x07
70 #define GL520_REG_FAN_MIN 0x08
71 #define GL520_REG_FAN_DIV 0x0f
72 #define GL520_REG_FAN_OFF GL520_
73
74 #define GL520_REG_ALARMS 0x12
75 #define GL520_REG_BEEP_MASK 0x10
76 #define GL520_REG_BEEP_ENABLE GL520_
77
78 /*
79 * Function declarations
80 */
81
82 static int gl520_probe(struct i2c_client *clie
83 const struct i2c_device
84 static int gl520_detect(struct i2c_client *cli
85 struct i2c_board_info
86 static void gl520_init_client(struct i2c_clien
87 static int gl520_remove(struct i2c_client *cli
88 static int gl520_read_value(struct i2c_client
89 static int gl520_write_value(struct i2c_client
90 static struct gl520_data *gl520_update_device(
91
92 /* Driver data */
93 static const struct i2c_device_id gl520_id[] =
94 { "gl520sm", gl520sm },
95 { }
96 };
97 MODULE_DEVICE_TABLE(i2c, gl520_id);
98
99 static struct i2c_driver gl520_driver = {
100 .class = I2C_CLASS_HWMON,
101 .driver = {
102 .name = "gl520sm",
103 },
104 .probe = gl520_probe,
105 .remove = gl520_remove,
106 .id_table = gl520_id,
107 .detect = gl520_detect,
108 .address_data = &addr_data,
109 };
110
111 /* Client data */
112 struct gl520_data {
113 struct device *hwmon_dev;
114 struct mutex update_lock;
115 char valid; /* zero until
116 unsigned long last_updated; /* in
117
118 u8 vid;
119 u8 vrm;
120 u8 in_input[5]; /* [0] = VVD *
121 u8 in_min[5]; /* [0] = VDD *
122 u8 in_max[5]; /* [0] = VDD *
123 u8 fan_input[2];
124 u8 fan_min[2];
125 u8 fan_div[2];
126 u8 fan_off;
127 u8 temp_input[2];
128 u8 temp_max[2];
129 u8 temp_max_hyst[2];
130 u8 alarms;
131 u8 beep_enable;
132 u8 beep_mask;
133 u8 alarm_mask;
134 u8 two_temps;
135 };
136
137 /*
138 * Sysfs stuff
139 */
140
141 static ssize_t get_cpu_vid(struct device *dev,
142 char *buf)
143 {
144 struct gl520_data *data = gl520_update
145 return sprintf(buf, "%u\n", vid_from_r
146 }
147 static DEVICE_ATTR(cpu0_vid, S_IRUGO, get_cpu_
148
149 #define VDD_FROM_REG(val) (((val)*95+2)/4)
150 #define VDD_TO_REG(val) (SENSORS_LIMIT((((val)
151
152 #define IN_FROM_REG(val) ((val)*19)
153 #define IN_TO_REG(val) (SENSORS_LIMIT((((val)+
154
155 static ssize_t get_in_input(struct device *dev
156 char *buf)
157 {
158 int n = to_sensor_dev_attr(attr)->inde
159 struct gl520_data *data = gl520_update
160 u8 r = data->in_input[n];
161
162 if (n == 0)
163 return sprintf(buf, "%d\n", VD
164 else
165 return sprintf(buf, "%d\n", IN
166 }
167
168 static ssize_t get_in_min(struct device *dev,
169 char *buf)
170 {
171 int n = to_sensor_dev_attr(attr)->inde
172 struct gl520_data *data = gl520_update
173 u8 r = data->in_min[n];
174
175 if (n == 0)
176 return sprintf(buf, "%d\n", VD
177 else
178 return sprintf(buf, "%d\n", IN
179 }
180
181 static ssize_t get_in_max(struct device *dev,
182 char *buf)
183 {
184 int n = to_sensor_dev_attr(attr)->inde
185 struct gl520_data *data = gl520_update
186 u8 r = data->in_max[n];
187
188 if (n == 0)
189 return sprintf(buf, "%d\n", VD
190 else
191 return sprintf(buf, "%d\n", IN
192 }
193
194 static ssize_t set_in_min(struct device *dev,
195 const char *buf, siz
196 {
197 struct i2c_client *client = to_i2c_cli
198 struct gl520_data *data = i2c_get_clie
199 int n = to_sensor_dev_attr(attr)->inde
200 long v = simple_strtol(buf, NULL, 10);
201 u8 r;
202
203 mutex_lock(&data->update_lock);
204
205 if (n == 0)
206 r = VDD_TO_REG(v);
207 else
208 r = IN_TO_REG(v);
209
210 data->in_min[n] = r;
211
212 if (n < 4)
213 gl520_write_value(client, GL52
214 (gl520_read_
215 & ~0xff) |
216 else
217 gl520_write_value(client, GL52
218
219 mutex_unlock(&data->update_lock);
220 return count;
221 }
222
223 static ssize_t set_in_max(struct device *dev,
224 const char *buf, siz
225 {
226 struct i2c_client *client = to_i2c_cli
227 struct gl520_data *data = i2c_get_clie
228 int n = to_sensor_dev_attr(attr)->inde
229 long v = simple_strtol(buf, NULL, 10);
230 u8 r;
231
232 if (n == 0)
233 r = VDD_TO_REG(v);
234 else
235 r = IN_TO_REG(v);
236
237 mutex_lock(&data->update_lock);
238
239 data->in_max[n] = r;
240
241 if (n < 4)
242 gl520_write_value(client, GL52
243 (gl520_read_
244 & ~0xff00)
245 else
246 gl520_write_value(client, GL52
247
248 mutex_unlock(&data->update_lock);
249 return count;
250 }
251
252 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO,
253 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO,
254 static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO,
255 static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO,
256 static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO,
257 static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO | S
258 get_in_min, set_in_min, 0);
259 static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S
260 get_in_min, set_in_min, 1);
261 static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S
262 get_in_min, set_in_min, 2);
263 static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO | S
264 get_in_min, set_in_min, 3);
265 static SENSOR_DEVICE_ATTR(in4_min, S_IRUGO | S
266 get_in_min, set_in_min, 4);
267 static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO | S
268 get_in_max, set_in_max, 0);
269 static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S
270 get_in_max, set_in_max, 1);
271 static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S
272 get_in_max, set_in_max, 2);
273 static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO | S
274 get_in_max, set_in_max, 3);
275 static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S
276 get_in_max, set_in_max, 4);
277
278 #define DIV_FROM_REG(val) (1 << (val))
279 #define FAN_FROM_REG(val,div) ((val)==0 ? 0 :
280 #define FAN_TO_REG(val,div) ((val)<=0?0:SENSOR
281
282 static ssize_t get_fan_input(struct device *de
283 char *buf)
284 {
285 int n = to_sensor_dev_attr(attr)->inde
286 struct gl520_data *data = gl520_update
287
288 return sprintf(buf, "%d\n", FAN_FROM_R
289
290 }
291
292 static ssize_t get_fan_min(struct device *dev,
293 char *buf)
294 {
295 int n = to_sensor_dev_attr(attr)->inde
296 struct gl520_data *data = gl520_update
297
298 return sprintf(buf, "%d\n", FAN_FROM_R
299
300 }
301
302 static ssize_t get_fan_div(struct device *dev,
303 char *buf)
304 {
305 int n = to_sensor_dev_attr(attr)->inde
306 struct gl520_data *data = gl520_update
307
308 return sprintf(buf, "%d\n", DIV_FROM_R
309 }
310
311 static ssize_t get_fan_off(struct device *dev,
312 char *buf)
313 {
314 struct gl520_data *data = gl520_update
315 return sprintf(buf, "%d\n", data->fan_
316 }
317
318 static ssize_t set_fan_min(struct device *dev,
319 const char *buf, si
320 {
321 struct i2c_client *client = to_i2c_cli
322 struct gl520_data *data = i2c_get_clie
323 int n = to_sensor_dev_attr(attr)->inde
324 unsigned long v = simple_strtoul(buf,
325 u8 r;
326
327 mutex_lock(&data->update_lock);
328 r = FAN_TO_REG(v, data->fan_div[n]);
329 data->fan_min[n] = r;
330
331 if (n == 0)
332 gl520_write_value(client, GL52
333 (gl520_read_
334 & ~0xff00)
335 else
336 gl520_write_value(client, GL52
337 (gl520_read_
338 & ~0xff) |
339
340 data->beep_mask = gl520_read_value(cli
341 if (data->fan_min[n] == 0)
342 data->alarm_mask &= (n == 0) ?
343 else
344 data->alarm_mask |= (n == 0) ?
345 data->beep_mask &= data->alarm_mask;
346 gl520_write_value(client, GL520_REG_BE
347
348 mutex_unlock(&data->update_lock);
349 return count;
350 }
351
352 static ssize_t set_fan_div(struct device *dev,
353 const char *buf, si
354 {
355 struct i2c_client *client = to_i2c_cli
356 struct gl520_data *data = i2c_get_clie
357 int n = to_sensor_dev_attr(attr)->inde
358 unsigned long v = simple_strtoul(buf,
359 u8 r;
360
361 switch (v) {
362 case 1: r = 0; break;
363 case 2: r = 1; break;
364 case 4: r = 2; break;
365 case 8: r = 3; break;
366 default:
367 dev_err(&client->dev, "fan_div
368 return -EINVAL;
369 }
370
371 mutex_lock(&data->update_lock);
372 data->fan_div[n] = r;
373
374 if (n == 0)
375 gl520_write_value(client, GL52
376 (gl520_read_
377 & ~0xc0) |
378 else
379 gl520_write_value(client, GL52
380 (gl520_read_
381 & ~0x30) |
382
383 mutex_unlock(&data->update_lock);
384 return count;
385 }
386
387 static ssize_t set_fan_off(struct device *dev,
388 const char *buf, si
389 {
390 struct i2c_client *client = to_i2c_cli
391 struct gl520_data *data = i2c_get_clie
392 u8 r = simple_strtoul(buf, NULL, 10)?1
393
394 mutex_lock(&data->update_lock);
395 data->fan_off = r;
396 gl520_write_value(client, GL520_REG_FA
397 (gl520_read_value(cl
398 & ~0x0c) | (r << 2)
399 mutex_unlock(&data->update_lock);
400 return count;
401 }
402
403 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO,
404 static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO,
405 static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO |
406 get_fan_min, set_fan_min, 0);
407 static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO |
408 get_fan_min, set_fan_min, 1);
409 static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO |
410 get_fan_div, set_fan_div, 0);
411 static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO |
412 get_fan_div, set_fan_div, 1);
413 static DEVICE_ATTR(fan1_off, S_IRUGO | S_IWUSR
414 get_fan_off, set_fan_off);
415
416 #define TEMP_FROM_REG(val) (((val) - 130) * 10
417 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((((va
418
419 static ssize_t get_temp_input(struct device *d
420 char *buf)
421 {
422 int n = to_sensor_dev_attr(attr)->inde
423 struct gl520_data *data = gl520_update
424
425 return sprintf(buf, "%d\n", TEMP_FROM_
426 }
427
428 static ssize_t get_temp_max(struct device *dev
429 char *buf)
430 {
431 int n = to_sensor_dev_attr(attr)->inde
432 struct gl520_data *data = gl520_update
433
434 return sprintf(buf, "%d\n", TEMP_FROM_
435 }
436
437 static ssize_t get_temp_max_hyst(struct device
438 *attr, char *
439 {
440 int n = to_sensor_dev_attr(attr)->inde
441 struct gl520_data *data = gl520_update
442
443 return sprintf(buf, "%d\n", TEMP_FROM_
444 }
445
446 static ssize_t set_temp_max(struct device *dev
447 const char *buf, s
448 {
449 struct i2c_client *client = to_i2c_cli
450 struct gl520_data *data = i2c_get_clie
451 int n = to_sensor_dev_attr(attr)->inde
452 long v = simple_strtol(buf, NULL, 10);
453
454 mutex_lock(&data->update_lock);
455 data->temp_max[n] = TEMP_TO_REG(v);
456 gl520_write_value(client, GL520_REG_TE
457 mutex_unlock(&data->update_lock);
458 return count;
459 }
460
461 static ssize_t set_temp_max_hyst(struct device
462 *attr, const
463 {
464 struct i2c_client *client = to_i2c_cli
465 struct gl520_data *data = i2c_get_clie
466 int n = to_sensor_dev_attr(attr)->inde
467 long v = simple_strtol(buf, NULL, 10);
468
469 mutex_lock(&data->update_lock);
470 data->temp_max_hyst[n] = TEMP_TO_REG(v
471 gl520_write_value(client, GL520_REG_TE
472 data->temp_max_hyst[
473 mutex_unlock(&data->update_lock);
474 return count;
475 }
476
477 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO
478 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO
479 static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO |
480 get_temp_max, set_temp_max, 0)
481 static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO |
482 get_temp_max, set_temp_max, 1)
483 static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IR
484 get_temp_max_hyst, set_temp_ma
485 static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IR
486 get_temp_max_hyst, set_temp_ma
487
488 static ssize_t get_alarms(struct device *dev,
489 char *buf)
490 {
491 struct gl520_data *data = gl520_update
492 return sprintf(buf, "%d\n", data->alar
493 }
494
495 static ssize_t get_beep_enable(struct device *
496 *attr, char *bu
497 {
498 struct gl520_data *data = gl520_update
499 return sprintf(buf, "%d\n", data->beep
500 }
501
502 static ssize_t get_beep_mask(struct device *de
503 char *buf)
504 {
505 struct gl520_data *data = gl520_update
506 return sprintf(buf, "%d\n", data->beep
507 }
508
509 static ssize_t set_beep_enable(struct device *
510 *attr, const ch
511 {
512 struct i2c_client *client = to_i2c_cli
513 struct gl520_data *data = i2c_get_clie
514 u8 r = simple_strtoul(buf, NULL, 10)?0
515
516 mutex_lock(&data->update_lock);
517 data->beep_enable = !r;
518 gl520_write_value(client, GL520_REG_BE
519 (gl520_read_value(cl
520 & ~0x04) | (r << 2)
521 mutex_unlock(&data->update_lock);
522 return count;
523 }
524
525 static ssize_t set_beep_mask(struct device *de
526 const char *buf,
527 {
528 struct i2c_client *client = to_i2c_cli
529 struct gl520_data *data = i2c_get_clie
530 u8 r = simple_strtoul(buf, NULL, 10);
531
532 mutex_lock(&data->update_lock);
533 r &= data->alarm_mask;
534 data->beep_mask = r;
535 gl520_write_value(client, GL520_REG_BE
536 mutex_unlock(&data->update_lock);
537 return count;
538 }
539
540 static DEVICE_ATTR(alarms, S_IRUGO, get_alarms
541 static DEVICE_ATTR(beep_enable, S_IRUGO | S_IW
542 get_beep_enable, set_beep_enab
543 static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUS
544 get_beep_mask, set_beep_mask);
545
546 static ssize_t get_alarm(struct device *dev, s
547 char *buf)
548 {
549 int bit_nr = to_sensor_dev_attr(attr)-
550 struct gl520_data *data = gl520_update
551
552 return sprintf(buf, "%d\n", (data->ala
553 }
554
555 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO,
556 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO,
557 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO,
558 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO,
559 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO
560 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO,
561 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO,
562 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO
563 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO,
564
565 static ssize_t get_beep(struct device *dev, st
566 char *buf)
567 {
568 int bitnr = to_sensor_dev_attr(attr)->
569 struct gl520_data *data = gl520_update
570
571 return sprintf(buf, "%d\n", (data->bee
572 }
573
574 static ssize_t set_beep(struct device *dev, st
575 const char *buf, size_
576 {
577 struct i2c_client *client = to_i2c_cli
578 struct gl520_data *data = i2c_get_clie
579 int bitnr = to_sensor_dev_attr(attr)->
580 unsigned long bit;
581
582 bit = simple_strtoul(buf, NULL, 10);
583 if (bit & ~1)
584 return -EINVAL;
585
586 mutex_lock(&data->update_lock);
587 data->beep_mask = gl520_read_value(cli
588 if (bit)
589 data->beep_mask |= (1 << bitnr
590 else
591 data->beep_mask &= ~(1 << bitn
592 gl520_write_value(client, GL520_REG_BE
593 mutex_unlock(&data->update_lock);
594 return count;
595 }
596
597 static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO |
598 static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO |
599 static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO |
600 static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO |
601 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO
602 static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO |
603 static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO |
604 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO
605 static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO |
606
607 static struct attribute *gl520_attributes[] =
608 &dev_attr_cpu0_vid.attr,
609
610 &sensor_dev_attr_in0_input.dev_attr.at
611 &sensor_dev_attr_in0_min.dev_attr.attr
612 &sensor_dev_attr_in0_max.dev_attr.attr
613 &sensor_dev_attr_in0_alarm.dev_attr.at
614 &sensor_dev_attr_in0_beep.dev_attr.att
615 &sensor_dev_attr_in1_input.dev_attr.at
616 &sensor_dev_attr_in1_min.dev_attr.attr
617 &sensor_dev_attr_in1_max.dev_attr.attr
618 &sensor_dev_attr_in1_alarm.dev_attr.at
619 &sensor_dev_attr_in1_beep.dev_attr.att
620 &sensor_dev_attr_in2_input.dev_attr.at
621 &sensor_dev_attr_in2_min.dev_attr.attr
622 &sensor_dev_attr_in2_max.dev_attr.attr
623 &sensor_dev_attr_in2_alarm.dev_attr.at
624 &sensor_dev_attr_in2_beep.dev_attr.att
625 &sensor_dev_attr_in3_input.dev_attr.at
626 &sensor_dev_attr_in3_min.dev_attr.attr
627 &sensor_dev_attr_in3_max.dev_attr.attr
628 &sensor_dev_attr_in3_alarm.dev_attr.at
629 &sensor_dev_attr_in3_beep.dev_attr.att
630
631 &sensor_dev_attr_fan1_input.dev_attr.a
632 &sensor_dev_attr_fan1_min.dev_attr.att
633 &sensor_dev_attr_fan1_div.dev_attr.att
634 &sensor_dev_attr_fan1_alarm.dev_attr.a
635 &sensor_dev_attr_fan1_beep.dev_attr.at
636 &dev_attr_fan1_off.attr,
637 &sensor_dev_attr_fan2_input.dev_attr.a
638 &sensor_dev_attr_fan2_min.dev_attr.att
639 &sensor_dev_attr_fan2_div.dev_attr.att
640 &sensor_dev_attr_fan2_alarm.dev_attr.a
641 &sensor_dev_attr_fan2_beep.dev_attr.at
642
643 &sensor_dev_attr_temp1_input.dev_attr.
644 &sensor_dev_attr_temp1_max.dev_attr.at
645 &sensor_dev_attr_temp1_max_hyst.dev_at
646 &sensor_dev_attr_temp1_alarm.dev_attr.
647 &sensor_dev_attr_temp1_beep.dev_attr.a
648
649 &dev_attr_alarms.attr,
650 &dev_attr_beep_enable.attr,
651 &dev_attr_beep_mask.attr,
652 NULL
653 };
654
655 static const struct attribute_group gl520_grou
656 .attrs = gl520_attributes,
657 };
658
659 static struct attribute *gl520_attributes_opt[
660 &sensor_dev_attr_in4_input.dev_attr.at
661 &sensor_dev_attr_in4_min.dev_attr.attr
662 &sensor_dev_attr_in4_max.dev_attr.attr
663 &sensor_dev_attr_in4_alarm.dev_attr.at
664 &sensor_dev_attr_in4_beep.dev_attr.att
665
666 &sensor_dev_attr_temp2_input.dev_attr.
667 &sensor_dev_attr_temp2_max.dev_attr.at
668 &sensor_dev_attr_temp2_max_hyst.dev_at
669 &sensor_dev_attr_temp2_alarm.dev_attr.
670 &sensor_dev_attr_temp2_beep.dev_attr.a
671 NULL
672 };
673
674 static const struct attribute_group gl520_grou
675 .attrs = gl520_attributes_opt,
676 };
677
678
679 /*
680 * Real code
681 */
682
683 /* Return 0 if detection is successful, -ENODE
684 static int gl520_detect(struct i2c_client *cli
685 struct i2c_board_info
686 {
687 struct i2c_adapter *adapter = client->
688
689 if (!i2c_check_functionality(adapter,
690 I2C_FUNC_
691 return -ENODEV;
692
693 /* Determine the chip type. */
694 if (kind < 0) {
695 if ((gl520_read_value(client,
696 ((gl520_read_value(client,
697 ((gl520_read_value(client,
698 dev_dbg(&client->dev,
699 return -ENODEV;
700 }
701 }
702
703 strlcpy(info->type, "gl520sm", I2C_NAM
704
705 return 0;
706 }
707
708 static int gl520_probe(struct i2c_client *clie
709 const struct i2c_device
710 {
711 struct gl520_data *data;
712 int err;
713
714 data = kzalloc(sizeof(struct gl520_dat
715 if (!data) {
716 err = -ENOMEM;
717 goto exit;
718 }
719
720 i2c_set_clientdata(client, data);
721 mutex_init(&data->update_lock);
722
723 /* Initialize the GL520SM chip */
724 gl520_init_client(client);
725
726 /* Register sysfs hooks */
727 if ((err = sysfs_create_group(&client-
728 goto exit_free;
729
730 if (data->two_temps) {
731 if ((err = device_create_file(
732 &sensor_dev_at
733 || (err = device_create_file(
734 &sensor_dev_at
735 || (err = device_create_file(
736 &sensor_dev_at
737 || (err = device_create_file(
738 &sensor_dev_at
739 || (err = device_create_file(
740 &sensor_dev_at
741 goto exit_remove_files
742 } else {
743 if ((err = device_create_file(
744 &sensor_dev_at
745 || (err = device_create_file(
746 &sensor_dev_at
747 || (err = device_create_file(
748 &sensor_dev_at
749 || (err = device_create_file(
750 &sensor_dev_at
751 || (err = device_create_file(
752 &sensor_dev_at
753 goto exit_remove_files
754 }
755
756
757 data->hwmon_dev = hwmon_device_registe
758 if (IS_ERR(data->hwmon_dev)) {
759 err = PTR_ERR(data->hwmon_dev)
760 goto exit_remove_files;
761 }
762
763 return 0;
764
765 exit_remove_files:
766 sysfs_remove_group(&client->dev.kobj,
767 sysfs_remove_group(&client->dev.kobj,
768 exit_free:
769 kfree(data);
770 exit:
771 return err;
772 }
773
774
775 /* Called when we have found a new GL520SM. */
776 static void gl520_init_client(struct i2c_clien
777 {
778 struct gl520_data *data = i2c_get_clie
779 u8 oldconf, conf;
780
781 conf = oldconf = gl520_read_value(clie
782
783 data->alarm_mask = 0xff;
784 data->vrm = vid_which_vrm();
785
786 if (extra_sensor_type == 1)
787 conf &= ~0x10;
788 else if (extra_sensor_type == 2)
789 conf |= 0x10;
790 data->two_temps = !(conf & 0x10);
791
792 /* If IRQ# is disabled, we can safely
793 if (!(conf & 0x20))
794 conf &= 0xf7;
795
796 /* Enable monitoring if needed */
797 conf |= 0x40;
798
799 if (conf != oldconf)
800 gl520_write_value(client, GL52
801
802 gl520_update_device(&(client->dev));
803
804 if (data->fan_min[0] == 0)
805 data->alarm_mask &= ~0x20;
806 if (data->fan_min[1] == 0)
807 data->alarm_mask &= ~0x40;
808
809 data->beep_mask &= data->alarm_mask;
810 gl520_write_value(client, GL520_REG_BE
811 }
812
813 static int gl520_remove(struct i2c_client *cli
814 {
815 struct gl520_data *data = i2c_get_clie
816
817 hwmon_device_unregister(data->hwmon_de
818 sysfs_remove_group(&client->dev.kobj,
819 sysfs_remove_group(&client->dev.kobj,
820
821 kfree(data);
822 return 0;
823 }
824
825
826 /* Registers 0x07 to 0x0c are word-sized, othe
827 GL520 uses a high-byte first convention */
828 static int gl520_read_value(struct i2c_client
829 {
830 if ((reg >= 0x07) && (reg <= 0x0c))
831 return swab16(i2c_smbus_read_w
832 else
833 return i2c_smbus_read_byte_dat
834 }
835
836 static int gl520_write_value(struct i2c_client
837 {
838 if ((reg >= 0x07) && (reg <= 0x0c))
839 return i2c_smbus_write_word_da
840 else
841 return i2c_smbus_write_byte_da
842 }
843
844
845 static struct gl520_data *gl520_update_device(
846 {
847 struct i2c_client *client = to_i2c_cli
848 struct gl520_data *data = i2c_get_clie
849 int val, i;
850
851 mutex_lock(&data->update_lock);
852
853 if (time_after(jiffies, data->last_upd
854
855 dev_dbg(&client->dev, "Startin
856
857 data->alarms = gl520_read_valu
858 data->beep_mask = gl520_read_v
859 data->vid = gl520_read_value(c
860
861 for (i = 0; i < 4; i++) {
862 data->in_input[i] = gl
863
864 val = gl520_read_value
865 data->in_min[i] = val
866 data->in_max[i] = (val
867 }
868
869 val = gl520_read_value(client,
870 data->fan_input[0] = (val >> 8
871 data->fan_input[1] = val & 0xf
872
873 val = gl520_read_value(client,
874 data->fan_min[0] = (val >> 8)
875 data->fan_min[1] = val & 0xff;
876
877 data->temp_input[0] = gl520_re
878
879 data->temp_max[0] = gl520_read
880
881 data->temp_max_hyst[0] = gl520
882
883
884 val = gl520_read_value(client,
885 data->fan_div[0] = (val >> 6)
886 data->fan_div[1] = (val >> 4)
887 data->fan_off = (val >> 2) & 0
888
889 data->alarms &= data->alarm_ma
890
891 val = gl520_read_value(client,
892 data->beep_enable = !((val >>
893
894 /* Temp1 and Vin4 are the same
895 if (data->two_temps) {
896 data->temp_input[1] =
897
898 data->temp_max[1] = gl
899
900 data->temp_max_hyst[1]
901
902 } else {
903 data->in_input[4] = gl
904
905 data->in_min[4] = gl52
906
907 data->in_max[4] = gl52
908
909 }
910
911 data->last_updated = jiffies;
912 data->valid = 1;
913 }
914
915 mutex_unlock(&data->update_lock);
916
917 return data;
918 }
919
920
921 static int __init sensors_gl520sm_init(void)
922 {
923 return i2c_add_driver(&gl520_driver);
924 }
925
926 static void __exit sensors_gl520sm_exit(void)
927 {
928 i2c_del_driver(&gl520_driver);
929 }
930
931
932 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>
933 "Kyösti Mälkki <kmalkki@cc.hut.fi>,
934 "Maarten Deprez <maartendeprez@users.s
935 MODULE_DESCRIPTION("GL520SM driver");
936 MODULE_LICENSE("GPL");
937
938 module_init(sensors_gl520sm_init);
939 module_exit(sensors_gl520sm_exit);
940
| This page was automatically generated by the LXR engine. |