1 /* $NetBSD: gumstix_machdep.c,v 1.50 2014/06/07 10:30:13 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 /* 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_evbarm_boardtype.h" 141 #include "opt_cputypes.h" 142 #include "opt_gumstix.h" 143 #ifdef OVERO 144 #include "opt_omap.h" 145 #include "prcm.h" 146 #endif 147 #include "opt_kgdb.h" 148 #include "opt_pmap_debug.h" 149 #include "opt_com.h" 150 151 #include <sys/param.h> 152 #include <sys/conf.h> 153 #include <sys/device.h> 154 #include <sys/exec.h> 155 #include <sys/kernel.h> 156 #include <sys/proc.h> 157 #include <sys/reboot.h> 158 #include <sys/systm.h> 159 #include <sys/termios.h> 160 #include <sys/bus.h> 161 #include <sys/cpu.h> 162 163 #include <uvm/uvm_extern.h> 164 165 #include <machine/autoconf.h> 166 #include <machine/bootconfig.h> 167 #include <arm/locore.h> 168 169 #include <arm/arm32/machdep.h> 170 #ifdef OVERO 171 #include <arm/omap/omap2_gpmcreg.h> 172 #include <arm/omap/omap2_prcm.h> 173 #include <arm/omap/omap2_reg.h> 174 #include <arm/omap/omap_var.h> 175 #include <arm/omap/omap_com.h> 176 #endif 177 #include <arm/xscale/pxa2x0reg.h> 178 #include <arm/xscale/pxa2x0var.h> 179 #include <arm/xscale/pxa2x0_gpio.h> 180 #include <evbarm/gumstix/gumstixreg.h> 181 #include <evbarm/gumstix/gumstixvar.h> 182 183 #include <dev/cons.h> 184 185 #ifdef KGDB 186 #include <sys/kgdb.h> 187 #endif 188 189 /* 190 * The range 0xc1000000 - 0xcfffffff is available for kernel VM space 191 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff 192 */ 193 #ifndef KERNEL_VM_BASE 194 #define KERNEL_VM_BASE 0xc1000000 195 #endif 196 #define KERNEL_VM_SIZE 0x0f000000 197 198 BootConfig bootconfig; /* Boot config storage */ 199 static char bootargs[MAX_BOOT_STRING]; 200 const size_t bootargs_len = sizeof(bootargs) - 1; /* without nul */ 201 char *boot_args = NULL; 202 203 uint32_t system_serial_high; 204 uint32_t system_serial_low; 205 206 /* Prototypes */ 207 #if defined(GUMSTIX) 208 static void read_system_serial(void); 209 #elif defined(OVERO) 210 static void overo_reset(void); 211 static void find_cpu_clock(void); 212 #endif 213 static void process_kernel_args(int, char *[]); 214 static void process_kernel_args_liner(char *); 215 #ifdef KGDB 216 static void kgdb_port_init(void); 217 #endif 218 static void gumstix_device_register(device_t, void *); 219 220 bs_protos(bs_notimpl); 221 222 #include "com.h" 223 #if NCOM > 0 224 #include <dev/ic/comreg.h> 225 #include <dev/ic/comvar.h> 226 #endif 227 228 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270) 229 #include "lcd.h" 230 #endif 231 232 #ifndef CONSPEED 233 #define CONSPEED B115200 /* It's a setting of the default of u-boot */ 234 #endif 235 #ifndef CONMODE 236 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 237 #endif 238 239 int comcnspeed = CONSPEED; 240 int comcnmode = CONMODE; 241 242 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE 243 static char console[16]; 244 #endif 245 246 extern void gxio_config_pin(void); 247 extern void gxio_config_expansion(char *); 248 249 250 static inline pd_entry_t * 251 read_ttb(void) 252 { 253 long ttb; 254 255 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb)); 256 257 return (pd_entry_t *)(ttb & ~((1<<14)-1)); 258 } 259 260 /* 261 * Static device mappings. These peripheral registers are mapped at 262 * fixed virtual addresses very early in initarm() so that we can use 263 * them while booting the kernel, and stay at the same address 264 * throughout whole kernel's life time. 265 * 266 * We use this table twice; once with bootstrap page table, and once 267 * with kernel's page table which we build up in initarm(). 268 * 269 * Since we map these registers into the bootstrap page table using 270 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map 271 * registers segment-aligned and segment-rounded in order to avoid 272 * using the 2nd page tables. 273 */ 274 275 #define _A(a) ((a) & ~L1_S_OFFSET) 276 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1)) 277 278 static const struct pmap_devmap gumstix_devmap[] = { 279 #if defined(GUMSTIX) 280 { 281 GUMSTIX_GPIO_VBASE, 282 _A(PXA2X0_GPIO_BASE), 283 _S(PXA250_GPIO_SIZE), 284 VM_PROT_READ | VM_PROT_WRITE, 285 PTE_NOCACHE, 286 }, 287 { 288 GUMSTIX_CLKMAN_VBASE, 289 _A(PXA2X0_CLKMAN_BASE), 290 _S(PXA2X0_CLKMAN_SIZE), 291 VM_PROT_READ | VM_PROT_WRITE, 292 PTE_NOCACHE, 293 }, 294 { 295 GUMSTIX_INTCTL_VBASE, 296 _A(PXA2X0_INTCTL_BASE), 297 _S(PXA2X0_INTCTL_SIZE), 298 VM_PROT_READ | VM_PROT_WRITE, 299 PTE_NOCACHE, 300 }, 301 { 302 GUMSTIX_FFUART_VBASE, 303 _A(PXA2X0_FFUART_BASE), 304 _S(4 * COM_NPORTS), 305 VM_PROT_READ | VM_PROT_WRITE, 306 PTE_NOCACHE, 307 }, 308 { 309 GUMSTIX_STUART_VBASE, 310 _A(PXA2X0_STUART_BASE), 311 _S(4 * COM_NPORTS), 312 VM_PROT_READ | VM_PROT_WRITE, 313 PTE_NOCACHE, 314 }, 315 { 316 GUMSTIX_BTUART_VBASE, 317 _A(PXA2X0_BTUART_BASE), 318 _S(4 * COM_NPORTS), 319 VM_PROT_READ | VM_PROT_WRITE, 320 PTE_NOCACHE, 321 }, 322 { 323 GUMSTIX_HWUART_VBASE, 324 _A(PXA2X0_HWUART_BASE), 325 _S(4 * COM_NPORTS), 326 VM_PROT_READ | VM_PROT_WRITE, 327 PTE_NOCACHE, 328 }, 329 { 330 GUMSTIX_LCDC_VBASE, 331 _A(PXA2X0_LCDC_BASE), 332 _S(4 * COM_NPORTS), 333 VM_PROT_READ | VM_PROT_WRITE, 334 PTE_NOCACHE, 335 }, 336 #elif defined(OVERO) 337 { 338 OVERO_L4_PERIPHERAL_VBASE, 339 _A(OMAP3530_L4_PERIPHERAL_BASE), 340 _S(OMAP3530_L4_PERIPHERAL_SIZE), 341 VM_PROT_READ | VM_PROT_WRITE, 342 PTE_NOCACHE 343 }, 344 { 345 OVERO_GPMC_VBASE, 346 _A(GPMC_BASE), 347 _S(GPMC_SIZE), 348 VM_PROT_READ | VM_PROT_WRITE, 349 PTE_NOCACHE 350 }, 351 #endif 352 { 0, 0, 0, 0, 0 } 353 }; 354 355 #undef _A 356 #undef _S 357 358 359 /* 360 * u_int initarm(...) 361 * 362 * Initial entry point on startup. This gets called before main() is 363 * entered. 364 * It should be responsible for setting up everything that must be 365 * in place when main is called. 366 * This includes 367 * Taking a copy of the boot configuration structure. 368 * Initialising the physical console so characters can be printed. 369 * Setting up page tables for the kernel 370 * Relocating the kernel to the bottom of physical memory 371 */ 372 u_int 373 initarm(void *arg) 374 { 375 extern char KERNEL_BASE_phys[]; 376 extern uint32_t *u_boot_args[]; 377 extern uint32_t ram_size; 378 enum { r0 = 0, r1 = 1, r2 = 2, r3 = 3 }; /* args from u-boot */ 379 380 /* 381 * We mapped PA == VA in gumstix_start.S. 382 * Also mapped SDRAM to KERNEL_BASE first 64Mbyte only with cachable. 383 * 384 * Gumstix (basix, connex, verdex, verdex-pro): 385 * Physical Address Range Description 386 * ----------------------- ---------------------------------- 387 * 0x00000000 - 0x00ffffff flash Memory (16MB or 4MB) 388 * 0x40000000 - 0x480fffff Processor Registers 389 * 0xa0000000 - 0xa3ffffff SDRAM Bank 0 (64MB or 128MB) 390 * 0xc0000000 - 0xc3ffffff KERNEL_BASE 391 * 392 * Overo: 393 * Physical Address Range Description 394 * ----------------------- ---------------------------------- 395 * 0x80000000 - 0x8fffffff SDRAM Bank 0 (256MB or 512MB) 396 * 0x80000000 - 0x83ffffff KERNEL_BASE 397 */ 398 399 #if defined(GUMSTIX) 400 cpu_reset_address = NULL; 401 #elif defined(OVERO) 402 cpu_reset_address = overo_reset; 403 404 find_cpu_clock(); // find our CPU speed. 405 #endif 406 407 /* 408 * Heads up ... Setup the CPU / MMU / TLB functions 409 */ 410 if (set_cpufuncs()) 411 panic("cpu not recognized!"); 412 413 /* map some peripheral registers at static I/O area */ 414 pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap); 415 416 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270) 417 /* start 32.768kHz OSC */ 418 ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON); 419 420 /* Get ready for splfoo() */ 421 pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE); 422 423 /* setup GPIO for {FF,ST,HW}UART. */ 424 pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE); 425 426 pxa2x0_clkman_bootstrap(GUMSTIX_CLKMAN_VBASE); 427 #elif defined(CPU_CORTEX) 428 cortex_pmc_ccnt_init(); 429 #endif 430 431 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 432 433 /* configure GPIOs. */ 434 gxio_config_pin(); 435 436 437 #ifndef GUMSTIX_NETBSD_ARGS_CONSOLE 438 consinit(); 439 #endif 440 #ifdef KGDB 441 kgdb_port_init(); 442 #endif 443 444 /* 445 * Examine the boot args string for options we need to know about 446 * now. 447 */ 448 #if defined(GUMSTIX) 449 #define SDRAM_START 0xa0000000UL 450 #elif defined(OVERO) 451 #define SDRAM_START 0x80000000UL 452 #endif 453 if (((uint32_t)u_boot_args[r0] & 0xf0000000) != SDRAM_START) 454 /* Maybe r0 is 'argc'. We are booted by command 'go'. */ 455 process_kernel_args((int)u_boot_args[r0], 456 (char **)u_boot_args[r1]); 457 else 458 /* 459 * Maybe r3 is 'boot args string' of 'bootm'. This string is 460 * linely. 461 */ 462 process_kernel_args_liner((char *)u_boot_args[r3]); 463 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE 464 consinit(); 465 #endif 466 467 /* Talk to the user */ 468 #define BDSTR(s) _BDSTR(s) 469 #define _BDSTR(s) #s 470 printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n"); 471 472 /* Read system serial */ 473 #if defined(GUMSTIX) 474 read_system_serial(); 475 #endif 476 477 #ifdef VERBOSE_INIT_ARM 478 printf("initarm: Configuring system ...\n"); 479 #endif 480 481 /* Fake bootconfig structure for the benefit of pmap.c */ 482 /* XXX must make the memory description h/w independent */ 483 bootconfig.dramblocks = 1; 484 bootconfig.dram[0].address = SDRAM_START; 485 bootconfig.dram[0].pages = ram_size / PAGE_SIZE; 486 487 KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE); 488 489 arm32_bootmem_init(bootconfig.dram[0].address, ram_size, 490 (uintptr_t) KERNEL_BASE_phys); 491 arm32_kernel_vm_init(KERNEL_VM_BASE, 492 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270) 493 ARM_VECTORS_LOW, 494 #elif defined(CPU_CORTEXA8) 495 ARM_VECTORS_HIGH, 496 #endif 497 0, gumstix_devmap, true); 498 499 evbarm_device_register = gumstix_device_register; 500 501 return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); 502 } 503 504 #if defined(GUMSTIX) 505 static void 506 read_system_serial(void) 507 { 508 #define GUMSTIX_SYSTEM_SERIAL_ADDR 0 509 #define GUMSTIX_SYSTEM_SERIAL_SIZE 8 510 #define FLASH_OFFSET_INTEL_PROTECTION 0x81 511 #define FLASH_OFFSET_USER_PROTECTION 0x85 512 #define FLASH_CMD_READ_ID 0x90 513 #define FLASH_CMD_RESET 0xff 514 int i; 515 char system_serial[GUMSTIX_SYSTEM_SERIAL_SIZE], *src; 516 char x; 517 518 src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/); 519 *(volatile uint16_t *)0 = FLASH_CMD_READ_ID; 520 memcpy(system_serial, 521 src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial)); 522 *(volatile uint16_t *)0 = FLASH_CMD_RESET; 523 524 for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++) 525 x &= system_serial[i]; 526 if (x == 0xff) { 527 src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/); 528 *(volatile uint16_t *)0 = FLASH_CMD_READ_ID; 529 memcpy(system_serial, 530 src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial)); 531 *(volatile uint16_t *)0 = FLASH_CMD_RESET; 532 533 /* 534 * XXXX: Don't need ??? 535 * gumstix_serial_hash(system_serial); 536 */ 537 } 538 system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 | 539 system_serial[2] << 8 | system_serial[3]; 540 system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 | 541 system_serial[6] << 8 | system_serial[7]; 542 543 printf("system serial: 0x"); 544 for (i = 0; i < sizeof (system_serial); i++) 545 printf("%02x", system_serial[i]); 546 printf("\n"); 547 } 548 549 #elif defined(OVERO) 550 551 static void 552 overo_reset(void) 553 { 554 555 #if NPRCM > 0 556 prcm_cold_reset(); 557 #endif 558 } 559 560 static void 561 find_cpu_clock(void) 562 { 563 const vaddr_t prm_base = OMAP2_PRM_BASE; 564 const vaddr_t cm_base = OMAP2_CM_BASE; 565 const uint32_t prm_clksel = 566 *(volatile uint32_t *)(prm_base + PLL_MOD + OMAP3_PRM_CLKSEL); 567 static const uint32_t prm_clksel_freqs[] = OMAP3_PRM_CLKSEL_FREQS; 568 const uint32_t sys_clk = 569 prm_clksel_freqs[__SHIFTOUT(prm_clksel, OMAP3_PRM_CLKSEL_CLKIN)]; 570 const uint32_t dpll1 = 571 *(volatile uint32_t *)(cm_base + OMAP3_CM_CLKSEL1_PLL_MPU); 572 const uint32_t dpll2 = 573 *(volatile uint32_t *)(cm_base + OMAP3_CM_CLKSEL2_PLL_MPU); 574 const uint32_t m = 575 __SHIFTOUT(dpll1, OMAP3_CM_CLKSEL1_PLL_MPU_DPLL_MULT); 576 const uint32_t n = __SHIFTOUT(dpll1, OMAP3_CM_CLKSEL1_PLL_MPU_DPLL_DIV); 577 const uint32_t m2 = 578 __SHIFTOUT(dpll2, OMAP3_CM_CLKSEL2_PLL_MPU_DPLL_CLKOUT_DIV); 579 580 /* 581 * MPU_CLK supplies ARM_FCLK which is twice the CPU frequency. 582 */ 583 curcpu()->ci_data.cpu_cc_freq = 584 ((sys_clk * m) / ((n + 1) * m2 * 2)) * OMAP3_PRM_CLKSEL_MULT; 585 omap_sys_clk = sys_clk * OMAP3_PRM_CLKSEL_MULT; 586 } 587 #endif 588 589 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER 590 static const char busheader_name[] = "busheader="; 591 #endif 592 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \ 593 defined(GUMSTIX_NETBSD_ARGS_EXPANSION) 594 static const char expansion_name[] = "expansion="; 595 #endif 596 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE 597 static const char console_name[] = "console="; 598 #endif 599 static void 600 process_kernel_args(int argc, char *argv[]) 601 { 602 int gxio_configured = 0, i, j; 603 604 boothowto = 0; 605 606 for (i = 1, j = 0; i < argc; i++) { 607 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER 608 if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) { 609 /* Configure for GPIOs of busheader side */ 610 gxio_config_expansion(argv[i] + strlen(busheader_name)); 611 gxio_configured = 1; 612 continue; 613 } 614 #endif 615 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \ 616 defined(GUMSTIX_NETBSD_ARGS_EXPANSION) 617 if (!strncmp(argv[i], expansion_name, strlen(expansion_name))) { 618 /* Configure expansion */ 619 gxio_config_expansion(argv[i] + strlen(expansion_name)); 620 gxio_configured = 1; 621 continue; 622 } 623 #endif 624 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE 625 if (!strncmp(argv[i], console_name, strlen(console_name))) { 626 strncpy(console, argv[i] + strlen(console_name), 627 sizeof(console)); 628 consinit(); 629 } 630 #endif 631 if (j == bootargs_len) { 632 *(bootargs + j) = '\0'; 633 continue; 634 } 635 if (j != 0) 636 *(bootargs + j++) = ' '; 637 strncpy(bootargs + j, argv[i], bootargs_len - j); 638 bootargs[bootargs_len] = '\0'; 639 j += strlen(argv[i]); 640 } 641 boot_args = bootargs; 642 643 parse_mi_bootargs(boot_args); 644 645 if (!gxio_configured) 646 gxio_config_expansion(NULL); 647 } 648 649 static void 650 process_kernel_args_liner(char *args) 651 { 652 int i = 0; 653 char *p = NULL; 654 655 boothowto = 0; 656 657 strncpy(bootargs, args, sizeof(bootargs)); 658 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \ 659 defined(GUMSTIX_NETBSD_ARGS_EXPANSION) 660 { 661 char *q; 662 663 if ((p = strstr(bootargs, expansion_name))) 664 q = p + strlen(expansion_name); 665 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER 666 else if ((p = strstr(bootargs, busheader_name))) 667 q = p + strlen(busheader_name); 668 #endif 669 if (p) { 670 char expansion[256], c; 671 672 i = 0; 673 do { 674 c = *(q + i); 675 if (c == ' ') 676 c = '\0'; 677 expansion[i++] = c; 678 } while (c != '\0' && i < sizeof(expansion)); 679 gxio_config_expansion(expansion); 680 strcpy(p, q + i); 681 } 682 } 683 #endif 684 if (p == NULL) 685 gxio_config_expansion(NULL); 686 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE 687 p = strstr(bootargs, console_name); 688 if (p != NULL) { 689 char c; 690 691 i = 0; 692 do { 693 c = *(p + strlen(console_name) + i); 694 if (c == ' ') 695 c = '\0'; 696 console[i++] = c; 697 } while (c != '\0' && i < sizeof(console)); 698 consinit(); 699 strcpy(p, p + strlen(console_name) + i); 700 } 701 #endif 702 boot_args = bootargs; 703 704 parse_mi_bootargs(boot_args); 705 } 706 707 #ifdef KGDB 708 #ifndef KGDB_DEVNAME 709 #define KGDB_DEVNAME "ffuart" 710 #endif 711 const char kgdb_devname[] = KGDB_DEVNAME; 712 713 #ifndef KGDB_DEVRATE 714 #define KGDB_DEVRATE CONSPEED 715 #endif 716 int kgdb_devrate = KGDB_DEVRATE; 717 718 #if (NCOM > 0) 719 #ifndef KGDB_DEVMODE 720 #define KGDB_DEVMODE CONMODE 721 #endif 722 int comkgdbmode = KGDB_DEVMODE; 723 #endif /* NCOM */ 724 725 #endif /* KGDB */ 726 727 728 void 729 consinit(void) 730 { 731 static int consinit_called = 0; 732 733 if (consinit_called != 0) 734 return; 735 736 consinit_called = 1; 737 738 #if NCOM > 0 739 740 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE 741 /* Maybe passed Linux's bootargs 'console=ttyS?,<speed>...' */ 742 if (strncmp(console, "ttyS", 4) == 0 && console[5] == ',') { 743 int i; 744 745 comcnspeed = 0; 746 for (i = 6; i < strlen(console) && isdigit(console[i]); i++) 747 comcnspeed = comcnspeed * 10 + (console[i] - '0'); 748 } 749 #endif 750 751 #if defined(GUMSTIX) 752 753 #ifdef FFUARTCONSOLE 754 #ifdef KGDB 755 if (strcmp(kgdb_devname, "ffuart") == 0){ 756 /* port is reserved for kgdb */ 757 } else 758 #endif 759 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE) 760 if (console[0] == '\0' || strcasecmp(console, "ffuart") == 0 || 761 strncmp(console, "ttyS0,", 6) == 0) 762 #endif 763 { 764 int rv; 765 766 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE, 767 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode); 768 if (rv == 0) { 769 pxa2x0_clkman_config(CKEN_FFUART, 1); 770 return; 771 } 772 } 773 #endif /* FFUARTCONSOLE */ 774 775 #ifdef STUARTCONSOLE 776 #ifdef KGDB 777 if (strcmp(kgdb_devname, "stuart") == 0) { 778 /* port is reserved for kgdb */ 779 } else 780 #endif 781 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE) 782 if (console[0] == '\0' || strcasecmp(console, "stuart") == 0) 783 #endif 784 { 785 int rv; 786 787 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE, 788 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode); 789 if (rv == 0) { 790 pxa2x0_clkman_config(CKEN_STUART, 1); 791 return; 792 } 793 } 794 #endif /* STUARTCONSOLE */ 795 796 #ifdef BTUARTCONSOLE 797 #ifdef KGDB 798 if (strcmp(kgdb_devname, "btuart") == 0) { 799 /* port is reserved for kgdb */ 800 } else 801 #endif 802 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE) 803 if (console[0] == '\0' || strcasecmp(console, "btuart") == 0) 804 #endif 805 { 806 int rv; 807 808 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE, 809 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode); 810 if (rv == 0) { 811 pxa2x0_clkman_config(CKEN_BTUART, 1); 812 return; 813 } 814 } 815 #endif /* BTUARTCONSOLE */ 816 817 #ifdef HWUARTCONSOLE 818 #ifdef KGDB 819 if (strcmp(kgdb_devname, "hwuart") == 0) { 820 /* port is reserved for kgdb */ 821 } else 822 #endif 823 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE) 824 if (console[0] == '\0' || strcasecmp(console, "hwuart") == 0) 825 #endif 826 { 827 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE, 828 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode); 829 if (rv == 0) { 830 pxa2x0_clkman_config(CKEN_HWUART, 1); 831 return; 832 } 833 } 834 #endif /* HWUARTCONSOLE */ 835 836 #elif defined(OVERO) 837 838 if (comcnattach(&omap_a4x_bs_tag, 0x49020000, comcnspeed, 839 OMAP_COM_FREQ, COM_TYPE_NORMAL, comcnmode) == 0) 840 return; 841 842 #endif /* GUMSTIX or OVERO */ 843 844 #endif /* NCOM */ 845 846 #if NLCD > 0 847 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE) 848 if (console[0] == '\0' || strcasecmp(console, "lcd") == 0) 849 #endif 850 { 851 gxlcd_cnattach(); 852 } 853 #endif 854 } 855 856 #ifdef KGDB 857 static void 858 kgdb_port_init(void) 859 { 860 #if (NCOM > 0) && defined(COM_PXA2X0) 861 paddr_t paddr = 0; 862 int cken = 0; 863 864 if (0 == strcmp(kgdb_devname, "ffuart")) { 865 paddr = PXA2X0_FFUART_BASE; 866 cken = CKEN_FFUART; 867 } else if (0 == strcmp(kgdb_devname, "stuart")) { 868 paddr = PXA2X0_STUART_BASE; 869 cken = CKEN_STUART; 870 } else if (0 == strcmp(kgdb_devname, "btuart")) { 871 paddr = PXA2X0_BTUART_BASE; 872 cken = CKEN_BTUART; 873 } else if (0 == strcmp(kgdb_devname, "hwuart")) { 874 paddr = PXA2X0_HWUART_BASE; 875 cken = CKEN_HWUART; 876 } 877 878 if (paddr && 879 0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr, 880 kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) { 881 882 pxa2x0_clkman_config(cken, 1); 883 } 884 885 #endif 886 } 887 #endif 888 889 static void 890 gumstix_device_register(device_t dev, void *aux) 891 { 892 prop_dictionary_t dict = device_properties(dev); 893 894 if (device_is_a(dev, "ehci")) { 895 prop_dictionary_set_uint16(dict, "nports", 2); 896 prop_dictionary_set_bool(dict, "phy-reset", true); 897 prop_dictionary_set_cstring(dict, "port0-mode", "none"); 898 prop_dictionary_set_int16(dict, "port0-gpio", -1); 899 prop_dictionary_set_cstring(dict, "port1-mode", "phy"); 900 prop_dictionary_set_int16(dict, "port1-gpio", 183); 901 prop_dictionary_set_bool(dict, "port1-gpioval", true); 902 prop_dictionary_set_uint16(dict, "dpll5-m", 443); 903 prop_dictionary_set_uint16(dict, "dpll5-n", 11); 904 prop_dictionary_set_uint16(dict, "dpll5-m2", 4); 905 } 906 if (device_is_a(dev, "ohci")) { 907 if (prop_dictionary_set_bool(dict, 908 "Ganged-power-mask-on-port1", 1) == false) { 909 printf("WARNING: unable to set power-mask for port1" 910 " property for %s\n", device_xname(dev)); 911 } 912 if (prop_dictionary_set_bool(dict, 913 "Ganged-power-mask-on-port2", 1) == false) { 914 printf("WARNING: unable to set power-mask for port2" 915 " property for %s\n", device_xname(dev)); 916 } 917 if (prop_dictionary_set_bool(dict, 918 "Ganged-power-mask-on-port3", 1) == false) { 919 printf("WARNING: unable to set power-mask for port3" 920 " property for %s\n", device_xname(dev)); 921 } 922 } 923 } 924