p2020come.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * Copyright 2009 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <hwconfig.h>
  24. #include <command.h>
  25. #include <asm/processor.h>
  26. #include <asm/mmu.h>
  27. #include <asm/cache.h>
  28. #include <asm/immap_85xx.h>
  29. #include <asm/mpc85xx_gpio.h>
  30. #include <asm/fsl_serdes.h>
  31. #include <asm/io.h>
  32. #include <miiphy.h>
  33. #include <libfdt.h>
  34. #include <fdt_support.h>
  35. #include <fsl_mdio.h>
  36. #include <tsec.h>
  37. #include <vsc7385.h>
  38. #include <netdev.h>
  39. #include <mmc.h>
  40. #include <malloc.h>
  41. #include <i2c.h>
  42. #if defined(CONFIG_PCI)
  43. #include <asm/fsl_pci.h>
  44. #include <pci.h>
  45. #endif
  46. DECLARE_GLOBAL_DATA_PTR;
  47. #if defined(CONFIG_PCI)
  48. void pci_init_board(void)
  49. {
  50. fsl_pcie_init_board(0);
  51. }
  52. void ft_pci_board_setup(void *blob)
  53. {
  54. FT_FSL_PCI_SETUP;
  55. }
  56. #endif
  57. #define BOARD_PERI_RST_SET (VSC7385_RST_SET | SLIC_RST_SET | \
  58. SGMII_PHY_RST_SET | PCIE_RST_SET | \
  59. RGMII_PHY_RST_SET)
  60. #define SYSCLK_MASK 0x00200000
  61. #define BOARDREV_MASK 0x10100000
  62. #define BOARDREV_B 0x10100000
  63. #define BOARDREV_C 0x00100000
  64. #define BOARDREV_D 0x00000000
  65. #define SYSCLK_66 66666666
  66. #define SYSCLK_50 50000000
  67. #define SYSCLK_100 100000000
  68. unsigned long get_board_sys_clk(ulong dummy)
  69. {
  70. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  71. u32 ddr_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO;
  72. ddr_ratio >>= MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
  73. switch (ddr_ratio) {
  74. case 0x0C:
  75. return SYSCLK_66;
  76. case 0x0A:
  77. case 0x08:
  78. return SYSCLK_100;
  79. default:
  80. puts("ERROR: unknown DDR ratio\n");
  81. return SYSCLK_100;
  82. }
  83. }
  84. unsigned long get_board_ddr_clk(ulong dummy)
  85. {
  86. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  87. u32 ddr_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO;
  88. ddr_ratio >>= MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
  89. switch (ddr_ratio) {
  90. case 0x0C:
  91. case 0x0A:
  92. return SYSCLK_66;
  93. case 0x08:
  94. return SYSCLK_100;
  95. default:
  96. puts("ERROR: unknown DDR ratio\n");
  97. return SYSCLK_100;
  98. }
  99. }
  100. #ifdef CONFIG_MMC
  101. int board_early_init_f(void)
  102. {
  103. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  104. setbits_be32(&gur->pmuxcr,
  105. (MPC85xx_PMUXCR_SDHC_CD |
  106. MPC85xx_PMUXCR_SDHC_WP));
  107. /* All the device are enable except for SRIO12 */
  108. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_SRIO);
  109. return 0;
  110. }
  111. #endif
  112. #define GPIO_DIR 0x0f3a0000
  113. #define GPIO_ODR 0x00000000
  114. #define GPIO_DAT 0x001a0000
  115. int checkboard(void)
  116. {
  117. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR + 0xC00);
  118. /*
  119. * GPIO
  120. * 0 - 3: CarryBoard Input;
  121. * 4 - 7: CarryBoard Output;
  122. * 8 : Mux as SDHC_CD (card detection)
  123. * 9 : Mux as SDHC_WP
  124. * 10 : Clear Watchdog timer
  125. * 11 : LED Input
  126. * 12 : Output to 1
  127. * 13 : Open Drain
  128. * 14 : LED Output
  129. * 15 : Switch Input
  130. *
  131. * Set GPIOs 11, 12, 14 to 1.
  132. */
  133. out_be32(&pgpio->gpodr, GPIO_ODR);
  134. mpc85xx_gpio_set(0xffffffff, GPIO_DIR, GPIO_DAT);
  135. puts("Board: Freescale COM Express P2020\n");
  136. return 0;
  137. }
  138. #define M41ST85W_I2C_BUS 1
  139. #define M41ST85W_I2C_ADDR 0x68
  140. #define M41ST85W_ERROR(fmt, args...) printf("ERROR: M41ST85W: " fmt, ##args)
  141. static void m41st85w_clear_bit(u8 reg, u8 mask, const char *name)
  142. {
  143. u8 data;
  144. if (i2c_read(M41ST85W_I2C_ADDR, reg, 1, &data, 1)) {
  145. M41ST85W_ERROR("unable to read %s bit\n", name);
  146. return;
  147. }
  148. if (data & mask) {
  149. data &= ~mask;
  150. if (i2c_write(M41ST85W_I2C_ADDR, reg, 1, &data, 1)) {
  151. M41ST85W_ERROR("unable to clear %s bit\n", name);
  152. return;
  153. }
  154. }
  155. }
  156. #define M41ST85W_REG_SEC2 0x01
  157. #define M41ST85W_REG_SEC2_ST 0x80
  158. #define M41ST85W_REG_ALHOUR 0x0c
  159. #define M41ST85W_REG_ALHOUR_HT 0x40
  160. /*
  161. * The P2020COME board has a STMicro M41ST85W RTC/watchdog
  162. * at i2c bus 1 address 0x68.
  163. */
  164. static void start_rtc(void)
  165. {
  166. unsigned int bus = i2c_get_bus_num();
  167. if (i2c_set_bus_num(M41ST85W_I2C_BUS)) {
  168. M41ST85W_ERROR("unable to set i2c bus\n");
  169. goto out;
  170. }
  171. /* ensure ST (stop) and HT (halt update) bits are cleared */
  172. m41st85w_clear_bit(M41ST85W_REG_SEC2, M41ST85W_REG_SEC2_ST, "ST");
  173. m41st85w_clear_bit(M41ST85W_REG_ALHOUR, M41ST85W_REG_ALHOUR_HT, "HT");
  174. out:
  175. /* reset the i2c bus */
  176. i2c_set_bus_num(bus);
  177. }
  178. int board_early_init_r(void)
  179. {
  180. start_rtc();
  181. return 0;
  182. }
  183. #define M41ST85W_REG_WATCHDOG 0x09
  184. #define M41ST85W_REG_WATCHDOG_WDS 0x80
  185. #define M41ST85W_REG_WATCHDOG_BMB0 0x04
  186. void board_reset(void)
  187. {
  188. u8 data = M41ST85W_REG_WATCHDOG_WDS | M41ST85W_REG_WATCHDOG_BMB0;
  189. /* set the hardware watchdog timeout to 1/16 second, then hang */
  190. i2c_set_bus_num(M41ST85W_I2C_BUS);
  191. i2c_write(M41ST85W_I2C_ADDR, M41ST85W_REG_WATCHDOG, 1, &data, 1);
  192. while (1)
  193. /* hang */;
  194. }
  195. #ifdef CONFIG_TSEC_ENET
  196. int board_eth_init(bd_t *bis)
  197. {
  198. struct fsl_pq_mdio_info mdio_info;
  199. struct tsec_info_struct tsec_info[4];
  200. int num = 0;
  201. #ifdef CONFIG_TSEC1
  202. SET_STD_TSEC_INFO(tsec_info[num], 1);
  203. num++;
  204. #endif
  205. #ifdef CONFIG_TSEC2
  206. SET_STD_TSEC_INFO(tsec_info[num], 2);
  207. num++;
  208. #endif
  209. #ifdef CONFIG_TSEC3
  210. SET_STD_TSEC_INFO(tsec_info[num], 3);
  211. if (is_serdes_configured(SGMII_TSEC3)) {
  212. puts("eTSEC3 is in sgmii mode.");
  213. tsec_info[num].flags |= TSEC_SGMII;
  214. }
  215. num++;
  216. #endif
  217. if (!num) {
  218. printf("No TSECs initialized\n");
  219. return 0;
  220. }
  221. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  222. mdio_info.name = DEFAULT_MII_NAME;
  223. fsl_pq_mdio_init(bis, &mdio_info);
  224. tsec_eth_init(bis, tsec_info, num);
  225. return pci_eth_init(bis);
  226. }
  227. #endif
  228. #if defined(CONFIG_OF_BOARD_SETUP)
  229. void ft_board_setup(void *blob, bd_t *bd)
  230. {
  231. phys_addr_t base;
  232. phys_size_t size;
  233. ft_cpu_setup(blob, bd);
  234. base = getenv_bootm_low();
  235. size = getenv_bootm_size();
  236. #if defined(CONFIG_PCI)
  237. ft_pci_board_setup(blob);
  238. #endif
  239. fdt_fixup_memory(blob, (u64)base, (u64)size);
  240. fdt_fixup_dr_usb(blob, bd);
  241. }
  242. #endif