pcs440ep.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 <ppc4xx.h>
  25. #include <asm/processor.h>
  26. #include <spd_sdram.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
  29. static void set_leds(int val)
  30. {
  31. unsigned char led[16] = {0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
  32. 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf};
  33. out32(GPIO0_OR, (in32(GPIO0_OR) & ~0x78000000) | (led[val] << 27));
  34. }
  35. int board_early_init_f(void)
  36. {
  37. register uint reg;
  38. set_leds(0); /* display boot info counter */
  39. /*--------------------------------------------------------------------
  40. * Setup the external bus controller/chip selects
  41. *-------------------------------------------------------------------*/
  42. mtdcr(ebccfga, xbcfg);
  43. reg = mfdcr(ebccfgd);
  44. mtdcr(ebccfgd, reg | 0x04000000); /* Set ATC */
  45. /*--------------------------------------------------------------------
  46. * GPIO's are alreay setup in cpu/ppc4xx/cpu_init.c
  47. * via define from board config file.
  48. *-------------------------------------------------------------------*/
  49. /*--------------------------------------------------------------------
  50. * Setup the interrupt controller polarities, triggers, etc.
  51. *-------------------------------------------------------------------*/
  52. mtdcr(uic0sr, 0xffffffff); /* clear all */
  53. mtdcr(uic0er, 0x00000000); /* disable all */
  54. mtdcr(uic0cr, 0x00000001); /* UIC1 crit is critical */
  55. mtdcr(uic0pr, 0xfffffe1f); /* per ref-board manual */
  56. mtdcr(uic0tr, 0x01c00000); /* per ref-board manual */
  57. mtdcr(uic0vr, 0x00000001); /* int31 highest, base=0x000 */
  58. mtdcr(uic0sr, 0xffffffff); /* clear all */
  59. mtdcr(uic1sr, 0xffffffff); /* clear all */
  60. mtdcr(uic1er, 0x00000000); /* disable all */
  61. mtdcr(uic1cr, 0x00000000); /* all non-critical */
  62. mtdcr(uic1pr, 0xffffe0ff); /* per ref-board manual */
  63. mtdcr(uic1tr, 0x00ffc000); /* per ref-board manual */
  64. mtdcr(uic1vr, 0x00000001); /* int31 highest, base=0x000 */
  65. mtdcr(uic1sr, 0xffffffff); /* clear all */
  66. /*--------------------------------------------------------------------
  67. * Setup other serial configuration
  68. *-------------------------------------------------------------------*/
  69. mfsdr(sdr_pci0, reg);
  70. mtsdr(sdr_pci0, 0x80000000 | reg); /* PCI arbiter enabled */
  71. mtsdr(sdr_pfc0, 0x00000100); /* Pin function: enable GPIO49-63 */
  72. mtsdr(sdr_pfc1, 0x00048000); /* Pin function: UART0 has 4 pins, select IRQ5 */
  73. return 0;
  74. }
  75. int misc_init_r (void)
  76. {
  77. uint pbcr;
  78. int size_val = 0;
  79. /* Re-do sizing to get full correct info */
  80. mtdcr(ebccfga, pb0cr);
  81. pbcr = mfdcr(ebccfgd);
  82. switch (gd->bd->bi_flashsize) {
  83. case 1 << 20:
  84. size_val = 0;
  85. break;
  86. case 2 << 20:
  87. size_val = 1;
  88. break;
  89. case 4 << 20:
  90. size_val = 2;
  91. break;
  92. case 8 << 20:
  93. size_val = 3;
  94. break;
  95. case 16 << 20:
  96. size_val = 4;
  97. break;
  98. case 32 << 20:
  99. size_val = 5;
  100. break;
  101. case 64 << 20:
  102. size_val = 6;
  103. break;
  104. case 128 << 20:
  105. size_val = 7;
  106. break;
  107. }
  108. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  109. mtdcr(ebccfga, pb0cr);
  110. mtdcr(ebccfgd, pbcr);
  111. /* adjust flash start and offset */
  112. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  113. gd->bd->bi_flashoffset = 0;
  114. /* Monitor protection ON by default */
  115. (void)flash_protect(FLAG_PROTECT_SET,
  116. -CFG_MONITOR_LEN,
  117. 0xffffffff,
  118. &flash_info[1]);
  119. /* Env protection ON by default */
  120. (void)flash_protect(FLAG_PROTECT_SET,
  121. CFG_ENV_ADDR_REDUND,
  122. CFG_ENV_ADDR_REDUND + 2*CFG_ENV_SECT_SIZE - 1,
  123. &flash_info[1]);
  124. return 0;
  125. }
  126. int checkboard(void)
  127. {
  128. char *s = getenv("serial#");
  129. printf("Board: PCS440EP");
  130. if (s != NULL) {
  131. puts(", serial# ");
  132. puts(s);
  133. }
  134. putc('\n');
  135. return (0);
  136. }
  137. long int initdram (int board_type)
  138. {
  139. long dram_size = 0;
  140. set_leds(1); /* display boot info counter */
  141. dram_size = spd_sdram();
  142. set_leds(2); /* display boot info counter */
  143. return dram_size;
  144. }
  145. #if defined(CFG_DRAM_TEST)
  146. int testdram(void)
  147. {
  148. unsigned long *mem = (unsigned long *)0;
  149. const unsigned long kend = (1024 / sizeof(unsigned long));
  150. unsigned long k, n;
  151. mtmsr(0);
  152. for (k = 0; k < CFG_KBYTES_SDRAM;
  153. ++k, mem += (1024 / sizeof(unsigned long))) {
  154. if ((k & 1023) == 0) {
  155. printf("%3d MB\r", k / 1024);
  156. }
  157. memset(mem, 0xaaaaaaaa, 1024);
  158. for (n = 0; n < kend; ++n) {
  159. if (mem[n] != 0xaaaaaaaa) {
  160. printf("SDRAM test fails at: %08x\n",
  161. (uint) & mem[n]);
  162. return 1;
  163. }
  164. }
  165. memset(mem, 0x55555555, 1024);
  166. for (n = 0; n < kend; ++n) {
  167. if (mem[n] != 0x55555555) {
  168. printf("SDRAM test fails at: %08x\n",
  169. (uint) & mem[n]);
  170. return 1;
  171. }
  172. }
  173. }
  174. printf("SDRAM test passes\n");
  175. return 0;
  176. }
  177. #endif
  178. /*************************************************************************
  179. * pci_pre_init
  180. *
  181. * This routine is called just prior to registering the hose and gives
  182. * the board the opportunity to check things. Returning a value of zero
  183. * indicates that things are bad & PCI initialization should be aborted.
  184. *
  185. * Different boards may wish to customize the pci controller structure
  186. * (add regions, override default access routines, etc) or perform
  187. * certain pre-initialization actions.
  188. *
  189. ************************************************************************/
  190. #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
  191. int pci_pre_init(struct pci_controller *hose)
  192. {
  193. unsigned long addr;
  194. /*-------------------------------------------------------------------------+
  195. | Set priority for all PLB3 devices to 0.
  196. | Set PLB3 arbiter to fair mode.
  197. +-------------------------------------------------------------------------*/
  198. mfsdr(sdr_amp1, addr);
  199. mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
  200. addr = mfdcr(plb3_acr);
  201. mtdcr(plb3_acr, addr | 0x80000000);
  202. /*-------------------------------------------------------------------------+
  203. | Set priority for all PLB4 devices to 0.
  204. +-------------------------------------------------------------------------*/
  205. mfsdr(sdr_amp0, addr);
  206. mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
  207. addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
  208. mtdcr(plb4_acr, addr);
  209. /*-------------------------------------------------------------------------+
  210. | Set Nebula PLB4 arbiter to fair mode.
  211. +-------------------------------------------------------------------------*/
  212. /* Segment0 */
  213. addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
  214. addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
  215. addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
  216. addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
  217. mtdcr(plb0_acr, addr);
  218. /* Segment1 */
  219. addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
  220. addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
  221. addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
  222. addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
  223. mtdcr(plb1_acr, addr);
  224. return 1;
  225. }
  226. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
  227. /*************************************************************************
  228. * pci_target_init
  229. *
  230. * The bootstrap configuration provides default settings for the pci
  231. * inbound map (PIM). But the bootstrap config choices are limited and
  232. * may not be sufficient for a given board.
  233. *
  234. ************************************************************************/
  235. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  236. void pci_target_init(struct pci_controller *hose)
  237. {
  238. /*--------------------------------------------------------------------------+
  239. * Set up Direct MMIO registers
  240. *--------------------------------------------------------------------------*/
  241. /*--------------------------------------------------------------------------+
  242. | PowerPC440 EP PCI Master configuration.
  243. | Map one 1Gig range of PLB/processor addresses to PCI memory space.
  244. | PLB address 0xA0000000-0xDFFFFFFF ==> PCI address 0xA0000000-0xDFFFFFFF
  245. | Use byte reversed out routines to handle endianess.
  246. | Make this region non-prefetchable.
  247. +--------------------------------------------------------------------------*/
  248. out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  249. out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */
  250. out32r(PCIX0_PMM0PCILA, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
  251. out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
  252. out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  253. out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  254. out32r(PCIX0_PMM1LA, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
  255. out32r(PCIX0_PMM1PCILA, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  256. out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
  257. out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  258. out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
  259. out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
  260. out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
  261. out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
  262. /*--------------------------------------------------------------------------+
  263. * Set up Configuration registers
  264. *--------------------------------------------------------------------------*/
  265. /* Program the board's subsystem id/vendor id */
  266. pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
  267. CFG_PCI_SUBSYS_VENDORID);
  268. pci_write_config_word(0, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_ID);
  269. /* Configure command register as bus master */
  270. pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
  271. /* 240nS PCI clock */
  272. pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
  273. /* No error reporting */
  274. pci_write_config_word(0, PCI_ERREN, 0);
  275. pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
  276. }
  277. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  278. /*************************************************************************
  279. * pci_master_init
  280. *
  281. ************************************************************************/
  282. #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
  283. void pci_master_init(struct pci_controller *hose)
  284. {
  285. unsigned short temp_short;
  286. /*--------------------------------------------------------------------------+
  287. | Write the PowerPC440 EP PCI Configuration regs.
  288. | Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  289. | Enable PowerPC440 EP to act as a PCI memory target (PTM).
  290. +--------------------------------------------------------------------------*/
  291. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  292. pci_write_config_word(0, PCI_COMMAND,
  293. temp_short | PCI_COMMAND_MASTER |
  294. PCI_COMMAND_MEMORY);
  295. }
  296. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT) */
  297. /*************************************************************************
  298. * is_pci_host
  299. *
  300. * This routine is called to determine if a pci scan should be
  301. * performed. With various hardware environments (especially cPCI and
  302. * PPMC) it's insufficient to depend on the state of the arbiter enable
  303. * bit in the strap register, or generic host/adapter assumptions.
  304. *
  305. * Rather than hard-code a bad assumption in the general 440 code, the
  306. * 440 pci code requires the board to decide at runtime.
  307. *
  308. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  309. *
  310. *
  311. ************************************************************************/
  312. #if defined(CONFIG_PCI)
  313. int is_pci_host(struct pci_controller *hose)
  314. {
  315. /* PCS440EP is always configured as host. */
  316. return (1);
  317. }
  318. #endif /* defined(CONFIG_PCI) */
  319. /*************************************************************************
  320. * hw_watchdog_reset
  321. *
  322. * This routine is called to reset (keep alive) the watchdog timer
  323. *
  324. ************************************************************************/
  325. #if defined(CONFIG_HW_WATCHDOG)
  326. void hw_watchdog_reset(void)
  327. {
  328. }
  329. #endif