Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 3 | * sis5595.c - Part of lm_sensors, Linux kernel modules |
| 4 | * for hardware monitoring |
| 5 | * |
| 6 | * Copyright (C) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>, |
| 7 | * Kyösti Mälkki <kmalkki@cc.hut.fi>, and |
| 8 | * Mark D. Studebaker <mdsxyz123@yahoo.com> |
| 9 | * Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with |
Jean Delvare | 7c81c60f | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 10 | * the help of Jean Delvare <jdelvare@suse.de> |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 11 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | /* |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 14 | * SiS southbridge has a LM78-like chip integrated on the same IC. |
| 15 | * This driver is a customized copy of lm78.c |
| 16 | * |
| 17 | * Supports following revisions: |
| 18 | * Version PCI ID PCI Revision |
| 19 | * 1 1039/0008 AF or less |
| 20 | * 2 1039/0008 B0 or greater |
| 21 | * |
| 22 | * Note: these chips contain a 0008 device which is incompatible with the |
| 23 | * 5595. We recognize these by the presence of the listed |
| 24 | * "blacklist" PCI ID and refuse to load. |
| 25 | * |
| 26 | * NOT SUPPORTED PCI ID BLACKLIST PCI ID |
| 27 | * 540 0008 0540 |
| 28 | * 550 0008 0550 |
| 29 | * 5513 0008 5511 |
| 30 | * 5581 0008 5597 |
| 31 | * 5582 0008 5597 |
| 32 | * 5597 0008 5597 |
| 33 | * 5598 0008 5597/5598 |
| 34 | * 630 0008 0630 |
| 35 | * 645 0008 0645 |
| 36 | * 730 0008 0730 |
| 37 | * 735 0008 0735 |
| 38 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Uwe Kleine-König | 847a3b0 | 2022-09-22 09:48:59 +0200 | [diff] [blame] | 40 | #define DRIVER_NAME "sis5595" |
Joe Perches | 4b2515d | 2010-10-20 06:51:47 +0000 | [diff] [blame] | 41 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/module.h> |
| 44 | #include <linux/slab.h> |
| 45 | #include <linux/ioport.h> |
| 46 | #include <linux/pci.h> |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 47 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 48 | #include <linux/hwmon.h> |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 49 | #include <linux/hwmon-sysfs.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 50 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/init.h> |
Dominik Hackl | ff32409 | 2005-05-16 18:12:18 +0200 | [diff] [blame] | 52 | #include <linux/jiffies.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 53 | #include <linux/mutex.h> |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 54 | #include <linux/sysfs.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 55 | #include <linux/acpi.h> |
H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 56 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 58 | /* |
| 59 | * If force_addr is set to anything different from 0, we forcibly enable |
| 60 | * the device at the given address. |
| 61 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static u16 force_addr; |
| 63 | module_param(force_addr, ushort, 0); |
| 64 | MODULE_PARM_DESC(force_addr, |
| 65 | "Initialize the base address of the sensors"); |
| 66 | |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 67 | static struct platform_device *pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | /* Many SIS5595 constants specified below */ |
| 70 | |
| 71 | /* Length of ISA address segment */ |
| 72 | #define SIS5595_EXTENT 8 |
| 73 | /* PCI Config Registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define SIS5595_BASE_REG 0x68 |
| 75 | #define SIS5595_PIN_REG 0x7A |
| 76 | #define SIS5595_ENABLE_REG 0x7B |
| 77 | |
| 78 | /* Where are the ISA address/data registers relative to the base address */ |
| 79 | #define SIS5595_ADDR_REG_OFFSET 5 |
| 80 | #define SIS5595_DATA_REG_OFFSET 6 |
| 81 | |
| 82 | /* The SIS5595 registers */ |
| 83 | #define SIS5595_REG_IN_MAX(nr) (0x2b + (nr) * 2) |
| 84 | #define SIS5595_REG_IN_MIN(nr) (0x2c + (nr) * 2) |
| 85 | #define SIS5595_REG_IN(nr) (0x20 + (nr)) |
| 86 | |
| 87 | #define SIS5595_REG_FAN_MIN(nr) (0x3b + (nr)) |
| 88 | #define SIS5595_REG_FAN(nr) (0x28 + (nr)) |
| 89 | |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 90 | /* |
| 91 | * On the first version of the chip, the temp registers are separate. |
| 92 | * On the second version, |
| 93 | * TEMP pin is shared with IN4, configured in PCI register 0x7A. |
| 94 | * The registers are the same as well. |
| 95 | * OVER and HYST are really MAX and MIN. |
| 96 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | #define REV2MIN 0xb0 |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 99 | #define SIS5595_REG_TEMP (((data->revision) >= REV2MIN) ? \ |
| 100 | SIS5595_REG_IN(4) : 0x27) |
| 101 | #define SIS5595_REG_TEMP_OVER (((data->revision) >= REV2MIN) ? \ |
| 102 | SIS5595_REG_IN_MAX(4) : 0x39) |
| 103 | #define SIS5595_REG_TEMP_HYST (((data->revision) >= REV2MIN) ? \ |
| 104 | SIS5595_REG_IN_MIN(4) : 0x3a) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | #define SIS5595_REG_CONFIG 0x40 |
| 107 | #define SIS5595_REG_ALARM1 0x41 |
| 108 | #define SIS5595_REG_ALARM2 0x42 |
| 109 | #define SIS5595_REG_FANDIV 0x47 |
| 110 | |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 111 | /* |
| 112 | * Conversions. Limit checking is only done on the TO_REG |
| 113 | * variants. |
| 114 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 116 | /* |
| 117 | * IN: mV, (0V to 4.08V) |
| 118 | * REG: 16mV/bit |
| 119 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | static inline u8 IN_TO_REG(unsigned long val) |
| 121 | { |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 122 | unsigned long nval = clamp_val(val, 0, 4080); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | return (nval + 8) / 16; |
| 124 | } |
| 125 | #define IN_FROM_REG(val) ((val) * 16) |
| 126 | |
| 127 | static inline u8 FAN_TO_REG(long rpm, int div) |
| 128 | { |
| 129 | if (rpm <= 0) |
| 130 | return 255; |
Dan Carpenter | 3806b45 | 2013-12-12 08:05:33 +0100 | [diff] [blame] | 131 | if (rpm > 1350000) |
| 132 | return 1; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 133 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static inline int FAN_FROM_REG(u8 val, int div) |
| 137 | { |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 138 | return val == 0 ? -1 : val == 255 ? 0 : 1350000 / (val * div); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 141 | /* |
| 142 | * TEMP: mC (-54.12C to +157.53C) |
| 143 | * REG: 0.83C/bit + 52.12, two's complement |
| 144 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | static inline int TEMP_FROM_REG(s8 val) |
| 146 | { |
| 147 | return val * 830 + 52120; |
| 148 | } |
Axel Lin | cc33654 | 2014-07-31 22:27:04 +0800 | [diff] [blame] | 149 | static inline s8 TEMP_TO_REG(long val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 151 | int nval = clamp_val(val, -54120, 157530) ; |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 152 | return nval < 0 ? (nval - 5212 - 415) / 830 : (nval - 5212 + 415) / 830; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 155 | /* |
Krzysztof Kozlowski | 5b1d7a0 | 2024-02-25 21:28:41 +0100 | [diff] [blame] | 156 | * FAN DIV: 1, 2, 4, or 8 |
| 157 | * REG: 0, 1, 2, or 3 (respectively) |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 158 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | #define DIV_FROM_REG(val) (1 << (val)) |
| 160 | |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 161 | /* |
| 162 | * For each registered chip, we need to keep some data in memory. |
| 163 | * The structure is dynamically allocated. |
| 164 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | struct sis5595_data { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 166 | unsigned short addr; |
| 167 | const char *name; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 168 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 169 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 171 | struct mutex update_lock; |
Paul Fertser | 952a11c | 2021-09-24 22:52:02 +0300 | [diff] [blame] | 172 | bool valid; /* true if following fields are valid */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | unsigned long last_updated; /* In jiffies */ |
| 174 | char maxins; /* == 3 if temp enabled, otherwise == 4 */ |
| 175 | u8 revision; /* Reg. value */ |
| 176 | |
| 177 | u8 in[5]; /* Register value */ |
| 178 | u8 in_max[5]; /* Register value */ |
| 179 | u8 in_min[5]; /* Register value */ |
| 180 | u8 fan[2]; /* Register value */ |
| 181 | u8 fan_min[2]; /* Register value */ |
| 182 | s8 temp; /* Register value */ |
| 183 | s8 temp_over; /* Register value */ |
| 184 | s8 temp_hyst; /* Register value */ |
| 185 | u8 fan_div[2]; /* Register encoding, shifted right */ |
| 186 | u16 alarms; /* Register encoding, combined */ |
| 187 | }; |
| 188 | |
| 189 | static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */ |
| 190 | |
Uwe Kleine-König | 1b2f9b1 | 2022-09-22 09:49:00 +0200 | [diff] [blame] | 191 | /* ISA access must be locked explicitly. */ |
| 192 | static int sis5595_read_value(struct sis5595_data *data, u8 reg) |
| 193 | { |
| 194 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Uwe Kleine-König | 1b2f9b1 | 2022-09-22 09:49:00 +0200 | [diff] [blame] | 196 | mutex_lock(&data->lock); |
| 197 | outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET); |
| 198 | res = inb_p(data->addr + SIS5595_DATA_REG_OFFSET); |
| 199 | mutex_unlock(&data->lock); |
| 200 | return res; |
| 201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Uwe Kleine-König | 1b2f9b1 | 2022-09-22 09:49:00 +0200 | [diff] [blame] | 203 | static void sis5595_write_value(struct sis5595_data *data, u8 reg, u8 value) |
| 204 | { |
| 205 | mutex_lock(&data->lock); |
| 206 | outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET); |
| 207 | outb_p(value, data->addr + SIS5595_DATA_REG_OFFSET); |
| 208 | mutex_unlock(&data->lock); |
| 209 | } |
| 210 | |
| 211 | static struct sis5595_data *sis5595_update_device(struct device *dev) |
| 212 | { |
| 213 | struct sis5595_data *data = dev_get_drvdata(dev); |
| 214 | int i; |
| 215 | |
| 216 | mutex_lock(&data->update_lock); |
| 217 | |
| 218 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
| 219 | || !data->valid) { |
| 220 | |
| 221 | for (i = 0; i <= data->maxins; i++) { |
| 222 | data->in[i] = |
| 223 | sis5595_read_value(data, SIS5595_REG_IN(i)); |
| 224 | data->in_min[i] = |
| 225 | sis5595_read_value(data, |
| 226 | SIS5595_REG_IN_MIN(i)); |
| 227 | data->in_max[i] = |
| 228 | sis5595_read_value(data, |
| 229 | SIS5595_REG_IN_MAX(i)); |
| 230 | } |
| 231 | for (i = 0; i < 2; i++) { |
| 232 | data->fan[i] = |
| 233 | sis5595_read_value(data, SIS5595_REG_FAN(i)); |
| 234 | data->fan_min[i] = |
| 235 | sis5595_read_value(data, |
| 236 | SIS5595_REG_FAN_MIN(i)); |
| 237 | } |
| 238 | if (data->maxins == 3) { |
| 239 | data->temp = |
| 240 | sis5595_read_value(data, SIS5595_REG_TEMP); |
| 241 | data->temp_over = |
| 242 | sis5595_read_value(data, SIS5595_REG_TEMP_OVER); |
| 243 | data->temp_hyst = |
| 244 | sis5595_read_value(data, SIS5595_REG_TEMP_HYST); |
| 245 | } |
| 246 | i = sis5595_read_value(data, SIS5595_REG_FANDIV); |
| 247 | data->fan_div[0] = (i >> 4) & 0x03; |
| 248 | data->fan_div[1] = i >> 6; |
| 249 | data->alarms = |
| 250 | sis5595_read_value(data, SIS5595_REG_ALARM1) | |
| 251 | (sis5595_read_value(data, SIS5595_REG_ALARM2) << 8); |
| 252 | data->last_updated = jiffies; |
| 253 | data->valid = true; |
| 254 | } |
| 255 | |
| 256 | mutex_unlock(&data->update_lock); |
| 257 | |
| 258 | return data; |
| 259 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | /* 4 Voltages */ |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 262 | static ssize_t in_show(struct device *dev, struct device_attribute *da, |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 263 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
| 265 | struct sis5595_data *data = sis5595_update_device(dev); |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 266 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
| 267 | int nr = attr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); |
| 269 | } |
| 270 | |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 271 | static ssize_t in_min_show(struct device *dev, struct device_attribute *da, |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 272 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { |
| 274 | struct sis5595_data *data = sis5595_update_device(dev); |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 275 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
| 276 | int nr = attr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); |
| 278 | } |
| 279 | |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 280 | static ssize_t in_max_show(struct device *dev, struct device_attribute *da, |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 281 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
| 283 | struct sis5595_data *data = sis5595_update_device(dev); |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 284 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
| 285 | int nr = attr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); |
| 287 | } |
| 288 | |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 289 | static ssize_t in_min_store(struct device *dev, struct device_attribute *da, |
| 290 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 292 | struct sis5595_data *data = dev_get_drvdata(dev); |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 293 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
| 294 | int nr = attr->index; |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 295 | unsigned long val; |
| 296 | int err; |
| 297 | |
| 298 | err = kstrtoul(buf, 10, &val); |
| 299 | if (err) |
| 300 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 302 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | data->in_min[nr] = IN_TO_REG(val); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 304 | sis5595_write_value(data, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 305 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | return count; |
| 307 | } |
| 308 | |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 309 | static ssize_t in_max_store(struct device *dev, struct device_attribute *da, |
| 310 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 312 | struct sis5595_data *data = dev_get_drvdata(dev); |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 313 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
| 314 | int nr = attr->index; |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 315 | unsigned long val; |
| 316 | int err; |
| 317 | |
| 318 | err = kstrtoul(buf, 10, &val); |
| 319 | if (err) |
| 320 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 322 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | data->in_max[nr] = IN_TO_REG(val); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 324 | sis5595_write_value(data, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 325 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | return count; |
| 327 | } |
| 328 | |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 329 | static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0); |
| 330 | static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0); |
| 331 | static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0); |
| 332 | static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1); |
| 333 | static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1); |
| 334 | static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1); |
| 335 | static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2); |
| 336 | static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2); |
| 337 | static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2); |
| 338 | static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3); |
| 339 | static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3); |
| 340 | static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3); |
| 341 | static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4); |
| 342 | static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4); |
| 343 | static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
| 345 | /* Temperature */ |
Julia Lawall | feaf8bd | 2016-12-22 13:05:05 +0100 | [diff] [blame] | 346 | static ssize_t temp1_input_show(struct device *dev, |
| 347 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
| 349 | struct sis5595_data *data = sis5595_update_device(dev); |
| 350 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); |
| 351 | } |
| 352 | |
Julia Lawall | feaf8bd | 2016-12-22 13:05:05 +0100 | [diff] [blame] | 353 | static ssize_t temp1_max_show(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 354 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
| 356 | struct sis5595_data *data = sis5595_update_device(dev); |
| 357 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over)); |
| 358 | } |
| 359 | |
Julia Lawall | feaf8bd | 2016-12-22 13:05:05 +0100 | [diff] [blame] | 360 | static ssize_t temp1_max_store(struct device *dev, |
| 361 | struct device_attribute *attr, const char *buf, |
| 362 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 364 | struct sis5595_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 365 | long val; |
| 366 | int err; |
| 367 | |
| 368 | err = kstrtol(buf, 10, &val); |
| 369 | if (err) |
| 370 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 372 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | data->temp_over = TEMP_TO_REG(val); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 374 | sis5595_write_value(data, SIS5595_REG_TEMP_OVER, data->temp_over); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 375 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | return count; |
| 377 | } |
| 378 | |
Julia Lawall | feaf8bd | 2016-12-22 13:05:05 +0100 | [diff] [blame] | 379 | static ssize_t temp1_max_hyst_show(struct device *dev, |
| 380 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
| 382 | struct sis5595_data *data = sis5595_update_device(dev); |
| 383 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst)); |
| 384 | } |
| 385 | |
Julia Lawall | feaf8bd | 2016-12-22 13:05:05 +0100 | [diff] [blame] | 386 | static ssize_t temp1_max_hyst_store(struct device *dev, |
| 387 | struct device_attribute *attr, |
| 388 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 390 | struct sis5595_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 391 | long val; |
| 392 | int err; |
| 393 | |
| 394 | err = kstrtol(buf, 10, &val); |
| 395 | if (err) |
| 396 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 398 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | data->temp_hyst = TEMP_TO_REG(val); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 400 | sis5595_write_value(data, SIS5595_REG_TEMP_HYST, data->temp_hyst); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 401 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return count; |
| 403 | } |
| 404 | |
Julia Lawall | feaf8bd | 2016-12-22 13:05:05 +0100 | [diff] [blame] | 405 | static DEVICE_ATTR_RO(temp1_input); |
| 406 | static DEVICE_ATTR_RW(temp1_max); |
| 407 | static DEVICE_ATTR_RW(temp1_max_hyst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | /* 2 Fans */ |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 410 | static ssize_t fan_show(struct device *dev, struct device_attribute *da, |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 411 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | { |
| 413 | struct sis5595_data *data = sis5595_update_device(dev); |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 414 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
| 415 | int nr = attr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 417 | DIV_FROM_REG(data->fan_div[nr]))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 420 | static ssize_t fan_min_show(struct device *dev, struct device_attribute *da, |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 421 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
| 423 | struct sis5595_data *data = sis5595_update_device(dev); |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 424 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
| 425 | int nr = attr->index; |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 426 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], |
| 427 | DIV_FROM_REG(data->fan_div[nr]))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 430 | static ssize_t fan_min_store(struct device *dev, struct device_attribute *da, |
| 431 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 433 | struct sis5595_data *data = dev_get_drvdata(dev); |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 434 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
| 435 | int nr = attr->index; |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 436 | unsigned long val; |
| 437 | int err; |
| 438 | |
| 439 | err = kstrtoul(buf, 10, &val); |
| 440 | if (err) |
| 441 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 443 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 445 | sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 446 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | return count; |
| 448 | } |
| 449 | |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 450 | static ssize_t fan_div_show(struct device *dev, struct device_attribute *da, |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 451 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
| 453 | struct sis5595_data *data = sis5595_update_device(dev); |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 454 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
| 455 | int nr = attr->index; |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 456 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 459 | /* |
| 460 | * Note: we save and restore the fan minimum here, because its value is |
| 461 | * determined in part by the fan divisor. This follows the principle of |
| 462 | * least surprise; the user doesn't expect the fan minimum to change just |
| 463 | * because the divisor changed. |
| 464 | */ |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 465 | static ssize_t fan_div_store(struct device *dev, struct device_attribute *da, |
| 466 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 468 | struct sis5595_data *data = dev_get_drvdata(dev); |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 469 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
| 470 | int nr = attr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | unsigned long min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | int reg; |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 473 | unsigned long val; |
| 474 | int err; |
| 475 | |
| 476 | err = kstrtoul(buf, 10, &val); |
| 477 | if (err) |
| 478 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 480 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | min = FAN_FROM_REG(data->fan_min[nr], |
| 482 | DIV_FROM_REG(data->fan_div[nr])); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 483 | reg = sis5595_read_value(data, SIS5595_REG_FANDIV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | switch (val) { |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 486 | case 1: |
| 487 | data->fan_div[nr] = 0; |
| 488 | break; |
| 489 | case 2: |
| 490 | data->fan_div[nr] = 1; |
| 491 | break; |
| 492 | case 4: |
| 493 | data->fan_div[nr] = 2; |
| 494 | break; |
| 495 | case 8: |
| 496 | data->fan_div[nr] = 3; |
| 497 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | default: |
Guenter Roeck | b55f375 | 2013-01-10 10:01:24 -0800 | [diff] [blame] | 499 | dev_err(dev, |
| 500 | "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", |
| 501 | val); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 502 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | return -EINVAL; |
| 504 | } |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | switch (nr) { |
| 507 | case 0: |
| 508 | reg = (reg & 0xcf) | (data->fan_div[nr] << 4); |
| 509 | break; |
| 510 | case 1: |
| 511 | reg = (reg & 0x3f) | (data->fan_div[nr] << 6); |
| 512 | break; |
| 513 | } |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 514 | sis5595_write_value(data, SIS5595_REG_FANDIV, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | data->fan_min[nr] = |
| 516 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 517 | sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 518 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | return count; |
| 520 | } |
| 521 | |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 522 | static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0); |
| 523 | static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0); |
| 524 | static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0); |
| 525 | static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1); |
| 526 | static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1); |
| 527 | static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | /* Alarms */ |
Julia Lawall | feaf8bd | 2016-12-22 13:05:05 +0100 | [diff] [blame] | 530 | static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 531 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
| 533 | struct sis5595_data *data = sis5595_update_device(dev); |
| 534 | return sprintf(buf, "%d\n", data->alarms); |
| 535 | } |
Julia Lawall | feaf8bd | 2016-12-22 13:05:05 +0100 | [diff] [blame] | 536 | static DEVICE_ATTR_RO(alarms); |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 537 | |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 538 | static ssize_t alarm_show(struct device *dev, struct device_attribute *da, |
Ivo Manca | 5c726b3 | 2007-10-15 20:50:53 +0200 | [diff] [blame] | 539 | char *buf) |
| 540 | { |
| 541 | struct sis5595_data *data = sis5595_update_device(dev); |
| 542 | int nr = to_sensor_dev_attr(da)->index; |
| 543 | return sprintf(buf, "%u\n", (data->alarms >> nr) & 1); |
| 544 | } |
Guenter Roeck | 60a9c3f | 2019-01-22 14:28:50 -0800 | [diff] [blame] | 545 | static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0); |
| 546 | static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1); |
| 547 | static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2); |
| 548 | static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3); |
| 549 | static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 15); |
| 550 | static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 6); |
| 551 | static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 7); |
| 552 | static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 15); |
Ivo Manca | 5c726b3 | 2007-10-15 20:50:53 +0200 | [diff] [blame] | 553 | |
Julia Lawall | feaf8bd | 2016-12-22 13:05:05 +0100 | [diff] [blame] | 554 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 555 | char *buf) |
| 556 | { |
| 557 | struct sis5595_data *data = dev_get_drvdata(dev); |
| 558 | return sprintf(buf, "%s\n", data->name); |
| 559 | } |
Julia Lawall | feaf8bd | 2016-12-22 13:05:05 +0100 | [diff] [blame] | 560 | static DEVICE_ATTR_RO(name); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 561 | |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 562 | static struct attribute *sis5595_attributes[] = { |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 563 | &sensor_dev_attr_in0_input.dev_attr.attr, |
| 564 | &sensor_dev_attr_in0_min.dev_attr.attr, |
| 565 | &sensor_dev_attr_in0_max.dev_attr.attr, |
Ivo Manca | 5c726b3 | 2007-10-15 20:50:53 +0200 | [diff] [blame] | 566 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 567 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 568 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 569 | &sensor_dev_attr_in1_max.dev_attr.attr, |
Ivo Manca | 5c726b3 | 2007-10-15 20:50:53 +0200 | [diff] [blame] | 570 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 571 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 572 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 573 | &sensor_dev_attr_in2_max.dev_attr.attr, |
Ivo Manca | 5c726b3 | 2007-10-15 20:50:53 +0200 | [diff] [blame] | 574 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 575 | &sensor_dev_attr_in3_input.dev_attr.attr, |
| 576 | &sensor_dev_attr_in3_min.dev_attr.attr, |
| 577 | &sensor_dev_attr_in3_max.dev_attr.attr, |
Ivo Manca | 5c726b3 | 2007-10-15 20:50:53 +0200 | [diff] [blame] | 578 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 579 | |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 580 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 581 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 582 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
Ivo Manca | 5c726b3 | 2007-10-15 20:50:53 +0200 | [diff] [blame] | 583 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 584 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 585 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
| 586 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
Ivo Manca | 5c726b3 | 2007-10-15 20:50:53 +0200 | [diff] [blame] | 587 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 588 | |
| 589 | &dev_attr_alarms.attr, |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 590 | &dev_attr_name.attr, |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 591 | NULL |
| 592 | }; |
| 593 | |
| 594 | static const struct attribute_group sis5595_group = { |
| 595 | .attrs = sis5595_attributes, |
| 596 | }; |
| 597 | |
Ivo Manca | 76e6386 | 2007-10-15 13:27:13 +0200 | [diff] [blame] | 598 | static struct attribute *sis5595_attributes_in4[] = { |
Jean Delvare | 1f5f48d | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 599 | &sensor_dev_attr_in4_input.dev_attr.attr, |
| 600 | &sensor_dev_attr_in4_min.dev_attr.attr, |
| 601 | &sensor_dev_attr_in4_max.dev_attr.attr, |
Ivo Manca | 5c726b3 | 2007-10-15 20:50:53 +0200 | [diff] [blame] | 602 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
Ivo Manca | 76e6386 | 2007-10-15 13:27:13 +0200 | [diff] [blame] | 603 | NULL |
| 604 | }; |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 605 | |
Ivo Manca | 76e6386 | 2007-10-15 13:27:13 +0200 | [diff] [blame] | 606 | static const struct attribute_group sis5595_group_in4 = { |
| 607 | .attrs = sis5595_attributes_in4, |
| 608 | }; |
| 609 | |
| 610 | static struct attribute *sis5595_attributes_temp1[] = { |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 611 | &dev_attr_temp1_input.attr, |
| 612 | &dev_attr_temp1_max.attr, |
| 613 | &dev_attr_temp1_max_hyst.attr, |
Ivo Manca | 5c726b3 | 2007-10-15 20:50:53 +0200 | [diff] [blame] | 614 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 615 | NULL |
| 616 | }; |
| 617 | |
Ivo Manca | 76e6386 | 2007-10-15 13:27:13 +0200 | [diff] [blame] | 618 | static const struct attribute_group sis5595_group_temp1 = { |
| 619 | .attrs = sis5595_attributes_temp1, |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 620 | }; |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 621 | |
Uwe Kleine-König | 1b2f9b1 | 2022-09-22 09:49:00 +0200 | [diff] [blame] | 622 | /* Called when we have found a new SIS5595. */ |
| 623 | static void sis5595_init_device(struct sis5595_data *data) |
| 624 | { |
| 625 | u8 config = sis5595_read_value(data, SIS5595_REG_CONFIG); |
| 626 | if (!(config & 0x01)) |
| 627 | sis5595_write_value(data, SIS5595_REG_CONFIG, |
| 628 | (config & 0xf7) | 0x01); |
| 629 | } |
| 630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | /* This is called when the module is loaded */ |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 632 | static int sis5595_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | { |
| 634 | int err = 0; |
| 635 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | struct sis5595_data *data; |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 637 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | char val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | /* Reserve the ISA region */ |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 641 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
Guenter Roeck | 5d224ad | 2012-06-02 11:20:23 -0700 | [diff] [blame] | 642 | if (!devm_request_region(&pdev->dev, res->start, SIS5595_EXTENT, |
Uwe Kleine-König | 847a3b0 | 2022-09-22 09:48:59 +0200 | [diff] [blame] | 643 | DRIVER_NAME)) |
Guenter Roeck | 5d224ad | 2012-06-02 11:20:23 -0700 | [diff] [blame] | 644 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
Guenter Roeck | 5d224ad | 2012-06-02 11:20:23 -0700 | [diff] [blame] | 646 | data = devm_kzalloc(&pdev->dev, sizeof(struct sis5595_data), |
| 647 | GFP_KERNEL); |
| 648 | if (!data) |
| 649 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 651 | mutex_init(&data->lock); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 652 | mutex_init(&data->update_lock); |
| 653 | data->addr = res->start; |
Uwe Kleine-König | 847a3b0 | 2022-09-22 09:48:59 +0200 | [diff] [blame] | 654 | data->name = DRIVER_NAME; |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 655 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 657 | /* |
| 658 | * Check revision and pin registers to determine whether 4 or 5 voltages |
| 659 | */ |
Auke Kok | 7b6d1f0 | 2007-08-27 16:17:01 -0700 | [diff] [blame] | 660 | data->revision = s_bridge->revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | /* 4 voltages, 1 temp */ |
| 662 | data->maxins = 3; |
| 663 | if (data->revision >= REV2MIN) { |
| 664 | pci_read_config_byte(s_bridge, SIS5595_PIN_REG, &val); |
| 665 | if (!(val & 0x80)) |
| 666 | /* 5 voltages, no temps */ |
| 667 | data->maxins = 4; |
| 668 | } |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /* Initialize the SIS5595 chip */ |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 671 | sis5595_init_device(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
| 673 | /* A few vars need to be filled upon startup */ |
| 674 | for (i = 0; i < 2; i++) { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 675 | data->fan_min[i] = sis5595_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | SIS5595_REG_FAN_MIN(i)); |
| 677 | } |
| 678 | |
| 679 | /* Register sysfs hooks */ |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 680 | err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group); |
| 681 | if (err) |
Guenter Roeck | 5d224ad | 2012-06-02 11:20:23 -0700 | [diff] [blame] | 682 | return err; |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 683 | if (data->maxins == 4) { |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 684 | err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group_in4); |
| 685 | if (err) |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 686 | goto exit_remove_files; |
| 687 | } else { |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 688 | err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group_temp1); |
| 689 | if (err) |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 690 | goto exit_remove_files; |
| 691 | } |
| 692 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 693 | data->hwmon_dev = hwmon_device_register(&pdev->dev); |
| 694 | if (IS_ERR(data->hwmon_dev)) { |
| 695 | err = PTR_ERR(data->hwmon_dev); |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 696 | goto exit_remove_files; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 697 | } |
| 698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | return 0; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 700 | |
Jean Delvare | a5ebe66 | 2006-09-24 21:24:46 +0200 | [diff] [blame] | 701 | exit_remove_files: |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 702 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group); |
Ivo Manca | 76e6386 | 2007-10-15 13:27:13 +0200 | [diff] [blame] | 703 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_in4); |
| 704 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_temp1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | return err; |
| 706 | } |
| 707 | |
Uwe Kleine-König | 3979775 | 2023-09-18 10:59:43 +0200 | [diff] [blame] | 708 | static void sis5595_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 710 | struct sis5595_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 712 | hwmon_device_unregister(data->hwmon_dev); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 713 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group); |
Ivo Manca | 76e6386 | 2007-10-15 13:27:13 +0200 | [diff] [blame] | 714 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_in4); |
| 715 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_temp1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Jingoo Han | cd9bb05 | 2013-12-03 07:10:29 +0000 | [diff] [blame] | 718 | static const struct pci_device_id sis5595_pci_ids[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, |
| 720 | { 0, } |
| 721 | }; |
| 722 | |
| 723 | MODULE_DEVICE_TABLE(pci, sis5595_pci_ids); |
| 724 | |
Bill Pemberton | a597724 | 2012-11-19 13:24:37 -0500 | [diff] [blame] | 725 | static int blacklist[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | PCI_DEVICE_ID_SI_540, |
| 727 | PCI_DEVICE_ID_SI_550, |
| 728 | PCI_DEVICE_ID_SI_630, |
| 729 | PCI_DEVICE_ID_SI_645, |
| 730 | PCI_DEVICE_ID_SI_730, |
| 731 | PCI_DEVICE_ID_SI_735, |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 732 | PCI_DEVICE_ID_SI_5511, /* |
| 733 | * 5513 chip has the 0008 device but |
| 734 | * that ID shows up in other chips so we |
| 735 | * use the 5511 ID for recognition |
| 736 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | PCI_DEVICE_ID_SI_5597, |
| 738 | PCI_DEVICE_ID_SI_5598, |
| 739 | 0 }; |
| 740 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 741 | static int sis5595_device_add(unsigned short address) |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 742 | { |
| 743 | struct resource res = { |
| 744 | .start = address, |
| 745 | .end = address + SIS5595_EXTENT - 1, |
Uwe Kleine-König | 847a3b0 | 2022-09-22 09:48:59 +0200 | [diff] [blame] | 746 | .name = DRIVER_NAME, |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 747 | .flags = IORESOURCE_IO, |
| 748 | }; |
| 749 | int err; |
| 750 | |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 751 | err = acpi_check_resource_conflict(&res); |
| 752 | if (err) |
| 753 | goto exit; |
| 754 | |
Uwe Kleine-König | 847a3b0 | 2022-09-22 09:48:59 +0200 | [diff] [blame] | 755 | pdev = platform_device_alloc(DRIVER_NAME, address); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 756 | if (!pdev) { |
| 757 | err = -ENOMEM; |
Joe Perches | 4b2515d | 2010-10-20 06:51:47 +0000 | [diff] [blame] | 758 | pr_err("Device allocation failed\n"); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 759 | goto exit; |
| 760 | } |
| 761 | |
| 762 | err = platform_device_add_resources(pdev, &res, 1); |
| 763 | if (err) { |
Joe Perches | 4b2515d | 2010-10-20 06:51:47 +0000 | [diff] [blame] | 764 | pr_err("Device resource addition failed (%d)\n", err); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 765 | goto exit_device_put; |
| 766 | } |
| 767 | |
| 768 | err = platform_device_add(pdev); |
| 769 | if (err) { |
Joe Perches | 4b2515d | 2010-10-20 06:51:47 +0000 | [diff] [blame] | 770 | pr_err("Device addition failed (%d)\n", err); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 771 | goto exit_device_put; |
| 772 | } |
| 773 | |
| 774 | return 0; |
| 775 | |
| 776 | exit_device_put: |
| 777 | platform_device_put(pdev); |
| 778 | exit: |
| 779 | return err; |
| 780 | } |
| 781 | |
Uwe Kleine-König | 1b2f9b1 | 2022-09-22 09:49:00 +0200 | [diff] [blame] | 782 | static struct platform_driver sis5595_driver = { |
| 783 | .driver = { |
| 784 | .name = DRIVER_NAME, |
| 785 | }, |
| 786 | .probe = sis5595_probe, |
Uwe Kleine-König | 3979775 | 2023-09-18 10:59:43 +0200 | [diff] [blame] | 787 | .remove_new = sis5595_remove, |
Uwe Kleine-König | 1b2f9b1 | 2022-09-22 09:49:00 +0200 | [diff] [blame] | 788 | }; |
| 789 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 790 | static int sis5595_pci_probe(struct pci_dev *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | const struct pci_device_id *id) |
| 792 | { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 793 | u16 address; |
| 794 | u8 enable; |
Ilpo Järvinen | a1f3898 | 2023-08-24 16:28:31 +0300 | [diff] [blame] | 795 | int *i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
| 797 | for (i = blacklist; *i != 0; i++) { |
Mark M. Hoffman | 5460a9d | 2007-10-14 14:57:35 -0400 | [diff] [blame] | 798 | struct pci_dev *d; |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 799 | d = pci_get_device(PCI_VENDOR_ID_SI, *i, NULL); |
| 800 | if (d) { |
| 801 | dev_err(&d->dev, |
| 802 | "Looked for SIS5595 but found unsupported device %.4x\n", |
| 803 | *i); |
Mark M. Hoffman | 5460a9d | 2007-10-14 14:57:35 -0400 | [diff] [blame] | 804 | pci_dev_put(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | return -ENODEV; |
| 806 | } |
| 807 | } |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 808 | |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 809 | force_addr &= ~(SIS5595_EXTENT - 1); |
| 810 | if (force_addr) { |
| 811 | dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", force_addr); |
| 812 | pci_write_config_word(dev, SIS5595_BASE_REG, force_addr); |
| 813 | } |
| 814 | |
Ilpo Järvinen | a1f3898 | 2023-08-24 16:28:31 +0300 | [diff] [blame] | 815 | err = pci_read_config_word(dev, SIS5595_BASE_REG, &address); |
| 816 | if (err != PCIBIOS_SUCCESSFUL) { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 817 | dev_err(&dev->dev, "Failed to read ISA address\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | return -ENODEV; |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 819 | } |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 820 | |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 821 | address &= ~(SIS5595_EXTENT - 1); |
| 822 | if (!address) { |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 823 | dev_err(&dev->dev, |
| 824 | "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | return -ENODEV; |
| 826 | } |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 827 | if (force_addr && address != force_addr) { |
| 828 | /* doesn't work for some chips? */ |
| 829 | dev_err(&dev->dev, "Failed to force ISA address\n"); |
| 830 | return -ENODEV; |
| 831 | } |
| 832 | |
Ilpo Järvinen | a1f3898 | 2023-08-24 16:28:31 +0300 | [diff] [blame] | 833 | err = pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable); |
| 834 | if (err != PCIBIOS_SUCCESSFUL) { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 835 | dev_err(&dev->dev, "Failed to read enable register\n"); |
| 836 | return -ENODEV; |
| 837 | } |
| 838 | if (!(enable & 0x80)) { |
Ilpo Järvinen | a1f3898 | 2023-08-24 16:28:31 +0300 | [diff] [blame] | 839 | err = pci_write_config_byte(dev, SIS5595_ENABLE_REG, enable | 0x80); |
| 840 | if (err != PCIBIOS_SUCCESSFUL) |
| 841 | goto enable_fail; |
| 842 | |
| 843 | err = pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable); |
| 844 | if (err != PCIBIOS_SUCCESSFUL) |
| 845 | goto enable_fail; |
| 846 | |
| 847 | /* doesn't work for some chips! */ |
| 848 | if (!(enable & 0x80)) |
| 849 | goto enable_fail; |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | if (platform_driver_register(&sis5595_driver)) { |
| 853 | dev_dbg(&dev->dev, "Failed to register sis5595 driver\n"); |
| 854 | goto exit; |
| 855 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | s_bridge = pci_dev_get(dev); |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 858 | /* Sets global pdev as a side effect */ |
| 859 | if (sis5595_device_add(address)) |
| 860 | goto exit_unregister; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
Guenter Roeck | 8fda79e | 2012-01-14 22:21:41 -0800 | [diff] [blame] | 862 | /* |
| 863 | * Always return failure here. This is to allow other drivers to bind |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | * to this pci device. We don't really want to have control over the |
| 865 | * pci device, we only wanted to read as few register values from it. |
| 866 | */ |
| 867 | return -ENODEV; |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 868 | |
Ilpo Järvinen | a1f3898 | 2023-08-24 16:28:31 +0300 | [diff] [blame] | 869 | enable_fail: |
| 870 | dev_err(&dev->dev, "Failed to enable HWM device\n"); |
| 871 | goto exit; |
| 872 | |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 873 | exit_unregister: |
| 874 | pci_dev_put(dev); |
| 875 | platform_driver_unregister(&sis5595_driver); |
| 876 | exit: |
| 877 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | static struct pci_driver sis5595_pci_driver = { |
Uwe Kleine-König | 847a3b0 | 2022-09-22 09:48:59 +0200 | [diff] [blame] | 881 | .name = DRIVER_NAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | .id_table = sis5595_pci_ids, |
| 883 | .probe = sis5595_pci_probe, |
| 884 | }; |
| 885 | |
| 886 | static int __init sm_sis5595_init(void) |
| 887 | { |
| 888 | return pci_register_driver(&sis5595_pci_driver); |
| 889 | } |
| 890 | |
| 891 | static void __exit sm_sis5595_exit(void) |
| 892 | { |
| 893 | pci_unregister_driver(&sis5595_pci_driver); |
| 894 | if (s_bridge != NULL) { |
Jean Delvare | 17e7dc4 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 895 | platform_device_unregister(pdev); |
| 896 | platform_driver_unregister(&sis5595_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | pci_dev_put(s_bridge); |
| 898 | s_bridge = NULL; |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | MODULE_AUTHOR("Aurelien Jarno <aurelien@aurel32.net>"); |
| 903 | MODULE_DESCRIPTION("SiS 5595 Sensor device"); |
| 904 | MODULE_LICENSE("GPL"); |
| 905 | |
| 906 | module_init(sm_sis5595_init); |
| 907 | module_exit(sm_sis5595_exit); |