alpr.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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(EBC0_CFG, 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. /*
  46. * Because of the interrupt handling rework to handle 440GX interrupts
  47. * with the common code, we needed to change names of the UIC registers.
  48. * Here the new relationship:
  49. *
  50. * U-Boot name 440GX name
  51. * -----------------------
  52. * UIC0 UICB0
  53. * UIC1 UIC0
  54. * UIC2 UIC1
  55. * UIC3 UIC2
  56. */
  57. mtdcr (UIC1SR, 0xffffffff); /* clear all */
  58. mtdcr (UIC1ER, 0x00000000); /* disable all */
  59. mtdcr (UIC1CR, 0x00000009); /* SMI & UIC1 crit are critical */
  60. mtdcr (UIC1PR, 0xfffffe03); /* per manual */
  61. mtdcr (UIC1TR, 0x01c00000); /* per manual */
  62. mtdcr (UIC1VR, 0x00000001); /* int31 highest, base=0x000 */
  63. mtdcr (UIC1SR, 0xffffffff); /* clear all */
  64. mtdcr (UIC2SR, 0xffffffff); /* clear all */
  65. mtdcr (UIC2ER, 0x00000000); /* disable all */
  66. mtdcr (UIC2CR, 0x00000000); /* all non-critical */
  67. mtdcr (UIC2PR, 0xffffe0ff); /* per ref-board manual */
  68. mtdcr (UIC2TR, 0x00ffc000); /* per ref-board manual */
  69. mtdcr (UIC2VR, 0x00000001); /* int31 highest, base=0x000 */
  70. mtdcr (UIC2SR, 0xffffffff); /* clear all */
  71. mtdcr (UIC3SR, 0xffffffff); /* clear all */
  72. mtdcr (UIC3ER, 0x00000000); /* disable all */
  73. mtdcr (UIC3CR, 0x00000000); /* all non-critical */
  74. mtdcr (UIC3PR, 0xffffffff); /* per ref-board manual */
  75. mtdcr (UIC3TR, 0x00ff8c0f); /* per ref-board manual */
  76. mtdcr (UIC3VR, 0x00000001); /* int31 highest, base=0x000 */
  77. mtdcr (UIC3SR, 0xffffffff); /* clear all */
  78. mtdcr (UIC0SR, 0xfc000000); /* clear all */
  79. mtdcr (UIC0ER, 0x00000000); /* disable all */
  80. mtdcr (UIC0CR, 0x00000000); /* all non-critical */
  81. mtdcr (UIC0PR, 0xfc000000); /* */
  82. mtdcr (UIC0TR, 0x00000000); /* */
  83. mtdcr (UIC0VR, 0x00000001); /* */
  84. /* Setup shutdown/SSD empty interrupt as inputs */
  85. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~(CONFIG_SYS_GPIO_SHUTDOWN | CONFIG_SYS_GPIO_SSD_EMPTY));
  86. out32(GPIO0_ODR, in32(GPIO0_ODR) & ~(CONFIG_SYS_GPIO_SHUTDOWN | CONFIG_SYS_GPIO_SSD_EMPTY));
  87. /* Setup GPIO/IRQ multiplexing */
  88. mtsdr(SDR0_PFC0, 0x01a33e00);
  89. return 0;
  90. }
  91. int last_stage_init(void)
  92. {
  93. unsigned short reg;
  94. /*
  95. * Configure LED's of both Marvell 88E1111 PHY's
  96. *
  97. * This has to be done after the 4xx ethernet driver is loaded,
  98. * so "last_stage_init()" is the right place.
  99. */
  100. miiphy_read("ppc_4xx_eth2", CONFIG_PHY2_ADDR, 0x18, &reg);
  101. reg |= 0x0001;
  102. miiphy_write("ppc_4xx_eth2", CONFIG_PHY2_ADDR, 0x18, reg);
  103. miiphy_read("ppc_4xx_eth3", CONFIG_PHY3_ADDR, 0x18, &reg);
  104. reg |= 0x0001;
  105. miiphy_write("ppc_4xx_eth3", CONFIG_PHY3_ADDR, 0x18, reg);
  106. return 0;
  107. }
  108. static int board_rev(void)
  109. {
  110. /* Setup as input */
  111. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~(CONFIG_SYS_GPIO_REV0 | CONFIG_SYS_GPIO_REV1));
  112. out32(GPIO0_ODR, in32(GPIO0_ODR) & ~(CONFIG_SYS_GPIO_REV0 | CONFIG_SYS_GPIO_REV1));
  113. return (in32(GPIO0_IR) >> 16) & 0x3;
  114. }
  115. int checkboard (void)
  116. {
  117. char *s = getenv ("serial#");
  118. printf ("Board: ALPR");
  119. if (s != NULL) {
  120. puts (", serial# ");
  121. puts (s);
  122. }
  123. printf(" (Rev. %d)\n", board_rev());
  124. return (0);
  125. }
  126. /*************************************************************************
  127. * pci_pre_init
  128. *
  129. * This routine is called just prior to registering the hose and gives
  130. * the board the opportunity to check things. Returning a value of zero
  131. * indicates that things are bad & PCI initialization should be aborted.
  132. *
  133. * Different boards may wish to customize the pci controller structure
  134. * (add regions, override default access routines, etc) or perform
  135. * certain pre-initialization actions.
  136. *
  137. ************************************************************************/
  138. #if defined(CONFIG_PCI)
  139. int pci_pre_init(struct pci_controller * hose )
  140. {
  141. unsigned long strap;
  142. /*--------------------------------------------------------------------------+
  143. * The ocotea board is always configured as the host & requires the
  144. * PCI arbiter to be enabled.
  145. *--------------------------------------------------------------------------*/
  146. mfsdr(SDR0_SDSTP1, strap);
  147. if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ){
  148. printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap);
  149. return 0;
  150. }
  151. /* FPGA Init */
  152. alpr_fpga_init ();
  153. return 1;
  154. }
  155. #endif /* defined(CONFIG_PCI) */
  156. /*************************************************************************
  157. * Override weak is_pci_host()
  158. *
  159. * This routine is called to determine if a pci scan should be
  160. * performed. With various hardware environments (especially cPCI and
  161. * PPMC) it's insufficient to depend on the state of the arbiter enable
  162. * bit in the strap register, or generic host/adapter assumptions.
  163. *
  164. * Rather than hard-code a bad assumption in the general 440 code, the
  165. * 440 pci code requires the board to decide at runtime.
  166. *
  167. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  168. *
  169. *
  170. ************************************************************************/
  171. #if defined(CONFIG_PCI)
  172. static void wait_for_pci_ready(void)
  173. {
  174. /*
  175. * Configure EREADY as input
  176. */
  177. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~CONFIG_SYS_GPIO_EREADY);
  178. udelay(1000);
  179. for (;;) {
  180. if (in32(GPIO0_IR) & CONFIG_SYS_GPIO_EREADY)
  181. return;
  182. }
  183. }
  184. int is_pci_host(struct pci_controller *hose)
  185. {
  186. wait_for_pci_ready();
  187. return 1; /* return 1 for host controller */
  188. }
  189. #endif /* defined(CONFIG_PCI) */
  190. /*************************************************************************
  191. * pci_master_init
  192. *
  193. ************************************************************************/
  194. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT)
  195. void pci_master_init(struct pci_controller *hose)
  196. {
  197. /*--------------------------------------------------------------------------+
  198. | PowerPC440 PCI Master configuration.
  199. | Map PLB/processor addresses to PCI memory space.
  200. | PLB address 0xA0000000-0xCFFFFFFF ==> PCI address 0x80000000-0xCFFFFFFF
  201. | Use byte reversed out routines to handle endianess.
  202. | Make this region non-prefetchable.
  203. +--------------------------------------------------------------------------*/
  204. out32r( PCIL0_POM0SA, 0 ); /* disable */
  205. out32r( PCIL0_POM1SA, 0 ); /* disable */
  206. out32r( PCIL0_POM2SA, 0 ); /* disable */
  207. out32r(PCIL0_POM0LAL, CONFIG_SYS_PCI_MEMBASE); /* PMM0 Local Address */
  208. out32r(PCIL0_POM0LAH, 0x00000003); /* PMM0 Local Address */
  209. out32r(PCIL0_POM0PCIAL, CONFIG_SYS_PCI_MEMBASE); /* PMM0 PCI Low Address */
  210. out32r(PCIL0_POM0PCIAH, 0x00000000); /* PMM0 PCI High Address */
  211. out32r(PCIL0_POM0SA, ~(0x10000000 - 1) | 1); /* 256MB + enable region */
  212. out32r(PCIL0_POM1LAL, CONFIG_SYS_PCI_MEMBASE2); /* PMM0 Local Address */
  213. out32r(PCIL0_POM1LAH, 0x00000003); /* PMM0 Local Address */
  214. out32r(PCIL0_POM1PCIAL, CONFIG_SYS_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  215. out32r(PCIL0_POM1PCIAH, 0x00000000); /* PMM0 PCI High Address */
  216. out32r(PCIL0_POM1SA, ~(0x10000000 - 1) | 1); /* 256MB + enable region */
  217. }
  218. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT) */
  219. #ifdef CONFIG_POST
  220. /*
  221. * Returns 1 if keys pressed to start the power-on long-running tests
  222. * Called from board_init_f().
  223. */
  224. int post_hotkeys_pressed(void)
  225. {
  226. return (ctrlc());
  227. }
  228. #endif