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