Home | History | Annotate | Line # | Download | only in gumstix
gxio.c revision 1.5
      1 /*	$NetBSD: gxio.c,v 1.5 2007/08/21 11:39:11 kiyohara Exp $ */
      2 /*
      3  * Copyright (C) 2005, 2006, 2007 WIDE Project and SOUM Corporation.
      4  * All rights reserved.
      5  *
      6  * Written by Takashi Kiyohara and Susumu Miki for WIDE Project and SOUM
      7  * Corporation.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. Neither the name of the project nor the name of SOUM Corporation
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT and SOUM CORPORATION ``AS IS''
     22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT AND SOUM CORPORATION
     25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  * POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: gxio.c,v 1.5 2007/08/21 11:39:11 kiyohara Exp $");
     35 
     36 #include "opt_gxio.h"
     37 
     38 #include <sys/param.h>
     39 #include <sys/device.h>
     40 #include <sys/errno.h>
     41 
     42 #include <sys/systm.h>
     43 
     44 #include <machine/bootconfig.h>
     45 
     46 #include <arm/xscale/pxa2x0cpu.h>
     47 #include <arm/xscale/pxa2x0reg.h>
     48 #include <arm/xscale/pxa2x0var.h>
     49 #include <arm/xscale/pxa2x0_gpio.h>
     50 #include <evbarm/gumstix/gumstixvar.h>
     51 
     52 #include "locators.h"
     53 
     54 
     55 struct gxioconf {
     56 	const char *name;
     57 	void (*config)(void);
     58 };
     59 
     60 static int gxiomatch(struct device *, struct cfdata *, void *);
     61 static void gxioattach(struct device *, struct device *, void *);
     62 static int gxiosearch(struct device *, struct cfdata *, const int *, void *);
     63 static int gxioprint(void *, const char *);
     64 
     65 void gxio_config_pin(void);
     66 void gxio_config_busheader(char *);
     67 static void gxio_config_gpio(const struct gxioconf *, char *);
     68 static void cfstix_config(void);
     69 static void etherstix_config(void);
     70 static void netcf_config(void);
     71 static void netduommc_config(void);
     72 static void netduo_config(void);
     73 static void netmmc_config(void);
     74 static void wifistix_cf_config(void);
     75 
     76 CFATTACH_DECL(
     77     gxio, sizeof(struct gxio_softc), gxiomatch, gxioattach, NULL, NULL);
     78 
     79 char busheader[MAX_BOOT_STRING];
     80 
     81 static struct pxa2x0_gpioconf boarddep_gpioconf[] = {
     82 	/* Bluetooth module configuration */
     83 	{  7, GPIO_OUT | GPIO_SET },	/* power on */
     84 	{ 12, GPIO_ALT_FN_1_OUT },	/* 32kHz out. required by SingleStone */
     85 
     86 	/* AC97 configuration */
     87 	{ 29, GPIO_CLR | GPIO_ALT_FN_1_IN },	/* SDATA_IN0 */
     88 
     89 	/* FFUART configuration : is connected only TXD/RXD */
     90 	{ 34, GPIO_ALT_FN_1_IN },	/* FFRXD */
     91 	{ 39, GPIO_ALT_FN_2_OUT },	/* FFTXD */
     92 
     93 #ifndef GXIO_BLUETOOTH_ON_HWUART
     94 	/* BTUART configuration */
     95 	{ 44, GPIO_ALT_FN_1_IN },	/* BTCST */
     96 	{ 45, GPIO_ALT_FN_2_OUT },	/* BTRST */
     97 #else
     98 	/* HWUART configuration */
     99 	{ 42, GPIO_ALT_FN_3_IN },	/* HWRXD */
    100 	{ 43, GPIO_ALT_FN_3_OUT },	/* HWTXD */
    101 	{ 44, GPIO_ALT_FN_3_IN },	/* HWCST */
    102 	{ 45, GPIO_ALT_FN_3_OUT },	/* HWRST */
    103 #endif
    104 
    105 #ifndef GXIO_BLUETOOTH_ON_HWUART
    106 	/* HWUART configuration */
    107 	{ 48, GPIO_ALT_FN_1_OUT },	/* HWTXD */
    108 	{ 49, GPIO_ALT_FN_1_IN },	/* HWRXD */
    109 	{ 50, GPIO_ALT_FN_1_IN },	/* HWCTS */
    110 	{ 51, GPIO_ALT_FN_1_OUT },	/* HWRTS */
    111 #endif
    112 
    113 	{ -1 }
    114 };
    115 
    116 static const struct gxioconf busheader_conf[] = {
    117 	{ "cfstix",		cfstix_config },
    118 	{ "etherstix",		etherstix_config },
    119 	{ "netcf",		netcf_config },
    120 	{ "netduo-mmc",		netduommc_config },
    121 	{ "netduo",		netduo_config },
    122 	{ "netmmc",		netmmc_config },
    123 	{ "wifistix-cf",	wifistix_cf_config },
    124 	{ "wifistix",		cfstix_config },
    125 	{ NULL }
    126 };
    127 
    128 
    129 /* ARGSUSED */
    130 static int
    131 gxiomatch(struct device *parent, struct cfdata *match, void *aux)
    132 {
    133 	bus_space_tag_t iot = &pxa2x0_bs_tag;
    134 	bus_space_handle_t ioh;
    135 
    136 	if (bus_space_map(iot,
    137 	    PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 0, &ioh))
    138 		return (0);
    139 	bus_space_unmap(iot, ioh, PXA2X0_MEMCTL_SIZE);
    140 
    141 	/* nothing */
    142 	return (1);
    143 }
    144 
    145 /* ARGSUSED */
    146 static void
    147 gxioattach(struct device *parent, struct device *self, void *aux)
    148 {
    149 	struct gxio_softc *sc = device_private(self);
    150 
    151 	aprint_normal("\n");
    152 	aprint_naive("\n");
    153 
    154 	sc->sc_iot = &pxa2x0_bs_tag;
    155 
    156 	if (bus_space_map(sc->sc_iot,
    157 	    PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 0, &sc->sc_ioh))
    158 		return;
    159 
    160 	/*
    161 	 *  Attach each gumstix expansion of busheader side devices
    162 	 */
    163 	config_search_ia(gxiosearch, self, "gxio", NULL);
    164 }
    165 
    166 /* ARGSUSED */
    167 static int
    168 gxiosearch(
    169     struct device *parent, struct cfdata *cf, const int *ldesc, void *aux)
    170 {
    171 	struct gxio_softc *sc = device_private(parent);
    172 	struct gxio_attach_args gxa;
    173 
    174 	gxa.gxa_sc = sc;
    175 	gxa.gxa_iot = sc->sc_iot;
    176 	gxa.gxa_addr = cf->cf_loc[GXIOCF_ADDR];
    177 	gxa.gxa_gpirq = cf->cf_loc[GXIOCF_GPIRQ];
    178 
    179 	if (config_match(parent, cf, &gxa))
    180 		config_attach(parent, cf, &gxa, gxioprint);
    181 
    182 	return (0);
    183 }
    184 
    185 /* ARGSUSED */
    186 static int
    187 gxioprint(void *aux, const char *name)
    188 {
    189 	struct gxio_attach_args *gxa = (struct gxio_attach_args *)aux;
    190 
    191 	if (gxa->gxa_addr != GXIOCF_ADDR_DEFAULT)
    192 		printf(" addr 0x%lx", gxa->gxa_addr);
    193 	if (gxa->gxa_gpirq > 0)
    194 		printf(" gpirq %d", gxa->gxa_gpirq);
    195 	return (UNCONF);
    196 }
    197 
    198 
    199 /*
    200  * configure for GPIO pin and expansion boards.
    201  */
    202 void
    203 gxio_config_pin()
    204 {
    205 	struct pxa2x0_gpioconf *gumstix_gpioconf[] = {
    206 		pxa25x_com_ffuart_gpioconf,
    207 		pxa25x_com_stuart_gpioconf,
    208 #ifndef GXIO_BLUETOOTH_ON_HWUART
    209 		pxa25x_com_btuart_gpioconf,
    210 #endif
    211 		pxa25x_com_hwuart_gpioconf,
    212 		pxa25x_i2c_gpioconf,
    213 		pxa25x_pxaacu_gpioconf,
    214 		boarddep_gpioconf,
    215 		NULL
    216 	};
    217 
    218 	/* XXX: turn off for power of bluetooth module */
    219 	pxa2x0_gpio_set_function(7, GPIO_OUT | GPIO_CLR);
    220 	delay(100);
    221 
    222 	pxa2x0_gpio_config(gumstix_gpioconf);
    223 }
    224 
    225 void
    226 gxio_config_busheader(char *expansion)
    227 {
    228 
    229 	gxio_config_gpio(busheader_conf, expansion);
    230 }
    231 
    232 static void
    233 gxio_config_gpio(const struct gxioconf *gxioconflist, char *expansion)
    234 {
    235 	int i, rv;
    236 
    237 	for (i = 0; i < strlen(expansion); i++)
    238 		expansion[i] = tolower(expansion[i]);
    239 	for (i = 0; gxioconflist[i].name != NULL; i++) {
    240 		rv = strncmp(expansion, gxioconflist[i].name,
    241 		    strlen(gxioconflist[i].name) + 1);
    242 		if (rv == 0) {
    243 			gxioconflist[i].config();
    244 			break;
    245 		}
    246 	}
    247 }
    248 
    249 
    250 static void
    251 cfstix_config()
    252 {
    253 	u_int gpio, npoe_fn;
    254 
    255 #if 1
    256 	/* this configuration set by pxapcic_attach_common()::pxa2x0_pcic.c */
    257 #else
    258 	pxa2x0_gpio_set_function(11, GPIO_IN);		/* PCD1 */
    259 	pxa2x0_gpio_set_function(26, GPIO_IN);		/* PRDY1/~IRQ1 */
    260 #endif
    261 	pxa2x0_gpio_set_function(4, GPIO_IN); 		/* BVD1/~STSCHG1 */
    262 
    263 	for (gpio = 48, npoe_fn = 0; gpio <= 53 ; gpio++)
    264 		npoe_fn |= pxa2x0_gpio_get_function(gpio);
    265 	npoe_fn &= GPIO_SET;
    266 
    267 	pxa2x0_gpio_set_function(48, GPIO_ALT_FN_2_OUT | npoe_fn); /* nPOE */
    268 	pxa2x0_gpio_set_function(49, GPIO_ALT_FN_2_OUT);	/* nPWE */
    269 	pxa2x0_gpio_set_function(50, GPIO_ALT_FN_2_OUT);	/* nPIOR */
    270 	pxa2x0_gpio_set_function(51, GPIO_ALT_FN_2_OUT);	/* nPIOW */
    271 	pxa2x0_gpio_set_function(52, GPIO_ALT_FN_2_OUT);	/* nPCE1 */
    272 	pxa2x0_gpio_set_function(53, GPIO_ALT_FN_2_OUT);	/* nPCE2 */
    273 	pxa2x0_gpio_set_function(54, GPIO_ALT_FN_2_OUT);	/* pSKTSEL */
    274 	pxa2x0_gpio_set_function(55, GPIO_ALT_FN_2_OUT);	/* nPREG */
    275 	pxa2x0_gpio_set_function(56, GPIO_ALT_FN_1_IN);		/* nPWAIT */
    276 	pxa2x0_gpio_set_function(57, GPIO_ALT_FN_1_IN);		/* nIOIS16 */
    277 }
    278 
    279 static void
    280 etherstix_config()
    281 {
    282 
    283 	pxa2x0_gpio_set_function(49, GPIO_ALT_FN_2_OUT);	/* nPWE */
    284 	pxa2x0_gpio_set_function(15, GPIO_ALT_FN_2_OUT);	/* nCS 1 */
    285 	pxa2x0_gpio_set_function(80, GPIO_OUT | GPIO_SET);	/* RESET 1 */
    286 	delay(1);
    287 	pxa2x0_gpio_set_function(80, GPIO_OUT | GPIO_CLR);
    288 	delay(50000);
    289 }
    290 
    291 static void
    292 netcf_config()
    293 {
    294 
    295 	etherstix_config();
    296 	cfstix_config();
    297 }
    298 
    299 static void
    300 netduommc_config()
    301 {
    302 
    303 	netduo_config();
    304 
    305 	/* mmc not yet... */
    306 }
    307 
    308 static void
    309 netduo_config()
    310 {
    311 
    312 	etherstix_config();
    313 
    314 	pxa2x0_gpio_set_function(78, GPIO_ALT_FN_2_OUT);	/* nCS 2 */
    315 	pxa2x0_gpio_set_function(52, GPIO_OUT | GPIO_SET);	/* RESET 2 */
    316 	delay(1);
    317 	pxa2x0_gpio_set_function(52, GPIO_OUT | GPIO_CLR);
    318 	delay(50000);
    319 }
    320 
    321 static void
    322 netmmc_config()
    323 {
    324 
    325 	etherstix_config();
    326 
    327 	/* mmc not yet... */
    328 }
    329 
    330 static void
    331 wifistix_cf_config()
    332 {
    333 
    334 #if 1
    335 	/* this configuration set by pxapcic_attach_common()::pxa2x0_pcic.c */
    336 #else
    337 	pxa2x0_gpio_set_function(36, GPIO_IN);		/* PCD2 */
    338 	pxa2x0_gpio_set_function(27, GPIO_IN);		/* PRDY2/~IRQ2 */
    339 #endif
    340 	pxa2x0_gpio_set_function(18, GPIO_IN); 		/* BVD2/~STSCHG2 */
    341 
    342 	cfstix_config();
    343 }
    344