gxio.c revision 1.12 1 /* $NetBSD: gxio.c,v 1.12 2009/11/22 12:00:56 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.12 2009/11/22 12:00:56 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 #include <sys/kernel.h>
42
43 #include <sys/systm.h>
44
45 #include <machine/bootconfig.h>
46
47 #include <arm/xscale/pxa2x0cpu.h>
48 #include <arm/xscale/pxa2x0reg.h>
49 #include <arm/xscale/pxa2x0var.h>
50 #include <arm/xscale/pxa2x0_gpio.h>
51 #include <evbarm/gumstix/gumstixvar.h>
52
53 #include "locators.h"
54
55
56 struct gxioconf {
57 const char *name;
58 void (*config)(void);
59 };
60
61 static int gxiomatch(device_t, cfdata_t, void *);
62 static void gxioattach(device_t, device_t, void *);
63 static int gxiosearch(device_t, cfdata_t, const int *, void *);
64 static int gxioprint(void *, const char *);
65
66 void gxio_config_pin(void);
67 void gxio_config_expansion(char *);
68 static void gxio_config_gpio(const struct gxioconf *, char *);
69 static void basix_config(void);
70 static void cfstix_config(void);
71 static void etherstix_config(void);
72 static void netcf_config(void);
73 static void netduommc_config(void);
74 static void netduo_config(void);
75 static void netmicrosd_config(void);
76 static void netwifimicrosd_config(void);
77 static void netmmc_config(void);
78 static void wifistix_config(void);
79 static void wifistix_cf_config(void);
80
81 CFATTACH_DECL_NEW(
82 gxio, sizeof(struct gxio_softc), gxiomatch, gxioattach, NULL, NULL);
83
84 char busheader[MAX_BOOT_STRING];
85
86 #if defined(CPU_XSCALE_PXA250)
87 static struct pxa2x0_gpioconf pxa255dep_gpioconf[] = {
88 /* Bluetooth module configuration */
89 { 7, GPIO_OUT | GPIO_SET }, /* power on */
90 { 12, GPIO_ALT_FN_1_OUT }, /* 32kHz out. required by SingleStone */
91
92 /* AC97 configuration */
93 { 29, GPIO_ALT_FN_1_IN }, /* SDATA_IN0 */
94
95 /* FFUART configuration */
96 { 35, GPIO_ALT_FN_1_IN }, /* CTS */
97 { 41, GPIO_ALT_FN_2_OUT }, /* RTS */
98
99 #ifndef GXIO_BLUETOOTH_ON_HWUART
100 /* BTUART configuration */
101 { 44, GPIO_ALT_FN_1_IN }, /* BTCTS */
102 { 45, GPIO_ALT_FN_2_OUT }, /* BTRTS */
103 #else
104 /* HWUART configuration */
105 { 42, GPIO_ALT_FN_3_IN }, /* HWRXD */
106 { 43, GPIO_ALT_FN_3_OUT }, /* HWTXD */
107 { 44, GPIO_ALT_FN_3_IN }, /* HWCTS */
108 { 45, GPIO_ALT_FN_3_OUT }, /* HWRTS */
109 #endif
110
111 #ifndef GXIO_BLUETOOTH_ON_HWUART
112 /* HWUART configuration */
113 { 48, GPIO_ALT_FN_1_OUT }, /* HWTXD */
114 { 49, GPIO_ALT_FN_1_IN }, /* HWRXD */
115 { 50, GPIO_ALT_FN_1_IN }, /* HWCTS */
116 { 51, GPIO_ALT_FN_1_OUT }, /* HWRTS */
117 #endif
118
119 { -1 }
120 };
121 #endif
122 #if defined(CPU_XSCALE_PXA270)
123 static struct pxa2x0_gpioconf verdexdep_gpioconf[] = {
124 /* Bluetooth module configuration */
125 { 9, GPIO_ALT_FN_3_OUT }, /* CHOUT<0> */
126
127 /* LCD configuration */
128 { 17, GPIO_IN }, /* backlight on */
129
130 /* FFUART configuration */
131 { 27, GPIO_ALT_FN_3_OUT }, /* FFRTS */
132 { 34, GPIO_ALT_FN_1_IN }, /* FFRXD */
133 { 39, GPIO_ALT_FN_2_OUT }, /* FFTXD */
134 { 100, GPIO_ALT_FN_3_IN }, /* FFCTS */
135
136 /* BTUART configuration */
137 { 42, GPIO_ALT_FN_1_IN }, /* BTRXD */
138 { 43, GPIO_ALT_FN_2_OUT }, /* BTTXD */
139 { 44, GPIO_ALT_FN_1_IN }, /* BTCTS */
140 { 45, GPIO_ALT_FN_2_OUT }, /* BTRTS */
141
142 /* AC97 configuration */
143 { 29, GPIO_ALT_FN_1_IN }, /* SDATA_IN0 */
144
145 { -1 }
146 };
147 #endif
148
149 static const struct gxioconf busheader_conf[] = {
150 { "basix", basix_config },
151 { "cfstix", cfstix_config },
152 { "etherstix", etherstix_config },
153 { "netcf", netcf_config },
154 { "netcf-vx", netcf_config },
155 { "netduo-mmc", netduommc_config },
156 { "netduo", netduo_config },
157 { "netmicrosd", netmicrosd_config },
158 { "netmicrosd-vx", netmicrosd_config },
159 { "netwifimicrosd", netwifimicrosd_config },
160 { "netmmc", netmmc_config },
161 { "netpro-vx", netwifimicrosd_config },
162 { "wifistix-cf", wifistix_cf_config },
163 { "wifistix", wifistix_config },
164 { NULL }
165 };
166
167 int gxpcic_gpio_reset;
168 struct gxpcic_slot_irqs gxpcic_slot_irqs[2] = { { 0, -1, -1 }, { 0, -1, -1 } };
169
170
171 /* ARGSUSED */
172 static int
173 gxiomatch(device_t parent, cfdata_t match, void *aux)
174 {
175 struct pxaip_attach_args *pxa = aux;
176 bus_space_tag_t iot = &pxa2x0_bs_tag;
177 bus_space_handle_t ioh;
178
179 if (strcmp(pxa->pxa_name, match->cf_name) != 0 ||
180 pxa->pxa_addr != PXAIPCF_ADDR_DEFAULT)
181 return 0;
182
183 if (bus_space_map(iot,
184 PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 0, &ioh))
185 return (0);
186 bus_space_unmap(iot, ioh, PXA2X0_MEMCTL_SIZE);
187
188 /* nothing */
189 return (1);
190 }
191
192 /* ARGSUSED */
193 static void
194 gxioattach(device_t parent, device_t self, void *aux)
195 {
196 struct gxio_softc *sc = device_private(self);
197
198 aprint_normal("\n");
199 aprint_naive("\n");
200
201 sc->sc_dev = self;
202 sc->sc_iot = &pxa2x0_bs_tag;
203
204 if (bus_space_map(sc->sc_iot,
205 PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 0, &sc->sc_ioh))
206 return;
207
208 /*
209 * Attach each gumstix expansion of busheader side devices
210 */
211 config_search_ia(gxiosearch, self, "gxio", NULL);
212 }
213
214 /* ARGSUSED */
215 static int
216 gxiosearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
217 {
218 struct gxio_softc *sc = device_private(parent);
219 struct gxio_attach_args gxa;
220
221 gxa.gxa_sc = sc;
222 gxa.gxa_iot = sc->sc_iot;
223 gxa.gxa_addr = cf->cf_loc[GXIOCF_ADDR];
224 gxa.gxa_gpirq = cf->cf_loc[GXIOCF_GPIRQ];
225
226 if (config_match(parent, cf, &gxa))
227 config_attach(parent, cf, &gxa, gxioprint);
228
229 return (0);
230 }
231
232 /* ARGSUSED */
233 static int
234 gxioprint(void *aux, const char *name)
235 {
236 struct gxio_attach_args *gxa = (struct gxio_attach_args *)aux;
237
238 if (gxa->gxa_addr != GXIOCF_ADDR_DEFAULT)
239 printf(" addr 0x%lx", gxa->gxa_addr);
240 if (gxa->gxa_gpirq > 0)
241 printf(" gpirq %d", gxa->gxa_gpirq);
242 return (UNCONF);
243 }
244
245
246 /*
247 * configure for GPIO pin and expansion boards.
248 */
249 void
250 gxio_config_pin(void)
251 {
252 #if defined(CPU_XSCALE_PXA250)
253 struct pxa2x0_gpioconf *gumstix_gpioconf[] = {
254 pxa25x_com_ffuart_gpioconf,
255 pxa25x_com_stuart_gpioconf,
256 #ifndef GXIO_BLUETOOTH_ON_HWUART
257 pxa25x_com_btuart_gpioconf,
258 #endif
259 pxa25x_com_hwuart_gpioconf,
260 pxa25x_i2c_gpioconf,
261 pxa25x_pxaacu_gpioconf,
262 pxa255dep_gpioconf,
263 NULL
264 };
265 #endif
266 #if defined(CPU_XSCALE_PXA270)
267 struct pxa2x0_gpioconf *verdex_gpioconf[] = {
268 pxa27x_com_ffuart_gpioconf,
269 pxa27x_com_stuart_gpioconf,
270 pxa27x_com_btuart_gpioconf,
271 pxa27x_i2c_gpioconf,
272 pxa27x_pxaacu_gpioconf,
273 pxa27x_pxamci_gpioconf,
274 pxa27x_ohci_gpioconf,
275 verdexdep_gpioconf,
276 NULL
277 };
278 #endif
279
280 /* XXX: turn off for power of bluetooth module */
281 pxa2x0_gpio_set_function(7, GPIO_OUT | GPIO_CLR);
282 delay(100);
283
284 #if defined(CPU_XSCALE_PXA270) && defined(CPU_XSCALE_PXA250)
285 pxa2x0_gpio_config(
286 (CPU_IS_PXA250) ? gumstix_gpioconf : verdex_gpioconf);
287 #else
288 #if defined(CPU_XSCALE_PXA270)
289 pxa2x0_gpio_config(verdex_gpioconf);
290 #else
291 pxa2x0_gpio_config(gumstix_gpioconf);
292 #endif
293 #endif
294 }
295
296 void
297 gxio_config_expansion(char *expansion)
298 {
299
300 if (expansion == NULL) {
301 printf("not specified 'busheader=' in the boot args.\n");
302 #ifdef GXIO_DEFAULT_EXPANSION
303 printf("configure default expansion (%s)\n",
304 GXIO_DEFAULT_EXPANSION);
305 expansion = __UNCONST(GXIO_DEFAULT_EXPANSION);
306 #else
307 return;
308 #endif
309 }
310 gxio_config_gpio(busheader_conf, expansion);
311 }
312
313 static void
314 gxio_config_gpio(const struct gxioconf *gxioconflist, char *expansion)
315 {
316 int i, rv;
317
318 for (i = 0; i < strlen(expansion); i++)
319 expansion[i] = tolower(expansion[i]);
320 for (i = 0; gxioconflist[i].name != NULL; i++) {
321 rv = strncmp(expansion, gxioconflist[i].name,
322 strlen(gxioconflist[i].name) + 1);
323 if (rv == 0) {
324 gxioconflist[i].config();
325 break;
326 }
327 }
328 }
329
330
331 static void
332 basix_config(void)
333 {
334
335 pxa2x0_gpio_set_function(8, GPIO_ALT_FN_1_OUT); /* MMCCS0 */
336 pxa2x0_gpio_set_function(53, GPIO_ALT_FN_1_OUT); /* MMCCLK */
337 #if 0
338 /* this configuration set by gxmci.c::pxamci_attach() */
339 pxa2x0_gpio_set_function(11, GPIO_IN); /* nSD_DETECT */
340 pxa2x0_gpio_set_function(22, GPIO_IN); /* nSD_WP */
341 #endif
342 }
343
344 static void
345 cfstix_config(void)
346 {
347 u_int gpio, npoe_fn;
348 #if defined(CPU_XSCALE_PXA270) && defined(CPU_XSCALE_PXA250)
349 int bvd = (CPU_IS_PXA250) ? 4 : 111;
350 #else
351 #if defined(CPU_XSCALE_PXA270)
352 const int bvd = 111;
353 #else
354 const int bvd = 4;
355 #endif
356 #endif
357
358 if (CPU_IS_PXA250) {
359 gxpcic_slot_irqs[0].valid = 1;
360 gxpcic_slot_irqs[0].cd = 11;
361 gxpcic_slot_irqs[0].prdy = 26;
362 gxpcic_gpio_reset = 8;
363 } else {
364 gxpcic_slot_irqs[0].valid = 1;
365 gxpcic_slot_irqs[0].cd = 104;
366 gxpcic_slot_irqs[0].prdy = 96;
367 gxpcic_gpio_reset = 97;
368 }
369
370 #if 1
371 /* PCD/PRDY set by pxa2x0_pcic.c::pxapcic_attach_common() */
372 #else
373 pxa2x0_gpio_set_function(11, GPIO_IN); /* PCD1 */
374 pxa2x0_gpio_set_function(26, GPIO_IN); /* PRDY1/~IRQ1 */
375 #endif
376 pxa2x0_gpio_set_function(bvd, GPIO_IN); /* BVD1/~STSCHG1 */
377
378 for (gpio = 48, npoe_fn = 0; gpio <= 53 ; gpio++)
379 npoe_fn |= pxa2x0_gpio_get_function(gpio);
380 npoe_fn &= GPIO_SET;
381
382 pxa2x0_gpio_set_function(48, GPIO_ALT_FN_2_OUT | npoe_fn); /* nPOE */
383 pxa2x0_gpio_set_function(49, GPIO_ALT_FN_2_OUT); /* nPWE */
384 pxa2x0_gpio_set_function(50, GPIO_ALT_FN_2_OUT); /* nPIOR */
385 pxa2x0_gpio_set_function(51, GPIO_ALT_FN_2_OUT); /* nPIOW */
386 if (CPU_IS_PXA250) {
387 pxa2x0_gpio_set_function(52, GPIO_ALT_FN_2_OUT); /* nPCE1 */
388 pxa2x0_gpio_set_function(53, GPIO_ALT_FN_2_OUT); /* nPCE2 */
389 pxa2x0_gpio_set_function(54, GPIO_ALT_FN_2_OUT); /* pSKTSEL */
390 } else {
391 pxa2x0_gpio_set_function(102, GPIO_ALT_FN_1_OUT); /* nPCE1 */
392 pxa2x0_gpio_set_function(105, GPIO_ALT_FN_1_OUT); /* nPCE2 */
393 pxa2x0_gpio_set_function(79, GPIO_ALT_FN_1_OUT); /* pSKTSEL */
394 }
395 pxa2x0_gpio_set_function(55, GPIO_ALT_FN_2_OUT); /* nPREG */
396 pxa2x0_gpio_set_function(56, GPIO_ALT_FN_1_IN); /* nPWAIT */
397 pxa2x0_gpio_set_function(57, GPIO_ALT_FN_1_IN); /* nIOIS16 */
398 }
399
400 static void
401 etherstix_config(void)
402 {
403 extern struct cfdata cfdata[];
404 #if defined(CPU_XSCALE_PXA270) && defined(CPU_XSCALE_PXA250)
405 int rst = (CPU_IS_PXA250) ? 80 : 32;
406 int irq = (CPU_IS_PXA250) ? 36 : 99;
407 #else
408 #if defined(CPU_XSCALE_PXA270)
409 const int rst = 32, irq = 99;
410 #else
411 const int rst = 80, irq = 36;
412 #endif
413 #endif
414 int i;
415
416 pxa2x0_gpio_set_function(49, GPIO_ALT_FN_2_OUT); /* nPWE */
417 pxa2x0_gpio_set_function(15, GPIO_ALT_FN_2_OUT); /* nCS 1 */
418 pxa2x0_gpio_set_function(rst, GPIO_OUT | GPIO_SET); /* RESET 1 */
419 delay(1);
420 pxa2x0_gpio_set_function(rst, GPIO_OUT | GPIO_CLR);
421 delay(50000);
422
423 for (i = 0; cfdata[i].cf_name != NULL; i++)
424 if (strcmp(cfdata[i].cf_name, "sm") == 0 &&
425 strcmp(cfdata[i].cf_atname, "sm_gxio") == 0 &&
426 cfdata[i].cf_loc[GXIOCF_ADDR] == 0x04000300 &&
427 cfdata[i].cf_loc[GXIOCF_GPIRQ] == GXIOCF_GPIRQ_DEFAULT)
428 cfdata[i].cf_loc[GXIOCF_GPIRQ] = irq;
429 }
430
431 static void
432 netcf_config(void)
433 {
434
435 etherstix_config();
436 cfstix_config();
437 if (CPU_IS_PXA270) {
438 /* Overwrite */
439 gxpcic_slot_irqs[0].cd = 104;
440 gxpcic_slot_irqs[0].prdy = 109;
441 gxpcic_gpio_reset = 110;
442 };
443 }
444
445 static void
446 netduommc_config(void)
447 {
448
449 netduo_config();
450 basix_config();
451 }
452
453 static void
454 netduo_config(void)
455 {
456
457 etherstix_config();
458
459 pxa2x0_gpio_set_function(78, GPIO_ALT_FN_2_OUT); /* nCS 2 */
460 pxa2x0_gpio_set_function(52, GPIO_OUT | GPIO_SET); /* RESET 2 */
461 delay(1);
462 pxa2x0_gpio_set_function(52, GPIO_OUT | GPIO_CLR);
463 delay(50000);
464 }
465
466 static void
467 netmicrosd_config(void)
468 {
469
470 /* MicroSD(mci) always configure on PXA270 */
471
472 pxa2x0_gpio_set_function(49, GPIO_ALT_FN_2_OUT); /* nPWE */
473 pxa2x0_gpio_set_function(15, GPIO_ALT_FN_2_OUT); /* nCS 1 */
474 pxa2x0_gpio_set_function(107, GPIO_OUT | GPIO_CLR); /* RESET 1 */
475 delay(hz / 2);
476 pxa2x0_gpio_set_function(107, GPIO_OUT | GPIO_SET);
477 delay(50000);
478 }
479
480 static void
481 netwifimicrosd_config(void)
482 {
483
484 netmicrosd_config();
485
486 cfstix_config();
487 /* However use pxamci. */
488 pxa2x0_gpio_set_function(111, GPIO_CLR | GPIO_ALT_FN_1_IN);
489 /* Power to Marvell 88W8385 */
490 pxa2x0_gpio_set_function(80, GPIO_OUT | GPIO_SET);
491 }
492
493 static void
494 netmmc_config(void)
495 {
496
497 etherstix_config();
498 basix_config();
499 }
500
501 static void
502 wifistix_config(void)
503 {
504
505 cfstix_config();
506
507 /* Power to Marvell 88W8385 */
508 pxa2x0_gpio_set_function(80, GPIO_OUT | GPIO_SET);
509 }
510
511 static void
512 wifistix_cf_config(void)
513 {
514
515 gxpcic_slot_irqs[1].valid = 1;
516 gxpcic_slot_irqs[1].cd = 36;
517 gxpcic_slot_irqs[1].prdy = 27;
518
519 #if 1
520 /* this configuration set by pxa2x0_pcic.c::pxapcic_attach_common() */
521 #else
522 pxa2x0_gpio_set_function(36, GPIO_IN); /* PCD2 */
523 pxa2x0_gpio_set_function(27, GPIO_IN); /* PRDY2/~IRQ2 */
524 #endif
525 pxa2x0_gpio_set_function(18, GPIO_IN); /* BVD2/~STSCHG2 */
526
527 cfstix_config();
528
529 /* Power to Marvell 88W8385 */
530 pxa2x0_gpio_set_function(80, GPIO_OUT | GPIO_SET);
531 }
532