gxio.c revision 1.13.2.1 1 /* $NetBSD: gxio.c,v 1.13.2.1 2010/04/30 14:39:15 uebayasi 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.13.2.1 2010/04/30 14:39:15 uebayasi 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 netcf_vx_config(void);
74 static void netduommc_config(void);
75 static void netduo_config(void);
76 static void netmicrosd_config(void);
77 static void netwifimicrosd_config(void);
78 static void netmmc_config(void);
79 static void wifistix_config(void);
80 static void wifistix_cf_config(void);
81
82 CFATTACH_DECL_NEW(
83 gxio, sizeof(struct gxio_softc), gxiomatch, gxioattach, NULL, NULL);
84
85 char busheader[MAX_BOOT_STRING];
86
87 #if defined(CPU_XSCALE_PXA250)
88 static struct pxa2x0_gpioconf pxa255dep_gpioconf[] = {
89 /* Bluetooth module configuration */
90 { 7, GPIO_OUT | GPIO_SET }, /* power on */
91 { 12, GPIO_ALT_FN_1_OUT }, /* 32kHz out. required by SingleStone */
92
93 /* AC97 configuration */
94 { 29, GPIO_ALT_FN_1_IN }, /* SDATA_IN0 */
95
96 /* FFUART configuration */
97 { 35, GPIO_ALT_FN_1_IN }, /* CTS */
98 { 41, GPIO_ALT_FN_2_OUT }, /* RTS */
99
100 #ifndef GXIO_BLUETOOTH_ON_HWUART
101 /* BTUART configuration */
102 { 44, GPIO_ALT_FN_1_IN }, /* BTCTS */
103 { 45, GPIO_ALT_FN_2_OUT }, /* BTRTS */
104 #else
105 /* HWUART configuration */
106 { 42, GPIO_ALT_FN_3_IN }, /* HWRXD */
107 { 43, GPIO_ALT_FN_3_OUT }, /* HWTXD */
108 { 44, GPIO_ALT_FN_3_IN }, /* HWCTS */
109 { 45, GPIO_ALT_FN_3_OUT }, /* HWRTS */
110 #endif
111
112 #ifndef GXIO_BLUETOOTH_ON_HWUART
113 /* HWUART configuration */
114 { 48, GPIO_ALT_FN_1_OUT }, /* HWTXD */
115 { 49, GPIO_ALT_FN_1_IN }, /* HWRXD */
116 { 50, GPIO_ALT_FN_1_IN }, /* HWCTS */
117 { 51, GPIO_ALT_FN_1_OUT }, /* HWRTS */
118 #endif
119
120 { -1 }
121 };
122 #endif
123 #if defined(CPU_XSCALE_PXA270)
124 static struct pxa2x0_gpioconf verdexdep_gpioconf[] = {
125 /* Bluetooth module configuration */
126 { 9, GPIO_ALT_FN_3_OUT }, /* CHOUT<0> */
127 { 12, GPIO_OUT | GPIO_SET },
128
129 /* LCD configuration */
130 { 17, GPIO_IN }, /* backlight on */
131
132 /* FFUART configuration */
133 { 34, GPIO_ALT_FN_1_IN }, /* FFRXD */
134 { 39, GPIO_ALT_FN_2_OUT }, /* FFTXD */
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_vx_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 #if defined(CPU_XSCALE_PXA250)
282 pxa2x0_gpio_set_function(7, GPIO_OUT | GPIO_CLR);
283 #elif defined(CPU_XSCALE_PXA270)
284 pxa2x0_gpio_set_function(12, GPIO_OUT | GPIO_CLR);
285 #endif
286 delay(100);
287
288 #if defined(CPU_XSCALE_PXA270) && defined(CPU_XSCALE_PXA250)
289 pxa2x0_gpio_config(
290 (CPU_IS_PXA250) ? gumstix_gpioconf : verdex_gpioconf);
291 #else
292 #if defined(CPU_XSCALE_PXA270)
293 pxa2x0_gpio_config(verdex_gpioconf);
294 #else
295 pxa2x0_gpio_config(gumstix_gpioconf);
296 #endif
297 #endif
298 }
299
300 void
301 gxio_config_expansion(char *expansion)
302 {
303
304 if (expansion == NULL) {
305 printf("not specified 'busheader=' in the boot args.\n");
306 #ifdef GXIO_DEFAULT_EXPANSION
307 printf("configure default expansion (%s)\n",
308 GXIO_DEFAULT_EXPANSION);
309 expansion = __UNCONST(GXIO_DEFAULT_EXPANSION);
310 #else
311 return;
312 #endif
313 }
314 gxio_config_gpio(busheader_conf, expansion);
315 }
316
317 static void
318 gxio_config_gpio(const struct gxioconf *gxioconflist, char *expansion)
319 {
320 int i, rv;
321
322 for (i = 0; i < strlen(expansion); i++)
323 expansion[i] = tolower(expansion[i]);
324 for (i = 0; gxioconflist[i].name != NULL; i++) {
325 rv = strncmp(expansion, gxioconflist[i].name,
326 strlen(gxioconflist[i].name) + 1);
327 if (rv == 0) {
328 gxioconflist[i].config();
329 break;
330 }
331 }
332 }
333
334
335 static void
336 basix_config(void)
337 {
338
339 pxa2x0_gpio_set_function(8, GPIO_ALT_FN_1_OUT); /* MMCCS0 */
340 pxa2x0_gpio_set_function(53, GPIO_ALT_FN_1_OUT); /* MMCCLK */
341 #if 0
342 /* this configuration set by gxmci.c::pxamci_attach() */
343 pxa2x0_gpio_set_function(11, GPIO_IN); /* nSD_DETECT */
344 pxa2x0_gpio_set_function(22, GPIO_IN); /* nSD_WP */
345 #endif
346 }
347
348 static void
349 cfstix_config(void)
350 {
351 u_int gpio, npoe_fn;
352 #if defined(CPU_XSCALE_PXA270) && defined(CPU_XSCALE_PXA250)
353 int bvd = (CPU_IS_PXA250) ? 4 : 111;
354 #else
355 #if defined(CPU_XSCALE_PXA270)
356 const int bvd = 111;
357 #else
358 const int bvd = 4;
359 #endif
360 #endif
361
362 if (CPU_IS_PXA250) {
363 gxpcic_slot_irqs[0].valid = 1;
364 gxpcic_slot_irqs[0].cd = 11;
365 gxpcic_slot_irqs[0].prdy = 26;
366 gxpcic_gpio_reset = 8;
367 } else {
368 gxpcic_slot_irqs[0].valid = 1;
369 gxpcic_slot_irqs[0].cd = 104;
370 gxpcic_slot_irqs[0].prdy = 96;
371 gxpcic_gpio_reset = 97;
372 }
373
374 #if 1
375 /* PCD/PRDY set by pxa2x0_pcic.c::pxapcic_attach_common() */
376 #else
377 pxa2x0_gpio_set_function(11, GPIO_IN); /* PCD1 */
378 pxa2x0_gpio_set_function(26, GPIO_IN); /* PRDY1/~IRQ1 */
379 #endif
380 pxa2x0_gpio_set_function(bvd, GPIO_IN); /* BVD1/~STSCHG1 */
381
382 for (gpio = 48, npoe_fn = 0; gpio <= 53 ; gpio++)
383 npoe_fn |= pxa2x0_gpio_get_function(gpio);
384 npoe_fn &= GPIO_SET;
385
386 pxa2x0_gpio_set_function(48, GPIO_ALT_FN_2_OUT | npoe_fn); /* nPOE */
387 pxa2x0_gpio_set_function(49, GPIO_ALT_FN_2_OUT); /* nPWE */
388 pxa2x0_gpio_set_function(50, GPIO_ALT_FN_2_OUT); /* nPIOR */
389 pxa2x0_gpio_set_function(51, GPIO_ALT_FN_2_OUT); /* nPIOW */
390 if (CPU_IS_PXA250) {
391 pxa2x0_gpio_set_function(52, GPIO_ALT_FN_2_OUT); /* nPCE1 */
392 pxa2x0_gpio_set_function(53, GPIO_ALT_FN_2_OUT); /* nPCE2 */
393 pxa2x0_gpio_set_function(54, GPIO_ALT_FN_2_OUT); /* pSKTSEL */
394 } else {
395 pxa2x0_gpio_set_function(102, GPIO_ALT_FN_1_OUT); /* nPCE1 */
396 pxa2x0_gpio_set_function(105, GPIO_ALT_FN_1_OUT); /* nPCE2 */
397 pxa2x0_gpio_set_function(79, GPIO_ALT_FN_1_OUT); /* pSKTSEL */
398 }
399 pxa2x0_gpio_set_function(55, GPIO_ALT_FN_2_OUT); /* nPREG */
400 pxa2x0_gpio_set_function(56, GPIO_ALT_FN_1_IN); /* nPWAIT */
401 pxa2x0_gpio_set_function(57, GPIO_ALT_FN_1_IN); /* nIOIS16 */
402 }
403
404 static void
405 etherstix_config(void)
406 {
407 extern struct cfdata cfdata[];
408 #if defined(CPU_XSCALE_PXA270) && defined(CPU_XSCALE_PXA250)
409 int rst = (CPU_IS_PXA250) ? 80 : 32;
410 int irq = (CPU_IS_PXA250) ? 36 : 99;
411 #else
412 #if defined(CPU_XSCALE_PXA270)
413 const int rst = 32, irq = 99;
414 #else
415 const int rst = 80, irq = 36;
416 #endif
417 #endif
418 int i;
419
420 pxa2x0_gpio_set_function(49, GPIO_ALT_FN_2_OUT); /* nPWE */
421 pxa2x0_gpio_set_function(15, GPIO_ALT_FN_2_OUT); /* nCS 1 */
422 pxa2x0_gpio_set_function(rst, GPIO_OUT | GPIO_SET); /* RESET 1 */
423 delay(1);
424 pxa2x0_gpio_set_function(rst, GPIO_OUT | GPIO_CLR);
425 delay(50000);
426
427 for (i = 0; cfdata[i].cf_name != NULL; i++)
428 if (strcmp(cfdata[i].cf_name, "sm") == 0 &&
429 strcmp(cfdata[i].cf_atname, "sm_gxio") == 0 &&
430 cfdata[i].cf_loc[GXIOCF_ADDR] == 0x04000300 &&
431 cfdata[i].cf_loc[GXIOCF_GPIRQ] == GXIOCF_GPIRQ_DEFAULT)
432 cfdata[i].cf_loc[GXIOCF_GPIRQ] = irq;
433 }
434
435 static void
436 netcf_config(void)
437 {
438
439 etherstix_config();
440 cfstix_config();
441 }
442
443 static void
444 netcf_vx_config(void)
445 {
446
447 /*
448 * XXXX: More power is necessary for NIC and USB???
449 * (no document. from Linux)
450 */
451
452 pxa2x0_gpio_set_function(27, GPIO_IN);
453 pxa2x0_gpio_set_function(107, GPIO_OUT | GPIO_CLR);
454 pxa2x0_gpio_set_function(118, GPIO_ALT_FN_1_IN | GPIO_CLR);
455
456 etherstix_config();
457 cfstix_config();
458 if (CPU_IS_PXA270) {
459 /* Overwrite */
460 gxpcic_slot_irqs[0].cd = 104;
461 gxpcic_slot_irqs[0].prdy = 109;
462 gxpcic_gpio_reset = 110;
463 };
464 }
465
466 static void
467 netduommc_config(void)
468 {
469
470 netduo_config();
471 basix_config();
472 }
473
474 static void
475 netduo_config(void)
476 {
477
478 etherstix_config();
479
480 pxa2x0_gpio_set_function(78, GPIO_ALT_FN_2_OUT); /* nCS 2 */
481 pxa2x0_gpio_set_function(52, GPIO_OUT | GPIO_SET); /* RESET 2 */
482 delay(1);
483 pxa2x0_gpio_set_function(52, GPIO_OUT | GPIO_CLR);
484 delay(50000);
485 }
486
487 static void
488 netmicrosd_config(void)
489 {
490
491 /* MicroSD(mci) always configure on PXA270 */
492
493 pxa2x0_gpio_set_function(49, GPIO_ALT_FN_2_OUT); /* nPWE */
494 pxa2x0_gpio_set_function(15, GPIO_ALT_FN_2_OUT); /* nCS 1 */
495 pxa2x0_gpio_set_function(107, GPIO_OUT | GPIO_CLR); /* RESET 1 */
496 delay(hz / 2);
497 pxa2x0_gpio_set_function(107, GPIO_OUT | GPIO_SET);
498 delay(50000);
499 }
500
501 static void
502 netwifimicrosd_config(void)
503 {
504
505 netmicrosd_config();
506
507 cfstix_config();
508 /* However use pxamci. */
509 pxa2x0_gpio_set_function(111, GPIO_CLR | GPIO_ALT_FN_1_IN);
510 /* Power to Marvell 88W8385 */
511 pxa2x0_gpio_set_function(80, GPIO_OUT | GPIO_SET);
512 }
513
514 static void
515 netmmc_config(void)
516 {
517
518 etherstix_config();
519 basix_config();
520 }
521
522 static void
523 wifistix_config(void)
524 {
525
526 cfstix_config();
527
528 /* Power to Marvell 88W8385 */
529 pxa2x0_gpio_set_function(80, GPIO_OUT | GPIO_SET);
530 }
531
532 static void
533 wifistix_cf_config(void)
534 {
535
536 gxpcic_slot_irqs[1].valid = 1;
537 gxpcic_slot_irqs[1].cd = 36;
538 gxpcic_slot_irqs[1].prdy = 27;
539
540 #if 1
541 /* this configuration set by pxa2x0_pcic.c::pxapcic_attach_common() */
542 #else
543 pxa2x0_gpio_set_function(36, GPIO_IN); /* PCD2 */
544 pxa2x0_gpio_set_function(27, GPIO_IN); /* PRDY2/~IRQ2 */
545 #endif
546 pxa2x0_gpio_set_function(18, GPIO_IN); /* BVD2/~STSCHG2 */
547
548 cfstix_config();
549
550 /* Power to Marvell 88W8385 */
551 pxa2x0_gpio_set_function(80, GPIO_OUT | GPIO_SET);
552 }
553