dsi_phy_hw_v2_0.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "dsi-phy-hw:" fmt
  6. #include <linux/math64.h>
  7. #include <linux/delay.h>
  8. #include "dsi_hw.h"
  9. #include "dsi_phy_hw.h"
  10. #define DSIPHY_CMN_REVISION_ID0 0x0000
  11. #define DSIPHY_CMN_REVISION_ID1 0x0004
  12. #define DSIPHY_CMN_REVISION_ID2 0x0008
  13. #define DSIPHY_CMN_REVISION_ID3 0x000C
  14. #define DSIPHY_CMN_CLK_CFG0 0x0010
  15. #define DSIPHY_CMN_CLK_CFG1 0x0014
  16. #define DSIPHY_CMN_GLBL_TEST_CTRL 0x0018
  17. #define DSIPHY_CMN_CTRL_0 0x001C
  18. #define DSIPHY_CMN_CTRL_1 0x0020
  19. #define DSIPHY_CMN_CAL_HW_TRIGGER 0x0024
  20. #define DSIPHY_CMN_CAL_SW_CFG0 0x0028
  21. #define DSIPHY_CMN_CAL_SW_CFG1 0x002C
  22. #define DSIPHY_CMN_CAL_SW_CFG2 0x0030
  23. #define DSIPHY_CMN_CAL_HW_CFG0 0x0034
  24. #define DSIPHY_CMN_CAL_HW_CFG1 0x0038
  25. #define DSIPHY_CMN_CAL_HW_CFG2 0x003C
  26. #define DSIPHY_CMN_CAL_HW_CFG3 0x0040
  27. #define DSIPHY_CMN_CAL_HW_CFG4 0x0044
  28. #define DSIPHY_CMN_PLL_CNTRL 0x0048
  29. #define DSIPHY_CMN_LDO_CNTRL 0x004C
  30. #define DSIPHY_CMN_REGULATOR_CAL_STATUS0 0x0064
  31. #define DSIPHY_CMN_REGULATOR_CAL_STATUS1 0x0068
  32. #define DSI_MDP_ULPS_CLAMP_ENABLE_OFF 0x0054
  33. /* n = 0..3 for data lanes and n = 4 for clock lane
  34. * t for count per lane
  35. */
  36. #define DSIPHY_DLNX_CFG(n, t) \
  37. (0x100 + ((t) * 0x04) + ((n) * 0x80))
  38. #define DSIPHY_DLNX_TIMING_CTRL(n, t) \
  39. (0x118 + ((t) * 0x04) + ((n) * 0x80))
  40. #define DSIPHY_DLNX_STRENGTH_CTRL(n, t) \
  41. (0x138 + ((t) * 0x04) + ((n) * 0x80))
  42. #define DSIPHY_DLNX_TEST_DATAPATH(n) (0x110 + ((n) * 0x80))
  43. #define DSIPHY_DLNX_TEST_STR(n) (0x114 + ((n) * 0x80))
  44. #define DSIPHY_DLNX_BIST_POLY(n) (0x140 + ((n) * 0x80))
  45. #define DSIPHY_DLNX_BIST_SEED0(n) (0x144 + ((n) * 0x80))
  46. #define DSIPHY_DLNX_BIST_SEED1(n) (0x148 + ((n) * 0x80))
  47. #define DSIPHY_DLNX_BIST_HEAD(n) (0x14C + ((n) * 0x80))
  48. #define DSIPHY_DLNX_BIST_SOT(n) (0x150 + ((n) * 0x80))
  49. #define DSIPHY_DLNX_BIST_CTRL0(n) (0x154 + ((n) * 0x80))
  50. #define DSIPHY_DLNX_BIST_CTRL1(n) (0x158 + ((n) * 0x80))
  51. #define DSIPHY_DLNX_BIST_CTRL2(n) (0x15C + ((n) * 0x80))
  52. #define DSIPHY_DLNX_BIST_CTRL3(n) (0x160 + ((n) * 0x80))
  53. #define DSIPHY_DLNX_VREG_CNTRL(n) (0x164 + ((n) * 0x80))
  54. #define DSIPHY_DLNX_HSTX_STR_STATUS(n) (0x168 + ((n) * 0x80))
  55. #define DSIPHY_DLNX_BIST_STATUS0(n) (0x16C + ((n) * 0x80))
  56. #define DSIPHY_DLNX_BIST_STATUS1(n) (0x170 + ((n) * 0x80))
  57. #define DSIPHY_DLNX_BIST_STATUS2(n) (0x174 + ((n) * 0x80))
  58. #define DSIPHY_DLNX_BIST_STATUS3(n) (0x178 + ((n) * 0x80))
  59. #define DSIPHY_DLNX_MISR_STATUS(n) (0x17C + ((n) * 0x80))
  60. #define DSIPHY_PLL_CLKBUFLR_EN 0x041C
  61. #define DSIPHY_PLL_PLL_BANDGAP 0x0508
  62. /**
  63. * regulator_enable() - enable regulators for DSI PHY
  64. * @phy: Pointer to DSI PHY hardware object.
  65. * @reg_cfg: Regulator configuration for all DSI lanes.
  66. */
  67. void dsi_phy_hw_v2_0_regulator_enable(struct dsi_phy_hw *phy,
  68. struct dsi_phy_per_lane_cfgs *reg_cfg)
  69. {
  70. int i;
  71. bool is_split_link = test_bit(DSI_PHY_SPLIT_LINK, phy->feature_map);
  72. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++)
  73. DSI_W32(phy, DSIPHY_DLNX_VREG_CNTRL(i), reg_cfg->lane[i][0]);
  74. if (is_split_link)
  75. DSI_W32(phy, DSIPHY_DLNX_VREG_CNTRL(DSI_LOGICAL_CLOCK_LANE+1),
  76. reg_cfg->lane[DSI_LOGICAL_CLOCK_LANE][0]);
  77. /* make sure all values are written to hardware */
  78. wmb();
  79. pr_debug("[DSI_%d] Phy regulators enabled\n", phy->index);
  80. }
  81. /**
  82. * regulator_disable() - disable regulators
  83. * @phy: Pointer to DSI PHY hardware object.
  84. */
  85. void dsi_phy_hw_v2_0_regulator_disable(struct dsi_phy_hw *phy)
  86. {
  87. pr_debug("[DSI_%d] Phy regulators disabled\n", phy->index);
  88. }
  89. /**
  90. * enable() - Enable PHY hardware
  91. * @phy: Pointer to DSI PHY hardware object.
  92. * @cfg: Per lane configurations for timing, strength and lane
  93. * configurations.
  94. */
  95. void dsi_phy_hw_v2_0_enable(struct dsi_phy_hw *phy,
  96. struct dsi_phy_cfg *cfg)
  97. {
  98. int i, j;
  99. struct dsi_phy_per_lane_cfgs *lanecfg = &cfg->lanecfg;
  100. struct dsi_phy_per_lane_cfgs *timing = &cfg->timing;
  101. struct dsi_phy_per_lane_cfgs *strength = &cfg->strength;
  102. u32 data;
  103. bool is_split_link = test_bit(DSI_PHY_SPLIT_LINK, phy->feature_map);
  104. DSI_W32(phy, DSIPHY_CMN_LDO_CNTRL, 0x1C);
  105. DSI_W32(phy, DSIPHY_CMN_GLBL_TEST_CTRL, 0x1);
  106. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  107. for (j = 0; j < lanecfg->count_per_lane; j++)
  108. DSI_W32(phy, DSIPHY_DLNX_CFG(i, j),
  109. lanecfg->lane[i][j]);
  110. DSI_W32(phy, DSIPHY_DLNX_TEST_STR(i), 0x88);
  111. for (j = 0; j < timing->count_per_lane; j++)
  112. DSI_W32(phy, DSIPHY_DLNX_TIMING_CTRL(i, j),
  113. timing->lane[i][j]);
  114. for (j = 0; j < strength->count_per_lane; j++)
  115. DSI_W32(phy, DSIPHY_DLNX_STRENGTH_CTRL(i, j),
  116. strength->lane[i][j]);
  117. }
  118. if (is_split_link) {
  119. i = DSI_LOGICAL_CLOCK_LANE;
  120. for (j = 0; j < lanecfg->count_per_lane; j++)
  121. DSI_W32(phy, DSIPHY_DLNX_CFG(i+1, j),
  122. lanecfg->lane[i][j]);
  123. DSI_W32(phy, DSIPHY_DLNX_TEST_STR(i+1), 0x0);
  124. DSI_W32(phy, DSIPHY_DLNX_TEST_DATAPATH(i+1), 0x88);
  125. for (j = 0; j < timing->count_per_lane; j++)
  126. DSI_W32(phy, DSIPHY_DLNX_TIMING_CTRL(i+1, j),
  127. timing->lane[i][j]);
  128. for (j = 0; j < strength->count_per_lane; j++)
  129. DSI_W32(phy, DSIPHY_DLNX_STRENGTH_CTRL(i+1, j),
  130. strength->lane[i][j]);
  131. /* enable split link for cmn clk cfg1 */
  132. data = DSI_R32(phy, DSIPHY_CMN_CLK_CFG1);
  133. data |= BIT(1);
  134. DSI_W32(phy, DSIPHY_CMN_CLK_CFG1, data);
  135. }
  136. /* make sure all values are written to hardware before enabling phy */
  137. wmb();
  138. DSI_W32(phy, DSIPHY_CMN_CTRL_1, 0x80);
  139. udelay(100);
  140. DSI_W32(phy, DSIPHY_CMN_CTRL_1, 0x00);
  141. data = DSI_R32(phy, DSIPHY_CMN_GLBL_TEST_CTRL);
  142. switch (cfg->pll_source) {
  143. case DSI_PLL_SOURCE_STANDALONE:
  144. DSI_W32(phy, DSIPHY_PLL_CLKBUFLR_EN, 0x01);
  145. data &= ~BIT(2);
  146. break;
  147. case DSI_PLL_SOURCE_NATIVE:
  148. DSI_W32(phy, DSIPHY_PLL_CLKBUFLR_EN, 0x03);
  149. data &= ~BIT(2);
  150. break;
  151. case DSI_PLL_SOURCE_NON_NATIVE:
  152. DSI_W32(phy, DSIPHY_PLL_CLKBUFLR_EN, 0x00);
  153. data |= BIT(2);
  154. break;
  155. default:
  156. break;
  157. }
  158. DSI_W32(phy, DSIPHY_CMN_GLBL_TEST_CTRL, data);
  159. /* Enable bias current for pll1 during split display case */
  160. if (cfg->pll_source == DSI_PLL_SOURCE_NON_NATIVE)
  161. DSI_W32(phy, DSIPHY_PLL_PLL_BANDGAP, 0x3);
  162. pr_debug("[DSI_%d]Phy enabled\n", phy->index);
  163. }
  164. /**
  165. * disable() - Disable PHY hardware
  166. * @phy: Pointer to DSI PHY hardware object.
  167. */
  168. void dsi_phy_hw_v2_0_disable(struct dsi_phy_hw *phy,
  169. struct dsi_phy_cfg *cfg)
  170. {
  171. DSI_W32(phy, DSIPHY_PLL_CLKBUFLR_EN, 0);
  172. DSI_W32(phy, DSIPHY_CMN_GLBL_TEST_CTRL, 0);
  173. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0);
  174. pr_debug("[DSI_%d]Phy disabled\n", phy->index);
  175. }
  176. /**
  177. * dsi_phy_hw_v2_0_idle_on() - Enable DSI PHY hardware during idle screen
  178. * @phy: Pointer to DSI PHY hardware object.
  179. */
  180. void dsi_phy_hw_v2_0_idle_on(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg)
  181. {
  182. int i = 0, j;
  183. struct dsi_phy_per_lane_cfgs *strength = &cfg->strength;
  184. bool is_split_link = test_bit(DSI_PHY_SPLIT_LINK, phy->feature_map);
  185. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  186. for (j = 0; j < strength->count_per_lane; j++)
  187. DSI_W32(phy, DSIPHY_DLNX_STRENGTH_CTRL(i, j),
  188. strength->lane[i][j]);
  189. }
  190. if (is_split_link) {
  191. i = DSI_LOGICAL_CLOCK_LANE;
  192. for (j = 0; j < strength->count_per_lane; j++)
  193. DSI_W32(phy, DSIPHY_DLNX_STRENGTH_CTRL(i+1, j),
  194. strength->lane[i][j]);
  195. }
  196. wmb(); /* make sure write happens */
  197. pr_debug("[DSI_%d]Phy enabled out of idle screen\n", phy->index);
  198. }
  199. /**
  200. * dsi_phy_hw_v2_0_idle_off() - Disable DSI PHY hardware during idle screen
  201. * @phy: Pointer to DSI PHY hardware object.
  202. */
  203. void dsi_phy_hw_v2_0_idle_off(struct dsi_phy_hw *phy)
  204. {
  205. int i = 0;
  206. bool is_split_link = test_bit(DSI_PHY_SPLIT_LINK, phy->feature_map);
  207. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x7f);
  208. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++)
  209. DSI_W32(phy, DSIPHY_DLNX_VREG_CNTRL(i), 0x1c);
  210. if (is_split_link)
  211. DSI_W32(phy, DSIPHY_DLNX_VREG_CNTRL(DSI_LOGICAL_CLOCK_LANE+1),
  212. 0x1c);
  213. DSI_W32(phy, DSIPHY_CMN_LDO_CNTRL, 0x1C);
  214. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++)
  215. DSI_W32(phy, DSIPHY_DLNX_STRENGTH_CTRL(i, 1), 0x0);
  216. if (is_split_link)
  217. DSI_W32(phy,
  218. DSIPHY_DLNX_STRENGTH_CTRL(DSI_LOGICAL_CLOCK_LANE+1, 1), 0x0);
  219. wmb(); /* make sure write happens */
  220. pr_debug("[DSI_%d]Phy disabled during idle screen\n", phy->index);
  221. }
  222. int dsi_phy_hw_timing_val_v2_0(struct dsi_phy_per_lane_cfgs *timing_cfg,
  223. u32 *timing_val, u32 size)
  224. {
  225. int i = 0, j = 0;
  226. if (size != (DSI_LANE_MAX * DSI_MAX_SETTINGS)) {
  227. pr_err("Unexpected timing array size %d\n", size);
  228. return -EINVAL;
  229. }
  230. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  231. for (j = 0; j < DSI_MAX_SETTINGS; j++) {
  232. timing_cfg->lane[i][j] = *timing_val;
  233. timing_val++;
  234. }
  235. }
  236. return 0;
  237. }
  238. void dsi_phy_hw_v2_0_clamp_ctrl(struct dsi_phy_hw *phy, bool enable)
  239. {
  240. u32 clamp_reg = 0;
  241. if (!phy->phy_clamp_base) {
  242. pr_debug("phy_clamp_base NULL\n");
  243. return;
  244. }
  245. if (enable) {
  246. clamp_reg |= BIT(0);
  247. DSI_MISC_W32(phy, DSI_MDP_ULPS_CLAMP_ENABLE_OFF,
  248. clamp_reg);
  249. pr_debug("clamp enabled\n");
  250. } else {
  251. clamp_reg &= ~BIT(0);
  252. DSI_MISC_W32(phy, DSI_MDP_ULPS_CLAMP_ENABLE_OFF,
  253. clamp_reg);
  254. pr_debug("clamp disabled\n");
  255. }
  256. }