alpr.c 10 KB

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