phy-qcom-qmp-ufs.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081
  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_address.h>
  15. #include <linux/phy/phy.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/regulator/consumer.h>
  18. #include <linux/reset.h>
  19. #include <linux/slab.h>
  20. #include <ufs/unipro.h>
  21. #include "phy-qcom-qmp-common.h"
  22. #include "phy-qcom-qmp.h"
  23. #include "phy-qcom-qmp-pcs-ufs-v2.h"
  24. #include "phy-qcom-qmp-pcs-ufs-v3.h"
  25. #include "phy-qcom-qmp-pcs-ufs-v4.h"
  26. #include "phy-qcom-qmp-pcs-ufs-v5.h"
  27. #include "phy-qcom-qmp-pcs-ufs-v6.h"
  28. #include "phy-qcom-qmp-qserdes-txrx-ufs-v6.h"
  29. /* QPHY_PCS_READY_STATUS bit */
  30. #define PCS_READY BIT(0)
  31. #define PHY_INIT_COMPLETE_TIMEOUT 10000
  32. #define NUM_OVERLAY 2
  33. /* set of registers with offsets different per-PHY */
  34. enum qphy_reg_layout {
  35. /* PCS registers */
  36. QPHY_SW_RESET,
  37. QPHY_START_CTRL,
  38. QPHY_PCS_READY_STATUS,
  39. QPHY_PCS_POWER_DOWN_CONTROL,
  40. /* Keep last to ensure regs_layout arrays are properly initialized */
  41. QPHY_LAYOUT_SIZE
  42. };
  43. static const unsigned int ufsphy_v2_regs_layout[QPHY_LAYOUT_SIZE] = {
  44. [QPHY_START_CTRL] = QPHY_V2_PCS_UFS_PHY_START,
  45. [QPHY_PCS_READY_STATUS] = QPHY_V2_PCS_UFS_READY_STATUS,
  46. [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V2_PCS_UFS_POWER_DOWN_CONTROL,
  47. };
  48. static const unsigned int ufsphy_v3_regs_layout[QPHY_LAYOUT_SIZE] = {
  49. [QPHY_START_CTRL] = QPHY_V3_PCS_UFS_PHY_START,
  50. [QPHY_PCS_READY_STATUS] = QPHY_V3_PCS_UFS_READY_STATUS,
  51. [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V3_PCS_UFS_POWER_DOWN_CONTROL,
  52. };
  53. static const unsigned int ufsphy_v4_regs_layout[QPHY_LAYOUT_SIZE] = {
  54. [QPHY_START_CTRL] = QPHY_V4_PCS_UFS_PHY_START,
  55. [QPHY_PCS_READY_STATUS] = QPHY_V4_PCS_UFS_READY_STATUS,
  56. [QPHY_SW_RESET] = QPHY_V4_PCS_UFS_SW_RESET,
  57. [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V4_PCS_UFS_POWER_DOWN_CONTROL,
  58. };
  59. static const unsigned int ufsphy_v5_regs_layout[QPHY_LAYOUT_SIZE] = {
  60. [QPHY_START_CTRL] = QPHY_V5_PCS_UFS_PHY_START,
  61. [QPHY_PCS_READY_STATUS] = QPHY_V5_PCS_UFS_READY_STATUS,
  62. [QPHY_SW_RESET] = QPHY_V5_PCS_UFS_SW_RESET,
  63. [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V5_PCS_UFS_POWER_DOWN_CONTROL,
  64. };
  65. static const unsigned int ufsphy_v6_regs_layout[QPHY_LAYOUT_SIZE] = {
  66. [QPHY_START_CTRL] = QPHY_V6_PCS_UFS_PHY_START,
  67. [QPHY_PCS_READY_STATUS] = QPHY_V6_PCS_UFS_READY_STATUS,
  68. [QPHY_SW_RESET] = QPHY_V6_PCS_UFS_SW_RESET,
  69. [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V6_PCS_UFS_POWER_DOWN_CONTROL,
  70. };
  71. static const struct qmp_phy_init_tbl msm8996_ufsphy_serdes[] = {
  72. QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x0e),
  73. QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0xd7),
  74. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x30),
  75. QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x06),
  76. QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
  77. QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0x0a),
  78. QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x05),
  79. QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0x0a),
  80. QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV_MODE1, 0x0a),
  81. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x01),
  82. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_CTRL, 0x10),
  83. QMP_PHY_INIT_CFG(QSERDES_COM_RESETSM_CNTRL, 0x20),
  84. QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x00),
  85. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_CFG, 0x00),
  86. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0xff),
  87. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x3f),
  88. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x54),
  89. QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x05),
  90. QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
  91. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x00),
  92. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x00),
  93. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x00),
  94. QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0x0b),
  95. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
  96. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
  97. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
  98. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  99. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE0, 0x28),
  100. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE0, 0x02),
  101. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0xff),
  102. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0x0c),
  103. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x00),
  104. QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE1, 0x98),
  105. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE1, 0x00),
  106. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE1, 0x00),
  107. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE1, 0x00),
  108. QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE1, 0x0b),
  109. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE1, 0x16),
  110. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE1, 0x28),
  111. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE1, 0x80),
  112. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE1, 0x00),
  113. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE1, 0xd6),
  114. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE1, 0x00),
  115. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE1, 0x32),
  116. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE1, 0x0f),
  117. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE1, 0x00),
  118. };
  119. static const struct qmp_phy_init_tbl msm8996_ufsphy_tx[] = {
  120. QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
  121. QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x02),
  122. };
  123. static const struct qmp_phy_init_tbl msm8996_ufsphy_rx[] = {
  124. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_LVL, 0x24),
  125. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_CNTRL, 0x02),
  126. QMP_PHY_INIT_CFG(QSERDES_RX_RX_INTERFACE_MODE, 0x00),
  127. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x18),
  128. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_FASTLOCK_FO_GAIN, 0x0B),
  129. QMP_PHY_INIT_CFG(QSERDES_RX_RX_TERM_BW, 0x5b),
  130. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_LSB, 0xff),
  131. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_MSB, 0x3f),
  132. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_LSB, 0xff),
  133. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_MSB, 0x0f),
  134. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0E),
  135. };
  136. static const struct qmp_phy_init_tbl sc7280_ufsphy_tx[] = {
  137. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_1_DIVIDER_BAND0_1, 0x06),
  138. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_2_DIVIDER_BAND0_1, 0x03),
  139. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_3_DIVIDER_BAND0_1, 0x01),
  140. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_4_DIVIDER_BAND0_1, 0x00),
  141. QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0x35),
  142. QMP_PHY_INIT_CFG(QSERDES_V4_TX_TRAN_DRVR_EMP_EN, 0x0c),
  143. };
  144. static const struct qmp_phy_init_tbl sc7280_ufsphy_rx[] = {
  145. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_LVL, 0x24),
  146. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x0f),
  147. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
  148. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_BAND, 0x18),
  149. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x0a),
  150. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
  151. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0xf1),
  152. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
  153. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x80),
  154. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0e),
  155. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x04),
  156. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x1b),
  157. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
  158. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
  159. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1d),
  160. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x00),
  161. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x10),
  162. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
  163. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
  164. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x6d),
  165. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0x6d),
  166. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xed),
  167. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x3b),
  168. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x3c),
  169. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0xe0),
  170. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0xc8),
  171. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xc8),
  172. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x3b),
  173. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb1),
  174. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_LOW, 0xe0),
  175. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH, 0xc8),
  176. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH2, 0xc8),
  177. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH3, 0x3b),
  178. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH4, 0xb1),
  179. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DCC_CTRL1, 0x0c),
  180. };
  181. static const struct qmp_phy_init_tbl sc7280_ufsphy_pcs[] = {
  182. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
  183. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
  184. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
  185. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
  186. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_DEBUG_BUS_CLKSEL, 0x1f),
  187. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
  188. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
  189. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_PLL_CNTL, 0x03),
  190. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TIMER_20US_CORECLK_STEPS_MSB, 0x16),
  191. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TIMER_20US_CORECLK_STEPS_LSB, 0xd8),
  192. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_PWM_GEAR_BAND, 0xaa),
  193. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_HS_GEAR_BAND, 0x06),
  194. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_HSGEAR_CAPABILITY, 0x03),
  195. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_HSGEAR_CAPABILITY, 0x03),
  196. };
  197. static const struct qmp_phy_init_tbl sc7280_ufsphy_hs_g4_rx[] = {
  198. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_LVL, 0x24),
  199. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x0f),
  200. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
  201. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_BAND, 0x18),
  202. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x0a),
  203. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
  204. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0xf1),
  205. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
  206. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x81),
  207. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0e),
  208. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x04),
  209. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x6f),
  210. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL1, 0x04),
  211. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x00),
  212. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x09),
  213. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x07),
  214. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x17),
  215. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x00),
  216. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x20),
  217. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0x80),
  218. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
  219. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x3f),
  220. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff),
  221. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xff),
  222. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
  223. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x2c),
  224. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0x6d),
  225. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0x6d),
  226. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xed),
  227. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x3b),
  228. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0x3c),
  229. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_LOW, 0xe0),
  230. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH, 0xc8),
  231. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH2, 0xc8),
  232. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH3, 0x3b),
  233. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH4, 0xb1),
  234. QMP_PHY_INIT_CFG(QSERDES_V4_RX_DCC_CTRL1, 0x0c),
  235. QMP_PHY_INIT_CFG(QSERDES_V4_RX_GM_CAL, 0x0f),
  236. };
  237. static const struct qmp_phy_init_tbl sm6115_ufsphy_serdes[] = {
  238. QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x0e),
  239. QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0x14),
  240. QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x30),
  241. QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x02),
  242. QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
  243. QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0x0a),
  244. QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x00),
  245. QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0x0a),
  246. QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV_MODE1, 0x0a),
  247. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x01),
  248. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_CTRL, 0x00),
  249. QMP_PHY_INIT_CFG(QSERDES_COM_RESETSM_CNTRL, 0x20),
  250. QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x00),
  251. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_CFG, 0x00),
  252. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0xff),
  253. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x3f),
  254. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x04),
  255. QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x05),
  256. QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
  257. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x00),
  258. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x00),
  259. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x00),
  260. QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0x0b),
  261. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
  262. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
  263. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
  264. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  265. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE0, 0x28),
  266. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE0, 0x02),
  267. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0xff),
  268. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0x0c),
  269. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x00),
  270. QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE1, 0x98),
  271. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE1, 0x00),
  272. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE1, 0x00),
  273. QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE1, 0x00),
  274. QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE1, 0x0b),
  275. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE1, 0x16),
  276. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE1, 0x28),
  277. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE1, 0x80),
  278. QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE1, 0x00),
  279. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE1, 0xd6),
  280. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE1, 0x00),
  281. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE1, 0x32),
  282. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE1, 0x0f),
  283. QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE1, 0x00),
  284. QMP_PHY_INIT_CFG(QSERDES_COM_PLL_IVCO, 0x0f),
  285. QMP_PHY_INIT_CFG(QSERDES_COM_BG_TRIM, 0x0f),
  286. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_INITVAL1, 0xff),
  287. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_INITVAL2, 0x00),
  288. };
  289. static const struct qmp_phy_init_tbl sm6115_ufsphy_hs_b_serdes[] = {
  290. QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x44),
  291. };
  292. static const struct qmp_phy_init_tbl sm6115_ufsphy_tx[] = {
  293. QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
  294. QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x06),
  295. };
  296. static const struct qmp_phy_init_tbl sm6115_ufsphy_rx[] = {
  297. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_LVL, 0x24),
  298. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_CNTRL, 0x0F),
  299. QMP_PHY_INIT_CFG(QSERDES_RX_RX_INTERFACE_MODE, 0x40),
  300. QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x1E),
  301. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_FASTLOCK_FO_GAIN, 0x0B),
  302. QMP_PHY_INIT_CFG(QSERDES_RX_RX_TERM_BW, 0x5B),
  303. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_LSB, 0xFF),
  304. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_MSB, 0x3F),
  305. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_LSB, 0xFF),
  306. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_MSB, 0x3F),
  307. QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0D),
  308. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SVS_SO_GAIN_HALF, 0x04),
  309. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SVS_SO_GAIN_QUARTER, 0x04),
  310. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SVS_SO_GAIN, 0x04),
  311. QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5B),
  312. };
  313. static const struct qmp_phy_init_tbl sm6115_ufsphy_pcs[] = {
  314. QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_PWM_GEAR_BAND, 0x15),
  315. QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
  316. QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0f),
  317. QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
  318. QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_MIN_STALL_NOCONFIG_TIME_CAP, 0x28),
  319. QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_SYM_RESYNC_CTRL, 0x03),
  320. QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_LARGE_AMP_POST_EMP_LVL, 0x12),
  321. QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_SMALL_AMP_POST_EMP_LVL, 0x0f),
  322. QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_MIN_HIBERN8_TIME, 0x9a), /* 8 us */
  323. };
  324. static const struct qmp_phy_init_tbl sdm845_ufsphy_serdes[] = {
  325. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
  326. QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x04),
  327. QMP_PHY_INIT_CFG(QSERDES_V3_COM_BG_TIMER, 0x0a),
  328. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
  329. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x06),
  330. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0xd5),
  331. QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL, 0x20),
  332. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
  333. QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x00),
  334. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x01),
  335. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_CTRL, 0x00),
  336. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00),
  337. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x04),
  338. QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x05),
  339. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_INITVAL1, 0xff),
  340. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_INITVAL2, 0x00),
  341. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82),
  342. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
  343. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
  344. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
  345. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
  346. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
  347. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xda),
  348. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01),
  349. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0xff),
  350. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x0c),
  351. QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE1, 0x98),
  352. QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE1, 0x06),
  353. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE1, 0x16),
  354. QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE1, 0x36),
  355. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE1, 0x3f),
  356. QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE1, 0x00),
  357. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE1, 0xc1),
  358. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE1, 0x00),
  359. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE1, 0x32),
  360. QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE1, 0x0f),
  361. };
  362. static const struct qmp_phy_init_tbl sdm845_ufsphy_hs_b_serdes[] = {
  363. QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x44),
  364. };
  365. static const struct qmp_phy_init_tbl sdm845_ufsphy_tx[] = {
  366. QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0x06),
  367. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x04),
  368. QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x07),
  369. };
  370. static const struct qmp_phy_init_tbl sdm845_ufsphy_rx[] = {
  371. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_LVL, 0x24),
  372. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x0f),
  373. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
  374. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_INTERFACE_MODE, 0x40),
  375. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
  376. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_TERM_BW, 0x5b),
  377. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
  378. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
  379. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1b),
  380. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_HALF, 0x04),
  381. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_QUARTER, 0x04),
  382. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN, 0x04),
  383. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
  384. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_PI_CONTROLS, 0x81),
  385. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
  386. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_MODE_00, 0x59),
  387. };
  388. static const struct qmp_phy_init_tbl sdm845_ufsphy_pcs[] = {
  389. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL2, 0x6e),
  390. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
  391. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
  392. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SYM_RESYNC_CTRL, 0x03),
  393. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
  394. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL1, 0x0f),
  395. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_MIN_HIBERN8_TIME, 0x9a),
  396. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
  397. };
  398. static const struct qmp_phy_init_tbl sm7150_ufsphy_rx[] = {
  399. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_LVL, 0x24),
  400. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x0f),
  401. QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
  402. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_INTERFACE_MODE, 0x40),
  403. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
  404. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_TERM_BW, 0x5b),
  405. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
  406. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
  407. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1b),
  408. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_HALF, 0x04),
  409. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_QUARTER, 0x04),
  410. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN, 0x04),
  411. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5b),
  412. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_PI_CONTROLS, 0x81),
  413. QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
  414. QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_MODE_00, 0x59),
  415. };
  416. static const struct qmp_phy_init_tbl sm7150_ufsphy_pcs[] = {
  417. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL2, 0x6f),
  418. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0f),
  419. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
  420. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SYM_RESYNC_CTRL, 0x03),
  421. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
  422. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL1, 0x0f),
  423. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
  424. QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
  425. };
  426. static const struct qmp_phy_init_tbl sm8150_ufsphy_serdes[] = {
  427. QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_EN_SEL, 0xd9),
  428. QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_SEL, 0x11),
  429. QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_HS_SWITCH_SEL, 0x00),
  430. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP_EN, 0x01),
  431. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x02),
  432. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_IVCO, 0x0f),
  433. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_INITVAL2, 0x00),
  434. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_HSCLK_SEL, 0x11),
  435. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE0, 0x82),
  436. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE0, 0x06),
  437. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE0, 0x16),
  438. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE0, 0x36),
  439. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE0, 0xff),
  440. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE0, 0x0c),
  441. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE0, 0xac),
  442. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE0, 0x1e),
  443. QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE1, 0x98),
  444. QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE1, 0x06),
  445. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE1, 0x16),
  446. QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE1, 0x36),
  447. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE1, 0x32),
  448. QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE1, 0x0f),
  449. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE1, 0xdd),
  450. QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE1, 0x23),
  451. };
  452. static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_b_serdes[] = {
  453. QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x06),
  454. };
  455. static const struct qmp_phy_init_tbl sm8150_ufsphy_tx[] = {
  456. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_1_DIVIDER_BAND0_1, 0x06),
  457. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_2_DIVIDER_BAND0_1, 0x03),
  458. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_3_DIVIDER_BAND0_1, 0x01),
  459. QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_4_DIVIDER_BAND0_1, 0x00),
  460. QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0x05),
  461. QMP_PHY_INIT_CFG(QSERDES_V4_TX_TRAN_DRVR_EMP_EN, 0x0c),
  462. };
  463. static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_g4_tx[] = {
  464. QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0x75),
  465. };
  466. static const struct qmp_phy_init_tbl sm8150_ufsphy_rx[] = {
  467. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_LVL, 0x24),
  468. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x0f),
  469. QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
  470. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_BAND, 0x18),
  471. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x0a),
  472. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
  473. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0xf1),
  474. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
  475. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x80),
  476. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0c),
  477. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x04),
  478. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x1b),
  479. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
  480. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
  481. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1d),
  482. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x00),
  483. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x10),
  484. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
  485. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
  486. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x36),
  487. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0x36),
  488. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xf6),
  489. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x3b),
  490. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x3d),
  491. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0xe0),
  492. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0xc8),
  493. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xc8),
  494. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x3b),
  495. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb1),
  496. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_LOW, 0xe0),
  497. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH, 0xc8),
  498. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH2, 0xc8),
  499. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH3, 0x3b),
  500. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH4, 0xb1),
  501. };
  502. static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_g4_rx[] = {
  503. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
  504. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x81),
  505. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0e),
  506. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x6f),
  507. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x20),
  508. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0x80),
  509. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
  510. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x3f),
  511. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff),
  512. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xff),
  513. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
  514. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x6c),
  515. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0x6d),
  516. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0x6d),
  517. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xed),
  518. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0x3c),
  519. };
  520. static const struct qmp_phy_init_tbl sm8150_ufsphy_pcs[] = {
  521. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
  522. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
  523. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
  524. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
  525. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_DEBUG_BUS_CLKSEL, 0x1f),
  526. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
  527. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
  528. };
  529. static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_g4_pcs[] = {
  530. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x10),
  531. QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_BIST_FIXED_PAT_CTRL, 0x0a),
  532. };
  533. static const struct qmp_phy_init_tbl sm8250_ufsphy_hs_g4_tx[] = {
  534. QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0xe5),
  535. };
  536. static const struct qmp_phy_init_tbl sm8250_ufsphy_hs_g4_rx[] = {
  537. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
  538. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x81),
  539. QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0e),
  540. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x6f),
  541. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL1, 0x04),
  542. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x00),
  543. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x09),
  544. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x07),
  545. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x17),
  546. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x20),
  547. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0x80),
  548. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
  549. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x3f),
  550. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff),
  551. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xff),
  552. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
  553. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x2c),
  554. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0x6d),
  555. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0x6d),
  556. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xed),
  557. QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0x3c),
  558. };
  559. static const struct qmp_phy_init_tbl sm8350_ufsphy_serdes[] = {
  560. QMP_PHY_INIT_CFG(QSERDES_V5_COM_SYSCLK_EN_SEL, 0xd9),
  561. QMP_PHY_INIT_CFG(QSERDES_V5_COM_HSCLK_SEL, 0x11),
  562. QMP_PHY_INIT_CFG(QSERDES_V5_COM_HSCLK_HS_SWITCH_SEL, 0x00),
  563. QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP_EN, 0x42),
  564. QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_MAP, 0x02),
  565. QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_IVCO, 0x0f),
  566. QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_INITVAL2, 0x00),
  567. QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_HSCLK_SEL, 0x11),
  568. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DEC_START_MODE0, 0x82),
  569. QMP_PHY_INIT_CFG(QSERDES_V5_COM_CP_CTRL_MODE0, 0x14),
  570. QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_RCTRL_MODE0, 0x18),
  571. QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_CCTRL_MODE0, 0x18),
  572. QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP1_MODE0, 0xff),
  573. QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP2_MODE0, 0x19),
  574. QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE1_MODE0, 0xac),
  575. QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE2_MODE0, 0x1e),
  576. QMP_PHY_INIT_CFG(QSERDES_V5_COM_DEC_START_MODE1, 0x98),
  577. QMP_PHY_INIT_CFG(QSERDES_V5_COM_CP_CTRL_MODE1, 0x14),
  578. QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_RCTRL_MODE1, 0x18),
  579. QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_CCTRL_MODE1, 0x18),
  580. QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP1_MODE1, 0x65),
  581. QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP2_MODE1, 0x1e),
  582. QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE1_MODE1, 0xdd),
  583. QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE2_MODE1, 0x23),
  584. };
  585. static const struct qmp_phy_init_tbl sm8350_ufsphy_hs_b_serdes[] = {
  586. QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_MAP, 0x06),
  587. };
  588. static const struct qmp_phy_init_tbl sm8350_ufsphy_tx[] = {
  589. QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_1_DIVIDER_BAND0_1, 0x06),
  590. QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_2_DIVIDER_BAND0_1, 0x03),
  591. QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_3_DIVIDER_BAND0_1, 0x01),
  592. QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_4_DIVIDER_BAND0_1, 0x00),
  593. QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_1, 0xf5),
  594. QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_3, 0x3f),
  595. QMP_PHY_INIT_CFG(QSERDES_V5_TX_RES_CODE_LANE_OFFSET_TX, 0x09),
  596. QMP_PHY_INIT_CFG(QSERDES_V5_TX_RES_CODE_LANE_OFFSET_RX, 0x09),
  597. QMP_PHY_INIT_CFG(QSERDES_V5_TX_TRAN_DRVR_EMP_EN, 0x0c),
  598. };
  599. static const struct qmp_phy_init_tbl sm8350_ufsphy_rx[] = {
  600. QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_LVL, 0x24),
  601. QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_CNTRL, 0x0f),
  602. QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
  603. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_BAND, 0x18),
  604. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FASTLOCK_FO_GAIN, 0x0a),
  605. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
  606. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_PI_CONTROLS, 0xf1),
  607. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
  608. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_PI_CTRL2, 0x80),
  609. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FO_GAIN, 0x0e),
  610. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SO_GAIN, 0x04),
  611. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_TERM_BW, 0x1b),
  612. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL1, 0x04),
  613. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
  614. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
  615. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1a),
  616. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x17),
  617. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x00),
  618. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_MEASURE_TIME, 0x10),
  619. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
  620. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
  621. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_LOW, 0x6d),
  622. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH, 0x6d),
  623. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH2, 0xed),
  624. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH3, 0x3b),
  625. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH4, 0x3c),
  626. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_LOW, 0xe0),
  627. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH, 0xc8),
  628. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH2, 0xc8),
  629. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH3, 0x3b),
  630. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH4, 0xb7),
  631. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_LOW, 0xe0),
  632. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH, 0xc8),
  633. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH2, 0xc8),
  634. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH3, 0x3b),
  635. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH4, 0xb7),
  636. QMP_PHY_INIT_CFG(QSERDES_V5_RX_DCC_CTRL1, 0x0c),
  637. };
  638. static const struct qmp_phy_init_tbl sm8350_ufsphy_pcs[] = {
  639. QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
  640. QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
  641. QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
  642. QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
  643. QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_DEBUG_BUS_CLKSEL, 0x1f),
  644. QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
  645. QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_RX_SIGDET_CTRL1, 0x0e),
  646. QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
  647. };
  648. static const struct qmp_phy_init_tbl sm8350_ufsphy_g4_tx[] = {
  649. QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_1, 0xe5),
  650. };
  651. static const struct qmp_phy_init_tbl sm8350_ufsphy_g4_rx[] = {
  652. QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_PI_CTRL2, 0x81),
  653. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_TERM_BW, 0x6f),
  654. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL2, 0x00),
  655. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4a),
  656. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL4, 0x0a),
  657. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_MEASURE_TIME, 0x20),
  658. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_LOW, 0x80),
  659. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
  660. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_LOW, 0xbf),
  661. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH, 0xbf),
  662. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH2, 0x7f),
  663. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH3, 0x7f),
  664. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH4, 0x2d),
  665. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_LOW, 0x6d),
  666. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH, 0x6d),
  667. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH2, 0xed),
  668. QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH4, 0x3c),
  669. };
  670. static const struct qmp_phy_init_tbl sm8350_ufsphy_g4_pcs[] = {
  671. QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_BIST_FIXED_PAT_CTRL, 0x0a),
  672. };
  673. static const struct qmp_phy_init_tbl sm8475_ufsphy_serdes[] = {
  674. QMP_PHY_INIT_CFG(QSERDES_V6_COM_SYSCLK_EN_SEL, 0xd9),
  675. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CMN_CONFIG_1, 0x16),
  676. QMP_PHY_INIT_CFG(QSERDES_V6_COM_HSCLK_SEL_1, 0x11),
  677. QMP_PHY_INIT_CFG(QSERDES_V6_COM_HSCLK_HS_SWITCH_SEL_1, 0x00),
  678. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP_EN, 0x01),
  679. QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_INITVAL2, 0x00),
  680. QMP_PHY_INIT_CFG(QSERDES_V6_COM_DEC_START_MODE0, 0x82),
  681. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_RCTRL_MODE0, 0x18),
  682. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_CCTRL_MODE0, 0x18),
  683. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP1_MODE0, 0xff),
  684. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP2_MODE0, 0x0c),
  685. };
  686. static const struct qmp_phy_init_tbl sm8475_ufsphy_g4_serdes[] = {
  687. QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_MAP, 0x04),
  688. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_IVCO, 0x0f),
  689. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE0, 0x14),
  690. QMP_PHY_INIT_CFG(QSERDES_V6_COM_DEC_START_MODE1, 0x98),
  691. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE1, 0x14),
  692. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_RCTRL_MODE1, 0x18),
  693. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_CCTRL_MODE1, 0x18),
  694. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP1_MODE1, 0x32),
  695. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP2_MODE1, 0x0f),
  696. };
  697. static const struct qmp_phy_init_tbl sm8475_ufsphy_g4_pcs[] = {
  698. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_PLL_CNTL, 0x0b),
  699. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_HSGEAR_CAPABILITY, 0x04),
  700. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_HSGEAR_CAPABILITY, 0x04),
  701. };
  702. static const struct qmp_phy_init_tbl sm8550_ufsphy_serdes[] = {
  703. QMP_PHY_INIT_CFG(QSERDES_V6_COM_SYSCLK_EN_SEL, 0xd9),
  704. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CMN_CONFIG_1, 0x16),
  705. QMP_PHY_INIT_CFG(QSERDES_V6_COM_HSCLK_SEL_1, 0x11),
  706. QMP_PHY_INIT_CFG(QSERDES_V6_COM_HSCLK_HS_SWITCH_SEL_1, 0x00),
  707. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP_EN, 0x01),
  708. QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_INITVAL2, 0x00),
  709. QMP_PHY_INIT_CFG(QSERDES_V6_COM_DEC_START_MODE0, 0x41),
  710. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_RCTRL_MODE0, 0x18),
  711. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_CCTRL_MODE0, 0x14),
  712. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP1_MODE0, 0x7f),
  713. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP2_MODE0, 0x06),
  714. };
  715. static const struct qmp_phy_init_tbl sm8550_ufsphy_hs_b_serdes[] = {
  716. QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_MAP, 0x44),
  717. };
  718. static const struct qmp_phy_init_tbl sm8550_ufsphy_g4_serdes[] = {
  719. QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_MAP, 0x04),
  720. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_IVCO, 0x0f),
  721. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE0, 0x0a),
  722. QMP_PHY_INIT_CFG(QSERDES_V6_COM_DEC_START_MODE1, 0x4c),
  723. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE1, 0x0a),
  724. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_RCTRL_MODE1, 0x18),
  725. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_CCTRL_MODE1, 0x14),
  726. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP1_MODE1, 0x99),
  727. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP2_MODE1, 0x07),
  728. };
  729. static const struct qmp_phy_init_tbl sm8550_ufsphy_g5_serdes[] = {
  730. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_IVCO, 0x1f),
  731. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CMN_IETRIM, 0x1b),
  732. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CMN_IPTRIM, 0x1c),
  733. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE0, 0x06),
  734. };
  735. static const struct qmp_phy_init_tbl sm8550_ufsphy_tx[] = {
  736. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_TX_LANE_MODE_1, 0x05),
  737. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_TX_RES_CODE_LANE_OFFSET_TX, 0x07),
  738. };
  739. static const struct qmp_phy_init_tbl sm8550_ufsphy_g4_tx[] = {
  740. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_TX_FR_DCC_CTRL, 0x4c),
  741. };
  742. static const struct qmp_phy_init_tbl sm8550_ufsphy_rx[] = {
  743. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FO_GAIN_RATE2, 0x0c),
  744. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B0, 0xc2),
  745. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B1, 0xc2),
  746. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B3, 0x1a),
  747. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B6, 0x60),
  748. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE2_B3, 0x9e),
  749. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE2_B6, 0x60),
  750. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B3, 0x9e),
  751. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B4, 0x0e),
  752. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B5, 0x36),
  753. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B8, 0x02),
  754. };
  755. static const struct qmp_phy_init_tbl sm8550_ufsphy_g4_rx[] = {
  756. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_VGA_CAL_MAN_VAL, 0x0e),
  757. };
  758. static const struct qmp_phy_init_tbl sm8550_ufsphy_g5_rx[] = {
  759. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FO_GAIN_RATE4, 0x0c),
  760. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_SO_GAIN_RATE4, 0x04),
  761. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x14),
  762. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_PI_CONTROLS, 0x07),
  763. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_OFFSET_ADAPTOR_CNTRL3, 0x0e),
  764. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FASTLOCK_COUNT_HIGH_RATE4, 0x02),
  765. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FASTLOCK_FO_GAIN_RATE4, 0x1c),
  766. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FASTLOCK_SO_GAIN_RATE4, 0x06),
  767. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_VGA_CAL_MAN_VAL, 0x08),
  768. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE4_B3, 0xb9),
  769. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE4_B4, 0x4f),
  770. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE4_B6, 0xff),
  771. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_DLL0_FTUNE_CTRL, 0x30),
  772. };
  773. static const struct qmp_phy_init_tbl sm8550_ufsphy_pcs[] = {
  774. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_SIGDET_CTRL2, 0x69),
  775. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0f),
  776. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
  777. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
  778. };
  779. static const struct qmp_phy_init_tbl sm8550_ufsphy_g4_pcs[] = {
  780. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_PLL_CNTL, 0x2b),
  781. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_HSGEAR_CAPABILITY, 0x04),
  782. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_HSGEAR_CAPABILITY, 0x04),
  783. };
  784. static const struct qmp_phy_init_tbl sm8550_ufsphy_g5_pcs[] = {
  785. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_PLL_CNTL, 0x33),
  786. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_HS_G5_SYNC_LENGTH_CAPABILITY, 0x4f),
  787. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_HSG5_SYNC_WAIT_TIME, 0x9e),
  788. };
  789. static const struct qmp_phy_init_tbl sm8650_ufsphy_serdes[] = {
  790. QMP_PHY_INIT_CFG(QSERDES_V6_COM_SYSCLK_EN_SEL, 0xd9),
  791. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CMN_CONFIG_1, 0x16),
  792. QMP_PHY_INIT_CFG(QSERDES_V6_COM_HSCLK_SEL_1, 0x11),
  793. QMP_PHY_INIT_CFG(QSERDES_V6_COM_HSCLK_HS_SWITCH_SEL_1, 0x00),
  794. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP_EN, 0x01),
  795. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_IVCO, 0x1f),
  796. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_IVCO_MODE1, 0x1f),
  797. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CMN_IETRIM, 0x0a),
  798. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CMN_IPTRIM, 0x17),
  799. QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_MAP, 0x04),
  800. QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_INITVAL2, 0x00),
  801. QMP_PHY_INIT_CFG(QSERDES_V6_COM_DEC_START_MODE0, 0x41),
  802. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE0, 0x06),
  803. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_RCTRL_MODE0, 0x18),
  804. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_CCTRL_MODE0, 0x14),
  805. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP1_MODE0, 0x7f),
  806. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP2_MODE0, 0x06),
  807. QMP_PHY_INIT_CFG(QSERDES_V6_COM_DEC_START_MODE1, 0x4c),
  808. QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE1, 0x06),
  809. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_RCTRL_MODE1, 0x18),
  810. QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_CCTRL_MODE1, 0x14),
  811. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP1_MODE1, 0x99),
  812. QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP2_MODE1, 0x07),
  813. };
  814. static const struct qmp_phy_init_tbl sm8650_ufsphy_tx[] = {
  815. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_TX_LANE_MODE_1, 0x01),
  816. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_TX_RES_CODE_LANE_OFFSET_TX, 0x07),
  817. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_TX_RES_CODE_LANE_OFFSET_RX, 0x0e),
  818. };
  819. static const struct qmp_phy_init_tbl sm8650_ufsphy_rx[] = {
  820. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FO_GAIN_RATE2, 0x0c),
  821. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FO_GAIN_RATE4, 0x0c),
  822. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_SO_GAIN_RATE4, 0x04),
  823. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x14),
  824. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_PI_CONTROLS, 0x07),
  825. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_OFFSET_ADAPTOR_CNTRL3, 0x0e),
  826. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FASTLOCK_COUNT_HIGH_RATE4, 0x02),
  827. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FASTLOCK_FO_GAIN_RATE4, 0x1c),
  828. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FASTLOCK_SO_GAIN_RATE4, 0x06),
  829. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_VGA_CAL_MAN_VAL, 0x3e),
  830. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_RX_EQU_ADAPTOR_CNTRL4, 0x0f),
  831. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B0, 0xce),
  832. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B1, 0xce),
  833. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B2, 0x18),
  834. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B3, 0x1a),
  835. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B4, 0x0f),
  836. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B6, 0x60),
  837. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE2_B3, 0x9e),
  838. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE2_B6, 0x60),
  839. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B3, 0x9e),
  840. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B4, 0x0e),
  841. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B5, 0x36),
  842. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B8, 0x02),
  843. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE4_B0, 0x24),
  844. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE4_B1, 0x24),
  845. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE4_B2, 0x20),
  846. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE4_B3, 0xb9),
  847. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE4_B4, 0x4f),
  848. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_SO_SATURATION, 0x1f),
  849. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_PI_CTRL1, 0x94),
  850. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_RX_TERM_BW_CTRL0, 0xfa),
  851. QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_DLL0_FTUNE_CTRL, 0x30),
  852. };
  853. static const struct qmp_phy_init_tbl sm8650_ufsphy_pcs[] = {
  854. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
  855. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
  856. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_PCS_CTRL1, 0xc1),
  857. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0f),
  858. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_SIGDET_CTRL2, 0x68),
  859. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_POST_EMP_LVL_S4, 0x0e),
  860. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_POST_EMP_LVL_S5, 0x12),
  861. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_POST_EMP_LVL_S6, 0x15),
  862. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_POST_EMP_LVL_S7, 0x19),
  863. };
  864. static const struct qmp_phy_init_tbl sm8650_ufsphy_g4_pcs[] = {
  865. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_PLL_CNTL, 0x13),
  866. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_HSGEAR_CAPABILITY, 0x04),
  867. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_HSGEAR_CAPABILITY, 0x04),
  868. };
  869. static const struct qmp_phy_init_tbl sm8650_ufsphy_g5_pcs[] = {
  870. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_PLL_CNTL, 0x33),
  871. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_HSGEAR_CAPABILITY, 0x05),
  872. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_HSGEAR_CAPABILITY, 0x05),
  873. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_HS_G5_SYNC_LENGTH_CAPABILITY, 0x4d),
  874. QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_HSG5_SYNC_WAIT_TIME, 0x9e),
  875. };
  876. struct qmp_ufs_offsets {
  877. u16 serdes;
  878. u16 pcs;
  879. u16 tx;
  880. u16 rx;
  881. u16 tx2;
  882. u16 rx2;
  883. };
  884. struct qmp_phy_cfg_tbls {
  885. /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
  886. const struct qmp_phy_init_tbl *serdes;
  887. int serdes_num;
  888. const struct qmp_phy_init_tbl *tx;
  889. int tx_num;
  890. const struct qmp_phy_init_tbl *rx;
  891. int rx_num;
  892. const struct qmp_phy_init_tbl *pcs;
  893. int pcs_num;
  894. /* Maximum supported Gear of this tbls */
  895. u32 max_gear;
  896. };
  897. /* struct qmp_phy_cfg - per-PHY initialization config */
  898. struct qmp_phy_cfg {
  899. int lanes;
  900. const struct qmp_ufs_offsets *offsets;
  901. /* Maximum supported Gear of this config */
  902. u32 max_supported_gear;
  903. /* Main init sequence for PHY blocks - serdes, tx, rx, pcs */
  904. const struct qmp_phy_cfg_tbls tbls;
  905. /* Additional sequence for HS Series B */
  906. const struct qmp_phy_cfg_tbls tbls_hs_b;
  907. /* Additional sequence for different HS Gears */
  908. const struct qmp_phy_cfg_tbls tbls_hs_overlay[NUM_OVERLAY];
  909. /* regulators to be requested */
  910. const char * const *vreg_list;
  911. int num_vregs;
  912. /* array of registers with different offsets */
  913. const unsigned int *regs;
  914. /* true, if PCS block has no separate SW_RESET register */
  915. bool no_pcs_sw_reset;
  916. };
  917. struct qmp_ufs {
  918. struct device *dev;
  919. const struct qmp_phy_cfg *cfg;
  920. void __iomem *serdes;
  921. void __iomem *pcs;
  922. void __iomem *pcs_misc;
  923. void __iomem *tx;
  924. void __iomem *rx;
  925. void __iomem *tx2;
  926. void __iomem *rx2;
  927. struct clk_bulk_data *clks;
  928. int num_clks;
  929. struct regulator_bulk_data *vregs;
  930. struct reset_control *ufs_reset;
  931. struct phy *phy;
  932. u32 mode;
  933. u32 submode;
  934. };
  935. static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
  936. {
  937. u32 reg;
  938. reg = readl(base + offset);
  939. reg |= val;
  940. writel(reg, base + offset);
  941. /* ensure that above write is through */
  942. readl(base + offset);
  943. }
  944. static inline void qphy_clrbits(void __iomem *base, u32 offset, u32 val)
  945. {
  946. u32 reg;
  947. reg = readl(base + offset);
  948. reg &= ~val;
  949. writel(reg, base + offset);
  950. /* ensure that above write is through */
  951. readl(base + offset);
  952. }
  953. /* list of regulators */
  954. static const char * const qmp_phy_vreg_l[] = {
  955. "vdda-phy", "vdda-pll",
  956. };
  957. static const struct qmp_ufs_offsets qmp_ufs_offsets = {
  958. .serdes = 0,
  959. .pcs = 0xc00,
  960. .tx = 0x400,
  961. .rx = 0x600,
  962. .tx2 = 0x800,
  963. .rx2 = 0xa00,
  964. };
  965. static const struct qmp_ufs_offsets qmp_ufs_offsets_v6 = {
  966. .serdes = 0,
  967. .pcs = 0x0400,
  968. .tx = 0x1000,
  969. .rx = 0x1200,
  970. .tx2 = 0x1800,
  971. .rx2 = 0x1a00,
  972. };
  973. static const struct qmp_phy_cfg msm8996_ufsphy_cfg = {
  974. .lanes = 1,
  975. .offsets = &qmp_ufs_offsets,
  976. .max_supported_gear = UFS_HS_G3,
  977. .tbls = {
  978. .serdes = msm8996_ufsphy_serdes,
  979. .serdes_num = ARRAY_SIZE(msm8996_ufsphy_serdes),
  980. .tx = msm8996_ufsphy_tx,
  981. .tx_num = ARRAY_SIZE(msm8996_ufsphy_tx),
  982. .rx = msm8996_ufsphy_rx,
  983. .rx_num = ARRAY_SIZE(msm8996_ufsphy_rx),
  984. },
  985. .vreg_list = qmp_phy_vreg_l,
  986. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  987. .regs = ufsphy_v2_regs_layout,
  988. .no_pcs_sw_reset = true,
  989. };
  990. static const struct qmp_phy_cfg sa8775p_ufsphy_cfg = {
  991. .lanes = 2,
  992. .offsets = &qmp_ufs_offsets,
  993. .max_supported_gear = UFS_HS_G4,
  994. .tbls = {
  995. .serdes = sm8350_ufsphy_serdes,
  996. .serdes_num = ARRAY_SIZE(sm8350_ufsphy_serdes),
  997. .tx = sm8350_ufsphy_tx,
  998. .tx_num = ARRAY_SIZE(sm8350_ufsphy_tx),
  999. .rx = sm8350_ufsphy_rx,
  1000. .rx_num = ARRAY_SIZE(sm8350_ufsphy_rx),
  1001. .pcs = sm8350_ufsphy_pcs,
  1002. .pcs_num = ARRAY_SIZE(sm8350_ufsphy_pcs),
  1003. },
  1004. .tbls_hs_b = {
  1005. .serdes = sm8350_ufsphy_hs_b_serdes,
  1006. .serdes_num = ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
  1007. },
  1008. .tbls_hs_overlay[0] = {
  1009. .tx = sm8350_ufsphy_g4_tx,
  1010. .tx_num = ARRAY_SIZE(sm8350_ufsphy_g4_tx),
  1011. .rx = sm8350_ufsphy_g4_rx,
  1012. .rx_num = ARRAY_SIZE(sm8350_ufsphy_g4_rx),
  1013. .pcs = sm8350_ufsphy_g4_pcs,
  1014. .pcs_num = ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
  1015. .max_gear = UFS_HS_G4,
  1016. },
  1017. .vreg_list = qmp_phy_vreg_l,
  1018. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1019. .regs = ufsphy_v5_regs_layout,
  1020. };
  1021. static const struct qmp_phy_cfg sc7280_ufsphy_cfg = {
  1022. .lanes = 2,
  1023. .offsets = &qmp_ufs_offsets,
  1024. .max_supported_gear = UFS_HS_G4,
  1025. .tbls = {
  1026. .serdes = sm8150_ufsphy_serdes,
  1027. .serdes_num = ARRAY_SIZE(sm8150_ufsphy_serdes),
  1028. .tx = sc7280_ufsphy_tx,
  1029. .tx_num = ARRAY_SIZE(sc7280_ufsphy_tx),
  1030. .rx = sc7280_ufsphy_rx,
  1031. .rx_num = ARRAY_SIZE(sc7280_ufsphy_rx),
  1032. .pcs = sc7280_ufsphy_pcs,
  1033. .pcs_num = ARRAY_SIZE(sc7280_ufsphy_pcs),
  1034. },
  1035. .tbls_hs_b = {
  1036. .serdes = sm8150_ufsphy_hs_b_serdes,
  1037. .serdes_num = ARRAY_SIZE(sm8150_ufsphy_hs_b_serdes),
  1038. },
  1039. .tbls_hs_overlay[0] = {
  1040. .tx = sm8250_ufsphy_hs_g4_tx,
  1041. .tx_num = ARRAY_SIZE(sm8250_ufsphy_hs_g4_tx),
  1042. .rx = sc7280_ufsphy_hs_g4_rx,
  1043. .rx_num = ARRAY_SIZE(sc7280_ufsphy_hs_g4_rx),
  1044. .pcs = sm8150_ufsphy_hs_g4_pcs,
  1045. .pcs_num = ARRAY_SIZE(sm8150_ufsphy_hs_g4_pcs),
  1046. .max_gear = UFS_HS_G4,
  1047. },
  1048. .vreg_list = qmp_phy_vreg_l,
  1049. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1050. .regs = ufsphy_v4_regs_layout,
  1051. };
  1052. static const struct qmp_phy_cfg sc8280xp_ufsphy_cfg = {
  1053. .lanes = 2,
  1054. .offsets = &qmp_ufs_offsets,
  1055. .max_supported_gear = UFS_HS_G4,
  1056. .tbls = {
  1057. .serdes = sm8350_ufsphy_serdes,
  1058. .serdes_num = ARRAY_SIZE(sm8350_ufsphy_serdes),
  1059. .tx = sm8350_ufsphy_tx,
  1060. .tx_num = ARRAY_SIZE(sm8350_ufsphy_tx),
  1061. .rx = sm8350_ufsphy_rx,
  1062. .rx_num = ARRAY_SIZE(sm8350_ufsphy_rx),
  1063. .pcs = sm8350_ufsphy_pcs,
  1064. .pcs_num = ARRAY_SIZE(sm8350_ufsphy_pcs),
  1065. },
  1066. .tbls_hs_b = {
  1067. .serdes = sm8350_ufsphy_hs_b_serdes,
  1068. .serdes_num = ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
  1069. },
  1070. .tbls_hs_overlay[0] = {
  1071. .tx = sm8350_ufsphy_g4_tx,
  1072. .tx_num = ARRAY_SIZE(sm8350_ufsphy_g4_tx),
  1073. .rx = sm8350_ufsphy_g4_rx,
  1074. .rx_num = ARRAY_SIZE(sm8350_ufsphy_g4_rx),
  1075. .pcs = sm8350_ufsphy_g4_pcs,
  1076. .pcs_num = ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
  1077. .max_gear = UFS_HS_G4,
  1078. },
  1079. .vreg_list = qmp_phy_vreg_l,
  1080. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1081. .regs = ufsphy_v5_regs_layout,
  1082. };
  1083. static const struct qmp_phy_cfg sdm845_ufsphy_cfg = {
  1084. .lanes = 2,
  1085. .offsets = &qmp_ufs_offsets,
  1086. .max_supported_gear = UFS_HS_G3,
  1087. .tbls = {
  1088. .serdes = sdm845_ufsphy_serdes,
  1089. .serdes_num = ARRAY_SIZE(sdm845_ufsphy_serdes),
  1090. .tx = sdm845_ufsphy_tx,
  1091. .tx_num = ARRAY_SIZE(sdm845_ufsphy_tx),
  1092. .rx = sdm845_ufsphy_rx,
  1093. .rx_num = ARRAY_SIZE(sdm845_ufsphy_rx),
  1094. .pcs = sdm845_ufsphy_pcs,
  1095. .pcs_num = ARRAY_SIZE(sdm845_ufsphy_pcs),
  1096. },
  1097. .tbls_hs_b = {
  1098. .serdes = sdm845_ufsphy_hs_b_serdes,
  1099. .serdes_num = ARRAY_SIZE(sdm845_ufsphy_hs_b_serdes),
  1100. },
  1101. .vreg_list = qmp_phy_vreg_l,
  1102. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1103. .regs = ufsphy_v3_regs_layout,
  1104. .no_pcs_sw_reset = true,
  1105. };
  1106. static const struct qmp_phy_cfg sm6115_ufsphy_cfg = {
  1107. .lanes = 1,
  1108. .offsets = &qmp_ufs_offsets,
  1109. .max_supported_gear = UFS_HS_G3,
  1110. .tbls = {
  1111. .serdes = sm6115_ufsphy_serdes,
  1112. .serdes_num = ARRAY_SIZE(sm6115_ufsphy_serdes),
  1113. .tx = sm6115_ufsphy_tx,
  1114. .tx_num = ARRAY_SIZE(sm6115_ufsphy_tx),
  1115. .rx = sm6115_ufsphy_rx,
  1116. .rx_num = ARRAY_SIZE(sm6115_ufsphy_rx),
  1117. .pcs = sm6115_ufsphy_pcs,
  1118. .pcs_num = ARRAY_SIZE(sm6115_ufsphy_pcs),
  1119. },
  1120. .tbls_hs_b = {
  1121. .serdes = sm6115_ufsphy_hs_b_serdes,
  1122. .serdes_num = ARRAY_SIZE(sm6115_ufsphy_hs_b_serdes),
  1123. },
  1124. .vreg_list = qmp_phy_vreg_l,
  1125. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1126. .regs = ufsphy_v2_regs_layout,
  1127. .no_pcs_sw_reset = true,
  1128. };
  1129. static const struct qmp_phy_cfg sm7150_ufsphy_cfg = {
  1130. .lanes = 1,
  1131. .offsets = &qmp_ufs_offsets,
  1132. .max_supported_gear = UFS_HS_G3,
  1133. .tbls = {
  1134. .serdes = sdm845_ufsphy_serdes,
  1135. .serdes_num = ARRAY_SIZE(sdm845_ufsphy_serdes),
  1136. .tx = sdm845_ufsphy_tx,
  1137. .tx_num = ARRAY_SIZE(sdm845_ufsphy_tx),
  1138. .rx = sm7150_ufsphy_rx,
  1139. .rx_num = ARRAY_SIZE(sm7150_ufsphy_rx),
  1140. .pcs = sm7150_ufsphy_pcs,
  1141. .pcs_num = ARRAY_SIZE(sm7150_ufsphy_pcs),
  1142. },
  1143. .tbls_hs_b = {
  1144. .serdes = sdm845_ufsphy_hs_b_serdes,
  1145. .serdes_num = ARRAY_SIZE(sdm845_ufsphy_hs_b_serdes),
  1146. },
  1147. .vreg_list = qmp_phy_vreg_l,
  1148. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1149. .regs = ufsphy_v3_regs_layout,
  1150. .no_pcs_sw_reset = true,
  1151. };
  1152. static const struct qmp_phy_cfg sm8150_ufsphy_cfg = {
  1153. .lanes = 2,
  1154. .offsets = &qmp_ufs_offsets,
  1155. .max_supported_gear = UFS_HS_G4,
  1156. .tbls = {
  1157. .serdes = sm8150_ufsphy_serdes,
  1158. .serdes_num = ARRAY_SIZE(sm8150_ufsphy_serdes),
  1159. .tx = sm8150_ufsphy_tx,
  1160. .tx_num = ARRAY_SIZE(sm8150_ufsphy_tx),
  1161. .rx = sm8150_ufsphy_rx,
  1162. .rx_num = ARRAY_SIZE(sm8150_ufsphy_rx),
  1163. .pcs = sm8150_ufsphy_pcs,
  1164. .pcs_num = ARRAY_SIZE(sm8150_ufsphy_pcs),
  1165. },
  1166. .tbls_hs_b = {
  1167. .serdes = sm8150_ufsphy_hs_b_serdes,
  1168. .serdes_num = ARRAY_SIZE(sm8150_ufsphy_hs_b_serdes),
  1169. },
  1170. .tbls_hs_overlay[0] = {
  1171. .tx = sm8150_ufsphy_hs_g4_tx,
  1172. .tx_num = ARRAY_SIZE(sm8150_ufsphy_hs_g4_tx),
  1173. .rx = sm8150_ufsphy_hs_g4_rx,
  1174. .rx_num = ARRAY_SIZE(sm8150_ufsphy_hs_g4_rx),
  1175. .pcs = sm8150_ufsphy_hs_g4_pcs,
  1176. .pcs_num = ARRAY_SIZE(sm8150_ufsphy_hs_g4_pcs),
  1177. .max_gear = UFS_HS_G4,
  1178. },
  1179. .vreg_list = qmp_phy_vreg_l,
  1180. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1181. .regs = ufsphy_v4_regs_layout,
  1182. };
  1183. static const struct qmp_phy_cfg sm8250_ufsphy_cfg = {
  1184. .lanes = 2,
  1185. .offsets = &qmp_ufs_offsets,
  1186. .max_supported_gear = UFS_HS_G4,
  1187. .tbls = {
  1188. .serdes = sm8150_ufsphy_serdes,
  1189. .serdes_num = ARRAY_SIZE(sm8150_ufsphy_serdes),
  1190. .tx = sm8150_ufsphy_tx,
  1191. .tx_num = ARRAY_SIZE(sm8150_ufsphy_tx),
  1192. .rx = sm8150_ufsphy_rx,
  1193. .rx_num = ARRAY_SIZE(sm8150_ufsphy_rx),
  1194. .pcs = sm8150_ufsphy_pcs,
  1195. .pcs_num = ARRAY_SIZE(sm8150_ufsphy_pcs),
  1196. },
  1197. .tbls_hs_b = {
  1198. .serdes = sm8150_ufsphy_hs_b_serdes,
  1199. .serdes_num = ARRAY_SIZE(sm8150_ufsphy_hs_b_serdes),
  1200. },
  1201. .tbls_hs_overlay[0] = {
  1202. .tx = sm8250_ufsphy_hs_g4_tx,
  1203. .tx_num = ARRAY_SIZE(sm8250_ufsphy_hs_g4_tx),
  1204. .rx = sm8250_ufsphy_hs_g4_rx,
  1205. .rx_num = ARRAY_SIZE(sm8250_ufsphy_hs_g4_rx),
  1206. .pcs = sm8150_ufsphy_hs_g4_pcs,
  1207. .pcs_num = ARRAY_SIZE(sm8150_ufsphy_hs_g4_pcs),
  1208. .max_gear = UFS_HS_G4,
  1209. },
  1210. .vreg_list = qmp_phy_vreg_l,
  1211. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1212. .regs = ufsphy_v4_regs_layout,
  1213. };
  1214. static const struct qmp_phy_cfg sm8350_ufsphy_cfg = {
  1215. .lanes = 2,
  1216. .offsets = &qmp_ufs_offsets,
  1217. .max_supported_gear = UFS_HS_G4,
  1218. .tbls = {
  1219. .serdes = sm8350_ufsphy_serdes,
  1220. .serdes_num = ARRAY_SIZE(sm8350_ufsphy_serdes),
  1221. .tx = sm8350_ufsphy_tx,
  1222. .tx_num = ARRAY_SIZE(sm8350_ufsphy_tx),
  1223. .rx = sm8350_ufsphy_rx,
  1224. .rx_num = ARRAY_SIZE(sm8350_ufsphy_rx),
  1225. .pcs = sm8350_ufsphy_pcs,
  1226. .pcs_num = ARRAY_SIZE(sm8350_ufsphy_pcs),
  1227. },
  1228. .tbls_hs_b = {
  1229. .serdes = sm8350_ufsphy_hs_b_serdes,
  1230. .serdes_num = ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
  1231. },
  1232. .tbls_hs_overlay[0] = {
  1233. .tx = sm8350_ufsphy_g4_tx,
  1234. .tx_num = ARRAY_SIZE(sm8350_ufsphy_g4_tx),
  1235. .rx = sm8350_ufsphy_g4_rx,
  1236. .rx_num = ARRAY_SIZE(sm8350_ufsphy_g4_rx),
  1237. .pcs = sm8350_ufsphy_g4_pcs,
  1238. .pcs_num = ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
  1239. .max_gear = UFS_HS_G4,
  1240. },
  1241. .vreg_list = qmp_phy_vreg_l,
  1242. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1243. .regs = ufsphy_v5_regs_layout,
  1244. };
  1245. static const struct qmp_phy_cfg sm8450_ufsphy_cfg = {
  1246. .lanes = 2,
  1247. .offsets = &qmp_ufs_offsets,
  1248. .max_supported_gear = UFS_HS_G4,
  1249. .tbls = {
  1250. .serdes = sm8350_ufsphy_serdes,
  1251. .serdes_num = ARRAY_SIZE(sm8350_ufsphy_serdes),
  1252. .tx = sm8350_ufsphy_tx,
  1253. .tx_num = ARRAY_SIZE(sm8350_ufsphy_tx),
  1254. .rx = sm8350_ufsphy_rx,
  1255. .rx_num = ARRAY_SIZE(sm8350_ufsphy_rx),
  1256. .pcs = sm8350_ufsphy_pcs,
  1257. .pcs_num = ARRAY_SIZE(sm8350_ufsphy_pcs),
  1258. },
  1259. .tbls_hs_b = {
  1260. .serdes = sm8350_ufsphy_hs_b_serdes,
  1261. .serdes_num = ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
  1262. },
  1263. .tbls_hs_overlay[0] = {
  1264. .tx = sm8350_ufsphy_g4_tx,
  1265. .tx_num = ARRAY_SIZE(sm8350_ufsphy_g4_tx),
  1266. .rx = sm8350_ufsphy_g4_rx,
  1267. .rx_num = ARRAY_SIZE(sm8350_ufsphy_g4_rx),
  1268. .pcs = sm8350_ufsphy_g4_pcs,
  1269. .pcs_num = ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
  1270. .max_gear = UFS_HS_G4,
  1271. },
  1272. .vreg_list = qmp_phy_vreg_l,
  1273. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1274. .regs = ufsphy_v5_regs_layout,
  1275. };
  1276. static const struct qmp_phy_cfg sm8475_ufsphy_cfg = {
  1277. .lanes = 2,
  1278. .offsets = &qmp_ufs_offsets_v6,
  1279. .max_supported_gear = UFS_HS_G4,
  1280. .tbls = {
  1281. .serdes = sm8475_ufsphy_serdes,
  1282. .serdes_num = ARRAY_SIZE(sm8475_ufsphy_serdes),
  1283. .tx = sm8550_ufsphy_tx,
  1284. .tx_num = ARRAY_SIZE(sm8550_ufsphy_tx),
  1285. .rx = sm8550_ufsphy_rx,
  1286. .rx_num = ARRAY_SIZE(sm8550_ufsphy_rx),
  1287. .pcs = sm8550_ufsphy_pcs,
  1288. .pcs_num = ARRAY_SIZE(sm8550_ufsphy_pcs),
  1289. },
  1290. .tbls_hs_b = {
  1291. .serdes = sm8550_ufsphy_hs_b_serdes,
  1292. .serdes_num = ARRAY_SIZE(sm8550_ufsphy_hs_b_serdes),
  1293. },
  1294. .tbls_hs_overlay[0] = {
  1295. .serdes = sm8475_ufsphy_g4_serdes,
  1296. .serdes_num = ARRAY_SIZE(sm8475_ufsphy_g4_serdes),
  1297. .tx = sm8550_ufsphy_g4_tx,
  1298. .tx_num = ARRAY_SIZE(sm8550_ufsphy_g4_tx),
  1299. .rx = sm8550_ufsphy_g4_rx,
  1300. .rx_num = ARRAY_SIZE(sm8550_ufsphy_g4_rx),
  1301. .pcs = sm8475_ufsphy_g4_pcs,
  1302. .pcs_num = ARRAY_SIZE(sm8475_ufsphy_g4_pcs),
  1303. .max_gear = UFS_HS_G4,
  1304. },
  1305. .vreg_list = qmp_phy_vreg_l,
  1306. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1307. .regs = ufsphy_v6_regs_layout,
  1308. };
  1309. static const struct qmp_phy_cfg sm8550_ufsphy_cfg = {
  1310. .lanes = 2,
  1311. .offsets = &qmp_ufs_offsets_v6,
  1312. .max_supported_gear = UFS_HS_G5,
  1313. .tbls = {
  1314. .serdes = sm8550_ufsphy_serdes,
  1315. .serdes_num = ARRAY_SIZE(sm8550_ufsphy_serdes),
  1316. .tx = sm8550_ufsphy_tx,
  1317. .tx_num = ARRAY_SIZE(sm8550_ufsphy_tx),
  1318. .rx = sm8550_ufsphy_rx,
  1319. .rx_num = ARRAY_SIZE(sm8550_ufsphy_rx),
  1320. .pcs = sm8550_ufsphy_pcs,
  1321. .pcs_num = ARRAY_SIZE(sm8550_ufsphy_pcs),
  1322. },
  1323. .tbls_hs_b = {
  1324. .serdes = sm8550_ufsphy_hs_b_serdes,
  1325. .serdes_num = ARRAY_SIZE(sm8550_ufsphy_hs_b_serdes),
  1326. },
  1327. .tbls_hs_overlay[0] = {
  1328. .serdes = sm8550_ufsphy_g4_serdes,
  1329. .serdes_num = ARRAY_SIZE(sm8550_ufsphy_g4_serdes),
  1330. .tx = sm8550_ufsphy_g4_tx,
  1331. .tx_num = ARRAY_SIZE(sm8550_ufsphy_g4_tx),
  1332. .rx = sm8550_ufsphy_g4_rx,
  1333. .rx_num = ARRAY_SIZE(sm8550_ufsphy_g4_rx),
  1334. .pcs = sm8550_ufsphy_g4_pcs,
  1335. .pcs_num = ARRAY_SIZE(sm8550_ufsphy_g4_pcs),
  1336. .max_gear = UFS_HS_G4,
  1337. },
  1338. .tbls_hs_overlay[1] = {
  1339. .serdes = sm8550_ufsphy_g5_serdes,
  1340. .serdes_num = ARRAY_SIZE(sm8550_ufsphy_g5_serdes),
  1341. .rx = sm8550_ufsphy_g5_rx,
  1342. .rx_num = ARRAY_SIZE(sm8550_ufsphy_g5_rx),
  1343. .pcs = sm8550_ufsphy_g5_pcs,
  1344. .pcs_num = ARRAY_SIZE(sm8550_ufsphy_g5_pcs),
  1345. .max_gear = UFS_HS_G5,
  1346. },
  1347. .vreg_list = qmp_phy_vreg_l,
  1348. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1349. .regs = ufsphy_v6_regs_layout,
  1350. };
  1351. static const struct qmp_phy_cfg sm8650_ufsphy_cfg = {
  1352. .lanes = 2,
  1353. .offsets = &qmp_ufs_offsets_v6,
  1354. .max_supported_gear = UFS_HS_G5,
  1355. .tbls = {
  1356. .serdes = sm8650_ufsphy_serdes,
  1357. .serdes_num = ARRAY_SIZE(sm8650_ufsphy_serdes),
  1358. .tx = sm8650_ufsphy_tx,
  1359. .tx_num = ARRAY_SIZE(sm8650_ufsphy_tx),
  1360. .rx = sm8650_ufsphy_rx,
  1361. .rx_num = ARRAY_SIZE(sm8650_ufsphy_rx),
  1362. .pcs = sm8650_ufsphy_pcs,
  1363. .pcs_num = ARRAY_SIZE(sm8650_ufsphy_pcs),
  1364. },
  1365. .tbls_hs_overlay[0] = {
  1366. .pcs = sm8650_ufsphy_g4_pcs,
  1367. .pcs_num = ARRAY_SIZE(sm8650_ufsphy_g4_pcs),
  1368. .max_gear = UFS_HS_G4,
  1369. },
  1370. .tbls_hs_overlay[1] = {
  1371. .pcs = sm8650_ufsphy_g5_pcs,
  1372. .pcs_num = ARRAY_SIZE(sm8650_ufsphy_g5_pcs),
  1373. .max_gear = UFS_HS_G5,
  1374. },
  1375. .vreg_list = qmp_phy_vreg_l,
  1376. .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
  1377. .regs = ufsphy_v6_regs_layout,
  1378. };
  1379. static void qmp_ufs_serdes_init(struct qmp_ufs *qmp, const struct qmp_phy_cfg_tbls *tbls)
  1380. {
  1381. void __iomem *serdes = qmp->serdes;
  1382. qmp_configure(qmp->dev, serdes, tbls->serdes, tbls->serdes_num);
  1383. }
  1384. static void qmp_ufs_lanes_init(struct qmp_ufs *qmp, const struct qmp_phy_cfg_tbls *tbls)
  1385. {
  1386. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1387. void __iomem *tx = qmp->tx;
  1388. void __iomem *rx = qmp->rx;
  1389. qmp_configure_lane(qmp->dev, tx, tbls->tx, tbls->tx_num, 1);
  1390. qmp_configure_lane(qmp->dev, rx, tbls->rx, tbls->rx_num, 1);
  1391. if (cfg->lanes >= 2) {
  1392. qmp_configure_lane(qmp->dev, qmp->tx2, tbls->tx, tbls->tx_num, 2);
  1393. qmp_configure_lane(qmp->dev, qmp->rx2, tbls->rx, tbls->rx_num, 2);
  1394. }
  1395. }
  1396. static void qmp_ufs_pcs_init(struct qmp_ufs *qmp, const struct qmp_phy_cfg_tbls *tbls)
  1397. {
  1398. void __iomem *pcs = qmp->pcs;
  1399. qmp_configure(qmp->dev, pcs, tbls->pcs, tbls->pcs_num);
  1400. }
  1401. static int qmp_ufs_get_gear_overlay(struct qmp_ufs *qmp, const struct qmp_phy_cfg *cfg)
  1402. {
  1403. u32 max_gear, floor_max_gear = cfg->max_supported_gear;
  1404. int idx, ret = -EINVAL;
  1405. for (idx = NUM_OVERLAY - 1; idx >= 0; idx--) {
  1406. max_gear = cfg->tbls_hs_overlay[idx].max_gear;
  1407. /* Skip if the table is not available */
  1408. if (max_gear == 0)
  1409. continue;
  1410. /* Direct matching, bail */
  1411. if (qmp->submode == max_gear)
  1412. return idx;
  1413. /* If no direct matching, the lowest gear is the best matching */
  1414. if (max_gear < floor_max_gear) {
  1415. ret = idx;
  1416. floor_max_gear = max_gear;
  1417. }
  1418. }
  1419. return ret;
  1420. }
  1421. static void qmp_ufs_init_registers(struct qmp_ufs *qmp, const struct qmp_phy_cfg *cfg)
  1422. {
  1423. int i;
  1424. qmp_ufs_serdes_init(qmp, &cfg->tbls);
  1425. qmp_ufs_lanes_init(qmp, &cfg->tbls);
  1426. qmp_ufs_pcs_init(qmp, &cfg->tbls);
  1427. i = qmp_ufs_get_gear_overlay(qmp, cfg);
  1428. if (i >= 0) {
  1429. qmp_ufs_serdes_init(qmp, &cfg->tbls_hs_overlay[i]);
  1430. qmp_ufs_lanes_init(qmp, &cfg->tbls_hs_overlay[i]);
  1431. qmp_ufs_pcs_init(qmp, &cfg->tbls_hs_overlay[i]);
  1432. }
  1433. if (qmp->mode == PHY_MODE_UFS_HS_B)
  1434. qmp_ufs_serdes_init(qmp, &cfg->tbls_hs_b);
  1435. }
  1436. static int qmp_ufs_com_init(struct qmp_ufs *qmp)
  1437. {
  1438. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1439. void __iomem *pcs = qmp->pcs;
  1440. int ret;
  1441. ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
  1442. if (ret) {
  1443. dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret);
  1444. return ret;
  1445. }
  1446. ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks);
  1447. if (ret)
  1448. goto err_disable_regulators;
  1449. qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
  1450. return 0;
  1451. err_disable_regulators:
  1452. regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
  1453. return ret;
  1454. }
  1455. static int qmp_ufs_com_exit(struct qmp_ufs *qmp)
  1456. {
  1457. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1458. reset_control_assert(qmp->ufs_reset);
  1459. clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
  1460. regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
  1461. return 0;
  1462. }
  1463. static int qmp_ufs_init(struct phy *phy)
  1464. {
  1465. struct qmp_ufs *qmp = phy_get_drvdata(phy);
  1466. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1467. int ret;
  1468. dev_vdbg(qmp->dev, "Initializing QMP phy\n");
  1469. if (cfg->no_pcs_sw_reset) {
  1470. /*
  1471. * Get UFS reset, which is delayed until now to avoid a
  1472. * circular dependency where UFS needs its PHY, but the PHY
  1473. * needs this UFS reset.
  1474. */
  1475. if (!qmp->ufs_reset) {
  1476. qmp->ufs_reset =
  1477. devm_reset_control_get_exclusive(qmp->dev,
  1478. "ufsphy");
  1479. if (IS_ERR(qmp->ufs_reset)) {
  1480. ret = PTR_ERR(qmp->ufs_reset);
  1481. dev_err(qmp->dev,
  1482. "failed to get UFS reset: %d\n",
  1483. ret);
  1484. qmp->ufs_reset = NULL;
  1485. return ret;
  1486. }
  1487. }
  1488. ret = reset_control_assert(qmp->ufs_reset);
  1489. if (ret)
  1490. return ret;
  1491. }
  1492. ret = qmp_ufs_com_init(qmp);
  1493. if (ret)
  1494. return ret;
  1495. return 0;
  1496. }
  1497. static int qmp_ufs_power_on(struct phy *phy)
  1498. {
  1499. struct qmp_ufs *qmp = phy_get_drvdata(phy);
  1500. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1501. void __iomem *pcs = qmp->pcs;
  1502. void __iomem *status;
  1503. unsigned int val;
  1504. int ret;
  1505. qmp_ufs_init_registers(qmp, cfg);
  1506. ret = reset_control_deassert(qmp->ufs_reset);
  1507. if (ret)
  1508. return ret;
  1509. /* Pull PHY out of reset state */
  1510. if (!cfg->no_pcs_sw_reset)
  1511. qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
  1512. /* start SerDes */
  1513. qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], SERDES_START);
  1514. status = pcs + cfg->regs[QPHY_PCS_READY_STATUS];
  1515. ret = readl_poll_timeout(status, val, (val & PCS_READY), 200,
  1516. PHY_INIT_COMPLETE_TIMEOUT);
  1517. if (ret) {
  1518. dev_err(qmp->dev, "phy initialization timed-out\n");
  1519. return ret;
  1520. }
  1521. return 0;
  1522. }
  1523. static int qmp_ufs_power_off(struct phy *phy)
  1524. {
  1525. struct qmp_ufs *qmp = phy_get_drvdata(phy);
  1526. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1527. /* PHY reset */
  1528. if (!cfg->no_pcs_sw_reset)
  1529. qphy_setbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
  1530. /* stop SerDes */
  1531. qphy_clrbits(qmp->pcs, cfg->regs[QPHY_START_CTRL], SERDES_START);
  1532. /* Put PHY into POWER DOWN state: active low */
  1533. qphy_clrbits(qmp->pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL],
  1534. SW_PWRDN);
  1535. return 0;
  1536. }
  1537. static int qmp_ufs_exit(struct phy *phy)
  1538. {
  1539. struct qmp_ufs *qmp = phy_get_drvdata(phy);
  1540. qmp_ufs_com_exit(qmp);
  1541. return 0;
  1542. }
  1543. static int qmp_ufs_enable(struct phy *phy)
  1544. {
  1545. int ret;
  1546. ret = qmp_ufs_init(phy);
  1547. if (ret)
  1548. return ret;
  1549. ret = qmp_ufs_power_on(phy);
  1550. if (ret)
  1551. qmp_ufs_exit(phy);
  1552. return ret;
  1553. }
  1554. static int qmp_ufs_disable(struct phy *phy)
  1555. {
  1556. int ret;
  1557. ret = qmp_ufs_power_off(phy);
  1558. if (ret)
  1559. return ret;
  1560. return qmp_ufs_exit(phy);
  1561. }
  1562. static int qmp_ufs_set_mode(struct phy *phy, enum phy_mode mode, int submode)
  1563. {
  1564. struct qmp_ufs *qmp = phy_get_drvdata(phy);
  1565. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1566. if (submode > cfg->max_supported_gear || submode == 0) {
  1567. dev_err(qmp->dev, "Invalid PHY submode %d\n", submode);
  1568. return -EINVAL;
  1569. }
  1570. qmp->mode = mode;
  1571. qmp->submode = submode;
  1572. return 0;
  1573. }
  1574. static const struct phy_ops qcom_qmp_ufs_phy_ops = {
  1575. .power_on = qmp_ufs_enable,
  1576. .power_off = qmp_ufs_disable,
  1577. .set_mode = qmp_ufs_set_mode,
  1578. .owner = THIS_MODULE,
  1579. };
  1580. static int qmp_ufs_vreg_init(struct qmp_ufs *qmp)
  1581. {
  1582. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1583. struct device *dev = qmp->dev;
  1584. int num = cfg->num_vregs;
  1585. int i;
  1586. qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL);
  1587. if (!qmp->vregs)
  1588. return -ENOMEM;
  1589. for (i = 0; i < num; i++)
  1590. qmp->vregs[i].supply = cfg->vreg_list[i];
  1591. return devm_regulator_bulk_get(dev, num, qmp->vregs);
  1592. }
  1593. static int qmp_ufs_clk_init(struct qmp_ufs *qmp)
  1594. {
  1595. struct device *dev = qmp->dev;
  1596. qmp->num_clks = devm_clk_bulk_get_all(dev, &qmp->clks);
  1597. if (qmp->num_clks < 0)
  1598. return qmp->num_clks;
  1599. return 0;
  1600. }
  1601. static void qmp_ufs_clk_release_provider(void *res)
  1602. {
  1603. of_clk_del_provider(res);
  1604. }
  1605. #define UFS_SYMBOL_CLOCKS 3
  1606. static int qmp_ufs_register_clocks(struct qmp_ufs *qmp, struct device_node *np)
  1607. {
  1608. struct clk_hw_onecell_data *clk_data;
  1609. struct clk_hw *hw;
  1610. char name[64];
  1611. int ret;
  1612. clk_data = devm_kzalloc(qmp->dev,
  1613. struct_size(clk_data, hws, UFS_SYMBOL_CLOCKS),
  1614. GFP_KERNEL);
  1615. if (!clk_data)
  1616. return -ENOMEM;
  1617. clk_data->num = UFS_SYMBOL_CLOCKS;
  1618. snprintf(name, sizeof(name), "%s::rx_symbol_0", dev_name(qmp->dev));
  1619. hw = devm_clk_hw_register_fixed_rate(qmp->dev, name, NULL, 0, 0);
  1620. if (IS_ERR(hw))
  1621. return PTR_ERR(hw);
  1622. clk_data->hws[0] = hw;
  1623. snprintf(name, sizeof(name), "%s::rx_symbol_1", dev_name(qmp->dev));
  1624. hw = devm_clk_hw_register_fixed_rate(qmp->dev, name, NULL, 0, 0);
  1625. if (IS_ERR(hw))
  1626. return PTR_ERR(hw);
  1627. clk_data->hws[1] = hw;
  1628. snprintf(name, sizeof(name), "%s::tx_symbol_0", dev_name(qmp->dev));
  1629. hw = devm_clk_hw_register_fixed_rate(qmp->dev, name, NULL, 0, 0);
  1630. if (IS_ERR(hw))
  1631. return PTR_ERR(hw);
  1632. clk_data->hws[2] = hw;
  1633. ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
  1634. if (ret)
  1635. return ret;
  1636. /*
  1637. * Roll a devm action because the clock provider can be a child node.
  1638. */
  1639. return devm_add_action_or_reset(qmp->dev, qmp_ufs_clk_release_provider, np);
  1640. }
  1641. static int qmp_ufs_parse_dt_legacy(struct qmp_ufs *qmp, struct device_node *np)
  1642. {
  1643. struct platform_device *pdev = to_platform_device(qmp->dev);
  1644. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1645. struct device *dev = qmp->dev;
  1646. qmp->serdes = devm_platform_ioremap_resource(pdev, 0);
  1647. if (IS_ERR(qmp->serdes))
  1648. return PTR_ERR(qmp->serdes);
  1649. /*
  1650. * Get memory resources for the PHY:
  1651. * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2.
  1652. * For dual lane PHYs: tx2 -> 3, rx2 -> 4, pcs_misc (optional) -> 5
  1653. * For single lane PHYs: pcs_misc (optional) -> 3.
  1654. */
  1655. qmp->tx = devm_of_iomap(dev, np, 0, NULL);
  1656. if (IS_ERR(qmp->tx))
  1657. return PTR_ERR(qmp->tx);
  1658. qmp->rx = devm_of_iomap(dev, np, 1, NULL);
  1659. if (IS_ERR(qmp->rx))
  1660. return PTR_ERR(qmp->rx);
  1661. qmp->pcs = devm_of_iomap(dev, np, 2, NULL);
  1662. if (IS_ERR(qmp->pcs))
  1663. return PTR_ERR(qmp->pcs);
  1664. if (cfg->lanes >= 2) {
  1665. qmp->tx2 = devm_of_iomap(dev, np, 3, NULL);
  1666. if (IS_ERR(qmp->tx2))
  1667. return PTR_ERR(qmp->tx2);
  1668. qmp->rx2 = devm_of_iomap(dev, np, 4, NULL);
  1669. if (IS_ERR(qmp->rx2))
  1670. return PTR_ERR(qmp->rx2);
  1671. qmp->pcs_misc = devm_of_iomap(dev, np, 5, NULL);
  1672. } else {
  1673. qmp->pcs_misc = devm_of_iomap(dev, np, 3, NULL);
  1674. }
  1675. if (IS_ERR(qmp->pcs_misc))
  1676. dev_vdbg(dev, "PHY pcs_misc-reg not used\n");
  1677. return 0;
  1678. }
  1679. static int qmp_ufs_parse_dt(struct qmp_ufs *qmp)
  1680. {
  1681. struct platform_device *pdev = to_platform_device(qmp->dev);
  1682. const struct qmp_phy_cfg *cfg = qmp->cfg;
  1683. const struct qmp_ufs_offsets *offs = cfg->offsets;
  1684. void __iomem *base;
  1685. if (!offs)
  1686. return -EINVAL;
  1687. base = devm_platform_ioremap_resource(pdev, 0);
  1688. if (IS_ERR(base))
  1689. return PTR_ERR(base);
  1690. qmp->serdes = base + offs->serdes;
  1691. qmp->pcs = base + offs->pcs;
  1692. qmp->tx = base + offs->tx;
  1693. qmp->rx = base + offs->rx;
  1694. if (cfg->lanes >= 2) {
  1695. qmp->tx2 = base + offs->tx2;
  1696. qmp->rx2 = base + offs->rx2;
  1697. }
  1698. return 0;
  1699. }
  1700. static int qmp_ufs_probe(struct platform_device *pdev)
  1701. {
  1702. struct device *dev = &pdev->dev;
  1703. struct phy_provider *phy_provider;
  1704. struct device_node *np;
  1705. struct qmp_ufs *qmp;
  1706. int ret;
  1707. qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL);
  1708. if (!qmp)
  1709. return -ENOMEM;
  1710. qmp->dev = dev;
  1711. qmp->cfg = of_device_get_match_data(dev);
  1712. if (!qmp->cfg)
  1713. return -EINVAL;
  1714. ret = qmp_ufs_clk_init(qmp);
  1715. if (ret)
  1716. return ret;
  1717. ret = qmp_ufs_vreg_init(qmp);
  1718. if (ret)
  1719. return ret;
  1720. /* Check for legacy binding with child node. */
  1721. np = of_get_next_available_child(dev->of_node, NULL);
  1722. if (np) {
  1723. ret = qmp_ufs_parse_dt_legacy(qmp, np);
  1724. } else {
  1725. np = of_node_get(dev->of_node);
  1726. ret = qmp_ufs_parse_dt(qmp);
  1727. }
  1728. if (ret)
  1729. goto err_node_put;
  1730. ret = qmp_ufs_register_clocks(qmp, np);
  1731. if (ret)
  1732. goto err_node_put;
  1733. qmp->phy = devm_phy_create(dev, np, &qcom_qmp_ufs_phy_ops);
  1734. if (IS_ERR(qmp->phy)) {
  1735. ret = PTR_ERR(qmp->phy);
  1736. dev_err(dev, "failed to create PHY: %d\n", ret);
  1737. goto err_node_put;
  1738. }
  1739. phy_set_drvdata(qmp->phy, qmp);
  1740. of_node_put(np);
  1741. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  1742. return PTR_ERR_OR_ZERO(phy_provider);
  1743. err_node_put:
  1744. of_node_put(np);
  1745. return ret;
  1746. }
  1747. static const struct of_device_id qmp_ufs_of_match_table[] = {
  1748. {
  1749. .compatible = "qcom,msm8996-qmp-ufs-phy",
  1750. .data = &msm8996_ufsphy_cfg,
  1751. }, {
  1752. .compatible = "qcom,msm8998-qmp-ufs-phy",
  1753. .data = &sdm845_ufsphy_cfg,
  1754. }, {
  1755. .compatible = "qcom,sa8775p-qmp-ufs-phy",
  1756. .data = &sa8775p_ufsphy_cfg,
  1757. }, {
  1758. .compatible = "qcom,sc7180-qmp-ufs-phy",
  1759. .data = &sm7150_ufsphy_cfg,
  1760. }, {
  1761. .compatible = "qcom,sc7280-qmp-ufs-phy",
  1762. .data = &sc7280_ufsphy_cfg,
  1763. }, {
  1764. .compatible = "qcom,sc8180x-qmp-ufs-phy",
  1765. .data = &sm8150_ufsphy_cfg,
  1766. }, {
  1767. .compatible = "qcom,sc8280xp-qmp-ufs-phy",
  1768. .data = &sc8280xp_ufsphy_cfg,
  1769. }, {
  1770. .compatible = "qcom,sdm845-qmp-ufs-phy",
  1771. .data = &sdm845_ufsphy_cfg,
  1772. }, {
  1773. .compatible = "qcom,sm6115-qmp-ufs-phy",
  1774. .data = &sm6115_ufsphy_cfg,
  1775. }, {
  1776. .compatible = "qcom,sm6125-qmp-ufs-phy",
  1777. .data = &sm6115_ufsphy_cfg,
  1778. }, {
  1779. .compatible = "qcom,sm6350-qmp-ufs-phy",
  1780. .data = &sdm845_ufsphy_cfg,
  1781. }, {
  1782. .compatible = "qcom,sm7150-qmp-ufs-phy",
  1783. .data = &sm7150_ufsphy_cfg,
  1784. }, {
  1785. .compatible = "qcom,sm8150-qmp-ufs-phy",
  1786. .data = &sm8150_ufsphy_cfg,
  1787. }, {
  1788. .compatible = "qcom,sm8250-qmp-ufs-phy",
  1789. .data = &sm8250_ufsphy_cfg,
  1790. }, {
  1791. .compatible = "qcom,sm8350-qmp-ufs-phy",
  1792. .data = &sm8350_ufsphy_cfg,
  1793. }, {
  1794. .compatible = "qcom,sm8450-qmp-ufs-phy",
  1795. .data = &sm8450_ufsphy_cfg,
  1796. }, {
  1797. .compatible = "qcom,sm8475-qmp-ufs-phy",
  1798. .data = &sm8475_ufsphy_cfg,
  1799. }, {
  1800. .compatible = "qcom,sm8550-qmp-ufs-phy",
  1801. .data = &sm8550_ufsphy_cfg,
  1802. }, {
  1803. .compatible = "qcom,sm8650-qmp-ufs-phy",
  1804. .data = &sm8650_ufsphy_cfg,
  1805. },
  1806. { },
  1807. };
  1808. MODULE_DEVICE_TABLE(of, qmp_ufs_of_match_table);
  1809. static struct platform_driver qmp_ufs_driver = {
  1810. .probe = qmp_ufs_probe,
  1811. .driver = {
  1812. .name = "qcom-qmp-ufs-phy",
  1813. .of_match_table = qmp_ufs_of_match_table,
  1814. },
  1815. };
  1816. module_platform_driver(qmp_ufs_driver);
  1817. MODULE_AUTHOR("Vivek Gautam <vivek.gautam@codeaurora.org>");
  1818. MODULE_DESCRIPTION("Qualcomm QMP UFS PHY driver");
  1819. MODULE_LICENSE("GPL v2");