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