gdppc440etx.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * (C) Copyright 2008
  3. * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
  4. *
  5. * Based on board/amcc/yosemite/yosemite.c
  6. * (C) Copyright 2006-2007
  7. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <ppc4xx.h>
  29. #include <asm/processor.h>
  30. #include <asm/io.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. /* info for FLASH chips */
  33. extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
  34. int board_early_init_f(void)
  35. {
  36. register uint reg;
  37. /*
  38. * Setup the external bus controller/chip selects
  39. */
  40. mfebc(xbcfg, reg);
  41. mtebc(xbcfg, reg | 0x04000000); /* Set ATC */
  42. /*
  43. * Setup the GPIO pins
  44. */
  45. /* setup Address lines for flash size 64Meg. */
  46. out32(GPIO0_OSRL, in32(GPIO0_OSRL) | 0x54000000);
  47. out32(GPIO0_TSRL, in32(GPIO0_TSRL) | 0x54000000);
  48. out32(GPIO0_ISR1L, in32(GPIO0_ISR1L) | 0x54000000);
  49. /* setup emac */
  50. out32(GPIO0_TCR, in32(GPIO0_TCR) | 0xC080);
  51. out32(GPIO0_TSRL, in32(GPIO0_TSRL) | 0x40);
  52. out32(GPIO0_ISR1L, in32(GPIO0_ISR1L) | 0x55);
  53. out32(GPIO0_OSRH, in32(GPIO0_OSRH) | 0x50004000);
  54. out32(GPIO0_ISR1H, in32(GPIO0_ISR1H) | 0x00440000);
  55. /* UART0 and UART1*/
  56. out32(GPIO1_TCR, in32(GPIO1_TCR) | 0x16000000);
  57. out32(GPIO1_OSRL, in32(GPIO1_OSRL) | 0x02180000);
  58. out32(GPIO1_ISR1L, in32(GPIO1_ISR1L) | 0x00400000);
  59. out32(GPIO1_ISR2L, in32(GPIO1_ISR2L) | 0x04010000);
  60. /* disable boot-eeprom WP */
  61. out32(GPIO0_OSRL, in32(GPIO0_OSRL) & ~0x00C00000);
  62. out32(GPIO0_TSRL, in32(GPIO0_TSRL) & ~0x00C00000);
  63. out32(GPIO0_ISR1L, in32(GPIO0_ISR1L) & ~0x00C00000);
  64. out32(GPIO0_TCR, in32(GPIO0_TCR) | 0x08000000);
  65. out32(GPIO0_OR, in32(GPIO0_OR) & ~0x08000000);
  66. /* external interrupts IRQ0...3 */
  67. out32(GPIO1_TCR, in32(GPIO1_TCR) & ~0x00f00000);
  68. out32(GPIO1_TSRL, in32(GPIO1_TSRL) & ~0x00005500);
  69. out32(GPIO1_ISR1L, in32(GPIO1_ISR1L) | 0x00005500);
  70. /*
  71. * Setup the interrupt controller polarities, triggers, etc.
  72. */
  73. mtdcr(uic0sr, 0xffffffff); /* clear all */
  74. mtdcr(uic0er, 0x00000000); /* disable all */
  75. mtdcr(uic0cr, 0x00000009); /* ATI & UIC1 crit are critical */
  76. mtdcr(uic0pr, 0xfffffe13); /* per ref-board manual */
  77. mtdcr(uic0tr, 0x01c00008); /* per ref-board manual */
  78. mtdcr(uic0vr, 0x00000001); /* int31 highest, base=0x000 */
  79. mtdcr(uic0sr, 0xffffffff); /* clear all */
  80. mtdcr(uic1sr, 0xffffffff); /* clear all */
  81. mtdcr(uic1er, 0x00000000); /* disable all */
  82. mtdcr(uic1cr, 0x00000000); /* all non-critical */
  83. mtdcr(uic1pr, 0xffffe0ff); /* per ref-board manual */
  84. mtdcr(uic1tr, 0x00ffc000); /* per ref-board manual */
  85. mtdcr(uic1vr, 0x00000001); /* int31 highest, base=0x000 */
  86. mtdcr(uic1sr, 0xffffffff); /* clear all */
  87. /*
  88. * Setup other serial configuration
  89. */
  90. mfsdr(sdr_pci0, reg);
  91. mtsdr(sdr_pci0, 0x80000000 | reg); /* PCI arbiter enabled */
  92. mtsdr(sdr_pfc0, 0x00003e00); /* Pin function */
  93. mtsdr(sdr_pfc1, 0x00048000); /* Pin function: UART0 has 4 pins */
  94. return 0;
  95. }
  96. int misc_init_r(void)
  97. {
  98. uint pbcr;
  99. int size_val;
  100. uint sz;
  101. /* Re-do sizing to get full correct info */
  102. mfebc(pb0cr, pbcr);
  103. if (gd->bd->bi_flashsize > 0x08000000)
  104. panic("Max. flash banksize is 128 MB!\n");
  105. for (sz = gd->bd->bi_flashsize, size_val = 7;
  106. ((sz & 0x08000000) == 0) && (size_val > 0); --size_val)
  107. sz <<= 1;
  108. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  109. mtebc(pb0cr, pbcr);
  110. /* adjust flash start and offset */
  111. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  112. gd->bd->bi_flashoffset = 0;
  113. /* Monitor protection ON by default */
  114. (void)flash_protect(FLAG_PROTECT_SET,
  115. -CONFIG_SYS_MONITOR_LEN,
  116. 0xffffffff,
  117. &flash_info[0]);
  118. return 0;
  119. }
  120. int checkboard(void)
  121. {
  122. char *s = getenv("serial#");
  123. u8 rev;
  124. u8 val;
  125. printf("Board: GDPPC440ETX - G&D PPC440EP/GR ETX-module");
  126. if (s != NULL) {
  127. puts(", serial# ");
  128. puts(s);
  129. }
  130. putc('\n');
  131. return 0;
  132. }
  133. /*
  134. * pci_pre_init
  135. *
  136. * This routine is called just prior to registering the hose and gives
  137. * the board the opportunity to check things. Returning a value of zero
  138. * indicates that things are bad & PCI initialization should be aborted.
  139. *
  140. * Different boards may wish to customize the pci controller structure
  141. * (add regions, override default access routines, etc) or perform
  142. * certain pre-initialization actions.
  143. *
  144. */
  145. #if defined(CONFIG_PCI)
  146. int pci_pre_init(struct pci_controller *hose)
  147. {
  148. unsigned long addr;
  149. /*
  150. * Set priority for all PLB3 devices to 0.
  151. * Set PLB3 arbiter to fair mode.
  152. */
  153. mfsdr(sdr_amp1, addr);
  154. mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
  155. addr = mfdcr(plb3_acr);
  156. mtdcr(plb3_acr, addr | 0x80000000);
  157. /*
  158. * Set priority for all PLB4 devices to 0.
  159. */
  160. mfsdr(sdr_amp0, addr);
  161. mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
  162. addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
  163. mtdcr(plb4_acr, addr);
  164. /*
  165. * Set Nebula PLB4 arbiter to fair mode.
  166. */
  167. /* Segment0 */
  168. addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
  169. addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
  170. addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
  171. addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
  172. mtdcr(plb0_acr, addr);
  173. /* Segment1 */
  174. addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
  175. addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
  176. addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
  177. addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
  178. mtdcr(plb1_acr, addr);
  179. /* enable 66 MHz ext. Clock */
  180. out32(GPIO1_TCR, in32(GPIO1_TCR) | 0x00008000);
  181. out32(GPIO1_OR, in32(GPIO1_OR) | 0x00008000);
  182. return 1;
  183. }
  184. #endif /* defined(CONFIG_PCI) */
  185. /*
  186. * pci_target_init
  187. *
  188. * The bootstrap configuration provides default settings for the pci
  189. * inbound map (PIM). But the bootstrap config choices are limited and
  190. * may not be sufficient for a given board.
  191. *
  192. */
  193. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
  194. void pci_target_init(struct pci_controller *hose)
  195. {
  196. /*
  197. * Set up Direct MMIO registers
  198. */
  199. /*
  200. * PowerPC440 EP PCI Master configuration.
  201. * Map one 1Gig range of PLB/processor addresses to PCI memory space.
  202. * PLB address 0xA0000000-0xDFFFFFFF
  203. * ==> PCI address 0xA0000000-0xDFFFFFFF
  204. * Use byte reversed out routines to handle endianess.
  205. * Make this region non-prefetchable.
  206. */
  207. out32r(PCIX0_PMM0MA, 0x00000000); /* disabled b4 setting */
  208. out32r(PCIX0_PMM0LA, CONFIG_SYS_PCI_MEMBASE);
  209. out32r(PCIX0_PMM0PCILA, CONFIG_SYS_PCI_MEMBASE);
  210. out32r(PCIX0_PMM0PCIHA, 0x00000000);
  211. out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M, no prefetch, enable region */
  212. out32r(PCIX0_PMM1MA, 0x00000000); /* disabled b4 setting */
  213. out32r(PCIX0_PMM1LA, CONFIG_SYS_PCI_MEMBASE2);
  214. out32r(PCIX0_PMM1PCILA, CONFIG_SYS_PCI_MEMBASE2);
  215. out32r(PCIX0_PMM1PCIHA, 0x00000000);
  216. out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M, no prefetch, enable region */
  217. out32r(PCIX0_PTM1MS, 0x00000001);
  218. out32r(PCIX0_PTM1LA, 0);
  219. out32r(PCIX0_PTM2MS, 0);
  220. out32r(PCIX0_PTM2LA, 0);
  221. /*
  222. * Set up Configuration registers
  223. */
  224. /* Program the board's subsystem id/vendor id */
  225. pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
  226. CONFIG_SYS_PCI_SUBSYS_VENDORID);
  227. pci_write_config_word(0, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_ID);
  228. /* Configure command register as bus master */
  229. pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
  230. /* 240nS PCI clock */
  231. pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
  232. /* No error reporting */
  233. pci_write_config_word(0, PCI_ERREN, 0);
  234. pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
  235. }
  236. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */
  237. /*
  238. * pci_master_init
  239. *
  240. */
  241. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT)
  242. void pci_master_init(struct pci_controller *hose)
  243. {
  244. unsigned short temp_short;
  245. /*
  246. * Write the PowerPC440 EP PCI Configuration regs.
  247. * Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  248. * Enable PowerPC440 EP to act as a PCI memory target (PTM).
  249. */
  250. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  251. pci_write_config_word(0, PCI_COMMAND,
  252. temp_short | PCI_COMMAND_MASTER |
  253. PCI_COMMAND_MEMORY);
  254. }
  255. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT) */
  256. /*
  257. * is_pci_host
  258. *
  259. * This routine is called to determine if a pci scan should be
  260. * performed. With various hardware environments (especially cPCI and
  261. * PPMC) it's insufficient to depend on the state of the arbiter enable
  262. * bit in the strap register, or generic host/adapter assumptions.
  263. *
  264. * Rather than hard-code a bad assumption in the general 440 code, the
  265. * 440 pci code requires the board to decide at runtime.
  266. *
  267. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  268. *
  269. *
  270. */
  271. #if defined(CONFIG_PCI)
  272. int is_pci_host(struct pci_controller *hose)
  273. {
  274. return 1;
  275. }
  276. #endif /* defined(CONFIG_PCI) */