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