34 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
36 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/pci.h>
55 static unsigned short force_addr;
58 "Initialize the base address of the sensors");
70 #define VIA686A_EXTENT 0x80
71 #define VIA686A_BASE_REG 0x70
72 #define VIA686A_ENABLE_REG 0x74
76 #define VIA686A_REG_IN_MAX(nr) (0x2b + ((nr) * 2))
77 #define VIA686A_REG_IN_MIN(nr) (0x2c + ((nr) * 2))
78 #define VIA686A_REG_IN(nr) (0x22 + (nr))
81 #define VIA686A_REG_FAN_MIN(nr) (0x3a + (nr))
82 #define VIA686A_REG_FAN(nr) (0x28 + (nr))
85 static const u8 VIA686A_REG_TEMP[] = { 0x20, 0x21, 0x1f };
86 static const u8 VIA686A_REG_TEMP_OVER[] = { 0x39, 0x3d, 0x1d };
87 static const u8 VIA686A_REG_TEMP_HYST[] = { 0x3a, 0x3e, 0x1e };
89 #define VIA686A_REG_TEMP_LOW1 0x4b
91 #define VIA686A_REG_TEMP_LOW23 0x49
93 #define VIA686A_REG_ALARM1 0x41
94 #define VIA686A_REG_ALARM2 0x42
95 #define VIA686A_REG_FANDIV 0x47
96 #define VIA686A_REG_CONFIG 0x40
105 #define VIA686A_REG_TEMP_MODE 0x4b
107 #define VIA686A_TEMP_MODE_MASK 0x3F
108 #define VIA686A_TEMP_MODE_CONTINUOUS 0x00
139 SENSORS_LIMIT((val * 21024 - 1205000) / 250000, 0, 255);
142 SENSORS_LIMIT((val * 15737 - 1205000) / 250000, 0, 255);
145 SENSORS_LIMIT((val * 10108 - 1205000) / 250000, 0, 255);
148 SENSORS_LIMIT((val * 41714 - 12050000) / 2500000, 0, 255);
159 return (
long) ((250000 * val + 1330000 + 21024 / 2) / 21024);
161 return (
long) ((250000 * val + 1330000 + 15737 / 2) / 15737);
163 return (
long) ((250000 * val + 1330000 + 10108 / 2) / 10108);
165 return (
long) ((2500000 * val + 13300000 + 41714 / 2) / 41714);
178 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
179 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 255);
182 #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (val) == 255 ? 0 : 1350000 / \
219 static const s16 tempLUT[] = {
220 -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519,
221 -503, -487, -471, -456, -442, -428, -414, -400, -387, -375,
222 -362, -350, -339, -327, -316, -305, -295, -285, -275, -265,
223 -255, -246, -237, -229, -220, -212, -204, -196, -188, -180,
224 -173, -166, -159, -152, -145, -139, -132, -126, -120, -114,
225 -108, -102, -96, -91, -85, -80, -74, -69, -64, -59, -54, -49,
226 -44, -39, -34, -29, -25, -20, -15, -11, -6, -2, 3, 7, 12, 16,
227 20, 25, 29, 33, 37, 42, 46, 50, 54, 59, 63, 67, 71, 75, 79, 84,
228 88, 92, 96, 100, 104, 109, 113, 117, 121, 125, 130, 134, 138,
229 142, 146, 151, 155, 159, 163, 168, 172, 176, 181, 185, 189,
230 193, 198, 202, 206, 211, 215, 219, 224, 228, 232, 237, 241,
231 245, 250, 254, 259, 263, 267, 272, 276, 281, 285, 290, 294,
232 299, 303, 307, 312, 316, 321, 325, 330, 334, 339, 344, 348,
233 353, 357, 362, 366, 371, 376, 380, 385, 390, 395, 399, 404,
234 409, 414, 419, 423, 428, 433, 438, 443, 449, 454, 459, 464,
235 469, 475, 480, 486, 491, 497, 502, 508, 514, 520, 526, 532,
236 538, 544, 551, 557, 564, 571, 578, 584, 592, 599, 606, 614,
237 621, 629, 637, 645, 654, 662, 671, 680, 689, 698, 708, 718,
238 728, 738, 749, 759, 770, 782, 793, 805, 818, 830, 843, 856,
239 870, 883, 898, 912, 927, 943, 958, 975, 991, 1008, 1026, 1044,
240 1062, 1081, 1101, 1121, 1141, 1162, 1184, 1206, 1229, 1252,
241 1276, 1301, 1326, 1352, 1378, 1406, 1434, 1462
267 static const u8 viaLUT[] = {
268 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23,
269 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40,
270 41, 43, 45, 46, 48, 49, 51, 53, 55, 57, 59, 60, 62, 64, 66,
271 69, 71, 73, 75, 77, 79, 82, 84, 86, 88, 91, 93, 95, 98, 100,
272 103, 105, 107, 110, 112, 115, 117, 119, 122, 124, 126, 129,
273 131, 134, 136, 138, 140, 143, 145, 147, 150, 152, 154, 156,
274 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180,
275 182, 183, 185, 187, 188, 190, 192, 193, 195, 196, 198, 199,
276 200, 202, 203, 205, 206, 207, 208, 209, 210, 211, 212, 213,
277 214, 215, 216, 217, 218, 219, 220, 221, 222, 222, 223, 224,
278 225, 226, 226, 227, 228, 228, 229, 230, 230, 231, 232, 232,
279 233, 233, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239,
290 return viaLUT[val <= -50000 ? 0 : val >= 110000 ? 160 :
291 (val < 0 ? val - 500 : val + 500) / 1000 + 50];
295 #define TEMP_FROM_REG(val) ((long)tempLUT[val] * 100)
298 static inline long TEMP_FROM_REG10(
u16 val)
300 u16 eightBits = val >> 2;
301 u16 twoBits = val & 3;
304 if (twoBits == 0 || eightBits == 255)
308 return (tempLUT[eightBits] * (4 - twoBits) +
309 tempLUT[eightBits + 1] * twoBits) * 25;
312 #define DIV_FROM_REG(val) (1 << (val))
313 #define DIV_TO_REG(val) ((val) == 8 ? 3 : (val) == 4 ? 2 : (val) == 1 ? 0 : 1)
339 static struct pci_dev *s_bridge;
373 int nr = attr->
index;
381 int nr = attr->
index;
386 const char *buf,
size_t count) {
389 int nr = attr->
index;
393 err = kstrtoul(buf, 10, &val);
405 const char *buf,
size_t count) {
408 int nr = attr->
index;
412 err = kstrtoul(buf, 10, &val);
423 #define show_in_offset(offset) \
424 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
425 show_in, NULL, offset); \
426 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
427 show_in_min, set_in_min, offset); \
428 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
429 show_in_max, set_in_max, offset);
442 int nr = attr->
index;
443 return sprintf(buf,
"%ld\n", TEMP_FROM_REG10(data->
temp[nr]));
449 int nr = attr->
index;
456 int nr = attr->
index;
460 const char *buf,
size_t count) {
463 int nr = attr->
index;
467 err = kstrtol(buf, 10, &val);
473 via686a_write_value(data, VIA686A_REG_TEMP_OVER[nr],
479 const char *buf,
size_t count) {
482 int nr = attr->
index;
486 err = kstrtol(buf, 10, &val);
492 via686a_write_value(data, VIA686A_REG_TEMP_HYST[nr],
497 #define show_temp_offset(offset) \
498 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
499 show_temp, NULL, offset - 1); \
500 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
501 show_temp_over, set_temp_over, offset - 1); \
502 static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
503 show_temp_hyst, set_temp_hyst, offset - 1);
514 int nr = attr->
index;
522 int nr = attr->
index;
531 int nr = attr->
index;
535 const char *buf,
size_t count) {
538 int nr = attr->
index;
542 err = kstrtoul(buf, 10, &val);
553 const char *buf,
size_t count) {
556 int nr = attr->
index;
561 err = kstrtoul(buf, 10, &val);
568 old = (old & 0x0f) | (data->
fan_div[1] << 6) | (data->
fan_div[0] << 4);
574 #define show_fan_offset(offset) \
575 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
576 show_fan, NULL, offset - 1); \
577 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
578 show_fan_min, set_fan_min, offset - 1); \
579 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
580 show_fan_div, set_fan_div, offset - 1);
621 static struct attribute *via686a_attributes[] = {
622 &sensor_dev_attr_in0_input.dev_attr.attr,
623 &sensor_dev_attr_in1_input.dev_attr.attr,
624 &sensor_dev_attr_in2_input.dev_attr.attr,
625 &sensor_dev_attr_in3_input.dev_attr.attr,
626 &sensor_dev_attr_in4_input.dev_attr.attr,
627 &sensor_dev_attr_in0_min.dev_attr.attr,
628 &sensor_dev_attr_in1_min.dev_attr.attr,
629 &sensor_dev_attr_in2_min.dev_attr.attr,
630 &sensor_dev_attr_in3_min.dev_attr.attr,
631 &sensor_dev_attr_in4_min.dev_attr.attr,
632 &sensor_dev_attr_in0_max.dev_attr.attr,
633 &sensor_dev_attr_in1_max.dev_attr.attr,
634 &sensor_dev_attr_in2_max.dev_attr.attr,
635 &sensor_dev_attr_in3_max.dev_attr.attr,
636 &sensor_dev_attr_in4_max.dev_attr.attr,
637 &sensor_dev_attr_in0_alarm.dev_attr.attr,
638 &sensor_dev_attr_in1_alarm.dev_attr.attr,
639 &sensor_dev_attr_in2_alarm.dev_attr.attr,
640 &sensor_dev_attr_in3_alarm.dev_attr.attr,
641 &sensor_dev_attr_in4_alarm.dev_attr.attr,
643 &sensor_dev_attr_temp1_input.dev_attr.attr,
644 &sensor_dev_attr_temp2_input.dev_attr.attr,
645 &sensor_dev_attr_temp3_input.dev_attr.attr,
646 &sensor_dev_attr_temp1_max.dev_attr.attr,
647 &sensor_dev_attr_temp2_max.dev_attr.attr,
648 &sensor_dev_attr_temp3_max.dev_attr.attr,
649 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
650 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
651 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
652 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
653 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
654 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
656 &sensor_dev_attr_fan1_input.dev_attr.attr,
657 &sensor_dev_attr_fan2_input.dev_attr.attr,
658 &sensor_dev_attr_fan1_min.dev_attr.attr,
659 &sensor_dev_attr_fan2_min.dev_attr.attr,
660 &sensor_dev_attr_fan1_div.dev_attr.attr,
661 &sensor_dev_attr_fan2_div.dev_attr.attr,
662 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
663 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
665 &dev_attr_alarms.attr,
671 .attrs = via686a_attributes,
679 .probe = via686a_probe,
694 via686a_driver.
driver.name)) {
695 dev_err(&pdev->
dev,
"Region 0x%lx-0x%lx already in use!\n",
696 (
unsigned long)res->
start, (
unsigned long)res->
end);
705 platform_set_drvdata(pdev, data);
707 data->
name =
"via686a";
711 via686a_init_device(data);
721 goto exit_remove_files;
741 static void via686a_update_fan_div(
struct via686a_data *data)
744 data->
fan_div[0] = (reg >> 4) & 0x03;
763 via686a_update_fan_div(data);
775 for (i = 0; i <= 4; i++) {
778 data->
in_min[
i] = via686a_read_value(data,
784 for (i = 1; i <= 2; i++) {
787 data->
fan_min[i - 1] = via686a_read_value(data,
790 for (i = 0; i <= 2; i++) {
791 data->
temp[
i] = via686a_read_value(data,
792 VIA686A_REG_TEMP[i]) << 2;
794 via686a_read_value(data,
795 VIA686A_REG_TEMP_OVER[i]);
797 via686a_read_value(data,
798 VIA686A_REG_TEMP_HYST[i]);
806 data->
temp[0] |= (via686a_read_value(data,
816 via686a_update_fan_div(data);
818 via686a_read_value(data,
853 pr_err(
"Device allocation failed\n");
859 pr_err(
"Device resource addition failed (%d)\n", err);
860 goto exit_device_put;
865 pr_err(
"Device addition failed (%d)\n", err);
866 goto exit_device_put;
884 dev_warn(&dev->
dev,
"Forcing ISA address 0x%x\n", address);
895 dev_err(&dev->
dev,
"base address not set - upgrade BIOS "
896 "or use force_addr=0xaddr\n");
903 if (!(val & 0x0001)) {
906 "with force_addr=0x%x\n", address);
921 if (via686a_device_add(address))
922 goto exit_unregister;
938 static struct pci_driver via686a_pci_driver = {
940 .id_table = via686a_pci_ids,
941 .probe = via686a_pci_probe,
944 static int __init sm_via686a_init(
void)
946 return pci_register_driver(&via686a_pci_driver);
949 static void __exit sm_via686a_exit(
void)
952 if (s_bridge !=
NULL) {