Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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> |
| 12 | Copyright (C) 2004 Jean Delvare <khali@linux-fr.org> |
| 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 | */ |
| 28 | |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/ioport.h> |
| 32 | #include <linux/jiffies.h> |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 33 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 34 | #include <linux/hwmon.h> |
| 35 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/init.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 37 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/io.h> |
| 39 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 40 | static struct platform_device *pdev; |
| 41 | |
| 42 | #define DRVNAME "smsc47b397" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | /* Super-I/0 registers and commands */ |
| 45 | |
| 46 | #define REG 0x2e /* The register to read/write */ |
| 47 | #define VAL 0x2f /* The value to read/write */ |
| 48 | |
| 49 | static inline void superio_outb(int reg, int val) |
| 50 | { |
| 51 | outb(reg, REG); |
| 52 | outb(val, VAL); |
| 53 | } |
| 54 | |
| 55 | static inline int superio_inb(int reg) |
| 56 | { |
| 57 | outb(reg, REG); |
| 58 | return inb(VAL); |
| 59 | } |
| 60 | |
| 61 | /* select superio logical device */ |
| 62 | static inline void superio_select(int ld) |
| 63 | { |
| 64 | superio_outb(0x07, ld); |
| 65 | } |
| 66 | |
| 67 | static inline void superio_enter(void) |
| 68 | { |
| 69 | outb(0x55, REG); |
| 70 | } |
| 71 | |
| 72 | static inline void superio_exit(void) |
| 73 | { |
| 74 | outb(0xAA, REG); |
| 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; |
| 95 | const char *name; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 96 | struct class_device *class_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 97 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 99 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | unsigned long last_updated; /* in jiffies */ |
| 101 | int valid; |
| 102 | |
| 103 | /* register values */ |
| 104 | u16 fan[4]; |
| 105 | u8 temp[4]; |
| 106 | }; |
| 107 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 108 | static int smsc47b397_read_value(struct smsc47b397_data* data, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | int res; |
| 111 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 112 | mutex_lock(&data->lock); |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 113 | outb(reg, data->addr); |
| 114 | res = inb_p(data->addr + 1); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 115 | mutex_unlock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return res; |
| 117 | } |
| 118 | |
| 119 | static struct smsc47b397_data *smsc47b397_update_device(struct device *dev) |
| 120 | { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 121 | struct smsc47b397_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | int i; |
| 123 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 124 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 127 | dev_dbg(dev, "starting device update...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* 4 temperature inputs, 4 fan inputs */ |
| 130 | for (i = 0; i < 4; i++) { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 131 | data->temp[i] = smsc47b397_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | SMSC47B397_REG_TEMP(i)); |
| 133 | |
| 134 | /* must read LSB first */ |
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_LSB(i)); |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 137 | data->fan[i] |= smsc47b397_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | SMSC47B397_REG_FAN_MSB(i)) << 8; |
| 139 | } |
| 140 | |
| 141 | data->last_updated = jiffies; |
| 142 | data->valid = 1; |
| 143 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 144 | dev_dbg(dev, "... device update complete\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 147 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | return data; |
| 150 | } |
| 151 | |
| 152 | /* TEMP: 0.001C/bit (-128C to +127C) |
| 153 | REG: 1C/bit, two's complement */ |
| 154 | static int temp_from_reg(u8 reg) |
| 155 | { |
| 156 | return (s8)reg * 1000; |
| 157 | } |
| 158 | |
| 159 | /* 0 <= nr <= 3 */ |
| 160 | static ssize_t show_temp(struct device *dev, char *buf, int nr) |
| 161 | { |
| 162 | struct smsc47b397_data *data = smsc47b397_update_device(dev); |
| 163 | return sprintf(buf, "%d\n", temp_from_reg(data->temp[nr])); |
| 164 | } |
| 165 | |
| 166 | #define sysfs_temp(num) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 167 | static ssize_t show_temp##num(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { \ |
| 169 | return show_temp(dev, buf, num-1); \ |
| 170 | } \ |
| 171 | static DEVICE_ATTR(temp##num##_input, S_IRUGO, show_temp##num, NULL) |
| 172 | |
| 173 | sysfs_temp(1); |
| 174 | sysfs_temp(2); |
| 175 | sysfs_temp(3); |
| 176 | sysfs_temp(4); |
| 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /* FAN: 1 RPM/bit |
| 179 | REG: count of 90kHz pulses / revolution */ |
| 180 | static int fan_from_reg(u16 reg) |
| 181 | { |
| 182 | return 90000 * 60 / reg; |
| 183 | } |
| 184 | |
| 185 | /* 0 <= nr <= 3 */ |
| 186 | static ssize_t show_fan(struct device *dev, char *buf, int nr) |
| 187 | { |
| 188 | struct smsc47b397_data *data = smsc47b397_update_device(dev); |
| 189 | return sprintf(buf, "%d\n", fan_from_reg(data->fan[nr])); |
| 190 | } |
| 191 | |
| 192 | #define sysfs_fan(num) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 193 | static ssize_t show_fan##num(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { \ |
| 195 | return show_fan(dev, buf, num-1); \ |
| 196 | } \ |
| 197 | static DEVICE_ATTR(fan##num##_input, S_IRUGO, show_fan##num, NULL) |
| 198 | |
| 199 | sysfs_fan(1); |
| 200 | sysfs_fan(2); |
| 201 | sysfs_fan(3); |
| 202 | sysfs_fan(4); |
| 203 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 204 | static ssize_t show_name(struct device *dev, struct device_attribute |
| 205 | *devattr, char *buf) |
| 206 | { |
| 207 | struct smsc47b397_data *data = dev_get_drvdata(dev); |
| 208 | return sprintf(buf, "%s\n", data->name); |
| 209 | } |
| 210 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 211 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 212 | static struct attribute *smsc47b397_attributes[] = { |
| 213 | &dev_attr_temp1_input.attr, |
| 214 | &dev_attr_temp2_input.attr, |
| 215 | &dev_attr_temp3_input.attr, |
| 216 | &dev_attr_temp4_input.attr, |
| 217 | &dev_attr_fan1_input.attr, |
| 218 | &dev_attr_fan2_input.attr, |
| 219 | &dev_attr_fan3_input.attr, |
| 220 | &dev_attr_fan4_input.attr, |
| 221 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 222 | &dev_attr_name.attr, |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 223 | NULL |
| 224 | }; |
| 225 | |
| 226 | static const struct attribute_group smsc47b397_group = { |
| 227 | .attrs = smsc47b397_attributes, |
| 228 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 230 | static int __devexit smsc47b397_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 232 | struct smsc47b397_data *data = platform_get_drvdata(pdev); |
| 233 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 235 | hwmon_device_unregister(data->class_dev); |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 236 | sysfs_remove_group(&pdev->dev.kobj, &smsc47b397_group); |
| 237 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 238 | release_region(res->start, SMSC_EXTENT); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 239 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 244 | static int smsc47b397_probe(struct platform_device *pdev); |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 245 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 246 | static struct platform_driver smsc47b397_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 247 | .driver = { |
Jean Delvare | 8721884 | 2006-09-03 22:36:14 +0200 | [diff] [blame] | 248 | .owner = THIS_MODULE, |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 249 | .name = DRVNAME, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 250 | }, |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 251 | .probe = smsc47b397_probe, |
| 252 | .remove = __devexit_p(smsc47b397_remove), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 255 | static int __devinit smsc47b397_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 257 | struct device *dev = &pdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | struct smsc47b397_data *data; |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 259 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | int err = 0; |
| 261 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 262 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 263 | if (!request_region(res->start, SMSC_EXTENT, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 264 | smsc47b397_driver.driver.name)) { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 265 | dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", |
| 266 | (unsigned long)res->start, |
| 267 | (unsigned long)res->start + SMSC_EXTENT - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | return -EBUSY; |
| 269 | } |
| 270 | |
Deepak Saxena | ba9c2e8 | 2005-10-17 23:08:32 +0200 | [diff] [blame] | 271 | if (!(data = kzalloc(sizeof(struct smsc47b397_data), GFP_KERNEL))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | err = -ENOMEM; |
| 273 | goto error_release; |
| 274 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 276 | data->addr = res->start; |
| 277 | data->name = "smsc47b397"; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 278 | mutex_init(&data->lock); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 279 | mutex_init(&data->update_lock); |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 280 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 282 | if ((err = sysfs_create_group(&dev->kobj, &smsc47b397_group))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | goto error_free; |
| 284 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 285 | data->class_dev = hwmon_device_register(dev); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 286 | if (IS_ERR(data->class_dev)) { |
| 287 | err = PTR_ERR(data->class_dev); |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 288 | goto error_remove; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 289 | } |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return 0; |
| 292 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 293 | error_remove: |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 294 | sysfs_remove_group(&dev->kobj, &smsc47b397_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | error_free: |
Alexey Dobriyan | 1f57ff8 | 2005-08-26 01:49:14 +0400 | [diff] [blame] | 296 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | error_release: |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 298 | release_region(res->start, SMSC_EXTENT); |
| 299 | return err; |
| 300 | } |
| 301 | |
| 302 | static int __init smsc47b397_device_add(unsigned short address) |
| 303 | { |
| 304 | struct resource res = { |
| 305 | .start = address, |
| 306 | .end = address + SMSC_EXTENT - 1, |
| 307 | .name = DRVNAME, |
| 308 | .flags = IORESOURCE_IO, |
| 309 | }; |
| 310 | int err; |
| 311 | |
| 312 | pdev = platform_device_alloc(DRVNAME, address); |
| 313 | if (!pdev) { |
| 314 | err = -ENOMEM; |
| 315 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); |
| 316 | goto exit; |
| 317 | } |
| 318 | |
| 319 | err = platform_device_add_resources(pdev, &res, 1); |
| 320 | if (err) { |
| 321 | printk(KERN_ERR DRVNAME ": Device resource addition failed " |
| 322 | "(%d)\n", err); |
| 323 | goto exit_device_put; |
| 324 | } |
| 325 | |
| 326 | err = platform_device_add(pdev); |
| 327 | if (err) { |
| 328 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", |
| 329 | err); |
| 330 | goto exit_device_put; |
| 331 | } |
| 332 | |
| 333 | return 0; |
| 334 | |
| 335 | exit_device_put: |
| 336 | platform_device_put(pdev); |
| 337 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | return err; |
| 339 | } |
| 340 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 341 | static int __init smsc47b397_find(unsigned short *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | { |
| 343 | u8 id, rev; |
| 344 | |
| 345 | superio_enter(); |
| 346 | id = superio_inb(SUPERIO_REG_DEVID); |
| 347 | |
Mark M. Hoffman | 7ab83a9 | 2005-10-17 23:01:45 +0200 | [diff] [blame] | 348 | if ((id != 0x6f) && (id != 0x81)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | superio_exit(); |
| 350 | return -ENODEV; |
| 351 | } |
| 352 | |
| 353 | rev = superio_inb(SUPERIO_REG_DEVREV); |
| 354 | |
| 355 | superio_select(SUPERIO_REG_LD8); |
| 356 | *addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8) |
| 357 | | superio_inb(SUPERIO_REG_BASE_LSB); |
| 358 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 359 | printk(KERN_INFO DRVNAME ": found SMSC %s " |
Mark M. Hoffman | 7ab83a9 | 2005-10-17 23:01:45 +0200 | [diff] [blame] | 360 | "(base address 0x%04x, revision %u)\n", |
| 361 | id == 0x81 ? "SCH5307-NS" : "LPC47B397-NC", *addr, rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | superio_exit(); |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static int __init smsc47b397_init(void) |
| 368 | { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 369 | unsigned short address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | int ret; |
| 371 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 372 | if ((ret = smsc47b397_find(&address))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | return ret; |
| 374 | |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 375 | ret = platform_driver_register(&smsc47b397_driver); |
| 376 | if (ret) |
| 377 | goto exit; |
| 378 | |
| 379 | /* Sets global pdev as a side effect */ |
| 380 | ret = smsc47b397_device_add(address); |
| 381 | if (ret) |
| 382 | goto exit_driver; |
| 383 | |
| 384 | return 0; |
| 385 | |
| 386 | exit_driver: |
| 387 | platform_driver_unregister(&smsc47b397_driver); |
| 388 | exit: |
| 389 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static void __exit smsc47b397_exit(void) |
| 393 | { |
Jean Delvare | 292fc1a | 2007-05-08 17:22:03 +0200 | [diff] [blame^] | 394 | platform_device_unregister(pdev); |
| 395 | platform_driver_unregister(&smsc47b397_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); |
| 399 | MODULE_DESCRIPTION("SMSC LPC47B397 driver"); |
| 400 | MODULE_LICENSE("GPL"); |
| 401 | |
| 402 | module_init(smsc47b397_init); |
| 403 | module_exit(smsc47b397_exit); |