edp_phy.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) 2014-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 "edp.h"
  14. #include "edp.xml.h"
  15. #define EDP_MAX_LANE 4
  16. struct edp_phy {
  17. void __iomem *base;
  18. };
  19. bool msm_edp_phy_ready(struct edp_phy *phy)
  20. {
  21. u32 status;
  22. int cnt = 100;
  23. while (--cnt) {
  24. status = edp_read(phy->base +
  25. REG_EDP_PHY_GLB_PHY_STATUS);
  26. if (status & 0x01)
  27. break;
  28. usleep_range(500, 1000);
  29. }
  30. if (cnt == 0) {
  31. pr_err("%s: PHY NOT ready\n", __func__);
  32. return false;
  33. } else {
  34. return true;
  35. }
  36. }
  37. void msm_edp_phy_ctrl(struct edp_phy *phy, int enable)
  38. {
  39. DBG("enable=%d", enable);
  40. if (enable) {
  41. /* Reset */
  42. edp_write(phy->base + REG_EDP_PHY_CTRL,
  43. EDP_PHY_CTRL_SW_RESET | EDP_PHY_CTRL_SW_RESET_PLL);
  44. /* Make sure fully reset */
  45. wmb();
  46. usleep_range(500, 1000);
  47. edp_write(phy->base + REG_EDP_PHY_CTRL, 0x000);
  48. edp_write(phy->base + REG_EDP_PHY_GLB_PD_CTL, 0x3f);
  49. edp_write(phy->base + REG_EDP_PHY_GLB_CFG, 0x1);
  50. } else {
  51. edp_write(phy->base + REG_EDP_PHY_GLB_PD_CTL, 0xc0);
  52. }
  53. }
  54. /* voltage mode and pre emphasis cfg */
  55. void msm_edp_phy_vm_pe_init(struct edp_phy *phy)
  56. {
  57. edp_write(phy->base + REG_EDP_PHY_GLB_VM_CFG0, 0x3);
  58. edp_write(phy->base + REG_EDP_PHY_GLB_VM_CFG1, 0x64);
  59. edp_write(phy->base + REG_EDP_PHY_GLB_MISC9, 0x6c);
  60. }
  61. void msm_edp_phy_vm_pe_cfg(struct edp_phy *phy, u32 v0, u32 v1)
  62. {
  63. edp_write(phy->base + REG_EDP_PHY_GLB_VM_CFG0, v0);
  64. edp_write(phy->base + REG_EDP_PHY_GLB_VM_CFG1, v1);
  65. }
  66. void msm_edp_phy_lane_power_ctrl(struct edp_phy *phy, bool up, u32 max_lane)
  67. {
  68. u32 i;
  69. u32 data;
  70. if (up)
  71. data = 0; /* power up */
  72. else
  73. data = 0x7; /* power down */
  74. for (i = 0; i < max_lane; i++)
  75. edp_write(phy->base + REG_EDP_PHY_LN_PD_CTL(i) , data);
  76. /* power down unused lane */
  77. data = 0x7; /* power down */
  78. for (i = max_lane; i < EDP_MAX_LANE; i++)
  79. edp_write(phy->base + REG_EDP_PHY_LN_PD_CTL(i) , data);
  80. }
  81. void *msm_edp_phy_init(struct device *dev, void __iomem *regbase)
  82. {
  83. struct edp_phy *phy = NULL;
  84. phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
  85. if (!phy)
  86. return NULL;
  87. phy->base = regbase;
  88. return phy;
  89. }