phy-qcom-qmp-usb-legacy.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2017, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/clk-provider.h>
  7. #include <linux/delay.h>
  8. #include <linux/err.h>
  9. #include <linux/io.h>
  10. #include <linux/iopoll.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <linux/of_device.h>
  15. #include <linux/of_address.h>
  16. #include <linux/phy/phy.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/regulator/consumer.h>
  19. #include <linux/reset.h>
  20. #include <linux/slab.h>
  21. #include "phy-qcom-qmp.h"
  22. #include "phy-qcom-qmp-pcs-misc-v3.h"
  23. #include "phy-qcom-qmp-pcs-usb-v4.h"
  24. #include "phy-qcom-qmp-pcs-usb-v5.h"
  25. #include "phy-qcom-qmp-dp-com-v3.h"
  26. /* QPHY_V3_DP_COM_RESET_OVRD_CTRL register bits */
  27. /* DP PHY soft reset */
  28. #define SW_DPPHY_RESET BIT(0)
  29. /* mux to select DP PHY reset control, 0:HW control, 1: software reset */
  30. #define SW_DPPHY_RESET_MUX BIT(1)
  31. /* USB3 PHY soft reset */
  32. #define SW_USB3PHY_RESET BIT(2)
  33. /* mux to select USB3 PHY reset control, 0:HW control, 1: software reset */
  34. #define SW_USB3PHY_RESET_MUX BIT(3)
  35. /* QPHY_V3_DP_COM_PHY_MODE_CTRL register bits */
  36. #define USB3_MODE BIT(0) /* enables USB3 mode */
  37. #define DP_MODE BIT(1) /* enables DP mode */
  38. #define PHY_INIT_COMPLETE_TIMEOUT 10000
  39. struct qmp_phy_init_tbl {
  40. unsigned int offset;
  41. unsigned int val;
  42. /*
  43. * mask of lanes for which this register is written
  44. * for cases when second lane needs different values
  45. */
  46. u8 lane_mask;
  47. };
  48. #define QMP_PHY_INIT_CFG(o, v) \
  49. { \
  50. .offset = o, \
  51. .val = v, \
  52. .lane_mask = 0xff, \
  53. }
  54. #define QMP_PHY_INIT_CFG_LANE(o, v, l) \
  55. { \
  56. .offset = o, \
  57. .val = v, \
  58. .lane_mask = l, \
  59. }
  60. /* set of registers with offsets different per-PHY */
  61. enum qphy_reg_layout {
  62. /* PCS registers */
  63. QPHY_SW_RESET,
  64. QPHY_START_CTRL,
  65. QPHY_PCS_STATUS,
  66. QPHY_PCS_AUTONOMOUS_MODE_CTRL,
  67. QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR,
  68. QPHY_PCS_POWER_DOWN_CONTROL,
  69. /* Keep last to ensure regs_layout arrays are properly initialized */
  70. QPHY_LAYOUT_SIZE
  71. };
  72. static const unsigned int qmp_v3_usb3phy_regs_layout[QPHY_LAYOUT_SIZE] = {
  73. [QPHY_SW_RESET] = QPHY_V3_PCS_SW_RESET,
  74. [QPHY_START_CTRL] = QPHY_V3_PCS_START_CONTROL,
  75. [QPHY_PCS_STATUS] = QPHY_V3_PCS_PCS_STATUS,
  76. [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = QPHY_V3_PCS_AUTONOMOUS_MODE_CTRL,
  77. [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = QPHY_V3_PCS_LFPS_RXTERM_IRQ_CLEAR,
  78. [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V3_PCS_POWER_DOWN_CONTROL,
  79. };
  80. static const unsigned int qmp_v4_usb3phy_regs_layout[QPHY_LAYOUT_SIZE] = {
  81. [QPHY_SW_RESET] = QPHY_V4_PCS_SW_RESET,
  82. [QPHY_START_CTRL] = QPHY_V4_PCS_START_CONTROL,
  83. [QPHY_PCS_STATUS] = QPHY_V4_PCS_PCS_STATUS1,
  84. [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V4_PCS_POWER_DOWN_CONTROL,
  85. /* In PCS_USB */
  86. [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = QPHY_V4_PCS_USB3_AUTONOMOUS_MODE_CTRL,
  87. [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = QPHY_V4_PCS_USB3_LFPS_RXTERM_IRQ_CLEAR,
  88. };
  89. static const unsigned int qmp_v5_usb3phy_regs_layout[QPHY_LAYOUT_SIZE] = {
  90. [QPHY_SW_RESET] = QPHY_V5_PCS_SW_RESET,
  91. [QPHY_START_CTRL] = QPHY_V5_PCS_START_CONTROL,
  92. [QPHY_PCS_STATUS] = QPHY_V5_PCS_PCS_STATUS1,
  93. [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V5_PCS_POWER_DOWN_CONTROL,
  94. /* In PCS_USB */
  95. [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = QPHY_V5_PCS_USB3_AUTONOMOUS_MODE_CTRL,
  96. [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = QPHY_V5_PCS_USB3_LFPS_RXTERM_IRQ_CLEAR,
  97. };
  98. static const struct qmp_phy_init_tbl qmp_v3_usb3_serdes_tbl[] = {
  99. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
  100. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0x14),
  101. QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
  102. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
  103. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
  104. QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL2, 0x08),
  105. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x16),
  106. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x01),
  107. QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x80),
  108. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82),
  109. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START1_MODE0, 0xab),
  110. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0xea),
  111. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x02),
  112. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
  113. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
  114. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
  115. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  116. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
  117. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01),
  118. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xc9),
  119. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORECLK_DIV_MODE0, 0x0a),
  120. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP3_MODE0, 0x00),
  121. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x34),
  122. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x15),
  123. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x04),
  124. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00),
  125. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_CFG, 0x00),
  126. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x00),
  127. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_BUF_ENABLE, 0x0a),
  128. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_EN_CENTER, 0x01),
  129. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER1, 0x31),
  130. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER2, 0x01),
  131. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER1, 0x00),
  132. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER2, 0x00),
  133. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE1, 0x85),
  134. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE2, 0x07),
  135. };
  136. static const struct qmp_phy_init_tbl qmp_v3_usb3_tx_tbl[] = {
  137. QMP_PHY_INIT_CFG(QSERDES_V3_TX_HIGHZ_DRVR_EN, 0x10),
  138. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RCV_DETECT_LVL_2, 0x12),
  139. QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0x16),
  140. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x09),
  141. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x06),
  142. };
  143. static const struct qmp_phy_init_tbl qmp_v3_usb3_rx_tbl[] = {
  144. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
  145. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
  146. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4e),
  147. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x18),
  148. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
  149. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x80),
  150. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x03),
  151. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x16),
  152. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x75),
  153. };
  154. static const struct qmp_phy_init_tbl qmp_v3_usb3_pcs_tbl[] = {
  155. /* FLL settings */
  156. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL2, 0x83),
  157. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_L, 0x09),
  158. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_H_TOL, 0xa2),
  159. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_MAN_CODE, 0x40),
  160. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL1, 0x02),
  161. /* Lock Det settings */
  162. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG1, 0xd1),
  163. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG2, 0x1f),
  164. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG3, 0x47),
  165. QMP_PHY_INIT_CFG(QPHY_V3_PCS_POWER_STATE_CONFIG2, 0x1b),
  166. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RX_SIGDET_LVL, 0xba),
  167. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V0, 0x9f),
  168. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V1, 0x9f),
  169. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V2, 0xb7),
  170. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V3, 0x4e),
  171. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V4, 0x65),
  172. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_LS, 0x6b),
  173. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V0, 0x15),
  174. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V0, 0x0d),
  175. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V1, 0x15),
  176. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V1, 0x0d),
  177. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V2, 0x15),
  178. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V2, 0x0d),
  179. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V3, 0x15),
  180. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V3, 0x1d),
  181. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V4, 0x15),
  182. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V4, 0x0d),
  183. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_LS, 0x15),
  184. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_LS, 0x0d),
  185. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RATE_SLEW_CNTRL, 0x02),
  186. QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
  187. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TSYNC_RSYNC_TIME, 0x44),
  188. QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
  189. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_L, 0xe7),
  190. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_H, 0x03),
  191. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_L, 0x40),
  192. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_H, 0x00),
  193. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_WAIT_TIME, 0x75),
  194. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LFPS_TX_ECSTART_EQTLOCK, 0x86),
  195. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_RUN_TIME, 0x13),
  196. };
  197. static const struct qmp_phy_init_tbl sm8150_usb3_serdes_tbl[] = {
  198. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_EN_CENTER, 0x01),
  199. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_PER1, 0x31),
  200. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_PER2, 0x01),
  201. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE1_MODE0, 0xde),
  202. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE2_MODE0, 0x07),
  203. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE1_MODE1, 0xde),
  204. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE2_MODE1, 0x07),
  205. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_BUF_ENABLE, 0x0a),
  206. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CMN_IPTRIM, 0x20),
  207. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE0, 0x06),
  208. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE1, 0x06),
  209. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE0, 0x16),
  210. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE1, 0x16),
  211. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE0, 0x36),
  212. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE1, 0x36),
  213. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_EN_SEL, 0x1a),
  214. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP_EN, 0x04),
  215. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE0, 0x14),
  216. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE0, 0x34),
  217. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE1, 0x34),
  218. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE1, 0x82),
  219. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE0, 0x82),
  220. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE1, 0x82),
  221. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START1_MODE0, 0xab),
  222. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START2_MODE0, 0xea),
  223. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START3_MODE0, 0x02),
  224. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x02),
  225. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START1_MODE1, 0xab),
  226. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START2_MODE1, 0xea),
  227. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START3_MODE1, 0x02),
  228. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE1_MODE0, 0x24),
  229. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE1_MODE1, 0x24),
  230. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE2_MODE1, 0x02),
  231. QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_SEL, 0x01),
  232. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CORECLK_DIV_MODE1, 0x08),
  233. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE0, 0xca),
  234. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE0, 0x1e),
  235. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE1, 0xca),
  236. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE1, 0x1e),
  237. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_HSCLK_SEL, 0x11),
  238. };
  239. static const struct qmp_phy_init_tbl sm8150_usb3_tx_tbl[] = {
  240. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_TX, 0x00),
  241. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_RX, 0x00),
  242. QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0xd5),
  243. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RCV_DETECT_LVL_2, 0x12),
  244. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PI_QEC_CTRL, 0x20),
  245. };
  246. static const struct qmp_phy_init_tbl sm8150_usb3_rx_tbl[] = {
  247. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x05),
  248. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x2f),
  249. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x7f),
  250. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0xff),
  251. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_HIGH, 0x0f),
  252. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0x99),
  253. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_THRESH1, 0x04),
  254. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_THRESH2, 0x08),
  255. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_GAIN1, 0x05),
  256. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_GAIN2, 0x05),
  257. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VGA_CAL_CNTRL1, 0x54),
  258. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VGA_CAL_CNTRL2, 0x0e),
  259. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
  260. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4a),
  261. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x0a),
  262. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
  263. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
  264. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
  265. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x04),
  266. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x0e),
  267. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0xbf),
  268. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xbf),
  269. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0x3f),
  270. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
  271. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x94),
  272. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0xdc),
  273. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0xdc),
  274. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0x5c),
  275. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x0b),
  276. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb3),
  277. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DFE_EN_TIMER, 0x04),
  278. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DFE_CTLE_POST_CAL_OFFSET, 0x38),
  279. QMP_PHY_INIT_CFG(QSERDES_V4_RX_AUX_DATA_TCOARSE_TFINE, 0xa0),
  280. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DCC_CTRL1, 0x0c),
  281. QMP_PHY_INIT_CFG(QSERDES_V4_RX_GM_CAL, 0x1f),
  282. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VTH_CODE, 0x10),
  283. };
  284. static const struct qmp_phy_init_tbl sm8150_usb3_pcs_tbl[] = {
  285. /* Lock Det settings */
  286. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG1, 0xd0),
  287. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG2, 0x07),
  288. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG6, 0x13),
  289. QMP_PHY_INIT_CFG(QPHY_V4_PCS_REFGEN_REQ_CONFIG1, 0x21),
  290. QMP_PHY_INIT_CFG(QPHY_V4_PCS_RX_SIGDET_LVL, 0xaa),
  291. QMP_PHY_INIT_CFG(QPHY_V4_PCS_CDR_RESET_TIME, 0x0a),
  292. QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG1, 0x88),
  293. QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG2, 0x13),
  294. QMP_PHY_INIT_CFG(QPHY_V4_PCS_PCS_TX_RX_CONFIG, 0x0c),
  295. QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG1, 0x4b),
  296. QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG5, 0x10),
  297. };
  298. static const struct qmp_phy_init_tbl sm8150_usb3_pcs_usb_tbl[] = {
  299. QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_LFPS_DET_HIGH_COUNT_VAL, 0xf8),
  300. QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_RXEQTRAINING_DFE_TIME_S2, 0x07),
  301. };
  302. static const struct qmp_phy_init_tbl sm8250_usb3_tx_tbl[] = {
  303. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_TX, 0x60),
  304. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_RX, 0x60),
  305. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_OFFSET_TX, 0x11),
  306. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_OFFSET_RX, 0x02),
  307. QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0xd5),
  308. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RCV_DETECT_LVL_2, 0x12),
  309. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_TX_PI_QEC_CTRL, 0x40, 1),
  310. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_TX_PI_QEC_CTRL, 0x54, 2),
  311. };
  312. static const struct qmp_phy_init_tbl sm8250_usb3_rx_tbl[] = {
  313. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x06),
  314. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x2f),
  315. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x7f),
  316. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0xff),
  317. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_HIGH, 0x0f),
  318. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0x99),
  319. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_THRESH1, 0x04),
  320. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_THRESH2, 0x08),
  321. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_GAIN1, 0x05),
  322. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_GAIN2, 0x05),
  323. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VGA_CAL_CNTRL1, 0x54),
  324. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VGA_CAL_CNTRL2, 0x0c),
  325. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
  326. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4a),
  327. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x0a),
  328. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
  329. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
  330. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
  331. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x04),
  332. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x0e),
  333. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_LOW, 0xff, 1),
  334. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_LOW, 0x7f, 2),
  335. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_HIGH, 0x7f, 1),
  336. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff, 2),
  337. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0x7f),
  338. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
  339. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x97),
  340. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0xdc),
  341. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0xdc),
  342. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0x5c),
  343. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x7b),
  344. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb4),
  345. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DFE_EN_TIMER, 0x04),
  346. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DFE_CTLE_POST_CAL_OFFSET, 0x38),
  347. QMP_PHY_INIT_CFG(QSERDES_V4_RX_AUX_DATA_TCOARSE_TFINE, 0xa0),
  348. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DCC_CTRL1, 0x0c),
  349. QMP_PHY_INIT_CFG(QSERDES_V4_RX_GM_CAL, 0x1f),
  350. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VTH_CODE, 0x10),
  351. };
  352. static const struct qmp_phy_init_tbl sm8250_usb3_pcs_tbl[] = {
  353. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG1, 0xd0),
  354. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG2, 0x07),
  355. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG3, 0x20),
  356. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG6, 0x13),
  357. QMP_PHY_INIT_CFG(QPHY_V4_PCS_REFGEN_REQ_CONFIG1, 0x21),
  358. QMP_PHY_INIT_CFG(QPHY_V4_PCS_RX_SIGDET_LVL, 0xa9),
  359. QMP_PHY_INIT_CFG(QPHY_V4_PCS_CDR_RESET_TIME, 0x0a),
  360. QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG1, 0x88),
  361. QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG2, 0x13),
  362. QMP_PHY_INIT_CFG(QPHY_V4_PCS_PCS_TX_RX_CONFIG, 0x0c),
  363. QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG1, 0x4b),
  364. QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG5, 0x10),
  365. };
  366. static const struct qmp_phy_init_tbl sm8250_usb3_pcs_usb_tbl[] = {
  367. QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_LFPS_DET_HIGH_COUNT_VAL, 0xf8),
  368. QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_RXEQTRAINING_DFE_TIME_S2, 0x07),
  369. };
  370. static const struct qmp_phy_init_tbl sm8350_usb3_tx_tbl[] = {
  371. QMP_PHY_INIT_CFG(QSERDES_V5_TX_RES_CODE_LANE_TX, 0x00),
  372. QMP_PHY_INIT_CFG(QSERDES_V5_TX_RES_CODE_LANE_RX, 0x00),
  373. QMP_PHY_INIT_CFG(QSERDES_V5_TX_RES_CODE_LANE_OFFSET_TX, 0x16),
  374. QMP_PHY_INIT_CFG(QSERDES_V5_TX_RES_CODE_LANE_OFFSET_RX, 0x0e),
  375. QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_1, 0x35),
  376. QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_3, 0x3f),
  377. QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_4, 0x7f),
  378. QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_5, 0x3f),
  379. QMP_PHY_INIT_CFG(QSERDES_V5_TX_RCV_DETECT_LVL_2, 0x12),
  380. QMP_PHY_INIT_CFG(QSERDES_V5_TX_PI_QEC_CTRL, 0x21),
  381. };
  382. static const struct qmp_phy_init_tbl sm8350_usb3_rx_tbl[] = {
  383. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FO_GAIN, 0x0a),
  384. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SO_GAIN, 0x05),
  385. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FASTLOCK_FO_GAIN, 0x2f),
  386. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x7f),
  387. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FASTLOCK_COUNT_LOW, 0xff),
  388. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FASTLOCK_COUNT_HIGH, 0x0f),
  389. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_PI_CONTROLS, 0x99),
  390. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SB2_THRESH1, 0x08),
  391. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SB2_THRESH2, 0x08),
  392. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SB2_GAIN1, 0x00),
  393. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SB2_GAIN2, 0x04),
  394. QMP_PHY_INIT_CFG(QSERDES_V5_RX_VGA_CAL_CNTRL1, 0x54),
  395. QMP_PHY_INIT_CFG(QSERDES_V5_RX_VGA_CAL_CNTRL2, 0x0f),
  396. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
  397. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4a),
  398. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL4, 0x0a),
  399. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
  400. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
  401. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x47),
  402. QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_CNTRL, 0x04),
  403. QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_DEGLITCH_CNTRL, 0x0e),
  404. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_LOW, 0xbb),
  405. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH, 0x7b),
  406. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH2, 0xbb),
  407. QMP_PHY_INIT_CFG_LANE(QSERDES_V5_RX_RX_MODE_00_HIGH3, 0x3d, 1),
  408. QMP_PHY_INIT_CFG_LANE(QSERDES_V5_RX_RX_MODE_00_HIGH3, 0x3c, 2),
  409. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH4, 0xdb),
  410. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_LOW, 0x64),
  411. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH, 0x24),
  412. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH2, 0xd2),
  413. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH3, 0x13),
  414. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH4, 0xa9),
  415. QMP_PHY_INIT_CFG(QSERDES_V5_RX_DFE_EN_TIMER, 0x04),
  416. QMP_PHY_INIT_CFG(QSERDES_V5_RX_DFE_CTLE_POST_CAL_OFFSET, 0x38),
  417. QMP_PHY_INIT_CFG(QSERDES_V5_RX_AUX_DATA_TCOARSE_TFINE, 0xa0),
  418. QMP_PHY_INIT_CFG(QSERDES_V5_RX_DCC_CTRL1, 0x0c),
  419. QMP_PHY_INIT_CFG(QSERDES_V5_RX_GM_CAL, 0x00),
  420. QMP_PHY_INIT_CFG(QSERDES_V5_RX_VTH_CODE, 0x10),
  421. };
  422. static const struct qmp_phy_init_tbl sm8350_usb3_pcs_tbl[] = {
  423. QMP_PHY_INIT_CFG(QPHY_V4_PCS_RCVR_DTCT_DLY_P1U2_L, 0xe7),
  424. QMP_PHY_INIT_CFG(QPHY_V4_PCS_RCVR_DTCT_DLY_P1U2_H, 0x03),
  425. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG1, 0xd0),
  426. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG2, 0x07),
  427. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG3, 0x20),
  428. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG6, 0x13),
  429. QMP_PHY_INIT_CFG(QPHY_V4_PCS_REFGEN_REQ_CONFIG1, 0x21),
  430. QMP_PHY_INIT_CFG(QPHY_V4_PCS_RX_SIGDET_LVL, 0xaa),
  431. QMP_PHY_INIT_CFG(QPHY_V4_PCS_CDR_RESET_TIME, 0x0a),
  432. QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG1, 0x88),
  433. QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG2, 0x13),
  434. QMP_PHY_INIT_CFG(QPHY_V4_PCS_PCS_TX_RX_CONFIG, 0x0c),
  435. QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG1, 0x4b),
  436. QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG5, 0x10),
  437. };
  438. static const struct qmp_phy_init_tbl sm8350_usb3_pcs_usb_tbl[] = {
  439. QMP_PHY_INIT_CFG(QPHY_V5_PCS_USB3_RCVR_DTCT_DLY_U3_L, 0x40),
  440. QMP_PHY_INIT_CFG(QPHY_V5_PCS_USB3_RCVR_DTCT_DLY_U3_H, 0x00),
  441. QMP_PHY_INIT_CFG(QPHY_V5_PCS_USB3_LFPS_DET_HIGH_COUNT_VAL, 0xf8),
  442. QMP_PHY_INIT_CFG(QPHY_V5_PCS_USB3_RXEQTRAINING_DFE_TIME_S2, 0x07),
  443. };
  444. struct qmp_usb_legacy_offsets {
  445. u16 serdes;
  446. u16 pcs;
  447. u16 pcs_usb;
  448. u16 tx;
  449. u16 rx;
  450. };
  451. /* struct qmp_phy_cfg - per-PHY initialization config */
  452. struct qmp_phy_cfg {
  453. const struct qmp_usb_legacy_offsets *offsets;
  454. /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
  455. const struct qmp_phy_init_tbl *serdes_tbl;
  456. int serdes_tbl_num;
  457. const struct qmp_phy_init_tbl *tx_tbl;
  458. int tx_tbl_num;
  459. const struct qmp_phy_init_tbl *rx_tbl;
  460. int rx_tbl_num;
  461. const struct qmp_phy_init_tbl *pcs_tbl;
  462. int pcs_tbl_num;
  463. const struct qmp_phy_init_tbl *pcs_usb_tbl;
  464. int pcs_usb_tbl_num;
  465. /* clock ids to be requested */
  466. const char * const *clk_list;
  467. int num_clks;
  468. /* resets to be requested */
  469. const char * const *reset_list;
  470. int num_resets;
  471. /* regulators to be requested */
  472. const char * const *vreg_list;
  473. int num_vregs;
  474. /* array of registers with different offsets */
  475. const unsigned int *regs;
  476. /* Offset from PCS to PCS_USB region */
  477. unsigned int pcs_usb_offset;
  478. };
  479. struct qmp_usb {
  480. struct device *dev;
  481. const struct qmp_phy_cfg *cfg;
  482. void __iomem *serdes;
  483. void __iomem *pcs;
  484. void __iomem *pcs_misc;
  485. void __iomem *pcs_usb;
  486. void __iomem *tx;
  487. void __iomem *rx;
  488. void __iomem *tx2;
  489. void __iomem *rx2;
  490. void __iomem *dp_com;
  491. struct clk *pipe_clk;
  492. struct clk_bulk_data *clks;
  493. struct reset_control_bulk_data *resets;
  494. struct regulator_bulk_data *vregs;
  495. enum phy_mode mode;
  496. struct phy *phy;
  497. struct clk_fixed_rate pipe_clk_fixed;
  498. };
  499. static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
  500. {
  501. u32 reg;
  502. reg = readl(base + offset);
  503. reg |= val;
  504. writel(reg, base + offset);
  505. /* ensure that above write is through */
  506. readl(base + offset);
  507. }
  508. static inline void qphy_clrbits(void __iomem *base, u32 offset, u32 val)
  509. {
  510. u32 reg;
  511. reg = readl(base + offset);
  512. reg &= ~val;
  513. writel(reg, base + offset);
  514. /* ensure that above write is through */
  515. readl(base + offset);
  516. }
  517. /* list of clocks required by phy */
  518. static const char * const qmp_v3_phy_clk_l[] = {
  519. "aux", "cfg_ahb", "ref", "com_aux",
  520. };
  521. static const char * const qmp_v4_ref_phy_clk_l[] = {
  522. "aux", "ref_clk_src", "ref", "com_aux",
  523. };
  524. /* the primary usb3 phy on sm8250 doesn't have a ref clock */
  525. static const char * const qmp_v4_sm8250_usbphy_clk_l[] = {
  526. "aux", "ref_clk_src", "com_aux"
  527. };
  528. /* list of resets */
  529. static const char * const msm8996_usb3phy_reset_l[] = {
  530. "phy", "common",
  531. };
  532. static const char * const sc7180_usb3phy_reset_l[] = {
  533. "phy",
  534. };
  535. /* list of regulators */
  536. static const char * const qmp_phy_vreg_l[] = {
  537. "vdda-phy", "vdda-pll",
  538. };
  539. static const struct qmp_phy_cfg qmp_v3_usb3phy_cfg = {
  540. .serdes_tbl = qmp_v3_usb3_serdes_tbl,
  541. .serdes_tbl_num = ARRAY_SIZE(qmp_v3_usb3_serdes_tbl),
  542. .tx_tbl = qmp_v3_usb3_tx_tbl,
  543. .tx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_tx_tbl),
  544. .rx_tbl = qmp_v3_usb3_rx_tbl,
  545. .rx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_rx_tbl),
  546. .pcs_tbl = qmp_v3_usb3_pcs_tbl,
  547. .pcs_tbl_num = ARRAY_SIZE(qmp_v3_usb3_pcs_tbl),
  548. .clk_list = qmp_v3_phy_clk_l,
  549. .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
  550. .reset_list = msm8996_usb3phy_reset_l,
  551. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  552. .vreg_list = qmp_phy_vreg_l,
  553. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  554. .regs = qmp_v3_usb3phy_regs_layout,
  555. };
  556. static const struct qmp_phy_cfg sc7180_usb3phy_cfg = {
  557. .serdes_tbl = qmp_v3_usb3_serdes_tbl,
  558. .serdes_tbl_num = ARRAY_SIZE(qmp_v3_usb3_serdes_tbl),
  559. .tx_tbl = qmp_v3_usb3_tx_tbl,
  560. .tx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_tx_tbl),
  561. .rx_tbl = qmp_v3_usb3_rx_tbl,
  562. .rx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_rx_tbl),
  563. .pcs_tbl = qmp_v3_usb3_pcs_tbl,
  564. .pcs_tbl_num = ARRAY_SIZE(qmp_v3_usb3_pcs_tbl),
  565. .clk_list = qmp_v3_phy_clk_l,
  566. .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
  567. .reset_list = sc7180_usb3phy_reset_l,
  568. .num_resets = ARRAY_SIZE(sc7180_usb3phy_reset_l),
  569. .vreg_list = qmp_phy_vreg_l,
  570. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  571. .regs = qmp_v3_usb3phy_regs_layout,
  572. };
  573. static const struct qmp_phy_cfg sm8150_usb3phy_cfg = {
  574. .serdes_tbl = sm8150_usb3_serdes_tbl,
  575. .serdes_tbl_num = ARRAY_SIZE(sm8150_usb3_serdes_tbl),
  576. .tx_tbl = sm8150_usb3_tx_tbl,
  577. .tx_tbl_num = ARRAY_SIZE(sm8150_usb3_tx_tbl),
  578. .rx_tbl = sm8150_usb3_rx_tbl,
  579. .rx_tbl_num = ARRAY_SIZE(sm8150_usb3_rx_tbl),
  580. .pcs_tbl = sm8150_usb3_pcs_tbl,
  581. .pcs_tbl_num = ARRAY_SIZE(sm8150_usb3_pcs_tbl),
  582. .pcs_usb_tbl = sm8150_usb3_pcs_usb_tbl,
  583. .pcs_usb_tbl_num = ARRAY_SIZE(sm8150_usb3_pcs_usb_tbl),
  584. .clk_list = qmp_v4_ref_phy_clk_l,
  585. .num_clks = ARRAY_SIZE(qmp_v4_ref_phy_clk_l),
  586. .reset_list = msm8996_usb3phy_reset_l,
  587. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  588. .vreg_list = qmp_phy_vreg_l,
  589. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  590. .regs = qmp_v4_usb3phy_regs_layout,
  591. .pcs_usb_offset = 0x300,
  592. };
  593. static const struct qmp_phy_cfg sm8250_usb3phy_cfg = {
  594. .serdes_tbl = sm8150_usb3_serdes_tbl,
  595. .serdes_tbl_num = ARRAY_SIZE(sm8150_usb3_serdes_tbl),
  596. .tx_tbl = sm8250_usb3_tx_tbl,
  597. .tx_tbl_num = ARRAY_SIZE(sm8250_usb3_tx_tbl),
  598. .rx_tbl = sm8250_usb3_rx_tbl,
  599. .rx_tbl_num = ARRAY_SIZE(sm8250_usb3_rx_tbl),
  600. .pcs_tbl = sm8250_usb3_pcs_tbl,
  601. .pcs_tbl_num = ARRAY_SIZE(sm8250_usb3_pcs_tbl),
  602. .pcs_usb_tbl = sm8250_usb3_pcs_usb_tbl,
  603. .pcs_usb_tbl_num = ARRAY_SIZE(sm8250_usb3_pcs_usb_tbl),
  604. .clk_list = qmp_v4_sm8250_usbphy_clk_l,
  605. .num_clks = ARRAY_SIZE(qmp_v4_sm8250_usbphy_clk_l),
  606. .reset_list = msm8996_usb3phy_reset_l,
  607. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  608. .vreg_list = qmp_phy_vreg_l,
  609. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  610. .regs = qmp_v4_usb3phy_regs_layout,
  611. .pcs_usb_offset = 0x300,
  612. };
  613. static const struct qmp_phy_cfg sm8350_usb3phy_cfg = {
  614. .serdes_tbl = sm8150_usb3_serdes_tbl,
  615. .serdes_tbl_num = ARRAY_SIZE(sm8150_usb3_serdes_tbl),
  616. .tx_tbl = sm8350_usb3_tx_tbl,
  617. .tx_tbl_num = ARRAY_SIZE(sm8350_usb3_tx_tbl),
  618. .rx_tbl = sm8350_usb3_rx_tbl,
  619. .rx_tbl_num = ARRAY_SIZE(sm8350_usb3_rx_tbl),
  620. .pcs_tbl = sm8350_usb3_pcs_tbl,
  621. .pcs_tbl_num = ARRAY_SIZE(sm8350_usb3_pcs_tbl),
  622. .pcs_usb_tbl = sm8350_usb3_pcs_usb_tbl,
  623. .pcs_usb_tbl_num = ARRAY_SIZE(sm8350_usb3_pcs_usb_tbl),
  624. .clk_list = qmp_v4_sm8250_usbphy_clk_l,
  625. .num_clks = ARRAY_SIZE(qmp_v4_sm8250_usbphy_clk_l),
  626. .reset_list = msm8996_usb3phy_reset_l,
  627. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  628. .vreg_list = qmp_phy_vreg_l,
  629. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  630. .regs = qmp_v5_usb3phy_regs_layout,
  631. .pcs_usb_offset = 0x300,
  632. };
  633. static void qmp_usb_legacy_configure_lane(void __iomem *base,
  634. const struct qmp_phy_init_tbl tbl[],
  635. int num,
  636. u8 lane_mask)
  637. {
  638. int i;
  639. const struct qmp_phy_init_tbl *t = tbl;
  640. if (!t)
  641. return;
  642. for (i = 0; i < num; i++, t++) {
  643. if (!(t->lane_mask & lane_mask))
  644. continue;
  645. writel(t->val, base + t->offset);
  646. }
  647. }
  648. static void qmp_usb_legacy_configure(void __iomem *base,
  649. const struct qmp_phy_init_tbl tbl[],
  650. int num)
  651. {
  652. qmp_usb_legacy_configure_lane(base, tbl, num, 0xff);
  653. }
  654. static int qmp_usb_legacy_serdes_init(struct qmp_usb *qmp)
  655. {
  656. const struct qmp_phy_cfg *cfg = qmp->cfg;
  657. void __iomem *serdes = qmp->serdes;
  658. const struct qmp_phy_init_tbl *serdes_tbl = cfg->serdes_tbl;
  659. int serdes_tbl_num = cfg->serdes_tbl_num;
  660. qmp_usb_legacy_configure(serdes, serdes_tbl, serdes_tbl_num);
  661. return 0;
  662. }
  663. static void qmp_usb_legacy_init_dp_com(struct phy *phy)
  664. {
  665. struct qmp_usb *qmp = phy_get_drvdata(phy);
  666. void __iomem *dp_com = qmp->dp_com;
  667. qphy_setbits(dp_com, QPHY_V3_DP_COM_POWER_DOWN_CTRL,
  668. SW_PWRDN);
  669. /* override hardware control for reset of qmp phy */
  670. qphy_setbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
  671. SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
  672. SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
  673. /* Default type-c orientation, i.e CC1 */
  674. qphy_setbits(dp_com, QPHY_V3_DP_COM_TYPEC_CTRL, 0x02);
  675. qphy_setbits(dp_com, QPHY_V3_DP_COM_PHY_MODE_CTRL,
  676. USB3_MODE | DP_MODE);
  677. /* bring both QMP USB and QMP DP PHYs PCS block out of reset */
  678. qphy_clrbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
  679. SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
  680. SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
  681. qphy_clrbits(dp_com, QPHY_V3_DP_COM_SWI_CTRL, 0x03);
  682. qphy_clrbits(dp_com, QPHY_V3_DP_COM_SW_RESET, SW_RESET);
  683. }
  684. static int qmp_usb_legacy_init(struct phy *phy)
  685. {
  686. struct qmp_usb *qmp = phy_get_drvdata(phy);
  687. const struct qmp_phy_cfg *cfg = qmp->cfg;
  688. void __iomem *pcs = qmp->pcs;
  689. int ret;
  690. ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
  691. if (ret) {
  692. dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret);
  693. return ret;
  694. }
  695. ret = reset_control_bulk_assert(cfg->num_resets, qmp->resets);
  696. if (ret) {
  697. dev_err(qmp->dev, "reset assert failed\n");
  698. goto err_disable_regulators;
  699. }
  700. ret = reset_control_bulk_deassert(cfg->num_resets, qmp->resets);
  701. if (ret) {
  702. dev_err(qmp->dev, "reset deassert failed\n");
  703. goto err_disable_regulators;
  704. }
  705. ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
  706. if (ret)
  707. goto err_assert_reset;
  708. qmp_usb_legacy_init_dp_com(phy);
  709. qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
  710. return 0;
  711. err_assert_reset:
  712. reset_control_bulk_assert(cfg->num_resets, qmp->resets);
  713. err_disable_regulators:
  714. regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
  715. return ret;
  716. }
  717. static int qmp_usb_legacy_exit(struct phy *phy)
  718. {
  719. struct qmp_usb *qmp = phy_get_drvdata(phy);
  720. const struct qmp_phy_cfg *cfg = qmp->cfg;
  721. reset_control_bulk_assert(cfg->num_resets, qmp->resets);
  722. clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
  723. regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
  724. return 0;
  725. }
  726. static int qmp_usb_legacy_power_on(struct phy *phy)
  727. {
  728. struct qmp_usb *qmp = phy_get_drvdata(phy);
  729. const struct qmp_phy_cfg *cfg = qmp->cfg;
  730. void __iomem *tx = qmp->tx;
  731. void __iomem *rx = qmp->rx;
  732. void __iomem *pcs = qmp->pcs;
  733. void __iomem *status;
  734. unsigned int val;
  735. int ret;
  736. qmp_usb_legacy_serdes_init(qmp);
  737. ret = clk_prepare_enable(qmp->pipe_clk);
  738. if (ret) {
  739. dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
  740. return ret;
  741. }
  742. /* Tx, Rx, and PCS configurations */
  743. qmp_usb_legacy_configure_lane(tx, cfg->tx_tbl, cfg->tx_tbl_num, 1);
  744. qmp_usb_legacy_configure_lane(rx, cfg->rx_tbl, cfg->rx_tbl_num, 1);
  745. qmp_usb_legacy_configure_lane(qmp->tx2, cfg->tx_tbl, cfg->tx_tbl_num, 2);
  746. qmp_usb_legacy_configure_lane(qmp->rx2, cfg->rx_tbl, cfg->rx_tbl_num, 2);
  747. qmp_usb_legacy_configure(pcs, cfg->pcs_tbl, cfg->pcs_tbl_num);
  748. usleep_range(10, 20);
  749. /* Pull PHY out of reset state */
  750. qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
  751. /* start SerDes and Phy-Coding-Sublayer */
  752. qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], SERDES_START | PCS_START);
  753. status = pcs + cfg->regs[QPHY_PCS_STATUS];
  754. ret = readl_poll_timeout(status, val, !(val & PHYSTATUS), 200,
  755. PHY_INIT_COMPLETE_TIMEOUT);
  756. if (ret) {
  757. dev_err(qmp->dev, "phy initialization timed-out\n");
  758. goto err_disable_pipe_clk;
  759. }
  760. return 0;
  761. err_disable_pipe_clk:
  762. clk_disable_unprepare(qmp->pipe_clk);
  763. return ret;
  764. }
  765. static int qmp_usb_legacy_power_off(struct phy *phy)
  766. {
  767. struct qmp_usb *qmp = phy_get_drvdata(phy);
  768. const struct qmp_phy_cfg *cfg = qmp->cfg;
  769. clk_disable_unprepare(qmp->pipe_clk);
  770. /* PHY reset */
  771. qphy_setbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
  772. /* stop SerDes and Phy-Coding-Sublayer */
  773. qphy_clrbits(qmp->pcs, cfg->regs[QPHY_START_CTRL],
  774. SERDES_START | PCS_START);
  775. /* Put PHY into POWER DOWN state: active low */
  776. qphy_clrbits(qmp->pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL],
  777. SW_PWRDN);
  778. return 0;
  779. }
  780. static int qmp_usb_legacy_enable(struct phy *phy)
  781. {
  782. int ret;
  783. ret = qmp_usb_legacy_init(phy);
  784. if (ret)
  785. return ret;
  786. ret = qmp_usb_legacy_power_on(phy);
  787. if (ret)
  788. qmp_usb_legacy_exit(phy);
  789. return ret;
  790. }
  791. static int qmp_usb_legacy_disable(struct phy *phy)
  792. {
  793. int ret;
  794. ret = qmp_usb_legacy_power_off(phy);
  795. if (ret)
  796. return ret;
  797. return qmp_usb_legacy_exit(phy);
  798. }
  799. static int qmp_usb_legacy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
  800. {
  801. struct qmp_usb *qmp = phy_get_drvdata(phy);
  802. qmp->mode = mode;
  803. return 0;
  804. }
  805. static const struct phy_ops qmp_usb_legacy_phy_ops = {
  806. .init = qmp_usb_legacy_enable,
  807. .exit = qmp_usb_legacy_disable,
  808. .set_mode = qmp_usb_legacy_set_mode,
  809. .owner = THIS_MODULE,
  810. };
  811. static void qmp_usb_legacy_enable_autonomous_mode(struct qmp_usb *qmp)
  812. {
  813. const struct qmp_phy_cfg *cfg = qmp->cfg;
  814. void __iomem *pcs_usb = qmp->pcs_usb ?: qmp->pcs;
  815. void __iomem *pcs_misc = qmp->pcs_misc;
  816. u32 intr_mask;
  817. if (qmp->mode == PHY_MODE_USB_HOST_SS ||
  818. qmp->mode == PHY_MODE_USB_DEVICE_SS)
  819. intr_mask = ARCVR_DTCT_EN | ALFPS_DTCT_EN;
  820. else
  821. intr_mask = ARCVR_DTCT_EN | ARCVR_DTCT_EVENT_SEL;
  822. /* Clear any pending interrupts status */
  823. qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  824. /* Writing 1 followed by 0 clears the interrupt */
  825. qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  826. qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
  827. ARCVR_DTCT_EN | ALFPS_DTCT_EN | ARCVR_DTCT_EVENT_SEL);
  828. /* Enable required PHY autonomous mode interrupts */
  829. qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], intr_mask);
  830. /* Enable i/o clamp_n for autonomous mode */
  831. if (pcs_misc)
  832. qphy_clrbits(pcs_misc, QPHY_V3_PCS_MISC_CLAMP_ENABLE, CLAMP_EN);
  833. }
  834. static void qmp_usb_legacy_disable_autonomous_mode(struct qmp_usb *qmp)
  835. {
  836. const struct qmp_phy_cfg *cfg = qmp->cfg;
  837. void __iomem *pcs_usb = qmp->pcs_usb ?: qmp->pcs;
  838. void __iomem *pcs_misc = qmp->pcs_misc;
  839. /* Disable i/o clamp_n on resume for normal mode */
  840. if (pcs_misc)
  841. qphy_setbits(pcs_misc, QPHY_V3_PCS_MISC_CLAMP_ENABLE, CLAMP_EN);
  842. qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
  843. ARCVR_DTCT_EN | ARCVR_DTCT_EVENT_SEL | ALFPS_DTCT_EN);
  844. qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  845. /* Writing 1 followed by 0 clears the interrupt */
  846. qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  847. }
  848. static int __maybe_unused qmp_usb_legacy_runtime_suspend(struct device *dev)
  849. {
  850. struct qmp_usb *qmp = dev_get_drvdata(dev);
  851. const struct qmp_phy_cfg *cfg = qmp->cfg;
  852. dev_vdbg(dev, "Suspending QMP phy, mode:%d\n", qmp->mode);
  853. if (!qmp->phy->init_count) {
  854. dev_vdbg(dev, "PHY not initialized, bailing out\n");
  855. return 0;
  856. }
  857. qmp_usb_legacy_enable_autonomous_mode(qmp);
  858. clk_disable_unprepare(qmp->pipe_clk);
  859. clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
  860. return 0;
  861. }
  862. static int __maybe_unused qmp_usb_legacy_runtime_resume(struct device *dev)
  863. {
  864. struct qmp_usb *qmp = dev_get_drvdata(dev);
  865. const struct qmp_phy_cfg *cfg = qmp->cfg;
  866. int ret = 0;
  867. dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->mode);
  868. if (!qmp->phy->init_count) {
  869. dev_vdbg(dev, "PHY not initialized, bailing out\n");
  870. return 0;
  871. }
  872. ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
  873. if (ret)
  874. return ret;
  875. ret = clk_prepare_enable(qmp->pipe_clk);
  876. if (ret) {
  877. dev_err(dev, "pipe_clk enable failed, err=%d\n", ret);
  878. clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
  879. return ret;
  880. }
  881. qmp_usb_legacy_disable_autonomous_mode(qmp);
  882. return 0;
  883. }
  884. static const struct dev_pm_ops qmp_usb_legacy_pm_ops = {
  885. SET_RUNTIME_PM_OPS(qmp_usb_legacy_runtime_suspend,
  886. qmp_usb_legacy_runtime_resume, NULL)
  887. };
  888. static int qmp_usb_legacy_vreg_init(struct qmp_usb *qmp)
  889. {
  890. const struct qmp_phy_cfg *cfg = qmp->cfg;
  891. struct device *dev = qmp->dev;
  892. int num = cfg->num_vregs;
  893. int i;
  894. qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL);
  895. if (!qmp->vregs)
  896. return -ENOMEM;
  897. for (i = 0; i < num; i++)
  898. qmp->vregs[i].supply = cfg->vreg_list[i];
  899. return devm_regulator_bulk_get(dev, num, qmp->vregs);
  900. }
  901. static int qmp_usb_legacy_reset_init(struct qmp_usb *qmp)
  902. {
  903. const struct qmp_phy_cfg *cfg = qmp->cfg;
  904. struct device *dev = qmp->dev;
  905. int i;
  906. int ret;
  907. qmp->resets = devm_kcalloc(dev, cfg->num_resets,
  908. sizeof(*qmp->resets), GFP_KERNEL);
  909. if (!qmp->resets)
  910. return -ENOMEM;
  911. for (i = 0; i < cfg->num_resets; i++)
  912. qmp->resets[i].id = cfg->reset_list[i];
  913. ret = devm_reset_control_bulk_get_exclusive(dev, cfg->num_resets, qmp->resets);
  914. if (ret)
  915. return dev_err_probe(dev, ret, "failed to get resets\n");
  916. return 0;
  917. }
  918. static int qmp_usb_legacy_clk_init(struct qmp_usb *qmp)
  919. {
  920. const struct qmp_phy_cfg *cfg = qmp->cfg;
  921. struct device *dev = qmp->dev;
  922. int num = cfg->num_clks;
  923. int i;
  924. qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL);
  925. if (!qmp->clks)
  926. return -ENOMEM;
  927. for (i = 0; i < num; i++)
  928. qmp->clks[i].id = cfg->clk_list[i];
  929. return devm_clk_bulk_get(dev, num, qmp->clks);
  930. }
  931. static void phy_clk_release_provider(void *res)
  932. {
  933. of_clk_del_provider(res);
  934. }
  935. /*
  936. * Register a fixed rate pipe clock.
  937. *
  938. * The <s>_pipe_clksrc generated by PHY goes to the GCC that gate
  939. * controls it. The <s>_pipe_clk coming out of the GCC is requested
  940. * by the PHY driver for its operations.
  941. * We register the <s>_pipe_clksrc here. The gcc driver takes care
  942. * of assigning this <s>_pipe_clksrc as parent to <s>_pipe_clk.
  943. * Below picture shows this relationship.
  944. *
  945. * +---------------+
  946. * | PHY block |<<---------------------------------------+
  947. * | | |
  948. * | +-------+ | +-----+ |
  949. * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
  950. * clk | +-------+ | +-----+
  951. * +---------------+
  952. */
  953. static int phy_pipe_clk_register(struct qmp_usb *qmp, struct device_node *np)
  954. {
  955. struct clk_fixed_rate *fixed = &qmp->pipe_clk_fixed;
  956. struct clk_init_data init = { };
  957. int ret;
  958. ret = of_property_read_string(np, "clock-output-names", &init.name);
  959. if (ret) {
  960. dev_err(qmp->dev, "%pOFn: No clock-output-names\n", np);
  961. return ret;
  962. }
  963. init.ops = &clk_fixed_rate_ops;
  964. /* controllers using QMP phys use 125MHz pipe clock interface */
  965. fixed->fixed_rate = 125000000;
  966. fixed->hw.init = &init;
  967. ret = devm_clk_hw_register(qmp->dev, &fixed->hw);
  968. if (ret)
  969. return ret;
  970. ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &fixed->hw);
  971. if (ret)
  972. return ret;
  973. /*
  974. * Roll a devm action because the clock provider is the child node, but
  975. * the child node is not actually a device.
  976. */
  977. return devm_add_action_or_reset(qmp->dev, phy_clk_release_provider, np);
  978. }
  979. static int qmp_usb_legacy_parse_dt_legacy(struct qmp_usb *qmp, struct device_node *np)
  980. {
  981. struct platform_device *pdev = to_platform_device(qmp->dev);
  982. const struct qmp_phy_cfg *cfg = qmp->cfg;
  983. struct device *dev = qmp->dev;
  984. qmp->serdes = devm_platform_ioremap_resource(pdev, 0);
  985. if (IS_ERR(qmp->serdes))
  986. return PTR_ERR(qmp->serdes);
  987. qmp->dp_com = devm_platform_ioremap_resource(pdev, 1);
  988. if (IS_ERR(qmp->dp_com))
  989. return PTR_ERR(qmp->dp_com);
  990. /*
  991. * Get memory resources for the PHY:
  992. * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2.
  993. * For dual lane PHYs: tx2 -> 3, rx2 -> 4, pcs_misc (optional) -> 5
  994. * For single lane PHYs: pcs_misc (optional) -> 3.
  995. */
  996. qmp->tx = devm_of_iomap(dev, np, 0, NULL);
  997. if (IS_ERR(qmp->tx))
  998. return PTR_ERR(qmp->tx);
  999. qmp->rx = devm_of_iomap(dev, np, 1, NULL);
  1000. if (IS_ERR(qmp->rx))
  1001. return PTR_ERR(qmp->rx);
  1002. qmp->pcs = devm_of_iomap(dev, np, 2, NULL);
  1003. if (IS_ERR(qmp->pcs))
  1004. return PTR_ERR(qmp->pcs);
  1005. if (cfg->pcs_usb_offset)
  1006. qmp->pcs_usb = qmp->pcs + cfg->pcs_usb_offset;
  1007. qmp->tx2 = devm_of_iomap(dev, np, 3, NULL);
  1008. if (IS_ERR(qmp->tx2))
  1009. return PTR_ERR(qmp->tx2);
  1010. qmp->rx2 = devm_of_iomap(dev, np, 4, NULL);
  1011. if (IS_ERR(qmp->rx2))
  1012. return PTR_ERR(qmp->rx2);
  1013. qmp->pcs_misc = devm_of_iomap(dev, np, 5, NULL);
  1014. if (IS_ERR(qmp->pcs_misc)) {
  1015. dev_vdbg(dev, "PHY pcs_misc-reg not used\n");
  1016. qmp->pcs_misc = NULL;
  1017. }
  1018. qmp->pipe_clk = devm_get_clk_from_child(dev, np, NULL);
  1019. if (IS_ERR(qmp->pipe_clk)) {
  1020. return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
  1021. "failed to get pipe clock\n");
  1022. }
  1023. return 0;
  1024. }
  1025. static int qmp_usb_legacy_parse_dt(struct qmp_usb *qmp)
  1026. {
  1027. struct platform_device *pdev = to_platform_device(qmp->dev);
  1028. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1029. const struct qmp_usb_legacy_offsets *offs = cfg->offsets;
  1030. struct device *dev = qmp->dev;
  1031. void __iomem *base;
  1032. if (!offs)
  1033. return -EINVAL;
  1034. base = devm_platform_ioremap_resource(pdev, 0);
  1035. if (IS_ERR(base))
  1036. return PTR_ERR(base);
  1037. qmp->serdes = base + offs->serdes;
  1038. qmp->pcs = base + offs->pcs;
  1039. qmp->pcs_usb = base + offs->pcs_usb;
  1040. qmp->tx = base + offs->tx;
  1041. qmp->rx = base + offs->rx;
  1042. qmp->pipe_clk = devm_clk_get(dev, "pipe");
  1043. if (IS_ERR(qmp->pipe_clk)) {
  1044. return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
  1045. "failed to get pipe clock\n");
  1046. }
  1047. return 0;
  1048. }
  1049. static int qmp_usb_legacy_probe(struct platform_device *pdev)
  1050. {
  1051. struct device *dev = &pdev->dev;
  1052. struct phy_provider *phy_provider;
  1053. struct device_node *np;
  1054. struct qmp_usb *qmp;
  1055. int ret;
  1056. qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL);
  1057. if (!qmp)
  1058. return -ENOMEM;
  1059. qmp->dev = dev;
  1060. dev_set_drvdata(dev, qmp);
  1061. qmp->cfg = of_device_get_match_data(dev);
  1062. if (!qmp->cfg)
  1063. return -EINVAL;
  1064. ret = qmp_usb_legacy_clk_init(qmp);
  1065. if (ret)
  1066. return ret;
  1067. ret = qmp_usb_legacy_reset_init(qmp);
  1068. if (ret)
  1069. return ret;
  1070. ret = qmp_usb_legacy_vreg_init(qmp);
  1071. if (ret)
  1072. return ret;
  1073. /* Check for legacy binding with child node. */
  1074. np = of_get_next_available_child(dev->of_node, NULL);
  1075. if (np) {
  1076. ret = qmp_usb_legacy_parse_dt_legacy(qmp, np);
  1077. } else {
  1078. np = of_node_get(dev->of_node);
  1079. ret = qmp_usb_legacy_parse_dt(qmp);
  1080. }
  1081. if (ret)
  1082. goto err_node_put;
  1083. pm_runtime_set_active(dev);
  1084. ret = devm_pm_runtime_enable(dev);
  1085. if (ret)
  1086. goto err_node_put;
  1087. /*
  1088. * Prevent runtime pm from being ON by default. Users can enable
  1089. * it using power/control in sysfs.
  1090. */
  1091. pm_runtime_forbid(dev);
  1092. ret = phy_pipe_clk_register(qmp, np);
  1093. if (ret)
  1094. goto err_node_put;
  1095. qmp->phy = devm_phy_create(dev, np, &qmp_usb_legacy_phy_ops);
  1096. if (IS_ERR(qmp->phy)) {
  1097. ret = PTR_ERR(qmp->phy);
  1098. dev_err(dev, "failed to create PHY: %d\n", ret);
  1099. goto err_node_put;
  1100. }
  1101. phy_set_drvdata(qmp->phy, qmp);
  1102. of_node_put(np);
  1103. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  1104. return PTR_ERR_OR_ZERO(phy_provider);
  1105. err_node_put:
  1106. of_node_put(np);
  1107. return ret;
  1108. }
  1109. static const struct of_device_id qmp_usb_legacy_of_match_table[] = {
  1110. {
  1111. .compatible = "qcom,sc7180-qmp-usb3-phy",
  1112. .data = &sc7180_usb3phy_cfg,
  1113. }, {
  1114. .compatible = "qcom,sc8180x-qmp-usb3-phy",
  1115. .data = &sm8150_usb3phy_cfg,
  1116. }, {
  1117. .compatible = "qcom,sdm845-qmp-usb3-phy",
  1118. .data = &qmp_v3_usb3phy_cfg,
  1119. }, {
  1120. .compatible = "qcom,sm8150-qmp-usb3-phy",
  1121. .data = &sm8150_usb3phy_cfg,
  1122. }, {
  1123. .compatible = "qcom,sm8250-qmp-usb3-phy",
  1124. .data = &sm8250_usb3phy_cfg,
  1125. }, {
  1126. .compatible = "qcom,sm8350-qmp-usb3-phy",
  1127. .data = &sm8350_usb3phy_cfg,
  1128. }, {
  1129. .compatible = "qcom,sm8450-qmp-usb3-phy",
  1130. .data = &sm8350_usb3phy_cfg,
  1131. },
  1132. { },
  1133. };
  1134. MODULE_DEVICE_TABLE(of, qmp_usb_legacy_of_match_table);
  1135. static struct platform_driver qmp_usb_legacy_driver = {
  1136. .probe = qmp_usb_legacy_probe,
  1137. .driver = {
  1138. .name = "qcom-qmp-usb-legacy-phy",
  1139. .pm = &qmp_usb_legacy_pm_ops,
  1140. .of_match_table = qmp_usb_legacy_of_match_table,
  1141. },
  1142. };
  1143. module_platform_driver(qmp_usb_legacy_driver);
  1144. MODULE_AUTHOR("Vivek Gautam <vivek.gautam@codeaurora.org>");
  1145. MODULE_DESCRIPTION("Qualcomm QMP legacy USB+DP PHY driver");
  1146. MODULE_LICENSE("GPL v2");