luan.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. u32 mfr;
  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. mfsdr(sdr_mfr, mfr);
  61. mfr |= SDR0_MFR_FIXD; /* Workaround for PCI/DMA */
  62. mtsdr(sdr_mfr, mfr);
  63. return 0;
  64. }
  65. /*************************************************************************
  66. * int misc_init_r()
  67. *
  68. ************************************************************************/
  69. int misc_init_r(void)
  70. {
  71. volatile epld_t *x = (epld_t *) CFG_EPLD_BASE;
  72. /* set modes of operation */
  73. x->ethuart |= EPLD2_ETH_MODE_10 | EPLD2_ETH_MODE_100 |
  74. EPLD2_ETH_MODE_1000 | EPLD2_ETH_DUPLEX_MODE;
  75. /* clear ETHERNET_AUTO_NEGO bit to turn on autonegotiation */
  76. x->ethuart &= ~EPLD2_ETH_AUTO_NEGO;
  77. /* put Ethernet+PHY in reset */
  78. x->ethuart &= ~EPLD2_RESET_ETH_N;
  79. udelay(10000);
  80. /* take Ethernet+PHY out of reset */
  81. x->ethuart |= EPLD2_RESET_ETH_N;
  82. return 0;
  83. }
  84. /*************************************************************************
  85. * int checkboard()
  86. *
  87. ************************************************************************/
  88. int checkboard(void)
  89. {
  90. char *s = getenv("serial#");
  91. printf("Board: Luan - AMCC PPC440SP Evaluation Board");
  92. if (s != NULL) {
  93. puts(", serial# ");
  94. puts(s);
  95. }
  96. putc('\n');
  97. return 0;
  98. }
  99. /*
  100. * Override the default functions in cpu/ppc4xx/44x_spd_ddr2.c with
  101. * board specific values.
  102. */
  103. u32 ddr_clktr(u32 default_val) {
  104. return (SDRAM_CLKTR_CLKP_180_DEG_ADV);
  105. }
  106. /*************************************************************************
  107. * int testdram()
  108. *
  109. ************************************************************************/
  110. #if defined(CFG_DRAM_TEST)
  111. int testdram(void)
  112. {
  113. unsigned long *mem = (unsigned long *) 0;
  114. const unsigned long kend = (1024 / sizeof(unsigned long));
  115. unsigned long k, n;
  116. mtmsr(0);
  117. for (k = 0; k < CFG_KBYTES_SDRAM;
  118. ++k, mem += (1024 / sizeof(unsigned long))) {
  119. if ((k & 1023) == 0) {
  120. printf("%3d MB\r", k / 1024);
  121. }
  122. memset(mem, 0xaaaaaaaa, 1024);
  123. for (n = 0; n < kend; ++n) {
  124. if (mem[n] != 0xaaaaaaaa) {
  125. printf("SDRAM test fails at: %08x\n",
  126. (uint) & mem[n]);
  127. return 1;
  128. }
  129. }
  130. memset(mem, 0x55555555, 1024);
  131. for (n = 0; n < kend; ++n) {
  132. if (mem[n] != 0x55555555) {
  133. printf("SDRAM test fails at: %08x\n",
  134. (uint) & mem[n]);
  135. return 1;
  136. }
  137. }
  138. }
  139. printf("SDRAM test passes\n");
  140. return 0;
  141. }
  142. #endif
  143. /*************************************************************************
  144. * pci_pre_init
  145. *
  146. * This routine is called just prior to registering the hose and gives
  147. * the board the opportunity to check things. Returning a value of zero
  148. * indicates that things are bad & PCI initialization should be aborted.
  149. *
  150. * Different boards may wish to customize the pci controller structure
  151. * (add regions, override default access routines, etc) or perform
  152. * certain pre-initialization actions.
  153. *
  154. ************************************************************************/
  155. #if defined(CONFIG_PCI)
  156. int pci_pre_init( struct pci_controller *hose )
  157. {
  158. unsigned long strap;
  159. /*--------------------------------------------------------------------------+
  160. * The luan board is always configured as the host & requires the
  161. * PCI arbiter to be enabled.
  162. *--------------------------------------------------------------------------*/
  163. mfsdr(sdr_sdstp1, strap);
  164. if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ) {
  165. printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap);
  166. return 0;
  167. }
  168. return 1;
  169. }
  170. #endif /* defined(CONFIG_PCI) */
  171. /*************************************************************************
  172. * pci_target_init
  173. *
  174. * The bootstrap configuration provides default settings for the pci
  175. * inbound map (PIM). But the bootstrap config choices are limited and
  176. * may not be sufficient for a given board.
  177. *
  178. ************************************************************************/
  179. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  180. void pci_target_init(struct pci_controller *hose)
  181. {
  182. /*--------------------------------------------------------------------------+
  183. * Disable everything
  184. *--------------------------------------------------------------------------*/
  185. out32r( PCIX0_PIM0SA, 0 ); /* disable */
  186. out32r( PCIX0_PIM1SA, 0 ); /* disable */
  187. out32r( PCIX0_PIM2SA, 0 ); /* disable */
  188. out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */
  189. /*--------------------------------------------------------------------------+
  190. * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
  191. * options to not support sizes such as 128/256 MB.
  192. *--------------------------------------------------------------------------*/
  193. out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE );
  194. out32r( PCIX0_PIM0LAH, 0 );
  195. out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 );
  196. out32r( PCIX0_BAR0, 0 );
  197. /*--------------------------------------------------------------------------+
  198. * Program the board's subsystem id/vendor id
  199. *--------------------------------------------------------------------------*/
  200. out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID );
  201. out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID );
  202. out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY );
  203. }
  204. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  205. /*************************************************************************
  206. * is_pci_host
  207. *
  208. * This routine is called to determine if a pci scan should be
  209. * performed. With various hardware environments (especially cPCI and
  210. * PPMC) it's insufficient to depend on the state of the arbiter enable
  211. * bit in the strap register, or generic host/adapter assumptions.
  212. *
  213. * Rather than hard-code a bad assumption in the general 440 code, the
  214. * 440 pci code requires the board to decide at runtime.
  215. *
  216. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  217. *
  218. *
  219. ************************************************************************/
  220. #if defined(CONFIG_PCI)
  221. int is_pci_host(struct pci_controller *hose)
  222. {
  223. return 1;
  224. }
  225. #endif /* defined(CONFIG_PCI) */
  226. /*************************************************************************
  227. * hw_watchdog_reset
  228. *
  229. * This routine is called to reset (keep alive) the watchdog timer
  230. *
  231. ************************************************************************/
  232. #if defined(CONFIG_HW_WATCHDOG)
  233. void hw_watchdog_reset(void)
  234. {
  235. }
  236. #endif
  237. /*************************************************************************
  238. * int on_off()
  239. *
  240. ************************************************************************/
  241. static int on_off( const char *s )
  242. {
  243. if (strcmp(s, "on") == 0) {
  244. return 1;
  245. } else if (strcmp(s, "off") == 0) {
  246. return 0;
  247. }
  248. return -1;
  249. }
  250. /*************************************************************************
  251. * void l2cache_disable()
  252. *
  253. ************************************************************************/
  254. static void l2cache_disable(void)
  255. {
  256. mtdcr( l2_cache_cfg, 0 );
  257. }
  258. /*************************************************************************
  259. * void l2cache_enable()
  260. *
  261. ************************************************************************/
  262. static void l2cache_enable(void) /* see p258 7.4.1 Enabling L2 Cache */
  263. {
  264. mtdcr( l2_cache_cfg, 0x80000000 ); /* enable L2_MODE L2_CFG[L2M] */
  265. mtdcr( l2_cache_addr, 0 ); /* set L2_ADDR with all zeros */
  266. mtdcr( l2_cache_cmd, 0x80000000 ); /* issue HCLEAR command via L2_CMD */
  267. while (!(mfdcr( l2_cache_stat ) & 0x80000000 )) ;; /* poll L2_SR for completion */
  268. mtdcr( l2_cache_cmd, 0x10000000 ); /* clear cache errors L2_CMD[CCP] */
  269. mtdcr( l2_cache_cmd, 0x08000000 ); /* clear tag errors L2_CMD[CTE] */
  270. mtdcr( l2_cache_snp0, 0 ); /* snoop registers */
  271. mtdcr( l2_cache_snp1, 0 );
  272. __asm__ volatile ("sync"); /* msync */
  273. mtdcr( l2_cache_cfg, 0xe0000000 ); /* inst and data use L2 */
  274. __asm__ volatile ("sync");
  275. }
  276. /*************************************************************************
  277. * int l2cache_status()
  278. *
  279. ************************************************************************/
  280. static int l2cache_status(void)
  281. {
  282. return (mfdcr( l2_cache_cfg ) & 0x60000000) != 0;
  283. }
  284. /*************************************************************************
  285. * int do_l2cache()
  286. *
  287. ************************************************************************/
  288. int do_l2cache( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
  289. {
  290. switch (argc) {
  291. case 2: /* on / off */
  292. switch (on_off(argv[1])) {
  293. case 0: l2cache_disable();
  294. break;
  295. case 1: l2cache_enable();
  296. break;
  297. }
  298. /* FALL TROUGH */
  299. case 1: /* get status */
  300. printf ("L2 Cache is %s\n",
  301. l2cache_status() ? "ON" : "OFF");
  302. return 0;
  303. default:
  304. printf ("Usage:\n%s\n", cmdtp->usage);
  305. return 1;
  306. }
  307. return 0;
  308. }
  309. U_BOOT_CMD(
  310. l2cache, 2, 1, do_l2cache,
  311. "l2cache - enable or disable L2 cache\n",
  312. "[on, off]\n"
  313. " - enable or disable L2 cache\n"
  314. );