hdmi_pll_20nm.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/err.h>
  7. #include <linux/delay.h>
  8. #include <linux/iopoll.h>
  9. #include <linux/clk/msm-clk-provider.h>
  10. #include <linux/clk/msm-clk.h>
  11. #include <linux/clk/msm-clock-generic.h>
  12. #include <dt-bindings/clock/msm-clocks-8994.h>
  13. #include "pll_drv.h"
  14. #include "hdmi_pll.h"
  15. /* hdmi phy registers */
  16. #define HDMI_PHY_CMD_SIZE 68
  17. #define HDMI_PHY_CLK_SIZE 97
  18. /* Set to 1 for auto KVCO cal; set to 0 for fixed value */
  19. #define HDMI_PHY_AUTO_KVCO_CAL 1
  20. /* PLL REGISTERS */
  21. #define QSERDES_COM_SYS_CLK_CTRL (0x000)
  22. #define QSERDES_COM_PLL_VCOTAIL_EN (0x004)
  23. #define QSERDES_COM_CMN_MODE (0x008)
  24. #define QSERDES_COM_IE_TRIM (0x00C)
  25. #define QSERDES_COM_IP_TRIM (0x010)
  26. #define QSERDES_COM_PLL_CNTRL (0x014)
  27. #define QSERDES_COM_PLL_PHSEL_CONTROL (0x018)
  28. #define QSERDES_COM_IPTAT_TRIM_VCCA_TX_SEL (0x01C)
  29. #define QSERDES_COM_PLL_PHSEL_DC (0x020)
  30. #define QSERDES_COM_PLL_IP_SETI (0x024)
  31. #define QSERDES_COM_CORE_CLK_IN_SYNC_SEL (0x028)
  32. #define QSERDES_COM_PLL_BKG_KVCO_CAL_EN (0x02C)
  33. #define QSERDES_COM_BIAS_EN_CLKBUFLR_EN (0x030)
  34. #define QSERDES_COM_PLL_CP_SETI (0x034)
  35. #define QSERDES_COM_PLL_IP_SETP (0x038)
  36. #define QSERDES_COM_PLL_CP_SETP (0x03C)
  37. #define QSERDES_COM_ATB_SEL1 (0x040)
  38. #define QSERDES_COM_ATB_SEL2 (0x044)
  39. #define QSERDES_COM_SYSCLK_EN_SEL_TXBAND (0x048)
  40. #define QSERDES_COM_RESETSM_CNTRL (0x04C)
  41. #define QSERDES_COM_RESETSM_CNTRL2 (0x050)
  42. #define QSERDES_COM_RESETSM_CNTRL3 (0x054)
  43. #define QSERDES_COM_RESETSM_PLL_CAL_COUNT1 (0x058)
  44. #define QSERDES_COM_RESETSM_PLL_CAL_COUNT2 (0x05C)
  45. #define QSERDES_COM_DIV_REF1 (0x060)
  46. #define QSERDES_COM_DIV_REF2 (0x064)
  47. #define QSERDES_COM_KVCO_COUNT1 (0x068)
  48. #define QSERDES_COM_KVCO_COUNT2 (0x06C)
  49. #define QSERDES_COM_KVCO_CAL_CNTRL (0x070)
  50. #define QSERDES_COM_KVCO_CODE (0x074)
  51. #define QSERDES_COM_VREF_CFG1 (0x078)
  52. #define QSERDES_COM_VREF_CFG2 (0x07C)
  53. #define QSERDES_COM_VREF_CFG3 (0x080)
  54. #define QSERDES_COM_VREF_CFG4 (0x084)
  55. #define QSERDES_COM_VREF_CFG5 (0x088)
  56. #define QSERDES_COM_VREF_CFG6 (0x08C)
  57. #define QSERDES_COM_PLLLOCK_CMP1 (0x090)
  58. #define QSERDES_COM_PLLLOCK_CMP2 (0x094)
  59. #define QSERDES_COM_PLLLOCK_CMP3 (0x098)
  60. #define QSERDES_COM_PLLLOCK_CMP_EN (0x09C)
  61. #define QSERDES_COM_BGTC (0x0A0)
  62. #define QSERDES_COM_PLL_TEST_UPDN (0x0A4)
  63. #define QSERDES_COM_PLL_VCO_TUNE (0x0A8)
  64. #define QSERDES_COM_DEC_START1 (0x0AC)
  65. #define QSERDES_COM_PLL_AMP_OS (0x0B0)
  66. #define QSERDES_COM_SSC_EN_CENTER (0x0B4)
  67. #define QSERDES_COM_SSC_ADJ_PER1 (0x0B8)
  68. #define QSERDES_COM_SSC_ADJ_PER2 (0x0BC)
  69. #define QSERDES_COM_SSC_PER1 (0x0C0)
  70. #define QSERDES_COM_SSC_PER2 (0x0C4)
  71. #define QSERDES_COM_SSC_STEP_SIZE1 (0x0C8)
  72. #define QSERDES_COM_SSC_STEP_SIZE2 (0x0CC)
  73. #define QSERDES_COM_RES_CODE_UP (0x0D0)
  74. #define QSERDES_COM_RES_CODE_DN (0x0D4)
  75. #define QSERDES_COM_RES_CODE_UP_OFFSET (0x0D8)
  76. #define QSERDES_COM_RES_CODE_DN_OFFSET (0x0DC)
  77. #define QSERDES_COM_RES_CODE_START_SEG1 (0x0E0)
  78. #define QSERDES_COM_RES_CODE_START_SEG2 (0x0E4)
  79. #define QSERDES_COM_RES_CODE_CAL_CSR (0x0E8)
  80. #define QSERDES_COM_RES_CODE (0x0EC)
  81. #define QSERDES_COM_RES_TRIM_CONTROL (0x0F0)
  82. #define QSERDES_COM_RES_TRIM_CONTROL2 (0x0F4)
  83. #define QSERDES_COM_RES_TRIM_EN_VCOCALDONE (0x0F8)
  84. #define QSERDES_COM_FAUX_EN (0x0FC)
  85. #define QSERDES_COM_DIV_FRAC_START1 (0x100)
  86. #define QSERDES_COM_DIV_FRAC_START2 (0x104)
  87. #define QSERDES_COM_DIV_FRAC_START3 (0x108)
  88. #define QSERDES_COM_DEC_START2 (0x10C)
  89. #define QSERDES_COM_PLL_RXTXEPCLK_EN (0x110)
  90. #define QSERDES_COM_PLL_CRCTRL (0x114)
  91. #define QSERDES_COM_PLL_CLKEPDIV (0x118)
  92. #define QSERDES_COM_PLL_FREQUPDATE (0x11C)
  93. #define QSERDES_COM_PLL_BKGCAL_TRIM_UP (0x120)
  94. #define QSERDES_COM_PLL_BKGCAL_TRIM_DN (0x124)
  95. #define QSERDES_COM_PLL_BKGCAL_TRIM_MUX (0x128)
  96. #define QSERDES_COM_PLL_BKGCAL_VREF_CFG (0x12C)
  97. #define QSERDES_COM_PLL_BKGCAL_DIV_REF1 (0x130)
  98. #define QSERDES_COM_PLL_BKGCAL_DIV_REF2 (0x134)
  99. #define QSERDES_COM_MUXADDR (0x138)
  100. #define QSERDES_COM_LOW_POWER_RO_CONTROL (0x13C)
  101. #define QSERDES_COM_POST_DIVIDER_CONTROL (0x140)
  102. #define QSERDES_COM_HR_OCLK2_DIVIDER (0x144)
  103. #define QSERDES_COM_HR_OCLK3_DIVIDER (0x148)
  104. #define QSERDES_COM_PLL_VCO_HIGH (0x14C)
  105. #define QSERDES_COM_RESET_SM (0x150)
  106. #define QSERDES_COM_MUXVAL (0x154)
  107. #define QSERDES_COM_CORE_RES_CODE_DN (0x158)
  108. #define QSERDES_COM_CORE_RES_CODE_UP (0x15C)
  109. #define QSERDES_COM_CORE_VCO_TUNE (0x160)
  110. #define QSERDES_COM_CORE_VCO_TAIL (0x164)
  111. #define QSERDES_COM_CORE_KVCO_CODE (0x168)
  112. /* Tx Channel 0 REGISTERS */
  113. #define QSERDES_TX_L0_BIST_MODE_LANENO (0x00)
  114. #define QSERDES_TX_L0_CLKBUF_ENABLE (0x04)
  115. #define QSERDES_TX_L0_TX_EMP_POST1_LVL (0x08)
  116. #define QSERDES_TX_L0_TX_DRV_LVL (0x0C)
  117. #define QSERDES_TX_L0_RESET_TSYNC_EN (0x10)
  118. #define QSERDES_TX_L0_LPB_EN (0x14)
  119. #define QSERDES_TX_L0_RES_CODE_UP (0x18)
  120. #define QSERDES_TX_L0_RES_CODE_DN (0x1C)
  121. #define QSERDES_TX_L0_PERL_LENGTH1 (0x20)
  122. #define QSERDES_TX_L0_PERL_LENGTH2 (0x24)
  123. #define QSERDES_TX_L0_SERDES_BYP_EN_OUT (0x28)
  124. #define QSERDES_TX_L0_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN (0x2C)
  125. #define QSERDES_TX_L0_PARRATE_REC_DETECT_IDLE_EN (0x30)
  126. #define QSERDES_TX_L0_BIST_PATTERN1 (0x34)
  127. #define QSERDES_TX_L0_BIST_PATTERN2 (0x38)
  128. #define QSERDES_TX_L0_BIST_PATTERN3 (0x3C)
  129. #define QSERDES_TX_L0_BIST_PATTERN4 (0x40)
  130. #define QSERDES_TX_L0_BIST_PATTERN5 (0x44)
  131. #define QSERDES_TX_L0_BIST_PATTERN6 (0x48)
  132. #define QSERDES_TX_L0_BIST_PATTERN7 (0x4C)
  133. #define QSERDES_TX_L0_BIST_PATTERN8 (0x50)
  134. #define QSERDES_TX_L0_LANE_MODE (0x54)
  135. #define QSERDES_TX_L0_IDAC_CAL_LANE_MODE (0x58)
  136. #define QSERDES_TX_L0_IDAC_CAL_LANE_MODE_CONFIGURATION (0x5C)
  137. #define QSERDES_TX_L0_ATB_SEL1 (0x60)
  138. #define QSERDES_TX_L0_ATB_SEL2 (0x64)
  139. #define QSERDES_TX_L0_RCV_DETECT_LVL (0x68)
  140. #define QSERDES_TX_L0_PRBS_SEED1 (0x6C)
  141. #define QSERDES_TX_L0_PRBS_SEED2 (0x70)
  142. #define QSERDES_TX_L0_PRBS_SEED3 (0x74)
  143. #define QSERDES_TX_L0_PRBS_SEED4 (0x78)
  144. #define QSERDES_TX_L0_RESET_GEN (0x7C)
  145. #define QSERDES_TX_L0_TRAN_DRVR_EMP_EN (0x80)
  146. #define QSERDES_TX_L0_TX_INTERFACE_MODE (0x84)
  147. #define QSERDES_TX_L0_PWM_CTRL (0x88)
  148. #define QSERDES_TX_L0_PWM_DATA (0x8C)
  149. #define QSERDES_TX_L0_PWM_ENC_DIV_CTRL (0x90)
  150. #define QSERDES_TX_L0_VMODE_CTRL1 (0x94)
  151. #define QSERDES_TX_L0_VMODE_CTRL2 (0x98)
  152. #define QSERDES_TX_L0_VMODE_CTRL3 (0x9C)
  153. #define QSERDES_TX_L0_VMODE_CTRL4 (0xA0)
  154. #define QSERDES_TX_L0_VMODE_CTRL5 (0xA4)
  155. #define QSERDES_TX_L0_VMODE_CTRL6 (0xA8)
  156. #define QSERDES_TX_L0_VMODE_CTRL7 (0xAC)
  157. #define QSERDES_TX_L0_TX_ALOG_INTF_OBSV_CNTL (0xB0)
  158. #define QSERDES_TX_L0_BIST_STATUS (0xB4)
  159. #define QSERDES_TX_L0_BIST_ERROR_COUNT1 (0xB8)
  160. #define QSERDES_TX_L0_BIST_ERROR_COUNT2 (0xBC)
  161. #define QSERDES_TX_L0_TX_ALOG_INTF_OBSV (0xC0)
  162. #define QSERDES_TX_L0_PWM_DEC_STATUS (0xC4)
  163. /* Tx Channel 1 REGISTERS */
  164. #define QSERDES_TX_L1_BIST_MODE_LANENO (0x00)
  165. #define QSERDES_TX_L1_CLKBUF_ENABLE (0x04)
  166. #define QSERDES_TX_L1_TX_EMP_POST1_LVL (0x08)
  167. #define QSERDES_TX_L1_TX_DRV_LVL (0x0C)
  168. #define QSERDES_TX_L1_RESET_TSYNC_EN (0x10)
  169. #define QSERDES_TX_L1_LPB_EN (0x14)
  170. #define QSERDES_TX_L1_RES_CODE_UP (0x18)
  171. #define QSERDES_TX_L1_RES_CODE_DN (0x1C)
  172. #define QSERDES_TX_L1_PERL_LENGTH1 (0x20)
  173. #define QSERDES_TX_L1_PERL_LENGTH2 (0x24)
  174. #define QSERDES_TX_L1_SERDES_BYP_EN_OUT (0x28)
  175. #define QSERDES_TX_L1_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN (0x2C)
  176. #define QSERDES_TX_L1_PARRATE_REC_DETECT_IDLE_EN (0x30)
  177. #define QSERDES_TX_L1_BIST_PATTERN1 (0x34)
  178. #define QSERDES_TX_L1_BIST_PATTERN2 (0x38)
  179. #define QSERDES_TX_L1_BIST_PATTERN3 (0x3C)
  180. #define QSERDES_TX_L1_BIST_PATTERN4 (0x40)
  181. #define QSERDES_TX_L1_BIST_PATTERN5 (0x44)
  182. #define QSERDES_TX_L1_BIST_PATTERN6 (0x48)
  183. #define QSERDES_TX_L1_BIST_PATTERN7 (0x4C)
  184. #define QSERDES_TX_L1_BIST_PATTERN8 (0x50)
  185. #define QSERDES_TX_L1_LANE_MODE (0x54)
  186. #define QSERDES_TX_L1_IDAC_CAL_LANE_MODE (0x58)
  187. #define QSERDES_TX_L1_IDAC_CAL_LANE_MODE_CONFIGURATION (0x5C)
  188. #define QSERDES_TX_L1_ATB_SEL1 (0x60)
  189. #define QSERDES_TX_L1_ATB_SEL2 (0x64)
  190. #define QSERDES_TX_L1_RCV_DETECT_LVL (0x68)
  191. #define QSERDES_TX_L1_PRBS_SEED1 (0x6C)
  192. #define QSERDES_TX_L1_PRBS_SEED2 (0x70)
  193. #define QSERDES_TX_L1_PRBS_SEED3 (0x74)
  194. #define QSERDES_TX_L1_PRBS_SEED4 (0x78)
  195. #define QSERDES_TX_L1_RESET_GEN (0x7C)
  196. #define QSERDES_TX_L1_TRAN_DRVR_EMP_EN (0x80)
  197. #define QSERDES_TX_L1_TX_INTERFACE_MODE (0x84)
  198. #define QSERDES_TX_L1_PWM_CTRL (0x88)
  199. #define QSERDES_TX_L1_PWM_DATA (0x8C)
  200. #define QSERDES_TX_L1_PWM_ENC_DIV_CTRL (0x90)
  201. #define QSERDES_TX_L1_VMODE_CTRL1 (0x94)
  202. #define QSERDES_TX_L1_VMODE_CTRL2 (0x98)
  203. #define QSERDES_TX_L1_VMODE_CTRL3 (0x9C)
  204. #define QSERDES_TX_L1_VMODE_CTRL4 (0xA0)
  205. #define QSERDES_TX_L1_VMODE_CTRL5 (0xA4)
  206. #define QSERDES_TX_L1_VMODE_CTRL6 (0xA8)
  207. #define QSERDES_TX_L1_VMODE_CTRL7 (0xAC)
  208. #define QSERDES_TX_L1_TX_ALOG_INTF_OBSV_CNTL (0xB0)
  209. #define QSERDES_TX_L1_BIST_STATUS (0xB4)
  210. #define QSERDES_TX_L1_BIST_ERROR_COUNT1 (0xB8)
  211. #define QSERDES_TX_L1_BIST_ERROR_COUNT2 (0xBC)
  212. #define QSERDES_TX_L1_TX_ALOG_INTF_OBSV (0xC0)
  213. #define QSERDES_TX_L1_PWM_DEC_STATUS (0xC4)
  214. /* Tx Channel 2 REGISERS */
  215. #define QSERDES_TX_L2_BIST_MODE_LANENO (0x00)
  216. #define QSERDES_TX_L2_CLKBUF_ENABLE (0x04)
  217. #define QSERDES_TX_L2_TX_EMP_POST1_LVL (0x08)
  218. #define QSERDES_TX_L2_TX_DRV_LVL (0x0C)
  219. #define QSERDES_TX_L2_RESET_TSYNC_EN (0x10)
  220. #define QSERDES_TX_L2_LPB_EN (0x14)
  221. #define QSERDES_TX_L2_RES_CODE_UP (0x18)
  222. #define QSERDES_TX_L2_RES_CODE_DN (0x1C)
  223. #define QSERDES_TX_L2_PERL_LENGTH1 (0x20)
  224. #define QSERDES_TX_L2_PERL_LENGTH2 (0x24)
  225. #define QSERDES_TX_L2_SERDES_BYP_EN_OUT (0x28)
  226. #define QSERDES_TX_L2_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN (0x2C)
  227. #define QSERDES_TX_L2_PARRATE_REC_DETECT_IDLE_EN (0x30)
  228. #define QSERDES_TX_L2_BIST_PATTERN1 (0x34)
  229. #define QSERDES_TX_L2_BIST_PATTERN2 (0x38)
  230. #define QSERDES_TX_L2_BIST_PATTERN3 (0x3C)
  231. #define QSERDES_TX_L2_BIST_PATTERN4 (0x40)
  232. #define QSERDES_TX_L2_BIST_PATTERN5 (0x44)
  233. #define QSERDES_TX_L2_BIST_PATTERN6 (0x48)
  234. #define QSERDES_TX_L2_BIST_PATTERN7 (0x4C)
  235. #define QSERDES_TX_L2_BIST_PATTERN8 (0x50)
  236. #define QSERDES_TX_L2_LANE_MODE (0x54)
  237. #define QSERDES_TX_L2_IDAC_CAL_LANE_MODE (0x58)
  238. #define QSERDES_TX_L2_IDAC_CAL_LANE_MODE_CONFIGURATION (0x5C)
  239. #define QSERDES_TX_L2_ATB_SEL1 (0x60)
  240. #define QSERDES_TX_L2_ATB_SEL2 (0x64)
  241. #define QSERDES_TX_L2_RCV_DETECT_LVL (0x68)
  242. #define QSERDES_TX_L2_PRBS_SEED1 (0x6C)
  243. #define QSERDES_TX_L2_PRBS_SEED2 (0x70)
  244. #define QSERDES_TX_L2_PRBS_SEED3 (0x74)
  245. #define QSERDES_TX_L2_PRBS_SEED4 (0x78)
  246. #define QSERDES_TX_L2_RESET_GEN (0x7C)
  247. #define QSERDES_TX_L2_TRAN_DRVR_EMP_EN (0x80)
  248. #define QSERDES_TX_L2_TX_INTERFACE_MODE (0x84)
  249. #define QSERDES_TX_L2_PWM_CTRL (0x88)
  250. #define QSERDES_TX_L2_PWM_DATA (0x8C)
  251. #define QSERDES_TX_L2_PWM_ENC_DIV_CTRL (0x90)
  252. #define QSERDES_TX_L2_VMODE_CTRL1 (0x94)
  253. #define QSERDES_TX_L2_VMODE_CTRL2 (0x98)
  254. #define QSERDES_TX_L2_VMODE_CTRL3 (0x9C)
  255. #define QSERDES_TX_L2_VMODE_CTRL4 (0xA0)
  256. #define QSERDES_TX_L2_VMODE_CTRL5 (0xA4)
  257. #define QSERDES_TX_L2_VMODE_CTRL6 (0xA8)
  258. #define QSERDES_TX_L2_VMODE_CTRL7 (0xAC)
  259. #define QSERDES_TX_L2_TX_ALOG_INTF_OBSV_CNTL (0xB0)
  260. #define QSERDES_TX_L2_BIST_STATUS (0xB4)
  261. #define QSERDES_TX_L2_BIST_ERROR_COUNT1 (0xB8)
  262. #define QSERDES_TX_L2_BIST_ERROR_COUNT2 (0xBC)
  263. #define QSERDES_TX_L2_TX_ALOG_INTF_OBSV (0xC0)
  264. #define QSERDES_TX_L2_PWM_DEC_STATUS (0xC4)
  265. /* Tx Channel 3 REGISERS */
  266. #define QSERDES_TX_L3_BIST_MODE_LANENO (0x00)
  267. #define QSERDES_TX_L3_CLKBUF_ENABLE (0x04)
  268. #define QSERDES_TX_L3_TX_EMP_POST1_LVL (0x08)
  269. #define QSERDES_TX_L3_TX_DRV_LVL (0x0C)
  270. #define QSERDES_TX_L3_RESET_TSYNC_EN (0x10)
  271. #define QSERDES_TX_L3_LPB_EN (0x14)
  272. #define QSERDES_TX_L3_RES_CODE_UP (0x18)
  273. #define QSERDES_TX_L3_RES_CODE_DN (0x1C)
  274. #define QSERDES_TX_L3_PERL_LENGTH1 (0x20)
  275. #define QSERDES_TX_L3_PERL_LENGTH2 (0x24)
  276. #define QSERDES_TX_L3_SERDES_BYP_EN_OUT (0x28)
  277. #define QSERDES_TX_L3_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN (0x2C)
  278. #define QSERDES_TX_L3_PARRATE_REC_DETECT_IDLE_EN (0x30)
  279. #define QSERDES_TX_L3_BIST_PATTERN1 (0x34)
  280. #define QSERDES_TX_L3_BIST_PATTERN2 (0x38)
  281. #define QSERDES_TX_L3_BIST_PATTERN3 (0x3C)
  282. #define QSERDES_TX_L3_BIST_PATTERN4 (0x40)
  283. #define QSERDES_TX_L3_BIST_PATTERN5 (0x44)
  284. #define QSERDES_TX_L3_BIST_PATTERN6 (0x48)
  285. #define QSERDES_TX_L3_BIST_PATTERN7 (0x4C)
  286. #define QSERDES_TX_L3_BIST_PATTERN8 (0x50)
  287. #define QSERDES_TX_L3_LANE_MODE (0x54)
  288. #define QSERDES_TX_L3_IDAC_CAL_LANE_MODE (0x58)
  289. #define QSERDES_TX_L3_IDAC_CAL_LANE_MODE_CONFIGURATION (0x5C)
  290. #define QSERDES_TX_L3_ATB_SEL1 (0x60)
  291. #define QSERDES_TX_L3_ATB_SEL2 (0x64)
  292. #define QSERDES_TX_L3_RCV_DETECT_LVL (0x68)
  293. #define QSERDES_TX_L3_PRBS_SEED1 (0x6C)
  294. #define QSERDES_TX_L3_PRBS_SEED2 (0x70)
  295. #define QSERDES_TX_L3_PRBS_SEED3 (0x74)
  296. #define QSERDES_TX_L3_PRBS_SEED4 (0x78)
  297. #define QSERDES_TX_L3_RESET_GEN (0x7C)
  298. #define QSERDES_TX_L3_TRAN_DRVR_EMP_EN (0x80)
  299. #define QSERDES_TX_L3_TX_INTERFACE_MODE (0x84)
  300. #define QSERDES_TX_L3_PWM_CTRL (0x88)
  301. #define QSERDES_TX_L3_PWM_DATA (0x8C)
  302. #define QSERDES_TX_L3_PWM_ENC_DIV_CTRL (0x90)
  303. #define QSERDES_TX_L3_VMODE_CTRL1 (0x94)
  304. #define QSERDES_TX_L3_VMODE_CTRL2 (0x98)
  305. #define QSERDES_TX_L3_VMODE_CTRL3 (0x9C)
  306. #define QSERDES_TX_L3_VMODE_CTRL4 (0xA0)
  307. #define QSERDES_TX_L3_VMODE_CTRL5 (0xA4)
  308. #define QSERDES_TX_L3_VMODE_CTRL6 (0xA8)
  309. #define QSERDES_TX_L3_VMODE_CTRL7 (0xAC)
  310. #define QSERDES_TX_L3_TX_ALOG_INTF_OBSV_CNTL (0xB0)
  311. #define QSERDES_TX_L3_BIST_STATUS (0xB4)
  312. #define QSERDES_TX_L3_BIST_ERROR_COUNT1 (0xB8)
  313. #define QSERDES_TX_L3_BIST_ERROR_COUNT2 (0xBC)
  314. #define QSERDES_TX_L3_TX_ALOG_INTF_OBSV (0xC0)
  315. #define QSERDES_TX_L3_PWM_DEC_STATUS (0xC4)
  316. /* HDMI PHY REGISTERS */
  317. #define HDMI_PHY_CFG (0x00)
  318. #define HDMI_PHY_PD_CTL (0x04)
  319. #define HDMI_PHY_MODE (0x08)
  320. #define HDMI_PHY_MISR_CLEAR (0x0C)
  321. #define HDMI_PHY_TX0_TX1_BIST_CFG0 (0x10)
  322. #define HDMI_PHY_TX0_TX1_BIST_CFG1 (0x14)
  323. #define HDMI_PHY_TX0_TX1_PRBS_SEED_BYTE0 (0x18)
  324. #define HDMI_PHY_TX0_TX1_PRBS_SEED_BYTE1 (0x1C)
  325. #define HDMI_PHY_TX0_TX1_PRBS_SEED_BYTE2 (0x20)
  326. #define HDMI_PHY_TX0_TX1_PRBS_SEED_BYTE3 (0x24)
  327. #define HDMI_PHY_TX0_TX1_PRBS_POLY_BYTE0 (0x28)
  328. #define HDMI_PHY_TX0_TX1_PRBS_POLY_BYTE1 (0x2C)
  329. #define HDMI_PHY_TX0_TX1_PRBS_POLY_BYTE2 (0x30)
  330. #define HDMI_PHY_TX0_TX1_PRBS_POLY_BYTE3 (0x34)
  331. #define HDMI_PHY_TX2_TX3_BIST_CFG0 (0x38)
  332. #define HDMI_PHY_TX2_TX3_BIST_CFG1 (0x3C)
  333. #define HDMI_PHY_TX2_TX3_PRBS_SEED_BYTE0 (0x40)
  334. #define HDMI_PHY_TX2_TX3_PRBS_SEED_BYTE1 (0x44)
  335. #define HDMI_PHY_TX2_TX3_PRBS_SEED_BYTE2 (0x48)
  336. #define HDMI_PHY_TX2_TX3_PRBS_SEED_BYTE3 (0x4C)
  337. #define HDMI_PHY_TX2_TX3_PRBS_POLY_BYTE0 (0x50)
  338. #define HDMI_PHY_TX2_TX3_PRBS_POLY_BYTE1 (0x54)
  339. #define HDMI_PHY_TX2_TX3_PRBS_POLY_BYTE2 (0x58)
  340. #define HDMI_PHY_TX2_TX3_PRBS_POLY_BYTE3 (0x5C)
  341. #define HDMI_PHY_DEBUG_BUS_SEL (0x60)
  342. #define HDMI_PHY_TXCAL_CFG0 (0x64)
  343. #define HDMI_PHY_TXCAL_CFG1 (0x68)
  344. #define HDMI_PHY_TX0_TX1_BIST_STATUS0 (0x6C)
  345. #define HDMI_PHY_TX0_TX1_BIST_STATUS1 (0x70)
  346. #define HDMI_PHY_TX0_TX1_BIST_STATUS2 (0x74)
  347. #define HDMI_PHY_TX2_TX3_BIST_STATUS0 (0x78)
  348. #define HDMI_PHY_TX2_TX3_BIST_STATUS1 (0x7C)
  349. #define HDMI_PHY_TX2_TX3_BIST_STATUS2 (0x80)
  350. #define HDMI_PHY_PRE_MISR_STATUS0 (0x84)
  351. #define HDMI_PHY_PRE_MISR_STATUS1 (0x88)
  352. #define HDMI_PHY_PRE_MISR_STATUS2 (0x8C)
  353. #define HDMI_PHY_PRE_MISR_STATUS3 (0x90)
  354. #define HDMI_PHY_POST_MISR_STATUS0 (0x94)
  355. #define HDMI_PHY_POST_MISR_STATUS1 (0x98)
  356. #define HDMI_PHY_POST_MISR_STATUS2 (0x9C)
  357. #define HDMI_PHY_POST_MISR_STATUS3 (0xA0)
  358. #define HDMI_PHY_STATUS (0xA4)
  359. #define HDMI_PHY_MISC3_STATUS (0xA8)
  360. #define HDMI_PHY_DEBUG_BUS0 (0xAC)
  361. #define HDMI_PHY_DEBUG_BUS1 (0xB0)
  362. #define HDMI_PHY_DEBUG_BUS2 (0xB4)
  363. #define HDMI_PHY_DEBUG_BUS3 (0xB8)
  364. #define HDMI_PHY_REVISION_ID0 (0xBC)
  365. #define HDMI_PHY_REVISION_ID1 (0xC0)
  366. #define HDMI_PHY_REVISION_ID2 (0xC4)
  367. #define HDMI_PHY_REVISION_ID3 (0xC8)
  368. #define HDMI_PLL_POLL_DELAY_US 50
  369. #define HDMI_PLL_POLL_TIMEOUT_US 125000
  370. #define HDMI_PLL_REF_CLK_RATE 192ULL
  371. #define HDMI_PLL_DIVISOR 10000000000ULL
  372. #define HDMI_PLL_DIVISOR_32 100000U
  373. #define HDMI_PLL_MIN_VCO_CLK 160000000ULL
  374. #define HDMI_PLL_TMDS_MAX 800000000U
  375. static int hdmi_20nm_pll_lock_status(struct mdss_pll_resources *io)
  376. {
  377. u32 status;
  378. int pll_locked = 0;
  379. int phy_ready = 0;
  380. int rc;
  381. rc = mdss_pll_resource_enable(io, true);
  382. if (rc) {
  383. pr_err("pll resource can't be enabled\n");
  384. return rc;
  385. }
  386. /* Poll for C_READY and PHY READY */
  387. pr_debug("%s: Waiting for PHY Ready\n", __func__);
  388. /* poll for PLL ready status */
  389. if (!readl_poll_timeout_atomic(
  390. (io->pll_base + QSERDES_COM_RESET_SM),
  391. status, ((status & BIT(6)) == 1),
  392. HDMI_PLL_POLL_DELAY_US,
  393. HDMI_PLL_POLL_TIMEOUT_US)) {
  394. pr_debug("%s: C READY\n", __func__);
  395. pll_locked = 1;
  396. } else {
  397. pr_debug("%s: C READY TIMEOUT\n", __func__);
  398. pll_locked = 0;
  399. }
  400. /* poll for PHY ready status */
  401. if (pll_locked && !readl_poll_timeout_atomic(
  402. (io->phy_base + HDMI_PHY_STATUS),
  403. status, ((status & BIT(0)) == 1),
  404. HDMI_PLL_POLL_DELAY_US,
  405. HDMI_PLL_POLL_TIMEOUT_US)) {
  406. pr_debug("%s: PHY READY\n", __func__);
  407. phy_ready = 1;
  408. } else {
  409. pr_debug("%s: PHY READY TIMEOUT\n", __func__);
  410. phy_ready = 0;
  411. }
  412. mdss_pll_resource_enable(io, false);
  413. return phy_ready;
  414. }
  415. static inline struct hdmi_pll_vco_clk *to_hdmi_20nm_vco_clk(struct clk *clk)
  416. {
  417. return container_of(clk, struct hdmi_pll_vco_clk, c);
  418. }
  419. static inline u32 hdmi_20nm_phy_pll_vco_reg_val(struct hdmi_pll_cfg *pll_cfg,
  420. u32 tmds_clk)
  421. {
  422. u32 index = 0;
  423. while (pll_cfg[index].vco_rate < HDMI_PLL_TMDS_MAX &&
  424. pll_cfg[index].vco_rate < tmds_clk)
  425. index++;
  426. return pll_cfg[index].reg;
  427. }
  428. static void hdmi_20nm_phy_pll_calc_settings(struct mdss_pll_resources *io,
  429. struct hdmi_pll_vco_clk *vco, u32 vco_clk, u32 tmds_clk)
  430. {
  431. u32 val = 0;
  432. u64 dec_start_val, frac_start_val, pll_lock_cmp;
  433. /* Calculate decimal and fractional values */
  434. dec_start_val = 1000000UL * vco_clk;
  435. do_div(dec_start_val, HDMI_PLL_REF_CLK_RATE);
  436. do_div(dec_start_val, 2U);
  437. frac_start_val = dec_start_val;
  438. do_div(frac_start_val, HDMI_PLL_DIVISOR_32);
  439. do_div(frac_start_val, HDMI_PLL_DIVISOR_32);
  440. frac_start_val *= HDMI_PLL_DIVISOR;
  441. frac_start_val = dec_start_val - frac_start_val;
  442. frac_start_val *= (u64)(2 << 19);
  443. do_div(frac_start_val, HDMI_PLL_DIVISOR_32);
  444. do_div(frac_start_val, HDMI_PLL_DIVISOR_32);
  445. pll_lock_cmp = dec_start_val;
  446. do_div(pll_lock_cmp, 10U);
  447. pll_lock_cmp *= 0x800;
  448. do_div(pll_lock_cmp, HDMI_PLL_DIVISOR_32);
  449. do_div(pll_lock_cmp, HDMI_PLL_DIVISOR_32);
  450. pll_lock_cmp -= 1U;
  451. do_div(dec_start_val, HDMI_PLL_DIVISOR_32);
  452. do_div(dec_start_val, HDMI_PLL_DIVISOR_32);
  453. /* PLL loop bandwidth */
  454. val = hdmi_20nm_phy_pll_vco_reg_val(vco->ip_seti, tmds_clk);
  455. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_IP_SETI, val);
  456. val = hdmi_20nm_phy_pll_vco_reg_val(vco->cp_seti, tmds_clk);
  457. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_CP_SETI, val);
  458. val = hdmi_20nm_phy_pll_vco_reg_val(vco->cp_setp, tmds_clk);
  459. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_CP_SETP, val);
  460. val = hdmi_20nm_phy_pll_vco_reg_val(vco->ip_setp, tmds_clk);
  461. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_IP_SETP, val);
  462. val = hdmi_20nm_phy_pll_vco_reg_val(vco->crctrl, tmds_clk);
  463. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_CRCTRL, val);
  464. /* PLL calibration */
  465. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_DIV_FRAC_START1,
  466. 0x80 | (frac_start_val & 0x7F));
  467. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_DIV_FRAC_START2,
  468. 0x80 | ((frac_start_val >> 7) & 0x7F));
  469. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_DIV_FRAC_START3,
  470. 0x40 | ((frac_start_val >> 14) & 0x3F));
  471. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_DEC_START1,
  472. 0x80 | (dec_start_val & 0x7F));
  473. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_DEC_START2,
  474. 0x02 | (0x01 & (dec_start_val >> 7)));
  475. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLLLOCK_CMP1,
  476. pll_lock_cmp & 0xFF);
  477. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLLLOCK_CMP2,
  478. (pll_lock_cmp >> 8) & 0xFF);
  479. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLLLOCK_CMP3,
  480. (pll_lock_cmp >> 16) & 0xFF);
  481. }
  482. static u32 hdmi_20nm_phy_pll_set_clk_rate(struct clk *c, u32 tmds_clk)
  483. {
  484. u32 tx_band = 0;
  485. struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c);
  486. struct mdss_pll_resources *io = vco->priv;
  487. u64 vco_clk = tmds_clk;
  488. while (vco_clk > 0 && vco_clk < HDMI_PLL_MIN_VCO_CLK) {
  489. tx_band++;
  490. vco_clk *= 2;
  491. }
  492. /* Initially shut down PHY */
  493. pr_debug("%s: Disabling PHY\n", __func__);
  494. MDSS_PLL_REG_W(io->phy_base, HDMI_PHY_PD_CTL, 0x0);
  495. udelay(1000);
  496. /* memory barrier */
  497. mb();
  498. /* power-up and recommended common block settings */
  499. MDSS_PLL_REG_W(io->phy_base, HDMI_PHY_PD_CTL, 0x1F);
  500. MDSS_PLL_REG_W(io->phy_base, HDMI_PHY_CFG, 0x01);
  501. udelay(1000);
  502. /* memory barrier */
  503. mb();
  504. MDSS_PLL_REG_W(io->phy_base, HDMI_PHY_CFG, 0x07);
  505. udelay(1000);
  506. /* memory barrier */
  507. mb();
  508. MDSS_PLL_REG_W(io->phy_base, HDMI_PHY_CFG, 0x05);
  509. udelay(1000);
  510. /* memory barrier */
  511. mb();
  512. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_SYS_CLK_CTRL, 0x42);
  513. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_VCOTAIL_EN, 0x03);
  514. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_CMN_MODE, 0x00);
  515. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_IE_TRIM, 0x00);
  516. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_IP_TRIM, 0x00);
  517. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_CNTRL, 0x07);
  518. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_PHSEL_CONTROL, 0x04);
  519. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_IPTAT_TRIM_VCCA_TX_SEL, 0xA0);
  520. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_PHSEL_DC, 0x00);
  521. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_CORE_CLK_IN_SYNC_SEL, 0x00);
  522. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_BKG_KVCO_CAL_EN, 0x00);
  523. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x0F);
  524. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_ATB_SEL1, 0x01);
  525. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_ATB_SEL2, 0x01);
  526. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_SYSCLK_EN_SEL_TXBAND,
  527. 0x4A + (0x10 * tx_band));
  528. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_VREF_CFG1, 0x00);
  529. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_VREF_CFG2, 0x00);
  530. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_BGTC, 0xFF);
  531. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_TEST_UPDN, 0x00);
  532. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_VCO_TUNE, 0x00);
  533. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_AMP_OS, 0x00);
  534. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_SSC_EN_CENTER, 0x00);
  535. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_RES_CODE_UP, 0x00);
  536. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_RES_CODE_DN, 0x00);
  537. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_KVCO_CODE,
  538. tmds_clk > 300000000 ? 0x3F : 0x00);
  539. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_KVCO_COUNT1,
  540. tmds_clk > 300000000 ? 0x00 : 0x8A);
  541. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_DIV_REF1, 0x00);
  542. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_DIV_REF2,
  543. tmds_clk > 300000000 ? 0x00 : 0x01);
  544. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_KVCO_CAL_CNTRL,
  545. tmds_clk > 300000000 ? 0x00 : 0x1F);
  546. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_VREF_CFG3,
  547. tmds_clk > 300000000 ? 0x00 : 0x40);
  548. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_VREF_CFG4, 0x00);
  549. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_VREF_CFG5, 0x10);
  550. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_RESETSM_CNTRL,
  551. tmds_clk > 300000000 ? 0x80 : 0x00);
  552. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_RES_CODE_CAL_CSR, 0x77);
  553. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_RES_TRIM_EN_VCOCALDONE, 0x00);
  554. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_RXTXEPCLK_EN, 0x0C);
  555. hdmi_20nm_phy_pll_calc_settings(io, vco, vco_clk, tmds_clk);
  556. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLLLOCK_CMP_EN, 0x11);
  557. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_PLL_CNTRL, 0x07);
  558. /* Resistor calibration linear search */
  559. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_RES_CODE_START_SEG1, 0x60);
  560. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_RES_CODE_START_SEG2, 0x60);
  561. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_RES_TRIM_CONTROL, 0x01);
  562. MDSS_PLL_REG_W(io->pll_base, QSERDES_COM_RESETSM_CNTRL2, 0x07);
  563. udelay(1000);
  564. /* memory barrier */
  565. mb();
  566. MDSS_PLL_REG_W(io->phy_base, HDMI_PHY_MODE, tx_band);
  567. /* TX lanes (transceivers) power-up sequence */
  568. MDSS_PLL_REG_W(io->pll_base + 0x400, QSERDES_TX_L0_CLKBUF_ENABLE, 0x03);
  569. MDSS_PLL_REG_W(io->pll_base + 0x600, QSERDES_TX_L1_CLKBUF_ENABLE, 0x03);
  570. MDSS_PLL_REG_W(io->pll_base + 0x800, QSERDES_TX_L2_CLKBUF_ENABLE, 0x03);
  571. MDSS_PLL_REG_W(io->pll_base + 0xA00, QSERDES_TX_L3_CLKBUF_ENABLE, 0x03);
  572. MDSS_PLL_REG_W(io->pll_base + 0x400,
  573. QSERDES_TX_L0_TRAN_DRVR_EMP_EN, 0x03);
  574. MDSS_PLL_REG_W(io->pll_base + 0x600,
  575. QSERDES_TX_L1_TRAN_DRVR_EMP_EN, 0x03);
  576. MDSS_PLL_REG_W(io->pll_base + 0x800,
  577. QSERDES_TX_L2_TRAN_DRVR_EMP_EN, 0x03);
  578. MDSS_PLL_REG_W(io->pll_base + 0xA00,
  579. QSERDES_TX_L3_TRAN_DRVR_EMP_EN, 0x03);
  580. MDSS_PLL_REG_W(io->pll_base + 0x400,
  581. QSERDES_TX_L0_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x6F);
  582. MDSS_PLL_REG_W(io->pll_base + 0x600,
  583. QSERDES_TX_L1_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x6F);
  584. MDSS_PLL_REG_W(io->pll_base + 0x800,
  585. QSERDES_TX_L2_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x6F);
  586. MDSS_PLL_REG_W(io->pll_base + 0xA00,
  587. QSERDES_TX_L3_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x6F);
  588. MDSS_PLL_REG_W(io->pll_base + 0x400,
  589. QSERDES_TX_L0_TX_EMP_POST1_LVL, 0x0000002F);
  590. MDSS_PLL_REG_W(io->phy_base, HDMI_PHY_TXCAL_CFG0, 0x000000AF);
  591. MDSS_PLL_REG_W(io->pll_base + 0x400, QSERDES_TX_L0_VMODE_CTRL1, 0x08);
  592. MDSS_PLL_REG_W(io->pll_base + 0x800, QSERDES_TX_L2_VMODE_CTRL1, 0x09);
  593. MDSS_PLL_REG_W(io->pll_base + 0x400, QSERDES_TX_L0_VMODE_CTRL5, 0xA0);
  594. MDSS_PLL_REG_W(io->pll_base + 0x400, QSERDES_TX_L0_VMODE_CTRL6, 0x01);
  595. MDSS_PLL_REG_W(io->pll_base + 0x800, QSERDES_TX_L2_VMODE_CTRL5, 0xA0);
  596. MDSS_PLL_REG_W(io->pll_base + 0x800, QSERDES_TX_L2_VMODE_CTRL6, 0x01);
  597. MDSS_PLL_REG_W(io->pll_base + 0x400,
  598. QSERDES_TX_L0_PARRATE_REC_DETECT_IDLE_EN, 0x40);
  599. MDSS_PLL_REG_W(io->pll_base + 0x400,
  600. QSERDES_TX_L0_TX_INTERFACE_MODE, 0x00);
  601. MDSS_PLL_REG_W(io->pll_base + 0x600,
  602. QSERDES_TX_L1_PARRATE_REC_DETECT_IDLE_EN, 0x40);
  603. MDSS_PLL_REG_W(io->pll_base + 0x600,
  604. QSERDES_TX_L1_TX_INTERFACE_MODE, 0x00);
  605. MDSS_PLL_REG_W(io->pll_base + 0x800,
  606. QSERDES_TX_L2_PARRATE_REC_DETECT_IDLE_EN, 0x40);
  607. MDSS_PLL_REG_W(io->pll_base + 0x800,
  608. QSERDES_TX_L2_TX_INTERFACE_MODE, 0x00);
  609. MDSS_PLL_REG_W(io->pll_base + 0xA00,
  610. QSERDES_TX_L3_PARRATE_REC_DETECT_IDLE_EN, 0x40);
  611. MDSS_PLL_REG_W(io->pll_base + 0xA00,
  612. QSERDES_TX_L3_TX_INTERFACE_MODE, 0x00);
  613. return 0;
  614. }
  615. static int hdmi_20nm_vco_enable(struct clk *c)
  616. {
  617. u32 ready_poll;
  618. u32 time_out_loop;
  619. /* Hardware recommended timeout iterator */
  620. u32 time_out_max = 50000;
  621. struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c);
  622. struct mdss_pll_resources *io = vco->priv;
  623. MDSS_PLL_REG_W(io->phy_base, HDMI_PHY_CFG, 0x00000000);
  624. udelay(100);
  625. /* memory barrier */
  626. mb();
  627. MDSS_PLL_REG_W(io->phy_base, HDMI_PHY_CFG, 0x00000003);
  628. udelay(100);
  629. /* memory barrier */
  630. mb();
  631. MDSS_PLL_REG_W(io->phy_base, HDMI_PHY_CFG, 0x00000009);
  632. udelay(100);
  633. /* memory barrier */
  634. mb();
  635. /* Poll for C_READY and PHY READY */
  636. pr_debug("%s: Waiting for PHY Ready\n", __func__);
  637. time_out_loop = 0;
  638. do {
  639. ready_poll = MDSS_PLL_REG_R(io->pll_base, QSERDES_COM_RESET_SM);
  640. time_out_loop++;
  641. udelay(10);
  642. } while (((ready_poll & (1 << 6)) == 0) &&
  643. (time_out_loop < time_out_max));
  644. if (time_out_loop >= time_out_max)
  645. pr_err("%s: ERROR: TIMED OUT BEFORE C READY\n", __func__);
  646. else
  647. pr_debug("%s: C READY\n", __func__);
  648. /* Poll for PHY READY */
  649. pr_debug("%s: Waiting for PHY Ready\n", __func__);
  650. time_out_loop = 0;
  651. do {
  652. ready_poll = MDSS_PLL_REG_R(io->phy_base, HDMI_PHY_STATUS);
  653. time_out_loop++;
  654. udelay(1);
  655. } while (((ready_poll & 0x1) == 0) && (time_out_loop < time_out_max));
  656. if (time_out_loop >= time_out_max)
  657. pr_err("%s: TIMED OUT BEFORE PHY READY\n", __func__);
  658. else
  659. pr_debug("%s: HDMI PHY READY\n", __func__);
  660. io->pll_on = true;
  661. return 0;
  662. }
  663. static int hdmi_20nm_vco_set_rate(struct clk *c, unsigned long rate)
  664. {
  665. struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c);
  666. struct mdss_pll_resources *io = vco->priv;
  667. void __iomem *pll_base;
  668. void __iomem *phy_base;
  669. unsigned int set_power_dwn = 0;
  670. int rc;
  671. rc = mdss_pll_resource_enable(io, true);
  672. if (rc) {
  673. pr_err("pll resource can't be enabled\n");
  674. return rc;
  675. }
  676. if (io->pll_on)
  677. set_power_dwn = 1;
  678. pll_base = io->pll_base;
  679. phy_base = io->phy_base;
  680. pr_debug("rate=%ld\n", rate);
  681. hdmi_20nm_phy_pll_set_clk_rate(c, rate);
  682. mdss_pll_resource_enable(io, false);
  683. if (set_power_dwn)
  684. hdmi_20nm_vco_enable(c);
  685. vco->rate = rate;
  686. vco->rate_set = true;
  687. return 0;
  688. }
  689. static unsigned long hdmi_20nm_vco_get_rate(struct clk *c)
  690. {
  691. unsigned long freq = 0;
  692. int rc;
  693. struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c);
  694. struct mdss_pll_resources *io = vco->priv;
  695. if (is_gdsc_disabled(io))
  696. return 0;
  697. rc = mdss_pll_resource_enable(io, true);
  698. if (rc) {
  699. pr_err("pll resource can't be enabled\n");
  700. return rc;
  701. }
  702. mdss_pll_resource_enable(io, false);
  703. return freq;
  704. }
  705. static long hdmi_20nm_vco_round_rate(struct clk *c, unsigned long rate)
  706. {
  707. unsigned long rrate = rate;
  708. pr_debug("rrate=%ld\n", rrate);
  709. return rrate;
  710. }
  711. static int hdmi_20nm_vco_prepare(struct clk *c)
  712. {
  713. struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c);
  714. struct mdss_pll_resources *io = vco->priv;
  715. int ret = 0;
  716. pr_debug("rate=%ld\n", vco->rate);
  717. if (!vco->rate_set && vco->rate)
  718. ret = hdmi_20nm_vco_set_rate(c, vco->rate);
  719. if (!ret) {
  720. ret = mdss_pll_resource_enable(io, true);
  721. if (ret)
  722. pr_err("pll resource can't be enabled\n");
  723. }
  724. return ret;
  725. }
  726. static void hdmi_20nm_vco_unprepare(struct clk *c)
  727. {
  728. struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c);
  729. struct mdss_pll_resources *io = vco->priv;
  730. vco->rate_set = false;
  731. if (!io) {
  732. pr_err("Invalid input parameter\n");
  733. return;
  734. }
  735. if (!io->pll_on &&
  736. mdss_pll_resource_enable(io, true)) {
  737. pr_err("pll resource can't be enabled\n");
  738. return;
  739. }
  740. io->handoff_resources = false;
  741. mdss_pll_resource_enable(io, false);
  742. io->pll_on = false;
  743. }
  744. static enum handoff hdmi_20nm_vco_handoff(struct clk *c)
  745. {
  746. enum handoff ret = HANDOFF_DISABLED_CLK;
  747. struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c);
  748. struct mdss_pll_resources *io = vco->priv;
  749. if (is_gdsc_disabled(io))
  750. return HANDOFF_DISABLED_CLK;
  751. if (mdss_pll_resource_enable(io, true)) {
  752. pr_err("pll resource can't be enabled\n");
  753. return ret;
  754. }
  755. io->handoff_resources = true;
  756. if (hdmi_20nm_pll_lock_status(io)) {
  757. io->pll_on = true;
  758. c->rate = hdmi_20nm_vco_get_rate(c);
  759. ret = HANDOFF_ENABLED_CLK;
  760. } else {
  761. io->handoff_resources = false;
  762. mdss_pll_resource_enable(io, false);
  763. }
  764. pr_debug("done, ret=%d\n", ret);
  765. return ret;
  766. }
  767. static const struct clk_ops hdmi_20nm_vco_clk_ops = {
  768. .enable = hdmi_20nm_vco_enable,
  769. .set_rate = hdmi_20nm_vco_set_rate,
  770. .get_rate = hdmi_20nm_vco_get_rate,
  771. .round_rate = hdmi_20nm_vco_round_rate,
  772. .prepare = hdmi_20nm_vco_prepare,
  773. .unprepare = hdmi_20nm_vco_unprepare,
  774. .handoff = hdmi_20nm_vco_handoff,
  775. };
  776. static struct hdmi_pll_vco_clk hdmi_20nm_vco_clk = {
  777. .ip_seti = (struct hdmi_pll_cfg[]){
  778. {550890000, 0x03},
  779. {589240000, 0x07},
  780. {689290000, 0x03},
  781. {727600000, 0x07},
  782. {HDMI_PLL_TMDS_MAX, 0x03},
  783. },
  784. .cp_seti = (struct hdmi_pll_cfg[]){
  785. {34440000, 0x3F},
  786. {36830000, 0x2F},
  787. {68870000, 0x3F},
  788. {73660000, 0x2F},
  789. {137730000, 0x3F},
  790. {147310000, 0x2F},
  791. {275450000, 0x3F},
  792. {294620000, 0x2F},
  793. {344650000, 0x3F},
  794. {363800000, 0x2F},
  795. {477960000, 0x3F},
  796. {512530000, 0x2F},
  797. {550890000, 0x1F},
  798. {589240000, 0x2F},
  799. {630900000, 0x3F},
  800. {650590000, 0x2F},
  801. {689290000, 0x1F},
  802. {727600000, 0x2F},
  803. {HDMI_PLL_TMDS_MAX, 0x3F},
  804. },
  805. .ip_setp = (struct hdmi_pll_cfg[]){
  806. {497340000, 0x03},
  807. {512530000, 0x07},
  808. {535680000, 0x03},
  809. {550890000, 0x07},
  810. {574060000, 0x03},
  811. {727600000, 0x07},
  812. {HDMI_PLL_TMDS_MAX, 0x03},
  813. },
  814. .cp_setp = (struct hdmi_pll_cfg[]){
  815. {36830000, 0x1F},
  816. {40010000, 0x17},
  817. {73660000, 0x1F},
  818. {80000000, 0x17},
  819. {147310000, 0x1F},
  820. {160010000, 0x17},
  821. {294620000, 0x1F},
  822. {363800000, 0x17},
  823. {497340000, 0x0F},
  824. {512530000, 0x1F},
  825. {535680000, 0x0F},
  826. {550890000, 0x1F},
  827. {574060000, 0x0F},
  828. {589240000, 0x1F},
  829. {727600000, 0x17},
  830. {HDMI_PLL_TMDS_MAX, 0x07},
  831. },
  832. .crctrl = (struct hdmi_pll_cfg[]){
  833. {40010000, 0xBB},
  834. {40030000, 0x77},
  835. {80000000, 0xBB},
  836. {80060000, 0x77},
  837. {160010000, 0xBB},
  838. {160120000, 0x77},
  839. {772930000, 0xBB},
  840. {HDMI_PLL_TMDS_MAX, 0xFF},
  841. },
  842. .c = {
  843. .dbg_name = "hdmi_20nm_vco_clk",
  844. .ops = &hdmi_20nm_vco_clk_ops,
  845. CLK_INIT(hdmi_20nm_vco_clk.c),
  846. },
  847. };
  848. static struct clk_lookup hdmipllcc_8994[] = {
  849. CLK_LIST(hdmi_20nm_vco_clk),
  850. };
  851. int hdmi_20nm_pll_clock_register(struct platform_device *pdev,
  852. struct mdss_pll_resources *pll_res)
  853. {
  854. int rc = -ENOTSUPP;
  855. /* Set client data for vco, mux and div clocks */
  856. hdmi_20nm_vco_clk.priv = pll_res;
  857. rc = of_msm_clock_register(pdev->dev.of_node, hdmipllcc_8994,
  858. ARRAY_SIZE(hdmipllcc_8994));
  859. if (rc) {
  860. pr_err("Clock register failed rc=%d\n", rc);
  861. rc = -EPROBE_DEFER;
  862. } else {
  863. pr_debug("%s: SUCCESS\n", __func__);
  864. }
  865. return rc;
  866. }