Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
| 5 | * Based on code provided from UDTech and AMCC |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <config.h> |
| 27 | #include <ppc4xx.h> |
| 28 | |
| 29 | #include <ppc_asm.tmpl> |
| 30 | #include <ppc_defs.h> |
| 31 | |
| 32 | #define mtsdram_as(reg, value) \ |
| 33 | addi r4,0,reg ; \ |
| 34 | mtdcr memcfga,r4 ; \ |
| 35 | addis r4,0,value@h ; \ |
| 36 | ori r4,r4,value@l ; \ |
| 37 | mtdcr memcfgd,r4 ; |
| 38 | |
| 39 | .globl ext_bus_cntlr_init |
| 40 | ext_bus_cntlr_init: |
Stefan Roese | 3d6cb3b | 2007-11-03 12:08:28 +0100 | [diff] [blame] | 41 | #if !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL) |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * DDR2 setup |
| 45 | */ |
| 46 | |
| 47 | /* Following the DDR Core Manual, here is the initialization */ |
| 48 | |
| 49 | /* Step 1 */ |
| 50 | |
| 51 | /* Step 2 */ |
| 52 | |
| 53 | /* Step 3 */ |
| 54 | |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 55 | /* base=00000000, size=256MByte (6), mode=7 (n*10*8) */ |
| 56 | mtsdram_as(SDRAM_MB0CF, 0x00006701); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 57 | |
| 58 | /* SET SDRAM_MB1CF - Not enabled */ |
| 59 | mtsdram_as(SDRAM_MB1CF, 0x00000000); |
| 60 | |
| 61 | /* SET SDRAM_MB2CF - Not enabled */ |
| 62 | mtsdram_as(SDRAM_MB2CF, 0x00000000); |
| 63 | |
| 64 | /* SET SDRAM_MB3CF - Not enabled */ |
| 65 | mtsdram_as(SDRAM_MB3CF, 0x00000000); |
| 66 | |
| 67 | /* SDRAM_CLKTR: Adv Addr clock by 90 deg */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 68 | mtsdram_as(SDRAM_CLKTR, 0x80000000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 69 | |
| 70 | /* Refresh Time register (0x30) Refresh every 7.8125uS */ |
| 71 | mtsdram_as(SDRAM_RTR, 0x06180000); |
| 72 | |
| 73 | /* SDRAM_SDTR1 */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 74 | mtsdram_as(SDRAM_SDTR1, 0x80201000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 75 | |
| 76 | /* SDRAM_SDTR2 */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 77 | mtsdram_as(SDRAM_SDTR2, 0x32204232); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 78 | |
| 79 | /* SDRAM_SDTR3 */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 80 | mtsdram_as(SDRAM_SDTR3, 0x080b0d1a); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 81 | |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 82 | mtsdram_as(SDRAM_MMODE, 0x00000442); |
| 83 | mtsdram_as(SDRAM_MEMODE, 0x00000404); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 84 | |
| 85 | /* SDRAM0_MCOPT1 (0X20) No ECC Gen */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 86 | mtsdram_as(SDRAM_MCOPT1, 0x04322000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 87 | |
| 88 | /* NOP */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 89 | mtsdram_as(SDRAM_INITPLR0, 0xa8380000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 90 | /* precharge 3 DDR clock cycle */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 91 | mtsdram_as(SDRAM_INITPLR1, 0x81900400); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 92 | /* EMR2 twr = 2tck */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 93 | mtsdram_as(SDRAM_INITPLR2, 0x81020000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 94 | /* EMR3 twr = 2tck */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 95 | mtsdram_as(SDRAM_INITPLR3, 0x81030000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 96 | /* EMR DLL ENABLE twr = 2tck */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 97 | mtsdram_as(SDRAM_INITPLR4, 0x81010404); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 98 | /* MR w/ DLL reset |
| 99 | * Note: 5 is CL. May need to be changed |
| 100 | */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 101 | mtsdram_as(SDRAM_INITPLR5, 0x81000542); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 102 | /* precharge 3 DDR clock cycle */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 103 | mtsdram_as(SDRAM_INITPLR6, 0x81900400); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 104 | /* Auto-refresh trfc = 26tck */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 105 | mtsdram_as(SDRAM_INITPLR7, 0x8D080000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 106 | /* Auto-refresh trfc = 26tck */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 107 | mtsdram_as(SDRAM_INITPLR8, 0x8D080000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 108 | /* Auto-refresh */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 109 | mtsdram_as(SDRAM_INITPLR9, 0x8D080000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 110 | /* Auto-refresh */ |
| 111 | mtsdram_as(SDRAM_INITPLR10, 0x8D080000); |
| 112 | /* MRS - normal operation; wait 2 cycle (set wait to tMRD) */ |
| 113 | mtsdram_as(SDRAM_INITPLR11, 0x81000442); |
| 114 | mtsdram_as(SDRAM_INITPLR12, 0x81010780); |
| 115 | mtsdram_as(SDRAM_INITPLR13, 0x81010400); |
| 116 | mtsdram_as(SDRAM_INITPLR14, 0x00000000); |
| 117 | mtsdram_as(SDRAM_INITPLR15, 0x00000000); |
| 118 | |
| 119 | /* SET MCIF0_CODT Die Termination On */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 120 | mtsdram_as(SDRAM_CODT, 0x0080f837); |
| 121 | mtsdram_as(SDRAM_MODT0, 0x01800000); |
| 122 | mtsdram_as(SDRAM_MODT1, 0x00000000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 123 | |
| 124 | mtsdram_as(SDRAM_WRDTR, 0x00000000); |
| 125 | |
| 126 | /* SDRAM0_MCOPT2 (0X21) Start initialization */ |
| 127 | mtsdram_as(SDRAM_MCOPT2, 0x20000000); |
| 128 | |
| 129 | /* Step 5 */ |
| 130 | lis r3,0x1 /* 400000 = wait 100ms */ |
| 131 | mtctr r3 |
| 132 | |
| 133 | pll_wait: |
| 134 | bdnz pll_wait |
| 135 | |
| 136 | /* Step 6 */ |
| 137 | |
| 138 | /* SDRAM_DLCR */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 139 | mtsdram_as(SDRAM_DLCR, 0x030000a5); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 140 | |
| 141 | /* SDRAM_RDCC */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 142 | mtsdram_as(SDRAM_RDCC, 0x40000000); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 143 | |
| 144 | /* SDRAM_RQDC */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 145 | mtsdram_as(SDRAM_RQDC, 0x80000038); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 146 | |
| 147 | /* SDRAM_RFDC */ |
Stefan Roese | 770c7af | 2007-10-21 08:05:18 +0200 | [diff] [blame] | 148 | mtsdram_as(SDRAM_RFDC, 0x00000209); |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 149 | |
| 150 | /* Enable memory controller */ |
| 151 | mtsdram_as(SDRAM_MCOPT2, 0x28000000); |
Stefan Roese | 3d6cb3b | 2007-11-03 12:08:28 +0100 | [diff] [blame] | 152 | #endif /* #ifndef CONFIG_NAND_U_BOOT */ |
Stefan Roese | 566806c | 2007-10-05 17:11:30 +0200 | [diff] [blame] | 153 | |
| 154 | blr |