kmp204x.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2013 Keymile AG
  4. * Valentin Longchamp <valentin.longchamp@keymile.com>
  5. *
  6. * Copyright 2011,2012 Freescale Semiconductor, Inc.
  7. */
  8. #include <common.h>
  9. #include <command.h>
  10. #include <netdev.h>
  11. #include <linux/compiler.h>
  12. #include <asm/mmu.h>
  13. #include <asm/processor.h>
  14. #include <asm/cache.h>
  15. #include <asm/immap_85xx.h>
  16. #include <asm/fsl_law.h>
  17. #include <asm/fsl_serdes.h>
  18. #include <asm/fsl_portals.h>
  19. #include <asm/fsl_liodn.h>
  20. #include <fm_eth.h>
  21. #include "../common/common.h"
  22. #include "kmp204x.h"
  23. static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
  24. int checkboard(void)
  25. {
  26. printf("Board: Keymile %s\n", CONFIG_KM_BOARD_NAME);
  27. return 0;
  28. }
  29. /* I2C deblocking uses the algorithm defined in board/keymile/common/common.c
  30. * 2 dedicated QRIO GPIOs externally pull the SCL and SDA lines
  31. * For I2C only the low state is activly driven and high state is pulled-up
  32. * by a resistor. Therefore the deblock GPIOs are used
  33. * -> as an active output to drive a low state
  34. * -> as an open-drain input to have a pulled-up high state
  35. */
  36. /* QRIO GPIOs used for deblocking */
  37. #define DEBLOCK_PORT1 GPIO_A
  38. #define DEBLOCK_SCL1 20
  39. #define DEBLOCK_SDA1 21
  40. /* By default deblock GPIOs are floating */
  41. static void i2c_deblock_gpio_cfg(void)
  42. {
  43. /* set I2C bus 1 deblocking GPIOs input, but 0 value for open drain */
  44. qrio_gpio_direction_input(DEBLOCK_PORT1, DEBLOCK_SCL1);
  45. qrio_gpio_direction_input(DEBLOCK_PORT1, DEBLOCK_SDA1);
  46. qrio_set_gpio(DEBLOCK_PORT1, DEBLOCK_SCL1, 0);
  47. qrio_set_gpio(DEBLOCK_PORT1, DEBLOCK_SDA1, 0);
  48. }
  49. void set_sda(int state)
  50. {
  51. qrio_set_opendrain_gpio(DEBLOCK_PORT1, DEBLOCK_SDA1, state);
  52. }
  53. void set_scl(int state)
  54. {
  55. qrio_set_opendrain_gpio(DEBLOCK_PORT1, DEBLOCK_SCL1, state);
  56. }
  57. int get_sda(void)
  58. {
  59. return qrio_get_gpio(DEBLOCK_PORT1, DEBLOCK_SDA1);
  60. }
  61. int get_scl(void)
  62. {
  63. return qrio_get_gpio(DEBLOCK_PORT1, DEBLOCK_SCL1);
  64. }
  65. #define ZL30158_RST 8
  66. #define BFTIC4_RST 0
  67. #define RSTRQSR1_WDT_RR 0x00200000
  68. #define RSTRQSR1_SW_RR 0x00100000
  69. int board_early_init_f(void)
  70. {
  71. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  72. bool cpuwd_flag = false;
  73. /* configure mode for uP reset request */
  74. qrio_uprstreq(UPREQ_CORE_RST);
  75. /* board only uses the DDR_MCK0, so disable the DDR_MCK1/2/3 */
  76. setbits_be32(&gur->ddrclkdr, 0x001f000f);
  77. /* set reset reason according CPU register */
  78. if ((gur->rstrqsr1 & (RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR)) ==
  79. RSTRQSR1_WDT_RR)
  80. cpuwd_flag = true;
  81. qrio_cpuwd_flag(cpuwd_flag);
  82. /* clear CPU bits by writing 1 */
  83. setbits_be32(&gur->rstrqsr1, RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR);
  84. /* set the BFTIC's prstcfg to reset at power-up and unit reset only */
  85. qrio_prstcfg(BFTIC4_RST, PRSTCFG_POWUP_UNIT_RST);
  86. /* and enable WD on it */
  87. qrio_wdmask(BFTIC4_RST, true);
  88. /* set the ZL30138's prstcfg to reset at power-up only */
  89. qrio_prstcfg(ZL30158_RST, PRSTCFG_POWUP_RST);
  90. /* and take it out of reset as soon as possible (needed for Hooper) */
  91. qrio_prst(ZL30158_RST, false, false);
  92. return 0;
  93. }
  94. int board_early_init_r(void)
  95. {
  96. int ret = 0;
  97. /* Flush d-cache and invalidate i-cache of any FLASH data */
  98. flush_dcache();
  99. invalidate_icache();
  100. set_liodns();
  101. setup_qbman_portals();
  102. ret = trigger_fpga_config();
  103. if (ret)
  104. printf("error triggering PCIe FPGA config\n");
  105. /* enable the Unit LED (red) & Boot LED (on) */
  106. qrio_set_leds();
  107. /* enable Application Buffer */
  108. qrio_enable_app_buffer();
  109. return ret;
  110. }
  111. unsigned long get_board_sys_clk(unsigned long dummy)
  112. {
  113. return 66666666;
  114. }
  115. #define ETH_FRONT_PHY_RST 15
  116. #define QSFP2_RST 11
  117. #define QSFP1_RST 10
  118. #define ZL30343_RST 9
  119. int misc_init_f(void)
  120. {
  121. /* configure QRIO pis for i2c deblocking */
  122. i2c_deblock_gpio_cfg();
  123. /* configure the front phy's prstcfg and take it out of reset */
  124. qrio_prstcfg(ETH_FRONT_PHY_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
  125. qrio_prst(ETH_FRONT_PHY_RST, false, false);
  126. /* set the ZL30343 prstcfg to reset at power-up only */
  127. qrio_prstcfg(ZL30343_RST, PRSTCFG_POWUP_RST);
  128. /* and enable the WD on it */
  129. qrio_wdmask(ZL30343_RST, true);
  130. /* set the QSFPs' prstcfg to reset at power-up and unit rst only */
  131. qrio_prstcfg(QSFP1_RST, PRSTCFG_POWUP_UNIT_RST);
  132. qrio_prstcfg(QSFP2_RST, PRSTCFG_POWUP_UNIT_RST);
  133. /* and enable the WD on them */
  134. qrio_wdmask(QSFP1_RST, true);
  135. qrio_wdmask(QSFP2_RST, true);
  136. return 0;
  137. }
  138. #define NUM_SRDS_BANKS 2
  139. int misc_init_r(void)
  140. {
  141. serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  142. u32 expected[NUM_SRDS_BANKS] = {SRDS_PLLCR0_RFCK_SEL_100,
  143. SRDS_PLLCR0_RFCK_SEL_125};
  144. unsigned int i;
  145. /* check SERDES reference clocks */
  146. for (i = 0; i < NUM_SRDS_BANKS; i++) {
  147. u32 actual = in_be32(&regs->bank[i].pllcr0);
  148. actual &= SRDS_PLLCR0_RFCK_SEL_MASK;
  149. if (actual != expected[i]) {
  150. printf("Warning: SERDES bank %u expects reference \
  151. clock %sMHz, but actual is %sMHz\n", i + 1,
  152. serdes_clock_to_string(expected[i]),
  153. serdes_clock_to_string(actual));
  154. }
  155. }
  156. ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
  157. return 0;
  158. }
  159. #if defined(CONFIG_HUSH_INIT_VAR)
  160. int hush_init_var(void)
  161. {
  162. ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
  163. return 0;
  164. }
  165. #endif
  166. #if defined(CONFIG_LAST_STAGE_INIT)
  167. int last_stage_init(void)
  168. {
  169. #if defined(CONFIG_KMCOGE4)
  170. /* on KMCOGE4, the BFTIC4 is on the LBAPP2 */
  171. struct bfticu_iomap *bftic4 =
  172. (struct bfticu_iomap *)CONFIG_SYS_LBAPP2_BASE;
  173. u8 dip_switch = in_8((u8 *)&(bftic4->mswitch)) & BFTICU_DIPSWITCH_MASK;
  174. if (dip_switch != 0) {
  175. /* start bootloader */
  176. puts("DIP: Enabled\n");
  177. env_set("actual_bank", "0");
  178. }
  179. #endif
  180. set_km_env();
  181. return 0;
  182. }
  183. #endif
  184. #ifdef CONFIG_SYS_DPAA_FMAN
  185. void fdt_fixup_fman_mac_addresses(void *blob)
  186. {
  187. int node, i, ret;
  188. char *tmp, *end;
  189. unsigned char mac_addr[6];
  190. /* get the mac addr from env */
  191. tmp = env_get("ethaddr");
  192. if (!tmp) {
  193. printf("ethaddr env variable not defined\n");
  194. return;
  195. }
  196. for (i = 0; i < 6; i++) {
  197. mac_addr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
  198. if (tmp)
  199. tmp = (*end) ? end+1 : end;
  200. }
  201. /* find the correct fdt ethernet path and correct it */
  202. node = fdt_path_offset(blob, "/soc/fman/ethernet@e8000");
  203. if (node < 0) {
  204. printf("no /soc/fman/ethernet path offset\n");
  205. return;
  206. }
  207. ret = fdt_setprop(blob, node, "local-mac-address", &mac_addr, 6);
  208. if (ret) {
  209. printf("error setting local-mac-address property\n");
  210. return;
  211. }
  212. }
  213. #endif
  214. int ft_board_setup(void *blob, bd_t *bd)
  215. {
  216. phys_addr_t base;
  217. phys_size_t size;
  218. ft_cpu_setup(blob, bd);
  219. base = env_get_bootm_low();
  220. size = env_get_bootm_size();
  221. fdt_fixup_memory(blob, (u64)base, (u64)size);
  222. #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
  223. fsl_fdt_fixup_dr_usb(blob, bd);
  224. #endif
  225. #ifdef CONFIG_PCI
  226. pci_of_setup(blob, bd);
  227. #endif
  228. fdt_fixup_liodn(blob);
  229. #ifdef CONFIG_SYS_DPAA_FMAN
  230. fdt_fixup_fman_ethernet(blob);
  231. fdt_fixup_fman_mac_addresses(blob);
  232. #endif
  233. return 0;
  234. }
  235. #if defined(CONFIG_POST)
  236. /* DIC26_SELFTEST GPIO used to start factory test sw */
  237. #define SELFTEST_PORT GPIO_A
  238. #define SELFTEST_PIN 31
  239. int post_hotkeys_pressed(void)
  240. {
  241. qrio_gpio_direction_input(SELFTEST_PORT, SELFTEST_PIN);
  242. return qrio_get_gpio(SELFTEST_PORT, SELFTEST_PIN);
  243. }
  244. #endif