sc520_asm.S 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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. /* This file is largely based on code obtned from AMD. AMD's original
  24. * copyright is included below
  25. */
  26. /*
  27. * =============================================================================
  28. *
  29. * Copyright 1999 Advanced Micro Devices, Inc.
  30. *
  31. * This software is the property of Advanced Micro Devices, Inc (AMD) which
  32. * specifically grants the user the right to modify, use and distribute this
  33. * software provided this COPYRIGHT NOTICE is not removed or altered. All
  34. * other rights are reserved by AMD.
  35. *
  36. * THE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY
  37. * OF ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT OF
  38. * THIRD-PARTY INTELLECTUAL PROPERTY, OR FITNESS FOR ANY PARTICULAR PURPOSE.
  39. * IN NO EVENT SHALL AMD OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER
  40. * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS
  41. * INTERRUPTION, LOSS OF INFORMAITON) ARISING OUT OF THE USE OF OR INABILITY
  42. * TO USE THE MATERIALS, EVEN IF AMD HAS BEEN ADVISED OF THE POSSIBILITY OF
  43. * SUCH DAMAGES. BECAUSE SOME JURSIDICTIONS PROHIBIT THE EXCLUSION OR
  44. * LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE
  45. * LIMITATION MAY NOT APPLY TO YOU.
  46. *
  47. * AMD does not assume any responsibility for any errors that may appear in
  48. * the Materials nor any responsibility to support or update the Materials.
  49. * AMD retains the right to make changes to its test specifications at any
  50. * time, without notice.
  51. *
  52. * So that all may benefit from your experience, please report any problems
  53. * or suggestions about this software back to AMD. Please include your name,
  54. * company, telephone number, AMD product requiring support and question or
  55. * problem encountered.
  56. *
  57. * Advanced Micro Devices, Inc. Worldwide support and contact
  58. * Embedded Processor Division information available at:
  59. * Systems Engineering epd.support@amd.com
  60. * 5204 E. Ben White Blvd. -or-
  61. * Austin, TX 78741 http://www.amd.com/html/support/techsup.html
  62. * ============================================================================
  63. */
  64. /*******************************************************************************
  65. * AUTHOR : Buddy Fey - Original.
  66. *******************************************************************************
  67. */
  68. /*******************************************************************************
  69. * FUNCTIONAL DESCRIPTION:
  70. * This routine is called to autodetect the geometry of the DRAM.
  71. *
  72. * This routine is called to determine the number of column bits for the DRAM
  73. * devices in this external bank. This routine assumes that the external bank
  74. * has been configured for an 11-bit column and for 4 internal banks. This gives
  75. * us the maximum address reach in memory. By writing a test value to the max
  76. * address and locating where it aliases to, we can determine the number of valid
  77. * column bits.
  78. *
  79. * This routine is called to determine the number of internal banks each DRAM
  80. * device has. The external bank (under test) is configured for maximum reach
  81. * with 11-bit columns and 4 internal banks. This routine will write to a max
  82. * address (BA1 and BA0 = 1) and then read from an address with BA1=0 to see if
  83. * that column is a "don't care". If BA1 does not affect write/read of data,
  84. * then this device has only 2 internal banks.
  85. *
  86. * This routine is called to determine the ending address for this external
  87. * bank of SDRAM. We write to a max address with a data value and then disable
  88. * row address bits looking for "don't care" locations. Each "don't care" bit
  89. * represents a dividing of the maximum density (128M) by 2. By dividing the
  90. * maximum of 32 4M chunks in an external bank down by all the "don't care" bits
  91. * determined during sizing, we set the proper density.
  92. *
  93. * WARNINGS.
  94. * bp must be preserved because it is used for return linkage.
  95. *
  96. * EXIT
  97. * nothing returned - but the memory subsystem is enabled
  98. *******************************************************************************
  99. */
  100. .section .text
  101. .equ DRCCTL, 0x0fffef010 /* DRAM control register */
  102. .equ DRCTMCTL, 0x0fffef012 /* DRAM timing control register */
  103. .equ DRCCFG, 0x0fffef014 /* DRAM bank configuration register */
  104. .equ DRCBENDADR, 0x0fffef018 /* DRAM bank ending address register */
  105. .equ ECCCTL, 0x0fffef020 /* DRAM ECC control register */
  106. .equ DBCTL, 0x0fffef040 /* DRAM buffer control register */
  107. .equ CACHELINESZ, 0x00000010 /* size of our cache line (read buffer) */
  108. .equ COL11_ADR, 0x0e001e00 /* 11 col addrs */
  109. .equ COL10_ADR, 0x0e000e00 /* 10 col addrs */
  110. .equ COL09_ADR, 0x0e000600 /* 9 col addrs */
  111. .equ COL08_ADR, 0x0e000200 /* 8 col addrs */
  112. .equ ROW14_ADR, 0x0f000000 /* 14 row addrs */
  113. .equ ROW13_ADR, 0x07000000 /* 13 row addrs */
  114. .equ ROW12_ADR, 0x03000000 /* 12 row addrs */
  115. .equ ROW11_ADR, 0x01000000 /* 11 row addrs/also bank switch */
  116. .equ ROW10_ADR, 0x00000000 /* 10 row addrs/also bank switch */
  117. .equ COL11_DATA, 0x0b0b0b0b /* 11 col addrs */
  118. .equ COL10_DATA, 0x0a0a0a0a /* 10 col data */
  119. .equ COL09_DATA, 0x09090909 /* 9 col data */
  120. .equ COL08_DATA, 0x08080808 /* 8 col data */
  121. .equ ROW14_DATA, 0x3f3f3f3f /* 14 row data (MASK) */
  122. .equ ROW13_DATA, 0x1f1f1f1f /* 13 row data (MASK) */
  123. .equ ROW12_DATA, 0x0f0f0f0f /* 12 row data (MASK) */
  124. .equ ROW11_DATA, 0x07070707 /* 11 row data/also bank switch (MASK) */
  125. .equ ROW10_DATA, 0xaaaaaaaa /* 10 row data/also bank switch (MASK) */
  126. /*
  127. * initialize dram controller registers
  128. */
  129. .globl mem_init
  130. mem_init:
  131. xorw %ax,%ax
  132. movl $DBCTL, %edi
  133. fs movb %al, (%edi) /* disable write buffer */
  134. movl $ECCCTL, %edi
  135. fs movb %al, (%edi) /* disable ECC */
  136. movl $DRCTMCTL, %edi
  137. movb $0x1E,%al /* Set SDRAM timing for slowest */
  138. fs movb %al, (%edi)
  139. /*
  140. * setup loop to do 4 external banks starting with bank 3
  141. */
  142. movl $0xff000000,%eax /* enable last bank and setup */
  143. movl $DRCBENDADR, %edi /* ending address register */
  144. fs movl %eax, (%edi)
  145. movl $DRCCFG, %edi /* setup */
  146. movw $0xbbbb,%ax /* dram config register for */
  147. fs movw %ax, (%edi)
  148. /*
  149. * issue a NOP to all DRAMs
  150. */
  151. movl $DRCCTL, %edi /* setup DRAM control register with */
  152. movb $0x1,%al /* Disable refresh,disable write buffer */
  153. fs movb %al, (%edi)
  154. movl $CACHELINESZ, %esi /* just a dummy address to write for */
  155. fs movw %ax, (%esi)
  156. /*
  157. * delay for 100 usec? 200?
  158. * ******this is a cludge for now *************
  159. */
  160. movw $100,%cx
  161. sizdelay:
  162. loop sizdelay /* we need 100 usec here */
  163. /***********************************************/
  164. /*
  165. * issue all banks precharge
  166. */
  167. movb $0x2,%al /* All banks precharge */
  168. fs movb %al, (%edi)
  169. fs movw %ax, (%esi)
  170. /*
  171. * issue 2 auto refreshes to all banks
  172. */
  173. movb $0x4,%al /* Auto refresh cmd */
  174. fs movb %al, (%edi)
  175. movw $2,%cx
  176. refresh1:
  177. fs movw %ax, (%esi)
  178. loop refresh1
  179. /*
  180. * issue LOAD MODE REGISTER command
  181. */
  182. movb $0x3,%al /* Load mode register cmd */
  183. fs movb %al, (%edi)
  184. fs movw %ax, (%esi)
  185. /*
  186. * issue 8 more auto refreshes to all banks
  187. */
  188. movb $0x4,%al /* Auto refresh cmd */
  189. fs movb %al, (%edi)
  190. movw $8,%cx
  191. refresh2:
  192. fs movw %ax, (%esi)
  193. loop refresh2
  194. /*
  195. * set control register to NORMAL mode
  196. */
  197. movb $0x0,%al /* Normal mode value */
  198. fs movb %al, (%edi)
  199. /*
  200. * size dram starting with external bank 3 moving to external bank 0
  201. */
  202. movl $0x3,%ecx /* start with external bank 3 */
  203. nextbank:
  204. /*
  205. * write col 11 wrap adr
  206. */
  207. movl $COL11_ADR, %esi /* set address to max col (11) wrap addr */
  208. movl $COL11_DATA, %eax /* pattern for max supported columns(11) */
  209. fs movl %eax, (%esi) /* write max col pattern at max col adr */
  210. fs movl (%esi), %ebx /* optional read */
  211. cmpl %ebx,%eax /* to verify write */
  212. jnz bad_ram /* this ram is bad */
  213. /*
  214. * write col 10 wrap adr
  215. */
  216. movl $COL10_ADR, %esi /* set address to 10 col wrap address */
  217. movl $COL10_DATA, %eax /* pattern for 10 col wrap */
  218. fs movl %eax, (%esi) /* write 10 col pattern @ 10 col wrap adr */
  219. fs movl (%esi), %ebx /* optional read */
  220. cmpl %ebx,%eax /* to verify write */
  221. jnz bad_ram /* this ram is bad */
  222. /*
  223. * write col 9 wrap adr
  224. */
  225. movl $COL09_ADR, %esi /* set address to 9 col wrap address */
  226. movl $COL09_DATA, %eax /* pattern for 9 col wrap */
  227. fs movl %eax, (%esi) /* write 9 col pattern @ 9 col wrap adr */
  228. fs movl (%esi), %ebx /* optional read */
  229. cmpl %ebx,%eax /* to verify write */
  230. jnz bad_ram /* this ram is bad */
  231. /*
  232. * write col 8 wrap adr
  233. */
  234. movl $COL08_ADR, %esi /* set address to min(8) col wrap address */
  235. movl $COL08_DATA, %eax /* pattern for min (8) col wrap */
  236. fs movl %eax, (%esi) /* write min col pattern @ min col adr */
  237. fs movl (%esi), %ebx /* optional read */
  238. cmpl %ebx,%eax /* to verify write */
  239. jnz bad_ram /* this ram is bad */
  240. /*
  241. * write row 14 wrap adr
  242. */
  243. movl $ROW14_ADR, %esi /* set address to max row (14) wrap addr */
  244. movl $ROW14_DATA, %eax /* pattern for max supported rows(14) */
  245. fs movl %eax, (%esi) /* write max row pattern at max row adr */
  246. fs movl (%esi), %ebx /* optional read */
  247. cmpl %ebx,%eax /* to verify write */
  248. jnz bad_ram /* this ram is bad */
  249. /*
  250. * write row 13 wrap adr
  251. */
  252. movl $ROW13_ADR, %esi /* set address to 13 row wrap address */
  253. movl $ROW13_DATA, %eax /* pattern for 13 row wrap */
  254. fs movl %eax, (%esi) /* write 13 row pattern @ 13 row wrap adr */
  255. fs movl (%esi), %ebx /* optional read */
  256. cmpl %ebx,%eax /* to verify write */
  257. jnz bad_ram /* this ram is bad */
  258. /*
  259. * write row 12 wrap adr
  260. */
  261. movl $ROW12_ADR, %esi /* set address to 12 row wrap address */
  262. movl $ROW12_DATA, %eax /* pattern for 12 row wrap */
  263. fs movl %eax, (%esi) /* write 12 row pattern @ 12 row wrap adr */
  264. fs movl (%esi), %ebx /* optional read */
  265. cmpl %ebx,%eax /* to verify write */
  266. jnz bad_ram /* this ram is bad */
  267. /*
  268. * write row 11 wrap adr
  269. */
  270. movl $ROW11_ADR, %edi /* set address to 11 row wrap address */
  271. movl $ROW11_DATA, %eax /* pattern for 11 row wrap */
  272. fs movl %eax, (%edi) /* write 11 row pattern @ 11 row wrap adr */
  273. fs movl (%edi), %ebx /* optional read */
  274. cmpl %ebx,%eax /* to verify write */
  275. jnz bad_ram /* this ram is bad */
  276. /*
  277. * write row 10 wrap adr --- this write is really to determine number of banks
  278. */
  279. movl $ROW10_ADR, %edi /* set address to 10 row wrap address */
  280. movl $ROW10_DATA, %eax /* pattern for 10 row wrap (AA) */
  281. fs movl %eax, (%edi) /* write 10 row pattern @ 10 row wrap adr */
  282. fs movl (%edi), %ebx /* optional read */
  283. cmpl %ebx,%eax /* to verify write */
  284. jnz bad_ram /* this ram is bad */
  285. /*
  286. * read data @ row 12 wrap adr to determine * banks,
  287. * and read data @ row 14 wrap adr to determine * rows.
  288. * if data @ row 12 wrap adr is not AA, 11 or 12 we have bad RAM.
  289. * if data @ row 12 wrap == AA, we only have 2 banks, NOT 4
  290. * if data @ row 12 wrap == 11 or 12, we have 4 banks,
  291. */
  292. xorw %di,%di /* value for 2 banks in DI */
  293. fs movl (%esi), %ebx /* read from 12 row wrap to check banks
  294. * (esi is setup from the write to row 12 wrap) */
  295. cmpl %ebx,%eax /* check for AA pattern (eax holds the aa pattern) */
  296. jz only2 /* if pattern == AA, we only have 2 banks */
  297. /* 4 banks */
  298. movw $8,%di /* value for 4 banks in DI (BNK_CNT bit) */
  299. cmpl $ROW11_DATA, %ebx /* only other legitimate values are 11 */
  300. jz only2
  301. cmpl $ROW12_DATA, %ebx /* and 12 */
  302. jnz bad_ram /* its bad if not 11 or 12! */
  303. /* fall through */
  304. only2:
  305. /*
  306. * validate row mask
  307. */
  308. movl $ROW14_ADR, %esi /* set address back to max row wrap addr */
  309. fs movl (%esi), %eax /* read actual number of rows @ row14 adr */
  310. cmpl $ROW11_DATA, %eax /* row must be greater than 11 pattern */
  311. jb bad_ram
  312. cmpl $ROW14_DATA, %eax /* and row must be less than 14 pattern */
  313. ja bad_ram
  314. cmpb %ah,%al /* verify all 4 bytes of dword same */
  315. jnz bad_ram
  316. movl %eax,%ebx
  317. shrl $16,%ebx
  318. cmpw %bx,%ax
  319. jnz bad_ram
  320. /*
  321. * read col 11 wrap adr for real column data value
  322. */
  323. movl $COL11_ADR, %esi /* set address to max col (11) wrap addr */
  324. fs movl (%esi), %eax /* read real col number at max col adr */
  325. /*
  326. * validate column data
  327. */
  328. cmpl $COL08_DATA, %eax /* col must be greater than 8 pattern */
  329. jb bad_ram
  330. cmpl $COL11_DATA, %eax /* and row must be less than 11 pattern */
  331. ja bad_ram
  332. subl $COL08_DATA, %eax /* normalize column data to zero */
  333. jc bad_ram
  334. cmpb %ah,%al /* verify all 4 bytes of dword equal */
  335. jnz bad_ram
  336. movl %eax,%edx
  337. shrl $16,%edx
  338. cmpw %dx,%ax
  339. jnz bad_ram
  340. /*
  341. * merge bank and col data together
  342. */
  343. addw %di,%dx /* merge of bank and col info in dl */
  344. /*
  345. * fix ending addr mask based upon col info
  346. */
  347. movb $3,%al
  348. subb %dh,%al /* dh contains the overflow from the bank/col merge */
  349. movb %bl,%dh /* bl contains the row mask (aa, 07, 0f, 1f or 3f) */
  350. xchgw %cx,%ax /* cx = ax = 3 or 2 depending on 2 or 4 bank device */
  351. shrb %cl,%dh /* */
  352. incb %dh /* ending addr is 1 greater than real end */
  353. xchgw %cx,%ax /* cx is bank number again */
  354. /*
  355. * issue all banks precharge
  356. */
  357. bad_reint:
  358. movl $DRCCTL, %esi /* setup DRAM control register with */
  359. movb $0x2,%al /* All banks precharge */
  360. fs movb %al, (%esi)
  361. movl $CACHELINESZ, %esi /* address to init read buffer */
  362. fs movw %ax, (%esi)
  363. /*
  364. * update ENDING ADDRESS REGISTER
  365. */
  366. movl $DRCBENDADR, %edi /* DRAM ending address register */
  367. movl %ecx,%ebx
  368. addl %ebx, %edi
  369. fs movb %dh, (%edi)
  370. /*
  371. * update CONFIG REGISTER
  372. */
  373. xorb %dh,%dh
  374. movw $0x00f,%bx
  375. movw %cx,%ax
  376. shlw $2,%ax
  377. xchgw %cx,%ax
  378. shlw %cl,%dx
  379. shlw %cl,%bx
  380. notw %bx
  381. xchgw %cx,%ax
  382. movl $DRCCFG, %edi
  383. fs mov (%edi), %ax
  384. andw %bx,%ax
  385. orw %dx,%ax
  386. fs movw %ax, (%edi)
  387. jcxz cleanup
  388. decw %cx
  389. movl %ecx,%ebx
  390. movl $DRCBENDADR, %edi /* DRAM ending address register */
  391. movb $0xff,%al
  392. addl %ebx, %edi
  393. fs movb %al, (%edi)
  394. /*
  395. * set control register to NORMAL mode
  396. */
  397. movl $DRCCTL, %esi /* setup DRAM control register with */
  398. movb $0x0,%al /* Normal mode value */
  399. fs movb %al, (%esi)
  400. movl $CACHELINESZ, %esi /* address to init read buffer */
  401. fs movw %ax, (%esi)
  402. jmp nextbank
  403. cleanup:
  404. movl $DRCBENDADR, %edi /* DRAM ending address register */
  405. movw $4,%cx
  406. xorw %ax,%ax
  407. cleanuplp:
  408. fs movb (%edi), %al
  409. orb %al,%al
  410. jz emptybank
  411. addb %ah,%al
  412. jns nottoomuch
  413. movb $0x7f,%al
  414. nottoomuch:
  415. movb %al,%ah
  416. orb $0x80,%al
  417. fs movb %al, (%edi)
  418. emptybank:
  419. incl %edi
  420. loop cleanuplp
  421. #if defined(CFG_SDRAM_CAS_LATENCY_2T) || defined(CFG_SDRAM_CAS_LATENCY_3T)
  422. /* set the CAS latency now since it is hard to do
  423. * when we run from the RAM */
  424. movl $DRCTMCTL, %edi /* DRAM timing register */
  425. movb (%edi), %al
  426. #ifdef CFG_SDRAM_CAS_LATENCY_2T
  427. andb $0xef, %al
  428. #endif
  429. #ifdef CFG_SDRAM_CAS_LATENCY_3T
  430. orb $0x10, %al
  431. #endif
  432. movb %al, (%edi)
  433. #endif
  434. movl $DRCCTL, %edi /* DRAM Control register */
  435. movb $0x3,%al /* Load mode register cmd */
  436. fs movb %al, (%edi)
  437. fs movw %ax, (%esi)
  438. movl $DRCCTL, %edi /* DRAM Control register */
  439. movb $0x18,%al /* Enable refresh and NORMAL mode */
  440. fs movb %al, (%edi)
  441. jmp dram_done
  442. bad_ram:
  443. xorl %edx,%edx
  444. xorl %edi,%edi
  445. jmp bad_reint
  446. dram_done:
  447. /* readback DRCBENDADR and return the number
  448. * of available ram bytes in %eax */
  449. movl $DRCBENDADR, %edi /* DRAM ending address register */
  450. movl (%edi), %eax
  451. movl %eax, %ecx
  452. andl $0x80000000, %ecx
  453. jz bank2
  454. andl $0x7f000000, %eax
  455. shrl $2, %eax
  456. movl %eax, %ebx
  457. bank2: movl (%edi), %eax
  458. movl %eax, %ecx
  459. andl $0x00800000, %ecx
  460. jz bank1
  461. andl $0x007f0000, %eax
  462. shll $6, %eax
  463. movl %eax, %ebx
  464. bank1: movl (%edi), %eax
  465. movl %eax, %ecx
  466. andl $0x00008000, %ecx
  467. jz bank0
  468. andl $0x00007f00, %eax
  469. shll $14, %eax
  470. movl %eax, %ebx
  471. bank0: movl (%edi), %eax
  472. movl %eax, %ecx
  473. andl $0x00000080, %ecx
  474. jz done
  475. andl $0x0000007f, %eax
  476. shll $22, %eax
  477. movl %eax, %ebx
  478. done: movl %ebx, %eax
  479. jmp *%ebp