Home | History | Annotate | Line # | Download | only in kobo
kobo_machdep.c revision 1.2.8.1
      1  1.2.8.1    skrll /*	$NetBSD: kobo_machdep.c,v 1.2.8.1 2015/06/06 14:39:58 skrll 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.2.8.1    skrll __KERNEL_RCSID(0, "$NetBSD: kobo_machdep.c,v 1.2.8.1 2015/06/06 14:39:58 skrll 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.2  hkenken #include <sys/reboot.h>
    122      1.1  hkenken #include <sys/termios.h>
    123      1.1  hkenken #include <sys/bus.h>
    124      1.1  hkenken 
    125      1.1  hkenken #include <machine/db_machdep.h>
    126      1.1  hkenken #ifdef KGDB
    127      1.1  hkenken #include <sys/kgdb.h>
    128      1.1  hkenken #endif
    129      1.1  hkenken 
    130      1.1  hkenken #include <machine/bootconfig.h>
    131      1.1  hkenken 
    132      1.1  hkenken #include <arm/arm32/machdep.h>
    133      1.1  hkenken 
    134      1.1  hkenken #include <arm/imx/imx51reg.h>
    135      1.1  hkenken #include <arm/imx/imx51var.h>
    136      1.1  hkenken #include <arm/imx/imxuartreg.h>
    137      1.1  hkenken #include <arm/imx/imxuartvar.h>
    138      1.1  hkenken #include <arm/imx/imx50_iomuxreg.h>
    139      1.1  hkenken #include <arm/imx/imxgpiovar.h>
    140      1.1  hkenken 
    141      1.1  hkenken #include <evbarm/kobo/kobo.h>
    142      1.1  hkenken #include <evbarm/kobo/kobo_reg.h>
    143      1.1  hkenken 
    144      1.1  hkenken /* Kernel text starts 1MB in from the bottom of the kernel address space. */
    145      1.1  hkenken #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00100000)
    146      1.1  hkenken 
    147      1.1  hkenken BootConfig bootconfig;		/* Boot config storage */
    148      1.1  hkenken static char bootargs[MAX_BOOT_STRING];
    149      1.1  hkenken char *boot_args = NULL;
    150      1.1  hkenken 
    151      1.1  hkenken extern char KERNEL_BASE_phys[];
    152      1.1  hkenken 
    153      1.1  hkenken /*
    154      1.1  hkenken  * Macros to translate between physical and virtual for a subset of the
    155      1.1  hkenken  * kernel address space.  *Not* for general use.
    156      1.1  hkenken  */
    157      1.1  hkenken #define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys)
    158      1.1  hkenken 
    159      1.1  hkenken void consinit(void);
    160      1.1  hkenken 
    161      1.1  hkenken #ifdef KGDB
    162      1.1  hkenken void	kgdb_port_init(void);
    163      1.1  hkenken #endif
    164      1.1  hkenken 
    165      1.1  hkenken static void init_clocks(void);
    166      1.1  hkenken static void setup_ioports(void);
    167      1.1  hkenken 
    168      1.1  hkenken #ifndef CONSPEED
    169      1.1  hkenken #define CONSPEED B115200	/* What RedBoot uses */
    170      1.1  hkenken #endif
    171      1.1  hkenken #ifndef CONMODE
    172      1.1  hkenken #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    173      1.1  hkenken #endif
    174      1.1  hkenken 
    175      1.1  hkenken int comcnspeed = CONSPEED;
    176      1.1  hkenken int comcnmode = CONMODE;
    177      1.1  hkenken 
    178      1.1  hkenken /*
    179      1.1  hkenken  * Static device mappings. These peripheral registers are mapped at
    180      1.1  hkenken  * fixed virtual addresses very early in initarm() so that we can use
    181      1.1  hkenken  * them while booting the kernel, and stay at the same address
    182      1.1  hkenken  * throughout whole kernel's life time.
    183      1.1  hkenken  *
    184      1.1  hkenken  * We use this table twice; once with bootstrap page table, and once
    185      1.1  hkenken  * with kernel's page table which we build up in initarm().
    186      1.1  hkenken  *
    187      1.1  hkenken  * Since we map these registers into the bootstrap page table using
    188      1.1  hkenken  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    189      1.1  hkenken  * registers segment-aligned and segment-rounded in order to avoid
    190      1.1  hkenken  * using the 2nd page tables.
    191      1.1  hkenken  */
    192      1.1  hkenken 
    193      1.1  hkenken #define _A(a)   ((a) & ~L1_S_OFFSET)
    194      1.1  hkenken #define _S(s)   (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    195      1.1  hkenken 
    196      1.1  hkenken const struct pmap_devmap kobo_devmap[] = {
    197      1.1  hkenken 	{
    198      1.1  hkenken 		/* for UART2, IOMUXC */
    199      1.1  hkenken 		.pd_va = _A(KOBO_IO_VBASE0),
    200      1.1  hkenken 		.pd_pa = _A(KOBO_IO_PBASE0),
    201      1.1  hkenken 		.pd_size = _S(L1_S_SIZE * 4),
    202      1.1  hkenken 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    203      1.1  hkenken 		.pd_cache = PTE_NOCACHE
    204      1.1  hkenken 	},
    205      1.1  hkenken 	{0}
    206      1.1  hkenken };
    207      1.1  hkenken 
    208      1.1  hkenken #undef	_A
    209      1.1  hkenken #undef	_S
    210      1.1  hkenken 
    211      1.1  hkenken #ifndef MEMSTART
    212      1.1  hkenken #define MEMSTART	0x70000000
    213      1.1  hkenken #endif
    214      1.1  hkenken #ifndef MEMSIZE
    215      1.1  hkenken #define MEMSIZE		256
    216      1.1  hkenken #endif
    217      1.1  hkenken 
    218      1.1  hkenken static void
    219      1.1  hkenken init_clocks(void)
    220      1.1  hkenken {
    221      1.1  hkenken 	cortex_pmc_ccnt_init();
    222      1.1  hkenken }
    223      1.1  hkenken 
    224      1.1  hkenken struct iomux_setup {
    225      1.1  hkenken 	/* iomux registers are 32-bit wide, but upper 16 bits are not
    226      1.1  hkenken 	 * used. */
    227      1.1  hkenken 	uint16_t	reg;
    228      1.1  hkenken 	uint16_t	val;
    229      1.1  hkenken };
    230      1.1  hkenken 
    231      1.1  hkenken #define	IOMUX_M(padname, mux)		\
    232      1.1  hkenken 	IOMUX_DATA(__CONCAT(IOMUXC_SW_MUX_CTL_PAD_,padname), mux)
    233      1.1  hkenken 
    234      1.1  hkenken #define	IOMUX_P(padname, pad)		\
    235      1.1  hkenken 	IOMUX_DATA(__CONCAT(IOMUXC_SW_PAD_CTL_PAD_,padname), pad)
    236      1.1  hkenken 
    237      1.1  hkenken #define	IOMUX_MP(padname, mux, pad)	\
    238      1.1  hkenken 	IOMUX_M(padname, mux), \
    239      1.1  hkenken 	IOMUX_P(padname, pad)
    240      1.1  hkenken 
    241      1.1  hkenken #define	IOMUX_DATA(offset, value)	\
    242      1.1  hkenken 	{				\
    243      1.1  hkenken 		.reg = (offset),	\
    244      1.1  hkenken 		.val = (value),		\
    245      1.1  hkenken 	}
    246      1.1  hkenken 
    247      1.1  hkenken const struct iomux_setup iomux_setup_data[] = {
    248      1.1  hkenken #define	HYS	PAD_CTL_HYS
    249      1.1  hkenken #define	ODE	PAD_CTL_ODE
    250      1.1  hkenken #define	DSEHIGH	PAD_CTL_DSE_HIGH
    251      1.1  hkenken #define	DSEMID	PAD_CTL_DSE_MID
    252      1.1  hkenken #define	DSELOW	PAD_CTL_DSE_LOW
    253      1.1  hkenken #define	DSEMAX	PAD_CTL_DSE_MAX
    254      1.1  hkenken #define	SRE	PAD_CTL_SRE
    255      1.1  hkenken #define	KEEPER	PAD_CTL_KEEPER
    256      1.1  hkenken #define	PULL	PAD_CTL_PULL
    257      1.1  hkenken #define	PU_22K	PAD_CTL_PUS_22K_PU
    258      1.1  hkenken #define	PU_47K	PAD_CTL_PUS_47K_PU
    259      1.1  hkenken #define	PU_100K	PAD_CTL_PUS_100K_PU
    260      1.1  hkenken #define	PD_100K	PAD_CTL_PUS_100K_PD
    261      1.1  hkenken #define	HVE	PAD_CTL_HVE	/* Low output voltage */
    262      1.1  hkenken 
    263      1.1  hkenken #define	ALT0	IOMUX_CONFIG_ALT0
    264      1.1  hkenken #define	ALT1	IOMUX_CONFIG_ALT1
    265      1.1  hkenken #define	ALT2	IOMUX_CONFIG_ALT2
    266      1.1  hkenken #define	ALT3	IOMUX_CONFIG_ALT3
    267      1.1  hkenken #define	ALT4	IOMUX_CONFIG_ALT4
    268      1.1  hkenken #define	ALT5	IOMUX_CONFIG_ALT5
    269      1.1  hkenken #define	ALT6	IOMUX_CONFIG_ALT6
    270      1.1  hkenken #define	ALT7	IOMUX_CONFIG_ALT7
    271      1.1  hkenken #define	SION	IOMUX_CONFIG_SION
    272      1.1  hkenken 
    273      1.1  hkenken 	/* I2C1 */
    274      1.1  hkenken 	IOMUX_MP(I2C1_SCL, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    275      1.1  hkenken 	IOMUX_MP(I2C1_SDA, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    276      1.1  hkenken 
    277      1.1  hkenken 	/* I2C2 */
    278      1.1  hkenken 	IOMUX_MP(I2C2_SCL, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    279      1.1  hkenken 	IOMUX_MP(I2C2_SDA, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    280      1.1  hkenken 
    281      1.1  hkenken 	/* I2C3 */
    282      1.1  hkenken 	IOMUX_MP(I2C3_SCL, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    283      1.1  hkenken 	IOMUX_MP(I2C3_SDA, ALT0 | SION, PULL | PU_100K | HYS | ODE | DSEHIGH),
    284      1.1  hkenken 
    285      1.1  hkenken 	/* UART2 */
    286      1.1  hkenken 	IOMUX_MP(UART2_RXD, ALT0, HYS | PULL | DSEHIGH | SRE),
    287      1.1  hkenken 	IOMUX_MP(UART2_TXD, ALT0, HYS | PULL | DSEHIGH | SRE),
    288      1.1  hkenken 
    289      1.1  hkenken 	/* SD1 */
    290      1.1  hkenken 	IOMUX_MP(SD1_CMD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    291      1.1  hkenken 	IOMUX_MP(SD1_CLK, ALT0, HVE | PU_22K | DSEMAX | SRE),
    292      1.1  hkenken 	IOMUX_MP(SD1_D0, ALT0, HVE | PU_22K | DSEMAX | SRE),
    293      1.1  hkenken 	IOMUX_MP(SD1_D1, ALT0, HVE | PU_22K | DSEMAX | SRE),
    294      1.1  hkenken 	IOMUX_MP(SD1_D2, ALT0, HVE | PU_22K | DSEMAX | SRE),
    295      1.1  hkenken 	IOMUX_MP(SD1_D3, ALT0, HVE | PU_22K | DSEMAX | SRE),
    296      1.1  hkenken //	IOMUX_MP(SD1_CD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    297      1.1  hkenken 
    298      1.1  hkenken 	/* SD2 */
    299      1.1  hkenken 	IOMUX_MP(SD2_CMD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    300      1.1  hkenken 	IOMUX_MP(SD2_CLK, ALT0, HVE | PU_22K | DSEMAX | SRE),
    301      1.1  hkenken 	IOMUX_MP(SD2_D0, ALT0, HVE | PU_22K | DSEMAX | SRE),
    302      1.1  hkenken 	IOMUX_MP(SD2_D1, ALT0, HVE | PU_22K | DSEMAX | SRE),
    303      1.1  hkenken 	IOMUX_MP(SD2_D2, ALT0, HVE | PU_22K | DSEMAX | SRE),
    304      1.1  hkenken 	IOMUX_MP(SD2_D3, ALT0, HVE | PU_22K | DSEMAX | SRE),
    305      1.1  hkenken 	IOMUX_MP(SD2_CD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    306      1.1  hkenken 
    307      1.1  hkenken 	IOMUX_DATA(IOMUXC_ESDHC2_IPP_CARD_DET_SELECT_INPUT, INPUT_DAISY_1),
    308      1.1  hkenken 
    309      1.1  hkenken 	/* SD3 */
    310      1.1  hkenken 	IOMUX_MP(SD3_CMD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    311      1.1  hkenken 	IOMUX_MP(SD3_CLK, ALT0, HVE | PU_22K | DSEMAX | SRE),
    312      1.1  hkenken 	IOMUX_MP(SD3_D0, ALT0, HVE | PU_22K | DSEMAX | SRE),
    313      1.1  hkenken 	IOMUX_MP(SD3_D1, ALT0, HVE | PU_22K | DSEMAX | SRE),
    314      1.1  hkenken 	IOMUX_MP(SD3_D2, ALT0, HVE | PU_22K | DSEMAX | SRE),
    315      1.1  hkenken 	IOMUX_MP(SD3_D3, ALT0, HVE | PU_22K | DSEMAX | SRE),
    316      1.1  hkenken //	IOMUX_MP(SD3_CD, ALT0, HVE | PU_22K | DSEMAX | SRE),
    317      1.1  hkenken 
    318      1.1  hkenken 	/* OTG */
    319      1.1  hkenken 	IOMUX_M(PWM2, ALT2),
    320      1.1  hkenken //	IOMUX_MP(PWM1, ALT2, HYS | KEEPER | DSEHIGH),
    321      1.1  hkenken 
    322      1.1  hkenken 	/* EPDC */
    323      1.1  hkenken 	IOMUX_M(EPDC_D0, ALT0),
    324      1.1  hkenken 	IOMUX_M(EPDC_D1, ALT0),
    325      1.1  hkenken 	IOMUX_M(EPDC_D2, ALT0),
    326      1.1  hkenken 	IOMUX_M(EPDC_D3, ALT0),
    327      1.1  hkenken 	IOMUX_M(EPDC_D4, ALT0),
    328      1.1  hkenken 	IOMUX_M(EPDC_D5, ALT0),
    329      1.1  hkenken 	IOMUX_M(EPDC_D6, ALT0),
    330      1.1  hkenken 	IOMUX_M(EPDC_D7, ALT0),
    331      1.1  hkenken 	IOMUX_M(EPDC_GDCLK, ALT0),
    332      1.1  hkenken 	IOMUX_M(EPDC_GDSP, ALT0),
    333      1.1  hkenken 	IOMUX_M(EPDC_GDOE, ALT0),
    334      1.1  hkenken 	IOMUX_M(EPDC_GDRL, ALT0),
    335      1.1  hkenken 	IOMUX_M(EPDC_SDCLK, ALT0),
    336      1.1  hkenken 	IOMUX_M(EPDC_SDOE, ALT0),
    337      1.1  hkenken 	IOMUX_M(EPDC_SDLE, ALT0),
    338      1.1  hkenken 	IOMUX_M(EPDC_BDR0, ALT0),
    339      1.1  hkenken 	IOMUX_M(EPDC_BDR1, ALT0),
    340      1.1  hkenken 	IOMUX_M(EPDC_SDCE0, ALT0),
    341      1.1  hkenken 
    342      1.1  hkenken 	IOMUX_M(EPDC_PWRSTAT, ALT1),	/* GPIO3[28] */
    343      1.1  hkenken 	IOMUX_M(EPDC_PWRCTRL0, ALT1),	/* GPIO3[29] */
    344      1.1  hkenken 	IOMUX_M(EPDC_VCOM0, ALT1),	/* GPIO4[21] */
    345      1.1  hkenken 	IOMUX_M(UART4_TXD, ALT1),	/* GPIO6[16] */
    346      1.1  hkenken 	IOMUX_M(UART4_RXD, ALT1),	/* GPIO6[17] */
    347      1.1  hkenken 
    348      1.1  hkenken //	IOMUX_M(PWM2, ALT1),		/* GPIO6[25] */
    349      1.1  hkenken 
    350      1.1  hkenken #undef	ODE
    351      1.1  hkenken #undef	HYS
    352      1.1  hkenken #undef	SRE
    353      1.1  hkenken #undef	PULL
    354      1.1  hkenken #undef	KEEPER
    355      1.1  hkenken #undef	PU_22K
    356      1.1  hkenken #undef	PU_47K
    357      1.1  hkenken #undef	PU_100K
    358      1.1  hkenken #undef	PD_100K
    359      1.1  hkenken #undef	HVE
    360      1.1  hkenken #undef	DSEMAX
    361      1.1  hkenken #undef	DSEHIGH
    362      1.1  hkenken #undef	DSEMID
    363      1.1  hkenken #undef	DSELOW
    364      1.1  hkenken 
    365      1.1  hkenken #undef	ALT0
    366      1.1  hkenken #undef	ALT1
    367      1.1  hkenken #undef	ALT2
    368      1.1  hkenken #undef	ALT3
    369      1.1  hkenken #undef	ALT4
    370      1.1  hkenken #undef	ALT5
    371      1.1  hkenken #undef	ALT6
    372      1.1  hkenken #undef	ALT7
    373      1.1  hkenken #undef	SION
    374      1.1  hkenken };
    375      1.1  hkenken 
    376      1.1  hkenken static void
    377      1.1  hkenken setup_ioports(void)
    378      1.1  hkenken {
    379      1.1  hkenken 	int i;
    380      1.1  hkenken 	const struct iomux_setup *p;
    381      1.1  hkenken 
    382      1.1  hkenken 	for (i=0; i < __arraycount(iomux_setup_data); ++i) {
    383      1.1  hkenken 		p = iomux_setup_data + i;
    384      1.1  hkenken 
    385      1.1  hkenken 		ioreg_write(KOBO_IOMUXC_VBASE + p->reg,
    386      1.1  hkenken 			    p->val);
    387      1.1  hkenken 	}
    388      1.1  hkenken }
    389      1.1  hkenken 
    390      1.1  hkenken #ifdef	CONSDEVNAME
    391      1.1  hkenken const char consdevname[] = CONSDEVNAME;
    392      1.1  hkenken 
    393      1.1  hkenken #ifndef	CONMODE
    394      1.1  hkenken #define	CONMODE	((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    395      1.1  hkenken #endif
    396      1.1  hkenken #ifndef	CONSPEED
    397      1.1  hkenken #define	CONSPEED	115200
    398      1.1  hkenken #endif
    399      1.1  hkenken 
    400      1.1  hkenken int consmode = CONMODE;
    401      1.1  hkenken int consrate = CONSPEED;
    402      1.1  hkenken 
    403      1.1  hkenken #endif	/* CONSDEVNAME */
    404      1.1  hkenken 
    405      1.1  hkenken #ifndef	IMXUART_FREQ
    406      1.1  hkenken #define	IMXUART_FREQ	24000000
    407      1.1  hkenken #endif
    408      1.1  hkenken 
    409      1.1  hkenken /*
    410      1.1  hkenken  * u_int initarm(...)
    411      1.1  hkenken  *
    412      1.1  hkenken  * Initial entry point on startup. This gets called before main() is
    413      1.1  hkenken  * entered.
    414      1.1  hkenken  * It should be responsible for setting up everything that must be
    415      1.1  hkenken  * in place when main is called.
    416      1.1  hkenken  * This includes
    417      1.1  hkenken  *   Taking a copy of the boot configuration structure.
    418      1.1  hkenken  *   Initialising the physical console so characters can be printed.
    419      1.1  hkenken  *   Setting up page tables for the kernel
    420      1.1  hkenken  */
    421      1.1  hkenken u_int
    422      1.1  hkenken initarm(void *arg)
    423      1.1  hkenken {
    424      1.1  hkenken 	/*
    425      1.1  hkenken 	 * Heads up ... Setup the CPU / MMU / TLB functions
    426      1.1  hkenken 	 */
    427      1.1  hkenken 	if (set_cpufuncs())		// starts PMC counter
    428      1.1  hkenken 		panic("cpu not recognized!");
    429      1.1  hkenken 
    430      1.1  hkenken 	/* map some peripheral registers */
    431      1.1  hkenken 	pmap_devmap_bootstrap((vaddr_t)armreg_ttbr_read() & -L1_TABLE_SIZE,
    432      1.1  hkenken 	    kobo_devmap);
    433      1.1  hkenken 
    434      1.1  hkenken 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    435      1.1  hkenken 
    436      1.1  hkenken 	/* Register devmap for devices we mapped in start */
    437      1.1  hkenken 	pmap_devmap_register(kobo_devmap);
    438      1.1  hkenken 	setup_ioports();
    439      1.1  hkenken 
    440      1.1  hkenken 	consinit();
    441      1.1  hkenken 
    442      1.1  hkenken 	init_clocks();
    443      1.1  hkenken 
    444      1.1  hkenken #ifdef KGDB
    445      1.1  hkenken 	kgdb_port_init();
    446      1.1  hkenken #endif
    447      1.1  hkenken 
    448      1.1  hkenken 	/* Talk to the user */
    449      1.1  hkenken 	printf("\nNetBSD/evbarm (" ___STRING(EVBARM_BOARDTYPE) ") booting ...\n");
    450      1.1  hkenken 
    451      1.1  hkenken #ifdef BOOT_ARGS
    452      1.1  hkenken 	char mi_bootargs[] = BOOT_ARGS;
    453      1.1  hkenken 	parse_mi_bootargs(mi_bootargs);
    454      1.1  hkenken #endif
    455      1.1  hkenken 	bootargs[0] = '\0';
    456      1.1  hkenken 
    457      1.1  hkenken #ifdef VERBOSE_INIT_ARM
    458      1.1  hkenken 	printf("initarm: Configuring system");
    459      1.1  hkenken 	printf(", CLIDR=%010o CTR=%#x",
    460      1.1  hkenken 	    armreg_clidr_read(), armreg_ctr_read());
    461      1.1  hkenken 	printf("\n");
    462      1.1  hkenken #endif
    463      1.1  hkenken 
    464      1.1  hkenken #ifdef VERBOSE_INIT_ARM
    465      1.1  hkenken 	printf("initarm: Configuring system ...\n");
    466      1.1  hkenken #endif
    467      1.1  hkenken 	/*
    468      1.1  hkenken 	 * Set up the variables that define the availability of physical
    469      1.1  hkenken 	 * memory.
    470      1.1  hkenken 	 */
    471      1.1  hkenken 
    472      1.1  hkenken 	/* Fake bootconfig structure for the benefit of pmap.c. */
    473      1.1  hkenken 	bootconfig.dramblocks = 1;
    474      1.1  hkenken 	bootconfig.dram[0].address = MEMSTART;
    475      1.1  hkenken 	bootconfig.dram[0].pages = (MEMSIZE * 1024 * 1024) / PAGE_SIZE;
    476      1.1  hkenken 
    477      1.1  hkenken 	psize_t ram_size = bootconfig.dram[0].pages * PAGE_SIZE;
    478      1.1  hkenken 
    479      1.1  hkenken #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
    480      1.1  hkenken 	const bool mapallmem_p = true;
    481      1.1  hkenken 	if (ram_size > (KERNEL_VM_BASE - KERNEL_BASE)) {
    482      1.1  hkenken 		printf("%s: dropping RAM size from %luMB to %uMB\n",
    483      1.1  hkenken 		    __func__, (unsigned long) (ram_size >> 20),
    484      1.1  hkenken 		    (KERNEL_VM_BASE - KERNEL_BASE) >> 20);
    485      1.1  hkenken 		ram_size = KERNEL_VM_BASE - KERNEL_BASE;
    486      1.1  hkenken 	}
    487      1.1  hkenken 	KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE);
    488      1.1  hkenken #else
    489      1.1  hkenken 	const bool mapallmem_p = false;
    490      1.1  hkenken #endif
    491      1.1  hkenken 
    492      1.1  hkenken 	arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
    493      1.1  hkenken 	    KERNEL_BASE_PHYS);
    494      1.1  hkenken 	arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,
    495      1.1  hkenken 	    kobo_devmap, mapallmem_p);
    496      1.1  hkenken 
    497      1.1  hkenken #ifdef BOOTHOWTO
    498      1.1  hkenken 	boothowto |= BOOTHOWTO;
    499      1.1  hkenken #endif
    500      1.1  hkenken 
    501      1.1  hkenken 	return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
    502      1.1  hkenken }
    503      1.1  hkenken 
    504      1.1  hkenken void
    505      1.1  hkenken consinit(void)
    506      1.1  hkenken {
    507      1.1  hkenken 	static int consinit_called = 0;
    508      1.1  hkenken 
    509      1.1  hkenken 	if (consinit_called)
    510      1.1  hkenken 		return;
    511      1.1  hkenken 
    512      1.1  hkenken 	consinit_called = 1;
    513      1.1  hkenken 
    514      1.1  hkenken #ifdef	CONSDEVNAME
    515      1.1  hkenken 
    516      1.1  hkenken #if NIMXUART > 0
    517      1.1  hkenken 	imxuart_set_frequency(IMXUART_FREQ, 2);
    518      1.1  hkenken #endif
    519      1.1  hkenken 
    520      1.1  hkenken #if (NIMXUART > 0) && defined(IMXUARTCONSOLE)
    521      1.1  hkenken 	if (strcmp(consdevname, "imxuart") == 0) {
    522      1.1  hkenken 		paddr_t consaddr;
    523      1.1  hkenken #ifdef	CONADDR
    524      1.1  hkenken 		consaddr = CONADDR;
    525      1.1  hkenken #else
    526      1.1  hkenken 		consaddr = IMX51_UART2_BASE;
    527      1.1  hkenken #endif
    528  1.2.8.1    skrll 		imxuart_cons_attach(&armv7_generic_bs_tag, consaddr, consrate, consmode);
    529      1.1  hkenken 		return;
    530      1.1  hkenken 	}
    531      1.1  hkenken #endif
    532      1.1  hkenken 
    533      1.1  hkenken #endif
    534      1.1  hkenken 
    535      1.1  hkenken #if (NWSDISPLAY > 0) && defined(IMXEPDCCONSOLE)
    536      1.1  hkenken #if NUKBD > 0
    537      1.1  hkenken 	ukbd_cnattach();
    538      1.1  hkenken #endif
    539      1.1  hkenken 	{
    540      1.1  hkenken 		extern void kobo_cnattach(void);
    541      1.1  hkenken 		kobo_cnattach();
    542      1.1  hkenken 	}
    543      1.1  hkenken #endif
    544      1.1  hkenken }
    545      1.1  hkenken 
    546      1.1  hkenken #ifdef KGDB
    547      1.1  hkenken #ifndef KGDB_DEVNAME
    548      1.1  hkenken #define KGDB_DEVNAME "imxuart"
    549      1.1  hkenken #endif
    550      1.1  hkenken #ifndef KGDB_DEVMODE
    551      1.1  hkenken #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    552      1.1  hkenken #endif
    553      1.1  hkenken 
    554      1.1  hkenken const char kgdb_devname[20] = KGDB_DEVNAME;
    555      1.1  hkenken int kgdb_mode = KGDB_DEVMODE;
    556      1.1  hkenken int kgdb_addr = KGDB_DEVADDR;
    557      1.1  hkenken extern int kgdb_rate;	/* defined in kgdb_stub.c */
    558      1.1  hkenken 
    559      1.1  hkenken void
    560      1.1  hkenken kgdb_port_init(void)
    561      1.1  hkenken {
    562      1.1  hkenken #if (NIMXUART > 0)
    563      1.1  hkenken 	if (strcmp(kgdb_devname, "imxuart") == 0) {
    564  1.2.8.1    skrll 		imxuart_kgdb_attach(&armv7_generic_bs_tag, kgdb_addr,
    565      1.1  hkenken 		kgdb_rate, kgdb_mode);
    566      1.1  hkenken 	    return;
    567      1.1  hkenken 	}
    568      1.1  hkenken 
    569      1.1  hkenken #endif
    570      1.1  hkenken }
    571      1.1  hkenken #endif
    572