2 gl520sm.c - Part of lm_sensors, Linux kernel modules for hardware
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>,
5 Kyösti Mälkki <kmalkki@cc.hut.fi>
6 Copyright (c) 2005 Maarten Deprez <maartendeprez@users.sourceforge.net>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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/i2c-sensor.h>
30 #include <linux/i2c-vid.h>
32 /* Type of the extra sensor */
33 static unsigned short extra_sensor_type;
34 module_param(extra_sensor_type, ushort, 0);
35 MODULE_PARM_DESC(extra_sensor_type, "Type of extra sensor (0=autodetect, 1=temperature, 2=voltage)");
37 /* Addresses to scan */
38 static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
39 static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
41 /* Insmod parameters */
42 SENSORS_INSMOD_1(gl520sm);
44 /* Many GL520 constants specified below
45 One of the inputs can be configured as either temp or voltage.
46 That's why _TEMP2 and _IN4 access the same register
49 /* The GL520 registers */
50 #define GL520_REG_CHIP_ID 0x00
51 #define GL520_REG_REVISION 0x01
52 #define GL520_REG_CONF 0x03
53 #define GL520_REG_MASK 0x11
55 #define GL520_REG_VID_INPUT 0x02
57 #define GL520_REG_IN0_INPUT 0x15
58 #define GL520_REG_IN0_LIMIT 0x0c
59 #define GL520_REG_IN0_MIN GL520_REG_IN0_LIMIT
60 #define GL520_REG_IN0_MAX GL520_REG_IN0_LIMIT
62 #define GL520_REG_IN1_INPUT 0x14
63 #define GL520_REG_IN1_LIMIT 0x09
64 #define GL520_REG_IN1_MIN GL520_REG_IN1_LIMIT
65 #define GL520_REG_IN1_MAX GL520_REG_IN1_LIMIT
67 #define GL520_REG_IN2_INPUT 0x13
68 #define GL520_REG_IN2_LIMIT 0x0a
69 #define GL520_REG_IN2_MIN GL520_REG_IN2_LIMIT
70 #define GL520_REG_IN2_MAX GL520_REG_IN2_LIMIT
72 #define GL520_REG_IN3_INPUT 0x0d
73 #define GL520_REG_IN3_LIMIT 0x0b
74 #define GL520_REG_IN3_MIN GL520_REG_IN3_LIMIT
75 #define GL520_REG_IN3_MAX GL520_REG_IN3_LIMIT
77 #define GL520_REG_IN4_INPUT 0x0e
78 #define GL520_REG_IN4_MAX 0x17
79 #define GL520_REG_IN4_MIN 0x18
81 #define GL520_REG_TEMP1_INPUT 0x04
82 #define GL520_REG_TEMP1_MAX 0x05
83 #define GL520_REG_TEMP1_MAX_HYST 0x06
85 #define GL520_REG_TEMP2_INPUT 0x0e
86 #define GL520_REG_TEMP2_MAX 0x17
87 #define GL520_REG_TEMP2_MAX_HYST 0x18
89 #define GL520_REG_FAN_INPUT 0x07
90 #define GL520_REG_FAN_MIN 0x08
91 #define GL520_REG_FAN_DIV 0x0f
92 #define GL520_REG_FAN_OFF GL520_REG_FAN_DIV
94 #define GL520_REG_ALARMS 0x12
95 #define GL520_REG_BEEP_MASK 0x10
96 #define GL520_REG_BEEP_ENABLE GL520_REG_CONF
99 * Function declarations
102 static int gl520_attach_adapter(struct i2c_adapter *adapter);
103 static int gl520_detect(struct i2c_adapter *adapter, int address, int kind);
104 static void gl520_init_client(struct i2c_client *client);
105 static int gl520_detach_client(struct i2c_client *client);
106 static int gl520_read_value(struct i2c_client *client, u8 reg);
107 static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value);
108 static struct gl520_data *gl520_update_device(struct device *dev);
111 static struct i2c_driver gl520_driver = {
112 .owner = THIS_MODULE,
114 .id = I2C_DRIVERID_GL520,
115 .flags = I2C_DF_NOTIFY,
116 .attach_adapter = gl520_attach_adapter,
117 .detach_client = gl520_detach_client,
122 struct i2c_client client;
123 struct semaphore update_lock;
124 char valid; /* zero until the following fields are valid */
125 unsigned long last_updated; /* in jiffies */
129 u8 in_input[5]; /* [0] = VVD */
130 u8 in_min[5]; /* [0] = VDD */
131 u8 in_max[5]; /* [0] = VDD */
150 #define sysfs_r(type, n, item, reg) \
151 static ssize_t get_##type##item (struct gl520_data *, char *, int); \
152 static ssize_t get_##type##n##item (struct device *, struct device_attribute *attr, char *); \
153 static ssize_t get_##type##n##item (struct device *dev, struct device_attribute *attr, char *buf) \
155 struct gl520_data *data = gl520_update_device(dev); \
156 return get_##type##item(data, buf, (n)); \
159 #define sysfs_w(type, n, item, reg) \
160 static ssize_t set_##type##item (struct i2c_client *, struct gl520_data *, const char *, size_t, int, int); \
161 static ssize_t set_##type##n##item (struct device *, struct device_attribute *attr, const char *, size_t); \
162 static ssize_t set_##type##n##item (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
164 struct i2c_client *client = to_i2c_client(dev); \
165 struct gl520_data *data = i2c_get_clientdata(client); \
166 return set_##type##item(client, data, buf, count, (n), reg); \
169 #define sysfs_rw_n(type, n, item, reg) \
170 sysfs_r(type, n, item, reg) \
171 sysfs_w(type, n, item, reg) \
172 static DEVICE_ATTR(type##n##item, S_IRUGO | S_IWUSR, get_##type##n##item, set_##type##n##item);
174 #define sysfs_ro_n(type, n, item, reg) \
175 sysfs_r(type, n, item, reg) \
176 static DEVICE_ATTR(type##n##item, S_IRUGO, get_##type##n##item, NULL);
178 #define sysfs_rw(type, item, reg) \
179 sysfs_r(type, 0, item, reg) \
180 sysfs_w(type, 0, item, reg) \
181 static DEVICE_ATTR(type##item, S_IRUGO | S_IWUSR, get_##type##0##item, set_##type##0##item);
183 #define sysfs_ro(type, item, reg) \
184 sysfs_r(type, 0, item, reg) \
185 static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL);
188 #define sysfs_vid(n) \
189 sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
191 #define device_create_file_vid(client, n) \
192 device_create_file(&client->dev, &dev_attr_cpu##n##_vid)
194 #define sysfs_in(n) \
195 sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \
196 sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \
197 sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \
199 #define device_create_file_in(client, n) \
200 ({device_create_file(&client->dev, &dev_attr_in##n##_input); \
201 device_create_file(&client->dev, &dev_attr_in##n##_min); \
202 device_create_file(&client->dev, &dev_attr_in##n##_max);})
204 #define sysfs_fan(n) \
205 sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
206 sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \
207 sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV)
209 #define device_create_file_fan(client, n) \
210 ({device_create_file(&client->dev, &dev_attr_fan##n##_input); \
211 device_create_file(&client->dev, &dev_attr_fan##n##_min); \
212 device_create_file(&client->dev, &dev_attr_fan##n##_div);})
214 #define sysfs_fan_off(n) \
215 sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \
217 #define device_create_file_fan_off(client, n) \
218 device_create_file(&client->dev, &dev_attr_fan##n##_off)
220 #define sysfs_temp(n) \
221 sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \
222 sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \
223 sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST)
225 #define device_create_file_temp(client, n) \
226 ({device_create_file(&client->dev, &dev_attr_temp##n##_input); \
227 device_create_file(&client->dev, &dev_attr_temp##n##_max); \
228 device_create_file(&client->dev, &dev_attr_temp##n##_max_hyst);})
230 #define sysfs_alarms() \
231 sysfs_ro(alarms, , GL520_REG_ALARMS) \
232 sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \
233 sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK)
235 #define device_create_file_alarms(client) \
236 ({device_create_file(&client->dev, &dev_attr_alarms); \
237 device_create_file(&client->dev, &dev_attr_beep_enable); \
238 device_create_file(&client->dev, &dev_attr_beep_mask);})
259 static ssize_t get_cpu_vid(struct gl520_data *data, char *buf, int n)
261 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
264 #define VDD_FROM_REG(val) (((val)*95+2)/4)
265 #define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255))
267 #define IN_FROM_REG(val) ((val)*19)
268 #define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255))
270 static ssize_t get_in_input(struct gl520_data *data, char *buf, int n)
272 u8 r = data->in_input[n];
275 return sprintf(buf, "%d\n", VDD_FROM_REG(r));
277 return sprintf(buf, "%d\n", IN_FROM_REG(r));
280 static ssize_t get_in_min(struct gl520_data *data, char *buf, int n)
282 u8 r = data->in_min[n];
285 return sprintf(buf, "%d\n", VDD_FROM_REG(r));
287 return sprintf(buf, "%d\n", IN_FROM_REG(r));
290 static ssize_t get_in_max(struct gl520_data *data, char *buf, int n)
292 u8 r = data->in_max[n];
295 return sprintf(buf, "%d\n", VDD_FROM_REG(r));
297 return sprintf(buf, "%d\n", IN_FROM_REG(r));
300 static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
302 long v = simple_strtol(buf, NULL, 10);
305 down(&data->update_lock);
315 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r);
317 gl520_write_value(client, reg, r);
319 up(&data->update_lock);
323 static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
325 long v = simple_strtol(buf, NULL, 10);
333 down(&data->update_lock);
338 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8));
340 gl520_write_value(client, reg, r);
342 up(&data->update_lock);
346 #define DIV_FROM_REG(val) (1 << (val))
347 #define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val) << (div))))
348 #define FAN_TO_REG(val,div) ((val)<=0?0:SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, 255));
350 static ssize_t get_fan_input(struct gl520_data *data, char *buf, int n)
352 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n - 1], data->fan_div[n - 1]));
355 static ssize_t get_fan_min(struct gl520_data *data, char *buf, int n)
357 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n - 1], data->fan_div[n - 1]));
360 static ssize_t get_fan_div(struct gl520_data *data, char *buf, int n)
362 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n - 1]));
365 static ssize_t get_fan_off(struct gl520_data *data, char *buf, int n)
367 return sprintf(buf, "%d\n", data->fan_off);
370 static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
372 unsigned long v = simple_strtoul(buf, NULL, 10);
375 down(&data->update_lock);
376 r = FAN_TO_REG(v, data->fan_div[n - 1]);
377 data->fan_min[n - 1] = r;
380 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8));
382 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r);
384 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
385 if (data->fan_min[n - 1] == 0)
386 data->alarm_mask &= (n == 1) ? ~0x20 : ~0x40;
388 data->alarm_mask |= (n == 1) ? 0x20 : 0x40;
389 data->beep_mask &= data->alarm_mask;
390 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
392 up(&data->update_lock);
396 static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
398 unsigned long v = simple_strtoul(buf, NULL, 10);
402 case 1: r = 0; break;
403 case 2: r = 1; break;
404 case 4: r = 2; break;
405 case 8: r = 3; break;
407 dev_err(&client->dev, "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", v);
411 down(&data->update_lock);
412 data->fan_div[n - 1] = r;
415 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xc0) | (r << 6));
417 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x30) | (r << 4));
419 up(&data->update_lock);
423 static ssize_t set_fan_off(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
425 u8 r = simple_strtoul(buf, NULL, 10)?1:0;
427 down(&data->update_lock);
429 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x0c) | (r << 2));
430 up(&data->update_lock);
434 #define TEMP_FROM_REG(val) (((val) - 130) * 1000)
435 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0?(val)-500:(val)+500) / 1000)+130),0,255))
437 static ssize_t get_temp_input(struct gl520_data *data, char *buf, int n)
439 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n - 1]));
442 static ssize_t get_temp_max(struct gl520_data *data, char *buf, int n)
444 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n - 1]));
447 static ssize_t get_temp_max_hyst(struct gl520_data *data, char *buf, int n)
449 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n - 1]));
452 static ssize_t set_temp_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
454 long v = simple_strtol(buf, NULL, 10);
456 down(&data->update_lock);
457 data->temp_max[n - 1] = TEMP_TO_REG(v);;
458 gl520_write_value(client, reg, data->temp_max[n - 1]);
459 up(&data->update_lock);
463 static ssize_t set_temp_max_hyst(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
465 long v = simple_strtol(buf, NULL, 10);
467 down(&data->update_lock);
468 data->temp_max_hyst[n - 1] = TEMP_TO_REG(v);
469 gl520_write_value(client, reg, data->temp_max_hyst[n - 1]);
470 up(&data->update_lock);
474 static ssize_t get_alarms(struct gl520_data *data, char *buf, int n)
476 return sprintf(buf, "%d\n", data->alarms);
479 static ssize_t get_beep_enable(struct gl520_data *data, char *buf, int n)
481 return sprintf(buf, "%d\n", data->beep_enable);
484 static ssize_t get_beep_mask(struct gl520_data *data, char *buf, int n)
486 return sprintf(buf, "%d\n", data->beep_mask);
489 static ssize_t set_beep_enable(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
491 u8 r = simple_strtoul(buf, NULL, 10)?0:1;
493 down(&data->update_lock);
494 data->beep_enable = !r;
495 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x04) | (r << 2));
496 up(&data->update_lock);
500 static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
502 u8 r = simple_strtoul(buf, NULL, 10);
504 down(&data->update_lock);
505 r &= data->alarm_mask;
507 gl520_write_value(client, reg, r);
508 up(&data->update_lock);
517 static int gl520_attach_adapter(struct i2c_adapter *adapter)
519 if (!(adapter->class & I2C_CLASS_HWMON))
521 return i2c_detect(adapter, &addr_data, gl520_detect);
524 static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
526 struct i2c_client *new_client;
527 struct gl520_data *data;
530 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
531 I2C_FUNC_SMBUS_WORD_DATA))
534 /* OK. For now, we presume we have a valid client. We now create the
535 client structure, even though we cannot fill it completely yet.
536 But it allows us to access gl520_{read,write}_value. */
538 if (!(data = kmalloc(sizeof(struct gl520_data), GFP_KERNEL))) {
542 memset(data, 0, sizeof(struct gl520_data));
544 new_client = &data->client;
545 i2c_set_clientdata(new_client, data);
546 new_client->addr = address;
547 new_client->adapter = adapter;
548 new_client->driver = &gl520_driver;
549 new_client->flags = 0;
551 /* Determine the chip type. */
553 if ((gl520_read_value(new_client, GL520_REG_CHIP_ID) != 0x20) ||
554 ((gl520_read_value(new_client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
555 ((gl520_read_value(new_client, GL520_REG_CONF) & 0x80) != 0x00)) {
556 dev_dbg(&new_client->dev, "Unknown chip type, skipping\n");
561 /* Fill in the remaining client fields */
562 strlcpy(new_client->name, "gl520sm", I2C_NAME_SIZE);
564 init_MUTEX(&data->update_lock);
566 /* Tell the I2C layer a new client has arrived */
567 if ((err = i2c_attach_client(new_client)))
570 /* Initialize the GL520SM chip */
571 gl520_init_client(new_client);
573 /* Register sysfs hooks */
574 device_create_file_vid(new_client, 0);
576 device_create_file_in(new_client, 0);
577 device_create_file_in(new_client, 1);
578 device_create_file_in(new_client, 2);
579 device_create_file_in(new_client, 3);
580 if (!data->two_temps)
581 device_create_file_in(new_client, 4);
583 device_create_file_fan(new_client, 1);
584 device_create_file_fan(new_client, 2);
585 device_create_file_fan_off(new_client, 1);
587 device_create_file_temp(new_client, 1);
589 device_create_file_temp(new_client, 2);
591 device_create_file_alarms(new_client);
602 /* Called when we have found a new GL520SM. */
603 static void gl520_init_client(struct i2c_client *client)
605 struct gl520_data *data = i2c_get_clientdata(client);
608 conf = oldconf = gl520_read_value(client, GL520_REG_CONF);
610 data->alarm_mask = 0xff;
611 data->vrm = i2c_which_vrm();
613 if (extra_sensor_type == 1)
615 else if (extra_sensor_type == 2)
617 data->two_temps = !(conf & 0x10);
619 /* If IRQ# is disabled, we can safely force comparator mode */
623 /* Enable monitoring if needed */
627 gl520_write_value(client, GL520_REG_CONF, conf);
629 gl520_update_device(&(client->dev));
631 if (data->fan_min[0] == 0)
632 data->alarm_mask &= ~0x20;
633 if (data->fan_min[1] == 0)
634 data->alarm_mask &= ~0x40;
636 data->beep_mask &= data->alarm_mask;
637 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
640 static int gl520_detach_client(struct i2c_client *client)
644 if ((err = i2c_detach_client(client))) {
645 dev_err(&client->dev, "Client deregistration failed, "
646 "client not detached.\n");
650 kfree(i2c_get_clientdata(client));
655 /* Registers 0x07 to 0x0c are word-sized, others are byte-sized
656 GL520 uses a high-byte first convention */
657 static int gl520_read_value(struct i2c_client *client, u8 reg)
659 if ((reg >= 0x07) && (reg <= 0x0c))
660 return swab16(i2c_smbus_read_word_data(client, reg));
662 return i2c_smbus_read_byte_data(client, reg);
665 static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value)
667 if ((reg >= 0x07) && (reg <= 0x0c))
668 return i2c_smbus_write_word_data(client, reg, swab16(value));
670 return i2c_smbus_write_byte_data(client, reg, value);
674 static struct gl520_data *gl520_update_device(struct device *dev)
676 struct i2c_client *client = to_i2c_client(dev);
677 struct gl520_data *data = i2c_get_clientdata(client);
680 down(&data->update_lock);
682 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
684 dev_dbg(&client->dev, "Starting gl520sm update\n");
686 data->alarms = gl520_read_value(client, GL520_REG_ALARMS);
687 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
688 data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f;
690 val = gl520_read_value(client, GL520_REG_IN0_LIMIT);
691 data->in_min[0] = val & 0xff;
692 data->in_max[0] = (val >> 8) & 0xff;
693 val = gl520_read_value(client, GL520_REG_IN1_LIMIT);
694 data->in_min[1] = val & 0xff;
695 data->in_max[1] = (val >> 8) & 0xff;
696 val = gl520_read_value(client, GL520_REG_IN2_LIMIT);
697 data->in_min[2] = val & 0xff;
698 data->in_max[2] = (val >> 8) & 0xff;
699 val = gl520_read_value(client, GL520_REG_IN3_LIMIT);
700 data->in_min[3] = val & 0xff;
701 data->in_max[3] = (val >> 8) & 0xff;
703 val = gl520_read_value(client, GL520_REG_FAN_INPUT);
704 data->fan_input[0] = (val >> 8) & 0xff;
705 data->fan_input[1] = val & 0xff;
707 val = gl520_read_value(client, GL520_REG_FAN_MIN);
708 data->fan_min[0] = (val >> 8) & 0xff;
709 data->fan_min[1] = val & 0xff;
711 data->temp_input[0] = gl520_read_value(client, GL520_REG_TEMP1_INPUT);
712 data->temp_max[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX);
713 data->temp_max_hyst[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX_HYST);
715 val = gl520_read_value(client, GL520_REG_FAN_DIV);
716 data->fan_div[0] = (val >> 6) & 0x03;
717 data->fan_div[1] = (val >> 4) & 0x03;
718 data->fan_off = (val >> 2) & 0x01;
720 data->alarms &= data->alarm_mask;
722 val = gl520_read_value(client, GL520_REG_CONF);
723 data->beep_enable = !((val >> 2) & 1);
725 data->in_input[0] = gl520_read_value(client, GL520_REG_IN0_INPUT);
726 data->in_input[1] = gl520_read_value(client, GL520_REG_IN1_INPUT);
727 data->in_input[2] = gl520_read_value(client, GL520_REG_IN2_INPUT);
728 data->in_input[3] = gl520_read_value(client, GL520_REG_IN3_INPUT);
730 /* Temp1 and Vin4 are the same input */
731 if (data->two_temps) {
732 data->temp_input[1] = gl520_read_value(client, GL520_REG_TEMP2_INPUT);
733 data->temp_max[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX);
734 data->temp_max_hyst[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX_HYST);
736 data->in_input[4] = gl520_read_value(client, GL520_REG_IN4_INPUT);
737 data->in_min[4] = gl520_read_value(client, GL520_REG_IN4_MIN);
738 data->in_max[4] = gl520_read_value(client, GL520_REG_IN4_MAX);
741 data->last_updated = jiffies;
745 up(&data->update_lock);
751 static int __init sensors_gl520sm_init(void)
753 return i2c_add_driver(&gl520_driver);
756 static void __exit sensors_gl520sm_exit(void)
758 i2c_del_driver(&gl520_driver);
762 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
763 "Kyösti Mälkki <kmalkki@cc.hut.fi>, "
764 "Maarten Deprez <maartendeprez@users.sourceforge.net>");
765 MODULE_DESCRIPTION("GL520SM driver");
766 MODULE_LICENSE("GPL");
768 module_init(sensors_gl520sm_init);
769 module_exit(sensors_gl520sm_exit);