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