wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>. |
| 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 | /* This file is largely based on code obtned from AMD. AMD's original |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 25 | * copyright is included below |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
Graeme Russ | 4d2a019 | 2010-04-24 00:05:59 +1000 | [diff] [blame] | 28 | /* TITLE SIZER - Aspen DRAM Sizing Routine. |
| 29 | * ============================================================================= |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 30 | * |
Graeme Russ | 4d2a019 | 2010-04-24 00:05:59 +1000 | [diff] [blame] | 31 | * Copyright 1999 Advanced Micro Devices, Inc. |
| 32 | * You may redistribute this program and/or modify this program under the terms |
| 33 | * of the GNU General Public License as published by the Free Software Foundation; |
| 34 | * either version 2 of the License, or (at your option) any later version. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 35 | * |
Graeme Russ | 4d2a019 | 2010-04-24 00:05:59 +1000 | [diff] [blame] | 36 | * This program is distributed WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED |
| 37 | * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 38 | * General Public License for more details. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 39 | * |
Graeme Russ | 4d2a019 | 2010-04-24 00:05:59 +1000 | [diff] [blame] | 40 | * You should have received a copy of the GNU General Public License along with |
| 41 | * this program; if not, write to the Free Software Foundation, Inc., |
| 42 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 43 | * |
Graeme Russ | 4d2a019 | 2010-04-24 00:05:59 +1000 | [diff] [blame] | 44 | * THE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY |
| 45 | * OF ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT OF |
| 46 | * THIRD-PARTY INTELLECTUAL PROPERTY, OR FITNESS FOR ANY PARTICULAR PURPOSE. |
| 47 | * IN NO EVENT SHALL AMD OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER |
| 48 | * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS |
| 49 | * INTERRUPTION, LOSS OF INFORMATION) ARISING OUT OF THE USE OF OR INABILITY |
| 50 | * TO USE THE MATERIALS, EVEN IF AMD HAS BEEN ADVISED OF THE POSSIBILITY OF |
| 51 | * SUCH DAMAGES. BECAUSE SOME JURSIDICTIONS PROHIBIT THE EXCLUSION OR |
| 52 | * LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE |
| 53 | * LIMITATION MAY NOT APPLY TO YOU. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 54 | * |
Graeme Russ | 4d2a019 | 2010-04-24 00:05:59 +1000 | [diff] [blame] | 55 | * AMD does not assume any responsibility for any errors that may appear in |
| 56 | * the Materials nor any responsibility to support or update the Materials. |
| 57 | * AMD retains the right to make changes to its test specifications at any |
| 58 | * time, without notice. |
| 59 | * ============================================================================== |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 60 | */ |
| 61 | |
Graeme Russ | 4d2a019 | 2010-04-24 00:05:59 +1000 | [diff] [blame] | 62 | /* |
| 63 | ****************************************************************************** |
| 64 | * |
| 65 | * FILE : sizer.asm - SDRAM DIMM Sizing Algorithm |
| 66 | * |
| 67 | * |
| 68 | * |
| 69 | * FUNCTIONS : sizemem() - jumped to, not called. To be executed after |
| 70 | * reset to determine the size of the SDRAM DIMMs. Initializes |
| 71 | * the memory subsystem. |
| 72 | * |
| 73 | * |
| 74 | * AUTHOR : Buddy Fey - Original. |
| 75 | * |
| 76 | * |
| 77 | * DESCRIPTION : Performs sizing on SDRAM DIMMs on ASPEN processor. |
| 78 | * NOTE: This is a small memory model version |
| 79 | * |
| 80 | * |
| 81 | * INPUTS : BP contains return address offset |
| 82 | * CACHE is assumed to be disabled. |
| 83 | * The FS segment limit has already been set to big real mode |
| 84 | * (full 32-bit addressing capability) |
| 85 | * |
| 86 | * |
| 87 | * OUTPUTS : None |
| 88 | * |
| 89 | * |
| 90 | * REG USE : ax,bx,cx,dx,di,si,bp, fs |
| 91 | * |
| 92 | * |
| 93 | * REVISION : See PVCS info below |
| 94 | * |
| 95 | * |
| 96 | * TEST PLAN CROSS REFERENCE: |
| 97 | * |
| 98 | * |
| 99 | * $Workfile: $ |
| 100 | * $Revision: 1.2 $ |
| 101 | * $Date: 1999/09/22 12:49:33 $ |
| 102 | * $Author: chipf $ |
| 103 | * $Log: sizer.asm $ |
| 104 | * Revision 1.2 1999/09/22 12:49:33 chipf |
| 105 | * Add legal header |
| 106 | * |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 107 | ******************************************************************************* |
| 108 | */ |
| 109 | |
| 110 | |
| 111 | /******************************************************************************* |
| 112 | * FUNCTIONAL DESCRIPTION: |
| 113 | * This routine is called to autodetect the geometry of the DRAM. |
| 114 | * |
| 115 | * This routine is called to determine the number of column bits for the DRAM |
| 116 | * devices in this external bank. This routine assumes that the external bank |
| 117 | * has been configured for an 11-bit column and for 4 internal banks. This gives |
| 118 | * us the maximum address reach in memory. By writing a test value to the max |
| 119 | * address and locating where it aliases to, we can determine the number of valid |
| 120 | * column bits. |
| 121 | * |
| 122 | * This routine is called to determine the number of internal banks each DRAM |
| 123 | * device has. The external bank (under test) is configured for maximum reach |
| 124 | * with 11-bit columns and 4 internal banks. This routine will write to a max |
| 125 | * address (BA1 and BA0 = 1) and then read from an address with BA1=0 to see if |
| 126 | * that column is a "don't care". If BA1 does not affect write/read of data, |
| 127 | * then this device has only 2 internal banks. |
| 128 | * |
| 129 | * This routine is called to determine the ending address for this external |
| 130 | * bank of SDRAM. We write to a max address with a data value and then disable |
| 131 | * row address bits looking for "don't care" locations. Each "don't care" bit |
| 132 | * represents a dividing of the maximum density (128M) by 2. By dividing the |
| 133 | * maximum of 32 4M chunks in an external bank down by all the "don't care" bits |
| 134 | * determined during sizing, we set the proper density. |
| 135 | * |
| 136 | * WARNINGS. |
| 137 | * bp must be preserved because it is used for return linkage. |
| 138 | * |
| 139 | * EXIT |
| 140 | * nothing returned - but the memory subsystem is enabled |
| 141 | ******************************************************************************* |
| 142 | */ |
| 143 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 144 | #include <config.h> |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 145 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 146 | .section .text |
| 147 | .equ DRCCTL, 0x0fffef010 /* DRAM control register */ |
| 148 | .equ DRCTMCTL, 0x0fffef012 /* DRAM timing control register */ |
| 149 | .equ DRCCFG, 0x0fffef014 /* DRAM bank configuration register */ |
| 150 | .equ DRCBENDADR, 0x0fffef018 /* DRAM bank ending address register */ |
| 151 | .equ ECCCTL, 0x0fffef020 /* DRAM ECC control register */ |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 152 | .equ ECCINT, 0x0fffefd18 /* DRAM ECC nmi-INT mapping */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 153 | .equ DBCTL, 0x0fffef040 /* DRAM buffer control register */ |
| 154 | |
| 155 | .equ CACHELINESZ, 0x00000010 /* size of our cache line (read buffer) */ |
| 156 | .equ COL11_ADR, 0x0e001e00 /* 11 col addrs */ |
| 157 | .equ COL10_ADR, 0x0e000e00 /* 10 col addrs */ |
| 158 | .equ COL09_ADR, 0x0e000600 /* 9 col addrs */ |
| 159 | .equ COL08_ADR, 0x0e000200 /* 8 col addrs */ |
| 160 | .equ ROW14_ADR, 0x0f000000 /* 14 row addrs */ |
| 161 | .equ ROW13_ADR, 0x07000000 /* 13 row addrs */ |
| 162 | .equ ROW12_ADR, 0x03000000 /* 12 row addrs */ |
| 163 | .equ ROW11_ADR, 0x01000000 /* 11 row addrs/also bank switch */ |
| 164 | .equ ROW10_ADR, 0x00000000 /* 10 row addrs/also bank switch */ |
| 165 | .equ COL11_DATA, 0x0b0b0b0b /* 11 col addrs */ |
| 166 | .equ COL10_DATA, 0x0a0a0a0a /* 10 col data */ |
| 167 | .equ COL09_DATA, 0x09090909 /* 9 col data */ |
| 168 | .equ COL08_DATA, 0x08080808 /* 8 col data */ |
| 169 | .equ ROW14_DATA, 0x3f3f3f3f /* 14 row data (MASK) */ |
| 170 | .equ ROW13_DATA, 0x1f1f1f1f /* 13 row data (MASK) */ |
| 171 | .equ ROW12_DATA, 0x0f0f0f0f /* 12 row data (MASK) */ |
| 172 | .equ ROW11_DATA, 0x07070707 /* 11 row data/also bank switch (MASK) */ |
| 173 | .equ ROW10_DATA, 0xaaaaaaaa /* 10 row data/also bank switch (MASK) */ |
| 174 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 175 | .globl mem_init |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 176 | mem_init: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 177 | /* initialize dram controller registers */ |
| 178 | xorw %ax, %ax |
| 179 | movl $DBCTL, %edi |
| 180 | movb %al, (%edi) /* disable write buffer */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 181 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 182 | movl $ECCCTL, %edi |
| 183 | movb %al, (%edi) /* disable ECC */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 184 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 185 | movl $DRCTMCTL, %edi |
| 186 | movb $0x1e, %al /* Set SDRAM timing for slowest */ |
| 187 | movb %al, (%edi) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 188 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 189 | /* setup loop to do 4 external banks starting with bank 3 */ |
| 190 | movl $0xff000000, %eax /* enable last bank and setup */ |
| 191 | movl $DRCBENDADR, %edi /* ending address register */ |
| 192 | movl %eax, (%edi) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 193 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 194 | movl $DRCCFG, %edi /* setup */ |
| 195 | movw $0xbbbb, %ax /* dram config register for */ |
| 196 | movw %ax, (%edi) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 197 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 198 | /* issue a NOP to all DRAMs */ |
| 199 | movl $DRCCTL, %edi /* setup DRAM control register with */ |
| 200 | movb $0x01, %al /* Disable refresh,disable write buffer */ |
| 201 | movb %al, (%edi) |
| 202 | movl $CACHELINESZ, %esi /* just a dummy address to write for */ |
| 203 | movw %ax, (%esi) |
| 204 | |
| 205 | /* delay for 100 usec? */ |
| 206 | movw $100, %cx |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 207 | sizdelay: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 208 | loop sizdelay |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 209 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 210 | /* issue all banks precharge */ |
| 211 | movb $0x02, %al |
| 212 | movb %al, (%edi) |
| 213 | movw %ax, (%esi) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 214 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 215 | /* issue 2 auto refreshes to all banks */ |
| 216 | movb $0x04, %al /* Auto refresh cmd */ |
| 217 | movb %al, (%edi) |
| 218 | movw $0x02, %cx |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 219 | refresh1: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 220 | movw %ax, (%esi) |
| 221 | loop refresh1 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 222 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 223 | /* issue LOAD MODE REGISTER command */ |
| 224 | movb $0x03, %al /* Load mode register cmd */ |
| 225 | movb %al, (%edi) |
| 226 | movw %ax, (%esi) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 227 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 228 | /* issue 8 more auto refreshes to all banks */ |
| 229 | movb $0x04, %al /* Auto refresh cmd */ |
| 230 | movb %al, (%edi) |
| 231 | movw $0x0008, %cx |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 232 | refresh2: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 233 | movw %ax, (%esi) |
| 234 | loop refresh2 |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 235 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 236 | /* set control register to NORMAL mode */ |
| 237 | movb $0x00, %al /* Normal mode value */ |
| 238 | movb %al, (%edi) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 239 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 240 | /* |
| 241 | * size dram starting with external bank 3 |
| 242 | * moving to external bank 0 |
| 243 | */ |
| 244 | movl $0x3, %ecx /* start with external bank 3 */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 245 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 246 | nextbank: |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 247 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 248 | /* write col 11 wrap adr */ |
| 249 | movl $COL11_ADR, %esi /* set address to max col (11) wrap addr */ |
| 250 | movl $COL11_DATA, %eax /* pattern for max supported columns(11) */ |
| 251 | movl %eax, (%esi) /* write max col pattern at max col adr */ |
| 252 | movl (%esi), %ebx /* optional read */ |
| 253 | cmpl %ebx, %eax /* to verify write */ |
| 254 | jnz bad_ram /* this ram is bad */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 255 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 256 | /* write col 10 wrap adr */ |
| 257 | movl $COL10_ADR, %esi /* set address to 10 col wrap address */ |
| 258 | movl $COL10_DATA, %eax /* pattern for 10 col wrap */ |
| 259 | movl %eax, (%esi) /* write 10 col pattern @ 10 col wrap adr */ |
| 260 | movl (%esi), %ebx /* optional read */ |
| 261 | cmpl %ebx, %eax /* to verify write */ |
| 262 | jnz bad_ram /* this ram is bad */ |
| 263 | |
| 264 | /* write col 9 wrap adr */ |
| 265 | movl $COL09_ADR, %esi /* set address to 9 col wrap address */ |
| 266 | movl $COL09_DATA, %eax /* pattern for 9 col wrap */ |
| 267 | movl %eax, (%esi) /* write 9 col pattern @ 9 col wrap adr */ |
| 268 | movl (%esi), %ebx /* optional read */ |
| 269 | cmpl %ebx, %eax /* to verify write */ |
| 270 | jnz bad_ram /* this ram is bad */ |
| 271 | |
| 272 | /* write col 8 wrap adr */ |
| 273 | movl $COL08_ADR, %esi /* set address to min(8) col wrap address */ |
| 274 | movl $COL08_DATA, %eax /* pattern for min (8) col wrap */ |
| 275 | movl %eax, (%esi) /* write min col pattern @ min col adr */ |
| 276 | movl (%esi), %ebx /* optional read */ |
| 277 | cmpl %ebx, %eax /* to verify write */ |
| 278 | jnz bad_ram /* this ram is bad */ |
| 279 | |
| 280 | /* write row 14 wrap adr */ |
| 281 | movl $ROW14_ADR, %esi /* set address to max row (14) wrap addr */ |
| 282 | movl $ROW14_DATA, %eax /* pattern for max supported rows(14) */ |
| 283 | movl %eax, (%esi) /* write max row pattern at max row adr */ |
| 284 | movl (%esi), %ebx /* optional read */ |
| 285 | cmpl %ebx, %eax /* to verify write */ |
| 286 | jnz bad_ram /* this ram is bad */ |
| 287 | |
| 288 | /* write row 13 wrap adr */ |
| 289 | movl $ROW13_ADR, %esi /* set address to 13 row wrap address */ |
| 290 | movl $ROW13_DATA, %eax /* pattern for 13 row wrap */ |
| 291 | movl %eax, (%esi) /* write 13 row pattern @ 13 row wrap adr */ |
| 292 | movl (%esi), %ebx /* optional read */ |
| 293 | cmpl %ebx, %eax /* to verify write */ |
| 294 | jnz bad_ram /* this ram is bad */ |
| 295 | |
| 296 | /* write row 12 wrap adr */ |
| 297 | movl $ROW12_ADR, %esi /* set address to 12 row wrap address */ |
| 298 | movl $ROW12_DATA, %eax /* pattern for 12 row wrap */ |
| 299 | movl %eax, (%esi) /* write 12 row pattern @ 12 row wrap adr */ |
| 300 | movl (%esi), %ebx /* optional read */ |
| 301 | cmpl %ebx, %eax /* to verify write */ |
| 302 | jnz bad_ram /* this ram is bad */ |
| 303 | |
| 304 | /* write row 11 wrap adr */ |
| 305 | movl $ROW11_ADR, %edi /* set address to 11 row wrap address */ |
| 306 | movl $ROW11_DATA, %eax /* pattern for 11 row wrap */ |
| 307 | movl %eax, (%edi) /* write 11 row pattern @ 11 row wrap adr */ |
| 308 | movl (%edi), %ebx /* optional read */ |
| 309 | cmpl %ebx, %eax /* to verify write */ |
| 310 | jnz bad_ram /* this ram is bad */ |
| 311 | |
| 312 | /* |
| 313 | * write row 10 wrap adr --- this write is really to determine |
| 314 | * number of banks |
| 315 | */ |
| 316 | movl $ROW10_ADR, %edi /* set address to 10 row wrap address */ |
| 317 | movl $ROW10_DATA, %eax /* pattern for 10 row wrap (AA) */ |
| 318 | movl %eax, (%edi) /* write 10 row pattern @ 10 row wrap adr */ |
| 319 | movl (%edi), %ebx /* optional read */ |
| 320 | cmpl %ebx, %eax /* to verify write */ |
| 321 | jnz bad_ram /* this ram is bad */ |
| 322 | |
| 323 | /* |
| 324 | * read data @ row 12 wrap adr to determine * banks, |
| 325 | * and read data @ row 14 wrap adr to determine * rows. |
| 326 | * if data @ row 12 wrap adr is not AA, 11 or 12 we have bad RAM. |
| 327 | * if data @ row 12 wrap == AA, we only have 2 banks, NOT 4 |
| 328 | * if data @ row 12 wrap == 11 or 12, we have 4 banks, |
| 329 | */ |
| 330 | xorw %di, %di /* value for 2 banks in DI */ |
| 331 | movl (%esi), %ebx /* read from 12 row wrap to check banks */ |
| 332 | /* (esi is setup from the write to row 12 wrap) */ |
| 333 | cmpl %ebx, %eax /* check for AA pattern (eax holds the aa pattern) */ |
| 334 | jz only2 /* if pattern == AA, we only have 2 banks */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 335 | |
| 336 | /* 4 banks */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 337 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 338 | movw $0x008, %di /* value for 4 banks in DI (BNK_CNT bit) */ |
| 339 | cmpl $ROW11_DATA, %ebx /* only other legitimate values are 11 */ |
| 340 | jz only2 |
| 341 | cmpl $ROW12_DATA, %ebx /* and 12 */ |
| 342 | jnz bad_ram /* its bad if not 11 or 12! */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 343 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 344 | /* fall through */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 345 | only2: |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 346 | /* |
| 347 | * validate row mask |
| 348 | */ |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 349 | movl $ROW14_ADR, %esi /* set address back to max row wrap addr */ |
| 350 | movl (%esi), %eax /* read actual number of rows @ row14 adr */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 351 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 352 | cmpl $ROW11_DATA, %eax /* row must be greater than 11 pattern */ |
| 353 | jb bad_ram |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 354 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 355 | cmpl $ROW14_DATA, %eax /* and row must be less than 14 pattern */ |
| 356 | ja bad_ram |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 357 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 358 | cmpb %ah, %al /* verify all 4 bytes of dword same */ |
| 359 | jnz bad_ram |
| 360 | movl %eax, %ebx |
| 361 | shrl $16, %ebx |
| 362 | cmpw %bx, %ax |
| 363 | jnz bad_ram |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 364 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 365 | /* |
| 366 | * read col 11 wrap adr for real column data value |
| 367 | */ |
| 368 | movl $COL11_ADR, %esi /* set address to max col (11) wrap addr */ |
| 369 | movl (%esi), %eax /* read real col number at max col adr */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 370 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 371 | /* |
| 372 | * validate column data |
| 373 | */ |
| 374 | cmpl $COL08_DATA, %eax /* col must be greater than 8 pattern */ |
| 375 | jb bad_ram |
| 376 | |
| 377 | cmpl $COL11_DATA, %eax /* and row must be less than 11 pattern */ |
| 378 | ja bad_ram |
| 379 | |
| 380 | subl $COL08_DATA, %eax /* normalize column data to zero */ |
| 381 | jc bad_ram |
| 382 | cmpb %ah, %al /* verify all 4 bytes of dword equal */ |
| 383 | jnz bad_ram |
| 384 | movl %eax, %edx |
| 385 | shrl $16, %edx |
| 386 | cmpw %dx, %ax |
| 387 | jnz bad_ram |
| 388 | |
| 389 | /* |
| 390 | * merge bank and col data together |
| 391 | */ |
| 392 | addw %di, %dx /* merge of bank and col info in dl */ |
| 393 | |
| 394 | /* |
| 395 | * fix ending addr mask based upon col info |
| 396 | */ |
| 397 | movb $0x03, %al |
| 398 | subb %dh, %al /* dh contains the overflow from the bank/col merge */ |
| 399 | movb %bl, %dh /* bl contains the row mask (aa, 07, 0f, 1f or 3f) */ |
| 400 | xchgw %cx, %ax /* cx = ax = 3 or 2 depending on 2 or 4 bank device */ |
| 401 | shrb %cl, %dh |
| 402 | incb %dh /* ending addr is 1 greater than real end */ |
| 403 | xchgw %cx, %ax /* cx is bank number again */ |
| 404 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 405 | bad_reint: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 406 | /* |
| 407 | * issue all banks precharge |
| 408 | */ |
| 409 | movl $DRCCTL, %esi /* setup DRAM control register with */ |
| 410 | movb $0x02, %al /* All banks precharge */ |
| 411 | movb %al, (%esi) |
| 412 | movl $CACHELINESZ, %esi /* address to init read buffer */ |
| 413 | movw %ax, (%esi) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 414 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 415 | /* |
| 416 | * update ENDING ADDRESS REGISTER |
| 417 | */ |
| 418 | movl $DRCBENDADR, %edi /* DRAM ending address register */ |
| 419 | movl %ecx, %ebx |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 420 | addl %ebx, %edi |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 421 | movb %dh, (%edi) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 422 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 423 | /* |
| 424 | * update CONFIG REGISTER |
| 425 | */ |
| 426 | xorb %dh, %dh |
| 427 | movw $0x000f, %bx |
| 428 | movw %cx, %ax |
| 429 | shlw $2, %ax |
| 430 | xchgw %cx, %ax |
| 431 | shlw %cl, %dx |
| 432 | shlw %cl, %bx |
| 433 | notw %bx |
| 434 | xchgw %cx, %ax |
| 435 | movl $DRCCFG, %edi |
| 436 | movw (%edi), %ax |
| 437 | andw %bx, %ax |
| 438 | orw %dx, %ax |
| 439 | movw %ax, (%edi) |
| 440 | jcxz cleanup |
| 441 | |
| 442 | decw %cx |
| 443 | movl %ecx, %ebx |
| 444 | movl $DRCBENDADR, %edi /* DRAM ending address register */ |
| 445 | movb $0xff, %al |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 446 | addl %ebx, %edi |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 447 | movb %al, (%edi) |
| 448 | |
| 449 | /* |
| 450 | * set control register to NORMAL mode |
| 451 | */ |
| 452 | movl $DRCCTL, %esi /* setup DRAM control register with */ |
| 453 | movb $0x00, %al /* Normal mode value */ |
| 454 | movb %al, (%esi) |
| 455 | movl $CACHELINESZ, %esi /* address to init read buffer */ |
| 456 | movw %ax, (%esi) |
| 457 | jmp nextbank |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 458 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 459 | cleanup: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 460 | movl $DRCBENDADR, %edi /* DRAM ending address register */ |
| 461 | movw $0x04, %cx |
| 462 | xorw %ax, %ax |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 463 | cleanuplp: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 464 | movb (%edi), %al |
| 465 | orb %al, %al |
| 466 | jz emptybank |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 467 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 468 | addb %ah, %al |
| 469 | jns nottoomuch |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 470 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 471 | movb $0x7f, %al |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 472 | nottoomuch: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 473 | movb %al, %ah |
| 474 | orb $0x80, %al |
| 475 | movb %al, (%edi) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 476 | emptybank: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 477 | incl %edi |
| 478 | loop cleanuplp |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 479 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 480 | #if defined CONFIG_SYS_SDRAM_DRCTMCTL |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 481 | /* just have your hardware desinger _GIVE_ you what you need here! */ |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 482 | movl $DRCTMCTL, %edi |
| 483 | movb $CONFIG_SYS_SDRAM_DRCTMCTL, %al |
| 484 | movb %al, (%edi) |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 485 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 486 | #if defined(CONFIG_SYS_SDRAM_CAS_LATENCY_2T) || defined(CONFIG_SYS_SDRAM_CAS_LATENCY_3T) |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 487 | /* |
| 488 | * Set the CAS latency now since it is hard to do |
| 489 | * when we run from the RAM |
| 490 | */ |
| 491 | movl $DRCTMCTL, %edi /* DRAM timing register */ |
| 492 | movb (%edi), %al |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 493 | #ifdef CONFIG_SYS_SDRAM_CAS_LATENCY_2T |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 494 | andb $0xef, %al |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 495 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 496 | #ifdef CONFIG_SYS_SDRAM_CAS_LATENCY_3T |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 497 | orb $0x10, %al |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 498 | #endif |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 499 | movb %al, (%edi) |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 500 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 501 | #endif |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 502 | movl $DRCCTL, %edi /* DRAM Control register */ |
| 503 | movb $0x03, %al /* Load mode register cmd */ |
| 504 | movb %al, (%edi) |
| 505 | movw %ax, (%esi) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 506 | |
| 507 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 508 | movl $DRCCTL, %edi /* DRAM Control register */ |
| 509 | movb $0x18, %al /* Enable refresh and NORMAL mode */ |
| 510 | movb %al, (%edi) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 511 | |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 512 | jmp dram_done |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 513 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 514 | bad_ram: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 515 | xorl %edx, %edx |
| 516 | xorl %edi, %edi |
| 517 | jmp bad_reint |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 518 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 519 | dram_done: |
| 520 | |
Graeme Russ | b39f12f | 2010-04-24 00:05:41 +1000 | [diff] [blame] | 521 | #if CONFIG_SYS_SDRAM_ECC_ENABLE |
| 522 | /* |
| 523 | * We are in the middle of an existing 'call' - Need to store the |
| 524 | * existing return address before making another 'call' |
| 525 | */ |
| 526 | movl %ebp, %ebx |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 527 | |
Graeme Russ | b39f12f | 2010-04-24 00:05:41 +1000 | [diff] [blame] | 528 | /* Get the memory size */ |
| 529 | movl $init_ecc, %ebp |
| 530 | jmpl get_mem_size |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 531 | |
Graeme Russ | b39f12f | 2010-04-24 00:05:41 +1000 | [diff] [blame] | 532 | init_ecc: |
| 533 | /* Restore the orignal return address */ |
| 534 | movl %ebx, %ebp |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 535 | |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 536 | /* A nominal memory test: just a byte at each address line */ |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 537 | movl %eax, %ecx |
| 538 | shrl $0x1, %ecx |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 539 | movl $0x1, %edi |
| 540 | memtest0: |
| 541 | movb $0xa5, (%edi) |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 542 | cmpb $0xa5, (%edi) |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 543 | jne out |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 544 | shrl $0x1, %ecx |
| 545 | andl %ecx, %ecx |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 546 | jz set_ecc |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 547 | shll $0x1, %edi |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 548 | jmp memtest0 |
| 549 | |
| 550 | set_ecc: |
| 551 | /* clear all ram with a memset */ |
| 552 | movl %eax, %ecx |
| 553 | xorl %esi, %esi |
| 554 | xorl %edi, %edi |
| 555 | xorl %eax, %eax |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 556 | shrl $0x2, %ecx |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 557 | cld |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 558 | rep stosl |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 559 | |
| 560 | /* enable read, write buffers */ |
| 561 | movb $0x11, %al |
| 562 | movl $DBCTL, %edi |
| 563 | movb %al, (%edi) |
| 564 | |
| 565 | /* enable NMI mapping for ECC */ |
| 566 | movl $ECCINT, %edi |
| 567 | movb $0x10, %al |
| 568 | movb %al, (%edi) |
| 569 | |
| 570 | /* Turn on ECC */ |
| 571 | movl $ECCCTL, %edi |
| 572 | movb $0x05, %al |
| 573 | movb %al,(%edi) |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 574 | #endif |
Graeme Russ | b39f12f | 2010-04-24 00:05:41 +1000 | [diff] [blame] | 575 | |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 576 | out: |
Graeme Russ | b39f12f | 2010-04-24 00:05:41 +1000 | [diff] [blame] | 577 | jmp *%ebp |
| 578 | |
| 579 | /* |
| 580 | * Read and decode the sc520 DRCBENDADR MMCR and return the number of |
| 581 | * available ram bytes in %eax |
| 582 | */ |
| 583 | .globl get_mem_size |
| 584 | get_mem_size: |
Graeme Russ | 3e6ec38 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 585 | movl $DRCBENDADR, %edi /* DRAM ending address register */ |
Graeme Russ | b39f12f | 2010-04-24 00:05:41 +1000 | [diff] [blame] | 586 | |
| 587 | bank0: movl (%edi), %eax |
| 588 | movl %eax, %ecx |
| 589 | andl $0x00000080, %ecx |
| 590 | jz bank1 |
| 591 | andl $0x0000007f, %eax |
| 592 | shll $22, %eax |
| 593 | movl %eax, %ebx |
| 594 | |
| 595 | bank1: movl (%edi), %eax |
| 596 | movl %eax, %ecx |
| 597 | andl $0x00008000, %ecx |
| 598 | jz bank2 |
| 599 | andl $0x00007f00, %eax |
| 600 | shll $14, %eax |
| 601 | movl %eax, %ebx |
| 602 | |
| 603 | bank2: movl (%edi), %eax |
| 604 | movl %eax, %ecx |
| 605 | andl $0x00800000, %ecx |
| 606 | jz bank3 |
| 607 | andl $0x007f0000, %eax |
| 608 | shll $6, %eax |
| 609 | movl %eax, %ebx |
| 610 | |
| 611 | bank3: movl (%edi), %eax |
| 612 | movl %eax, %ecx |
| 613 | andl $0x80000000, %ecx |
| 614 | jz done |
| 615 | andl $0x7f000000, %eax |
| 616 | shrl $2, %eax |
| 617 | movl %eax, %ebx |
| 618 | |
| 619 | done: |
Wolfgang Denk | 8ceef30 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 620 | movl %ebx, %eax |
| 621 | jmp *%ebp |