phy-qcom-qusb2.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2017, 2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/delay.h>
  7. #include <linux/err.h>
  8. #include <linux/io.h>
  9. #include <linux/kernel.h>
  10. #include <linux/mfd/syscon.h>
  11. #include <linux/module.h>
  12. #include <linux/nvmem-consumer.h>
  13. #include <linux/of.h>
  14. #include <linux/of_device.h>
  15. #include <linux/phy/phy.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/regmap.h>
  18. #include <linux/regulator/consumer.h>
  19. #include <linux/reset.h>
  20. #include <linux/slab.h>
  21. #include <dt-bindings/phy/phy-qcom-qusb2.h>
  22. #define QUSB2PHY_PLL 0x0
  23. #define QUSB2PHY_PLL_TEST 0x04
  24. #define CLK_REF_SEL BIT(7)
  25. #define QUSB2PHY_PLL_TUNE 0x08
  26. #define QUSB2PHY_PLL_USER_CTL1 0x0c
  27. #define QUSB2PHY_PLL_USER_CTL2 0x10
  28. #define QUSB2PHY_PLL_AUTOPGM_CTL1 0x1c
  29. #define QUSB2PHY_PLL_PWR_CTRL 0x18
  30. /* QUSB2PHY_PLL_STATUS register bits */
  31. #define PLL_LOCKED BIT(5)
  32. /* QUSB2PHY_PLL_COMMON_STATUS_ONE register bits */
  33. #define CORE_READY_STATUS BIT(0)
  34. /* QUSB2PHY_PORT_POWERDOWN register bits */
  35. #define CLAMP_N_EN BIT(5)
  36. #define FREEZIO_N BIT(1)
  37. #define POWER_DOWN BIT(0)
  38. /* QUSB2PHY_PWR_CTRL1 register bits */
  39. #define PWR_CTRL1_VREF_SUPPLY_TRIM BIT(5)
  40. #define PWR_CTRL1_CLAMP_N_EN BIT(1)
  41. #define QUSB2PHY_REFCLK_ENABLE BIT(0)
  42. #define PHY_CLK_SCHEME_SEL BIT(0)
  43. /* QUSB2PHY_INTR_CTRL register bits */
  44. #define DMSE_INTR_HIGH_SEL BIT(4)
  45. #define DPSE_INTR_HIGH_SEL BIT(3)
  46. #define CHG_DET_INTR_EN BIT(2)
  47. #define DMSE_INTR_EN BIT(1)
  48. #define DPSE_INTR_EN BIT(0)
  49. /* QUSB2PHY_PLL_CORE_INPUT_OVERRIDE register bits */
  50. #define CORE_PLL_EN_FROM_RESET BIT(4)
  51. #define CORE_RESET BIT(5)
  52. #define CORE_RESET_MUX BIT(6)
  53. /* QUSB2PHY_IMP_CTRL1 register bits */
  54. #define IMP_RES_OFFSET_MASK GENMASK(5, 0)
  55. #define IMP_RES_OFFSET_SHIFT 0x0
  56. /* QUSB2PHY_PLL_BIAS_CONTROL_2 register bits */
  57. #define BIAS_CTRL2_RES_OFFSET_MASK GENMASK(5, 0)
  58. #define BIAS_CTRL2_RES_OFFSET_SHIFT 0x0
  59. /* QUSB2PHY_CHG_CONTROL_2 register bits */
  60. #define CHG_CTRL2_OFFSET_MASK GENMASK(5, 4)
  61. #define CHG_CTRL2_OFFSET_SHIFT 0x4
  62. /* QUSB2PHY_PORT_TUNE1 register bits */
  63. #define HSTX_TRIM_MASK GENMASK(7, 4)
  64. #define HSTX_TRIM_SHIFT 0x4
  65. #define PREEMPH_WIDTH_HALF_BIT BIT(2)
  66. #define PREEMPHASIS_EN_MASK GENMASK(1, 0)
  67. #define PREEMPHASIS_EN_SHIFT 0x0
  68. /* QUSB2PHY_PORT_TUNE2 register bits */
  69. #define HSDISC_TRIM_MASK GENMASK(1, 0)
  70. #define HSDISC_TRIM_SHIFT 0x0
  71. #define QUSB2PHY_PLL_ANALOG_CONTROLS_TWO 0x04
  72. #define QUSB2PHY_PLL_CLOCK_INVERTERS 0x18c
  73. #define QUSB2PHY_PLL_CMODE 0x2c
  74. #define QUSB2PHY_PLL_LOCK_DELAY 0x184
  75. #define QUSB2PHY_PLL_DIGITAL_TIMERS_TWO 0xb4
  76. #define QUSB2PHY_PLL_BIAS_CONTROL_1 0x194
  77. #define QUSB2PHY_PLL_BIAS_CONTROL_2 0x198
  78. #define QUSB2PHY_PWR_CTRL2 0x214
  79. #define QUSB2PHY_IMP_CTRL1 0x220
  80. #define QUSB2PHY_IMP_CTRL2 0x224
  81. #define QUSB2PHY_CHG_CTRL2 0x23c
  82. struct qusb2_phy_init_tbl {
  83. unsigned int offset;
  84. unsigned int val;
  85. /*
  86. * register part of layout ?
  87. * if yes, then offset gives index in the reg-layout
  88. */
  89. int in_layout;
  90. };
  91. #define QUSB2_PHY_INIT_CFG(o, v) \
  92. { \
  93. .offset = o, \
  94. .val = v, \
  95. }
  96. #define QUSB2_PHY_INIT_CFG_L(o, v) \
  97. { \
  98. .offset = o, \
  99. .val = v, \
  100. .in_layout = 1, \
  101. }
  102. /* set of registers with offsets different per-PHY */
  103. enum qusb2phy_reg_layout {
  104. QUSB2PHY_PLL_CORE_INPUT_OVERRIDE,
  105. QUSB2PHY_PLL_STATUS,
  106. QUSB2PHY_PORT_TUNE1,
  107. QUSB2PHY_PORT_TUNE2,
  108. QUSB2PHY_PORT_TUNE3,
  109. QUSB2PHY_PORT_TUNE4,
  110. QUSB2PHY_PORT_TUNE5,
  111. QUSB2PHY_PORT_TEST1,
  112. QUSB2PHY_PORT_TEST2,
  113. QUSB2PHY_PORT_POWERDOWN,
  114. QUSB2PHY_INTR_CTRL,
  115. };
  116. static const struct qusb2_phy_init_tbl ipq6018_init_tbl[] = {
  117. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL, 0x14),
  118. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE1, 0xF8),
  119. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE2, 0xB3),
  120. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE3, 0x83),
  121. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE4, 0xC0),
  122. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_TUNE, 0x30),
  123. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL1, 0x79),
  124. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL2, 0x21),
  125. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE5, 0x00),
  126. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_PWR_CTRL, 0x00),
  127. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TEST2, 0x14),
  128. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_TEST, 0x80),
  129. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_AUTOPGM_CTL1, 0x9F),
  130. };
  131. static const unsigned int ipq6018_regs_layout[] = {
  132. [QUSB2PHY_PLL_STATUS] = 0x38,
  133. [QUSB2PHY_PORT_TUNE1] = 0x80,
  134. [QUSB2PHY_PORT_TUNE2] = 0x84,
  135. [QUSB2PHY_PORT_TUNE3] = 0x88,
  136. [QUSB2PHY_PORT_TUNE4] = 0x8C,
  137. [QUSB2PHY_PORT_TUNE5] = 0x90,
  138. [QUSB2PHY_PORT_TEST1] = 0x98,
  139. [QUSB2PHY_PORT_TEST2] = 0x9C,
  140. [QUSB2PHY_PORT_POWERDOWN] = 0xB4,
  141. [QUSB2PHY_INTR_CTRL] = 0xBC,
  142. };
  143. static const unsigned int msm8996_regs_layout[] = {
  144. [QUSB2PHY_PLL_STATUS] = 0x38,
  145. [QUSB2PHY_PORT_TUNE1] = 0x80,
  146. [QUSB2PHY_PORT_TUNE2] = 0x84,
  147. [QUSB2PHY_PORT_TUNE3] = 0x88,
  148. [QUSB2PHY_PORT_TUNE4] = 0x8c,
  149. [QUSB2PHY_PORT_TUNE5] = 0x90,
  150. [QUSB2PHY_PORT_TEST1] = 0xb8,
  151. [QUSB2PHY_PORT_TEST2] = 0x9c,
  152. [QUSB2PHY_PORT_POWERDOWN] = 0xb4,
  153. [QUSB2PHY_INTR_CTRL] = 0xbc,
  154. };
  155. static const struct qusb2_phy_init_tbl msm8996_init_tbl[] = {
  156. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE1, 0xf8),
  157. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE2, 0xb3),
  158. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE3, 0x83),
  159. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE4, 0xc0),
  160. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_TUNE, 0x30),
  161. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL1, 0x79),
  162. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL2, 0x21),
  163. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TEST2, 0x14),
  164. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_AUTOPGM_CTL1, 0x9f),
  165. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_PWR_CTRL, 0x00),
  166. };
  167. static const unsigned int msm8998_regs_layout[] = {
  168. [QUSB2PHY_PLL_CORE_INPUT_OVERRIDE] = 0xa8,
  169. [QUSB2PHY_PLL_STATUS] = 0x1a0,
  170. [QUSB2PHY_PORT_TUNE1] = 0x23c,
  171. [QUSB2PHY_PORT_TUNE2] = 0x240,
  172. [QUSB2PHY_PORT_TUNE3] = 0x244,
  173. [QUSB2PHY_PORT_TUNE4] = 0x248,
  174. [QUSB2PHY_PORT_TEST1] = 0x24c,
  175. [QUSB2PHY_PORT_TEST2] = 0x250,
  176. [QUSB2PHY_PORT_POWERDOWN] = 0x210,
  177. [QUSB2PHY_INTR_CTRL] = 0x22c,
  178. };
  179. static const struct qusb2_phy_init_tbl msm8998_init_tbl[] = {
  180. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_ANALOG_CONTROLS_TWO, 0x13),
  181. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_CLOCK_INVERTERS, 0x7c),
  182. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_CMODE, 0x80),
  183. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_LOCK_DELAY, 0x0a),
  184. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE1, 0xa5),
  185. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE2, 0x09),
  186. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_DIGITAL_TIMERS_TWO, 0x19),
  187. };
  188. static const struct qusb2_phy_init_tbl sm6115_init_tbl[] = {
  189. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE1, 0xf8),
  190. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE2, 0x53),
  191. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE3, 0x81),
  192. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE4, 0x17),
  193. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_TUNE, 0x30),
  194. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL1, 0x79),
  195. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL2, 0x21),
  196. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TEST2, 0x14),
  197. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_AUTOPGM_CTL1, 0x9f),
  198. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_PWR_CTRL, 0x00),
  199. };
  200. static const unsigned int qusb2_v2_regs_layout[] = {
  201. [QUSB2PHY_PLL_CORE_INPUT_OVERRIDE] = 0xa8,
  202. [QUSB2PHY_PLL_STATUS] = 0x1a0,
  203. [QUSB2PHY_PORT_TUNE1] = 0x240,
  204. [QUSB2PHY_PORT_TUNE2] = 0x244,
  205. [QUSB2PHY_PORT_TUNE3] = 0x248,
  206. [QUSB2PHY_PORT_TUNE4] = 0x24c,
  207. [QUSB2PHY_PORT_TUNE5] = 0x250,
  208. [QUSB2PHY_PORT_TEST1] = 0x254,
  209. [QUSB2PHY_PORT_TEST2] = 0x258,
  210. [QUSB2PHY_PORT_POWERDOWN] = 0x210,
  211. [QUSB2PHY_INTR_CTRL] = 0x230,
  212. };
  213. static const struct qusb2_phy_init_tbl qusb2_v2_init_tbl[] = {
  214. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_ANALOG_CONTROLS_TWO, 0x03),
  215. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_CLOCK_INVERTERS, 0x7c),
  216. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_CMODE, 0x80),
  217. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_LOCK_DELAY, 0x0a),
  218. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_DIGITAL_TIMERS_TWO, 0x19),
  219. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_BIAS_CONTROL_1, 0x40),
  220. QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_BIAS_CONTROL_2, 0x20),
  221. QUSB2_PHY_INIT_CFG(QUSB2PHY_PWR_CTRL2, 0x21),
  222. QUSB2_PHY_INIT_CFG(QUSB2PHY_IMP_CTRL1, 0x0),
  223. QUSB2_PHY_INIT_CFG(QUSB2PHY_IMP_CTRL2, 0x58),
  224. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE1, 0x30),
  225. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE2, 0x29),
  226. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE3, 0xca),
  227. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE4, 0x04),
  228. QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE5, 0x03),
  229. QUSB2_PHY_INIT_CFG(QUSB2PHY_CHG_CTRL2, 0x0),
  230. };
  231. struct qusb2_phy_cfg {
  232. const struct qusb2_phy_init_tbl *tbl;
  233. /* number of entries in the table */
  234. unsigned int tbl_num;
  235. /* offset to PHY_CLK_SCHEME register in TCSR map */
  236. unsigned int clk_scheme_offset;
  237. /* array of registers with different offsets */
  238. const unsigned int *regs;
  239. unsigned int mask_core_ready;
  240. unsigned int disable_ctrl;
  241. unsigned int autoresume_en;
  242. /* true if PHY has PLL_TEST register to select clk_scheme */
  243. bool has_pll_test;
  244. /* true if TUNE1 register must be updated by fused value, else TUNE2 */
  245. bool update_tune1_with_efuse;
  246. /* true if PHY has PLL_CORE_INPUT_OVERRIDE register to reset PLL */
  247. bool has_pll_override;
  248. /* true if PHY default clk scheme is single-ended */
  249. bool se_clk_scheme_default;
  250. };
  251. static const struct qusb2_phy_cfg msm8996_phy_cfg = {
  252. .tbl = msm8996_init_tbl,
  253. .tbl_num = ARRAY_SIZE(msm8996_init_tbl),
  254. .regs = msm8996_regs_layout,
  255. .has_pll_test = true,
  256. .se_clk_scheme_default = true,
  257. .disable_ctrl = (CLAMP_N_EN | FREEZIO_N | POWER_DOWN),
  258. .mask_core_ready = PLL_LOCKED,
  259. .autoresume_en = BIT(3),
  260. };
  261. static const struct qusb2_phy_cfg msm8998_phy_cfg = {
  262. .tbl = msm8998_init_tbl,
  263. .tbl_num = ARRAY_SIZE(msm8998_init_tbl),
  264. .regs = msm8998_regs_layout,
  265. .disable_ctrl = POWER_DOWN,
  266. .mask_core_ready = CORE_READY_STATUS,
  267. .has_pll_override = true,
  268. .se_clk_scheme_default = true,
  269. .autoresume_en = BIT(0),
  270. .update_tune1_with_efuse = true,
  271. };
  272. static const struct qusb2_phy_cfg ipq6018_phy_cfg = {
  273. .tbl = ipq6018_init_tbl,
  274. .tbl_num = ARRAY_SIZE(ipq6018_init_tbl),
  275. .regs = ipq6018_regs_layout,
  276. .disable_ctrl = POWER_DOWN,
  277. .mask_core_ready = PLL_LOCKED,
  278. /* autoresume not used */
  279. .autoresume_en = BIT(0),
  280. };
  281. static const struct qusb2_phy_cfg qusb2_v2_phy_cfg = {
  282. .tbl = qusb2_v2_init_tbl,
  283. .tbl_num = ARRAY_SIZE(qusb2_v2_init_tbl),
  284. .regs = qusb2_v2_regs_layout,
  285. .disable_ctrl = (PWR_CTRL1_VREF_SUPPLY_TRIM | PWR_CTRL1_CLAMP_N_EN |
  286. POWER_DOWN),
  287. .mask_core_ready = CORE_READY_STATUS,
  288. .has_pll_override = true,
  289. .se_clk_scheme_default = true,
  290. .autoresume_en = BIT(0),
  291. .update_tune1_with_efuse = true,
  292. };
  293. static const struct qusb2_phy_cfg sdm660_phy_cfg = {
  294. .tbl = msm8996_init_tbl,
  295. .tbl_num = ARRAY_SIZE(msm8996_init_tbl),
  296. .regs = msm8996_regs_layout,
  297. .has_pll_test = true,
  298. .se_clk_scheme_default = false,
  299. .disable_ctrl = (CLAMP_N_EN | FREEZIO_N | POWER_DOWN),
  300. .mask_core_ready = PLL_LOCKED,
  301. .autoresume_en = BIT(3),
  302. };
  303. static const struct qusb2_phy_cfg sm6115_phy_cfg = {
  304. .tbl = sm6115_init_tbl,
  305. .tbl_num = ARRAY_SIZE(sm6115_init_tbl),
  306. .regs = msm8996_regs_layout,
  307. .has_pll_test = true,
  308. .se_clk_scheme_default = true,
  309. .disable_ctrl = (CLAMP_N_EN | FREEZIO_N | POWER_DOWN),
  310. .mask_core_ready = PLL_LOCKED,
  311. .autoresume_en = BIT(3),
  312. };
  313. static const char * const qusb2_phy_vreg_names[] = {
  314. "vdd", "vdda-pll", "vdda-phy-dpdm",
  315. };
  316. #define QUSB2_NUM_VREGS ARRAY_SIZE(qusb2_phy_vreg_names)
  317. /* struct override_param - structure holding qusb2 v2 phy overriding param
  318. * set override true if the device tree property exists and read and assign
  319. * to value
  320. */
  321. struct override_param {
  322. bool override;
  323. u8 value;
  324. };
  325. /*struct override_params - structure holding qusb2 v2 phy overriding params
  326. * @imp_res_offset: rescode offset to be updated in IMP_CTRL1 register
  327. * @hstx_trim: HSTX_TRIM to be updated in TUNE1 register
  328. * @preemphasis: Amplitude Pre-Emphasis to be updated in TUNE1 register
  329. * @preemphasis_width: half/full-width Pre-Emphasis updated via TUNE1
  330. * @bias_ctrl: bias ctrl to be updated in BIAS_CONTROL_2 register
  331. * @charge_ctrl: charge ctrl to be updated in CHG_CTRL2 register
  332. * @hsdisc_trim: disconnect threshold to be updated in TUNE2 register
  333. */
  334. struct override_params {
  335. struct override_param imp_res_offset;
  336. struct override_param hstx_trim;
  337. struct override_param preemphasis;
  338. struct override_param preemphasis_width;
  339. struct override_param bias_ctrl;
  340. struct override_param charge_ctrl;
  341. struct override_param hsdisc_trim;
  342. };
  343. /**
  344. * struct qusb2_phy - structure holding qusb2 phy attributes
  345. *
  346. * @phy: generic phy
  347. * @base: iomapped memory space for qubs2 phy
  348. *
  349. * @cfg_ahb_clk: AHB2PHY interface clock
  350. * @ref_clk: phy reference clock
  351. * @iface_clk: phy interface clock
  352. * @phy_reset: phy reset control
  353. * @vregs: regulator supplies bulk data
  354. *
  355. * @tcsr: TCSR syscon register map
  356. * @cell: nvmem cell containing phy tuning value
  357. *
  358. * @overrides: pointer to structure for all overriding tuning params
  359. *
  360. * @cfg: phy config data
  361. * @has_se_clk_scheme: indicate if PHY has single-ended ref clock scheme
  362. * @phy_initialized: indicate if PHY has been initialized
  363. * @mode: current PHY mode
  364. */
  365. struct qusb2_phy {
  366. struct phy *phy;
  367. void __iomem *base;
  368. struct clk *cfg_ahb_clk;
  369. struct clk *ref_clk;
  370. struct clk *iface_clk;
  371. struct reset_control *phy_reset;
  372. struct regulator_bulk_data vregs[QUSB2_NUM_VREGS];
  373. struct regmap *tcsr;
  374. struct nvmem_cell *cell;
  375. struct override_params overrides;
  376. const struct qusb2_phy_cfg *cfg;
  377. bool has_se_clk_scheme;
  378. bool phy_initialized;
  379. enum phy_mode mode;
  380. };
  381. static inline void qusb2_write_mask(void __iomem *base, u32 offset,
  382. u32 val, u32 mask)
  383. {
  384. u32 reg;
  385. reg = readl(base + offset);
  386. reg &= ~mask;
  387. reg |= val & mask;
  388. writel(reg, base + offset);
  389. /* Ensure above write is completed */
  390. readl(base + offset);
  391. }
  392. static inline void qusb2_setbits(void __iomem *base, u32 offset, u32 val)
  393. {
  394. u32 reg;
  395. reg = readl(base + offset);
  396. reg |= val;
  397. writel(reg, base + offset);
  398. /* Ensure above write is completed */
  399. readl(base + offset);
  400. }
  401. static inline void qusb2_clrbits(void __iomem *base, u32 offset, u32 val)
  402. {
  403. u32 reg;
  404. reg = readl(base + offset);
  405. reg &= ~val;
  406. writel(reg, base + offset);
  407. /* Ensure above write is completed */
  408. readl(base + offset);
  409. }
  410. static inline
  411. void qcom_qusb2_phy_configure(void __iomem *base,
  412. const unsigned int *regs,
  413. const struct qusb2_phy_init_tbl tbl[], int num)
  414. {
  415. int i;
  416. for (i = 0; i < num; i++) {
  417. if (tbl[i].in_layout)
  418. writel(tbl[i].val, base + regs[tbl[i].offset]);
  419. else
  420. writel(tbl[i].val, base + tbl[i].offset);
  421. }
  422. }
  423. /*
  424. * Update board specific PHY tuning override values if specified from
  425. * device tree.
  426. */
  427. static void qusb2_phy_override_phy_params(struct qusb2_phy *qphy)
  428. {
  429. const struct qusb2_phy_cfg *cfg = qphy->cfg;
  430. struct override_params *or = &qphy->overrides;
  431. if (or->imp_res_offset.override)
  432. qusb2_write_mask(qphy->base, QUSB2PHY_IMP_CTRL1,
  433. or->imp_res_offset.value << IMP_RES_OFFSET_SHIFT,
  434. IMP_RES_OFFSET_MASK);
  435. if (or->bias_ctrl.override)
  436. qusb2_write_mask(qphy->base, QUSB2PHY_PLL_BIAS_CONTROL_2,
  437. or->bias_ctrl.value << BIAS_CTRL2_RES_OFFSET_SHIFT,
  438. BIAS_CTRL2_RES_OFFSET_MASK);
  439. if (or->charge_ctrl.override)
  440. qusb2_write_mask(qphy->base, QUSB2PHY_CHG_CTRL2,
  441. or->charge_ctrl.value << CHG_CTRL2_OFFSET_SHIFT,
  442. CHG_CTRL2_OFFSET_MASK);
  443. if (or->hstx_trim.override)
  444. qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE1],
  445. or->hstx_trim.value << HSTX_TRIM_SHIFT,
  446. HSTX_TRIM_MASK);
  447. if (or->preemphasis.override)
  448. qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE1],
  449. or->preemphasis.value << PREEMPHASIS_EN_SHIFT,
  450. PREEMPHASIS_EN_MASK);
  451. if (or->preemphasis_width.override) {
  452. if (or->preemphasis_width.value ==
  453. QUSB2_V2_PREEMPHASIS_WIDTH_HALF_BIT)
  454. qusb2_setbits(qphy->base,
  455. cfg->regs[QUSB2PHY_PORT_TUNE1],
  456. PREEMPH_WIDTH_HALF_BIT);
  457. else
  458. qusb2_clrbits(qphy->base,
  459. cfg->regs[QUSB2PHY_PORT_TUNE1],
  460. PREEMPH_WIDTH_HALF_BIT);
  461. }
  462. if (or->hsdisc_trim.override)
  463. qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE2],
  464. or->hsdisc_trim.value << HSDISC_TRIM_SHIFT,
  465. HSDISC_TRIM_MASK);
  466. }
  467. /*
  468. * Fetches HS Tx tuning value from nvmem and sets the
  469. * QUSB2PHY_PORT_TUNE1/2 register.
  470. * For error case, skip setting the value and use the default value.
  471. */
  472. static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
  473. {
  474. struct device *dev = &qphy->phy->dev;
  475. const struct qusb2_phy_cfg *cfg = qphy->cfg;
  476. u8 *val, hstx_trim;
  477. /* efuse register is optional */
  478. if (!qphy->cell)
  479. return;
  480. /*
  481. * Read efuse register having TUNE2/1 parameter's high nibble.
  482. * If efuse register shows value as 0x0 (indicating value is not
  483. * fused), or if we fail to find a valid efuse register setting,
  484. * then use default value for high nibble that we have already
  485. * set while configuring the phy.
  486. */
  487. val = nvmem_cell_read(qphy->cell, NULL);
  488. if (IS_ERR(val)) {
  489. dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
  490. return;
  491. }
  492. hstx_trim = val[0];
  493. kfree(val);
  494. if (!hstx_trim) {
  495. dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
  496. return;
  497. }
  498. /* Fused TUNE1/2 value is the higher nibble only */
  499. if (cfg->update_tune1_with_efuse)
  500. qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE1],
  501. hstx_trim << HSTX_TRIM_SHIFT, HSTX_TRIM_MASK);
  502. else
  503. qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE2],
  504. hstx_trim << HSTX_TRIM_SHIFT, HSTX_TRIM_MASK);
  505. }
  506. static int qusb2_phy_set_mode(struct phy *phy,
  507. enum phy_mode mode, int submode)
  508. {
  509. struct qusb2_phy *qphy = phy_get_drvdata(phy);
  510. qphy->mode = mode;
  511. return 0;
  512. }
  513. static int __maybe_unused qusb2_phy_runtime_suspend(struct device *dev)
  514. {
  515. struct qusb2_phy *qphy = dev_get_drvdata(dev);
  516. const struct qusb2_phy_cfg *cfg = qphy->cfg;
  517. u32 intr_mask;
  518. dev_vdbg(dev, "Suspending QUSB2 Phy, mode:%d\n", qphy->mode);
  519. if (!qphy->phy_initialized) {
  520. dev_vdbg(dev, "PHY not initialized, bailing out\n");
  521. return 0;
  522. }
  523. /*
  524. * Enable DP/DM interrupts to detect line state changes based on current
  525. * speed. In other words, enable the triggers _opposite_ of what the
  526. * current D+/D- levels are e.g. if currently D+ high, D- low
  527. * (HS 'J'/Suspend), configure the mask to trigger on D+ low OR D- high
  528. */
  529. intr_mask = DPSE_INTR_EN | DMSE_INTR_EN;
  530. switch (qphy->mode) {
  531. case PHY_MODE_USB_HOST_HS:
  532. case PHY_MODE_USB_HOST_FS:
  533. case PHY_MODE_USB_DEVICE_HS:
  534. case PHY_MODE_USB_DEVICE_FS:
  535. intr_mask |= DMSE_INTR_HIGH_SEL;
  536. break;
  537. case PHY_MODE_USB_HOST_LS:
  538. case PHY_MODE_USB_DEVICE_LS:
  539. intr_mask |= DPSE_INTR_HIGH_SEL;
  540. break;
  541. default:
  542. /* No device connected, enable both DP/DM high interrupt */
  543. intr_mask |= DMSE_INTR_HIGH_SEL;
  544. intr_mask |= DPSE_INTR_HIGH_SEL;
  545. break;
  546. }
  547. writel(intr_mask, qphy->base + cfg->regs[QUSB2PHY_INTR_CTRL]);
  548. /* hold core PLL into reset */
  549. if (cfg->has_pll_override) {
  550. qusb2_setbits(qphy->base,
  551. cfg->regs[QUSB2PHY_PLL_CORE_INPUT_OVERRIDE],
  552. CORE_PLL_EN_FROM_RESET | CORE_RESET |
  553. CORE_RESET_MUX);
  554. }
  555. /* enable phy auto-resume only if device is connected on bus */
  556. if (qphy->mode != PHY_MODE_INVALID) {
  557. qusb2_setbits(qphy->base, cfg->regs[QUSB2PHY_PORT_TEST1],
  558. cfg->autoresume_en);
  559. /* Autoresume bit has to be toggled in order to enable it */
  560. qusb2_clrbits(qphy->base, cfg->regs[QUSB2PHY_PORT_TEST1],
  561. cfg->autoresume_en);
  562. }
  563. if (!qphy->has_se_clk_scheme)
  564. clk_disable_unprepare(qphy->ref_clk);
  565. clk_disable_unprepare(qphy->cfg_ahb_clk);
  566. clk_disable_unprepare(qphy->iface_clk);
  567. return 0;
  568. }
  569. static int __maybe_unused qusb2_phy_runtime_resume(struct device *dev)
  570. {
  571. struct qusb2_phy *qphy = dev_get_drvdata(dev);
  572. const struct qusb2_phy_cfg *cfg = qphy->cfg;
  573. int ret;
  574. dev_vdbg(dev, "Resuming QUSB2 phy, mode:%d\n", qphy->mode);
  575. if (!qphy->phy_initialized) {
  576. dev_vdbg(dev, "PHY not initialized, bailing out\n");
  577. return 0;
  578. }
  579. ret = clk_prepare_enable(qphy->iface_clk);
  580. if (ret) {
  581. dev_err(dev, "failed to enable iface_clk, %d\n", ret);
  582. return ret;
  583. }
  584. ret = clk_prepare_enable(qphy->cfg_ahb_clk);
  585. if (ret) {
  586. dev_err(dev, "failed to enable cfg ahb clock, %d\n", ret);
  587. goto disable_iface_clk;
  588. }
  589. if (!qphy->has_se_clk_scheme) {
  590. ret = clk_prepare_enable(qphy->ref_clk);
  591. if (ret) {
  592. dev_err(dev, "failed to enable ref clk, %d\n", ret);
  593. goto disable_ahb_clk;
  594. }
  595. }
  596. writel(0x0, qphy->base + cfg->regs[QUSB2PHY_INTR_CTRL]);
  597. /* bring core PLL out of reset */
  598. if (cfg->has_pll_override) {
  599. qusb2_clrbits(qphy->base,
  600. cfg->regs[QUSB2PHY_PLL_CORE_INPUT_OVERRIDE],
  601. CORE_RESET | CORE_RESET_MUX);
  602. }
  603. return 0;
  604. disable_ahb_clk:
  605. clk_disable_unprepare(qphy->cfg_ahb_clk);
  606. disable_iface_clk:
  607. clk_disable_unprepare(qphy->iface_clk);
  608. return ret;
  609. }
  610. static int qusb2_phy_init(struct phy *phy)
  611. {
  612. struct qusb2_phy *qphy = phy_get_drvdata(phy);
  613. const struct qusb2_phy_cfg *cfg = qphy->cfg;
  614. unsigned int val = 0;
  615. unsigned int clk_scheme;
  616. int ret;
  617. dev_vdbg(&phy->dev, "%s(): Initializing QUSB2 phy\n", __func__);
  618. /* turn on regulator supplies */
  619. ret = regulator_bulk_enable(ARRAY_SIZE(qphy->vregs), qphy->vregs);
  620. if (ret)
  621. return ret;
  622. ret = clk_prepare_enable(qphy->iface_clk);
  623. if (ret) {
  624. dev_err(&phy->dev, "failed to enable iface_clk, %d\n", ret);
  625. goto poweroff_phy;
  626. }
  627. /* enable ahb interface clock to program phy */
  628. ret = clk_prepare_enable(qphy->cfg_ahb_clk);
  629. if (ret) {
  630. dev_err(&phy->dev, "failed to enable cfg ahb clock, %d\n", ret);
  631. goto disable_iface_clk;
  632. }
  633. /* Perform phy reset */
  634. ret = reset_control_assert(qphy->phy_reset);
  635. if (ret) {
  636. dev_err(&phy->dev, "failed to assert phy_reset, %d\n", ret);
  637. goto disable_ahb_clk;
  638. }
  639. /* 100 us delay to keep PHY in reset mode */
  640. usleep_range(100, 150);
  641. ret = reset_control_deassert(qphy->phy_reset);
  642. if (ret) {
  643. dev_err(&phy->dev, "failed to de-assert phy_reset, %d\n", ret);
  644. goto disable_ahb_clk;
  645. }
  646. /* Disable the PHY */
  647. qusb2_setbits(qphy->base, cfg->regs[QUSB2PHY_PORT_POWERDOWN],
  648. qphy->cfg->disable_ctrl);
  649. if (cfg->has_pll_test) {
  650. /* save reset value to override reference clock scheme later */
  651. val = readl(qphy->base + QUSB2PHY_PLL_TEST);
  652. }
  653. qcom_qusb2_phy_configure(qphy->base, cfg->regs, cfg->tbl,
  654. cfg->tbl_num);
  655. /* Override board specific PHY tuning values */
  656. qusb2_phy_override_phy_params(qphy);
  657. /* Set efuse value for tuning the PHY */
  658. qusb2_phy_set_tune2_param(qphy);
  659. /* Enable the PHY */
  660. qusb2_clrbits(qphy->base, cfg->regs[QUSB2PHY_PORT_POWERDOWN],
  661. POWER_DOWN);
  662. /* Required to get phy pll lock successfully */
  663. usleep_range(150, 160);
  664. /*
  665. * Not all the SoCs have got a readable TCSR_PHY_CLK_SCHEME
  666. * register in the TCSR so, if there's none, use the default
  667. * value hardcoded in the configuration.
  668. */
  669. qphy->has_se_clk_scheme = cfg->se_clk_scheme_default;
  670. /*
  671. * read TCSR_PHY_CLK_SCHEME register to check if single-ended
  672. * clock scheme is selected. If yes, then disable differential
  673. * ref_clk and use single-ended clock, otherwise use differential
  674. * ref_clk only.
  675. */
  676. if (qphy->tcsr) {
  677. ret = regmap_read(qphy->tcsr, qphy->cfg->clk_scheme_offset,
  678. &clk_scheme);
  679. if (ret) {
  680. dev_err(&phy->dev, "failed to read clk scheme reg\n");
  681. goto assert_phy_reset;
  682. }
  683. /* is it a differential clock scheme ? */
  684. if (!(clk_scheme & PHY_CLK_SCHEME_SEL)) {
  685. dev_vdbg(&phy->dev, "%s(): select differential clk\n",
  686. __func__);
  687. qphy->has_se_clk_scheme = false;
  688. } else {
  689. dev_vdbg(&phy->dev, "%s(): select single-ended clk\n",
  690. __func__);
  691. }
  692. }
  693. if (!qphy->has_se_clk_scheme) {
  694. ret = clk_prepare_enable(qphy->ref_clk);
  695. if (ret) {
  696. dev_err(&phy->dev, "failed to enable ref clk, %d\n",
  697. ret);
  698. goto assert_phy_reset;
  699. }
  700. }
  701. if (cfg->has_pll_test) {
  702. if (!qphy->has_se_clk_scheme)
  703. val &= ~CLK_REF_SEL;
  704. else
  705. val |= CLK_REF_SEL;
  706. writel(val, qphy->base + QUSB2PHY_PLL_TEST);
  707. /* ensure above write is through */
  708. readl(qphy->base + QUSB2PHY_PLL_TEST);
  709. }
  710. /* Required to get phy pll lock successfully */
  711. usleep_range(100, 110);
  712. val = readb(qphy->base + cfg->regs[QUSB2PHY_PLL_STATUS]);
  713. if (!(val & cfg->mask_core_ready)) {
  714. dev_err(&phy->dev,
  715. "QUSB2PHY pll lock failed: status reg = %x\n", val);
  716. ret = -EBUSY;
  717. goto disable_ref_clk;
  718. }
  719. qphy->phy_initialized = true;
  720. return 0;
  721. disable_ref_clk:
  722. if (!qphy->has_se_clk_scheme)
  723. clk_disable_unprepare(qphy->ref_clk);
  724. assert_phy_reset:
  725. reset_control_assert(qphy->phy_reset);
  726. disable_ahb_clk:
  727. clk_disable_unprepare(qphy->cfg_ahb_clk);
  728. disable_iface_clk:
  729. clk_disable_unprepare(qphy->iface_clk);
  730. poweroff_phy:
  731. regulator_bulk_disable(ARRAY_SIZE(qphy->vregs), qphy->vregs);
  732. return ret;
  733. }
  734. static int qusb2_phy_exit(struct phy *phy)
  735. {
  736. struct qusb2_phy *qphy = phy_get_drvdata(phy);
  737. /* Disable the PHY */
  738. qusb2_setbits(qphy->base, qphy->cfg->regs[QUSB2PHY_PORT_POWERDOWN],
  739. qphy->cfg->disable_ctrl);
  740. if (!qphy->has_se_clk_scheme)
  741. clk_disable_unprepare(qphy->ref_clk);
  742. reset_control_assert(qphy->phy_reset);
  743. clk_disable_unprepare(qphy->cfg_ahb_clk);
  744. clk_disable_unprepare(qphy->iface_clk);
  745. regulator_bulk_disable(ARRAY_SIZE(qphy->vregs), qphy->vregs);
  746. qphy->phy_initialized = false;
  747. return 0;
  748. }
  749. static const struct phy_ops qusb2_phy_gen_ops = {
  750. .init = qusb2_phy_init,
  751. .exit = qusb2_phy_exit,
  752. .set_mode = qusb2_phy_set_mode,
  753. .owner = THIS_MODULE,
  754. };
  755. static const struct of_device_id qusb2_phy_of_match_table[] = {
  756. {
  757. .compatible = "qcom,ipq6018-qusb2-phy",
  758. .data = &ipq6018_phy_cfg,
  759. }, {
  760. .compatible = "qcom,ipq8074-qusb2-phy",
  761. .data = &msm8996_phy_cfg,
  762. }, {
  763. .compatible = "qcom,msm8953-qusb2-phy",
  764. .data = &msm8996_phy_cfg,
  765. }, {
  766. .compatible = "qcom,msm8996-qusb2-phy",
  767. .data = &msm8996_phy_cfg,
  768. }, {
  769. .compatible = "qcom,msm8998-qusb2-phy",
  770. .data = &msm8998_phy_cfg,
  771. }, {
  772. .compatible = "qcom,qcm2290-qusb2-phy",
  773. .data = &sm6115_phy_cfg,
  774. }, {
  775. .compatible = "qcom,sdm660-qusb2-phy",
  776. .data = &sdm660_phy_cfg,
  777. }, {
  778. .compatible = "qcom,sm4250-qusb2-phy",
  779. .data = &sm6115_phy_cfg,
  780. }, {
  781. .compatible = "qcom,sm6115-qusb2-phy",
  782. .data = &sm6115_phy_cfg,
  783. }, {
  784. /*
  785. * Deprecated. Only here to support legacy device
  786. * trees that didn't include "qcom,qusb2-v2-phy"
  787. */
  788. .compatible = "qcom,sdm845-qusb2-phy",
  789. .data = &qusb2_v2_phy_cfg,
  790. }, {
  791. .compatible = "qcom,qusb2-v2-phy",
  792. .data = &qusb2_v2_phy_cfg,
  793. },
  794. { },
  795. };
  796. MODULE_DEVICE_TABLE(of, qusb2_phy_of_match_table);
  797. static const struct dev_pm_ops qusb2_phy_pm_ops = {
  798. SET_RUNTIME_PM_OPS(qusb2_phy_runtime_suspend,
  799. qusb2_phy_runtime_resume, NULL)
  800. };
  801. static int qusb2_phy_probe(struct platform_device *pdev)
  802. {
  803. struct device *dev = &pdev->dev;
  804. struct qusb2_phy *qphy;
  805. struct phy_provider *phy_provider;
  806. struct phy *generic_phy;
  807. int ret, i;
  808. int num;
  809. u32 value;
  810. struct override_params *or;
  811. qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL);
  812. if (!qphy)
  813. return -ENOMEM;
  814. or = &qphy->overrides;
  815. qphy->base = devm_platform_ioremap_resource(pdev, 0);
  816. if (IS_ERR(qphy->base))
  817. return PTR_ERR(qphy->base);
  818. qphy->cfg_ahb_clk = devm_clk_get(dev, "cfg_ahb");
  819. if (IS_ERR(qphy->cfg_ahb_clk))
  820. return dev_err_probe(dev, PTR_ERR(qphy->cfg_ahb_clk),
  821. "failed to get cfg ahb clk\n");
  822. qphy->ref_clk = devm_clk_get(dev, "ref");
  823. if (IS_ERR(qphy->ref_clk))
  824. return dev_err_probe(dev, PTR_ERR(qphy->ref_clk),
  825. "failed to get ref clk\n");
  826. qphy->iface_clk = devm_clk_get_optional(dev, "iface");
  827. if (IS_ERR(qphy->iface_clk))
  828. return PTR_ERR(qphy->iface_clk);
  829. qphy->phy_reset = devm_reset_control_get_by_index(&pdev->dev, 0);
  830. if (IS_ERR(qphy->phy_reset)) {
  831. dev_err(dev, "failed to get phy core reset\n");
  832. return PTR_ERR(qphy->phy_reset);
  833. }
  834. num = ARRAY_SIZE(qphy->vregs);
  835. for (i = 0; i < num; i++)
  836. qphy->vregs[i].supply = qusb2_phy_vreg_names[i];
  837. ret = devm_regulator_bulk_get(dev, num, qphy->vregs);
  838. if (ret)
  839. return dev_err_probe(dev, ret,
  840. "failed to get regulator supplies\n");
  841. /* Get the specific init parameters of QMP phy */
  842. qphy->cfg = of_device_get_match_data(dev);
  843. qphy->tcsr = syscon_regmap_lookup_by_phandle(dev->of_node,
  844. "qcom,tcsr-syscon");
  845. if (IS_ERR(qphy->tcsr)) {
  846. dev_dbg(dev, "failed to lookup TCSR regmap\n");
  847. qphy->tcsr = NULL;
  848. }
  849. qphy->cell = devm_nvmem_cell_get(dev, NULL);
  850. if (IS_ERR(qphy->cell)) {
  851. if (PTR_ERR(qphy->cell) == -EPROBE_DEFER)
  852. return -EPROBE_DEFER;
  853. qphy->cell = NULL;
  854. dev_dbg(dev, "failed to lookup tune2 hstx trim value\n");
  855. }
  856. if (!of_property_read_u32(dev->of_node, "qcom,imp-res-offset-value",
  857. &value)) {
  858. or->imp_res_offset.value = (u8)value;
  859. or->imp_res_offset.override = true;
  860. }
  861. if (!of_property_read_u32(dev->of_node, "qcom,bias-ctrl-value",
  862. &value)) {
  863. or->bias_ctrl.value = (u8)value;
  864. or->bias_ctrl.override = true;
  865. }
  866. if (!of_property_read_u32(dev->of_node, "qcom,charge-ctrl-value",
  867. &value)) {
  868. or->charge_ctrl.value = (u8)value;
  869. or->charge_ctrl.override = true;
  870. }
  871. if (!of_property_read_u32(dev->of_node, "qcom,hstx-trim-value",
  872. &value)) {
  873. or->hstx_trim.value = (u8)value;
  874. or->hstx_trim.override = true;
  875. }
  876. if (!of_property_read_u32(dev->of_node, "qcom,preemphasis-level",
  877. &value)) {
  878. or->preemphasis.value = (u8)value;
  879. or->preemphasis.override = true;
  880. }
  881. if (!of_property_read_u32(dev->of_node, "qcom,preemphasis-width",
  882. &value)) {
  883. or->preemphasis_width.value = (u8)value;
  884. or->preemphasis_width.override = true;
  885. }
  886. if (!of_property_read_u32(dev->of_node, "qcom,hsdisc-trim-value",
  887. &value)) {
  888. or->hsdisc_trim.value = (u8)value;
  889. or->hsdisc_trim.override = true;
  890. }
  891. pm_runtime_set_active(dev);
  892. pm_runtime_enable(dev);
  893. /*
  894. * Prevent runtime pm from being ON by default. Users can enable
  895. * it using power/control in sysfs.
  896. */
  897. pm_runtime_forbid(dev);
  898. generic_phy = devm_phy_create(dev, NULL, &qusb2_phy_gen_ops);
  899. if (IS_ERR(generic_phy)) {
  900. ret = PTR_ERR(generic_phy);
  901. dev_err(dev, "failed to create phy, %d\n", ret);
  902. pm_runtime_disable(dev);
  903. return ret;
  904. }
  905. qphy->phy = generic_phy;
  906. dev_set_drvdata(dev, qphy);
  907. phy_set_drvdata(generic_phy, qphy);
  908. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  909. if (!IS_ERR(phy_provider))
  910. dev_info(dev, "Registered Qcom-QUSB2 phy\n");
  911. else
  912. pm_runtime_disable(dev);
  913. return PTR_ERR_OR_ZERO(phy_provider);
  914. }
  915. static struct platform_driver qusb2_phy_driver = {
  916. .probe = qusb2_phy_probe,
  917. .driver = {
  918. .name = "qcom-qusb2-phy",
  919. .pm = &qusb2_phy_pm_ops,
  920. .of_match_table = qusb2_phy_of_match_table,
  921. },
  922. };
  923. module_platform_driver(qusb2_phy_driver);
  924. MODULE_AUTHOR("Vivek Gautam <[email protected]>");
  925. MODULE_DESCRIPTION("Qualcomm QUSB2 PHY driver");
  926. MODULE_LICENSE("GPL v2");