blob: 585c53baf6589a28b164d5925c08c15b7365ac2f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasutc140e982011-11-08 23:18:08 +00002/*
Otavio Salvadorfd96c032013-01-11 03:19:08 +00003 * Freescale i.MX23/i.MX28 common code
Marek Vasutc140e982011-11-08 23:18:08 +00004 *
5 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
6 * on behalf of DENX Software Engineering GmbH
7 *
8 * Based on code from LTIB:
9 * Copyright (C) 2010 Freescale Semiconductor, Inc.
Marek Vasutc140e982011-11-08 23:18:08 +000010 */
11
12#include <common.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090013#include <linux/errno.h>
Marek Vasutc140e982011-11-08 23:18:08 +000014#include <asm/io.h>
15#include <asm/arch/clock.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020016#include <asm/mach-imx/dma.h>
Marek Vasutc140e982011-11-08 23:18:08 +000017#include <asm/arch/gpio.h>
Marek Vasut53fdab22011-11-08 23:18:13 +000018#include <asm/arch/iomux.h>
Marek Vasutc140e982011-11-08 23:18:08 +000019#include <asm/arch/imx-regs.h>
20#include <asm/arch/sys_proto.h>
Fabio Estevam570dcfd2013-01-08 05:21:45 +000021#include <linux/compiler.h>
Marek Vasutc140e982011-11-08 23:18:08 +000022
Marek Vasut5bf48fb2011-11-08 23:18:23 +000023DECLARE_GLOBAL_DATA_PTR;
24
Marek Vasutc140e982011-11-08 23:18:08 +000025/* Lowlevel init isn't used on i.MX28, so just have a dummy here */
Mans Rullgard04ef8652018-04-21 16:11:06 +010026__weak void lowlevel_init(void) {}
Marek Vasutc140e982011-11-08 23:18:08 +000027
28void reset_cpu(ulong ignored) __attribute__((noreturn));
29
30void reset_cpu(ulong ignored)
31{
Otavio Salvador22f4ff92012-08-05 09:05:31 +000032 struct mxs_rtc_regs *rtc_regs =
33 (struct mxs_rtc_regs *)MXS_RTC_BASE;
34 struct mxs_lcdif_regs *lcdif_regs =
35 (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
Marek Vasut9c53b7e2012-05-01 11:09:47 +000036
37 /*
38 * Shut down the LCD controller as it interferes with BootROM boot mode
39 * pads sampling.
40 */
41 writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr);
Marek Vasutc140e982011-11-08 23:18:08 +000042
43 /* Wait 1 uS before doing the actual watchdog reset */
44 writel(1, &rtc_regs->hw_rtc_watchdog);
45 writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
46
47 /* Endless loop, reset will exit from here */
48 for (;;)
49 ;
50}
51
Marek Vasut39c31032013-04-25 16:37:12 +000052/*
53 * This function will craft a jumptable at 0x0 which will redirect interrupt
54 * vectoring to proper location of U-Boot in RAM.
55 *
56 * The structure of the jumptable will be as follows:
57 * ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times
58 * <destination address> ... for each previous ldr, thus also repeated 8 times
59 *
60 * The "ldr pc, [pc, #0x18]" instruction above loads address from memory at
61 * offset 0x18 from current value of PC register. Note that PC is already
62 * incremented by 4 when computing the offset, so the effective offset is
63 * actually 0x20, this the associated <destination address>. Loading the PC
64 * register with an address performs a jump to that address.
65 */
Marek Vasut5bf48fb2011-11-08 23:18:23 +000066void mx28_fixup_vt(uint32_t start_addr)
67{
Marek Vasut39c31032013-04-25 16:37:12 +000068 /* ldr pc, [pc, #0x18] */
69 const uint32_t ldr_pc = 0xe59ff018;
70 /* Jumptable location is 0x0 */
71 uint32_t *vt = (uint32_t *)0x0;
Marek Vasut5bf48fb2011-11-08 23:18:23 +000072 int i;
73
Marek Vasut39c31032013-04-25 16:37:12 +000074 for (i = 0; i < 8; i++) {
Wolfgang Denk6ae80832014-11-06 14:02:57 +010075 /* cppcheck-suppress nullPointer */
Marek Vasut39c31032013-04-25 16:37:12 +000076 vt[i] = ldr_pc;
Wolfgang Denk6ae80832014-11-06 14:02:57 +010077 /* cppcheck-suppress nullPointer */
Marek Vasut39c31032013-04-25 16:37:12 +000078 vt[i + 8] = start_addr + (4 * i);
79 }
Marek Vasut5bf48fb2011-11-08 23:18:23 +000080}
81
82#ifdef CONFIG_ARCH_MISC_INIT
83int arch_misc_init(void)
84{
85 mx28_fixup_vt(gd->relocaddr);
Marek Vasutc140e982011-11-08 23:18:08 +000086 return 0;
87}
Marek Vasut5bf48fb2011-11-08 23:18:23 +000088#endif
Marek Vasutc140e982011-11-08 23:18:08 +000089
Marek Vasutc140e982011-11-08 23:18:08 +000090int arch_cpu_init(void)
91{
Otavio Salvador22f4ff92012-08-05 09:05:31 +000092 struct mxs_clkctrl_regs *clkctrl_regs =
93 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasut5bf48fb2011-11-08 23:18:23 +000094 extern uint32_t _start;
95
96 mx28_fixup_vt((uint32_t)&_start);
Marek Vasutc140e982011-11-08 23:18:08 +000097
98 /*
99 * Enable NAND clock
100 */
Rasmus Villemoes6cb658c2019-09-12 09:17:10 +0000101 /* Set bypass bit */
Marek Vasutc140e982011-11-08 23:18:08 +0000102 writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
103 &clkctrl_regs->hw_clkctrl_clkseq_set);
104
Rasmus Villemoes6cb658c2019-09-12 09:17:10 +0000105 /* Set GPMI clock to ref_xtal / 1 */
Marek Vasutc140e982011-11-08 23:18:08 +0000106 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
107 CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1);
108
109 udelay(1000);
110
Marek Vasut53fdab22011-11-08 23:18:13 +0000111 /*
112 * Configure GPIO unit
113 */
114 mxs_gpio_init();
115
Marek Vasut93541b42012-04-08 17:34:46 +0000116#ifdef CONFIG_APBH_DMA
117 /* Start APBH DMA */
118 mxs_dma_init();
119#endif
120
Marek Vasutc140e982011-11-08 23:18:08 +0000121 return 0;
122}
Marek Vasutc140e982011-11-08 23:18:08 +0000123
Peng Fanb741b162015-08-13 10:55:33 +0800124u32 get_cpu_rev(void)
Otavio Salvadorca36b532012-07-28 11:43:47 +0000125{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000126 struct mxs_digctl_regs *digctl_regs =
127 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000128 uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;
129
130 switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000131 case HW_DIGCTL_CHIPID_MX23:
132 switch (rev) {
133 case 0x0:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000134 case 0x1:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000135 case 0x2:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000136 case 0x3:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000137 case 0x4:
Peng Fanb741b162015-08-13 10:55:33 +0800138 return (MXC_CPU_MX23 << 12) | (rev + 0x10);
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000139 default:
Peng Fanb741b162015-08-13 10:55:33 +0800140 return 0;
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000141 }
Otavio Salvadorca36b532012-07-28 11:43:47 +0000142 case HW_DIGCTL_CHIPID_MX28:
143 switch (rev) {
144 case 0x1:
Peng Fanb741b162015-08-13 10:55:33 +0800145 return (MXC_CPU_MX28 << 12) | 0x12;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000146 default:
Peng Fanb741b162015-08-13 10:55:33 +0800147 return 0;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000148 }
149 default:
Peng Fanb741b162015-08-13 10:55:33 +0800150 return 0;
151 }
152}
153
154#if defined(CONFIG_DISPLAY_CPUINFO)
155const char *get_imx_type(u32 imxtype)
156{
157 switch (imxtype) {
158 case MXC_CPU_MX23:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200159 return "23";
Peng Fanb741b162015-08-13 10:55:33 +0800160 case MXC_CPU_MX28:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200161 return "28";
Peng Fanb741b162015-08-13 10:55:33 +0800162 default:
Otavio Salvadorca36b532012-07-28 11:43:47 +0000163 return "??";
164 }
165}
166
Marek Vasutc140e982011-11-08 23:18:08 +0000167int print_cpuinfo(void)
168{
Peng Fanb741b162015-08-13 10:55:33 +0800169 u32 cpurev;
Mans Rullgard2f66b402018-04-21 16:11:09 +0100170 struct mxs_spl_data *data = MXS_SPL_DATA;
Marek Vasutb28fe462012-05-01 11:09:45 +0000171
Peng Fanb741b162015-08-13 10:55:33 +0800172 cpurev = get_cpu_rev();
173 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
174 get_imx_type((cpurev & 0xFF000) >> 12),
175 (cpurev & 0x000F0) >> 4,
176 (cpurev & 0x0000F) >> 0,
Otavio Salvadorca36b532012-07-28 11:43:47 +0000177 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000178 printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
Marek Vasutc140e982011-11-08 23:18:08 +0000179 return 0;
180}
181#endif
182
183int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
184{
185 printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
186 printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
187 printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
188 printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
189 return 0;
190}
191
192/*
193 * Initializes on-chip ethernet controllers.
194 */
Otavio Salvadord1de2e02012-08-19 04:58:29 +0000195#if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
Marek Vasutc140e982011-11-08 23:18:08 +0000196int cpu_eth_init(bd_t *bis)
197{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000198 struct mxs_clkctrl_regs *clkctrl_regs =
199 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasutc140e982011-11-08 23:18:08 +0000200
201 /* Turn on ENET clocks */
202 clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
203 CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
204
205 /* Set up ENET PLL for 50 MHz */
206 /* Power on ENET PLL */
207 writel(CLKCTRL_PLL2CTRL0_POWER,
208 &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
209
210 udelay(10);
211
212 /* Gate on ENET PLL */
213 writel(CLKCTRL_PLL2CTRL0_CLKGATE,
214 &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
215
216 /* Enable pad output */
217 setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
218
219 return 0;
220}
221#endif
222
Fabio Estevam570dcfd2013-01-08 05:21:45 +0000223__weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
Fabio Estevam4029c012011-12-20 06:42:29 +0000224{
225 mac[0] = 0x00;
226 mac[1] = 0x04; /* Use FSL vendor MAC address by default */
227
228 if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
229 mac[5] += 1;
230}
231
Fabio Estevam4029c012011-12-20 06:42:29 +0000232#ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
233
234#define MXS_OCOTP_MAX_TIMEOUT 1000000
235void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
236{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000237 struct mxs_ocotp_regs *ocotp_regs =
238 (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
Fabio Estevam4029c012011-12-20 06:42:29 +0000239 uint32_t data;
240
241 memset(mac, 0, 6);
242
243 writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
244
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000245 if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
Fabio Estevam4029c012011-12-20 06:42:29 +0000246 MXS_OCOTP_MAX_TIMEOUT)) {
247 printf("MXS FEC: Can't get MAC from OCOTP\n");
248 return;
249 }
250
251 data = readl(&ocotp_regs->hw_ocotp_cust0);
252
253 mac[2] = (data >> 24) & 0xff;
254 mac[3] = (data >> 16) & 0xff;
255 mac[4] = (data >> 8) & 0xff;
256 mac[5] = data & 0xff;
257 mx28_adjust_mac(dev_id, mac);
258}
259#else
260void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
261{
262 memset(mac, 0, 6);
263}
264#endif
265
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000266int mxs_dram_init(void)
Fabio Estevam93f3a892011-12-20 05:46:33 +0000267{
Mans Rullgard2f66b402018-04-21 16:11:09 +0100268 struct mxs_spl_data *data = MXS_SPL_DATA;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000269
Marek Vasut9136fe92012-05-01 11:09:44 +0000270 if (data->mem_dram_size == 0) {
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000271 printf("MXS:\n"
Marek Vasut9136fe92012-05-01 11:09:44 +0000272 "Error, the RAM size passed up from SPL is 0!\n");
Fabio Estevam93f3a892011-12-20 05:46:33 +0000273 hang();
274 }
275
Marek Vasut9136fe92012-05-01 11:09:44 +0000276 gd->ram_size = data->mem_dram_size;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000277 return 0;
278}
279
Marek Vasutc140e982011-11-08 23:18:08 +0000280U_BOOT_CMD(
281 clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
282 "display clocks",
283 ""
284);