xref: /rk3399_rockchip-uboot/arch/arm/cpu/arm926ejs/mxs/spl_boot.c (revision 9c2c8a3129ff357b0bd052e1bc248c4c3368c49c)
1 /*
2  * Freescale i.MX28 Boot setup
3  *
4  * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5  * on behalf of DENX Software Engineering GmbH
6  *
7  * SPDX-License-Identifier:	GPL-2.0+
8  */
9 
10 #include <common.h>
11 #include <config.h>
12 #include <asm/io.h>
13 #include <asm/arch/imx-regs.h>
14 #include <asm/arch/sys_proto.h>
15 #include <asm/gpio.h>
16 
17 #include "mxs_init.h"
18 
19 /*
20  * This delay function is intended to be used only in early stage of boot, where
21  * clock are not set up yet. The timer used here is reset on every boot and
22  * takes a few seconds to roll. The boot doesn't take that long, so to keep the
23  * code simple, it doesn't take rolling into consideration.
24  */
25 void early_delay(int delay)
26 {
27 	struct mxs_digctl_regs *digctl_regs =
28 		(struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
29 
30 	uint32_t st = readl(&digctl_regs->hw_digctl_microseconds);
31 	st += delay;
32 	while (st > readl(&digctl_regs->hw_digctl_microseconds))
33 		;
34 }
35 
36 #define	MUX_CONFIG_BOOTMODE_PAD	(MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
37 static const iomux_cfg_t iomux_boot[] = {
38 #if defined(CONFIG_MX23)
39 	MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
40 	MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
41 	MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
42 	MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
43 	MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
44 	MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
45 #elif defined(CONFIG_MX28)
46 	MX28_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
47 	MX28_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
48 	MX28_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
49 	MX28_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
50 	MX28_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
51 	MX28_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
52 #endif
53 };
54 
55 static uint8_t mxs_get_bootmode_index(void)
56 {
57 	uint8_t bootmode = 0;
58 	int i;
59 	uint8_t masked;
60 
61 	/* Setup IOMUX of bootmode pads to GPIO */
62 	mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
63 
64 #if defined(CONFIG_MX23)
65 	/* Setup bootmode pins as GPIO input */
66 	gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
67 	gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
68 	gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
69 	gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
70 	gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
71 
72 	/* Read bootmode pads */
73 	bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
74 	bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
75 	bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
76 	bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
77 	bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
78 #elif defined(CONFIG_MX28)
79 	/* Setup bootmode pins as GPIO input */
80 	gpio_direction_input(MX28_PAD_LCD_D00__GPIO_1_0);
81 	gpio_direction_input(MX28_PAD_LCD_D01__GPIO_1_1);
82 	gpio_direction_input(MX28_PAD_LCD_D02__GPIO_1_2);
83 	gpio_direction_input(MX28_PAD_LCD_D03__GPIO_1_3);
84 	gpio_direction_input(MX28_PAD_LCD_D04__GPIO_1_4);
85 	gpio_direction_input(MX28_PAD_LCD_D05__GPIO_1_5);
86 
87 	/* Read bootmode pads */
88 	bootmode |= (gpio_get_value(MX28_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
89 	bootmode |= (gpio_get_value(MX28_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
90 	bootmode |= (gpio_get_value(MX28_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
91 	bootmode |= (gpio_get_value(MX28_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
92 	bootmode |= (gpio_get_value(MX28_PAD_LCD_D04__GPIO_1_4) ? 1 : 0) << 4;
93 	bootmode |= (gpio_get_value(MX28_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
94 #endif
95 
96 	for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
97 		masked = bootmode & mxs_boot_modes[i].boot_mask;
98 		if (masked == mxs_boot_modes[i].boot_pads)
99 			break;
100 	}
101 
102 	return i;
103 }
104 
105 static void mxs_spl_fixup_vectors(void)
106 {
107 	/*
108 	 * Copy our vector table to 0x0, since due to HAB, we cannot
109 	 * be loaded to 0x0. We want to have working vectoring though,
110 	 * thus this fixup. Our vectoring table is PIC, so copying is
111 	 * fine.
112 	 */
113 	extern uint32_t _start;
114 	memcpy(0x0, &_start, 0x60);
115 }
116 
117 void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr,
118 			 const iomux_cfg_t *iomux_setup,
119 			 const unsigned int iomux_size)
120 {
121 	struct mxs_spl_data *data = (struct mxs_spl_data *)
122 		((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
123 	uint8_t bootmode = mxs_get_bootmode_index();
124 
125 	mxs_spl_fixup_vectors();
126 
127 	mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
128 
129 	mxs_power_init();
130 
131 	mxs_mem_init();
132 	data->mem_dram_size = mxs_mem_get_size();
133 
134 	data->boot_mode_idx = bootmode;
135 
136 	mxs_power_wait_pswitch();
137 }
138 
139 /* Support aparatus */
140 inline void board_init_f(unsigned long bootflag)
141 {
142 	for (;;)
143 		;
144 }
145 
146 inline void board_init_r(gd_t *id, ulong dest_addr)
147 {
148 	for (;;)
149 		;
150 }
151