2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-11-08 23:18:08 +00:00
|
|
|
/*
|
2013-01-11 03:19:08 +00:00
|
|
|
* Freescale i.MX23/i.MX28 common code
|
2011-11-08 23:18:08 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
|
|
|
|
* on behalf of DENX Software Engineering GmbH
|
|
|
|
*
|
|
|
|
* Based on code from LTIB:
|
|
|
|
* Copyright (C) 2010 Freescale Semiconductor, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-12-28 17:45:01 +00:00
|
|
|
#include <cpu_func.h>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2011-11-08 23:18:08 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/clock.h>
|
2017-06-29 08:16:06 +00:00
|
|
|
#include <asm/mach-imx/dma.h>
|
2011-11-08 23:18:08 +00:00
|
|
|
#include <asm/arch/gpio.h>
|
2011-11-08 23:18:13 +00:00
|
|
|
#include <asm/arch/iomux.h>
|
2011-11-08 23:18:08 +00:00
|
|
|
#include <asm/arch/imx-regs.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
2013-01-08 05:21:45 +00:00
|
|
|
#include <linux/compiler.h>
|
2011-11-08 23:18:08 +00:00
|
|
|
|
2011-11-08 23:18:23 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2011-11-08 23:18:08 +00:00
|
|
|
/* Lowlevel init isn't used on i.MX28, so just have a dummy here */
|
2018-04-21 15:11:06 +00:00
|
|
|
__weak void lowlevel_init(void) {}
|
2011-11-08 23:18:08 +00:00
|
|
|
|
|
|
|
void reset_cpu(ulong ignored) __attribute__((noreturn));
|
|
|
|
|
|
|
|
void reset_cpu(ulong ignored)
|
|
|
|
{
|
2012-08-05 09:05:31 +00:00
|
|
|
struct mxs_rtc_regs *rtc_regs =
|
|
|
|
(struct mxs_rtc_regs *)MXS_RTC_BASE;
|
|
|
|
struct mxs_lcdif_regs *lcdif_regs =
|
|
|
|
(struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
|
2012-05-01 11:09:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Shut down the LCD controller as it interferes with BootROM boot mode
|
|
|
|
* pads sampling.
|
|
|
|
*/
|
|
|
|
writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr);
|
2011-11-08 23:18:08 +00:00
|
|
|
|
|
|
|
/* Wait 1 uS before doing the actual watchdog reset */
|
|
|
|
writel(1, &rtc_regs->hw_rtc_watchdog);
|
|
|
|
writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
|
|
|
|
|
|
|
|
/* Endless loop, reset will exit from here */
|
|
|
|
for (;;)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2013-04-25 16:37:12 +00:00
|
|
|
/*
|
|
|
|
* This function will craft a jumptable at 0x0 which will redirect interrupt
|
|
|
|
* vectoring to proper location of U-Boot in RAM.
|
|
|
|
*
|
|
|
|
* The structure of the jumptable will be as follows:
|
|
|
|
* ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times
|
|
|
|
* <destination address> ... for each previous ldr, thus also repeated 8 times
|
|
|
|
*
|
|
|
|
* The "ldr pc, [pc, #0x18]" instruction above loads address from memory at
|
|
|
|
* offset 0x18 from current value of PC register. Note that PC is already
|
|
|
|
* incremented by 4 when computing the offset, so the effective offset is
|
|
|
|
* actually 0x20, this the associated <destination address>. Loading the PC
|
|
|
|
* register with an address performs a jump to that address.
|
|
|
|
*/
|
2011-11-08 23:18:23 +00:00
|
|
|
void mx28_fixup_vt(uint32_t start_addr)
|
|
|
|
{
|
2013-04-25 16:37:12 +00:00
|
|
|
/* ldr pc, [pc, #0x18] */
|
|
|
|
const uint32_t ldr_pc = 0xe59ff018;
|
|
|
|
/* Jumptable location is 0x0 */
|
|
|
|
uint32_t *vt = (uint32_t *)0x0;
|
2011-11-08 23:18:23 +00:00
|
|
|
int i;
|
|
|
|
|
2013-04-25 16:37:12 +00:00
|
|
|
for (i = 0; i < 8; i++) {
|
2014-11-06 13:02:57 +00:00
|
|
|
/* cppcheck-suppress nullPointer */
|
2013-04-25 16:37:12 +00:00
|
|
|
vt[i] = ldr_pc;
|
2014-11-06 13:02:57 +00:00
|
|
|
/* cppcheck-suppress nullPointer */
|
2013-04-25 16:37:12 +00:00
|
|
|
vt[i + 8] = start_addr + (4 * i);
|
|
|
|
}
|
2011-11-08 23:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_MISC_INIT
|
|
|
|
int arch_misc_init(void)
|
|
|
|
{
|
|
|
|
mx28_fixup_vt(gd->relocaddr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-08 23:18:08 +00:00
|
|
|
int arch_cpu_init(void)
|
|
|
|
{
|
2012-08-05 09:05:31 +00:00
|
|
|
struct mxs_clkctrl_regs *clkctrl_regs =
|
|
|
|
(struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
|
2011-11-08 23:18:23 +00:00
|
|
|
extern uint32_t _start;
|
|
|
|
|
|
|
|
mx28_fixup_vt((uint32_t)&_start);
|
2011-11-08 23:18:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable NAND clock
|
|
|
|
*/
|
2019-09-12 09:17:10 +00:00
|
|
|
/* Set bypass bit */
|
2011-11-08 23:18:08 +00:00
|
|
|
writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
|
|
|
|
&clkctrl_regs->hw_clkctrl_clkseq_set);
|
|
|
|
|
2019-09-12 09:17:10 +00:00
|
|
|
/* Set GPMI clock to ref_xtal / 1 */
|
2019-09-12 09:17:11 +00:00
|
|
|
clrbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, CLKCTRL_GPMI_CLKGATE);
|
|
|
|
while (readl(&clkctrl_regs->hw_clkctrl_gpmi) & CLKCTRL_GPMI_CLKGATE)
|
|
|
|
;
|
2011-11-08 23:18:08 +00:00
|
|
|
clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
|
2019-09-12 09:17:11 +00:00
|
|
|
CLKCTRL_GPMI_DIV_MASK, 1);
|
2011-11-08 23:18:08 +00:00
|
|
|
|
|
|
|
udelay(1000);
|
|
|
|
|
2011-11-08 23:18:13 +00:00
|
|
|
/*
|
|
|
|
* Configure GPIO unit
|
|
|
|
*/
|
|
|
|
mxs_gpio_init();
|
|
|
|
|
2012-04-08 17:34:46 +00:00
|
|
|
#ifdef CONFIG_APBH_DMA
|
|
|
|
/* Start APBH DMA */
|
|
|
|
mxs_dma_init();
|
|
|
|
#endif
|
|
|
|
|
2011-11-08 23:18:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-13 02:55:33 +00:00
|
|
|
u32 get_cpu_rev(void)
|
2012-07-28 11:43:47 +00:00
|
|
|
{
|
2012-08-05 09:05:31 +00:00
|
|
|
struct mxs_digctl_regs *digctl_regs =
|
|
|
|
(struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
|
2012-07-28 11:43:47 +00:00
|
|
|
uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;
|
|
|
|
|
|
|
|
switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
|
2013-01-11 03:19:08 +00:00
|
|
|
case HW_DIGCTL_CHIPID_MX23:
|
|
|
|
switch (rev) {
|
|
|
|
case 0x0:
|
|
|
|
case 0x1:
|
|
|
|
case 0x2:
|
|
|
|
case 0x3:
|
|
|
|
case 0x4:
|
2015-08-13 02:55:33 +00:00
|
|
|
return (MXC_CPU_MX23 << 12) | (rev + 0x10);
|
2013-01-11 03:19:08 +00:00
|
|
|
default:
|
2015-08-13 02:55:33 +00:00
|
|
|
return 0;
|
2013-01-11 03:19:08 +00:00
|
|
|
}
|
2012-07-28 11:43:47 +00:00
|
|
|
case HW_DIGCTL_CHIPID_MX28:
|
|
|
|
switch (rev) {
|
|
|
|
case 0x1:
|
2015-08-13 02:55:33 +00:00
|
|
|
return (MXC_CPU_MX28 << 12) | 0x12;
|
2012-07-28 11:43:47 +00:00
|
|
|
default:
|
2015-08-13 02:55:33 +00:00
|
|
|
return 0;
|
2012-07-28 11:43:47 +00:00
|
|
|
}
|
2015-08-13 02:55:33 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_DISPLAY_CPUINFO)
|
|
|
|
const char *get_imx_type(u32 imxtype)
|
|
|
|
{
|
|
|
|
switch (imxtype) {
|
|
|
|
case MXC_CPU_MX23:
|
2016-06-06 12:26:39 +00:00
|
|
|
return "23";
|
2015-08-13 02:55:33 +00:00
|
|
|
case MXC_CPU_MX28:
|
2016-06-06 12:26:39 +00:00
|
|
|
return "28";
|
2012-07-28 11:43:47 +00:00
|
|
|
default:
|
|
|
|
return "??";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-08 23:18:08 +00:00
|
|
|
int print_cpuinfo(void)
|
|
|
|
{
|
2015-08-13 02:55:33 +00:00
|
|
|
u32 cpurev;
|
2018-04-21 15:11:09 +00:00
|
|
|
struct mxs_spl_data *data = MXS_SPL_DATA;
|
2012-05-01 11:09:45 +00:00
|
|
|
|
2015-08-13 02:55:33 +00:00
|
|
|
cpurev = get_cpu_rev();
|
|
|
|
printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
|
|
|
|
get_imx_type((cpurev & 0xFF000) >> 12),
|
|
|
|
(cpurev & 0x000F0) >> 4,
|
|
|
|
(cpurev & 0x0000F) >> 0,
|
2012-07-28 11:43:47 +00:00
|
|
|
mxc_get_clock(MXC_ARM_CLK) / 1000000);
|
2012-08-13 09:53:12 +00:00
|
|
|
printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
|
2011-11-08 23:18:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
|
|
|
|
{
|
|
|
|
printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
|
|
|
|
printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
|
|
|
|
printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
|
|
|
|
printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes on-chip ethernet controllers.
|
|
|
|
*/
|
2012-08-19 04:58:29 +00:00
|
|
|
#if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
|
2011-11-08 23:18:08 +00:00
|
|
|
int cpu_eth_init(bd_t *bis)
|
|
|
|
{
|
2012-08-05 09:05:31 +00:00
|
|
|
struct mxs_clkctrl_regs *clkctrl_regs =
|
|
|
|
(struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
|
2011-11-08 23:18:08 +00:00
|
|
|
|
|
|
|
/* Turn on ENET clocks */
|
|
|
|
clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
|
|
|
|
CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
|
|
|
|
|
|
|
|
/* Set up ENET PLL for 50 MHz */
|
|
|
|
/* Power on ENET PLL */
|
|
|
|
writel(CLKCTRL_PLL2CTRL0_POWER,
|
|
|
|
&clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
|
|
|
|
|
|
|
|
udelay(10);
|
|
|
|
|
|
|
|
/* Gate on ENET PLL */
|
|
|
|
writel(CLKCTRL_PLL2CTRL0_CLKGATE,
|
|
|
|
&clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
|
|
|
|
|
|
|
|
/* Enable pad output */
|
|
|
|
setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-08 05:21:45 +00:00
|
|
|
__weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
|
2011-12-20 06:42:29 +00:00
|
|
|
{
|
|
|
|
mac[0] = 0x00;
|
|
|
|
mac[1] = 0x04; /* Use FSL vendor MAC address by default */
|
|
|
|
|
|
|
|
if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
|
|
|
|
mac[5] += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
|
|
|
|
|
|
|
|
#define MXS_OCOTP_MAX_TIMEOUT 1000000
|
|
|
|
void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
|
|
|
|
{
|
2012-08-05 09:05:31 +00:00
|
|
|
struct mxs_ocotp_regs *ocotp_regs =
|
|
|
|
(struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
|
2011-12-20 06:42:29 +00:00
|
|
|
uint32_t data;
|
|
|
|
|
|
|
|
memset(mac, 0, 6);
|
|
|
|
|
|
|
|
writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
|
|
|
|
|
2012-08-13 09:53:12 +00:00
|
|
|
if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
|
2011-12-20 06:42:29 +00:00
|
|
|
MXS_OCOTP_MAX_TIMEOUT)) {
|
|
|
|
printf("MXS FEC: Can't get MAC from OCOTP\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = readl(&ocotp_regs->hw_ocotp_cust0);
|
|
|
|
|
|
|
|
mac[2] = (data >> 24) & 0xff;
|
|
|
|
mac[3] = (data >> 16) & 0xff;
|
|
|
|
mac[4] = (data >> 8) & 0xff;
|
|
|
|
mac[5] = data & 0xff;
|
|
|
|
mx28_adjust_mac(dev_id, mac);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
|
|
|
|
{
|
|
|
|
memset(mac, 0, 6);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-19 04:58:30 +00:00
|
|
|
int mxs_dram_init(void)
|
2011-12-20 05:46:33 +00:00
|
|
|
{
|
2018-04-21 15:11:09 +00:00
|
|
|
struct mxs_spl_data *data = MXS_SPL_DATA;
|
2011-12-20 05:46:33 +00:00
|
|
|
|
2012-05-01 11:09:44 +00:00
|
|
|
if (data->mem_dram_size == 0) {
|
2012-08-19 04:58:30 +00:00
|
|
|
printf("MXS:\n"
|
2012-05-01 11:09:44 +00:00
|
|
|
"Error, the RAM size passed up from SPL is 0!\n");
|
2011-12-20 05:46:33 +00:00
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
2012-05-01 11:09:44 +00:00
|
|
|
gd->ram_size = data->mem_dram_size;
|
2011-12-20 05:46:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-08 23:18:08 +00:00
|
|
|
U_BOOT_CMD(
|
|
|
|
clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
|
|
|
|
"display clocks",
|
|
|
|
""
|
|
|
|
);
|