alpr.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. DECLARE_GLOBAL_DATA_PTR;
  28. extern int alpr_fpga_init(void);
  29. int board_early_init_f (void)
  30. {
  31. unsigned long mfr;
  32. /*-------------------------------------------------------------------------+
  33. | Initialize EBC CONFIG
  34. +-------------------------------------------------------------------------*/
  35. mtebc(xbcfg, EBC_CFG_LE_UNLOCK |
  36. EBC_CFG_PTD_ENABLE | 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, 0xfffffe13); /* per ref-board manual */
  47. mtdcr (uic0tr, 0x01c00008); /* per ref-board 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. mfsdr (sdr_mfr, mfr);
  71. mfr &= ~SDR0_MFR_ECS_MASK;
  72. return 0;
  73. }
  74. int checkboard (void)
  75. {
  76. char *s = getenv ("serial#");
  77. printf ("Board: ALPR");
  78. if (s != NULL) {
  79. puts (", serial# ");
  80. puts (s);
  81. }
  82. putc ('\n');
  83. return (0);
  84. }
  85. #if defined(CFG_DRAM_TEST)
  86. int testdram (void)
  87. {
  88. uint *pstart = (uint *) 0x00000000;
  89. uint *pend = (uint *) 0x08000000;
  90. uint *p;
  91. for (p = pstart; p < pend; p++)
  92. *p = 0xaaaaaaaa;
  93. for (p = pstart; p < pend; p++) {
  94. if (*p != 0xaaaaaaaa) {
  95. printf ("SDRAM test fails at: %08x\n", (uint) p);
  96. return 1;
  97. }
  98. }
  99. for (p = pstart; p < pend; p++)
  100. *p = 0x55555555;
  101. for (p = pstart; p < pend; p++) {
  102. if (*p != 0x55555555) {
  103. printf ("SDRAM test fails at: %08x\n", (uint) p);
  104. return 1;
  105. }
  106. }
  107. return 0;
  108. }
  109. #endif
  110. /*************************************************************************
  111. * pci_pre_init
  112. *
  113. * This routine is called just prior to registering the hose and gives
  114. * the board the opportunity to check things. Returning a value of zero
  115. * indicates that things are bad & PCI initialization should be aborted.
  116. *
  117. * Different boards may wish to customize the pci controller structure
  118. * (add regions, override default access routines, etc) or perform
  119. * certain pre-initialization actions.
  120. *
  121. ************************************************************************/
  122. #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
  123. int pci_pre_init(struct pci_controller * hose )
  124. {
  125. unsigned long strap;
  126. /*--------------------------------------------------------------------------+
  127. * The ocotea board is always configured as the host & requires the
  128. * PCI arbiter to be enabled.
  129. *--------------------------------------------------------------------------*/
  130. mfsdr(sdr_sdstp1, strap);
  131. if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ){
  132. printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap);
  133. return 0;
  134. }
  135. /* FPGA Init */
  136. alpr_fpga_init ();
  137. return 1;
  138. }
  139. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
  140. /*************************************************************************
  141. * pci_target_init
  142. *
  143. * The bootstrap configuration provides default settings for the pci
  144. * inbound map (PIM). But the bootstrap config choices are limited and
  145. * may not be sufficient for a given board.
  146. *
  147. ************************************************************************/
  148. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  149. void pci_target_init(struct pci_controller * hose )
  150. {
  151. /*--------------------------------------------------------------------------+
  152. * Disable everything
  153. *--------------------------------------------------------------------------*/
  154. out32r( PCIX0_PIM0SA, 0 ); /* disable */
  155. out32r( PCIX0_PIM1SA, 0 ); /* disable */
  156. out32r( PCIX0_PIM2SA, 0 ); /* disable */
  157. out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */
  158. /*--------------------------------------------------------------------------+
  159. * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
  160. * options to not support sizes such as 128/256 MB.
  161. *--------------------------------------------------------------------------*/
  162. out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE );
  163. out32r( PCIX0_PIM0LAH, 0 );
  164. out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 );
  165. out32r( PCIX0_BAR0, 0 );
  166. /*--------------------------------------------------------------------------+
  167. * Program the board's subsystem id/vendor id
  168. *--------------------------------------------------------------------------*/
  169. out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID );
  170. out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID );
  171. out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  172. }
  173. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  174. /*************************************************************************
  175. * is_pci_host
  176. *
  177. * This routine is called to determine if a pci scan should be
  178. * performed. With various hardware environments (especially cPCI and
  179. * PPMC) it's insufficient to depend on the state of the arbiter enable
  180. * bit in the strap register, or generic host/adapter assumptions.
  181. *
  182. * Rather than hard-code a bad assumption in the general 440 code, the
  183. * 440 pci code requires the board to decide at runtime.
  184. *
  185. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  186. *
  187. *
  188. ************************************************************************/
  189. #if defined(CONFIG_PCI)
  190. int is_pci_host(struct pci_controller *hose)
  191. {
  192. /* The ocotea board is always configured as host. */
  193. return(1);
  194. }
  195. #endif /* defined(CONFIG_PCI) */
  196. /*************************************************************************
  197. * pci_master_init
  198. *
  199. ************************************************************************/
  200. #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
  201. void pci_master_init(struct pci_controller *hose)
  202. {
  203. unsigned short temp_short;
  204. #if 0
  205. /*--------------------------------------------------------------------------+
  206. | Write the PowerPC440 PCI Configuration regs.
  207. | Enable PowerPC440 to be a master on the PCI bus (PMM).
  208. | Enable PowerPC440 to act as a PCI memory target (PTM).
  209. +--------------------------------------------------------------------------*/
  210. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  211. pci_write_config_word(0, PCI_COMMAND,
  212. temp_short | PCI_COMMAND_MASTER |
  213. PCI_COMMAND_MEMORY);
  214. #endif
  215. #if 1
  216. /*--------------------------------------------------------------------------+
  217. | PowerPC440 PCI Master configuration.
  218. | Map PLB/processor addresses to PCI memory space.
  219. | PLB address 0xA0000000-0xCFFFFFFF ==> PCI address 0x80000000-0xCFFFFFFF
  220. | Use byte reversed out routines to handle endianess.
  221. | Make this region non-prefetchable.
  222. +--------------------------------------------------------------------------*/
  223. out32r( PCIX0_POM0SA, 0 ); /* disable */
  224. out32r( PCIX0_POM1SA, 0 ); /* disable */
  225. out32r( PCIX0_POM2SA, 0 ); /* disable */
  226. out32r(PCIX0_POM0LAL, CFG_PCI_MEMBASE); /* PMM0 Local Address */
  227. out32r(PCIX0_POM0LAH, 0x00000003); /* PMM0 Local Address */
  228. out32r(PCIX0_POM0PCIAL, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
  229. out32r(PCIX0_POM0PCIAH, 0x00000000); /* PMM0 PCI High Address */
  230. out32r(PCIX0_POM0SA, ~(0x10000000 - 1) | 1); /* 256MB + enable region */
  231. out32r(PCIX0_POM1LAL, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
  232. out32r(PCIX0_POM1LAH, 0x00000003); /* PMM0 Local Address */
  233. out32r(PCIX0_POM1PCIAL, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  234. out32r(PCIX0_POM1PCIAH, 0x00000000); /* PMM0 PCI High Address */
  235. out32r(PCIX0_POM1SA, ~(0x10000000 - 1) | 1); /* 256MB + enable region */
  236. #endif
  237. }
  238. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT) */
  239. #ifdef CONFIG_POST
  240. /*
  241. * Returns 1 if keys pressed to start the power-on long-running tests
  242. * Called from board_init_f().
  243. */
  244. int post_hotkeys_pressed(void)
  245. {
  246. return (ctrlc());
  247. }
  248. #endif