diff options
Diffstat (limited to 'drivers/char/pc8736x_gpio.c')
-rw-r--r-- | drivers/char/pc8736x_gpio.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c index 4005ee0aa11e..645eb81cb5a9 100644 --- a/drivers/char/pc8736x_gpio.c +++ b/drivers/char/pc8736x_gpio.c | |||
@@ -3,18 +3,18 @@ | |||
3 | National Semiconductor PC8736x GPIO driver. Allows a user space | 3 | National Semiconductor PC8736x GPIO driver. Allows a user space |
4 | process to play with the GPIO pins. | 4 | process to play with the GPIO pins. |
5 | 5 | ||
6 | Copyright (c) 2005 Jim Cromie <jim.cromie@gmail.com> | 6 | Copyright (c) 2005,2006 Jim Cromie <jim.cromie@gmail.com> |
7 | 7 | ||
8 | adapted from linux/drivers/char/scx200_gpio.c | 8 | adapted from linux/drivers/char/scx200_gpio.c |
9 | Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>, | 9 | Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>, |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/config.h> | ||
13 | #include <linux/fs.h> | 12 | #include <linux/fs.h> |
14 | #include <linux/module.h> | 13 | #include <linux/module.h> |
15 | #include <linux/errno.h> | 14 | #include <linux/errno.h> |
16 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
17 | #include <linux/init.h> | 16 | #include <linux/init.h> |
17 | #include <linux/cdev.h> | ||
18 | #include <linux/io.h> | 18 | #include <linux/io.h> |
19 | #include <linux/ioport.h> | 19 | #include <linux/ioport.h> |
20 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
@@ -25,7 +25,7 @@ | |||
25 | #define DEVNAME "pc8736x_gpio" | 25 | #define DEVNAME "pc8736x_gpio" |
26 | 26 | ||
27 | MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>"); | 27 | MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>"); |
28 | MODULE_DESCRIPTION("NatSemi PC-8736x GPIO Pin Driver"); | 28 | MODULE_DESCRIPTION("NatSemi/Winbond PC-8736x GPIO Pin Driver"); |
29 | MODULE_LICENSE("GPL"); | 29 | MODULE_LICENSE("GPL"); |
30 | 30 | ||
31 | static int major; /* default to dynamic major */ | 31 | static int major; /* default to dynamic major */ |
@@ -38,14 +38,14 @@ static u8 pc8736x_gpio_shadow[4]; | |||
38 | 38 | ||
39 | #define SIO_BASE1 0x2E /* 1st command-reg to check */ | 39 | #define SIO_BASE1 0x2E /* 1st command-reg to check */ |
40 | #define SIO_BASE2 0x4E /* alt command-reg to check */ | 40 | #define SIO_BASE2 0x4E /* alt command-reg to check */ |
41 | #define SIO_BASE_OFFSET 0x20 | ||
42 | 41 | ||
43 | #define SIO_SID 0x20 /* SuperI/O ID Register */ | 42 | #define SIO_SID 0x20 /* SuperI/O ID Register */ |
44 | #define SIO_SID_VALUE 0xe9 /* Expected value in SuperI/O ID Register */ | 43 | #define SIO_SID_VALUE 0xe9 /* Expected value in SuperI/O ID Register */ |
45 | 44 | ||
46 | #define SIO_CF1 0x21 /* chip config, bit0 is chip enable */ | 45 | #define SIO_CF1 0x21 /* chip config, bit0 is chip enable */ |
47 | 46 | ||
48 | #define PC8736X_GPIO_SIZE 16 | 47 | #define PC8736X_GPIO_RANGE 16 /* ioaddr range */ |
48 | #define PC8736X_GPIO_CT 32 /* minors matching 4 8 bit ports */ | ||
49 | 49 | ||
50 | #define SIO_UNIT_SEL 0x7 /* unit select reg */ | 50 | #define SIO_UNIT_SEL 0x7 /* unit select reg */ |
51 | #define SIO_UNIT_ACT 0x30 /* unit enable */ | 51 | #define SIO_UNIT_ACT 0x30 /* unit enable */ |
@@ -212,31 +212,30 @@ static void pc8736x_gpio_change(unsigned index) | |||
212 | pc8736x_gpio_set(index, !pc8736x_gpio_current(index)); | 212 | pc8736x_gpio_set(index, !pc8736x_gpio_current(index)); |
213 | } | 213 | } |
214 | 214 | ||
215 | static struct nsc_gpio_ops pc8736x_access = { | 215 | static struct nsc_gpio_ops pc8736x_gpio_ops = { |
216 | .owner = THIS_MODULE, | 216 | .owner = THIS_MODULE, |
217 | .gpio_config = pc8736x_gpio_configure, | 217 | .gpio_config = pc8736x_gpio_configure, |
218 | .gpio_dump = nsc_gpio_dump, | 218 | .gpio_dump = nsc_gpio_dump, |
219 | .gpio_get = pc8736x_gpio_get, | 219 | .gpio_get = pc8736x_gpio_get, |
220 | .gpio_set = pc8736x_gpio_set, | 220 | .gpio_set = pc8736x_gpio_set, |
221 | .gpio_set_high = pc8736x_gpio_set_high, | ||
222 | .gpio_set_low = pc8736x_gpio_set_low, | ||
223 | .gpio_change = pc8736x_gpio_change, | 221 | .gpio_change = pc8736x_gpio_change, |
224 | .gpio_current = pc8736x_gpio_current | 222 | .gpio_current = pc8736x_gpio_current |
225 | }; | 223 | }; |
224 | EXPORT_SYMBOL(pc8736x_gpio_ops); | ||
226 | 225 | ||
227 | static int pc8736x_gpio_open(struct inode *inode, struct file *file) | 226 | static int pc8736x_gpio_open(struct inode *inode, struct file *file) |
228 | { | 227 | { |
229 | unsigned m = iminor(inode); | 228 | unsigned m = iminor(inode); |
230 | file->private_data = &pc8736x_access; | 229 | file->private_data = &pc8736x_gpio_ops; |
231 | 230 | ||
232 | dev_dbg(&pdev->dev, "open %d\n", m); | 231 | dev_dbg(&pdev->dev, "open %d\n", m); |
233 | 232 | ||
234 | if (m > 63) | 233 | if (m >= PC8736X_GPIO_CT) |
235 | return -EINVAL; | 234 | return -EINVAL; |
236 | return nonseekable_open(inode, file); | 235 | return nonseekable_open(inode, file); |
237 | } | 236 | } |
238 | 237 | ||
239 | static const struct file_operations pc8736x_gpio_fops = { | 238 | static const struct file_operations pc8736x_gpio_fileops = { |
240 | .owner = THIS_MODULE, | 239 | .owner = THIS_MODULE, |
241 | .open = pc8736x_gpio_open, | 240 | .open = pc8736x_gpio_open, |
242 | .write = nsc_gpio_write, | 241 | .write = nsc_gpio_write, |
@@ -255,9 +254,12 @@ static void __init pc8736x_init_shadow(void) | |||
255 | 254 | ||
256 | } | 255 | } |
257 | 256 | ||
257 | static struct cdev pc8736x_gpio_cdev; | ||
258 | |||
258 | static int __init pc8736x_gpio_init(void) | 259 | static int __init pc8736x_gpio_init(void) |
259 | { | 260 | { |
260 | int rc = 0; | 261 | int rc; |
262 | dev_t devid; | ||
261 | 263 | ||
262 | pdev = platform_device_alloc(DEVNAME, 0); | 264 | pdev = platform_device_alloc(DEVNAME, 0); |
263 | if (!pdev) | 265 | if (!pdev) |
@@ -275,7 +277,7 @@ static int __init pc8736x_gpio_init(void) | |||
275 | dev_err(&pdev->dev, "no device found\n"); | 277 | dev_err(&pdev->dev, "no device found\n"); |
276 | goto undo_platform_dev_add; | 278 | goto undo_platform_dev_add; |
277 | } | 279 | } |
278 | pc8736x_access.dev = &pdev->dev; | 280 | pc8736x_gpio_ops.dev = &pdev->dev; |
279 | 281 | ||
280 | /* Verify that chip and it's GPIO unit are both enabled. | 282 | /* Verify that chip and it's GPIO unit are both enabled. |
281 | My BIOS does this, so I take minimum action here | 283 | My BIOS does this, so I take minimum action here |
@@ -297,7 +299,7 @@ static int __init pc8736x_gpio_init(void) | |||
297 | pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8 | 299 | pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8 |
298 | | superio_inb(SIO_BASE_LADDR)); | 300 | | superio_inb(SIO_BASE_LADDR)); |
299 | 301 | ||
300 | if (!request_region(pc8736x_gpio_base, 16, DEVNAME)) { | 302 | if (!request_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE, DEVNAME)) { |
301 | rc = -ENODEV; | 303 | rc = -ENODEV; |
302 | dev_err(&pdev->dev, "GPIO ioport %x busy\n", | 304 | dev_err(&pdev->dev, "GPIO ioport %x busy\n", |
303 | pc8736x_gpio_base); | 305 | pc8736x_gpio_base); |
@@ -305,10 +307,17 @@ static int __init pc8736x_gpio_init(void) | |||
305 | } | 307 | } |
306 | dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base); | 308 | dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base); |
307 | 309 | ||
308 | rc = register_chrdev(major, DEVNAME, &pc8736x_gpio_fops); | 310 | if (major) { |
311 | devid = MKDEV(major, 0); | ||
312 | rc = register_chrdev_region(devid, PC8736X_GPIO_CT, DEVNAME); | ||
313 | } else { | ||
314 | rc = alloc_chrdev_region(&devid, 0, PC8736X_GPIO_CT, DEVNAME); | ||
315 | major = MAJOR(devid); | ||
316 | } | ||
317 | |||
309 | if (rc < 0) { | 318 | if (rc < 0) { |
310 | dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc); | 319 | dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc); |
311 | goto undo_platform_dev_add; | 320 | goto undo_request_region; |
312 | } | 321 | } |
313 | if (!major) { | 322 | if (!major) { |
314 | major = rc; | 323 | major = rc; |
@@ -316,8 +325,15 @@ static int __init pc8736x_gpio_init(void) | |||
316 | } | 325 | } |
317 | 326 | ||
318 | pc8736x_init_shadow(); | 327 | pc8736x_init_shadow(); |
328 | |||
329 | /* ignore minor errs, and succeed */ | ||
330 | cdev_init(&pc8736x_gpio_cdev, &pc8736x_gpio_fileops); | ||
331 | cdev_add(&pc8736x_gpio_cdev, devid, PC8736X_GPIO_CT); | ||
332 | |||
319 | return 0; | 333 | return 0; |
320 | 334 | ||
335 | undo_request_region: | ||
336 | release_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE); | ||
321 | undo_platform_dev_add: | 337 | undo_platform_dev_add: |
322 | platform_device_del(pdev); | 338 | platform_device_del(pdev); |
323 | undo_platform_dev_alloc: | 339 | undo_platform_dev_alloc: |
@@ -328,14 +344,15 @@ undo_platform_dev_alloc: | |||
328 | 344 | ||
329 | static void __exit pc8736x_gpio_cleanup(void) | 345 | static void __exit pc8736x_gpio_cleanup(void) |
330 | { | 346 | { |
331 | dev_dbg(&pdev->dev, " cleanup\n"); | 347 | dev_dbg(&pdev->dev, "cleanup\n"); |
332 | 348 | ||
333 | release_region(pc8736x_gpio_base, 16); | 349 | cdev_del(&pc8736x_gpio_cdev); |
350 | unregister_chrdev_region(MKDEV(major,0), PC8736X_GPIO_CT); | ||
351 | release_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE); | ||
334 | 352 | ||
335 | unregister_chrdev(major, DEVNAME); | 353 | platform_device_del(pdev); |
354 | platform_device_put(pdev); | ||
336 | } | 355 | } |
337 | 356 | ||
338 | EXPORT_SYMBOL(pc8736x_access); | ||
339 | |||
340 | module_init(pc8736x_gpio_init); | 357 | module_init(pc8736x_gpio_init); |
341 | module_exit(pc8736x_gpio_cleanup); | 358 | module_exit(pc8736x_gpio_cleanup); |