1 /* $NetBSD: gumstix_machdep.c,v 1.74 2023/08/03 08:16:30 mrg 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 * 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 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 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 /* 471 * XXXGCC12. 472 * This accesses beyond what "char *src" is known to supply. 473 */ 474 #pragma GCC push_options 475 #pragma GCC diagnostic ignored "-Warray-bounds" 476 477 src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/); 478 *(volatile uint16_t *)0 = FLASH_CMD_READ_ID; 479 memcpy(system_serial, 480 src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial)); 481 *(volatile uint16_t *)0 = FLASH_CMD_RESET; 482 483 for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++) 484 x &= system_serial[i]; 485 if (x == 0xff) { 486 src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/); 487 *(volatile uint16_t *)0 = FLASH_CMD_READ_ID; 488 memcpy(system_serial, 489 src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial)); 490 *(volatile uint16_t *)0 = FLASH_CMD_RESET; 491 492 /* 493 * XXXX: Don't need ??? 494 * gumstix_serial_hash(system_serial); 495 */ 496 } 497 #pragma GCC pop_options 498 system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 | 499 system_serial[2] << 8 | system_serial[3]; 500 system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 | 501 system_serial[6] << 8 | system_serial[7]; 502 503 printf("system serial: 0x"); 504 for (i = 0; i < sizeof (system_serial); i++) 505 printf("%02x", system_serial[i]); 506 printf("\n"); 507 } 508 #endif 509 510 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER 511 static const char busheader_name[] = "busheader="; 512 #endif 513 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \ 514 defined(GUMSTIX_NETBSD_ARGS_EXPANSION) 515 static const char expansion_name[] = "expansion="; 516 #endif 517 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE 518 static const char console_name[] = "console="; 519 #endif 520 static void 521 process_kernel_args(int argc, char *argv[]) 522 { 523 int gxio_configured = 0, i, j; 524 525 boothowto = 0; 526 527 for (i = 1, j = 0; i < argc; i++) { 528 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER 529 if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) { 530 /* Configure for GPIOs of busheader side */ 531 gxio_config_expansion(argv[i] + strlen(busheader_name)); 532 gxio_configured = 1; 533 continue; 534 } 535 #endif 536 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \ 537 defined(GUMSTIX_NETBSD_ARGS_EXPANSION) 538 if (!strncmp(argv[i], expansion_name, strlen(expansion_name))) { 539 /* Configure expansion */ 540 gxio_config_expansion(argv[i] + strlen(expansion_name)); 541 gxio_configured = 1; 542 continue; 543 } 544 #endif 545 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE 546 if (!strncmp(argv[i], console_name, strlen(console_name))) { 547 strncpy(console, argv[i] + strlen(console_name), 548 sizeof(console)); 549 consinit(); 550 } 551 #endif 552 if (j == bootargs_len) { 553 *(bootargs + j) = '\0'; 554 continue; 555 } 556 if (j != 0) 557 *(bootargs + j++) = ' '; 558 strncpy(bootargs + j, argv[i], bootargs_len - j); 559 bootargs[bootargs_len] = '\0'; 560 j += strlen(argv[i]); 561 } 562 boot_args = bootargs; 563 564 parse_mi_bootargs(boot_args); 565 566 if (!gxio_configured) 567 gxio_config_expansion(NULL); 568 } 569 570 static void 571 process_kernel_args_liner(char *args) 572 { 573 int i = 0; 574 char *p = NULL; 575 576 boothowto = 0; 577 578 strncpy(bootargs, args, sizeof(bootargs)); 579 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \ 580 defined(GUMSTIX_NETBSD_ARGS_EXPANSION) 581 { 582 char *q; 583 584 if ((p = strstr(bootargs, expansion_name))) 585 q = p + strlen(expansion_name); 586 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER 587 else if ((p = strstr(bootargs, busheader_name))) 588 q = p + strlen(busheader_name); 589 #endif 590 if (p) { 591 char expansion[256], c; 592 593 i = 0; 594 do { 595 c = *(q + i); 596 if (c == ' ') 597 c = '\0'; 598 expansion[i++] = c; 599 } while (c != '\0' && i < sizeof(expansion)); 600 gxio_config_expansion(expansion); 601 strcpy(p, q + i); 602 } 603 } 604 #endif 605 if (p == NULL) 606 gxio_config_expansion(NULL); 607 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE 608 p = strstr(bootargs, console_name); 609 if (p != NULL) { 610 char c; 611 612 i = 0; 613 do { 614 c = *(p + strlen(console_name) + i); 615 if (c == ' ') 616 c = '\0'; 617 console[i++] = c; 618 } while (c != '\0' && i < sizeof(console)); 619 consinit(); 620 strcpy(p, p + strlen(console_name) + i); 621 } 622 #endif 623 boot_args = bootargs; 624 625 parse_mi_bootargs(boot_args); 626 } 627 628 #ifdef KGDB 629 #ifndef KGDB_DEVNAME 630 #define KGDB_DEVNAME "ffuart" 631 #endif 632 const char kgdb_devname[] = KGDB_DEVNAME; 633 634 #ifndef KGDB_DEVRATE 635 #define KGDB_DEVRATE CONSPEED 636 #endif 637 int kgdb_devrate = KGDB_DEVRATE; 638 639 #if (NCOM > 0) 640 #ifndef KGDB_DEVMODE 641 #define KGDB_DEVMODE CONMODE 642 #endif 643 int comkgdbmode = KGDB_DEVMODE; 644 #endif /* NCOM */ 645 646 #endif /* KGDB */ 647 648 649 void 650 consinit(void) 651 { 652 static int consinit_called = 0; 653 654 if (consinit_called != 0) 655 return; 656 657 consinit_called = 1; 658 659 #if NCOM > 0 660 661 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE 662 /* Maybe passed Linux's bootargs 'console=ttyS?,<speed>...' */ 663 if (strncmp(console, "ttyS", 4) == 0 && console[5] == ',') { 664 int i; 665 666 comcnspeed = 0; 667 for (i = 6; i < strlen(console) && isdigit(console[i]); i++) 668 comcnspeed = comcnspeed * 10 + (console[i] - '0'); 669 } 670 #endif 671 672 #if defined(GUMSTIX) 673 674 #ifdef FFUARTCONSOLE 675 #ifdef KGDB 676 if (strcmp(kgdb_devname, "ffuart") == 0){ 677 /* port is reserved for kgdb */ 678 } else 679 #endif 680 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE) 681 if (console[0] == '\0' || strcasecmp(console, "ffuart") == 0 || 682 strncmp(console, "ttyS0,", 6) == 0) 683 #endif 684 { 685 int rv; 686 687 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE, 688 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode); 689 if (rv == 0) { 690 pxa2x0_clkman_config(CKEN_FFUART, 1); 691 return; 692 } 693 } 694 #endif /* FFUARTCONSOLE */ 695 696 #ifdef STUARTCONSOLE 697 #ifdef KGDB 698 if (strcmp(kgdb_devname, "stuart") == 0) { 699 /* port is reserved for kgdb */ 700 } else 701 #endif 702 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE) 703 if (console[0] == '\0' || strcasecmp(console, "stuart") == 0) 704 #endif 705 { 706 int rv; 707 708 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE, 709 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode); 710 if (rv == 0) { 711 pxa2x0_clkman_config(CKEN_STUART, 1); 712 return; 713 } 714 } 715 #endif /* STUARTCONSOLE */ 716 717 #ifdef BTUARTCONSOLE 718 #ifdef KGDB 719 if (strcmp(kgdb_devname, "btuart") == 0) { 720 /* port is reserved for kgdb */ 721 } else 722 #endif 723 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE) 724 if (console[0] == '\0' || strcasecmp(console, "btuart") == 0) 725 #endif 726 { 727 int rv; 728 729 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE, 730 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode); 731 if (rv == 0) { 732 pxa2x0_clkman_config(CKEN_BTUART, 1); 733 return; 734 } 735 } 736 #endif /* BTUARTCONSOLE */ 737 738 #ifdef HWUARTCONSOLE 739 #ifdef KGDB 740 if (strcmp(kgdb_devname, "hwuart") == 0) { 741 /* port is reserved for kgdb */ 742 } else 743 #endif 744 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE) 745 if (console[0] == '\0' || strcasecmp(console, "hwuart") == 0) 746 #endif 747 { 748 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE, 749 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode); 750 if (rv == 0) { 751 pxa2x0_clkman_config(CKEN_HWUART, 1); 752 return; 753 } 754 } 755 #endif /* HWUARTCONSOLE */ 756 757 #endif /* GUMSTIX */ 758 759 #endif /* NCOM */ 760 761 #if NLCD > 0 762 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE) 763 if (console[0] == '\0' || strcasecmp(console, "lcd") == 0) 764 #endif 765 { 766 gxlcd_cnattach(); 767 } 768 #endif 769 } 770 771 #ifdef KGDB 772 static void 773 kgdb_port_init(void) 774 { 775 #if (NCOM > 0) && defined(COM_PXA2X0) 776 paddr_t paddr = 0; 777 int cken = 0; 778 779 if (0 == strcmp(kgdb_devname, "ffuart")) { 780 paddr = PXA2X0_FFUART_BASE; 781 cken = CKEN_FFUART; 782 } else if (0 == strcmp(kgdb_devname, "stuart")) { 783 paddr = PXA2X0_STUART_BASE; 784 cken = CKEN_STUART; 785 } else if (0 == strcmp(kgdb_devname, "btuart")) { 786 paddr = PXA2X0_BTUART_BASE; 787 cken = CKEN_BTUART; 788 } else if (0 == strcmp(kgdb_devname, "hwuart")) { 789 paddr = PXA2X0_HWUART_BASE; 790 cken = CKEN_HWUART; 791 } 792 793 if (paddr && 794 0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr, 795 kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) { 796 797 pxa2x0_clkman_config(cken, 1); 798 } 799 800 #endif 801 } 802 #endif 803 804 static void 805 gumstix_device_register(device_t dev, void *aux) 806 { 807 prop_dictionary_t dict = device_properties(dev); 808 809 if (device_is_a(dev, "ehci")) { 810 prop_dictionary_set_uint16(dict, "dpll5-m", 443); 811 prop_dictionary_set_uint16(dict, "dpll5-n", 11); 812 prop_dictionary_set_uint16(dict, "dpll5-m2", 4); 813 } 814 if (device_is_a(dev, "ohci")) { 815 if (prop_dictionary_set_bool(dict, 816 "Ganged-power-mask-on-port1", 1) == false) { 817 printf("WARNING: unable to set power-mask for port1" 818 " property for %s\n", device_xname(dev)); 819 } 820 if (prop_dictionary_set_bool(dict, 821 "Ganged-power-mask-on-port2", 1) == false) { 822 printf("WARNING: unable to set power-mask for port2" 823 " property for %s\n", device_xname(dev)); 824 } 825 if (prop_dictionary_set_bool(dict, 826 "Ganged-power-mask-on-port3", 1) == false) { 827 printf("WARNING: unable to set power-mask for port3" 828 " property for %s\n", device_xname(dev)); 829 } 830 } 831 } 832