1 /* this setupcpu function comes from: */
2 /*==============================================================================*/
3 /* FILE : start16.asm*/
5 /* DESC : A 16 bit mode assembly language startup program, intended for*/
6 /* use with on Aspen SC520 platforms.*/
8 /* 11/16/2000 Added support for the NetSC520*/
9 /* 12/28/2000 Modified to boot linux image*/
11 /* =============================================================================*/
13 /* Copyright 2000 Advanced Micro Devices, Inc. */
15 /* This software is the property of Advanced Micro Devices, Inc (AMD) which */
16 /* specifically grants the user the right to modify, use and distribute this */
17 /* software provided this COPYRIGHT NOTICE is not removed or altered. All */
18 /* other rights are reserved by AMD. */
20 /* THE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY */
21 /* OF ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT OF */
22 /* THIRD-PARTY INTELLECTUAL PROPERTY, OR FITNESS FOR ANY PARTICULAR PURPOSE.*/
23 /* IN NO EVENT SHALL AMD OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER*/
24 /* (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS*/
25 /* INTERRUPTION, LOSS OF INFORMATION) ARISING OUT OF THE USE OF OR INABILITY*/
26 /* TO USE THE MATERIALS, EVEN IF AMD HAS BEEN ADVISED OF THE POSSIBILITY OF*/
27 /* SUCH DAMAGES. BECAUSE SOME JURSIDICTIONS PROHIBIT THE EXCLUSION OR*/
28 /* LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE*/
29 /* LIMITATION MAY NOT APPLY TO YOU.*/
31 /* AMD does not assume any responsibility for any errors that may appear in*/
32 /* the Materials nor any responsibility to support or update the Materials.*/
33 /* AMD retains the right to make changes to its test specifications at any*/
34 /* time, without notice.*/
36 /* So that all may benefit from your experience, please report any problems */
37 /* or suggestions about this software back to AMD. Please include your name, */
38 /* company, telephone number, AMD product requiring support and question or */
39 /* problem encountered. */
41 /* Advanced Micro Devices, Inc. Worldwide support and contact */
42 /* Embedded Processor Division information available at: */
43 /* Systems Engineering epd.support@amd.com*/
44 /* 5204 E. Ben White Blvd. -or-*/
45 /* Austin, TX 78741 http://www.amd.com/html/support/techsup.html*/
46 /* ============================================================================*/
49 #define OUTC(addr, val) *(unsigned char *)(addr) = (val)
51 /* sadly, romcc can't quite handle what we want, so we do this ugly thing */
52 #define drcctl (( volatile unsigned char *)0xfffef010)
53 #define drcmctl (( volatile unsigned char *)0xfffef012)
54 #define drccfg (( volatile unsigned char *)0xfffef014)
56 #define drcbendadr (( volatile unsigned long *)0xfffef018)
57 #define eccctl (( volatile unsigned char *)0xfffef020)
58 #define dbctl (( volatile unsigned char *)0xfffef040)
62 volatile unsigned char *cp;
63 volatile unsigned short *sp;
64 volatile unsigned long *edi;
66 /* do this to see if MMCR will start acting right. we suspect
67 * you have to do SOMETHING to get things going. I'm really
68 * starting to hate this processor.
71 /* no, that did not help. I wonder what will?
72 * outl(0x800df0cb, 0xfffc);
75 /* well, this is special! You have to do SHORT writes to the
76 * locations, even though they are CHAR in size and CHAR aligned
77 * and technically, a SHORT write will result in -- yoo ha! --
78 * over writing the next location! Thanks to the u-boot guys
79 * for a reference code I can use. with these short pointers,
80 * it now reliably comes up after power cycle with printk. Ah yi
84 /* turn off the write buffer*/
85 /* per the note above, make this a short? Let's try it. */
86 sp = (unsigned short *)0xfffef040;
89 /* as per the book: */
90 /* PAR register setup */
91 /* set up the PAR registers as they are on the MSM586SEG */
92 /* moved to romstage.c by Stepan, Ron says: */
93 /* NOTE: move this to mainboard.c ASAP */
97 sp = (unsigned short *)0xfffefc24;
101 sp = (unsigned short *)0xfffefc80;
104 /* byte writes in AMD assembly */
105 /* we do short anyway, since u-boot does ... */
106 /*set the GP CS offset*/
107 sp = (unsigned short *)0xfffefc08;
109 /*set the GP CS width*/
110 sp = (unsigned short *)0xfffefc09;
113 /* short writes in AMD assembly */
114 /*set the GP CS width*/
115 sp = (unsigned short *)0xfffefc0a;
117 /*set the RD pulse width*/
118 sp = (unsigned short *)0xfffefc0b;
120 /*set the GP RD offset */
121 sp = (unsigned short *)0xfffefc0c;
123 /*set the GP WR pulse width*/
124 sp = (unsigned short *)0xfffefc0d;
126 /*set the GP WR offset*/
127 sp = (unsigned short *)0xfffefc0e;
131 /* set up the GP IO pins*/
132 /*set the GPIO directionreg*/
133 sp = (unsigned short *)0xfffefc2c;
135 /*set the GPIO directionreg*/
136 sp = (unsigned short *)0xfffefc2a;
138 /*set the GPIO pin function 31-16 reg*/
139 sp = (unsigned short *)0xfffefc22;
141 /*set the GPIO pin function 15-0 reg*/
142 sp = (unsigned short *)0xfffefc20;
146 /* the 0x80 led should now be working*/
149 /* wtf are 680 leds ... */
150 par = (unsigned long *) 0xfffef0c4;
156 /* set the uart baud rate clocks to the normal 1.8432 MHz.*/
157 /* enable interrupts here? Why not? */
158 cp = (unsigned char *)0xfffefcc0;
159 *cp = 4 | 3; /* uart 1 clock source */
160 cp = (unsigned char *)0xfffefcc4;
161 *cp = 4; /* uart 2 clock source */
164 /*; set the interrupt mapping registers.*/
165 cp = (unsigned char *)0x0fffefd20;
168 cp = (unsigned char *)0x0fffefd28;
171 cp = (unsigned char *)0x0fffefd29;
174 cp = (unsigned char *)0x0fffefd30;
177 cp = (unsigned char *)0x0fffefd43;
180 cp = (unsigned char *)0x0fffefd51;
184 /* Stepan says: This needs to go to the msm586seg code */
185 /* "enumerate" the PCI. Mainly set the interrupt bits on the PCnetFast. */
186 outl(0x08000683c, 0xcf8);
187 outl(0xc, 0xcfc); /* set the interrupt line */
190 /* Set the SC520 PCI host bridge to target mode to
191 * allow external bus mastering events
193 /* index the status command register on device 0*/
194 outl(0x080000004, 0x0cf8);
195 outl(0x2, 0xcfc); /*set the memory access enable bit*/
196 OUTC(0x0fffef072, 1); /* enable req bits in SYSARBMENB */
207 #define CACHELINESZ 0x00000010 /* size of our cache line (read buffer)*/
209 #define COL11_ADR *(unsigned int *)0x0e001e00 /* 11 col addrs*/
210 #define COL10_ADR *(unsigned int *)0x0e000e00 /* 10 col addrs*/
211 #define COL09_ADR *(unsigned int *)0x0e000600 /* 9 col addrs*/
212 #define COL08_ADR *(unsigned int *)0x0e000200 /* 8 col addrs*/
214 #define ROW14_ADR *(unsigned int *)0x0f000000 /* 14 row addrs*/
215 #define ROW13_ADR *(unsigned int *)0x07000000 /* 13 row addrs*/
216 #define ROW12_ADR *(unsigned int *)0x03000000 /* 12 row addrs*/
217 #define ROW11_ADR *(unsigned int *)0x01000000 /* 11 row addrs/also bank switch*/
218 #define ROW10_ADR *(unsigned int *)0x00000000 /* 10 row addrs/also bank switch*/
220 #define COL11_DATA 0x0b0b0b0b /* 11 col addrs*/
221 #define COL10_DATA 0x0a0a0a0a /* 10 col data*/
222 #define COL09_DATA 0x09090909 /* 9 col data*/
223 #define COL08_DATA 0x08080808 /* 8 col data*/
225 #define ROW14_DATA 0x3f3f3f3f /* 14 row data (MASK)*/
226 #define ROW13_DATA 0x1f1f1f1f /* 13 row data (MASK)*/
227 #define ROW12_DATA 0x0f0f0f0f /* 12 row data (MASK)*/
228 #define ROW11_DATA 0x07070707 /* 11 row data/also bank switch (MASK)*/
229 #define ROW10_DATA 0xaaaaaaaa /* 10 row data/also bank switch (MASK)*/
233 volatile unsigned short *ptr = (volatile unsigned short *)CACHELINESZ;
237 #include "pc80/udelay_io.c"
239 static void dumpram(void){
240 print_err("ctl "); print_err_hex8(*drcctl); print_err("\n");
241 print_err("mctl "); print_err_hex8(*drcmctl); print_err("\n");
242 print_err("cfg "); print_err_hex8(*drccfg); print_err("\n");
244 print_err("bendadr0 "); print_err_hex8(*drcbendadr); print_err("\n");
245 print_err("bendadr1 "); print_err_hex8(*drcbendadr); print_err("\n");
246 print_err("bendadr2 "); print_err_hex8(*drcbendadr); print_err("\n");
247 print_err("bendadr3"); print_err_hex8(*drcbendadr); print_err("\n");
250 /* there is a lot of silliness in the amd code, and it is
251 * causing romcc real headaches, so we're going to be be a little
253 * so, the order of ops is:
255 * see if bank is there.
256 * if we can write a word, and read it back, to hell with paranoia
257 * the bank is there. So write the magic byte, read it back, and
258 * use that to get size, etc. Try to keep things very simple,
259 * so people can actually follow the damned code.
262 /* cache is assumed to be disabled */
266 int rows,banks, cols, i, bank;
268 volatile unsigned long *lp = (volatile unsigned long *) CACHELINESZ;
270 /* initialize dram controller registers */
271 /* disable write buffer/read-ahead buffer */
273 /* no ecc interrupts of any kind. */
275 /* Set SDRAM timing for slowest speed. */
278 /* setup dram register for all banks
279 * with max cols and max banks
280 * this is the oldest trick in the book. You are going to set up for max rows
281 * and cols, then do a write, then see if the data is wrapped to low memory.
282 * you can actually tell by which data gets to which low memory,
283 * exactly how many rows and cols you have.
287 /* setup loop to do 4 external banks starting with bank 3 */
288 *drcbendadr=0x0ff000000;
289 /* for now, set it up for one loop of bank 0. Just to get it to go at all. */
292 /* issue a NOP to all DRAMs */
293 /* Setup DRAM control register with Disable refresh,
294 * disable write buffer Test Mode and NOP command select
298 /* dummy write for NOP to take effect */
303 print_err("after udelay\n");
305 /* issue all banks precharge */
307 print_err("set *drcctl to 2 \n");
311 /* issue 2 auto refreshes to all banks */
314 print_err("AUTO1\n");
316 print_err("AUTO2\n");
318 /* issue LOAD MODE REGISTER command */
321 print_err("LOAD MODE REG\n");
324 for (i=0; i<8; i++) /* refresh 8 times */{
326 print_err("dummy write\n");
328 print_err("8 dummy writes\n");
330 /* set control register to NORMAL mode */
332 print_err("normal\n");
334 print_err("HI done normal\n");
336 print_err("sizemem\n");
337 for(bank = 3; bank >= 0; bank--) {
338 print_err("Try to assign to l\n");
340 print_err("assigned l ... \n");
341 if (*lp != 0xdeadbeef) {
342 print_err(" no memory at bank ");
343 // print_err_hex8(bank);
344 // print_err(" value "); print_err_hex32(*lp);
350 *drccfg = *drccfg >> 4;
354 print_err("loop around\n");
359 /* enable last bank and setup ending address
360 * register for max ram in last bank
362 *drcbendadr=0x0ff000000;
367 /* issue a NOP to all DRAMs */
368 /* Setup DRAM control register with Disable refresh,
369 * disable write buffer Test Mode and NOP command select
373 /* dummy write for NOP to take effect */
378 print_err("after udelay\n");
380 /* issue all banks precharge */
382 print_err("set *drcctl to 2 \n");
386 /* issue 2 auto refreshes to all banks */
389 print_err("AUTO1\n");
391 print_err("AUTO2\n");
393 /* issue LOAD MODE REGISTER command */
396 print_err("LOAD MODE REG\n");
399 for (i=0; i<8; i++) /* refresh 8 times */{
401 print_err("dummy write\n");
403 print_err("8 dummy writes\n");
405 /* set control register to NORMAL mode */
407 print_err("normal\n");
409 print_err("HI done normal\n");
413 /* this is really ugly, it is right from assembly code.
414 * we need to clean it up later
418 /* write col 11 wrap adr */
419 COL11_ADR=COL11_DATA;
420 if(COL11_ADR!=COL11_DATA)
424 /* write col 10 wrap adr */
425 COL10_ADR=COL10_DATA;
426 if(COL10_ADR!=COL10_DATA)
430 /* write col 9 wrap adr */
431 COL09_ADR=COL09_DATA;
432 if(COL09_ADR!=COL09_DATA)
436 /* write col 8 wrap adr */
437 COL08_ADR=COL08_DATA;
438 if(COL08_ADR!=COL08_DATA)
442 /* write row 14 wrap adr */
443 ROW14_ADR=ROW14_DATA;
444 if(ROW14_ADR!=ROW14_DATA)
448 /* write row 13 wrap adr */
449 ROW13_ADR=ROW13_DATA;
450 if(ROW13_ADR!=ROW13_DATA)
454 /* write row 12 wrap adr */
455 ROW12_ADR=ROW12_DATA;
456 if(ROW12_ADR!=ROW12_DATA)
460 /* write row 11 wrap adr */
461 ROW11_ADR=ROW11_DATA;
462 if(ROW11_ADR!=ROW11_DATA)
466 /* write row 10 wrap adr */
467 ROW10_ADR=ROW10_DATA;
468 if(ROW10_ADR!=ROW10_DATA)
473 * read data @ row 12 wrap adr to determine # banks,
474 * and read data @ row 14 wrap adr to determine # rows.
475 * if data @ row 12 wrap adr is not AA, 11 or 12 we have bad RAM.
476 * if data @ row 12 wrap == AA, we only have 2 banks, NOT 4
477 * if data @ row 12 wrap == 11 or 12, we have 4 banks
481 if (ROW12_ADR != ROW10_DATA) {
484 if(ROW12_ADR != ROW11_DATA) {
485 if(ROW12_ADR != ROW12_DATA)
490 /* validate row mask */
496 /* verify all 4 bytes of dword same */
498 if(rows&0xffff!=(rows>>16)&0xffff)
500 if(rows&0xff!=(rows>>8)&0xff)
503 /* now just get one of them */
505 print_err("rows"); print_err_hex32(rows); print_err("\n");
506 /* validate column data */
512 /* verify all 4 bytes of dword same */
514 if(cols&0xffff!=(cols>>16)&0xffff)
516 if(cols&0xff!=(cols>>8)&0xff)
519 print_err("cols"); print_err_hex32(cols); print_err("\n");
522 /* cols now is in the range of 0 1 2 3 ...
527 /* wacky end addr calculation */
533 /* what a fookin' mess this is */
535 i+=8; /* <-- i holds merged value */
536 /* i now has the col width in bits 0-1 and the bank count (2 or 4)
538 * this is the format for the drccfg register
541 /* fix ending addr mask*/
543 /* let's just go with this to start ... see if we can get ANYWHERE */
544 /* need to get end addr. Need to do it with the bank in mind. */
548 *drcbendaddr = rows >> al;
549 print_err("computed ending_adr = "); print_err_hex8(ending_adr);
554 /* issue all banks recharge */
558 /* update ending address register */
559 // *drcbendadr = ending_adr;
561 /* update config register */
562 *drccfg &= ~(0xff << bank*4);
564 *drccfg = ((banks == 4 ? 8 : 0) | cols & 3)<< (bank*4);
566 /* skip the rest for now */
568 // *drccfg=*drccfg&YYY|ZZZZ;
573 *drcbendaddr = 0xff000000;
574 //*(&*drcbendadr+XXYYXX)=0xff;
578 /* set control register to NORMAL mode */
584 print_info("bad ram!\n");
585 /* you are here because the read-after-write failed,
586 * in most cases because: no ram in that bank!
587 * set badbank to 1 and go to reinit
592 print_err("DONE NEXTBANK\n");
596 /* note: based on AMD code*/
597 /* This code is known to work on the digital logic board and on the technologic
602 volatile unsigned long *zero = (unsigned long *) CACHELINESZ;
604 /* set up 0x18 .. **/
610 /* do the dummy write */
617 /* two autorefreshes */
620 print_debug("one zero out on refresh\n");
622 print_debug("two zero out on refresh\n");
624 /* load mode register */
627 print_debug("DONE the load mode reg\n");
632 print_debug("DONE one last write and then turn on refresh etc\n");
635 print_debug("DONE the normal\n");
637 if (*zero != 0xdeadbeef)
638 print_debug("NO LUCK\n");
640 print_debug("did a store and load ...\n");
641 //print_err_hex32(*zero);
642 // print_err(" zero is now "); print_err_hex32(*zero); print_err("\n");