p3p440.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * (C) Copyright 2005
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * Copyright (C) 2002 Scott McNutt <smcnutt@artesyncp.com>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <asm/processor.h>
  27. #include <command.h>
  28. #include "p3p440.h"
  29. DECLARE_GLOBAL_DATA_PTR;
  30. void set_led(int color)
  31. {
  32. switch (color) {
  33. case LED_OFF:
  34. out32(GPIO0_OR, in32(GPIO0_OR) & ~CONFIG_SYS_LED_GREEN & ~CONFIG_SYS_LED_RED);
  35. break;
  36. case LED_GREEN:
  37. out32(GPIO0_OR, (in32(GPIO0_OR) | CONFIG_SYS_LED_GREEN) & ~CONFIG_SYS_LED_RED);
  38. break;
  39. case LED_RED:
  40. out32(GPIO0_OR, (in32(GPIO0_OR) | CONFIG_SYS_LED_RED) & ~CONFIG_SYS_LED_GREEN);
  41. break;
  42. case LED_ORANGE:
  43. out32(GPIO0_OR, in32(GPIO0_OR) | CONFIG_SYS_LED_GREEN | CONFIG_SYS_LED_RED);
  44. break;
  45. }
  46. }
  47. static int is_monarch(void)
  48. {
  49. out32(GPIO0_OR, in32(GPIO0_OR) & ~CONFIG_SYS_GPIO_RDY);
  50. udelay(1000);
  51. if (in32(GPIO0_IR) & CONFIG_SYS_MONARCH_IO)
  52. return 0;
  53. else
  54. return 1;
  55. }
  56. static void wait_for_pci_ready(void)
  57. {
  58. /*
  59. * Configure EREADY_IO as input
  60. */
  61. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~CONFIG_SYS_EREADY_IO);
  62. udelay(1000);
  63. for (;;) {
  64. if (in32(GPIO0_IR) & CONFIG_SYS_EREADY_IO)
  65. return;
  66. }
  67. }
  68. int board_early_init_f(void)
  69. {
  70. uint reg;
  71. /*--------------------------------------------------------------------
  72. * Setup the external bus controller/chip selects
  73. *-------------------------------------------------------------------*/
  74. mtdcr(ebccfga, xbcfg);
  75. reg = mfdcr(ebccfgd);
  76. mtdcr(ebccfgd, reg | 0x04000000); /* Set ATC */
  77. /*--------------------------------------------------------------------
  78. * Setup pin multiplexing (GPIO/IRQ...)
  79. *-------------------------------------------------------------------*/
  80. mtdcr(cpc0_gpio, 0x03F01F80);
  81. out32(GPIO0_ODR, 0x00000000); /* no open drain pins */
  82. out32(GPIO0_TCR, CONFIG_SYS_GPIO_RDY | CONFIG_SYS_EREADY_IO | CONFIG_SYS_LED_RED | CONFIG_SYS_LED_GREEN);
  83. out32(GPIO0_OR, CONFIG_SYS_GPIO_RDY);
  84. /*--------------------------------------------------------------------
  85. * Setup the interrupt controller polarities, triggers, etc.
  86. *-------------------------------------------------------------------*/
  87. mtdcr(uic0sr, 0xffffffff); /* clear all */
  88. mtdcr(uic0er, 0x00000000); /* disable all */
  89. mtdcr(uic0cr, 0x00000001); /* UIC1 crit is critical */
  90. mtdcr(uic0pr, 0xfffffe13); /* per ref-board manual */
  91. mtdcr(uic0tr, 0x01c00008); /* per ref-board manual */
  92. mtdcr(uic0vr, 0x00000001); /* int31 highest, base=0x000 */
  93. mtdcr(uic0sr, 0xffffffff); /* clear all */
  94. mtdcr(uic1sr, 0xffffffff); /* clear all */
  95. mtdcr(uic1er, 0x00000000); /* disable all */
  96. mtdcr(uic1cr, 0x00000000); /* all non-critical */
  97. mtdcr(uic1pr, 0xffffe0ff); /* per ref-board manual */
  98. mtdcr(uic1tr, 0x00ffc000); /* per ref-board manual */
  99. mtdcr(uic1vr, 0x00000001); /* int31 highest, base=0x000 */
  100. mtdcr(uic1sr, 0xffffffff); /* clear all */
  101. return 0;
  102. }
  103. int checkboard(void)
  104. {
  105. char *s = getenv("serial#");
  106. printf("Board: P3P440");
  107. if (s != NULL) {
  108. puts(", serial# ");
  109. puts(s);
  110. }
  111. if (is_monarch()) {
  112. puts(", Monarch");
  113. } else {
  114. puts(", None-Monarch");
  115. }
  116. putc('\n');
  117. return (0);
  118. }
  119. int misc_init_r (void)
  120. {
  121. /*
  122. * Adjust flash start and offset to detected values
  123. */
  124. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  125. gd->bd->bi_flashoffset = 0;
  126. /*
  127. * Check if only one FLASH bank is available
  128. */
  129. if (gd->bd->bi_flashsize != CONFIG_SYS_MAX_FLASH_BANKS * (0 - CONFIG_SYS_FLASH0)) {
  130. mtebc(pb1cr, 0); /* disable cs */
  131. mtebc(pb1ap, 0);
  132. mtebc(pb2cr, 0); /* disable cs */
  133. mtebc(pb2ap, 0);
  134. mtebc(pb3cr, 0); /* disable cs */
  135. mtebc(pb3ap, 0);
  136. }
  137. return 0;
  138. }
  139. /*************************************************************************
  140. * pci_pre_init
  141. *
  142. * This routine is called just prior to registering the hose and gives
  143. * the board the opportunity to check things. Returning a value of zero
  144. * indicates that things are bad & PCI initialization should be aborted.
  145. *
  146. * Different boards may wish to customize the pci controller structure
  147. * (add regions, override default access routines, etc) or perform
  148. * certain pre-initialization actions.
  149. *
  150. ************************************************************************/
  151. #if defined(CONFIG_PCI)
  152. int pci_pre_init(struct pci_controller *hose)
  153. {
  154. unsigned long strap;
  155. /*--------------------------------------------------------------------------+
  156. * The P3P440 board is always configured as the host & requires the
  157. * PCI arbiter to be disabled because it's an PMC module.
  158. *--------------------------------------------------------------------------*/
  159. strap = mfdcr(cpc0_strp1);
  160. if (strap & 0x00100000) {
  161. printf("PCI: CPC0_STRP1[PAE] set.\n");
  162. return 0;
  163. }
  164. return 1;
  165. }
  166. #endif /* defined(CONFIG_PCI) */
  167. /*************************************************************************
  168. * pci_target_init
  169. *
  170. * The bootstrap configuration provides default settings for the pci
  171. * inbound map (PIM). But the bootstrap config choices are limited and
  172. * may not be sufficient for a given board.
  173. *
  174. ************************************************************************/
  175. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
  176. void pci_target_init(struct pci_controller *hose)
  177. {
  178. /*--------------------------------------------------------------------------+
  179. * Disable everything
  180. *--------------------------------------------------------------------------*/
  181. out32r(PCIX0_PIM0SA, 0); /* disable */
  182. out32r(PCIX0_PIM1SA, 0); /* disable */
  183. out32r(PCIX0_PIM2SA, 0); /* disable */
  184. out32r(PCIX0_EROMBA, 0); /* disable expansion rom */
  185. /*--------------------------------------------------------------------------+
  186. * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
  187. * options to not support sizes such as 128/256 MB.
  188. *--------------------------------------------------------------------------*/
  189. out32r(PCIX0_PIM0LAL, CONFIG_SYS_SDRAM_BASE);
  190. out32r(PCIX0_PIM0LAH, 0);
  191. out32r(PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1);
  192. out32r(PCIX0_BAR0, 0);
  193. /*--------------------------------------------------------------------------+
  194. * Program the board's subsystem id/vendor id
  195. *--------------------------------------------------------------------------*/
  196. out16r(PCIX0_SBSYSVID, CONFIG_SYS_PCI_SUBSYS_VENDORID);
  197. out16r(PCIX0_SBSYSID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
  198. out16r(PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY);
  199. }
  200. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */
  201. /*************************************************************************
  202. * is_pci_host
  203. *
  204. * This routine is called to determine if a pci scan should be
  205. * performed. With various hardware environments (especially cPCI and
  206. * PPMC) it's insufficient to depend on the state of the arbiter enable
  207. * bit in the strap register, or generic host/adapter assumptions.
  208. *
  209. * Rather than hard-code a bad assumption in the general 440 code, the
  210. * 440 pci code requires the board to decide at runtime.
  211. *
  212. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  213. *
  214. *
  215. ************************************************************************/
  216. #if defined(CONFIG_PCI)
  217. int is_pci_host(struct pci_controller *hose)
  218. {
  219. if (is_monarch()) {
  220. wait_for_pci_ready();
  221. return 1; /* return 1 for host controller */
  222. } else {
  223. return 0; /* return 0 for adapter controller */
  224. }
  225. }
  226. #endif /* defined(CONFIG_PCI) */