luan.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*
  2. * (C) Copyright 2005
  3. * John Otken, jotken@softadvances.com
  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. #include <common.h>
  24. #include <command.h>
  25. #include <ppc4xx.h>
  26. #include <asm/processor.h>
  27. #include <spd_sdram.h>
  28. #include "epld.h"
  29. DECLARE_GLOBAL_DATA_PTR;
  30. extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
  31. /*************************************************************************
  32. * int board_early_init_f()
  33. *
  34. ************************************************************************/
  35. int board_early_init_f(void)
  36. {
  37. volatile epld_t *x = (epld_t *) CFG_EPLD_BASE;
  38. mtebc( pb0ap, 0x03800000 ); /* set chip selects */
  39. mtebc( pb0cr, 0xffc58000 ); /* ebc0_b0cr, 4MB at 0xffc00000 CS0 */
  40. mtebc( pb1ap, 0x03800000 );
  41. mtebc( pb1cr, 0xff018000 ); /* ebc0_b1cr, 1MB at 0xff000000 CS1 */
  42. mtebc( pb2ap, 0x03800000 );
  43. mtebc( pb2cr, 0xff838000 ); /* ebc0_b2cr, 2MB at 0xff800000 CS2 */
  44. mtdcr( uic1sr, 0xffffffff ); /* Clear all interrupts */
  45. mtdcr( uic1er, 0x00000000 ); /* disable all interrupts */
  46. mtdcr( uic1cr, 0x00000000 ); /* Set Critical / Non Critical interrupts */
  47. mtdcr( uic1pr, 0x7fff83ff ); /* Set Interrupt Polarities */
  48. mtdcr( uic1tr, 0x001f8000 ); /* Set Interrupt Trigger Levels */
  49. mtdcr( uic1vr, 0x00000001 ); /* Set Vect base=0,INT31 Highest priority */
  50. mtdcr( uic1sr, 0x00000000 ); /* clear all interrupts */
  51. mtdcr( uic1sr, 0xffffffff );
  52. mtdcr( uic0sr, 0xffffffff ); /* Clear all interrupts */
  53. mtdcr( uic0er, 0x00000000 ); /* disable all interrupts excepted cascade */
  54. mtdcr( uic0cr, 0x00000001 ); /* Set Critical / Non Critical interrupts */
  55. mtdcr( uic0pr, 0xffffffff ); /* Set Interrupt Polarities */
  56. mtdcr( uic0tr, 0x01000004 ); /* Set Interrupt Trigger Levels */
  57. mtdcr( uic0vr, 0x00000001 ); /* Set Vect base=0,INT31 Highest priority */
  58. mtdcr( uic0sr, 0x00000000 ); /* clear all interrupts */
  59. mtdcr( uic0sr, 0xffffffff );
  60. x->ethuart &= ~EPLD2_RESET_ETH_N; /* put Ethernet+PHY in reset */
  61. return 0;
  62. }
  63. /*************************************************************************
  64. * int misc_init_r()
  65. *
  66. ************************************************************************/
  67. int misc_init_r(void)
  68. {
  69. volatile epld_t *x = (epld_t *) CFG_EPLD_BASE;
  70. x->ethuart |= EPLD2_RESET_ETH_N; /* take Ethernet+PHY out of reset */
  71. return 0;
  72. }
  73. /*************************************************************************
  74. * int checkboard()
  75. *
  76. ************************************************************************/
  77. int checkboard(void)
  78. {
  79. char *s = getenv("serial#");
  80. printf("Board: Luan - AMCC PPC440SP Evaluation Board");
  81. if (s != NULL) {
  82. puts(", serial# ");
  83. puts(s);
  84. }
  85. putc('\n');
  86. return 0;
  87. }
  88. /*************************************************************************
  89. * long int fixed_sdram()
  90. *
  91. ************************************************************************/
  92. static long int fixed_sdram(void)
  93. { /* DDR2 init from BDI2000 script */
  94. mtdcr( 0x10, 0x00000021 ); /* MCIF0_MCOPT2 - zero DCEN bit */
  95. mtdcr( 0x11, 0x84000000 );
  96. mtdcr( 0x10, 0x00000020 ); /* MCIF0_MCOPT1 - no ECC, 64 bits, 4 banks, DDR2 */
  97. mtdcr( 0x11, 0x2D122000 );
  98. mtdcr( 0x10, 0x00000026 ); /* MCIF0_CODT - die termination on */
  99. mtdcr( 0x11, 0x00800026 );
  100. mtdcr( 0x10, 0x00000081 ); /* MCIF0_WRDTR - Write DQS Adv 90 + Fractional DQS Delay */
  101. mtdcr( 0x11, 0x82000800 );
  102. mtdcr( 0x10, 0x00000080 ); /* MCIF0_CLKTR - advance addr clock by 180 deg */
  103. mtdcr( 0x11, 0x80000000 );
  104. mtdcr( 0x10, 0x00000040 ); /* MCIF0_MB0CF - turn on CS0, N x 10 coll */
  105. mtdcr( 0x11, 0x00000201 );
  106. mtdcr( 0x10, 0x00000044 ); /* MCIF0_MB1CF - turn on CS0, N x 10 coll */
  107. mtdcr( 0x11, 0x00000201 );
  108. mtdcr( 0x10, 0x00000030 ); /* MCIF0_RTR - refresh every 7.8125uS */
  109. mtdcr( 0x11, 0x08200000 );
  110. mtdcr( 0x10, 0x00000085 ); /* MCIF0_SDTR1 - timing register 1 */
  111. mtdcr( 0x11, 0x80201000 );
  112. mtdcr( 0x10, 0x00000086 ); /* MCIF0_SDTR2 - timing register 2 */
  113. mtdcr( 0x11, 0x42103242 );
  114. mtdcr( 0x10, 0x00000087 ); /* MCIF0_SDTR3 - timing register 3 */
  115. mtdcr( 0x11, 0x0C100D14 );
  116. mtdcr( 0x10, 0x00000088 ); /* MCIF0_MMODE - CAS is 4 cycles */
  117. mtdcr( 0x11, 0x00000642 );
  118. mtdcr( 0x10, 0x00000089 ); /* MCIF0_MEMODE - diff DQS disabled */
  119. mtdcr( 0x11, 0x00000400 ); /* ODT term disabled */
  120. mtdcr( 0x10, 0x00000050 ); /* MCIF0_INITPLR0 - NOP */
  121. mtdcr( 0x11, 0x81b80000 );
  122. mtdcr( 0x10, 0x00000051 ); /* MCIF0_INITPLR1 - PRE */
  123. mtdcr( 0x11, 0x82100400 );
  124. mtdcr( 0x10, 0x00000052 ); /* MCIF0_INITPLR2 - EMR2 */
  125. mtdcr( 0x11, 0x80820000 );
  126. mtdcr( 0x10, 0x00000053 ); /* MCIF0_INITPLR3 - EMR3 */
  127. mtdcr( 0x11, 0x80830000 );
  128. mtdcr( 0x10, 0x00000054 ); /* MCIF0_INITPLR4 - EMR DLL ENABLE */
  129. mtdcr( 0x11, 0x80810000 );
  130. mtdcr( 0x10, 0x00000055 ); /* MCIF0_INITPLR5 - MR DLL RESET */
  131. mtdcr( 0x11, 0x80800542 );
  132. mtdcr( 0x10, 0x00000056 ); /* MCIF0_INITPLR6 - PRE */
  133. mtdcr( 0x11, 0x82100400 );
  134. mtdcr( 0x10, 0x00000057 ); /* MCIF0_INITPLR7 - refresh */
  135. mtdcr( 0x11, 0x99080000 );
  136. mtdcr( 0x10, 0x00000058 ); /* MCIF0_INITPLR8 */
  137. mtdcr( 0x11, 0x99080000 );
  138. mtdcr( 0x10, 0x00000059 ); /* MCIF0_INITPLR9 */
  139. mtdcr( 0x11, 0x99080000 );
  140. mtdcr( 0x10, 0x0000005A ); /* MCIF0_INITPLR10 */
  141. mtdcr( 0x11, 0x99080000 );
  142. mtdcr( 0x10, 0x0000005B ); /* MCIF0_INITPLR11 - MR */
  143. mtdcr( 0x11, 0x80800442 );
  144. mtdcr( 0x10, 0x0000005C ); /* MCIF0_INITPLR12 - EMR OCD Default */
  145. mtdcr( 0x11, 0x80810380 );
  146. mtdcr( 0x10, 0x0000005D ); /* MCIF0_INITPLR13 - EMR OCD exit */
  147. mtdcr( 0x11, 0x80810000 );
  148. udelay( 10*1000 );
  149. mtdcr( 0x10, 0x00000021 ); /* MCIF0_MCOPT2 - execute preloaded init */
  150. mtdcr( 0x11, 0x28000000 ); /* set DC_EN */
  151. udelay( 100*1000 );
  152. mtdcr( 0x40, 0x0000F800 ); /* MQ0_B0BAS: base addr 00000000 / 256MB */
  153. mtdcr( 0x41, 0x1000F800 ); /* MQ0_B1BAS: base addr 10000000 / 256MB */
  154. mtdcr( 0x10, 0x00000078 ); /* MCIF0_RDCC - auto set read stage */
  155. mtdcr( 0x11, 0x00000000 );
  156. mtdcr( 0x10, 0x00000070 ); /* MCIF0_RQDC - read DQS delay control */
  157. mtdcr( 0x11, 0x8000003A ); /* enabled, frac DQS delay */
  158. mtdcr( 0x10, 0x00000074 ); /* MCIF0_RFDC - two clock feedback delay */
  159. mtdcr( 0x11, 0x00000200 );
  160. return 512 << 20;
  161. }
  162. /*************************************************************************
  163. * long int initdram
  164. *
  165. ************************************************************************/
  166. long int initdram( int board_type )
  167. {
  168. long dram_size = 0;
  169. #if defined(CONFIG_SPD_EEPROM)
  170. dram_size = spd_sdram (0);
  171. #else
  172. dram_size = fixed_sdram ();
  173. #endif
  174. return dram_size;
  175. }
  176. /*************************************************************************
  177. * int testdram()
  178. *
  179. ************************************************************************/
  180. #if defined(CFG_DRAM_TEST)
  181. int testdram(void)
  182. {
  183. unsigned long *mem = (unsigned long *) 0;
  184. const unsigned long kend = (1024 / sizeof(unsigned long));
  185. unsigned long k, n;
  186. mtmsr(0);
  187. for (k = 0; k < CFG_KBYTES_SDRAM;
  188. ++k, mem += (1024 / sizeof(unsigned long))) {
  189. if ((k & 1023) == 0) {
  190. printf("%3d MB\r", k / 1024);
  191. }
  192. memset(mem, 0xaaaaaaaa, 1024);
  193. for (n = 0; n < kend; ++n) {
  194. if (mem[n] != 0xaaaaaaaa) {
  195. printf("SDRAM test fails at: %08x\n",
  196. (uint) & mem[n]);
  197. return 1;
  198. }
  199. }
  200. memset(mem, 0x55555555, 1024);
  201. for (n = 0; n < kend; ++n) {
  202. if (mem[n] != 0x55555555) {
  203. printf("SDRAM test fails at: %08x\n",
  204. (uint) & mem[n]);
  205. return 1;
  206. }
  207. }
  208. }
  209. printf("SDRAM test passes\n");
  210. return 0;
  211. }
  212. #endif
  213. /*************************************************************************
  214. * pci_pre_init
  215. *
  216. * This routine is called just prior to registering the hose and gives
  217. * the board the opportunity to check things. Returning a value of zero
  218. * indicates that things are bad & PCI initialization should be aborted.
  219. *
  220. * Different boards may wish to customize the pci controller structure
  221. * (add regions, override default access routines, etc) or perform
  222. * certain pre-initialization actions.
  223. *
  224. ************************************************************************/
  225. #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
  226. int pci_pre_init( struct pci_controller *hose )
  227. {
  228. unsigned long strap;
  229. /*--------------------------------------------------------------------------+
  230. * The luan board is always configured as the host & requires the
  231. * PCI arbiter to be enabled.
  232. *--------------------------------------------------------------------------*/
  233. mfsdr(sdr_sdstp1, strap);
  234. if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ) {
  235. printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap);
  236. return 0;
  237. }
  238. return 1;
  239. }
  240. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
  241. /*************************************************************************
  242. * pci_target_init
  243. *
  244. * The bootstrap configuration provides default settings for the pci
  245. * inbound map (PIM). But the bootstrap config choices are limited and
  246. * may not be sufficient for a given board.
  247. *
  248. ************************************************************************/
  249. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  250. void pci_target_init(struct pci_controller *hose)
  251. {
  252. /*--------------------------------------------------------------------------+
  253. * Disable everything
  254. *--------------------------------------------------------------------------*/
  255. out32r( PCIX0_PIM0SA, 0 ); /* disable */
  256. out32r( PCIX0_PIM1SA, 0 ); /* disable */
  257. out32r( PCIX0_PIM2SA, 0 ); /* disable */
  258. out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */
  259. /*--------------------------------------------------------------------------+
  260. * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
  261. * options to not support sizes such as 128/256 MB.
  262. *--------------------------------------------------------------------------*/
  263. out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE );
  264. out32r( PCIX0_PIM0LAH, 0 );
  265. out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 );
  266. out32r( PCIX0_BAR0, 0 );
  267. /*--------------------------------------------------------------------------+
  268. * Program the board's subsystem id/vendor id
  269. *--------------------------------------------------------------------------*/
  270. out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID );
  271. out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID );
  272. out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY );
  273. }
  274. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  275. /*************************************************************************
  276. * is_pci_host
  277. *
  278. * This routine is called to determine if a pci scan should be
  279. * performed. With various hardware environments (especially cPCI and
  280. * PPMC) it's insufficient to depend on the state of the arbiter enable
  281. * bit in the strap register, or generic host/adapter assumptions.
  282. *
  283. * Rather than hard-code a bad assumption in the general 440 code, the
  284. * 440 pci code requires the board to decide at runtime.
  285. *
  286. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  287. *
  288. *
  289. ************************************************************************/
  290. #if defined(CONFIG_PCI)
  291. int is_pci_host(struct pci_controller *hose)
  292. {
  293. return 1;
  294. }
  295. #endif /* defined(CONFIG_PCI) */
  296. /*************************************************************************
  297. * hw_watchdog_reset
  298. *
  299. * This routine is called to reset (keep alive) the watchdog timer
  300. *
  301. ************************************************************************/
  302. #if defined(CONFIG_HW_WATCHDOG)
  303. void hw_watchdog_reset(void)
  304. {
  305. }
  306. #endif
  307. /*************************************************************************
  308. * int on_off()
  309. *
  310. ************************************************************************/
  311. static int on_off( const char *s )
  312. {
  313. if (strcmp(s, "on") == 0) {
  314. return 1;
  315. } else if (strcmp(s, "off") == 0) {
  316. return 0;
  317. }
  318. return -1;
  319. }
  320. /*************************************************************************
  321. * void l2cache_disable()
  322. *
  323. ************************************************************************/
  324. static void l2cache_disable(void)
  325. {
  326. mtdcr( l2_cache_cfg, 0 );
  327. }
  328. /*************************************************************************
  329. * void l2cache_enable()
  330. *
  331. ************************************************************************/
  332. static void l2cache_enable(void) /* see p258 7.4.1 Enabling L2 Cache */
  333. {
  334. mtdcr( l2_cache_cfg, 0x80000000 ); /* enable L2_MODE L2_CFG[L2M] */
  335. mtdcr( l2_cache_addr, 0 ); /* set L2_ADDR with all zeros */
  336. mtdcr( l2_cache_cmd, 0x80000000 ); /* issue HCLEAR command via L2_CMD */
  337. while (!(mfdcr( l2_cache_stat ) & 0x80000000 )) ;; /* poll L2_SR for completion */
  338. mtdcr( l2_cache_cmd, 0x10000000 ); /* clear cache errors L2_CMD[CCP] */
  339. mtdcr( l2_cache_cmd, 0x08000000 ); /* clear tag errors L2_CMD[CTE] */
  340. mtdcr( l2_cache_snp0, 0 ); /* snoop registers */
  341. mtdcr( l2_cache_snp1, 0 );
  342. __asm__ volatile ("sync"); /* msync */
  343. mtdcr( l2_cache_cfg, 0xe0000000 ); /* inst and data use L2 */
  344. __asm__ volatile ("sync");
  345. }
  346. /*************************************************************************
  347. * int l2cache_status()
  348. *
  349. ************************************************************************/
  350. static int l2cache_status(void)
  351. {
  352. return (mfdcr( l2_cache_cfg ) & 0x60000000) != 0;
  353. }
  354. /*************************************************************************
  355. * int do_l2cache()
  356. *
  357. ************************************************************************/
  358. int do_l2cache( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
  359. {
  360. switch (argc) {
  361. case 2: /* on / off */
  362. switch (on_off(argv[1])) {
  363. case 0: l2cache_disable();
  364. break;
  365. case 1: l2cache_enable();
  366. break;
  367. }
  368. /* FALL TROUGH */
  369. case 1: /* get status */
  370. printf ("L2 Cache is %s\n",
  371. l2cache_status() ? "ON" : "OFF");
  372. return 0;
  373. default:
  374. printf ("Usage:\n%s\n", cmdtp->usage);
  375. return 1;
  376. }
  377. return 0;
  378. }
  379. U_BOOT_CMD(
  380. l2cache, 2, 1, do_l2cache,
  381. "l2cache - enable or disable L2 cache\n",
  382. "[on, off]\n"
  383. " - enable or disable L2 cache\n"
  384. );