diff options
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/Kconfig | 13 | ||||
-rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
-rw-r--r-- | drivers/gpio/gpio-da9052.c | 6 | ||||
-rw-r--r-- | drivers/gpio/gpio-tps6586x.c | 9 | ||||
-rw-r--r-- | drivers/gpio/gpio-twl4030.c | 12 | ||||
-rw-r--r-- | drivers/gpio/gpio-viperboard.c | 517 |
6 files changed, 551 insertions, 7 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index bf892bd68c1..8ae1f5b1966 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -683,4 +683,17 @@ config GPIO_MSIC | |||
683 | Enable support for GPIO on intel MSIC controllers found in | 683 | Enable support for GPIO on intel MSIC controllers found in |
684 | intel MID devices | 684 | intel MID devices |
685 | 685 | ||
686 | comment "USB GPIO expanders:" | ||
687 | |||
688 | config GPIO_VIPERBOARD | ||
689 | tristate "Viperboard GPIO a & b support" | ||
690 | depends on MFD_VIPERBOARD && USB | ||
691 | help | ||
692 | Say yes here to access the GPIO signals of Nano River | ||
693 | Technologies Viperboard. There are two GPIO chips on the | ||
694 | board: gpioa and gpiob. | ||
695 | See viperboard API specification and Nano | ||
696 | River Tech's viperboard.h for detailed meaning | ||
697 | of the module parameters. | ||
698 | |||
686 | endif | 699 | endif |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 76b34468325..c5aebd008dd 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -76,6 +76,7 @@ obj-$(CONFIG_GPIO_TS5500) += gpio-ts5500.o | |||
76 | obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o | 76 | obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o |
77 | obj-$(CONFIG_GPIO_TWL6040) += gpio-twl6040.o | 77 | obj-$(CONFIG_GPIO_TWL6040) += gpio-twl6040.o |
78 | obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o | 78 | obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o |
79 | obj-$(CONFIG_GPIO_VIPERBOARD) += gpio-viperboard.o | ||
79 | obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o | 80 | obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o |
80 | obj-$(CONFIG_GPIO_VT8500) += gpio-vt8500.o | 81 | obj-$(CONFIG_GPIO_VT8500) += gpio-vt8500.o |
81 | obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o | 82 | obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o |
diff --git a/drivers/gpio/gpio-da9052.c b/drivers/gpio/gpio-da9052.c index a05aacd2777..29b11e9b6a7 100644 --- a/drivers/gpio/gpio-da9052.c +++ b/drivers/gpio/gpio-da9052.c | |||
@@ -185,7 +185,11 @@ static int da9052_gpio_to_irq(struct gpio_chip *gc, u32 offset) | |||
185 | struct da9052_gpio *gpio = to_da9052_gpio(gc); | 185 | struct da9052_gpio *gpio = to_da9052_gpio(gc); |
186 | struct da9052 *da9052 = gpio->da9052; | 186 | struct da9052 *da9052 = gpio->da9052; |
187 | 187 | ||
188 | return da9052->irq_base + DA9052_IRQ_GPI0 + offset; | 188 | int irq; |
189 | |||
190 | irq = regmap_irq_get_virq(da9052->irq_data, DA9052_IRQ_GPI0 + offset); | ||
191 | |||
192 | return irq; | ||
189 | } | 193 | } |
190 | 194 | ||
191 | static struct gpio_chip reference_gp = { | 195 | static struct gpio_chip reference_gp = { |
diff --git a/drivers/gpio/gpio-tps6586x.c b/drivers/gpio/gpio-tps6586x.c index c1b82da5650..29e8e750bd4 100644 --- a/drivers/gpio/gpio-tps6586x.c +++ b/drivers/gpio/gpio-tps6586x.c | |||
@@ -80,6 +80,14 @@ static int tps6586x_gpio_output(struct gpio_chip *gc, unsigned offset, | |||
80 | val, mask); | 80 | val, mask); |
81 | } | 81 | } |
82 | 82 | ||
83 | static int tps6586x_gpio_to_irq(struct gpio_chip *gc, unsigned offset) | ||
84 | { | ||
85 | struct tps6586x_gpio *tps6586x_gpio = to_tps6586x_gpio(gc); | ||
86 | |||
87 | return tps6586x_irq_get_virq(tps6586x_gpio->parent, | ||
88 | TPS6586X_INT_PLDO_0 + offset); | ||
89 | } | ||
90 | |||
83 | static int tps6586x_gpio_probe(struct platform_device *pdev) | 91 | static int tps6586x_gpio_probe(struct platform_device *pdev) |
84 | { | 92 | { |
85 | struct tps6586x_platform_data *pdata; | 93 | struct tps6586x_platform_data *pdata; |
@@ -106,6 +114,7 @@ static int tps6586x_gpio_probe(struct platform_device *pdev) | |||
106 | tps6586x_gpio->gpio_chip.direction_output = tps6586x_gpio_output; | 114 | tps6586x_gpio->gpio_chip.direction_output = tps6586x_gpio_output; |
107 | tps6586x_gpio->gpio_chip.set = tps6586x_gpio_set; | 115 | tps6586x_gpio->gpio_chip.set = tps6586x_gpio_set; |
108 | tps6586x_gpio->gpio_chip.get = tps6586x_gpio_get; | 116 | tps6586x_gpio->gpio_chip.get = tps6586x_gpio_get; |
117 | tps6586x_gpio->gpio_chip.to_irq = tps6586x_gpio_to_irq; | ||
109 | 118 | ||
110 | #ifdef CONFIG_OF_GPIO | 119 | #ifdef CONFIG_OF_GPIO |
111 | tps6586x_gpio->gpio_chip.of_node = pdev->dev.parent->of_node; | 120 | tps6586x_gpio->gpio_chip.of_node = pdev->dev.parent->of_node; |
diff --git a/drivers/gpio/gpio-twl4030.c b/drivers/gpio/gpio-twl4030.c index 00329f2fc05..9572aa137e6 100644 --- a/drivers/gpio/gpio-twl4030.c +++ b/drivers/gpio/gpio-twl4030.c | |||
@@ -355,13 +355,13 @@ static struct gpio_chip twl_gpiochip = { | |||
355 | 355 | ||
356 | static int gpio_twl4030_pulls(u32 ups, u32 downs) | 356 | static int gpio_twl4030_pulls(u32 ups, u32 downs) |
357 | { | 357 | { |
358 | u8 message[6]; | 358 | u8 message[5]; |
359 | unsigned i, gpio_bit; | 359 | unsigned i, gpio_bit; |
360 | 360 | ||
361 | /* For most pins, a pulldown was enabled by default. | 361 | /* For most pins, a pulldown was enabled by default. |
362 | * We should have data that's specific to this board. | 362 | * We should have data that's specific to this board. |
363 | */ | 363 | */ |
364 | for (gpio_bit = 1, i = 1; i < 6; i++) { | 364 | for (gpio_bit = 1, i = 0; i < 5; i++) { |
365 | u8 bit_mask; | 365 | u8 bit_mask; |
366 | unsigned j; | 366 | unsigned j; |
367 | 367 | ||
@@ -380,16 +380,16 @@ static int gpio_twl4030_pulls(u32 ups, u32 downs) | |||
380 | 380 | ||
381 | static int gpio_twl4030_debounce(u32 debounce, u8 mmc_cd) | 381 | static int gpio_twl4030_debounce(u32 debounce, u8 mmc_cd) |
382 | { | 382 | { |
383 | u8 message[4]; | 383 | u8 message[3]; |
384 | 384 | ||
385 | /* 30 msec of debouncing is always used for MMC card detect, | 385 | /* 30 msec of debouncing is always used for MMC card detect, |
386 | * and is optional for everything else. | 386 | * and is optional for everything else. |
387 | */ | 387 | */ |
388 | message[1] = (debounce & 0xff) | (mmc_cd & 0x03); | 388 | message[0] = (debounce & 0xff) | (mmc_cd & 0x03); |
389 | debounce >>= 8; | 389 | debounce >>= 8; |
390 | message[2] = (debounce & 0xff); | 390 | message[1] = (debounce & 0xff); |
391 | debounce >>= 8; | 391 | debounce >>= 8; |
392 | message[3] = (debounce & 0x03); | 392 | message[2] = (debounce & 0x03); |
393 | 393 | ||
394 | return twl_i2c_write(TWL4030_MODULE_GPIO, message, | 394 | return twl_i2c_write(TWL4030_MODULE_GPIO, message, |
395 | REG_GPIO_DEBEN1, 3); | 395 | REG_GPIO_DEBEN1, 3); |
diff --git a/drivers/gpio/gpio-viperboard.c b/drivers/gpio/gpio-viperboard.c new file mode 100644 index 00000000000..13772996cf2 --- /dev/null +++ b/drivers/gpio/gpio-viperboard.c | |||
@@ -0,0 +1,517 @@ | |||
1 | /* | ||
2 | * Nano River Technologies viperboard GPIO lib driver | ||
3 | * | ||
4 | * (C) 2012 by Lemonage GmbH | ||
5 | * Author: Lars Poeschel <poeschel@lemonage.de> | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/errno.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/types.h> | ||
20 | #include <linux/mutex.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | |||
23 | #include <linux/usb.h> | ||
24 | #include <linux/gpio.h> | ||
25 | |||
26 | #include <linux/mfd/viperboard.h> | ||
27 | |||
28 | #define VPRBRD_GPIOA_CLK_1MHZ 0 | ||
29 | #define VPRBRD_GPIOA_CLK_100KHZ 1 | ||
30 | #define VPRBRD_GPIOA_CLK_10KHZ 2 | ||
31 | #define VPRBRD_GPIOA_CLK_1KHZ 3 | ||
32 | #define VPRBRD_GPIOA_CLK_100HZ 4 | ||
33 | #define VPRBRD_GPIOA_CLK_10HZ 5 | ||
34 | |||
35 | #define VPRBRD_GPIOA_FREQ_DEFAULT 1000 | ||
36 | |||
37 | #define VPRBRD_GPIOA_CMD_CONT 0x00 | ||
38 | #define VPRBRD_GPIOA_CMD_PULSE 0x01 | ||
39 | #define VPRBRD_GPIOA_CMD_PWM 0x02 | ||
40 | #define VPRBRD_GPIOA_CMD_SETOUT 0x03 | ||
41 | #define VPRBRD_GPIOA_CMD_SETIN 0x04 | ||
42 | #define VPRBRD_GPIOA_CMD_SETINT 0x05 | ||
43 | #define VPRBRD_GPIOA_CMD_GETIN 0x06 | ||
44 | |||
45 | #define VPRBRD_GPIOB_CMD_SETDIR 0x00 | ||
46 | #define VPRBRD_GPIOB_CMD_SETVAL 0x01 | ||
47 | |||
48 | struct vprbrd_gpioa_msg { | ||
49 | u8 cmd; | ||
50 | u8 clk; | ||
51 | u8 offset; | ||
52 | u8 t1; | ||
53 | u8 t2; | ||
54 | u8 invert; | ||
55 | u8 pwmlevel; | ||
56 | u8 outval; | ||
57 | u8 risefall; | ||
58 | u8 answer; | ||
59 | u8 __fill; | ||
60 | } __packed; | ||
61 | |||
62 | struct vprbrd_gpiob_msg { | ||
63 | u8 cmd; | ||
64 | u16 val; | ||
65 | u16 mask; | ||
66 | } __packed; | ||
67 | |||
68 | struct vprbrd_gpio { | ||
69 | struct gpio_chip gpioa; /* gpio a related things */ | ||
70 | u32 gpioa_out; | ||
71 | u32 gpioa_val; | ||
72 | struct gpio_chip gpiob; /* gpio b related things */ | ||
73 | u32 gpiob_out; | ||
74 | u32 gpiob_val; | ||
75 | struct vprbrd *vb; | ||
76 | }; | ||
77 | |||
78 | /* gpioa sampling clock module parameter */ | ||
79 | static unsigned char gpioa_clk; | ||
80 | static unsigned int gpioa_freq = VPRBRD_GPIOA_FREQ_DEFAULT; | ||
81 | module_param(gpioa_freq, uint, 0); | ||
82 | MODULE_PARM_DESC(gpioa_freq, | ||
83 | "gpio-a sampling freq in Hz (default is 1000Hz) valid values: 10, 100, 1000, 10000, 100000, 1000000"); | ||
84 | |||
85 | /* ----- begin of gipo a chip -------------------------------------------- */ | ||
86 | |||
87 | static int vprbrd_gpioa_get(struct gpio_chip *chip, | ||
88 | unsigned offset) | ||
89 | { | ||
90 | int ret, answer, error = 0; | ||
91 | struct vprbrd_gpio *gpio = | ||
92 | container_of(chip, struct vprbrd_gpio, gpioa); | ||
93 | struct vprbrd *vb = gpio->vb; | ||
94 | struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; | ||
95 | |||
96 | /* if io is set to output, just return the saved value */ | ||
97 | if (gpio->gpioa_out & (1 << offset)) | ||
98 | return gpio->gpioa_val & (1 << offset); | ||
99 | |||
100 | mutex_lock(&vb->lock); | ||
101 | |||
102 | gamsg->cmd = VPRBRD_GPIOA_CMD_GETIN; | ||
103 | gamsg->clk = 0x00; | ||
104 | gamsg->offset = offset; | ||
105 | gamsg->t1 = 0x00; | ||
106 | gamsg->t2 = 0x00; | ||
107 | gamsg->invert = 0x00; | ||
108 | gamsg->pwmlevel = 0x00; | ||
109 | gamsg->outval = 0x00; | ||
110 | gamsg->risefall = 0x00; | ||
111 | gamsg->answer = 0x00; | ||
112 | gamsg->__fill = 0x00; | ||
113 | |||
114 | ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), | ||
115 | VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_OUT, 0x0000, | ||
116 | 0x0000, gamsg, sizeof(struct vprbrd_gpioa_msg), | ||
117 | VPRBRD_USB_TIMEOUT_MS); | ||
118 | if (ret != sizeof(struct vprbrd_gpioa_msg)) | ||
119 | error = -EREMOTEIO; | ||
120 | |||
121 | ret = usb_control_msg(vb->usb_dev, usb_rcvctrlpipe(vb->usb_dev, 0), | ||
122 | VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_IN, 0x0000, | ||
123 | 0x0000, gamsg, sizeof(struct vprbrd_gpioa_msg), | ||
124 | VPRBRD_USB_TIMEOUT_MS); | ||
125 | answer = gamsg->answer & 0x01; | ||
126 | |||
127 | mutex_unlock(&vb->lock); | ||
128 | |||
129 | if (ret != sizeof(struct vprbrd_gpioa_msg)) | ||
130 | error = -EREMOTEIO; | ||
131 | |||
132 | if (error) | ||
133 | return error; | ||
134 | |||
135 | return answer; | ||
136 | } | ||
137 | |||
138 | static void vprbrd_gpioa_set(struct gpio_chip *chip, | ||
139 | unsigned offset, int value) | ||
140 | { | ||
141 | int ret; | ||
142 | struct vprbrd_gpio *gpio = | ||
143 | container_of(chip, struct vprbrd_gpio, gpioa); | ||
144 | struct vprbrd *vb = gpio->vb; | ||
145 | struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; | ||
146 | |||
147 | if (gpio->gpioa_out & (1 << offset)) { | ||
148 | if (value) | ||
149 | gpio->gpioa_val |= (1 << offset); | ||
150 | else | ||
151 | gpio->gpioa_val &= ~(1 << offset); | ||
152 | |||
153 | mutex_lock(&vb->lock); | ||
154 | |||
155 | gamsg->cmd = VPRBRD_GPIOA_CMD_SETOUT; | ||
156 | gamsg->clk = 0x00; | ||
157 | gamsg->offset = offset; | ||
158 | gamsg->t1 = 0x00; | ||
159 | gamsg->t2 = 0x00; | ||
160 | gamsg->invert = 0x00; | ||
161 | gamsg->pwmlevel = 0x00; | ||
162 | gamsg->outval = value; | ||
163 | gamsg->risefall = 0x00; | ||
164 | gamsg->answer = 0x00; | ||
165 | gamsg->__fill = 0x00; | ||
166 | |||
167 | ret = usb_control_msg(vb->usb_dev, | ||
168 | usb_sndctrlpipe(vb->usb_dev, 0), | ||
169 | VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_OUT, | ||
170 | 0x0000, 0x0000, gamsg, | ||
171 | sizeof(struct vprbrd_gpioa_msg), VPRBRD_USB_TIMEOUT_MS); | ||
172 | |||
173 | mutex_unlock(&vb->lock); | ||
174 | |||
175 | if (ret != sizeof(struct vprbrd_gpioa_msg)) | ||
176 | dev_err(chip->dev, "usb error setting pin value\n"); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | static int vprbrd_gpioa_direction_input(struct gpio_chip *chip, | ||
181 | unsigned offset) | ||
182 | { | ||
183 | int ret; | ||
184 | struct vprbrd_gpio *gpio = | ||
185 | container_of(chip, struct vprbrd_gpio, gpioa); | ||
186 | struct vprbrd *vb = gpio->vb; | ||
187 | struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; | ||
188 | |||
189 | gpio->gpioa_out &= ~(1 << offset); | ||
190 | |||
191 | mutex_lock(&vb->lock); | ||
192 | |||
193 | gamsg->cmd = VPRBRD_GPIOA_CMD_SETIN; | ||
194 | gamsg->clk = gpioa_clk; | ||
195 | gamsg->offset = offset; | ||
196 | gamsg->t1 = 0x00; | ||
197 | gamsg->t2 = 0x00; | ||
198 | gamsg->invert = 0x00; | ||
199 | gamsg->pwmlevel = 0x00; | ||
200 | gamsg->outval = 0x00; | ||
201 | gamsg->risefall = 0x00; | ||
202 | gamsg->answer = 0x00; | ||
203 | gamsg->__fill = 0x00; | ||
204 | |||
205 | ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), | ||
206 | VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_OUT, 0x0000, | ||
207 | 0x0000, gamsg, sizeof(struct vprbrd_gpioa_msg), | ||
208 | VPRBRD_USB_TIMEOUT_MS); | ||
209 | |||
210 | mutex_unlock(&vb->lock); | ||
211 | |||
212 | if (ret != sizeof(struct vprbrd_gpioa_msg)) | ||
213 | return -EREMOTEIO; | ||
214 | |||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | static int vprbrd_gpioa_direction_output(struct gpio_chip *chip, | ||
219 | unsigned offset, int value) | ||
220 | { | ||
221 | int ret; | ||
222 | struct vprbrd_gpio *gpio = | ||
223 | container_of(chip, struct vprbrd_gpio, gpioa); | ||
224 | struct vprbrd *vb = gpio->vb; | ||
225 | struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; | ||
226 | |||
227 | gpio->gpioa_out |= (1 << offset); | ||
228 | if (value) | ||
229 | gpio->gpioa_val |= (1 << offset); | ||
230 | else | ||
231 | gpio->gpioa_val &= ~(1 << offset); | ||
232 | |||
233 | mutex_lock(&vb->lock); | ||
234 | |||
235 | gamsg->cmd = VPRBRD_GPIOA_CMD_SETOUT; | ||
236 | gamsg->clk = 0x00; | ||
237 | gamsg->offset = offset; | ||
238 | gamsg->t1 = 0x00; | ||
239 | gamsg->t2 = 0x00; | ||
240 | gamsg->invert = 0x00; | ||
241 | gamsg->pwmlevel = 0x00; | ||
242 | gamsg->outval = value; | ||
243 | gamsg->risefall = 0x00; | ||
244 | gamsg->answer = 0x00; | ||
245 | gamsg->__fill = 0x00; | ||
246 | |||
247 | ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), | ||
248 | VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_OUT, 0x0000, | ||
249 | 0x0000, gamsg, sizeof(struct vprbrd_gpioa_msg), | ||
250 | VPRBRD_USB_TIMEOUT_MS); | ||
251 | |||
252 | mutex_unlock(&vb->lock); | ||
253 | |||
254 | if (ret != sizeof(struct vprbrd_gpioa_msg)) | ||
255 | return -EREMOTEIO; | ||
256 | |||
257 | return 0; | ||
258 | } | ||
259 | |||
260 | /* ----- end of gpio a chip ---------------------------------------------- */ | ||
261 | |||
262 | /* ----- begin of gipo b chip -------------------------------------------- */ | ||
263 | |||
264 | static int vprbrd_gpiob_setdir(struct vprbrd *vb, unsigned offset, | ||
265 | unsigned dir) | ||
266 | { | ||
267 | struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; | ||
268 | int ret; | ||
269 | |||
270 | gbmsg->cmd = VPRBRD_GPIOB_CMD_SETDIR; | ||
271 | gbmsg->val = cpu_to_be16(dir << offset); | ||
272 | gbmsg->mask = cpu_to_be16(0x0001 << offset); | ||
273 | |||
274 | ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), | ||
275 | VPRBRD_USB_REQUEST_GPIOB, VPRBRD_USB_TYPE_OUT, 0x0000, | ||
276 | 0x0000, gbmsg, sizeof(struct vprbrd_gpiob_msg), | ||
277 | VPRBRD_USB_TIMEOUT_MS); | ||
278 | |||
279 | if (ret != sizeof(struct vprbrd_gpiob_msg)) | ||
280 | return -EREMOTEIO; | ||
281 | |||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | static int vprbrd_gpiob_get(struct gpio_chip *chip, | ||
286 | unsigned offset) | ||
287 | { | ||
288 | int ret; | ||
289 | u16 val; | ||
290 | struct vprbrd_gpio *gpio = | ||
291 | container_of(chip, struct vprbrd_gpio, gpiob); | ||
292 | struct vprbrd *vb = gpio->vb; | ||
293 | struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; | ||
294 | |||
295 | /* if io is set to output, just return the saved value */ | ||
296 | if (gpio->gpiob_out & (1 << offset)) | ||
297 | return gpio->gpiob_val & (1 << offset); | ||
298 | |||
299 | mutex_lock(&vb->lock); | ||
300 | |||
301 | ret = usb_control_msg(vb->usb_dev, usb_rcvctrlpipe(vb->usb_dev, 0), | ||
302 | VPRBRD_USB_REQUEST_GPIOB, VPRBRD_USB_TYPE_IN, 0x0000, | ||
303 | 0x0000, gbmsg, sizeof(struct vprbrd_gpiob_msg), | ||
304 | VPRBRD_USB_TIMEOUT_MS); | ||
305 | val = gbmsg->val; | ||
306 | |||
307 | mutex_unlock(&vb->lock); | ||
308 | |||
309 | if (ret != sizeof(struct vprbrd_gpiob_msg)) | ||
310 | return ret; | ||
311 | |||
312 | /* cache the read values */ | ||
313 | gpio->gpiob_val = be16_to_cpu(val); | ||
314 | |||
315 | return (gpio->gpiob_val >> offset) & 0x1; | ||
316 | } | ||
317 | |||
318 | static void vprbrd_gpiob_set(struct gpio_chip *chip, | ||
319 | unsigned offset, int value) | ||
320 | { | ||
321 | int ret; | ||
322 | struct vprbrd_gpio *gpio = | ||
323 | container_of(chip, struct vprbrd_gpio, gpiob); | ||
324 | struct vprbrd *vb = gpio->vb; | ||
325 | struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; | ||
326 | |||
327 | if (gpio->gpiob_out & (1 << offset)) { | ||
328 | if (value) | ||
329 | gpio->gpiob_val |= (1 << offset); | ||
330 | else | ||
331 | gpio->gpiob_val &= ~(1 << offset); | ||
332 | |||
333 | mutex_lock(&vb->lock); | ||
334 | |||
335 | gbmsg->cmd = VPRBRD_GPIOB_CMD_SETVAL; | ||
336 | gbmsg->val = cpu_to_be16(value << offset); | ||
337 | gbmsg->mask = cpu_to_be16(0x0001 << offset); | ||
338 | |||
339 | ret = usb_control_msg(vb->usb_dev, | ||
340 | usb_sndctrlpipe(vb->usb_dev, 0), | ||
341 | VPRBRD_USB_REQUEST_GPIOB, VPRBRD_USB_TYPE_OUT, | ||
342 | 0x0000, 0x0000, gbmsg, | ||
343 | sizeof(struct vprbrd_gpiob_msg), VPRBRD_USB_TIMEOUT_MS); | ||
344 | |||
345 | mutex_unlock(&vb->lock); | ||
346 | |||
347 | if (ret != sizeof(struct vprbrd_gpiob_msg)) | ||
348 | dev_err(chip->dev, "usb error setting pin value\n"); | ||
349 | } | ||
350 | } | ||
351 | |||
352 | static int vprbrd_gpiob_direction_input(struct gpio_chip *chip, | ||
353 | unsigned offset) | ||
354 | { | ||
355 | int ret; | ||
356 | struct vprbrd_gpio *gpio = | ||
357 | container_of(chip, struct vprbrd_gpio, gpiob); | ||
358 | struct vprbrd *vb = gpio->vb; | ||
359 | |||
360 | gpio->gpiob_out &= ~(1 << offset); | ||
361 | |||
362 | mutex_lock(&vb->lock); | ||
363 | |||
364 | ret = vprbrd_gpiob_setdir(vb, offset, 0); | ||
365 | |||
366 | mutex_unlock(&vb->lock); | ||
367 | |||
368 | if (ret) | ||
369 | dev_err(chip->dev, "usb error setting pin to input\n"); | ||
370 | |||
371 | return ret; | ||
372 | } | ||
373 | |||
374 | static int vprbrd_gpiob_direction_output(struct gpio_chip *chip, | ||
375 | unsigned offset, int value) | ||
376 | { | ||
377 | int ret; | ||
378 | struct vprbrd_gpio *gpio = | ||
379 | container_of(chip, struct vprbrd_gpio, gpiob); | ||
380 | struct vprbrd *vb = gpio->vb; | ||
381 | |||
382 | gpio->gpiob_out |= (1 << offset); | ||
383 | if (value) | ||
384 | gpio->gpiob_val |= (1 << offset); | ||
385 | else | ||
386 | gpio->gpiob_val &= ~(1 << offset); | ||
387 | |||
388 | mutex_lock(&vb->lock); | ||
389 | |||
390 | ret = vprbrd_gpiob_setdir(vb, offset, 1); | ||
391 | if (ret) | ||
392 | dev_err(chip->dev, "usb error setting pin to output\n"); | ||
393 | |||
394 | mutex_unlock(&vb->lock); | ||
395 | |||
396 | vprbrd_gpiob_set(chip, offset, value); | ||
397 | |||
398 | return ret; | ||
399 | } | ||
400 | |||
401 | /* ----- end of gpio b chip ---------------------------------------------- */ | ||
402 | |||
403 | static int __devinit vprbrd_gpio_probe(struct platform_device *pdev) | ||
404 | { | ||
405 | struct vprbrd *vb = dev_get_drvdata(pdev->dev.parent); | ||
406 | struct vprbrd_gpio *vb_gpio; | ||
407 | int ret; | ||
408 | |||
409 | vb_gpio = devm_kzalloc(&pdev->dev, sizeof(*vb_gpio), GFP_KERNEL); | ||
410 | if (vb_gpio == NULL) | ||
411 | return -ENOMEM; | ||
412 | |||
413 | vb_gpio->vb = vb; | ||
414 | /* registering gpio a */ | ||
415 | vb_gpio->gpioa.label = "viperboard gpio a"; | ||
416 | vb_gpio->gpioa.dev = &pdev->dev; | ||
417 | vb_gpio->gpioa.owner = THIS_MODULE; | ||
418 | vb_gpio->gpioa.base = -1; | ||
419 | vb_gpio->gpioa.ngpio = 16; | ||
420 | vb_gpio->gpioa.can_sleep = 1; | ||
421 | vb_gpio->gpioa.set = vprbrd_gpioa_set; | ||
422 | vb_gpio->gpioa.get = vprbrd_gpioa_get; | ||
423 | vb_gpio->gpioa.direction_input = vprbrd_gpioa_direction_input; | ||
424 | vb_gpio->gpioa.direction_output = vprbrd_gpioa_direction_output; | ||
425 | ret = gpiochip_add(&vb_gpio->gpioa); | ||
426 | if (ret < 0) { | ||
427 | dev_err(vb_gpio->gpioa.dev, "could not add gpio a"); | ||
428 | goto err_gpioa; | ||
429 | } | ||
430 | |||
431 | /* registering gpio b */ | ||
432 | vb_gpio->gpiob.label = "viperboard gpio b"; | ||
433 | vb_gpio->gpiob.dev = &pdev->dev; | ||
434 | vb_gpio->gpiob.owner = THIS_MODULE; | ||
435 | vb_gpio->gpiob.base = -1; | ||
436 | vb_gpio->gpiob.ngpio = 16; | ||
437 | vb_gpio->gpiob.can_sleep = 1; | ||
438 | vb_gpio->gpiob.set = vprbrd_gpiob_set; | ||
439 | vb_gpio->gpiob.get = vprbrd_gpiob_get; | ||
440 | vb_gpio->gpiob.direction_input = vprbrd_gpiob_direction_input; | ||
441 | vb_gpio->gpiob.direction_output = vprbrd_gpiob_direction_output; | ||
442 | ret = gpiochip_add(&vb_gpio->gpiob); | ||
443 | if (ret < 0) { | ||
444 | dev_err(vb_gpio->gpiob.dev, "could not add gpio b"); | ||
445 | goto err_gpiob; | ||
446 | } | ||
447 | |||
448 | platform_set_drvdata(pdev, vb_gpio); | ||
449 | |||
450 | return ret; | ||
451 | |||
452 | err_gpiob: | ||
453 | ret = gpiochip_remove(&vb_gpio->gpioa); | ||
454 | |||
455 | err_gpioa: | ||
456 | return ret; | ||
457 | } | ||
458 | |||
459 | static int __devexit vprbrd_gpio_remove(struct platform_device *pdev) | ||
460 | { | ||
461 | struct vprbrd_gpio *vb_gpio = platform_get_drvdata(pdev); | ||
462 | int ret; | ||
463 | |||
464 | ret = gpiochip_remove(&vb_gpio->gpiob); | ||
465 | if (ret == 0) | ||
466 | ret = gpiochip_remove(&vb_gpio->gpioa); | ||
467 | |||
468 | return ret; | ||
469 | } | ||
470 | |||
471 | static struct platform_driver vprbrd_gpio_driver = { | ||
472 | .driver.name = "viperboard-gpio", | ||
473 | .driver.owner = THIS_MODULE, | ||
474 | .probe = vprbrd_gpio_probe, | ||
475 | .remove = __devexit_p(vprbrd_gpio_remove), | ||
476 | }; | ||
477 | |||
478 | static int __init vprbrd_gpio_init(void) | ||
479 | { | ||
480 | switch (gpioa_freq) { | ||
481 | case 1000000: | ||
482 | gpioa_clk = VPRBRD_GPIOA_CLK_1MHZ; | ||
483 | break; | ||
484 | case 100000: | ||
485 | gpioa_clk = VPRBRD_GPIOA_CLK_100KHZ; | ||
486 | break; | ||
487 | case 10000: | ||
488 | gpioa_clk = VPRBRD_GPIOA_CLK_10KHZ; | ||
489 | break; | ||
490 | case 1000: | ||
491 | gpioa_clk = VPRBRD_GPIOA_CLK_1KHZ; | ||
492 | break; | ||
493 | case 100: | ||
494 | gpioa_clk = VPRBRD_GPIOA_CLK_100HZ; | ||
495 | break; | ||
496 | case 10: | ||
497 | gpioa_clk = VPRBRD_GPIOA_CLK_10HZ; | ||
498 | break; | ||
499 | default: | ||
500 | pr_warn("invalid gpioa_freq (%d)\n", gpioa_freq); | ||
501 | gpioa_clk = VPRBRD_GPIOA_CLK_1KHZ; | ||
502 | } | ||
503 | |||
504 | return platform_driver_register(&vprbrd_gpio_driver); | ||
505 | } | ||
506 | subsys_initcall(vprbrd_gpio_init); | ||
507 | |||
508 | static void __exit vprbrd_gpio_exit(void) | ||
509 | { | ||
510 | platform_driver_unregister(&vprbrd_gpio_driver); | ||
511 | } | ||
512 | module_exit(vprbrd_gpio_exit); | ||
513 | |||
514 | MODULE_AUTHOR("Lars Poeschel <poeschel@lemonage.de>"); | ||
515 | MODULE_DESCRIPTION("GPIO driver for Nano River Techs Viperboard"); | ||
516 | MODULE_LICENSE("GPL"); | ||
517 | MODULE_ALIAS("platform:viperboard-gpio"); | ||