xref: /rk3399_rockchip-uboot/board/freescale/m5253evbe/m5253evbe.c (revision fc843a02acad62e231a3e779cebd1712688146fc)
1a1436a84STsiChungLiew /*
2a1436a84STsiChungLiew  * (C) Copyright 2000-2003
3a1436a84STsiChungLiew  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4a1436a84STsiChungLiew  *
532dbaafaSAlison Wang  * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
6a1436a84STsiChungLiew  * Hayden Fraser (Hayden.Fraser@freescale.com)
7a1436a84STsiChungLiew  *
81a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
9a1436a84STsiChungLiew  */
10a1436a84STsiChungLiew 
11a1436a84STsiChungLiew #include <common.h>
12a1436a84STsiChungLiew #include <asm/immap.h>
1332dbaafaSAlison Wang #include <asm/io.h>
14a1436a84STsiChungLiew 
15088454cdSSimon Glass DECLARE_GLOBAL_DATA_PTR;
16088454cdSSimon Glass 
checkboard(void)17a1436a84STsiChungLiew int checkboard(void)
18a1436a84STsiChungLiew {
19a1436a84STsiChungLiew 	puts("Board: ");
20a1436a84STsiChungLiew 	puts("Freescale MCF5253 EVBE\n");
21a1436a84STsiChungLiew 	return 0;
22a1436a84STsiChungLiew };
23a1436a84STsiChungLiew 
dram_init(void)24f1683aa7SSimon Glass int dram_init(void)
25a1436a84STsiChungLiew {
26a1436a84STsiChungLiew 	/*
27a1436a84STsiChungLiew 	 * Check to see if the SDRAM has already been initialized
28a1436a84STsiChungLiew 	 * by a run control tool
29a1436a84STsiChungLiew 	 */
30a1436a84STsiChungLiew 	if (!(mbar_readLong(MCFSIM_DCR) & 0x8000)) {
31a1436a84STsiChungLiew 		u32 RC, dramsize;
32a1436a84STsiChungLiew 
336d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		RC = (CONFIG_SYS_CLK / 1000000) >> 1;
34a1436a84STsiChungLiew 		RC = (RC * 15) >> 4;
35a1436a84STsiChungLiew 
36a1436a84STsiChungLiew 		/* Initialize DRAM Control Register: DCR */
37a1436a84STsiChungLiew 		mbar_writeShort(MCFSIM_DCR, (0x8400 | RC));
38d361307eSTsiChung Liew 		asm("nop");
39a1436a84STsiChungLiew 
40d361307eSTsiChung Liew 		mbar_writeLong(MCFSIM_DACR0, 0x00002320);
41d361307eSTsiChung Liew 		asm("nop");
42a1436a84STsiChungLiew 
43a1436a84STsiChungLiew 		/* Initialize DMR0 */
446d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		dramsize = ((CONFIG_SYS_SDRAM_SIZE << 20) - 1) & 0xFFFC0000;
45a1436a84STsiChungLiew 		mbar_writeLong(MCFSIM_DMR0, dramsize | 1);
46d361307eSTsiChung Liew 		asm("nop");
47a1436a84STsiChungLiew 
48d361307eSTsiChung Liew 		mbar_writeLong(MCFSIM_DACR0, 0x00002328);
49d361307eSTsiChung Liew 		asm("nop");
50a1436a84STsiChungLiew 
51a1436a84STsiChungLiew 		/* Write to this block to initiate precharge */
526d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		*(u32 *) (CONFIG_SYS_SDRAM_BASE) = 0xa5a5a5a5;
53d361307eSTsiChung Liew 		asm("nop");
54a1436a84STsiChungLiew 
55a1436a84STsiChungLiew 		/* Set RE bit in DACR */
56a1436a84STsiChungLiew 		mbar_writeLong(MCFSIM_DACR0,
57a1436a84STsiChungLiew 			       mbar_readLong(MCFSIM_DACR0) | 0x8000);
58d361307eSTsiChung Liew 		asm("nop");
59a1436a84STsiChungLiew 
60a1436a84STsiChungLiew 		/* Wait for at least 8 auto refresh cycles to occur */
61a1436a84STsiChungLiew 		udelay(500);
62a1436a84STsiChungLiew 
63a1436a84STsiChungLiew 		/* Finish the configuration by issuing the MRS */
64a1436a84STsiChungLiew 		mbar_writeLong(MCFSIM_DACR0,
65a1436a84STsiChungLiew 			       mbar_readLong(MCFSIM_DACR0) | 0x0040);
66d361307eSTsiChung Liew 		asm("nop");
67a1436a84STsiChungLiew 
686d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		*(u32 *) (CONFIG_SYS_SDRAM_BASE + 0x800) = 0xa5a5a5a5;
69a1436a84STsiChungLiew 	}
70a1436a84STsiChungLiew 
71088454cdSSimon Glass 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
72088454cdSSimon Glass 
73088454cdSSimon Glass 	return 0;
74a1436a84STsiChungLiew }
75a1436a84STsiChungLiew 
testdram(void)76a1436a84STsiChungLiew int testdram(void)
77a1436a84STsiChungLiew {
78a1436a84STsiChungLiew 	/* TODO: XXX XXX XXX */
79a1436a84STsiChungLiew 	printf("DRAM test not implemented!\n");
80a1436a84STsiChungLiew 
81a1436a84STsiChungLiew 	return (0);
82a1436a84STsiChungLiew }
83a1436a84STsiChungLiew 
84*fc843a02SSimon Glass #ifdef CONFIG_IDE
85a1436a84STsiChungLiew #include <ata.h>
ide_preinit(void)86a1436a84STsiChungLiew int ide_preinit(void)
87a1436a84STsiChungLiew {
88a1436a84STsiChungLiew 	return (0);
89a1436a84STsiChungLiew }
90a1436a84STsiChungLiew 
ide_set_reset(int idereset)91a1436a84STsiChungLiew void ide_set_reset(int idereset)
92a1436a84STsiChungLiew {
9332dbaafaSAlison Wang 	atac_t *ata = (atac_t *) CONFIG_SYS_ATA_BASE_ADDR;
94a1436a84STsiChungLiew 	long period;
95a1436a84STsiChungLiew 	/*  t1,  t2,  t3,  t4,  t5,  t6,  t9, tRD,  tA */
96a1436a84STsiChungLiew 	int piotms[5][9] = { {70, 165, 60, 30, 50, 5, 20, 0, 35},	/* PIO 0 */
97a1436a84STsiChungLiew 	{50, 125, 45, 20, 35, 5, 15, 0, 35},	/* PIO 1 */
98a1436a84STsiChungLiew 	{30, 100, 30, 15, 20, 5, 10, 0, 35},	/* PIO 2 */
99a1436a84STsiChungLiew 	{30, 80, 30, 10, 20, 5, 10, 0, 35},	/* PIO 3 */
100a1436a84STsiChungLiew 	{25, 70, 20, 10, 20, 5, 10, 0, 35}	/* PIO 4 */
101a1436a84STsiChungLiew 	};
102a1436a84STsiChungLiew 
103a1436a84STsiChungLiew 	if (idereset) {
10432dbaafaSAlison Wang 		/* control reset */
10532dbaafaSAlison Wang 		out_8(&ata->cr, 0);
106a1436a84STsiChungLiew 		udelay(100);
107a1436a84STsiChungLiew 	} else {
108a1436a84STsiChungLiew 		mbar2_writeLong(CIM_MISCCR, CIM_MISCCR_CPUEND);
109a1436a84STsiChungLiew 
110a1436a84STsiChungLiew #define CALC_TIMING(t) (t + period - 1) / period
1116d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		period = 1000000000 / (CONFIG_SYS_CLK / 2);	/* period in ns */
112a1436a84STsiChungLiew 
113a1436a84STsiChungLiew 		/*ata->ton = CALC_TIMING (180); */
11432dbaafaSAlison Wang 		out_8(&ata->t1, CALC_TIMING(piotms[2][0]));
11532dbaafaSAlison Wang 		out_8(&ata->t2w, CALC_TIMING(piotms[2][1]));
11632dbaafaSAlison Wang 		out_8(&ata->t2r, CALC_TIMING(piotms[2][1]));
11732dbaafaSAlison Wang 		out_8(&ata->ta, CALC_TIMING(piotms[2][8]));
11832dbaafaSAlison Wang 		out_8(&ata->trd, CALC_TIMING(piotms[2][7]));
11932dbaafaSAlison Wang 		out_8(&ata->t4, CALC_TIMING(piotms[2][3]));
12032dbaafaSAlison Wang 		out_8(&ata->t9, CALC_TIMING(piotms[2][6]));
121a1436a84STsiChungLiew 
12232dbaafaSAlison Wang 		/* IORDY enable */
12332dbaafaSAlison Wang 		out_8(&ata->cr, 0x40);
124a1436a84STsiChungLiew 		udelay(2000);
12532dbaafaSAlison Wang 		/* IORDY enable */
12632dbaafaSAlison Wang 		setbits_8(&ata->cr, 0x01);
127a1436a84STsiChungLiew 	}
128a1436a84STsiChungLiew }
129*fc843a02SSimon Glass #endif				/* CONFIG_IDE */
130