comphy_a3700.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. /*
  2. * Copyright (C) 2015-2016 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <fdtdec.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/cpu.h>
  10. #include <asm/arch/soc.h>
  11. #include "comphy_a3700.h"
  12. DECLARE_GLOBAL_DATA_PTR;
  13. struct sgmii_phy_init_data_fix {
  14. u16 addr;
  15. u16 value;
  16. };
  17. /* Changes to 40M1G25 mode data required for running 40M3G125 init mode */
  18. static struct sgmii_phy_init_data_fix sgmii_phy_init_fix[] = {
  19. {0x005, 0x07CC}, {0x015, 0x0000}, {0x01B, 0x0000}, {0x01D, 0x0000},
  20. {0x01E, 0x0000}, {0x01F, 0x0000}, {0x020, 0x0000}, {0x021, 0x0030},
  21. {0x026, 0x0888}, {0x04D, 0x0152}, {0x04F, 0xA020}, {0x050, 0x07CC},
  22. {0x053, 0xE9CA}, {0x055, 0xBD97}, {0x071, 0x3015}, {0x076, 0x03AA},
  23. {0x07C, 0x0FDF}, {0x0C2, 0x3030}, {0x0C3, 0x8000}, {0x0E2, 0x5550},
  24. {0x0E3, 0x12A4}, {0x0E4, 0x7D00}, {0x0E6, 0x0C83}, {0x101, 0xFCC0},
  25. {0x104, 0x0C10}
  26. };
  27. /* 40M1G25 mode init data */
  28. static u16 sgmii_phy_init[512] = {
  29. /* 0 1 2 3 4 5 6 7 */
  30. /*-----------------------------------------------------------*/
  31. /* 8 9 A B C D E F */
  32. 0x3110, 0xFD83, 0x6430, 0x412F, 0x82C0, 0x06FA, 0x4500, 0x6D26, /* 00 */
  33. 0xAFC0, 0x8000, 0xC000, 0x0000, 0x2000, 0x49CC, 0x0BC9, 0x2A52, /* 08 */
  34. 0x0BD2, 0x0CDE, 0x13D2, 0x0CE8, 0x1149, 0x10E0, 0x0000, 0x0000, /* 10 */
  35. 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x4134, 0x0D2D, 0xFFFF, /* 18 */
  36. 0xFFE0, 0x4030, 0x1016, 0x0030, 0x0000, 0x0800, 0x0866, 0x0000, /* 20 */
  37. 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, /* 28 */
  38. 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 30 */
  39. 0x0000, 0x0000, 0x000F, 0x6A62, 0x1988, 0x3100, 0x3100, 0x3100, /* 38 */
  40. 0x3100, 0xA708, 0x2430, 0x0830, 0x1030, 0x4610, 0xFF00, 0xFF00, /* 40 */
  41. 0x0060, 0x1000, 0x0400, 0x0040, 0x00F0, 0x0155, 0x1100, 0xA02A, /* 48 */
  42. 0x06FA, 0x0080, 0xB008, 0xE3ED, 0x5002, 0xB592, 0x7A80, 0x0001, /* 50 */
  43. 0x020A, 0x8820, 0x6014, 0x8054, 0xACAA, 0xFC88, 0x2A02, 0x45CF, /* 58 */
  44. 0x000F, 0x1817, 0x2860, 0x064F, 0x0000, 0x0204, 0x1800, 0x6000, /* 60 */
  45. 0x810F, 0x4F23, 0x4000, 0x4498, 0x0850, 0x0000, 0x000E, 0x1002, /* 68 */
  46. 0x9D3A, 0x3009, 0xD066, 0x0491, 0x0001, 0x6AB0, 0x0399, 0x3780, /* 70 */
  47. 0x0040, 0x5AC0, 0x4A80, 0x0000, 0x01DF, 0x0000, 0x0007, 0x0000, /* 78 */
  48. 0x2D54, 0x00A1, 0x4000, 0x0100, 0xA20A, 0x0000, 0x0000, 0x0000, /* 80 */
  49. 0x0000, 0x0000, 0x0000, 0x7400, 0x0E81, 0x1000, 0x1242, 0x0210, /* 88 */
  50. 0x80DF, 0x0F1F, 0x2F3F, 0x4F5F, 0x6F7F, 0x0F1F, 0x2F3F, 0x4F5F, /* 90 */
  51. 0x6F7F, 0x4BAD, 0x0000, 0x0000, 0x0800, 0x0000, 0x2400, 0xB651, /* 98 */
  52. 0xC9E0, 0x4247, 0x0A24, 0x0000, 0xAF19, 0x1004, 0x0000, 0x0000, /* A0 */
  53. 0x0000, 0x0013, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* A8 */
  54. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* B0 */
  55. 0x0000, 0x0000, 0x0000, 0x0060, 0x0000, 0x0000, 0x0000, 0x0000, /* B8 */
  56. 0x0000, 0x0000, 0x3010, 0xFA00, 0x0000, 0x0000, 0x0000, 0x0003, /* C0 */
  57. 0x1618, 0x8200, 0x8000, 0x0400, 0x050F, 0x0000, 0x0000, 0x0000, /* C8 */
  58. 0x4C93, 0x0000, 0x1000, 0x1120, 0x0010, 0x1242, 0x1242, 0x1E00, /* D0 */
  59. 0x0000, 0x0000, 0x0000, 0x00F8, 0x0000, 0x0041, 0x0800, 0x0000, /* D8 */
  60. 0x82A0, 0x572E, 0x2490, 0x14A9, 0x4E00, 0x0000, 0x0803, 0x0541, /* E0 */
  61. 0x0C15, 0x0000, 0x0000, 0x0400, 0x2626, 0x0000, 0x0000, 0x4200, /* E8 */
  62. 0x0000, 0xAA55, 0x1020, 0x0000, 0x0000, 0x5010, 0x0000, 0x0000, /* F0 */
  63. 0x0000, 0x0000, 0x5000, 0x0000, 0x0000, 0x0000, 0x02F2, 0x0000, /* F8 */
  64. 0x101F, 0xFDC0, 0x4000, 0x8010, 0x0110, 0x0006, 0x0000, 0x0000, /*100 */
  65. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*108 */
  66. 0x04CF, 0x0000, 0x04CF, 0x0000, 0x04CF, 0x0000, 0x04C6, 0x0000, /*110 */
  67. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*118 */
  68. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*120 */
  69. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*128 */
  70. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*130 */
  71. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*138 */
  72. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*140 */
  73. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*148 */
  74. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*150 */
  75. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*158 */
  76. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*160 */
  77. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*168 */
  78. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*170 */
  79. 0x0000, 0x0000, 0x0000, 0x00F0, 0x08A2, 0x3112, 0x0A14, 0x0000, /*178 */
  80. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*180 */
  81. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*188 */
  82. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*190 */
  83. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*198 */
  84. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1A0 */
  85. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1A8 */
  86. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1B0 */
  87. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1B8 */
  88. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1C0 */
  89. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1C8 */
  90. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1D0 */
  91. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1D8 */
  92. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1E0 */
  93. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1E8 */
  94. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1F0 */
  95. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 /*1F8 */
  96. };
  97. /*
  98. * comphy_poll_reg
  99. *
  100. * return: 1 on success, 0 on timeout
  101. */
  102. static u32 comphy_poll_reg(void *addr, u32 val, u32 mask, u32 timeout,
  103. u8 op_type)
  104. {
  105. u32 rval = 0xDEAD;
  106. for (; timeout > 0; timeout--) {
  107. if (op_type == POLL_16B_REG)
  108. rval = readw(addr); /* 16 bit */
  109. else
  110. rval = readl(addr) ; /* 32 bit */
  111. if ((rval & mask) == val)
  112. return 1;
  113. udelay(10000);
  114. }
  115. debug("Time out waiting (%p = %#010x)\n", addr, rval);
  116. return 0;
  117. }
  118. /*
  119. * comphy_pcie_power_up
  120. *
  121. * return: 1 if PLL locked (OK), 0 otherwise (FAIL)
  122. */
  123. static int comphy_pcie_power_up(u32 speed, u32 invert)
  124. {
  125. int ret;
  126. debug_enter();
  127. /*
  128. * 1. Enable max PLL.
  129. */
  130. reg_set16((void __iomem *)LANE_CFG1_ADDR(PCIE),
  131. bf_use_max_pll_rate, 0);
  132. /*
  133. * 2. Select 20 bit SERDES interface.
  134. */
  135. reg_set16((void __iomem *)GLOB_CLK_SRC_LO_ADDR(PCIE),
  136. bf_cfg_sel_20b, 0);
  137. /*
  138. * 3. Force to use reg setting for PCIe mode
  139. */
  140. reg_set16((void __iomem *)MISC_REG1_ADDR(PCIE),
  141. bf_sel_bits_pcie_force, 0);
  142. /*
  143. * 4. Change RX wait
  144. */
  145. reg_set16((void __iomem *)PWR_MGM_TIM1_ADDR(PCIE), 0x10C, 0xFFFF);
  146. /*
  147. * 5. Enable idle sync
  148. */
  149. reg_set16((void __iomem *)UNIT_CTRL_ADDR(PCIE),
  150. 0x60 | rb_idle_sync_en, 0xFFFF);
  151. /*
  152. * 6. Enable the output of 100M/125M/500M clock
  153. */
  154. reg_set16((void __iomem *)MISC_REG0_ADDR(PCIE),
  155. 0xA00D | rb_clk500m_en | rb_clk100m_125m_en, 0xFFFF);
  156. /*
  157. * 7. Enable TX
  158. */
  159. reg_set((void __iomem *)PHY_REF_CLK_ADDR, 0x1342, 0xFFFFFFFF);
  160. /*
  161. * 8. Check crystal jumper setting and program the Power and PLL
  162. * Control accordingly
  163. */
  164. if (get_ref_clk() == 40) {
  165. reg_set16((void __iomem *)PWR_PLL_CTRL_ADDR(PCIE),
  166. 0xFC63, 0xFFFF); /* 40 MHz */
  167. } else {
  168. reg_set16((void __iomem *)PWR_PLL_CTRL_ADDR(PCIE),
  169. 0xFC62, 0xFFFF); /* 25 MHz */
  170. }
  171. /*
  172. * 9. Override Speed_PLL value and use MAC PLL
  173. */
  174. reg_set16((void __iomem *)KVCO_CAL_CTRL_ADDR(PCIE),
  175. 0x0040 | rb_use_max_pll_rate, 0xFFFF);
  176. /*
  177. * 10. Check the Polarity invert bit
  178. */
  179. if (invert & PHY_POLARITY_TXD_INVERT) {
  180. reg_set16((void __iomem *)SYNC_PATTERN_ADDR(PCIE),
  181. phy_txd_inv, 0);
  182. }
  183. if (invert & PHY_POLARITY_RXD_INVERT) {
  184. reg_set16((void __iomem *)SYNC_PATTERN_ADDR(PCIE),
  185. phy_rxd_inv, 0);
  186. }
  187. /*
  188. * 11. Release SW reset
  189. */
  190. reg_set16((void __iomem *)GLOB_PHY_CTRL0_ADDR(PCIE),
  191. rb_mode_core_clk_freq_sel | rb_mode_pipe_width_32,
  192. bf_soft_rst | bf_mode_refdiv);
  193. /* Wait for > 55 us to allow PCLK be enabled */
  194. udelay(PLL_SET_DELAY_US);
  195. /* Assert PCLK enabled */
  196. ret = comphy_poll_reg((void *)LANE_STAT1_ADDR(PCIE), /* address */
  197. rb_txdclk_pclk_en, /* value */
  198. rb_txdclk_pclk_en, /* mask */
  199. PLL_LOCK_TIMEOUT, /* timeout */
  200. POLL_16B_REG); /* 16bit */
  201. if (ret == 0)
  202. printf("Failed to lock PCIe PLL\n");
  203. debug_exit();
  204. /* Return the status of the PLL */
  205. return ret;
  206. }
  207. /*
  208. * comphy_sata_power_up
  209. *
  210. * return: 1 if PLL locked (OK), 0 otherwise (FAIL)
  211. */
  212. static int comphy_sata_power_up(void)
  213. {
  214. int ret;
  215. debug_enter();
  216. /*
  217. * 0. Swap SATA TX lines
  218. */
  219. reg_set((void __iomem *)rh_vsreg_addr,
  220. vphy_sync_pattern_reg, 0xFFFFFFFF);
  221. reg_set((void __iomem *)rh_vsreg_data, bs_txd_inv, bs_txd_inv);
  222. /*
  223. * 1. Select 40-bit data width width
  224. */
  225. reg_set((void __iomem *)rh_vsreg_addr, vphy_loopback_reg0, 0xFFFFFFFF);
  226. reg_set((void __iomem *)rh_vsreg_data, 0x800, bs_phyintf_40bit);
  227. /*
  228. * 2. Select reference clock and PHY mode (SATA)
  229. */
  230. reg_set((void __iomem *)rh_vsreg_addr, vphy_power_reg0, 0xFFFFFFFF);
  231. if (get_ref_clk() == 40) {
  232. reg_set((void __iomem *)rh_vsreg_data,
  233. 0x3, 0x00FF); /* 40 MHz */
  234. } else {
  235. reg_set((void __iomem *)rh_vsreg_data,
  236. 0x1, 0x00FF); /* 25 MHz */
  237. }
  238. /*
  239. * 3. Use maximum PLL rate (no power save)
  240. */
  241. reg_set((void __iomem *)rh_vsreg_addr, vphy_calctl_reg, 0xFFFFFFFF);
  242. reg_set((void __iomem *)rh_vsreg_data,
  243. bs_max_pll_rate, bs_max_pll_rate);
  244. /*
  245. * 4. Reset reserved bit (??)
  246. */
  247. reg_set((void __iomem *)rh_vsreg_addr, vphy_reserve_reg, 0xFFFFFFFF);
  248. reg_set((void __iomem *)rh_vsreg_data, 0, bs_phyctrl_frm_pin);
  249. /*
  250. * 5. Set vendor-specific configuration (??)
  251. */
  252. reg_set((void __iomem *)rh_vs0_a, vsata_ctrl_reg, 0xFFFFFFFF);
  253. reg_set((void __iomem *)rh_vs0_d, bs_phy_pu_pll, bs_phy_pu_pll);
  254. /* Wait for > 55 us to allow PLL be enabled */
  255. udelay(PLL_SET_DELAY_US);
  256. /* Assert SATA PLL enabled */
  257. reg_set((void __iomem *)rh_vsreg_addr, vphy_loopback_reg0, 0xFFFFFFFF);
  258. ret = comphy_poll_reg((void *)rh_vsreg_data, /* address */
  259. bs_pll_ready_tx, /* value */
  260. bs_pll_ready_tx, /* mask */
  261. PLL_LOCK_TIMEOUT, /* timeout */
  262. POLL_32B_REG); /* 32bit */
  263. if (ret == 0)
  264. printf("Failed to lock SATA PLL\n");
  265. debug_exit();
  266. return ret;
  267. }
  268. /*
  269. * comphy_usb3_power_up
  270. *
  271. * return: 1 if PLL locked (OK), 0 otherwise (FAIL)
  272. */
  273. static int comphy_usb3_power_up(u32 type, u32 speed, u32 invert)
  274. {
  275. int ret;
  276. debug_enter();
  277. /*
  278. * 1. Power up OTG module
  279. */
  280. reg_set((void __iomem *)USB2_PHY_OTG_CTRL_ADDR, rb_pu_otg, 0);
  281. /*
  282. * 2. Set counter for 100us pulse in USB3 Host and Device
  283. * restore default burst size limit (Reference Clock 31:24)
  284. */
  285. reg_set((void __iomem *)USB3_CTRPUL_VAL_REG,
  286. 0x8 << 24, rb_usb3_ctr_100ns);
  287. /* 0xd005c300 = 0x1001 */
  288. /* set PRD_TXDEEMPH (3.5db de-emph) */
  289. reg_set16((void __iomem *)LANE_CFG0_ADDR(USB3), 0x1, 0xFF);
  290. /*
  291. * unset BIT0: set Tx Electrical Idle Mode: Transmitter is in
  292. * low impedance mode during electrical idle
  293. */
  294. /* unset BIT4: set G2 Tx Datapath with no Delayed Latency */
  295. /* unset BIT6: set Tx Detect Rx Mode at LoZ mode */
  296. reg_set16((void __iomem *)LANE_CFG1_ADDR(USB3), 0x0, 0xFFFF);
  297. /* 0xd005c310 = 0x93: set Spread Spectrum Clock Enabled */
  298. reg_set16((void __iomem *)LANE_CFG4_ADDR(USB3),
  299. bf_spread_spectrum_clock_en, 0x80);
  300. /*
  301. * set Override Margining Controls From the MAC: Use margining signals
  302. * from lane configuration
  303. */
  304. reg_set16((void __iomem *)TEST_MODE_CTRL_ADDR(USB3),
  305. rb_mode_margin_override, 0xFFFF);
  306. /* set Lane-to-Lane Bundle Clock Sampling Period = per PCLK cycles */
  307. /* set Mode Clock Source = PCLK is generated from REFCLK */
  308. reg_set16((void __iomem *)GLOB_CLK_SRC_LO_ADDR(USB3), 0x0, 0xFF);
  309. /* set G2 Spread Spectrum Clock Amplitude at 4K */
  310. reg_set16((void __iomem *)GEN2_SETTING_2_ADDR(USB3), g2_tx_ssc_amp,
  311. 0xF000);
  312. /*
  313. * unset G3 Spread Spectrum Clock Amplitude & set G3 TX and RX Register
  314. * Master Current Select
  315. */
  316. reg_set16((void __iomem *)GEN2_SETTING_3_ADDR(USB3), 0x0, 0xFFFF);
  317. /*
  318. * 3. Check crystal jumper setting and program the Power and PLL
  319. * Control accordingly
  320. */
  321. if (get_ref_clk() == 40) {
  322. reg_set16((void __iomem *)PWR_PLL_CTRL_ADDR(USB3), 0xFCA3,
  323. 0xFFFF); /* 40 MHz */
  324. } else {
  325. reg_set16((void __iomem *)PWR_PLL_CTRL_ADDR(USB3), 0xFCA2,
  326. 0xFFFF); /* 25 MHz */
  327. }
  328. /*
  329. * 4. Change RX wait
  330. */
  331. reg_set16((void __iomem *)PWR_MGM_TIM1_ADDR(USB3), 0x10C, 0xFFFF);
  332. /*
  333. * 5. Enable idle sync
  334. */
  335. reg_set16((void __iomem *)UNIT_CTRL_ADDR(USB3), 0x60 | rb_idle_sync_en,
  336. 0xFFFF);
  337. /*
  338. * 6. Enable the output of 500M clock
  339. */
  340. reg_set16((void __iomem *)MISC_REG0_ADDR(USB3), 0xA00D | rb_clk500m_en,
  341. 0xFFFF);
  342. /*
  343. * 7. Set 20-bit data width
  344. */
  345. reg_set16((void __iomem *)DIG_LB_EN_ADDR(USB3), 0x0400, 0xFFFF);
  346. /*
  347. * 8. Override Speed_PLL value and use MAC PLL
  348. */
  349. reg_set16((void __iomem *)KVCO_CAL_CTRL_ADDR(USB3),
  350. 0x0040 | rb_use_max_pll_rate, 0xFFFF);
  351. /*
  352. * 9. Check the Polarity invert bit
  353. */
  354. if (invert & PHY_POLARITY_TXD_INVERT) {
  355. reg_set16((void __iomem *)SYNC_PATTERN_ADDR(USB3),
  356. phy_txd_inv, 0);
  357. }
  358. if (invert & PHY_POLARITY_RXD_INVERT) {
  359. reg_set16((void __iomem *)SYNC_PATTERN_ADDR(USB3),
  360. phy_rxd_inv, 0);
  361. }
  362. /*
  363. * 10. Release SW reset
  364. */
  365. reg_set16((void __iomem *)GLOB_PHY_CTRL0_ADDR(USB3),
  366. rb_mode_core_clk_freq_sel | rb_mode_pipe_width_32 | 0x20,
  367. 0xFFFF);
  368. /* Wait for > 55 us to allow PCLK be enabled */
  369. udelay(PLL_SET_DELAY_US);
  370. /* Assert PCLK enabled */
  371. ret = comphy_poll_reg((void *)LANE_STAT1_ADDR(USB3), /* address */
  372. rb_txdclk_pclk_en, /* value */
  373. rb_txdclk_pclk_en, /* mask */
  374. PLL_LOCK_TIMEOUT, /* timeout */
  375. POLL_16B_REG); /* 16bit */
  376. if (ret == 0)
  377. printf("Failed to lock USB3 PLL\n");
  378. /*
  379. * Set Soft ID for Host mode (Device mode works with Hard ID
  380. * detection)
  381. */
  382. if (type == PHY_TYPE_USB3_HOST0) {
  383. /*
  384. * set BIT0: set ID_MODE of Host/Device = "Soft ID" (BIT1)
  385. * clear BIT1: set SOFT_ID = Host
  386. * set BIT4: set INT_MODE = ID. Interrupt Mode: enable
  387. * interrupt by ID instead of using both interrupts
  388. * of HOST and Device ORed simultaneously
  389. * INT_MODE=ID in order to avoid unexpected
  390. * behaviour or both interrupts together
  391. */
  392. reg_set((void __iomem *)USB32_CTRL_BASE,
  393. usb32_ctrl_id_mode | usb32_ctrl_int_mode,
  394. usb32_ctrl_id_mode | usb32_ctrl_soft_id |
  395. usb32_ctrl_int_mode);
  396. }
  397. debug_exit();
  398. return ret;
  399. }
  400. /*
  401. * comphy_usb2_power_up
  402. *
  403. * return: 1 if PLL locked (OK), 0 otherwise (FAIL)
  404. */
  405. static int comphy_usb2_power_up(u8 usb32)
  406. {
  407. int ret;
  408. debug_enter();
  409. if (usb32 != 0 && usb32 != 1) {
  410. printf("invalid usb32 value: (%d), should be either 0 or 1\n",
  411. usb32);
  412. debug_exit();
  413. return 0;
  414. }
  415. /*
  416. * 0. Setup PLL. 40MHz clock uses defaults.
  417. * See "PLL Settings for Typical REFCLK" table
  418. */
  419. if (get_ref_clk() == 25) {
  420. reg_set((void __iomem *)USB2_PHY_BASE(usb32),
  421. 5 | (96 << 16), 0x3F | (0xFF << 16) | (0x3 << 28));
  422. }
  423. /*
  424. * 1. PHY pull up and disable USB2 suspend
  425. */
  426. reg_set((void __iomem *)USB2_PHY_CTRL_ADDR(usb32),
  427. RB_USB2PHY_SUSPM(usb32) | RB_USB2PHY_PU(usb32), 0);
  428. if (usb32 != 0) {
  429. /*
  430. * 2. Power up OTG module
  431. */
  432. reg_set((void __iomem *)USB2_PHY_OTG_CTRL_ADDR, rb_pu_otg, 0);
  433. /*
  434. * 3. Configure PHY charger detection
  435. */
  436. reg_set((void __iomem *)USB2_PHY_CHRGR_DET_ADDR, 0,
  437. rb_cdp_en | rb_dcp_en | rb_pd_en | rb_cdp_dm_auto |
  438. rb_enswitch_dp | rb_enswitch_dm | rb_pu_chrg_dtc);
  439. }
  440. /* Assert PLL calibration done */
  441. ret = comphy_poll_reg((void *)USB2_PHY_CAL_CTRL_ADDR(usb32),
  442. rb_usb2phy_pllcal_done, /* value */
  443. rb_usb2phy_pllcal_done, /* mask */
  444. PLL_LOCK_TIMEOUT, /* timeout */
  445. POLL_32B_REG); /* 32bit */
  446. if (ret == 0)
  447. printf("Failed to end USB2 PLL calibration\n");
  448. /* Assert impedance calibration done */
  449. ret = comphy_poll_reg((void *)USB2_PHY_CAL_CTRL_ADDR(usb32),
  450. rb_usb2phy_impcal_done, /* value */
  451. rb_usb2phy_impcal_done, /* mask */
  452. PLL_LOCK_TIMEOUT, /* timeout */
  453. POLL_32B_REG); /* 32bit */
  454. if (ret == 0)
  455. printf("Failed to end USB2 impedance calibration\n");
  456. /* Assert squetch calibration done */
  457. ret = comphy_poll_reg((void *)USB2_PHY_RX_CHAN_CTRL1_ADDR(usb32),
  458. rb_usb2phy_sqcal_done, /* value */
  459. rb_usb2phy_sqcal_done, /* mask */
  460. PLL_LOCK_TIMEOUT, /* timeout */
  461. POLL_32B_REG); /* 32bit */
  462. if (ret == 0)
  463. printf("Failed to end USB2 unknown calibration\n");
  464. /* Assert PLL is ready */
  465. ret = comphy_poll_reg((void *)USB2_PHY_PLL_CTRL0_ADDR(usb32),
  466. rb_usb2phy_pll_ready, /* value */
  467. rb_usb2phy_pll_ready, /* mask */
  468. PLL_LOCK_TIMEOUT, /* timeout */
  469. POLL_32B_REG); /* 32bit */
  470. if (ret == 0)
  471. printf("Failed to lock USB2 PLL\n");
  472. debug_exit();
  473. return ret;
  474. }
  475. /*
  476. * comphy_emmc_power_up
  477. *
  478. * return: 1 if PLL locked (OK), 0 otherwise (FAIL)
  479. */
  480. static int comphy_emmc_power_up(void)
  481. {
  482. debug_enter();
  483. /*
  484. * 1. Bus power ON, Bus voltage 1.8V
  485. */
  486. reg_set((void __iomem *)SDIO_HOST_CTRL1_ADDR, 0xB00, 0xF00);
  487. /*
  488. * 2. Set FIFO parameters
  489. */
  490. reg_set((void __iomem *)SDIO_SDHC_FIFO_ADDR, 0x315, 0xFFFFFFFF);
  491. /*
  492. * 3. Set Capabilities 1_2
  493. */
  494. reg_set((void __iomem *)SDIO_CAP_12_ADDR, 0x25FAC8B2, 0xFFFFFFFF);
  495. /*
  496. * 4. Set Endian
  497. */
  498. reg_set((void __iomem *)SDIO_ENDIAN_ADDR, 0x00c00000, 0);
  499. /*
  500. * 4. Init PHY
  501. */
  502. reg_set((void __iomem *)SDIO_PHY_TIMING_ADDR, 0x80000000, 0x80000000);
  503. reg_set((void __iomem *)SDIO_PHY_PAD_CTRL0_ADDR, 0x50000000,
  504. 0xF0000000);
  505. /*
  506. * 5. DLL reset
  507. */
  508. reg_set((void __iomem *)SDIO_DLL_RST_ADDR, 0xFFFEFFFF, 0);
  509. reg_set((void __iomem *)SDIO_DLL_RST_ADDR, 0x00010000, 0);
  510. debug_exit();
  511. return 1;
  512. }
  513. /*
  514. * comphy_sgmii_power_up
  515. *
  516. * return:
  517. */
  518. static void comphy_sgmii_phy_init(u32 lane, u32 speed)
  519. {
  520. const int fix_arr_sz = ARRAY_SIZE(sgmii_phy_init_fix);
  521. int addr, fix_idx;
  522. u16 val;
  523. fix_idx = 0;
  524. for (addr = 0; addr < 512; addr++) {
  525. /*
  526. * All PHY register values are defined in full for 3.125Gbps
  527. * SERDES speed. The values required for 1.25 Gbps are almost
  528. * the same and only few registers should be "fixed" in
  529. * comparison to 3.125 Gbps values. These register values are
  530. * stored in "sgmii_phy_init_fix" array.
  531. */
  532. if ((speed != PHY_SPEED_1_25G) &&
  533. (sgmii_phy_init_fix[fix_idx].addr == addr)) {
  534. /* Use new value */
  535. val = sgmii_phy_init_fix[fix_idx].value;
  536. if (fix_idx < fix_arr_sz)
  537. fix_idx++;
  538. } else {
  539. val = sgmii_phy_init[addr];
  540. }
  541. phy_write16(lane, addr, val, 0xFFFF);
  542. }
  543. }
  544. /*
  545. * comphy_sgmii_power_up
  546. *
  547. * return: 1 if PLL locked (OK), 0 otherwise (FAIL)
  548. */
  549. static int comphy_sgmii_power_up(u32 lane, u32 speed, u32 invert)
  550. {
  551. int ret;
  552. debug_enter();
  553. /*
  554. * 1. Configure PHY to SATA/SAS mode by setting pin PIN_PIPE_SEL=0
  555. */
  556. reg_set((void __iomem *)COMPHY_SEL_ADDR, 0, rf_compy_select(lane));
  557. /*
  558. * 2. Reset PHY by setting PHY input port PIN_RESET=1.
  559. * 3. Set PHY input port PIN_TX_IDLE=1, PIN_PU_IVREF=1 to keep
  560. * PHY TXP/TXN output to idle state during PHY initialization
  561. * 4. Set PHY input port PIN_PU_PLL=0, PIN_PU_RX=0, PIN_PU_TX=0.
  562. */
  563. reg_set((void __iomem *)COMPHY_PHY_CFG1_ADDR(lane),
  564. rb_pin_reset_comphy | rb_pin_tx_idle | rb_pin_pu_iveref,
  565. rb_pin_reset_core | rb_pin_pu_pll |
  566. rb_pin_pu_rx | rb_pin_pu_tx);
  567. /*
  568. * 5. Release reset to the PHY by setting PIN_RESET=0.
  569. */
  570. reg_set((void __iomem *)COMPHY_PHY_CFG1_ADDR(lane),
  571. 0, rb_pin_reset_comphy);
  572. /*
  573. * 7. Set PIN_PHY_GEN_TX[3:0] and PIN_PHY_GEN_RX[3:0] to decide
  574. * COMPHY bit rate
  575. */
  576. if (speed == PHY_SPEED_3_125G) { /* 3.125 GHz */
  577. reg_set((void __iomem *)COMPHY_PHY_CFG1_ADDR(lane),
  578. (0x8 << rf_gen_rx_sel_shift) |
  579. (0x8 << rf_gen_tx_sel_shift),
  580. rf_gen_rx_select | rf_gen_tx_select);
  581. } else if (speed == PHY_SPEED_1_25G) { /* 1.25 GHz */
  582. reg_set((void __iomem *)COMPHY_PHY_CFG1_ADDR(lane),
  583. (0x6 << rf_gen_rx_sel_shift) |
  584. (0x6 << rf_gen_tx_sel_shift),
  585. rf_gen_rx_select | rf_gen_tx_select);
  586. } else {
  587. printf("Unsupported COMPHY speed!\n");
  588. return 0;
  589. }
  590. /*
  591. * 8. Wait 1mS for bandgap and reference clocks to stabilize;
  592. * then start SW programming.
  593. */
  594. mdelay(10);
  595. /* 9. Program COMPHY register PHY_MODE */
  596. phy_write16(lane, PHY_PWR_PLL_CTRL_ADDR,
  597. PHY_MODE_SGMII << rf_phy_mode_shift, rf_phy_mode_mask);
  598. /*
  599. * 10. Set COMPHY register REFCLK_SEL to select the correct REFCLK
  600. * source
  601. */
  602. phy_write16(lane, PHY_MISC_REG0_ADDR, 0, rb_ref_clk_sel);
  603. /*
  604. * 11. Set correct reference clock frequency in COMPHY register
  605. * REF_FREF_SEL.
  606. */
  607. if (get_ref_clk() == 40) {
  608. phy_write16(lane, PHY_PWR_PLL_CTRL_ADDR,
  609. 0x4 << rf_ref_freq_sel_shift, rf_ref_freq_sel_mask);
  610. } else {
  611. /* 25MHz */
  612. phy_write16(lane, PHY_PWR_PLL_CTRL_ADDR,
  613. 0x1 << rf_ref_freq_sel_shift, rf_ref_freq_sel_mask);
  614. }
  615. /* 12. Program COMPHY register PHY_GEN_MAX[1:0] */
  616. /*
  617. * This step is mentioned in the flow received from verification team.
  618. * However the PHY_GEN_MAX value is only meaningful for other
  619. * interfaces (not SGMII). For instance, it selects SATA speed
  620. * 1.5/3/6 Gbps or PCIe speed 2.5/5 Gbps
  621. */
  622. /*
  623. * 13. Program COMPHY register SEL_BITS to set correct parallel data
  624. * bus width
  625. */
  626. /* 10bit */
  627. phy_write16(lane, PHY_DIG_LB_EN_ADDR, 0, rf_data_width_mask);
  628. /*
  629. * 14. As long as DFE function needs to be enabled in any mode,
  630. * COMPHY register DFE_UPDATE_EN[5:0] shall be programmed to 0x3F
  631. * for real chip during COMPHY power on.
  632. */
  633. /*
  634. * The step 14 exists (and empty) in the original initialization flow
  635. * obtained from the verification team. According to the functional
  636. * specification DFE_UPDATE_EN already has the default value 0x3F
  637. */
  638. /*
  639. * 15. Program COMPHY GEN registers.
  640. * These registers should be programmed based on the lab testing
  641. * result to achieve optimal performance. Please contact the CEA
  642. * group to get the related GEN table during real chip bring-up.
  643. * We only requred to run though the entire registers programming
  644. * flow defined by "comphy_sgmii_phy_init" when the REF clock is
  645. * 40 MHz. For REF clock 25 MHz the default values stored in PHY
  646. * registers are OK.
  647. */
  648. debug("Running C-DPI phy init %s mode\n",
  649. speed == PHY_SPEED_3_125G ? "2G5" : "1G");
  650. if (get_ref_clk() == 40)
  651. comphy_sgmii_phy_init(lane, speed);
  652. /*
  653. * 16. [Simulation Only] should not be used for real chip.
  654. * By pass power up calibration by programming EXT_FORCE_CAL_DONE
  655. * (R02h[9]) to 1 to shorten COMPHY simulation time.
  656. */
  657. /*
  658. * 17. [Simulation Only: should not be used for real chip]
  659. * Program COMPHY register FAST_DFE_TIMER_EN=1 to shorten RX
  660. * training simulation time.
  661. */
  662. /*
  663. * 18. Check the PHY Polarity invert bit
  664. */
  665. if (invert & PHY_POLARITY_TXD_INVERT)
  666. phy_write16(lane, PHY_SYNC_PATTERN_ADDR, phy_txd_inv, 0);
  667. if (invert & PHY_POLARITY_RXD_INVERT)
  668. phy_write16(lane, PHY_SYNC_PATTERN_ADDR, phy_rxd_inv, 0);
  669. /*
  670. * 19. Set PHY input ports PIN_PU_PLL, PIN_PU_TX and PIN_PU_RX to 1
  671. * to start PHY power up sequence. All the PHY register
  672. * programming should be done before PIN_PU_PLL=1. There should be
  673. * no register programming for normal PHY operation from this point.
  674. */
  675. reg_set((void __iomem *)COMPHY_PHY_CFG1_ADDR(lane),
  676. rb_pin_pu_pll | rb_pin_pu_rx | rb_pin_pu_tx,
  677. rb_pin_pu_pll | rb_pin_pu_rx | rb_pin_pu_tx);
  678. /*
  679. * 20. Wait for PHY power up sequence to finish by checking output ports
  680. * PIN_PLL_READY_TX=1 and PIN_PLL_READY_RX=1.
  681. */
  682. ret = comphy_poll_reg((void *)COMPHY_PHY_STAT1_ADDR(lane), /* address */
  683. rb_pll_ready_tx | rb_pll_ready_rx, /* value */
  684. rb_pll_ready_tx | rb_pll_ready_rx, /* mask */
  685. PLL_LOCK_TIMEOUT, /* timeout */
  686. POLL_32B_REG); /* 32bit */
  687. if (ret == 0)
  688. printf("Failed to lock PLL for SGMII PHY %d\n", lane);
  689. /*
  690. * 21. Set COMPHY input port PIN_TX_IDLE=0
  691. */
  692. reg_set((void __iomem *)COMPHY_PHY_CFG1_ADDR(lane),
  693. 0x0, rb_pin_tx_idle);
  694. /*
  695. * 22. After valid data appear on PIN_RXDATA bus, set PIN_RX_INIT=1.
  696. * to start RX initialization. PIN_RX_INIT_DONE will be cleared to
  697. * 0 by the PHY. After RX initialization is done, PIN_RX_INIT_DONE
  698. * will be set to 1 by COMPHY. Set PIN_RX_INIT=0 after
  699. * PIN_RX_INIT_DONE= 1.
  700. * Please refer to RX initialization part for details.
  701. */
  702. reg_set((void __iomem *)COMPHY_PHY_CFG1_ADDR(lane), rb_phy_rx_init,
  703. 0x0);
  704. ret = comphy_poll_reg((void *)COMPHY_PHY_STAT1_ADDR(lane), /* address */
  705. rb_rx_init_done, /* value */
  706. rb_rx_init_done, /* mask */
  707. PLL_LOCK_TIMEOUT, /* timeout */
  708. POLL_32B_REG); /* 32bit */
  709. if (ret == 0)
  710. printf("Failed to init RX of SGMII PHY %d\n", lane);
  711. debug_exit();
  712. return ret;
  713. }
  714. void comphy_dedicated_phys_init(void)
  715. {
  716. int node, usb32, ret = 1;
  717. const void *blob = gd->fdt_blob;
  718. debug_enter();
  719. for (usb32 = 0; usb32 <= 1; usb32++) {
  720. /*
  721. * There are 2 UTMI PHYs in this SOC.
  722. * One is independendent and one is paired with USB3 port (OTG)
  723. */
  724. if (usb32 == 0) {
  725. node = fdt_node_offset_by_compatible(
  726. blob, -1, "marvell,armada-3700-ehci");
  727. } else {
  728. node = fdt_node_offset_by_compatible(
  729. blob, -1, "marvell,armada3700-xhci");
  730. }
  731. if (node > 0) {
  732. if (fdtdec_get_is_enabled(blob, node)) {
  733. ret = comphy_usb2_power_up(usb32);
  734. if (ret == 0)
  735. printf("Failed to initialize UTMI PHY\n");
  736. else
  737. debug("UTMI PHY init succeed\n");
  738. } else {
  739. debug("USB%d node is disabled\n",
  740. usb32 == 0 ? 2 : 3);
  741. }
  742. } else {
  743. debug("No USB%d node in DT\n", usb32 == 0 ? 2 : 3);
  744. }
  745. }
  746. node = fdt_node_offset_by_compatible(blob, -1,
  747. "marvell,armada-3700-ahci");
  748. if (node > 0) {
  749. if (fdtdec_get_is_enabled(blob, node)) {
  750. ret = comphy_sata_power_up();
  751. if (ret == 0)
  752. printf("Failed to initialize SATA PHY\n");
  753. else
  754. debug("SATA PHY init succeed\n");
  755. } else {
  756. debug("SATA node is disabled\n");
  757. }
  758. } else {
  759. debug("No SATA node in DT\n");
  760. }
  761. node = fdt_node_offset_by_compatible(blob, -1,
  762. "marvell,armada-3700-sdio");
  763. if (node <= 0) {
  764. debug("No SDIO node in DT, looking for MMC one\n");
  765. node = fdt_node_offset_by_compatible(blob, -1,
  766. "marvell,xenon-sdhci");
  767. }
  768. if (node > 0) {
  769. if (fdtdec_get_is_enabled(blob, node)) {
  770. ret = comphy_emmc_power_up();
  771. if (ret == 0)
  772. printf("Failed to initialize SDIO/eMMC PHY\n");
  773. else
  774. debug("SDIO/eMMC PHY init succeed\n");
  775. } else {
  776. debug("SDIO/eMMC node is disabled\n");
  777. }
  778. } else {
  779. debug("No SDIO/eMMC node in DT\n");
  780. }
  781. debug_exit();
  782. }
  783. int comphy_a3700_init(struct chip_serdes_phy_config *chip_cfg,
  784. struct comphy_map *serdes_map)
  785. {
  786. struct comphy_map *comphy_map;
  787. u32 comphy_max_count = chip_cfg->comphy_lanes_count;
  788. u32 lane, ret = 0;
  789. debug_enter();
  790. for (lane = 0, comphy_map = serdes_map; lane < comphy_max_count;
  791. lane++, comphy_map++) {
  792. debug("Initialize serdes number %d\n", lane);
  793. debug("Serdes type = 0x%x invert=%d\n",
  794. comphy_map->type, comphy_map->invert);
  795. switch (comphy_map->type) {
  796. case PHY_TYPE_UNCONNECTED:
  797. continue;
  798. break;
  799. case PHY_TYPE_PEX0:
  800. ret = comphy_pcie_power_up(comphy_map->speed,
  801. comphy_map->invert);
  802. break;
  803. case PHY_TYPE_USB3_HOST0:
  804. case PHY_TYPE_USB3_DEVICE:
  805. ret = comphy_usb3_power_up(comphy_map->type,
  806. comphy_map->speed,
  807. comphy_map->invert);
  808. break;
  809. case PHY_TYPE_SGMII0:
  810. case PHY_TYPE_SGMII1:
  811. ret = comphy_sgmii_power_up(lane, comphy_map->speed,
  812. comphy_map->invert);
  813. break;
  814. default:
  815. debug("Unknown SerDes type, skip initialize SerDes %d\n",
  816. lane);
  817. ret = 1;
  818. break;
  819. }
  820. if (ret == 0)
  821. printf("PLL is not locked - Failed to initialize lane %d\n",
  822. lane);
  823. }
  824. debug_exit();
  825. return ret;
  826. }