1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * gl518sm.c - Part of lm_sensors, Linux kernel modules for hardware
5 * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and
6 * Kyosti Malkki <kmalkki@cc.hut.fi>
7 * Copyright (C) 2004 Hong-Gunn Chew <hglinux@gunnet.org> and
8 * Jean Delvare <jdelvare@suse.de>
10 * Ported to Linux 2.6 by Hong-Gunn Chew with the help of Jean Delvare
11 * and advice of Greg Kroah-Hartman.
13 * Notes about the port:
14 * Release 0x00 of the GL518SM chipset doesn't support reading of in0,
15 * in1 nor in2. The original driver had an ugly workaround to get them
16 * anyway (changing limits and watching alarms trigger and wear off).
17 * We did not keep that part of the original driver in the Linux 2.6
18 * version, since it was making the driver significantly more complex
19 * with no real benefit.
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/jiffies.h>
26 #include <linux/i2c.h>
27 #include <linux/hwmon.h>
28 #include <linux/hwmon-sysfs.h>
29 #include <linux/err.h>
30 #include <linux/mutex.h>
31 #include <linux/sysfs.h>
33 /* Addresses to scan */
34 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
36 enum chips { gl518sm_r00, gl518sm_r80 };
38 /* Many GL518 constants specified below */
40 /* The GL518 registers */
41 #define GL518_REG_CHIP_ID 0x00
42 #define GL518_REG_REVISION 0x01
43 #define GL518_REG_VENDOR_ID 0x02
44 #define GL518_REG_CONF 0x03
45 #define GL518_REG_TEMP_IN 0x04
46 #define GL518_REG_TEMP_MAX 0x05
47 #define GL518_REG_TEMP_HYST 0x06
48 #define GL518_REG_FAN_COUNT 0x07
49 #define GL518_REG_FAN_LIMIT 0x08
50 #define GL518_REG_VIN1_LIMIT 0x09
51 #define GL518_REG_VIN2_LIMIT 0x0a
52 #define GL518_REG_VIN3_LIMIT 0x0b
53 #define GL518_REG_VDD_LIMIT 0x0c
54 #define GL518_REG_VIN3 0x0d
55 #define GL518_REG_MISC 0x0f
56 #define GL518_REG_ALARM 0x10
57 #define GL518_REG_MASK 0x11
58 #define GL518_REG_INT 0x12
59 #define GL518_REG_VIN2 0x13
60 #define GL518_REG_VIN1 0x14
61 #define GL518_REG_VDD 0x15
65 * Conversions. Rounding and limit checking is only done on the TO_REG
66 * variants. Note that you should be a bit careful with which arguments
67 * these macros are called: arguments may be evaluated more than once.
68 * Fixing this is just not worth it.
71 #define RAW_FROM_REG(val) val
73 #define BOOL_FROM_REG(val) ((val) ? 0 : 1)
74 #define BOOL_TO_REG(val) ((val) ? 0 : 1)
76 #define TEMP_CLAMP(val) clamp_val(val, -119000, 136000)
77 #define TEMP_TO_REG(val) (DIV_ROUND_CLOSEST(TEMP_CLAMP(val), 1000) + 119)
78 #define TEMP_FROM_REG(val) (((val) - 119) * 1000)
80 static inline u8 FAN_TO_REG(long rpm, int div)
85 rpmdiv = clamp_val(rpm, 1, 960000) * div;
86 return clamp_val((480000 + rpmdiv / 2) / rpmdiv, 1, 255);
88 #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) * (div))))
90 #define IN_CLAMP(val) clamp_val(val, 0, 255 * 19)
91 #define IN_TO_REG(val) DIV_ROUND_CLOSEST(IN_CLAMP(val), 19)
92 #define IN_FROM_REG(val) ((val) * 19)
94 #define VDD_CLAMP(val) clamp_val(val, 0, 255 * 95 / 4)
95 #define VDD_TO_REG(val) DIV_ROUND_CLOSEST(VDD_CLAMP(val) * 4, 95)
96 #define VDD_FROM_REG(val) DIV_ROUND_CLOSEST((val) * 95, 4)
98 #define DIV_FROM_REG(val) (1 << (val))
100 #define BEEP_MASK_TO_REG(val) ((val) & 0x7f & data->alarm_mask)
101 #define BEEP_MASK_FROM_REG(val) ((val) & 0x7f)
103 /* Each client has this additional data */
105 struct i2c_client *client;
106 const struct attribute_group *groups[3];
109 struct mutex update_lock;
110 bool valid; /* true if following fields are valid */
111 unsigned long last_updated; /* In jiffies */
113 u8 voltage_in[4]; /* Register values; [0] = VDD */
114 u8 voltage_min[4]; /* Register values; [0] = VDD */
115 u8 voltage_max[4]; /* Register values; [0] = VDD */
118 u8 fan_div[2]; /* Register encoding, shifted right */
119 u8 fan_auto1; /* Boolean */
120 u8 temp_in; /* Register values */
121 u8 temp_max; /* Register values */
122 u8 temp_hyst; /* Register values */
123 u8 alarms; /* Register value */
125 u8 beep_mask; /* Register value */
126 u8 beep_enable; /* Boolean */
130 * Registers 0x07 to 0x0c are word-sized, others are byte-sized
131 * GL518 uses a high-byte first convention, which is exactly opposite to
132 * the SMBus standard.
134 static int gl518_read_value(struct i2c_client *client, u8 reg)
136 if ((reg >= 0x07) && (reg <= 0x0c))
137 return i2c_smbus_read_word_swapped(client, reg);
139 return i2c_smbus_read_byte_data(client, reg);
142 static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value)
144 if ((reg >= 0x07) && (reg <= 0x0c))
145 return i2c_smbus_write_word_swapped(client, reg, value);
147 return i2c_smbus_write_byte_data(client, reg, value);
150 static struct gl518_data *gl518_update_device(struct device *dev)
152 struct gl518_data *data = dev_get_drvdata(dev);
153 struct i2c_client *client = data->client;
156 mutex_lock(&data->update_lock);
158 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
160 dev_dbg(&client->dev, "Starting gl518 update\n");
162 data->alarms = gl518_read_value(client, GL518_REG_INT);
163 data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
165 val = gl518_read_value(client, GL518_REG_VDD_LIMIT);
166 data->voltage_min[0] = val & 0xff;
167 data->voltage_max[0] = (val >> 8) & 0xff;
168 val = gl518_read_value(client, GL518_REG_VIN1_LIMIT);
169 data->voltage_min[1] = val & 0xff;
170 data->voltage_max[1] = (val >> 8) & 0xff;
171 val = gl518_read_value(client, GL518_REG_VIN2_LIMIT);
172 data->voltage_min[2] = val & 0xff;
173 data->voltage_max[2] = (val >> 8) & 0xff;
174 val = gl518_read_value(client, GL518_REG_VIN3_LIMIT);
175 data->voltage_min[3] = val & 0xff;
176 data->voltage_max[3] = (val >> 8) & 0xff;
178 val = gl518_read_value(client, GL518_REG_FAN_COUNT);
179 data->fan_in[0] = (val >> 8) & 0xff;
180 data->fan_in[1] = val & 0xff;
182 val = gl518_read_value(client, GL518_REG_FAN_LIMIT);
183 data->fan_min[0] = (val >> 8) & 0xff;
184 data->fan_min[1] = val & 0xff;
186 data->temp_in = gl518_read_value(client, GL518_REG_TEMP_IN);
188 gl518_read_value(client, GL518_REG_TEMP_MAX);
190 gl518_read_value(client, GL518_REG_TEMP_HYST);
192 val = gl518_read_value(client, GL518_REG_MISC);
193 data->fan_div[0] = (val >> 6) & 0x03;
194 data->fan_div[1] = (val >> 4) & 0x03;
195 data->fan_auto1 = (val >> 3) & 0x01;
197 data->alarms &= data->alarm_mask;
199 val = gl518_read_value(client, GL518_REG_CONF);
200 data->beep_enable = (val >> 2) & 1;
202 if (data->type != gl518sm_r00) {
203 data->voltage_in[0] =
204 gl518_read_value(client, GL518_REG_VDD);
205 data->voltage_in[1] =
206 gl518_read_value(client, GL518_REG_VIN1);
207 data->voltage_in[2] =
208 gl518_read_value(client, GL518_REG_VIN2);
210 data->voltage_in[3] =
211 gl518_read_value(client, GL518_REG_VIN3);
213 data->last_updated = jiffies;
217 mutex_unlock(&data->update_lock);
226 #define show(type, suffix, value) \
227 static ssize_t show_##suffix(struct device *dev, \
228 struct device_attribute *attr, char *buf) \
230 struct gl518_data *data = gl518_update_device(dev); \
231 return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \
234 show(TEMP, temp_input1, temp_in);
235 show(TEMP, temp_max1, temp_max);
236 show(TEMP, temp_hyst1, temp_hyst);
237 show(BOOL, fan_auto1, fan_auto1);
238 show(VDD, in_input0, voltage_in[0]);
239 show(IN, in_input1, voltage_in[1]);
240 show(IN, in_input2, voltage_in[2]);
241 show(IN, in_input3, voltage_in[3]);
242 show(VDD, in_min0, voltage_min[0]);
243 show(IN, in_min1, voltage_min[1]);
244 show(IN, in_min2, voltage_min[2]);
245 show(IN, in_min3, voltage_min[3]);
246 show(VDD, in_max0, voltage_max[0]);
247 show(IN, in_max1, voltage_max[1]);
248 show(IN, in_max2, voltage_max[2]);
249 show(IN, in_max3, voltage_max[3]);
250 show(RAW, alarms, alarms);
251 show(BOOL, beep_enable, beep_enable);
252 show(BEEP_MASK, beep_mask, beep_mask);
254 static ssize_t fan_input_show(struct device *dev,
255 struct device_attribute *attr, char *buf)
257 int nr = to_sensor_dev_attr(attr)->index;
258 struct gl518_data *data = gl518_update_device(dev);
259 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_in[nr],
260 DIV_FROM_REG(data->fan_div[nr])));
263 static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
266 int nr = to_sensor_dev_attr(attr)->index;
267 struct gl518_data *data = gl518_update_device(dev);
268 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
269 DIV_FROM_REG(data->fan_div[nr])));
272 static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
275 int nr = to_sensor_dev_attr(attr)->index;
276 struct gl518_data *data = gl518_update_device(dev);
277 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
280 #define set(type, suffix, value, reg) \
281 static ssize_t set_##suffix(struct device *dev, \
282 struct device_attribute *attr, \
283 const char *buf, size_t count) \
285 struct gl518_data *data = dev_get_drvdata(dev); \
286 struct i2c_client *client = data->client; \
288 int err = kstrtol(buf, 10, &val); \
292 mutex_lock(&data->update_lock); \
293 data->value = type##_TO_REG(val); \
294 gl518_write_value(client, reg, data->value); \
295 mutex_unlock(&data->update_lock); \
299 #define set_bits(type, suffix, value, reg, mask, shift) \
300 static ssize_t set_##suffix(struct device *dev, \
301 struct device_attribute *attr, \
302 const char *buf, size_t count) \
304 struct gl518_data *data = dev_get_drvdata(dev); \
305 struct i2c_client *client = data->client; \
308 int err = kstrtoul(buf, 10, &val); \
312 mutex_lock(&data->update_lock); \
313 regvalue = gl518_read_value(client, reg); \
314 data->value = type##_TO_REG(val); \
315 regvalue = (regvalue & ~mask) | (data->value << shift); \
316 gl518_write_value(client, reg, regvalue); \
317 mutex_unlock(&data->update_lock); \
321 #define set_low(type, suffix, value, reg) \
322 set_bits(type, suffix, value, reg, 0x00ff, 0)
323 #define set_high(type, suffix, value, reg) \
324 set_bits(type, suffix, value, reg, 0xff00, 8)
326 set(TEMP, temp_max1, temp_max, GL518_REG_TEMP_MAX);
327 set(TEMP, temp_hyst1, temp_hyst, GL518_REG_TEMP_HYST);
328 set_bits(BOOL, fan_auto1, fan_auto1, GL518_REG_MISC, 0x08, 3);
329 set_low(VDD, in_min0, voltage_min[0], GL518_REG_VDD_LIMIT);
330 set_low(IN, in_min1, voltage_min[1], GL518_REG_VIN1_LIMIT);
331 set_low(IN, in_min2, voltage_min[2], GL518_REG_VIN2_LIMIT);
332 set_low(IN, in_min3, voltage_min[3], GL518_REG_VIN3_LIMIT);
333 set_high(VDD, in_max0, voltage_max[0], GL518_REG_VDD_LIMIT);
334 set_high(IN, in_max1, voltage_max[1], GL518_REG_VIN1_LIMIT);
335 set_high(IN, in_max2, voltage_max[2], GL518_REG_VIN2_LIMIT);
336 set_high(IN, in_max3, voltage_max[3], GL518_REG_VIN3_LIMIT);
337 set_bits(BOOL, beep_enable, beep_enable, GL518_REG_CONF, 0x04, 2);
338 set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM);
340 static ssize_t fan_min_store(struct device *dev,
341 struct device_attribute *attr, const char *buf,
344 struct gl518_data *data = dev_get_drvdata(dev);
345 struct i2c_client *client = data->client;
346 int nr = to_sensor_dev_attr(attr)->index;
351 err = kstrtoul(buf, 10, &val);
355 mutex_lock(&data->update_lock);
356 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
357 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
358 regvalue = (regvalue & (0xff << (8 * nr)))
359 | (data->fan_min[nr] << (8 * (1 - nr)));
360 gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue);
362 data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
363 if (data->fan_min[nr] == 0)
364 data->alarm_mask &= ~(0x20 << nr);
366 data->alarm_mask |= (0x20 << nr);
367 data->beep_mask &= data->alarm_mask;
368 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
370 mutex_unlock(&data->update_lock);
374 static ssize_t fan_div_store(struct device *dev,
375 struct device_attribute *attr, const char *buf,
378 struct gl518_data *data = dev_get_drvdata(dev);
379 struct i2c_client *client = data->client;
380 int nr = to_sensor_dev_attr(attr)->index;
385 err = kstrtoul(buf, 10, &val);
404 "Invalid fan clock divider %lu, choose one of 1, 2, 4 or 8\n",
409 mutex_lock(&data->update_lock);
410 regvalue = gl518_read_value(client, GL518_REG_MISC);
411 data->fan_div[nr] = val;
412 regvalue = (regvalue & ~(0xc0 >> (2 * nr)))
413 | (data->fan_div[nr] << (6 - 2 * nr));
414 gl518_write_value(client, GL518_REG_MISC, regvalue);
415 mutex_unlock(&data->update_lock);
419 static DEVICE_ATTR(temp1_input, 0444, show_temp_input1, NULL);
420 static DEVICE_ATTR(temp1_max, 0644, show_temp_max1, set_temp_max1);
421 static DEVICE_ATTR(temp1_max_hyst, 0644,
422 show_temp_hyst1, set_temp_hyst1);
423 static DEVICE_ATTR(fan1_auto, 0644, show_fan_auto1, set_fan_auto1);
424 static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0);
425 static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1);
426 static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
427 static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
428 static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
429 static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
430 static DEVICE_ATTR(in0_input, 0444, show_in_input0, NULL);
431 static DEVICE_ATTR(in1_input, 0444, show_in_input1, NULL);
432 static DEVICE_ATTR(in2_input, 0444, show_in_input2, NULL);
433 static DEVICE_ATTR(in3_input, 0444, show_in_input3, NULL);
434 static DEVICE_ATTR(in0_min, 0644, show_in_min0, set_in_min0);
435 static DEVICE_ATTR(in1_min, 0644, show_in_min1, set_in_min1);
436 static DEVICE_ATTR(in2_min, 0644, show_in_min2, set_in_min2);
437 static DEVICE_ATTR(in3_min, 0644, show_in_min3, set_in_min3);
438 static DEVICE_ATTR(in0_max, 0644, show_in_max0, set_in_max0);
439 static DEVICE_ATTR(in1_max, 0644, show_in_max1, set_in_max1);
440 static DEVICE_ATTR(in2_max, 0644, show_in_max2, set_in_max2);
441 static DEVICE_ATTR(in3_max, 0644, show_in_max3, set_in_max3);
442 static DEVICE_ATTR(alarms, 0444, show_alarms, NULL);
443 static DEVICE_ATTR(beep_enable, 0644,
444 show_beep_enable, set_beep_enable);
445 static DEVICE_ATTR(beep_mask, 0644,
446 show_beep_mask, set_beep_mask);
448 static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
451 int bitnr = to_sensor_dev_attr(attr)->index;
452 struct gl518_data *data = gl518_update_device(dev);
453 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
456 static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
457 static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
458 static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
459 static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
460 static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
461 static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 5);
462 static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 6);
464 static ssize_t beep_show(struct device *dev, struct device_attribute *attr,
467 int bitnr = to_sensor_dev_attr(attr)->index;
468 struct gl518_data *data = gl518_update_device(dev);
469 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
472 static ssize_t beep_store(struct device *dev, struct device_attribute *attr,
473 const char *buf, size_t count)
475 struct gl518_data *data = dev_get_drvdata(dev);
476 struct i2c_client *client = data->client;
477 int bitnr = to_sensor_dev_attr(attr)->index;
481 err = kstrtoul(buf, 10, &bit);
488 mutex_lock(&data->update_lock);
489 data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
491 data->beep_mask |= (1 << bitnr);
493 data->beep_mask &= ~(1 << bitnr);
494 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
495 mutex_unlock(&data->update_lock);
499 static SENSOR_DEVICE_ATTR_RW(in0_beep, beep, 0);
500 static SENSOR_DEVICE_ATTR_RW(in1_beep, beep, 1);
501 static SENSOR_DEVICE_ATTR_RW(in2_beep, beep, 2);
502 static SENSOR_DEVICE_ATTR_RW(in3_beep, beep, 3);
503 static SENSOR_DEVICE_ATTR_RW(temp1_beep, beep, 4);
504 static SENSOR_DEVICE_ATTR_RW(fan1_beep, beep, 5);
505 static SENSOR_DEVICE_ATTR_RW(fan2_beep, beep, 6);
507 static struct attribute *gl518_attributes[] = {
508 &dev_attr_in3_input.attr,
509 &dev_attr_in0_min.attr,
510 &dev_attr_in1_min.attr,
511 &dev_attr_in2_min.attr,
512 &dev_attr_in3_min.attr,
513 &dev_attr_in0_max.attr,
514 &dev_attr_in1_max.attr,
515 &dev_attr_in2_max.attr,
516 &dev_attr_in3_max.attr,
517 &sensor_dev_attr_in0_alarm.dev_attr.attr,
518 &sensor_dev_attr_in1_alarm.dev_attr.attr,
519 &sensor_dev_attr_in2_alarm.dev_attr.attr,
520 &sensor_dev_attr_in3_alarm.dev_attr.attr,
521 &sensor_dev_attr_in0_beep.dev_attr.attr,
522 &sensor_dev_attr_in1_beep.dev_attr.attr,
523 &sensor_dev_attr_in2_beep.dev_attr.attr,
524 &sensor_dev_attr_in3_beep.dev_attr.attr,
526 &dev_attr_fan1_auto.attr,
527 &sensor_dev_attr_fan1_input.dev_attr.attr,
528 &sensor_dev_attr_fan2_input.dev_attr.attr,
529 &sensor_dev_attr_fan1_min.dev_attr.attr,
530 &sensor_dev_attr_fan2_min.dev_attr.attr,
531 &sensor_dev_attr_fan1_div.dev_attr.attr,
532 &sensor_dev_attr_fan2_div.dev_attr.attr,
533 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
534 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
535 &sensor_dev_attr_fan1_beep.dev_attr.attr,
536 &sensor_dev_attr_fan2_beep.dev_attr.attr,
538 &dev_attr_temp1_input.attr,
539 &dev_attr_temp1_max.attr,
540 &dev_attr_temp1_max_hyst.attr,
541 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
542 &sensor_dev_attr_temp1_beep.dev_attr.attr,
544 &dev_attr_alarms.attr,
545 &dev_attr_beep_enable.attr,
546 &dev_attr_beep_mask.attr,
550 static const struct attribute_group gl518_group = {
551 .attrs = gl518_attributes,
554 static struct attribute *gl518_attributes_r80[] = {
555 &dev_attr_in0_input.attr,
556 &dev_attr_in1_input.attr,
557 &dev_attr_in2_input.attr,
561 static const struct attribute_group gl518_group_r80 = {
562 .attrs = gl518_attributes_r80,
569 /* Return 0 if detection is successful, -ENODEV otherwise */
570 static int gl518_detect(struct i2c_client *client, struct i2c_board_info *info)
572 struct i2c_adapter *adapter = client->adapter;
575 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
576 I2C_FUNC_SMBUS_WORD_DATA))
579 /* Now, we do the remaining detection. */
580 if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80)
581 || (gl518_read_value(client, GL518_REG_CONF) & 0x80))
584 /* Determine the chip type. */
585 rev = gl518_read_value(client, GL518_REG_REVISION);
586 if (rev != 0x00 && rev != 0x80)
589 strscpy(info->type, "gl518sm", I2C_NAME_SIZE);
595 * Called when we have found a new GL518SM.
596 * Note that we preserve D4:NoFan2 and D2:beep_enable.
598 static void gl518_init_client(struct i2c_client *client)
600 /* Make sure we leave D7:Reset untouched */
601 u8 regvalue = gl518_read_value(client, GL518_REG_CONF) & 0x7f;
603 /* Comparator mode (D3=0), standby mode (D6=0) */
604 gl518_write_value(client, GL518_REG_CONF, (regvalue &= 0x37));
606 /* Never interrupts */
607 gl518_write_value(client, GL518_REG_MASK, 0x00);
609 /* Clear status register (D5=1), start (D6=1) */
610 gl518_write_value(client, GL518_REG_CONF, 0x20 | regvalue);
611 gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue);
614 static int gl518_probe(struct i2c_client *client)
616 struct device *dev = &client->dev;
617 struct device *hwmon_dev;
618 struct gl518_data *data;
621 data = devm_kzalloc(dev, sizeof(struct gl518_data), GFP_KERNEL);
625 data->client = client;
626 revision = gl518_read_value(client, GL518_REG_REVISION);
627 data->type = revision == 0x80 ? gl518sm_r80 : gl518sm_r00;
628 mutex_init(&data->update_lock);
630 /* Initialize the GL518SM chip */
631 data->alarm_mask = 0xff;
632 gl518_init_client(client);
635 data->groups[0] = &gl518_group;
636 if (data->type == gl518sm_r80)
637 data->groups[1] = &gl518_group_r80;
639 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
641 return PTR_ERR_OR_ZERO(hwmon_dev);
644 static const struct i2c_device_id gl518_id[] = {
648 MODULE_DEVICE_TABLE(i2c, gl518_id);
650 static struct i2c_driver gl518_driver = {
651 .class = I2C_CLASS_HWMON,
655 .probe = gl518_probe,
656 .id_table = gl518_id,
657 .detect = gl518_detect,
658 .address_list = normal_i2c,
661 module_i2c_driver(gl518_driver);
663 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
664 "Kyosti Malkki <kmalkki@cc.hut.fi> and "
665 "Hong-Gunn Chew <hglinux@gunnet.org>");
666 MODULE_DESCRIPTION("GL518SM driver");
667 MODULE_LICENSE("GPL");