blob: f44205c3a8c2d44d592d5cf5776d503bf64febcb [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>
Simon Glassafb02152019-12-28 10:45:01 -070013#include <cpu_func.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090014#include <linux/errno.h>
Marek Vasutc140e982011-11-08 23:18:08 +000015#include <asm/io.h>
16#include <asm/arch/clock.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020017#include <asm/mach-imx/dma.h>
Marek Vasutc140e982011-11-08 23:18:08 +000018#include <asm/arch/gpio.h>
Marek Vasut53fdab22011-11-08 23:18:13 +000019#include <asm/arch/iomux.h>
Marek Vasutc140e982011-11-08 23:18:08 +000020#include <asm/arch/imx-regs.h>
21#include <asm/arch/sys_proto.h>
Fabio Estevam570dcfd2013-01-08 05:21:45 +000022#include <linux/compiler.h>
Marek Vasutc140e982011-11-08 23:18:08 +000023
Marek Vasut5bf48fb2011-11-08 23:18:23 +000024DECLARE_GLOBAL_DATA_PTR;
25
Marek Vasutc140e982011-11-08 23:18:08 +000026/* Lowlevel init isn't used on i.MX28, so just have a dummy here */
Mans Rullgard04ef8652018-04-21 16:11:06 +010027__weak void lowlevel_init(void) {}
Marek Vasutc140e982011-11-08 23:18:08 +000028
29void reset_cpu(ulong ignored) __attribute__((noreturn));
30
31void reset_cpu(ulong ignored)
32{
Otavio Salvador22f4ff92012-08-05 09:05:31 +000033 struct mxs_rtc_regs *rtc_regs =
34 (struct mxs_rtc_regs *)MXS_RTC_BASE;
35 struct mxs_lcdif_regs *lcdif_regs =
36 (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
Marek Vasut9c53b7e2012-05-01 11:09:47 +000037
38 /*
39 * Shut down the LCD controller as it interferes with BootROM boot mode
40 * pads sampling.
41 */
42 writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr);
Marek Vasutc140e982011-11-08 23:18:08 +000043
44 /* Wait 1 uS before doing the actual watchdog reset */
45 writel(1, &rtc_regs->hw_rtc_watchdog);
46 writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
47
48 /* Endless loop, reset will exit from here */
49 for (;;)
50 ;
51}
52
Marek Vasut39c31032013-04-25 16:37:12 +000053/*
54 * This function will craft a jumptable at 0x0 which will redirect interrupt
55 * vectoring to proper location of U-Boot in RAM.
56 *
57 * The structure of the jumptable will be as follows:
58 * ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times
59 * <destination address> ... for each previous ldr, thus also repeated 8 times
60 *
61 * The "ldr pc, [pc, #0x18]" instruction above loads address from memory at
62 * offset 0x18 from current value of PC register. Note that PC is already
63 * incremented by 4 when computing the offset, so the effective offset is
64 * actually 0x20, this the associated <destination address>. Loading the PC
65 * register with an address performs a jump to that address.
66 */
Marek Vasut5bf48fb2011-11-08 23:18:23 +000067void mx28_fixup_vt(uint32_t start_addr)
68{
Marek Vasut39c31032013-04-25 16:37:12 +000069 /* ldr pc, [pc, #0x18] */
70 const uint32_t ldr_pc = 0xe59ff018;
71 /* Jumptable location is 0x0 */
72 uint32_t *vt = (uint32_t *)0x0;
Marek Vasut5bf48fb2011-11-08 23:18:23 +000073 int i;
74
Marek Vasut39c31032013-04-25 16:37:12 +000075 for (i = 0; i < 8; i++) {
Wolfgang Denk6ae80832014-11-06 14:02:57 +010076 /* cppcheck-suppress nullPointer */
Marek Vasut39c31032013-04-25 16:37:12 +000077 vt[i] = ldr_pc;
Wolfgang Denk6ae80832014-11-06 14:02:57 +010078 /* cppcheck-suppress nullPointer */
Marek Vasut39c31032013-04-25 16:37:12 +000079 vt[i + 8] = start_addr + (4 * i);
80 }
Marek Vasut5bf48fb2011-11-08 23:18:23 +000081}
82
83#ifdef CONFIG_ARCH_MISC_INIT
84int arch_misc_init(void)
85{
86 mx28_fixup_vt(gd->relocaddr);
Marek Vasutc140e982011-11-08 23:18:08 +000087 return 0;
88}
Marek Vasut5bf48fb2011-11-08 23:18:23 +000089#endif
Marek Vasutc140e982011-11-08 23:18:08 +000090
Marek Vasutc140e982011-11-08 23:18:08 +000091int arch_cpu_init(void)
92{
Otavio Salvador22f4ff92012-08-05 09:05:31 +000093 struct mxs_clkctrl_regs *clkctrl_regs =
94 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasut5bf48fb2011-11-08 23:18:23 +000095 extern uint32_t _start;
96
97 mx28_fixup_vt((uint32_t)&_start);
Marek Vasutc140e982011-11-08 23:18:08 +000098
99 /*
100 * Enable NAND clock
101 */
Rasmus Villemoes6cb658c2019-09-12 09:17:10 +0000102 /* Set bypass bit */
Marek Vasutc140e982011-11-08 23:18:08 +0000103 writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
104 &clkctrl_regs->hw_clkctrl_clkseq_set);
105
Rasmus Villemoes6cb658c2019-09-12 09:17:10 +0000106 /* Set GPMI clock to ref_xtal / 1 */
Rasmus Villemoes5a84b032019-09-12 09:17:11 +0000107 clrbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, CLKCTRL_GPMI_CLKGATE);
108 while (readl(&clkctrl_regs->hw_clkctrl_gpmi) & CLKCTRL_GPMI_CLKGATE)
109 ;
Marek Vasutc140e982011-11-08 23:18:08 +0000110 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
Rasmus Villemoes5a84b032019-09-12 09:17:11 +0000111 CLKCTRL_GPMI_DIV_MASK, 1);
Marek Vasutc140e982011-11-08 23:18:08 +0000112
113 udelay(1000);
114
Marek Vasut53fdab22011-11-08 23:18:13 +0000115 /*
116 * Configure GPIO unit
117 */
118 mxs_gpio_init();
119
Marek Vasut93541b42012-04-08 17:34:46 +0000120#ifdef CONFIG_APBH_DMA
121 /* Start APBH DMA */
122 mxs_dma_init();
123#endif
124
Marek Vasutc140e982011-11-08 23:18:08 +0000125 return 0;
126}
Marek Vasutc140e982011-11-08 23:18:08 +0000127
Peng Fanb741b162015-08-13 10:55:33 +0800128u32 get_cpu_rev(void)
Otavio Salvadorca36b532012-07-28 11:43:47 +0000129{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000130 struct mxs_digctl_regs *digctl_regs =
131 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000132 uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;
133
134 switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000135 case HW_DIGCTL_CHIPID_MX23:
136 switch (rev) {
137 case 0x0:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000138 case 0x1:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000139 case 0x2:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000140 case 0x3:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000141 case 0x4:
Peng Fanb741b162015-08-13 10:55:33 +0800142 return (MXC_CPU_MX23 << 12) | (rev + 0x10);
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000143 default:
Peng Fanb741b162015-08-13 10:55:33 +0800144 return 0;
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000145 }
Otavio Salvadorca36b532012-07-28 11:43:47 +0000146 case HW_DIGCTL_CHIPID_MX28:
147 switch (rev) {
148 case 0x1:
Peng Fanb741b162015-08-13 10:55:33 +0800149 return (MXC_CPU_MX28 << 12) | 0x12;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000150 default:
Peng Fanb741b162015-08-13 10:55:33 +0800151 return 0;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000152 }
153 default:
Peng Fanb741b162015-08-13 10:55:33 +0800154 return 0;
155 }
156}
157
158#if defined(CONFIG_DISPLAY_CPUINFO)
159const char *get_imx_type(u32 imxtype)
160{
161 switch (imxtype) {
162 case MXC_CPU_MX23:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200163 return "23";
Peng Fanb741b162015-08-13 10:55:33 +0800164 case MXC_CPU_MX28:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200165 return "28";
Peng Fanb741b162015-08-13 10:55:33 +0800166 default:
Otavio Salvadorca36b532012-07-28 11:43:47 +0000167 return "??";
168 }
169}
170
Marek Vasutc140e982011-11-08 23:18:08 +0000171int print_cpuinfo(void)
172{
Peng Fanb741b162015-08-13 10:55:33 +0800173 u32 cpurev;
Mans Rullgard2f66b402018-04-21 16:11:09 +0100174 struct mxs_spl_data *data = MXS_SPL_DATA;
Marek Vasutb28fe462012-05-01 11:09:45 +0000175
Peng Fanb741b162015-08-13 10:55:33 +0800176 cpurev = get_cpu_rev();
177 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
178 get_imx_type((cpurev & 0xFF000) >> 12),
179 (cpurev & 0x000F0) >> 4,
180 (cpurev & 0x0000F) >> 0,
Otavio Salvadorca36b532012-07-28 11:43:47 +0000181 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000182 printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
Marek Vasutc140e982011-11-08 23:18:08 +0000183 return 0;
184}
185#endif
186
187int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
188{
189 printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
190 printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
191 printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
192 printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
193 return 0;
194}
195
196/*
197 * Initializes on-chip ethernet controllers.
198 */
Otavio Salvadord1de2e02012-08-19 04:58:29 +0000199#if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
Marek Vasutc140e982011-11-08 23:18:08 +0000200int cpu_eth_init(bd_t *bis)
201{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000202 struct mxs_clkctrl_regs *clkctrl_regs =
203 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasutc140e982011-11-08 23:18:08 +0000204
205 /* Turn on ENET clocks */
206 clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
207 CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
208
209 /* Set up ENET PLL for 50 MHz */
210 /* Power on ENET PLL */
211 writel(CLKCTRL_PLL2CTRL0_POWER,
212 &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
213
214 udelay(10);
215
216 /* Gate on ENET PLL */
217 writel(CLKCTRL_PLL2CTRL0_CLKGATE,
218 &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
219
220 /* Enable pad output */
221 setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
222
223 return 0;
224}
225#endif
226
Fabio Estevam570dcfd2013-01-08 05:21:45 +0000227__weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
Fabio Estevam4029c012011-12-20 06:42:29 +0000228{
229 mac[0] = 0x00;
230 mac[1] = 0x04; /* Use FSL vendor MAC address by default */
231
232 if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
233 mac[5] += 1;
234}
235
Fabio Estevam4029c012011-12-20 06:42:29 +0000236#ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
237
238#define MXS_OCOTP_MAX_TIMEOUT 1000000
239void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
240{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000241 struct mxs_ocotp_regs *ocotp_regs =
242 (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
Fabio Estevam4029c012011-12-20 06:42:29 +0000243 uint32_t data;
244
245 memset(mac, 0, 6);
246
247 writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
248
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000249 if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
Fabio Estevam4029c012011-12-20 06:42:29 +0000250 MXS_OCOTP_MAX_TIMEOUT)) {
251 printf("MXS FEC: Can't get MAC from OCOTP\n");
252 return;
253 }
254
255 data = readl(&ocotp_regs->hw_ocotp_cust0);
256
257 mac[2] = (data >> 24) & 0xff;
258 mac[3] = (data >> 16) & 0xff;
259 mac[4] = (data >> 8) & 0xff;
260 mac[5] = data & 0xff;
261 mx28_adjust_mac(dev_id, mac);
262}
263#else
264void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
265{
266 memset(mac, 0, 6);
267}
268#endif
269
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000270int mxs_dram_init(void)
Fabio Estevam93f3a892011-12-20 05:46:33 +0000271{
Mans Rullgard2f66b402018-04-21 16:11:09 +0100272 struct mxs_spl_data *data = MXS_SPL_DATA;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000273
Marek Vasut9136fe92012-05-01 11:09:44 +0000274 if (data->mem_dram_size == 0) {
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000275 printf("MXS:\n"
Marek Vasut9136fe92012-05-01 11:09:44 +0000276 "Error, the RAM size passed up from SPL is 0!\n");
Fabio Estevam93f3a892011-12-20 05:46:33 +0000277 hang();
278 }
279
Marek Vasut9136fe92012-05-01 11:09:44 +0000280 gd->ram_size = data->mem_dram_size;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000281 return 0;
282}
283
Marek Vasutc140e982011-11-08 23:18:08 +0000284U_BOOT_CMD(
285 clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
286 "display clocks",
287 ""
288);