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/hwmon.h>
30 #include <linux/hwmon-vid.h>
31 #include <linux/err.h>
33 /* Type of the extra sensor */
34 static unsigned short extra_sensor_type;
35 module_param(extra_sensor_type, ushort, 0);
36 MODULE_PARM_DESC(extra_sensor_type, "Type of extra sensor (0=autodetect, 1=temperature, 2=voltage)");
38 /* Addresses to scan */
39 static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
41 /* Insmod parameters */
42 I2C_CLIENT_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 class_device *class_dev;
124 struct semaphore update_lock;
125 char valid; /* zero until the following fields are valid */
126 unsigned long last_updated; /* in jiffies */
130 u8 in_input[5]; /* [0] = VVD */
131 u8 in_min[5]; /* [0] = VDD */
132 u8 in_max[5]; /* [0] = VDD */
151 #define sysfs_r(type, n, item, reg) \
152 static ssize_t get_##type##item (struct gl520_data *, char *, int); \
153 static ssize_t get_##type##n##item (struct device *, struct device_attribute *attr, char *); \
154 static ssize_t get_##type##n##item (struct device *dev, struct device_attribute *attr, char *buf) \
156 struct gl520_data *data = gl520_update_device(dev); \
157 return get_##type##item(data, buf, (n)); \
160 #define sysfs_w(type, n, item, reg) \
161 static ssize_t set_##type##item (struct i2c_client *, struct gl520_data *, const char *, size_t, int, int); \
162 static ssize_t set_##type##n##item (struct device *, struct device_attribute *attr, const char *, size_t); \
163 static ssize_t set_##type##n##item (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
165 struct i2c_client *client = to_i2c_client(dev); \
166 struct gl520_data *data = i2c_get_clientdata(client); \
167 return set_##type##item(client, data, buf, count, (n), reg); \
170 #define sysfs_rw_n(type, n, item, reg) \
171 sysfs_r(type, n, item, reg) \
172 sysfs_w(type, n, item, reg) \
173 static DEVICE_ATTR(type##n##item, S_IRUGO | S_IWUSR, get_##type##n##item, set_##type##n##item);
175 #define sysfs_ro_n(type, n, item, reg) \
176 sysfs_r(type, n, item, reg) \
177 static DEVICE_ATTR(type##n##item, S_IRUGO, get_##type##n##item, NULL);
179 #define sysfs_rw(type, item, reg) \
180 sysfs_r(type, 0, item, reg) \
181 sysfs_w(type, 0, item, reg) \
182 static DEVICE_ATTR(type##item, S_IRUGO | S_IWUSR, get_##type##0##item, set_##type##0##item);
184 #define sysfs_ro(type, item, reg) \
185 sysfs_r(type, 0, item, reg) \
186 static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL);
189 #define sysfs_vid(n) \
190 sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
192 #define device_create_file_vid(client, n) \
193 device_create_file(&client->dev, &dev_attr_cpu##n##_vid)
195 #define sysfs_in(n) \
196 sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \
197 sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \
198 sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \
200 #define device_create_file_in(client, n) \
201 ({device_create_file(&client->dev, &dev_attr_in##n##_input); \
202 device_create_file(&client->dev, &dev_attr_in##n##_min); \
203 device_create_file(&client->dev, &dev_attr_in##n##_max);})
205 #define sysfs_fan(n) \
206 sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
207 sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \
208 sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV)
210 #define device_create_file_fan(client, n) \
211 ({device_create_file(&client->dev, &dev_attr_fan##n##_input); \
212 device_create_file(&client->dev, &dev_attr_fan##n##_min); \
213 device_create_file(&client->dev, &dev_attr_fan##n##_div);})
215 #define sysfs_fan_off(n) \
216 sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \
218 #define device_create_file_fan_off(client, n) \
219 device_create_file(&client->dev, &dev_attr_fan##n##_off)
221 #define sysfs_temp(n) \
222 sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \
223 sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \
224 sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST)
226 #define device_create_file_temp(client, n) \
227 ({device_create_file(&client->dev, &dev_attr_temp##n##_input); \
228 device_create_file(&client->dev, &dev_attr_temp##n##_max); \
229 device_create_file(&client->dev, &dev_attr_temp##n##_max_hyst);})
231 #define sysfs_alarms() \
232 sysfs_ro(alarms, , GL520_REG_ALARMS) \
233 sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \
234 sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK)
236 #define device_create_file_alarms(client) \
237 ({device_create_file(&client->dev, &dev_attr_alarms); \
238 device_create_file(&client->dev, &dev_attr_beep_enable); \
239 device_create_file(&client->dev, &dev_attr_beep_mask);})
260 static ssize_t get_cpu_vid(struct gl520_data *data, char *buf, int n)
262 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
265 #define VDD_FROM_REG(val) (((val)*95+2)/4)
266 #define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255))
268 #define IN_FROM_REG(val) ((val)*19)
269 #define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255))
271 static ssize_t get_in_input(struct gl520_data *data, char *buf, int n)
273 u8 r = data->in_input[n];
276 return sprintf(buf, "%d\n", VDD_FROM_REG(r));
278 return sprintf(buf, "%d\n", IN_FROM_REG(r));
281 static ssize_t get_in_min(struct gl520_data *data, char *buf, int n)
283 u8 r = data->in_min[n];
286 return sprintf(buf, "%d\n", VDD_FROM_REG(r));
288 return sprintf(buf, "%d\n", IN_FROM_REG(r));
291 static ssize_t get_in_max(struct gl520_data *data, char *buf, int n)
293 u8 r = data->in_max[n];
296 return sprintf(buf, "%d\n", VDD_FROM_REG(r));
298 return sprintf(buf, "%d\n", IN_FROM_REG(r));
301 static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
303 long v = simple_strtol(buf, NULL, 10);
306 down(&data->update_lock);
316 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r);
318 gl520_write_value(client, reg, r);
320 up(&data->update_lock);
324 static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
326 long v = simple_strtol(buf, NULL, 10);
334 down(&data->update_lock);
339 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8));
341 gl520_write_value(client, reg, r);
343 up(&data->update_lock);
347 #define DIV_FROM_REG(val) (1 << (val))
348 #define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val) << (div))))
349 #define FAN_TO_REG(val,div) ((val)<=0?0:SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, 255));
351 static ssize_t get_fan_input(struct gl520_data *data, char *buf, int n)
353 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n - 1], data->fan_div[n - 1]));
356 static ssize_t get_fan_min(struct gl520_data *data, char *buf, int n)
358 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n - 1], data->fan_div[n - 1]));
361 static ssize_t get_fan_div(struct gl520_data *data, char *buf, int n)
363 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n - 1]));
366 static ssize_t get_fan_off(struct gl520_data *data, char *buf, int n)
368 return sprintf(buf, "%d\n", data->fan_off);
371 static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
373 unsigned long v = simple_strtoul(buf, NULL, 10);
376 down(&data->update_lock);
377 r = FAN_TO_REG(v, data->fan_div[n - 1]);
378 data->fan_min[n - 1] = r;
381 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8));
383 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r);
385 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
386 if (data->fan_min[n - 1] == 0)
387 data->alarm_mask &= (n == 1) ? ~0x20 : ~0x40;
389 data->alarm_mask |= (n == 1) ? 0x20 : 0x40;
390 data->beep_mask &= data->alarm_mask;
391 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
393 up(&data->update_lock);
397 static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
399 unsigned long v = simple_strtoul(buf, NULL, 10);
403 case 1: r = 0; break;
404 case 2: r = 1; break;
405 case 4: r = 2; break;
406 case 8: r = 3; break;
408 dev_err(&client->dev, "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", v);
412 down(&data->update_lock);
413 data->fan_div[n - 1] = r;
416 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xc0) | (r << 6));
418 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x30) | (r << 4));
420 up(&data->update_lock);
424 static ssize_t set_fan_off(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
426 u8 r = simple_strtoul(buf, NULL, 10)?1:0;
428 down(&data->update_lock);
430 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x0c) | (r << 2));
431 up(&data->update_lock);
435 #define TEMP_FROM_REG(val) (((val) - 130) * 1000)
436 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0?(val)-500:(val)+500) / 1000)+130),0,255))
438 static ssize_t get_temp_input(struct gl520_data *data, char *buf, int n)
440 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n - 1]));
443 static ssize_t get_temp_max(struct gl520_data *data, char *buf, int n)
445 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n - 1]));
448 static ssize_t get_temp_max_hyst(struct gl520_data *data, char *buf, int n)
450 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n - 1]));
453 static ssize_t set_temp_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
455 long v = simple_strtol(buf, NULL, 10);
457 down(&data->update_lock);
458 data->temp_max[n - 1] = TEMP_TO_REG(v);;
459 gl520_write_value(client, reg, data->temp_max[n - 1]);
460 up(&data->update_lock);
464 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)
466 long v = simple_strtol(buf, NULL, 10);
468 down(&data->update_lock);
469 data->temp_max_hyst[n - 1] = TEMP_TO_REG(v);
470 gl520_write_value(client, reg, data->temp_max_hyst[n - 1]);
471 up(&data->update_lock);
475 static ssize_t get_alarms(struct gl520_data *data, char *buf, int n)
477 return sprintf(buf, "%d\n", data->alarms);
480 static ssize_t get_beep_enable(struct gl520_data *data, char *buf, int n)
482 return sprintf(buf, "%d\n", data->beep_enable);
485 static ssize_t get_beep_mask(struct gl520_data *data, char *buf, int n)
487 return sprintf(buf, "%d\n", data->beep_mask);
490 static ssize_t set_beep_enable(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
492 u8 r = simple_strtoul(buf, NULL, 10)?0:1;
494 down(&data->update_lock);
495 data->beep_enable = !r;
496 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x04) | (r << 2));
497 up(&data->update_lock);
501 static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
503 u8 r = simple_strtoul(buf, NULL, 10);
505 down(&data->update_lock);
506 r &= data->alarm_mask;
508 gl520_write_value(client, reg, r);
509 up(&data->update_lock);
518 static int gl520_attach_adapter(struct i2c_adapter *adapter)
520 if (!(adapter->class & I2C_CLASS_HWMON))
522 return i2c_probe(adapter, &addr_data, gl520_detect);
525 static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
527 struct i2c_client *new_client;
528 struct gl520_data *data;
531 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
532 I2C_FUNC_SMBUS_WORD_DATA))
535 /* OK. For now, we presume we have a valid client. We now create the
536 client structure, even though we cannot fill it completely yet.
537 But it allows us to access gl520_{read,write}_value. */
539 if (!(data = kzalloc(sizeof(struct gl520_data), GFP_KERNEL))) {
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 data->class_dev = hwmon_device_register(&new_client->dev);
575 if (IS_ERR(data->class_dev)) {
576 err = PTR_ERR(data->class_dev);
580 device_create_file_vid(new_client, 0);
582 device_create_file_in(new_client, 0);
583 device_create_file_in(new_client, 1);
584 device_create_file_in(new_client, 2);
585 device_create_file_in(new_client, 3);
586 if (!data->two_temps)
587 device_create_file_in(new_client, 4);
589 device_create_file_fan(new_client, 1);
590 device_create_file_fan(new_client, 2);
591 device_create_file_fan_off(new_client, 1);
593 device_create_file_temp(new_client, 1);
595 device_create_file_temp(new_client, 2);
597 device_create_file_alarms(new_client);
602 i2c_detach_client(new_client);
610 /* Called when we have found a new GL520SM. */
611 static void gl520_init_client(struct i2c_client *client)
613 struct gl520_data *data = i2c_get_clientdata(client);
616 conf = oldconf = gl520_read_value(client, GL520_REG_CONF);
618 data->alarm_mask = 0xff;
619 data->vrm = vid_which_vrm();
621 if (extra_sensor_type == 1)
623 else if (extra_sensor_type == 2)
625 data->two_temps = !(conf & 0x10);
627 /* If IRQ# is disabled, we can safely force comparator mode */
631 /* Enable monitoring if needed */
635 gl520_write_value(client, GL520_REG_CONF, conf);
637 gl520_update_device(&(client->dev));
639 if (data->fan_min[0] == 0)
640 data->alarm_mask &= ~0x20;
641 if (data->fan_min[1] == 0)
642 data->alarm_mask &= ~0x40;
644 data->beep_mask &= data->alarm_mask;
645 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
648 static int gl520_detach_client(struct i2c_client *client)
650 struct gl520_data *data = i2c_get_clientdata(client);
653 hwmon_device_unregister(data->class_dev);
655 if ((err = i2c_detach_client(client)))
663 /* Registers 0x07 to 0x0c are word-sized, others are byte-sized
664 GL520 uses a high-byte first convention */
665 static int gl520_read_value(struct i2c_client *client, u8 reg)
667 if ((reg >= 0x07) && (reg <= 0x0c))
668 return swab16(i2c_smbus_read_word_data(client, reg));
670 return i2c_smbus_read_byte_data(client, reg);
673 static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value)
675 if ((reg >= 0x07) && (reg <= 0x0c))
676 return i2c_smbus_write_word_data(client, reg, swab16(value));
678 return i2c_smbus_write_byte_data(client, reg, value);
682 static struct gl520_data *gl520_update_device(struct device *dev)
684 struct i2c_client *client = to_i2c_client(dev);
685 struct gl520_data *data = i2c_get_clientdata(client);
688 down(&data->update_lock);
690 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
692 dev_dbg(&client->dev, "Starting gl520sm update\n");
694 data->alarms = gl520_read_value(client, GL520_REG_ALARMS);
695 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
696 data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f;
698 val = gl520_read_value(client, GL520_REG_IN0_LIMIT);
699 data->in_min[0] = val & 0xff;
700 data->in_max[0] = (val >> 8) & 0xff;
701 val = gl520_read_value(client, GL520_REG_IN1_LIMIT);
702 data->in_min[1] = val & 0xff;
703 data->in_max[1] = (val >> 8) & 0xff;
704 val = gl520_read_value(client, GL520_REG_IN2_LIMIT);
705 data->in_min[2] = val & 0xff;
706 data->in_max[2] = (val >> 8) & 0xff;
707 val = gl520_read_value(client, GL520_REG_IN3_LIMIT);
708 data->in_min[3] = val & 0xff;
709 data->in_max[3] = (val >> 8) & 0xff;
711 val = gl520_read_value(client, GL520_REG_FAN_INPUT);
712 data->fan_input[0] = (val >> 8) & 0xff;
713 data->fan_input[1] = val & 0xff;
715 val = gl520_read_value(client, GL520_REG_FAN_MIN);
716 data->fan_min[0] = (val >> 8) & 0xff;
717 data->fan_min[1] = val & 0xff;
719 data->temp_input[0] = gl520_read_value(client, GL520_REG_TEMP1_INPUT);
720 data->temp_max[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX);
721 data->temp_max_hyst[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX_HYST);
723 val = gl520_read_value(client, GL520_REG_FAN_DIV);
724 data->fan_div[0] = (val >> 6) & 0x03;
725 data->fan_div[1] = (val >> 4) & 0x03;
726 data->fan_off = (val >> 2) & 0x01;
728 data->alarms &= data->alarm_mask;
730 val = gl520_read_value(client, GL520_REG_CONF);
731 data->beep_enable = !((val >> 2) & 1);
733 data->in_input[0] = gl520_read_value(client, GL520_REG_IN0_INPUT);
734 data->in_input[1] = gl520_read_value(client, GL520_REG_IN1_INPUT);
735 data->in_input[2] = gl520_read_value(client, GL520_REG_IN2_INPUT);
736 data->in_input[3] = gl520_read_value(client, GL520_REG_IN3_INPUT);
738 /* Temp1 and Vin4 are the same input */
739 if (data->two_temps) {
740 data->temp_input[1] = gl520_read_value(client, GL520_REG_TEMP2_INPUT);
741 data->temp_max[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX);
742 data->temp_max_hyst[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX_HYST);
744 data->in_input[4] = gl520_read_value(client, GL520_REG_IN4_INPUT);
745 data->in_min[4] = gl520_read_value(client, GL520_REG_IN4_MIN);
746 data->in_max[4] = gl520_read_value(client, GL520_REG_IN4_MAX);
749 data->last_updated = jiffies;
753 up(&data->update_lock);
759 static int __init sensors_gl520sm_init(void)
761 return i2c_add_driver(&gl520_driver);
764 static void __exit sensors_gl520sm_exit(void)
766 i2c_del_driver(&gl520_driver);
770 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
771 "Kyösti Mälkki <kmalkki@cc.hut.fi>, "
772 "Maarten Deprez <maartendeprez@users.sourceforge.net>");
773 MODULE_DESCRIPTION("GL520SM driver");
774 MODULE_LICENSE("GPL");
776 module_init(sensors_gl520sm_init);
777 module_exit(sensors_gl520sm_exit);