24 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include <linux/i2c.h>
37 static unsigned short extra_sensor_type;
39 MODULE_PARM_DESC(extra_sensor_type,
"Type of extra sensor (0=autodetect, 1=temperature, 2=voltage)");
42 static const unsigned short normal_i2c[] = { 0x2c, 0x2d,
I2C_CLIENT_END };
51 #define GL520_REG_CHIP_ID 0x00
52 #define GL520_REG_REVISION 0x01
53 #define GL520_REG_CONF 0x03
54 #define GL520_REG_MASK 0x11
56 #define GL520_REG_VID_INPUT 0x02
58 static const u8 GL520_REG_IN_INPUT[] = { 0x15, 0x14, 0x13, 0x0d, 0x0e };
59 static const u8 GL520_REG_IN_LIMIT[] = { 0x0c, 0x09, 0x0a, 0x0b };
60 static const u8 GL520_REG_IN_MIN[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x18 };
61 static const u8 GL520_REG_IN_MAX[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x17 };
63 static const u8 GL520_REG_TEMP_INPUT[] = { 0x04, 0x0e };
64 static const u8 GL520_REG_TEMP_MAX[] = { 0x05, 0x17 };
65 static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 };
67 #define GL520_REG_FAN_INPUT 0x07
68 #define GL520_REG_FAN_MIN 0x08
69 #define GL520_REG_FAN_DIV 0x0f
70 #define GL520_REG_FAN_OFF GL520_REG_FAN_DIV
72 #define GL520_REG_ALARMS 0x12
73 #define GL520_REG_BEEP_MASK 0x10
74 #define GL520_REG_BEEP_ENABLE GL520_REG_CONF
101 .probe = gl520_probe,
102 .remove = gl520_remove,
103 .id_table = gl520_id,
104 .detect = gl520_detect,
105 .address_list = normal_i2c,
146 #define VDD_FROM_REG(val) (((val) * 95 + 2) / 4)
147 #define VDD_TO_REG(val) SENSORS_LIMIT((((val) * 4 + 47) / 95), 0, 255)
149 #define IN_FROM_REG(val) ((val) * 19)
150 #define IN_TO_REG(val) SENSORS_LIMIT((((val) + 9) / 19), 0, 255)
182 struct gl520_data *data = gl520_update_device(dev);
192 const char *buf,
size_t count)
195 struct gl520_data *data = i2c_get_clientdata(client);
201 err = kstrtol(buf, 10, &v);
215 gl520_write_value(client, GL520_REG_IN_MIN[n],
216 (gl520_read_value(client, GL520_REG_IN_MIN[n])
219 gl520_write_value(client, GL520_REG_IN_MIN[n], r);
226 const char *buf,
size_t count)
229 struct gl520_data *data = i2c_get_clientdata(client);
235 err = kstrtol(buf, 10, &v);
249 gl520_write_value(client, GL520_REG_IN_MAX[n],
250 (gl520_read_value(client, GL520_REG_IN_MAX[n])
251 & ~0xff00) | (r << 8));
253 gl520_write_value(client, GL520_REG_IN_MAX[n], r);
265 get_in_min, set_in_min, 0);
267 get_in_min, set_in_min, 1);
269 get_in_min, set_in_min, 2);
271 get_in_min, set_in_min, 3);
273 get_in_min, set_in_min, 4);
275 get_in_max, set_in_max, 0);
277 get_in_max, set_in_max, 1);
279 get_in_max, set_in_max, 2);
281 get_in_max, set_in_max, 3);
283 get_in_max, set_in_max, 4);
285 #define DIV_FROM_REG(val) (1 << (val))
286 #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) << (div))))
287 #define FAN_TO_REG(val, div) ((val) <= 0 ? 0 : \
288 SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, \
295 struct gl520_data *data = gl520_update_device(dev);
305 struct gl520_data *data = gl520_update_device(dev);
315 struct gl520_data *data = gl520_update_device(dev);
323 struct gl520_data *data = gl520_update_device(dev);
328 const char *buf,
size_t count)
331 struct gl520_data *data = i2c_get_clientdata(client);
337 err = kstrtoul(buf, 10, &v);
348 & ~0xff00) | (r << 8));
367 const char *buf,
size_t count)
370 struct gl520_data *data = i2c_get_clientdata(client);
376 err = kstrtoul(buf, 10, &v);
395 "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", v);
405 & ~0xc0) | (r << 6));
409 & ~0x30) | (r << 4));
416 const char *buf,
size_t count)
419 struct gl520_data *data = i2c_get_clientdata(client);
424 err = kstrtoul(buf, 10, &v);
434 & ~0x0c) | (r << 2));
442 get_fan_min, set_fan_min, 0);
444 get_fan_min, set_fan_min, 1);
446 get_fan_div, set_fan_div, 0);
448 get_fan_div, set_fan_div, 1);
450 get_fan_off, set_fan_off);
452 #define TEMP_FROM_REG(val) (((val) - 130) * 1000)
453 #define TEMP_TO_REG(val) SENSORS_LIMIT(((((val) < 0 ? \
454 (val) - 500 : (val) + 500) / 1000) + 130), 0, 255)
460 struct gl520_data *data = gl520_update_device(dev);
469 struct gl520_data *data = gl520_update_device(dev);
478 struct gl520_data *data = gl520_update_device(dev);
484 const char *buf,
size_t count)
487 struct gl520_data *data = i2c_get_clientdata(client);
492 err = kstrtol(buf, 10, &v);
498 gl520_write_value(client, GL520_REG_TEMP_MAX[n], data->
temp_max[n]);
504 *attr,
const char *buf,
size_t count)
507 struct gl520_data *data = i2c_get_clientdata(client);
512 err = kstrtol(buf, 10, &v);
518 gl520_write_value(client, GL520_REG_TEMP_MAX_HYST[n],
527 get_temp_max, set_temp_max, 0);
529 get_temp_max, set_temp_max, 1);
531 get_temp_max_hyst, set_temp_max_hyst, 0);
533 get_temp_max_hyst, set_temp_max_hyst, 1);
538 struct gl520_data *data = gl520_update_device(dev);
545 struct gl520_data *data = gl520_update_device(dev);
552 struct gl520_data *data = gl520_update_device(dev);
557 *attr,
const char *buf,
size_t count)
560 struct gl520_data *data = i2c_get_clientdata(client);
565 err = kstrtoul(buf, 10, &v);
575 & ~0x04) | (r << 2));
581 const char *buf,
size_t count)
584 struct gl520_data *data = i2c_get_clientdata(client);
588 err = kstrtoul(buf, 10, &r);
602 get_beep_enable, set_beep_enable);
604 get_beep_mask, set_beep_mask);
610 struct gl520_data *data = gl520_update_device(dev);
629 struct gl520_data *data = gl520_update_device(dev);
635 const char *buf,
size_t count)
638 struct gl520_data *data = i2c_get_clientdata(client);
644 err = kstrtoul(buf, 10, &bit);
671 static struct attribute *gl520_attributes[] = {
672 &dev_attr_cpu0_vid.attr,
674 &sensor_dev_attr_in0_input.dev_attr.attr,
675 &sensor_dev_attr_in0_min.dev_attr.attr,
676 &sensor_dev_attr_in0_max.dev_attr.attr,
677 &sensor_dev_attr_in0_alarm.dev_attr.attr,
678 &sensor_dev_attr_in0_beep.dev_attr.attr,
679 &sensor_dev_attr_in1_input.dev_attr.attr,
680 &sensor_dev_attr_in1_min.dev_attr.attr,
681 &sensor_dev_attr_in1_max.dev_attr.attr,
682 &sensor_dev_attr_in1_alarm.dev_attr.attr,
683 &sensor_dev_attr_in1_beep.dev_attr.attr,
684 &sensor_dev_attr_in2_input.dev_attr.attr,
685 &sensor_dev_attr_in2_min.dev_attr.attr,
686 &sensor_dev_attr_in2_max.dev_attr.attr,
687 &sensor_dev_attr_in2_alarm.dev_attr.attr,
688 &sensor_dev_attr_in2_beep.dev_attr.attr,
689 &sensor_dev_attr_in3_input.dev_attr.attr,
690 &sensor_dev_attr_in3_min.dev_attr.attr,
691 &sensor_dev_attr_in3_max.dev_attr.attr,
692 &sensor_dev_attr_in3_alarm.dev_attr.attr,
693 &sensor_dev_attr_in3_beep.dev_attr.attr,
695 &sensor_dev_attr_fan1_input.dev_attr.attr,
696 &sensor_dev_attr_fan1_min.dev_attr.attr,
697 &sensor_dev_attr_fan1_div.dev_attr.attr,
698 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
699 &sensor_dev_attr_fan1_beep.dev_attr.attr,
700 &dev_attr_fan1_off.attr,
701 &sensor_dev_attr_fan2_input.dev_attr.attr,
702 &sensor_dev_attr_fan2_min.dev_attr.attr,
703 &sensor_dev_attr_fan2_div.dev_attr.attr,
704 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
705 &sensor_dev_attr_fan2_beep.dev_attr.attr,
707 &sensor_dev_attr_temp1_input.dev_attr.attr,
708 &sensor_dev_attr_temp1_max.dev_attr.attr,
709 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
710 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
711 &sensor_dev_attr_temp1_beep.dev_attr.attr,
713 &dev_attr_alarms.attr,
714 &dev_attr_beep_enable.attr,
715 &dev_attr_beep_mask.attr,
720 .attrs = gl520_attributes,
723 static struct attribute *gl520_attributes_in4[] = {
724 &sensor_dev_attr_in4_input.dev_attr.attr,
725 &sensor_dev_attr_in4_min.dev_attr.attr,
726 &sensor_dev_attr_in4_max.dev_attr.attr,
727 &sensor_dev_attr_in4_alarm.dev_attr.attr,
728 &sensor_dev_attr_in4_beep.dev_attr.attr,
732 static struct attribute *gl520_attributes_temp2[] = {
733 &sensor_dev_attr_temp2_input.dev_attr.attr,
734 &sensor_dev_attr_temp2_max.dev_attr.attr,
735 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
736 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
737 &sensor_dev_attr_temp2_beep.dev_attr.attr,
742 .attrs = gl520_attributes_in4,
746 .attrs = gl520_attributes_temp2,
767 dev_dbg(&client->
dev,
"Unknown chip type, skipping\n");
776 static int gl520_probe(
struct i2c_client *client,
787 i2c_set_clientdata(client, data);
791 gl520_init_client(client);
804 goto exit_remove_files;
809 goto exit_remove_files;
823 static void gl520_init_client(
struct i2c_client *client)
825 struct gl520_data *data = i2c_get_clientdata(client);
833 if (extra_sensor_type == 1)
835 else if (extra_sensor_type == 2)
849 gl520_update_device(&(client->
dev));
860 static int gl520_remove(
struct i2c_client *client)
862 struct gl520_data *data = i2c_get_clientdata(client);
879 if ((reg >= 0x07) && (reg <= 0x0c))
880 return i2c_smbus_read_word_swapped(client, reg);
887 if ((reg >= 0x07) && (reg <= 0x0c))
888 return i2c_smbus_write_word_swapped(client, reg, value);
897 struct gl520_data *data = i2c_get_clientdata(client);
904 dev_dbg(&client->
dev,
"Starting gl520sm update\n");
908 data->
vid = gl520_read_value(client,
911 for (i = 0; i < 4; i++) {
912 data->
in_input[
i] = gl520_read_value(client,
913 GL520_REG_IN_INPUT[i]);
914 val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]);
916 data->
in_max[
i] = (val >> 8) & 0xff;
924 data->
fan_min[0] = (val >> 8) & 0xff;
927 data->
temp_input[0] = gl520_read_value(client,
928 GL520_REG_TEMP_INPUT[0]);
929 data->
temp_max[0] = gl520_read_value(client,
930 GL520_REG_TEMP_MAX[0]);
932 GL520_REG_TEMP_MAX_HYST[0]);
935 data->
fan_div[0] = (val >> 6) & 0x03;
936 data->
fan_div[1] = (val >> 4) & 0x03;
937 data->
fan_off = (val >> 2) & 0x01;
946 data->
temp_input[1] = gl520_read_value(client,
947 GL520_REG_TEMP_INPUT[1]);
948 data->
temp_max[1] = gl520_read_value(client,
949 GL520_REG_TEMP_MAX[1]);
951 GL520_REG_TEMP_MAX_HYST[1]);
953 data->
in_input[4] = gl520_read_value(client,
954 GL520_REG_IN_INPUT[4]);
955 data->
in_min[4] = gl520_read_value(client,
956 GL520_REG_IN_MIN[4]);
957 data->
in_max[4] = gl520_read_value(client,
958 GL520_REG_IN_MAX[4]);