mxs.c 8.0 KB
Newer Older
M
Marek Vasut 已提交
1
/*
2
 * Freescale i.MX23/i.MX28 common code
M
Marek Vasut 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 *
 * 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.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <common.h>
#include <asm/errno.h>
#include <asm/io.h>
#include <asm/arch/clock.h>
33
#include <asm/arch/dma.h>
M
Marek Vasut 已提交
34
#include <asm/arch/gpio.h>
M
Marek Vasut 已提交
35
#include <asm/arch/iomux.h>
M
Marek Vasut 已提交
36 37
#include <asm/arch/imx-regs.h>
#include <asm/arch/sys_proto.h>
38
#include <linux/compiler.h>
M
Marek Vasut 已提交
39

M
Marek Vasut 已提交
40 41
DECLARE_GLOBAL_DATA_PTR;

M
Marek Vasut 已提交
42 43 44
/* 1 second delay should be plenty of time for block reset. */
#define	RESET_MAX_TIMEOUT	1000000

45 46
#define	MXS_BLOCK_SFTRST	(1 << 31)
#define	MXS_BLOCK_CLKGATE	(1 << 30)
M
Marek Vasut 已提交
47 48 49 50 51 52 53 54

/* Lowlevel init isn't used on i.MX28, so just have a dummy here */
inline void lowlevel_init(void) {}

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

void reset_cpu(ulong ignored)
{
55 56 57 58
	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;
59 60 61 62 63 64

	/*
	 * 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 已提交
65 66 67 68 69 70 71 72 73 74

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

M
Marek Vasut 已提交
75 76 77 78 79 80 81 82 83 84
void enable_caches(void)
{
#ifndef CONFIG_SYS_ICACHE_OFF
	icache_enable();
#endif
#ifndef CONFIG_SYS_DCACHE_OFF
	dcache_enable();
#endif
}

85 86
int mxs_wait_mask_set(struct mxs_register_32 *reg, uint32_t mask, unsigned
								int timeout)
M
Marek Vasut 已提交
87 88 89 90 91 92 93 94 95 96
{
	while (--timeout) {
		if ((readl(&reg->reg) & mask) == mask)
			break;
		udelay(1);
	}

	return !timeout;
}

97 98
int mxs_wait_mask_clr(struct mxs_register_32 *reg, uint32_t mask, unsigned
								int timeout)
M
Marek Vasut 已提交
99 100 101 102 103 104 105 106 107 108
{
	while (--timeout) {
		if ((readl(&reg->reg) & mask) == 0)
			break;
		udelay(1);
	}

	return !timeout;
}

109
int mxs_reset_block(struct mxs_register_32 *reg)
M
Marek Vasut 已提交
110 111
{
	/* Clear SFTRST */
112
	writel(MXS_BLOCK_SFTRST, &reg->reg_clr);
M
Marek Vasut 已提交
113

114
	if (mxs_wait_mask_clr(reg, MXS_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
M
Marek Vasut 已提交
115 116 117
		return 1;

	/* Clear CLKGATE */
118
	writel(MXS_BLOCK_CLKGATE, &reg->reg_clr);
M
Marek Vasut 已提交
119 120

	/* Set SFTRST */
121
	writel(MXS_BLOCK_SFTRST, &reg->reg_set);
M
Marek Vasut 已提交
122 123

	/* Wait for CLKGATE being set */
124
	if (mxs_wait_mask_set(reg, MXS_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
M
Marek Vasut 已提交
125 126 127
		return 1;

	/* Clear SFTRST */
128
	writel(MXS_BLOCK_SFTRST, &reg->reg_clr);
M
Marek Vasut 已提交
129

130
	if (mxs_wait_mask_clr(reg, MXS_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
M
Marek Vasut 已提交
131 132 133
		return 1;

	/* Clear CLKGATE */
134
	writel(MXS_BLOCK_CLKGATE, &reg->reg_clr);
M
Marek Vasut 已提交
135

136
	if (mxs_wait_mask_clr(reg, MXS_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
M
Marek Vasut 已提交
137 138 139 140 141
		return 1;

	return 0;
}

M
Marek Vasut 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
void mx28_fixup_vt(uint32_t start_addr)
{
	uint32_t *vt = (uint32_t *)0x20;
	int i;

	for (i = 0; i < 8; i++)
		vt[i] = start_addr + (4 * i);
}

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

M
Marek Vasut 已提交
159 160
int arch_cpu_init(void)
{
161 162
	struct mxs_clkctrl_regs *clkctrl_regs =
		(struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
M
Marek Vasut 已提交
163 164 165
	extern uint32_t _start;

	mx28_fixup_vt((uint32_t)&_start);
M
Marek Vasut 已提交
166 167 168 169 170 171 172 173 174 175 176 177 178 179

	/*
	 * Enable NAND clock
	 */
	/* Clear bypass bit */
	writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
		&clkctrl_regs->hw_clkctrl_clkseq_set);

	/* Set GPMI clock to ref_gpmi / 12 */
	clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
		CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1);

	udelay(1000);

M
Marek Vasut 已提交
180 181 182 183 184
	/*
	 * Configure GPIO unit
	 */
	mxs_gpio_init();

185 186 187 188 189
#ifdef	CONFIG_APBH_DMA
	/* Start APBH DMA */
	mxs_dma_init();
#endif

M
Marek Vasut 已提交
190 191 192 193
	return 0;
}

#if defined(CONFIG_DISPLAY_CPUINFO)
194 195
static const char *get_cpu_type(void)
{
196 197
	struct mxs_digctl_regs *digctl_regs =
		(struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
198 199

	switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
200 201
	case HW_DIGCTL_CHIPID_MX23:
		return "23";
202 203 204 205 206 207 208 209 210
	case HW_DIGCTL_CHIPID_MX28:
		return "28";
	default:
		return "??";
	}
}

static const char *get_cpu_rev(void)
{
211 212
	struct mxs_digctl_regs *digctl_regs =
		(struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
213 214 215
	uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;

	switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
	case HW_DIGCTL_CHIPID_MX23:
		switch (rev) {
		case 0x0:
			return "1.0";
		case 0x1:
			return "1.1";
		case 0x2:
			return "1.2";
		case 0x3:
			return "1.3";
		case 0x4:
			return "1.4";
		default:
			return "??";
		}
231 232 233 234 235 236 237 238 239 240 241 242
	case HW_DIGCTL_CHIPID_MX28:
		switch (rev) {
		case 0x1:
			return "1.2";
		default:
			return "??";
		}
	default:
		return "??";
	}
}

M
Marek Vasut 已提交
243 244
int print_cpuinfo(void)
{
245 246
	struct mxs_spl_data *data = (struct mxs_spl_data *)
		((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
247

248 249 250 251
	printf("CPU:   Freescale i.MX%s rev%s at %d MHz\n",
		get_cpu_type(),
		get_cpu_rev(),
		mxc_get_clock(MXC_ARM_CLK) / 1000000);
252
	printf("BOOT:  %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
M
Marek Vasut 已提交
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
	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.
 */
269
#if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
M
Marek Vasut 已提交
270 271
int cpu_eth_init(bd_t *bis)
{
272 273
	struct mxs_clkctrl_regs *clkctrl_regs =
		(struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
M
Marek Vasut 已提交
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296

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

297
__weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
298 299 300 301 302 303 304 305 306 307 308 309 310
{
	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)
{
311 312
	struct mxs_ocotp_regs *ocotp_regs =
		(struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
313 314 315 316 317 318
	uint32_t data;

	memset(mac, 0, 6);

	writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);

319
	if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
				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

340
int mxs_dram_init(void)
341
{
342 343
	struct mxs_spl_data *data = (struct mxs_spl_data *)
		((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
344

345
	if (data->mem_dram_size == 0) {
346
		printf("MXS:\n"
347
			"Error, the RAM size passed up from SPL is 0!\n");
348 349 350
		hang();
	}

351
	gd->ram_size = data->mem_dram_size;
352 353 354
	return 0;
}

M
Marek Vasut 已提交
355 356 357 358 359
U_BOOT_CMD(
	clocks,	CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
	"display clocks",
	""
);