diff options
-rw-r--r-- | drivers/gpio/Kconfig | 12 | ||||
-rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
-rw-r--r-- | drivers/gpio/ucb1400_gpio.c | 125 | ||||
-rw-r--r-- | drivers/mfd/ucb1400_core.c | 31 | ||||
-rw-r--r-- | include/linux/ucb1400.h | 19 |
5 files changed, 184 insertions, 4 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 223e7c92fd54..ccca08e0b595 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -202,4 +202,16 @@ config GPIO_MC33880 | |||
202 | SPI driver for Freescale MC33880 high-side/low-side switch. | 202 | SPI driver for Freescale MC33880 high-side/low-side switch. |
203 | This provides GPIO interface supporting inputs and outputs. | 203 | This provides GPIO interface supporting inputs and outputs. |
204 | 204 | ||
205 | comment "AC97 GPIO expanders:" | ||
206 | |||
207 | config GPIO_UCB1400 | ||
208 | bool "Philips UCB1400 GPIO" | ||
209 | depends on UCB1400_CORE | ||
210 | help | ||
211 | This enables support for the Philips UCB1400 GPIO pins. | ||
212 | The UCB1400 is an AC97 audio codec. | ||
213 | |||
214 | To compile this driver as a module, choose M here: the | ||
215 | module will be called ucb1400_gpio. | ||
216 | |||
205 | endif | 217 | endif |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index f35de16c7c49..c1ac034698c5 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -12,6 +12,7 @@ obj-$(CONFIG_GPIO_PCA953X) += pca953x.o | |||
12 | obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o | 12 | obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o |
13 | obj-$(CONFIG_GPIO_PL061) += pl061.o | 13 | obj-$(CONFIG_GPIO_PL061) += pl061.o |
14 | obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o | 14 | obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o |
15 | obj-$(CONFIG_GPIO_UCB1400) += ucb1400_gpio.o | ||
15 | obj-$(CONFIG_GPIO_XILINX) += xilinx_gpio.o | 16 | obj-$(CONFIG_GPIO_XILINX) += xilinx_gpio.o |
16 | obj-$(CONFIG_GPIO_BT8XX) += bt8xxgpio.o | 17 | obj-$(CONFIG_GPIO_BT8XX) += bt8xxgpio.o |
17 | obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o | 18 | obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o |
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"); | ||
diff --git a/drivers/mfd/ucb1400_core.c b/drivers/mfd/ucb1400_core.c index 78c2135c5de6..2afc08006e6d 100644 --- a/drivers/mfd/ucb1400_core.c +++ b/drivers/mfd/ucb1400_core.c | |||
@@ -48,9 +48,11 @@ static int ucb1400_core_probe(struct device *dev) | |||
48 | int err; | 48 | int err; |
49 | struct ucb1400 *ucb; | 49 | struct ucb1400 *ucb; |
50 | struct ucb1400_ts ucb_ts; | 50 | struct ucb1400_ts ucb_ts; |
51 | struct ucb1400_gpio ucb_gpio; | ||
51 | struct snd_ac97 *ac97; | 52 | struct snd_ac97 *ac97; |
52 | 53 | ||
53 | memset(&ucb_ts, 0, sizeof(ucb_ts)); | 54 | memset(&ucb_ts, 0, sizeof(ucb_ts)); |
55 | memset(&ucb_gpio, 0, sizeof(ucb_gpio)); | ||
54 | 56 | ||
55 | ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL); | 57 | ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL); |
56 | if (!ucb) { | 58 | if (!ucb) { |
@@ -68,25 +70,44 @@ static int ucb1400_core_probe(struct device *dev) | |||
68 | goto err0; | 70 | goto err0; |
69 | } | 71 | } |
70 | 72 | ||
73 | /* GPIO */ | ||
74 | ucb_gpio.ac97 = ac97; | ||
75 | ucb->ucb1400_gpio = platform_device_alloc("ucb1400_gpio", -1); | ||
76 | if (!ucb->ucb1400_gpio) { | ||
77 | err = -ENOMEM; | ||
78 | goto err0; | ||
79 | } | ||
80 | err = platform_device_add_data(ucb->ucb1400_gpio, &ucb_gpio, | ||
81 | sizeof(ucb_gpio)); | ||
82 | if (err) | ||
83 | goto err1; | ||
84 | err = platform_device_add(ucb->ucb1400_gpio); | ||
85 | if (err) | ||
86 | goto err1; | ||
87 | |||
71 | /* TOUCHSCREEN */ | 88 | /* TOUCHSCREEN */ |
72 | ucb_ts.ac97 = ac97; | 89 | ucb_ts.ac97 = ac97; |
73 | ucb->ucb1400_ts = platform_device_alloc("ucb1400_ts", -1); | 90 | ucb->ucb1400_ts = platform_device_alloc("ucb1400_ts", -1); |
74 | if (!ucb->ucb1400_ts) { | 91 | if (!ucb->ucb1400_ts) { |
75 | err = -ENOMEM; | 92 | err = -ENOMEM; |
76 | goto err0; | 93 | goto err2; |
77 | } | 94 | } |
78 | err = platform_device_add_data(ucb->ucb1400_ts, &ucb_ts, | 95 | err = platform_device_add_data(ucb->ucb1400_ts, &ucb_ts, |
79 | sizeof(ucb_ts)); | 96 | sizeof(ucb_ts)); |
80 | if (err) | 97 | if (err) |
81 | goto err1; | 98 | goto err3; |
82 | err = platform_device_add(ucb->ucb1400_ts); | 99 | err = platform_device_add(ucb->ucb1400_ts); |
83 | if (err) | 100 | if (err) |
84 | goto err1; | 101 | goto err3; |
85 | 102 | ||
86 | return 0; | 103 | return 0; |
87 | 104 | ||
88 | err1: | 105 | err3: |
89 | platform_device_put(ucb->ucb1400_ts); | 106 | platform_device_put(ucb->ucb1400_ts); |
107 | err2: | ||
108 | platform_device_unregister(ucb->ucb1400_gpio); | ||
109 | err1: | ||
110 | platform_device_put(ucb->ucb1400_gpio); | ||
90 | err0: | 111 | err0: |
91 | kfree(ucb); | 112 | kfree(ucb); |
92 | err: | 113 | err: |
@@ -98,6 +119,8 @@ static int ucb1400_core_remove(struct device *dev) | |||
98 | struct ucb1400 *ucb = dev_get_drvdata(dev); | 119 | struct ucb1400 *ucb = dev_get_drvdata(dev); |
99 | 120 | ||
100 | platform_device_unregister(ucb->ucb1400_ts); | 121 | platform_device_unregister(ucb->ucb1400_ts); |
122 | platform_device_unregister(ucb->ucb1400_gpio); | ||
123 | |||
101 | kfree(ucb); | 124 | kfree(ucb); |
102 | return 0; | 125 | return 0; |
103 | } | 126 | } |
diff --git a/include/linux/ucb1400.h b/include/linux/ucb1400.h index ae779bb8cc0f..adb44066680c 100644 --- a/include/linux/ucb1400.h +++ b/include/linux/ucb1400.h | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <sound/ac97_codec.h> | 26 | #include <sound/ac97_codec.h> |
27 | #include <linux/mutex.h> | 27 | #include <linux/mutex.h> |
28 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
29 | #include <linux/gpio.h> | ||
29 | 30 | ||
30 | /* | 31 | /* |
31 | * UCB1400 AC-link registers | 32 | * UCB1400 AC-link registers |
@@ -82,6 +83,17 @@ | |||
82 | #define UCB_ID 0x7e | 83 | #define UCB_ID 0x7e |
83 | #define UCB_ID_1400 0x4304 | 84 | #define UCB_ID_1400 0x4304 |
84 | 85 | ||
86 | struct ucb1400_gpio_data { | ||
87 | int gpio_offset; | ||
88 | int (*gpio_setup)(struct device *dev, int ngpio); | ||
89 | int (*gpio_teardown)(struct device *dev, int ngpio); | ||
90 | }; | ||
91 | |||
92 | struct ucb1400_gpio { | ||
93 | struct gpio_chip gc; | ||
94 | struct snd_ac97 *ac97; | ||
95 | }; | ||
96 | |||
85 | struct ucb1400_ts { | 97 | struct ucb1400_ts { |
86 | struct input_dev *ts_idev; | 98 | struct input_dev *ts_idev; |
87 | struct task_struct *ts_task; | 99 | struct task_struct *ts_task; |
@@ -95,6 +107,7 @@ struct ucb1400_ts { | |||
95 | 107 | ||
96 | struct ucb1400 { | 108 | struct ucb1400 { |
97 | struct platform_device *ucb1400_ts; | 109 | struct platform_device *ucb1400_ts; |
110 | struct platform_device *ucb1400_gpio; | ||
98 | }; | 111 | }; |
99 | 112 | ||
100 | static inline u16 ucb1400_reg_read(struct snd_ac97 *ac97, u16 reg) | 113 | static inline u16 ucb1400_reg_read(struct snd_ac97 *ac97, u16 reg) |
@@ -147,4 +160,10 @@ static inline void ucb1400_adc_disable(struct snd_ac97 *ac97) | |||
147 | unsigned int ucb1400_adc_read(struct snd_ac97 *ac97, u16 adc_channel, | 160 | unsigned int ucb1400_adc_read(struct snd_ac97 *ac97, u16 adc_channel, |
148 | int adcsync); | 161 | int adcsync); |
149 | 162 | ||
163 | #ifdef CONFIG_GPIO_UCB1400 | ||
164 | void __init ucb1400_gpio_set_data(struct ucb1400_gpio_data *data); | ||
165 | #else | ||
166 | static inline void ucb1400_gpio_set_data(struct ucb1400_gpio_data *data) {} | ||
167 | #endif | ||
168 | |||
150 | #endif | 169 | #endif |