2 * sis5595.c - Part of lm_sensors, Linux kernel modules
3 * for hardware monitoring
5 * Copyright (C) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>,
6 * Kyösti Mälkki <kmalkki@cc.hut.fi>, and
7 * Mark D. Studebaker <mdsxyz123@yahoo.com>
8 * Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
9 * the help of Jean Delvare <jdelvare@suse.de>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * SiS southbridge has a LM78-like chip integrated on the same IC.
28 * This driver is a customized copy of lm78.c
30 * Supports following revisions:
31 * Version PCI ID PCI Revision
32 * 1 1039/0008 AF or less
33 * 2 1039/0008 B0 or greater
35 * Note: these chips contain a 0008 device which is incompatible with the
36 * 5595. We recognize these by the presence of the listed
37 * "blacklist" PCI ID and refuse to load.
39 * NOT SUPPORTED PCI ID BLACKLIST PCI ID
53 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
55 #include <linux/module.h>
56 #include <linux/slab.h>
57 #include <linux/ioport.h>
58 #include <linux/pci.h>
59 #include <linux/platform_device.h>
60 #include <linux/hwmon.h>
61 #include <linux/hwmon-sysfs.h>
62 #include <linux/err.h>
63 #include <linux/init.h>
64 #include <linux/jiffies.h>
65 #include <linux/mutex.h>
66 #include <linux/sysfs.h>
67 #include <linux/acpi.h>
71 * If force_addr is set to anything different from 0, we forcibly enable
72 * the device at the given address.
74 static u16 force_addr;
75 module_param(force_addr, ushort, 0);
76 MODULE_PARM_DESC(force_addr,
77 "Initialize the base address of the sensors");
79 static struct platform_device *pdev;
81 /* Many SIS5595 constants specified below */
83 /* Length of ISA address segment */
84 #define SIS5595_EXTENT 8
85 /* PCI Config Registers */
86 #define SIS5595_BASE_REG 0x68
87 #define SIS5595_PIN_REG 0x7A
88 #define SIS5595_ENABLE_REG 0x7B
90 /* Where are the ISA address/data registers relative to the base address */
91 #define SIS5595_ADDR_REG_OFFSET 5
92 #define SIS5595_DATA_REG_OFFSET 6
94 /* The SIS5595 registers */
95 #define SIS5595_REG_IN_MAX(nr) (0x2b + (nr) * 2)
96 #define SIS5595_REG_IN_MIN(nr) (0x2c + (nr) * 2)
97 #define SIS5595_REG_IN(nr) (0x20 + (nr))
99 #define SIS5595_REG_FAN_MIN(nr) (0x3b + (nr))
100 #define SIS5595_REG_FAN(nr) (0x28 + (nr))
103 * On the first version of the chip, the temp registers are separate.
104 * On the second version,
105 * TEMP pin is shared with IN4, configured in PCI register 0x7A.
106 * The registers are the same as well.
107 * OVER and HYST are really MAX and MIN.
111 #define SIS5595_REG_TEMP (((data->revision) >= REV2MIN) ? \
112 SIS5595_REG_IN(4) : 0x27)
113 #define SIS5595_REG_TEMP_OVER (((data->revision) >= REV2MIN) ? \
114 SIS5595_REG_IN_MAX(4) : 0x39)
115 #define SIS5595_REG_TEMP_HYST (((data->revision) >= REV2MIN) ? \
116 SIS5595_REG_IN_MIN(4) : 0x3a)
118 #define SIS5595_REG_CONFIG 0x40
119 #define SIS5595_REG_ALARM1 0x41
120 #define SIS5595_REG_ALARM2 0x42
121 #define SIS5595_REG_FANDIV 0x47
124 * Conversions. Limit checking is only done on the TO_REG
129 * IN: mV, (0V to 4.08V)
132 static inline u8 IN_TO_REG(unsigned long val)
134 unsigned long nval = clamp_val(val, 0, 4080);
135 return (nval + 8) / 16;
137 #define IN_FROM_REG(val) ((val) * 16)
139 static inline u8 FAN_TO_REG(long rpm, int div)
145 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
148 static inline int FAN_FROM_REG(u8 val, int div)
150 return val == 0 ? -1 : val == 255 ? 0 : 1350000 / (val * div);
154 * TEMP: mC (-54.12C to +157.53C)
155 * REG: 0.83C/bit + 52.12, two's complement
157 static inline int TEMP_FROM_REG(s8 val)
159 return val * 830 + 52120;
161 static inline s8 TEMP_TO_REG(long val)
163 int nval = clamp_val(val, -54120, 157530) ;
164 return nval < 0 ? (nval - 5212 - 415) / 830 : (nval - 5212 + 415) / 830;
168 * FAN DIV: 1, 2, 4, or 8 (defaults to 2)
169 * REG: 0, 1, 2, or 3 (respectively) (defaults to 1)
171 static inline u8 DIV_TO_REG(int val)
173 return val == 8 ? 3 : val == 4 ? 2 : val == 1 ? 0 : 1;
175 #define DIV_FROM_REG(val) (1 << (val))
178 * For each registered chip, we need to keep some data in memory.
179 * The structure is dynamically allocated.
181 struct sis5595_data {
184 struct device *hwmon_dev;
187 struct mutex update_lock;
188 char valid; /* !=0 if following fields are valid */
189 unsigned long last_updated; /* In jiffies */
190 char maxins; /* == 3 if temp enabled, otherwise == 4 */
191 u8 revision; /* Reg. value */
193 u8 in[5]; /* Register value */
194 u8 in_max[5]; /* Register value */
195 u8 in_min[5]; /* Register value */
196 u8 fan[2]; /* Register value */
197 u8 fan_min[2]; /* Register value */
198 s8 temp; /* Register value */
199 s8 temp_over; /* Register value */
200 s8 temp_hyst; /* Register value */
201 u8 fan_div[2]; /* Register encoding, shifted right */
202 u16 alarms; /* Register encoding, combined */
205 static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */
207 static int sis5595_probe(struct platform_device *pdev);
208 static int sis5595_remove(struct platform_device *pdev);
210 static int sis5595_read_value(struct sis5595_data *data, u8 reg);
211 static void sis5595_write_value(struct sis5595_data *data, u8 reg, u8 value);
212 static struct sis5595_data *sis5595_update_device(struct device *dev);
213 static void sis5595_init_device(struct sis5595_data *data);
215 static struct platform_driver sis5595_driver = {
219 .probe = sis5595_probe,
220 .remove = sis5595_remove,
224 static ssize_t in_show(struct device *dev, struct device_attribute *da,
227 struct sis5595_data *data = sis5595_update_device(dev);
228 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
229 int nr = attr->index;
230 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
233 static ssize_t in_min_show(struct device *dev, struct device_attribute *da,
236 struct sis5595_data *data = sis5595_update_device(dev);
237 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
238 int nr = attr->index;
239 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
242 static ssize_t in_max_show(struct device *dev, struct device_attribute *da,
245 struct sis5595_data *data = sis5595_update_device(dev);
246 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
247 int nr = attr->index;
248 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
251 static ssize_t in_min_store(struct device *dev, struct device_attribute *da,
252 const char *buf, size_t count)
254 struct sis5595_data *data = dev_get_drvdata(dev);
255 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
256 int nr = attr->index;
260 err = kstrtoul(buf, 10, &val);
264 mutex_lock(&data->update_lock);
265 data->in_min[nr] = IN_TO_REG(val);
266 sis5595_write_value(data, SIS5595_REG_IN_MIN(nr), data->in_min[nr]);
267 mutex_unlock(&data->update_lock);
271 static ssize_t in_max_store(struct device *dev, struct device_attribute *da,
272 const char *buf, size_t count)
274 struct sis5595_data *data = dev_get_drvdata(dev);
275 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
276 int nr = attr->index;
280 err = kstrtoul(buf, 10, &val);
284 mutex_lock(&data->update_lock);
285 data->in_max[nr] = IN_TO_REG(val);
286 sis5595_write_value(data, SIS5595_REG_IN_MAX(nr), data->in_max[nr]);
287 mutex_unlock(&data->update_lock);
291 static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0);
292 static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
293 static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
294 static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1);
295 static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
296 static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
297 static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2);
298 static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
299 static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
300 static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3);
301 static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
302 static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
303 static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4);
304 static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
305 static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
308 static ssize_t temp1_input_show(struct device *dev,
309 struct device_attribute *attr, char *buf)
311 struct sis5595_data *data = sis5595_update_device(dev);
312 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
315 static ssize_t temp1_max_show(struct device *dev, struct device_attribute *attr,
318 struct sis5595_data *data = sis5595_update_device(dev);
319 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
322 static ssize_t temp1_max_store(struct device *dev,
323 struct device_attribute *attr, const char *buf,
326 struct sis5595_data *data = dev_get_drvdata(dev);
330 err = kstrtol(buf, 10, &val);
334 mutex_lock(&data->update_lock);
335 data->temp_over = TEMP_TO_REG(val);
336 sis5595_write_value(data, SIS5595_REG_TEMP_OVER, data->temp_over);
337 mutex_unlock(&data->update_lock);
341 static ssize_t temp1_max_hyst_show(struct device *dev,
342 struct device_attribute *attr, char *buf)
344 struct sis5595_data *data = sis5595_update_device(dev);
345 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst));
348 static ssize_t temp1_max_hyst_store(struct device *dev,
349 struct device_attribute *attr,
350 const char *buf, size_t count)
352 struct sis5595_data *data = dev_get_drvdata(dev);
356 err = kstrtol(buf, 10, &val);
360 mutex_lock(&data->update_lock);
361 data->temp_hyst = TEMP_TO_REG(val);
362 sis5595_write_value(data, SIS5595_REG_TEMP_HYST, data->temp_hyst);
363 mutex_unlock(&data->update_lock);
367 static DEVICE_ATTR_RO(temp1_input);
368 static DEVICE_ATTR_RW(temp1_max);
369 static DEVICE_ATTR_RW(temp1_max_hyst);
372 static ssize_t fan_show(struct device *dev, struct device_attribute *da,
375 struct sis5595_data *data = sis5595_update_device(dev);
376 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
377 int nr = attr->index;
378 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
379 DIV_FROM_REG(data->fan_div[nr])));
382 static ssize_t fan_min_show(struct device *dev, struct device_attribute *da,
385 struct sis5595_data *data = sis5595_update_device(dev);
386 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
387 int nr = attr->index;
388 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
389 DIV_FROM_REG(data->fan_div[nr])));
392 static ssize_t fan_min_store(struct device *dev, struct device_attribute *da,
393 const char *buf, size_t count)
395 struct sis5595_data *data = dev_get_drvdata(dev);
396 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
397 int nr = attr->index;
401 err = kstrtoul(buf, 10, &val);
405 mutex_lock(&data->update_lock);
406 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
407 sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]);
408 mutex_unlock(&data->update_lock);
412 static ssize_t fan_div_show(struct device *dev, struct device_attribute *da,
415 struct sis5595_data *data = sis5595_update_device(dev);
416 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
417 int nr = attr->index;
418 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
422 * Note: we save and restore the fan minimum here, because its value is
423 * determined in part by the fan divisor. This follows the principle of
424 * least surprise; the user doesn't expect the fan minimum to change just
425 * because the divisor changed.
427 static ssize_t fan_div_store(struct device *dev, struct device_attribute *da,
428 const char *buf, size_t count)
430 struct sis5595_data *data = dev_get_drvdata(dev);
431 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
432 int nr = attr->index;
438 err = kstrtoul(buf, 10, &val);
442 mutex_lock(&data->update_lock);
443 min = FAN_FROM_REG(data->fan_min[nr],
444 DIV_FROM_REG(data->fan_div[nr]));
445 reg = sis5595_read_value(data, SIS5595_REG_FANDIV);
449 data->fan_div[nr] = 0;
452 data->fan_div[nr] = 1;
455 data->fan_div[nr] = 2;
458 data->fan_div[nr] = 3;
462 "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n",
464 mutex_unlock(&data->update_lock);
470 reg = (reg & 0xcf) | (data->fan_div[nr] << 4);
473 reg = (reg & 0x3f) | (data->fan_div[nr] << 6);
476 sis5595_write_value(data, SIS5595_REG_FANDIV, reg);
478 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
479 sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]);
480 mutex_unlock(&data->update_lock);
484 static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
485 static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
486 static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
487 static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
488 static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
489 static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
492 static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
495 struct sis5595_data *data = sis5595_update_device(dev);
496 return sprintf(buf, "%d\n", data->alarms);
498 static DEVICE_ATTR_RO(alarms);
500 static ssize_t alarm_show(struct device *dev, struct device_attribute *da,
503 struct sis5595_data *data = sis5595_update_device(dev);
504 int nr = to_sensor_dev_attr(da)->index;
505 return sprintf(buf, "%u\n", (data->alarms >> nr) & 1);
507 static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
508 static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
509 static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
510 static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
511 static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 15);
512 static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 6);
513 static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 7);
514 static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 15);
516 static ssize_t name_show(struct device *dev, struct device_attribute *attr,
519 struct sis5595_data *data = dev_get_drvdata(dev);
520 return sprintf(buf, "%s\n", data->name);
522 static DEVICE_ATTR_RO(name);
524 static struct attribute *sis5595_attributes[] = {
525 &sensor_dev_attr_in0_input.dev_attr.attr,
526 &sensor_dev_attr_in0_min.dev_attr.attr,
527 &sensor_dev_attr_in0_max.dev_attr.attr,
528 &sensor_dev_attr_in0_alarm.dev_attr.attr,
529 &sensor_dev_attr_in1_input.dev_attr.attr,
530 &sensor_dev_attr_in1_min.dev_attr.attr,
531 &sensor_dev_attr_in1_max.dev_attr.attr,
532 &sensor_dev_attr_in1_alarm.dev_attr.attr,
533 &sensor_dev_attr_in2_input.dev_attr.attr,
534 &sensor_dev_attr_in2_min.dev_attr.attr,
535 &sensor_dev_attr_in2_max.dev_attr.attr,
536 &sensor_dev_attr_in2_alarm.dev_attr.attr,
537 &sensor_dev_attr_in3_input.dev_attr.attr,
538 &sensor_dev_attr_in3_min.dev_attr.attr,
539 &sensor_dev_attr_in3_max.dev_attr.attr,
540 &sensor_dev_attr_in3_alarm.dev_attr.attr,
542 &sensor_dev_attr_fan1_input.dev_attr.attr,
543 &sensor_dev_attr_fan1_min.dev_attr.attr,
544 &sensor_dev_attr_fan1_div.dev_attr.attr,
545 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
546 &sensor_dev_attr_fan2_input.dev_attr.attr,
547 &sensor_dev_attr_fan2_min.dev_attr.attr,
548 &sensor_dev_attr_fan2_div.dev_attr.attr,
549 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
551 &dev_attr_alarms.attr,
556 static const struct attribute_group sis5595_group = {
557 .attrs = sis5595_attributes,
560 static struct attribute *sis5595_attributes_in4[] = {
561 &sensor_dev_attr_in4_input.dev_attr.attr,
562 &sensor_dev_attr_in4_min.dev_attr.attr,
563 &sensor_dev_attr_in4_max.dev_attr.attr,
564 &sensor_dev_attr_in4_alarm.dev_attr.attr,
568 static const struct attribute_group sis5595_group_in4 = {
569 .attrs = sis5595_attributes_in4,
572 static struct attribute *sis5595_attributes_temp1[] = {
573 &dev_attr_temp1_input.attr,
574 &dev_attr_temp1_max.attr,
575 &dev_attr_temp1_max_hyst.attr,
576 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
580 static const struct attribute_group sis5595_group_temp1 = {
581 .attrs = sis5595_attributes_temp1,
584 /* This is called when the module is loaded */
585 static int sis5595_probe(struct platform_device *pdev)
589 struct sis5595_data *data;
590 struct resource *res;
593 /* Reserve the ISA region */
594 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
595 if (!devm_request_region(&pdev->dev, res->start, SIS5595_EXTENT,
596 sis5595_driver.driver.name))
599 data = devm_kzalloc(&pdev->dev, sizeof(struct sis5595_data),
604 mutex_init(&data->lock);
605 mutex_init(&data->update_lock);
606 data->addr = res->start;
607 data->name = "sis5595";
608 platform_set_drvdata(pdev, data);
611 * Check revision and pin registers to determine whether 4 or 5 voltages
613 data->revision = s_bridge->revision;
614 /* 4 voltages, 1 temp */
616 if (data->revision >= REV2MIN) {
617 pci_read_config_byte(s_bridge, SIS5595_PIN_REG, &val);
619 /* 5 voltages, no temps */
623 /* Initialize the SIS5595 chip */
624 sis5595_init_device(data);
626 /* A few vars need to be filled upon startup */
627 for (i = 0; i < 2; i++) {
628 data->fan_min[i] = sis5595_read_value(data,
629 SIS5595_REG_FAN_MIN(i));
632 /* Register sysfs hooks */
633 err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group);
636 if (data->maxins == 4) {
637 err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group_in4);
639 goto exit_remove_files;
641 err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group_temp1);
643 goto exit_remove_files;
646 data->hwmon_dev = hwmon_device_register(&pdev->dev);
647 if (IS_ERR(data->hwmon_dev)) {
648 err = PTR_ERR(data->hwmon_dev);
649 goto exit_remove_files;
655 sysfs_remove_group(&pdev->dev.kobj, &sis5595_group);
656 sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_in4);
657 sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_temp1);
661 static int sis5595_remove(struct platform_device *pdev)
663 struct sis5595_data *data = platform_get_drvdata(pdev);
665 hwmon_device_unregister(data->hwmon_dev);
666 sysfs_remove_group(&pdev->dev.kobj, &sis5595_group);
667 sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_in4);
668 sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_temp1);
673 /* ISA access must be locked explicitly. */
674 static int sis5595_read_value(struct sis5595_data *data, u8 reg)
678 mutex_lock(&data->lock);
679 outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET);
680 res = inb_p(data->addr + SIS5595_DATA_REG_OFFSET);
681 mutex_unlock(&data->lock);
685 static void sis5595_write_value(struct sis5595_data *data, u8 reg, u8 value)
687 mutex_lock(&data->lock);
688 outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET);
689 outb_p(value, data->addr + SIS5595_DATA_REG_OFFSET);
690 mutex_unlock(&data->lock);
693 /* Called when we have found a new SIS5595. */
694 static void sis5595_init_device(struct sis5595_data *data)
696 u8 config = sis5595_read_value(data, SIS5595_REG_CONFIG);
697 if (!(config & 0x01))
698 sis5595_write_value(data, SIS5595_REG_CONFIG,
699 (config & 0xf7) | 0x01);
702 static struct sis5595_data *sis5595_update_device(struct device *dev)
704 struct sis5595_data *data = dev_get_drvdata(dev);
707 mutex_lock(&data->update_lock);
709 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
712 for (i = 0; i <= data->maxins; i++) {
714 sis5595_read_value(data, SIS5595_REG_IN(i));
716 sis5595_read_value(data,
717 SIS5595_REG_IN_MIN(i));
719 sis5595_read_value(data,
720 SIS5595_REG_IN_MAX(i));
722 for (i = 0; i < 2; i++) {
724 sis5595_read_value(data, SIS5595_REG_FAN(i));
726 sis5595_read_value(data,
727 SIS5595_REG_FAN_MIN(i));
729 if (data->maxins == 3) {
731 sis5595_read_value(data, SIS5595_REG_TEMP);
733 sis5595_read_value(data, SIS5595_REG_TEMP_OVER);
735 sis5595_read_value(data, SIS5595_REG_TEMP_HYST);
737 i = sis5595_read_value(data, SIS5595_REG_FANDIV);
738 data->fan_div[0] = (i >> 4) & 0x03;
739 data->fan_div[1] = i >> 6;
741 sis5595_read_value(data, SIS5595_REG_ALARM1) |
742 (sis5595_read_value(data, SIS5595_REG_ALARM2) << 8);
743 data->last_updated = jiffies;
747 mutex_unlock(&data->update_lock);
752 static const struct pci_device_id sis5595_pci_ids[] = {
753 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
757 MODULE_DEVICE_TABLE(pci, sis5595_pci_ids);
759 static int blacklist[] = {
760 PCI_DEVICE_ID_SI_540,
761 PCI_DEVICE_ID_SI_550,
762 PCI_DEVICE_ID_SI_630,
763 PCI_DEVICE_ID_SI_645,
764 PCI_DEVICE_ID_SI_730,
765 PCI_DEVICE_ID_SI_735,
766 PCI_DEVICE_ID_SI_5511, /*
767 * 5513 chip has the 0008 device but
768 * that ID shows up in other chips so we
769 * use the 5511 ID for recognition
771 PCI_DEVICE_ID_SI_5597,
772 PCI_DEVICE_ID_SI_5598,
775 static int sis5595_device_add(unsigned short address)
777 struct resource res = {
779 .end = address + SIS5595_EXTENT - 1,
781 .flags = IORESOURCE_IO,
785 err = acpi_check_resource_conflict(&res);
789 pdev = platform_device_alloc("sis5595", address);
792 pr_err("Device allocation failed\n");
796 err = platform_device_add_resources(pdev, &res, 1);
798 pr_err("Device resource addition failed (%d)\n", err);
799 goto exit_device_put;
802 err = platform_device_add(pdev);
804 pr_err("Device addition failed (%d)\n", err);
805 goto exit_device_put;
811 platform_device_put(pdev);
816 static int sis5595_pci_probe(struct pci_dev *dev,
817 const struct pci_device_id *id)
823 for (i = blacklist; *i != 0; i++) {
825 d = pci_get_device(PCI_VENDOR_ID_SI, *i, NULL);
828 "Looked for SIS5595 but found unsupported device %.4x\n",
835 force_addr &= ~(SIS5595_EXTENT - 1);
837 dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", force_addr);
838 pci_write_config_word(dev, SIS5595_BASE_REG, force_addr);
841 if (PCIBIOS_SUCCESSFUL !=
842 pci_read_config_word(dev, SIS5595_BASE_REG, &address)) {
843 dev_err(&dev->dev, "Failed to read ISA address\n");
847 address &= ~(SIS5595_EXTENT - 1);
850 "Base address not set - upgrade BIOS or use force_addr=0xaddr\n");
853 if (force_addr && address != force_addr) {
854 /* doesn't work for some chips? */
855 dev_err(&dev->dev, "Failed to force ISA address\n");
859 if (PCIBIOS_SUCCESSFUL !=
860 pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable)) {
861 dev_err(&dev->dev, "Failed to read enable register\n");
864 if (!(enable & 0x80)) {
865 if ((PCIBIOS_SUCCESSFUL !=
866 pci_write_config_byte(dev, SIS5595_ENABLE_REG,
868 || (PCIBIOS_SUCCESSFUL !=
869 pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable))
870 || (!(enable & 0x80))) {
871 /* doesn't work for some chips! */
872 dev_err(&dev->dev, "Failed to enable HWM device\n");
877 if (platform_driver_register(&sis5595_driver)) {
878 dev_dbg(&dev->dev, "Failed to register sis5595 driver\n");
882 s_bridge = pci_dev_get(dev);
883 /* Sets global pdev as a side effect */
884 if (sis5595_device_add(address))
885 goto exit_unregister;
888 * Always return failure here. This is to allow other drivers to bind
889 * to this pci device. We don't really want to have control over the
890 * pci device, we only wanted to read as few register values from it.
896 platform_driver_unregister(&sis5595_driver);
901 static struct pci_driver sis5595_pci_driver = {
903 .id_table = sis5595_pci_ids,
904 .probe = sis5595_pci_probe,
907 static int __init sm_sis5595_init(void)
909 return pci_register_driver(&sis5595_pci_driver);
912 static void __exit sm_sis5595_exit(void)
914 pci_unregister_driver(&sis5595_pci_driver);
915 if (s_bridge != NULL) {
916 platform_device_unregister(pdev);
917 platform_driver_unregister(&sis5595_driver);
918 pci_dev_put(s_bridge);
923 MODULE_AUTHOR("Aurelien Jarno <aurelien@aurel32.net>");
924 MODULE_DESCRIPTION("SiS 5595 Sensor device");
925 MODULE_LICENSE("GPL");
927 module_init(sm_sis5595_init);
928 module_exit(sm_sis5595_exit);