dsi_phy_28nm.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include "dsi_phy.h"
  14. #include "dsi.xml.h"
  15. static void dsi_28nm_dphy_set_timing(struct msm_dsi_phy *phy,
  16. struct msm_dsi_dphy_timing *timing)
  17. {
  18. void __iomem *base = phy->base;
  19. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_0,
  20. DSI_28nm_PHY_TIMING_CTRL_0_CLK_ZERO(timing->clk_zero));
  21. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_1,
  22. DSI_28nm_PHY_TIMING_CTRL_1_CLK_TRAIL(timing->clk_trail));
  23. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_2,
  24. DSI_28nm_PHY_TIMING_CTRL_2_CLK_PREPARE(timing->clk_prepare));
  25. if (timing->clk_zero & BIT(8))
  26. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_3,
  27. DSI_28nm_PHY_TIMING_CTRL_3_CLK_ZERO_8);
  28. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_4,
  29. DSI_28nm_PHY_TIMING_CTRL_4_HS_EXIT(timing->hs_exit));
  30. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_5,
  31. DSI_28nm_PHY_TIMING_CTRL_5_HS_ZERO(timing->hs_zero));
  32. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_6,
  33. DSI_28nm_PHY_TIMING_CTRL_6_HS_PREPARE(timing->hs_prepare));
  34. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_7,
  35. DSI_28nm_PHY_TIMING_CTRL_7_HS_TRAIL(timing->hs_trail));
  36. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_8,
  37. DSI_28nm_PHY_TIMING_CTRL_8_HS_RQST(timing->hs_rqst));
  38. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_9,
  39. DSI_28nm_PHY_TIMING_CTRL_9_TA_GO(timing->ta_go) |
  40. DSI_28nm_PHY_TIMING_CTRL_9_TA_SURE(timing->ta_sure));
  41. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_10,
  42. DSI_28nm_PHY_TIMING_CTRL_10_TA_GET(timing->ta_get));
  43. dsi_phy_write(base + REG_DSI_28nm_PHY_TIMING_CTRL_11,
  44. DSI_28nm_PHY_TIMING_CTRL_11_TRIG3_CMD(0));
  45. }
  46. static void dsi_28nm_phy_regulator_ctrl(struct msm_dsi_phy *phy, bool enable)
  47. {
  48. void __iomem *base = phy->reg_base;
  49. if (!enable) {
  50. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CAL_PWR_CFG, 0);
  51. return;
  52. }
  53. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_0, 0x0);
  54. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CAL_PWR_CFG, 1);
  55. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_5, 0);
  56. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_3, 0);
  57. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_2, 0x3);
  58. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_1, 0x9);
  59. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_0, 0x7);
  60. dsi_phy_write(base + REG_DSI_28nm_PHY_REGULATOR_CTRL_4, 0x20);
  61. }
  62. static int dsi_28nm_phy_enable(struct msm_dsi_phy *phy, int src_pll_id,
  63. const unsigned long bit_rate, const unsigned long esc_rate)
  64. {
  65. struct msm_dsi_dphy_timing *timing = &phy->timing;
  66. int i;
  67. void __iomem *base = phy->base;
  68. DBG("");
  69. if (msm_dsi_dphy_timing_calc(timing, bit_rate, esc_rate)) {
  70. dev_err(&phy->pdev->dev,
  71. "%s: D-PHY timing calculation failed\n", __func__);
  72. return -EINVAL;
  73. }
  74. dsi_phy_write(base + REG_DSI_28nm_PHY_STRENGTH_0, 0xff);
  75. dsi_28nm_phy_regulator_ctrl(phy, true);
  76. dsi_phy_write(base + REG_DSI_28nm_PHY_LDO_CNTRL, 0x00);
  77. dsi_28nm_dphy_set_timing(phy, timing);
  78. dsi_phy_write(base + REG_DSI_28nm_PHY_CTRL_1, 0x00);
  79. dsi_phy_write(base + REG_DSI_28nm_PHY_CTRL_0, 0x5f);
  80. dsi_phy_write(base + REG_DSI_28nm_PHY_STRENGTH_1, 0x6);
  81. for (i = 0; i < 4; i++) {
  82. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_0(i), 0);
  83. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_1(i), 0);
  84. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_2(i), 0);
  85. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_3(i), 0);
  86. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_CFG_4(i), 0);
  87. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_TEST_DATAPATH(i), 0);
  88. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_DEBUG_SEL(i), 0);
  89. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_TEST_STR_0(i), 0x1);
  90. dsi_phy_write(base + REG_DSI_28nm_PHY_LN_TEST_STR_1(i), 0x97);
  91. }
  92. dsi_phy_write(base + REG_DSI_28nm_PHY_LNCK_CFG_4, 0);
  93. dsi_phy_write(base + REG_DSI_28nm_PHY_LNCK_CFG_1, 0xc0);
  94. dsi_phy_write(base + REG_DSI_28nm_PHY_LNCK_TEST_STR0, 0x1);
  95. dsi_phy_write(base + REG_DSI_28nm_PHY_LNCK_TEST_STR1, 0xbb);
  96. dsi_phy_write(base + REG_DSI_28nm_PHY_CTRL_0, 0x5f);
  97. msm_dsi_phy_set_src_pll(phy, src_pll_id,
  98. REG_DSI_28nm_PHY_GLBL_TEST_CTRL,
  99. DSI_28nm_PHY_GLBL_TEST_CTRL_BITCLK_HS_SEL);
  100. return 0;
  101. }
  102. static void dsi_28nm_phy_disable(struct msm_dsi_phy *phy)
  103. {
  104. dsi_phy_write(phy->base + REG_DSI_28nm_PHY_CTRL_0, 0);
  105. dsi_28nm_phy_regulator_ctrl(phy, false);
  106. /*
  107. * Wait for the registers writes to complete in order to
  108. * ensure that the phy is completely disabled
  109. */
  110. wmb();
  111. }
  112. const struct msm_dsi_phy_cfg dsi_phy_28nm_hpm_cfgs = {
  113. .type = MSM_DSI_PHY_28NM_HPM,
  114. .src_pll_truthtable = { {true, true}, {false, true} },
  115. .reg_cfg = {
  116. .num = 1,
  117. .regs = {
  118. {"vddio", 1800000, 1800000, 100000, 100},
  119. },
  120. },
  121. .ops = {
  122. .enable = dsi_28nm_phy_enable,
  123. .disable = dsi_28nm_phy_disable,
  124. },
  125. };
  126. const struct msm_dsi_phy_cfg dsi_phy_28nm_lp_cfgs = {
  127. .type = MSM_DSI_PHY_28NM_LP,
  128. .src_pll_truthtable = { {true, true}, {true, true} },
  129. .reg_cfg = {
  130. .num = 1,
  131. .regs = {
  132. {"vddio", 1800000, 1800000, 100000, 100},
  133. },
  134. },
  135. .ops = {
  136. .enable = dsi_28nm_phy_enable,
  137. .disable = dsi_28nm_phy_disable,
  138. },
  139. };