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