blob: 16c080a1e159c7c34003254e85f44c125cad01d5 [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>
Simon Glassf11478f2019-12-28 10:45:07 -070014#include <hang.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090015#include <linux/errno.h>
Marek Vasutc140e982011-11-08 23:18:08 +000016#include <asm/io.h>
17#include <asm/arch/clock.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/dma.h>
Marek Vasutc140e982011-11-08 23:18:08 +000019#include <asm/arch/gpio.h>
Marek Vasut53fdab22011-11-08 23:18:13 +000020#include <asm/arch/iomux.h>
Marek Vasutc140e982011-11-08 23:18:08 +000021#include <asm/arch/imx-regs.h>
22#include <asm/arch/sys_proto.h>
Fabio Estevam570dcfd2013-01-08 05:21:45 +000023#include <linux/compiler.h>
Marek Vasutc140e982011-11-08 23:18:08 +000024
Marek Vasut5bf48fb2011-11-08 23:18:23 +000025DECLARE_GLOBAL_DATA_PTR;
26
Marek Vasutc140e982011-11-08 23:18:08 +000027/* Lowlevel init isn't used on i.MX28, so just have a dummy here */
Mans Rullgard04ef8652018-04-21 16:11:06 +010028__weak void lowlevel_init(void) {}
Marek Vasutc140e982011-11-08 23:18:08 +000029
30void reset_cpu(ulong ignored) __attribute__((noreturn));
31
32void reset_cpu(ulong ignored)
33{
Otavio Salvador22f4ff92012-08-05 09:05:31 +000034 struct mxs_rtc_regs *rtc_regs =
35 (struct mxs_rtc_regs *)MXS_RTC_BASE;
36 struct mxs_lcdif_regs *lcdif_regs =
37 (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
Marek Vasut9c53b7e2012-05-01 11:09:47 +000038
39 /*
40 * Shut down the LCD controller as it interferes with BootROM boot mode
41 * pads sampling.
42 */
43 writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr);
Marek Vasutc140e982011-11-08 23:18:08 +000044
45 /* Wait 1 uS before doing the actual watchdog reset */
46 writel(1, &rtc_regs->hw_rtc_watchdog);
47 writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
48
49 /* Endless loop, reset will exit from here */
50 for (;;)
51 ;
52}
53
Marek Vasut39c31032013-04-25 16:37:12 +000054/*
55 * This function will craft a jumptable at 0x0 which will redirect interrupt
56 * vectoring to proper location of U-Boot in RAM.
57 *
58 * The structure of the jumptable will be as follows:
59 * ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times
60 * <destination address> ... for each previous ldr, thus also repeated 8 times
61 *
62 * The "ldr pc, [pc, #0x18]" instruction above loads address from memory at
63 * offset 0x18 from current value of PC register. Note that PC is already
64 * incremented by 4 when computing the offset, so the effective offset is
65 * actually 0x20, this the associated <destination address>. Loading the PC
66 * register with an address performs a jump to that address.
67 */
Marek Vasut5bf48fb2011-11-08 23:18:23 +000068void mx28_fixup_vt(uint32_t start_addr)
69{
Marek Vasut39c31032013-04-25 16:37:12 +000070 /* ldr pc, [pc, #0x18] */
71 const uint32_t ldr_pc = 0xe59ff018;
72 /* Jumptable location is 0x0 */
73 uint32_t *vt = (uint32_t *)0x0;
Marek Vasut5bf48fb2011-11-08 23:18:23 +000074 int i;
75
Marek Vasut39c31032013-04-25 16:37:12 +000076 for (i = 0; i < 8; i++) {
Wolfgang Denk6ae80832014-11-06 14:02:57 +010077 /* cppcheck-suppress nullPointer */
Marek Vasut39c31032013-04-25 16:37:12 +000078 vt[i] = ldr_pc;
Wolfgang Denk6ae80832014-11-06 14:02:57 +010079 /* cppcheck-suppress nullPointer */
Marek Vasut39c31032013-04-25 16:37:12 +000080 vt[i + 8] = start_addr + (4 * i);
81 }
Marek Vasut5bf48fb2011-11-08 23:18:23 +000082}
83
84#ifdef CONFIG_ARCH_MISC_INIT
85int arch_misc_init(void)
86{
87 mx28_fixup_vt(gd->relocaddr);
Marek Vasutc140e982011-11-08 23:18:08 +000088 return 0;
89}
Marek Vasut5bf48fb2011-11-08 23:18:23 +000090#endif
Marek Vasutc140e982011-11-08 23:18:08 +000091
Marek Vasutc140e982011-11-08 23:18:08 +000092int arch_cpu_init(void)
93{
Otavio Salvador22f4ff92012-08-05 09:05:31 +000094 struct mxs_clkctrl_regs *clkctrl_regs =
95 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasut5bf48fb2011-11-08 23:18:23 +000096 extern uint32_t _start;
97
98 mx28_fixup_vt((uint32_t)&_start);
Marek Vasutc140e982011-11-08 23:18:08 +000099
100 /*
101 * Enable NAND clock
102 */
Rasmus Villemoes6cb658c2019-09-12 09:17:10 +0000103 /* Set bypass bit */
Marek Vasutc140e982011-11-08 23:18:08 +0000104 writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
105 &clkctrl_regs->hw_clkctrl_clkseq_set);
106
Rasmus Villemoes6cb658c2019-09-12 09:17:10 +0000107 /* Set GPMI clock to ref_xtal / 1 */
Rasmus Villemoes5a84b032019-09-12 09:17:11 +0000108 clrbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, CLKCTRL_GPMI_CLKGATE);
109 while (readl(&clkctrl_regs->hw_clkctrl_gpmi) & CLKCTRL_GPMI_CLKGATE)
110 ;
Marek Vasutc140e982011-11-08 23:18:08 +0000111 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
Rasmus Villemoes5a84b032019-09-12 09:17:11 +0000112 CLKCTRL_GPMI_DIV_MASK, 1);
Marek Vasutc140e982011-11-08 23:18:08 +0000113
114 udelay(1000);
115
Marek Vasut53fdab22011-11-08 23:18:13 +0000116 /*
117 * Configure GPIO unit
118 */
119 mxs_gpio_init();
120
Marek Vasut93541b42012-04-08 17:34:46 +0000121#ifdef CONFIG_APBH_DMA
122 /* Start APBH DMA */
123 mxs_dma_init();
124#endif
125
Marek Vasutc140e982011-11-08 23:18:08 +0000126 return 0;
127}
Marek Vasutc140e982011-11-08 23:18:08 +0000128
Peng Fanb741b162015-08-13 10:55:33 +0800129u32 get_cpu_rev(void)
Otavio Salvadorca36b532012-07-28 11:43:47 +0000130{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000131 struct mxs_digctl_regs *digctl_regs =
132 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000133 uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;
134
135 switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000136 case HW_DIGCTL_CHIPID_MX23:
137 switch (rev) {
138 case 0x0:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000139 case 0x1:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000140 case 0x2:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000141 case 0x3:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000142 case 0x4:
Peng Fanb741b162015-08-13 10:55:33 +0800143 return (MXC_CPU_MX23 << 12) | (rev + 0x10);
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000144 default:
Peng Fanb741b162015-08-13 10:55:33 +0800145 return 0;
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000146 }
Otavio Salvadorca36b532012-07-28 11:43:47 +0000147 case HW_DIGCTL_CHIPID_MX28:
148 switch (rev) {
149 case 0x1:
Peng Fanb741b162015-08-13 10:55:33 +0800150 return (MXC_CPU_MX28 << 12) | 0x12;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000151 default:
Peng Fanb741b162015-08-13 10:55:33 +0800152 return 0;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000153 }
154 default:
Peng Fanb741b162015-08-13 10:55:33 +0800155 return 0;
156 }
157}
158
159#if defined(CONFIG_DISPLAY_CPUINFO)
160const char *get_imx_type(u32 imxtype)
161{
162 switch (imxtype) {
163 case MXC_CPU_MX23:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200164 return "23";
Peng Fanb741b162015-08-13 10:55:33 +0800165 case MXC_CPU_MX28:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200166 return "28";
Peng Fanb741b162015-08-13 10:55:33 +0800167 default:
Otavio Salvadorca36b532012-07-28 11:43:47 +0000168 return "??";
169 }
170}
171
Marek Vasutc140e982011-11-08 23:18:08 +0000172int print_cpuinfo(void)
173{
Peng Fanb741b162015-08-13 10:55:33 +0800174 u32 cpurev;
Mans Rullgard2f66b402018-04-21 16:11:09 +0100175 struct mxs_spl_data *data = MXS_SPL_DATA;
Marek Vasutb28fe462012-05-01 11:09:45 +0000176
Peng Fanb741b162015-08-13 10:55:33 +0800177 cpurev = get_cpu_rev();
178 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
179 get_imx_type((cpurev & 0xFF000) >> 12),
180 (cpurev & 0x000F0) >> 4,
181 (cpurev & 0x0000F) >> 0,
Otavio Salvadorca36b532012-07-28 11:43:47 +0000182 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000183 printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
Marek Vasutc140e982011-11-08 23:18:08 +0000184 return 0;
185}
186#endif
187
188int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
189{
190 printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
191 printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
192 printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
193 printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
194 return 0;
195}
196
197/*
198 * Initializes on-chip ethernet controllers.
199 */
Otavio Salvadord1de2e02012-08-19 04:58:29 +0000200#if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
Marek Vasutc140e982011-11-08 23:18:08 +0000201int cpu_eth_init(bd_t *bis)
202{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000203 struct mxs_clkctrl_regs *clkctrl_regs =
204 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasutc140e982011-11-08 23:18:08 +0000205
206 /* Turn on ENET clocks */
207 clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
208 CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
209
210 /* Set up ENET PLL for 50 MHz */
211 /* Power on ENET PLL */
212 writel(CLKCTRL_PLL2CTRL0_POWER,
213 &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
214
215 udelay(10);
216
217 /* Gate on ENET PLL */
218 writel(CLKCTRL_PLL2CTRL0_CLKGATE,
219 &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
220
221 /* Enable pad output */
222 setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
223
224 return 0;
225}
226#endif
227
Fabio Estevam570dcfd2013-01-08 05:21:45 +0000228__weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
Fabio Estevam4029c012011-12-20 06:42:29 +0000229{
230 mac[0] = 0x00;
231 mac[1] = 0x04; /* Use FSL vendor MAC address by default */
232
233 if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
234 mac[5] += 1;
235}
236
Fabio Estevam4029c012011-12-20 06:42:29 +0000237#ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
238
239#define MXS_OCOTP_MAX_TIMEOUT 1000000
240void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
241{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000242 struct mxs_ocotp_regs *ocotp_regs =
243 (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
Fabio Estevam4029c012011-12-20 06:42:29 +0000244 uint32_t data;
245
246 memset(mac, 0, 6);
247
248 writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
249
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000250 if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
Fabio Estevam4029c012011-12-20 06:42:29 +0000251 MXS_OCOTP_MAX_TIMEOUT)) {
252 printf("MXS FEC: Can't get MAC from OCOTP\n");
253 return;
254 }
255
256 data = readl(&ocotp_regs->hw_ocotp_cust0);
257
258 mac[2] = (data >> 24) & 0xff;
259 mac[3] = (data >> 16) & 0xff;
260 mac[4] = (data >> 8) & 0xff;
261 mac[5] = data & 0xff;
262 mx28_adjust_mac(dev_id, mac);
263}
264#else
265void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
266{
267 memset(mac, 0, 6);
268}
269#endif
270
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000271int mxs_dram_init(void)
Fabio Estevam93f3a892011-12-20 05:46:33 +0000272{
Mans Rullgard2f66b402018-04-21 16:11:09 +0100273 struct mxs_spl_data *data = MXS_SPL_DATA;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000274
Marek Vasut9136fe92012-05-01 11:09:44 +0000275 if (data->mem_dram_size == 0) {
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000276 printf("MXS:\n"
Marek Vasut9136fe92012-05-01 11:09:44 +0000277 "Error, the RAM size passed up from SPL is 0!\n");
Fabio Estevam93f3a892011-12-20 05:46:33 +0000278 hang();
279 }
280
Marek Vasut9136fe92012-05-01 11:09:44 +0000281 gd->ram_size = data->mem_dram_size;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000282 return 0;
283}
284
Marek Vasutc140e982011-11-08 23:18:08 +0000285U_BOOT_CMD(
286 clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
287 "display clocks",
288 ""
289);