blob: 183aa40b6d1d30daa05b3e109ba800728ea422e4 [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 */
Rasmus Villemoes5a84b032019-09-12 09:17:11 +0000106 clrbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, CLKCTRL_GPMI_CLKGATE);
107 while (readl(&clkctrl_regs->hw_clkctrl_gpmi) & CLKCTRL_GPMI_CLKGATE)
108 ;
Marek Vasutc140e982011-11-08 23:18:08 +0000109 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
Rasmus Villemoes5a84b032019-09-12 09:17:11 +0000110 CLKCTRL_GPMI_DIV_MASK, 1);
Marek Vasutc140e982011-11-08 23:18:08 +0000111
112 udelay(1000);
113
Marek Vasut53fdab22011-11-08 23:18:13 +0000114 /*
115 * Configure GPIO unit
116 */
117 mxs_gpio_init();
118
Marek Vasut93541b42012-04-08 17:34:46 +0000119#ifdef CONFIG_APBH_DMA
120 /* Start APBH DMA */
121 mxs_dma_init();
122#endif
123
Marek Vasutc140e982011-11-08 23:18:08 +0000124 return 0;
125}
Marek Vasutc140e982011-11-08 23:18:08 +0000126
Peng Fanb741b162015-08-13 10:55:33 +0800127u32 get_cpu_rev(void)
Otavio Salvadorca36b532012-07-28 11:43:47 +0000128{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000129 struct mxs_digctl_regs *digctl_regs =
130 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000131 uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;
132
133 switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000134 case HW_DIGCTL_CHIPID_MX23:
135 switch (rev) {
136 case 0x0:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000137 case 0x1:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000138 case 0x2:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000139 case 0x3:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000140 case 0x4:
Peng Fanb741b162015-08-13 10:55:33 +0800141 return (MXC_CPU_MX23 << 12) | (rev + 0x10);
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000142 default:
Peng Fanb741b162015-08-13 10:55:33 +0800143 return 0;
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000144 }
Otavio Salvadorca36b532012-07-28 11:43:47 +0000145 case HW_DIGCTL_CHIPID_MX28:
146 switch (rev) {
147 case 0x1:
Peng Fanb741b162015-08-13 10:55:33 +0800148 return (MXC_CPU_MX28 << 12) | 0x12;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000149 default:
Peng Fanb741b162015-08-13 10:55:33 +0800150 return 0;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000151 }
152 default:
Peng Fanb741b162015-08-13 10:55:33 +0800153 return 0;
154 }
155}
156
157#if defined(CONFIG_DISPLAY_CPUINFO)
158const char *get_imx_type(u32 imxtype)
159{
160 switch (imxtype) {
161 case MXC_CPU_MX23:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200162 return "23";
Peng Fanb741b162015-08-13 10:55:33 +0800163 case MXC_CPU_MX28:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200164 return "28";
Peng Fanb741b162015-08-13 10:55:33 +0800165 default:
Otavio Salvadorca36b532012-07-28 11:43:47 +0000166 return "??";
167 }
168}
169
Marek Vasutc140e982011-11-08 23:18:08 +0000170int print_cpuinfo(void)
171{
Peng Fanb741b162015-08-13 10:55:33 +0800172 u32 cpurev;
Mans Rullgard2f66b402018-04-21 16:11:09 +0100173 struct mxs_spl_data *data = MXS_SPL_DATA;
Marek Vasutb28fe462012-05-01 11:09:45 +0000174
Peng Fanb741b162015-08-13 10:55:33 +0800175 cpurev = get_cpu_rev();
176 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
177 get_imx_type((cpurev & 0xFF000) >> 12),
178 (cpurev & 0x000F0) >> 4,
179 (cpurev & 0x0000F) >> 0,
Otavio Salvadorca36b532012-07-28 11:43:47 +0000180 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000181 printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
Marek Vasutc140e982011-11-08 23:18:08 +0000182 return 0;
183}
184#endif
185
186int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
187{
188 printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
189 printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
190 printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
191 printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
192 return 0;
193}
194
195/*
196 * Initializes on-chip ethernet controllers.
197 */
Otavio Salvadord1de2e02012-08-19 04:58:29 +0000198#if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
Marek Vasutc140e982011-11-08 23:18:08 +0000199int cpu_eth_init(bd_t *bis)
200{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000201 struct mxs_clkctrl_regs *clkctrl_regs =
202 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasutc140e982011-11-08 23:18:08 +0000203
204 /* Turn on ENET clocks */
205 clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
206 CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
207
208 /* Set up ENET PLL for 50 MHz */
209 /* Power on ENET PLL */
210 writel(CLKCTRL_PLL2CTRL0_POWER,
211 &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
212
213 udelay(10);
214
215 /* Gate on ENET PLL */
216 writel(CLKCTRL_PLL2CTRL0_CLKGATE,
217 &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
218
219 /* Enable pad output */
220 setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
221
222 return 0;
223}
224#endif
225
Fabio Estevam570dcfd2013-01-08 05:21:45 +0000226__weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
Fabio Estevam4029c012011-12-20 06:42:29 +0000227{
228 mac[0] = 0x00;
229 mac[1] = 0x04; /* Use FSL vendor MAC address by default */
230
231 if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
232 mac[5] += 1;
233}
234
Fabio Estevam4029c012011-12-20 06:42:29 +0000235#ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
236
237#define MXS_OCOTP_MAX_TIMEOUT 1000000
238void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
239{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000240 struct mxs_ocotp_regs *ocotp_regs =
241 (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
Fabio Estevam4029c012011-12-20 06:42:29 +0000242 uint32_t data;
243
244 memset(mac, 0, 6);
245
246 writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
247
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000248 if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
Fabio Estevam4029c012011-12-20 06:42:29 +0000249 MXS_OCOTP_MAX_TIMEOUT)) {
250 printf("MXS FEC: Can't get MAC from OCOTP\n");
251 return;
252 }
253
254 data = readl(&ocotp_regs->hw_ocotp_cust0);
255
256 mac[2] = (data >> 24) & 0xff;
257 mac[3] = (data >> 16) & 0xff;
258 mac[4] = (data >> 8) & 0xff;
259 mac[5] = data & 0xff;
260 mx28_adjust_mac(dev_id, mac);
261}
262#else
263void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
264{
265 memset(mac, 0, 6);
266}
267#endif
268
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000269int mxs_dram_init(void)
Fabio Estevam93f3a892011-12-20 05:46:33 +0000270{
Mans Rullgard2f66b402018-04-21 16:11:09 +0100271 struct mxs_spl_data *data = MXS_SPL_DATA;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000272
Marek Vasut9136fe92012-05-01 11:09:44 +0000273 if (data->mem_dram_size == 0) {
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000274 printf("MXS:\n"
Marek Vasut9136fe92012-05-01 11:09:44 +0000275 "Error, the RAM size passed up from SPL is 0!\n");
Fabio Estevam93f3a892011-12-20 05:46:33 +0000276 hang();
277 }
278
Marek Vasut9136fe92012-05-01 11:09:44 +0000279 gd->ram_size = data->mem_dram_size;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000280 return 0;
281}
282
Marek Vasutc140e982011-11-08 23:18:08 +0000283U_BOOT_CMD(
284 clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
285 "display clocks",
286 ""
287);