phy-qcom-qmp.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  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 <dt-bindings/phy/phy.h>
  22. #include "phy-qcom-qmp.h"
  23. /* QPHY_SW_RESET bit */
  24. #define SW_RESET BIT(0)
  25. /* QPHY_POWER_DOWN_CONTROL */
  26. #define SW_PWRDN BIT(0)
  27. #define REFCLK_DRV_DSBL BIT(1)
  28. /* QPHY_START_CONTROL bits */
  29. #define SERDES_START BIT(0)
  30. #define PCS_START BIT(1)
  31. #define PLL_READY_GATE_EN BIT(3)
  32. /* QPHY_PCS_STATUS bit */
  33. #define PHYSTATUS BIT(6)
  34. /* QPHY_COM_PCS_READY_STATUS bit */
  35. #define PCS_READY BIT(0)
  36. /* QPHY_V3_DP_COM_RESET_OVRD_CTRL register bits */
  37. /* DP PHY soft reset */
  38. #define SW_DPPHY_RESET BIT(0)
  39. /* mux to select DP PHY reset control, 0:HW control, 1: software reset */
  40. #define SW_DPPHY_RESET_MUX BIT(1)
  41. /* USB3 PHY soft reset */
  42. #define SW_USB3PHY_RESET BIT(2)
  43. /* mux to select USB3 PHY reset control, 0:HW control, 1: software reset */
  44. #define SW_USB3PHY_RESET_MUX BIT(3)
  45. /* QPHY_V3_DP_COM_PHY_MODE_CTRL register bits */
  46. #define USB3_MODE BIT(0) /* enables USB3 mode */
  47. #define DP_MODE BIT(1) /* enables DP mode */
  48. /* QPHY_PCS_AUTONOMOUS_MODE_CTRL register bits */
  49. #define ARCVR_DTCT_EN BIT(0)
  50. #define ALFPS_DTCT_EN BIT(1)
  51. #define ARCVR_DTCT_EVENT_SEL BIT(4)
  52. /* QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR register bits */
  53. #define IRQ_CLEAR BIT(0)
  54. /* QPHY_PCS_LFPS_RXTERM_IRQ_STATUS register bits */
  55. #define RCVR_DETECT BIT(0)
  56. /* QPHY_V3_PCS_MISC_CLAMP_ENABLE register bits */
  57. #define CLAMP_EN BIT(0) /* enables i/o clamp_n */
  58. #define PHY_INIT_COMPLETE_TIMEOUT 10000
  59. #define POWER_DOWN_DELAY_US_MIN 10
  60. #define POWER_DOWN_DELAY_US_MAX 11
  61. #define MAX_PROP_NAME 32
  62. struct qmp_phy_init_tbl {
  63. unsigned int offset;
  64. unsigned int val;
  65. /*
  66. * register part of layout ?
  67. * if yes, then offset gives index in the reg-layout
  68. */
  69. int in_layout;
  70. };
  71. #define QMP_PHY_INIT_CFG(o, v) \
  72. { \
  73. .offset = o, \
  74. .val = v, \
  75. }
  76. #define QMP_PHY_INIT_CFG_L(o, v) \
  77. { \
  78. .offset = o, \
  79. .val = v, \
  80. .in_layout = 1, \
  81. }
  82. /* set of registers with offsets different per-PHY */
  83. enum qphy_reg_layout {
  84. /* Common block control registers */
  85. QPHY_COM_SW_RESET,
  86. QPHY_COM_POWER_DOWN_CONTROL,
  87. QPHY_COM_START_CONTROL,
  88. QPHY_COM_PCS_READY_STATUS,
  89. /* PCS registers */
  90. QPHY_PLL_LOCK_CHK_DLY_TIME,
  91. QPHY_FLL_CNTRL1,
  92. QPHY_FLL_CNTRL2,
  93. QPHY_FLL_CNT_VAL_L,
  94. QPHY_FLL_CNT_VAL_H_TOL,
  95. QPHY_FLL_MAN_CODE,
  96. QPHY_SW_RESET,
  97. QPHY_START_CTRL,
  98. QPHY_PCS_READY_STATUS,
  99. QPHY_PCS_AUTONOMOUS_MODE_CTRL,
  100. QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR,
  101. QPHY_PCS_LFPS_RXTERM_IRQ_STATUS,
  102. };
  103. static const unsigned int pciephy_regs_layout[] = {
  104. [QPHY_COM_SW_RESET] = 0x400,
  105. [QPHY_COM_POWER_DOWN_CONTROL] = 0x404,
  106. [QPHY_COM_START_CONTROL] = 0x408,
  107. [QPHY_COM_PCS_READY_STATUS] = 0x448,
  108. [QPHY_PLL_LOCK_CHK_DLY_TIME] = 0xa8,
  109. [QPHY_FLL_CNTRL1] = 0xc4,
  110. [QPHY_FLL_CNTRL2] = 0xc8,
  111. [QPHY_FLL_CNT_VAL_L] = 0xcc,
  112. [QPHY_FLL_CNT_VAL_H_TOL] = 0xd0,
  113. [QPHY_FLL_MAN_CODE] = 0xd4,
  114. [QPHY_SW_RESET] = 0x00,
  115. [QPHY_START_CTRL] = 0x08,
  116. [QPHY_PCS_READY_STATUS] = 0x174,
  117. };
  118. static const unsigned int usb3phy_regs_layout[] = {
  119. [QPHY_FLL_CNTRL1] = 0xc0,
  120. [QPHY_FLL_CNTRL2] = 0xc4,
  121. [QPHY_FLL_CNT_VAL_L] = 0xc8,
  122. [QPHY_FLL_CNT_VAL_H_TOL] = 0xcc,
  123. [QPHY_FLL_MAN_CODE] = 0xd0,
  124. [QPHY_SW_RESET] = 0x00,
  125. [QPHY_START_CTRL] = 0x08,
  126. [QPHY_PCS_READY_STATUS] = 0x17c,
  127. [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = 0x0d4,
  128. [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = 0x0d8,
  129. [QPHY_PCS_LFPS_RXTERM_IRQ_STATUS] = 0x178,
  130. };
  131. static const unsigned int qmp_v3_usb3phy_regs_layout[] = {
  132. [QPHY_SW_RESET] = 0x00,
  133. [QPHY_START_CTRL] = 0x08,
  134. [QPHY_PCS_READY_STATUS] = 0x174,
  135. [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = 0x0d8,
  136. [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = 0x0dc,
  137. [QPHY_PCS_LFPS_RXTERM_IRQ_STATUS] = 0x170,
  138. };
  139. static const struct qmp_phy_init_tbl msm8996_pcie_serdes_tbl[] = {
  140. QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x1c),
  141. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_ENABLE1, 0x10),
  142. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x33),
  143. QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x06),
  144. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x42),
  145. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x00),
  146. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0xff),
  147. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x1f),
  148. QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x01),
  149. QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x01),
  150. QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x00),
  151. QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0x0a),
  152. QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0x09),
  153. QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
  154. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x03),
  155. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x55),
  156. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x55),
  157. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x00),
  158. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0x1a),
  159. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0x0a),
  160. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x33),
  161. QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x02),
  162. QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_BUF_ENABLE, 0x1f),
  163. QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0x04),
  164. QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0x0b),
  165. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
  166. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
  167. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  168. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
  169. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_EN_CENTER, 0x01),
  170. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER1, 0x31),
  171. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER2, 0x01),
  172. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER1, 0x02),
  173. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER2, 0x00),
  174. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE1, 0x2f),
  175. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE2, 0x19),
  176. QMP_PHY_INIT_CFG(QSERDES_COM_RESCODE_DIV_NUM, 0x15),
  177. QMP_PHY_INIT_CFG(QSERDES_COM_BG_TRIM, 0x0f),
  178. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_IVCO, 0x0f),
  179. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_EP_DIV, 0x19),
  180. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_ENABLE1, 0x10),
  181. QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x00),
  182. QMP_PHY_INIT_CFG(QSERDES_COM_RESCODE_DIV_NUM, 0x40),
  183. };
  184. static const struct qmp_phy_init_tbl msm8996_pcie_tx_tbl[] = {
  185. QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
  186. QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x06),
  187. };
  188. static const struct qmp_phy_init_tbl msm8996_pcie_rx_tbl[] = {
  189. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_ENABLES, 0x1c),
  190. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x01),
  191. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3, 0x00),
  192. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4, 0xdb),
  193. QMP_PHY_INIT_CFG(QSERDES_RX_RX_BAND, 0x18),
  194. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_GAIN, 0x04),
  195. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_GAIN_HALF, 0x04),
  196. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
  197. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x14),
  198. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_LVL, 0x19),
  199. };
  200. static const struct qmp_phy_init_tbl msm8996_pcie_pcs_tbl[] = {
  201. QMP_PHY_INIT_CFG(QPHY_RX_IDLE_DTCT_CNTRL, 0x4c),
  202. QMP_PHY_INIT_CFG(QPHY_PWRUP_RESET_DLY_TIME_AUXCLK, 0x00),
  203. QMP_PHY_INIT_CFG(QPHY_LP_WAKEUP_DLY_TIME_AUXCLK, 0x01),
  204. QMP_PHY_INIT_CFG_L(QPHY_PLL_LOCK_CHK_DLY_TIME, 0x05),
  205. QMP_PHY_INIT_CFG(QPHY_ENDPOINT_REFCLK_DRIVE, 0x05),
  206. QMP_PHY_INIT_CFG(QPHY_POWER_DOWN_CONTROL, 0x02),
  207. QMP_PHY_INIT_CFG(QPHY_POWER_STATE_CONFIG4, 0x00),
  208. QMP_PHY_INIT_CFG(QPHY_POWER_STATE_CONFIG1, 0xa3),
  209. QMP_PHY_INIT_CFG(QPHY_TXDEEMPH_M3P5DB_V0, 0x0e),
  210. };
  211. static const struct qmp_phy_init_tbl msm8996_usb3_serdes_tbl[] = {
  212. QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0x14),
  213. QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
  214. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x30),
  215. QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x06),
  216. QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x01),
  217. QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x00),
  218. QMP_PHY_INIT_CFG(QSERDES_COM_BG_TRIM, 0x0f),
  219. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_IVCO, 0x0f),
  220. QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x04),
  221. /* PLL and Loop filter settings */
  222. QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
  223. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x55),
  224. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x55),
  225. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x03),
  226. QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0x0b),
  227. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
  228. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
  229. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
  230. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_CTRL, 0x00),
  231. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0x15),
  232. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0x34),
  233. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x00),
  234. QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x00),
  235. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_CFG, 0x00),
  236. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x00),
  237. QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0x0a),
  238. /* SSC settings */
  239. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_EN_CENTER, 0x01),
  240. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER1, 0x31),
  241. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER2, 0x01),
  242. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER1, 0x00),
  243. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER2, 0x00),
  244. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE1, 0xde),
  245. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE2, 0x07),
  246. };
  247. static const struct qmp_phy_init_tbl msm8996_usb3_tx_tbl[] = {
  248. QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
  249. QMP_PHY_INIT_CFG(QSERDES_TX_RCV_DETECT_LVL_2, 0x12),
  250. QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x06),
  251. };
  252. static const struct qmp_phy_init_tbl msm8996_usb3_rx_tbl[] = {
  253. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
  254. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_GAIN, 0x04),
  255. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x02),
  256. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4c),
  257. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4, 0xbb),
  258. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
  259. QMP_PHY_INIT_CFG(QSERDES_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x80),
  260. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_CNTRL, 0x03),
  261. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_LVL, 0x18),
  262. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x16),
  263. };
  264. static const struct qmp_phy_init_tbl msm8996_usb3_pcs_tbl[] = {
  265. /* FLL settings */
  266. QMP_PHY_INIT_CFG_L(QPHY_FLL_CNTRL2, 0x03),
  267. QMP_PHY_INIT_CFG_L(QPHY_FLL_CNTRL1, 0x02),
  268. QMP_PHY_INIT_CFG_L(QPHY_FLL_CNT_VAL_L, 0x09),
  269. QMP_PHY_INIT_CFG_L(QPHY_FLL_CNT_VAL_H_TOL, 0x42),
  270. QMP_PHY_INIT_CFG_L(QPHY_FLL_MAN_CODE, 0x85),
  271. /* Lock Det settings */
  272. QMP_PHY_INIT_CFG(QPHY_LOCK_DETECT_CONFIG1, 0xd1),
  273. QMP_PHY_INIT_CFG(QPHY_LOCK_DETECT_CONFIG2, 0x1f),
  274. QMP_PHY_INIT_CFG(QPHY_LOCK_DETECT_CONFIG3, 0x47),
  275. QMP_PHY_INIT_CFG(QPHY_POWER_STATE_CONFIG2, 0x08),
  276. };
  277. static const struct qmp_phy_init_tbl ipq8074_pcie_serdes_tbl[] = {
  278. QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x18),
  279. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_ENABLE1, 0x10),
  280. QMP_PHY_INIT_CFG(QSERDES_COM_BG_TRIM, 0xf),
  281. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x1),
  282. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x0),
  283. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0xff),
  284. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x1f),
  285. QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x6),
  286. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_IVCO, 0xf),
  287. QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x0),
  288. QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x1),
  289. QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x20),
  290. QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0xa),
  291. QMP_PHY_INIT_CFG(QSERDES_COM_RESETSM_CNTRL, 0x20),
  292. QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0xa),
  293. QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0xa),
  294. QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
  295. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x3),
  296. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x55),
  297. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x55),
  298. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x0),
  299. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0xD),
  300. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0xD04),
  301. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x33),
  302. QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x2),
  303. QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_BUF_ENABLE, 0x1f),
  304. QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0xb),
  305. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
  306. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
  307. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x0),
  308. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
  309. QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CTRL_BY_PSM, 0x1),
  310. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_EN_CENTER, 0x1),
  311. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER1, 0x31),
  312. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER2, 0x1),
  313. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER1, 0x2),
  314. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER2, 0x0),
  315. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE1, 0x2f),
  316. QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE2, 0x19),
  317. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_EP_DIV, 0x19),
  318. };
  319. static const struct qmp_phy_init_tbl ipq8074_pcie_tx_tbl[] = {
  320. QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
  321. QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x6),
  322. QMP_PHY_INIT_CFG(QSERDES_TX_RES_CODE_LANE_OFFSET, 0x2),
  323. QMP_PHY_INIT_CFG(QSERDES_TX_RCV_DETECT_LVL_2, 0x12),
  324. QMP_PHY_INIT_CFG(QSERDES_TX_EMP_POST1_LVL, 0x36),
  325. QMP_PHY_INIT_CFG(QSERDES_TX_SLEW_CNTL, 0x0a),
  326. };
  327. static const struct qmp_phy_init_tbl ipq8074_pcie_rx_tbl[] = {
  328. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_ENABLES, 0x1c),
  329. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x14),
  330. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x1),
  331. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3, 0x0),
  332. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4, 0xdb),
  333. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
  334. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_GAIN, 0x4),
  335. };
  336. static const struct qmp_phy_init_tbl ipq8074_pcie_pcs_tbl[] = {
  337. QMP_PHY_INIT_CFG(QPHY_ENDPOINT_REFCLK_DRIVE, 0x4),
  338. QMP_PHY_INIT_CFG(QPHY_OSC_DTCT_ACTIONS, 0x0),
  339. QMP_PHY_INIT_CFG(QPHY_PWRUP_RESET_DLY_TIME_AUXCLK, 0x40),
  340. QMP_PHY_INIT_CFG(QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_MSB, 0x0),
  341. QMP_PHY_INIT_CFG(QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_LSB, 0x40),
  342. QMP_PHY_INIT_CFG(QPHY_PLL_LOCK_CHK_DLY_TIME_AUXCLK_LSB, 0x0),
  343. QMP_PHY_INIT_CFG(QPHY_LP_WAKEUP_DLY_TIME_AUXCLK, 0x40),
  344. QMP_PHY_INIT_CFG_L(QPHY_PLL_LOCK_CHK_DLY_TIME, 0x73),
  345. QMP_PHY_INIT_CFG(QPHY_RX_SIGDET_LVL, 0x99),
  346. QMP_PHY_INIT_CFG(QPHY_TXDEEMPH_M6DB_V0, 0x15),
  347. QMP_PHY_INIT_CFG(QPHY_TXDEEMPH_M3P5DB_V0, 0xe),
  348. QMP_PHY_INIT_CFG_L(QPHY_SW_RESET, 0x0),
  349. QMP_PHY_INIT_CFG_L(QPHY_START_CTRL, 0x3),
  350. };
  351. static const struct qmp_phy_init_tbl qmp_v3_usb3_serdes_tbl[] = {
  352. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
  353. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0x14),
  354. QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
  355. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
  356. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
  357. QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL2, 0x08),
  358. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x16),
  359. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x01),
  360. QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x80),
  361. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82),
  362. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START1_MODE0, 0xab),
  363. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0xea),
  364. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x02),
  365. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
  366. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
  367. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
  368. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  369. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
  370. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01),
  371. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xc9),
  372. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORECLK_DIV_MODE0, 0x0a),
  373. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP3_MODE0, 0x00),
  374. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x34),
  375. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x15),
  376. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x04),
  377. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00),
  378. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_CFG, 0x00),
  379. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x00),
  380. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_BUF_ENABLE, 0x0a),
  381. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_EN_CENTER, 0x01),
  382. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER1, 0x31),
  383. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER2, 0x01),
  384. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER1, 0x00),
  385. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER2, 0x00),
  386. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE1, 0x85),
  387. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE2, 0x07),
  388. };
  389. static const struct qmp_phy_init_tbl qmp_v3_usb3_tx_tbl[] = {
  390. QMP_PHY_INIT_CFG(QSERDES_V3_TX_HIGHZ_DRVR_EN, 0x10),
  391. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RCV_DETECT_LVL_2, 0x12),
  392. QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0x16),
  393. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x09),
  394. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x06),
  395. };
  396. static const struct qmp_phy_init_tbl qmp_v3_usb3_rx_tbl[] = {
  397. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
  398. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
  399. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4e),
  400. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x18),
  401. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
  402. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x80),
  403. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x03),
  404. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x16),
  405. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x75),
  406. };
  407. static const struct qmp_phy_init_tbl qmp_v3_usb3_pcs_tbl[] = {
  408. /* FLL settings */
  409. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL2, 0x83),
  410. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_L, 0x09),
  411. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_H_TOL, 0xa2),
  412. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_MAN_CODE, 0x40),
  413. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL1, 0x02),
  414. /* Lock Det settings */
  415. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG1, 0xd1),
  416. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG2, 0x1f),
  417. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG3, 0x47),
  418. QMP_PHY_INIT_CFG(QPHY_V3_PCS_POWER_STATE_CONFIG2, 0x1b),
  419. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RX_SIGDET_LVL, 0xba),
  420. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V0, 0x9f),
  421. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V1, 0x9f),
  422. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V2, 0xb7),
  423. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V3, 0x4e),
  424. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V4, 0x65),
  425. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_LS, 0x6b),
  426. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V0, 0x15),
  427. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V0, 0x0d),
  428. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V1, 0x15),
  429. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V1, 0x0d),
  430. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V2, 0x15),
  431. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V2, 0x0d),
  432. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V3, 0x15),
  433. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V3, 0x1d),
  434. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V4, 0x15),
  435. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V4, 0x0d),
  436. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_LS, 0x15),
  437. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_LS, 0x0d),
  438. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RATE_SLEW_CNTRL, 0x02),
  439. QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
  440. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TSYNC_RSYNC_TIME, 0x44),
  441. QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
  442. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_L, 0xe7),
  443. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_H, 0x03),
  444. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_L, 0x40),
  445. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_H, 0x00),
  446. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_WAIT_TIME, 0x75),
  447. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LFPS_TX_ECSTART_EQTLOCK, 0x86),
  448. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_RUN_TIME, 0x13),
  449. };
  450. static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_serdes_tbl[] = {
  451. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
  452. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0x14),
  453. QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x04),
  454. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
  455. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
  456. QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL2, 0x08),
  457. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x06),
  458. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x01),
  459. QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x80),
  460. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82),
  461. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START1_MODE0, 0xab),
  462. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0xea),
  463. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x02),
  464. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
  465. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
  466. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
  467. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  468. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
  469. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01),
  470. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xc9),
  471. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORECLK_DIV_MODE0, 0x0a),
  472. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP3_MODE0, 0x00),
  473. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x34),
  474. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x15),
  475. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x04),
  476. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00),
  477. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_CFG, 0x00),
  478. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x00),
  479. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_BUF_ENABLE, 0x0a),
  480. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_EN_CENTER, 0x01),
  481. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER1, 0x31),
  482. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER2, 0x01),
  483. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER1, 0x00),
  484. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER2, 0x00),
  485. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE1, 0x85),
  486. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE2, 0x07),
  487. };
  488. static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_tx_tbl[] = {
  489. QMP_PHY_INIT_CFG(QSERDES_V3_TX_HIGHZ_DRVR_EN, 0x10),
  490. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RCV_DETECT_LVL_2, 0x12),
  491. QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0xc6),
  492. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x06),
  493. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x06),
  494. };
  495. static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_rx_tbl[] = {
  496. QMP_PHY_INIT_CFG(QSERDES_V3_RX_VGA_CAL_CNTRL2, 0x0c),
  497. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_MODE_00, 0x50),
  498. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
  499. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0e),
  500. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4e),
  501. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x18),
  502. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
  503. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x80),
  504. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x03),
  505. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x1c),
  506. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x75),
  507. };
  508. static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_pcs_tbl[] = {
  509. /* FLL settings */
  510. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL2, 0x83),
  511. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_L, 0x09),
  512. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_H_TOL, 0xa2),
  513. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_MAN_CODE, 0x40),
  514. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL1, 0x02),
  515. /* Lock Det settings */
  516. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG1, 0xd1),
  517. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG2, 0x1f),
  518. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG3, 0x47),
  519. QMP_PHY_INIT_CFG(QPHY_V3_PCS_POWER_STATE_CONFIG2, 0x1b),
  520. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RX_SIGDET_LVL, 0xba),
  521. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V0, 0x9f),
  522. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V1, 0x9f),
  523. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V2, 0xb5),
  524. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V3, 0x4c),
  525. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V4, 0x64),
  526. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_LS, 0x6a),
  527. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V0, 0x15),
  528. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V0, 0x0d),
  529. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V1, 0x15),
  530. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V1, 0x0d),
  531. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V2, 0x15),
  532. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V2, 0x0d),
  533. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V3, 0x15),
  534. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V3, 0x1d),
  535. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V4, 0x15),
  536. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V4, 0x0d),
  537. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_LS, 0x15),
  538. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_LS, 0x0d),
  539. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RATE_SLEW_CNTRL, 0x02),
  540. QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
  541. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TSYNC_RSYNC_TIME, 0x44),
  542. QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
  543. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_L, 0xe7),
  544. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_H, 0x03),
  545. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_L, 0x40),
  546. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_H, 0x00),
  547. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_WAIT_TIME, 0x75),
  548. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LFPS_TX_ECSTART_EQTLOCK, 0x86),
  549. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_RUN_TIME, 0x13),
  550. QMP_PHY_INIT_CFG(QPHY_V3_PCS_REFGEN_REQ_CONFIG1, 0x21),
  551. QMP_PHY_INIT_CFG(QPHY_V3_PCS_REFGEN_REQ_CONFIG2, 0x60),
  552. };
  553. /* struct qmp_phy_cfg - per-PHY initialization config */
  554. struct qmp_phy_cfg {
  555. /* phy-type - PCIE/UFS/USB */
  556. unsigned int type;
  557. /* number of lanes provided by phy */
  558. int nlanes;
  559. /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
  560. const struct qmp_phy_init_tbl *serdes_tbl;
  561. int serdes_tbl_num;
  562. const struct qmp_phy_init_tbl *tx_tbl;
  563. int tx_tbl_num;
  564. const struct qmp_phy_init_tbl *rx_tbl;
  565. int rx_tbl_num;
  566. const struct qmp_phy_init_tbl *pcs_tbl;
  567. int pcs_tbl_num;
  568. /* clock ids to be requested */
  569. const char * const *clk_list;
  570. int num_clks;
  571. /* resets to be requested */
  572. const char * const *reset_list;
  573. int num_resets;
  574. /* regulators to be requested */
  575. const char * const *vreg_list;
  576. int num_vregs;
  577. /* array of registers with different offsets */
  578. const unsigned int *regs;
  579. unsigned int start_ctrl;
  580. unsigned int pwrdn_ctrl;
  581. unsigned int mask_pcs_ready;
  582. unsigned int mask_com_pcs_ready;
  583. /* true, if PHY has a separate PHY_COM control block */
  584. bool has_phy_com_ctrl;
  585. /* true, if PHY has a reset for individual lanes */
  586. bool has_lane_rst;
  587. /* true, if PHY needs delay after POWER_DOWN */
  588. bool has_pwrdn_delay;
  589. /* power_down delay in usec */
  590. int pwrdn_delay_min;
  591. int pwrdn_delay_max;
  592. /* true, if PHY has a separate DP_COM control block */
  593. bool has_phy_dp_com_ctrl;
  594. /* Register offset of secondary tx/rx lanes for USB DP combo PHY */
  595. unsigned int tx_b_lane_offset;
  596. unsigned int rx_b_lane_offset;
  597. };
  598. /**
  599. * struct qmp_phy - per-lane phy descriptor
  600. *
  601. * @phy: generic phy
  602. * @tx: iomapped memory space for lane's tx
  603. * @rx: iomapped memory space for lane's rx
  604. * @pcs: iomapped memory space for lane's pcs
  605. * @pcs_misc: iomapped memory space for lane's pcs_misc
  606. * @pipe_clk: pipe lock
  607. * @index: lane index
  608. * @qmp: QMP phy to which this lane belongs
  609. * @lane_rst: lane's reset controller
  610. */
  611. struct qmp_phy {
  612. struct phy *phy;
  613. void __iomem *tx;
  614. void __iomem *rx;
  615. void __iomem *pcs;
  616. void __iomem *pcs_misc;
  617. struct clk *pipe_clk;
  618. unsigned int index;
  619. struct qcom_qmp *qmp;
  620. struct reset_control *lane_rst;
  621. };
  622. /**
  623. * struct qcom_qmp - structure holding QMP phy block attributes
  624. *
  625. * @dev: device
  626. * @serdes: iomapped memory space for phy's serdes
  627. * @dp_com: iomapped memory space for phy's dp_com control block
  628. *
  629. * @clks: array of clocks required by phy
  630. * @resets: array of resets required by phy
  631. * @vregs: regulator supplies bulk data
  632. *
  633. * @cfg: phy specific configuration
  634. * @phys: array of per-lane phy descriptors
  635. * @phy_mutex: mutex lock for PHY common block initialization
  636. * @init_count: phy common block initialization count
  637. * @phy_initialized: indicate if PHY has been initialized
  638. * @mode: current PHY mode
  639. */
  640. struct qcom_qmp {
  641. struct device *dev;
  642. void __iomem *serdes;
  643. void __iomem *dp_com;
  644. struct clk_bulk_data *clks;
  645. struct reset_control **resets;
  646. struct regulator_bulk_data *vregs;
  647. const struct qmp_phy_cfg *cfg;
  648. struct qmp_phy **phys;
  649. struct mutex phy_mutex;
  650. int init_count;
  651. bool phy_initialized;
  652. enum phy_mode mode;
  653. };
  654. static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
  655. {
  656. u32 reg;
  657. reg = readl(base + offset);
  658. reg |= val;
  659. writel(reg, base + offset);
  660. /* ensure that above write is through */
  661. readl(base + offset);
  662. }
  663. static inline void qphy_clrbits(void __iomem *base, u32 offset, u32 val)
  664. {
  665. u32 reg;
  666. reg = readl(base + offset);
  667. reg &= ~val;
  668. writel(reg, base + offset);
  669. /* ensure that above write is through */
  670. readl(base + offset);
  671. }
  672. /* list of clocks required by phy */
  673. static const char * const msm8996_phy_clk_l[] = {
  674. "aux", "cfg_ahb", "ref",
  675. };
  676. static const char * const qmp_v3_phy_clk_l[] = {
  677. "aux", "cfg_ahb", "ref", "com_aux",
  678. };
  679. /* list of resets */
  680. static const char * const msm8996_pciephy_reset_l[] = {
  681. "phy", "common", "cfg",
  682. };
  683. static const char * const msm8996_usb3phy_reset_l[] = {
  684. "phy", "common",
  685. };
  686. /* list of regulators */
  687. static const char * const msm8996_phy_vreg_l[] = {
  688. "vdda-phy", "vdda-pll",
  689. };
  690. static const struct qmp_phy_cfg msm8996_pciephy_cfg = {
  691. .type = PHY_TYPE_PCIE,
  692. .nlanes = 3,
  693. .serdes_tbl = msm8996_pcie_serdes_tbl,
  694. .serdes_tbl_num = ARRAY_SIZE(msm8996_pcie_serdes_tbl),
  695. .tx_tbl = msm8996_pcie_tx_tbl,
  696. .tx_tbl_num = ARRAY_SIZE(msm8996_pcie_tx_tbl),
  697. .rx_tbl = msm8996_pcie_rx_tbl,
  698. .rx_tbl_num = ARRAY_SIZE(msm8996_pcie_rx_tbl),
  699. .pcs_tbl = msm8996_pcie_pcs_tbl,
  700. .pcs_tbl_num = ARRAY_SIZE(msm8996_pcie_pcs_tbl),
  701. .clk_list = msm8996_phy_clk_l,
  702. .num_clks = ARRAY_SIZE(msm8996_phy_clk_l),
  703. .reset_list = msm8996_pciephy_reset_l,
  704. .num_resets = ARRAY_SIZE(msm8996_pciephy_reset_l),
  705. .vreg_list = msm8996_phy_vreg_l,
  706. .num_vregs = ARRAY_SIZE(msm8996_phy_vreg_l),
  707. .regs = pciephy_regs_layout,
  708. .start_ctrl = PCS_START | PLL_READY_GATE_EN,
  709. .pwrdn_ctrl = SW_PWRDN | REFCLK_DRV_DSBL,
  710. .mask_com_pcs_ready = PCS_READY,
  711. .has_phy_com_ctrl = true,
  712. .has_lane_rst = true,
  713. .has_pwrdn_delay = true,
  714. .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
  715. .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
  716. };
  717. static const struct qmp_phy_cfg msm8996_usb3phy_cfg = {
  718. .type = PHY_TYPE_USB3,
  719. .nlanes = 1,
  720. .serdes_tbl = msm8996_usb3_serdes_tbl,
  721. .serdes_tbl_num = ARRAY_SIZE(msm8996_usb3_serdes_tbl),
  722. .tx_tbl = msm8996_usb3_tx_tbl,
  723. .tx_tbl_num = ARRAY_SIZE(msm8996_usb3_tx_tbl),
  724. .rx_tbl = msm8996_usb3_rx_tbl,
  725. .rx_tbl_num = ARRAY_SIZE(msm8996_usb3_rx_tbl),
  726. .pcs_tbl = msm8996_usb3_pcs_tbl,
  727. .pcs_tbl_num = ARRAY_SIZE(msm8996_usb3_pcs_tbl),
  728. .clk_list = msm8996_phy_clk_l,
  729. .num_clks = ARRAY_SIZE(msm8996_phy_clk_l),
  730. .reset_list = msm8996_usb3phy_reset_l,
  731. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  732. .vreg_list = msm8996_phy_vreg_l,
  733. .num_vregs = ARRAY_SIZE(msm8996_phy_vreg_l),
  734. .regs = usb3phy_regs_layout,
  735. .start_ctrl = SERDES_START | PCS_START,
  736. .pwrdn_ctrl = SW_PWRDN,
  737. .mask_pcs_ready = PHYSTATUS,
  738. };
  739. static const char * const ipq8074_pciephy_clk_l[] = {
  740. "aux", "cfg_ahb",
  741. };
  742. /* list of resets */
  743. static const char * const ipq8074_pciephy_reset_l[] = {
  744. "phy", "common",
  745. };
  746. static const struct qmp_phy_cfg ipq8074_pciephy_cfg = {
  747. .type = PHY_TYPE_PCIE,
  748. .nlanes = 1,
  749. .serdes_tbl = ipq8074_pcie_serdes_tbl,
  750. .serdes_tbl_num = ARRAY_SIZE(ipq8074_pcie_serdes_tbl),
  751. .tx_tbl = ipq8074_pcie_tx_tbl,
  752. .tx_tbl_num = ARRAY_SIZE(ipq8074_pcie_tx_tbl),
  753. .rx_tbl = ipq8074_pcie_rx_tbl,
  754. .rx_tbl_num = ARRAY_SIZE(ipq8074_pcie_rx_tbl),
  755. .pcs_tbl = ipq8074_pcie_pcs_tbl,
  756. .pcs_tbl_num = ARRAY_SIZE(ipq8074_pcie_pcs_tbl),
  757. .clk_list = ipq8074_pciephy_clk_l,
  758. .num_clks = ARRAY_SIZE(ipq8074_pciephy_clk_l),
  759. .reset_list = ipq8074_pciephy_reset_l,
  760. .num_resets = ARRAY_SIZE(ipq8074_pciephy_reset_l),
  761. .vreg_list = NULL,
  762. .num_vregs = 0,
  763. .regs = pciephy_regs_layout,
  764. .start_ctrl = SERDES_START | PCS_START,
  765. .pwrdn_ctrl = SW_PWRDN | REFCLK_DRV_DSBL,
  766. .mask_pcs_ready = PHYSTATUS,
  767. .has_phy_com_ctrl = false,
  768. .has_lane_rst = false,
  769. .has_pwrdn_delay = true,
  770. .pwrdn_delay_min = 995, /* us */
  771. .pwrdn_delay_max = 1005, /* us */
  772. };
  773. static const struct qmp_phy_cfg qmp_v3_usb3phy_cfg = {
  774. .type = PHY_TYPE_USB3,
  775. .nlanes = 1,
  776. .serdes_tbl = qmp_v3_usb3_serdes_tbl,
  777. .serdes_tbl_num = ARRAY_SIZE(qmp_v3_usb3_serdes_tbl),
  778. .tx_tbl = qmp_v3_usb3_tx_tbl,
  779. .tx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_tx_tbl),
  780. .rx_tbl = qmp_v3_usb3_rx_tbl,
  781. .rx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_rx_tbl),
  782. .pcs_tbl = qmp_v3_usb3_pcs_tbl,
  783. .pcs_tbl_num = ARRAY_SIZE(qmp_v3_usb3_pcs_tbl),
  784. .clk_list = qmp_v3_phy_clk_l,
  785. .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
  786. .reset_list = msm8996_usb3phy_reset_l,
  787. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  788. .vreg_list = msm8996_phy_vreg_l,
  789. .num_vregs = ARRAY_SIZE(msm8996_phy_vreg_l),
  790. .regs = qmp_v3_usb3phy_regs_layout,
  791. .start_ctrl = SERDES_START | PCS_START,
  792. .pwrdn_ctrl = SW_PWRDN,
  793. .mask_pcs_ready = PHYSTATUS,
  794. .has_pwrdn_delay = true,
  795. .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
  796. .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
  797. .has_phy_dp_com_ctrl = true,
  798. .tx_b_lane_offset = 0x400,
  799. .rx_b_lane_offset = 0x400,
  800. };
  801. static const struct qmp_phy_cfg qmp_v3_usb3_uniphy_cfg = {
  802. .type = PHY_TYPE_USB3,
  803. .nlanes = 1,
  804. .serdes_tbl = qmp_v3_usb3_uniphy_serdes_tbl,
  805. .serdes_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_serdes_tbl),
  806. .tx_tbl = qmp_v3_usb3_uniphy_tx_tbl,
  807. .tx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_tx_tbl),
  808. .rx_tbl = qmp_v3_usb3_uniphy_rx_tbl,
  809. .rx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_rx_tbl),
  810. .pcs_tbl = qmp_v3_usb3_uniphy_pcs_tbl,
  811. .pcs_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_pcs_tbl),
  812. .clk_list = qmp_v3_phy_clk_l,
  813. .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
  814. .reset_list = msm8996_usb3phy_reset_l,
  815. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  816. .vreg_list = msm8996_phy_vreg_l,
  817. .num_vregs = ARRAY_SIZE(msm8996_phy_vreg_l),
  818. .regs = qmp_v3_usb3phy_regs_layout,
  819. .start_ctrl = SERDES_START | PCS_START,
  820. .pwrdn_ctrl = SW_PWRDN,
  821. .mask_pcs_ready = PHYSTATUS,
  822. .has_pwrdn_delay = true,
  823. .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
  824. .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
  825. };
  826. static void qcom_qmp_phy_configure(void __iomem *base,
  827. const unsigned int *regs,
  828. const struct qmp_phy_init_tbl tbl[],
  829. int num)
  830. {
  831. int i;
  832. const struct qmp_phy_init_tbl *t = tbl;
  833. if (!t)
  834. return;
  835. for (i = 0; i < num; i++, t++) {
  836. if (t->in_layout)
  837. writel(t->val, base + regs[t->offset]);
  838. else
  839. writel(t->val, base + t->offset);
  840. }
  841. }
  842. static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
  843. {
  844. const struct qmp_phy_cfg *cfg = qmp->cfg;
  845. void __iomem *serdes = qmp->serdes;
  846. void __iomem *dp_com = qmp->dp_com;
  847. int ret, i;
  848. mutex_lock(&qmp->phy_mutex);
  849. if (qmp->init_count++) {
  850. mutex_unlock(&qmp->phy_mutex);
  851. return 0;
  852. }
  853. /* turn on regulator supplies */
  854. ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
  855. if (ret) {
  856. dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret);
  857. goto err_reg_enable;
  858. }
  859. for (i = 0; i < cfg->num_resets; i++) {
  860. ret = reset_control_assert(qmp->resets[i]);
  861. if (ret) {
  862. dev_err(qmp->dev, "%s reset assert failed\n",
  863. cfg->reset_list[i]);
  864. goto err_rst_assert;
  865. }
  866. }
  867. for (i = cfg->num_resets - 1; i >= 0; i--) {
  868. ret = reset_control_deassert(qmp->resets[i]);
  869. if (ret) {
  870. dev_err(qmp->dev, "%s reset deassert failed\n",
  871. qmp->cfg->reset_list[i]);
  872. goto err_rst;
  873. }
  874. }
  875. ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
  876. if (ret) {
  877. dev_err(qmp->dev, "failed to enable clks, err=%d\n", ret);
  878. goto err_rst;
  879. }
  880. if (cfg->has_phy_com_ctrl)
  881. qphy_setbits(serdes, cfg->regs[QPHY_COM_POWER_DOWN_CONTROL],
  882. SW_PWRDN);
  883. if (cfg->has_phy_dp_com_ctrl) {
  884. qphy_setbits(dp_com, QPHY_V3_DP_COM_POWER_DOWN_CTRL,
  885. SW_PWRDN);
  886. /* override hardware control for reset of qmp phy */
  887. qphy_setbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
  888. SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
  889. SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
  890. qphy_setbits(dp_com, QPHY_V3_DP_COM_PHY_MODE_CTRL,
  891. USB3_MODE | DP_MODE);
  892. /* bring both QMP USB and QMP DP PHYs PCS block out of reset */
  893. qphy_clrbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
  894. SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
  895. SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
  896. }
  897. /* Serdes configuration */
  898. qcom_qmp_phy_configure(serdes, cfg->regs, cfg->serdes_tbl,
  899. cfg->serdes_tbl_num);
  900. if (cfg->has_phy_com_ctrl) {
  901. void __iomem *status;
  902. unsigned int mask, val;
  903. qphy_clrbits(serdes, cfg->regs[QPHY_COM_SW_RESET], SW_RESET);
  904. qphy_setbits(serdes, cfg->regs[QPHY_COM_START_CONTROL],
  905. SERDES_START | PCS_START);
  906. status = serdes + cfg->regs[QPHY_COM_PCS_READY_STATUS];
  907. mask = cfg->mask_com_pcs_ready;
  908. ret = readl_poll_timeout(status, val, (val & mask), 10,
  909. PHY_INIT_COMPLETE_TIMEOUT);
  910. if (ret) {
  911. dev_err(qmp->dev,
  912. "phy common block init timed-out\n");
  913. goto err_com_init;
  914. }
  915. }
  916. mutex_unlock(&qmp->phy_mutex);
  917. return 0;
  918. err_com_init:
  919. clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
  920. err_rst:
  921. while (++i < cfg->num_resets)
  922. reset_control_assert(qmp->resets[i]);
  923. err_rst_assert:
  924. regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
  925. err_reg_enable:
  926. mutex_unlock(&qmp->phy_mutex);
  927. return ret;
  928. }
  929. static int qcom_qmp_phy_com_exit(struct qcom_qmp *qmp)
  930. {
  931. const struct qmp_phy_cfg *cfg = qmp->cfg;
  932. void __iomem *serdes = qmp->serdes;
  933. int i = cfg->num_resets;
  934. mutex_lock(&qmp->phy_mutex);
  935. if (--qmp->init_count) {
  936. mutex_unlock(&qmp->phy_mutex);
  937. return 0;
  938. }
  939. if (cfg->has_phy_com_ctrl) {
  940. qphy_setbits(serdes, cfg->regs[QPHY_COM_START_CONTROL],
  941. SERDES_START | PCS_START);
  942. qphy_clrbits(serdes, cfg->regs[QPHY_COM_SW_RESET],
  943. SW_RESET);
  944. qphy_setbits(serdes, cfg->regs[QPHY_COM_POWER_DOWN_CONTROL],
  945. SW_PWRDN);
  946. }
  947. while (--i >= 0)
  948. reset_control_assert(qmp->resets[i]);
  949. clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
  950. regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
  951. mutex_unlock(&qmp->phy_mutex);
  952. return 0;
  953. }
  954. /* PHY Initialization */
  955. static int qcom_qmp_phy_init(struct phy *phy)
  956. {
  957. struct qmp_phy *qphy = phy_get_drvdata(phy);
  958. struct qcom_qmp *qmp = qphy->qmp;
  959. const struct qmp_phy_cfg *cfg = qmp->cfg;
  960. void __iomem *tx = qphy->tx;
  961. void __iomem *rx = qphy->rx;
  962. void __iomem *pcs = qphy->pcs;
  963. void __iomem *dp_com = qmp->dp_com;
  964. void __iomem *status;
  965. unsigned int mask, val;
  966. int ret;
  967. dev_vdbg(qmp->dev, "Initializing QMP phy\n");
  968. ret = qcom_qmp_phy_com_init(qmp);
  969. if (ret)
  970. return ret;
  971. if (cfg->has_lane_rst) {
  972. ret = reset_control_deassert(qphy->lane_rst);
  973. if (ret) {
  974. dev_err(qmp->dev, "lane%d reset deassert failed\n",
  975. qphy->index);
  976. goto err_lane_rst;
  977. }
  978. }
  979. ret = clk_prepare_enable(qphy->pipe_clk);
  980. if (ret) {
  981. dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
  982. goto err_clk_enable;
  983. }
  984. /* Tx, Rx, and PCS configurations */
  985. qcom_qmp_phy_configure(tx, cfg->regs, cfg->tx_tbl, cfg->tx_tbl_num);
  986. /* Configuration for other LANE for USB-DP combo PHY */
  987. if (cfg->has_phy_dp_com_ctrl)
  988. qcom_qmp_phy_configure(tx + cfg->tx_b_lane_offset, cfg->regs,
  989. cfg->tx_tbl, cfg->tx_tbl_num);
  990. qcom_qmp_phy_configure(rx, cfg->regs, cfg->rx_tbl, cfg->rx_tbl_num);
  991. if (cfg->has_phy_dp_com_ctrl)
  992. qcom_qmp_phy_configure(rx + cfg->rx_b_lane_offset, cfg->regs,
  993. cfg->rx_tbl, cfg->rx_tbl_num);
  994. qcom_qmp_phy_configure(pcs, cfg->regs, cfg->pcs_tbl, cfg->pcs_tbl_num);
  995. /*
  996. * Pull out PHY from POWER DOWN state.
  997. * This is active low enable signal to power-down PHY.
  998. */
  999. qphy_setbits(pcs, QPHY_POWER_DOWN_CONTROL, cfg->pwrdn_ctrl);
  1000. if (cfg->has_pwrdn_delay)
  1001. usleep_range(cfg->pwrdn_delay_min, cfg->pwrdn_delay_max);
  1002. /* Pull PHY out of reset state */
  1003. qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
  1004. if (cfg->has_phy_dp_com_ctrl)
  1005. qphy_clrbits(dp_com, QPHY_V3_DP_COM_SW_RESET, SW_RESET);
  1006. /* start SerDes and Phy-Coding-Sublayer */
  1007. qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], cfg->start_ctrl);
  1008. status = pcs + cfg->regs[QPHY_PCS_READY_STATUS];
  1009. mask = cfg->mask_pcs_ready;
  1010. ret = readl_poll_timeout(status, val, !(val & mask), 1,
  1011. PHY_INIT_COMPLETE_TIMEOUT);
  1012. if (ret) {
  1013. dev_err(qmp->dev, "phy initialization timed-out\n");
  1014. goto err_pcs_ready;
  1015. }
  1016. qmp->phy_initialized = true;
  1017. return ret;
  1018. err_pcs_ready:
  1019. clk_disable_unprepare(qphy->pipe_clk);
  1020. err_clk_enable:
  1021. if (cfg->has_lane_rst)
  1022. reset_control_assert(qphy->lane_rst);
  1023. err_lane_rst:
  1024. qcom_qmp_phy_com_exit(qmp);
  1025. return ret;
  1026. }
  1027. static int qcom_qmp_phy_exit(struct phy *phy)
  1028. {
  1029. struct qmp_phy *qphy = phy_get_drvdata(phy);
  1030. struct qcom_qmp *qmp = qphy->qmp;
  1031. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1032. clk_disable_unprepare(qphy->pipe_clk);
  1033. /* PHY reset */
  1034. qphy_setbits(qphy->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
  1035. /* stop SerDes and Phy-Coding-Sublayer */
  1036. qphy_clrbits(qphy->pcs, cfg->regs[QPHY_START_CTRL], cfg->start_ctrl);
  1037. /* Put PHY into POWER DOWN state: active low */
  1038. qphy_clrbits(qphy->pcs, QPHY_POWER_DOWN_CONTROL, cfg->pwrdn_ctrl);
  1039. if (cfg->has_lane_rst)
  1040. reset_control_assert(qphy->lane_rst);
  1041. qcom_qmp_phy_com_exit(qmp);
  1042. qmp->phy_initialized = false;
  1043. return 0;
  1044. }
  1045. static int qcom_qmp_phy_set_mode(struct phy *phy, enum phy_mode mode)
  1046. {
  1047. struct qmp_phy *qphy = phy_get_drvdata(phy);
  1048. struct qcom_qmp *qmp = qphy->qmp;
  1049. qmp->mode = mode;
  1050. return 0;
  1051. }
  1052. static void qcom_qmp_phy_enable_autonomous_mode(struct qmp_phy *qphy)
  1053. {
  1054. struct qcom_qmp *qmp = qphy->qmp;
  1055. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1056. void __iomem *pcs = qphy->pcs;
  1057. void __iomem *pcs_misc = qphy->pcs_misc;
  1058. u32 intr_mask;
  1059. if (qmp->mode == PHY_MODE_USB_HOST_SS ||
  1060. qmp->mode == PHY_MODE_USB_DEVICE_SS)
  1061. intr_mask = ARCVR_DTCT_EN | ALFPS_DTCT_EN;
  1062. else
  1063. intr_mask = ARCVR_DTCT_EN | ARCVR_DTCT_EVENT_SEL;
  1064. /* Clear any pending interrupts status */
  1065. qphy_setbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  1066. /* Writing 1 followed by 0 clears the interrupt */
  1067. qphy_clrbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  1068. qphy_clrbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
  1069. ARCVR_DTCT_EN | ALFPS_DTCT_EN | ARCVR_DTCT_EVENT_SEL);
  1070. /* Enable required PHY autonomous mode interrupts */
  1071. qphy_setbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], intr_mask);
  1072. /* Enable i/o clamp_n for autonomous mode */
  1073. if (pcs_misc)
  1074. qphy_clrbits(pcs_misc, QPHY_V3_PCS_MISC_CLAMP_ENABLE, CLAMP_EN);
  1075. }
  1076. static void qcom_qmp_phy_disable_autonomous_mode(struct qmp_phy *qphy)
  1077. {
  1078. struct qcom_qmp *qmp = qphy->qmp;
  1079. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1080. void __iomem *pcs = qphy->pcs;
  1081. void __iomem *pcs_misc = qphy->pcs_misc;
  1082. /* Disable i/o clamp_n on resume for normal mode */
  1083. if (pcs_misc)
  1084. qphy_setbits(pcs_misc, QPHY_V3_PCS_MISC_CLAMP_ENABLE, CLAMP_EN);
  1085. qphy_clrbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
  1086. ARCVR_DTCT_EN | ARCVR_DTCT_EVENT_SEL | ALFPS_DTCT_EN);
  1087. qphy_setbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  1088. /* Writing 1 followed by 0 clears the interrupt */
  1089. qphy_clrbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  1090. }
  1091. static int __maybe_unused qcom_qmp_phy_runtime_suspend(struct device *dev)
  1092. {
  1093. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  1094. struct qmp_phy *qphy = qmp->phys[0];
  1095. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1096. dev_vdbg(dev, "Suspending QMP phy, mode:%d\n", qmp->mode);
  1097. /* Supported only for USB3 PHY */
  1098. if (cfg->type != PHY_TYPE_USB3)
  1099. return 0;
  1100. if (!qmp->phy_initialized) {
  1101. dev_vdbg(dev, "PHY not initialized, bailing out\n");
  1102. return 0;
  1103. }
  1104. qcom_qmp_phy_enable_autonomous_mode(qphy);
  1105. clk_disable_unprepare(qphy->pipe_clk);
  1106. clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
  1107. return 0;
  1108. }
  1109. static int __maybe_unused qcom_qmp_phy_runtime_resume(struct device *dev)
  1110. {
  1111. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  1112. struct qmp_phy *qphy = qmp->phys[0];
  1113. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1114. int ret = 0;
  1115. dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->mode);
  1116. /* Supported only for USB3 PHY */
  1117. if (cfg->type != PHY_TYPE_USB3)
  1118. return 0;
  1119. if (!qmp->phy_initialized) {
  1120. dev_vdbg(dev, "PHY not initialized, bailing out\n");
  1121. return 0;
  1122. }
  1123. ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
  1124. if (ret) {
  1125. dev_err(qmp->dev, "failed to enable clks, err=%d\n", ret);
  1126. return ret;
  1127. }
  1128. ret = clk_prepare_enable(qphy->pipe_clk);
  1129. if (ret) {
  1130. dev_err(dev, "pipe_clk enable failed, err=%d\n", ret);
  1131. clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
  1132. return ret;
  1133. }
  1134. qcom_qmp_phy_disable_autonomous_mode(qphy);
  1135. return 0;
  1136. }
  1137. static int qcom_qmp_phy_vreg_init(struct device *dev)
  1138. {
  1139. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  1140. int num = qmp->cfg->num_vregs;
  1141. int i;
  1142. qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL);
  1143. if (!qmp->vregs)
  1144. return -ENOMEM;
  1145. for (i = 0; i < num; i++)
  1146. qmp->vregs[i].supply = qmp->cfg->vreg_list[i];
  1147. return devm_regulator_bulk_get(dev, num, qmp->vregs);
  1148. }
  1149. static int qcom_qmp_phy_reset_init(struct device *dev)
  1150. {
  1151. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  1152. int i;
  1153. qmp->resets = devm_kcalloc(dev, qmp->cfg->num_resets,
  1154. sizeof(*qmp->resets), GFP_KERNEL);
  1155. if (!qmp->resets)
  1156. return -ENOMEM;
  1157. for (i = 0; i < qmp->cfg->num_resets; i++) {
  1158. struct reset_control *rst;
  1159. const char *name = qmp->cfg->reset_list[i];
  1160. rst = devm_reset_control_get(dev, name);
  1161. if (IS_ERR(rst)) {
  1162. dev_err(dev, "failed to get %s reset\n", name);
  1163. return PTR_ERR(rst);
  1164. }
  1165. qmp->resets[i] = rst;
  1166. }
  1167. return 0;
  1168. }
  1169. static int qcom_qmp_phy_clk_init(struct device *dev)
  1170. {
  1171. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  1172. int num = qmp->cfg->num_clks;
  1173. int i;
  1174. qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL);
  1175. if (!qmp->clks)
  1176. return -ENOMEM;
  1177. for (i = 0; i < num; i++)
  1178. qmp->clks[i].id = qmp->cfg->clk_list[i];
  1179. return devm_clk_bulk_get(dev, num, qmp->clks);
  1180. }
  1181. /*
  1182. * Register a fixed rate pipe clock.
  1183. *
  1184. * The <s>_pipe_clksrc generated by PHY goes to the GCC that gate
  1185. * controls it. The <s>_pipe_clk coming out of the GCC is requested
  1186. * by the PHY driver for its operations.
  1187. * We register the <s>_pipe_clksrc here. The gcc driver takes care
  1188. * of assigning this <s>_pipe_clksrc as parent to <s>_pipe_clk.
  1189. * Below picture shows this relationship.
  1190. *
  1191. * +---------------+
  1192. * | PHY block |<<---------------------------------------+
  1193. * | | |
  1194. * | +-------+ | +-----+ |
  1195. * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
  1196. * clk | +-------+ | +-----+
  1197. * +---------------+
  1198. */
  1199. static int phy_pipe_clk_register(struct qcom_qmp *qmp, struct device_node *np)
  1200. {
  1201. struct clk_fixed_rate *fixed;
  1202. struct clk_init_data init = { };
  1203. int ret;
  1204. if ((qmp->cfg->type != PHY_TYPE_USB3) &&
  1205. (qmp->cfg->type != PHY_TYPE_PCIE)) {
  1206. /* not all phys register pipe clocks, so return success */
  1207. return 0;
  1208. }
  1209. ret = of_property_read_string(np, "clock-output-names", &init.name);
  1210. if (ret) {
  1211. dev_err(qmp->dev, "%s: No clock-output-names\n", np->name);
  1212. return ret;
  1213. }
  1214. fixed = devm_kzalloc(qmp->dev, sizeof(*fixed), GFP_KERNEL);
  1215. if (!fixed)
  1216. return -ENOMEM;
  1217. init.ops = &clk_fixed_rate_ops;
  1218. /* controllers using QMP phys use 125MHz pipe clock interface */
  1219. fixed->fixed_rate = 125000000;
  1220. fixed->hw.init = &init;
  1221. return devm_clk_hw_register(qmp->dev, &fixed->hw);
  1222. }
  1223. static const struct phy_ops qcom_qmp_phy_gen_ops = {
  1224. .init = qcom_qmp_phy_init,
  1225. .exit = qcom_qmp_phy_exit,
  1226. .set_mode = qcom_qmp_phy_set_mode,
  1227. .owner = THIS_MODULE,
  1228. };
  1229. static
  1230. int qcom_qmp_phy_create(struct device *dev, struct device_node *np, int id)
  1231. {
  1232. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  1233. struct phy *generic_phy;
  1234. struct qmp_phy *qphy;
  1235. char prop_name[MAX_PROP_NAME];
  1236. int ret;
  1237. qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL);
  1238. if (!qphy)
  1239. return -ENOMEM;
  1240. /*
  1241. * Get memory resources for each phy lane:
  1242. * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2; and
  1243. * pcs_misc (optional) -> 3.
  1244. */
  1245. qphy->tx = of_iomap(np, 0);
  1246. if (!qphy->tx)
  1247. return -ENOMEM;
  1248. qphy->rx = of_iomap(np, 1);
  1249. if (!qphy->rx)
  1250. return -ENOMEM;
  1251. qphy->pcs = of_iomap(np, 2);
  1252. if (!qphy->pcs)
  1253. return -ENOMEM;
  1254. qphy->pcs_misc = of_iomap(np, 3);
  1255. if (!qphy->pcs_misc)
  1256. dev_vdbg(dev, "PHY pcs_misc-reg not used\n");
  1257. /*
  1258. * Get PHY's Pipe clock, if any. USB3 and PCIe are PIPE3
  1259. * based phys, so they essentially have pipe clock. So,
  1260. * we return error in case phy is USB3 or PIPE type.
  1261. * Otherwise, we initialize pipe clock to NULL for
  1262. * all phys that don't need this.
  1263. */
  1264. snprintf(prop_name, sizeof(prop_name), "pipe%d", id);
  1265. qphy->pipe_clk = of_clk_get_by_name(np, prop_name);
  1266. if (IS_ERR(qphy->pipe_clk)) {
  1267. if (qmp->cfg->type == PHY_TYPE_PCIE ||
  1268. qmp->cfg->type == PHY_TYPE_USB3) {
  1269. ret = PTR_ERR(qphy->pipe_clk);
  1270. if (ret != -EPROBE_DEFER)
  1271. dev_err(dev,
  1272. "failed to get lane%d pipe_clk, %d\n",
  1273. id, ret);
  1274. return ret;
  1275. }
  1276. qphy->pipe_clk = NULL;
  1277. }
  1278. /* Get lane reset, if any */
  1279. if (qmp->cfg->has_lane_rst) {
  1280. snprintf(prop_name, sizeof(prop_name), "lane%d", id);
  1281. qphy->lane_rst = of_reset_control_get(np, prop_name);
  1282. if (IS_ERR(qphy->lane_rst)) {
  1283. dev_err(dev, "failed to get lane%d reset\n", id);
  1284. return PTR_ERR(qphy->lane_rst);
  1285. }
  1286. }
  1287. generic_phy = devm_phy_create(dev, np, &qcom_qmp_phy_gen_ops);
  1288. if (IS_ERR(generic_phy)) {
  1289. ret = PTR_ERR(generic_phy);
  1290. dev_err(dev, "failed to create qphy %d\n", ret);
  1291. return ret;
  1292. }
  1293. qphy->phy = generic_phy;
  1294. qphy->index = id;
  1295. qphy->qmp = qmp;
  1296. qmp->phys[id] = qphy;
  1297. phy_set_drvdata(generic_phy, qphy);
  1298. return 0;
  1299. }
  1300. static const struct of_device_id qcom_qmp_phy_of_match_table[] = {
  1301. {
  1302. .compatible = "qcom,msm8996-qmp-pcie-phy",
  1303. .data = &msm8996_pciephy_cfg,
  1304. }, {
  1305. .compatible = "qcom,msm8996-qmp-usb3-phy",
  1306. .data = &msm8996_usb3phy_cfg,
  1307. }, {
  1308. .compatible = "qcom,ipq8074-qmp-pcie-phy",
  1309. .data = &ipq8074_pciephy_cfg,
  1310. }, {
  1311. .compatible = "qcom,sdm845-qmp-usb3-phy",
  1312. .data = &qmp_v3_usb3phy_cfg,
  1313. }, {
  1314. .compatible = "qcom,sdm845-qmp-usb3-uni-phy",
  1315. .data = &qmp_v3_usb3_uniphy_cfg,
  1316. },
  1317. { },
  1318. };
  1319. MODULE_DEVICE_TABLE(of, qcom_qmp_phy_of_match_table);
  1320. static const struct dev_pm_ops qcom_qmp_phy_pm_ops = {
  1321. SET_RUNTIME_PM_OPS(qcom_qmp_phy_runtime_suspend,
  1322. qcom_qmp_phy_runtime_resume, NULL)
  1323. };
  1324. static int qcom_qmp_phy_probe(struct platform_device *pdev)
  1325. {
  1326. struct qcom_qmp *qmp;
  1327. struct device *dev = &pdev->dev;
  1328. struct resource *res;
  1329. struct device_node *child;
  1330. struct phy_provider *phy_provider;
  1331. void __iomem *base;
  1332. int num, id;
  1333. int ret;
  1334. qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL);
  1335. if (!qmp)
  1336. return -ENOMEM;
  1337. qmp->dev = dev;
  1338. dev_set_drvdata(dev, qmp);
  1339. /* Get the specific init parameters of QMP phy */
  1340. qmp->cfg = of_device_get_match_data(dev);
  1341. if (!qmp->cfg)
  1342. return -EINVAL;
  1343. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1344. base = devm_ioremap_resource(dev, res);
  1345. if (IS_ERR(base))
  1346. return PTR_ERR(base);
  1347. /* per PHY serdes; usually located at base address */
  1348. qmp->serdes = base;
  1349. /* per PHY dp_com; if PHY has dp_com control block */
  1350. if (qmp->cfg->has_phy_dp_com_ctrl) {
  1351. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  1352. "dp_com");
  1353. base = devm_ioremap_resource(dev, res);
  1354. if (IS_ERR(base))
  1355. return PTR_ERR(base);
  1356. qmp->dp_com = base;
  1357. }
  1358. mutex_init(&qmp->phy_mutex);
  1359. ret = qcom_qmp_phy_clk_init(dev);
  1360. if (ret)
  1361. return ret;
  1362. ret = qcom_qmp_phy_reset_init(dev);
  1363. if (ret)
  1364. return ret;
  1365. ret = qcom_qmp_phy_vreg_init(dev);
  1366. if (ret) {
  1367. dev_err(dev, "failed to get regulator supplies\n");
  1368. return ret;
  1369. }
  1370. num = of_get_available_child_count(dev->of_node);
  1371. /* do we have a rogue child node ? */
  1372. if (num > qmp->cfg->nlanes)
  1373. return -EINVAL;
  1374. qmp->phys = devm_kcalloc(dev, num, sizeof(*qmp->phys), GFP_KERNEL);
  1375. if (!qmp->phys)
  1376. return -ENOMEM;
  1377. id = 0;
  1378. pm_runtime_set_active(dev);
  1379. pm_runtime_enable(dev);
  1380. /*
  1381. * Prevent runtime pm from being ON by default. Users can enable
  1382. * it using power/control in sysfs.
  1383. */
  1384. pm_runtime_forbid(dev);
  1385. for_each_available_child_of_node(dev->of_node, child) {
  1386. /* Create per-lane phy */
  1387. ret = qcom_qmp_phy_create(dev, child, id);
  1388. if (ret) {
  1389. dev_err(dev, "failed to create lane%d phy, %d\n",
  1390. id, ret);
  1391. pm_runtime_disable(dev);
  1392. return ret;
  1393. }
  1394. /*
  1395. * Register the pipe clock provided by phy.
  1396. * See function description to see details of this pipe clock.
  1397. */
  1398. ret = phy_pipe_clk_register(qmp, child);
  1399. if (ret) {
  1400. dev_err(qmp->dev,
  1401. "failed to register pipe clock source\n");
  1402. pm_runtime_disable(dev);
  1403. return ret;
  1404. }
  1405. id++;
  1406. }
  1407. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  1408. if (!IS_ERR(phy_provider))
  1409. dev_info(dev, "Registered Qcom-QMP phy\n");
  1410. else
  1411. pm_runtime_disable(dev);
  1412. return PTR_ERR_OR_ZERO(phy_provider);
  1413. }
  1414. static struct platform_driver qcom_qmp_phy_driver = {
  1415. .probe = qcom_qmp_phy_probe,
  1416. .driver = {
  1417. .name = "qcom-qmp-phy",
  1418. .pm = &qcom_qmp_phy_pm_ops,
  1419. .of_match_table = qcom_qmp_phy_of_match_table,
  1420. },
  1421. };
  1422. module_platform_driver(qcom_qmp_phy_driver);
  1423. MODULE_AUTHOR("Vivek Gautam <vivek.gautam@codeaurora.org>");
  1424. MODULE_DESCRIPTION("Qualcomm QMP PHY driver");
  1425. MODULE_LICENSE("GPL v2");