Marian Balakowicz | c952aed | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
TsiChungLiew | 1692b48 | 2007-08-15 20:32:06 -0500 | [diff] [blame] | 9 | #include <asm/immap.h> |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 10 | |
| 11 | int checkboard (void) { |
| 12 | puts ("Board: Freescale M5271EVB\n"); |
| 13 | return 0; |
| 14 | }; |
| 15 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 16 | phys_size_t initdram (int board_type) { |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 17 | |
| 18 | int i; |
| 19 | |
| 20 | /* Enable Address lines 23-21 and lower 16bits of data path */ |
| 21 | mbar_writeByte(MCF_GPIO_PAR_AD, MCF_GPIO_AD_ADDR23 | |
| 22 | MCF_GPIO_AD_ADDR22 | MCF_GPIO_AD_ADDR21 | |
| 23 | MCF_GPIO_AD_DATAL); |
| 24 | |
| 25 | /* Set CS2 pin to be SD_CS0 */ |
| 26 | mbar_writeByte(MCF_GPIO_PAR_CS, mbar_readByte(MCF_GPIO_PAR_CS) |
| 27 | | MCF_GPIO_PAR_CS_PAR_CS2); |
| 28 | |
| 29 | /* Configure SDRAM Control Pin Assignemnt Register */ |
| 30 | mbar_writeByte(MCF_GPIO_PAR_SDRAM, MCF_GPIO_SDRAM_CSSDCS_00 | |
| 31 | MCF_GPIO_SDRAM_SDWE | MCF_GPIO_SDRAM_SCAS | |
| 32 | MCF_GPIO_SDRAM_SRAS | MCF_GPIO_SDRAM_SCKE | |
| 33 | MCF_GPIO_SDRAM_SDCS_11); |
TsiChung Liew | 7c1822e | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 34 | asm(" nop"); |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Check to see if the SDRAM has already been initialized |
| 38 | * by a run control tool |
| 39 | */ |
Wolfgang Denk | c2c4944 | 2006-05-10 17:43:20 +0200 | [diff] [blame] | 40 | if (!(mbar_readLong(MCF_SDRAMC_DACR0) & MCF_SDRAMC_DACRn_RE)) { |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 41 | /* Initialize DRAM Control Register: DCR */ |
Wolfgang Denk | c2c4944 | 2006-05-10 17:43:20 +0200 | [diff] [blame] | 42 | mbar_writeShort(MCF_SDRAMC_DCR, |
TsiChung Liew | 7c1822e | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 43 | MCF_SDRAMC_DCR_RTIM(2) |
| 44 | | MCF_SDRAMC_DCR_RC(0x2E)); |
| 45 | asm(" nop"); |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Initialize DACR0 |
| 49 | * |
| 50 | * CASL: 01 |
| 51 | * CBM: cmd at A20, bank select bits 21 and up |
| 52 | * PS: 32bit port size |
| 53 | */ |
| 54 | mbar_writeLong(MCF_SDRAMC_DACR0, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 55 | MCF_SDRAMC_DACRn_BA(CONFIG_SYS_SDRAM_BASE>>18) |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 56 | | MCF_SDRAMC_DACRn_CASL(1) |
| 57 | | MCF_SDRAMC_DACRn_CBM(3) |
| 58 | | MCF_SDRAMC_DACRn_PS(0)); |
TsiChung Liew | 7c1822e | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 59 | asm(" nop"); |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 60 | |
| 61 | /* Initialize DMR0 */ |
Wolfgang Denk | c2c4944 | 2006-05-10 17:43:20 +0200 | [diff] [blame] | 62 | mbar_writeLong(MCF_SDRAMC_DMR0, |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 63 | MCF_SDRAMC_DMRn_BAM_16M |
| 64 | | MCF_SDRAMC_DMRn_V); |
TsiChung Liew | 7c1822e | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 65 | asm(" nop"); |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 66 | |
| 67 | /* Set IP bit in DACR */ |
| 68 | mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0) |
| 69 | | MCF_SDRAMC_DACRn_IP); |
TsiChung Liew | 7c1822e | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 70 | asm(" nop"); |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 71 | |
| 72 | /* Wait at least 20ns to allow banks to precharge */ |
| 73 | for (i = 0; i < 5; i++) |
| 74 | asm(" nop"); |
| 75 | |
| 76 | /* Write to this block to initiate precharge */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 77 | *(u32 *)(CONFIG_SYS_SDRAM_BASE) = 0xa5a5a5a5; |
TsiChung Liew | 7c1822e | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 78 | asm(" nop"); |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 79 | |
| 80 | /* Set RE bit in DACR */ |
| 81 | mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0) |
| 82 | | MCF_SDRAMC_DACRn_RE); |
| 83 | |
| 84 | /* Wait for at least 8 auto refresh cycles to occur */ |
| 85 | for (i = 0; i < 2000; i++) |
| 86 | asm(" nop"); |
| 87 | |
| 88 | /* Finish the configuration by issuing the MRS */ |
| 89 | mbar_writeLong(MCF_SDRAMC_DACR0, mbar_readLong(MCF_SDRAMC_DACR0) |
| 90 | | MCF_SDRAMC_DACRn_MRS); |
TsiChung Liew | 7c1822e | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 91 | asm(" nop"); |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | * Write to the SDRAM Mode Register A0-A11 = 0x400 |
| 95 | * |
| 96 | * Write Burst Mode = Programmed Burst Length |
| 97 | * Op Mode = Standard Op |
| 98 | * CAS Latency = 2 |
| 99 | * Burst Type = Sequential |
| 100 | * Burst Length = 1 |
| 101 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 102 | *(u32 *)(CONFIG_SYS_SDRAM_BASE + 0x400) = 0xa5a5a5a5; |
TsiChung Liew | 7c1822e | 2010-03-10 16:14:01 -0600 | [diff] [blame] | 103 | asm(" nop"); |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 104 | } |
| 105 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 106 | return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; |
Marian Balakowicz | c952aed | 2006-05-09 11:54:44 +0200 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | int testdram (void) { |
| 110 | |
| 111 | /* TODO: XXX XXX XXX */ |
| 112 | printf ("DRAM test not implemented!\n"); |
| 113 | |
| 114 | return (0); |
| 115 | } |