Home | History | Annotate | Line # | Download | only in kobo
kobo_machdep.c revision 1.1
      1  1.1  hkenken /*	$NetBSD: kobo_machdep.c,v 1.1 2014/07/25 11:22:50 hkenken Exp $	*/
      2  1.1  hkenken 
      3  1.1  hkenken /*
      4  1.1  hkenken  * Copyright (c) 2002, 2003, 2005, 2010  Genetec Corporation.
      5  1.1  hkenken  * All rights reserved.
      6  1.1  hkenken  * Written by Hiroyuki Bessho for Genetec Corporation.
      7  1.1  hkenken  *
      8  1.1  hkenken  * Redistribution and use in source and binary forms, with or without
      9  1.1  hkenken  * modification, are permitted provided that the following conditions
     10  1.1  hkenken  * are met:
     11  1.1  hkenken  * 1. Redistributions of source code must retain the above copyright
     12  1.1  hkenken  *    notice, this list of conditions and the following disclaimer.
     13  1.1  hkenken  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  hkenken  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  hkenken  *    documentation and/or other materials provided with the distribution.
     16  1.1  hkenken  *
     17  1.1  hkenken  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     18  1.1  hkenken  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  1.1  hkenken  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  1.1  hkenken  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     21  1.1  hkenken  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  1.1  hkenken  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  1.1  hkenken  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  1.1  hkenken  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  1.1  hkenken  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  1.1  hkenken  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  1.1  hkenken  * POSSIBILITY OF SUCH DAMAGE.
     28  1.1  hkenken  *
     29  1.1  hkenken  * Machine dependent functions for kernel setup for RAKUTEN Kobo.
     30  1.1  hkenken  * Based on iq80310_machhdep.c
     31  1.1  hkenken  */
     32  1.1  hkenken /*
     33  1.1  hkenken  * Copyright (c) 2001 Wasabi Systems, Inc.
     34  1.1  hkenken  * All rights reserved.
     35  1.1  hkenken  *
     36  1.1  hkenken  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     37  1.1  hkenken  *
     38  1.1  hkenken  * Redistribution and use in source and binary forms, with or without
     39  1.1  hkenken  * modification, are permitted provided that the following conditions
     40  1.1  hkenken  * are met:
     41  1.1  hkenken  * 1. Redistributions of source code must retain the above copyright
     42  1.1  hkenken  *    notice, this list of conditions and the following disclaimer.
     43  1.1  hkenken  * 2. Redistributions in binary form must reproduce the above copyright
     44  1.1  hkenken  *    notice, this list of conditions and the following disclaimer in the
     45  1.1  hkenken  *    documentation and/or other materials provided with the distribution.
     46  1.1  hkenken  * 3. All advertising materials mentioning features or use of this software
     47  1.1  hkenken  *    must display the following acknowledgement:
     48  1.1  hkenken  *	This product includes software developed for the NetBSD Project by
     49  1.1  hkenken  *	Wasabi Systems, Inc.
     50  1.1  hkenken  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     51  1.1  hkenken  *    or promote products derived from this software without specific prior
     52  1.1  hkenken  *    written permission.
     53  1.1  hkenken  *
     54  1.1  hkenken  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     55  1.1  hkenken  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     56  1.1  hkenken  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     57  1.1  hkenken  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     58  1.1  hkenken  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     59  1.1  hkenken  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     60  1.1  hkenken  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     61  1.1  hkenken  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     62  1.1  hkenken  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     63  1.1  hkenken  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     64  1.1  hkenken  * POSSIBILITY OF SUCH DAMAGE.
     65  1.1  hkenken  */
     66  1.1  hkenken 
     67  1.1  hkenken /*
     68  1.1  hkenken  * Copyright (c) 1997,1998 Mark Brinicombe.
     69  1.1  hkenken  * Copyright (c) 1997,1998 Causality Limited.
     70  1.1  hkenken  * All rights reserved.
     71  1.1  hkenken  *
     72  1.1  hkenken  * Redistribution and use in source and binary forms, with or without
     73  1.1  hkenken  * modification, are permitted provided that the following conditions
     74  1.1  hkenken  * are met:
     75  1.1  hkenken  * 1. Redistributions of source code must retain the above copyright
     76  1.1  hkenken  *    notice, this list of conditions and the following disclaimer.
     77  1.1  hkenken  * 2. Redistributions in binary form must reproduce the above copyright
     78  1.1  hkenken  *    notice, this list of conditions and the following disclaimer in the
     79  1.1  hkenken  *    documentation and/or other materials provided with the distribution.
     80  1.1  hkenken  * 3. All advertising materials mentioning features or use of this software
     81  1.1  hkenken  *    must display the following acknowledgement:
     82  1.1  hkenken  *	This product includes software developed by Mark Brinicombe
     83  1.1  hkenken  *	for the NetBSD Project.
     84  1.1  hkenken  * 4. The name of the company nor the name of the author may be used to
     85  1.1  hkenken  *    endorse or promote products derived from this software without specific
     86  1.1  hkenken  *    prior written permission.
     87  1.1  hkenken  *
     88  1.1  hkenken  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     89  1.1  hkenken  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     90  1.1  hkenken  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     91  1.1  hkenken  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     92  1.1  hkenken  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     93  1.1  hkenken  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     94  1.1  hkenken  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     95  1.1  hkenken  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     96  1.1  hkenken  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     97  1.1  hkenken  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     98  1.1  hkenken  * SUCH DAMAGE.
     99  1.1  hkenken  *
    100  1.1  hkenken  * Machine dependent functions for kernel setup for Intel IQ80310 evaluation
    101  1.1  hkenken  * boards using RedBoot firmware.
    102  1.1  hkenken  */
    103  1.1  hkenken 
    104  1.1  hkenken #include <sys/cdefs.h>
    105  1.1  hkenken __KERNEL_RCSID(0, "$NetBSD: kobo_machdep.c,v 1.1 2014/07/25 11:22:50 hkenken Exp $");
    106  1.1  hkenken 
    107  1.1  hkenken #include "opt_evbarm_boardtype.h"
    108  1.1  hkenken #include "opt_arm_debug.h"
    109  1.1  hkenken #include "opt_cputypes.h"
    110  1.1  hkenken #include "opt_ddb.h"
    111  1.1  hkenken #include "opt_kgdb.h"
    112  1.1  hkenken #include "opt_md.h"
    113  1.1  hkenken #include "opt_com.h"
    114  1.1  hkenken #include "imxuart.h"
    115  1.1  hkenken #include "opt_imxuart.h"
    116  1.1  hkenken #include "opt_imx.h"
    117  1.1  hkenken #include "opt_machdep.h"
    118  1.1  hkenken 
    119  1.1  hkenken #include <sys/param.h>
    120  1.1  hkenken #include <sys/device.h>
    121  1.1  hkenken #include <sys/termios.h>
    122  1.1  hkenken #include <sys/bus.h>
    123  1.1  hkenken 
    124  1.1  hkenken #include <machine/db_machdep.h>
    125  1.1  hkenken #ifdef KGDB
    126  1.1  hkenken #include <sys/kgdb.h>
    127  1.1  hkenken #endif
    128  1.1  hkenken 
    129  1.1  hkenken #include <machine/bootconfig.h>
    130  1.1  hkenken 
    131  1.1  hkenken #include <arm/arm32/machdep.h>
    132  1.1  hkenken 
    133  1.1  hkenken #include <arm/imx/imx51reg.h>
    134  1.1  hkenken #include <arm/imx/imx51var.h>
    135  1.1  hkenken #include <arm/imx/imxuartreg.h>
    136  1.1  hkenken #include <arm/imx/imxuartvar.h>
    137  1.1  hkenken #include <arm/imx/imx50_iomuxreg.h>
    138  1.1  hkenken #include <arm/imx/imxgpiovar.h>
    139  1.1  hkenken 
    140  1.1  hkenken #include <evbarm/kobo/kobo.h>
    141  1.1  hkenken #include <evbarm/kobo/kobo_reg.h>
    142  1.1  hkenken 
    143  1.1  hkenken /* Kernel text starts 1MB in from the bottom of the kernel address space. */
    144  1.1  hkenken #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00100000)
    145  1.1  hkenken 
    146  1.1  hkenken BootConfig bootconfig;		/* Boot config storage */
    147  1.1  hkenken static char bootargs[MAX_BOOT_STRING];
    148  1.1  hkenken char *boot_args = NULL;
    149  1.1  hkenken 
    150  1.1  hkenken extern char KERNEL_BASE_phys[];
    151  1.1  hkenken 
    152  1.1  hkenken /*
    153  1.1  hkenken  * Macros to translate between physical and virtual for a subset of the
    154  1.1  hkenken  * kernel address space.  *Not* for general use.
    155  1.1  hkenken  */
    156  1.1  hkenken #define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys)
    157  1.1  hkenken 
    158  1.1  hkenken void consinit(void);
    159  1.1  hkenken 
    160  1.1  hkenken #ifdef KGDB
    161  1.1  hkenken void	kgdb_port_init(void);
    162  1.1  hkenken #endif
    163  1.1  hkenken 
    164  1.1  hkenken static void init_clocks(void);
    165  1.1  hkenken static void setup_ioports(void);
    166  1.1  hkenken 
    167  1.1  hkenken #ifndef CONSPEED
    168  1.1  hkenken #define CONSPEED B115200	/* What RedBoot uses */
    169  1.1  hkenken #endif
    170  1.1  hkenken #ifndef CONMODE
    171  1.1  hkenken #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    172  1.1  hkenken #endif
    173  1.1  hkenken 
    174  1.1  hkenken int comcnspeed = CONSPEED;
    175  1.1  hkenken int comcnmode = CONMODE;
    176  1.1  hkenken 
    177  1.1  hkenken /*
    178  1.1  hkenken  * Static device mappings. These peripheral registers are mapped at
    179  1.1  hkenken  * fixed virtual addresses very early in initarm() so that we can use
    180  1.1  hkenken  * them while booting the kernel, and stay at the same address
    181  1.1  hkenken  * throughout whole kernel's life time.
    182  1.1  hkenken  *
    183  1.1  hkenken  * We use this table twice; once with bootstrap page table, and once
    184  1.1  hkenken  * with kernel's page table which we build up in initarm().
    185  1.1  hkenken  *
    186  1.1  hkenken  * Since we map these registers into the bootstrap page table using
    187  1.1  hkenken  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    188  1.1  hkenken  * registers segment-aligned and segment-rounded in order to avoid
    189  1.1  hkenken  * using the 2nd page tables.
    190  1.1  hkenken  */
    191  1.1  hkenken 
    192  1.1  hkenken #define _A(a)   ((a) & ~L1_S_OFFSET)
    193  1.1  hkenken #define _S(s)   (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    194  1.1  hkenken 
    195  1.1  hkenken const struct pmap_devmap kobo_devmap[] = {
    196  1.1  hkenken 	{
    197  1.1  hkenken 		/* for UART2, IOMUXC */
    198  1.1  hkenken 		.pd_va = _A(KOBO_IO_VBASE0),
    199  1.1  hkenken 		.pd_pa = _A(KOBO_IO_PBASE0),
    200  1.1  hkenken 		.pd_size = _S(L1_S_SIZE * 4),
    201  1.1  hkenken 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    202  1.1  hkenken 		.pd_cache = PTE_NOCACHE
    203  1.1  hkenken 	},
    204  1.1  hkenken 	{0}
    205  1.1  hkenken };
    206  1.1  hkenken 
    207  1.1  hkenken #undef	_A
    208  1.1  hkenken #undef	_S
    209  1.1  hkenken 
    210  1.1  hkenken #ifndef MEMSTART
    211  1.1  hkenken #define MEMSTART	0x70000000
    212  1.1  hkenken #endif
    213  1.1  hkenken #ifndef MEMSIZE
    214  1.1  hkenken #define MEMSIZE		256
    215  1.1  hkenken #endif
    216  1.1  hkenken 
    217  1.1  hkenken static void
    218  1.1  hkenken init_clocks(void)
    219  1.1  hkenken {
    220  1.1  hkenken 	cortex_pmc_ccnt_init();
    221  1.1  hkenken }
    222  1.1  hkenken 
    223  1.1  hkenken struct iomux_setup {
    224  1.1  hkenken 	/* iomux registers are 32-bit wide, but upper 16 bits are not
    225  1.1  hkenken 	 * used. */
    226  1.1  hkenken 	uint16_t	reg;
    227  1.1  hkenken 	uint16_t	val;
    228  1.1  hkenken };
    229  1.1  hkenken 
    230  1.1  hkenken #define	IOMUX_M(padname, mux)		\
    231  1.1  hkenken 	IOMUX_DATA(__CONCAT(IOMUXC_SW_MUX_CTL_PAD_,padname), mux)
    232  1.1  hkenken 
    233  1.1  hkenken #define	IOMUX_P(padname, pad)		\
    234  1.1  hkenken 	IOMUX_DATA(__CONCAT(IOMUXC_SW_PAD_CTL_PAD_,padname), pad)
    235  1.1  hkenken 
    236  1.1  hkenken #define	IOMUX_MP(padname, mux, pad)	\
    237  1.1  hkenken 	IOMUX_M(padname, mux), \
    238  1.1  hkenken 	IOMUX_P(padname, pad)
    239  1.1  hkenken 
    240  1.1  hkenken #define	IOMUX_DATA(offset, value)	\
    241  1.1  hkenken 	{				\
    242  1.1  hkenken 		.reg = (offset),	\
    243  1.1  hkenken 		.val = (value),		\
    244  1.1  hkenken 	}
    245  1.1  hkenken 
    246  1.1  hkenken const struct iomux_setup iomux_setup_data[] = {
    247  1.1  hkenken #define	HYS	PAD_CTL_HYS
    248  1.1  hkenken #define	ODE	PAD_CTL_ODE
    249  1.1  hkenken #define	DSEHIGH	PAD_CTL_DSE_HIGH
    250  1.1  hkenken #define	DSEMID	PAD_CTL_DSE_MID
    251  1.1  hkenken #define	DSELOW	PAD_CTL_DSE_LOW
    252  1.1  hkenken #define	DSEMAX	PAD_CTL_DSE_MAX
    253  1.1  hkenken #define	SRE	PAD_CTL_SRE
    254  1.1  hkenken #define	KEEPER	PAD_CTL_KEEPER
    255  1.1  hkenken #define	PULL	PAD_CTL_PULL
    256  1.1  hkenken #define	PU_22K	PAD_CTL_PUS_22K_PU
    257  1.1  hkenken #define	PU_47K	PAD_CTL_PUS_47K_PU
    258  1.1  hkenken #define	PU_100K	PAD_CTL_PUS_100K_PU
    259  1.1  hkenken #define	PD_100K	PAD_CTL_PUS_100K_PD
    260  1.1  hkenken #define	HVE	PAD_CTL_HVE	/* Low output voltage */
    261  1.1  hkenken 
    262  1.1  hkenken #define	ALT0	IOMUX_CONFIG_ALT0
    263  1.1  hkenken #define	ALT1	IOMUX_CONFIG_ALT1
    264  1.1  hkenken #define	ALT2	IOMUX_CONFIG_ALT2
    265  1.1  hkenken #define	ALT3	IOMUX_CONFIG_ALT3
    266  1.1  hkenken #define	ALT4	IOMUX_CONFIG_ALT4
    267  1.1  hkenken #define	ALT5	IOMUX_CONFIG_ALT5
    268  1.1  hkenken #define	ALT6	IOMUX_CONFIG_ALT6
    269  1.1  hkenken #define	ALT7	IOMUX_CONFIG_ALT7
    270  1.1  hkenken #define	SION	IOMUX_CONFIG_SION
    271  1.1  hkenken 
    272  1.1  hkenken 	/* I2C1 */
    273  1.1  hkenken 	IOMUX_MP(I2C1_SCL, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    274  1.1  hkenken 	IOMUX_MP(I2C1_SDA, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    275  1.1  hkenken 
    276  1.1  hkenken 	/* I2C2 */
    277  1.1  hkenken 	IOMUX_MP(I2C2_SCL, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    278  1.1  hkenken 	IOMUX_MP(I2C2_SDA, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    279  1.1  hkenken 
    280  1.1  hkenken 	/* I2C3 */
    281  1.1  hkenken 	IOMUX_MP(I2C3_SCL, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    282  1.1  hkenken 	IOMUX_MP(I2C3_SDA, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    283  1.1  hkenken 
    284  1.1  hkenken 	/* UART2 */
    285  1.1  hkenken 	IOMUX_MP(UART2_RXD, ALT0, HYS | PULL | DSEHIGH | SRE),
    286  1.1  hkenken 	IOMUX_MP(UART2_TXD, ALT0, HYS | PULL | DSEHIGH | SRE),
    287  1.1  hkenken 
    288  1.1  hkenken 	/* SD1 */
    289  1.1  hkenken 	IOMUX_MP(SD1_CMD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    290  1.1  hkenken 	IOMUX_MP(SD1_CLK, ALT0, HVE | PU_22K | DSEMAX | SRE),
    291  1.1  hkenken 	IOMUX_MP(SD1_D0, ALT0, HVE | PU_22K | DSEMAX | SRE),
    292  1.1  hkenken 	IOMUX_MP(SD1_D1, ALT0, HVE | PU_22K | DSEMAX | SRE),
    293  1.1  hkenken 	IOMUX_MP(SD1_D2, ALT0, HVE | PU_22K | DSEMAX | SRE),
    294  1.1  hkenken 	IOMUX_MP(SD1_D3, ALT0, HVE | PU_22K | DSEMAX | SRE),
    295  1.1  hkenken //	IOMUX_MP(SD1_CD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    296  1.1  hkenken 
    297  1.1  hkenken 	/* SD2 */
    298  1.1  hkenken 	IOMUX_MP(SD2_CMD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    299  1.1  hkenken 	IOMUX_MP(SD2_CLK, ALT0, HVE | PU_22K | DSEMAX | SRE),
    300  1.1  hkenken 	IOMUX_MP(SD2_D0, ALT0, HVE | PU_22K | DSEMAX | SRE),
    301  1.1  hkenken 	IOMUX_MP(SD2_D1, ALT0, HVE | PU_22K | DSEMAX | SRE),
    302  1.1  hkenken 	IOMUX_MP(SD2_D2, ALT0, HVE | PU_22K | DSEMAX | SRE),
    303  1.1  hkenken 	IOMUX_MP(SD2_D3, ALT0, HVE | PU_22K | DSEMAX | SRE),
    304  1.1  hkenken 	IOMUX_MP(SD2_CD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    305  1.1  hkenken 
    306  1.1  hkenken 	IOMUX_DATA(IOMUXC_ESDHC2_IPP_CARD_DET_SELECT_INPUT, INPUT_DAISY_1),
    307  1.1  hkenken 
    308  1.1  hkenken 	/* SD3 */
    309  1.1  hkenken 	IOMUX_MP(SD3_CMD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    310  1.1  hkenken 	IOMUX_MP(SD3_CLK, ALT0, HVE | PU_22K | DSEMAX | SRE),
    311  1.1  hkenken 	IOMUX_MP(SD3_D0, ALT0, HVE | PU_22K | DSEMAX | SRE),
    312  1.1  hkenken 	IOMUX_MP(SD3_D1, ALT0, HVE | PU_22K | DSEMAX | SRE),
    313  1.1  hkenken 	IOMUX_MP(SD3_D2, ALT0, HVE | PU_22K | DSEMAX | SRE),
    314  1.1  hkenken 	IOMUX_MP(SD3_D3, ALT0, HVE | PU_22K | DSEMAX | SRE),
    315  1.1  hkenken //	IOMUX_MP(SD3_CD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    316  1.1  hkenken 
    317  1.1  hkenken 	/* OTG */
    318  1.1  hkenken 	IOMUX_M(PWM2, ALT2),
    319  1.1  hkenken //	IOMUX_MP(PWM1, ALT2, HYS | KEEPER | DSEHIGH),
    320  1.1  hkenken 
    321  1.1  hkenken 	/* EPDC */
    322  1.1  hkenken 	IOMUX_M(EPDC_D0, ALT0),
    323  1.1  hkenken 	IOMUX_M(EPDC_D1, ALT0),
    324  1.1  hkenken 	IOMUX_M(EPDC_D2, ALT0),
    325  1.1  hkenken 	IOMUX_M(EPDC_D3, ALT0),
    326  1.1  hkenken 	IOMUX_M(EPDC_D4, ALT0),
    327  1.1  hkenken 	IOMUX_M(EPDC_D5, ALT0),
    328  1.1  hkenken 	IOMUX_M(EPDC_D6, ALT0),
    329  1.1  hkenken 	IOMUX_M(EPDC_D7, ALT0),
    330  1.1  hkenken 	IOMUX_M(EPDC_GDCLK, ALT0),
    331  1.1  hkenken 	IOMUX_M(EPDC_GDSP, ALT0),
    332  1.1  hkenken 	IOMUX_M(EPDC_GDOE, ALT0),
    333  1.1  hkenken 	IOMUX_M(EPDC_GDRL, ALT0),
    334  1.1  hkenken 	IOMUX_M(EPDC_SDCLK, ALT0),
    335  1.1  hkenken 	IOMUX_M(EPDC_SDOE, ALT0),
    336  1.1  hkenken 	IOMUX_M(EPDC_SDLE, ALT0),
    337  1.1  hkenken 	IOMUX_M(EPDC_BDR0, ALT0),
    338  1.1  hkenken 	IOMUX_M(EPDC_BDR1, ALT0),
    339  1.1  hkenken 	IOMUX_M(EPDC_SDCE0, ALT0),
    340  1.1  hkenken 
    341  1.1  hkenken 	IOMUX_M(EPDC_PWRSTAT, ALT1),	/* GPIO3[28] */
    342  1.1  hkenken 	IOMUX_M(EPDC_PWRCTRL0, ALT1),	/* GPIO3[29] */
    343  1.1  hkenken 	IOMUX_M(EPDC_VCOM0, ALT1),	/* GPIO4[21] */
    344  1.1  hkenken 	IOMUX_M(UART4_TXD, ALT1),	/* GPIO6[16] */
    345  1.1  hkenken 	IOMUX_M(UART4_RXD, ALT1),	/* GPIO6[17] */
    346  1.1  hkenken 
    347  1.1  hkenken //	IOMUX_M(PWM2, ALT1),		/* GPIO6[25] */
    348  1.1  hkenken 
    349  1.1  hkenken #undef	ODE
    350  1.1  hkenken #undef	HYS
    351  1.1  hkenken #undef	SRE
    352  1.1  hkenken #undef	PULL
    353  1.1  hkenken #undef	KEEPER
    354  1.1  hkenken #undef	PU_22K
    355  1.1  hkenken #undef	PU_47K
    356  1.1  hkenken #undef	PU_100K
    357  1.1  hkenken #undef	PD_100K
    358  1.1  hkenken #undef	HVE
    359  1.1  hkenken #undef	DSEMAX
    360  1.1  hkenken #undef	DSEHIGH
    361  1.1  hkenken #undef	DSEMID
    362  1.1  hkenken #undef	DSELOW
    363  1.1  hkenken 
    364  1.1  hkenken #undef	ALT0
    365  1.1  hkenken #undef	ALT1
    366  1.1  hkenken #undef	ALT2
    367  1.1  hkenken #undef	ALT3
    368  1.1  hkenken #undef	ALT4
    369  1.1  hkenken #undef	ALT5
    370  1.1  hkenken #undef	ALT6
    371  1.1  hkenken #undef	ALT7
    372  1.1  hkenken #undef	SION
    373  1.1  hkenken };
    374  1.1  hkenken 
    375  1.1  hkenken static void
    376  1.1  hkenken setup_ioports(void)
    377  1.1  hkenken {
    378  1.1  hkenken 	int i;
    379  1.1  hkenken 	const struct iomux_setup *p;
    380  1.1  hkenken 
    381  1.1  hkenken 	for (i=0; i < __arraycount(iomux_setup_data); ++i) {
    382  1.1  hkenken 		p = iomux_setup_data + i;
    383  1.1  hkenken 
    384  1.1  hkenken 		ioreg_write(KOBO_IOMUXC_VBASE + p->reg,
    385  1.1  hkenken 			    p->val);
    386  1.1  hkenken 	}
    387  1.1  hkenken }
    388  1.1  hkenken 
    389  1.1  hkenken #ifdef	CONSDEVNAME
    390  1.1  hkenken const char consdevname[] = CONSDEVNAME;
    391  1.1  hkenken 
    392  1.1  hkenken #ifndef	CONMODE
    393  1.1  hkenken #define	CONMODE	((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    394  1.1  hkenken #endif
    395  1.1  hkenken #ifndef	CONSPEED
    396  1.1  hkenken #define	CONSPEED	115200
    397  1.1  hkenken #endif
    398  1.1  hkenken 
    399  1.1  hkenken int consmode = CONMODE;
    400  1.1  hkenken int consrate = CONSPEED;
    401  1.1  hkenken 
    402  1.1  hkenken #endif	/* CONSDEVNAME */
    403  1.1  hkenken 
    404  1.1  hkenken #ifndef	IMXUART_FREQ
    405  1.1  hkenken #define	IMXUART_FREQ	24000000
    406  1.1  hkenken #endif
    407  1.1  hkenken 
    408  1.1  hkenken /*
    409  1.1  hkenken  * u_int initarm(...)
    410  1.1  hkenken  *
    411  1.1  hkenken  * Initial entry point on startup. This gets called before main() is
    412  1.1  hkenken  * entered.
    413  1.1  hkenken  * It should be responsible for setting up everything that must be
    414  1.1  hkenken  * in place when main is called.
    415  1.1  hkenken  * This includes
    416  1.1  hkenken  *   Taking a copy of the boot configuration structure.
    417  1.1  hkenken  *   Initialising the physical console so characters can be printed.
    418  1.1  hkenken  *   Setting up page tables for the kernel
    419  1.1  hkenken  */
    420  1.1  hkenken u_int
    421  1.1  hkenken initarm(void *arg)
    422  1.1  hkenken {
    423  1.1  hkenken 	/*
    424  1.1  hkenken 	 * Heads up ... Setup the CPU / MMU / TLB functions
    425  1.1  hkenken 	 */
    426  1.1  hkenken 	if (set_cpufuncs())		// starts PMC counter
    427  1.1  hkenken 		panic("cpu not recognized!");
    428  1.1  hkenken 
    429  1.1  hkenken 	/* map some peripheral registers */
    430  1.1  hkenken 	pmap_devmap_bootstrap((vaddr_t)armreg_ttbr_read() & -L1_TABLE_SIZE,
    431  1.1  hkenken 	    kobo_devmap);
    432  1.1  hkenken 
    433  1.1  hkenken 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    434  1.1  hkenken 
    435  1.1  hkenken 	/* Register devmap for devices we mapped in start */
    436  1.1  hkenken 	pmap_devmap_register(kobo_devmap);
    437  1.1  hkenken 	setup_ioports();
    438  1.1  hkenken 
    439  1.1  hkenken 	consinit();
    440  1.1  hkenken 
    441  1.1  hkenken 	init_clocks();
    442  1.1  hkenken 
    443  1.1  hkenken #ifdef KGDB
    444  1.1  hkenken 	kgdb_port_init();
    445  1.1  hkenken #endif
    446  1.1  hkenken 
    447  1.1  hkenken 	/* Talk to the user */
    448  1.1  hkenken 	printf("\nNetBSD/evbarm (" ___STRING(EVBARM_BOARDTYPE) ") booting ...\n");
    449  1.1  hkenken 
    450  1.1  hkenken #ifdef BOOT_ARGS
    451  1.1  hkenken 	char mi_bootargs[] = BOOT_ARGS;
    452  1.1  hkenken 	parse_mi_bootargs(mi_bootargs);
    453  1.1  hkenken #endif
    454  1.1  hkenken 	bootargs[0] = '\0';
    455  1.1  hkenken 
    456  1.1  hkenken #ifdef VERBOSE_INIT_ARM
    457  1.1  hkenken 	printf("initarm: Configuring system");
    458  1.1  hkenken 	printf(", CLIDR=%010o CTR=%#x",
    459  1.1  hkenken 	    armreg_clidr_read(), armreg_ctr_read());
    460  1.1  hkenken 	printf("\n");
    461  1.1  hkenken #endif
    462  1.1  hkenken 
    463  1.1  hkenken #ifdef VERBOSE_INIT_ARM
    464  1.1  hkenken 	printf("initarm: Configuring system ...\n");
    465  1.1  hkenken #endif
    466  1.1  hkenken 	/*
    467  1.1  hkenken 	 * Set up the variables that define the availability of physical
    468  1.1  hkenken 	 * memory.
    469  1.1  hkenken 	 */
    470  1.1  hkenken 
    471  1.1  hkenken 	/* Fake bootconfig structure for the benefit of pmap.c. */
    472  1.1  hkenken 	bootconfig.dramblocks = 1;
    473  1.1  hkenken 	bootconfig.dram[0].address = MEMSTART;
    474  1.1  hkenken 	bootconfig.dram[0].pages = (MEMSIZE * 1024 * 1024) / PAGE_SIZE;
    475  1.1  hkenken 
    476  1.1  hkenken 	psize_t ram_size = bootconfig.dram[0].pages * PAGE_SIZE;
    477  1.1  hkenken 
    478  1.1  hkenken #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
    479  1.1  hkenken 	const bool mapallmem_p = true;
    480  1.1  hkenken 	if (ram_size > (KERNEL_VM_BASE - KERNEL_BASE)) {
    481  1.1  hkenken 		printf("%s: dropping RAM size from %luMB to %uMB\n",
    482  1.1  hkenken 		    __func__, (unsigned long) (ram_size >> 20),
    483  1.1  hkenken 		    (KERNEL_VM_BASE - KERNEL_BASE) >> 20);
    484  1.1  hkenken 		ram_size = KERNEL_VM_BASE - KERNEL_BASE;
    485  1.1  hkenken 	}
    486  1.1  hkenken 	KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE);
    487  1.1  hkenken #else
    488  1.1  hkenken 	const bool mapallmem_p = false;
    489  1.1  hkenken #endif
    490  1.1  hkenken 
    491  1.1  hkenken 	arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
    492  1.1  hkenken 	    KERNEL_BASE_PHYS);
    493  1.1  hkenken 	arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,
    494  1.1  hkenken 	    kobo_devmap, mapallmem_p);
    495  1.1  hkenken 
    496  1.1  hkenken #ifdef BOOTHOWTO
    497  1.1  hkenken 	boothowto |= BOOTHOWTO;
    498  1.1  hkenken #endif
    499  1.1  hkenken 
    500  1.1  hkenken 	return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
    501  1.1  hkenken }
    502  1.1  hkenken 
    503  1.1  hkenken void
    504  1.1  hkenken consinit(void)
    505  1.1  hkenken {
    506  1.1  hkenken 	static int consinit_called = 0;
    507  1.1  hkenken 
    508  1.1  hkenken 	if (consinit_called)
    509  1.1  hkenken 		return;
    510  1.1  hkenken 
    511  1.1  hkenken 	consinit_called = 1;
    512  1.1  hkenken 
    513  1.1  hkenken #ifdef	CONSDEVNAME
    514  1.1  hkenken 
    515  1.1  hkenken #if NIMXUART > 0
    516  1.1  hkenken 	imxuart_set_frequency(IMXUART_FREQ, 2);
    517  1.1  hkenken #endif
    518  1.1  hkenken 
    519  1.1  hkenken #if (NIMXUART > 0) && defined(IMXUARTCONSOLE)
    520  1.1  hkenken 	if (strcmp(consdevname, "imxuart") == 0) {
    521  1.1  hkenken 		paddr_t consaddr;
    522  1.1  hkenken #ifdef	CONADDR
    523  1.1  hkenken 		consaddr = CONADDR;
    524  1.1  hkenken #else
    525  1.1  hkenken 		consaddr = IMX51_UART2_BASE;
    526  1.1  hkenken #endif
    527  1.1  hkenken 		imxuart_cons_attach(&imx_bs_tag, consaddr, consrate, consmode);
    528  1.1  hkenken 		return;
    529  1.1  hkenken 	}
    530  1.1  hkenken #endif
    531  1.1  hkenken 
    532  1.1  hkenken #endif
    533  1.1  hkenken 
    534  1.1  hkenken #if (NWSDISPLAY > 0) && defined(IMXEPDCCONSOLE)
    535  1.1  hkenken #if NUKBD > 0
    536  1.1  hkenken 	ukbd_cnattach();
    537  1.1  hkenken #endif
    538  1.1  hkenken 	{
    539  1.1  hkenken 		extern void kobo_cnattach(void);
    540  1.1  hkenken 		kobo_cnattach();
    541  1.1  hkenken 	}
    542  1.1  hkenken #endif
    543  1.1  hkenken }
    544  1.1  hkenken 
    545  1.1  hkenken #ifdef KGDB
    546  1.1  hkenken #ifndef KGDB_DEVNAME
    547  1.1  hkenken #define KGDB_DEVNAME "imxuart"
    548  1.1  hkenken #endif
    549  1.1  hkenken #ifndef KGDB_DEVMODE
    550  1.1  hkenken #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    551  1.1  hkenken #endif
    552  1.1  hkenken 
    553  1.1  hkenken const char kgdb_devname[20] = KGDB_DEVNAME;
    554  1.1  hkenken int kgdb_mode = KGDB_DEVMODE;
    555  1.1  hkenken int kgdb_addr = KGDB_DEVADDR;
    556  1.1  hkenken extern int kgdb_rate;	/* defined in kgdb_stub.c */
    557  1.1  hkenken 
    558  1.1  hkenken void
    559  1.1  hkenken kgdb_port_init(void)
    560  1.1  hkenken {
    561  1.1  hkenken #if (NIMXUART > 0)
    562  1.1  hkenken 	if (strcmp(kgdb_devname, "imxuart") == 0) {
    563  1.1  hkenken 		imxuart_kgdb_attach(&imx_bs_tag, kgdb_addr,
    564  1.1  hkenken 		kgdb_rate, kgdb_mode);
    565  1.1  hkenken 	    return;
    566  1.1  hkenken 	}
    567  1.1  hkenken 
    568  1.1  hkenken #endif
    569  1.1  hkenken }
    570  1.1  hkenken #endif
    571