t3corp.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * (C) Copyright 2010
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <common.h>
  21. #include <asm/ppc440.h>
  22. #include <libfdt.h>
  23. #include <fdt_support.h>
  24. #include <i2c.h>
  25. #include <mtd/cfi_flash.h>
  26. #include <asm/processor.h>
  27. #include <asm/io.h>
  28. #include <asm/mmu.h>
  29. #include <asm/4xx_pcie.h>
  30. #include <asm/ppc4xx-gpio.h>
  31. int board_early_init_f(void)
  32. {
  33. /*
  34. * Setup the interrupt controller polarities, triggers, etc.
  35. */
  36. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  37. mtdcr(UIC0ER, 0x00000000); /* disable all */
  38. mtdcr(UIC0CR, 0x00000005); /* ATI & UIC1 crit are critical */
  39. mtdcr(UIC0PR, 0xffffffff); /* per ref-board manual */
  40. mtdcr(UIC0TR, 0x00000000); /* per ref-board manual */
  41. mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 */
  42. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  43. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  44. mtdcr(UIC1ER, 0x00000000); /* disable all */
  45. mtdcr(UIC1CR, 0x00000000); /* all non-critical */
  46. mtdcr(UIC1PR, 0x7fffffff); /* per ref-board manual */
  47. mtdcr(UIC1TR, 0x00000000); /* per ref-board manual */
  48. mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 */
  49. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  50. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  51. mtdcr(UIC2ER, 0x00000000); /* disable all */
  52. mtdcr(UIC2CR, 0x00000000); /* all non-critical */
  53. mtdcr(UIC2PR, 0xffffffff); /* per ref-board manual */
  54. mtdcr(UIC2TR, 0x00000000); /* per ref-board manual */
  55. mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 */
  56. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  57. mtdcr(UIC3SR, 0xffffffff); /* clear all */
  58. mtdcr(UIC3ER, 0x00000000); /* disable all */
  59. mtdcr(UIC3CR, 0x00000000); /* all non-critical */
  60. mtdcr(UIC3PR, 0xffffffff); /* per ref-board manual */
  61. mtdcr(UIC3TR, 0x00000000); /* per ref-board manual */
  62. mtdcr(UIC3VR, 0x00000000); /* int31 highest, base=0x000 */
  63. mtdcr(UIC3SR, 0xffffffff); /* clear all */
  64. /*
  65. * Configure PFC (Pin Function Control) registers
  66. * enable GPIO 49-63
  67. * UART0: 4 pins
  68. */
  69. mtsdr(SDR0_PFC0, 0x00007fff);
  70. mtsdr(SDR0_PFC1, 0x00040000);
  71. /* Enable PCI host functionality in SDR0_PCI0 */
  72. mtsdr(SDR0_PCI0, 0xe0000000);
  73. mtsdr(SDR0_SRST1, 0); /* Pull AHB out of reset default=1 */
  74. /* Setup PLB4-AHB bridge based on the system address map */
  75. mtdcr(AHB_TOP, 0x8000004B);
  76. mtdcr(AHB_BOT, 0x8000004B);
  77. return 0;
  78. }
  79. int checkboard(void)
  80. {
  81. char buf[64];
  82. int i = getenv_f("serial#", buf, sizeof(buf));
  83. printf("Board: T3CORP");
  84. if (i > 0) {
  85. puts(", serial# ");
  86. puts(buf);
  87. }
  88. putc('\n');
  89. return 0;
  90. }
  91. int board_early_init_r(void)
  92. {
  93. /*
  94. * T3CORP has 64MBytes of NOR flash (Spansion 29GL512), but the
  95. * boot EBC mapping only supports a maximum of 16MBytes
  96. * (4.ff00.0000 - 4.ffff.ffff).
  97. * To solve this problem, the flash has to get remapped to another
  98. * EBC address which accepts bigger regions:
  99. *
  100. * 0xfn00.0000 -> 4.cn00.0000
  101. */
  102. /* Remap the NOR flash to 0xcn00.0000 ... 0xcfff.ffff */
  103. mtebc(PB0CR, CONFIG_SYS_FLASH_BASE_PHYS_L | EBC_BXCR_BS_64MB |
  104. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT);
  105. /* Remove TLB entry of boot EBC mapping */
  106. remove_tlb(CONFIG_SYS_BOOT_BASE_ADDR, 16 << 20);
  107. /* Add TLB entry for 0xfn00.0000 -> 0x4.cn00.0000 */
  108. program_tlb(CONFIG_SYS_FLASH_BASE_PHYS, CONFIG_SYS_FLASH_BASE,
  109. CONFIG_SYS_FLASH_SIZE, TLB_WORD2_I_ENABLE);
  110. /*
  111. * Now accessing of the whole 64Mbytes of NOR flash at virtual address
  112. * 0xfc00.0000 is possible
  113. */
  114. /*
  115. * Clear potential errors resulting from auto-calibration.
  116. * If not done, then we could get an interrupt later on when
  117. * exceptions are enabled.
  118. */
  119. set_mcsr(get_mcsr());
  120. return 0;
  121. }
  122. int misc_init_r(void)
  123. {
  124. u32 sdr0_srst1 = 0;
  125. u32 eth_cfg;
  126. /*
  127. * Set EMAC mode/configuration (GMII, SGMII, RGMII...).
  128. * This is board specific, so let's do it here.
  129. */
  130. mfsdr(SDR0_ETH_CFG, eth_cfg);
  131. /* disable SGMII mode */
  132. eth_cfg &= ~(SDR0_ETH_CFG_SGMII2_ENABLE |
  133. SDR0_ETH_CFG_SGMII1_ENABLE |
  134. SDR0_ETH_CFG_SGMII0_ENABLE);
  135. /* Set the for 2 RGMII mode */
  136. /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
  137. eth_cfg &= ~SDR0_ETH_CFG_GMC0_BRIDGE_SEL;
  138. eth_cfg &= ~SDR0_ETH_CFG_GMC1_BRIDGE_SEL;
  139. mtsdr(SDR0_ETH_CFG, eth_cfg);
  140. /*
  141. * The AHB Bridge core is held in reset after power-on or reset
  142. * so enable it now
  143. */
  144. mfsdr(SDR0_SRST1, sdr0_srst1);
  145. sdr0_srst1 &= ~SDR0_SRST1_AHB;
  146. mtsdr(SDR0_SRST1, sdr0_srst1);
  147. return 0;
  148. }
  149. int board_pcie_last(void)
  150. {
  151. /*
  152. * Only PCIe0 for now, PCIe1 hangs on this board
  153. */
  154. return 0;
  155. }
  156. /*
  157. * Board specific WRDTR and CLKTR values used by the auto-
  158. * calibration code (4xx_ibm_ddr2_autocalib.c).
  159. */
  160. static struct sdram_timing board_scan_options[] = {
  161. {1, 2},
  162. {-1, -1}
  163. };
  164. struct sdram_timing *ddr_scan_option(struct sdram_timing *default_val)
  165. {
  166. return board_scan_options;
  167. }
  168. /*
  169. * Accessor functions replacing the "weak" functions in
  170. * drivers/mtd/cfi_flash.c
  171. *
  172. * The NOR flash devices "behind" the FPGA's (Xilinx DS617)
  173. * can only be read correctly in 16bit mode. We need to emulate
  174. * 8bit and 32bit reads here in the board specific code.
  175. */
  176. u8 flash_read8(void *addr)
  177. {
  178. u16 val = __raw_readw((void *)((u32)addr & ~1));
  179. if ((u32)addr & 1)
  180. return val;
  181. return val >> 8;
  182. }
  183. u32 flash_read32(void *addr)
  184. {
  185. return (__raw_readw(addr) << 16) | __raw_readw((void *)((u32)addr + 2));
  186. }
  187. void flash_cmd_reset(flash_info_t *info)
  188. {
  189. /*
  190. * FLASH at address CONFIG_SYS_FLASH_BASE is a Spansion chip and
  191. * needs the Spansion type reset commands. The other flash chip
  192. * is located behind a FPGA (Xilinx DS617) and needs the Intel type
  193. * reset command.
  194. */
  195. if (info->start[0] == CONFIG_SYS_FLASH_BASE)
  196. flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
  197. else
  198. flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
  199. }