xpedite1k.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. * Copyright (C) 2003 Travis B. Sawyer <travis.sawyer@sandburst.com>
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <asm/processor.h>
  24. #include <spd_sdram.h>
  25. #include <i2c.h>
  26. DECLARE_GLOBAL_DATA_PTR;
  27. #define BOOT_SMALL_FLASH 32 /* 00100000 */
  28. #define FLASH_ONBD_N 2 /* 00000010 */
  29. #define FLASH_SRAM_SEL 1 /* 00000001 */
  30. long int fixed_sdram (void);
  31. int board_early_init_f(void)
  32. {
  33. unsigned long sdrreg;
  34. /* TBS: Setup the GPIO access for the user LEDs */
  35. mfsdr(sdr_pfc0, sdrreg);
  36. mtsdr(sdr_pfc0, (sdrreg & ~0x00000100) | 0x00000E00);
  37. out32(CONFIG_SYS_GPIO_BASE + 0x018, (USR_LED0 | USR_LED1 | USR_LED2 | USR_LED3));
  38. LED0_OFF();
  39. LED1_OFF();
  40. LED2_OFF();
  41. LED3_OFF();
  42. /*--------------------------------------------------------------------
  43. * Setup the external bus controller/chip selects
  44. *-------------------------------------------------------------------*/
  45. /* set the bus controller */
  46. mtebc (pb0ap, 0x04055200); /* FLASH/SRAM */
  47. mtebc (pb0cr, 0xfff18000); /* BAS=0xfff 1MB R/W 8-bit */
  48. mtebc (pb1ap, 0x04055200); /* FLASH/SRAM */
  49. mtebc (pb1cr, 0xfe098000); /* BAS=0xff8 16MB R/W 8-bit */
  50. /*--------------------------------------------------------------------
  51. * Setup the interrupt controller polarities, triggers, etc.
  52. *-------------------------------------------------------------------*/
  53. /*
  54. * Because of the interrupt handling rework to handle 440GX interrupts
  55. * with the common code, we needed to change names of the UIC registers.
  56. * Here the new relationship:
  57. *
  58. * U-Boot name 440GX name
  59. * -----------------------
  60. * UIC0 UICB0
  61. * UIC1 UIC0
  62. * UIC2 UIC1
  63. * UIC3 UIC2
  64. */
  65. mtdcr (uic1sr, 0xffffffff); /* clear all */
  66. mtdcr (uic1er, 0x00000000); /* disable all */
  67. mtdcr (uic1cr, 0x00000003); /* SMI & UIC1 crit are critical */
  68. mtdcr (uic1pr, 0xfffffe00); /* per ref-board manual */
  69. mtdcr (uic1tr, 0x01c00000); /* per ref-board manual */
  70. mtdcr (uic1vr, 0x00000001); /* int31 highest, base=0x000 */
  71. mtdcr (uic1sr, 0xffffffff); /* clear all */
  72. mtdcr (uic2sr, 0xffffffff); /* clear all */
  73. mtdcr (uic2er, 0x00000000); /* disable all */
  74. mtdcr (uic2cr, 0x00000000); /* all non-critical */
  75. mtdcr (uic2pr, 0xffffc0ff); /* per ref-board manual */
  76. mtdcr (uic2tr, 0x00ff8000); /* per ref-board manual */
  77. mtdcr (uic2vr, 0x00000001); /* int31 highest, base=0x000 */
  78. mtdcr (uic2sr, 0xffffffff); /* clear all */
  79. mtdcr (uic3sr, 0xffffffff); /* clear all */
  80. mtdcr (uic3er, 0x00000000); /* disable all */
  81. mtdcr (uic3cr, 0x00000000); /* all non-critical */
  82. mtdcr (uic3pr, 0xffffffff); /* per ref-board manual */
  83. mtdcr (uic3tr, 0x00ff8c0f); /* per ref-board manual */
  84. mtdcr (uic3vr, 0x00000001); /* int31 highest, base=0x000 */
  85. mtdcr (uic3sr, 0xffffffff); /* clear all */
  86. mtdcr (uic0sr, 0xfc000000); /* clear all */
  87. mtdcr (uic0er, 0x00000000); /* disable all */
  88. mtdcr (uic0cr, 0x00000000); /* all non-critical */
  89. mtdcr (uic0pr, 0xfc000000); /* */
  90. mtdcr (uic0tr, 0x00000000); /* */
  91. mtdcr (uic0vr, 0x00000001); /* */
  92. LED0_ON();
  93. return 0;
  94. }
  95. int checkboard (void)
  96. {
  97. printf ("Board: XES XPedite1000 440GX\n");
  98. return (0);
  99. }
  100. phys_size_t initdram (int board_type)
  101. {
  102. long dram_size = 0;
  103. #if defined(CONFIG_SPD_EEPROM)
  104. dram_size = spd_sdram ();
  105. #else
  106. dram_size = fixed_sdram ();
  107. #endif
  108. return dram_size;
  109. }
  110. #if defined(CONFIG_SYS_DRAM_TEST)
  111. int testdram (void)
  112. {
  113. uint *pstart = (uint *) 0x00000000;
  114. uint *pend = (uint *) 0x08000000;
  115. uint *p;
  116. for (p = pstart; p < pend; p++)
  117. *p = 0xaaaaaaaa;
  118. for (p = pstart; p < pend; p++) {
  119. if (*p != 0xaaaaaaaa) {
  120. printf ("SDRAM test fails at: %08x\n", (uint) p);
  121. return 1;
  122. }
  123. }
  124. for (p = pstart; p < pend; p++)
  125. *p = 0x55555555;
  126. for (p = pstart; p < pend; p++) {
  127. if (*p != 0x55555555) {
  128. printf ("SDRAM test fails at: %08x\n", (uint) p);
  129. return 1;
  130. }
  131. }
  132. return 0;
  133. }
  134. #endif
  135. #if !defined(CONFIG_SPD_EEPROM)
  136. /*************************************************************************
  137. * fixed sdram init -- doesn't use serial presence detect.
  138. *
  139. * Assumes: 128 MB, non-ECC, non-registered
  140. * PLB @ 133 MHz
  141. *
  142. ************************************************************************/
  143. long int fixed_sdram (void)
  144. {
  145. uint reg;
  146. /*--------------------------------------------------------------------
  147. * Setup some default
  148. *------------------------------------------------------------------*/
  149. mtsdram (mem_uabba, 0x00000000); /* ubba=0 (default) */
  150. mtsdram (mem_slio, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
  151. mtsdram (mem_devopt, 0x00000000); /* dll=0 ds=0 (normal) */
  152. mtsdram (mem_wddctr, 0x00000000); /* wrcp=0 dcd=0 */
  153. mtsdram (mem_clktr, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */
  154. /*--------------------------------------------------------------------
  155. * Setup for board-specific specific mem
  156. *------------------------------------------------------------------*/
  157. /*
  158. * Following for CAS Latency = 2.5 @ 133 MHz PLB
  159. */
  160. mtsdram (mem_b0cr, 0x000a4001); /* SDBA=0x000 128MB, Mode 3, enabled */
  161. mtsdram (mem_tr0, 0x410a4012); /* WR=2 WD=1 CL=2.5 PA=3 CP=4 LD=2 */
  162. /* RA=10 RD=3 */
  163. mtsdram (mem_tr1, 0x8080082f); /* SS=T2 SL=STAGE 3 CD=1 CT=0x02f */
  164. mtsdram (mem_rtr, 0x08200000); /* Rate 15.625 ns @ 133 MHz PLB */
  165. mtsdram (mem_cfg1, 0x00000000); /* Self-refresh exit, disable PM */
  166. udelay (400); /* Delay 200 usecs (min) */
  167. /*--------------------------------------------------------------------
  168. * Enable the controller, then wait for DCEN to complete
  169. *------------------------------------------------------------------*/
  170. mtsdram (mem_cfg0, 0x86000000); /* DCEN=1, PMUD=1, 64-bit */
  171. for (;;) {
  172. mfsdram (mem_mcsts, reg);
  173. if (reg & 0x80000000)
  174. break;
  175. }
  176. return (128 * 1024 * 1024); /* 128 MB */
  177. }
  178. #endif /* !defined(CONFIG_SPD_EEPROM) */
  179. /*************************************************************************
  180. * pci_pre_init
  181. *
  182. * This routine is called just prior to registering the hose and gives
  183. * the board the opportunity to check things. Returning a value of zero
  184. * indicates that things are bad & PCI initialization should be aborted.
  185. *
  186. * Different boards may wish to customize the pci controller structure
  187. * (add regions, override default access routines, etc) or perform
  188. * certain pre-initialization actions.
  189. *
  190. ************************************************************************/
  191. #if defined(CONFIG_PCI)
  192. int pci_pre_init(struct pci_controller * hose )
  193. {
  194. unsigned long strap;
  195. /* See if we're supposed to setup the pci */
  196. mfsdr(sdr_sdstp1, strap);
  197. if ((strap & 0x00010000) == 0) {
  198. return (0);
  199. }
  200. #if defined(CONFIG_SYS_PCI_FORCE_PCI_CONV)
  201. /* Setup System Device Register PCIX0_XCR */
  202. mfsdr(sdr_xcr, strap);
  203. strap &= 0x0f000000;
  204. mtsdr(sdr_xcr, strap);
  205. #endif
  206. return 1;
  207. }
  208. #endif /* defined(CONFIG_PCI) */
  209. /*************************************************************************
  210. * pci_target_init
  211. *
  212. * The bootstrap configuration provides default settings for the pci
  213. * inbound map (PIM). But the bootstrap config choices are limited and
  214. * may not be sufficient for a given board.
  215. *
  216. ************************************************************************/
  217. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
  218. void pci_target_init(struct pci_controller * hose )
  219. {
  220. /*--------------------------------------------------------------------------+
  221. * Disable everything
  222. *--------------------------------------------------------------------------*/
  223. out32r( PCIX0_PIM0SA, 0 ); /* disable */
  224. out32r( PCIX0_PIM1SA, 0 ); /* disable */
  225. out32r( PCIX0_PIM2SA, 0 ); /* disable */
  226. out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */
  227. /*--------------------------------------------------------------------------+
  228. * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
  229. * options to not support sizes such as 128/256 MB.
  230. *--------------------------------------------------------------------------*/
  231. out32r( PCIX0_PIM0LAL, CONFIG_SYS_SDRAM_BASE );
  232. out32r( PCIX0_PIM0LAH, 0 );
  233. out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 );
  234. out32r( PCIX0_BAR0, 0 );
  235. /*--------------------------------------------------------------------------+
  236. * Program the board's subsystem id/vendor id
  237. *--------------------------------------------------------------------------*/
  238. out16r( PCIX0_SBSYSVID, CONFIG_SYS_PCI_SUBSYS_VENDORID );
  239. out16r( PCIX0_SBSYSID, CONFIG_SYS_PCI_SUBSYS_DEVICEID );
  240. out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY );
  241. }
  242. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */
  243. /*************************************************************************
  244. * is_pci_host
  245. *
  246. * This routine is called to determine if a pci scan should be
  247. * performed. With various hardware environments (especially cPCI and
  248. * PPMC) it's insufficient to depend on the state of the arbiter enable
  249. * bit in the strap register, or generic host/adapter assumptions.
  250. *
  251. * Rather than hard-code a bad assumption in the general 440 code, the
  252. * 440 pci code requires the board to decide at runtime.
  253. *
  254. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  255. *
  256. *
  257. ************************************************************************/
  258. #if defined(CONFIG_PCI)
  259. int is_pci_host(struct pci_controller *hose)
  260. {
  261. return ((in32(CONFIG_SYS_GPIO_BASE + 0x1C) & 0x00000800) == 0);
  262. }
  263. #endif /* defined(CONFIG_PCI) */
  264. #ifdef CONFIG_POST
  265. /*
  266. * Returns 1 if keys pressed to start the power-on long-running tests
  267. * Called from board_init_f().
  268. */
  269. int post_hotkeys_pressed(void)
  270. {
  271. return (ctrlc());
  272. }
  273. void post_word_store (ulong a)
  274. {
  275. volatile ulong *save_addr =
  276. (volatile ulong *)(CONFIG_SYS_POST_WORD_ADDR);
  277. *save_addr = a;
  278. }
  279. ulong post_word_load (void)
  280. {
  281. volatile ulong *save_addr =
  282. (volatile ulong *)(CONFIG_SYS_POST_WORD_ADDR);
  283. return *save_addr;
  284. }
  285. #endif
  286. /*-----------------------------------------------------------------------------
  287. * board_get_enetaddr -- Read the MAC Addresses in the I2C EEPROM
  288. *-----------------------------------------------------------------------------
  289. */
  290. static int read_i2c;
  291. static void board_get_enetaddr(uchar *enet)
  292. {
  293. int i;
  294. unsigned char buff[0x100], *cp;
  295. if (read_i2c)
  296. return;
  297. /* Initialize I2C */
  298. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  299. /* Read 256 bytes in EEPROM */
  300. i2c_read (0x50, 0, 1, buff, 0x100);
  301. cp = &buff[0xF4];
  302. for (i = 0; i < 6; i++,cp++)
  303. enet[i] = *cp;
  304. printf("MAC address = %pM\n", enet);
  305. read_i2c = 1;
  306. }
  307. int misc_init_r(void)
  308. {
  309. uchar enetaddr[6], i2c_enetaddr[6];
  310. if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
  311. board_get_enetaddr(i2c_enetaddr);
  312. eth_putenv_enetaddr("ethaddr", i2c_enetaddr);
  313. }
  314. #ifdef CONFIG_HAS_ETH1
  315. if (!eth_getenv_enetaddr("eth1addr", enetaddr)) {
  316. board_get_enetaddr(i2c_enetaddr);
  317. eth_putenv_enetaddr("eth1addr", i2c_enetaddr);
  318. }
  319. #endif
  320. #ifdef CONFIG_HAS_ETH2
  321. if (!eth_getenv_enetaddr("eth2addr", enetaddr)) {
  322. board_get_enetaddr(i2c_enetaddr);
  323. eth_putenv_enetaddr("eth2addr", i2c_enetaddr);
  324. }
  325. #endif
  326. #ifdef CONFIG_HAS_ETH3
  327. if (!eth_getenv_enetaddr("eth3addr", enetaddr)) {
  328. board_get_enetaddr(i2c_enetaddr);
  329. eth_putenv_enetaddr("eth3addr", i2c_enetaddr);
  330. }
  331. #endif
  332. return 0;
  333. }