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 | 2a52dd6 | 2012-01-19 11:02:25 -0800 | [diff] [blame] | 3 | * smsc47b397.c - Part of lm_sensors, Linux kernel modules |
| 4 | * for hardware monitoring |
| 5 | * |
| 6 | * Supports the SMSC LPC47B397-NC Super-I/O chip. |
| 7 | * |
| 8 | * Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com> |
| 9 | * Copyright (C) 2004 Utilitek Systems, Inc. |
| 10 | * |
| 11 | * derived in part from smsc47m1.c: |
| 12 | * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> |
Jean Delvare | 7c81c60f | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 13 | * Copyright (C) 2004 Jean Delvare <jdelvare@suse.de> |
Guenter Roeck | 2a52dd6 | 2012-01-19 11:02:25 -0800 | [diff] [blame] | 14 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Joe Perches | bf1a85e | 2010-10-20 06:51:48 +0000 | [diff] [blame] | 16 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/ioport.h> |
| 21 | #include <linux/jiffies.h> |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 23 | #include <linux/hwmon.h> |
Jean Delvare | 3659a01 | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 24 | #include <linux/hwmon-sysfs.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 25 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/init.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 27 | #include <linux/mutex.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 28 | #include <linux/acpi.h> |
H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 29 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 31 | static unsigned short force_id; |
| 32 | module_param(force_id, ushort, 0); |
| 33 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); |
| 34 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 35 | static struct platform_device *pdev; |
| 36 | |
| 37 | #define DRVNAME "smsc47b397" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | /* Super-I/0 registers and commands */ |
| 40 | |
| 41 | #define REG 0x2e /* The register to read/write */ |
| 42 | #define VAL 0x2f /* The value to read/write */ |
| 43 | |
| 44 | static inline void superio_outb(int reg, int val) |
| 45 | { |
| 46 | outb(reg, REG); |
| 47 | outb(val, VAL); |
| 48 | } |
| 49 | |
| 50 | static inline int superio_inb(int reg) |
| 51 | { |
| 52 | outb(reg, REG); |
| 53 | return inb(VAL); |
| 54 | } |
| 55 | |
| 56 | /* select superio logical device */ |
| 57 | static inline void superio_select(int ld) |
| 58 | { |
| 59 | superio_outb(0x07, ld); |
| 60 | } |
| 61 | |
Guenter Roeck | 8c08267 | 2019-04-04 11:22:42 -0700 | [diff] [blame] | 62 | static inline int superio_enter(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
Guenter Roeck | 8c08267 | 2019-04-04 11:22:42 -0700 | [diff] [blame] | 64 | if (!request_muxed_region(REG, 2, DRVNAME)) |
| 65 | return -EBUSY; |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | outb(0x55, REG); |
Guenter Roeck | 8c08267 | 2019-04-04 11:22:42 -0700 | [diff] [blame] | 68 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static inline void superio_exit(void) |
| 72 | { |
| 73 | outb(0xAA, REG); |
Guenter Roeck | 8c08267 | 2019-04-04 11:22:42 -0700 | [diff] [blame] | 74 | release_region(REG, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | #define SUPERIO_REG_DEVID 0x20 |
| 78 | #define SUPERIO_REG_DEVREV 0x21 |
| 79 | #define SUPERIO_REG_BASE_MSB 0x60 |
| 80 | #define SUPERIO_REG_BASE_LSB 0x61 |
| 81 | #define SUPERIO_REG_LD8 0x08 |
| 82 | |
| 83 | #define SMSC_EXTENT 0x02 |
| 84 | |
| 85 | /* 0 <= nr <= 3 */ |
| 86 | static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80}; |
| 87 | #define SMSC47B397_REG_TEMP(nr) (smsc47b397_reg_temp[(nr)]) |
| 88 | |
| 89 | /* 0 <= nr <= 3 */ |
| 90 | #define SMSC47B397_REG_FAN_LSB(nr) (0x28 + 2 * (nr)) |
| 91 | #define SMSC47B397_REG_FAN_MSB(nr) (0x29 + 2 * (nr)) |
| 92 | |
| 93 | struct smsc47b397_data { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 94 | unsigned short addr; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 95 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 97 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | unsigned long last_updated; /* in jiffies */ |
| 99 | int valid; |
| 100 | |
| 101 | /* register values */ |
| 102 | u16 fan[4]; |
| 103 | u8 temp[4]; |
| 104 | }; |
| 105 | |
Jean Delvare | 371f2e0 | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 106 | static int smsc47b397_read_value(struct smsc47b397_data *data, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | int res; |
| 109 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 110 | mutex_lock(&data->lock); |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 111 | outb(reg, data->addr); |
| 112 | res = inb_p(data->addr + 1); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 113 | mutex_unlock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return res; |
| 115 | } |
| 116 | |
| 117 | static struct smsc47b397_data *smsc47b397_update_device(struct device *dev) |
| 118 | { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 119 | struct smsc47b397_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | int i; |
| 121 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 122 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 125 | dev_dbg(dev, "starting device update...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | /* 4 temperature inputs, 4 fan inputs */ |
| 128 | for (i = 0; i < 4; i++) { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 129 | data->temp[i] = smsc47b397_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | SMSC47B397_REG_TEMP(i)); |
| 131 | |
| 132 | /* must read LSB first */ |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 133 | data->fan[i] = smsc47b397_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | SMSC47B397_REG_FAN_LSB(i)); |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 135 | data->fan[i] |= smsc47b397_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | SMSC47B397_REG_FAN_MSB(i)) << 8; |
| 137 | } |
| 138 | |
| 139 | data->last_updated = jiffies; |
| 140 | data->valid = 1; |
| 141 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 142 | dev_dbg(dev, "... device update complete\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 145 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | return data; |
| 148 | } |
| 149 | |
Guenter Roeck | 2a52dd6 | 2012-01-19 11:02:25 -0800 | [diff] [blame] | 150 | /* |
| 151 | * TEMP: 0.001C/bit (-128C to +127C) |
| 152 | * REG: 1C/bit, two's complement |
| 153 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | static int temp_from_reg(u8 reg) |
| 155 | { |
| 156 | return (s8)reg * 1000; |
| 157 | } |
| 158 | |
Guenter Roeck | 8721bde | 2018-12-10 14:02:21 -0800 | [diff] [blame] | 159 | static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, |
| 160 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Jean Delvare | 3659a01 | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 162 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | struct smsc47b397_data *data = smsc47b397_update_device(dev); |
Jean Delvare | 3659a01 | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 164 | return sprintf(buf, "%d\n", temp_from_reg(data->temp[attr->index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Guenter Roeck | 8721bde | 2018-12-10 14:02:21 -0800 | [diff] [blame] | 167 | static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0); |
| 168 | static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1); |
| 169 | static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); |
| 170 | static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Guenter Roeck | 2a52dd6 | 2012-01-19 11:02:25 -0800 | [diff] [blame] | 172 | /* |
| 173 | * FAN: 1 RPM/bit |
| 174 | * REG: count of 90kHz pulses / revolution |
| 175 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | static int fan_from_reg(u16 reg) |
| 177 | { |
Jean Delvare | 90205c6 | 2007-06-23 14:58:22 +0200 | [diff] [blame] | 178 | if (reg == 0 || reg == 0xffff) |
| 179 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return 90000 * 60 / reg; |
| 181 | } |
| 182 | |
Guenter Roeck | 8721bde | 2018-12-10 14:02:21 -0800 | [diff] [blame] | 183 | static ssize_t fan_show(struct device *dev, struct device_attribute *devattr, |
| 184 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
Jean Delvare | 3659a01 | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 186 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 187 | struct smsc47b397_data *data = smsc47b397_update_device(dev); |
| 188 | return sprintf(buf, "%d\n", fan_from_reg(data->fan[attr->index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
Guenter Roeck | 8721bde | 2018-12-10 14:02:21 -0800 | [diff] [blame] | 190 | static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0); |
| 191 | static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1); |
| 192 | static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2); |
| 193 | static SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Axel Lin | 9b993e3 | 2014-07-08 09:27:38 +0800 | [diff] [blame] | 195 | static struct attribute *smsc47b397_attrs[] = { |
Jean Delvare | 3659a01 | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 196 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 197 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 198 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 199 | &sensor_dev_attr_temp4_input.dev_attr.attr, |
| 200 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 201 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 202 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 203 | &sensor_dev_attr_fan4_input.dev_attr.attr, |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 204 | |
| 205 | NULL |
| 206 | }; |
| 207 | |
Axel Lin | 9b993e3 | 2014-07-08 09:27:38 +0800 | [diff] [blame] | 208 | ATTRIBUTE_GROUPS(smsc47b397); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 210 | static int smsc47b397_probe(struct platform_device *pdev); |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 211 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 212 | static struct platform_driver smsc47b397_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 213 | .driver = { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 214 | .name = DRVNAME, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 215 | }, |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 216 | .probe = smsc47b397_probe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 219 | static int smsc47b397_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 221 | struct device *dev = &pdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | struct smsc47b397_data *data; |
Axel Lin | 9b993e3 | 2014-07-08 09:27:38 +0800 | [diff] [blame] | 223 | struct device *hwmon_dev; |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 224 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 226 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
Guenter Roeck | e43d5fe | 2012-06-02 12:04:06 -0700 | [diff] [blame] | 227 | if (!devm_request_region(dev, res->start, SMSC_EXTENT, |
| 228 | smsc47b397_driver.driver.name)) { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 229 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", |
| 230 | (unsigned long)res->start, |
| 231 | (unsigned long)res->start + SMSC_EXTENT - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | return -EBUSY; |
| 233 | } |
| 234 | |
Guenter Roeck | e43d5fe | 2012-06-02 12:04:06 -0700 | [diff] [blame] | 235 | data = devm_kzalloc(dev, sizeof(struct smsc47b397_data), GFP_KERNEL); |
| 236 | if (!data) |
| 237 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 239 | data->addr = res->start; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 240 | mutex_init(&data->lock); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 241 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Axel Lin | 9b993e3 | 2014-07-08 09:27:38 +0800 | [diff] [blame] | 243 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, "smsc47b397", |
| 244 | data, |
| 245 | smsc47b397_groups); |
| 246 | return PTR_ERR_OR_ZERO(hwmon_dev); |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static int __init smsc47b397_device_add(unsigned short address) |
| 250 | { |
| 251 | struct resource res = { |
| 252 | .start = address, |
| 253 | .end = address + SMSC_EXTENT - 1, |
| 254 | .name = DRVNAME, |
| 255 | .flags = IORESOURCE_IO, |
| 256 | }; |
| 257 | int err; |
| 258 | |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 259 | err = acpi_check_resource_conflict(&res); |
| 260 | if (err) |
| 261 | goto exit; |
| 262 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 263 | pdev = platform_device_alloc(DRVNAME, address); |
| 264 | if (!pdev) { |
| 265 | err = -ENOMEM; |
Joe Perches | bf1a85e | 2010-10-20 06:51:48 +0000 | [diff] [blame] | 266 | pr_err("Device allocation failed\n"); |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 267 | goto exit; |
| 268 | } |
| 269 | |
| 270 | err = platform_device_add_resources(pdev, &res, 1); |
| 271 | if (err) { |
Joe Perches | bf1a85e | 2010-10-20 06:51:48 +0000 | [diff] [blame] | 272 | pr_err("Device resource addition failed (%d)\n", err); |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 273 | goto exit_device_put; |
| 274 | } |
| 275 | |
| 276 | err = platform_device_add(pdev); |
| 277 | if (err) { |
Joe Perches | bf1a85e | 2010-10-20 06:51:48 +0000 | [diff] [blame] | 278 | pr_err("Device addition failed (%d)\n", err); |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 279 | goto exit_device_put; |
| 280 | } |
| 281 | |
| 282 | return 0; |
| 283 | |
| 284 | exit_device_put: |
| 285 | platform_device_put(pdev); |
| 286 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return err; |
| 288 | } |
| 289 | |
Guenter Roeck | 8528e07 | 2012-03-28 08:35:26 -0700 | [diff] [blame] | 290 | static int __init smsc47b397_find(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | { |
| 292 | u8 id, rev; |
Craig Kelley | 8093077 | 2008-02-29 10:24:44 -0700 | [diff] [blame] | 293 | char *name; |
Guenter Roeck | 8528e07 | 2012-03-28 08:35:26 -0700 | [diff] [blame] | 294 | unsigned short addr; |
Guenter Roeck | 8c08267 | 2019-04-04 11:22:42 -0700 | [diff] [blame] | 295 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Guenter Roeck | 8c08267 | 2019-04-04 11:22:42 -0700 | [diff] [blame] | 297 | err = superio_enter(); |
| 298 | if (err) |
| 299 | return err; |
| 300 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 301 | id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
Jean Delvare | 371f2e0 | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 303 | switch (id) { |
Craig Kelley | 8093077 | 2008-02-29 10:24:44 -0700 | [diff] [blame] | 304 | case 0x81: |
| 305 | name = "SCH5307-NS"; |
| 306 | break; |
| 307 | case 0x6f: |
| 308 | name = "LPC47B397-NC"; |
| 309 | break; |
| 310 | case 0x85: |
| 311 | case 0x8c: |
| 312 | name = "SCH5317"; |
| 313 | break; |
| 314 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | superio_exit(); |
| 316 | return -ENODEV; |
| 317 | } |
| 318 | |
| 319 | rev = superio_inb(SUPERIO_REG_DEVREV); |
| 320 | |
| 321 | superio_select(SUPERIO_REG_LD8); |
Guenter Roeck | 8528e07 | 2012-03-28 08:35:26 -0700 | [diff] [blame] | 322 | addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | | superio_inb(SUPERIO_REG_BASE_LSB); |
| 324 | |
Joe Perches | bf1a85e | 2010-10-20 06:51:48 +0000 | [diff] [blame] | 325 | pr_info("found SMSC %s (base address 0x%04x, revision %u)\n", |
Guenter Roeck | 8528e07 | 2012-03-28 08:35:26 -0700 | [diff] [blame] | 326 | name, addr, rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | superio_exit(); |
Guenter Roeck | 8528e07 | 2012-03-28 08:35:26 -0700 | [diff] [blame] | 329 | return addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static int __init smsc47b397_init(void) |
| 333 | { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 334 | unsigned short address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | int ret; |
| 336 | |
Guenter Roeck | 8528e07 | 2012-03-28 08:35:26 -0700 | [diff] [blame] | 337 | ret = smsc47b397_find(); |
| 338 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | return ret; |
Guenter Roeck | 8528e07 | 2012-03-28 08:35:26 -0700 | [diff] [blame] | 340 | address = ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 342 | ret = platform_driver_register(&smsc47b397_driver); |
| 343 | if (ret) |
| 344 | goto exit; |
| 345 | |
| 346 | /* Sets global pdev as a side effect */ |
| 347 | ret = smsc47b397_device_add(address); |
| 348 | if (ret) |
| 349 | goto exit_driver; |
| 350 | |
| 351 | return 0; |
| 352 | |
| 353 | exit_driver: |
| 354 | platform_driver_unregister(&smsc47b397_driver); |
| 355 | exit: |
| 356 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static void __exit smsc47b397_exit(void) |
| 360 | { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame] | 361 | platform_device_unregister(pdev); |
| 362 | platform_driver_unregister(&smsc47b397_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); |
| 366 | MODULE_DESCRIPTION("SMSC LPC47B397 driver"); |
| 367 | MODULE_LICENSE("GPL"); |
| 368 | |
| 369 | module_init(smsc47b397_init); |
| 370 | module_exit(smsc47b397_exit); |