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