p2020come.c 5.6 KB

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