phy-qcom-qmp-combo.c 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964
  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. /* QPHY_START_CONTROL bits */
  28. #define SERDES_START BIT(0)
  29. #define PCS_START BIT(1)
  30. /* QPHY_PCS_STATUS bit */
  31. #define PHYSTATUS BIT(6)
  32. /* QPHY_V3_DP_COM_RESET_OVRD_CTRL register bits */
  33. /* DP PHY soft reset */
  34. #define SW_DPPHY_RESET BIT(0)
  35. /* mux to select DP PHY reset control, 0:HW control, 1: software reset */
  36. #define SW_DPPHY_RESET_MUX BIT(1)
  37. /* USB3 PHY soft reset */
  38. #define SW_USB3PHY_RESET BIT(2)
  39. /* mux to select USB3 PHY reset control, 0:HW control, 1: software reset */
  40. #define SW_USB3PHY_RESET_MUX BIT(3)
  41. /* QPHY_V3_DP_COM_PHY_MODE_CTRL register bits */
  42. #define USB3_MODE BIT(0) /* enables USB3 mode */
  43. #define DP_MODE BIT(1) /* enables DP mode */
  44. /* QPHY_PCS_AUTONOMOUS_MODE_CTRL register bits */
  45. #define ARCVR_DTCT_EN BIT(0)
  46. #define ALFPS_DTCT_EN BIT(1)
  47. #define ARCVR_DTCT_EVENT_SEL BIT(4)
  48. /* QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR register bits */
  49. #define IRQ_CLEAR BIT(0)
  50. /* QPHY_PCS_LFPS_RXTERM_IRQ_STATUS register bits */
  51. #define RCVR_DETECT BIT(0)
  52. /* QPHY_V3_PCS_MISC_CLAMP_ENABLE register bits */
  53. #define CLAMP_EN BIT(0) /* enables i/o clamp_n */
  54. #define PHY_INIT_COMPLETE_TIMEOUT 10000
  55. #define POWER_DOWN_DELAY_US_MIN 10
  56. #define POWER_DOWN_DELAY_US_MAX 11
  57. struct qmp_phy_init_tbl {
  58. unsigned int offset;
  59. unsigned int val;
  60. /*
  61. * register part of layout ?
  62. * if yes, then offset gives index in the reg-layout
  63. */
  64. bool in_layout;
  65. /*
  66. * mask of lanes for which this register is written
  67. * for cases when second lane needs different values
  68. */
  69. u8 lane_mask;
  70. };
  71. #define QMP_PHY_INIT_CFG(o, v) \
  72. { \
  73. .offset = o, \
  74. .val = v, \
  75. .lane_mask = 0xff, \
  76. }
  77. #define QMP_PHY_INIT_CFG_L(o, v) \
  78. { \
  79. .offset = o, \
  80. .val = v, \
  81. .in_layout = true, \
  82. .lane_mask = 0xff, \
  83. }
  84. #define QMP_PHY_INIT_CFG_LANE(o, v, l) \
  85. { \
  86. .offset = o, \
  87. .val = v, \
  88. .lane_mask = l, \
  89. }
  90. /* set of registers with offsets different per-PHY */
  91. enum qphy_reg_layout {
  92. /* PCS registers */
  93. QPHY_SW_RESET,
  94. QPHY_START_CTRL,
  95. QPHY_PCS_STATUS,
  96. QPHY_PCS_AUTONOMOUS_MODE_CTRL,
  97. QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR,
  98. QPHY_PCS_LFPS_RXTERM_IRQ_STATUS,
  99. QPHY_PCS_POWER_DOWN_CONTROL,
  100. /* Keep last to ensure regs_layout arrays are properly initialized */
  101. QPHY_LAYOUT_SIZE
  102. };
  103. static const unsigned int qmp_v3_usb3phy_regs_layout[QPHY_LAYOUT_SIZE] = {
  104. [QPHY_SW_RESET] = 0x00,
  105. [QPHY_START_CTRL] = 0x08,
  106. [QPHY_PCS_STATUS] = 0x174,
  107. [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = 0x0d8,
  108. [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = 0x0dc,
  109. [QPHY_PCS_LFPS_RXTERM_IRQ_STATUS] = 0x170,
  110. };
  111. static const unsigned int qmp_v4_usb3phy_regs_layout[QPHY_LAYOUT_SIZE] = {
  112. [QPHY_SW_RESET] = 0x00,
  113. [QPHY_START_CTRL] = 0x44,
  114. [QPHY_PCS_STATUS] = 0x14,
  115. [QPHY_PCS_POWER_DOWN_CONTROL] = 0x40,
  116. /* In PCS_USB */
  117. [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = 0x008,
  118. [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = 0x014,
  119. };
  120. static const struct qmp_phy_init_tbl qmp_v3_usb3_serdes_tbl[] = {
  121. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
  122. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0x14),
  123. QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
  124. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
  125. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
  126. QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL2, 0x08),
  127. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x16),
  128. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x01),
  129. QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x80),
  130. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82),
  131. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START1_MODE0, 0xab),
  132. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0xea),
  133. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x02),
  134. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
  135. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
  136. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
  137. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  138. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
  139. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01),
  140. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xc9),
  141. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORECLK_DIV_MODE0, 0x0a),
  142. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP3_MODE0, 0x00),
  143. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x34),
  144. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x15),
  145. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x04),
  146. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00),
  147. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_CFG, 0x00),
  148. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x00),
  149. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_BUF_ENABLE, 0x0a),
  150. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_EN_CENTER, 0x01),
  151. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER1, 0x31),
  152. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER2, 0x01),
  153. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER1, 0x00),
  154. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER2, 0x00),
  155. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE1, 0x85),
  156. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE2, 0x07),
  157. };
  158. static const struct qmp_phy_init_tbl qmp_v3_usb3_tx_tbl[] = {
  159. QMP_PHY_INIT_CFG(QSERDES_V3_TX_HIGHZ_DRVR_EN, 0x10),
  160. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RCV_DETECT_LVL_2, 0x12),
  161. QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0x16),
  162. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x09),
  163. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x06),
  164. };
  165. static const struct qmp_phy_init_tbl qmp_v3_dp_serdes_tbl[] = {
  166. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x01),
  167. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0x37),
  168. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
  169. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_ENABLE1, 0x0e),
  170. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_BUF_ENABLE, 0x06),
  171. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
  172. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x02),
  173. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START1_MODE0, 0x00),
  174. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
  175. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  176. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x00),
  177. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP3_MODE0, 0x00),
  178. QMP_PHY_INIT_CFG(QSERDES_V3_COM_BG_TIMER, 0x0a),
  179. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORECLK_DIV_MODE0, 0x0a),
  180. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_CTRL, 0x00),
  181. QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x3f),
  182. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x1f),
  183. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
  184. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
  185. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
  186. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
  187. };
  188. static const struct qmp_phy_init_tbl qmp_v3_dp_serdes_tbl_rbr[] = {
  189. QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x0c),
  190. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x69),
  191. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0x80),
  192. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x07),
  193. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x6f),
  194. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x08),
  195. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x00),
  196. };
  197. static const struct qmp_phy_init_tbl qmp_v3_dp_serdes_tbl_hbr[] = {
  198. QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x04),
  199. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x69),
  200. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0x80),
  201. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x07),
  202. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x0f),
  203. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x0e),
  204. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x00),
  205. };
  206. static const struct qmp_phy_init_tbl qmp_v3_dp_serdes_tbl_hbr2[] = {
  207. QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x00),
  208. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x8c),
  209. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0x00),
  210. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x0a),
  211. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x1f),
  212. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x1c),
  213. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x00),
  214. };
  215. static const struct qmp_phy_init_tbl qmp_v3_dp_serdes_tbl_hbr3[] = {
  216. QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x03),
  217. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x69),
  218. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0x80),
  219. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x07),
  220. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x2f),
  221. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x2a),
  222. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x08),
  223. };
  224. static const struct qmp_phy_init_tbl qmp_v3_dp_tx_tbl[] = {
  225. QMP_PHY_INIT_CFG(QSERDES_V3_TX_TRANSCEIVER_BIAS_EN, 0x1a),
  226. QMP_PHY_INIT_CFG(QSERDES_V3_TX_VMODE_CTRL1, 0x40),
  227. QMP_PHY_INIT_CFG(QSERDES_V3_TX_PRE_STALL_LDO_BOOST_EN, 0x30),
  228. QMP_PHY_INIT_CFG(QSERDES_V3_TX_INTERFACE_SELECT, 0x3d),
  229. QMP_PHY_INIT_CFG(QSERDES_V3_TX_CLKBUF_ENABLE, 0x0f),
  230. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RESET_TSYNC_EN, 0x03),
  231. QMP_PHY_INIT_CFG(QSERDES_V3_TX_TRAN_DRVR_EMP_EN, 0x03),
  232. QMP_PHY_INIT_CFG(QSERDES_V3_TX_PARRATE_REC_DETECT_IDLE_EN, 0x00),
  233. QMP_PHY_INIT_CFG(QSERDES_V3_TX_TX_INTERFACE_MODE, 0x00),
  234. QMP_PHY_INIT_CFG(QSERDES_V3_TX_TX_BAND, 0x4),
  235. QMP_PHY_INIT_CFG(QSERDES_V3_TX_TX_POL_INV, 0x0a),
  236. QMP_PHY_INIT_CFG(QSERDES_V3_TX_TX_DRV_LVL, 0x38),
  237. QMP_PHY_INIT_CFG(QSERDES_V3_TX_TX_EMP_POST1_LVL, 0x20),
  238. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x06),
  239. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x07),
  240. };
  241. static const struct qmp_phy_init_tbl qmp_v3_usb3_rx_tbl[] = {
  242. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
  243. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
  244. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4e),
  245. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x18),
  246. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
  247. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x80),
  248. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x03),
  249. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x16),
  250. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x75),
  251. };
  252. static const struct qmp_phy_init_tbl qmp_v3_usb3_pcs_tbl[] = {
  253. /* FLL settings */
  254. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL2, 0x83),
  255. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_L, 0x09),
  256. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_H_TOL, 0xa2),
  257. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_MAN_CODE, 0x40),
  258. QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL1, 0x02),
  259. /* Lock Det settings */
  260. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG1, 0xd1),
  261. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG2, 0x1f),
  262. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG3, 0x47),
  263. QMP_PHY_INIT_CFG(QPHY_V3_PCS_POWER_STATE_CONFIG2, 0x1b),
  264. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RX_SIGDET_LVL, 0xba),
  265. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V0, 0x9f),
  266. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V1, 0x9f),
  267. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V2, 0xb7),
  268. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V3, 0x4e),
  269. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V4, 0x65),
  270. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_LS, 0x6b),
  271. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V0, 0x15),
  272. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V0, 0x0d),
  273. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V1, 0x15),
  274. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V1, 0x0d),
  275. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V2, 0x15),
  276. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V2, 0x0d),
  277. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V3, 0x15),
  278. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V3, 0x1d),
  279. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V4, 0x15),
  280. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V4, 0x0d),
  281. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_LS, 0x15),
  282. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_LS, 0x0d),
  283. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RATE_SLEW_CNTRL, 0x02),
  284. QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
  285. QMP_PHY_INIT_CFG(QPHY_V3_PCS_TSYNC_RSYNC_TIME, 0x44),
  286. QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
  287. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_L, 0xe7),
  288. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_H, 0x03),
  289. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_L, 0x40),
  290. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_H, 0x00),
  291. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_WAIT_TIME, 0x75),
  292. QMP_PHY_INIT_CFG(QPHY_V3_PCS_LFPS_TX_ECSTART_EQTLOCK, 0x86),
  293. QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_RUN_TIME, 0x13),
  294. };
  295. static const struct qmp_phy_init_tbl sm8150_usb3_serdes_tbl[] = {
  296. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_EN_CENTER, 0x01),
  297. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_PER1, 0x31),
  298. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_PER2, 0x01),
  299. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE1_MODE0, 0xde),
  300. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE2_MODE0, 0x07),
  301. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE1_MODE1, 0xde),
  302. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SSC_STEP_SIZE2_MODE1, 0x07),
  303. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_BUF_ENABLE, 0x0a),
  304. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CMN_IPTRIM, 0x20),
  305. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE0, 0x06),
  306. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE1, 0x06),
  307. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE0, 0x16),
  308. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE1, 0x16),
  309. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE0, 0x36),
  310. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE1, 0x36),
  311. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_EN_SEL, 0x1a),
  312. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP_EN, 0x04),
  313. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE0, 0x14),
  314. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE0, 0x34),
  315. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE1, 0x34),
  316. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE1, 0x82),
  317. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE0, 0x82),
  318. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE1, 0x82),
  319. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START1_MODE0, 0xab),
  320. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START2_MODE0, 0xea),
  321. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START3_MODE0, 0x02),
  322. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x02),
  323. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START1_MODE1, 0xab),
  324. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START2_MODE1, 0xea),
  325. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START3_MODE1, 0x02),
  326. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE1_MODE0, 0x24),
  327. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE1_MODE1, 0x24),
  328. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE2_MODE1, 0x02),
  329. QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_SEL, 0x01),
  330. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CORECLK_DIV_MODE1, 0x08),
  331. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE0, 0xca),
  332. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE0, 0x1e),
  333. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE1, 0xca),
  334. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE1, 0x1e),
  335. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_HSCLK_SEL, 0x11),
  336. };
  337. static const struct qmp_phy_init_tbl sm8150_usb3_tx_tbl[] = {
  338. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_TX, 0x00),
  339. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_RX, 0x00),
  340. QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0xd5),
  341. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RCV_DETECT_LVL_2, 0x12),
  342. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PI_QEC_CTRL, 0x20),
  343. };
  344. static const struct qmp_phy_init_tbl sm8150_usb3_rx_tbl[] = {
  345. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x05),
  346. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x2f),
  347. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x7f),
  348. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0xff),
  349. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_HIGH, 0x0f),
  350. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0x99),
  351. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_THRESH1, 0x04),
  352. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_THRESH2, 0x08),
  353. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_GAIN1, 0x05),
  354. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_GAIN2, 0x05),
  355. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VGA_CAL_CNTRL1, 0x54),
  356. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VGA_CAL_CNTRL2, 0x0e),
  357. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
  358. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4a),
  359. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x0a),
  360. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
  361. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
  362. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
  363. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x04),
  364. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x0e),
  365. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0xbf),
  366. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xbf),
  367. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0x3f),
  368. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
  369. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x94),
  370. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0xdc),
  371. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0xdc),
  372. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0x5c),
  373. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x0b),
  374. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb3),
  375. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DFE_EN_TIMER, 0x04),
  376. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DFE_CTLE_POST_CAL_OFFSET, 0x38),
  377. QMP_PHY_INIT_CFG(QSERDES_V4_RX_AUX_DATA_TCOARSE_TFINE, 0xa0),
  378. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DCC_CTRL1, 0x0c),
  379. QMP_PHY_INIT_CFG(QSERDES_V4_RX_GM_CAL, 0x1f),
  380. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VTH_CODE, 0x10),
  381. };
  382. static const struct qmp_phy_init_tbl sm8150_usb3_pcs_tbl[] = {
  383. /* Lock Det settings */
  384. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG1, 0xd0),
  385. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG2, 0x07),
  386. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG6, 0x13),
  387. QMP_PHY_INIT_CFG(QPHY_V4_PCS_REFGEN_REQ_CONFIG1, 0x21),
  388. QMP_PHY_INIT_CFG(QPHY_V4_PCS_RX_SIGDET_LVL, 0xaa),
  389. QMP_PHY_INIT_CFG(QPHY_V4_PCS_CDR_RESET_TIME, 0x0a),
  390. QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG1, 0x88),
  391. QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG2, 0x13),
  392. QMP_PHY_INIT_CFG(QPHY_V4_PCS_PCS_TX_RX_CONFIG, 0x0c),
  393. QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG1, 0x4b),
  394. QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG5, 0x10),
  395. };
  396. static const struct qmp_phy_init_tbl sm8150_usb3_pcs_usb_tbl[] = {
  397. QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_LFPS_DET_HIGH_COUNT_VAL, 0xf8),
  398. QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_RXEQTRAINING_DFE_TIME_S2, 0x07),
  399. };
  400. static const struct qmp_phy_init_tbl sm8250_usb3_tx_tbl[] = {
  401. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_TX, 0x60),
  402. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_RX, 0x60),
  403. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_OFFSET_TX, 0x11),
  404. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_OFFSET_RX, 0x02),
  405. QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0xd5),
  406. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RCV_DETECT_LVL_2, 0x12),
  407. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_TX_PI_QEC_CTRL, 0x40, 1),
  408. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_TX_PI_QEC_CTRL, 0x54, 2),
  409. };
  410. static const struct qmp_phy_init_tbl sm8250_usb3_rx_tbl[] = {
  411. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x06),
  412. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x2f),
  413. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x7f),
  414. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0xff),
  415. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_HIGH, 0x0f),
  416. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0x99),
  417. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_THRESH1, 0x04),
  418. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_THRESH2, 0x08),
  419. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_GAIN1, 0x05),
  420. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SB2_GAIN2, 0x05),
  421. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VGA_CAL_CNTRL1, 0x54),
  422. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VGA_CAL_CNTRL2, 0x0c),
  423. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
  424. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4a),
  425. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x0a),
  426. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
  427. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
  428. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
  429. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x04),
  430. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x0e),
  431. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_LOW, 0xff, 1),
  432. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_LOW, 0x7f, 2),
  433. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_HIGH, 0x7f, 1),
  434. QMP_PHY_INIT_CFG_LANE(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff, 2),
  435. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0x7f),
  436. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
  437. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x97),
  438. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0xdc),
  439. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0xdc),
  440. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0x5c),
  441. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x7b),
  442. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb4),
  443. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DFE_EN_TIMER, 0x04),
  444. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DFE_CTLE_POST_CAL_OFFSET, 0x38),
  445. QMP_PHY_INIT_CFG(QSERDES_V4_RX_AUX_DATA_TCOARSE_TFINE, 0xa0),
  446. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DCC_CTRL1, 0x0c),
  447. QMP_PHY_INIT_CFG(QSERDES_V4_RX_GM_CAL, 0x1f),
  448. QMP_PHY_INIT_CFG(QSERDES_V4_RX_VTH_CODE, 0x10),
  449. };
  450. static const struct qmp_phy_init_tbl sm8250_usb3_pcs_tbl[] = {
  451. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG1, 0xd0),
  452. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG2, 0x07),
  453. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG3, 0x20),
  454. QMP_PHY_INIT_CFG(QPHY_V4_PCS_LOCK_DETECT_CONFIG6, 0x13),
  455. QMP_PHY_INIT_CFG(QPHY_V4_PCS_REFGEN_REQ_CONFIG1, 0x21),
  456. QMP_PHY_INIT_CFG(QPHY_V4_PCS_RX_SIGDET_LVL, 0xa9),
  457. QMP_PHY_INIT_CFG(QPHY_V4_PCS_CDR_RESET_TIME, 0x0a),
  458. QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG1, 0x88),
  459. QMP_PHY_INIT_CFG(QPHY_V4_PCS_ALIGN_DETECT_CONFIG2, 0x13),
  460. QMP_PHY_INIT_CFG(QPHY_V4_PCS_PCS_TX_RX_CONFIG, 0x0c),
  461. QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG1, 0x4b),
  462. QMP_PHY_INIT_CFG(QPHY_V4_PCS_EQ_CONFIG5, 0x10),
  463. };
  464. static const struct qmp_phy_init_tbl sm8250_usb3_pcs_usb_tbl[] = {
  465. QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_LFPS_DET_HIGH_COUNT_VAL, 0xf8),
  466. QMP_PHY_INIT_CFG(QPHY_V4_PCS_USB3_RXEQTRAINING_DFE_TIME_S2, 0x07),
  467. };
  468. static const struct qmp_phy_init_tbl qmp_v4_dp_serdes_tbl[] = {
  469. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SVS_MODE_CLK_SEL, 0x05),
  470. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_EN_SEL, 0x3b),
  471. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYS_CLK_CTRL, 0x02),
  472. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CLK_ENABLE1, 0x0c),
  473. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_BUF_ENABLE, 0x06),
  474. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CLK_SELECT, 0x30),
  475. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_IVCO, 0x0f),
  476. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE0, 0x36),
  477. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE0, 0x16),
  478. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE0, 0x06),
  479. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CMN_CONFIG, 0x02),
  480. QMP_PHY_INIT_CFG(QSERDES_V4_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
  481. QMP_PHY_INIT_CFG(QSERDES_V4_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  482. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x00),
  483. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START1_MODE0, 0x00),
  484. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BG_TIMER, 0x0a),
  485. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CORECLK_DIV_MODE0, 0x0a),
  486. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_CTRL, 0x00),
  487. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIAS_EN_CLKBUFLR_EN, 0x17),
  488. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CORE_CLK_EN, 0x1f),
  489. };
  490. static const struct qmp_phy_init_tbl qmp_v4_dp_serdes_tbl_rbr[] = {
  491. QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_SEL, 0x05),
  492. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE0, 0x69),
  493. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START2_MODE0, 0x80),
  494. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START3_MODE0, 0x07),
  495. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE0, 0x6f),
  496. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE0, 0x08),
  497. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP_EN, 0x04),
  498. };
  499. static const struct qmp_phy_init_tbl qmp_v4_dp_serdes_tbl_hbr[] = {
  500. QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_SEL, 0x03),
  501. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE0, 0x69),
  502. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START2_MODE0, 0x80),
  503. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START3_MODE0, 0x07),
  504. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE0, 0x0f),
  505. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE0, 0x0e),
  506. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP_EN, 0x08),
  507. };
  508. static const struct qmp_phy_init_tbl qmp_v4_dp_serdes_tbl_hbr2[] = {
  509. QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_SEL, 0x01),
  510. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE0, 0x8c),
  511. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START2_MODE0, 0x00),
  512. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START3_MODE0, 0x0a),
  513. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE0, 0x1f),
  514. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE0, 0x1c),
  515. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP_EN, 0x08),
  516. };
  517. static const struct qmp_phy_init_tbl qmp_v4_dp_serdes_tbl_hbr3[] = {
  518. QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_SEL, 0x00),
  519. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE0, 0x69),
  520. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START2_MODE0, 0x80),
  521. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START3_MODE0, 0x07),
  522. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE0, 0x2f),
  523. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE0, 0x2a),
  524. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP_EN, 0x08),
  525. };
  526. static const struct qmp_phy_init_tbl qmp_v4_dp_tx_tbl[] = {
  527. QMP_PHY_INIT_CFG(QSERDES_V4_TX_VMODE_CTRL1, 0x40),
  528. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PRE_STALL_LDO_BOOST_EN, 0x30),
  529. QMP_PHY_INIT_CFG(QSERDES_V4_TX_INTERFACE_SELECT, 0x3b),
  530. QMP_PHY_INIT_CFG(QSERDES_V4_TX_CLKBUF_ENABLE, 0x0f),
  531. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RESET_TSYNC_EN, 0x03),
  532. QMP_PHY_INIT_CFG(QSERDES_V4_TX_TRAN_DRVR_EMP_EN, 0x0f),
  533. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PARRATE_REC_DETECT_IDLE_EN, 0x00),
  534. QMP_PHY_INIT_CFG(QSERDES_V4_TX_TX_INTERFACE_MODE, 0x00),
  535. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_OFFSET_TX, 0x11),
  536. QMP_PHY_INIT_CFG(QSERDES_V4_TX_RES_CODE_LANE_OFFSET_RX, 0x11),
  537. QMP_PHY_INIT_CFG(QSERDES_V4_TX_TX_BAND, 0x4),
  538. QMP_PHY_INIT_CFG(QSERDES_V4_TX_TX_POL_INV, 0x0a),
  539. QMP_PHY_INIT_CFG(QSERDES_V4_TX_TX_DRV_LVL, 0x2a),
  540. QMP_PHY_INIT_CFG(QSERDES_V4_TX_TX_EMP_POST1_LVL, 0x20),
  541. };
  542. static const struct qmp_phy_init_tbl qmp_v5_dp_serdes_tbl[] = {
  543. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SVS_MODE_CLK_SEL, 0x05),
  544. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_EN_SEL, 0x3b),
  545. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYS_CLK_CTRL, 0x02),
  546. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CLK_ENABLE1, 0x0c),
  547. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_BUF_ENABLE, 0x06),
  548. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CLK_SELECT, 0x30),
  549. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_IVCO, 0x0f),
  550. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE0, 0x36),
  551. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE1, 0x36),
  552. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE0, 0x16),
  553. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE1, 0x16),
  554. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE0, 0x06),
  555. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE1, 0x06),
  556. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CMN_CONFIG, 0x02),
  557. QMP_PHY_INIT_CFG(QSERDES_V4_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
  558. QMP_PHY_INIT_CFG(QSERDES_V4_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  559. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x02),
  560. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DIV_FRAC_START1_MODE0, 0x00),
  561. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BG_TIMER, 0x0a),
  562. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CORECLK_DIV_MODE0, 0x0a),
  563. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_CTRL, 0x00),
  564. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIAS_EN_CLKBUFLR_EN, 0x17),
  565. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CORE_CLK_EN, 0x1f),
  566. };
  567. static const struct qmp_phy_init_tbl qmp_v5_5nm_dp_tx_tbl[] = {
  568. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_LANE_MODE_3, 0x51),
  569. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_TRANSCEIVER_BIAS_EN, 0x1a),
  570. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_VMODE_CTRL1, 0x40),
  571. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_PRE_STALL_LDO_BOOST_EN, 0x0),
  572. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_INTERFACE_SELECT, 0xff),
  573. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_CLKBUF_ENABLE, 0x0f),
  574. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_RESET_TSYNC_EN, 0x03),
  575. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_TRAN_DRVR_EMP_EN, 0xf),
  576. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_PARRATE_REC_DETECT_IDLE_EN, 0x00),
  577. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_RES_CODE_LANE_OFFSET_TX, 0x11),
  578. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_RES_CODE_LANE_OFFSET_RX, 0x11),
  579. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_TX_BAND, 0x01),
  580. };
  581. static const struct qmp_phy_init_tbl sc8280xp_usb43dp_serdes_tbl[] = {
  582. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SSC_EN_CENTER, 0x01),
  583. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SSC_PER1, 0x31),
  584. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SSC_PER2, 0x01),
  585. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SSC_STEP_SIZE1_MODE0, 0xfd),
  586. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SSC_STEP_SIZE2_MODE0, 0x0d),
  587. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SSC_STEP_SIZE1_MODE1, 0xfd),
  588. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SSC_STEP_SIZE2_MODE1, 0x0d),
  589. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SYSCLK_BUF_ENABLE, 0x0a),
  590. QMP_PHY_INIT_CFG(QSERDES_V5_COM_CP_CTRL_MODE0, 0x02),
  591. QMP_PHY_INIT_CFG(QSERDES_V5_COM_CP_CTRL_MODE1, 0x02),
  592. QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_RCTRL_MODE0, 0x16),
  593. QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_RCTRL_MODE1, 0x16),
  594. QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_CCTRL_MODE0, 0x36),
  595. QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_CCTRL_MODE1, 0x36),
  596. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SYSCLK_EN_SEL, 0x1a),
  597. QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP_EN, 0x04),
  598. QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP1_MODE0, 0x14),
  599. QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP2_MODE0, 0x34),
  600. QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP1_MODE1, 0x34),
  601. QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP2_MODE1, 0x82),
  602. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DEC_START_MODE0, 0x04),
  603. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DEC_START_MSB_MODE0, 0x01),
  604. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DEC_START_MODE1, 0x04),
  605. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DEC_START_MSB_MODE1, 0x01),
  606. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DIV_FRAC_START1_MODE0, 0x55),
  607. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DIV_FRAC_START2_MODE0, 0xd5),
  608. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DIV_FRAC_START3_MODE0, 0x05),
  609. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DIV_FRAC_START1_MODE1, 0x55),
  610. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DIV_FRAC_START2_MODE1, 0xd5),
  611. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DIV_FRAC_START3_MODE1, 0x05),
  612. QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_MAP, 0x02),
  613. QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE1_MODE0, 0xd4),
  614. QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE2_MODE0, 0x00),
  615. QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE1_MODE1, 0xd4),
  616. QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE2_MODE1, 0x00),
  617. QMP_PHY_INIT_CFG(QSERDES_V5_COM_HSCLK_SEL, 0x13),
  618. QMP_PHY_INIT_CFG(QSERDES_V5_COM_HSCLK_HS_SWITCH_SEL, 0x00),
  619. QMP_PHY_INIT_CFG(QSERDES_V5_COM_CORECLK_DIV_MODE0, 0x0a),
  620. QMP_PHY_INIT_CFG(QSERDES_V5_COM_CORECLK_DIV_MODE1, 0x04),
  621. QMP_PHY_INIT_CFG(QSERDES_V5_COM_CORE_CLK_EN, 0x60),
  622. QMP_PHY_INIT_CFG(QSERDES_V5_COM_CMN_CONFIG, 0x76),
  623. QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_IVCO, 0xff),
  624. QMP_PHY_INIT_CFG(QSERDES_V5_COM_INTEGLOOP_GAIN0_MODE0, 0x20),
  625. QMP_PHY_INIT_CFG(QSERDES_V5_COM_INTEGLOOP_GAIN0_MODE1, 0x20),
  626. QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_INITVAL2, 0x00),
  627. QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_MAXVAL2, 0x01),
  628. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SVS_MODE_CLK_SEL, 0x0a),
  629. };
  630. static const struct qmp_phy_init_tbl sc8280xp_usb43dp_tx_tbl[] = {
  631. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_LANE_MODE_1, 0x05),
  632. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_LANE_MODE_2, 0xc2),
  633. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_LANE_MODE_3, 0x10),
  634. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_RES_CODE_LANE_OFFSET_TX, 0x1f),
  635. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_TX_RES_CODE_LANE_OFFSET_RX, 0x0a),
  636. };
  637. static const struct qmp_phy_init_tbl sc8280xp_usb43dp_rx_tbl[] = {
  638. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_SIGDET_CNTRL, 0x04),
  639. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_SIGDET_DEGLITCH_CNTRL, 0x0e),
  640. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_SIGDET_ENABLES, 0x00),
  641. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE_0_1_B0, 0xd2),
  642. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE_0_1_B1, 0xd2),
  643. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE_0_1_B2, 0xdb),
  644. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE_0_1_B3, 0x21),
  645. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE_0_1_B4, 0x3f),
  646. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE_0_1_B5, 0x80),
  647. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE_0_1_B6, 0x45),
  648. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE_0_1_B7, 0x00),
  649. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE2_B0, 0x6b),
  650. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE2_B1, 0x63),
  651. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE2_B2, 0xb6),
  652. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE2_B3, 0x23),
  653. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE2_B4, 0x35),
  654. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE2_B5, 0x30),
  655. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE2_B6, 0x8e),
  656. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_MODE_RATE2_B7, 0x00),
  657. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_IVCM_CAL_CODE_OVERRIDE, 0x00),
  658. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_IVCM_CAL_CTRL2, 0x80),
  659. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_SUMMER_CAL_SPD_MODE, 0x1b),
  660. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_DFE_CTLE_POST_CAL_OFFSET, 0x38),
  661. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_UCDR_PI_CONTROLS, 0x15),
  662. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_UCDR_SB2_GAIN2_RATE2, 0x0a),
  663. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_RX_IVCM_POSTCAL_OFFSET, 0x7c),
  664. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_VGA_CAL_CNTRL1, 0x00),
  665. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_VGA_CAL_MAN_VAL, 0x0d),
  666. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_DFE_DAC_ENABLE1, 0x00),
  667. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_DFE_3, 0x45),
  668. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_GM_CAL, 0x09),
  669. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_UCDR_FO_GAIN_RATE2, 0x09),
  670. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_UCDR_SO_GAIN_RATE2, 0x05),
  671. QMP_PHY_INIT_CFG(QSERDES_V5_5NM_RX_Q_PI_INTRINSIC_BIAS_RATE32, 0x3f),
  672. };
  673. static const struct qmp_phy_init_tbl sc8280xp_usb43dp_pcs_tbl[] = {
  674. QMP_PHY_INIT_CFG(QPHY_V5_PCS_RCVR_DTCT_DLY_P1U2_L, 0xe7),
  675. QMP_PHY_INIT_CFG(QPHY_V5_PCS_RCVR_DTCT_DLY_P1U2_H, 0x03),
  676. QMP_PHY_INIT_CFG(QPHY_V5_PCS_LOCK_DETECT_CONFIG1, 0xd0),
  677. QMP_PHY_INIT_CFG(QPHY_V5_PCS_LOCK_DETECT_CONFIG2, 0x07),
  678. QMP_PHY_INIT_CFG(QPHY_V5_PCS_LOCK_DETECT_CONFIG3, 0x20),
  679. QMP_PHY_INIT_CFG(QPHY_V5_PCS_LOCK_DETECT_CONFIG6, 0x13),
  680. QMP_PHY_INIT_CFG(QPHY_V5_PCS_REFGEN_REQ_CONFIG1, 0x21),
  681. QMP_PHY_INIT_CFG(QPHY_V5_PCS_RX_SIGDET_LVL, 0xaa),
  682. QMP_PHY_INIT_CFG(QPHY_V5_PCS_RX_CONFIG, 0x0a),
  683. QMP_PHY_INIT_CFG(QPHY_V5_PCS_ALIGN_DETECT_CONFIG1, 0x88),
  684. QMP_PHY_INIT_CFG(QPHY_V5_PCS_ALIGN_DETECT_CONFIG2, 0x13),
  685. QMP_PHY_INIT_CFG(QPHY_V5_PCS_PCS_TX_RX_CONFIG, 0x0c),
  686. QMP_PHY_INIT_CFG(QPHY_V5_PCS_EQ_CONFIG1, 0x4b),
  687. QMP_PHY_INIT_CFG(QPHY_V5_PCS_EQ_CONFIG5, 0x10),
  688. QMP_PHY_INIT_CFG(QPHY_V5_PCS_USB3_LFPS_DET_HIGH_COUNT_VAL, 0xf8),
  689. QMP_PHY_INIT_CFG(QPHY_V5_PCS_USB3_RXEQTRAINING_DFE_TIME_S2, 0x07),
  690. };
  691. /* list of regulators */
  692. struct qmp_regulator_data {
  693. const char *name;
  694. unsigned int enable_load;
  695. };
  696. static struct qmp_regulator_data qmp_phy_vreg_l[] = {
  697. { .name = "vdda-phy", .enable_load = 21800 },
  698. { .name = "vdda-pll", .enable_load = 36000 },
  699. };
  700. static const u8 qmp_dp_v3_pre_emphasis_hbr3_hbr2[4][4] = {
  701. { 0x00, 0x0c, 0x15, 0x1a },
  702. { 0x02, 0x0e, 0x16, 0xff },
  703. { 0x02, 0x11, 0xff, 0xff },
  704. { 0x04, 0xff, 0xff, 0xff }
  705. };
  706. static const u8 qmp_dp_v3_voltage_swing_hbr3_hbr2[4][4] = {
  707. { 0x02, 0x12, 0x16, 0x1a },
  708. { 0x09, 0x19, 0x1f, 0xff },
  709. { 0x10, 0x1f, 0xff, 0xff },
  710. { 0x1f, 0xff, 0xff, 0xff }
  711. };
  712. static const u8 qmp_dp_v3_pre_emphasis_hbr_rbr[4][4] = {
  713. { 0x00, 0x0c, 0x14, 0x19 },
  714. { 0x00, 0x0b, 0x12, 0xff },
  715. { 0x00, 0x0b, 0xff, 0xff },
  716. { 0x04, 0xff, 0xff, 0xff }
  717. };
  718. static const u8 qmp_dp_v3_voltage_swing_hbr_rbr[4][4] = {
  719. { 0x08, 0x0f, 0x16, 0x1f },
  720. { 0x11, 0x1e, 0x1f, 0xff },
  721. { 0x19, 0x1f, 0xff, 0xff },
  722. { 0x1f, 0xff, 0xff, 0xff }
  723. };
  724. static const u8 qmp_dp_v5_pre_emphasis_hbr3_hbr2[4][4] = {
  725. { 0x20, 0x2c, 0x35, 0x3b },
  726. { 0x22, 0x2e, 0x36, 0xff },
  727. { 0x22, 0x31, 0xff, 0xff },
  728. { 0x24, 0xff, 0xff, 0xff }
  729. };
  730. static const u8 qmp_dp_v5_voltage_swing_hbr3_hbr2[4][4] = {
  731. { 0x22, 0x32, 0x36, 0x3a },
  732. { 0x29, 0x39, 0x3f, 0xff },
  733. { 0x30, 0x3f, 0xff, 0xff },
  734. { 0x3f, 0xff, 0xff, 0xff }
  735. };
  736. static const u8 qmp_dp_v5_pre_emphasis_hbr_rbr[4][4] = {
  737. { 0x20, 0x2d, 0x34, 0x3a },
  738. { 0x20, 0x2e, 0x35, 0xff },
  739. { 0x20, 0x2e, 0xff, 0xff },
  740. { 0x24, 0xff, 0xff, 0xff }
  741. };
  742. static const u8 qmp_dp_v5_voltage_swing_hbr_rbr[4][4] = {
  743. { 0x28, 0x2f, 0x36, 0x3f },
  744. { 0x31, 0x3e, 0x3f, 0xff },
  745. { 0x36, 0x3f, 0xff, 0xff },
  746. { 0x3f, 0xff, 0xff, 0xff }
  747. };
  748. struct qmp_phy;
  749. /* struct qmp_phy_cfg - per-PHY initialization config */
  750. struct qmp_phy_cfg {
  751. /* phy-type - PCIE/UFS/USB */
  752. unsigned int type;
  753. int lanes;
  754. /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
  755. const struct qmp_phy_init_tbl *serdes_tbl;
  756. int serdes_tbl_num;
  757. const struct qmp_phy_init_tbl *tx_tbl;
  758. int tx_tbl_num;
  759. const struct qmp_phy_init_tbl *rx_tbl;
  760. int rx_tbl_num;
  761. const struct qmp_phy_init_tbl *pcs_tbl;
  762. int pcs_tbl_num;
  763. const struct qmp_phy_init_tbl *pcs_usb_tbl;
  764. int pcs_usb_tbl_num;
  765. /* Init sequence for DP PHY block link rates */
  766. const struct qmp_phy_init_tbl *serdes_tbl_rbr;
  767. int serdes_tbl_rbr_num;
  768. const struct qmp_phy_init_tbl *serdes_tbl_hbr;
  769. int serdes_tbl_hbr_num;
  770. const struct qmp_phy_init_tbl *serdes_tbl_hbr2;
  771. int serdes_tbl_hbr2_num;
  772. const struct qmp_phy_init_tbl *serdes_tbl_hbr3;
  773. int serdes_tbl_hbr3_num;
  774. /* DP PHY swing and pre_emphasis tables */
  775. const u8 (*swing_hbr_rbr)[4][4];
  776. const u8 (*swing_hbr3_hbr2)[4][4];
  777. const u8 (*pre_emphasis_hbr_rbr)[4][4];
  778. const u8 (*pre_emphasis_hbr3_hbr2)[4][4];
  779. /* DP PHY callbacks */
  780. int (*configure_dp_phy)(struct qmp_phy *qphy);
  781. void (*configure_dp_tx)(struct qmp_phy *qphy);
  782. int (*calibrate_dp_phy)(struct qmp_phy *qphy);
  783. void (*dp_aux_init)(struct qmp_phy *qphy);
  784. /* clock ids to be requested */
  785. const char * const *clk_list;
  786. int num_clks;
  787. /* resets to be requested */
  788. const char * const *reset_list;
  789. int num_resets;
  790. /* regulators to be requested */
  791. const struct qmp_regulator_data *vreg_list;
  792. int num_vregs;
  793. /* array of registers with different offsets */
  794. const unsigned int *regs;
  795. unsigned int start_ctrl;
  796. unsigned int pwrdn_ctrl;
  797. /* bit offset of PHYSTATUS in QPHY_PCS_STATUS register */
  798. unsigned int phy_status;
  799. /* true, if PHY needs delay after POWER_DOWN */
  800. bool has_pwrdn_delay;
  801. /* power_down delay in usec */
  802. int pwrdn_delay_min;
  803. int pwrdn_delay_max;
  804. /* Offset from PCS to PCS_USB region */
  805. unsigned int pcs_usb_offset;
  806. };
  807. struct qmp_phy_combo_cfg {
  808. const struct qmp_phy_cfg *usb_cfg;
  809. const struct qmp_phy_cfg *dp_cfg;
  810. };
  811. /**
  812. * struct qmp_phy - per-lane phy descriptor
  813. *
  814. * @phy: generic phy
  815. * @cfg: phy specific configuration
  816. * @serdes: iomapped memory space for phy's serdes (i.e. PLL)
  817. * @tx: iomapped memory space for lane's tx
  818. * @rx: iomapped memory space for lane's rx
  819. * @pcs: iomapped memory space for lane's pcs
  820. * @tx2: iomapped memory space for second lane's tx (in dual lane PHYs)
  821. * @rx2: iomapped memory space for second lane's rx (in dual lane PHYs)
  822. * @pcs_misc: iomapped memory space for lane's pcs_misc
  823. * @pcs_usb: iomapped memory space for lane's pcs_usb
  824. * @pipe_clk: pipe clock
  825. * @qmp: QMP phy to which this lane belongs
  826. * @mode: current PHY mode
  827. * @dp_aux_cfg: Display port aux config
  828. * @dp_opts: Display port optional config
  829. * @dp_clks: Display port clocks
  830. */
  831. struct qmp_phy {
  832. struct phy *phy;
  833. const struct qmp_phy_cfg *cfg;
  834. void __iomem *serdes;
  835. void __iomem *tx;
  836. void __iomem *rx;
  837. void __iomem *pcs;
  838. void __iomem *tx2;
  839. void __iomem *rx2;
  840. void __iomem *pcs_misc;
  841. void __iomem *pcs_usb;
  842. struct clk *pipe_clk;
  843. struct qcom_qmp *qmp;
  844. enum phy_mode mode;
  845. unsigned int dp_aux_cfg;
  846. struct phy_configure_opts_dp dp_opts;
  847. struct qmp_phy_dp_clks *dp_clks;
  848. };
  849. struct qmp_phy_dp_clks {
  850. struct qmp_phy *qphy;
  851. struct clk_hw dp_link_hw;
  852. struct clk_hw dp_pixel_hw;
  853. };
  854. /**
  855. * struct qcom_qmp - structure holding QMP phy block attributes
  856. *
  857. * @dev: device
  858. * @dp_com: iomapped memory space for phy's dp_com control block
  859. *
  860. * @clks: array of clocks required by phy
  861. * @resets: array of resets required by phy
  862. * @vregs: regulator supplies bulk data
  863. *
  864. * @phys: array of per-lane phy descriptors
  865. * @phy_mutex: mutex lock for PHY common block initialization
  866. * @init_count: phy common block initialization count
  867. * @ufs_reset: optional UFS PHY reset handle
  868. */
  869. struct qcom_qmp {
  870. struct device *dev;
  871. void __iomem *dp_com;
  872. struct clk_bulk_data *clks;
  873. struct reset_control_bulk_data *resets;
  874. struct regulator_bulk_data *vregs;
  875. struct qmp_phy **phys;
  876. struct qmp_phy *usb_phy;
  877. struct mutex phy_mutex;
  878. int init_count;
  879. struct reset_control *ufs_reset;
  880. };
  881. static void qcom_qmp_v3_phy_dp_aux_init(struct qmp_phy *qphy);
  882. static void qcom_qmp_v3_phy_configure_dp_tx(struct qmp_phy *qphy);
  883. static int qcom_qmp_v3_phy_configure_dp_phy(struct qmp_phy *qphy);
  884. static int qcom_qmp_v3_dp_phy_calibrate(struct qmp_phy *qphy);
  885. static void qcom_qmp_v4_phy_dp_aux_init(struct qmp_phy *qphy);
  886. static void qcom_qmp_v4_phy_configure_dp_tx(struct qmp_phy *qphy);
  887. static int qcom_qmp_v4_phy_configure_dp_phy(struct qmp_phy *qphy);
  888. static int qcom_qmp_v4_dp_phy_calibrate(struct qmp_phy *qphy);
  889. static int qcom_qmp_v5_phy_configure_dp_phy(struct qmp_phy *qphy);
  890. static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
  891. {
  892. u32 reg;
  893. reg = readl(base + offset);
  894. reg |= val;
  895. writel(reg, base + offset);
  896. /* ensure that above write is through */
  897. readl(base + offset);
  898. }
  899. static inline void qphy_clrbits(void __iomem *base, u32 offset, u32 val)
  900. {
  901. u32 reg;
  902. reg = readl(base + offset);
  903. reg &= ~val;
  904. writel(reg, base + offset);
  905. /* ensure that above write is through */
  906. readl(base + offset);
  907. }
  908. /* list of clocks required by phy */
  909. static const char * const qmp_v3_phy_clk_l[] = {
  910. "aux", "cfg_ahb", "ref", "com_aux",
  911. };
  912. static const char * const qmp_v4_phy_clk_l[] = {
  913. "aux", "ref_clk_src", "ref", "com_aux",
  914. };
  915. /* the primary usb3 phy on sm8250 doesn't have a ref clock */
  916. static const char * const qmp_v4_sm8250_usbphy_clk_l[] = {
  917. "aux", "ref_clk_src", "com_aux"
  918. };
  919. /* list of resets */
  920. static const char * const msm8996_usb3phy_reset_l[] = {
  921. "phy", "common",
  922. };
  923. static const char * const sc7180_usb3phy_reset_l[] = {
  924. "phy",
  925. };
  926. static const struct qmp_phy_cfg sc7180_usb3phy_cfg = {
  927. .type = PHY_TYPE_USB3,
  928. .lanes = 2,
  929. .serdes_tbl = qmp_v3_usb3_serdes_tbl,
  930. .serdes_tbl_num = ARRAY_SIZE(qmp_v3_usb3_serdes_tbl),
  931. .tx_tbl = qmp_v3_usb3_tx_tbl,
  932. .tx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_tx_tbl),
  933. .rx_tbl = qmp_v3_usb3_rx_tbl,
  934. .rx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_rx_tbl),
  935. .pcs_tbl = qmp_v3_usb3_pcs_tbl,
  936. .pcs_tbl_num = ARRAY_SIZE(qmp_v3_usb3_pcs_tbl),
  937. .clk_list = qmp_v3_phy_clk_l,
  938. .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
  939. .reset_list = sc7180_usb3phy_reset_l,
  940. .num_resets = ARRAY_SIZE(sc7180_usb3phy_reset_l),
  941. .vreg_list = qmp_phy_vreg_l,
  942. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  943. .regs = qmp_v3_usb3phy_regs_layout,
  944. .start_ctrl = SERDES_START | PCS_START,
  945. .pwrdn_ctrl = SW_PWRDN,
  946. .phy_status = PHYSTATUS,
  947. .has_pwrdn_delay = true,
  948. .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
  949. .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
  950. };
  951. static const struct qmp_phy_cfg sc7180_dpphy_cfg = {
  952. .type = PHY_TYPE_DP,
  953. .lanes = 2,
  954. .serdes_tbl = qmp_v3_dp_serdes_tbl,
  955. .serdes_tbl_num = ARRAY_SIZE(qmp_v3_dp_serdes_tbl),
  956. .tx_tbl = qmp_v3_dp_tx_tbl,
  957. .tx_tbl_num = ARRAY_SIZE(qmp_v3_dp_tx_tbl),
  958. .serdes_tbl_rbr = qmp_v3_dp_serdes_tbl_rbr,
  959. .serdes_tbl_rbr_num = ARRAY_SIZE(qmp_v3_dp_serdes_tbl_rbr),
  960. .serdes_tbl_hbr = qmp_v3_dp_serdes_tbl_hbr,
  961. .serdes_tbl_hbr_num = ARRAY_SIZE(qmp_v3_dp_serdes_tbl_hbr),
  962. .serdes_tbl_hbr2 = qmp_v3_dp_serdes_tbl_hbr2,
  963. .serdes_tbl_hbr2_num = ARRAY_SIZE(qmp_v3_dp_serdes_tbl_hbr2),
  964. .serdes_tbl_hbr3 = qmp_v3_dp_serdes_tbl_hbr3,
  965. .serdes_tbl_hbr3_num = ARRAY_SIZE(qmp_v3_dp_serdes_tbl_hbr3),
  966. .swing_hbr_rbr = &qmp_dp_v3_voltage_swing_hbr_rbr,
  967. .pre_emphasis_hbr_rbr = &qmp_dp_v3_pre_emphasis_hbr_rbr,
  968. .swing_hbr3_hbr2 = &qmp_dp_v3_voltage_swing_hbr3_hbr2,
  969. .pre_emphasis_hbr3_hbr2 = &qmp_dp_v3_pre_emphasis_hbr3_hbr2,
  970. .clk_list = qmp_v3_phy_clk_l,
  971. .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
  972. .reset_list = sc7180_usb3phy_reset_l,
  973. .num_resets = ARRAY_SIZE(sc7180_usb3phy_reset_l),
  974. .vreg_list = qmp_phy_vreg_l,
  975. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  976. .regs = qmp_v3_usb3phy_regs_layout,
  977. .dp_aux_init = qcom_qmp_v3_phy_dp_aux_init,
  978. .configure_dp_tx = qcom_qmp_v3_phy_configure_dp_tx,
  979. .configure_dp_phy = qcom_qmp_v3_phy_configure_dp_phy,
  980. .calibrate_dp_phy = qcom_qmp_v3_dp_phy_calibrate,
  981. };
  982. static const struct qmp_phy_combo_cfg sc7180_usb3dpphy_cfg = {
  983. .usb_cfg = &sc7180_usb3phy_cfg,
  984. .dp_cfg = &sc7180_dpphy_cfg,
  985. };
  986. static const struct qmp_phy_cfg sdm845_usb3phy_cfg = {
  987. .type = PHY_TYPE_USB3,
  988. .lanes = 2,
  989. .serdes_tbl = qmp_v3_usb3_serdes_tbl,
  990. .serdes_tbl_num = ARRAY_SIZE(qmp_v3_usb3_serdes_tbl),
  991. .tx_tbl = qmp_v3_usb3_tx_tbl,
  992. .tx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_tx_tbl),
  993. .rx_tbl = qmp_v3_usb3_rx_tbl,
  994. .rx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_rx_tbl),
  995. .pcs_tbl = qmp_v3_usb3_pcs_tbl,
  996. .pcs_tbl_num = ARRAY_SIZE(qmp_v3_usb3_pcs_tbl),
  997. .clk_list = qmp_v3_phy_clk_l,
  998. .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
  999. .reset_list = msm8996_usb3phy_reset_l,
  1000. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  1001. .vreg_list = qmp_phy_vreg_l,
  1002. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1003. .regs = qmp_v3_usb3phy_regs_layout,
  1004. .start_ctrl = SERDES_START | PCS_START,
  1005. .pwrdn_ctrl = SW_PWRDN,
  1006. .phy_status = PHYSTATUS,
  1007. .has_pwrdn_delay = true,
  1008. .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
  1009. .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
  1010. };
  1011. static const struct qmp_phy_cfg sdm845_dpphy_cfg = {
  1012. .type = PHY_TYPE_DP,
  1013. .lanes = 2,
  1014. .serdes_tbl = qmp_v3_dp_serdes_tbl,
  1015. .serdes_tbl_num = ARRAY_SIZE(qmp_v3_dp_serdes_tbl),
  1016. .tx_tbl = qmp_v3_dp_tx_tbl,
  1017. .tx_tbl_num = ARRAY_SIZE(qmp_v3_dp_tx_tbl),
  1018. .serdes_tbl_rbr = qmp_v3_dp_serdes_tbl_rbr,
  1019. .serdes_tbl_rbr_num = ARRAY_SIZE(qmp_v3_dp_serdes_tbl_rbr),
  1020. .serdes_tbl_hbr = qmp_v3_dp_serdes_tbl_hbr,
  1021. .serdes_tbl_hbr_num = ARRAY_SIZE(qmp_v3_dp_serdes_tbl_hbr),
  1022. .serdes_tbl_hbr2 = qmp_v3_dp_serdes_tbl_hbr2,
  1023. .serdes_tbl_hbr2_num = ARRAY_SIZE(qmp_v3_dp_serdes_tbl_hbr2),
  1024. .serdes_tbl_hbr3 = qmp_v3_dp_serdes_tbl_hbr3,
  1025. .serdes_tbl_hbr3_num = ARRAY_SIZE(qmp_v3_dp_serdes_tbl_hbr3),
  1026. .swing_hbr_rbr = &qmp_dp_v3_voltage_swing_hbr_rbr,
  1027. .pre_emphasis_hbr_rbr = &qmp_dp_v3_pre_emphasis_hbr_rbr,
  1028. .swing_hbr3_hbr2 = &qmp_dp_v3_voltage_swing_hbr3_hbr2,
  1029. .pre_emphasis_hbr3_hbr2 = &qmp_dp_v3_pre_emphasis_hbr3_hbr2,
  1030. .clk_list = qmp_v3_phy_clk_l,
  1031. .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
  1032. .reset_list = msm8996_usb3phy_reset_l,
  1033. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  1034. .vreg_list = qmp_phy_vreg_l,
  1035. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1036. .regs = qmp_v3_usb3phy_regs_layout,
  1037. .dp_aux_init = qcom_qmp_v3_phy_dp_aux_init,
  1038. .configure_dp_tx = qcom_qmp_v3_phy_configure_dp_tx,
  1039. .configure_dp_phy = qcom_qmp_v3_phy_configure_dp_phy,
  1040. .calibrate_dp_phy = qcom_qmp_v3_dp_phy_calibrate,
  1041. };
  1042. static const struct qmp_phy_combo_cfg sdm845_usb3dpphy_cfg = {
  1043. .usb_cfg = &sdm845_usb3phy_cfg,
  1044. .dp_cfg = &sdm845_dpphy_cfg,
  1045. };
  1046. static const struct qmp_phy_cfg sm8150_usb3phy_cfg = {
  1047. .type = PHY_TYPE_USB3,
  1048. .lanes = 2,
  1049. .serdes_tbl = sm8150_usb3_serdes_tbl,
  1050. .serdes_tbl_num = ARRAY_SIZE(sm8150_usb3_serdes_tbl),
  1051. .tx_tbl = sm8150_usb3_tx_tbl,
  1052. .tx_tbl_num = ARRAY_SIZE(sm8150_usb3_tx_tbl),
  1053. .rx_tbl = sm8150_usb3_rx_tbl,
  1054. .rx_tbl_num = ARRAY_SIZE(sm8150_usb3_rx_tbl),
  1055. .pcs_tbl = sm8150_usb3_pcs_tbl,
  1056. .pcs_tbl_num = ARRAY_SIZE(sm8150_usb3_pcs_tbl),
  1057. .pcs_usb_tbl = sm8150_usb3_pcs_usb_tbl,
  1058. .pcs_usb_tbl_num = ARRAY_SIZE(sm8150_usb3_pcs_usb_tbl),
  1059. .clk_list = qmp_v4_phy_clk_l,
  1060. .num_clks = ARRAY_SIZE(qmp_v4_phy_clk_l),
  1061. .reset_list = msm8996_usb3phy_reset_l,
  1062. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  1063. .vreg_list = qmp_phy_vreg_l,
  1064. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1065. .regs = qmp_v4_usb3phy_regs_layout,
  1066. .pcs_usb_offset = 0x300,
  1067. .start_ctrl = SERDES_START | PCS_START,
  1068. .pwrdn_ctrl = SW_PWRDN,
  1069. .phy_status = PHYSTATUS,
  1070. .has_pwrdn_delay = true,
  1071. .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
  1072. .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
  1073. };
  1074. static const struct qmp_phy_cfg sc8180x_dpphy_cfg = {
  1075. .type = PHY_TYPE_DP,
  1076. .lanes = 2,
  1077. .serdes_tbl = qmp_v4_dp_serdes_tbl,
  1078. .serdes_tbl_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl),
  1079. .tx_tbl = qmp_v4_dp_tx_tbl,
  1080. .tx_tbl_num = ARRAY_SIZE(qmp_v4_dp_tx_tbl),
  1081. .serdes_tbl_rbr = qmp_v4_dp_serdes_tbl_rbr,
  1082. .serdes_tbl_rbr_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_rbr),
  1083. .serdes_tbl_hbr = qmp_v4_dp_serdes_tbl_hbr,
  1084. .serdes_tbl_hbr_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_hbr),
  1085. .serdes_tbl_hbr2 = qmp_v4_dp_serdes_tbl_hbr2,
  1086. .serdes_tbl_hbr2_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_hbr2),
  1087. .serdes_tbl_hbr3 = qmp_v4_dp_serdes_tbl_hbr3,
  1088. .serdes_tbl_hbr3_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_hbr3),
  1089. .swing_hbr_rbr = &qmp_dp_v3_voltage_swing_hbr_rbr,
  1090. .pre_emphasis_hbr_rbr = &qmp_dp_v3_pre_emphasis_hbr_rbr,
  1091. .swing_hbr3_hbr2 = &qmp_dp_v3_voltage_swing_hbr3_hbr2,
  1092. .pre_emphasis_hbr3_hbr2 = &qmp_dp_v3_pre_emphasis_hbr3_hbr2,
  1093. .clk_list = qmp_v3_phy_clk_l,
  1094. .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
  1095. .reset_list = msm8996_usb3phy_reset_l,
  1096. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  1097. .vreg_list = qmp_phy_vreg_l,
  1098. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1099. .regs = qmp_v3_usb3phy_regs_layout,
  1100. .dp_aux_init = qcom_qmp_v4_phy_dp_aux_init,
  1101. .configure_dp_tx = qcom_qmp_v4_phy_configure_dp_tx,
  1102. .configure_dp_phy = qcom_qmp_v4_phy_configure_dp_phy,
  1103. .calibrate_dp_phy = qcom_qmp_v4_dp_phy_calibrate,
  1104. };
  1105. static const struct qmp_phy_combo_cfg sc8180x_usb3dpphy_cfg = {
  1106. .usb_cfg = &sm8150_usb3phy_cfg,
  1107. .dp_cfg = &sc8180x_dpphy_cfg,
  1108. };
  1109. static const struct qmp_phy_cfg sc8280xp_usb43dp_usb_cfg = {
  1110. .type = PHY_TYPE_USB3,
  1111. .lanes = 2,
  1112. .serdes_tbl = sc8280xp_usb43dp_serdes_tbl,
  1113. .serdes_tbl_num = ARRAY_SIZE(sc8280xp_usb43dp_serdes_tbl),
  1114. .tx_tbl = sc8280xp_usb43dp_tx_tbl,
  1115. .tx_tbl_num = ARRAY_SIZE(sc8280xp_usb43dp_tx_tbl),
  1116. .rx_tbl = sc8280xp_usb43dp_rx_tbl,
  1117. .rx_tbl_num = ARRAY_SIZE(sc8280xp_usb43dp_rx_tbl),
  1118. .pcs_tbl = sc8280xp_usb43dp_pcs_tbl,
  1119. .pcs_tbl_num = ARRAY_SIZE(sc8280xp_usb43dp_pcs_tbl),
  1120. .clk_list = qmp_v4_phy_clk_l,
  1121. .num_clks = ARRAY_SIZE(qmp_v4_phy_clk_l),
  1122. .reset_list = msm8996_usb3phy_reset_l,
  1123. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  1124. .vreg_list = qmp_phy_vreg_l,
  1125. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1126. .regs = qmp_v4_usb3phy_regs_layout,
  1127. .pcs_usb_offset = 0x300,
  1128. .start_ctrl = SERDES_START | PCS_START,
  1129. .pwrdn_ctrl = SW_PWRDN,
  1130. .phy_status = PHYSTATUS,
  1131. .has_pwrdn_delay = true,
  1132. .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
  1133. .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
  1134. };
  1135. static const struct qmp_phy_cfg sc8280xp_usb43dp_dp_cfg = {
  1136. .type = PHY_TYPE_DP,
  1137. .lanes = 2,
  1138. .serdes_tbl = qmp_v5_dp_serdes_tbl,
  1139. .serdes_tbl_num = ARRAY_SIZE(qmp_v5_dp_serdes_tbl),
  1140. .tx_tbl = qmp_v5_5nm_dp_tx_tbl,
  1141. .tx_tbl_num = ARRAY_SIZE(qmp_v5_5nm_dp_tx_tbl),
  1142. .serdes_tbl_rbr = qmp_v4_dp_serdes_tbl_rbr,
  1143. .serdes_tbl_rbr_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_rbr),
  1144. .serdes_tbl_hbr = qmp_v4_dp_serdes_tbl_hbr,
  1145. .serdes_tbl_hbr_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_hbr),
  1146. .serdes_tbl_hbr2 = qmp_v4_dp_serdes_tbl_hbr2,
  1147. .serdes_tbl_hbr2_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_hbr2),
  1148. .serdes_tbl_hbr3 = qmp_v4_dp_serdes_tbl_hbr3,
  1149. .serdes_tbl_hbr3_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_hbr3),
  1150. .swing_hbr_rbr = &qmp_dp_v5_voltage_swing_hbr_rbr,
  1151. .pre_emphasis_hbr_rbr = &qmp_dp_v5_pre_emphasis_hbr_rbr,
  1152. .swing_hbr3_hbr2 = &qmp_dp_v5_voltage_swing_hbr3_hbr2,
  1153. .pre_emphasis_hbr3_hbr2 = &qmp_dp_v5_pre_emphasis_hbr3_hbr2,
  1154. .clk_list = qmp_v4_phy_clk_l,
  1155. .num_clks = ARRAY_SIZE(qmp_v4_phy_clk_l),
  1156. .reset_list = msm8996_usb3phy_reset_l,
  1157. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  1158. .vreg_list = qmp_phy_vreg_l,
  1159. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1160. .regs = qmp_v4_usb3phy_regs_layout,
  1161. .dp_aux_init = qcom_qmp_v4_phy_dp_aux_init,
  1162. .configure_dp_tx = qcom_qmp_v4_phy_configure_dp_tx,
  1163. .configure_dp_phy = qcom_qmp_v5_phy_configure_dp_phy,
  1164. .calibrate_dp_phy = qcom_qmp_v4_dp_phy_calibrate,
  1165. };
  1166. static const struct qmp_phy_combo_cfg sc8280xp_usb43dpphy_combo_cfg = {
  1167. .usb_cfg = &sc8280xp_usb43dp_usb_cfg,
  1168. .dp_cfg = &sc8280xp_usb43dp_dp_cfg,
  1169. };
  1170. static const struct qmp_phy_cfg sm8250_usb3phy_cfg = {
  1171. .type = PHY_TYPE_USB3,
  1172. .lanes = 2,
  1173. .serdes_tbl = sm8150_usb3_serdes_tbl,
  1174. .serdes_tbl_num = ARRAY_SIZE(sm8150_usb3_serdes_tbl),
  1175. .tx_tbl = sm8250_usb3_tx_tbl,
  1176. .tx_tbl_num = ARRAY_SIZE(sm8250_usb3_tx_tbl),
  1177. .rx_tbl = sm8250_usb3_rx_tbl,
  1178. .rx_tbl_num = ARRAY_SIZE(sm8250_usb3_rx_tbl),
  1179. .pcs_tbl = sm8250_usb3_pcs_tbl,
  1180. .pcs_tbl_num = ARRAY_SIZE(sm8250_usb3_pcs_tbl),
  1181. .pcs_usb_tbl = sm8250_usb3_pcs_usb_tbl,
  1182. .pcs_usb_tbl_num = ARRAY_SIZE(sm8250_usb3_pcs_usb_tbl),
  1183. .clk_list = qmp_v4_sm8250_usbphy_clk_l,
  1184. .num_clks = ARRAY_SIZE(qmp_v4_sm8250_usbphy_clk_l),
  1185. .reset_list = msm8996_usb3phy_reset_l,
  1186. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  1187. .vreg_list = qmp_phy_vreg_l,
  1188. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1189. .regs = qmp_v4_usb3phy_regs_layout,
  1190. .pcs_usb_offset = 0x300,
  1191. .start_ctrl = SERDES_START | PCS_START,
  1192. .pwrdn_ctrl = SW_PWRDN,
  1193. .phy_status = PHYSTATUS,
  1194. .has_pwrdn_delay = true,
  1195. .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
  1196. .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
  1197. };
  1198. static const struct qmp_phy_cfg sm8250_dpphy_cfg = {
  1199. .type = PHY_TYPE_DP,
  1200. .lanes = 2,
  1201. .serdes_tbl = qmp_v4_dp_serdes_tbl,
  1202. .serdes_tbl_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl),
  1203. .tx_tbl = qmp_v4_dp_tx_tbl,
  1204. .tx_tbl_num = ARRAY_SIZE(qmp_v4_dp_tx_tbl),
  1205. .serdes_tbl_rbr = qmp_v4_dp_serdes_tbl_rbr,
  1206. .serdes_tbl_rbr_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_rbr),
  1207. .serdes_tbl_hbr = qmp_v4_dp_serdes_tbl_hbr,
  1208. .serdes_tbl_hbr_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_hbr),
  1209. .serdes_tbl_hbr2 = qmp_v4_dp_serdes_tbl_hbr2,
  1210. .serdes_tbl_hbr2_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_hbr2),
  1211. .serdes_tbl_hbr3 = qmp_v4_dp_serdes_tbl_hbr3,
  1212. .serdes_tbl_hbr3_num = ARRAY_SIZE(qmp_v4_dp_serdes_tbl_hbr3),
  1213. .swing_hbr_rbr = &qmp_dp_v3_voltage_swing_hbr_rbr,
  1214. .pre_emphasis_hbr_rbr = &qmp_dp_v3_pre_emphasis_hbr_rbr,
  1215. .swing_hbr3_hbr2 = &qmp_dp_v3_voltage_swing_hbr3_hbr2,
  1216. .pre_emphasis_hbr3_hbr2 = &qmp_dp_v3_pre_emphasis_hbr3_hbr2,
  1217. .clk_list = qmp_v4_sm8250_usbphy_clk_l,
  1218. .num_clks = ARRAY_SIZE(qmp_v4_sm8250_usbphy_clk_l),
  1219. .reset_list = msm8996_usb3phy_reset_l,
  1220. .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
  1221. .vreg_list = qmp_phy_vreg_l,
  1222. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1223. .regs = qmp_v4_usb3phy_regs_layout,
  1224. .dp_aux_init = qcom_qmp_v4_phy_dp_aux_init,
  1225. .configure_dp_tx = qcom_qmp_v4_phy_configure_dp_tx,
  1226. .configure_dp_phy = qcom_qmp_v4_phy_configure_dp_phy,
  1227. .calibrate_dp_phy = qcom_qmp_v4_dp_phy_calibrate,
  1228. };
  1229. static const struct qmp_phy_combo_cfg sm8250_usb3dpphy_cfg = {
  1230. .usb_cfg = &sm8250_usb3phy_cfg,
  1231. .dp_cfg = &sm8250_dpphy_cfg,
  1232. };
  1233. static void qmp_combo_configure_lane(void __iomem *base,
  1234. const unsigned int *regs,
  1235. const struct qmp_phy_init_tbl tbl[],
  1236. int num,
  1237. u8 lane_mask)
  1238. {
  1239. int i;
  1240. const struct qmp_phy_init_tbl *t = tbl;
  1241. if (!t)
  1242. return;
  1243. for (i = 0; i < num; i++, t++) {
  1244. if (!(t->lane_mask & lane_mask))
  1245. continue;
  1246. if (t->in_layout)
  1247. writel(t->val, base + regs[t->offset]);
  1248. else
  1249. writel(t->val, base + t->offset);
  1250. }
  1251. }
  1252. static void qmp_combo_configure(void __iomem *base,
  1253. const unsigned int *regs,
  1254. const struct qmp_phy_init_tbl tbl[],
  1255. int num)
  1256. {
  1257. qmp_combo_configure_lane(base, regs, tbl, num, 0xff);
  1258. }
  1259. static int qmp_combo_serdes_init(struct qmp_phy *qphy)
  1260. {
  1261. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1262. void __iomem *serdes = qphy->serdes;
  1263. const struct phy_configure_opts_dp *dp_opts = &qphy->dp_opts;
  1264. const struct qmp_phy_init_tbl *serdes_tbl = cfg->serdes_tbl;
  1265. int serdes_tbl_num = cfg->serdes_tbl_num;
  1266. qmp_combo_configure(serdes, cfg->regs, serdes_tbl, serdes_tbl_num);
  1267. if (cfg->type == PHY_TYPE_DP) {
  1268. switch (dp_opts->link_rate) {
  1269. case 1620:
  1270. qmp_combo_configure(serdes, cfg->regs,
  1271. cfg->serdes_tbl_rbr,
  1272. cfg->serdes_tbl_rbr_num);
  1273. break;
  1274. case 2700:
  1275. qmp_combo_configure(serdes, cfg->regs,
  1276. cfg->serdes_tbl_hbr,
  1277. cfg->serdes_tbl_hbr_num);
  1278. break;
  1279. case 5400:
  1280. qmp_combo_configure(serdes, cfg->regs,
  1281. cfg->serdes_tbl_hbr2,
  1282. cfg->serdes_tbl_hbr2_num);
  1283. break;
  1284. case 8100:
  1285. qmp_combo_configure(serdes, cfg->regs,
  1286. cfg->serdes_tbl_hbr3,
  1287. cfg->serdes_tbl_hbr3_num);
  1288. break;
  1289. default:
  1290. /* Other link rates aren't supported */
  1291. return -EINVAL;
  1292. }
  1293. }
  1294. return 0;
  1295. }
  1296. static void qcom_qmp_v3_phy_dp_aux_init(struct qmp_phy *qphy)
  1297. {
  1298. writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
  1299. DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
  1300. qphy->pcs + QSERDES_DP_PHY_PD_CTL);
  1301. /* Turn on BIAS current for PHY/PLL */
  1302. writel(QSERDES_V3_COM_BIAS_EN | QSERDES_V3_COM_BIAS_EN_MUX |
  1303. QSERDES_V3_COM_CLKBUF_L_EN | QSERDES_V3_COM_EN_SYSCLK_TX_SEL,
  1304. qphy->serdes + QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN);
  1305. writel(DP_PHY_PD_CTL_PSR_PWRDN, qphy->pcs + QSERDES_DP_PHY_PD_CTL);
  1306. writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
  1307. DP_PHY_PD_CTL_LANE_0_1_PWRDN |
  1308. DP_PHY_PD_CTL_LANE_2_3_PWRDN | DP_PHY_PD_CTL_PLL_PWRDN |
  1309. DP_PHY_PD_CTL_DP_CLAMP_EN,
  1310. qphy->pcs + QSERDES_DP_PHY_PD_CTL);
  1311. writel(QSERDES_V3_COM_BIAS_EN |
  1312. QSERDES_V3_COM_BIAS_EN_MUX | QSERDES_V3_COM_CLKBUF_R_EN |
  1313. QSERDES_V3_COM_CLKBUF_L_EN | QSERDES_V3_COM_EN_SYSCLK_TX_SEL |
  1314. QSERDES_V3_COM_CLKBUF_RX_DRIVE_L,
  1315. qphy->serdes + QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN);
  1316. writel(0x00, qphy->pcs + QSERDES_DP_PHY_AUX_CFG0);
  1317. writel(0x13, qphy->pcs + QSERDES_DP_PHY_AUX_CFG1);
  1318. writel(0x24, qphy->pcs + QSERDES_DP_PHY_AUX_CFG2);
  1319. writel(0x00, qphy->pcs + QSERDES_DP_PHY_AUX_CFG3);
  1320. writel(0x0a, qphy->pcs + QSERDES_DP_PHY_AUX_CFG4);
  1321. writel(0x26, qphy->pcs + QSERDES_DP_PHY_AUX_CFG5);
  1322. writel(0x0a, qphy->pcs + QSERDES_DP_PHY_AUX_CFG6);
  1323. writel(0x03, qphy->pcs + QSERDES_DP_PHY_AUX_CFG7);
  1324. writel(0xbb, qphy->pcs + QSERDES_DP_PHY_AUX_CFG8);
  1325. writel(0x03, qphy->pcs + QSERDES_DP_PHY_AUX_CFG9);
  1326. qphy->dp_aux_cfg = 0;
  1327. writel(PHY_AUX_STOP_ERR_MASK | PHY_AUX_DEC_ERR_MASK |
  1328. PHY_AUX_SYNC_ERR_MASK | PHY_AUX_ALIGN_ERR_MASK |
  1329. PHY_AUX_REQ_ERR_MASK,
  1330. qphy->pcs + QSERDES_V3_DP_PHY_AUX_INTERRUPT_MASK);
  1331. }
  1332. static int qmp_combo_configure_dp_swing(struct qmp_phy *qphy,
  1333. unsigned int drv_lvl_reg, unsigned int emp_post_reg)
  1334. {
  1335. const struct phy_configure_opts_dp *dp_opts = &qphy->dp_opts;
  1336. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1337. unsigned int v_level = 0, p_level = 0;
  1338. u8 voltage_swing_cfg, pre_emphasis_cfg;
  1339. int i;
  1340. for (i = 0; i < dp_opts->lanes; i++) {
  1341. v_level = max(v_level, dp_opts->voltage[i]);
  1342. p_level = max(p_level, dp_opts->pre[i]);
  1343. }
  1344. if (dp_opts->link_rate <= 2700) {
  1345. voltage_swing_cfg = (*cfg->swing_hbr_rbr)[v_level][p_level];
  1346. pre_emphasis_cfg = (*cfg->pre_emphasis_hbr_rbr)[v_level][p_level];
  1347. } else {
  1348. voltage_swing_cfg = (*cfg->swing_hbr3_hbr2)[v_level][p_level];
  1349. pre_emphasis_cfg = (*cfg->pre_emphasis_hbr3_hbr2)[v_level][p_level];
  1350. }
  1351. /* TODO: Move check to config check */
  1352. if (voltage_swing_cfg == 0xFF && pre_emphasis_cfg == 0xFF)
  1353. return -EINVAL;
  1354. /* Enable MUX to use Cursor values from these registers */
  1355. voltage_swing_cfg |= DP_PHY_TXn_TX_DRV_LVL_MUX_EN;
  1356. pre_emphasis_cfg |= DP_PHY_TXn_TX_EMP_POST1_LVL_MUX_EN;
  1357. writel(voltage_swing_cfg, qphy->tx + drv_lvl_reg);
  1358. writel(pre_emphasis_cfg, qphy->tx + emp_post_reg);
  1359. writel(voltage_swing_cfg, qphy->tx2 + drv_lvl_reg);
  1360. writel(pre_emphasis_cfg, qphy->tx2 + emp_post_reg);
  1361. return 0;
  1362. }
  1363. static void qcom_qmp_v3_phy_configure_dp_tx(struct qmp_phy *qphy)
  1364. {
  1365. const struct phy_configure_opts_dp *dp_opts = &qphy->dp_opts;
  1366. u32 bias_en, drvr_en;
  1367. if (qmp_combo_configure_dp_swing(qphy, QSERDES_V3_TX_TX_DRV_LVL,
  1368. QSERDES_V3_TX_TX_EMP_POST1_LVL) < 0)
  1369. return;
  1370. if (dp_opts->lanes == 1) {
  1371. bias_en = 0x3e;
  1372. drvr_en = 0x13;
  1373. } else {
  1374. bias_en = 0x3f;
  1375. drvr_en = 0x10;
  1376. }
  1377. writel(drvr_en, qphy->tx + QSERDES_V3_TX_HIGHZ_DRVR_EN);
  1378. writel(bias_en, qphy->tx + QSERDES_V3_TX_TRANSCEIVER_BIAS_EN);
  1379. writel(drvr_en, qphy->tx2 + QSERDES_V3_TX_HIGHZ_DRVR_EN);
  1380. writel(bias_en, qphy->tx2 + QSERDES_V3_TX_TRANSCEIVER_BIAS_EN);
  1381. }
  1382. static bool qmp_combo_configure_dp_mode(struct qmp_phy *qphy)
  1383. {
  1384. u32 val;
  1385. bool reverse = false;
  1386. val = DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
  1387. DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN;
  1388. /*
  1389. * TODO: Assume orientation is CC1 for now and two lanes, need to
  1390. * use type-c connector to understand orientation and lanes.
  1391. *
  1392. * Otherwise val changes to be like below if this code understood
  1393. * the orientation of the type-c cable.
  1394. *
  1395. * if (lane_cnt == 4 || orientation == ORIENTATION_CC2)
  1396. * val |= DP_PHY_PD_CTL_LANE_0_1_PWRDN;
  1397. * if (lane_cnt == 4 || orientation == ORIENTATION_CC1)
  1398. * val |= DP_PHY_PD_CTL_LANE_2_3_PWRDN;
  1399. * if (orientation == ORIENTATION_CC2)
  1400. * writel(0x4c, qphy->pcs + QSERDES_V3_DP_PHY_MODE);
  1401. */
  1402. val |= DP_PHY_PD_CTL_LANE_2_3_PWRDN;
  1403. writel(val, qphy->pcs + QSERDES_DP_PHY_PD_CTL);
  1404. writel(0x5c, qphy->pcs + QSERDES_DP_PHY_MODE);
  1405. return reverse;
  1406. }
  1407. static int qcom_qmp_v3_phy_configure_dp_phy(struct qmp_phy *qphy)
  1408. {
  1409. const struct qmp_phy_dp_clks *dp_clks = qphy->dp_clks;
  1410. const struct phy_configure_opts_dp *dp_opts = &qphy->dp_opts;
  1411. u32 phy_vco_div, status;
  1412. unsigned long pixel_freq;
  1413. qmp_combo_configure_dp_mode(qphy);
  1414. writel(0x05, qphy->pcs + QSERDES_V3_DP_PHY_TX0_TX1_LANE_CTL);
  1415. writel(0x05, qphy->pcs + QSERDES_V3_DP_PHY_TX2_TX3_LANE_CTL);
  1416. switch (dp_opts->link_rate) {
  1417. case 1620:
  1418. phy_vco_div = 0x1;
  1419. pixel_freq = 1620000000UL / 2;
  1420. break;
  1421. case 2700:
  1422. phy_vco_div = 0x1;
  1423. pixel_freq = 2700000000UL / 2;
  1424. break;
  1425. case 5400:
  1426. phy_vco_div = 0x2;
  1427. pixel_freq = 5400000000UL / 4;
  1428. break;
  1429. case 8100:
  1430. phy_vco_div = 0x0;
  1431. pixel_freq = 8100000000UL / 6;
  1432. break;
  1433. default:
  1434. /* Other link rates aren't supported */
  1435. return -EINVAL;
  1436. }
  1437. writel(phy_vco_div, qphy->pcs + QSERDES_V3_DP_PHY_VCO_DIV);
  1438. clk_set_rate(dp_clks->dp_link_hw.clk, dp_opts->link_rate * 100000);
  1439. clk_set_rate(dp_clks->dp_pixel_hw.clk, pixel_freq);
  1440. writel(0x04, qphy->pcs + QSERDES_DP_PHY_AUX_CFG2);
  1441. writel(0x01, qphy->pcs + QSERDES_DP_PHY_CFG);
  1442. writel(0x05, qphy->pcs + QSERDES_DP_PHY_CFG);
  1443. writel(0x01, qphy->pcs + QSERDES_DP_PHY_CFG);
  1444. writel(0x09, qphy->pcs + QSERDES_DP_PHY_CFG);
  1445. writel(0x20, qphy->serdes + QSERDES_V3_COM_RESETSM_CNTRL);
  1446. if (readl_poll_timeout(qphy->serdes + QSERDES_V3_COM_C_READY_STATUS,
  1447. status,
  1448. ((status & BIT(0)) > 0),
  1449. 500,
  1450. 10000))
  1451. return -ETIMEDOUT;
  1452. writel(0x19, qphy->pcs + QSERDES_DP_PHY_CFG);
  1453. if (readl_poll_timeout(qphy->pcs + QSERDES_V3_DP_PHY_STATUS,
  1454. status,
  1455. ((status & BIT(1)) > 0),
  1456. 500,
  1457. 10000))
  1458. return -ETIMEDOUT;
  1459. writel(0x18, qphy->pcs + QSERDES_DP_PHY_CFG);
  1460. udelay(2000);
  1461. writel(0x19, qphy->pcs + QSERDES_DP_PHY_CFG);
  1462. return readl_poll_timeout(qphy->pcs + QSERDES_V3_DP_PHY_STATUS,
  1463. status,
  1464. ((status & BIT(1)) > 0),
  1465. 500,
  1466. 10000);
  1467. }
  1468. /*
  1469. * We need to calibrate the aux setting here as many times
  1470. * as the caller tries
  1471. */
  1472. static int qcom_qmp_v3_dp_phy_calibrate(struct qmp_phy *qphy)
  1473. {
  1474. static const u8 cfg1_settings[] = { 0x13, 0x23, 0x1d };
  1475. u8 val;
  1476. qphy->dp_aux_cfg++;
  1477. qphy->dp_aux_cfg %= ARRAY_SIZE(cfg1_settings);
  1478. val = cfg1_settings[qphy->dp_aux_cfg];
  1479. writel(val, qphy->pcs + QSERDES_DP_PHY_AUX_CFG1);
  1480. return 0;
  1481. }
  1482. static void qcom_qmp_v4_phy_dp_aux_init(struct qmp_phy *qphy)
  1483. {
  1484. writel(DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_PSR_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN |
  1485. DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN,
  1486. qphy->pcs + QSERDES_DP_PHY_PD_CTL);
  1487. /* Turn on BIAS current for PHY/PLL */
  1488. writel(0x17, qphy->serdes + QSERDES_V4_COM_BIAS_EN_CLKBUFLR_EN);
  1489. writel(0x00, qphy->pcs + QSERDES_DP_PHY_AUX_CFG0);
  1490. writel(0x13, qphy->pcs + QSERDES_DP_PHY_AUX_CFG1);
  1491. writel(0xa4, qphy->pcs + QSERDES_DP_PHY_AUX_CFG2);
  1492. writel(0x00, qphy->pcs + QSERDES_DP_PHY_AUX_CFG3);
  1493. writel(0x0a, qphy->pcs + QSERDES_DP_PHY_AUX_CFG4);
  1494. writel(0x26, qphy->pcs + QSERDES_DP_PHY_AUX_CFG5);
  1495. writel(0x0a, qphy->pcs + QSERDES_DP_PHY_AUX_CFG6);
  1496. writel(0x03, qphy->pcs + QSERDES_DP_PHY_AUX_CFG7);
  1497. writel(0xb7, qphy->pcs + QSERDES_DP_PHY_AUX_CFG8);
  1498. writel(0x03, qphy->pcs + QSERDES_DP_PHY_AUX_CFG9);
  1499. qphy->dp_aux_cfg = 0;
  1500. writel(PHY_AUX_STOP_ERR_MASK | PHY_AUX_DEC_ERR_MASK |
  1501. PHY_AUX_SYNC_ERR_MASK | PHY_AUX_ALIGN_ERR_MASK |
  1502. PHY_AUX_REQ_ERR_MASK,
  1503. qphy->pcs + QSERDES_V4_DP_PHY_AUX_INTERRUPT_MASK);
  1504. }
  1505. static void qcom_qmp_v4_phy_configure_dp_tx(struct qmp_phy *qphy)
  1506. {
  1507. /* Program default values before writing proper values */
  1508. writel(0x27, qphy->tx + QSERDES_V4_TX_TX_DRV_LVL);
  1509. writel(0x27, qphy->tx2 + QSERDES_V4_TX_TX_DRV_LVL);
  1510. writel(0x20, qphy->tx + QSERDES_V4_TX_TX_EMP_POST1_LVL);
  1511. writel(0x20, qphy->tx2 + QSERDES_V4_TX_TX_EMP_POST1_LVL);
  1512. qmp_combo_configure_dp_swing(qphy, QSERDES_V4_TX_TX_DRV_LVL,
  1513. QSERDES_V4_TX_TX_EMP_POST1_LVL);
  1514. }
  1515. static int qcom_qmp_v45_phy_configure_dp_phy(struct qmp_phy *qphy)
  1516. {
  1517. const struct qmp_phy_dp_clks *dp_clks = qphy->dp_clks;
  1518. const struct phy_configure_opts_dp *dp_opts = &qphy->dp_opts;
  1519. u32 phy_vco_div, status;
  1520. unsigned long pixel_freq;
  1521. writel(0x0f, qphy->pcs + QSERDES_V4_DP_PHY_CFG_1);
  1522. qmp_combo_configure_dp_mode(qphy);
  1523. writel(0x13, qphy->pcs + QSERDES_DP_PHY_AUX_CFG1);
  1524. writel(0xa4, qphy->pcs + QSERDES_DP_PHY_AUX_CFG2);
  1525. writel(0x05, qphy->pcs + QSERDES_V4_DP_PHY_TX0_TX1_LANE_CTL);
  1526. writel(0x05, qphy->pcs + QSERDES_V4_DP_PHY_TX2_TX3_LANE_CTL);
  1527. switch (dp_opts->link_rate) {
  1528. case 1620:
  1529. phy_vco_div = 0x1;
  1530. pixel_freq = 1620000000UL / 2;
  1531. break;
  1532. case 2700:
  1533. phy_vco_div = 0x1;
  1534. pixel_freq = 2700000000UL / 2;
  1535. break;
  1536. case 5400:
  1537. phy_vco_div = 0x2;
  1538. pixel_freq = 5400000000UL / 4;
  1539. break;
  1540. case 8100:
  1541. phy_vco_div = 0x0;
  1542. pixel_freq = 8100000000UL / 6;
  1543. break;
  1544. default:
  1545. /* Other link rates aren't supported */
  1546. return -EINVAL;
  1547. }
  1548. writel(phy_vco_div, qphy->pcs + QSERDES_V4_DP_PHY_VCO_DIV);
  1549. clk_set_rate(dp_clks->dp_link_hw.clk, dp_opts->link_rate * 100000);
  1550. clk_set_rate(dp_clks->dp_pixel_hw.clk, pixel_freq);
  1551. writel(0x01, qphy->pcs + QSERDES_DP_PHY_CFG);
  1552. writel(0x05, qphy->pcs + QSERDES_DP_PHY_CFG);
  1553. writel(0x01, qphy->pcs + QSERDES_DP_PHY_CFG);
  1554. writel(0x09, qphy->pcs + QSERDES_DP_PHY_CFG);
  1555. writel(0x20, qphy->serdes + QSERDES_V4_COM_RESETSM_CNTRL);
  1556. if (readl_poll_timeout(qphy->serdes + QSERDES_V4_COM_C_READY_STATUS,
  1557. status,
  1558. ((status & BIT(0)) > 0),
  1559. 500,
  1560. 10000))
  1561. return -ETIMEDOUT;
  1562. if (readl_poll_timeout(qphy->serdes + QSERDES_V4_COM_CMN_STATUS,
  1563. status,
  1564. ((status & BIT(0)) > 0),
  1565. 500,
  1566. 10000))
  1567. return -ETIMEDOUT;
  1568. if (readl_poll_timeout(qphy->serdes + QSERDES_V4_COM_CMN_STATUS,
  1569. status,
  1570. ((status & BIT(1)) > 0),
  1571. 500,
  1572. 10000))
  1573. return -ETIMEDOUT;
  1574. writel(0x19, qphy->pcs + QSERDES_DP_PHY_CFG);
  1575. if (readl_poll_timeout(qphy->pcs + QSERDES_V4_DP_PHY_STATUS,
  1576. status,
  1577. ((status & BIT(0)) > 0),
  1578. 500,
  1579. 10000))
  1580. return -ETIMEDOUT;
  1581. if (readl_poll_timeout(qphy->pcs + QSERDES_V4_DP_PHY_STATUS,
  1582. status,
  1583. ((status & BIT(1)) > 0),
  1584. 500,
  1585. 10000))
  1586. return -ETIMEDOUT;
  1587. return 0;
  1588. }
  1589. static int qcom_qmp_v4_phy_configure_dp_phy(struct qmp_phy *qphy)
  1590. {
  1591. const struct phy_configure_opts_dp *dp_opts = &qphy->dp_opts;
  1592. u32 bias0_en, drvr0_en, bias1_en, drvr1_en;
  1593. bool reverse = false;
  1594. u32 status;
  1595. int ret;
  1596. ret = qcom_qmp_v45_phy_configure_dp_phy(qphy);
  1597. if (ret < 0)
  1598. return ret;
  1599. /*
  1600. * At least for 7nm DP PHY this has to be done after enabling link
  1601. * clock.
  1602. */
  1603. if (dp_opts->lanes == 1) {
  1604. bias0_en = reverse ? 0x3e : 0x15;
  1605. bias1_en = reverse ? 0x15 : 0x3e;
  1606. drvr0_en = reverse ? 0x13 : 0x10;
  1607. drvr1_en = reverse ? 0x10 : 0x13;
  1608. } else if (dp_opts->lanes == 2) {
  1609. bias0_en = reverse ? 0x3f : 0x15;
  1610. bias1_en = reverse ? 0x15 : 0x3f;
  1611. drvr0_en = 0x10;
  1612. drvr1_en = 0x10;
  1613. } else {
  1614. bias0_en = 0x3f;
  1615. bias1_en = 0x3f;
  1616. drvr0_en = 0x10;
  1617. drvr1_en = 0x10;
  1618. }
  1619. writel(drvr0_en, qphy->tx + QSERDES_V4_TX_HIGHZ_DRVR_EN);
  1620. writel(bias0_en, qphy->tx + QSERDES_V4_TX_TRANSCEIVER_BIAS_EN);
  1621. writel(drvr1_en, qphy->tx2 + QSERDES_V4_TX_HIGHZ_DRVR_EN);
  1622. writel(bias1_en, qphy->tx2 + QSERDES_V4_TX_TRANSCEIVER_BIAS_EN);
  1623. writel(0x18, qphy->pcs + QSERDES_DP_PHY_CFG);
  1624. udelay(2000);
  1625. writel(0x19, qphy->pcs + QSERDES_DP_PHY_CFG);
  1626. if (readl_poll_timeout(qphy->pcs + QSERDES_V4_DP_PHY_STATUS,
  1627. status,
  1628. ((status & BIT(1)) > 0),
  1629. 500,
  1630. 10000))
  1631. return -ETIMEDOUT;
  1632. writel(0x0a, qphy->tx + QSERDES_V4_TX_TX_POL_INV);
  1633. writel(0x0a, qphy->tx2 + QSERDES_V4_TX_TX_POL_INV);
  1634. writel(0x27, qphy->tx + QSERDES_V4_TX_TX_DRV_LVL);
  1635. writel(0x27, qphy->tx2 + QSERDES_V4_TX_TX_DRV_LVL);
  1636. writel(0x20, qphy->tx + QSERDES_V4_TX_TX_EMP_POST1_LVL);
  1637. writel(0x20, qphy->tx2 + QSERDES_V4_TX_TX_EMP_POST1_LVL);
  1638. return 0;
  1639. }
  1640. static int qcom_qmp_v5_phy_configure_dp_phy(struct qmp_phy *qphy)
  1641. {
  1642. const struct phy_configure_opts_dp *dp_opts = &qphy->dp_opts;
  1643. u32 bias0_en, drvr0_en, bias1_en, drvr1_en;
  1644. bool reverse = false;
  1645. u32 status;
  1646. int ret;
  1647. ret = qcom_qmp_v45_phy_configure_dp_phy(qphy);
  1648. if (ret < 0)
  1649. return ret;
  1650. if (dp_opts->lanes == 1) {
  1651. bias0_en = reverse ? 0x3e : 0x1a;
  1652. drvr0_en = reverse ? 0x13 : 0x10;
  1653. bias1_en = reverse ? 0x15 : 0x3e;
  1654. drvr1_en = reverse ? 0x10 : 0x13;
  1655. } else if (dp_opts->lanes == 2) {
  1656. bias0_en = reverse ? 0x3f : 0x15;
  1657. drvr0_en = 0x10;
  1658. bias1_en = reverse ? 0x15 : 0x3f;
  1659. drvr1_en = 0x10;
  1660. } else {
  1661. bias0_en = 0x3f;
  1662. bias1_en = 0x3f;
  1663. drvr0_en = 0x10;
  1664. drvr1_en = 0x10;
  1665. }
  1666. writel(drvr0_en, qphy->tx + QSERDES_V5_5NM_TX_HIGHZ_DRVR_EN);
  1667. writel(bias0_en, qphy->tx + QSERDES_V5_5NM_TX_TRANSCEIVER_BIAS_EN);
  1668. writel(drvr1_en, qphy->tx2 + QSERDES_V5_5NM_TX_HIGHZ_DRVR_EN);
  1669. writel(bias1_en, qphy->tx2 + QSERDES_V5_5NM_TX_TRANSCEIVER_BIAS_EN);
  1670. writel(0x18, qphy->pcs + QSERDES_DP_PHY_CFG);
  1671. udelay(2000);
  1672. writel(0x19, qphy->pcs + QSERDES_DP_PHY_CFG);
  1673. if (readl_poll_timeout(qphy->pcs + QSERDES_V4_DP_PHY_STATUS,
  1674. status,
  1675. ((status & BIT(1)) > 0),
  1676. 500,
  1677. 10000))
  1678. return -ETIMEDOUT;
  1679. writel(0x0a, qphy->tx + QSERDES_V5_5NM_TX_TX_POL_INV);
  1680. writel(0x0a, qphy->tx2 + QSERDES_V5_5NM_TX_TX_POL_INV);
  1681. writel(0x27, qphy->tx + QSERDES_V5_5NM_TX_TX_DRV_LVL);
  1682. writel(0x27, qphy->tx2 + QSERDES_V5_5NM_TX_TX_DRV_LVL);
  1683. writel(0x20, qphy->tx + QSERDES_V5_5NM_TX_TX_EMP_POST1_LVL);
  1684. writel(0x20, qphy->tx2 + QSERDES_V5_5NM_TX_TX_EMP_POST1_LVL);
  1685. return 0;
  1686. }
  1687. /*
  1688. * We need to calibrate the aux setting here as many times
  1689. * as the caller tries
  1690. */
  1691. static int qcom_qmp_v4_dp_phy_calibrate(struct qmp_phy *qphy)
  1692. {
  1693. static const u8 cfg1_settings[] = { 0x20, 0x13, 0x23, 0x1d };
  1694. u8 val;
  1695. qphy->dp_aux_cfg++;
  1696. qphy->dp_aux_cfg %= ARRAY_SIZE(cfg1_settings);
  1697. val = cfg1_settings[qphy->dp_aux_cfg];
  1698. writel(val, qphy->pcs + QSERDES_DP_PHY_AUX_CFG1);
  1699. return 0;
  1700. }
  1701. static int qcom_qmp_dp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
  1702. {
  1703. const struct phy_configure_opts_dp *dp_opts = &opts->dp;
  1704. struct qmp_phy *qphy = phy_get_drvdata(phy);
  1705. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1706. memcpy(&qphy->dp_opts, dp_opts, sizeof(*dp_opts));
  1707. if (qphy->dp_opts.set_voltages) {
  1708. cfg->configure_dp_tx(qphy);
  1709. qphy->dp_opts.set_voltages = 0;
  1710. }
  1711. return 0;
  1712. }
  1713. static int qcom_qmp_dp_phy_calibrate(struct phy *phy)
  1714. {
  1715. struct qmp_phy *qphy = phy_get_drvdata(phy);
  1716. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1717. if (cfg->calibrate_dp_phy)
  1718. return cfg->calibrate_dp_phy(qphy);
  1719. return 0;
  1720. }
  1721. static int qmp_combo_com_init(struct qmp_phy *qphy)
  1722. {
  1723. struct qcom_qmp *qmp = qphy->qmp;
  1724. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1725. struct qmp_phy *usb_phy = qmp->usb_phy;
  1726. void __iomem *dp_com = qmp->dp_com;
  1727. int ret;
  1728. mutex_lock(&qmp->phy_mutex);
  1729. if (qmp->init_count++) {
  1730. mutex_unlock(&qmp->phy_mutex);
  1731. return 0;
  1732. }
  1733. /* turn on regulator supplies */
  1734. ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
  1735. if (ret) {
  1736. dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret);
  1737. goto err_decrement_count;
  1738. }
  1739. ret = reset_control_bulk_assert(cfg->num_resets, qmp->resets);
  1740. if (ret) {
  1741. dev_err(qmp->dev, "reset assert failed\n");
  1742. goto err_disable_regulators;
  1743. }
  1744. ret = reset_control_bulk_deassert(cfg->num_resets, qmp->resets);
  1745. if (ret) {
  1746. dev_err(qmp->dev, "reset deassert failed\n");
  1747. goto err_disable_regulators;
  1748. }
  1749. ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
  1750. if (ret)
  1751. goto err_assert_reset;
  1752. qphy_setbits(dp_com, QPHY_V3_DP_COM_POWER_DOWN_CTRL, SW_PWRDN);
  1753. /* override hardware control for reset of qmp phy */
  1754. qphy_setbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
  1755. SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
  1756. SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
  1757. /* Default type-c orientation, i.e CC1 */
  1758. qphy_setbits(dp_com, QPHY_V3_DP_COM_TYPEC_CTRL, 0x02);
  1759. qphy_setbits(dp_com, QPHY_V3_DP_COM_PHY_MODE_CTRL, USB3_MODE | DP_MODE);
  1760. /* bring both QMP USB and QMP DP PHYs PCS block out of reset */
  1761. qphy_clrbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
  1762. SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
  1763. SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
  1764. qphy_clrbits(dp_com, QPHY_V3_DP_COM_SWI_CTRL, 0x03);
  1765. qphy_clrbits(dp_com, QPHY_V3_DP_COM_SW_RESET, SW_RESET);
  1766. if (usb_phy->cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL])
  1767. qphy_setbits(usb_phy->pcs,
  1768. usb_phy->cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL],
  1769. usb_phy->cfg->pwrdn_ctrl);
  1770. else
  1771. qphy_setbits(usb_phy->pcs, QPHY_V2_PCS_POWER_DOWN_CONTROL,
  1772. usb_phy->cfg->pwrdn_ctrl);
  1773. mutex_unlock(&qmp->phy_mutex);
  1774. return 0;
  1775. err_assert_reset:
  1776. reset_control_bulk_assert(cfg->num_resets, qmp->resets);
  1777. err_disable_regulators:
  1778. regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
  1779. err_decrement_count:
  1780. qmp->init_count--;
  1781. mutex_unlock(&qmp->phy_mutex);
  1782. return ret;
  1783. }
  1784. static int qmp_combo_com_exit(struct qmp_phy *qphy)
  1785. {
  1786. struct qcom_qmp *qmp = qphy->qmp;
  1787. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1788. mutex_lock(&qmp->phy_mutex);
  1789. if (--qmp->init_count) {
  1790. mutex_unlock(&qmp->phy_mutex);
  1791. return 0;
  1792. }
  1793. reset_control_assert(qmp->ufs_reset);
  1794. reset_control_bulk_assert(cfg->num_resets, qmp->resets);
  1795. clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
  1796. regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
  1797. mutex_unlock(&qmp->phy_mutex);
  1798. return 0;
  1799. }
  1800. static int qmp_combo_init(struct phy *phy)
  1801. {
  1802. struct qmp_phy *qphy = phy_get_drvdata(phy);
  1803. struct qcom_qmp *qmp = qphy->qmp;
  1804. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1805. int ret;
  1806. dev_vdbg(qmp->dev, "Initializing QMP phy\n");
  1807. ret = qmp_combo_com_init(qphy);
  1808. if (ret)
  1809. return ret;
  1810. if (cfg->type == PHY_TYPE_DP)
  1811. cfg->dp_aux_init(qphy);
  1812. return 0;
  1813. }
  1814. static int qmp_combo_power_on(struct phy *phy)
  1815. {
  1816. struct qmp_phy *qphy = phy_get_drvdata(phy);
  1817. struct qcom_qmp *qmp = qphy->qmp;
  1818. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1819. void __iomem *tx = qphy->tx;
  1820. void __iomem *rx = qphy->rx;
  1821. void __iomem *pcs = qphy->pcs;
  1822. void __iomem *status;
  1823. unsigned int mask, val, ready;
  1824. int ret;
  1825. qmp_combo_serdes_init(qphy);
  1826. ret = clk_prepare_enable(qphy->pipe_clk);
  1827. if (ret) {
  1828. dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
  1829. return ret;
  1830. }
  1831. /* Tx, Rx, and PCS configurations */
  1832. qmp_combo_configure_lane(tx, cfg->regs, cfg->tx_tbl, cfg->tx_tbl_num, 1);
  1833. if (cfg->lanes >= 2) {
  1834. qmp_combo_configure_lane(qphy->tx2, cfg->regs, cfg->tx_tbl,
  1835. cfg->tx_tbl_num, 2);
  1836. }
  1837. /* Configure special DP tx tunings */
  1838. if (cfg->type == PHY_TYPE_DP)
  1839. cfg->configure_dp_tx(qphy);
  1840. qmp_combo_configure_lane(rx, cfg->regs, cfg->rx_tbl, cfg->rx_tbl_num, 1);
  1841. if (cfg->lanes >= 2) {
  1842. qmp_combo_configure_lane(qphy->rx2, cfg->regs, cfg->rx_tbl,
  1843. cfg->rx_tbl_num, 2);
  1844. }
  1845. /* Configure link rate, swing, etc. */
  1846. if (cfg->type == PHY_TYPE_DP)
  1847. cfg->configure_dp_phy(qphy);
  1848. else
  1849. qmp_combo_configure(pcs, cfg->regs, cfg->pcs_tbl, cfg->pcs_tbl_num);
  1850. ret = reset_control_deassert(qmp->ufs_reset);
  1851. if (ret)
  1852. goto err_disable_pipe_clk;
  1853. if (cfg->has_pwrdn_delay)
  1854. usleep_range(cfg->pwrdn_delay_min, cfg->pwrdn_delay_max);
  1855. if (cfg->type != PHY_TYPE_DP) {
  1856. /* Pull PHY out of reset state */
  1857. qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
  1858. /* start SerDes and Phy-Coding-Sublayer */
  1859. qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], cfg->start_ctrl);
  1860. status = pcs + cfg->regs[QPHY_PCS_STATUS];
  1861. mask = cfg->phy_status;
  1862. ready = 0;
  1863. ret = readl_poll_timeout(status, val, (val & mask) == ready, 10,
  1864. PHY_INIT_COMPLETE_TIMEOUT);
  1865. if (ret) {
  1866. dev_err(qmp->dev, "phy initialization timed-out\n");
  1867. goto err_disable_pipe_clk;
  1868. }
  1869. }
  1870. return 0;
  1871. err_disable_pipe_clk:
  1872. clk_disable_unprepare(qphy->pipe_clk);
  1873. return ret;
  1874. }
  1875. static int qmp_combo_power_off(struct phy *phy)
  1876. {
  1877. struct qmp_phy *qphy = phy_get_drvdata(phy);
  1878. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1879. clk_disable_unprepare(qphy->pipe_clk);
  1880. if (cfg->type == PHY_TYPE_DP) {
  1881. /* Assert DP PHY power down */
  1882. writel(DP_PHY_PD_CTL_PSR_PWRDN, qphy->pcs + QSERDES_DP_PHY_PD_CTL);
  1883. } else {
  1884. /* PHY reset */
  1885. qphy_setbits(qphy->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
  1886. /* stop SerDes and Phy-Coding-Sublayer */
  1887. qphy_clrbits(qphy->pcs, cfg->regs[QPHY_START_CTRL], cfg->start_ctrl);
  1888. /* Put PHY into POWER DOWN state: active low */
  1889. if (cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL]) {
  1890. qphy_clrbits(qphy->pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL],
  1891. cfg->pwrdn_ctrl);
  1892. } else {
  1893. qphy_clrbits(qphy->pcs, QPHY_V2_PCS_POWER_DOWN_CONTROL,
  1894. cfg->pwrdn_ctrl);
  1895. }
  1896. }
  1897. return 0;
  1898. }
  1899. static int qmp_combo_exit(struct phy *phy)
  1900. {
  1901. struct qmp_phy *qphy = phy_get_drvdata(phy);
  1902. qmp_combo_com_exit(qphy);
  1903. return 0;
  1904. }
  1905. static int qmp_combo_enable(struct phy *phy)
  1906. {
  1907. int ret;
  1908. ret = qmp_combo_init(phy);
  1909. if (ret)
  1910. return ret;
  1911. ret = qmp_combo_power_on(phy);
  1912. if (ret)
  1913. qmp_combo_exit(phy);
  1914. return ret;
  1915. }
  1916. static int qmp_combo_disable(struct phy *phy)
  1917. {
  1918. int ret;
  1919. ret = qmp_combo_power_off(phy);
  1920. if (ret)
  1921. return ret;
  1922. return qmp_combo_exit(phy);
  1923. }
  1924. static int qmp_combo_set_mode(struct phy *phy, enum phy_mode mode, int submode)
  1925. {
  1926. struct qmp_phy *qphy = phy_get_drvdata(phy);
  1927. qphy->mode = mode;
  1928. return 0;
  1929. }
  1930. static void qmp_combo_enable_autonomous_mode(struct qmp_phy *qphy)
  1931. {
  1932. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1933. void __iomem *pcs_usb = qphy->pcs_usb ?: qphy->pcs;
  1934. void __iomem *pcs_misc = qphy->pcs_misc;
  1935. u32 intr_mask;
  1936. if (qphy->mode == PHY_MODE_USB_HOST_SS ||
  1937. qphy->mode == PHY_MODE_USB_DEVICE_SS)
  1938. intr_mask = ARCVR_DTCT_EN | ALFPS_DTCT_EN;
  1939. else
  1940. intr_mask = ARCVR_DTCT_EN | ARCVR_DTCT_EVENT_SEL;
  1941. /* Clear any pending interrupts status */
  1942. qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  1943. /* Writing 1 followed by 0 clears the interrupt */
  1944. qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  1945. qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
  1946. ARCVR_DTCT_EN | ALFPS_DTCT_EN | ARCVR_DTCT_EVENT_SEL);
  1947. /* Enable required PHY autonomous mode interrupts */
  1948. qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], intr_mask);
  1949. /* Enable i/o clamp_n for autonomous mode */
  1950. if (pcs_misc)
  1951. qphy_clrbits(pcs_misc, QPHY_V3_PCS_MISC_CLAMP_ENABLE, CLAMP_EN);
  1952. }
  1953. static void qmp_combo_disable_autonomous_mode(struct qmp_phy *qphy)
  1954. {
  1955. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1956. void __iomem *pcs_usb = qphy->pcs_usb ?: qphy->pcs;
  1957. void __iomem *pcs_misc = qphy->pcs_misc;
  1958. /* Disable i/o clamp_n on resume for normal mode */
  1959. if (pcs_misc)
  1960. qphy_setbits(pcs_misc, QPHY_V3_PCS_MISC_CLAMP_ENABLE, CLAMP_EN);
  1961. qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
  1962. ARCVR_DTCT_EN | ARCVR_DTCT_EVENT_SEL | ALFPS_DTCT_EN);
  1963. qphy_setbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  1964. /* Writing 1 followed by 0 clears the interrupt */
  1965. qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  1966. }
  1967. static int __maybe_unused qmp_combo_runtime_suspend(struct device *dev)
  1968. {
  1969. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  1970. struct qmp_phy *qphy = qmp->usb_phy;
  1971. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1972. dev_vdbg(dev, "Suspending QMP phy, mode:%d\n", qphy->mode);
  1973. if (!qmp->init_count) {
  1974. dev_vdbg(dev, "PHY not initialized, bailing out\n");
  1975. return 0;
  1976. }
  1977. qmp_combo_enable_autonomous_mode(qphy);
  1978. clk_disable_unprepare(qphy->pipe_clk);
  1979. clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
  1980. return 0;
  1981. }
  1982. static int __maybe_unused qmp_combo_runtime_resume(struct device *dev)
  1983. {
  1984. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  1985. struct qmp_phy *qphy = qmp->usb_phy;
  1986. const struct qmp_phy_cfg *cfg = qphy->cfg;
  1987. int ret = 0;
  1988. dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qphy->mode);
  1989. if (!qmp->init_count) {
  1990. dev_vdbg(dev, "PHY not initialized, bailing out\n");
  1991. return 0;
  1992. }
  1993. ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
  1994. if (ret)
  1995. return ret;
  1996. ret = clk_prepare_enable(qphy->pipe_clk);
  1997. if (ret) {
  1998. dev_err(dev, "pipe_clk enable failed, err=%d\n", ret);
  1999. clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
  2000. return ret;
  2001. }
  2002. qmp_combo_disable_autonomous_mode(qphy);
  2003. return 0;
  2004. }
  2005. static int qmp_combo_vreg_init(struct device *dev, const struct qmp_phy_cfg *cfg)
  2006. {
  2007. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  2008. int num = cfg->num_vregs;
  2009. int ret, i;
  2010. qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL);
  2011. if (!qmp->vregs)
  2012. return -ENOMEM;
  2013. for (i = 0; i < num; i++)
  2014. qmp->vregs[i].supply = cfg->vreg_list[i].name;
  2015. ret = devm_regulator_bulk_get(dev, num, qmp->vregs);
  2016. if (ret) {
  2017. dev_err(dev, "failed at devm_regulator_bulk_get\n");
  2018. return ret;
  2019. }
  2020. for (i = 0; i < num; i++) {
  2021. ret = regulator_set_load(qmp->vregs[i].consumer,
  2022. cfg->vreg_list[i].enable_load);
  2023. if (ret) {
  2024. dev_err(dev, "failed to set load at %s\n",
  2025. qmp->vregs[i].supply);
  2026. return ret;
  2027. }
  2028. }
  2029. return 0;
  2030. }
  2031. static int qmp_combo_reset_init(struct device *dev, const struct qmp_phy_cfg *cfg)
  2032. {
  2033. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  2034. int i;
  2035. int ret;
  2036. qmp->resets = devm_kcalloc(dev, cfg->num_resets,
  2037. sizeof(*qmp->resets), GFP_KERNEL);
  2038. if (!qmp->resets)
  2039. return -ENOMEM;
  2040. for (i = 0; i < cfg->num_resets; i++)
  2041. qmp->resets[i].id = cfg->reset_list[i];
  2042. ret = devm_reset_control_bulk_get_exclusive(dev, cfg->num_resets, qmp->resets);
  2043. if (ret)
  2044. return dev_err_probe(dev, ret, "failed to get resets\n");
  2045. return 0;
  2046. }
  2047. static int qmp_combo_clk_init(struct device *dev, const struct qmp_phy_cfg *cfg)
  2048. {
  2049. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  2050. int num = cfg->num_clks;
  2051. int i;
  2052. qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL);
  2053. if (!qmp->clks)
  2054. return -ENOMEM;
  2055. for (i = 0; i < num; i++)
  2056. qmp->clks[i].id = cfg->clk_list[i];
  2057. return devm_clk_bulk_get(dev, num, qmp->clks);
  2058. }
  2059. static void phy_clk_release_provider(void *res)
  2060. {
  2061. of_clk_del_provider(res);
  2062. }
  2063. /*
  2064. * Register a fixed rate pipe clock.
  2065. *
  2066. * The <s>_pipe_clksrc generated by PHY goes to the GCC that gate
  2067. * controls it. The <s>_pipe_clk coming out of the GCC is requested
  2068. * by the PHY driver for its operations.
  2069. * We register the <s>_pipe_clksrc here. The gcc driver takes care
  2070. * of assigning this <s>_pipe_clksrc as parent to <s>_pipe_clk.
  2071. * Below picture shows this relationship.
  2072. *
  2073. * +---------------+
  2074. * | PHY block |<<---------------------------------------+
  2075. * | | |
  2076. * | +-------+ | +-----+ |
  2077. * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
  2078. * clk | +-------+ | +-----+
  2079. * +---------------+
  2080. */
  2081. static int phy_pipe_clk_register(struct qcom_qmp *qmp, struct device_node *np)
  2082. {
  2083. struct clk_fixed_rate *fixed;
  2084. struct clk_init_data init = { };
  2085. int ret;
  2086. ret = of_property_read_string(np, "clock-output-names", &init.name);
  2087. if (ret) {
  2088. dev_err(qmp->dev, "%pOFn: No clock-output-names\n", np);
  2089. return ret;
  2090. }
  2091. fixed = devm_kzalloc(qmp->dev, sizeof(*fixed), GFP_KERNEL);
  2092. if (!fixed)
  2093. return -ENOMEM;
  2094. init.ops = &clk_fixed_rate_ops;
  2095. /* controllers using QMP phys use 125MHz pipe clock interface */
  2096. fixed->fixed_rate = 125000000;
  2097. fixed->hw.init = &init;
  2098. ret = devm_clk_hw_register(qmp->dev, &fixed->hw);
  2099. if (ret)
  2100. return ret;
  2101. ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &fixed->hw);
  2102. if (ret)
  2103. return ret;
  2104. /*
  2105. * Roll a devm action because the clock provider is the child node, but
  2106. * the child node is not actually a device.
  2107. */
  2108. return devm_add_action_or_reset(qmp->dev, phy_clk_release_provider, np);
  2109. }
  2110. /*
  2111. * Display Port PLL driver block diagram for branch clocks
  2112. *
  2113. * +------------------------------+
  2114. * | DP_VCO_CLK |
  2115. * | |
  2116. * | +-------------------+ |
  2117. * | | (DP PLL/VCO) | |
  2118. * | +---------+---------+ |
  2119. * | v |
  2120. * | +----------+-----------+ |
  2121. * | | hsclk_divsel_clk_src | |
  2122. * | +----------+-----------+ |
  2123. * +------------------------------+
  2124. * |
  2125. * +---------<---------v------------>----------+
  2126. * | |
  2127. * +--------v----------------+ |
  2128. * | dp_phy_pll_link_clk | |
  2129. * | link_clk | |
  2130. * +--------+----------------+ |
  2131. * | |
  2132. * | |
  2133. * v v
  2134. * Input to DISPCC block |
  2135. * for link clk, crypto clk |
  2136. * and interface clock |
  2137. * |
  2138. * |
  2139. * +--------<------------+-----------------+---<---+
  2140. * | | |
  2141. * +----v---------+ +--------v-----+ +--------v------+
  2142. * | vco_divided | | vco_divided | | vco_divided |
  2143. * | _clk_src | | _clk_src | | _clk_src |
  2144. * | | | | | |
  2145. * |divsel_six | | divsel_two | | divsel_four |
  2146. * +-------+------+ +-----+--------+ +--------+------+
  2147. * | | |
  2148. * v---->----------v-------------<------v
  2149. * |
  2150. * +----------+-----------------+
  2151. * | dp_phy_pll_vco_div_clk |
  2152. * +---------+------------------+
  2153. * |
  2154. * v
  2155. * Input to DISPCC block
  2156. * for DP pixel clock
  2157. *
  2158. */
  2159. static int qcom_qmp_dp_pixel_clk_determine_rate(struct clk_hw *hw,
  2160. struct clk_rate_request *req)
  2161. {
  2162. switch (req->rate) {
  2163. case 1620000000UL / 2:
  2164. case 2700000000UL / 2:
  2165. /* 5.4 and 8.1 GHz are same link rate as 2.7GHz, i.e. div 4 and div 6 */
  2166. return 0;
  2167. default:
  2168. return -EINVAL;
  2169. }
  2170. }
  2171. static unsigned long
  2172. qcom_qmp_dp_pixel_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
  2173. {
  2174. const struct qmp_phy_dp_clks *dp_clks;
  2175. const struct qmp_phy *qphy;
  2176. const struct phy_configure_opts_dp *dp_opts;
  2177. dp_clks = container_of(hw, struct qmp_phy_dp_clks, dp_pixel_hw);
  2178. qphy = dp_clks->qphy;
  2179. dp_opts = &qphy->dp_opts;
  2180. switch (dp_opts->link_rate) {
  2181. case 1620:
  2182. return 1620000000UL / 2;
  2183. case 2700:
  2184. return 2700000000UL / 2;
  2185. case 5400:
  2186. return 5400000000UL / 4;
  2187. case 8100:
  2188. return 8100000000UL / 6;
  2189. default:
  2190. return 0;
  2191. }
  2192. }
  2193. static const struct clk_ops qcom_qmp_dp_pixel_clk_ops = {
  2194. .determine_rate = qcom_qmp_dp_pixel_clk_determine_rate,
  2195. .recalc_rate = qcom_qmp_dp_pixel_clk_recalc_rate,
  2196. };
  2197. static int qcom_qmp_dp_link_clk_determine_rate(struct clk_hw *hw,
  2198. struct clk_rate_request *req)
  2199. {
  2200. switch (req->rate) {
  2201. case 162000000:
  2202. case 270000000:
  2203. case 540000000:
  2204. case 810000000:
  2205. return 0;
  2206. default:
  2207. return -EINVAL;
  2208. }
  2209. }
  2210. static unsigned long
  2211. qcom_qmp_dp_link_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
  2212. {
  2213. const struct qmp_phy_dp_clks *dp_clks;
  2214. const struct qmp_phy *qphy;
  2215. const struct phy_configure_opts_dp *dp_opts;
  2216. dp_clks = container_of(hw, struct qmp_phy_dp_clks, dp_link_hw);
  2217. qphy = dp_clks->qphy;
  2218. dp_opts = &qphy->dp_opts;
  2219. switch (dp_opts->link_rate) {
  2220. case 1620:
  2221. case 2700:
  2222. case 5400:
  2223. case 8100:
  2224. return dp_opts->link_rate * 100000;
  2225. default:
  2226. return 0;
  2227. }
  2228. }
  2229. static const struct clk_ops qcom_qmp_dp_link_clk_ops = {
  2230. .determine_rate = qcom_qmp_dp_link_clk_determine_rate,
  2231. .recalc_rate = qcom_qmp_dp_link_clk_recalc_rate,
  2232. };
  2233. static struct clk_hw *
  2234. qcom_qmp_dp_clks_hw_get(struct of_phandle_args *clkspec, void *data)
  2235. {
  2236. struct qmp_phy_dp_clks *dp_clks = data;
  2237. unsigned int idx = clkspec->args[0];
  2238. if (idx >= 2) {
  2239. pr_err("%s: invalid index %u\n", __func__, idx);
  2240. return ERR_PTR(-EINVAL);
  2241. }
  2242. if (idx == 0)
  2243. return &dp_clks->dp_link_hw;
  2244. return &dp_clks->dp_pixel_hw;
  2245. }
  2246. static int phy_dp_clks_register(struct qcom_qmp *qmp, struct qmp_phy *qphy,
  2247. struct device_node *np)
  2248. {
  2249. struct clk_init_data init = { };
  2250. struct qmp_phy_dp_clks *dp_clks;
  2251. char name[64];
  2252. int ret;
  2253. dp_clks = devm_kzalloc(qmp->dev, sizeof(*dp_clks), GFP_KERNEL);
  2254. if (!dp_clks)
  2255. return -ENOMEM;
  2256. dp_clks->qphy = qphy;
  2257. qphy->dp_clks = dp_clks;
  2258. snprintf(name, sizeof(name), "%s::link_clk", dev_name(qmp->dev));
  2259. init.ops = &qcom_qmp_dp_link_clk_ops;
  2260. init.name = name;
  2261. dp_clks->dp_link_hw.init = &init;
  2262. ret = devm_clk_hw_register(qmp->dev, &dp_clks->dp_link_hw);
  2263. if (ret)
  2264. return ret;
  2265. snprintf(name, sizeof(name), "%s::vco_div_clk", dev_name(qmp->dev));
  2266. init.ops = &qcom_qmp_dp_pixel_clk_ops;
  2267. init.name = name;
  2268. dp_clks->dp_pixel_hw.init = &init;
  2269. ret = devm_clk_hw_register(qmp->dev, &dp_clks->dp_pixel_hw);
  2270. if (ret)
  2271. return ret;
  2272. ret = of_clk_add_hw_provider(np, qcom_qmp_dp_clks_hw_get, dp_clks);
  2273. if (ret)
  2274. return ret;
  2275. /*
  2276. * Roll a devm action because the clock provider is the child node, but
  2277. * the child node is not actually a device.
  2278. */
  2279. return devm_add_action_or_reset(qmp->dev, phy_clk_release_provider, np);
  2280. }
  2281. static const struct phy_ops qmp_combo_usb_ops = {
  2282. .init = qmp_combo_enable,
  2283. .exit = qmp_combo_disable,
  2284. .set_mode = qmp_combo_set_mode,
  2285. .owner = THIS_MODULE,
  2286. };
  2287. static const struct phy_ops qmp_combo_dp_ops = {
  2288. .init = qmp_combo_init,
  2289. .configure = qcom_qmp_dp_phy_configure,
  2290. .power_on = qmp_combo_power_on,
  2291. .calibrate = qcom_qmp_dp_phy_calibrate,
  2292. .power_off = qmp_combo_power_off,
  2293. .exit = qmp_combo_exit,
  2294. .set_mode = qmp_combo_set_mode,
  2295. .owner = THIS_MODULE,
  2296. };
  2297. static int qmp_combo_create(struct device *dev, struct device_node *np, int id,
  2298. void __iomem *serdes, const struct qmp_phy_cfg *cfg)
  2299. {
  2300. struct qcom_qmp *qmp = dev_get_drvdata(dev);
  2301. struct phy *generic_phy;
  2302. struct qmp_phy *qphy;
  2303. const struct phy_ops *ops;
  2304. int ret;
  2305. qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL);
  2306. if (!qphy)
  2307. return -ENOMEM;
  2308. qphy->cfg = cfg;
  2309. qphy->serdes = serdes;
  2310. /*
  2311. * Get memory resources for each phy lane:
  2312. * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2.
  2313. * For dual lane PHYs: tx2 -> 3, rx2 -> 4, pcs_misc (optional) -> 5
  2314. * For single lane PHYs: pcs_misc (optional) -> 3.
  2315. */
  2316. qphy->tx = devm_of_iomap(dev, np, 0, NULL);
  2317. if (IS_ERR(qphy->tx))
  2318. return PTR_ERR(qphy->tx);
  2319. qphy->rx = devm_of_iomap(dev, np, 1, NULL);
  2320. if (IS_ERR(qphy->rx))
  2321. return PTR_ERR(qphy->rx);
  2322. qphy->pcs = devm_of_iomap(dev, np, 2, NULL);
  2323. if (IS_ERR(qphy->pcs))
  2324. return PTR_ERR(qphy->pcs);
  2325. if (cfg->pcs_usb_offset)
  2326. qphy->pcs_usb = qphy->pcs + cfg->pcs_usb_offset;
  2327. if (cfg->lanes >= 2) {
  2328. qphy->tx2 = devm_of_iomap(dev, np, 3, NULL);
  2329. if (IS_ERR(qphy->tx2))
  2330. return PTR_ERR(qphy->tx2);
  2331. qphy->rx2 = devm_of_iomap(dev, np, 4, NULL);
  2332. if (IS_ERR(qphy->rx2))
  2333. return PTR_ERR(qphy->rx2);
  2334. qphy->pcs_misc = devm_of_iomap(dev, np, 5, NULL);
  2335. } else {
  2336. qphy->pcs_misc = devm_of_iomap(dev, np, 3, NULL);
  2337. }
  2338. if (IS_ERR(qphy->pcs_misc)) {
  2339. dev_vdbg(dev, "PHY pcs_misc-reg not used\n");
  2340. qphy->pcs_misc = NULL;
  2341. }
  2342. /*
  2343. * Get PHY's Pipe clock, if any. USB3 and PCIe are PIPE3
  2344. * based phys, so they essentially have pipe clock. So,
  2345. * we return error in case phy is USB3 or PIPE type.
  2346. * Otherwise, we initialize pipe clock to NULL for
  2347. * all phys that don't need this.
  2348. */
  2349. qphy->pipe_clk = devm_get_clk_from_child(dev, np, NULL);
  2350. if (IS_ERR(qphy->pipe_clk)) {
  2351. if (cfg->type == PHY_TYPE_USB3)
  2352. return dev_err_probe(dev, PTR_ERR(qphy->pipe_clk),
  2353. "failed to get lane%d pipe_clk\n",
  2354. id);
  2355. qphy->pipe_clk = NULL;
  2356. }
  2357. if (cfg->type == PHY_TYPE_DP)
  2358. ops = &qmp_combo_dp_ops;
  2359. else
  2360. ops = &qmp_combo_usb_ops;
  2361. generic_phy = devm_phy_create(dev, np, ops);
  2362. if (IS_ERR(generic_phy)) {
  2363. ret = PTR_ERR(generic_phy);
  2364. dev_err(dev, "failed to create qphy %d\n", ret);
  2365. return ret;
  2366. }
  2367. qphy->phy = generic_phy;
  2368. qphy->qmp = qmp;
  2369. qmp->phys[id] = qphy;
  2370. phy_set_drvdata(generic_phy, qphy);
  2371. return 0;
  2372. }
  2373. static const struct of_device_id qmp_combo_of_match_table[] = {
  2374. {
  2375. .compatible = "qcom,sc7180-qmp-usb3-dp-phy",
  2376. .data = &sc7180_usb3dpphy_cfg,
  2377. },
  2378. {
  2379. .compatible = "qcom,sdm845-qmp-usb3-dp-phy",
  2380. .data = &sdm845_usb3dpphy_cfg,
  2381. },
  2382. {
  2383. .compatible = "qcom,sm8250-qmp-usb3-dp-phy",
  2384. .data = &sm8250_usb3dpphy_cfg,
  2385. },
  2386. {
  2387. .compatible = "qcom,sc8180x-qmp-usb3-dp-phy",
  2388. .data = &sc8180x_usb3dpphy_cfg,
  2389. },
  2390. {
  2391. .compatible = "qcom,sc8280xp-qmp-usb43dp-phy",
  2392. .data = &sc8280xp_usb43dpphy_combo_cfg,
  2393. },
  2394. { }
  2395. };
  2396. MODULE_DEVICE_TABLE(of, qmp_combo_of_match_table);
  2397. static const struct dev_pm_ops qmp_combo_pm_ops = {
  2398. SET_RUNTIME_PM_OPS(qmp_combo_runtime_suspend,
  2399. qmp_combo_runtime_resume, NULL)
  2400. };
  2401. static int qmp_combo_probe(struct platform_device *pdev)
  2402. {
  2403. struct qcom_qmp *qmp;
  2404. struct device *dev = &pdev->dev;
  2405. struct device_node *child;
  2406. struct phy_provider *phy_provider;
  2407. void __iomem *serdes;
  2408. void __iomem *usb_serdes;
  2409. void __iomem *dp_serdes = NULL;
  2410. const struct qmp_phy_combo_cfg *combo_cfg = NULL;
  2411. const struct qmp_phy_cfg *cfg = NULL;
  2412. const struct qmp_phy_cfg *usb_cfg = NULL;
  2413. const struct qmp_phy_cfg *dp_cfg = NULL;
  2414. int num, id, expected_phys;
  2415. int ret;
  2416. qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL);
  2417. if (!qmp)
  2418. return -ENOMEM;
  2419. qmp->dev = dev;
  2420. dev_set_drvdata(dev, qmp);
  2421. /* Get the specific init parameters of QMP phy */
  2422. combo_cfg = of_device_get_match_data(dev);
  2423. if (!combo_cfg)
  2424. return -EINVAL;
  2425. usb_cfg = combo_cfg->usb_cfg;
  2426. cfg = usb_cfg; /* Setup clks and regulators */
  2427. /* per PHY serdes; usually located at base address */
  2428. usb_serdes = serdes = devm_platform_ioremap_resource(pdev, 0);
  2429. if (IS_ERR(serdes))
  2430. return PTR_ERR(serdes);
  2431. qmp->dp_com = devm_platform_ioremap_resource(pdev, 1);
  2432. if (IS_ERR(qmp->dp_com))
  2433. return PTR_ERR(qmp->dp_com);
  2434. /* Only two serdes for combo PHY */
  2435. dp_serdes = devm_platform_ioremap_resource(pdev, 2);
  2436. if (IS_ERR(dp_serdes))
  2437. return PTR_ERR(dp_serdes);
  2438. dp_cfg = combo_cfg->dp_cfg;
  2439. expected_phys = 2;
  2440. mutex_init(&qmp->phy_mutex);
  2441. ret = qmp_combo_clk_init(dev, cfg);
  2442. if (ret)
  2443. return ret;
  2444. ret = qmp_combo_reset_init(dev, cfg);
  2445. if (ret)
  2446. return ret;
  2447. ret = qmp_combo_vreg_init(dev, cfg);
  2448. if (ret)
  2449. return dev_err_probe(dev, ret,
  2450. "failed to get regulator supplies\n");
  2451. num = of_get_available_child_count(dev->of_node);
  2452. /* do we have a rogue child node ? */
  2453. if (num > expected_phys)
  2454. return -EINVAL;
  2455. qmp->phys = devm_kcalloc(dev, num, sizeof(*qmp->phys), GFP_KERNEL);
  2456. if (!qmp->phys)
  2457. return -ENOMEM;
  2458. pm_runtime_set_active(dev);
  2459. ret = devm_pm_runtime_enable(dev);
  2460. if (ret)
  2461. return ret;
  2462. /*
  2463. * Prevent runtime pm from being ON by default. Users can enable
  2464. * it using power/control in sysfs.
  2465. */
  2466. pm_runtime_forbid(dev);
  2467. id = 0;
  2468. for_each_available_child_of_node(dev->of_node, child) {
  2469. if (of_node_name_eq(child, "dp-phy")) {
  2470. cfg = dp_cfg;
  2471. serdes = dp_serdes;
  2472. /* Create per-lane phy */
  2473. ret = qmp_combo_create(dev, child, id, serdes, cfg);
  2474. if (ret) {
  2475. dev_err(dev, "failed to create lane%d phy, %d\n",
  2476. id, ret);
  2477. goto err_node_put;
  2478. }
  2479. ret = phy_dp_clks_register(qmp, qmp->phys[id], child);
  2480. if (ret) {
  2481. dev_err(qmp->dev,
  2482. "failed to register DP clock source\n");
  2483. goto err_node_put;
  2484. }
  2485. } else if (of_node_name_eq(child, "usb3-phy")) {
  2486. cfg = usb_cfg;
  2487. serdes = usb_serdes;
  2488. /* Create per-lane phy */
  2489. ret = qmp_combo_create(dev, child, id, serdes, cfg);
  2490. if (ret) {
  2491. dev_err(dev, "failed to create lane%d phy, %d\n",
  2492. id, ret);
  2493. goto err_node_put;
  2494. }
  2495. qmp->usb_phy = qmp->phys[id];
  2496. /*
  2497. * Register the pipe clock provided by phy.
  2498. * See function description to see details of this pipe clock.
  2499. */
  2500. ret = phy_pipe_clk_register(qmp, child);
  2501. if (ret) {
  2502. dev_err(qmp->dev,
  2503. "failed to register pipe clock source\n");
  2504. goto err_node_put;
  2505. }
  2506. }
  2507. id++;
  2508. }
  2509. if (!qmp->usb_phy)
  2510. return -EINVAL;
  2511. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  2512. return PTR_ERR_OR_ZERO(phy_provider);
  2513. err_node_put:
  2514. of_node_put(child);
  2515. return ret;
  2516. }
  2517. static struct platform_driver qmp_combo_driver = {
  2518. .probe = qmp_combo_probe,
  2519. .driver = {
  2520. .name = "qcom-qmp-combo-phy",
  2521. .pm = &qmp_combo_pm_ops,
  2522. .of_match_table = qmp_combo_of_match_table,
  2523. },
  2524. };
  2525. module_platform_driver(qmp_combo_driver);
  2526. MODULE_AUTHOR("Vivek Gautam <[email protected]>");
  2527. MODULE_DESCRIPTION("Qualcomm QMP USB+DP combo PHY driver");
  2528. MODULE_LICENSE("GPL v2");