mxs.c 6.6 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0+
M
Marek Vasut 已提交
2
/*
3
 * Freescale i.MX23/i.MX28 common code
M
Marek Vasut 已提交
4 5 6 7 8 9 10 11 12
 *
 * 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>
13
#include <cpu_func.h>
14
#include <linux/errno.h>
M
Marek Vasut 已提交
15 16
#include <asm/io.h>
#include <asm/arch/clock.h>
17
#include <asm/mach-imx/dma.h>
M
Marek Vasut 已提交
18
#include <asm/arch/gpio.h>
M
Marek Vasut 已提交
19
#include <asm/arch/iomux.h>
M
Marek Vasut 已提交
20 21
#include <asm/arch/imx-regs.h>
#include <asm/arch/sys_proto.h>
22
#include <linux/compiler.h>
M
Marek Vasut 已提交
23

M
Marek Vasut 已提交
24 25
DECLARE_GLOBAL_DATA_PTR;

M
Marek Vasut 已提交
26
/* Lowlevel init isn't used on i.MX28, so just have a dummy here */
27
__weak void lowlevel_init(void) {}
M
Marek Vasut 已提交
28 29 30 31 32

void reset_cpu(ulong ignored) __attribute__((noreturn));

void reset_cpu(ulong ignored)
{
33 34 35 36
	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;
37 38 39 40 41 42

	/*
	 * Shut down the LCD controller as it interferes with BootROM boot mode
	 * pads sampling.
	 */
	writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr);
M
Marek Vasut 已提交
43 44 45 46 47 48 49 50 51 52

	/* 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 (;;)
		;
}

53 54 55 56 57 58 59 60 61 62 63 64 65 66
/*
 * 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.
 */
M
Marek Vasut 已提交
67 68
void mx28_fixup_vt(uint32_t start_addr)
{
69 70 71 72
	/* ldr pc, [pc, #0x18] */
	const uint32_t ldr_pc = 0xe59ff018;
	/* Jumptable location is 0x0 */
	uint32_t *vt = (uint32_t *)0x0;
M
Marek Vasut 已提交
73 74
	int i;

75
	for (i = 0; i < 8; i++) {
76
		/* cppcheck-suppress nullPointer */
77
		vt[i] = ldr_pc;
78
		/* cppcheck-suppress nullPointer */
79 80
		vt[i + 8] = start_addr + (4 * i);
	}
M
Marek Vasut 已提交
81 82 83 84 85 86 87 88 89 90
}

#ifdef	CONFIG_ARCH_MISC_INIT
int arch_misc_init(void)
{
	mx28_fixup_vt(gd->relocaddr);
	return 0;
}
#endif

M
Marek Vasut 已提交
91 92
int arch_cpu_init(void)
{
93 94
	struct mxs_clkctrl_regs *clkctrl_regs =
		(struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
M
Marek Vasut 已提交
95 96 97
	extern uint32_t _start;

	mx28_fixup_vt((uint32_t)&_start);
M
Marek Vasut 已提交
98 99 100 101

	/*
	 * Enable NAND clock
	 */
102
	/* Set bypass bit */
M
Marek Vasut 已提交
103 104 105
	writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
		&clkctrl_regs->hw_clkctrl_clkseq_set);

106
	/* Set GPMI clock to ref_xtal / 1 */
107 108 109
	clrbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, CLKCTRL_GPMI_CLKGATE);
	while (readl(&clkctrl_regs->hw_clkctrl_gpmi) & CLKCTRL_GPMI_CLKGATE)
		;
M
Marek Vasut 已提交
110
	clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
111
		CLKCTRL_GPMI_DIV_MASK, 1);
M
Marek Vasut 已提交
112 113 114

	udelay(1000);

M
Marek Vasut 已提交
115 116 117 118 119
	/*
	 * Configure GPIO unit
	 */
	mxs_gpio_init();

120 121 122 123 124
#ifdef	CONFIG_APBH_DMA
	/* Start APBH DMA */
	mxs_dma_init();
#endif

M
Marek Vasut 已提交
125 126 127
	return 0;
}

P
Peng Fan 已提交
128
u32 get_cpu_rev(void)
129
{
130 131
	struct mxs_digctl_regs *digctl_regs =
		(struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
132 133 134
	uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;

	switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
135 136 137 138 139 140 141
	case HW_DIGCTL_CHIPID_MX23:
		switch (rev) {
		case 0x0:
		case 0x1:
		case 0x2:
		case 0x3:
		case 0x4:
P
Peng Fan 已提交
142
			return (MXC_CPU_MX23 << 12) | (rev + 0x10);
143
		default:
P
Peng Fan 已提交
144
			return 0;
145
		}
146 147 148
	case HW_DIGCTL_CHIPID_MX28:
		switch (rev) {
		case 0x1:
P
Peng Fan 已提交
149
			return (MXC_CPU_MX28 << 12) | 0x12;
150
		default:
P
Peng Fan 已提交
151
			return 0;
152
		}
P
Peng Fan 已提交
153 154 155 156 157 158 159 160 161 162
	default:
		return 0;
	}
}

#if defined(CONFIG_DISPLAY_CPUINFO)
const char *get_imx_type(u32 imxtype)
{
	switch (imxtype) {
	case MXC_CPU_MX23:
163
		return "23";
P
Peng Fan 已提交
164
	case MXC_CPU_MX28:
165
		return "28";
166 167 168 169 170
	default:
		return "??";
	}
}

M
Marek Vasut 已提交
171 172
int print_cpuinfo(void)
{
P
Peng Fan 已提交
173
	u32 cpurev;
M
Mans Rullgard 已提交
174
	struct mxs_spl_data *data = MXS_SPL_DATA;
175

P
Peng Fan 已提交
176 177 178 179 180
	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,
181
		mxc_get_clock(MXC_ARM_CLK) / 1000000);
182
	printf("BOOT:  %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
M
Marek Vasut 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
	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.
 */
199
#if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
M
Marek Vasut 已提交
200 201
int cpu_eth_init(bd_t *bis)
{
202 203
	struct mxs_clkctrl_regs *clkctrl_regs =
		(struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
M
Marek Vasut 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226

	/* 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

227
__weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
228 229 230 231 232 233 234 235 236 237 238 239 240
{
	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)
{
241 242
	struct mxs_ocotp_regs *ocotp_regs =
		(struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
243 244 245 246 247 248
	uint32_t data;

	memset(mac, 0, 6);

	writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);

249
	if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
				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

270
int mxs_dram_init(void)
271
{
M
Mans Rullgard 已提交
272
	struct mxs_spl_data *data = MXS_SPL_DATA;
273

274
	if (data->mem_dram_size == 0) {
275
		printf("MXS:\n"
276
			"Error, the RAM size passed up from SPL is 0!\n");
277 278 279
		hang();
	}

280
	gd->ram_size = data->mem_dram_size;
281 282 283
	return 0;
}

M
Marek Vasut 已提交
284 285 286 287 288
U_BOOT_CMD(
	clocks,	CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
	"display clocks",
	""
);