Home | History | Annotate | Line # | Download | only in xscale
pxa2x0_gpio.c revision 1.3.2.3
      1  1.3.2.3   yamt /*	$NetBSD: pxa2x0_gpio.c,v 1.3.2.3 2007/09/03 14:23:28 yamt 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.3.2.3   yamt __KERNEL_RCSID(0, "$NetBSD: pxa2x0_gpio.c,v 1.3.2.3 2007/09/03 14:23:28 yamt 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.3.2.2   yamt 	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.3.2.2   yamt 	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.3.2.1   yamt 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.3.2.1   yamt 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.3.2.2   yamt 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.3.2.2   yamt 	gh->gh_level = level;
    240  1.3.2.2   yamt 	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.3.2.2   yamt 	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.3.2.2   yamt 		do {
    418  1.3.2.2   yamt 			nhandled = (gh->gh_func)(gh->gh_arg);
    419  1.3.2.2   yamt 			handled |= nhandled;
    420  1.3.2.2   yamt 			gh = gh->gh_next;
    421  1.3.2.2   yamt 		} 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.3.2.2   yamt 
    529  1.3.2.2   yamt /*
    530  1.3.2.2   yamt  * Quick function to read pin value
    531  1.3.2.2   yamt  */
    532  1.3.2.2   yamt int
    533  1.3.2.2   yamt pxa2x0_gpio_get_bit(u_int gpio)
    534  1.3.2.2   yamt {
    535  1.3.2.2   yamt 	struct pxagpio_softc *sc = pxagpio_softc;
    536  1.3.2.2   yamt 	int bit;
    537  1.3.2.2   yamt 
    538  1.3.2.2   yamt 	bit = GPIO_BIT(gpio);
    539  1.3.2.2   yamt 	if (pxagpio_reg_read(sc, GPIO_REG(GPIO_GPLR0, gpio)) & bit)
    540  1.3.2.2   yamt 		return 1;
    541  1.3.2.2   yamt 	else
    542  1.3.2.2   yamt 		return 0;
    543  1.3.2.2   yamt }
    544  1.3.2.2   yamt 
    545  1.3.2.2   yamt /*
    546  1.3.2.2   yamt  * Quick function to set pin to 1
    547  1.3.2.2   yamt  */
    548  1.3.2.2   yamt void
    549  1.3.2.2   yamt pxa2x0_gpio_set_bit(u_int gpio)
    550  1.3.2.2   yamt {
    551  1.3.2.2   yamt 	struct pxagpio_softc *sc = pxagpio_softc;
    552  1.3.2.2   yamt 	int bit;
    553  1.3.2.2   yamt 
    554  1.3.2.2   yamt 	bit = GPIO_BIT(gpio);
    555  1.3.2.2   yamt 	pxagpio_reg_write(sc, GPIO_REG(GPIO_GPSR0, gpio), bit);
    556  1.3.2.2   yamt }
    557  1.3.2.2   yamt 
    558  1.3.2.2   yamt /*
    559  1.3.2.2   yamt  * Quick function to set pin to 0
    560  1.3.2.2   yamt  */
    561  1.3.2.2   yamt void
    562  1.3.2.2   yamt pxa2x0_gpio_clear_bit(u_int gpio)
    563  1.3.2.2   yamt {
    564  1.3.2.2   yamt 	struct pxagpio_softc *sc = pxagpio_softc;
    565  1.3.2.2   yamt 	int bit;
    566  1.3.2.2   yamt 
    567  1.3.2.2   yamt 	bit = GPIO_BIT(gpio);
    568  1.3.2.2   yamt 	pxagpio_reg_write(sc, GPIO_REG(GPIO_GPCR0, gpio), bit);
    569  1.3.2.2   yamt }
    570  1.3.2.2   yamt 
    571  1.3.2.2   yamt /*
    572  1.3.2.2   yamt  * Quick function to change pin direction
    573  1.3.2.2   yamt  */
    574  1.3.2.2   yamt void
    575  1.3.2.2   yamt pxa2x0_gpio_set_dir(u_int gpio, int dir)
    576  1.3.2.2   yamt {
    577  1.3.2.2   yamt 	struct pxagpio_softc *sc = pxagpio_softc;
    578  1.3.2.2   yamt 	int bit;
    579  1.3.2.2   yamt 	u_int32_t reg;
    580  1.3.2.2   yamt 
    581  1.3.2.2   yamt 	bit = GPIO_BIT(gpio);
    582  1.3.2.2   yamt 
    583  1.3.2.2   yamt 	reg = pxagpio_reg_read(sc, GPIO_REG(GPIO_GPDR0, gpio)) & ~bit;
    584  1.3.2.2   yamt 	if (GPIO_FN_IS_OUT(dir))
    585  1.3.2.2   yamt 		reg |= bit;
    586  1.3.2.2   yamt 	pxagpio_reg_write(sc, GPIO_REG(GPIO_GPDR0, gpio), reg);
    587  1.3.2.2   yamt }
    588  1.3.2.2   yamt 
    589  1.3.2.2   yamt /*
    590  1.3.2.2   yamt  * Quick function to clear interrupt status on a pin
    591  1.3.2.2   yamt  * GPIO pins may be toggle in an interrupt and we dont want
    592  1.3.2.2   yamt  * extra spurious interrupts to occur.
    593  1.3.2.2   yamt  * Suppose this causes a slight race if a key is pressed while
    594  1.3.2.2   yamt  * the interrupt handler is running. (yes this is for the keyboard driver)
    595  1.3.2.2   yamt  */
    596  1.3.2.2   yamt void
    597  1.3.2.2   yamt pxa2x0_gpio_clear_intr(u_int gpio)
    598  1.3.2.2   yamt {
    599  1.3.2.2   yamt 	struct pxagpio_softc *sc = pxagpio_softc;
    600  1.3.2.2   yamt 	int bit;
    601  1.3.2.2   yamt 
    602  1.3.2.2   yamt 	bit = GPIO_BIT(gpio);
    603  1.3.2.2   yamt 	pxagpio_reg_write(sc, GPIO_REG(GPIO_GEDR0, gpio), bit);
    604  1.3.2.2   yamt }
    605  1.3.2.2   yamt 
    606  1.3.2.2   yamt /*
    607  1.3.2.2   yamt  * Quick function to mask (disable) a GPIO interrupt
    608  1.3.2.2   yamt  */
    609  1.3.2.2   yamt void
    610  1.3.2.2   yamt pxa2x0_gpio_intr_mask(void *v)
    611  1.3.2.2   yamt {
    612  1.3.2.2   yamt 	struct gpio_irq_handler *gh = (struct gpio_irq_handler *)v;
    613  1.3.2.2   yamt 
    614  1.3.2.2   yamt 	pxa2x0_gpio_set_intr_level(gh->gh_gpio, IPL_NONE);
    615  1.3.2.2   yamt }
    616  1.3.2.2   yamt 
    617  1.3.2.2   yamt /*
    618  1.3.2.2   yamt  * Quick function to unmask (enable) a GPIO interrupt
    619  1.3.2.2   yamt  */
    620  1.3.2.2   yamt void
    621  1.3.2.2   yamt pxa2x0_gpio_intr_unmask(void *v)
    622  1.3.2.2   yamt {
    623  1.3.2.2   yamt 	struct gpio_irq_handler *gh = (struct gpio_irq_handler *)v;
    624  1.3.2.2   yamt 
    625  1.3.2.2   yamt 	pxa2x0_gpio_set_intr_level(gh->gh_gpio, gh->gh_level);
    626  1.3.2.2   yamt }
    627  1.3.2.2   yamt 
    628  1.3.2.2   yamt /*
    629  1.3.2.2   yamt  * Configure the edge sensitivity of interrupt pins
    630  1.3.2.2   yamt  */
    631  1.3.2.2   yamt void
    632  1.3.2.2   yamt pxa2x0_gpio_set_intr_level(u_int gpio, int level)
    633  1.3.2.2   yamt {
    634  1.3.2.2   yamt 	struct pxagpio_softc *sc = pxagpio_softc;
    635  1.3.2.2   yamt 	u_int32_t bit;
    636  1.3.2.2   yamt 	u_int32_t gfer;
    637  1.3.2.2   yamt 	u_int32_t grer;
    638  1.3.2.2   yamt 	int s;
    639  1.3.2.2   yamt 
    640  1.3.2.2   yamt 	s = splhigh();
    641  1.3.2.2   yamt 
    642  1.3.2.2   yamt 	bit = GPIO_BIT(gpio);
    643  1.3.2.2   yamt 	gfer = pxagpio_reg_read(sc, GPIO_REG(GPIO_GFER0, gpio));
    644  1.3.2.2   yamt 	grer = pxagpio_reg_read(sc, GPIO_REG(GPIO_GRER0, gpio));
    645  1.3.2.2   yamt 
    646  1.3.2.2   yamt 	switch (level) {
    647  1.3.2.2   yamt 	case IST_NONE:
    648  1.3.2.2   yamt 		gfer &= ~bit;
    649  1.3.2.2   yamt 		grer &= ~bit;
    650  1.3.2.2   yamt 		break;
    651  1.3.2.2   yamt 	case IST_EDGE_FALLING:
    652  1.3.2.2   yamt 		gfer |= bit;
    653  1.3.2.2   yamt 		grer &= ~bit;
    654  1.3.2.2   yamt 		break;
    655  1.3.2.2   yamt 	case IST_EDGE_RISING:
    656  1.3.2.2   yamt 		gfer &= ~bit;
    657  1.3.2.2   yamt 		grer |= bit;
    658  1.3.2.2   yamt 		break;
    659  1.3.2.2   yamt 	case IST_EDGE_BOTH:
    660  1.3.2.2   yamt 		gfer |= bit;
    661  1.3.2.2   yamt 		grer |= bit;
    662  1.3.2.2   yamt 		break;
    663  1.3.2.2   yamt 	default:
    664  1.3.2.2   yamt 		panic("pxa2x0_gpio_set_intr_level: bad level: %d", level);
    665  1.3.2.2   yamt 		break;
    666  1.3.2.2   yamt 	}
    667  1.3.2.2   yamt 
    668  1.3.2.2   yamt 	pxagpio_reg_write(sc, GPIO_REG(GPIO_GFER0, gpio), gfer);
    669  1.3.2.2   yamt 	pxagpio_reg_write(sc, GPIO_REG(GPIO_GRER0, gpio), grer);
    670  1.3.2.2   yamt 
    671  1.3.2.2   yamt 	splx(s);
    672  1.3.2.2   yamt }
    673  1.3.2.3   yamt 
    674  1.3.2.3   yamt 
    675  1.3.2.3   yamt #if defined(CPU_XSCALE_PXA250)
    676  1.3.2.3   yamt /*
    677  1.3.2.3   yamt  * Configurations of GPIO for PXA25x
    678  1.3.2.3   yamt  */
    679  1.3.2.3   yamt struct pxa2x0_gpioconf pxa25x_com_btuart_gpioconf[] = {
    680  1.3.2.3   yamt 	{ 42, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* BTRXD */
    681  1.3.2.3   yamt 	{ 43, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* BTTXD */
    682  1.3.2.3   yamt 
    683  1.3.2.3   yamt #if 0	/* optional */
    684  1.3.2.3   yamt 	{ 44, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* BTCTS */
    685  1.3.2.3   yamt 	{ 45, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* BTRTS */
    686  1.3.2.3   yamt #endif
    687  1.3.2.3   yamt 
    688  1.3.2.3   yamt 	{ -1 }
    689  1.3.2.3   yamt };
    690  1.3.2.3   yamt 
    691  1.3.2.3   yamt struct pxa2x0_gpioconf pxa25x_com_ffuart_gpioconf[] = {
    692  1.3.2.3   yamt 	{ 34, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* FFRXD */
    693  1.3.2.3   yamt 
    694  1.3.2.3   yamt #if 0	/* optional */
    695  1.3.2.3   yamt 	{ 35, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* CTS */
    696  1.3.2.3   yamt 	{ 36, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* DCD */
    697  1.3.2.3   yamt 	{ 37, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* DSR */
    698  1.3.2.3   yamt 	{ 38, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* RI */
    699  1.3.2.3   yamt #endif
    700  1.3.2.3   yamt 
    701  1.3.2.3   yamt 	{ 39, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* FFTXD */
    702  1.3.2.3   yamt 
    703  1.3.2.3   yamt #if 0	/* optional */
    704  1.3.2.3   yamt 	{ 40, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* DTR */
    705  1.3.2.3   yamt 	{ 41, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* RTS */
    706  1.3.2.3   yamt #endif
    707  1.3.2.3   yamt 
    708  1.3.2.3   yamt 	{ -1 }
    709  1.3.2.3   yamt };
    710  1.3.2.3   yamt 
    711  1.3.2.3   yamt struct pxa2x0_gpioconf pxa25x_com_hwuart_gpioconf[] = {
    712  1.3.2.3   yamt #if 0	/* We can select and/or. */
    713  1.3.2.3   yamt 	{ 42, GPIO_CLR | GPIO_ALT_FN_3_IN },	/* HWRXD */
    714  1.3.2.3   yamt 	{ 49, GPIO_CLR | GPIO_ALT_FN_2_IN },	/* HWRXD */
    715  1.3.2.3   yamt 
    716  1.3.2.3   yamt 	{ 43, GPIO_CLR | GPIO_ALT_FN_3_OUT },	/* HWTXD */
    717  1.3.2.3   yamt 	{ 48, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* HWTXD */
    718  1.3.2.3   yamt 
    719  1.3.2.3   yamt #if 0	/* optional */
    720  1.3.2.3   yamt 	{ 44, GPIO_CLR | GPIO_ALT_FN_3_IN },	/* HWCST */
    721  1.3.2.3   yamt 	{ 51, GPIO_CLR | GPIO_ALT_FN_3_IN },	/* HWCST */
    722  1.3.2.3   yamt 
    723  1.3.2.3   yamt 	{ 45, GPIO_CLR | GPIO_ALT_FN_3_OUT },	/* HWRST */
    724  1.3.2.3   yamt 	{ 52, GPIO_CLR | GPIO_ALT_FN_3_OUT },	/* HWRST */
    725  1.3.2.3   yamt #endif
    726  1.3.2.3   yamt #endif
    727  1.3.2.3   yamt 
    728  1.3.2.3   yamt 	{ -1 }
    729  1.3.2.3   yamt };
    730  1.3.2.3   yamt 
    731  1.3.2.3   yamt struct pxa2x0_gpioconf pxa25x_com_stuart_gpioconf[] = {
    732  1.3.2.3   yamt 	{ 46, GPIO_CLR | GPIO_ALT_FN_2_IN },	/* RXD */
    733  1.3.2.3   yamt 	{ 47, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* TXD */
    734  1.3.2.3   yamt 	{ -1 }
    735  1.3.2.3   yamt };
    736  1.3.2.3   yamt 
    737  1.3.2.3   yamt struct pxa2x0_gpioconf pxa25x_i2c_gpioconf[] = {
    738  1.3.2.3   yamt 	{ -1 }
    739  1.3.2.3   yamt };
    740  1.3.2.3   yamt 
    741  1.3.2.3   yamt struct pxa2x0_gpioconf pxa25x_i2s_gpioconf[] = {
    742  1.3.2.3   yamt 	{ 28, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* BITCLK */
    743  1.3.2.3   yamt 	{ 29, GPIO_CLR | GPIO_ALT_FN_2_IN },	/* SDATA_IN */
    744  1.3.2.3   yamt 	{ 30, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* SDATA_OUT */
    745  1.3.2.3   yamt 	{ 31, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* SYNC */
    746  1.3.2.3   yamt 	{ 32, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* SYSCLK */
    747  1.3.2.3   yamt 	{ -1 }
    748  1.3.2.3   yamt };
    749  1.3.2.3   yamt 
    750  1.3.2.3   yamt struct pxa2x0_gpioconf pxa25x_pcic_gpioconf[] = {
    751  1.3.2.3   yamt 	{ 48, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPOE */
    752  1.3.2.3   yamt 	{ 49, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPWE */
    753  1.3.2.3   yamt 	{ 50, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPIOR */
    754  1.3.2.3   yamt 	{ 51, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPIOW */
    755  1.3.2.3   yamt 
    756  1.3.2.3   yamt #if 0	/* We can select and/or. */
    757  1.3.2.3   yamt 	{ 52, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPCE1 */
    758  1.3.2.3   yamt 	{ 53, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPCE2 */
    759  1.3.2.3   yamt #endif
    760  1.3.2.3   yamt 
    761  1.3.2.3   yamt 	{ 54, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* pSKTSEL */
    762  1.3.2.3   yamt 	{ 55, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPREG */
    763  1.3.2.3   yamt 	{ 56, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* nPWAIT */
    764  1.3.2.3   yamt 	{ 57, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* nIOIS16 */
    765  1.3.2.3   yamt 	{ -1 }
    766  1.3.2.3   yamt };
    767  1.3.2.3   yamt 
    768  1.3.2.3   yamt struct pxa2x0_gpioconf pxa25x_pxaacu_gpioconf[] = {
    769  1.3.2.3   yamt 	{ 28, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* BITCLK */
    770  1.3.2.3   yamt 	{ 30, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* SDATA_OUT */
    771  1.3.2.3   yamt 	{ 31, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* SYNC */
    772  1.3.2.3   yamt 
    773  1.3.2.3   yamt #if 0	/* We can select and/or. */
    774  1.3.2.3   yamt 	{ 29, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* SDATA_IN0 */
    775  1.3.2.3   yamt 	{ 32, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* SDATA_IN1 */
    776  1.3.2.3   yamt #endif
    777  1.3.2.3   yamt 
    778  1.3.2.3   yamt 	{ -1 }
    779  1.3.2.3   yamt };
    780  1.3.2.3   yamt 
    781  1.3.2.3   yamt struct pxa2x0_gpioconf pxa25x_pxamci_gpioconf[] = {
    782  1.3.2.3   yamt #if 0	/* We can select and/or. */
    783  1.3.2.3   yamt 	{  6, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* MMCCLK */
    784  1.3.2.3   yamt 	{ 53, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* MMCCLK */
    785  1.3.2.3   yamt 	{ 54, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* MMCCLK */
    786  1.3.2.3   yamt 
    787  1.3.2.3   yamt 	{  8, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* MMCCS0 */
    788  1.3.2.3   yamt 	{ 34, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* MMCCS0 */
    789  1.3.2.3   yamt 	{ 67, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* MMCCS0 */
    790  1.3.2.3   yamt 
    791  1.3.2.3   yamt 	{  9, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* MMCCS1 */
    792  1.3.2.3   yamt 	{ 39, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* MMCCS1 */
    793  1.3.2.3   yamt 	{ 68, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* MMCCS1 */
    794  1.3.2.3   yamt #endif
    795  1.3.2.3   yamt 
    796  1.3.2.3   yamt 	{  -1 }
    797  1.3.2.3   yamt };
    798  1.3.2.3   yamt #endif
    799  1.3.2.3   yamt 
    800  1.3.2.3   yamt #if defined(CPU_XSCALE_PXA270)
    801  1.3.2.3   yamt /*
    802  1.3.2.3   yamt  * Configurations of GPIO for PXA27x
    803  1.3.2.3   yamt  */
    804  1.3.2.3   yamt struct pxa2x0_gpioconf pxa27x_com_btuart_gpioconf[] = {
    805  1.3.2.3   yamt 	{  42, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* BTRXD */
    806  1.3.2.3   yamt 	{  43, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* BTTXD */
    807  1.3.2.3   yamt 
    808  1.3.2.3   yamt #if 0	/* optional */
    809  1.3.2.3   yamt 	{  44, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* BTCTS */
    810  1.3.2.3   yamt 	{  45, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* BTRTS */
    811  1.3.2.3   yamt #endif
    812  1.3.2.3   yamt 
    813  1.3.2.3   yamt 	{  -1 }
    814  1.3.2.3   yamt };
    815  1.3.2.3   yamt 
    816  1.3.2.3   yamt struct pxa2x0_gpioconf pxa27x_com_ffuart_gpioconf[] = {
    817  1.3.2.3   yamt #if 0	/* We can select and/or. */
    818  1.3.2.3   yamt 	{  16, GPIO_CLR | GPIO_ALT_FN_3_OUT },	/* FFTXD */
    819  1.3.2.3   yamt 	{  37, GPIO_CLR | GPIO_ALT_FN_3_OUT },	/* FFTXD */
    820  1.3.2.3   yamt 	{  39, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* FFTXD */
    821  1.3.2.3   yamt 	{  83, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* FFTXD */
    822  1.3.2.3   yamt 	{  99, GPIO_CLR | GPIO_ALT_FN_3_OUT },	/* FFTXD */
    823  1.3.2.3   yamt 
    824  1.3.2.3   yamt 	{  19, GPIO_CLR | GPIO_ALT_FN_3_IN },	/* FFRXD */
    825  1.3.2.3   yamt 	{  33, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* FFRXD */
    826  1.3.2.3   yamt 	{  34, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* FFRXD */
    827  1.3.2.3   yamt 	{  41, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* FFRXD */
    828  1.3.2.3   yamt 	{  53, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* FFRXD */
    829  1.3.2.3   yamt 	{  85, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* FFRXD */
    830  1.3.2.3   yamt 	{  96, GPIO_CLR | GPIO_ALT_FN_3_IN },	/* FFRXD */
    831  1.3.2.3   yamt 	{ 102, GPIO_CLR | GPIO_ALT_FN_3_IN },	/* FFRXD */
    832  1.3.2.3   yamt 
    833  1.3.2.3   yamt 	{   9, GPIO_CLR | GPIO_ALT_FN_3_IN },	/* FFCTS */
    834  1.3.2.3   yamt 	{  26, GPIO_CLR | GPIO_ALT_FN_3_IN },	/* FFCTS */
    835  1.3.2.3   yamt 	{  35, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* FFCTS */
    836  1.3.2.3   yamt 	{ 100, GPIO_CLR | GPIO_ALT_FN_3_IN },	/* FFCTS */
    837  1.3.2.3   yamt 
    838  1.3.2.3   yamt 	{  27, GPIO_CLR | GPIO_ALT_FN_3_OUT },	/* FFRTS */
    839  1.3.2.3   yamt 	{  41, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* FFRTS */
    840  1.3.2.3   yamt 	{  83, GPIO_CLR | GPIO_ALT_FN_3_OUT },	/* FFRTS */
    841  1.3.2.3   yamt 	{  98, GPIO_CLR | GPIO_ALT_FN_3_OUT },	/* FFRTS */
    842  1.3.2.3   yamt 
    843  1.3.2.3   yamt 	{  40, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* FFDTR */
    844  1.3.2.3   yamt 	{  82, GPIO_CLR | GPIO_ALT_FN_3_OUT },	/* FFDTR */
    845  1.3.2.3   yamt 
    846  1.3.2.3   yamt 	{  36, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* FFDCD */
    847  1.3.2.3   yamt 
    848  1.3.2.3   yamt 	{  33, GPIO_CLR | GPIO_ALT_FN_2_IN },	/* FFDSR */
    849  1.3.2.3   yamt 	{  37, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* FFDSR */
    850  1.3.2.3   yamt 
    851  1.3.2.3   yamt 	{  38, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* FFRI */
    852  1.3.2.3   yamt #endif
    853  1.3.2.3   yamt 	{  -1 }
    854  1.3.2.3   yamt };
    855  1.3.2.3   yamt 
    856  1.3.2.3   yamt struct pxa2x0_gpioconf pxa27x_com_hwuart_gpioconf[] = {
    857  1.3.2.3   yamt 	{  -1 }
    858  1.3.2.3   yamt };
    859  1.3.2.3   yamt 
    860  1.3.2.3   yamt struct pxa2x0_gpioconf pxa27x_com_stuart_gpioconf[] = {
    861  1.3.2.3   yamt 	{  46, GPIO_CLR | GPIO_ALT_FN_2_IN },	/* STD_RXD */
    862  1.3.2.3   yamt 	{  47, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* STD_TXD */
    863  1.3.2.3   yamt 	{  -1 }
    864  1.3.2.3   yamt };
    865  1.3.2.3   yamt 
    866  1.3.2.3   yamt struct pxa2x0_gpioconf pxa27x_i2c_gpioconf[] = {
    867  1.3.2.3   yamt 	{ 117, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* SCL */
    868  1.3.2.3   yamt 	{ 118, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* SDA */
    869  1.3.2.3   yamt 	{  -1 }
    870  1.3.2.3   yamt };
    871  1.3.2.3   yamt 
    872  1.3.2.3   yamt struct pxa2x0_gpioconf pxa27x_i2s_gpioconf[] = {
    873  1.3.2.3   yamt 	{  28, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* I2S_BITCLK */
    874  1.3.2.3   yamt 	{  29, GPIO_CLR | GPIO_ALT_FN_2_IN },	/* I2S_SDATA_IN */
    875  1.3.2.3   yamt 	{  30, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* I2S_SDATA_OUT */
    876  1.3.2.3   yamt 	{  31, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* I2S_SYNC */
    877  1.3.2.3   yamt 	{ 113, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* I2S_SYSCLK */
    878  1.3.2.3   yamt 	{  -1 }
    879  1.3.2.3   yamt };
    880  1.3.2.3   yamt 
    881  1.3.2.3   yamt struct pxa2x0_gpioconf pxa27x_pcic_gpioconf[] = {
    882  1.3.2.3   yamt 	{  48, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPOE */
    883  1.3.2.3   yamt 	{  49, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPWE */
    884  1.3.2.3   yamt 	{  50, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPIOR */
    885  1.3.2.3   yamt 	{  51, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPIOW */
    886  1.3.2.3   yamt 	{  55, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPREG */
    887  1.3.2.3   yamt 	{  56, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* nPWAIT */
    888  1.3.2.3   yamt 	{  57, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* nIOIS16 */
    889  1.3.2.3   yamt 	{ 104, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* pSKTSEL */
    890  1.3.2.3   yamt 
    891  1.3.2.3   yamt #if 0	/* We can select and/or. */
    892  1.3.2.3   yamt 	{  85, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* nPCE1 */
    893  1.3.2.3   yamt 	{  86, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* nPCE1 */
    894  1.3.2.3   yamt 	{ 102, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* nPCE1 */
    895  1.3.2.3   yamt 
    896  1.3.2.3   yamt 	{  54, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPCE2 */
    897  1.3.2.3   yamt 	{  78, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* nPCE2 */
    898  1.3.2.3   yamt 	{ 105, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* nPCE2 */
    899  1.3.2.3   yamt #endif
    900  1.3.2.3   yamt 
    901  1.3.2.3   yamt 	{  -1 }
    902  1.3.2.3   yamt };
    903  1.3.2.3   yamt 
    904  1.3.2.3   yamt struct pxa2x0_gpioconf pxa27x_pxaacu_gpioconf[] = {
    905  1.3.2.3   yamt 	{  28, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* BITCLK */
    906  1.3.2.3   yamt 	{  30, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* SDATA_OUT */
    907  1.3.2.3   yamt 
    908  1.3.2.3   yamt #if 0	/* We can select and/or. */
    909  1.3.2.3   yamt 	{  31, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* SYNC */
    910  1.3.2.3   yamt 	{  94, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* SYNC */
    911  1.3.2.3   yamt 
    912  1.3.2.3   yamt 	{  29, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* SDATA_IN0 */
    913  1.3.2.3   yamt 	{ 116, GPIO_CLR | GPIO_ALT_FN_2_IN },	/* SDATA_IN0 */
    914  1.3.2.3   yamt 
    915  1.3.2.3   yamt 	{  32, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* SDATA_IN1 */
    916  1.3.2.3   yamt 	{  99, GPIO_CLR | GPIO_ALT_FN_2_IN },	/* SDATA_IN1 */
    917  1.3.2.3   yamt 
    918  1.3.2.3   yamt 	{  95, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* RESET_n */
    919  1.3.2.3   yamt 	{ 113, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* RESET_n */
    920  1.3.2.3   yamt #endif
    921  1.3.2.3   yamt 
    922  1.3.2.3   yamt 	{  -1 }
    923  1.3.2.3   yamt };
    924  1.3.2.3   yamt 
    925  1.3.2.3   yamt struct pxa2x0_gpioconf pxa27x_pxamci_gpioconf[] = {
    926  1.3.2.3   yamt 	{  32, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* MMCLK */
    927  1.3.2.3   yamt 	{ 112, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* MMCMD */
    928  1.3.2.3   yamt 	{  92, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* MMDAT<0> */
    929  1.3.2.3   yamt 
    930  1.3.2.3   yamt #if 0	/* optional */
    931  1.3.2.3   yamt 	{ 109, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* MMDAT<1> */
    932  1.3.2.3   yamt 	{ 110, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* MMDAT<2>/MMCCS<0> */
    933  1.3.2.3   yamt 	{ 111, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* MMDAT<3>/MMCCS<1> */
    934  1.3.2.3   yamt #endif
    935  1.3.2.3   yamt 
    936  1.3.2.3   yamt 	{  -1 }
    937  1.3.2.3   yamt };
    938  1.3.2.3   yamt #endif
    939  1.3.2.3   yamt 
    940  1.3.2.3   yamt void
    941  1.3.2.3   yamt pxa2x0_gpio_config(struct pxa2x0_gpioconf **conflist)
    942  1.3.2.3   yamt {
    943  1.3.2.3   yamt 	int i, j;
    944  1.3.2.3   yamt 
    945  1.3.2.3   yamt 	for (i = 0; conflist[i] != NULL; i++)
    946  1.3.2.3   yamt 		for (j = 0; conflist[i][j].pin != -1; j++)
    947  1.3.2.3   yamt 			pxa2x0_gpio_set_function(conflist[i][j].pin,
    948  1.3.2.3   yamt 			    conflist[i][j].value);
    949  1.3.2.3   yamt }
    950