alpr.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * (C) Copyright 2006
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  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 <asm/processor.h>
  25. #include <spd_sdram.h>
  26. #include <ppc4xx_enet.h>
  27. #include <miiphy.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. extern int alpr_fpga_init(void);
  30. int board_early_init_f (void)
  31. {
  32. /*-------------------------------------------------------------------------
  33. * Initialize EBC CONFIG
  34. *-------------------------------------------------------------------------*/
  35. mtebc(xbcfg, EBC_CFG_LE_UNLOCK |
  36. EBC_CFG_PTD_DISABLE | EBC_CFG_RTC_64PERCLK |
  37. EBC_CFG_ATC_PREVIOUS | EBC_CFG_DTC_PREVIOUS |
  38. EBC_CFG_CTC_PREVIOUS | EBC_CFG_EMC_NONDEFAULT |
  39. EBC_CFG_PME_DISABLE | EBC_CFG_PR_32);
  40. /*--------------------------------------------------------------------
  41. * Setup the interrupt controller polarities, triggers, etc.
  42. *-------------------------------------------------------------------*/
  43. mtdcr (uic0sr, 0xffffffff); /* clear all */
  44. mtdcr (uic0er, 0x00000000); /* disable all */
  45. mtdcr (uic0cr, 0x00000009); /* SMI & UIC1 crit are critical */
  46. mtdcr (uic0pr, 0xfffffe03); /* per manual */
  47. mtdcr (uic0tr, 0x01c00000); /* per manual */
  48. mtdcr (uic0vr, 0x00000001); /* int31 highest, base=0x000 */
  49. mtdcr (uic0sr, 0xffffffff); /* clear all */
  50. mtdcr (uic1sr, 0xffffffff); /* clear all */
  51. mtdcr (uic1er, 0x00000000); /* disable all */
  52. mtdcr (uic1cr, 0x00000000); /* all non-critical */
  53. mtdcr (uic1pr, 0xffffe0ff); /* per ref-board manual */
  54. mtdcr (uic1tr, 0x00ffc000); /* per ref-board manual */
  55. mtdcr (uic1vr, 0x00000001); /* int31 highest, base=0x000 */
  56. mtdcr (uic1sr, 0xffffffff); /* clear all */
  57. mtdcr (uic2sr, 0xffffffff); /* clear all */
  58. mtdcr (uic2er, 0x00000000); /* disable all */
  59. mtdcr (uic2cr, 0x00000000); /* all non-critical */
  60. mtdcr (uic2pr, 0xffffffff); /* per ref-board manual */
  61. mtdcr (uic2tr, 0x00ff8c0f); /* per ref-board manual */
  62. mtdcr (uic2vr, 0x00000001); /* int31 highest, base=0x000 */
  63. mtdcr (uic2sr, 0xffffffff); /* clear all */
  64. mtdcr (uicb0sr, 0xfc000000); /* clear all */
  65. mtdcr (uicb0er, 0x00000000); /* disable all */
  66. mtdcr (uicb0cr, 0x00000000); /* all non-critical */
  67. mtdcr (uicb0pr, 0xfc000000); /* */
  68. mtdcr (uicb0tr, 0x00000000); /* */
  69. mtdcr (uicb0vr, 0x00000001); /* */
  70. /* Setup GPIO/IRQ multiplexing */
  71. mtsdr(sdr_pfc0, 0x01a03e00);
  72. return 0;
  73. }
  74. int last_stage_init(void)
  75. {
  76. unsigned short reg;
  77. /*
  78. * Configure LED's of both Marvell 88E1111 PHY's
  79. *
  80. * This has to be done after the 4xx ethernet driver is loaded,
  81. * so "last_stage_init()" is the right place.
  82. */
  83. miiphy_read("ppc_4xx_eth2", CONFIG_PHY2_ADDR, 0x18, &reg);
  84. reg |= 0x0001;
  85. miiphy_write("ppc_4xx_eth2", CONFIG_PHY2_ADDR, 0x18, reg);
  86. miiphy_read("ppc_4xx_eth3", CONFIG_PHY3_ADDR, 0x18, &reg);
  87. reg |= 0x0001;
  88. miiphy_write("ppc_4xx_eth3", CONFIG_PHY3_ADDR, 0x18, reg);
  89. return 0;
  90. }
  91. static int board_rev(void)
  92. {
  93. int rev;
  94. u32 pfc0;
  95. /* Setup GPIO14 & 15 as GPIO */
  96. mfsdr(sdr_pfc0, pfc0);
  97. pfc0 |= CFG_GPIO_REV0 | CFG_GPIO_REV1;
  98. mtsdr(sdr_pfc0, pfc0);
  99. /* Setup as input */
  100. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~(CFG_GPIO_REV0 | CFG_GPIO_REV0));
  101. out32(GPIO0_ODR, in32(GPIO0_ODR) & ~(CFG_GPIO_REV0 | CFG_GPIO_REV0));
  102. rev = (in32(GPIO0_IR) >> 16) & 0x3;
  103. /* Setup GPIO14 & 15 as non GPIO again */
  104. mfsdr(sdr_pfc0, pfc0);
  105. pfc0 &= ~(CFG_GPIO_REV0 | CFG_GPIO_REV1);
  106. mtsdr(sdr_pfc0, pfc0);
  107. return rev;
  108. }
  109. int checkboard (void)
  110. {
  111. char *s = getenv ("serial#");
  112. printf ("Board: ALPR");
  113. if (s != NULL) {
  114. puts (", serial# ");
  115. puts (s);
  116. }
  117. printf(" (Rev. %d)\n", board_rev());
  118. return (0);
  119. }
  120. #if defined(CFG_DRAM_TEST)
  121. int testdram (void)
  122. {
  123. uint *pstart = (uint *) 0x00000000;
  124. uint *pend = (uint *) 0x08000000;
  125. uint *p;
  126. for (p = pstart; p < pend; p++)
  127. *p = 0xaaaaaaaa;
  128. for (p = pstart; p < pend; p++) {
  129. if (*p != 0xaaaaaaaa) {
  130. printf ("SDRAM test fails at: %08x\n", (uint) p);
  131. return 1;
  132. }
  133. }
  134. for (p = pstart; p < pend; p++)
  135. *p = 0x55555555;
  136. for (p = pstart; p < pend; p++) {
  137. if (*p != 0x55555555) {
  138. printf ("SDRAM test fails at: %08x\n", (uint) p);
  139. return 1;
  140. }
  141. }
  142. return 0;
  143. }
  144. #endif
  145. /*************************************************************************
  146. * pci_pre_init
  147. *
  148. * This routine is called just prior to registering the hose and gives
  149. * the board the opportunity to check things. Returning a value of zero
  150. * indicates that things are bad & PCI initialization should be aborted.
  151. *
  152. * Different boards may wish to customize the pci controller structure
  153. * (add regions, override default access routines, etc) or perform
  154. * certain pre-initialization actions.
  155. *
  156. ************************************************************************/
  157. #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
  158. int pci_pre_init(struct pci_controller * hose )
  159. {
  160. unsigned long strap;
  161. /*--------------------------------------------------------------------------+
  162. * The ocotea board is always configured as the host & requires the
  163. * PCI arbiter to be enabled.
  164. *--------------------------------------------------------------------------*/
  165. mfsdr(sdr_sdstp1, strap);
  166. if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ){
  167. printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap);
  168. return 0;
  169. }
  170. /* FPGA Init */
  171. alpr_fpga_init ();
  172. return 1;
  173. }
  174. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
  175. /*************************************************************************
  176. * pci_target_init
  177. *
  178. * The bootstrap configuration provides default settings for the pci
  179. * inbound map (PIM). But the bootstrap config choices are limited and
  180. * may not be sufficient for a given board.
  181. *
  182. ************************************************************************/
  183. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  184. void pci_target_init(struct pci_controller * hose )
  185. {
  186. /*--------------------------------------------------------------------------+
  187. * Disable everything
  188. *--------------------------------------------------------------------------*/
  189. out32r( PCIX0_PIM0SA, 0 ); /* disable */
  190. out32r( PCIX0_PIM1SA, 0 ); /* disable */
  191. out32r( PCIX0_PIM2SA, 0 ); /* disable */
  192. out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */
  193. /*--------------------------------------------------------------------------+
  194. * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
  195. * options to not support sizes such as 128/256 MB.
  196. *--------------------------------------------------------------------------*/
  197. out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE );
  198. out32r( PCIX0_PIM0LAH, 0 );
  199. out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 );
  200. out32r( PCIX0_BAR0, 0 );
  201. /*--------------------------------------------------------------------------+
  202. * Program the board's subsystem id/vendor id
  203. *--------------------------------------------------------------------------*/
  204. out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID );
  205. out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID );
  206. out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  207. }
  208. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  209. /*************************************************************************
  210. * is_pci_host
  211. *
  212. * This routine is called to determine if a pci scan should be
  213. * performed. With various hardware environments (especially cPCI and
  214. * PPMC) it's insufficient to depend on the state of the arbiter enable
  215. * bit in the strap register, or generic host/adapter assumptions.
  216. *
  217. * Rather than hard-code a bad assumption in the general 440 code, the
  218. * 440 pci code requires the board to decide at runtime.
  219. *
  220. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  221. *
  222. *
  223. ************************************************************************/
  224. #if defined(CONFIG_PCI)
  225. static void wait_for_pci_ready(void)
  226. {
  227. /*
  228. * Configure EREADY as input
  229. */
  230. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~CFG_GPIO_EREADY);
  231. udelay(1000);
  232. for (;;) {
  233. if (in32(GPIO0_IR) & CFG_GPIO_EREADY)
  234. return;
  235. }
  236. }
  237. int is_pci_host(struct pci_controller *hose)
  238. {
  239. wait_for_pci_ready();
  240. return 1; /* return 1 for host controller */
  241. }
  242. #endif /* defined(CONFIG_PCI) */
  243. /*************************************************************************
  244. * pci_master_init
  245. *
  246. ************************************************************************/
  247. #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
  248. void pci_master_init(struct pci_controller *hose)
  249. {
  250. /*--------------------------------------------------------------------------+
  251. | PowerPC440 PCI Master configuration.
  252. | Map PLB/processor addresses to PCI memory space.
  253. | PLB address 0xA0000000-0xCFFFFFFF ==> PCI address 0x80000000-0xCFFFFFFF
  254. | Use byte reversed out routines to handle endianess.
  255. | Make this region non-prefetchable.
  256. +--------------------------------------------------------------------------*/
  257. out32r( PCIX0_POM0SA, 0 ); /* disable */
  258. out32r( PCIX0_POM1SA, 0 ); /* disable */
  259. out32r( PCIX0_POM2SA, 0 ); /* disable */
  260. out32r(PCIX0_POM0LAL, CFG_PCI_MEMBASE); /* PMM0 Local Address */
  261. out32r(PCIX0_POM0LAH, 0x00000003); /* PMM0 Local Address */
  262. out32r(PCIX0_POM0PCIAL, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
  263. out32r(PCIX0_POM0PCIAH, 0x00000000); /* PMM0 PCI High Address */
  264. out32r(PCIX0_POM0SA, ~(0x10000000 - 1) | 1); /* 256MB + enable region */
  265. out32r(PCIX0_POM1LAL, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
  266. out32r(PCIX0_POM1LAH, 0x00000003); /* PMM0 Local Address */
  267. out32r(PCIX0_POM1PCIAL, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  268. out32r(PCIX0_POM1PCIAH, 0x00000000); /* PMM0 PCI High Address */
  269. out32r(PCIX0_POM1SA, ~(0x10000000 - 1) | 1); /* 256MB + enable region */
  270. }
  271. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT) */
  272. #ifdef CONFIG_POST
  273. /*
  274. * Returns 1 if keys pressed to start the power-on long-running tests
  275. * Called from board_init_f().
  276. */
  277. int post_hotkeys_pressed(void)
  278. {
  279. return (ctrlc());
  280. }
  281. #endif