roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 1 | /* |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 2 | * (C) Copyright 2004-05; Tundra Semiconductor Corp. |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 3 | * |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 4 | * Added automatic detect of SDC settings |
| 5 | * Copyright (c) 2005 Freescale Semiconductor, Inc. |
| 6 | * Maintainer tie-fei.zang@freescale.com |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 7 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 9 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 10 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 11 | /* |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 12 | * FILENAME: asm_init.s |
| 13 | * |
| 14 | * Originator: Alex Bounine |
| 15 | * |
| 16 | * DESCRIPTION: |
| 17 | * Initialization code for the Tundra Tsi108 bridge chip |
| 18 | * |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 19 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 20 | |
| 21 | #include <config.h> |
| 22 | #include <version.h> |
| 23 | |
| 24 | #include <ppc_asm.tmpl> |
| 25 | #include <ppc_defs.h> |
| 26 | #include <asm/processor.h> |
| 27 | |
| 28 | #include <tsi108.h> |
| 29 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 30 | /* |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 31 | * Build Configuration Options |
| 32 | */ |
| 33 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 34 | /* #define DISABLE_PBM disables usage of PB Master */ |
| 35 | /* #define SDC_HARDCODED_INIT config SDRAM controller with hardcoded values */ |
| 36 | /* #define SDC_AUTOPRECH_EN enable SDRAM auto precharge */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 37 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 38 | /* |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 39 | * Hardcoded SDC settings |
| 40 | */ |
| 41 | |
| 42 | #ifdef SDC_HARDCODED_INIT |
| 43 | |
| 44 | /* Micron MT9HTF6472AY-40EA1 : Unbuffered, 512MB, 400, CL3, Single Rank */ |
| 45 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 46 | #define VAL_SD_REFRESH (0x61A) |
| 47 | #define VAL_SD_TIMING (0x0308336b) |
| 48 | #define VAL_SD_D0_CTRL (0x07100021) /* auto-precharge disabled */ |
| 49 | #define VAL_SD_D0_BAR (0x0FE00000) /* 512MB @ 0x00000000 */ |
| 50 | #define VAL_SD_D1_CTRL (0x07100021) /* auto-precharge disabled */ |
| 51 | #define VAL_SD_D1_BAR (0x0FE00200) /* 512MB @ 0x20000000 */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 52 | |
| 53 | #endif /* SDC_HARDCODED_INIT */ |
| 54 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 55 | /* |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 56 | CPU Configuration: |
| 57 | |
| 58 | CPU Address and Data Parity enables. |
| 59 | |
| 60 | #define CPU_AP |
| 61 | #define CPU_DP |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 62 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 63 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 64 | /* |
| 65 | * Macros |
| 66 | * !!! Attention !!! Macros LOAD_PTR, LOAD_U32 and LOAD_MEM defined below are |
| 67 | * expected to work correctly for the CSR space within 32KB range. |
| 68 | * |
| 69 | * LOAD_PTR and LOAD_U32 - load specified register with a 32 bit constant. |
| 70 | * These macros are absolutely identical except their names. This difference |
| 71 | * is provided intentionally for better readable code. |
| 72 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 73 | |
| 74 | #define LOAD_PTR(reg,const32) \ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 75 | addis reg,r0,const32@h; ori reg,reg,const32@l |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 76 | |
| 77 | #define LOAD_U32(reg,const32) \ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 78 | addis reg,r0,const32@h; ori reg,reg,const32@l |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 79 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 80 | /* LOADMEM initializes a register with the contents of a specified 32-bit |
| 81 | * memory location, usually a CSR value. |
| 82 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 83 | |
| 84 | #define LOAD_MEM(reg,addr32) \ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 85 | addis reg,r0,addr32@ha; lwz reg,addr32@l(reg) |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 86 | |
| 87 | #ifndef SDC_HARDCODED_INIT |
| 88 | sdc_clk_sync: |
| 89 | /* MHz: 0,0,183,100,133,167,200,233 */ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 90 | .long 0, 0, 6, 10, 8, 6, 5, 4 /* nSec */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 91 | #endif |
| 92 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 93 | /* |
| 94 | * board_asm_init() - early initialization function. Coded to be portable to |
| 95 | * dual-CPU configuration. |
| 96 | * Checks CPU number and performs board HW initialization if called for CPU0. |
| 97 | * Registers used: r3,r4,r5,r6,r19,r29 |
| 98 | * |
| 99 | * NOTE: For dual-CPU configuration only CPU0 is allowed to configure Tsi108 |
| 100 | * and the rest of the board. Current implementation demonstrates two |
| 101 | * possible ways to identify CPU number: |
| 102 | * - for MPC74xx platform: uses MSSCR0[ID] bit as defined in UM. |
| 103 | * - for PPC750FX/GX boards: uses WHO_AM_I bit reported by Tsi108. |
| 104 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 105 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 106 | .globl board_asm_init |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 107 | board_asm_init: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 108 | mflr r19 /* Save LR to be able return later. */ |
| 109 | bl icache_enable /* Enable icache to reduce reads from flash. */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 110 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 111 | /* Initialize pointer to Tsi108 register space */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 112 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 113 | LOAD_PTR(r29,CONFIG_SYS_TSI108_CSR_RST_BASE)/* r29 - pointer to tsi108 CSR space */ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 114 | ori r4,r29,TSI108_PB_REG_OFFSET |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 115 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 116 | /* Check Processor Version Number */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 117 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 118 | mfspr r3, PVR |
| 119 | rlwinm r3,r3,16,16,23 /* get ((Processor Version Number) & 0xFF00) */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 120 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 121 | cmpli 0,0,r3,0x8000 /* MPC74xx */ |
| 122 | bne cont_brd_init |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 123 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 124 | /* |
| 125 | * For MPC744x/5x enable extended BATs[4-7] |
| 126 | * Sri: Set HIGH_BAT_EN and XBSEN, and SPD =1 |
| 127 | * to disable prefetch |
| 128 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 129 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 130 | mfspr r5, HID0 |
| 131 | oris r5, r5, 0x0080 /* Set HID0[HIGH_BAT_EN] bit #8 */ |
| 132 | ori r5, r5, 0x0380 /* Set SPD,XBSEN,SGE bits #22,23,24 */ |
| 133 | mtspr HID0, r5 |
| 134 | isync |
| 135 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 136 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 137 | /* Adding code to disable external interventions in MPX bus mode */ |
| 138 | mfspr r3, 1014 |
| 139 | oris r3, r3, 0x0100 /* Set the EIDIS bit in MSSCR0: bit 7 */ |
| 140 | mtspr 1014, r3 |
| 141 | isync |
| 142 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 143 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 144 | /* Sri: code to enable FP unit */ |
| 145 | mfmsr r3 |
| 146 | ori r3, r3, 0x2000 |
| 147 | mtmsr r3 |
| 148 | isync |
| 149 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 150 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 151 | /* def CONFIG_DUAL_CPU |
| 152 | * For MPC74xx processor, use MSSCR0[ID] bit to identify CPU number. |
| 153 | */ |
| 154 | #if(1) |
| 155 | mfspr r3,1014 /* read MSSCR0 */ |
| 156 | rlwinm. r3,r3,27,31,31 /* get processor ID number */ |
| 157 | mtspr SPRN_PIR,r3 /* Save CPU ID */ |
| 158 | sync |
| 159 | bne init_done |
| 160 | b do_tsi108_init |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 161 | |
| 162 | cont_brd_init: |
| 163 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 164 | /* An alternative method of checking the processor number (in addition |
| 165 | * to configuration using MSSCR0[ID] bit on MPC74xx). |
| 166 | * Good for IBM PPC750FX/GX. |
| 167 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 168 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 169 | lwz r3,PB_BUS_MS_SELECT(r4) /* read PB_ID register */ |
| 170 | rlwinm. r3,r3,24,31,31 /* get processor ID number */ |
| 171 | bne init_done |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 172 | #else |
| 173 | |
| 174 | cont_brd_init: |
| 175 | |
| 176 | #endif /* CONFIG_DUAL_CPU */ |
| 177 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 178 | /* Initialize Tsi108 chip */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 179 | |
| 180 | do_tsi108_init: |
| 181 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 182 | /* |
| 183 | * Adjust HLP/Flash parameters. By default after reset the HLP port is |
| 184 | * set to support slow devices. Better performance can be achived when |
| 185 | * an optimal parameters are used for specific EPROM device. |
| 186 | * NOTE: This should be performed ASAP for the emulation platform |
| 187 | * because it has 5MHz HLP clocking. |
| 188 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 189 | |
| 190 | #ifdef CONFIG_TSI108EMU |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 191 | ori r4,r29,TSI108_HLP_REG_OFFSET |
| 192 | LOAD_U32(r5,0x434422c0) |
| 193 | stw r5,0x08(r4) /* set HLP B0_CTRL0 */ |
| 194 | sync |
| 195 | LOAD_U32(r5,0xd0012000) |
| 196 | stw r5,0x0c(r4) /* set HLP B0_CTRL1 */ |
| 197 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 198 | #endif |
| 199 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 200 | /* Initialize PB interface. */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 201 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 202 | ori r4,r29,TSI108_PB_REG_OFFSET |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 203 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 204 | #if (CONFIG_SYS_TSI108_CSR_BASE != CONFIG_SYS_TSI108_CSR_RST_BASE) |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 205 | /* Relocate (if required) Tsi108 registers. Set new value for |
| 206 | * PB_REG_BAR: |
| 207 | * Note we are in the 32-bit address mode. |
| 208 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 209 | LOAD_U32(r5,(CONFIG_SYS_TSI108_CSR_BASE | 0x01)) /* PB_REG_BAR: BA + EN */ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 210 | stw r5,PB_REG_BAR(r4) |
| 211 | andis. r29,r5,0xFFFF |
| 212 | sync |
| 213 | ori r4,r29,TSI108_PB_REG_OFFSET |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 214 | #endif |
| 215 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 216 | /* Set PB Slave configuration register */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 217 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 218 | LOAD_U32(r5,0x00002481) /* PB_SCR: TEA enabled,AACK delay = 1 */ |
| 219 | lwz r3, PB_RSR(r4) /* get PB bus mode */ |
| 220 | xori r3,r3,0x0001 /* mask PB_BMODE: r3 -> (0 = 60X, 1 = MPX) */ |
| 221 | rlwimi r5,r3,14,17,17 /* for MPX: set DTI_MODE bit */ |
| 222 | stw r5,PB_SCR(r4) |
| 223 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 224 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 225 | /* Configure PB Arbiter */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 226 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 227 | lwz r5,PB_ARB_CTRL(r4) /* Read PB Arbiter Control Register */ |
| 228 | li r3, 0x00F0 /* ARB_PIPELINE_DEP mask */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 229 | #ifdef DISABLE_PBM |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 230 | ori r3,r3,0x1000 /* add PBM_EN to clear (enabled by default) */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 231 | #endif |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 232 | andc r5,r5,r3 /* Clear the masked bit fields */ |
| 233 | ori r5,r5,0x0001 /* Set pipeline depth */ |
| 234 | stw r5,PB_ARB_CTRL(r4) |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 235 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 236 | #if (0) /* currently using the default settings for PBM after reset */ |
| 237 | LOAD_U32(r5,0x) /* value for PB_MCR */ |
| 238 | stw r5,PB_MCR(r4) |
| 239 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 240 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 241 | LOAD_U32(r5,0x) /* value for PB_MCMD */ |
| 242 | stw r5,PB_MCMD(r4) |
| 243 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 244 | #endif |
| 245 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 246 | /* Disable or enable PVT based on processor bus frequency |
| 247 | * 1. Read CG_PWRUP_STATUS register field bits 18,17,16 |
| 248 | * 2. See if the value is < or > 133mhz (18:16 = 100) |
| 249 | * 3. If > enable PVT |
| 250 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 251 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 252 | LOAD_U32(r3,0xC0002234) |
| 253 | lwz r3,0(r3) |
| 254 | rlwinm r3,r3,16,29,31 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 255 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 256 | cmpi 0,0,r3,0x0004 |
| 257 | bgt sdc_init |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 258 | |
| 259 | #ifndef CONFIG_TSI108EMU |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 260 | /* FIXME: Disable PB calibration control for any real Tsi108 board */ |
| 261 | li r5,0x0101 /* disable calibration control */ |
| 262 | stw r5,PB_PVT_CTRL2(r4) |
| 263 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 264 | #endif |
| 265 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 266 | /* Initialize SDRAM controller. */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 267 | |
| 268 | sdc_init: |
| 269 | |
| 270 | #ifndef SDC_HARDCODED_INIT |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 271 | /* get SDC clock prior doing sdram controller autoconfig */ |
| 272 | ori r4,r29,TSI108_CLK_REG_OFFSET /* r4 - ptr to CG registers */ |
| 273 | lwz r3, CG_PWRUP_STATUS(r4) /* get CG configuration */ |
| 274 | rlwinm r3,r3,12,29,31 /* r3 - SD clk */ |
| 275 | lis r5,sdc_clk_sync@h |
| 276 | ori r5,r5,sdc_clk_sync@l |
| 277 | /* Sri: At this point check if r3 = 001. If yes, |
| 278 | * the memory frequency should be same as the |
| 279 | * MPX bus frequency |
| 280 | */ |
| 281 | cmpi 0,0,r3,0x0001 |
| 282 | bne get_nsec |
| 283 | lwz r6, CG_PWRUP_STATUS(r4) |
| 284 | rlwinm r6,r6,16,29,31 |
| 285 | mr r3,r6 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 286 | |
| 287 | get_nsec: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 288 | rlwinm r3,r3,2,0,31 |
| 289 | lwzx r9,r5,r3 /* get SD clk rate in nSec */ |
| 290 | /* ATTN: r9 will be used by SPD routine */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 291 | #endif /* !SDC_HARDCODED_INIT */ |
| 292 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 293 | ori r4,r29,TSI108_SD_REG_OFFSET /* r4 - ptr to SDRAM registers */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 294 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 295 | /* Initialize SDRAM controller. SDRAM Size = 512MB, One DIMM. */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 296 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 297 | LOAD_U32(r5,0x00) |
| 298 | stw r5,SD_INT_ENABLE(r4) /* Ensure that interrupts are disabled */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 299 | #ifdef ENABLE_SDRAM_ECC |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 300 | li r5, 0x01 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 301 | #endif /* ENABLE_SDRAM_ECC */ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 302 | stw r5,SD_ECC_CTRL(r4) /* Enable/Disable ECC */ |
| 303 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 304 | |
| 305 | #ifdef SDC_HARDCODED_INIT /* config sdram controller with hardcoded values */ |
| 306 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 307 | /* First read the CG_PWRUP_STATUS register to get the |
| 308 | * memory speed from bits 22,21,20 |
| 309 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 310 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 311 | LOAD_U32(r3,0xC0002234) |
| 312 | lwz r3,0(r3) |
| 313 | rlwinm r3,r3,12,29,31 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 314 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 315 | /* Now first check for 166, then 200, or default */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 316 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 317 | cmpi 0,0,r3,0x0005 |
| 318 | bne check_for_200mhz |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 319 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 320 | /* set values for 166 Mhz memory speed |
| 321 | * Set refresh rate and timing parameters |
| 322 | */ |
| 323 | LOAD_U32(r5,0x00000515) |
| 324 | stw r5,SD_REFRESH(r4) |
| 325 | LOAD_U32(r5,0x03073368) |
| 326 | stw r5,SD_TIMING(r4) |
| 327 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 328 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 329 | /* Initialize DIMM0 control and BAR registers */ |
| 330 | LOAD_U32(r5,VAL_SD_D0_CTRL) /* auto-precharge disabled */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 331 | #ifdef SDC_AUTOPRECH_EN |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 332 | oris r5,r5,0x0001 /* set auto precharge EN bit */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 333 | #endif |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 334 | stw r5,SD_D0_CTRL(r4) |
| 335 | LOAD_U32(r5,VAL_SD_D0_BAR) |
| 336 | stw r5,SD_D0_BAR(r4) |
| 337 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 338 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 339 | /* Initialize DIMM1 control and BAR registers |
| 340 | * (same as dimm 0, next 512MB, disabled) |
| 341 | */ |
| 342 | LOAD_U32(r5,VAL_SD_D1_CTRL) /* auto-precharge disabled */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 343 | #ifdef SDC_AUTOPRECH_EN |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 344 | oris r5,r5,0x0001 /* set auto precharge EN bit */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 345 | #endif |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 346 | stw r5,SD_D1_CTRL(r4) |
| 347 | LOAD_U32(r5,VAL_SD_D1_BAR) |
| 348 | stw r5,SD_D1_BAR(r4) |
| 349 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 350 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 351 | b sdc_init_done |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 352 | |
| 353 | check_for_200mhz: |
| 354 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 355 | cmpi 0,0,r3,0x0006 |
| 356 | bne set_default_values |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 357 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 358 | /* set values for 200Mhz memory speed |
| 359 | * Set refresh rate and timing parameters |
| 360 | */ |
| 361 | LOAD_U32(r5,0x0000061a) |
| 362 | stw r5,SD_REFRESH(r4) |
| 363 | LOAD_U32(r5,0x03083348) |
| 364 | stw r5,SD_TIMING(r4) |
| 365 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 366 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 367 | /* Initialize DIMM0 control and BAR registers */ |
| 368 | LOAD_U32(r5,VAL_SD_D0_CTRL) /* auto-precharge disabled */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 369 | #ifdef SDC_AUTOPRECH_EN |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 370 | oris r5,r5,0x0001 /* set auto precharge EN bit */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 371 | #endif |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 372 | stw r5,SD_D0_CTRL(r4) |
| 373 | LOAD_U32(r5,VAL_SD_D0_BAR) |
| 374 | stw r5,SD_D0_BAR(r4) |
| 375 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 376 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 377 | /* Initialize DIMM1 control and BAR registers |
| 378 | * (same as dimm 0, next 512MB, disabled) |
| 379 | */ |
| 380 | LOAD_U32(r5,VAL_SD_D1_CTRL) /* auto-precharge disabled */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 381 | #ifdef SDC_AUTOPRECH_EN |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 382 | oris r5,r5,0x0001 /* set auto precharge EN bit */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 383 | #endif |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 384 | stw r5,SD_D1_CTRL(r4) |
| 385 | LOAD_U32(r5,VAL_SD_D1_BAR) |
| 386 | stw r5,SD_D1_BAR(r4) |
| 387 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 388 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 389 | b sdc_init_done |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 390 | |
| 391 | set_default_values: |
| 392 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 393 | /* Set refresh rate and timing parameters */ |
| 394 | LOAD_U32(r5,VAL_SD_REFRESH) |
| 395 | stw r5,SD_REFRESH(r4) |
| 396 | LOAD_U32(r5,VAL_SD_TIMING) |
| 397 | stw r5,SD_TIMING(r4) |
| 398 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 399 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 400 | /* Initialize DIMM0 control and BAR registers */ |
| 401 | LOAD_U32(r5,VAL_SD_D0_CTRL) /* auto-precharge disabled */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 402 | #ifdef SDC_AUTOPRECH_EN |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 403 | oris r5,r5,0x0001 /* set auto precharge EN bit */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 404 | #endif |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 405 | stw r5,SD_D0_CTRL(r4) |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 406 | LOAD_U32(r5,VAL_SD_D0_BAR) |
| 407 | stw r5,SD_D0_BAR(r4) |
| 408 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 409 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 410 | /* Initialize DIMM1 control and BAR registers |
| 411 | * (same as dimm 0, next 512MB, disabled) |
| 412 | */ |
| 413 | LOAD_U32(r5,VAL_SD_D1_CTRL) /* auto-precharge disabled */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 414 | #ifdef SDC_AUTOPRECH_EN |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 415 | oris r5,r5,0x0001 /* set auto precharge EN bit */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 416 | #endif |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 417 | stw r5,SD_D1_CTRL(r4) |
| 418 | LOAD_U32(r5,VAL_SD_D1_BAR) |
| 419 | stw r5,SD_D1_BAR(r4) |
| 420 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 421 | #else /* !SDC_HARDCODED_INIT */ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 422 | bl tsi108_sdram_spd /* automatically detect SDC settings */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 423 | #endif /* SDC_HARDCODED_INIT */ |
| 424 | |
| 425 | sdc_init_done: |
| 426 | |
| 427 | #ifdef DISABLE_PBM |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 428 | LOAD_U32(r5,0x00000030) /* PB_EN + OCN_EN */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 429 | #else |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 430 | LOAD_U32(r5,0x00000230) /* PB_EN + OCN_EN + PB/OCN=80/20 */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 431 | #endif /* DISABLE_PBM */ |
| 432 | |
| 433 | #ifdef CONFIG_TSI108EMU |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 434 | oris r5,r5,0x0010 /* set EMULATION_MODE bit */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 435 | #endif |
| 436 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 437 | stw r5,SD_CTRL(r4) |
| 438 | eieio |
| 439 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 440 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 441 | /* Enable SDRAM access */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 442 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 443 | oris r5,r5,0x8000 /* start SDC: set SD_CTRL[ENABLE] bit */ |
| 444 | stw r5,SD_CTRL(r4) |
| 445 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 446 | |
| 447 | wait_init_complete: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 448 | lwz r5,SD_STATUS(r4) |
| 449 | andi. r5,r5,0x0001 |
| 450 | /* wait until SDRAM initialization is complete */ |
| 451 | beq wait_init_complete |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 452 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 453 | /* Map SDRAM into the processor bus address space */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 454 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 455 | ori r4,r29,TSI108_PB_REG_OFFSET |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 456 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 457 | /* Setup BARs associated with direct path PB<->SDRAM */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 458 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 459 | /* PB_SDRAM_BAR1: |
| 460 | * provides a direct path to the main system memory (cacheable SDRAM) |
| 461 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 462 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 463 | /* BA=0,Size=512MB, ENable, No Addr.Translation */ |
| 464 | LOAD_U32(r5, 0x00000011) |
| 465 | stw r5,PB_SDRAM_BAR1(r4) |
| 466 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 467 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 468 | /* Make sure that PB_SDRAM_BAR1 decoder is set |
| 469 | * (to allow following immediate read from SDRAM) |
| 470 | */ |
| 471 | lwz r5,PB_SDRAM_BAR1(r4) |
| 472 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 473 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 474 | /* PB_SDRAM_BAR2: |
| 475 | * provides non-cacheable alias (via the direct path) to main |
| 476 | * system memory. |
| 477 | * Size = 512MB, ENable, Addr.Translation - ON, |
| 478 | * BA = 0x0_40000000, TA = 0x0_00000000 |
| 479 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 480 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 481 | LOAD_U32(r5, 0x40010011) |
| 482 | stw r5,PB_SDRAM_BAR2(r4) |
| 483 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 484 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 485 | /* Make sure that PB_SDRAM_BAR2 decoder is set |
| 486 | * (to allow following immediate read from SDRAM) |
| 487 | */ |
| 488 | lwz r5,PB_SDRAM_BAR2(r4) |
| 489 | sync |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 490 | |
| 491 | init_done: |
| 492 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 493 | /* All done. Restore LR and return. */ |
| 494 | mtlr r19 |
| 495 | blr |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 496 | |
| 497 | #if (0) |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 498 | /* |
| 499 | * init_cpu1 |
| 500 | * This routine enables CPU1 on the dual-processor system. |
| 501 | * Now there is only one processor in the system |
| 502 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 503 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 504 | .global enable_cpu1 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 505 | enable_cpu1: |
| 506 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 507 | lis r3,Tsi108_Base@ha /* Get Grendel CSR Base Addr */ |
| 508 | addi r3,r3,Tsi108_Base@l |
| 509 | lwz r3,0(r3) /* R3 = CSR Base Addr */ |
| 510 | ori r4,r3,TSI108_PB_REG_OFFSET |
| 511 | lwz r3,PB_ARB_CTRL(r4) /* Read PB Arbiter Control Register */ |
| 512 | ori r3,r3,0x0200 /* Set M1_EN bit */ |
| 513 | stw r3,PB_ARB_CTRL(r4) |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 514 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 515 | blr |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 516 | #endif |
| 517 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 518 | /* |
| 519 | * enable_EI |
| 520 | * Enable CPU core external interrupt |
| 521 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 522 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 523 | .global enable_EI |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 524 | enable_EI: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 525 | mfmsr r3 |
| 526 | ori r3,r3,0x8000 /* set EE bit */ |
| 527 | mtmsr r3 |
| 528 | blr |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 529 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 530 | /* |
| 531 | * disable_EI |
| 532 | * Disable CPU core external interrupt |
| 533 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 534 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 535 | .global disable_EI |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 536 | disable_EI: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 537 | mfmsr r3 |
| 538 | li r4,-32768 /* aka "li r4,0x8000" */ |
| 539 | andc r3,r3,r4 /* clear EE bit */ |
| 540 | mtmsr r3 |
| 541 | blr |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 542 | |
| 543 | #ifdef ENABLE_SDRAM_ECC |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 544 | /* enables SDRAM ECC */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 545 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 546 | .global enable_ECC |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 547 | enable_ECC: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 548 | ori r4,r29,TSI108_SD_REG_OFFSET |
| 549 | lwz r3,SD_ECC_CTRL(r4) /* Read SDRAM ECC Control Register */ |
| 550 | ori r3,r3,0x0001 /* Set ECC_EN bit */ |
| 551 | stw r3,SD_ECC_CTRL(r4) |
| 552 | blr |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 553 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 554 | /* |
| 555 | * clear_ECC_err |
| 556 | * Clears all pending SDRAM ECC errors |
| 557 | * (normally after SDRAM scrubbing/initialization) |
| 558 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 559 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 560 | .global clear_ECC_err |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 561 | clear_ECC_err: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 562 | ori r4,r29,TSI108_SD_REG_OFFSET |
| 563 | ori r3,r0,0x0030 /* ECC_UE_INT + ECC_CE_INT bits */ |
| 564 | stw r3,SD_INT_STATUS(r4) |
| 565 | blr |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 566 | |
| 567 | #endif /* ENABLE_SDRAM_ECC */ |
| 568 | |
| 569 | #ifndef SDC_HARDCODED_INIT |
| 570 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 571 | /* SDRAM SPD Support */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 572 | #define SD_I2C_CTRL1 (0x400) |
| 573 | #define SD_I2C_CTRL2 (0x404) |
| 574 | #define SD_I2C_RD_DATA (0x408) |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 575 | #define SD_I2C_WR_DATA (0x40C) |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 576 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 577 | /* |
| 578 | * SDRAM SPD Support Macros |
| 579 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 580 | |
| 581 | #define SPD_DIMM0 (0x00000100) |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 582 | #define SPD_DIMM1 (0x00000200) /* SPD_DIMM1 was 0x00000000 */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 583 | |
| 584 | #define SPD_RDIMM (0x01) |
| 585 | #define SPD_UDIMM (0x02) |
| 586 | |
| 587 | #define SPD_CAS_3 0x8 |
| 588 | #define SPD_CAS_4 0x10 |
| 589 | #define SPD_CAS_5 0x20 |
| 590 | |
| 591 | #define ERR_NO_DIMM_FOUND (0xdb0) |
| 592 | #define ERR_TRAS_FAIL (0xdb1) |
| 593 | #define ERR_TRCD_FAIL (0xdb2) |
| 594 | #define ERR_TRP_FAIL (0xdb3) |
| 595 | #define ERR_TWR_FAIL (0xdb4) |
| 596 | #define ERR_UNKNOWN_PART (0xdb5) |
| 597 | #define ERR_NRANK_INVALID (0xdb6) |
| 598 | #define ERR_DIMM_SIZE (0xdb7) |
| 599 | #define ERR_ADDR_MODE (0xdb8) |
| 600 | #define ERR_RFRSH_RATE (0xdb9) |
| 601 | #define ERR_DIMM_TYPE (0xdba) |
| 602 | #define ERR_CL_VALUE (0xdbb) |
| 603 | #define ERR_TRFC_FAIL (0xdbc) |
| 604 | |
| 605 | /* READ_SPD requirements: |
| 606 | * byte - byte address in SPD device (0 - 255) |
| 607 | * r3 = will return data read from I2C Byte location |
| 608 | * r4 - unchanged (SDC base addr) |
| 609 | * r5 - clobbered in routine (I2C status) |
| 610 | * r10 - number of DDR slot where first SPD device is detected |
| 611 | */ |
| 612 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 613 | #define READ_SPD(byte_num) \ |
| 614 | addis r3, 0, byte_num@l; \ |
| 615 | or r3, r3, r10; \ |
| 616 | ori r3, r3, 0x0A; \ |
| 617 | stw r3, SD_I2C_CTRL1(r4); \ |
| 618 | li r3, I2C_CNTRL2_START; \ |
| 619 | stw r3, SD_I2C_CTRL2(r4); \ |
| 620 | eieio; \ |
| 621 | sync; \ |
| 622 | li r3, 0x100; \ |
| 623 | 1:; \ |
| 624 | addic. r3, r3, -1; \ |
| 625 | bne 1b; \ |
| 626 | 2:; \ |
| 627 | lwz r5, SD_I2C_CTRL2(r4); \ |
| 628 | rlwinm. r3,r5,0,23,23; \ |
| 629 | bne 2b; \ |
| 630 | rlwinm. r3,r5,0,3,3; \ |
| 631 | lwz r3,SD_I2C_RD_DATA(r4) |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 632 | |
| 633 | #define SPD_MIN_RFRSH (0x80) |
| 634 | #define SPD_MAX_RFRSH (0x85) |
| 635 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 636 | refresh_rates: /* in nSec */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 637 | .long 15625 /* Normal (0x80) */ |
| 638 | .long 3900 /* Reduced 0.25x (0x81) */ |
| 639 | .long 7800 /* Reduced 0.5x (0x82) */ |
| 640 | .long 31300 /* Extended 2x (0x83) */ |
| 641 | .long 62500 /* Extended 4x (0x84) */ |
| 642 | .long 125000 /* Extended 8x (0x85) */ |
| 643 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 644 | /* |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 645 | * tsi108_sdram_spd |
| 646 | * |
| 647 | * Inittializes SDRAM Controller using DDR2 DIMM Serial Presence Detect data |
| 648 | * Uses registers: r4 - SDC base address (not changed) |
| 649 | * r9 - SDC clocking period in nSec |
| 650 | * Changes registers: r3,r5,r6,r7,r8,r10,r11 |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 651 | */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 652 | |
| 653 | tsi108_sdram_spd: |
| 654 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 655 | li r10,SPD_DIMM0 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 656 | xor r11,r11,r11 /* DIMM Base Address: starts from 0 */ |
| 657 | |
| 658 | do_first_dimm: |
| 659 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 660 | /* Program Refresh Rate Register */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 661 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 662 | READ_SPD(12) /* get Refresh Rate */ |
| 663 | beq check_next_slot |
| 664 | li r5, ERR_RFRSH_RATE |
| 665 | cmpi 0,0,r3,SPD_MIN_RFRSH |
| 666 | ble spd_fail |
| 667 | cmpi 0,0,r3,SPD_MAX_RFRSH |
| 668 | bgt spd_fail |
| 669 | addi r3,r3,-SPD_MIN_RFRSH |
| 670 | rlwinm r3,r3,2,0,31 |
| 671 | lis r5,refresh_rates@h |
| 672 | ori r5,r5,refresh_rates@l |
| 673 | lwzx r5,r5,r3 /* get refresh rate in nSec */ |
| 674 | divwu r5,r5,r9 /* calculate # of SDC clocks */ |
| 675 | stw r5,SD_REFRESH(r4) /* Set refresh rate */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 676 | sync |
| 677 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 678 | /* Program SD Timing Register */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 679 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 680 | li r7, 0 /* clear r7 prior parameter collection */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 681 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 682 | READ_SPD(20) /* get DIMM type: Registered or Unbuffered */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 683 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 684 | li r5, ERR_DIMM_TYPE |
| 685 | cmpi 0,0,r3,SPD_UDIMM |
| 686 | beq do_cl |
| 687 | cmpi 0,0,r3,SPD_RDIMM |
| 688 | bne spd_fail |
| 689 | oris r7,r7,0x1000 /* set SD_TIMING[DIMM_TYPE] bit */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 690 | |
| 691 | do_cl: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 692 | READ_SPD(18) /* Get CAS Latency */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 693 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 694 | li r5,ERR_CL_VALUE |
| 695 | andi. r6,r3,SPD_CAS_3 |
| 696 | beq cl_4 |
| 697 | li r6,3 |
| 698 | b set_cl |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 699 | cl_4: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 700 | andi. r6,r3,SPD_CAS_4 |
| 701 | beq cl_5 |
| 702 | li r6,4 |
| 703 | b set_cl |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 704 | cl_5: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 705 | andi. r6,r3,SPD_CAS_5 |
| 706 | beq spd_fail |
| 707 | li r6,5 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 708 | set_cl: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 709 | rlwimi r7,r6,24,5,7 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 710 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 711 | READ_SPD(30) /* Get tRAS */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 712 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 713 | divwu r6,r3,r9 |
| 714 | mullw r8,r6,r9 |
| 715 | subf. r8,r8,r3 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 716 | beq set_tras |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 717 | addi r6,r6,1 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 718 | set_tras: |
| 719 | li r5,ERR_TRAS_FAIL |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 720 | cmpi 0,0,r6,0x0F /* max supported value */ |
| 721 | bgt spd_fail |
| 722 | rlwimi r7,r6,16,12,15 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 723 | |
| 724 | READ_SPD(29) /* Get tRCD */ |
| 725 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 726 | /* right shift tRCD by 2 bits as per DDR2 spec */ |
| 727 | rlwinm r3,r3,30,2,31 |
| 728 | divwu r6,r3,r9 |
| 729 | mullw r8,r6,r9 |
| 730 | subf. r8,r8,r3 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 731 | beq set_trcd |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 732 | addi r6,r6,1 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 733 | set_trcd: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 734 | li r5,ERR_TRCD_FAIL |
| 735 | cmpi 0,0,r6,0x07 /* max supported value */ |
| 736 | bgt spd_fail |
| 737 | rlwimi r7,r6,12,17,19 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 738 | |
| 739 | READ_SPD(27) /* Get tRP value */ |
| 740 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 741 | rlwinm r3,r3,30,2,31 /* right shift tRP by 2 bits as per DDR2 spec */ |
| 742 | divwu r6,r3,r9 |
| 743 | mullw r8,r6,r9 |
| 744 | subf. r8,r8,r3 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 745 | beq set_trp |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 746 | addi r6,r6,1 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 747 | set_trp: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 748 | li r5,ERR_TRP_FAIL |
| 749 | cmpi 0,0,r6,0x07 /* max supported value */ |
| 750 | bgt spd_fail |
| 751 | rlwimi r7,r6,8,21,23 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 752 | |
| 753 | READ_SPD(36) /* Get tWR value */ |
| 754 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 755 | rlwinm r3,r3,30,2,31 /* right shift tWR by 2 bits as per DDR2 spec */ |
| 756 | divwu r6,r3,r9 |
| 757 | mullw r8,r6,r9 |
| 758 | subf. r8,r8,r3 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 759 | beq set_twr |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 760 | addi r6,r6,1 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 761 | set_twr: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 762 | addi r6,r6,-1 /* Tsi108 SDC always gives one extra clock */ |
| 763 | li r5,ERR_TWR_FAIL |
| 764 | cmpi 0,0,r6,0x07 /* max supported value */ |
| 765 | bgt spd_fail |
| 766 | rlwimi r7,r6,5,24,26 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 767 | |
| 768 | READ_SPD(42) /* Get tRFC */ |
| 769 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 770 | li r5, ERR_TRFC_FAIL |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 771 | /* Tsi108 spec: tRFC=(tRFC + 1)/2 */ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 772 | addi r3,r3,1 |
| 773 | rlwinm. r3,r3,31,1,31 /* divide by 2 */ |
| 774 | beq spd_fail |
| 775 | divwu r6,r3,r9 |
| 776 | mullw r8,r6,r9 |
| 777 | subf. r8,r8,r3 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 778 | beq set_trfc |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 779 | addi r6,r6,1 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 780 | set_trfc: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 781 | cmpi 0,0,r6,0x1F /* max supported value */ |
| 782 | bgt spd_fail |
| 783 | rlwimi r7,r6,0,27,31 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 784 | |
| 785 | stw r7,SD_TIMING(r4) |
| 786 | sync |
| 787 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 788 | /* |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 789 | * The following two registers are set on per-DIMM basis. |
| 790 | * The SD_REFRESH and SD_TIMING settings are common for both DIMMS |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 791 | */ |
| 792 | |
| 793 | do_each_dimm: |
| 794 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 795 | /* Program SDRAM DIMM Control Register */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 796 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 797 | li r7, 0 /* clear r7 prior parameter collection */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 798 | |
| 799 | READ_SPD(13) /* Get Primary SDRAM Width */ |
| 800 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 801 | cmpi 0,0,r3,4 /* Check for 4-bit SDRAM */ |
| 802 | beq do_nbank |
| 803 | oris r7,r7,0x0010 /* Set MEM_WIDTH bit */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 804 | |
| 805 | do_nbank: |
| 806 | READ_SPD(17) /* Get Number of banks on SDRAM device */ |
| 807 | beq spd_read_fail |
| 808 | /* Grendel only distinguish betw. 4 or 8-bank memory parts */ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 809 | li r5,ERR_UNKNOWN_PART /* non-supported memory part */ |
| 810 | cmpi 0,0,r3,4 |
| 811 | beq do_nrank |
| 812 | cmpi 0,0,r3,8 |
| 813 | bne spd_fail |
| 814 | ori r7,r7,0x1000 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 815 | |
| 816 | do_nrank: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 817 | READ_SPD(5) /* Get # of Ranks */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 818 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 819 | li r5,ERR_NRANK_INVALID |
| 820 | andi. r6,r3,0x7 /* Use bits [2..0] only */ |
| 821 | beq do_addr_mode |
| 822 | cmpi 0,0,r6,1 |
| 823 | bgt spd_fail |
| 824 | rlwimi r7,r6,8,23,23 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 825 | |
| 826 | do_addr_mode: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 827 | READ_SPD(4) /* Get # of Column Addresses */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 828 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 829 | li r5, ERR_ADDR_MODE |
| 830 | andi. r3,r3,0x0f /* cut off reserved bits */ |
| 831 | cmpi 0,0,r3,8 |
| 832 | ble spd_fail |
| 833 | cmpi 0,0,r3,15 |
| 834 | bgt spd_fail |
| 835 | addi r6,r3,-8 /* calculate ADDR_MODE parameter */ |
| 836 | rlwimi r7,r6,4,24,27 /* set ADDR_MODE field */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 837 | |
| 838 | set_dimm_ctrl: |
| 839 | #ifdef SDC_AUTOPRECH_EN |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 840 | oris r7,r7,0x0001 /* set auto precharge EN bit */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 841 | #endif |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 842 | ori r7,r7,1 /* set ENABLE bit */ |
| 843 | cmpi 0,0,r10,SPD_DIMM0 |
| 844 | bne 1f |
| 845 | stw r7,SD_D0_CTRL(r4) |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 846 | sync |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 847 | b set_dimm_bar |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 848 | 1: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 849 | stw r7,SD_D1_CTRL(r4) |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 850 | sync |
| 851 | |
| 852 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 853 | /* Program SDRAM DIMMx Base Address Register */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 854 | |
| 855 | set_dimm_bar: |
| 856 | READ_SPD(5) /* get # of Ranks */ |
| 857 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 858 | andi. r7,r3,0x7 |
| 859 | addi r7,r7,1 |
| 860 | READ_SPD(31) /* Read DIMM rank density */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 861 | beq spd_read_fail |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 862 | rlwinm r5,r3,27,29,31 |
| 863 | rlwinm r6,r3,3,24,28 |
| 864 | or r5,r6,r5 /* r5 = Normalized Rank Density byte */ |
| 865 | lis r8, 0x0080 /* 128MB >> 4 */ |
| 866 | mullw r8,r8,r5 /* r8 = (rank_size >> 4) */ |
| 867 | mullw r8,r8,r7 /* r8 = (DIMM_size >> 4) */ |
| 868 | neg r7,r8 |
| 869 | rlwinm r7,r7,28,4,31 |
| 870 | or r7,r7,r11 /* set ADDR field */ |
| 871 | rlwinm r8,r8,12,20,31 |
| 872 | add r11,r11,r8 /* set Base Addr for next DIMM */ |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 873 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 874 | cmpi 0,0,r10,SPD_DIMM0 |
| 875 | bne set_dimm1_size |
| 876 | stw r7,SD_D0_BAR(r4) |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 877 | sync |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 878 | li r10,SPD_DIMM1 |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 879 | READ_SPD(0) |
| 880 | bne do_each_dimm |
| 881 | b spd_done |
| 882 | |
| 883 | set_dimm1_size: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 884 | stw r7,SD_D1_BAR(r4) |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 885 | sync |
| 886 | spd_done: |
| 887 | blr |
| 888 | |
| 889 | check_next_slot: |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 890 | cmpi 0,0,r10,SPD_DIMM1 |
| 891 | beq spd_read_fail |
| 892 | li r10,SPD_DIMM1 |
| 893 | b do_first_dimm |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 894 | spd_read_fail: |
| 895 | ori r3,r0,0xdead |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 896 | b err_hung |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 897 | spd_fail: |
| 898 | li r3,0x0bad |
| 899 | sync |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 900 | err_hung: /* hang here for debugging */ |
| 901 | nop |
| 902 | nop |
| 903 | b err_hung |
roy zang | aceddd8 | 2006-11-02 18:52:21 +0800 | [diff] [blame] | 904 | |
| 905 | #endif /* !SDC_HARDCODED_INIT */ |