Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2006 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
TsiChungLiew | f28e1bd | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 25 | #include <asm/immap.h> |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 26 | |
| 27 | int checkboard (void) { |
| 28 | puts ("Board: Freescale M5271EVB\n"); |
| 29 | return 0; |
| 30 | }; |
| 31 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 32 | phys_size_t initdram (int board_type) { |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 33 | |
| 34 | int i; |
| 35 | |
| 36 | /* Enable Address lines 23-21 and lower 16bits of data path */ |
| 37 | mbar_writeByte(MCF_GPIO_PAR_AD, MCF_GPIO_AD_ADDR23 | |
| 38 | MCF_GPIO_AD_ADDR22 | MCF_GPIO_AD_ADDR21 | |
| 39 | MCF_GPIO_AD_DATAL); |
| 40 | |
| 41 | /* Set CS2 pin to be SD_CS0 */ |
| 42 | mbar_writeByte(MCF_GPIO_PAR_CS, mbar_readByte(MCF_GPIO_PAR_CS) |
| 43 | | MCF_GPIO_PAR_CS_PAR_CS2); |
| 44 | |
| 45 | /* Configure SDRAM Control Pin Assignemnt Register */ |
| 46 | mbar_writeByte(MCF_GPIO_PAR_SDRAM, MCF_GPIO_SDRAM_CSSDCS_00 | |
| 47 | MCF_GPIO_SDRAM_SDWE | MCF_GPIO_SDRAM_SCAS | |
| 48 | MCF_GPIO_SDRAM_SRAS | MCF_GPIO_SDRAM_SCKE | |
| 49 | MCF_GPIO_SDRAM_SDCS_11); |
TsiChung Liew | 53e4290 | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 50 | asm(" nop"); |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Check to see if the SDRAM has already been initialized |
| 54 | * by a run control tool |
| 55 | */ |
Wolfgang Denk | 977b50f | 2006-05-10 17:43:20 +0200 | [diff] [blame] | 56 | if (!(mbar_readLong(MCF_SDRAMC_DACR0) & MCF_SDRAMC_DACRn_RE)) { |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 57 | /* Initialize DRAM Control Register: DCR */ |
Wolfgang Denk | 977b50f | 2006-05-10 17:43:20 +0200 | [diff] [blame] | 58 | mbar_writeShort(MCF_SDRAMC_DCR, |
TsiChung Liew | 53e4290 | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 59 | MCF_SDRAMC_DCR_RTIM(2) |
| 60 | | MCF_SDRAMC_DCR_RC(0x2E)); |
| 61 | asm(" nop"); |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | * Initialize DACR0 |
| 65 | * |
| 66 | * CASL: 01 |
| 67 | * CBM: cmd at A20, bank select bits 21 and up |
| 68 | * PS: 32bit port size |
| 69 | */ |
| 70 | mbar_writeLong(MCF_SDRAMC_DACR0, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 71 | MCF_SDRAMC_DACRn_BA(CONFIG_SYS_SDRAM_BASE>>18) |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 72 | | MCF_SDRAMC_DACRn_CASL(1) |
| 73 | | MCF_SDRAMC_DACRn_CBM(3) |
| 74 | | MCF_SDRAMC_DACRn_PS(0)); |
TsiChung Liew | 53e4290 | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 75 | asm(" nop"); |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 76 | |
| 77 | /* Initialize DMR0 */ |
Wolfgang Denk | 977b50f | 2006-05-10 17:43:20 +0200 | [diff] [blame] | 78 | mbar_writeLong(MCF_SDRAMC_DMR0, |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 79 | MCF_SDRAMC_DMRn_BAM_16M |
| 80 | | MCF_SDRAMC_DMRn_V); |
TsiChung Liew | 53e4290 | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 81 | asm(" nop"); |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 82 | |
| 83 | /* Set IP bit in DACR */ |
| 84 | mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0) |
| 85 | | MCF_SDRAMC_DACRn_IP); |
TsiChung Liew | 53e4290 | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 86 | asm(" nop"); |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 87 | |
| 88 | /* Wait at least 20ns to allow banks to precharge */ |
| 89 | for (i = 0; i < 5; i++) |
| 90 | asm(" nop"); |
| 91 | |
| 92 | /* Write to this block to initiate precharge */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 93 | *(u32 *)(CONFIG_SYS_SDRAM_BASE) = 0xa5a5a5a5; |
TsiChung Liew | 53e4290 | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 94 | asm(" nop"); |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 95 | |
| 96 | /* Set RE bit in DACR */ |
| 97 | mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0) |
| 98 | | MCF_SDRAMC_DACRn_RE); |
| 99 | |
| 100 | /* Wait for at least 8 auto refresh cycles to occur */ |
| 101 | for (i = 0; i < 2000; i++) |
| 102 | asm(" nop"); |
| 103 | |
| 104 | /* Finish the configuration by issuing the MRS */ |
| 105 | mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0) |
| 106 | | MCF_SDRAMC_DACRn_MRS); |
TsiChung Liew | 53e4290 | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 107 | asm(" nop"); |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * Write to the SDRAM Mode Register A0-A11 = 0x400 |
| 111 | * |
| 112 | * Write Burst Mode = Programmed Burst Length |
| 113 | * Op Mode = Standard Op |
| 114 | * CAS Latency = 2 |
| 115 | * Burst Type = Sequential |
| 116 | * Burst Length = 1 |
| 117 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 118 | *(u32 *)(CONFIG_SYS_SDRAM_BASE + 0x400) = 0xa5a5a5a5; |
TsiChung Liew | 53e4290 | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 119 | asm(" nop"); |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 122 | return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; |
Marian Balakowicz | 78b123c | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | int testdram (void) { |
| 126 | |
| 127 | /* TODO: XXX XXX XXX */ |
| 128 | printf ("DRAM test not implemented!\n"); |
| 129 | |
| 130 | return (0); |
| 131 | } |