blob: 8243aeb2c0f6904d4ec9179985bf506d6b74c3ec [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 Glassed38aef2020-05-10 11:40:03 -060013#include <command.h>
Simon Glassafb02152019-12-28 10:45:01 -070014#include <cpu_func.h>
Simon Glassf11478f2019-12-28 10:45:07 -070015#include <hang.h>
Simon Glass97589732020-05-10 11:40:02 -060016#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060017#include <net.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090019#include <linux/errno.h>
Marek Vasutc140e982011-11-08 23:18:08 +000020#include <asm/io.h>
21#include <asm/arch/clock.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020022#include <asm/mach-imx/dma.h>
Marek Vasutc140e982011-11-08 23:18:08 +000023#include <asm/arch/gpio.h>
Marek Vasut53fdab22011-11-08 23:18:13 +000024#include <asm/arch/iomux.h>
Marek Vasutc140e982011-11-08 23:18:08 +000025#include <asm/arch/imx-regs.h>
26#include <asm/arch/sys_proto.h>
Fabio Estevam570dcfd2013-01-08 05:21:45 +000027#include <linux/compiler.h>
Marek Vasutc140e982011-11-08 23:18:08 +000028
Marek Vasut5bf48fb2011-11-08 23:18:23 +000029DECLARE_GLOBAL_DATA_PTR;
30
Marek Vasutc140e982011-11-08 23:18:08 +000031/* Lowlevel init isn't used on i.MX28, so just have a dummy here */
Mans Rullgard04ef8652018-04-21 16:11:06 +010032__weak void lowlevel_init(void) {}
Marek Vasutc140e982011-11-08 23:18:08 +000033
34void reset_cpu(ulong ignored) __attribute__((noreturn));
35
36void reset_cpu(ulong ignored)
37{
Otavio Salvador22f4ff92012-08-05 09:05:31 +000038 struct mxs_rtc_regs *rtc_regs =
39 (struct mxs_rtc_regs *)MXS_RTC_BASE;
40 struct mxs_lcdif_regs *lcdif_regs =
41 (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
Marek Vasut9c53b7e2012-05-01 11:09:47 +000042
43 /*
44 * Shut down the LCD controller as it interferes with BootROM boot mode
45 * pads sampling.
46 */
47 writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr);
Marek Vasutc140e982011-11-08 23:18:08 +000048
49 /* Wait 1 uS before doing the actual watchdog reset */
50 writel(1, &rtc_regs->hw_rtc_watchdog);
51 writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
52
53 /* Endless loop, reset will exit from here */
54 for (;;)
55 ;
56}
57
Marek Vasut39c31032013-04-25 16:37:12 +000058/*
59 * This function will craft a jumptable at 0x0 which will redirect interrupt
60 * vectoring to proper location of U-Boot in RAM.
61 *
62 * The structure of the jumptable will be as follows:
63 * ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times
64 * <destination address> ... for each previous ldr, thus also repeated 8 times
65 *
66 * The "ldr pc, [pc, #0x18]" instruction above loads address from memory at
67 * offset 0x18 from current value of PC register. Note that PC is already
68 * incremented by 4 when computing the offset, so the effective offset is
69 * actually 0x20, this the associated <destination address>. Loading the PC
70 * register with an address performs a jump to that address.
71 */
Marek Vasut5bf48fb2011-11-08 23:18:23 +000072void mx28_fixup_vt(uint32_t start_addr)
73{
Marek Vasut39c31032013-04-25 16:37:12 +000074 /* ldr pc, [pc, #0x18] */
75 const uint32_t ldr_pc = 0xe59ff018;
76 /* Jumptable location is 0x0 */
77 uint32_t *vt = (uint32_t *)0x0;
Marek Vasut5bf48fb2011-11-08 23:18:23 +000078 int i;
79
Marek Vasut39c31032013-04-25 16:37:12 +000080 for (i = 0; i < 8; i++) {
Wolfgang Denk6ae80832014-11-06 14:02:57 +010081 /* cppcheck-suppress nullPointer */
Marek Vasut39c31032013-04-25 16:37:12 +000082 vt[i] = ldr_pc;
Wolfgang Denk6ae80832014-11-06 14:02:57 +010083 /* cppcheck-suppress nullPointer */
Marek Vasut39c31032013-04-25 16:37:12 +000084 vt[i + 8] = start_addr + (4 * i);
85 }
Marek Vasut5bf48fb2011-11-08 23:18:23 +000086}
87
88#ifdef CONFIG_ARCH_MISC_INIT
89int arch_misc_init(void)
90{
91 mx28_fixup_vt(gd->relocaddr);
Marek Vasutc140e982011-11-08 23:18:08 +000092 return 0;
93}
Marek Vasut5bf48fb2011-11-08 23:18:23 +000094#endif
Marek Vasutc140e982011-11-08 23:18:08 +000095
Marek Vasutc140e982011-11-08 23:18:08 +000096int arch_cpu_init(void)
97{
Otavio Salvador22f4ff92012-08-05 09:05:31 +000098 struct mxs_clkctrl_regs *clkctrl_regs =
99 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasut5bf48fb2011-11-08 23:18:23 +0000100 extern uint32_t _start;
101
102 mx28_fixup_vt((uint32_t)&_start);
Marek Vasutc140e982011-11-08 23:18:08 +0000103
104 /*
105 * Enable NAND clock
106 */
Rasmus Villemoes6cb658c2019-09-12 09:17:10 +0000107 /* Set bypass bit */
Marek Vasutc140e982011-11-08 23:18:08 +0000108 writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
109 &clkctrl_regs->hw_clkctrl_clkseq_set);
110
Rasmus Villemoes6cb658c2019-09-12 09:17:10 +0000111 /* Set GPMI clock to ref_xtal / 1 */
Rasmus Villemoes5a84b032019-09-12 09:17:11 +0000112 clrbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, CLKCTRL_GPMI_CLKGATE);
113 while (readl(&clkctrl_regs->hw_clkctrl_gpmi) & CLKCTRL_GPMI_CLKGATE)
114 ;
Marek Vasutc140e982011-11-08 23:18:08 +0000115 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
Rasmus Villemoes5a84b032019-09-12 09:17:11 +0000116 CLKCTRL_GPMI_DIV_MASK, 1);
Marek Vasutc140e982011-11-08 23:18:08 +0000117
118 udelay(1000);
119
Marek Vasut53fdab22011-11-08 23:18:13 +0000120 /*
121 * Configure GPIO unit
122 */
123 mxs_gpio_init();
124
Marek Vasut93541b42012-04-08 17:34:46 +0000125#ifdef CONFIG_APBH_DMA
126 /* Start APBH DMA */
127 mxs_dma_init();
128#endif
129
Marek Vasutc140e982011-11-08 23:18:08 +0000130 return 0;
131}
Marek Vasutc140e982011-11-08 23:18:08 +0000132
Peng Fanb741b162015-08-13 10:55:33 +0800133u32 get_cpu_rev(void)
Otavio Salvadorca36b532012-07-28 11:43:47 +0000134{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000135 struct mxs_digctl_regs *digctl_regs =
136 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000137 uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;
138
139 switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000140 case HW_DIGCTL_CHIPID_MX23:
141 switch (rev) {
142 case 0x0:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000143 case 0x1:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000144 case 0x2:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000145 case 0x3:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000146 case 0x4:
Peng Fanb741b162015-08-13 10:55:33 +0800147 return (MXC_CPU_MX23 << 12) | (rev + 0x10);
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000148 default:
Peng Fanb741b162015-08-13 10:55:33 +0800149 return 0;
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000150 }
Otavio Salvadorca36b532012-07-28 11:43:47 +0000151 case HW_DIGCTL_CHIPID_MX28:
152 switch (rev) {
153 case 0x1:
Peng Fanb741b162015-08-13 10:55:33 +0800154 return (MXC_CPU_MX28 << 12) | 0x12;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000155 default:
Peng Fanb741b162015-08-13 10:55:33 +0800156 return 0;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000157 }
158 default:
Peng Fanb741b162015-08-13 10:55:33 +0800159 return 0;
160 }
161}
162
163#if defined(CONFIG_DISPLAY_CPUINFO)
164const char *get_imx_type(u32 imxtype)
165{
166 switch (imxtype) {
167 case MXC_CPU_MX23:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200168 return "23";
Peng Fanb741b162015-08-13 10:55:33 +0800169 case MXC_CPU_MX28:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200170 return "28";
Peng Fanb741b162015-08-13 10:55:33 +0800171 default:
Otavio Salvadorca36b532012-07-28 11:43:47 +0000172 return "??";
173 }
174}
175
Marek Vasutc140e982011-11-08 23:18:08 +0000176int print_cpuinfo(void)
177{
Peng Fanb741b162015-08-13 10:55:33 +0800178 u32 cpurev;
Mans Rullgard2f66b402018-04-21 16:11:09 +0100179 struct mxs_spl_data *data = MXS_SPL_DATA;
Marek Vasutb28fe462012-05-01 11:09:45 +0000180
Peng Fanb741b162015-08-13 10:55:33 +0800181 cpurev = get_cpu_rev();
182 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
183 get_imx_type((cpurev & 0xFF000) >> 12),
184 (cpurev & 0x000F0) >> 4,
185 (cpurev & 0x0000F) >> 0,
Otavio Salvadorca36b532012-07-28 11:43:47 +0000186 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000187 printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
Marek Vasutc140e982011-11-08 23:18:08 +0000188 return 0;
189}
190#endif
191
Simon Glassed38aef2020-05-10 11:40:03 -0600192int do_mx28_showclocks(struct cmd_tbl *cmdtp, int flag, int argc,
193 char *const argv[])
Marek Vasutc140e982011-11-08 23:18:08 +0000194{
195 printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
196 printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
197 printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
198 printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
199 return 0;
200}
201
202/*
203 * Initializes on-chip ethernet controllers.
204 */
Otavio Salvadord1de2e02012-08-19 04:58:29 +0000205#if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900206int cpu_eth_init(struct bd_info *bis)
Marek Vasutc140e982011-11-08 23:18:08 +0000207{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000208 struct mxs_clkctrl_regs *clkctrl_regs =
209 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasutc140e982011-11-08 23:18:08 +0000210
211 /* Turn on ENET clocks */
212 clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
213 CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
214
215 /* Set up ENET PLL for 50 MHz */
216 /* Power on ENET PLL */
217 writel(CLKCTRL_PLL2CTRL0_POWER,
218 &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
219
220 udelay(10);
221
222 /* Gate on ENET PLL */
223 writel(CLKCTRL_PLL2CTRL0_CLKGATE,
224 &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
225
226 /* Enable pad output */
227 setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
228
229 return 0;
230}
231#endif
232
Fabio Estevam570dcfd2013-01-08 05:21:45 +0000233__weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
Fabio Estevam4029c012011-12-20 06:42:29 +0000234{
235 mac[0] = 0x00;
236 mac[1] = 0x04; /* Use FSL vendor MAC address by default */
237
238 if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
239 mac[5] += 1;
240}
241
Fabio Estevam4029c012011-12-20 06:42:29 +0000242#ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
243
244#define MXS_OCOTP_MAX_TIMEOUT 1000000
245void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
246{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000247 struct mxs_ocotp_regs *ocotp_regs =
248 (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
Fabio Estevam4029c012011-12-20 06:42:29 +0000249 uint32_t data;
250
251 memset(mac, 0, 6);
252
253 writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
254
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000255 if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
Fabio Estevam4029c012011-12-20 06:42:29 +0000256 MXS_OCOTP_MAX_TIMEOUT)) {
257 printf("MXS FEC: Can't get MAC from OCOTP\n");
258 return;
259 }
260
261 data = readl(&ocotp_regs->hw_ocotp_cust0);
262
263 mac[2] = (data >> 24) & 0xff;
264 mac[3] = (data >> 16) & 0xff;
265 mac[4] = (data >> 8) & 0xff;
266 mac[5] = data & 0xff;
267 mx28_adjust_mac(dev_id, mac);
268}
269#else
270void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
271{
272 memset(mac, 0, 6);
273}
274#endif
275
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000276int mxs_dram_init(void)
Fabio Estevam93f3a892011-12-20 05:46:33 +0000277{
Mans Rullgard2f66b402018-04-21 16:11:09 +0100278 struct mxs_spl_data *data = MXS_SPL_DATA;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000279
Marek Vasut9136fe92012-05-01 11:09:44 +0000280 if (data->mem_dram_size == 0) {
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000281 printf("MXS:\n"
Marek Vasut9136fe92012-05-01 11:09:44 +0000282 "Error, the RAM size passed up from SPL is 0!\n");
Fabio Estevam93f3a892011-12-20 05:46:33 +0000283 hang();
284 }
285
Marek Vasut9136fe92012-05-01 11:09:44 +0000286 gd->ram_size = data->mem_dram_size;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000287 return 0;
288}
289
Marek Vasutc140e982011-11-08 23:18:08 +0000290U_BOOT_CMD(
291 clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
292 "display clocks",
293 ""
294);