ocotea.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. * Copyright (C) 2004 PaulReynolds@lhsolutions.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 "ocotea.h"
  24. #include <asm/processor.h>
  25. #include <spd_sdram.h>
  26. #include <440gx_enet.h>
  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. void fpga_init (void);
  32. int board_early_init_f (void)
  33. {
  34. /*-------------------------------------------------------------------------+
  35. | Initialize EBC CONFIG
  36. +-------------------------------------------------------------------------*/
  37. mtebc(xbcfg, EBC_CFG_LE_UNLOCK |
  38. EBC_CFG_PTD_ENABLE | EBC_CFG_RTC_64PERCLK |
  39. EBC_CFG_ATC_PREVIOUS | EBC_CFG_DTC_PREVIOUS |
  40. EBC_CFG_CTC_PREVIOUS | EBC_CFG_EMC_NONDEFAULT |
  41. EBC_CFG_PME_DISABLE | EBC_CFG_PR_32);
  42. /*-------------------------------------------------------------------------+
  43. | 1 MB FLASH / 1 MB SRAM. Initialize bank 0 with default values.
  44. +-------------------------------------------------------------------------*/
  45. mtebc(pb0ap, EBC_BXAP_BME_DISABLED|EBC_BXAP_TWT_ENCODE(8)|
  46. EBC_BXAP_BCE_DISABLE|
  47. EBC_BXAP_CSN_ENCODE(1)|EBC_BXAP_OEN_ENCODE(1)|
  48. EBC_BXAP_WBN_ENCODE(1)|EBC_BXAP_WBF_ENCODE(1)|
  49. EBC_BXAP_TH_ENCODE(1)|EBC_BXAP_RE_DISABLED|
  50. EBC_BXAP_BEM_WRITEONLY|
  51. EBC_BXAP_PEN_DISABLED);
  52. mtebc(pb0cr, EBC_BXCR_BAS_ENCODE(0xFFE00000)|
  53. EBC_BXCR_BS_2MB|EBC_BXCR_BU_RW|EBC_BXCR_BW_8BIT);
  54. /*-------------------------------------------------------------------------+
  55. | 8KB NVRAM/RTC. Initialize bank 1 with default values.
  56. +-------------------------------------------------------------------------*/
  57. mtebc(pb1ap, EBC_BXAP_BME_DISABLED|EBC_BXAP_TWT_ENCODE(10)|
  58. EBC_BXAP_BCE_DISABLE|
  59. EBC_BXAP_CSN_ENCODE(1)|EBC_BXAP_OEN_ENCODE(1)|
  60. EBC_BXAP_WBN_ENCODE(1)|EBC_BXAP_WBF_ENCODE(1)|
  61. EBC_BXAP_TH_ENCODE(1)|EBC_BXAP_RE_DISABLED|
  62. EBC_BXAP_BEM_WRITEONLY|
  63. EBC_BXAP_PEN_DISABLED);
  64. mtebc(pb1cr, EBC_BXCR_BAS_ENCODE(0x48000000)|
  65. EBC_BXCR_BS_1MB|EBC_BXCR_BU_RW|EBC_BXCR_BW_8BIT);
  66. /*-------------------------------------------------------------------------+
  67. | 4 MB FLASH. Initialize bank 2 with default values.
  68. +-------------------------------------------------------------------------*/
  69. mtebc(pb2ap, EBC_BXAP_BME_DISABLED|EBC_BXAP_TWT_ENCODE(10)|
  70. EBC_BXAP_BCE_DISABLE|
  71. EBC_BXAP_CSN_ENCODE(1)|EBC_BXAP_OEN_ENCODE(1)|
  72. EBC_BXAP_WBN_ENCODE(1)|EBC_BXAP_WBF_ENCODE(1)|
  73. EBC_BXAP_TH_ENCODE(1)|EBC_BXAP_RE_DISABLED|
  74. EBC_BXAP_BEM_WRITEONLY|
  75. EBC_BXAP_PEN_DISABLED);
  76. mtebc(pb2cr, EBC_BXCR_BAS_ENCODE(0xFF800000)|
  77. EBC_BXCR_BS_4MB|EBC_BXCR_BU_RW|EBC_BXCR_BW_8BIT);
  78. /*-------------------------------------------------------------------------+
  79. | FPGA. Initialize bank 7 with default values.
  80. +-------------------------------------------------------------------------*/
  81. mtebc(pb7ap, EBC_BXAP_BME_DISABLED|EBC_BXAP_TWT_ENCODE(7)|
  82. EBC_BXAP_BCE_DISABLE|
  83. EBC_BXAP_CSN_ENCODE(1)|EBC_BXAP_OEN_ENCODE(1)|
  84. EBC_BXAP_WBN_ENCODE(1)|EBC_BXAP_WBF_ENCODE(1)|
  85. EBC_BXAP_TH_ENCODE(1)|EBC_BXAP_RE_DISABLED|
  86. EBC_BXAP_BEM_WRITEONLY|
  87. EBC_BXAP_PEN_DISABLED);
  88. mtebc(pb7cr, EBC_BXCR_BAS_ENCODE(0x48300000)|
  89. EBC_BXCR_BS_1MB|EBC_BXCR_BU_RW|EBC_BXCR_BW_8BIT);
  90. /*--------------------------------------------------------------------
  91. * Setup the interrupt controller polarities, triggers, etc.
  92. *-------------------------------------------------------------------*/
  93. mtdcr (uic0sr, 0xffffffff); /* clear all */
  94. mtdcr (uic0er, 0x00000000); /* disable all */
  95. mtdcr (uic0cr, 0x00000009); /* SMI & UIC1 crit are critical */
  96. mtdcr (uic0pr, 0xfffffe13); /* per ref-board manual */
  97. mtdcr (uic0tr, 0x01c00008); /* per ref-board manual */
  98. mtdcr (uic0vr, 0x00000001); /* int31 highest, base=0x000 */
  99. mtdcr (uic0sr, 0xffffffff); /* clear all */
  100. mtdcr (uic1sr, 0xffffffff); /* clear all */
  101. mtdcr (uic1er, 0x00000000); /* disable all */
  102. mtdcr (uic1cr, 0x00000000); /* all non-critical */
  103. mtdcr (uic1pr, 0xffffe0ff); /* per ref-board manual */
  104. mtdcr (uic1tr, 0x00ffc000); /* per ref-board manual */
  105. mtdcr (uic1vr, 0x00000001); /* int31 highest, base=0x000 */
  106. mtdcr (uic1sr, 0xffffffff); /* clear all */
  107. fpga_init();
  108. return 0;
  109. }
  110. int checkboard (void)
  111. {
  112. sys_info_t sysinfo;
  113. get_sys_info (&sysinfo);
  114. printf ("Board: IBM 440GX Evaluation Board\n");
  115. printf ("\tVCO: %lu MHz\n", sysinfo.freqVCOMhz / 1000000);
  116. printf ("\tCPU: %lu MHz\n", sysinfo.freqProcessor / 1000000);
  117. printf ("\tPLB: %lu MHz\n", sysinfo.freqPLB / 1000000);
  118. printf ("\tOPB: %lu MHz\n", sysinfo.freqOPB / 1000000);
  119. printf ("\tEPB: %lu MHz\n", sysinfo.freqEPB / 1000000);
  120. return (0);
  121. }
  122. long int initdram (int board_type)
  123. {
  124. long dram_size = 0;
  125. #if defined(CONFIG_SPD_EEPROM)
  126. dram_size = spd_sdram (0);
  127. #else
  128. dram_size = fixed_sdram ();
  129. #endif
  130. return dram_size;
  131. }
  132. #if defined(CFG_DRAM_TEST)
  133. int testdram (void)
  134. {
  135. uint *pstart = (uint *) 0x00000000;
  136. uint *pend = (uint *) 0x08000000;
  137. uint *p;
  138. for (p = pstart; p < pend; p++)
  139. *p = 0xaaaaaaaa;
  140. for (p = pstart; p < pend; p++) {
  141. if (*p != 0xaaaaaaaa) {
  142. printf ("SDRAM test fails at: %08x\n", (uint) p);
  143. return 1;
  144. }
  145. }
  146. for (p = pstart; p < pend; p++)
  147. *p = 0x55555555;
  148. for (p = pstart; p < pend; p++) {
  149. if (*p != 0x55555555) {
  150. printf ("SDRAM test fails at: %08x\n", (uint) p);
  151. return 1;
  152. }
  153. }
  154. return 0;
  155. }
  156. #endif
  157. #if !defined(CONFIG_SPD_EEPROM)
  158. /*************************************************************************
  159. * fixed sdram init -- doesn't use serial presence detect.
  160. *
  161. * Assumes: 128 MB, non-ECC, non-registered
  162. * PLB @ 133 MHz
  163. *
  164. ************************************************************************/
  165. long int fixed_sdram (void)
  166. {
  167. uint reg;
  168. /*--------------------------------------------------------------------
  169. * Setup some default
  170. *------------------------------------------------------------------*/
  171. mtsdram (mem_uabba, 0x00000000); /* ubba=0 (default) */
  172. mtsdram (mem_slio, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
  173. mtsdram (mem_devopt, 0x00000000); /* dll=0 ds=0 (normal) */
  174. mtsdram (mem_wddctr, 0x00000000); /* wrcp=0 dcd=0 */
  175. mtsdram (mem_clktr, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */
  176. /*--------------------------------------------------------------------
  177. * Setup for board-specific specific mem
  178. *------------------------------------------------------------------*/
  179. /*
  180. * Following for CAS Latency = 2.5 @ 133 MHz PLB
  181. */
  182. mtsdram (mem_b0cr, 0x000a4001); /* SDBA=0x000 128MB, Mode 3, enabled */
  183. mtsdram (mem_tr0, 0x410a4012); /* WR=2 WD=1 CL=2.5 PA=3 CP=4 LD=2 */
  184. /* RA=10 RD=3 */
  185. mtsdram (mem_tr1, 0x8080082f); /* SS=T2 SL=STAGE 3 CD=1 CT=0x02f */
  186. mtsdram (mem_rtr, 0x08200000); /* Rate 15.625 ns @ 133 MHz PLB */
  187. mtsdram (mem_cfg1, 0x00000000); /* Self-refresh exit, disable PM */
  188. udelay (400); /* Delay 200 usecs (min) */
  189. /*--------------------------------------------------------------------
  190. * Enable the controller, then wait for DCEN to complete
  191. *------------------------------------------------------------------*/
  192. mtsdram (mem_cfg0, 0x86000000); /* DCEN=1, PMUD=1, 64-bit */
  193. for (;;) {
  194. mfsdram (mem_mcsts, reg);
  195. if (reg & 0x80000000)
  196. break;
  197. }
  198. return (128 * 1024 * 1024); /* 128 MB */
  199. }
  200. #endif /* !defined(CONFIG_SPD_EEPROM) */
  201. /*************************************************************************
  202. * pci_pre_init
  203. *
  204. * This routine is called just prior to registering the hose and gives
  205. * the board the opportunity to check things. Returning a value of zero
  206. * indicates that things are bad & PCI initialization should be aborted.
  207. *
  208. * Different boards may wish to customize the pci controller structure
  209. * (add regions, override default access routines, etc) or perform
  210. * certain pre-initialization actions.
  211. *
  212. ************************************************************************/
  213. #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
  214. int pci_pre_init(struct pci_controller * hose )
  215. {
  216. unsigned long strap;
  217. /*--------------------------------------------------------------------------+
  218. * The ocotea board is always configured as the host & requires the
  219. * PCI arbiter to be enabled.
  220. *--------------------------------------------------------------------------*/
  221. mfsdr(sdr_sdstp1, strap);
  222. if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ){
  223. printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap);
  224. return 0;
  225. }
  226. return 1;
  227. }
  228. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
  229. /*************************************************************************
  230. * pci_target_init
  231. *
  232. * The bootstrap configuration provides default settings for the pci
  233. * inbound map (PIM). But the bootstrap config choices are limited and
  234. * may not be sufficient for a given board.
  235. *
  236. ************************************************************************/
  237. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  238. void pci_target_init(struct pci_controller * hose )
  239. {
  240. DECLARE_GLOBAL_DATA_PTR;
  241. /*--------------------------------------------------------------------------+
  242. * Disable everything
  243. *--------------------------------------------------------------------------*/
  244. out32r( PCIX0_PIM0SA, 0 ); /* disable */
  245. out32r( PCIX0_PIM1SA, 0 ); /* disable */
  246. out32r( PCIX0_PIM2SA, 0 ); /* disable */
  247. out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */
  248. /*--------------------------------------------------------------------------+
  249. * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
  250. * options to not support sizes such as 128/256 MB.
  251. *--------------------------------------------------------------------------*/
  252. out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE );
  253. out32r( PCIX0_PIM0LAH, 0 );
  254. out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 );
  255. out32r( PCIX0_BAR0, 0 );
  256. /*--------------------------------------------------------------------------+
  257. * Program the board's subsystem id/vendor id
  258. *--------------------------------------------------------------------------*/
  259. out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID );
  260. out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID );
  261. out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY );
  262. }
  263. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  264. /*************************************************************************
  265. * is_pci_host
  266. *
  267. * This routine is called to determine if a pci scan should be
  268. * performed. With various hardware environments (especially cPCI and
  269. * PPMC) it's insufficient to depend on the state of the arbiter enable
  270. * bit in the strap register, or generic host/adapter assumptions.
  271. *
  272. * Rather than hard-code a bad assumption in the general 440 code, the
  273. * 440 pci code requires the board to decide at runtime.
  274. *
  275. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  276. *
  277. *
  278. ************************************************************************/
  279. #if defined(CONFIG_PCI)
  280. int is_pci_host(struct pci_controller *hose)
  281. {
  282. /* The ocotea board is always configured as host. */
  283. return(1);
  284. }
  285. #endif /* defined(CONFIG_PCI) */
  286. void fpga_init(void)
  287. {
  288. unsigned long group;
  289. unsigned long sdr0_pfc0;
  290. unsigned long sdr0_pfc1;
  291. unsigned long sdr0_cust0;
  292. unsigned long pvr;
  293. mfsdr (sdr_pfc0, sdr0_pfc0);
  294. mfsdr (sdr_pfc1, sdr0_pfc1);
  295. group = SDR0_PFC1_EPS_DECODE(sdr0_pfc1);
  296. pvr = get_pvr ();
  297. sdr0_pfc0 = (sdr0_pfc0 & ~SDR0_PFC0_GEIE_MASK) | SDR0_PFC0_GEIE_TRE;
  298. if ( ((pvr == PVR_440GX_RA) || (pvr == PVR_440GX_RB)) && ((group == 4) || (group == 5))) {
  299. sdr0_pfc0 = (sdr0_pfc0 & ~SDR0_PFC0_TRE_MASK) | SDR0_PFC0_TRE_DISABLE;
  300. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_CTEMS_MASK) | SDR0_PFC1_CTEMS_EMS;
  301. out8(FPGA_REG2, (in8(FPGA_REG2) & ~FPGA_REG2_EXT_INTFACE_MASK) |
  302. FPGA_REG2_EXT_INTFACE_ENABLE);
  303. mtsdr (sdr_pfc0, sdr0_pfc0);
  304. mtsdr (sdr_pfc1, sdr0_pfc1);
  305. } else {
  306. sdr0_pfc0 = (sdr0_pfc0 & ~SDR0_PFC0_TRE_MASK) | SDR0_PFC0_TRE_ENABLE;
  307. switch (group)
  308. {
  309. case 0:
  310. case 1:
  311. case 2:
  312. /* CPU trace A */
  313. out8(FPGA_REG2, (in8(FPGA_REG2) & ~FPGA_REG2_EXT_INTFACE_MASK) |
  314. FPGA_REG2_EXT_INTFACE_ENABLE);
  315. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_CTEMS_MASK) | SDR0_PFC1_CTEMS_EMS;
  316. mtsdr (sdr_pfc0, sdr0_pfc0);
  317. mtsdr (sdr_pfc1, sdr0_pfc1);
  318. break;
  319. case 3:
  320. case 4:
  321. case 5:
  322. case 6:
  323. /* CPU trace B - Over EBMI */
  324. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_CTEMS_MASK) | SDR0_PFC1_CTEMS_CPUTRACE;
  325. mtsdr (sdr_pfc0, sdr0_pfc0);
  326. mtsdr (sdr_pfc1, sdr0_pfc1);
  327. out8(FPGA_REG2, (in8(FPGA_REG2) & ~FPGA_REG2_EXT_INTFACE_MASK) |
  328. FPGA_REG2_EXT_INTFACE_DISABLE);
  329. break;
  330. }
  331. }
  332. /* Initialize the ethernet specific functions in the fpga */
  333. mfsdr(sdr_pfc1, sdr0_pfc1);
  334. mfsdr(sdr_cust0, sdr0_cust0);
  335. if ( (SDR0_PFC1_EPS_DECODE(sdr0_pfc1) == 4) &&
  336. ((SDR0_CUST0_RGMII2_DECODE(sdr0_cust0) == RGMII_FER_GMII) ||
  337. (SDR0_CUST0_RGMII2_DECODE(sdr0_cust0) == RGMII_FER_TBI)))
  338. {
  339. if ((in8(FPGA_REG0) & FPGA_REG0_ECLS_MASK) == FPGA_REG0_ECLS_VER1)
  340. {
  341. out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_ENET_MASK1) |
  342. FPGA_REG3_ENET_GROUP7);
  343. }
  344. else
  345. {
  346. if (SDR0_CUST0_RGMII2_DECODE(sdr0_cust0) == RGMII_FER_GMII)
  347. {
  348. out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_ENET_MASK2) |
  349. FPGA_REG3_ENET_GROUP7);
  350. }
  351. else
  352. {
  353. out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_ENET_MASK2) |
  354. FPGA_REG3_ENET_GROUP8);
  355. }
  356. }
  357. }
  358. else
  359. {
  360. if ((in8(FPGA_REG0) & FPGA_REG0_ECLS_MASK) == FPGA_REG0_ECLS_VER1)
  361. {
  362. out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_ENET_MASK1) |
  363. FPGA_REG3_ENET_ENCODE1(SDR0_PFC1_EPS_DECODE(sdr0_pfc1)));
  364. }
  365. else
  366. {
  367. out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_ENET_MASK2) |
  368. FPGA_REG3_ENET_ENCODE2(SDR0_PFC1_EPS_DECODE(sdr0_pfc1)));
  369. }
  370. }
  371. out8(FPGA_REG4, FPGA_REG4_GPHY_MODE10 |
  372. FPGA_REG4_GPHY_MODE100 | FPGA_REG4_GPHY_MODE1000 |
  373. FPGA_REG4_GPHY_FRC_DPLX | FPGA_REG4_CONNECT_PHYS);
  374. /* reset the gigabyte phy if necessary */
  375. if (SDR0_PFC1_EPS_DECODE(sdr0_pfc1) >= 3)
  376. {
  377. if ((in8(FPGA_REG0) & FPGA_REG0_ECLS_MASK) == FPGA_REG0_ECLS_VER1)
  378. {
  379. out8(FPGA_REG3, in8(FPGA_REG3) & ~FPGA_REG3_GIGABIT_RESET_DISABLE);
  380. udelay(10000);
  381. out8(FPGA_REG3, in8(FPGA_REG3) | FPGA_REG3_GIGABIT_RESET_DISABLE);
  382. }
  383. else
  384. {
  385. out8(FPGA_REG2, in8(FPGA_REG2) & ~FPGA_REG2_GIGABIT_RESET_DISABLE);
  386. udelay(10000);
  387. out8(FPGA_REG2, in8(FPGA_REG2) | FPGA_REG2_GIGABIT_RESET_DISABLE);
  388. }
  389. }
  390. /* Turn off the LED's */
  391. out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_STAT_MASK) |
  392. FPGA_REG3_STAT_LED8_DISAB | FPGA_REG3_STAT_LED4_DISAB |
  393. FPGA_REG3_STAT_LED2_DISAB | FPGA_REG3_STAT_LED1_DISAB);
  394. return;
  395. }
  396. #ifdef CONFIG_POST
  397. /*
  398. * Returns 1 if keys pressed to start the power-on long-running tests
  399. * Called from board_init_f().
  400. */
  401. int post_hotkeys_pressed(void)
  402. {
  403. return (ctrlc());
  404. }
  405. #endif