dsi_phy_hw_v2_0.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. #define DSIPHY_DLNX_CFG0(n) (0x100 + ((n) * 0x80))
  35. #define DSIPHY_DLNX_CFG1(n) (0x104 + ((n) * 0x80))
  36. #define DSIPHY_DLNX_CFG2(n) (0x108 + ((n) * 0x80))
  37. #define DSIPHY_DLNX_CFG3(n) (0x10C + ((n) * 0x80))
  38. #define DSIPHY_DLNX_TEST_DATAPATH(n) (0x110 + ((n) * 0x80))
  39. #define DSIPHY_DLNX_TEST_STR(n) (0x114 + ((n) * 0x80))
  40. #define DSIPHY_DLNX_TIMING_CTRL_4(n) (0x118 + ((n) * 0x80))
  41. #define DSIPHY_DLNX_TIMING_CTRL_5(n) (0x11C + ((n) * 0x80))
  42. #define DSIPHY_DLNX_TIMING_CTRL_6(n) (0x120 + ((n) * 0x80))
  43. #define DSIPHY_DLNX_TIMING_CTRL_7(n) (0x124 + ((n) * 0x80))
  44. #define DSIPHY_DLNX_TIMING_CTRL_8(n) (0x128 + ((n) * 0x80))
  45. #define DSIPHY_DLNX_TIMING_CTRL_9(n) (0x12C + ((n) * 0x80))
  46. #define DSIPHY_DLNX_TIMING_CTRL_10(n) (0x130 + ((n) * 0x80))
  47. #define DSIPHY_DLNX_TIMING_CTRL_11(n) (0x134 + ((n) * 0x80))
  48. #define DSIPHY_DLNX_STRENGTH_CTRL_0(n) (0x138 + ((n) * 0x80))
  49. #define DSIPHY_DLNX_STRENGTH_CTRL_1(n) (0x13C + ((n) * 0x80))
  50. #define DSIPHY_DLNX_BIST_POLY(n) (0x140 + ((n) * 0x80))
  51. #define DSIPHY_DLNX_BIST_SEED0(n) (0x144 + ((n) * 0x80))
  52. #define DSIPHY_DLNX_BIST_SEED1(n) (0x148 + ((n) * 0x80))
  53. #define DSIPHY_DLNX_BIST_HEAD(n) (0x14C + ((n) * 0x80))
  54. #define DSIPHY_DLNX_BIST_SOT(n) (0x150 + ((n) * 0x80))
  55. #define DSIPHY_DLNX_BIST_CTRL0(n) (0x154 + ((n) * 0x80))
  56. #define DSIPHY_DLNX_BIST_CTRL1(n) (0x158 + ((n) * 0x80))
  57. #define DSIPHY_DLNX_BIST_CTRL2(n) (0x15C + ((n) * 0x80))
  58. #define DSIPHY_DLNX_BIST_CTRL3(n) (0x160 + ((n) * 0x80))
  59. #define DSIPHY_DLNX_VREG_CNTRL(n) (0x164 + ((n) * 0x80))
  60. #define DSIPHY_DLNX_HSTX_STR_STATUS(n) (0x168 + ((n) * 0x80))
  61. #define DSIPHY_DLNX_BIST_STATUS0(n) (0x16C + ((n) * 0x80))
  62. #define DSIPHY_DLNX_BIST_STATUS1(n) (0x170 + ((n) * 0x80))
  63. #define DSIPHY_DLNX_BIST_STATUS2(n) (0x174 + ((n) * 0x80))
  64. #define DSIPHY_DLNX_BIST_STATUS3(n) (0x178 + ((n) * 0x80))
  65. #define DSIPHY_DLNX_MISR_STATUS(n) (0x17C + ((n) * 0x80))
  66. #define DSIPHY_PLL_CLKBUFLR_EN 0x041C
  67. #define DSIPHY_PLL_PLL_BANDGAP 0x0508
  68. /**
  69. * regulator_enable() - enable regulators for DSI PHY
  70. * @phy: Pointer to DSI PHY hardware object.
  71. * @reg_cfg: Regulator configuration for all DSI lanes.
  72. */
  73. void dsi_phy_hw_v2_0_regulator_enable(struct dsi_phy_hw *phy,
  74. struct dsi_phy_per_lane_cfgs *reg_cfg)
  75. {
  76. int i;
  77. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++)
  78. DSI_W32(phy, DSIPHY_DLNX_VREG_CNTRL(i), reg_cfg->lane[i][0]);
  79. /* make sure all values are written to hardware */
  80. wmb();
  81. pr_debug("[DSI_%d] Phy regulators enabled\n", phy->index);
  82. }
  83. /**
  84. * regulator_disable() - disable regulators
  85. * @phy: Pointer to DSI PHY hardware object.
  86. */
  87. void dsi_phy_hw_v2_0_regulator_disable(struct dsi_phy_hw *phy)
  88. {
  89. pr_debug("[DSI_%d] Phy regulators disabled\n", phy->index);
  90. }
  91. /**
  92. * enable() - Enable PHY hardware
  93. * @phy: Pointer to DSI PHY hardware object.
  94. * @cfg: Per lane configurations for timing, strength and lane
  95. * configurations.
  96. */
  97. void dsi_phy_hw_v2_0_enable(struct dsi_phy_hw *phy,
  98. struct dsi_phy_cfg *cfg)
  99. {
  100. int i;
  101. struct dsi_phy_per_lane_cfgs *timing = &cfg->timing;
  102. u32 data;
  103. DSI_W32(phy, DSIPHY_CMN_LDO_CNTRL, 0x1C);
  104. DSI_W32(phy, DSIPHY_CMN_GLBL_TEST_CTRL, 0x1);
  105. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  106. DSI_W32(phy, DSIPHY_DLNX_CFG0(i), cfg->lanecfg.lane[i][0]);
  107. DSI_W32(phy, DSIPHY_DLNX_CFG1(i), cfg->lanecfg.lane[i][1]);
  108. DSI_W32(phy, DSIPHY_DLNX_CFG2(i), cfg->lanecfg.lane[i][2]);
  109. DSI_W32(phy, DSIPHY_DLNX_CFG3(i), cfg->lanecfg.lane[i][3]);
  110. DSI_W32(phy, DSIPHY_DLNX_TEST_STR(i), 0x88);
  111. DSI_W32(phy, DSIPHY_DLNX_TIMING_CTRL_4(i), timing->lane[i][0]);
  112. DSI_W32(phy, DSIPHY_DLNX_TIMING_CTRL_5(i), timing->lane[i][1]);
  113. DSI_W32(phy, DSIPHY_DLNX_TIMING_CTRL_6(i), timing->lane[i][2]);
  114. DSI_W32(phy, DSIPHY_DLNX_TIMING_CTRL_7(i), timing->lane[i][3]);
  115. DSI_W32(phy, DSIPHY_DLNX_TIMING_CTRL_8(i), timing->lane[i][4]);
  116. DSI_W32(phy, DSIPHY_DLNX_TIMING_CTRL_9(i), timing->lane[i][5]);
  117. DSI_W32(phy, DSIPHY_DLNX_TIMING_CTRL_10(i), timing->lane[i][6]);
  118. DSI_W32(phy, DSIPHY_DLNX_TIMING_CTRL_11(i), timing->lane[i][7]);
  119. DSI_W32(phy, DSIPHY_DLNX_STRENGTH_CTRL_0(i),
  120. cfg->strength.lane[i][0]);
  121. DSI_W32(phy, DSIPHY_DLNX_STRENGTH_CTRL_1(i),
  122. cfg->strength.lane[i][1]);
  123. }
  124. /* make sure all values are written to hardware before enabling phy */
  125. wmb();
  126. DSI_W32(phy, DSIPHY_CMN_CTRL_1, 0x80);
  127. udelay(100);
  128. DSI_W32(phy, DSIPHY_CMN_CTRL_1, 0x00);
  129. data = DSI_R32(phy, DSIPHY_CMN_GLBL_TEST_CTRL);
  130. switch (cfg->pll_source) {
  131. case DSI_PLL_SOURCE_STANDALONE:
  132. DSI_W32(phy, DSIPHY_PLL_CLKBUFLR_EN, 0x01);
  133. data &= ~BIT(2);
  134. break;
  135. case DSI_PLL_SOURCE_NATIVE:
  136. DSI_W32(phy, DSIPHY_PLL_CLKBUFLR_EN, 0x03);
  137. data &= ~BIT(2);
  138. break;
  139. case DSI_PLL_SOURCE_NON_NATIVE:
  140. DSI_W32(phy, DSIPHY_PLL_CLKBUFLR_EN, 0x00);
  141. data |= BIT(2);
  142. break;
  143. default:
  144. break;
  145. }
  146. DSI_W32(phy, DSIPHY_CMN_GLBL_TEST_CTRL, data);
  147. /* Enable bias current for pll1 during split display case */
  148. if (cfg->pll_source == DSI_PLL_SOURCE_NON_NATIVE)
  149. DSI_W32(phy, DSIPHY_PLL_PLL_BANDGAP, 0x3);
  150. pr_debug("[DSI_%d]Phy enabled\n", phy->index);
  151. }
  152. /**
  153. * disable() - Disable PHY hardware
  154. * @phy: Pointer to DSI PHY hardware object.
  155. */
  156. void dsi_phy_hw_v2_0_disable(struct dsi_phy_hw *phy,
  157. struct dsi_phy_cfg *cfg)
  158. {
  159. DSI_W32(phy, DSIPHY_PLL_CLKBUFLR_EN, 0);
  160. DSI_W32(phy, DSIPHY_CMN_GLBL_TEST_CTRL, 0);
  161. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0);
  162. pr_debug("[DSI_%d]Phy disabled\n", phy->index);
  163. }
  164. /**
  165. * dsi_phy_hw_v2_0_idle_on() - Enable DSI PHY hardware during idle screen
  166. * @phy: Pointer to DSI PHY hardware object.
  167. */
  168. void dsi_phy_hw_v2_0_idle_on(struct dsi_phy_hw *phy, struct dsi_phy_cfg *cfg)
  169. {
  170. int i = 0;
  171. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  172. DSI_W32(phy, DSIPHY_DLNX_STRENGTH_CTRL_0(i),
  173. cfg->strength.lane[i][0]);
  174. DSI_W32(phy, DSIPHY_DLNX_STRENGTH_CTRL_1(i),
  175. cfg->strength.lane[i][1]);
  176. }
  177. wmb(); /* make sure write happens */
  178. pr_debug("[DSI_%d]Phy enabled out of idle screen\n", phy->index);
  179. }
  180. /**
  181. * dsi_phy_hw_v2_0_idle_off() - Disable DSI PHY hardware during idle screen
  182. * @phy: Pointer to DSI PHY hardware object.
  183. */
  184. void dsi_phy_hw_v2_0_idle_off(struct dsi_phy_hw *phy)
  185. {
  186. int i = 0;
  187. DSI_W32(phy, DSIPHY_CMN_CTRL_0, 0x7f);
  188. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++)
  189. DSI_W32(phy, DSIPHY_DLNX_VREG_CNTRL(i), 0x1c);
  190. DSI_W32(phy, DSIPHY_CMN_LDO_CNTRL, 0x1C);
  191. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++)
  192. DSI_W32(phy, DSIPHY_DLNX_STRENGTH_CTRL_1(i), 0x0);
  193. wmb(); /* make sure write happens */
  194. pr_debug("[DSI_%d]Phy disabled during idle screen\n", phy->index);
  195. }
  196. int dsi_phy_hw_timing_val_v2_0(struct dsi_phy_per_lane_cfgs *timing_cfg,
  197. u32 *timing_val, u32 size)
  198. {
  199. int i = 0, j = 0;
  200. if (size != (DSI_LANE_MAX * DSI_MAX_SETTINGS)) {
  201. pr_err("Unexpected timing array size %d\n", size);
  202. return -EINVAL;
  203. }
  204. for (i = DSI_LOGICAL_LANE_0; i < DSI_LANE_MAX; i++) {
  205. for (j = 0; j < DSI_MAX_SETTINGS; j++) {
  206. timing_cfg->lane[i][j] = *timing_val;
  207. timing_val++;
  208. }
  209. }
  210. return 0;
  211. }
  212. void dsi_phy_hw_v2_0_clamp_ctrl(struct dsi_phy_hw *phy, bool enable)
  213. {
  214. u32 clamp_reg = 0;
  215. if (!phy->phy_clamp_base) {
  216. pr_debug("phy_clamp_base NULL\n");
  217. return;
  218. }
  219. if (enable) {
  220. clamp_reg |= BIT(0);
  221. DSI_MISC_W32(phy, DSI_MDP_ULPS_CLAMP_ENABLE_OFF,
  222. clamp_reg);
  223. pr_debug("clamp enabled\n");
  224. } else {
  225. clamp_reg &= ~BIT(0);
  226. DSI_MISC_W32(phy, DSI_MDP_ULPS_CLAMP_ENABLE_OFF,
  227. clamp_reg);
  228. pr_debug("clamp disabled\n");
  229. }
  230. }