diff options
Diffstat (limited to 'drivers/char/pc8736x_gpio.c')
-rw-r--r-- | drivers/char/pc8736x_gpio.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c index c860de6a6fde..84e5a68635f1 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,14 +212,12 @@ 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 | }; |
@@ -227,16 +225,16 @@ static struct nsc_gpio_ops pc8736x_access = { | |||
227 | static int pc8736x_gpio_open(struct inode *inode, struct file *file) | 225 | static int pc8736x_gpio_open(struct inode *inode, struct file *file) |
228 | { | 226 | { |
229 | unsigned m = iminor(inode); | 227 | unsigned m = iminor(inode); |
230 | file->private_data = &pc8736x_access; | 228 | file->private_data = &pc8736x_gpio_ops; |
231 | 229 | ||
232 | dev_dbg(&pdev->dev, "open %d\n", m); | 230 | dev_dbg(&pdev->dev, "open %d\n", m); |
233 | 231 | ||
234 | if (m > 63) | 232 | if (m >= PC8736X_GPIO_CT) |
235 | return -EINVAL; | 233 | return -EINVAL; |
236 | return nonseekable_open(inode, file); | 234 | return nonseekable_open(inode, file); |
237 | } | 235 | } |
238 | 236 | ||
239 | static struct file_operations pc8736x_gpio_fops = { | 237 | static const struct file_operations pc8736x_gpio_fileops = { |
240 | .owner = THIS_MODULE, | 238 | .owner = THIS_MODULE, |
241 | .open = pc8736x_gpio_open, | 239 | .open = pc8736x_gpio_open, |
242 | .write = nsc_gpio_write, | 240 | .write = nsc_gpio_write, |
@@ -255,9 +253,12 @@ static void __init pc8736x_init_shadow(void) | |||
255 | 253 | ||
256 | } | 254 | } |
257 | 255 | ||
256 | static struct cdev pc8736x_gpio_cdev; | ||
257 | |||
258 | static int __init pc8736x_gpio_init(void) | 258 | static int __init pc8736x_gpio_init(void) |
259 | { | 259 | { |
260 | int rc = 0; | 260 | int rc; |
261 | dev_t devid; | ||
261 | 262 | ||
262 | pdev = platform_device_alloc(DEVNAME, 0); | 263 | pdev = platform_device_alloc(DEVNAME, 0); |
263 | if (!pdev) | 264 | if (!pdev) |
@@ -275,7 +276,7 @@ static int __init pc8736x_gpio_init(void) | |||
275 | dev_err(&pdev->dev, "no device found\n"); | 276 | dev_err(&pdev->dev, "no device found\n"); |
276 | goto undo_platform_dev_add; | 277 | goto undo_platform_dev_add; |
277 | } | 278 | } |
278 | pc8736x_access.dev = &pdev->dev; | 279 | pc8736x_gpio_ops.dev = &pdev->dev; |
279 | 280 | ||
280 | /* Verify that chip and it's GPIO unit are both enabled. | 281 | /* Verify that chip and it's GPIO unit are both enabled. |
281 | My BIOS does this, so I take minimum action here | 282 | My BIOS does this, so I take minimum action here |
@@ -297,7 +298,7 @@ static int __init pc8736x_gpio_init(void) | |||
297 | pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8 | 298 | pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8 |
298 | | superio_inb(SIO_BASE_LADDR)); | 299 | | superio_inb(SIO_BASE_LADDR)); |
299 | 300 | ||
300 | if (!request_region(pc8736x_gpio_base, 16, DEVNAME)) { | 301 | if (!request_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE, DEVNAME)) { |
301 | rc = -ENODEV; | 302 | rc = -ENODEV; |
302 | dev_err(&pdev->dev, "GPIO ioport %x busy\n", | 303 | dev_err(&pdev->dev, "GPIO ioport %x busy\n", |
303 | pc8736x_gpio_base); | 304 | pc8736x_gpio_base); |
@@ -305,10 +306,17 @@ static int __init pc8736x_gpio_init(void) | |||
305 | } | 306 | } |
306 | dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base); | 307 | dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base); |
307 | 308 | ||
308 | rc = register_chrdev(major, DEVNAME, &pc8736x_gpio_fops); | 309 | if (major) { |
310 | devid = MKDEV(major, 0); | ||
311 | rc = register_chrdev_region(devid, PC8736X_GPIO_CT, DEVNAME); | ||
312 | } else { | ||
313 | rc = alloc_chrdev_region(&devid, 0, PC8736X_GPIO_CT, DEVNAME); | ||
314 | major = MAJOR(devid); | ||
315 | } | ||
316 | |||
309 | if (rc < 0) { | 317 | if (rc < 0) { |
310 | dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc); | 318 | dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc); |
311 | goto undo_platform_dev_add; | 319 | goto undo_request_region; |
312 | } | 320 | } |
313 | if (!major) { | 321 | if (!major) { |
314 | major = rc; | 322 | major = rc; |
@@ -316,8 +324,15 @@ static int __init pc8736x_gpio_init(void) | |||
316 | } | 324 | } |
317 | 325 | ||
318 | pc8736x_init_shadow(); | 326 | pc8736x_init_shadow(); |
327 | |||
328 | /* ignore minor errs, and succeed */ | ||
329 | cdev_init(&pc8736x_gpio_cdev, &pc8736x_gpio_fileops); | ||
330 | cdev_add(&pc8736x_gpio_cdev, devid, PC8736X_GPIO_CT); | ||
331 | |||
319 | return 0; | 332 | return 0; |
320 | 333 | ||
334 | undo_request_region: | ||
335 | release_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE); | ||
321 | undo_platform_dev_add: | 336 | undo_platform_dev_add: |
322 | platform_device_del(pdev); | 337 | platform_device_del(pdev); |
323 | undo_platform_dev_alloc: | 338 | undo_platform_dev_alloc: |
@@ -328,14 +343,15 @@ undo_platform_dev_alloc: | |||
328 | 343 | ||
329 | static void __exit pc8736x_gpio_cleanup(void) | 344 | static void __exit pc8736x_gpio_cleanup(void) |
330 | { | 345 | { |
331 | dev_dbg(&pdev->dev, " cleanup\n"); | 346 | dev_dbg(&pdev->dev, "cleanup\n"); |
332 | 347 | ||
333 | release_region(pc8736x_gpio_base, 16); | 348 | cdev_del(&pc8736x_gpio_cdev); |
349 | unregister_chrdev_region(MKDEV(major,0), PC8736X_GPIO_CT); | ||
350 | release_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE); | ||
334 | 351 | ||
335 | unregister_chrdev(major, DEVNAME); | 352 | platform_device_del(pdev); |
353 | platform_device_put(pdev); | ||
336 | } | 354 | } |
337 | 355 | ||
338 | EXPORT_SYMBOL(pc8736x_access); | ||
339 | |||
340 | module_init(pc8736x_gpio_init); | 356 | module_init(pc8736x_gpio_init); |
341 | module_exit(pc8736x_gpio_cleanup); | 357 | module_exit(pc8736x_gpio_cleanup); |