gumstix_machdep.c revision 1.69.2.1 1 /* $NetBSD: gumstix_machdep.c,v 1.69.2.1 2020/12/14 14:37:52 thorpej 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 #include "opt_multiprocessor.h"
148 #if defined(OVERO) || defined(DUOVERO) || defined(PEPPER)
149 #include "opt_omap.h"
150
151 #if defined(DUOVERO)
152 #include "arml2cc.h"
153 #endif
154 #include "prcm.h"
155
156 #include "arma9tmr.h"
157 #include "armgtmr.h"
158 #endif
159
160 #include <sys/param.h>
161 #include <sys/conf.h>
162 #include <sys/device.h>
163 #include <sys/exec.h>
164 #include <sys/kernel.h>
165 #include <sys/proc.h>
166 #include <sys/reboot.h>
167 #include <sys/systm.h>
168 #include <sys/termios.h>
169 #include <sys/bus.h>
170 #include <sys/cpu.h>
171 #include <sys/gpio.h>
172
173 #include <prop/proplib.h>
174
175 #include <uvm/uvm_extern.h>
176
177 #include <arm/mainbus/mainbus.h> /* don't reorder */
178
179 #include <machine/autoconf.h> /* don't reorder */
180 #include <machine/bootconfig.h>
181 #include <arm/locore.h>
182
183 #include <arm/arm32/machdep.h>
184
185 #include <arm/omap/omap2_obiovar.h>
186 #include <arm/omap/am335x_prcm.h>
187 #include <arm/omap/omap2_gpio.h>
188 #include <arm/omap/omap2_gpmcreg.h>
189 #include <arm/omap/omap2_prcm.h>
190 #if defined(OVERO) || defined(DUOVERO) || defined(PEPPER)
191 #include <arm/omap/omap2_reg.h> /* Must required "opt_omap.h" */
192 #endif
193 #include <arm/omap/omap3_sdmmcreg.h>
194 #include <arm/omap/omap_var.h>
195 #include <arm/omap/omap_com.h>
196 #include <arm/omap/tifbvar.h>
197
198 #include <arm/xscale/pxa2x0reg.h>
199 #include <arm/xscale/pxa2x0var.h>
200 #include <arm/xscale/pxa2x0_gpio.h>
201 #include <evbarm/gumstix/gumstixreg.h>
202 #include <evbarm/gumstix/gumstixvar.h>
203
204 #include <arm/cortex/pl310_var.h>
205 #include <arm/cortex/pl310_reg.h>
206 #include <arm/cortex/scu_reg.h>
207
208 #include <arm/cortex/a9tmr_var.h>
209
210 #include <arm/cortex/gtmr_var.h>
211
212 #include <dev/cons.h>
213
214 #ifdef KGDB
215 #include <sys/kgdb.h>
216 #endif
217
218 #ifdef VERBOSE_INIT_ARM
219 #define VPRINTF(...) printf(__VA_ARGS__)
220 #else
221 #define VPRINTF(...) __nothing
222 #endif
223
224 /*
225 * The range 0xc1000000 - 0xfd000000 is available for kernel VM space
226 * Core-logic registers and I/O mappings occupy
227 *
228 * 0xfd000000 - 0xfd800000 on gumstix
229 * 0xc0000000 - 0xc0400000 on overo, duovero and pepper
230 */
231 #ifndef KERNEL_VM_BASE
232 #define KERNEL_VM_BASE 0xc8000000
233 #endif
234 #define KERNEL_VM_SIZE 0x35000000
235
236 BootConfig bootconfig; /* Boot config storage */
237 static char bootargs[MAX_BOOT_STRING];
238 const size_t bootargs_len = sizeof(bootargs) - 1; /* without nul */
239 char *boot_args = NULL;
240
241 uint32_t system_serial_high;
242 uint32_t system_serial_low;
243
244 /* Prototypes */
245 #if defined(GUMSTIX)
246 static void read_system_serial(void);
247 #endif
248 #if defined(OMAP2)
249 static void omap_reset(void);
250 static void find_cpu_clock(void);
251 #endif
252 static void process_kernel_args(int, char *[]);
253 static void process_kernel_args_liner(char *);
254 #ifdef KGDB
255 static void kgdb_port_init(void);
256 #endif
257 static void gumstix_device_register(device_t, void *);
258
259 bs_protos(bs_notimpl);
260
261 #include "com.h"
262 #if NCOM > 0
263 #include <dev/ic/comreg.h>
264 #include <dev/ic/comvar.h>
265 #endif
266
267 #if defined(CPU_XSCALE)
268 #include "lcd.h"
269 #endif
270
271 #ifndef CONSPEED
272 #define CONSPEED B115200 /* It's a setting of the default of u-boot */
273 #endif
274 #ifndef CONMODE
275 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
276 #endif
277
278 int comcnspeed = CONSPEED;
279 int comcnmode = CONMODE;
280
281 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
282 static char console[16];
283 #endif
284
285 const struct tifb_panel_info *tifb_panel_info = NULL;
286 /* Use TPS65217 White LED Driver */
287 bool use_tps65217_wled = false;
288
289 extern void gxio_config(void);
290 extern void gxio_config_expansion(char *);
291
292
293 static inline pd_entry_t *
294 read_ttb(void)
295 {
296 long ttb;
297
298 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
299
300 return (pd_entry_t *)(ttb & ~((1<<14)-1));
301 }
302
303 /*
304 * Static device mappings. These peripheral registers are mapped at
305 * fixed virtual addresses very early in initarm() so that we can use
306 * them while booting the kernel, and stay at the same address
307 * throughout whole kernel's life time.
308 *
309 * We use this table twice; once with bootstrap page table, and once
310 * with kernel's page table which we build up in initarm().
311 *
312 * Since we map these registers into the bootstrap page table using
313 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
314 * registers segment-aligned and segment-rounded in order to avoid
315 * using the 2nd page tables.
316 */
317
318 #define _A(a) ((a) & ~L1_S_OFFSET)
319 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
320
321 static const struct pmap_devmap gumstix_devmap[] = {
322 #if defined(GUMSTIX)
323 {
324 GUMSTIX_GPIO_VBASE,
325 _A(PXA2X0_GPIO_BASE),
326 _S(PXA250_GPIO_SIZE),
327 VM_PROT_READ | VM_PROT_WRITE,
328 PTE_NOCACHE,
329 },
330 {
331 GUMSTIX_CLKMAN_VBASE,
332 _A(PXA2X0_CLKMAN_BASE),
333 _S(PXA2X0_CLKMAN_SIZE),
334 VM_PROT_READ | VM_PROT_WRITE,
335 PTE_NOCACHE,
336 },
337 {
338 GUMSTIX_INTCTL_VBASE,
339 _A(PXA2X0_INTCTL_BASE),
340 _S(PXA2X0_INTCTL_SIZE),
341 VM_PROT_READ | VM_PROT_WRITE,
342 PTE_NOCACHE,
343 },
344 {
345 GUMSTIX_FFUART_VBASE,
346 _A(PXA2X0_FFUART_BASE),
347 _S(4 * COM_NPORTS),
348 VM_PROT_READ | VM_PROT_WRITE,
349 PTE_NOCACHE,
350 },
351 {
352 GUMSTIX_STUART_VBASE,
353 _A(PXA2X0_STUART_BASE),
354 _S(4 * COM_NPORTS),
355 VM_PROT_READ | VM_PROT_WRITE,
356 PTE_NOCACHE,
357 },
358 {
359 GUMSTIX_BTUART_VBASE,
360 _A(PXA2X0_BTUART_BASE),
361 _S(4 * COM_NPORTS),
362 VM_PROT_READ | VM_PROT_WRITE,
363 PTE_NOCACHE,
364 },
365 {
366 GUMSTIX_HWUART_VBASE,
367 _A(PXA2X0_HWUART_BASE),
368 _S(4 * COM_NPORTS),
369 VM_PROT_READ | VM_PROT_WRITE,
370 PTE_NOCACHE,
371 },
372 {
373 GUMSTIX_LCDC_VBASE,
374 _A(PXA2X0_LCDC_BASE),
375 _S(4 * COM_NPORTS),
376 VM_PROT_READ | VM_PROT_WRITE,
377 PTE_NOCACHE,
378 },
379 #elif defined(OVERO)
380 { /* SCM, PRCM */
381 OVERO_L4_CORE_VBASE,
382 _A(OMAP3530_L4_CORE_BASE),
383 _S(L1_S_SIZE), /* No need 16MB. Use only first 1MB */
384 VM_PROT_READ | VM_PROT_WRITE,
385 PTE_NOCACHE
386 },
387 { /* Console, GPIO[2-6] */
388 OVERO_L4_PERIPHERAL_VBASE,
389 _A(OMAP3530_L4_PERIPHERAL_BASE),
390 _S(OMAP3530_L4_PERIPHERAL_SIZE),
391 VM_PROT_READ | VM_PROT_WRITE,
392 PTE_NOCACHE
393 },
394 { /* GPIO1 */
395 OVERO_L4_WAKEUP_VBASE,
396 _A(OMAP3530_L4_WAKEUP_BASE),
397 _S(OMAP3530_L4_WAKEUP_SIZE),
398 VM_PROT_READ | VM_PROT_WRITE,
399 PTE_NOCACHE
400 },
401 {
402 OVERO_GPMC_VBASE,
403 _A(GPMC_BASE),
404 _S(GPMC_SIZE),
405 VM_PROT_READ | VM_PROT_WRITE,
406 PTE_NOCACHE
407 },
408 {
409 OVERO_SRDC_VBASE,
410 _A(OMAP3530_SDRC_BASE),
411 _S(OMAP3530_SDRC_SIZE),
412 VM_PROT_READ | VM_PROT_WRITE,
413 PTE_NOCACHE
414 },
415 #elif defined(DUOVERO)
416 {
417 DUOVERO_L4_CM_VBASE,
418 _A(OMAP4430_L4_CORE_BASE + 0x100000),
419 _S(L1_S_SIZE),
420 VM_PROT_READ | VM_PROT_WRITE,
421 PTE_NOCACHE
422 },
423 { /* Console, SCU, L2CC, GPIO[2-6] */
424 DUOVERO_L4_PERIPHERAL_VBASE,
425 _A(OMAP4430_L4_PERIPHERAL_BASE),
426 _S(L1_S_SIZE * 3),
427 VM_PROT_READ | VM_PROT_WRITE,
428 PTE_NOCACHE
429 },
430 { /* PRCM, GPIO1 */
431 DUOVERO_L4_WAKEUP_VBASE,
432 _A(OMAP4430_L4_WAKEUP_BASE),
433 _S(OMAP4430_L4_WAKEUP_SIZE),
434 VM_PROT_READ | VM_PROT_WRITE,
435 PTE_NOCACHE
436 },
437 {
438 DUOVERO_GPMC_VBASE,
439 _A(GPMC_BASE),
440 _S(GPMC_SIZE),
441 VM_PROT_READ | VM_PROT_WRITE,
442 PTE_NOCACHE
443 },
444 {
445 DUOVERO_DMM_VBASE,
446 _A(OMAP4430_DMM_BASE),
447 _S(OMAP4430_DMM_SIZE),
448 VM_PROT_READ | VM_PROT_WRITE,
449 PTE_NOCACHE
450 },
451 #elif defined(PEPPER)
452 {
453 /* CM, Control Module, GPIO0, Console */
454 PEPPER_PRCM_VBASE,
455 _A(OMAP2_CM_BASE),
456 _S(L1_S_SIZE),
457 VM_PROT_READ | VM_PROT_WRITE,
458 PTE_NOCACHE
459 },
460 {
461 /* GPIO[1-3] */
462 PEPPER_L4_PERIPHERAL_VBASE,
463 _A(TI_AM335X_L4_PERIPHERAL_BASE),
464 _S(L1_S_SIZE),
465 VM_PROT_READ | VM_PROT_WRITE,
466 PTE_NOCACHE
467 },
468 #endif
469 { 0, 0, 0, 0, 0 }
470 };
471
472 #undef _A
473 #undef _S
474
475 #ifdef MULTIPROCESSOR
476 void gumstix_cpu_hatch(struct cpu_info *);
477
478 void
479 gumstix_cpu_hatch(struct cpu_info *ci)
480 {
481 #if NARMA9TMR > 0
482 if (CPU_ID_CORTEX_A9_P(curcpu()->ci_arm_cpuid)) {
483 a9tmr_init_cpu_clock(ci);
484 }
485 #endif
486 #if NARMGTMR > 0
487 if (CPU_ID_CORTEX_A7_P(curcpu()->ci_arm_cpuid) ||
488 CPU_ID_CORTEX_A15_P(curcpu()->ci_arm_cpuid)) {
489 gtmr_init_cpu_clock(ci);
490 }
491 #endif
492 }
493 #endif
494
495
496 static void
497 gumstix_mpstart(void)
498 {
499 #if defined(MULTIPROCESSOR)
500 const bus_space_tag_t iot = &omap_bs_tag;
501 int error;
502
503 if (CPU_ID_CORTEX_A9_P(curcpu()->ci_arm_cpuid)) {
504 bus_space_handle_t scu_ioh;
505 error = bus_space_map(iot, OMAP4_SCU_BASE, OMAP4_SCU_SIZE, 0, &scu_ioh);
506 if (error)
507 panic("Could't map OMAP4_SCU_BASE");
508
509 /*
510 * Invalidate all SCU cache tags. That is, for all cores (0-3)
511 */
512 bus_space_write_4(iot, scu_ioh, SCU_INV_ALL_REG, 0xffff);
513
514 uint32_t diagctl = bus_space_read_4(iot, scu_ioh, SCU_DIAG_CONTROL);
515 diagctl |= SCU_DIAG_DISABLE_MIGBIT;
516 bus_space_write_4(iot, scu_ioh, SCU_DIAG_CONTROL, diagctl);
517
518 uint32_t scu_ctl = bus_space_read_4(iot, scu_ioh, SCU_CTL);
519 scu_ctl |= SCU_CTL_SCU_ENA;
520 bus_space_write_4(iot, scu_ioh, SCU_CTL, scu_ctl);
521
522 armv7_dcache_wbinv_all();
523 }
524
525 bus_space_handle_t wugen_ioh;
526 error = bus_space_map(iot, OMAP4_WUGEN_BASE, OMAP4_WUGEN_SIZE, 0,
527 &wugen_ioh);
528 if (error)
529 panic("Couldn't map OMAP4_WUGEN_BASE");
530 const paddr_t mpstart = KERN_VTOPHYS((vaddr_t)cpu_mpstart);
531
532 bus_space_write_4(iot, wugen_ioh, OMAP4_AUX_CORE_BOOT1, mpstart);
533
534 for (size_t i = 1; i < arm_cpu_max; i++) {
535 uint32_t boot = bus_space_read_4(iot, wugen_ioh, OMAP4_AUX_CORE_BOOT0);
536 boot |= __SHIFTIN(0xf, i * 4);
537 bus_space_write_4(iot, wugen_ioh, OMAP4_AUX_CORE_BOOT0, boot);
538 }
539
540 dsb(sy);
541 sev();
542
543 u_int i;
544 for (i = 0x10000000; i > 0; i--) {
545 if (cpu_hatched_p(cpuindex))
546 break;
547 }
548
549 if (i == 0) {
550 aprint_error("cpu%d: WARNING: AP failed to start\n",
551 cpuindex);
552 }
553 #endif
554 }
555
556 #if defined(CPU_CORTEX)
557 /* filled in before cleaning bss. keep in .data */
558 u_int uboot_args[4] __attribute__((__section__(".data")));
559 #else
560 extern uint32_t *uboot_args;
561 #endif
562
563 /*
564 * vaddr_t initarm(...)
565 *
566 * Initial entry point on startup. This gets called before main() is
567 * entered.
568 * It should be responsible for setting up everything that must be
569 * in place when main is called.
570 * This includes
571 * Taking a copy of the boot configuration structure.
572 * Initialising the physical console so characters can be printed.
573 * Setting up page tables for the kernel
574 * Relocating the kernel to the bottom of physical memory
575 */
576 vaddr_t
577 initarm(void *arg)
578 {
579 extern char KERNEL_BASE_phys[];
580 uint32_t ram_size = 0x400000;
581 enum { r0 = 0, r1 = 1, r2 = 2, r3 = 3 }; /* args from u-boot */
582
583 #if defined(OVERO) || defined(DUOVERO) /* || defined(PEPPER) */
584 const bus_space_tag_t iot = &omap_bs_tag;
585 #endif
586
587 #if defined(CPU_XSCALE)
588
589 /*
590 * We mapped PA == VA in gumstix_start.S.
591 * Also mapped SDRAM to KERNEL_BASE first 64Mbyte only with cachable.
592 *
593 * Gumstix (basix, connex, verdex, verdex-pro):
594 * Physical Address Range Description
595 * ----------------------- ----------------------------------
596 * 0x00000000 - 0x00ffffff flash Memory (16MB or 4MB)
597 * 0x40000000 - 0x480fffff Processor Registers
598 * 0xa0000000 - 0xa3ffffff SDRAM Bank 0 (64MB or 128MB)
599 * 0xc0000000 - 0xc3ffffff KERNEL_BASE
600 */
601 extern vaddr_t xscale_cache_clean_addr;
602 xscale_cache_clean_addr = 0xff000000U;
603
604 cpu_reset_address = NULL;
605 #elif defined(OMAP2)
606 cpu_reset_address = omap_reset;
607
608 find_cpu_clock();
609 #endif
610
611 /*
612 * Heads up ... Setup the CPU / MMU / TLB functions
613 */
614 if (set_cpufuncs())
615 panic("cpu not recognized!");
616
617 /* map some peripheral registers at static I/O area */
618 pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap);
619
620 #if defined(CPU_XSCALE)
621 /* start 32.768kHz OSC */
622 ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON);
623
624 /* Get ready for splfoo() */
625 pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE);
626
627 /* setup GPIO for {FF,ST,HW}UART. */
628 pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
629
630 pxa2x0_clkman_bootstrap(GUMSTIX_CLKMAN_VBASE);
631 #endif
632
633
634 #if defined(OVERO)
635
636 #define OMAP3530_SRDC_MCFG_p(p) (0x80 + ((p) * 0x30))
637 #define OMAP3530_SRDC_MCFG_RAMSIZE __BITS(17,8)
638
639 bus_space_handle_t sdrcioh;
640 if (bus_space_map(iot, OMAP3530_SDRC_BASE, OMAP3530_SDRC_SIZE,
641 0, &sdrcioh) != 0)
642 panic("OMAP_SDRC_BASE map failed\n");
643
644 ram_size = 0;
645 for (u_int p = 0; p < 2; p++) {
646 uint32_t mcfg = bus_space_read_4(iot, sdrcioh,
647 OMAP3530_SRDC_MCFG_p(p));
648 ram_size += __SHIFTOUT(mcfg, OMAP3530_SRDC_MCFG_RAMSIZE) *
649 (2 * 1024 * 1024);
650 }
651
652 #elif defined(DUOVERO)
653
654 #define OMAP4_DMM_LISA_MAP_i(i) (0x40 + ((i) * 0x4))
655 #define OMAP4_DMM_LISA_SYS_ADDR __BITS(31,24)
656 #define OMAP4_DMM_LISA_SYS_SIZE __BITS(22,20)
657 #define OMAP4_DMM_LISA_SDRC_ADDRSPC __BITS(17,16)
658
659 bus_space_handle_t dmmioh;
660 if (bus_space_map(iot, OMAP4430_DMM_BASE, OMAP4430_DMM_SIZE, 0,
661 &dmmioh) != 0)
662 panic("OMAP4_DMM_BASE map failed\n");
663
664 ram_size = 0;
665 for (u_int i = 0; i < 4; i++) {
666 const uint32_t lisa = bus_space_read_4(iot, dmmioh,
667 OMAP4_DMM_LISA_MAP_i(i));
668
669 const uint32_t sys_addr =
670 __SHIFTOUT(lisa, OMAP4_DMM_LISA_SYS_ADDR);
671 /* skip non-physical */
672 if ((sys_addr & 0x80) != 0)
673 continue;
674
675 const uint32_t sdrc_addrspc =
676 __SHIFTOUT(lisa, OMAP4_DMM_LISA_SDRC_ADDRSPC);
677 /* Skip reserced areas */
678 if (sdrc_addrspc == 2)
679 continue;
680
681 const uint32_t sys_size =
682 __SHIFTOUT(lisa, OMAP4_DMM_LISA_SYS_SIZE);
683 ram_size += (16 * 1024 * 1024) << sys_size;
684 }
685
686
687 #endif
688
689 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
690
691 /* configure MUX, GPIO and CLK. */
692 gxio_config();
693
694 #ifndef GUMSTIX_NETBSD_ARGS_CONSOLE
695 consinit();
696 #endif
697 #ifdef KGDB
698 kgdb_port_init();
699 #endif
700
701 /*
702 * Examine the boot args string for options we need to know about
703 * now.
704 */
705 #if defined(GUMSTIX)
706 #define SDRAM_START 0xa0000000UL
707 #elif defined(OVERO) || defined(DUOVERO) || defined(PEPPER)
708 #define SDRAM_START 0x80000000UL
709 #endif
710 if (uboot_args[r0] < SDRAM_START ||
711 uboot_args[r0] >= SDRAM_START + ram_size)
712 /* Maybe r0 is 'argc'. We are booted by command 'go'. */
713 process_kernel_args(uboot_args[r0], (char **)uboot_args[r1]);
714 else
715 /*
716 * Maybe r3 is 'boot args string' of 'bootm'. This string is
717 * linely.
718 */
719 process_kernel_args_liner((char *)uboot_args[r3]);
720 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
721 consinit();
722 #endif
723
724 /* Talk to the user */
725 #define BDSTR(s) _BDSTR(s)
726 #define _BDSTR(s) #s
727 printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
728
729 /* Read system serial */
730 #if defined(GUMSTIX)
731 read_system_serial();
732 #endif
733
734 VPRINTF("initarm: Configuring system ...\n");
735
736 #if defined(OMAP_4430)
737 bus_space_handle_t ioh;
738
739 #if NARML2CC > 0
740 /*
741 * Initialize L2-Cache parameters
742 */
743
744 if (bus_space_map(iot, OMAP4_L2CC_BASE, OMAP4_L2CC_SIZE, 0, &ioh) != 0)
745 panic("OMAP4_L2CC_BASE map failed\n");
746 arml2cc_init(iot, ioh, 0);
747 #endif
748
749 #ifdef MULTIPROCESSOR
750 if (bus_space_map(iot, OMAP4_SCU_BASE, SCU_SIZE, 0, &ioh) != 0)
751 panic("OMAP4_SCU_BASE map failed\n");
752 arm_cpu_max =
753 1 + (bus_space_read_4(iot, ioh, SCU_CFG) & SCU_CFG_CPUMAX);
754 #endif
755 #endif
756
757 /* Fake bootconfig structure for the benefit of pmap.c */
758 /* XXX must make the memory description h/w independent */
759 bootconfig.dramblocks = 1;
760 bootconfig.dram[0].address = SDRAM_START;
761 bootconfig.dram[0].pages = ram_size / PAGE_SIZE;
762
763 KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE);
764
765 arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
766 (uintptr_t) KERNEL_BASE_phys);
767 arm32_kernel_vm_init(KERNEL_VM_BASE,
768 #if defined(CPU_XSCALE)
769 ARM_VECTORS_LOW,
770 #elif defined(CPU_CORTEX)
771 ARM_VECTORS_HIGH,
772 #endif
773 0, gumstix_devmap, true);
774
775 evbarm_device_register = gumstix_device_register;
776
777 vaddr_t sp = initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
778
779 /*
780 * initarm_common flushes cache if required before AP start
781 */
782 gumstix_mpstart();
783
784 return sp;
785 }
786
787 #if defined(GUMSTIX)
788 static void
789 read_system_serial(void)
790 {
791 #define GUMSTIX_SYSTEM_SERIAL_ADDR 0
792 #define GUMSTIX_SYSTEM_SERIAL_SIZE 8
793 #define FLASH_OFFSET_INTEL_PROTECTION 0x81
794 #define FLASH_OFFSET_USER_PROTECTION 0x85
795 #define FLASH_CMD_READ_ID 0x90
796 #define FLASH_CMD_RESET 0xff
797 int i;
798 char system_serial[GUMSTIX_SYSTEM_SERIAL_SIZE], *src;
799 char x;
800
801 src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/);
802 *(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
803 memcpy(system_serial,
804 src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
805 *(volatile uint16_t *)0 = FLASH_CMD_RESET;
806
807 for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++)
808 x &= system_serial[i];
809 if (x == 0xff) {
810 src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/);
811 *(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
812 memcpy(system_serial,
813 src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
814 *(volatile uint16_t *)0 = FLASH_CMD_RESET;
815
816 /*
817 * XXXX: Don't need ???
818 * gumstix_serial_hash(system_serial);
819 */
820 }
821 system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 |
822 system_serial[2] << 8 | system_serial[3];
823 system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 |
824 system_serial[6] << 8 | system_serial[7];
825
826 printf("system serial: 0x");
827 for (i = 0; i < sizeof (system_serial); i++)
828 printf("%02x", system_serial[i]);
829 printf("\n");
830 }
831 #endif
832
833 #if defined(OMAP2)
834 static void
835 omap_reset(void)
836 {
837
838 #if defined(TI_AM335X)
839 vaddr_t prm_base = (PEPPER_PRCM_VBASE + AM335X_PRCM_PRM_DEVICE);
840
841 *(volatile uint32_t *)(prm_base + PRM_RSTCTRL) = RST_GLOBAL_WARM_SW;
842 #elif defined(OMAP_4430)
843 *(volatile uint32_t *)(DUOVERO_L4_WAKEUP_VBASE + OMAP4_PRM_RSTCTRL) =
844 OMAP4_PRM_RSTCTRL_WARM;
845 #endif
846
847 #if NPRCM > 0
848 prcm_cold_reset();
849 #endif
850 }
851
852 static void
853 find_cpu_clock(void)
854 {
855 const vaddr_t prm_base __unused = OMAP2_PRM_BASE;
856 const vaddr_t cm_base = OMAP2_CM_BASE;
857
858 #if defined(OMAP_3530)
859
860 const uint32_t prm_clksel =
861 *(volatile uint32_t *)(prm_base + PLL_MOD + OMAP3_PRM_CLKSEL);
862 static const uint32_t prm_clksel_freqs[] = OMAP3_PRM_CLKSEL_FREQS;
863 const uint32_t sys_clk =
864 prm_clksel_freqs[__SHIFTOUT(prm_clksel, OMAP3_PRM_CLKSEL_CLKIN)];
865 const uint32_t dpll1 =
866 *(volatile uint32_t *)(cm_base + OMAP3_CM_CLKSEL1_PLL_MPU);
867 const uint32_t dpll2 =
868 *(volatile uint32_t *)(cm_base + OMAP3_CM_CLKSEL2_PLL_MPU);
869 const uint32_t m =
870 __SHIFTOUT(dpll1, OMAP3_CM_CLKSEL1_PLL_MPU_DPLL_MULT);
871 const uint32_t n = __SHIFTOUT(dpll1, OMAP3_CM_CLKSEL1_PLL_MPU_DPLL_DIV);
872 const uint32_t m2 =
873 __SHIFTOUT(dpll2, OMAP3_CM_CLKSEL2_PLL_MPU_DPLL_CLKOUT_DIV);
874
875 /*
876 * MPU_CLK supplies ARM_FCLK which is twice the CPU frequency.
877 */
878 curcpu()->ci_data.cpu_cc_freq =
879 ((sys_clk * m) / ((n + 1) * m2 * 2)) * OMAP3_PRM_CLKSEL_MULT;
880 omap_sys_clk = sys_clk * OMAP3_PRM_CLKSEL_MULT;
881
882 #elif defined(OMAP_4430)
883
884 const uint32_t prm_clksel =
885 *(volatile uint32_t *)(prm_base + OMAP4_CM_SYS_CLKSEL);
886 static const uint32_t cm_clksel_freqs[] = OMAP4_CM_CLKSEL_FREQS;
887 const uint32_t sys_clk =
888 cm_clksel_freqs[__SHIFTOUT(prm_clksel, OMAP4_CM_SYS_CLKSEL_CLKIN)];
889 const uint32_t dpll1 =
890 *(volatile uint32_t *)(cm_base + OMAP4_CM_CLKSEL_DPLL_MPU);
891 const uint32_t dpll2 =
892 *(volatile uint32_t *)(cm_base + OMAP4_CM_DIV_M2_DPLL_MPU);
893 const uint32_t m =
894 __SHIFTOUT(dpll1, OMAP4_CM_CLKSEL_DPLL_MPU_DPLL_MULT);
895 const uint32_t n = __SHIFTOUT(dpll1, OMAP4_CM_CLKSEL_DPLL_MPU_DPLL_DIV);
896 const uint32_t m2 =
897 __SHIFTOUT(dpll2, OMAP4_CM_DIV_M2_DPLL_MPU_DPLL_CLKOUT_DIV);
898
899 /*
900 * MPU_CLK supplies ARM_FCLK which is twice the CPU frequency.
901 */
902 curcpu()->ci_data.cpu_cc_freq =
903 ((sys_clk * 2 * m) / ((n + 1) * m2)) * OMAP4_CM_CLKSEL_MULT / 2;
904 omap_sys_clk = sys_clk * OMAP4_CM_CLKSEL_MULT;
905
906 #elif defined(TI_AM335X)
907
908 prcm_bootstrap(cm_base);
909 am335x_sys_clk(TI_AM335X_CTLMOD_BASE);
910 am335x_cpu_clk();
911
912 #endif
913 }
914 #endif
915
916 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
917 static const char busheader_name[] = "busheader=";
918 #endif
919 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
920 defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
921 static const char expansion_name[] = "expansion=";
922 #endif
923 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
924 static const char console_name[] = "console=";
925 #endif
926 static void
927 process_kernel_args(int argc, char *argv[])
928 {
929 int gxio_configured = 0, i, j;
930
931 boothowto = 0;
932
933 for (i = 1, j = 0; i < argc; i++) {
934 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
935 if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) {
936 /* Configure for GPIOs of busheader side */
937 gxio_config_expansion(argv[i] + strlen(busheader_name));
938 gxio_configured = 1;
939 continue;
940 }
941 #endif
942 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
943 defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
944 if (!strncmp(argv[i], expansion_name, strlen(expansion_name))) {
945 /* Configure expansion */
946 gxio_config_expansion(argv[i] + strlen(expansion_name));
947 gxio_configured = 1;
948 continue;
949 }
950 #endif
951 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
952 if (!strncmp(argv[i], console_name, strlen(console_name))) {
953 strncpy(console, argv[i] + strlen(console_name),
954 sizeof(console));
955 consinit();
956 }
957 #endif
958 if (j == bootargs_len) {
959 *(bootargs + j) = '\0';
960 continue;
961 }
962 if (j != 0)
963 *(bootargs + j++) = ' ';
964 strncpy(bootargs + j, argv[i], bootargs_len - j);
965 bootargs[bootargs_len] = '\0';
966 j += strlen(argv[i]);
967 }
968 boot_args = bootargs;
969
970 parse_mi_bootargs(boot_args);
971
972 if (!gxio_configured)
973 gxio_config_expansion(NULL);
974 }
975
976 static void
977 process_kernel_args_liner(char *args)
978 {
979 int i = 0;
980 char *p = NULL;
981
982 boothowto = 0;
983
984 strncpy(bootargs, args, sizeof(bootargs));
985 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
986 defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
987 {
988 char *q;
989
990 if ((p = strstr(bootargs, expansion_name)))
991 q = p + strlen(expansion_name);
992 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
993 else if ((p = strstr(bootargs, busheader_name)))
994 q = p + strlen(busheader_name);
995 #endif
996 if (p) {
997 char expansion[256], c;
998
999 i = 0;
1000 do {
1001 c = *(q + i);
1002 if (c == ' ')
1003 c = '\0';
1004 expansion[i++] = c;
1005 } while (c != '\0' && i < sizeof(expansion));
1006 gxio_config_expansion(expansion);
1007 strcpy(p, q + i);
1008 }
1009 }
1010 #endif
1011 if (p == NULL)
1012 gxio_config_expansion(NULL);
1013 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
1014 p = strstr(bootargs, console_name);
1015 if (p != NULL) {
1016 char c;
1017
1018 i = 0;
1019 do {
1020 c = *(p + strlen(console_name) + i);
1021 if (c == ' ')
1022 c = '\0';
1023 console[i++] = c;
1024 } while (c != '\0' && i < sizeof(console));
1025 consinit();
1026 strcpy(p, p + strlen(console_name) + i);
1027 }
1028 #endif
1029 boot_args = bootargs;
1030
1031 parse_mi_bootargs(boot_args);
1032 }
1033
1034 #ifdef KGDB
1035 #ifndef KGDB_DEVNAME
1036 #define KGDB_DEVNAME "ffuart"
1037 #endif
1038 const char kgdb_devname[] = KGDB_DEVNAME;
1039
1040 #ifndef KGDB_DEVRATE
1041 #define KGDB_DEVRATE CONSPEED
1042 #endif
1043 int kgdb_devrate = KGDB_DEVRATE;
1044
1045 #if (NCOM > 0)
1046 #ifndef KGDB_DEVMODE
1047 #define KGDB_DEVMODE CONMODE
1048 #endif
1049 int comkgdbmode = KGDB_DEVMODE;
1050 #endif /* NCOM */
1051
1052 #endif /* KGDB */
1053
1054
1055 void
1056 consinit(void)
1057 {
1058 static int consinit_called = 0;
1059
1060 if (consinit_called != 0)
1061 return;
1062
1063 consinit_called = 1;
1064
1065 #if NCOM > 0
1066
1067 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
1068 /* Maybe passed Linux's bootargs 'console=ttyS?,<speed>...' */
1069 if (strncmp(console, "ttyS", 4) == 0 && console[5] == ',') {
1070 int i;
1071
1072 comcnspeed = 0;
1073 for (i = 6; i < strlen(console) && isdigit(console[i]); i++)
1074 comcnspeed = comcnspeed * 10 + (console[i] - '0');
1075 }
1076 #endif
1077
1078 #if defined(GUMSTIX)
1079
1080 #ifdef FFUARTCONSOLE
1081 #ifdef KGDB
1082 if (strcmp(kgdb_devname, "ffuart") == 0){
1083 /* port is reserved for kgdb */
1084 } else
1085 #endif
1086 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
1087 if (console[0] == '\0' || strcasecmp(console, "ffuart") == 0 ||
1088 strncmp(console, "ttyS0,", 6) == 0)
1089 #endif
1090 {
1091 int rv;
1092
1093 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
1094 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
1095 if (rv == 0) {
1096 pxa2x0_clkman_config(CKEN_FFUART, 1);
1097 return;
1098 }
1099 }
1100 #endif /* FFUARTCONSOLE */
1101
1102 #ifdef STUARTCONSOLE
1103 #ifdef KGDB
1104 if (strcmp(kgdb_devname, "stuart") == 0) {
1105 /* port is reserved for kgdb */
1106 } else
1107 #endif
1108 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
1109 if (console[0] == '\0' || strcasecmp(console, "stuart") == 0)
1110 #endif
1111 {
1112 int rv;
1113
1114 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE,
1115 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
1116 if (rv == 0) {
1117 pxa2x0_clkman_config(CKEN_STUART, 1);
1118 return;
1119 }
1120 }
1121 #endif /* STUARTCONSOLE */
1122
1123 #ifdef BTUARTCONSOLE
1124 #ifdef KGDB
1125 if (strcmp(kgdb_devname, "btuart") == 0) {
1126 /* port is reserved for kgdb */
1127 } else
1128 #endif
1129 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
1130 if (console[0] == '\0' || strcasecmp(console, "btuart") == 0)
1131 #endif
1132 {
1133 int rv;
1134
1135 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
1136 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
1137 if (rv == 0) {
1138 pxa2x0_clkman_config(CKEN_BTUART, 1);
1139 return;
1140 }
1141 }
1142 #endif /* BTUARTCONSOLE */
1143
1144 #ifdef HWUARTCONSOLE
1145 #ifdef KGDB
1146 if (strcmp(kgdb_devname, "hwuart") == 0) {
1147 /* port is reserved for kgdb */
1148 } else
1149 #endif
1150 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
1151 if (console[0] == '\0' || strcasecmp(console, "hwuart") == 0)
1152 #endif
1153 {
1154 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE,
1155 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
1156 if (rv == 0) {
1157 pxa2x0_clkman_config(CKEN_HWUART, 1);
1158 return;
1159 }
1160 }
1161 #endif /* HWUARTCONSOLE */
1162
1163 #elif defined(OVERO) || defined(DUOVERO) || defined(PEPPER)
1164
1165 if (comcnattach(&omap_a4x_bs_tag, CONSADDR, comcnspeed,
1166 OMAP_COM_FREQ, COM_TYPE_NORMAL, comcnmode) == 0)
1167 return;
1168
1169 #endif /* GUMSTIX or OVERO */
1170
1171 #endif /* NCOM */
1172
1173 #if NLCD > 0
1174 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
1175 if (console[0] == '\0' || strcasecmp(console, "lcd") == 0)
1176 #endif
1177 {
1178 gxlcd_cnattach();
1179 }
1180 #endif
1181 }
1182
1183 #ifdef KGDB
1184 static void
1185 kgdb_port_init(void)
1186 {
1187 #if (NCOM > 0) && defined(COM_PXA2X0)
1188 paddr_t paddr = 0;
1189 int cken = 0;
1190
1191 if (0 == strcmp(kgdb_devname, "ffuart")) {
1192 paddr = PXA2X0_FFUART_BASE;
1193 cken = CKEN_FFUART;
1194 } else if (0 == strcmp(kgdb_devname, "stuart")) {
1195 paddr = PXA2X0_STUART_BASE;
1196 cken = CKEN_STUART;
1197 } else if (0 == strcmp(kgdb_devname, "btuart")) {
1198 paddr = PXA2X0_BTUART_BASE;
1199 cken = CKEN_BTUART;
1200 } else if (0 == strcmp(kgdb_devname, "hwuart")) {
1201 paddr = PXA2X0_HWUART_BASE;
1202 cken = CKEN_HWUART;
1203 }
1204
1205 if (paddr &&
1206 0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
1207 kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
1208
1209 pxa2x0_clkman_config(cken, 1);
1210 }
1211
1212 #endif
1213 }
1214 #endif
1215
1216 static void
1217 gumstix_device_register(device_t dev, void *aux)
1218 {
1219 prop_dictionary_t dict = device_properties(dev);
1220
1221 if (device_is_a(dev, "arma9tmr") ||
1222 device_is_a(dev, "a9wdt")) {
1223 /*
1224 * We need to tell the A9 Global/Watchdog Timer
1225 * what frequency it runs at.
1226 */
1227
1228 /*
1229 * This clock always runs at (arm_clk div 2) and only goes
1230 * to timers that are part of the A9 MP core subsystem.
1231 */
1232 prop_dictionary_set_uint32(dict, "frequency",
1233 curcpu()->ci_data.cpu_cc_freq / 2);
1234 }
1235 if (device_is_a(dev, "armperiph")) {
1236 if (device_is_a(device_parent(dev), "mainbus")) {
1237 #if defined(OMAP2)
1238 /*
1239 * XXX KLUDGE ALERT XXX
1240 * The iot mainbus supplies is completely wrong since
1241 * it scales addresses by 2. The simpliest remedy is
1242 * to replace with our bus space used for the armcore
1243 * registers (which armperiph uses).
1244 */
1245 struct mainbus_attach_args * const mb = aux;
1246 mb->mb_iot = &omap_bs_tag;
1247 #endif
1248 }
1249 }
1250 if (device_is_a(dev, "ehci")) {
1251 #if defined(OVERO)
1252 prop_dictionary_set_uint16(dict, "nports", 2);
1253 prop_dictionary_set_bool(dict, "phy-reset", true);
1254 prop_dictionary_set_cstring(dict, "port0-mode", "none");
1255 prop_dictionary_set_int16(dict, "port0-gpio", -1);
1256 prop_dictionary_set_cstring(dict, "port1-mode", "phy");
1257 prop_dictionary_set_int16(dict, "port1-gpio", 183);
1258 prop_dictionary_set_bool(dict, "port1-gpioval", true);
1259 #elif defined(DUOVERO)
1260 prop_dictionary_set_uint16(dict, "nports", 1);
1261 prop_dictionary_set_bool(dict, "phy-reset", true);
1262 prop_dictionary_set_cstring(dict, "port0-mode", "phy");
1263 prop_dictionary_set_int16(dict, "port0-gpio", 62);
1264 prop_dictionary_set_bool(dict, "port0-gpioval", false);
1265 prop_dictionary_set_bool(dict, "port0-extclk", true);
1266 #endif
1267 prop_dictionary_set_uint16(dict, "dpll5-m", 443);
1268 prop_dictionary_set_uint16(dict, "dpll5-n", 11);
1269 prop_dictionary_set_uint16(dict, "dpll5-m2", 4);
1270 }
1271 if (device_is_a(dev, "ohci")) {
1272 if (prop_dictionary_set_bool(dict,
1273 "Ganged-power-mask-on-port1", 1) == false) {
1274 printf("WARNING: unable to set power-mask for port1"
1275 " property for %s\n", device_xname(dev));
1276 }
1277 if (prop_dictionary_set_bool(dict,
1278 "Ganged-power-mask-on-port2", 1) == false) {
1279 printf("WARNING: unable to set power-mask for port2"
1280 " property for %s\n", device_xname(dev));
1281 }
1282 if (prop_dictionary_set_bool(dict,
1283 "Ganged-power-mask-on-port3", 1) == false) {
1284 printf("WARNING: unable to set power-mask for port3"
1285 " property for %s\n", device_xname(dev));
1286 }
1287 }
1288 if (device_is_a(dev, "omapmputmr")) {
1289 struct obio_attach_args *obio = aux;
1290
1291 switch (obio->obio_addr) {
1292 case 0x49032000: /* GPTIMER2 */
1293 case 0x49034000: /* GPTIMER3 */
1294 case 0x49036000: /* GPTIMER4 */
1295 case 0x49038000: /* GPTIMER5 */
1296 case 0x4903a000: /* GPTIMER6 */
1297 case 0x4903c000: /* GPTIMER7 */
1298 case 0x4903e000: /* GPTIMER8 */
1299 case 0x49040000: /* GPTIMER9 */
1300 #if defined(OVERO)
1301 {
1302 /* Ensure enable PRCM.CM_[FI]CLKEN_PER[3:10]. */
1303 const int en =
1304 1 << (((obio->obio_addr >> 13) & 0x3f) - 0x16);
1305
1306 ioreg_write(OVERO_L4_CORE_VBASE + 0x5000,
1307 ioreg_read(OVERO_L4_CORE_VBASE + 0x5000) | en);
1308 ioreg_write(OVERO_L4_CORE_VBASE + 0x5010,
1309 ioreg_read(OVERO_L4_CORE_VBASE + 0x5010) | en);
1310 }
1311 #endif
1312 break;
1313 }
1314 }
1315 if (device_is_a(dev, "sdhc")) {
1316 bool dualvolt = false;
1317
1318 #if defined(OVERO) || defined(DUOVERO)
1319 if (device_is_a(device_parent(dev), "obio")) {
1320 struct obio_attach_args *obio = aux;
1321
1322 #if defined(OVERO)
1323 if (obio->obio_addr == SDMMC2_BASE_3530)
1324 dualvolt = true;
1325 #elif defined(DUOVERO)
1326 if (obio->obio_addr == SDMMC5_BASE_4430)
1327 dualvolt = true;
1328 #endif
1329 }
1330 #endif
1331 #if defined(PEPPER)
1332 if (device_is_a(device_parent(dev), "mainbus")) {
1333 struct mainbus_attach_args * const mb = aux;
1334
1335 if (mb->mb_iobase == SDMMC3_BASE_TIAM335X)
1336 dualvolt = true;
1337 }
1338 #endif
1339 prop_dictionary_set_bool(dict, "dual-volt", dualvolt);
1340 }
1341 if (device_is_a(dev, "tifb")) {
1342 prop_data_t panel_info;
1343
1344 panel_info = prop_data_create_data_nocopy(tifb_panel_info,
1345 sizeof(struct tifb_panel_info));
1346 KASSERT(panel_info != NULL);
1347 prop_dictionary_set(dict, "panel-info", panel_info);
1348 prop_object_release(panel_info);
1349
1350 #if defined(OMAP2)
1351 /* enable LCD */
1352 omap2_gpio_ctl(59, GPIO_PIN_OUTPUT);
1353 omap2_gpio_write(59, 0); /* reset */
1354 delay(100);
1355 omap2_gpio_write(59, 1);
1356 #endif
1357 }
1358 if (device_is_a(dev, "tps65217pmic")) {
1359 #if defined(TI_AM335X)
1360 extern const char *mpu_supply;
1361
1362 mpu_supply = "DCDC3";
1363 #endif
1364
1365 if (use_tps65217_wled) {
1366 prop_dictionary_set_int32(dict, "isel", 1);
1367 prop_dictionary_set_int32(dict, "fdim", 200);
1368 prop_dictionary_set_int32(dict, "brightness", 80);
1369 }
1370 }
1371 }
1372