53 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
55 #include <linux/module.h>
56 #include <linux/slab.h>
58 #include <linux/pci.h>
75 static u16 force_addr;
78 "Initialize the base address of the sensors");
85 #define SIS5595_EXTENT 8
87 #define SIS5595_BASE_REG 0x68
88 #define SIS5595_PIN_REG 0x7A
89 #define SIS5595_ENABLE_REG 0x7B
92 #define SIS5595_ADDR_REG_OFFSET 5
93 #define SIS5595_DATA_REG_OFFSET 6
96 #define SIS5595_REG_IN_MAX(nr) (0x2b + (nr) * 2)
97 #define SIS5595_REG_IN_MIN(nr) (0x2c + (nr) * 2)
98 #define SIS5595_REG_IN(nr) (0x20 + (nr))
100 #define SIS5595_REG_FAN_MIN(nr) (0x3b + (nr))
101 #define SIS5595_REG_FAN(nr) (0x28 + (nr))
112 #define SIS5595_REG_TEMP (((data->revision) >= REV2MIN) ? \
113 SIS5595_REG_IN(4) : 0x27)
114 #define SIS5595_REG_TEMP_OVER (((data->revision) >= REV2MIN) ? \
115 SIS5595_REG_IN_MAX(4) : 0x39)
116 #define SIS5595_REG_TEMP_HYST (((data->revision) >= REV2MIN) ? \
117 SIS5595_REG_IN_MIN(4) : 0x3a)
119 #define SIS5595_REG_CONFIG 0x40
120 #define SIS5595_REG_ALARM1 0x41
121 #define SIS5595_REG_ALARM2 0x42
122 #define SIS5595_REG_FANDIV 0x47
135 unsigned long nval = SENSORS_LIMIT(val, 0, 4080);
136 return (nval + 8) / 16;
138 #define IN_FROM_REG(val) ((val) * 16)
144 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
149 return val == 0 ? -1 : val == 255 ? 0 : 1350000 / (val *
div);
158 return val * 830 + 52120;
162 int nval = SENSORS_LIMIT(val, -54120, 157530) ;
163 return nval < 0 ? (nval - 5212 - 415) / 830 : (nval - 5212 + 415) / 830;
172 return val == 8 ? 3 : val == 4 ? 2 : val == 1 ? 0 : 1;
174 #define DIV_FROM_REG(val) (1 << (val))
204 static struct pci_dev *s_bridge;
219 .probe = sis5595_probe,
238 int nr = attr->
index;
247 int nr = attr->
index;
252 const char *buf,
size_t count)
256 int nr = attr->
index;
260 err = kstrtoul(buf, 10, &val);
272 const char *buf,
size_t count)
276 int nr = attr->
index;
280 err = kstrtoul(buf, 10, &val);
291 #define show_in_offset(offset) \
292 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
293 show_in, NULL, offset); \
294 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
295 show_in_min, set_in_min, offset); \
296 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
297 show_in_max, set_in_max, offset);
321 const char *buf,
size_t count)
327 err = kstrtol(buf, 10, &val);
346 const char *buf,
size_t count)
352 err = kstrtol(buf, 10, &val);
365 show_temp_over, set_temp_over);
367 show_temp_hyst, set_temp_hyst);
375 int nr = attr->
index;
385 int nr = attr->
index;
391 const char *buf,
size_t count)
395 int nr = attr->
index;
399 err = kstrtoul(buf, 10, &val);
415 int nr = attr->
index;
426 const char *buf,
size_t count)
430 int nr = attr->
index;
436 err = kstrtoul(buf, 10, &val);
459 dev_err(dev,
"fan_div value %ld not "
460 "supported. Choose one of 1, 2, 4 or 8!\n", val);
467 reg = (reg & 0xcf) | (data->
fan_div[nr] << 4);
470 reg = (reg & 0x3f) | (data->
fan_div[nr] << 6);
481 #define show_fan_offset(offset) \
482 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
483 show_fan, NULL, offset - 1); \
484 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
485 show_fan_min, set_fan_min, offset - 1); \
486 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
487 show_fan_div, set_fan_div, offset - 1);
525 static struct attribute *sis5595_attributes[] = {
526 &sensor_dev_attr_in0_input.dev_attr.attr,
527 &sensor_dev_attr_in0_min.dev_attr.attr,
528 &sensor_dev_attr_in0_max.dev_attr.attr,
529 &sensor_dev_attr_in0_alarm.dev_attr.attr,
530 &sensor_dev_attr_in1_input.dev_attr.attr,
531 &sensor_dev_attr_in1_min.dev_attr.attr,
532 &sensor_dev_attr_in1_max.dev_attr.attr,
533 &sensor_dev_attr_in1_alarm.dev_attr.attr,
534 &sensor_dev_attr_in2_input.dev_attr.attr,
535 &sensor_dev_attr_in2_min.dev_attr.attr,
536 &sensor_dev_attr_in2_max.dev_attr.attr,
537 &sensor_dev_attr_in2_alarm.dev_attr.attr,
538 &sensor_dev_attr_in3_input.dev_attr.attr,
539 &sensor_dev_attr_in3_min.dev_attr.attr,
540 &sensor_dev_attr_in3_max.dev_attr.attr,
541 &sensor_dev_attr_in3_alarm.dev_attr.attr,
543 &sensor_dev_attr_fan1_input.dev_attr.attr,
544 &sensor_dev_attr_fan1_min.dev_attr.attr,
545 &sensor_dev_attr_fan1_div.dev_attr.attr,
546 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
547 &sensor_dev_attr_fan2_input.dev_attr.attr,
548 &sensor_dev_attr_fan2_min.dev_attr.attr,
549 &sensor_dev_attr_fan2_div.dev_attr.attr,
550 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
552 &dev_attr_alarms.attr,
558 .attrs = sis5595_attributes,
561 static struct attribute *sis5595_attributes_in4[] = {
562 &sensor_dev_attr_in4_input.dev_attr.attr,
563 &sensor_dev_attr_in4_min.dev_attr.attr,
564 &sensor_dev_attr_in4_max.dev_attr.attr,
565 &sensor_dev_attr_in4_alarm.dev_attr.attr,
570 .attrs = sis5595_attributes_in4,
573 static struct attribute *sis5595_attributes_temp1[] = {
574 &dev_attr_temp1_input.attr,
575 &dev_attr_temp1_max.attr,
576 &dev_attr_temp1_max_hyst.attr,
577 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
582 .attrs = sis5595_attributes_temp1,
597 sis5595_driver.
driver.name))
608 data->
name =
"sis5595";
609 platform_set_drvdata(pdev, data);
625 sis5595_init_device(data);
628 for (i = 0; i < 2; i++) {
629 data->
fan_min[
i] = sis5595_read_value(data,
640 goto exit_remove_files;
644 goto exit_remove_files;
650 goto exit_remove_files;
699 if (!(config & 0x01))
701 (config & 0xf7) | 0x01);
714 for (i = 0; i <= data->
maxins; i++) {
718 sis5595_read_value(data,
721 sis5595_read_value(data,
724 for (i = 0; i < 2; i++) {
728 sis5595_read_value(data,
740 data->
fan_div[0] = (i >> 4) & 0x03;
794 pr_err(
"Device allocation failed\n");
800 pr_err(
"Device resource addition failed (%d)\n", err);
801 goto exit_device_put;
806 pr_err(
"Device addition failed (%d)\n", err);
807 goto exit_device_put;
825 for (i = blacklist; *i != 0; i++) {
830 "Looked for SIS5595 but found unsupported device %.4x\n",
839 dev_warn(&dev->
dev,
"Forcing ISA address 0x%x\n", force_addr);
845 dev_err(&dev->
dev,
"Failed to read ISA address\n");
852 "Base address not set - upgrade BIOS or use force_addr=0xaddr\n");
855 if (force_addr && address != force_addr) {
857 dev_err(&dev->
dev,
"Failed to force ISA address\n");
863 dev_err(&dev->
dev,
"Failed to read enable register\n");
866 if (!(enable & 0x80)) {
872 || (!(enable & 0x80))) {
874 dev_err(&dev->
dev,
"Failed to enable HWM device\n");
880 dev_dbg(&dev->
dev,
"Failed to register sis5595 driver\n");
886 if (sis5595_device_add(address))
887 goto exit_unregister;
903 static struct pci_driver sis5595_pci_driver = {
905 .id_table = sis5595_pci_ids,
906 .probe = sis5595_pci_probe,
909 static int __init sm_sis5595_init(
void)
911 return pci_register_driver(&sis5595_pci_driver);
914 static void __exit sm_sis5595_exit(
void)
917 if (s_bridge !=
NULL) {