t3corp.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 *s = getenv("serial#");
  82. printf("Board: T3CORP");
  83. if (s != NULL) {
  84. puts(", serial# ");
  85. puts(s);
  86. }
  87. putc('\n');
  88. return 0;
  89. }
  90. int board_early_init_r(void)
  91. {
  92. /*
  93. * T3CORP has 64MBytes of NOR flash (Spansion 29GL512), but the
  94. * boot EBC mapping only supports a maximum of 16MBytes
  95. * (4.ff00.0000 - 4.ffff.ffff).
  96. * To solve this problem, the flash has to get remapped to another
  97. * EBC address which accepts bigger regions:
  98. *
  99. * 0xfn00.0000 -> 4.cn00.0000
  100. */
  101. /* Remap the NOR flash to 0xcn00.0000 ... 0xcfff.ffff */
  102. mtebc(PB0CR, CONFIG_SYS_FLASH_BASE_PHYS_L | EBC_BXCR_BS_64MB |
  103. EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT);
  104. /* Remove TLB entry of boot EBC mapping */
  105. remove_tlb(CONFIG_SYS_BOOT_BASE_ADDR, 16 << 20);
  106. /* Add TLB entry for 0xfn00.0000 -> 0x4.cn00.0000 */
  107. program_tlb(CONFIG_SYS_FLASH_BASE_PHYS, CONFIG_SYS_FLASH_BASE,
  108. CONFIG_SYS_FLASH_SIZE, TLB_WORD2_I_ENABLE);
  109. /*
  110. * Now accessing of the whole 64Mbytes of NOR flash at virtual address
  111. * 0xfc00.0000 is possible
  112. */
  113. /*
  114. * Clear potential errors resulting from auto-calibration.
  115. * If not done, then we could get an interrupt later on when
  116. * exceptions are enabled.
  117. */
  118. set_mcsr(get_mcsr());
  119. return 0;
  120. }
  121. int misc_init_r(void)
  122. {
  123. u32 sdr0_srst1 = 0;
  124. u32 eth_cfg;
  125. /*
  126. * Set EMAC mode/configuration (GMII, SGMII, RGMII...).
  127. * This is board specific, so let's do it here.
  128. */
  129. mfsdr(SDR0_ETH_CFG, eth_cfg);
  130. /* disable SGMII mode */
  131. eth_cfg &= ~(SDR0_ETH_CFG_SGMII2_ENABLE |
  132. SDR0_ETH_CFG_SGMII1_ENABLE |
  133. SDR0_ETH_CFG_SGMII0_ENABLE);
  134. /* Set the for 2 RGMII mode */
  135. /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
  136. eth_cfg &= ~SDR0_ETH_CFG_GMC0_BRIDGE_SEL;
  137. eth_cfg &= ~SDR0_ETH_CFG_GMC1_BRIDGE_SEL;
  138. mtsdr(SDR0_ETH_CFG, eth_cfg);
  139. /*
  140. * The AHB Bridge core is held in reset after power-on or reset
  141. * so enable it now
  142. */
  143. mfsdr(SDR0_SRST1, sdr0_srst1);
  144. sdr0_srst1 &= ~SDR0_SRST1_AHB;
  145. mtsdr(SDR0_SRST1, sdr0_srst1);
  146. return 0;
  147. }
  148. int board_pcie_last(void)
  149. {
  150. /*
  151. * Only PCIe0 for now, PCIe1 hangs on this board
  152. */
  153. return 0;
  154. }
  155. /*
  156. * Board specific WRDTR and CLKTR values used by the auto-
  157. * calibration code (4xx_ibm_ddr2_autocalib.c).
  158. */
  159. static struct sdram_timing board_scan_options[] = {
  160. {1, 2},
  161. {-1, -1}
  162. };
  163. struct sdram_timing *ddr_scan_option(struct sdram_timing *default_val)
  164. {
  165. return board_scan_options;
  166. }
  167. /*
  168. * Accessor functions replacing the "weak" functions in
  169. * drivers/mtd/cfi_flash.c
  170. *
  171. * The NOR flash devices "behind" the FPGA's (Xilinx DS617)
  172. * can only be read correctly in 16bit mode. We need to emulate
  173. * 8bit and 32bit reads here in the board specific code.
  174. */
  175. u8 flash_read8(void *addr)
  176. {
  177. u16 val = __raw_readw((void *)((u32)addr & ~1));
  178. if ((u32)addr & 1)
  179. return val;
  180. return val >> 8;
  181. }
  182. u32 flash_read32(void *addr)
  183. {
  184. return (__raw_readw(addr) << 16) | __raw_readw((void *)((u32)addr + 2));
  185. }
  186. void flash_cmd_reset(flash_info_t *info)
  187. {
  188. /*
  189. * FLASH at address CONFIG_SYS_FLASH_BASE is a Spansion chip and
  190. * needs the Spansion type reset commands. The other flash chip
  191. * is located behind a FPGA (Xilinx DS617) and needs the Intel type
  192. * reset command.
  193. */
  194. if (info->start[0] == CONFIG_SYS_FLASH_BASE)
  195. flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
  196. else
  197. flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
  198. }