xref: /netbsd-src/sys/arch/evbarm/gumstix/gumstix_machdep.c (revision 10468976faed43bfb6791764325d6bc693da8196)
1 /*	$NetBSD: gumstix_machdep.c,v 1.75 2023/10/12 11:33:37 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 	xscale_cache_clean_addr = 0xff000000U;
363 
364 	cpu_reset_address = NULL;
365 #endif
366 
367 	/*
368 	 * Heads up ... Setup the CPU / MMU / TLB functions
369 	 */
370 	if (set_cpufuncs())
371 		panic("cpu not recognized!");
372 
373 	/* map some peripheral registers at static I/O area */
374 	pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap);
375 
376 #if defined(CPU_XSCALE)
377 	/* start 32.768kHz OSC */
378 	ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON);
379 
380 	/* Get ready for splfoo() */
381 	pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE);
382 
383 	/* setup GPIO for {FF,ST,HW}UART. */
384 	pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
385 
386 	pxa2x0_clkman_bootstrap(GUMSTIX_CLKMAN_VBASE);
387 #endif
388 
389 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
390 
391 	/* configure MUX, GPIO and CLK. */
392 	gxio_config();
393 
394 #ifndef GUMSTIX_NETBSD_ARGS_CONSOLE
395 	consinit();
396 #endif
397 #ifdef KGDB
398 	kgdb_port_init();
399 #endif
400 
401 	/*
402 	 * Examine the boot args string for options we need to know about
403 	 * now.
404 	 */
405 #if defined(GUMSTIX)
406 #define SDRAM_START	0xa0000000UL
407 #endif
408 	if (uboot_args[r0] < SDRAM_START ||
409 	    uboot_args[r0] >= SDRAM_START + ram_size)
410 		/* Maybe r0 is 'argc'.  We are booted by command 'go'. */
411 		process_kernel_args(uboot_args[r0], (char **)uboot_args[r1]);
412 	else
413 		/*
414 		 * Maybe r3 is 'boot args string' of 'bootm'.  This string is
415 		 * linely.
416 		 */
417 		process_kernel_args_liner((char *)uboot_args[r3]);
418 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
419 	consinit();
420 #endif
421 
422 	/* Talk to the user */
423 #define BDSTR(s)	_BDSTR(s)
424 #define _BDSTR(s)	#s
425 	printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
426 
427 	/* Read system serial */
428 #if defined(GUMSTIX)
429 	read_system_serial();
430 #endif
431 
432 	VPRINTF("initarm: Configuring system ...\n");
433 
434 	/* Fake bootconfig structure for the benefit of pmap.c */
435 	/* XXX must make the memory description h/w independent */
436 	bootconfig.dramblocks = 1;
437 	bootconfig.dram[0].address = SDRAM_START;
438 	bootconfig.dram[0].pages = ram_size / PAGE_SIZE;
439 
440 	KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE);
441 
442 	arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
443 	    (uintptr_t) KERNEL_BASE_phys);
444 	arm32_kernel_vm_init(KERNEL_VM_BASE,
445 #if defined(CPU_XSCALE)
446 	    ARM_VECTORS_LOW,
447 #endif
448 	    0, gumstix_devmap, true);
449 
450 	evbarm_device_register = gumstix_device_register;
451 
452 	return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
453 }
454 
455 #if defined(GUMSTIX)
456 static void
read_system_serial(void)457 read_system_serial(void)
458 {
459 #define GUMSTIX_SYSTEM_SERIAL_ADDR	0
460 #define GUMSTIX_SYSTEM_SERIAL_SIZE	8
461 #define FLASH_OFFSET_INTEL_PROTECTION	0x81
462 #define FLASH_OFFSET_USER_PROTECTION	0x85
463 #define FLASH_CMD_READ_ID		0x90
464 #define FLASH_CMD_RESET			0xff
465 	int i;
466 	char system_serial[GUMSTIX_SYSTEM_SERIAL_SIZE], *src;
467 	char x;
468 
469 /*
470  * XXXGCC12.
471  * This accesses beyond what "char *src" is known to supply.
472  */
473 #pragma GCC push_options
474 #pragma GCC diagnostic ignored "-Warray-bounds"
475 
476 	src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/);
477 	*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
478 	memcpy(system_serial,
479 	    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
480 	*(volatile uint16_t *)0 = FLASH_CMD_RESET;
481 
482 	for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++)
483 		x &= system_serial[i];
484 	if (x == 0xff) {
485 		src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/);
486 		*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
487 		memcpy(system_serial,
488 		    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
489 		*(volatile uint16_t *)0 = FLASH_CMD_RESET;
490 
491 		/*
492 		 * XXXX: Don't need ???
493 		 * gumstix_serial_hash(system_serial);
494 		 */
495 	}
496 #pragma GCC pop_options
497 	system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 |
498 	    system_serial[2] << 8 | system_serial[3];
499 	system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 |
500 	    system_serial[6] << 8 | system_serial[7];
501 
502 	printf("system serial: 0x");
503 	for (i = 0; i < sizeof (system_serial); i++)
504 		printf("%02x", system_serial[i]);
505 	printf("\n");
506 }
507 #endif
508 
509 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
510 static const char busheader_name[] = "busheader=";
511 #endif
512 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
513     defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
514 static const char expansion_name[] = "expansion=";
515 #endif
516 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
517 static const char console_name[] = "console=";
518 #endif
519 static void
process_kernel_args(int argc,char * argv[])520 process_kernel_args(int argc, char *argv[])
521 {
522 	int gxio_configured = 0, i, j;
523 
524 	boothowto = 0;
525 
526 	for (i = 1, j = 0; i < argc; i++) {
527 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
528 		if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) {
529 			/* Configure for GPIOs of busheader side */
530 			gxio_config_expansion(argv[i] + strlen(busheader_name));
531 			gxio_configured = 1;
532 			continue;
533 		}
534 #endif
535 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
536     defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
537 		if (!strncmp(argv[i], expansion_name, strlen(expansion_name))) {
538 			/* Configure expansion */
539 			gxio_config_expansion(argv[i] + strlen(expansion_name));
540 			gxio_configured = 1;
541 			continue;
542 		}
543 #endif
544 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
545 		if (!strncmp(argv[i], console_name, strlen(console_name))) {
546 			strncpy(console, argv[i] + strlen(console_name),
547 			    sizeof(console));
548 			consinit();
549 		}
550 #endif
551 		if (j == bootargs_len) {
552 			*(bootargs + j) = '\0';
553 			continue;
554 		}
555 		if (j != 0)
556 			*(bootargs + j++) = ' ';
557 		strncpy(bootargs + j, argv[i], bootargs_len - j);
558 		bootargs[bootargs_len] = '\0';
559 		j += strlen(argv[i]);
560 	}
561 	boot_args = bootargs;
562 
563 	parse_mi_bootargs(boot_args);
564 
565 	if (!gxio_configured)
566 		gxio_config_expansion(NULL);
567 }
568 
569 static void
process_kernel_args_liner(char * args)570 process_kernel_args_liner(char *args)
571 {
572 	int i = 0;
573 	char *p = NULL;
574 
575 	boothowto = 0;
576 
577 	strncpy(bootargs, args, sizeof(bootargs));
578 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
579     defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
580 	{
581 		char *q;
582 
583 		if ((p = strstr(bootargs, expansion_name)))
584 			q = p + strlen(expansion_name);
585 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
586 		else if ((p = strstr(bootargs, busheader_name)))
587 			q = p + strlen(busheader_name);
588 #endif
589 		if (p) {
590 			char expansion[256], c;
591 
592 			i = 0;
593 			do {
594 				c = *(q + i);
595 				if (c == ' ')
596 					c = '\0';
597 				expansion[i++] = c;
598 			} while (c != '\0' && i < sizeof(expansion));
599 			gxio_config_expansion(expansion);
600 			strcpy(p, q + i);
601 		}
602 	}
603 #endif
604 	if (p == NULL)
605 		gxio_config_expansion(NULL);
606 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
607 	p = strstr(bootargs, console_name);
608 	if (p != NULL) {
609 		char c;
610 
611 		i = 0;
612 		do {
613 			c = *(p + strlen(console_name) + i);
614 			if (c == ' ')
615 				c = '\0';
616 			console[i++] = c;
617 		} while (c != '\0' && i < sizeof(console));
618 		consinit();
619 		strcpy(p, p + strlen(console_name) + i);
620 	}
621 #endif
622 	boot_args = bootargs;
623 
624 	parse_mi_bootargs(boot_args);
625 }
626 
627 #ifdef KGDB
628 #ifndef KGDB_DEVNAME
629 #define KGDB_DEVNAME	"ffuart"
630 #endif
631 const char kgdb_devname[] = KGDB_DEVNAME;
632 
633 #ifndef KGDB_DEVRATE
634 #define KGDB_DEVRATE	CONSPEED
635 #endif
636 int kgdb_devrate = KGDB_DEVRATE;
637 
638 #if (NCOM > 0)
639 #ifndef KGDB_DEVMODE
640 #define KGDB_DEVMODE	CONMODE
641 #endif
642 int comkgdbmode = KGDB_DEVMODE;
643 #endif /* NCOM */
644 
645 #endif /* KGDB */
646 
647 
648 void
consinit(void)649 consinit(void)
650 {
651 	static int consinit_called = 0;
652 
653 	if (consinit_called != 0)
654 		return;
655 
656 	consinit_called = 1;
657 
658 #if NCOM > 0
659 
660 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
661 	/* Maybe passed Linux's bootargs 'console=ttyS?,<speed>...' */
662 	if (strncmp(console, "ttyS", 4) == 0 && console[5] == ',') {
663 		int i;
664 
665 		comcnspeed = 0;
666 		for (i = 6; i < strlen(console) && isdigit(console[i]); i++)
667 			comcnspeed = comcnspeed * 10 + (console[i] - '0');
668 	}
669 #endif
670 
671 #if defined(GUMSTIX)
672 
673 #ifdef FFUARTCONSOLE
674 #ifdef KGDB
675 	if (strcmp(kgdb_devname, "ffuart") == 0){
676 		/* port is reserved for kgdb */
677 	} else
678 #endif
679 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
680 	if (console[0] == '\0' || strcasecmp(console, "ffuart") == 0 ||
681 	    strncmp(console, "ttyS0,", 6) == 0)
682 #endif
683 	{
684 		int rv;
685 
686 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
687 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
688 		if (rv == 0) {
689 			pxa2x0_clkman_config(CKEN_FFUART, 1);
690 			return;
691 		}
692 	}
693 #endif /* FFUARTCONSOLE */
694 
695 #ifdef STUARTCONSOLE
696 #ifdef KGDB
697 	if (strcmp(kgdb_devname, "stuart") == 0) {
698 		/* port is reserved for kgdb */
699 	} else
700 #endif
701 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
702 	if (console[0] == '\0' || strcasecmp(console, "stuart") == 0)
703 #endif
704 	{
705 		int rv;
706 
707 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE,
708 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
709 		if (rv == 0) {
710 			pxa2x0_clkman_config(CKEN_STUART, 1);
711 			return;
712 		}
713 	}
714 #endif /* STUARTCONSOLE */
715 
716 #ifdef BTUARTCONSOLE
717 #ifdef KGDB
718 	if (strcmp(kgdb_devname, "btuart") == 0) {
719 		/* port is reserved for kgdb */
720 	} else
721 #endif
722 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
723 	if (console[0] == '\0' || strcasecmp(console, "btuart") == 0)
724 #endif
725 	{
726 		int rv;
727 
728 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
729 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
730 		if (rv == 0) {
731 			pxa2x0_clkman_config(CKEN_BTUART, 1);
732 			return;
733 		}
734 	}
735 #endif /* BTUARTCONSOLE */
736 
737 #ifdef HWUARTCONSOLE
738 #ifdef KGDB
739 	if (strcmp(kgdb_devname, "hwuart") == 0) {
740 		/* port is reserved for kgdb */
741 	} else
742 #endif
743 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
744 	if (console[0] == '\0' || strcasecmp(console, "hwuart") == 0)
745 #endif
746 	{
747 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE,
748 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
749 		if (rv == 0) {
750 			pxa2x0_clkman_config(CKEN_HWUART, 1);
751 			return;
752 		}
753 	}
754 #endif /* HWUARTCONSOLE */
755 
756 #endif /* GUMSTIX */
757 
758 #endif /* NCOM */
759 
760 #if NLCD > 0
761 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
762 	if (console[0] == '\0' || strcasecmp(console, "lcd") == 0)
763 #endif
764 	{
765 		gxlcd_cnattach();
766 	}
767 #endif
768 }
769 
770 #ifdef KGDB
771 static void
kgdb_port_init(void)772 kgdb_port_init(void)
773 {
774 #if (NCOM > 0) && defined(COM_PXA2X0)
775 	paddr_t paddr = 0;
776 	int cken = 0;
777 
778 	if (0 == strcmp(kgdb_devname, "ffuart")) {
779 		paddr = PXA2X0_FFUART_BASE;
780 		cken = CKEN_FFUART;
781 	} else if (0 == strcmp(kgdb_devname, "stuart")) {
782 		paddr = PXA2X0_STUART_BASE;
783 		cken = CKEN_STUART;
784 	} else if (0 == strcmp(kgdb_devname, "btuart")) {
785 		paddr = PXA2X0_BTUART_BASE;
786 		cken = CKEN_BTUART;
787 	} else if (0 == strcmp(kgdb_devname, "hwuart")) {
788 		paddr = PXA2X0_HWUART_BASE;
789 		cken = CKEN_HWUART;
790 	}
791 
792 	if (paddr &&
793 	    0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
794 		kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
795 
796 		pxa2x0_clkman_config(cken, 1);
797 	}
798 
799 #endif
800 }
801 #endif
802 
803 static void
gumstix_device_register(device_t dev,void * aux)804 gumstix_device_register(device_t dev, void *aux)
805 {
806 	prop_dictionary_t dict = device_properties(dev);
807 
808 	if (device_is_a(dev, "ehci")) {
809 		prop_dictionary_set_uint16(dict, "dpll5-m", 443);
810 		prop_dictionary_set_uint16(dict, "dpll5-n", 11);
811 		prop_dictionary_set_uint16(dict, "dpll5-m2", 4);
812 	}
813 	if (device_is_a(dev, "ohci")) {
814 		if (prop_dictionary_set_bool(dict,
815 		    "Ganged-power-mask-on-port1", 1) == false) {
816 			printf("WARNING: unable to set power-mask for port1"
817 			    " property for %s\n", device_xname(dev));
818 		}
819 		if (prop_dictionary_set_bool(dict,
820 		    "Ganged-power-mask-on-port2", 1) == false) {
821 			printf("WARNING: unable to set power-mask for port2"
822 			    " property for %s\n", device_xname(dev));
823 		}
824 		if (prop_dictionary_set_bool(dict,
825 		    "Ganged-power-mask-on-port3", 1) == false) {
826 			printf("WARNING: unable to set power-mask for port3"
827 			    " property for %s\n", device_xname(dev));
828 		}
829 	}
830 }
831