pxa2x0_gpio.c revision 1.19 1 1.19 thorpej /* $NetBSD: pxa2x0_gpio.c,v 1.19 2020/11/20 18:49:45 thorpej Exp $ */
2 1.1 scw
3 1.1 scw /*
4 1.1 scw * Copyright 2003 Wasabi Systems, Inc.
5 1.1 scw * All rights reserved.
6 1.1 scw *
7 1.1 scw * Written by Steve C. Woodford for Wasabi Systems, Inc.
8 1.1 scw *
9 1.1 scw * Redistribution and use in source and binary forms, with or without
10 1.1 scw * modification, are permitted provided that the following conditions
11 1.1 scw * are met:
12 1.1 scw * 1. Redistributions of source code must retain the above copyright
13 1.1 scw * notice, this list of conditions and the following disclaimer.
14 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 scw * notice, this list of conditions and the following disclaimer in the
16 1.1 scw * documentation and/or other materials provided with the distribution.
17 1.1 scw * 3. All advertising materials mentioning features or use of this software
18 1.1 scw * must display the following acknowledgement:
19 1.1 scw * This product includes software developed for the NetBSD Project by
20 1.1 scw * Wasabi Systems, Inc.
21 1.1 scw * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 scw * or promote products derived from this software without specific prior
23 1.1 scw * written permission.
24 1.1 scw *
25 1.1 scw * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 scw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 scw * POSSIBILITY OF SUCH DAMAGE.
36 1.1 scw */
37 1.2 lukem
38 1.2 lukem #include <sys/cdefs.h>
39 1.19 thorpej __KERNEL_RCSID(0, "$NetBSD: pxa2x0_gpio.c,v 1.19 2020/11/20 18:49:45 thorpej Exp $");
40 1.1 scw
41 1.17 pgoyette #include "gpio.h"
42 1.1 scw #include "opt_pxa2x0_gpio.h"
43 1.1 scw
44 1.1 scw #include <sys/param.h>
45 1.1 scw #include <sys/systm.h>
46 1.1 scw #include <sys/device.h>
47 1.19 thorpej #include <sys/kmem.h>
48 1.1 scw
49 1.1 scw #include <machine/intr.h>
50 1.15 dyoung #include <sys/bus.h>
51 1.1 scw
52 1.3 bsh #include <arm/xscale/pxa2x0cpu.h>
53 1.1 scw #include <arm/xscale/pxa2x0reg.h>
54 1.1 scw #include <arm/xscale/pxa2x0var.h>
55 1.1 scw #include <arm/xscale/pxa2x0_gpio.h>
56 1.1 scw
57 1.1 scw #include "locators.h"
58 1.1 scw
59 1.17 pgoyette #include <sys/gpio.h>
60 1.17 pgoyette #include <dev/gpio/gpiovar.h>
61 1.17 pgoyette
62 1.1 scw struct gpio_irq_handler {
63 1.6 ober struct gpio_irq_handler *gh_next;
64 1.1 scw int (*gh_func)(void *);
65 1.1 scw void *gh_arg;
66 1.1 scw int gh_spl;
67 1.1 scw u_int gh_gpio;
68 1.6 ober int gh_level;
69 1.1 scw };
70 1.1 scw
71 1.1 scw struct pxagpio_softc {
72 1.14 nonaka device_t sc_dev;
73 1.1 scw bus_space_tag_t sc_bust;
74 1.1 scw bus_space_handle_t sc_bush;
75 1.3 bsh void *sc_irqcookie[4];
76 1.16 skrll uint32_t sc_mask[4];
77 1.1 scw #ifdef PXAGPIO_HAS_GPION_INTRS
78 1.1 scw struct gpio_irq_handler *sc_handlers[GPIO_NPINS];
79 1.1 scw #else
80 1.1 scw struct gpio_irq_handler *sc_handlers[2];
81 1.1 scw #endif
82 1.17 pgoyette struct gpio_chipset_tag sc_gpio_gc;
83 1.17 pgoyette gpio_pin_t sc_gpio_pins[GPIO_NPINS];
84 1.1 scw };
85 1.1 scw
86 1.14 nonaka static int pxagpio_match(device_t, cfdata_t, void *);
87 1.14 nonaka static void pxagpio_attach(device_t, device_t, void *);
88 1.1 scw
89 1.17 pgoyette #if NGPIO > 0
90 1.17 pgoyette static int pxa2x0_gpio_pin_read(void *, int);
91 1.17 pgoyette static void pxa2x0_gpio_pin_write(void *, int, int);
92 1.17 pgoyette static void pxa2x0_gpio_pin_ctl(void *, int, int);
93 1.17 pgoyette #endif
94 1.17 pgoyette
95 1.14 nonaka CFATTACH_DECL_NEW(pxagpio, sizeof(struct pxagpio_softc),
96 1.1 scw pxagpio_match, pxagpio_attach, NULL, NULL);
97 1.1 scw
98 1.1 scw static struct pxagpio_softc *pxagpio_softc;
99 1.1 scw static vaddr_t pxagpio_regs;
100 1.1 scw #define GPIO_BOOTSTRAP_REG(reg) \
101 1.16 skrll (*((volatile uint32_t *)(pxagpio_regs + (reg))))
102 1.1 scw
103 1.1 scw static int gpio_intr0(void *);
104 1.1 scw static int gpio_intr1(void *);
105 1.1 scw #ifdef PXAGPIO_HAS_GPION_INTRS
106 1.1 scw static int gpio_dispatch(struct pxagpio_softc *, int);
107 1.1 scw static int gpio_intrN(void *);
108 1.1 scw #endif
109 1.1 scw
110 1.16 skrll static inline uint32_t
111 1.1 scw pxagpio_reg_read(struct pxagpio_softc *sc, int reg)
112 1.1 scw {
113 1.1 scw if (__predict_true(sc != NULL))
114 1.1 scw return (bus_space_read_4(sc->sc_bust, sc->sc_bush, reg));
115 1.1 scw else
116 1.1 scw if (pxagpio_regs)
117 1.1 scw return (GPIO_BOOTSTRAP_REG(reg));
118 1.1 scw panic("pxagpio_reg_read: not bootstrapped");
119 1.1 scw }
120 1.1 scw
121 1.5 perry static inline void
122 1.16 skrll pxagpio_reg_write(struct pxagpio_softc *sc, int reg, uint32_t val)
123 1.1 scw {
124 1.1 scw if (__predict_true(sc != NULL))
125 1.1 scw bus_space_write_4(sc->sc_bust, sc->sc_bush, reg, val);
126 1.1 scw else
127 1.1 scw if (pxagpio_regs)
128 1.1 scw GPIO_BOOTSTRAP_REG(reg) = val;
129 1.1 scw else
130 1.1 scw panic("pxagpio_reg_write: not bootstrapped");
131 1.1 scw return;
132 1.1 scw }
133 1.1 scw
134 1.1 scw static int
135 1.14 nonaka pxagpio_match(device_t parent, cfdata_t cf, void *aux)
136 1.1 scw {
137 1.1 scw struct pxaip_attach_args *pxa = aux;
138 1.1 scw
139 1.1 scw if (pxagpio_softc != NULL || pxa->pxa_addr != PXA2X0_GPIO_BASE)
140 1.1 scw return (0);
141 1.1 scw
142 1.1 scw pxa->pxa_size = PXA2X0_GPIO_SIZE;
143 1.1 scw
144 1.1 scw return (1);
145 1.1 scw }
146 1.1 scw
147 1.7 peter static void
148 1.14 nonaka pxagpio_attach(device_t parent, device_t self, void *aux)
149 1.1 scw {
150 1.14 nonaka struct pxagpio_softc *sc = device_private(self);
151 1.1 scw struct pxaip_attach_args *pxa = aux;
152 1.17 pgoyette #if NGPIO > 0
153 1.17 pgoyette struct gpiobus_attach_args gba;
154 1.17 pgoyette int pin, maxpin;
155 1.17 pgoyette u_int func;
156 1.17 pgoyette #endif
157 1.1 scw
158 1.14 nonaka sc->sc_dev = self;
159 1.1 scw sc->sc_bust = pxa->pxa_iot;
160 1.1 scw
161 1.1 scw aprint_normal(": GPIO Controller\n");
162 1.1 scw
163 1.1 scw if (bus_space_map(sc->sc_bust, pxa->pxa_addr, pxa->pxa_size, 0,
164 1.1 scw &sc->sc_bush)) {
165 1.14 nonaka aprint_error_dev(self, "Can't map registers!\n");
166 1.1 scw return;
167 1.1 scw }
168 1.1 scw
169 1.3 bsh pxagpio_regs = (vaddr_t)bus_space_vaddr(sc->sc_bust, sc->sc_bush);
170 1.3 bsh
171 1.1 scw memset(sc->sc_handlers, 0, sizeof(sc->sc_handlers));
172 1.1 scw
173 1.1 scw /*
174 1.1 scw * Disable all GPIO interrupts
175 1.1 scw */
176 1.1 scw pxagpio_reg_write(sc, GPIO_GRER0, 0);
177 1.1 scw pxagpio_reg_write(sc, GPIO_GRER1, 0);
178 1.1 scw pxagpio_reg_write(sc, GPIO_GRER2, 0);
179 1.1 scw pxagpio_reg_write(sc, GPIO_GFER0, 0);
180 1.1 scw pxagpio_reg_write(sc, GPIO_GFER1, 0);
181 1.1 scw pxagpio_reg_write(sc, GPIO_GFER2, 0);
182 1.1 scw pxagpio_reg_write(sc, GPIO_GEDR0, ~0);
183 1.1 scw pxagpio_reg_write(sc, GPIO_GEDR1, ~0);
184 1.1 scw pxagpio_reg_write(sc, GPIO_GEDR2, ~0);
185 1.3 bsh #ifdef CPU_XSCALE_PXA270
186 1.3 bsh if (CPU_IS_PXA270) {
187 1.3 bsh pxagpio_reg_write(sc, GPIO_GRER3, 0);
188 1.3 bsh pxagpio_reg_write(sc, GPIO_GFER3, 0);
189 1.3 bsh pxagpio_reg_write(sc, GPIO_GEDR3, ~0);
190 1.3 bsh }
191 1.3 bsh #endif
192 1.1 scw
193 1.1 scw #ifdef PXAGPIO_HAS_GPION_INTRS
194 1.1 scw sc->sc_irqcookie[2] = pxa2x0_intr_establish(PXA2X0_INT_GPION, IPL_BIO,
195 1.1 scw gpio_intrN, sc);
196 1.1 scw if (sc->sc_irqcookie[2] == NULL) {
197 1.14 nonaka aprint_error_dev(self, "failed to hook main GPIO interrupt\n");
198 1.1 scw return;
199 1.1 scw }
200 1.1 scw #endif
201 1.1 scw
202 1.1 scw sc->sc_irqcookie[0] = sc->sc_irqcookie[1] = NULL;
203 1.1 scw
204 1.1 scw pxagpio_softc = sc;
205 1.17 pgoyette #if NGPIO > 0
206 1.17 pgoyette #if defined(CPU_XSCALE_PXA250) && defined(CPU_XSCALE_PXA270)
207 1.17 pgoyette maxpin = CPU_IS_PXA270 ? PXA270_GPIO_NPINS : PXA250_GPIO_NPINS;
208 1.17 pgoyette #else
209 1.17 pgoyette maxpin = GPIO_NPINS;
210 1.17 pgoyette #endif
211 1.17 pgoyette for (pin = 0; pin < maxpin; ++pin) {
212 1.17 pgoyette
213 1.17 pgoyette sc->sc_gpio_pins[pin].pin_num = pin;
214 1.17 pgoyette func = pxa2x0_gpio_get_function(pin);
215 1.17 pgoyette
216 1.17 pgoyette if (GPIO_IS_GPIO(func)) {
217 1.17 pgoyette sc->sc_gpio_pins[pin].pin_caps = GPIO_PIN_INPUT |
218 1.17 pgoyette GPIO_PIN_OUTPUT;
219 1.17 pgoyette sc->sc_gpio_pins[pin].pin_state =
220 1.17 pgoyette pxa2x0_gpio_pin_read(sc, pin);
221 1.17 pgoyette } else {
222 1.17 pgoyette sc->sc_gpio_pins[pin].pin_caps = 0;
223 1.17 pgoyette sc->sc_gpio_pins[pin].pin_state = 0;
224 1.17 pgoyette }
225 1.17 pgoyette }
226 1.17 pgoyette
227 1.17 pgoyette /* create controller tag */
228 1.17 pgoyette sc->sc_gpio_gc.gp_cookie = sc;
229 1.17 pgoyette sc->sc_gpio_gc.gp_pin_read = pxa2x0_gpio_pin_read;
230 1.17 pgoyette sc->sc_gpio_gc.gp_pin_write = pxa2x0_gpio_pin_write;
231 1.17 pgoyette sc->sc_gpio_gc.gp_pin_ctl = pxa2x0_gpio_pin_ctl;
232 1.17 pgoyette
233 1.17 pgoyette gba.gba_gc = &sc->sc_gpio_gc;
234 1.17 pgoyette gba.gba_pins = sc->sc_gpio_pins;
235 1.17 pgoyette gba.gba_npins = maxpin;
236 1.17 pgoyette
237 1.17 pgoyette config_found_ia(self, "gpiobus", &gba, gpiobus_print);
238 1.17 pgoyette #else
239 1.17 pgoyette aprint_normal_dev(sc->sc_dev, "no GPIO configured in kernel\n");
240 1.17 pgoyette #endif
241 1.1 scw }
242 1.1 scw
243 1.1 scw void
244 1.1 scw pxa2x0_gpio_bootstrap(vaddr_t gpio_regs)
245 1.1 scw {
246 1.1 scw
247 1.1 scw pxagpio_regs = gpio_regs;
248 1.1 scw }
249 1.1 scw
250 1.1 scw void *
251 1.1 scw pxa2x0_gpio_intr_establish(u_int gpio, int level, int spl, int (*func)(void *),
252 1.1 scw void *arg)
253 1.1 scw {
254 1.1 scw struct pxagpio_softc *sc = pxagpio_softc;
255 1.1 scw struct gpio_irq_handler *gh;
256 1.16 skrll uint32_t bit, reg;
257 1.1 scw
258 1.1 scw #ifdef PXAGPIO_HAS_GPION_INTRS
259 1.1 scw if (gpio >= GPIO_NPINS)
260 1.1 scw panic("pxa2x0_gpio_intr_establish: bad pin number: %d", gpio);
261 1.1 scw #else
262 1.1 scw if (gpio > 1)
263 1.1 scw panic("pxa2x0_gpio_intr_establish: bad pin number: %d", gpio);
264 1.1 scw #endif
265 1.1 scw
266 1.1 scw if (!GPIO_IS_GPIO_IN(pxa2x0_gpio_get_function(gpio)))
267 1.1 scw panic("pxa2x0_gpio_intr_establish: Pin %d not GPIO_IN", gpio);
268 1.1 scw
269 1.1 scw switch (level) {
270 1.1 scw case IST_EDGE_FALLING:
271 1.1 scw case IST_EDGE_RISING:
272 1.1 scw case IST_EDGE_BOTH:
273 1.1 scw break;
274 1.1 scw
275 1.1 scw default:
276 1.1 scw panic("pxa2x0_gpio_intr_establish: bad level: %d", level);
277 1.1 scw break;
278 1.1 scw }
279 1.1 scw
280 1.1 scw if (sc->sc_handlers[gpio] != NULL)
281 1.1 scw panic("pxa2x0_gpio_intr_establish: illegal shared interrupt");
282 1.1 scw
283 1.19 thorpej gh = kmem_alloc(sizeof(*gh), KM_SLEEP);
284 1.1 scw gh->gh_func = func;
285 1.1 scw gh->gh_arg = arg;
286 1.1 scw gh->gh_spl = spl;
287 1.1 scw gh->gh_gpio = gpio;
288 1.6 ober gh->gh_level = level;
289 1.6 ober gh->gh_next = sc->sc_handlers[gpio];
290 1.1 scw sc->sc_handlers[gpio] = gh;
291 1.1 scw
292 1.1 scw if (gpio == 0) {
293 1.1 scw KDASSERT(sc->sc_irqcookie[0] == NULL);
294 1.1 scw sc->sc_irqcookie[0] = pxa2x0_intr_establish(PXA2X0_INT_GPIO0,
295 1.1 scw spl, gpio_intr0, sc);
296 1.1 scw KDASSERT(sc->sc_irqcookie[0]);
297 1.1 scw } else
298 1.1 scw if (gpio == 1) {
299 1.1 scw KDASSERT(sc->sc_irqcookie[1] == NULL);
300 1.1 scw sc->sc_irqcookie[1] = pxa2x0_intr_establish(PXA2X0_INT_GPIO1,
301 1.1 scw spl, gpio_intr1, sc);
302 1.1 scw KDASSERT(sc->sc_irqcookie[1]);
303 1.1 scw }
304 1.1 scw
305 1.1 scw bit = GPIO_BIT(gpio);
306 1.1 scw sc->sc_mask[GPIO_BANK(gpio)] |= bit;
307 1.1 scw
308 1.1 scw switch (level) {
309 1.1 scw case IST_EDGE_FALLING:
310 1.1 scw reg = pxagpio_reg_read(sc, GPIO_REG(GPIO_GFER0, gpio));
311 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GFER0, gpio), reg | bit);
312 1.1 scw break;
313 1.1 scw
314 1.1 scw case IST_EDGE_RISING:
315 1.1 scw reg = pxagpio_reg_read(sc, GPIO_REG(GPIO_GRER0, gpio));
316 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GRER0, gpio), reg | bit);
317 1.1 scw break;
318 1.1 scw
319 1.1 scw case IST_EDGE_BOTH:
320 1.1 scw reg = pxagpio_reg_read(sc, GPIO_REG(GPIO_GFER0, gpio));
321 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GFER0, gpio), reg | bit);
322 1.1 scw reg = pxagpio_reg_read(sc, GPIO_REG(GPIO_GRER0, gpio));
323 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GRER0, gpio), reg | bit);
324 1.1 scw break;
325 1.1 scw }
326 1.1 scw
327 1.1 scw return (gh);
328 1.1 scw }
329 1.1 scw
330 1.1 scw void
331 1.1 scw pxa2x0_gpio_intr_disestablish(void *cookie)
332 1.1 scw {
333 1.1 scw struct pxagpio_softc *sc = pxagpio_softc;
334 1.1 scw struct gpio_irq_handler *gh = cookie;
335 1.16 skrll uint32_t bit, reg;
336 1.1 scw
337 1.1 scw bit = GPIO_BIT(gh->gh_gpio);
338 1.1 scw
339 1.1 scw reg = pxagpio_reg_read(sc, GPIO_REG(GPIO_GFER0, gh->gh_gpio));
340 1.1 scw reg &= ~bit;
341 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GFER0, gh->gh_gpio), reg);
342 1.1 scw reg = pxagpio_reg_read(sc, GPIO_REG(GPIO_GRER0, gh->gh_gpio));
343 1.1 scw reg &= ~bit;
344 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GRER0, gh->gh_gpio), reg);
345 1.1 scw
346 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GEDR0, gh->gh_gpio), bit);
347 1.1 scw
348 1.1 scw sc->sc_mask[GPIO_BANK(gh->gh_gpio)] &= ~bit;
349 1.1 scw sc->sc_handlers[gh->gh_gpio] = NULL;
350 1.1 scw
351 1.1 scw if (gh->gh_gpio == 0) {
352 1.1 scw #if 0
353 1.1 scw pxa2x0_intr_disestablish(sc->sc_irqcookie[0]);
354 1.1 scw sc->sc_irqcookie[0] = NULL;
355 1.1 scw #else
356 1.1 scw panic("pxa2x0_gpio_intr_disestablish: can't unhook GPIO#0");
357 1.1 scw #endif
358 1.1 scw } else
359 1.1 scw if (gh->gh_gpio == 1) {
360 1.1 scw #if 0
361 1.1 scw pxa2x0_intr_disestablish(sc->sc_irqcookie[1]);
362 1.10 nonaka sc->sc_irqcookie[1] = NULL;
363 1.1 scw #else
364 1.10 nonaka panic("pxa2x0_gpio_intr_disestablish: can't unhook GPIO#1");
365 1.1 scw #endif
366 1.1 scw }
367 1.1 scw
368 1.19 thorpej kmem_free(gh, sizeof(*gh));
369 1.1 scw }
370 1.1 scw
371 1.1 scw static int
372 1.1 scw gpio_intr0(void *arg)
373 1.1 scw {
374 1.1 scw struct pxagpio_softc *sc = arg;
375 1.1 scw
376 1.1 scw #ifdef DIAGNOSTIC
377 1.1 scw if (sc->sc_handlers[0] == NULL) {
378 1.14 nonaka aprint_error_dev(sc->sc_dev, "stray GPIO#0 edge interrupt\n");
379 1.1 scw return (0);
380 1.1 scw }
381 1.1 scw #endif
382 1.1 scw
383 1.1 scw bus_space_write_4(sc->sc_bust, sc->sc_bush, GPIO_REG(GPIO_GEDR0, 0),
384 1.1 scw GPIO_BIT(0));
385 1.1 scw
386 1.1 scw return ((sc->sc_handlers[0]->gh_func)(sc->sc_handlers[0]->gh_arg));
387 1.1 scw }
388 1.1 scw
389 1.1 scw static int
390 1.1 scw gpio_intr1(void *arg)
391 1.1 scw {
392 1.1 scw struct pxagpio_softc *sc = arg;
393 1.1 scw
394 1.1 scw #ifdef DIAGNOSTIC
395 1.1 scw if (sc->sc_handlers[1] == NULL) {
396 1.14 nonaka aprint_error_dev(sc->sc_dev, "stray GPIO#1 edge interrupt\n");
397 1.1 scw return (0);
398 1.1 scw }
399 1.1 scw #endif
400 1.1 scw
401 1.1 scw bus_space_write_4(sc->sc_bust, sc->sc_bush, GPIO_REG(GPIO_GEDR0, 1),
402 1.1 scw GPIO_BIT(1));
403 1.1 scw
404 1.1 scw return ((sc->sc_handlers[1]->gh_func)(sc->sc_handlers[1]->gh_arg));
405 1.1 scw }
406 1.1 scw
407 1.1 scw #ifdef PXAGPIO_HAS_GPION_INTRS
408 1.1 scw static int
409 1.1 scw gpio_dispatch(struct pxagpio_softc *sc, int gpio_base)
410 1.1 scw {
411 1.1 scw struct gpio_irq_handler **ghp, *gh;
412 1.6 ober int i, s, nhandled, handled, pins;
413 1.16 skrll uint32_t gedr, mask;
414 1.1 scw int bank;
415 1.1 scw
416 1.1 scw /* Fetch bitmap of pending interrupts on this GPIO bank */
417 1.1 scw gedr = pxagpio_reg_read(sc, GPIO_REG(GPIO_GEDR0, gpio_base));
418 1.1 scw
419 1.1 scw /* Don't handle GPIO 0/1 here */
420 1.1 scw if (gpio_base == 0)
421 1.1 scw gedr &= ~(GPIO_BIT(0) | GPIO_BIT(1));
422 1.1 scw
423 1.1 scw /* Bail early if there are no pending interrupts in this bank */
424 1.1 scw if (gedr == 0)
425 1.1 scw return (0);
426 1.1 scw
427 1.1 scw /* Acknowledge pending interrupts. */
428 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GEDR0, gpio_base), gedr);
429 1.1 scw
430 1.1 scw bank = GPIO_BANK(gpio_base);
431 1.1 scw
432 1.1 scw /*
433 1.1 scw * We're only interested in those for which we have a handler
434 1.1 scw * registered
435 1.1 scw */
436 1.1 scw #ifdef DEBUG
437 1.1 scw if ((gedr & sc->sc_mask[bank]) == 0) {
438 1.14 nonaka aprint_error_dev(sc->sc_dev,
439 1.14 nonaka "stray GPIO interrupt. Bank %d, GEDR 0x%08x, mask 0x%08x\n",
440 1.14 nonaka bank, gedr, sc->sc_mask[bank]);
441 1.1 scw return (1); /* XXX: Pretend we dealt with it */
442 1.1 scw }
443 1.1 scw #endif
444 1.1 scw
445 1.1 scw gedr &= sc->sc_mask[bank];
446 1.1 scw ghp = &sc->sc_handlers[gpio_base];
447 1.3 bsh if (CPU_IS_PXA270)
448 1.3 bsh pins = (gpio_base < 96) ? 32 : 25;
449 1.3 bsh else
450 1.3 bsh pins = (gpio_base < 64) ? 32 : 17;
451 1.1 scw handled = 0;
452 1.1 scw
453 1.1 scw for (i = 0, mask = 1; i < pins && gedr; i++, ghp++, mask <<= 1) {
454 1.1 scw if ((gedr & mask) == 0)
455 1.1 scw continue;
456 1.1 scw gedr &= ~mask;
457 1.1 scw
458 1.1 scw if ((gh = *ghp) == NULL) {
459 1.14 nonaka aprint_error_dev(sc->sc_dev,
460 1.14 nonaka "unhandled GPIO interrupt. GPIO#%d\n",
461 1.14 nonaka gpio_base + i);
462 1.1 scw continue;
463 1.1 scw }
464 1.1 scw
465 1.1 scw s = _splraise(gh->gh_spl);
466 1.6 ober do {
467 1.6 ober nhandled = (gh->gh_func)(gh->gh_arg);
468 1.6 ober handled |= nhandled;
469 1.6 ober gh = gh->gh_next;
470 1.6 ober } while (gh != NULL);
471 1.1 scw splx(s);
472 1.1 scw }
473 1.1 scw
474 1.1 scw return (handled);
475 1.1 scw }
476 1.1 scw
477 1.1 scw static int
478 1.1 scw gpio_intrN(void *arg)
479 1.1 scw {
480 1.1 scw struct pxagpio_softc *sc = arg;
481 1.1 scw int handled;
482 1.1 scw
483 1.1 scw handled = gpio_dispatch(sc, 0);
484 1.1 scw handled |= gpio_dispatch(sc, 32);
485 1.1 scw handled |= gpio_dispatch(sc, 64);
486 1.3 bsh if (CPU_IS_PXA270)
487 1.3 bsh handled |= gpio_dispatch(sc, 96);
488 1.1 scw return (handled);
489 1.1 scw }
490 1.1 scw #endif /* PXAGPIO_HAS_GPION_INTRS */
491 1.1 scw
492 1.1 scw u_int
493 1.1 scw pxa2x0_gpio_get_function(u_int gpio)
494 1.1 scw {
495 1.1 scw struct pxagpio_softc *sc = pxagpio_softc;
496 1.16 skrll uint32_t rv, io;
497 1.1 scw
498 1.1 scw KDASSERT(gpio < GPIO_NPINS);
499 1.1 scw
500 1.1 scw rv = pxagpio_reg_read(sc, GPIO_FN_REG(gpio)) >> GPIO_FN_SHIFT(gpio);
501 1.1 scw rv = GPIO_FN(rv);
502 1.1 scw
503 1.1 scw io = pxagpio_reg_read(sc, GPIO_REG(GPIO_GPDR0, gpio));
504 1.1 scw if (io & GPIO_BIT(gpio))
505 1.1 scw rv |= GPIO_OUT;
506 1.1 scw
507 1.1 scw io = pxagpio_reg_read(sc, GPIO_REG(GPIO_GPLR0, gpio));
508 1.1 scw if (io & GPIO_BIT(gpio))
509 1.1 scw rv |= GPIO_SET;
510 1.1 scw
511 1.1 scw return (rv);
512 1.1 scw }
513 1.1 scw
514 1.1 scw u_int
515 1.1 scw pxa2x0_gpio_set_function(u_int gpio, u_int fn)
516 1.1 scw {
517 1.1 scw struct pxagpio_softc *sc = pxagpio_softc;
518 1.16 skrll uint32_t rv, bit;
519 1.1 scw u_int oldfn;
520 1.1 scw
521 1.1 scw KDASSERT(gpio < GPIO_NPINS);
522 1.1 scw
523 1.1 scw oldfn = pxa2x0_gpio_get_function(gpio);
524 1.1 scw
525 1.1 scw if (GPIO_FN(fn) == GPIO_FN(oldfn) &&
526 1.1 scw GPIO_FN_IS_OUT(fn) == GPIO_FN_IS_OUT(oldfn)) {
527 1.1 scw /*
528 1.1 scw * The pin's function is not changing.
529 1.1 scw * For Alternate Functions and GPIO input, we can just
530 1.1 scw * return now.
531 1.1 scw * For GPIO output pins, check the initial state is
532 1.1 scw * the same.
533 1.1 scw *
534 1.1 scw * Return 'fn' instead of 'oldfn' so the caller can
535 1.1 scw * reliably detect that we didn't change anything.
536 1.1 scw * (The initial state might be different for non-
537 1.1 scw * GPIO output pins).
538 1.1 scw */
539 1.1 scw if (!GPIO_IS_GPIO_OUT(fn) ||
540 1.1 scw GPIO_FN_IS_SET(fn) == GPIO_FN_IS_SET(oldfn))
541 1.1 scw return (fn);
542 1.1 scw }
543 1.1 scw
544 1.1 scw /*
545 1.1 scw * See section 4.1.3.7 of the PXA2x0 Developer's Manual for
546 1.1 scw * the correct procedure for changing GPIO pin functions.
547 1.1 scw */
548 1.1 scw
549 1.1 scw bit = GPIO_BIT(gpio);
550 1.1 scw
551 1.1 scw /*
552 1.1 scw * 1. Configure the correct set/clear state of the pin
553 1.1 scw */
554 1.1 scw if (GPIO_FN_IS_SET(fn))
555 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GPSR0, gpio), bit);
556 1.1 scw else
557 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GPCR0, gpio), bit);
558 1.1 scw
559 1.1 scw /*
560 1.1 scw * 2. Configure the pin as an input or output as appropriate
561 1.1 scw */
562 1.1 scw rv = pxagpio_reg_read(sc, GPIO_REG(GPIO_GPDR0, gpio)) & ~bit;
563 1.1 scw if (GPIO_FN_IS_OUT(fn))
564 1.1 scw rv |= bit;
565 1.1 scw pxagpio_reg_write(sc, GPIO_REG(GPIO_GPDR0, gpio), rv);
566 1.1 scw
567 1.1 scw /*
568 1.1 scw * 3. Configure the pin's function
569 1.1 scw */
570 1.1 scw bit = GPIO_FN_MASK << GPIO_FN_SHIFT(gpio);
571 1.1 scw fn = GPIO_FN(fn) << GPIO_FN_SHIFT(gpio);
572 1.1 scw rv = pxagpio_reg_read(sc, GPIO_FN_REG(gpio)) & ~bit;
573 1.1 scw pxagpio_reg_write(sc, GPIO_FN_REG(gpio), rv | fn);
574 1.1 scw
575 1.1 scw return (oldfn);
576 1.1 scw }
577 1.6 ober
578 1.6 ober /*
579 1.6 ober * Quick function to read pin value
580 1.6 ober */
581 1.6 ober int
582 1.6 ober pxa2x0_gpio_get_bit(u_int gpio)
583 1.6 ober {
584 1.6 ober struct pxagpio_softc *sc = pxagpio_softc;
585 1.6 ober int bit;
586 1.6 ober
587 1.6 ober bit = GPIO_BIT(gpio);
588 1.6 ober if (pxagpio_reg_read(sc, GPIO_REG(GPIO_GPLR0, gpio)) & bit)
589 1.6 ober return 1;
590 1.6 ober else
591 1.6 ober return 0;
592 1.6 ober }
593 1.6 ober
594 1.6 ober /*
595 1.6 ober * Quick function to set pin to 1
596 1.6 ober */
597 1.6 ober void
598 1.6 ober pxa2x0_gpio_set_bit(u_int gpio)
599 1.6 ober {
600 1.6 ober struct pxagpio_softc *sc = pxagpio_softc;
601 1.6 ober int bit;
602 1.6 ober
603 1.6 ober bit = GPIO_BIT(gpio);
604 1.6 ober pxagpio_reg_write(sc, GPIO_REG(GPIO_GPSR0, gpio), bit);
605 1.6 ober }
606 1.6 ober
607 1.6 ober /*
608 1.6 ober * Quick function to set pin to 0
609 1.6 ober */
610 1.6 ober void
611 1.6 ober pxa2x0_gpio_clear_bit(u_int gpio)
612 1.6 ober {
613 1.6 ober struct pxagpio_softc *sc = pxagpio_softc;
614 1.6 ober int bit;
615 1.6 ober
616 1.6 ober bit = GPIO_BIT(gpio);
617 1.6 ober pxagpio_reg_write(sc, GPIO_REG(GPIO_GPCR0, gpio), bit);
618 1.6 ober }
619 1.6 ober
620 1.6 ober /*
621 1.6 ober * Quick function to change pin direction
622 1.6 ober */
623 1.6 ober void
624 1.6 ober pxa2x0_gpio_set_dir(u_int gpio, int dir)
625 1.6 ober {
626 1.6 ober struct pxagpio_softc *sc = pxagpio_softc;
627 1.6 ober int bit;
628 1.16 skrll uint32_t reg;
629 1.6 ober
630 1.6 ober bit = GPIO_BIT(gpio);
631 1.6 ober
632 1.6 ober reg = pxagpio_reg_read(sc, GPIO_REG(GPIO_GPDR0, gpio)) & ~bit;
633 1.6 ober if (GPIO_FN_IS_OUT(dir))
634 1.6 ober reg |= bit;
635 1.6 ober pxagpio_reg_write(sc, GPIO_REG(GPIO_GPDR0, gpio), reg);
636 1.6 ober }
637 1.6 ober
638 1.6 ober /*
639 1.6 ober * Quick function to clear interrupt status on a pin
640 1.6 ober * GPIO pins may be toggle in an interrupt and we dont want
641 1.6 ober * extra spurious interrupts to occur.
642 1.6 ober * Suppose this causes a slight race if a key is pressed while
643 1.6 ober * the interrupt handler is running. (yes this is for the keyboard driver)
644 1.6 ober */
645 1.6 ober void
646 1.6 ober pxa2x0_gpio_clear_intr(u_int gpio)
647 1.6 ober {
648 1.6 ober struct pxagpio_softc *sc = pxagpio_softc;
649 1.6 ober int bit;
650 1.6 ober
651 1.6 ober bit = GPIO_BIT(gpio);
652 1.6 ober pxagpio_reg_write(sc, GPIO_REG(GPIO_GEDR0, gpio), bit);
653 1.6 ober }
654 1.6 ober
655 1.6 ober /*
656 1.6 ober * Quick function to mask (disable) a GPIO interrupt
657 1.6 ober */
658 1.6 ober void
659 1.6 ober pxa2x0_gpio_intr_mask(void *v)
660 1.6 ober {
661 1.6 ober struct gpio_irq_handler *gh = (struct gpio_irq_handler *)v;
662 1.6 ober
663 1.6 ober pxa2x0_gpio_set_intr_level(gh->gh_gpio, IPL_NONE);
664 1.6 ober }
665 1.6 ober
666 1.6 ober /*
667 1.6 ober * Quick function to unmask (enable) a GPIO interrupt
668 1.6 ober */
669 1.6 ober void
670 1.6 ober pxa2x0_gpio_intr_unmask(void *v)
671 1.6 ober {
672 1.6 ober struct gpio_irq_handler *gh = (struct gpio_irq_handler *)v;
673 1.6 ober
674 1.6 ober pxa2x0_gpio_set_intr_level(gh->gh_gpio, gh->gh_level);
675 1.6 ober }
676 1.6 ober
677 1.6 ober /*
678 1.6 ober * Configure the edge sensitivity of interrupt pins
679 1.6 ober */
680 1.6 ober void
681 1.6 ober pxa2x0_gpio_set_intr_level(u_int gpio, int level)
682 1.6 ober {
683 1.6 ober struct pxagpio_softc *sc = pxagpio_softc;
684 1.16 skrll uint32_t bit;
685 1.16 skrll uint32_t gfer;
686 1.16 skrll uint32_t grer;
687 1.6 ober int s;
688 1.6 ober
689 1.6 ober s = splhigh();
690 1.6 ober
691 1.6 ober bit = GPIO_BIT(gpio);
692 1.6 ober gfer = pxagpio_reg_read(sc, GPIO_REG(GPIO_GFER0, gpio));
693 1.6 ober grer = pxagpio_reg_read(sc, GPIO_REG(GPIO_GRER0, gpio));
694 1.6 ober
695 1.6 ober switch (level) {
696 1.6 ober case IST_NONE:
697 1.6 ober gfer &= ~bit;
698 1.6 ober grer &= ~bit;
699 1.6 ober break;
700 1.6 ober case IST_EDGE_FALLING:
701 1.6 ober gfer |= bit;
702 1.6 ober grer &= ~bit;
703 1.6 ober break;
704 1.6 ober case IST_EDGE_RISING:
705 1.6 ober gfer &= ~bit;
706 1.6 ober grer |= bit;
707 1.6 ober break;
708 1.6 ober case IST_EDGE_BOTH:
709 1.6 ober gfer |= bit;
710 1.6 ober grer |= bit;
711 1.6 ober break;
712 1.6 ober default:
713 1.6 ober panic("pxa2x0_gpio_set_intr_level: bad level: %d", level);
714 1.6 ober break;
715 1.6 ober }
716 1.6 ober
717 1.6 ober pxagpio_reg_write(sc, GPIO_REG(GPIO_GFER0, gpio), gfer);
718 1.6 ober pxagpio_reg_write(sc, GPIO_REG(GPIO_GRER0, gpio), grer);
719 1.6 ober
720 1.6 ober splx(s);
721 1.6 ober }
722 1.8 kiyohara
723 1.17 pgoyette #if NGPIO > 0
724 1.17 pgoyette /* GPIO support functions */
725 1.17 pgoyette static int
726 1.17 pgoyette pxa2x0_gpio_pin_read(void *arg, int pin)
727 1.17 pgoyette {
728 1.17 pgoyette return pxa2x0_gpio_get_bit(pin);
729 1.17 pgoyette }
730 1.17 pgoyette
731 1.17 pgoyette static void
732 1.17 pgoyette pxa2x0_gpio_pin_write(void *arg, int pin, int value)
733 1.17 pgoyette {
734 1.17 pgoyette if (value == GPIO_PIN_HIGH) {
735 1.17 pgoyette pxa2x0_gpio_set_bit(pin);
736 1.17 pgoyette } else {
737 1.17 pgoyette pxa2x0_gpio_clear_bit(pin);
738 1.17 pgoyette }
739 1.17 pgoyette }
740 1.17 pgoyette
741 1.17 pgoyette static void
742 1.17 pgoyette pxa2x0_gpio_pin_ctl(void *arg, int pin, int flags)
743 1.17 pgoyette {
744 1.17 pgoyette if (flags & GPIO_PIN_OUTPUT) {
745 1.17 pgoyette pxa2x0_gpio_set_function(pin, GPIO_OUT);
746 1.17 pgoyette } else if (flags & GPIO_PIN_INPUT) {
747 1.17 pgoyette pxa2x0_gpio_set_function(pin, GPIO_IN);
748 1.17 pgoyette }
749 1.17 pgoyette }
750 1.17 pgoyette #endif
751 1.8 kiyohara
752 1.8 kiyohara #if defined(CPU_XSCALE_PXA250)
753 1.8 kiyohara /*
754 1.8 kiyohara * Configurations of GPIO for PXA25x
755 1.8 kiyohara */
756 1.8 kiyohara struct pxa2x0_gpioconf pxa25x_com_btuart_gpioconf[] = {
757 1.8 kiyohara { 42, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* BTRXD */
758 1.8 kiyohara { 43, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* BTTXD */
759 1.8 kiyohara
760 1.8 kiyohara #if 0 /* optional */
761 1.8 kiyohara { 44, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* BTCTS */
762 1.8 kiyohara { 45, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* BTRTS */
763 1.8 kiyohara #endif
764 1.8 kiyohara
765 1.8 kiyohara { -1 }
766 1.8 kiyohara };
767 1.8 kiyohara
768 1.8 kiyohara struct pxa2x0_gpioconf pxa25x_com_ffuart_gpioconf[] = {
769 1.8 kiyohara { 34, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* FFRXD */
770 1.8 kiyohara
771 1.8 kiyohara #if 0 /* optional */
772 1.8 kiyohara { 35, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* CTS */
773 1.8 kiyohara { 36, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* DCD */
774 1.8 kiyohara { 37, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* DSR */
775 1.8 kiyohara { 38, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* RI */
776 1.8 kiyohara #endif
777 1.8 kiyohara
778 1.8 kiyohara { 39, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* FFTXD */
779 1.8 kiyohara
780 1.8 kiyohara #if 0 /* optional */
781 1.8 kiyohara { 40, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* DTR */
782 1.8 kiyohara { 41, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* RTS */
783 1.8 kiyohara #endif
784 1.8 kiyohara
785 1.8 kiyohara { -1 }
786 1.8 kiyohara };
787 1.8 kiyohara
788 1.8 kiyohara struct pxa2x0_gpioconf pxa25x_com_hwuart_gpioconf[] = {
789 1.8 kiyohara #if 0 /* We can select and/or. */
790 1.8 kiyohara { 42, GPIO_CLR | GPIO_ALT_FN_3_IN }, /* HWRXD */
791 1.8 kiyohara { 49, GPIO_CLR | GPIO_ALT_FN_2_IN }, /* HWRXD */
792 1.8 kiyohara
793 1.8 kiyohara { 43, GPIO_CLR | GPIO_ALT_FN_3_OUT }, /* HWTXD */
794 1.8 kiyohara { 48, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* HWTXD */
795 1.8 kiyohara
796 1.8 kiyohara #if 0 /* optional */
797 1.8 kiyohara { 44, GPIO_CLR | GPIO_ALT_FN_3_IN }, /* HWCST */
798 1.8 kiyohara { 51, GPIO_CLR | GPIO_ALT_FN_3_IN }, /* HWCST */
799 1.8 kiyohara
800 1.8 kiyohara { 45, GPIO_CLR | GPIO_ALT_FN_3_OUT }, /* HWRST */
801 1.8 kiyohara { 52, GPIO_CLR | GPIO_ALT_FN_3_OUT }, /* HWRST */
802 1.8 kiyohara #endif
803 1.8 kiyohara #endif
804 1.8 kiyohara
805 1.8 kiyohara { -1 }
806 1.8 kiyohara };
807 1.8 kiyohara
808 1.8 kiyohara struct pxa2x0_gpioconf pxa25x_com_stuart_gpioconf[] = {
809 1.8 kiyohara { 46, GPIO_CLR | GPIO_ALT_FN_2_IN }, /* RXD */
810 1.8 kiyohara { 47, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* TXD */
811 1.8 kiyohara { -1 }
812 1.8 kiyohara };
813 1.8 kiyohara
814 1.8 kiyohara struct pxa2x0_gpioconf pxa25x_i2c_gpioconf[] = {
815 1.8 kiyohara { -1 }
816 1.8 kiyohara };
817 1.8 kiyohara
818 1.8 kiyohara struct pxa2x0_gpioconf pxa25x_i2s_gpioconf[] = {
819 1.8 kiyohara { 28, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* BITCLK */
820 1.8 kiyohara { 29, GPIO_CLR | GPIO_ALT_FN_2_IN }, /* SDATA_IN */
821 1.8 kiyohara { 30, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* SDATA_OUT */
822 1.8 kiyohara { 31, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* SYNC */
823 1.8 kiyohara { 32, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* SYSCLK */
824 1.8 kiyohara { -1 }
825 1.8 kiyohara };
826 1.8 kiyohara
827 1.8 kiyohara struct pxa2x0_gpioconf pxa25x_pcic_gpioconf[] = {
828 1.8 kiyohara { 48, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPOE */
829 1.8 kiyohara { 49, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPWE */
830 1.8 kiyohara { 50, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPIOR */
831 1.8 kiyohara { 51, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPIOW */
832 1.8 kiyohara
833 1.8 kiyohara #if 0 /* We can select and/or. */
834 1.8 kiyohara { 52, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPCE1 */
835 1.8 kiyohara { 53, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPCE2 */
836 1.8 kiyohara #endif
837 1.8 kiyohara
838 1.8 kiyohara { 54, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* pSKTSEL */
839 1.8 kiyohara { 55, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPREG */
840 1.8 kiyohara { 56, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* nPWAIT */
841 1.8 kiyohara { 57, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* nIOIS16 */
842 1.8 kiyohara { -1 }
843 1.8 kiyohara };
844 1.8 kiyohara
845 1.8 kiyohara struct pxa2x0_gpioconf pxa25x_pxaacu_gpioconf[] = {
846 1.8 kiyohara { 28, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* BITCLK */
847 1.8 kiyohara { 30, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* SDATA_OUT */
848 1.8 kiyohara { 31, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* SYNC */
849 1.8 kiyohara
850 1.8 kiyohara #if 0 /* We can select and/or. */
851 1.8 kiyohara { 29, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* SDATA_IN0 */
852 1.8 kiyohara { 32, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* SDATA_IN1 */
853 1.8 kiyohara #endif
854 1.8 kiyohara
855 1.8 kiyohara { -1 }
856 1.8 kiyohara };
857 1.8 kiyohara
858 1.8 kiyohara struct pxa2x0_gpioconf pxa25x_pxamci_gpioconf[] = {
859 1.8 kiyohara #if 0 /* We can select and/or. */
860 1.8 kiyohara { 6, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* MMCCLK */
861 1.8 kiyohara { 53, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* MMCCLK */
862 1.8 kiyohara { 54, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* MMCCLK */
863 1.8 kiyohara
864 1.8 kiyohara { 8, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* MMCCS0 */
865 1.8 kiyohara { 34, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* MMCCS0 */
866 1.8 kiyohara { 67, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* MMCCS0 */
867 1.8 kiyohara
868 1.8 kiyohara { 9, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* MMCCS1 */
869 1.8 kiyohara { 39, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* MMCCS1 */
870 1.8 kiyohara { 68, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* MMCCS1 */
871 1.8 kiyohara #endif
872 1.8 kiyohara
873 1.8 kiyohara { -1 }
874 1.8 kiyohara };
875 1.8 kiyohara #endif
876 1.8 kiyohara
877 1.8 kiyohara #if defined(CPU_XSCALE_PXA270)
878 1.8 kiyohara /*
879 1.8 kiyohara * Configurations of GPIO for PXA27x
880 1.8 kiyohara */
881 1.8 kiyohara struct pxa2x0_gpioconf pxa27x_com_btuart_gpioconf[] = {
882 1.8 kiyohara { 42, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* BTRXD */
883 1.8 kiyohara { 43, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* BTTXD */
884 1.8 kiyohara
885 1.8 kiyohara #if 0 /* optional */
886 1.8 kiyohara { 44, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* BTCTS */
887 1.8 kiyohara { 45, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* BTRTS */
888 1.8 kiyohara #endif
889 1.8 kiyohara
890 1.8 kiyohara { -1 }
891 1.8 kiyohara };
892 1.8 kiyohara
893 1.8 kiyohara struct pxa2x0_gpioconf pxa27x_com_ffuart_gpioconf[] = {
894 1.8 kiyohara #if 0 /* We can select and/or. */
895 1.8 kiyohara { 16, GPIO_CLR | GPIO_ALT_FN_3_OUT }, /* FFTXD */
896 1.8 kiyohara { 37, GPIO_CLR | GPIO_ALT_FN_3_OUT }, /* FFTXD */
897 1.8 kiyohara { 39, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* FFTXD */
898 1.8 kiyohara { 83, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* FFTXD */
899 1.8 kiyohara { 99, GPIO_CLR | GPIO_ALT_FN_3_OUT }, /* FFTXD */
900 1.8 kiyohara
901 1.8 kiyohara { 19, GPIO_CLR | GPIO_ALT_FN_3_IN }, /* FFRXD */
902 1.8 kiyohara { 33, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* FFRXD */
903 1.8 kiyohara { 34, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* FFRXD */
904 1.8 kiyohara { 41, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* FFRXD */
905 1.8 kiyohara { 53, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* FFRXD */
906 1.8 kiyohara { 85, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* FFRXD */
907 1.8 kiyohara { 96, GPIO_CLR | GPIO_ALT_FN_3_IN }, /* FFRXD */
908 1.8 kiyohara { 102, GPIO_CLR | GPIO_ALT_FN_3_IN }, /* FFRXD */
909 1.8 kiyohara
910 1.8 kiyohara { 9, GPIO_CLR | GPIO_ALT_FN_3_IN }, /* FFCTS */
911 1.8 kiyohara { 26, GPIO_CLR | GPIO_ALT_FN_3_IN }, /* FFCTS */
912 1.8 kiyohara { 35, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* FFCTS */
913 1.8 kiyohara { 100, GPIO_CLR | GPIO_ALT_FN_3_IN }, /* FFCTS */
914 1.8 kiyohara
915 1.8 kiyohara { 27, GPIO_CLR | GPIO_ALT_FN_3_OUT }, /* FFRTS */
916 1.8 kiyohara { 41, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* FFRTS */
917 1.8 kiyohara { 83, GPIO_CLR | GPIO_ALT_FN_3_OUT }, /* FFRTS */
918 1.8 kiyohara { 98, GPIO_CLR | GPIO_ALT_FN_3_OUT }, /* FFRTS */
919 1.8 kiyohara
920 1.8 kiyohara { 40, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* FFDTR */
921 1.8 kiyohara { 82, GPIO_CLR | GPIO_ALT_FN_3_OUT }, /* FFDTR */
922 1.8 kiyohara
923 1.8 kiyohara { 36, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* FFDCD */
924 1.8 kiyohara
925 1.8 kiyohara { 33, GPIO_CLR | GPIO_ALT_FN_2_IN }, /* FFDSR */
926 1.8 kiyohara { 37, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* FFDSR */
927 1.8 kiyohara
928 1.8 kiyohara { 38, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* FFRI */
929 1.8 kiyohara #endif
930 1.8 kiyohara { -1 }
931 1.8 kiyohara };
932 1.8 kiyohara
933 1.8 kiyohara struct pxa2x0_gpioconf pxa27x_com_stuart_gpioconf[] = {
934 1.8 kiyohara { 46, GPIO_CLR | GPIO_ALT_FN_2_IN }, /* STD_RXD */
935 1.8 kiyohara { 47, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* STD_TXD */
936 1.8 kiyohara { -1 }
937 1.8 kiyohara };
938 1.8 kiyohara
939 1.8 kiyohara struct pxa2x0_gpioconf pxa27x_i2c_gpioconf[] = {
940 1.8 kiyohara { 117, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* SCL */
941 1.8 kiyohara { 118, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* SDA */
942 1.8 kiyohara { -1 }
943 1.8 kiyohara };
944 1.8 kiyohara
945 1.8 kiyohara struct pxa2x0_gpioconf pxa27x_i2s_gpioconf[] = {
946 1.8 kiyohara { 28, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* I2S_BITCLK */
947 1.8 kiyohara { 29, GPIO_CLR | GPIO_ALT_FN_2_IN }, /* I2S_SDATA_IN */
948 1.8 kiyohara { 30, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* I2S_SDATA_OUT */
949 1.8 kiyohara { 31, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* I2S_SYNC */
950 1.8 kiyohara { 113, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* I2S_SYSCLK */
951 1.8 kiyohara { -1 }
952 1.8 kiyohara };
953 1.8 kiyohara
954 1.13 kiyohara struct pxa2x0_gpioconf pxa27x_ohci_gpioconf[] = {
955 1.13 kiyohara #if 0 /* We can select and/or. */
956 1.13 kiyohara { 88, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* USBHPWR1 */
957 1.13 kiyohara { 89, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* USBHPEN1 */
958 1.13 kiyohara { 119, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* USBHPWR2 */
959 1.13 kiyohara { 120, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* USBHPEN2 */
960 1.13 kiyohara #endif
961 1.13 kiyohara { -1 }
962 1.13 kiyohara };
963 1.13 kiyohara
964 1.8 kiyohara struct pxa2x0_gpioconf pxa27x_pcic_gpioconf[] = {
965 1.8 kiyohara { 48, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPOE */
966 1.8 kiyohara { 49, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPWE */
967 1.8 kiyohara { 50, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPIOR */
968 1.8 kiyohara { 51, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPIOW */
969 1.8 kiyohara { 55, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPREG */
970 1.8 kiyohara { 56, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* nPWAIT */
971 1.8 kiyohara { 57, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* nIOIS16 */
972 1.8 kiyohara
973 1.8 kiyohara #if 0 /* We can select and/or. */
974 1.8 kiyohara { 85, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* nPCE1 */
975 1.8 kiyohara { 86, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* nPCE1 */
976 1.8 kiyohara { 102, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* nPCE1 */
977 1.8 kiyohara
978 1.8 kiyohara { 54, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* nPCE2 */
979 1.8 kiyohara { 78, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* nPCE2 */
980 1.8 kiyohara { 105, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* nPCE2 */
981 1.13 kiyohara
982 1.13 kiyohara { 79, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* pSKTSEL */
983 1.13 kiyohara { 104, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* pSKTSEL */
984 1.8 kiyohara #endif
985 1.8 kiyohara
986 1.8 kiyohara { -1 }
987 1.8 kiyohara };
988 1.8 kiyohara
989 1.8 kiyohara struct pxa2x0_gpioconf pxa27x_pxaacu_gpioconf[] = {
990 1.8 kiyohara { 28, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* BITCLK */
991 1.8 kiyohara { 30, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* SDATA_OUT */
992 1.8 kiyohara
993 1.8 kiyohara #if 0 /* We can select and/or. */
994 1.8 kiyohara { 31, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* SYNC */
995 1.8 kiyohara { 94, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* SYNC */
996 1.8 kiyohara
997 1.8 kiyohara { 29, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* SDATA_IN0 */
998 1.8 kiyohara { 116, GPIO_CLR | GPIO_ALT_FN_2_IN }, /* SDATA_IN0 */
999 1.8 kiyohara
1000 1.8 kiyohara { 32, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* SDATA_IN1 */
1001 1.8 kiyohara { 99, GPIO_CLR | GPIO_ALT_FN_2_IN }, /* SDATA_IN1 */
1002 1.8 kiyohara
1003 1.8 kiyohara { 95, GPIO_CLR | GPIO_ALT_FN_1_OUT }, /* RESET_n */
1004 1.8 kiyohara { 113, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* RESET_n */
1005 1.8 kiyohara #endif
1006 1.8 kiyohara
1007 1.8 kiyohara { -1 }
1008 1.8 kiyohara };
1009 1.8 kiyohara
1010 1.8 kiyohara struct pxa2x0_gpioconf pxa27x_pxamci_gpioconf[] = {
1011 1.8 kiyohara { 32, GPIO_CLR | GPIO_ALT_FN_2_OUT }, /* MMCLK */
1012 1.8 kiyohara { 92, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* MMDAT<0> */
1013 1.8 kiyohara { 109, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* MMDAT<1> */
1014 1.8 kiyohara { 110, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* MMDAT<2>/MMCCS<0> */
1015 1.8 kiyohara { 111, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* MMDAT<3>/MMCCS<1> */
1016 1.13 kiyohara { 112, GPIO_CLR | GPIO_ALT_FN_1_IN }, /* MMCMD */
1017 1.8 kiyohara
1018 1.8 kiyohara { -1 }
1019 1.8 kiyohara };
1020 1.8 kiyohara #endif
1021 1.8 kiyohara
1022 1.8 kiyohara void
1023 1.8 kiyohara pxa2x0_gpio_config(struct pxa2x0_gpioconf **conflist)
1024 1.8 kiyohara {
1025 1.8 kiyohara int i, j;
1026 1.8 kiyohara
1027 1.8 kiyohara for (i = 0; conflist[i] != NULL; i++)
1028 1.8 kiyohara for (j = 0; conflist[i][j].pin != -1; j++)
1029 1.8 kiyohara pxa2x0_gpio_set_function(conflist[i][j].pin,
1030 1.8 kiyohara conflist[i][j].value);
1031 1.8 kiyohara }
1032