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