comphy_a3700.c 28 KB

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