1a1436a84STsiChungLiew /* 2a1436a84STsiChungLiew * (C) Copyright 2000-2003 3a1436a84STsiChungLiew * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4a1436a84STsiChungLiew * 5*32dbaafaSAlison Wang * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc. 6a1436a84STsiChungLiew * Hayden Fraser (Hayden.Fraser@freescale.com) 7a1436a84STsiChungLiew * 8a1436a84STsiChungLiew * See file CREDITS for list of people who contributed to this 9a1436a84STsiChungLiew * project. 10a1436a84STsiChungLiew * 11a1436a84STsiChungLiew * This program is free software; you can redistribute it and/or 12a1436a84STsiChungLiew * modify it under the terms of the GNU General Public License as 13a1436a84STsiChungLiew * published by the Free Software Foundation; either version 2 of 14a1436a84STsiChungLiew * the License, or (at your option) any later version. 15a1436a84STsiChungLiew * 16a1436a84STsiChungLiew * This program is distributed in the hope that it will be useful, 17a1436a84STsiChungLiew * but WITHOUT ANY WARRANTY; without even the implied warranty of 18a1436a84STsiChungLiew * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19a1436a84STsiChungLiew * GNU General Public License for more details. 20a1436a84STsiChungLiew * 21a1436a84STsiChungLiew * You should have received a copy of the GNU General Public License 22a1436a84STsiChungLiew * along with this program; if not, write to the Free Software 23a1436a84STsiChungLiew * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 24a1436a84STsiChungLiew * MA 02111-1307 USA 25a1436a84STsiChungLiew */ 26a1436a84STsiChungLiew 27a1436a84STsiChungLiew #include <common.h> 28a1436a84STsiChungLiew #include <asm/immap.h> 29*32dbaafaSAlison Wang #include <asm/io.h> 30a1436a84STsiChungLiew 31a1436a84STsiChungLiew int checkboard(void) 32a1436a84STsiChungLiew { 33a1436a84STsiChungLiew puts("Board: "); 34a1436a84STsiChungLiew puts("Freescale MCF5253 EVBE\n"); 35a1436a84STsiChungLiew return 0; 36a1436a84STsiChungLiew }; 37a1436a84STsiChungLiew 389973e3c6SBecky Bruce phys_size_t initdram(int board_type) 39a1436a84STsiChungLiew { 40a1436a84STsiChungLiew /* 41a1436a84STsiChungLiew * Check to see if the SDRAM has already been initialized 42a1436a84STsiChungLiew * by a run control tool 43a1436a84STsiChungLiew */ 44a1436a84STsiChungLiew if (!(mbar_readLong(MCFSIM_DCR) & 0x8000)) { 45a1436a84STsiChungLiew u32 RC, dramsize; 46a1436a84STsiChungLiew 476d0f6bcfSJean-Christophe PLAGNIOL-VILLARD RC = (CONFIG_SYS_CLK / 1000000) >> 1; 48a1436a84STsiChungLiew RC = (RC * 15) >> 4; 49a1436a84STsiChungLiew 50a1436a84STsiChungLiew /* Initialize DRAM Control Register: DCR */ 51a1436a84STsiChungLiew mbar_writeShort(MCFSIM_DCR, (0x8400 | RC)); 52d361307eSTsiChung Liew asm("nop"); 53a1436a84STsiChungLiew 54d361307eSTsiChung Liew mbar_writeLong(MCFSIM_DACR0, 0x00002320); 55d361307eSTsiChung Liew asm("nop"); 56a1436a84STsiChungLiew 57a1436a84STsiChungLiew /* Initialize DMR0 */ 586d0f6bcfSJean-Christophe PLAGNIOL-VILLARD dramsize = ((CONFIG_SYS_SDRAM_SIZE << 20) - 1) & 0xFFFC0000; 59a1436a84STsiChungLiew mbar_writeLong(MCFSIM_DMR0, dramsize | 1); 60d361307eSTsiChung Liew asm("nop"); 61a1436a84STsiChungLiew 62d361307eSTsiChung Liew mbar_writeLong(MCFSIM_DACR0, 0x00002328); 63d361307eSTsiChung Liew asm("nop"); 64a1436a84STsiChungLiew 65a1436a84STsiChungLiew /* Write to this block to initiate precharge */ 666d0f6bcfSJean-Christophe PLAGNIOL-VILLARD *(u32 *) (CONFIG_SYS_SDRAM_BASE) = 0xa5a5a5a5; 67d361307eSTsiChung Liew asm("nop"); 68a1436a84STsiChungLiew 69a1436a84STsiChungLiew /* Set RE bit in DACR */ 70a1436a84STsiChungLiew mbar_writeLong(MCFSIM_DACR0, 71a1436a84STsiChungLiew mbar_readLong(MCFSIM_DACR0) | 0x8000); 72d361307eSTsiChung Liew asm("nop"); 73a1436a84STsiChungLiew 74a1436a84STsiChungLiew /* Wait for at least 8 auto refresh cycles to occur */ 75a1436a84STsiChungLiew udelay(500); 76a1436a84STsiChungLiew 77a1436a84STsiChungLiew /* Finish the configuration by issuing the MRS */ 78a1436a84STsiChungLiew mbar_writeLong(MCFSIM_DACR0, 79a1436a84STsiChungLiew mbar_readLong(MCFSIM_DACR0) | 0x0040); 80d361307eSTsiChung Liew asm("nop"); 81a1436a84STsiChungLiew 826d0f6bcfSJean-Christophe PLAGNIOL-VILLARD *(u32 *) (CONFIG_SYS_SDRAM_BASE + 0x800) = 0xa5a5a5a5; 83a1436a84STsiChungLiew } 84a1436a84STsiChungLiew 856d0f6bcfSJean-Christophe PLAGNIOL-VILLARD return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; 86a1436a84STsiChungLiew } 87a1436a84STsiChungLiew 88a1436a84STsiChungLiew int testdram(void) 89a1436a84STsiChungLiew { 90a1436a84STsiChungLiew /* TODO: XXX XXX XXX */ 91a1436a84STsiChungLiew printf("DRAM test not implemented!\n"); 92a1436a84STsiChungLiew 93a1436a84STsiChungLiew return (0); 94a1436a84STsiChungLiew } 95a1436a84STsiChungLiew 96a1436a84STsiChungLiew #ifdef CONFIG_CMD_IDE 97a1436a84STsiChungLiew #include <ata.h> 98a1436a84STsiChungLiew int ide_preinit(void) 99a1436a84STsiChungLiew { 100a1436a84STsiChungLiew return (0); 101a1436a84STsiChungLiew } 102a1436a84STsiChungLiew 103a1436a84STsiChungLiew void ide_set_reset(int idereset) 104a1436a84STsiChungLiew { 105*32dbaafaSAlison Wang atac_t *ata = (atac_t *) CONFIG_SYS_ATA_BASE_ADDR; 106a1436a84STsiChungLiew long period; 107a1436a84STsiChungLiew /* t1, t2, t3, t4, t5, t6, t9, tRD, tA */ 108a1436a84STsiChungLiew int piotms[5][9] = { {70, 165, 60, 30, 50, 5, 20, 0, 35}, /* PIO 0 */ 109a1436a84STsiChungLiew {50, 125, 45, 20, 35, 5, 15, 0, 35}, /* PIO 1 */ 110a1436a84STsiChungLiew {30, 100, 30, 15, 20, 5, 10, 0, 35}, /* PIO 2 */ 111a1436a84STsiChungLiew {30, 80, 30, 10, 20, 5, 10, 0, 35}, /* PIO 3 */ 112a1436a84STsiChungLiew {25, 70, 20, 10, 20, 5, 10, 0, 35} /* PIO 4 */ 113a1436a84STsiChungLiew }; 114a1436a84STsiChungLiew 115a1436a84STsiChungLiew if (idereset) { 116*32dbaafaSAlison Wang /* control reset */ 117*32dbaafaSAlison Wang out_8(&ata->cr, 0); 118a1436a84STsiChungLiew udelay(100); 119a1436a84STsiChungLiew } else { 120a1436a84STsiChungLiew mbar2_writeLong(CIM_MISCCR, CIM_MISCCR_CPUEND); 121a1436a84STsiChungLiew 122a1436a84STsiChungLiew #define CALC_TIMING(t) (t + period - 1) / period 1236d0f6bcfSJean-Christophe PLAGNIOL-VILLARD period = 1000000000 / (CONFIG_SYS_CLK / 2); /* period in ns */ 124a1436a84STsiChungLiew 125a1436a84STsiChungLiew /*ata->ton = CALC_TIMING (180); */ 126*32dbaafaSAlison Wang out_8(&ata->t1, CALC_TIMING(piotms[2][0])); 127*32dbaafaSAlison Wang out_8(&ata->t2w, CALC_TIMING(piotms[2][1])); 128*32dbaafaSAlison Wang out_8(&ata->t2r, CALC_TIMING(piotms[2][1])); 129*32dbaafaSAlison Wang out_8(&ata->ta, CALC_TIMING(piotms[2][8])); 130*32dbaafaSAlison Wang out_8(&ata->trd, CALC_TIMING(piotms[2][7])); 131*32dbaafaSAlison Wang out_8(&ata->t4, CALC_TIMING(piotms[2][3])); 132*32dbaafaSAlison Wang out_8(&ata->t9, CALC_TIMING(piotms[2][6])); 133a1436a84STsiChungLiew 134*32dbaafaSAlison Wang /* IORDY enable */ 135*32dbaafaSAlison Wang out_8(&ata->cr, 0x40); 136a1436a84STsiChungLiew udelay(2000); 137*32dbaafaSAlison Wang /* IORDY enable */ 138*32dbaafaSAlison Wang setbits_8(&ata->cr, 0x01); 139a1436a84STsiChungLiew } 140a1436a84STsiChungLiew } 141a1436a84STsiChungLiew #endif /* CONFIG_CMD_IDE */ 142