1 /* $NetBSD: gumstix_machdep.c,v 1.73 2023/04/20 08:28:04 skrll 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 /*
34 * Copyright (c) 2002, 2003, 2004, 2005 Genetec Corporation.
35 * All rights reserved.
36 *
37 * Written by Hiroyuki Bessho for Genetec Corporation.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. The name of Genetec Corporation may not be used to endorse or
48 * promote products derived from this software without specific prior
49 * written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
53 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
54 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
55 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
56 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
57 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
58 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
59 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
61 * POSSIBILITY OF SUCH DAMAGE.
62 *
63 * Machine dependent functions for kernel setup for Genetec G4250EBX
64 * evaluation board.
65 *
66 * Based on iq80310_machhdep.c
67 */
68 /*
69 * Copyright (c) 2001 Wasabi Systems, Inc.
70 * All rights reserved.
71 *
72 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
73 *
74 * Redistribution and use in source and binary forms, with or without
75 * modification, are permitted provided that the following conditions
76 * are met:
77 * 1. Redistributions of source code must retain the above copyright
78 * notice, this list of conditions and the following disclaimer.
79 * 2. Redistributions in binary form must reproduce the above copyright
80 * notice, this list of conditions and the following disclaimer in the
81 * documentation and/or other materials provided with the distribution.
82 * 3. All advertising materials mentioning features or use of this software
83 * must display the following acknowledgement:
84 * This product includes software developed for the NetBSD Project by
85 * Wasabi Systems, Inc.
86 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
87 * or promote products derived from this software without specific prior
88 * written permission.
89 *
90 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
92 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
93 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
94 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
95 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
96 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
97 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
98 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
99 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
100 * POSSIBILITY OF SUCH DAMAGE.
101 */
102
103 /*
104 * Copyright (c) 1997,1998 Mark Brinicombe.
105 * Copyright (c) 1997,1998 Causality Limited.
106 * All rights reserved.
107 *
108 * Redistribution and use in source and binary forms, with or without
109 * modification, are permitted provided that the following conditions
110 * are met:
111 * 1. Redistributions of source code must retain the above copyright
112 * notice, this list of conditions and the following disclaimer.
113 * 2. Redistributions in binary form must reproduce the above copyright
114 * notice, this list of conditions and the following disclaimer in the
115 * documentation and/or other materials provided with the distribution.
116 * 3. All advertising materials mentioning features or use of this software
117 * must display the following acknowledgement:
118 * This product includes software developed by Mark Brinicombe
119 * for the NetBSD Project.
120 * 4. The name of the company nor the name of the author may be used to
121 * endorse or promote products derived from this software without specific
122 * prior written permission.
123 *
124 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
125 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
126 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
127 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
128 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
129 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
130 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
131 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
132 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
133 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
134 * SUCH DAMAGE.
135 *
136 * Machine dependent functions for kernel setup for Intel IQ80310 evaluation
137 * boards using RedBoot firmware.
138 */
139
140 #include "opt_arm_debug.h"
141 #include "opt_com.h"
142 #include "opt_console.h"
143 #include "opt_cputypes.h"
144 #include "opt_evbarm_boardtype.h"
145 #include "opt_gumstix.h"
146 #include "opt_kgdb.h"
147
148 #include <sys/param.h>
149 #include <sys/conf.h>
150 #include <sys/device.h>
151 #include <sys/exec.h>
152 #include <sys/kernel.h>
153 #include <sys/proc.h>
154 #include <sys/reboot.h>
155 #include <sys/systm.h>
156 #include <sys/termios.h>
157 #include <sys/bus.h>
158 #include <sys/cpu.h>
159 #include <sys/gpio.h>
160
161 #include <prop/proplib.h>
162
163 #include <uvm/uvm_extern.h>
164
165 #include <arm/mainbus/mainbus.h> /* don't reorder */
166
167 #include <machine/autoconf.h> /* don't reorder */
168 #include <machine/bootconfig.h>
169 #include <arm/locore.h>
170
171 #include <arm/arm32/machdep.h>
172
173 #include <arm/xscale/pxa2x0reg.h>
174 #include <arm/xscale/pxa2x0var.h>
175 #include <arm/xscale/pxa2x0_gpio.h>
176 #include <evbarm/gumstix/gumstixreg.h>
177 #include <evbarm/gumstix/gumstixvar.h>
178
179 #include <dev/cons.h>
180
181 #ifdef KGDB
182 #include <sys/kgdb.h>
183 #endif
184
185 #ifdef VERBOSE_INIT_ARM
186 #define VPRINTF(...) printf(__VA_ARGS__)
187 #else
188 #define VPRINTF(...) __nothing
189 #endif
190
191 /*
192 * The range 0xc1000000 - 0xfd000000 is available for kernel VM space
193 * Core-logic registers and I/O mappings occupy
194 *
195 * 0xfd000000 - 0xfd800000 on gumstix
196 */
197 #ifndef KERNEL_VM_BASE
198 #define KERNEL_VM_BASE 0xc8000000
199 #endif
200 #define KERNEL_VM_SIZE 0x35000000
201
202 BootConfig bootconfig; /* Boot config storage */
203 static char bootargs[MAX_BOOT_STRING];
204 const size_t bootargs_len = sizeof(bootargs) - 1; /* without nul */
205 char *boot_args = NULL;
206
207 uint32_t system_serial_high;
208 uint32_t system_serial_low;
209
210 /* Prototypes */
211 #if defined(GUMSTIX)
212 static void read_system_serial(void);
213 #endif
214 static void process_kernel_args(int, char *[]);
215 static void process_kernel_args_liner(char *);
216 #ifdef KGDB
217 static void kgdb_port_init(void);
218 #endif
219 static void gumstix_device_register(device_t, void *);
220
221 bs_protos(bs_notimpl);
222
223 #include "com.h"
224 #if NCOM > 0
225 #include <dev/ic/comreg.h>
226 #include <dev/ic/comvar.h>
227 #endif
228
229 #if defined(CPU_XSCALE)
230 #include "lcd.h"
231 #endif
232
233 #ifndef CONSPEED
234 #define CONSPEED B115200 /* It's a setting of the default of u-boot */
235 #endif
236 #ifndef CONMODE
237 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
238 #endif
239
240 int comcnspeed = CONSPEED;
241 int comcnmode = CONMODE;
242
243 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
244 static char console[16];
245 #endif
246
247 const struct tifb_panel_info *tifb_panel_info = NULL;
248 /* Use TPS65217 White LED Driver */
249 bool use_tps65217_wled = false;
250
251 extern void gxio_config(void);
252 extern void gxio_config_expansion(char *);
253
254
255 static inline pd_entry_t *
read_ttb(void)256 read_ttb(void)
257 {
258 long ttb;
259
260 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
261
262 return (pd_entry_t *)(ttb & ~((1<<14)-1));
263 }
264
265 /*
266 * Static device mappings. These peripheral registers are mapped at
267 * fixed virtual addresses very early in initarm() so that we can use
268 * them while booting the kernel, and stay at the same address
269 * throughout whole kernel's life time.
270 *
271 * We use this table twice; once with bootstrap page table, and once
272 * with kernel's page table which we build up in initarm().
273 *
274 * Since we map these registers into the bootstrap page table using
275 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
276 * registers segment-aligned and segment-rounded in order to avoid
277 * using the 2nd page tables.
278 */
279
280 static const struct pmap_devmap gumstix_devmap[] = {
281 #if defined(GUMSTIX)
282 DEVMAP_ENTRY(
283 GUMSTIX_GPIO_VBASE,
284 PXA2X0_GPIO_BASE,
285 PXA250_GPIO_SIZE
286 ),
287 DEVMAP_ENTRY(
288 GUMSTIX_CLKMAN_VBASE,
289 PXA2X0_CLKMAN_BASE,
290 PXA2X0_CLKMAN_SIZE
291 ),
292 DEVMAP_ENTRY(
293 GUMSTIX_INTCTL_VBASE,
294 PXA2X0_INTCTL_BASE,
295 PXA2X0_INTCTL_SIZE
296 ),
297 DEVMAP_ENTRY(
298 GUMSTIX_FFUART_VBASE,
299 PXA2X0_FFUART_BASE,
300 4 * COM_NPORTS
301 ),
302 DEVMAP_ENTRY(
303 GUMSTIX_STUART_VBASE,
304 PXA2X0_STUART_BASE,
305 4 * COM_NPORTS
306 ),
307 DEVMAP_ENTRY(
308 GUMSTIX_BTUART_VBASE,
309 PXA2X0_BTUART_BASE,
310 4 * COM_NPORTS
311 ),
312 DEVMAP_ENTRY(
313 GUMSTIX_HWUART_VBASE,
314 PXA2X0_HWUART_BASE,
315 4 * COM_NPORTS
316 ),
317 DEVMAP_ENTRY(
318 GUMSTIX_LCDC_VBASE,
319 PXA2X0_LCDC_BASE,
320 4 * COM_NPORTS
321 ),
322 #endif
323 DEVMAP_ENTRY_END
324 };
325
326 extern uint32_t *uboot_args;
327
328 /*
329 * vaddr_t initarm(...)
330 *
331 * Initial entry point on startup. This gets called before main() is
332 * entered.
333 * It should be responsible for setting up everything that must be
334 * in place when main is called.
335 * This includes
336 * Taking a copy of the boot configuration structure.
337 * Initialising the physical console so characters can be printed.
338 * Setting up page tables for the kernel
339 * Relocating the kernel to the bottom of physical memory
340 */
341 vaddr_t
initarm(void * arg)342 initarm(void *arg)
343 {
344 extern char KERNEL_BASE_phys[];
345 uint32_t ram_size = 0x400000;
346 enum { r0 = 0, r1 = 1, r2 = 2, r3 = 3 }; /* args from u-boot */
347
348 #if defined(CPU_XSCALE)
349
350 /*
351 * We mapped PA == VA in gumstix_start.S.
352 * Also mapped SDRAM to KERNEL_BASE first 64Mbyte only with cachable.
353 *
354 * Gumstix (basix, connex, verdex, verdex-pro):
355 * Physical Address Range Description
356 * ----------------------- ----------------------------------
357 * 0x00000000 - 0x00ffffff flash Memory (16MB or 4MB)
358 * 0x40000000 - 0x480fffff Processor Registers
359 * 0xa0000000 - 0xa3ffffff SDRAM Bank 0 (64MB or 128MB)
360 * 0xc0000000 - 0xc3ffffff KERNEL_BASE
361 */
362 extern vaddr_t xscale_cache_clean_addr;
363 xscale_cache_clean_addr = 0xff000000U;
364
365 cpu_reset_address = NULL;
366 #endif
367
368 /*
369 * Heads up ... Setup the CPU / MMU / TLB functions
370 */
371 if (set_cpufuncs())
372 panic("cpu not recognized!");
373
374 /* map some peripheral registers at static I/O area */
375 pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap);
376
377 #if defined(CPU_XSCALE)
378 /* start 32.768kHz OSC */
379 ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON);
380
381 /* Get ready for splfoo() */
382 pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE);
383
384 /* setup GPIO for {FF,ST,HW}UART. */
385 pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
386
387 pxa2x0_clkman_bootstrap(GUMSTIX_CLKMAN_VBASE);
388 #endif
389
390 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
391
392 /* configure MUX, GPIO and CLK. */
393 gxio_config();
394
395 #ifndef GUMSTIX_NETBSD_ARGS_CONSOLE
396 consinit();
397 #endif
398 #ifdef KGDB
399 kgdb_port_init();
400 #endif
401
402 /*
403 * Examine the boot args string for options we need to know about
404 * now.
405 */
406 #if defined(GUMSTIX)
407 #define SDRAM_START 0xa0000000UL
408 #endif
409 if (uboot_args[r0] < SDRAM_START ||
410 uboot_args[r0] >= SDRAM_START + ram_size)
411 /* Maybe r0 is 'argc'. We are booted by command 'go'. */
412 process_kernel_args(uboot_args[r0], (char **)uboot_args[r1]);
413 else
414 /*
415 * Maybe r3 is 'boot args string' of 'bootm'. This string is
416 * linely.
417 */
418 process_kernel_args_liner((char *)uboot_args[r3]);
419 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
420 consinit();
421 #endif
422
423 /* Talk to the user */
424 #define BDSTR(s) _BDSTR(s)
425 #define _BDSTR(s) #s
426 printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
427
428 /* Read system serial */
429 #if defined(GUMSTIX)
430 read_system_serial();
431 #endif
432
433 VPRINTF("initarm: Configuring system ...\n");
434
435 /* Fake bootconfig structure for the benefit of pmap.c */
436 /* XXX must make the memory description h/w independent */
437 bootconfig.dramblocks = 1;
438 bootconfig.dram[0].address = SDRAM_START;
439 bootconfig.dram[0].pages = ram_size / PAGE_SIZE;
440
441 KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE);
442
443 arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
444 (uintptr_t) KERNEL_BASE_phys);
445 arm32_kernel_vm_init(KERNEL_VM_BASE,
446 #if defined(CPU_XSCALE)
447 ARM_VECTORS_LOW,
448 #endif
449 0, gumstix_devmap, true);
450
451 evbarm_device_register = gumstix_device_register;
452
453 return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
454 }
455
456 #if defined(GUMSTIX)
457 static void
read_system_serial(void)458 read_system_serial(void)
459 {
460 #define GUMSTIX_SYSTEM_SERIAL_ADDR 0
461 #define GUMSTIX_SYSTEM_SERIAL_SIZE 8
462 #define FLASH_OFFSET_INTEL_PROTECTION 0x81
463 #define FLASH_OFFSET_USER_PROTECTION 0x85
464 #define FLASH_CMD_READ_ID 0x90
465 #define FLASH_CMD_RESET 0xff
466 int i;
467 char system_serial[GUMSTIX_SYSTEM_SERIAL_SIZE], *src;
468 char x;
469
470 src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/);
471 *(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
472 memcpy(system_serial,
473 src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
474 *(volatile uint16_t *)0 = FLASH_CMD_RESET;
475
476 for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++)
477 x &= system_serial[i];
478 if (x == 0xff) {
479 src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/);
480 *(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
481 memcpy(system_serial,
482 src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
483 *(volatile uint16_t *)0 = FLASH_CMD_RESET;
484
485 /*
486 * XXXX: Don't need ???
487 * gumstix_serial_hash(system_serial);
488 */
489 }
490 system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 |
491 system_serial[2] << 8 | system_serial[3];
492 system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 |
493 system_serial[6] << 8 | system_serial[7];
494
495 printf("system serial: 0x");
496 for (i = 0; i < sizeof (system_serial); i++)
497 printf("%02x", system_serial[i]);
498 printf("\n");
499 }
500 #endif
501
502 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
503 static const char busheader_name[] = "busheader=";
504 #endif
505 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
506 defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
507 static const char expansion_name[] = "expansion=";
508 #endif
509 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
510 static const char console_name[] = "console=";
511 #endif
512 static void
process_kernel_args(int argc,char * argv[])513 process_kernel_args(int argc, char *argv[])
514 {
515 int gxio_configured = 0, i, j;
516
517 boothowto = 0;
518
519 for (i = 1, j = 0; i < argc; i++) {
520 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
521 if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) {
522 /* Configure for GPIOs of busheader side */
523 gxio_config_expansion(argv[i] + strlen(busheader_name));
524 gxio_configured = 1;
525 continue;
526 }
527 #endif
528 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
529 defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
530 if (!strncmp(argv[i], expansion_name, strlen(expansion_name))) {
531 /* Configure expansion */
532 gxio_config_expansion(argv[i] + strlen(expansion_name));
533 gxio_configured = 1;
534 continue;
535 }
536 #endif
537 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
538 if (!strncmp(argv[i], console_name, strlen(console_name))) {
539 strncpy(console, argv[i] + strlen(console_name),
540 sizeof(console));
541 consinit();
542 }
543 #endif
544 if (j == bootargs_len) {
545 *(bootargs + j) = '\0';
546 continue;
547 }
548 if (j != 0)
549 *(bootargs + j++) = ' ';
550 strncpy(bootargs + j, argv[i], bootargs_len - j);
551 bootargs[bootargs_len] = '\0';
552 j += strlen(argv[i]);
553 }
554 boot_args = bootargs;
555
556 parse_mi_bootargs(boot_args);
557
558 if (!gxio_configured)
559 gxio_config_expansion(NULL);
560 }
561
562 static void
process_kernel_args_liner(char * args)563 process_kernel_args_liner(char *args)
564 {
565 int i = 0;
566 char *p = NULL;
567
568 boothowto = 0;
569
570 strncpy(bootargs, args, sizeof(bootargs));
571 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
572 defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
573 {
574 char *q;
575
576 if ((p = strstr(bootargs, expansion_name)))
577 q = p + strlen(expansion_name);
578 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
579 else if ((p = strstr(bootargs, busheader_name)))
580 q = p + strlen(busheader_name);
581 #endif
582 if (p) {
583 char expansion[256], c;
584
585 i = 0;
586 do {
587 c = *(q + i);
588 if (c == ' ')
589 c = '\0';
590 expansion[i++] = c;
591 } while (c != '\0' && i < sizeof(expansion));
592 gxio_config_expansion(expansion);
593 strcpy(p, q + i);
594 }
595 }
596 #endif
597 if (p == NULL)
598 gxio_config_expansion(NULL);
599 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
600 p = strstr(bootargs, console_name);
601 if (p != NULL) {
602 char c;
603
604 i = 0;
605 do {
606 c = *(p + strlen(console_name) + i);
607 if (c == ' ')
608 c = '\0';
609 console[i++] = c;
610 } while (c != '\0' && i < sizeof(console));
611 consinit();
612 strcpy(p, p + strlen(console_name) + i);
613 }
614 #endif
615 boot_args = bootargs;
616
617 parse_mi_bootargs(boot_args);
618 }
619
620 #ifdef KGDB
621 #ifndef KGDB_DEVNAME
622 #define KGDB_DEVNAME "ffuart"
623 #endif
624 const char kgdb_devname[] = KGDB_DEVNAME;
625
626 #ifndef KGDB_DEVRATE
627 #define KGDB_DEVRATE CONSPEED
628 #endif
629 int kgdb_devrate = KGDB_DEVRATE;
630
631 #if (NCOM > 0)
632 #ifndef KGDB_DEVMODE
633 #define KGDB_DEVMODE CONMODE
634 #endif
635 int comkgdbmode = KGDB_DEVMODE;
636 #endif /* NCOM */
637
638 #endif /* KGDB */
639
640
641 void
consinit(void)642 consinit(void)
643 {
644 static int consinit_called = 0;
645
646 if (consinit_called != 0)
647 return;
648
649 consinit_called = 1;
650
651 #if NCOM > 0
652
653 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
654 /* Maybe passed Linux's bootargs 'console=ttyS?,<speed>...' */
655 if (strncmp(console, "ttyS", 4) == 0 && console[5] == ',') {
656 int i;
657
658 comcnspeed = 0;
659 for (i = 6; i < strlen(console) && isdigit(console[i]); i++)
660 comcnspeed = comcnspeed * 10 + (console[i] - '0');
661 }
662 #endif
663
664 #if defined(GUMSTIX)
665
666 #ifdef FFUARTCONSOLE
667 #ifdef KGDB
668 if (strcmp(kgdb_devname, "ffuart") == 0){
669 /* port is reserved for kgdb */
670 } else
671 #endif
672 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
673 if (console[0] == '\0' || strcasecmp(console, "ffuart") == 0 ||
674 strncmp(console, "ttyS0,", 6) == 0)
675 #endif
676 {
677 int rv;
678
679 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
680 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
681 if (rv == 0) {
682 pxa2x0_clkman_config(CKEN_FFUART, 1);
683 return;
684 }
685 }
686 #endif /* FFUARTCONSOLE */
687
688 #ifdef STUARTCONSOLE
689 #ifdef KGDB
690 if (strcmp(kgdb_devname, "stuart") == 0) {
691 /* port is reserved for kgdb */
692 } else
693 #endif
694 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
695 if (console[0] == '\0' || strcasecmp(console, "stuart") == 0)
696 #endif
697 {
698 int rv;
699
700 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE,
701 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
702 if (rv == 0) {
703 pxa2x0_clkman_config(CKEN_STUART, 1);
704 return;
705 }
706 }
707 #endif /* STUARTCONSOLE */
708
709 #ifdef BTUARTCONSOLE
710 #ifdef KGDB
711 if (strcmp(kgdb_devname, "btuart") == 0) {
712 /* port is reserved for kgdb */
713 } else
714 #endif
715 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
716 if (console[0] == '\0' || strcasecmp(console, "btuart") == 0)
717 #endif
718 {
719 int rv;
720
721 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
722 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
723 if (rv == 0) {
724 pxa2x0_clkman_config(CKEN_BTUART, 1);
725 return;
726 }
727 }
728 #endif /* BTUARTCONSOLE */
729
730 #ifdef HWUARTCONSOLE
731 #ifdef KGDB
732 if (strcmp(kgdb_devname, "hwuart") == 0) {
733 /* port is reserved for kgdb */
734 } else
735 #endif
736 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
737 if (console[0] == '\0' || strcasecmp(console, "hwuart") == 0)
738 #endif
739 {
740 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE,
741 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
742 if (rv == 0) {
743 pxa2x0_clkman_config(CKEN_HWUART, 1);
744 return;
745 }
746 }
747 #endif /* HWUARTCONSOLE */
748
749 #endif /* GUMSTIX */
750
751 #endif /* NCOM */
752
753 #if NLCD > 0
754 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
755 if (console[0] == '\0' || strcasecmp(console, "lcd") == 0)
756 #endif
757 {
758 gxlcd_cnattach();
759 }
760 #endif
761 }
762
763 #ifdef KGDB
764 static void
kgdb_port_init(void)765 kgdb_port_init(void)
766 {
767 #if (NCOM > 0) && defined(COM_PXA2X0)
768 paddr_t paddr = 0;
769 int cken = 0;
770
771 if (0 == strcmp(kgdb_devname, "ffuart")) {
772 paddr = PXA2X0_FFUART_BASE;
773 cken = CKEN_FFUART;
774 } else if (0 == strcmp(kgdb_devname, "stuart")) {
775 paddr = PXA2X0_STUART_BASE;
776 cken = CKEN_STUART;
777 } else if (0 == strcmp(kgdb_devname, "btuart")) {
778 paddr = PXA2X0_BTUART_BASE;
779 cken = CKEN_BTUART;
780 } else if (0 == strcmp(kgdb_devname, "hwuart")) {
781 paddr = PXA2X0_HWUART_BASE;
782 cken = CKEN_HWUART;
783 }
784
785 if (paddr &&
786 0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
787 kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
788
789 pxa2x0_clkman_config(cken, 1);
790 }
791
792 #endif
793 }
794 #endif
795
796 static void
gumstix_device_register(device_t dev,void * aux)797 gumstix_device_register(device_t dev, void *aux)
798 {
799 prop_dictionary_t dict = device_properties(dev);
800
801 if (device_is_a(dev, "ehci")) {
802 prop_dictionary_set_uint16(dict, "dpll5-m", 443);
803 prop_dictionary_set_uint16(dict, "dpll5-n", 11);
804 prop_dictionary_set_uint16(dict, "dpll5-m2", 4);
805 }
806 if (device_is_a(dev, "ohci")) {
807 if (prop_dictionary_set_bool(dict,
808 "Ganged-power-mask-on-port1", 1) == false) {
809 printf("WARNING: unable to set power-mask for port1"
810 " property for %s\n", device_xname(dev));
811 }
812 if (prop_dictionary_set_bool(dict,
813 "Ganged-power-mask-on-port2", 1) == false) {
814 printf("WARNING: unable to set power-mask for port2"
815 " property for %s\n", device_xname(dev));
816 }
817 if (prop_dictionary_set_bool(dict,
818 "Ganged-power-mask-on-port3", 1) == false) {
819 printf("WARNING: unable to set power-mask for port3"
820 " property for %s\n", device_xname(dev));
821 }
822 }
823 }
824