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