phy-qcom-qmp.c 53 KB

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