28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/pci.h>
44 static int force_addr;
50 #define VT8231_EXTENT 0x80
51 #define VT8231_BASE_REG 0x70
52 #define VT8231_ENABLE_REG 0x74
77 #define VT8231_REG_FAN_MIN(nr) (0x3b + (nr))
78 #define VT8231_REG_FAN(nr) (0x29 + (nr))
82 static const u8 regvolt[] = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26 };
83 static const u8 regvoltmax[] = { 0x3d, 0x2b, 0x2d, 0x2f, 0x31, 0x33 };
84 static const u8 regvoltmin[] = { 0x3e, 0x2c, 0x2e, 0x30, 0x32, 0x34 };
95 #define VT8231_REG_TEMP_LOW01 0x49
96 #define VT8231_REG_TEMP_LOW25 0x4d
98 static const u8 regtemp[] = { 0x1f, 0x21, 0x22, 0x23, 0x24, 0x25 };
99 static const u8 regtempmax[] = { 0x39, 0x3d, 0x2b, 0x2d, 0x2f, 0x31 };
100 static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
102 #define TEMP_FROM_REG(reg) (((253 * 4 - (reg)) * 550 + 105) / 210)
103 #define TEMP_MAXMIN_FROM_REG(reg) (((253 - (reg)) * 2200 + 105) / 210)
104 #define TEMP_MAXMIN_TO_REG(val) (253 - ((val) * 210 + 1100) / 2200)
106 #define VT8231_REG_CONFIG 0x40
107 #define VT8231_REG_ALARM1 0x41
108 #define VT8231_REG_ALARM2 0x42
109 #define VT8231_REG_FANDIV 0x47
110 #define VT8231_REG_UCH_CONFIG 0x4a
111 #define VT8231_REG_TEMP1_CONFIG 0x4b
112 #define VT8231_REG_TEMP2_CONFIG 0x4c
118 #define ISTEMP(i, ch_config) ((i) == 0 ? 1 : \
119 ((ch_config) >> ((i)+1)) & 0x01)
121 #define ISVOLT(i, ch_config) ((i) == 5 ? 1 : \
122 !(((ch_config) >> ((i)+2)) & 0x01))
124 #define DIV_FROM_REG(val) (1 << (val))
150 return SENSORS_LIMIT(1310720 / (rpm * div), 1, 255);
153 #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : 1310720 / ((val) * (div)))
177 static struct pci_dev *s_bridge;
202 return sprintf(buf,
"%d\n", ((data->
in[nr] - 3) * 10000) / 958);
209 int nr = sensor_attr->
index;
210 struct vt8231_data *data = vt8231_update_device(dev);
212 return sprintf(buf,
"%d\n", ((data->
in_min[nr] - 3) * 10000) / 958);
219 int nr = sensor_attr->
index;
220 struct vt8231_data *data = vt8231_update_device(dev);
222 return sprintf(buf,
"%d\n", (((data->
in_max[nr] - 3) * 10000) / 958));
226 const char *buf,
size_t count)
229 int nr = sensor_attr->
index;
234 err = kstrtoul(buf, 10, &val);
239 data->
in_min[
nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255);
240 vt8231_write_value(data, regvoltmin[nr], data->
in_min[nr]);
246 const char *buf,
size_t count)
249 int nr = sensor_attr->
index;
254 err = kstrtoul(buf, 10, &val);
259 data->
in_max[
nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255);
260 vt8231_write_value(data, regvoltmax[nr], data->
in_max[nr]);
269 struct vt8231_data *data = vt8231_update_device(dev);
272 (((data->
in[5] - 3) * 10000 * 54) / (958 * 34)));
278 struct vt8231_data *data = vt8231_update_device(dev);
281 (((data->
in_min[5] - 3) * 10000 * 54) / (958 * 34)));
287 struct vt8231_data *data = vt8231_update_device(dev);
290 (((data->
in_max[5] - 3) * 10000 * 54) / (958 * 34)));
294 const char *buf,
size_t count)
300 err = kstrtoul(buf, 10, &val);
305 data->
in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3,
307 vt8231_write_value(data, regvoltmin[5], data->
in_min[5]);
313 const char *buf,
size_t count)
319 err = kstrtoul(buf, 10, &val);
324 data->
in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3,
326 vt8231_write_value(data, regvoltmax[5], data->
in_max[5]);
331 #define define_voltage_sysfs(offset) \
332 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
333 show_in, NULL, offset); \
334 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
335 show_in_min, set_in_min, offset); \
336 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
337 show_in_max, set_in_max, offset)
353 struct vt8231_data *data = vt8231_update_device(dev);
360 struct vt8231_data *data = vt8231_update_device(dev);
367 struct vt8231_data *data = vt8231_update_device(dev);
372 const char *buf,
size_t count)
378 err = kstrtol(buf, 10, &val);
383 data->
temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255);
384 vt8231_write_value(data, regtempmax[0], data->
temp_max[0]);
389 const char *buf,
size_t count)
395 err = kstrtol(buf, 10, &val);
400 data->
temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255);
401 vt8231_write_value(data, regtempmin[0], data->
temp_min[0]);
410 int nr = sensor_attr->
index;
411 struct vt8231_data *data = vt8231_update_device(dev);
419 int nr = sensor_attr->
index;
420 struct vt8231_data *data = vt8231_update_device(dev);
428 int nr = sensor_attr->
index;
429 struct vt8231_data *data = vt8231_update_device(dev);
434 const char *buf,
size_t count)
437 int nr = sensor_attr->
index;
442 err = kstrtol(buf, 10, &val);
448 vt8231_write_value(data, regtempmax[nr], data->
temp_max[nr]);
453 const char *buf,
size_t count)
456 int nr = sensor_attr->
index;
461 err = kstrtol(buf, 10, &val);
467 vt8231_write_value(data, regtempmin[nr], data->
temp_min[nr]);
476 #define define_temperature_sysfs(offset) \
477 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
478 show_temp, NULL, offset - 1); \
479 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
480 show_temp_max, set_temp_max, offset - 1); \
481 static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
482 show_temp_min, set_temp_min, offset - 1)
500 int nr = sensor_attr->
index;
501 struct vt8231_data *data = vt8231_update_device(dev);
510 int nr = sensor_attr->
index;
511 struct vt8231_data *data = vt8231_update_device(dev);
520 int nr = sensor_attr->
index;
521 struct vt8231_data *data = vt8231_update_device(dev);
526 const char *buf,
size_t count)
529 int nr = sensor_attr->
index;
534 err = kstrtoul(buf, 10, &val);
546 const char *buf,
size_t count)
551 int nr = sensor_attr->
index;
557 err = kstrtoul(buf, 10, &val);
576 dev_err(dev,
"fan_div value %ld not supported. "
577 "Choose one of 1, 2, 4 or 8!\n", val);
586 old = (old & 0x0f) | (data->
fan_div[1] << 6) | (data->
fan_div[0] << 4);
593 #define define_fan_sysfs(offset) \
594 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
595 show_fan, NULL, offset - 1); \
596 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
597 show_fan_div, set_fan_div, offset - 1); \
598 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
599 show_fan_min, set_fan_min, offset - 1)
608 struct vt8231_data *data = vt8231_update_device(dev);
617 struct vt8231_data *data = vt8231_update_device(dev);
643 static struct attribute *vt8231_attributes_temps[6][5] = {
645 &dev_attr_temp1_input.attr,
646 &dev_attr_temp1_max_hyst.attr,
647 &dev_attr_temp1_max.attr,
648 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
651 &sensor_dev_attr_temp2_input.dev_attr.attr,
652 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
653 &sensor_dev_attr_temp2_max.dev_attr.attr,
654 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
657 &sensor_dev_attr_temp3_input.dev_attr.attr,
658 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
659 &sensor_dev_attr_temp3_max.dev_attr.attr,
660 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
663 &sensor_dev_attr_temp4_input.dev_attr.attr,
664 &sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
665 &sensor_dev_attr_temp4_max.dev_attr.attr,
666 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
669 &sensor_dev_attr_temp5_input.dev_attr.attr,
670 &sensor_dev_attr_temp5_max_hyst.dev_attr.attr,
671 &sensor_dev_attr_temp5_max.dev_attr.attr,
672 &sensor_dev_attr_temp5_alarm.dev_attr.attr,
675 &sensor_dev_attr_temp6_input.dev_attr.attr,
676 &sensor_dev_attr_temp6_max_hyst.dev_attr.attr,
677 &sensor_dev_attr_temp6_max.dev_attr.attr,
678 &sensor_dev_attr_temp6_alarm.dev_attr.attr,
684 { .attrs = vt8231_attributes_temps[0] },
685 { .attrs = vt8231_attributes_temps[1] },
686 { .attrs = vt8231_attributes_temps[2] },
687 { .attrs = vt8231_attributes_temps[3] },
688 { .attrs = vt8231_attributes_temps[4] },
689 { .attrs = vt8231_attributes_temps[5] },
692 static struct attribute *vt8231_attributes_volts[6][5] = {
694 &sensor_dev_attr_in0_input.dev_attr.attr,
695 &sensor_dev_attr_in0_min.dev_attr.attr,
696 &sensor_dev_attr_in0_max.dev_attr.attr,
697 &sensor_dev_attr_in0_alarm.dev_attr.attr,
700 &sensor_dev_attr_in1_input.dev_attr.attr,
701 &sensor_dev_attr_in1_min.dev_attr.attr,
702 &sensor_dev_attr_in1_max.dev_attr.attr,
703 &sensor_dev_attr_in1_alarm.dev_attr.attr,
706 &sensor_dev_attr_in2_input.dev_attr.attr,
707 &sensor_dev_attr_in2_min.dev_attr.attr,
708 &sensor_dev_attr_in2_max.dev_attr.attr,
709 &sensor_dev_attr_in2_alarm.dev_attr.attr,
712 &sensor_dev_attr_in3_input.dev_attr.attr,
713 &sensor_dev_attr_in3_min.dev_attr.attr,
714 &sensor_dev_attr_in3_max.dev_attr.attr,
715 &sensor_dev_attr_in3_alarm.dev_attr.attr,
718 &sensor_dev_attr_in4_input.dev_attr.attr,
719 &sensor_dev_attr_in4_min.dev_attr.attr,
720 &sensor_dev_attr_in4_max.dev_attr.attr,
721 &sensor_dev_attr_in4_alarm.dev_attr.attr,
724 &dev_attr_in5_input.attr,
725 &dev_attr_in5_min.attr,
726 &dev_attr_in5_max.attr,
727 &sensor_dev_attr_in5_alarm.dev_attr.attr,
733 { .attrs = vt8231_attributes_volts[0] },
734 { .attrs = vt8231_attributes_volts[1] },
735 { .attrs = vt8231_attributes_volts[2] },
736 { .attrs = vt8231_attributes_volts[3] },
737 { .attrs = vt8231_attributes_volts[4] },
738 { .attrs = vt8231_attributes_volts[5] },
741 static struct attribute *vt8231_attributes[] = {
742 &sensor_dev_attr_fan1_input.dev_attr.attr,
743 &sensor_dev_attr_fan2_input.dev_attr.attr,
744 &sensor_dev_attr_fan1_min.dev_attr.attr,
745 &sensor_dev_attr_fan2_min.dev_attr.attr,
746 &sensor_dev_attr_fan1_div.dev_attr.attr,
747 &sensor_dev_attr_fan2_div.dev_attr.attr,
748 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
749 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
750 &dev_attr_alarms.attr,
756 .attrs = vt8231_attributes,
764 .probe = vt8231_probe,
778 static struct pci_driver vt8231_pci_driver = {
780 .id_table = vt8231_pci_ids,
781 .probe = vt8231_pci_probe,
793 vt8231_driver.
driver.name)) {
794 dev_err(&pdev->
dev,
"Region 0x%lx-0x%lx already in use!\n",
795 (
unsigned long)res->
start, (
unsigned long)res->
end);
803 platform_set_drvdata(pdev, data);
805 data->
name =
"vt8231";
808 vt8231_init_device(data);
821 &vt8231_group_temps[
i]);
823 goto exit_remove_files;
830 &vt8231_group_volts[
i]);
832 goto exit_remove_files;
839 goto exit_remove_files;
847 for (i = 0; i <
ARRAY_SIZE(vt8231_group_temps); i++)
856 struct vt8231_data *data = platform_get_drvdata(pdev);
861 for (i = 0; i <
ARRAY_SIZE(vt8231_group_volts); i++)
864 for (i = 0; i <
ARRAY_SIZE(vt8231_group_temps); i++)
872 static void vt8231_init_device(
struct vt8231_data *data)
888 for (i = 0; i < 6; i++) {
890 data->
in[
i] = vt8231_read_value(data,
892 data->
in_min[
i] = vt8231_read_value(data,
894 data->
in_max[
i] = vt8231_read_value(data,
898 for (i = 0; i < 2; i++) {
899 data->
fan[
i] = vt8231_read_value(data,
901 data->
fan_min[
i] = vt8231_read_value(data,
906 low = (low >> 6) | ((low & 0x30) >> 2)
908 for (i = 0; i < 6; i++) {
910 data->
temp[
i] = (vt8231_read_value(data,
912 | ((low >> (2 * i)) & 0x03);
913 data->
temp_max[
i] = vt8231_read_value(data,
915 data->
temp_min[
i] = vt8231_read_value(data,
921 data->
fan_div[0] = (i >> 4) & 0x03;
963 pr_err(
"Device allocation failed\n");
969 pr_err(
"Device resource addition failed (%d)\n", err);
970 goto exit_device_put;
975 pr_err(
"Device addition failed (%d)\n", err);
976 goto exit_device_put;
992 address = force_addr & 0xff00;
1007 dev_err(&dev->
dev,
"base address not set - upgrade BIOS or use force_addr=0xaddr\n");
1015 if (!(val & 0x0001)) {
1027 if (vt8231_device_add(address))
1028 goto exit_unregister;
1049 static int __init sm_vt8231_init(
void)
1051 return pci_register_driver(&vt8231_pci_driver);
1054 static void __exit sm_vt8231_exit(
void)
1057 if (s_bridge !=
NULL) {