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