blob: 840dd9edbd2c68d67d540802bf7b5bf0446d1fe8 [file] [log] [blame]
Marek Vasutc140e982011-11-08 23:18:08 +00001/*
Otavio Salvadorfd96c032013-01-11 03:19:08 +00002 * Freescale i.MX23/i.MX28 common code
Marek Vasutc140e982011-11-08 23:18:08 +00003 *
4 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5 * on behalf of DENX Software Engineering GmbH
6 *
7 * Based on code from LTIB:
8 * Copyright (C) 2010 Freescale Semiconductor, Inc.
9 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Marek Vasutc140e982011-11-08 23:18:08 +000011 */
12
13#include <common.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>
Stefan Roese136f3f42013-04-09 21:06:07 +000017#include <asm/imx-common/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 */
Måns Rullgård297abca2015-07-28 14:39:49 +010027void 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 Vasut6e5ce312012-03-15 18:33:23 +000053void enable_caches(void)
54{
55#ifndef CONFIG_SYS_ICACHE_OFF
56 icache_enable();
57#endif
58#ifndef CONFIG_SYS_DCACHE_OFF
59 dcache_enable();
60#endif
61}
62
Marek Vasut39c31032013-04-25 16:37:12 +000063/*
64 * This function will craft a jumptable at 0x0 which will redirect interrupt
65 * vectoring to proper location of U-Boot in RAM.
66 *
67 * The structure of the jumptable will be as follows:
68 * ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times
69 * <destination address> ... for each previous ldr, thus also repeated 8 times
70 *
71 * The "ldr pc, [pc, #0x18]" instruction above loads address from memory at
72 * offset 0x18 from current value of PC register. Note that PC is already
73 * incremented by 4 when computing the offset, so the effective offset is
74 * actually 0x20, this the associated <destination address>. Loading the PC
75 * register with an address performs a jump to that address.
76 */
Marek Vasut5bf48fb2011-11-08 23:18:23 +000077void mx28_fixup_vt(uint32_t start_addr)
78{
Marek Vasut39c31032013-04-25 16:37:12 +000079 /* ldr pc, [pc, #0x18] */
80 const uint32_t ldr_pc = 0xe59ff018;
81 /* Jumptable location is 0x0 */
82 uint32_t *vt = (uint32_t *)0x0;
Marek Vasut5bf48fb2011-11-08 23:18:23 +000083 int i;
84
Marek Vasut39c31032013-04-25 16:37:12 +000085 for (i = 0; i < 8; i++) {
Wolfgang Denk6ae80832014-11-06 14:02:57 +010086 /* cppcheck-suppress nullPointer */
Marek Vasut39c31032013-04-25 16:37:12 +000087 vt[i] = ldr_pc;
Wolfgang Denk6ae80832014-11-06 14:02:57 +010088 /* cppcheck-suppress nullPointer */
Marek Vasut39c31032013-04-25 16:37:12 +000089 vt[i + 8] = start_addr + (4 * i);
90 }
Marek Vasut5bf48fb2011-11-08 23:18:23 +000091}
92
93#ifdef CONFIG_ARCH_MISC_INIT
94int arch_misc_init(void)
95{
96 mx28_fixup_vt(gd->relocaddr);
Marek Vasutc140e982011-11-08 23:18:08 +000097 return 0;
98}
Marek Vasut5bf48fb2011-11-08 23:18:23 +000099#endif
Marek Vasutc140e982011-11-08 23:18:08 +0000100
Marek Vasutc140e982011-11-08 23:18:08 +0000101int arch_cpu_init(void)
102{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000103 struct mxs_clkctrl_regs *clkctrl_regs =
104 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasut5bf48fb2011-11-08 23:18:23 +0000105 extern uint32_t _start;
106
107 mx28_fixup_vt((uint32_t)&_start);
Marek Vasutc140e982011-11-08 23:18:08 +0000108
109 /*
110 * Enable NAND clock
111 */
112 /* Clear bypass bit */
113 writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
114 &clkctrl_regs->hw_clkctrl_clkseq_set);
115
116 /* Set GPMI clock to ref_gpmi / 12 */
117 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
118 CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1);
119
120 udelay(1000);
121
Marek Vasut53fdab22011-11-08 23:18:13 +0000122 /*
123 * Configure GPIO unit
124 */
125 mxs_gpio_init();
126
Marek Vasut93541b42012-04-08 17:34:46 +0000127#ifdef CONFIG_APBH_DMA
128 /* Start APBH DMA */
129 mxs_dma_init();
130#endif
131
Marek Vasutc140e982011-11-08 23:18:08 +0000132 return 0;
133}
Marek Vasutc140e982011-11-08 23:18:08 +0000134
Peng Fanb741b162015-08-13 10:55:33 +0800135u32 get_cpu_rev(void)
Otavio Salvadorca36b532012-07-28 11:43:47 +0000136{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000137 struct mxs_digctl_regs *digctl_regs =
138 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000139 uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;
140
141 switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000142 case HW_DIGCTL_CHIPID_MX23:
143 switch (rev) {
144 case 0x0:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000145 case 0x1:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000146 case 0x2:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000147 case 0x3:
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000148 case 0x4:
Peng Fanb741b162015-08-13 10:55:33 +0800149 return (MXC_CPU_MX23 << 12) | (rev + 0x10);
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000150 default:
Peng Fanb741b162015-08-13 10:55:33 +0800151 return 0;
Otavio Salvadorfd96c032013-01-11 03:19:08 +0000152 }
Otavio Salvadorca36b532012-07-28 11:43:47 +0000153 case HW_DIGCTL_CHIPID_MX28:
154 switch (rev) {
155 case 0x1:
Peng Fanb741b162015-08-13 10:55:33 +0800156 return (MXC_CPU_MX28 << 12) | 0x12;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000157 default:
Peng Fanb741b162015-08-13 10:55:33 +0800158 return 0;
Otavio Salvadorca36b532012-07-28 11:43:47 +0000159 }
160 default:
Peng Fanb741b162015-08-13 10:55:33 +0800161 return 0;
162 }
163}
164
165#if defined(CONFIG_DISPLAY_CPUINFO)
166const char *get_imx_type(u32 imxtype)
167{
168 switch (imxtype) {
169 case MXC_CPU_MX23:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200170 return "23";
Peng Fanb741b162015-08-13 10:55:33 +0800171 case MXC_CPU_MX28:
Michael Heimpold0ad9e1f2016-06-06 14:26:39 +0200172 return "28";
Peng Fanb741b162015-08-13 10:55:33 +0800173 default:
Otavio Salvadorca36b532012-07-28 11:43:47 +0000174 return "??";
175 }
176}
177
Marek Vasutc140e982011-11-08 23:18:08 +0000178int print_cpuinfo(void)
179{
Peng Fanb741b162015-08-13 10:55:33 +0800180 u32 cpurev;
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000181 struct mxs_spl_data *data = (struct mxs_spl_data *)
182 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
Marek Vasutb28fe462012-05-01 11:09:45 +0000183
Peng Fanb741b162015-08-13 10:55:33 +0800184 cpurev = get_cpu_rev();
185 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
186 get_imx_type((cpurev & 0xFF000) >> 12),
187 (cpurev & 0x000F0) >> 4,
188 (cpurev & 0x0000F) >> 0,
Otavio Salvadorca36b532012-07-28 11:43:47 +0000189 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000190 printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
Marek Vasutc140e982011-11-08 23:18:08 +0000191 return 0;
192}
193#endif
194
195int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
196{
197 printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
198 printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
199 printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
200 printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
201 return 0;
202}
203
204/*
205 * Initializes on-chip ethernet controllers.
206 */
Otavio Salvadord1de2e02012-08-19 04:58:29 +0000207#if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
Marek Vasutc140e982011-11-08 23:18:08 +0000208int cpu_eth_init(bd_t *bis)
209{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000210 struct mxs_clkctrl_regs *clkctrl_regs =
211 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasutc140e982011-11-08 23:18:08 +0000212
213 /* Turn on ENET clocks */
214 clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
215 CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
216
217 /* Set up ENET PLL for 50 MHz */
218 /* Power on ENET PLL */
219 writel(CLKCTRL_PLL2CTRL0_POWER,
220 &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
221
222 udelay(10);
223
224 /* Gate on ENET PLL */
225 writel(CLKCTRL_PLL2CTRL0_CLKGATE,
226 &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
227
228 /* Enable pad output */
229 setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
230
231 return 0;
232}
233#endif
234
Fabio Estevam570dcfd2013-01-08 05:21:45 +0000235__weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
Fabio Estevam4029c012011-12-20 06:42:29 +0000236{
237 mac[0] = 0x00;
238 mac[1] = 0x04; /* Use FSL vendor MAC address by default */
239
240 if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
241 mac[5] += 1;
242}
243
Fabio Estevam4029c012011-12-20 06:42:29 +0000244#ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
245
246#define MXS_OCOTP_MAX_TIMEOUT 1000000
247void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
248{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000249 struct mxs_ocotp_regs *ocotp_regs =
250 (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
Fabio Estevam4029c012011-12-20 06:42:29 +0000251 uint32_t data;
252
253 memset(mac, 0, 6);
254
255 writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
256
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000257 if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
Fabio Estevam4029c012011-12-20 06:42:29 +0000258 MXS_OCOTP_MAX_TIMEOUT)) {
259 printf("MXS FEC: Can't get MAC from OCOTP\n");
260 return;
261 }
262
263 data = readl(&ocotp_regs->hw_ocotp_cust0);
264
265 mac[2] = (data >> 24) & 0xff;
266 mac[3] = (data >> 16) & 0xff;
267 mac[4] = (data >> 8) & 0xff;
268 mac[5] = data & 0xff;
269 mx28_adjust_mac(dev_id, mac);
270}
271#else
272void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
273{
274 memset(mac, 0, 6);
275}
276#endif
277
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000278int mxs_dram_init(void)
Fabio Estevam93f3a892011-12-20 05:46:33 +0000279{
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000280 struct mxs_spl_data *data = (struct mxs_spl_data *)
281 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
Fabio Estevam93f3a892011-12-20 05:46:33 +0000282
Marek Vasut9136fe92012-05-01 11:09:44 +0000283 if (data->mem_dram_size == 0) {
Otavio Salvadora2bbe0c2012-08-19 04:58:30 +0000284 printf("MXS:\n"
Marek Vasut9136fe92012-05-01 11:09:44 +0000285 "Error, the RAM size passed up from SPL is 0!\n");
Fabio Estevam93f3a892011-12-20 05:46:33 +0000286 hang();
287 }
288
Marek Vasut9136fe92012-05-01 11:09:44 +0000289 gd->ram_size = data->mem_dram_size;
Fabio Estevam93f3a892011-12-20 05:46:33 +0000290 return 0;
291}
292
Marek Vasutc140e982011-11-08 23:18:08 +0000293U_BOOT_CMD(
294 clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
295 "display clocks",
296 ""
297);