phy-qcom-qusb2.c 30 KB

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