alpr.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 <asm/ppc4xx-emac.h>
  28. #include <miiphy.h>
  29. #include <asm/processor.h>
  30. #include <asm/4xx_pci.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. extern int alpr_fpga_init(void);
  33. int board_early_init_f (void)
  34. {
  35. /*-------------------------------------------------------------------------
  36. * Initialize EBC CONFIG
  37. *-------------------------------------------------------------------------*/
  38. mtebc(EBC0_CFG, EBC_CFG_LE_UNLOCK |
  39. EBC_CFG_PTD_DISABLE | EBC_CFG_RTC_64PERCLK |
  40. EBC_CFG_ATC_PREVIOUS | EBC_CFG_DTC_PREVIOUS |
  41. EBC_CFG_CTC_PREVIOUS | EBC_CFG_EMC_NONDEFAULT |
  42. EBC_CFG_PME_DISABLE | EBC_CFG_PR_32);
  43. /*--------------------------------------------------------------------
  44. * Setup the interrupt controller polarities, triggers, etc.
  45. *-------------------------------------------------------------------*/
  46. /*
  47. * Because of the interrupt handling rework to handle 440GX interrupts
  48. * with the common code, we needed to change names of the UIC registers.
  49. * Here the new relationship:
  50. *
  51. * U-Boot name 440GX name
  52. * -----------------------
  53. * UIC0 UICB0
  54. * UIC1 UIC0
  55. * UIC2 UIC1
  56. * UIC3 UIC2
  57. */
  58. mtdcr (UIC1SR, 0xffffffff); /* clear all */
  59. mtdcr (UIC1ER, 0x00000000); /* disable all */
  60. mtdcr (UIC1CR, 0x00000009); /* SMI & UIC1 crit are critical */
  61. mtdcr (UIC1PR, 0xfffffe03); /* per manual */
  62. mtdcr (UIC1TR, 0x01c00000); /* per manual */
  63. mtdcr (UIC1VR, 0x00000001); /* int31 highest, base=0x000 */
  64. mtdcr (UIC1SR, 0xffffffff); /* clear all */
  65. mtdcr (UIC2SR, 0xffffffff); /* clear all */
  66. mtdcr (UIC2ER, 0x00000000); /* disable all */
  67. mtdcr (UIC2CR, 0x00000000); /* all non-critical */
  68. mtdcr (UIC2PR, 0xffffe0ff); /* per ref-board manual */
  69. mtdcr (UIC2TR, 0x00ffc000); /* per ref-board manual */
  70. mtdcr (UIC2VR, 0x00000001); /* int31 highest, base=0x000 */
  71. mtdcr (UIC2SR, 0xffffffff); /* clear all */
  72. mtdcr (UIC3SR, 0xffffffff); /* clear all */
  73. mtdcr (UIC3ER, 0x00000000); /* disable all */
  74. mtdcr (UIC3CR, 0x00000000); /* all non-critical */
  75. mtdcr (UIC3PR, 0xffffffff); /* per ref-board manual */
  76. mtdcr (UIC3TR, 0x00ff8c0f); /* per ref-board manual */
  77. mtdcr (UIC3VR, 0x00000001); /* int31 highest, base=0x000 */
  78. mtdcr (UIC3SR, 0xffffffff); /* clear all */
  79. mtdcr (UIC0SR, 0xfc000000); /* clear all */
  80. mtdcr (UIC0ER, 0x00000000); /* disable all */
  81. mtdcr (UIC0CR, 0x00000000); /* all non-critical */
  82. mtdcr (UIC0PR, 0xfc000000); /* */
  83. mtdcr (UIC0TR, 0x00000000); /* */
  84. mtdcr (UIC0VR, 0x00000001); /* */
  85. /* Setup shutdown/SSD empty interrupt as inputs */
  86. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~(CONFIG_SYS_GPIO_SHUTDOWN | CONFIG_SYS_GPIO_SSD_EMPTY));
  87. out32(GPIO0_ODR, in32(GPIO0_ODR) & ~(CONFIG_SYS_GPIO_SHUTDOWN | CONFIG_SYS_GPIO_SSD_EMPTY));
  88. /* Setup GPIO/IRQ multiplexing */
  89. mtsdr(SDR0_PFC0, 0x01a33e00);
  90. return 0;
  91. }
  92. int last_stage_init(void)
  93. {
  94. unsigned short reg;
  95. /*
  96. * Configure LED's of both Marvell 88E1111 PHY's
  97. *
  98. * This has to be done after the 4xx ethernet driver is loaded,
  99. * so "last_stage_init()" is the right place.
  100. */
  101. miiphy_read("ppc_4xx_eth2", CONFIG_PHY2_ADDR, 0x18, &reg);
  102. reg |= 0x0001;
  103. miiphy_write("ppc_4xx_eth2", CONFIG_PHY2_ADDR, 0x18, reg);
  104. miiphy_read("ppc_4xx_eth3", CONFIG_PHY3_ADDR, 0x18, &reg);
  105. reg |= 0x0001;
  106. miiphy_write("ppc_4xx_eth3", CONFIG_PHY3_ADDR, 0x18, reg);
  107. return 0;
  108. }
  109. static int board_rev(void)
  110. {
  111. /* Setup as input */
  112. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~(CONFIG_SYS_GPIO_REV0 | CONFIG_SYS_GPIO_REV1));
  113. out32(GPIO0_ODR, in32(GPIO0_ODR) & ~(CONFIG_SYS_GPIO_REV0 | CONFIG_SYS_GPIO_REV1));
  114. return (in32(GPIO0_IR) >> 16) & 0x3;
  115. }
  116. int checkboard (void)
  117. {
  118. char *s = getenv ("serial#");
  119. printf ("Board: ALPR");
  120. if (s != NULL) {
  121. puts (", serial# ");
  122. puts (s);
  123. }
  124. printf(" (Rev. %d)\n", board_rev());
  125. return (0);
  126. }
  127. #if defined(CONFIG_PCI)
  128. /*
  129. * Override weak pci_pre_init()
  130. */
  131. int pci_pre_init(struct pci_controller *hose)
  132. {
  133. if (__pci_pre_init(hose) == 0)
  134. return 0;
  135. /* FPGA Init */
  136. alpr_fpga_init();
  137. return 1;
  138. }
  139. /*************************************************************************
  140. * Override weak is_pci_host()
  141. *
  142. * This routine is called to determine if a pci scan should be
  143. * performed. With various hardware environments (especially cPCI and
  144. * PPMC) it's insufficient to depend on the state of the arbiter enable
  145. * bit in the strap register, or generic host/adapter assumptions.
  146. *
  147. * Rather than hard-code a bad assumption in the general 440 code, the
  148. * 440 pci code requires the board to decide at runtime.
  149. *
  150. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  151. *
  152. *
  153. ************************************************************************/
  154. static void wait_for_pci_ready(void)
  155. {
  156. /*
  157. * Configure EREADY as input
  158. */
  159. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~CONFIG_SYS_GPIO_EREADY);
  160. udelay(1000);
  161. for (;;) {
  162. if (in32(GPIO0_IR) & CONFIG_SYS_GPIO_EREADY)
  163. return;
  164. }
  165. }
  166. int is_pci_host(struct pci_controller *hose)
  167. {
  168. wait_for_pci_ready();
  169. return 1; /* return 1 for host controller */
  170. }
  171. #endif /* defined(CONFIG_PCI) */
  172. /*************************************************************************
  173. * pci_master_init
  174. *
  175. ************************************************************************/
  176. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT)
  177. void pci_master_init(struct pci_controller *hose)
  178. {
  179. /*--------------------------------------------------------------------------+
  180. | PowerPC440 PCI Master configuration.
  181. | Map PLB/processor addresses to PCI memory space.
  182. | PLB address 0xA0000000-0xCFFFFFFF ==> PCI address 0x80000000-0xCFFFFFFF
  183. | Use byte reversed out routines to handle endianess.
  184. | Make this region non-prefetchable.
  185. +--------------------------------------------------------------------------*/
  186. out32r( PCIL0_POM0SA, 0 ); /* disable */
  187. out32r( PCIL0_POM1SA, 0 ); /* disable */
  188. out32r( PCIL0_POM2SA, 0 ); /* disable */
  189. out32r(PCIL0_POM0LAL, CONFIG_SYS_PCI_MEMBASE); /* PMM0 Local Address */
  190. out32r(PCIL0_POM0LAH, 0x00000003); /* PMM0 Local Address */
  191. out32r(PCIL0_POM0PCIAL, CONFIG_SYS_PCI_MEMBASE); /* PMM0 PCI Low Address */
  192. out32r(PCIL0_POM0PCIAH, 0x00000000); /* PMM0 PCI High Address */
  193. out32r(PCIL0_POM0SA, ~(0x10000000 - 1) | 1); /* 256MB + enable region */
  194. out32r(PCIL0_POM1LAL, CONFIG_SYS_PCI_MEMBASE2); /* PMM0 Local Address */
  195. out32r(PCIL0_POM1LAH, 0x00000003); /* PMM0 Local Address */
  196. out32r(PCIL0_POM1PCIAL, CONFIG_SYS_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  197. out32r(PCIL0_POM1PCIAH, 0x00000000); /* PMM0 PCI High Address */
  198. out32r(PCIL0_POM1SA, ~(0x10000000 - 1) | 1); /* 256MB + enable region */
  199. }
  200. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT) */