diff options
author | Marek Vasut <marek.vasut@gmail.com> | 2009-09-22 19:46:35 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-23 10:39:48 -0400 |
commit | 4cf8e53b3b55fa2f9b2a6b9c3e557b649adf7c6a (patch) | |
tree | 3a3ca1ba8ced694568f7c0ee31c19f7fcc6e38a9 /drivers/gpio/ucb1400_gpio.c | |
parent | 1e5db00687c1ebd93a902caf1d3694209013cb3e (diff) |
mfd/gpio: add a GPIO interface to the UCB1400 MFD chip driver via gpiolib
Cc: Eric Miao <eric.y.miao@gmail.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: David Brownell <david-b@pacbell.net>
Cc: Samuel Ortiz <sameo@openedhand.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/gpio/ucb1400_gpio.c')
-rw-r--r-- | drivers/gpio/ucb1400_gpio.c | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/drivers/gpio/ucb1400_gpio.c b/drivers/gpio/ucb1400_gpio.c new file mode 100644 index 000000000000..50e6bd1392ce --- /dev/null +++ b/drivers/gpio/ucb1400_gpio.c | |||
@@ -0,0 +1,125 @@ | |||
1 | /* | ||
2 | * Philips UCB1400 GPIO driver | ||
3 | * | ||
4 | * Author: Marek Vasut <marek.vasut@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/ucb1400.h> | ||
14 | |||
15 | struct ucb1400_gpio_data *ucbdata; | ||
16 | |||
17 | static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off) | ||
18 | { | ||
19 | struct ucb1400_gpio *gpio; | ||
20 | gpio = container_of(gc, struct ucb1400_gpio, gc); | ||
21 | ucb1400_gpio_set_direction(gpio->ac97, off, 0); | ||
22 | return 0; | ||
23 | } | ||
24 | |||
25 | static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val) | ||
26 | { | ||
27 | struct ucb1400_gpio *gpio; | ||
28 | gpio = container_of(gc, struct ucb1400_gpio, gc); | ||
29 | ucb1400_gpio_set_direction(gpio->ac97, off, 1); | ||
30 | ucb1400_gpio_set_value(gpio->ac97, off, val); | ||
31 | return 0; | ||
32 | } | ||
33 | |||
34 | static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off) | ||
35 | { | ||
36 | struct ucb1400_gpio *gpio; | ||
37 | gpio = container_of(gc, struct ucb1400_gpio, gc); | ||
38 | return ucb1400_gpio_get_value(gpio->ac97, off); | ||
39 | } | ||
40 | |||
41 | static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val) | ||
42 | { | ||
43 | struct ucb1400_gpio *gpio; | ||
44 | gpio = container_of(gc, struct ucb1400_gpio, gc); | ||
45 | ucb1400_gpio_set_value(gpio->ac97, off, val); | ||
46 | } | ||
47 | |||
48 | static int ucb1400_gpio_probe(struct platform_device *dev) | ||
49 | { | ||
50 | struct ucb1400_gpio *ucb = dev->dev.platform_data; | ||
51 | int err = 0; | ||
52 | |||
53 | if (!(ucbdata && ucbdata->gpio_offset)) { | ||
54 | err = -EINVAL; | ||
55 | goto err; | ||
56 | } | ||
57 | |||
58 | platform_set_drvdata(dev, ucb); | ||
59 | |||
60 | ucb->gc.label = "ucb1400_gpio"; | ||
61 | ucb->gc.base = ucbdata->gpio_offset; | ||
62 | ucb->gc.ngpio = 10; | ||
63 | ucb->gc.owner = THIS_MODULE; | ||
64 | |||
65 | ucb->gc.direction_input = ucb1400_gpio_dir_in; | ||
66 | ucb->gc.direction_output = ucb1400_gpio_dir_out; | ||
67 | ucb->gc.get = ucb1400_gpio_get; | ||
68 | ucb->gc.set = ucb1400_gpio_set; | ||
69 | ucb->gc.can_sleep = 1; | ||
70 | |||
71 | err = gpiochip_add(&ucb->gc); | ||
72 | if (err) | ||
73 | goto err; | ||
74 | |||
75 | if (ucbdata && ucbdata->gpio_setup) | ||
76 | err = ucbdata->gpio_setup(&dev->dev, ucb->gc.ngpio); | ||
77 | |||
78 | err: | ||
79 | return err; | ||
80 | |||
81 | } | ||
82 | |||
83 | static int ucb1400_gpio_remove(struct platform_device *dev) | ||
84 | { | ||
85 | int err = 0; | ||
86 | struct ucb1400_gpio *ucb = platform_get_drvdata(dev); | ||
87 | |||
88 | if (ucbdata && ucbdata->gpio_teardown) { | ||
89 | err = ucbdata->gpio_teardown(&dev->dev, ucb->gc.ngpio); | ||
90 | if (err) | ||
91 | return err; | ||
92 | } | ||
93 | |||
94 | err = gpiochip_remove(&ucb->gc); | ||
95 | return err; | ||
96 | } | ||
97 | |||
98 | static struct platform_driver ucb1400_gpio_driver = { | ||
99 | .probe = ucb1400_gpio_probe, | ||
100 | .remove = ucb1400_gpio_remove, | ||
101 | .driver = { | ||
102 | .name = "ucb1400_gpio" | ||
103 | }, | ||
104 | }; | ||
105 | |||
106 | static int __init ucb1400_gpio_init(void) | ||
107 | { | ||
108 | return platform_driver_register(&ucb1400_gpio_driver); | ||
109 | } | ||
110 | |||
111 | static void __exit ucb1400_gpio_exit(void) | ||
112 | { | ||
113 | platform_driver_unregister(&ucb1400_gpio_driver); | ||
114 | } | ||
115 | |||
116 | void __init ucb1400_gpio_set_data(struct ucb1400_gpio_data *data) | ||
117 | { | ||
118 | ucbdata = data; | ||
119 | } | ||
120 | |||
121 | module_init(ucb1400_gpio_init); | ||
122 | module_exit(ucb1400_gpio_exit); | ||
123 | |||
124 | MODULE_DESCRIPTION("Philips UCB1400 GPIO driver"); | ||
125 | MODULE_LICENSE("GPL"); | ||