hdmi_phy_8x74.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "hdmi.h"
  18. struct hdmi_phy_8x74 {
  19. struct hdmi_phy base;
  20. struct hdmi *hdmi;
  21. void __iomem *mmio;
  22. };
  23. #define to_hdmi_phy_8x74(x) container_of(x, struct hdmi_phy_8x74, base)
  24. static void phy_write(struct hdmi_phy_8x74 *phy, u32 reg, u32 data)
  25. {
  26. msm_writel(data, phy->mmio + reg);
  27. }
  28. //static u32 phy_read(struct hdmi_phy_8x74 *phy, u32 reg)
  29. //{
  30. // return msm_readl(phy->mmio + reg);
  31. //}
  32. static void hdmi_phy_8x74_destroy(struct hdmi_phy *phy)
  33. {
  34. struct hdmi_phy_8x74 *phy_8x74 = to_hdmi_phy_8x74(phy);
  35. kfree(phy_8x74);
  36. }
  37. static void hdmi_phy_8x74_reset(struct hdmi_phy *phy)
  38. {
  39. struct hdmi_phy_8x74 *phy_8x74 = to_hdmi_phy_8x74(phy);
  40. struct hdmi *hdmi = phy_8x74->hdmi;
  41. unsigned int val;
  42. /* NOTE that HDMI_PHY_CTL is in core mmio, not phy mmio: */
  43. val = hdmi_read(hdmi, REG_HDMI_PHY_CTRL);
  44. if (val & HDMI_PHY_CTRL_SW_RESET_LOW) {
  45. /* pull low */
  46. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  47. val & ~HDMI_PHY_CTRL_SW_RESET);
  48. } else {
  49. /* pull high */
  50. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  51. val | HDMI_PHY_CTRL_SW_RESET);
  52. }
  53. if (val & HDMI_PHY_CTRL_SW_RESET_PLL_LOW) {
  54. /* pull low */
  55. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  56. val & ~HDMI_PHY_CTRL_SW_RESET_PLL);
  57. } else {
  58. /* pull high */
  59. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  60. val | HDMI_PHY_CTRL_SW_RESET_PLL);
  61. }
  62. msleep(100);
  63. if (val & HDMI_PHY_CTRL_SW_RESET_LOW) {
  64. /* pull high */
  65. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  66. val | HDMI_PHY_CTRL_SW_RESET);
  67. } else {
  68. /* pull low */
  69. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  70. val & ~HDMI_PHY_CTRL_SW_RESET);
  71. }
  72. if (val & HDMI_PHY_CTRL_SW_RESET_PLL_LOW) {
  73. /* pull high */
  74. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  75. val | HDMI_PHY_CTRL_SW_RESET_PLL);
  76. } else {
  77. /* pull low */
  78. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  79. val & ~HDMI_PHY_CTRL_SW_RESET_PLL);
  80. }
  81. }
  82. static void hdmi_phy_8x74_powerup(struct hdmi_phy *phy,
  83. unsigned long int pixclock)
  84. {
  85. struct hdmi_phy_8x74 *phy_8x74 = to_hdmi_phy_8x74(phy);
  86. phy_write(phy_8x74, REG_HDMI_8x74_ANA_CFG0, 0x1b);
  87. phy_write(phy_8x74, REG_HDMI_8x74_ANA_CFG1, 0xf2);
  88. phy_write(phy_8x74, REG_HDMI_8x74_BIST_CFG0, 0x0);
  89. phy_write(phy_8x74, REG_HDMI_8x74_BIST_PATN0, 0x0);
  90. phy_write(phy_8x74, REG_HDMI_8x74_BIST_PATN1, 0x0);
  91. phy_write(phy_8x74, REG_HDMI_8x74_BIST_PATN2, 0x0);
  92. phy_write(phy_8x74, REG_HDMI_8x74_BIST_PATN3, 0x0);
  93. phy_write(phy_8x74, REG_HDMI_8x74_PD_CTRL1, 0x20);
  94. }
  95. static void hdmi_phy_8x74_powerdown(struct hdmi_phy *phy)
  96. {
  97. struct hdmi_phy_8x74 *phy_8x74 = to_hdmi_phy_8x74(phy);
  98. phy_write(phy_8x74, REG_HDMI_8x74_PD_CTRL0, 0x7f);
  99. }
  100. static const struct hdmi_phy_funcs hdmi_phy_8x74_funcs = {
  101. .destroy = hdmi_phy_8x74_destroy,
  102. .reset = hdmi_phy_8x74_reset,
  103. .powerup = hdmi_phy_8x74_powerup,
  104. .powerdown = hdmi_phy_8x74_powerdown,
  105. };
  106. struct hdmi_phy *hdmi_phy_8x74_init(struct hdmi *hdmi)
  107. {
  108. struct hdmi_phy_8x74 *phy_8x74;
  109. struct hdmi_phy *phy = NULL;
  110. int ret;
  111. phy_8x74 = kzalloc(sizeof(*phy_8x74), GFP_KERNEL);
  112. if (!phy_8x74) {
  113. ret = -ENOMEM;
  114. goto fail;
  115. }
  116. phy = &phy_8x74->base;
  117. phy->funcs = &hdmi_phy_8x74_funcs;
  118. phy_8x74->hdmi = hdmi;
  119. /* for 8x74, the phy mmio is mapped separately: */
  120. phy_8x74->mmio = msm_ioremap(hdmi->pdev,
  121. "phy_physical", "HDMI_8x74");
  122. if (IS_ERR(phy_8x74->mmio)) {
  123. ret = PTR_ERR(phy_8x74->mmio);
  124. goto fail;
  125. }
  126. return phy;
  127. fail:
  128. if (phy)
  129. hdmi_phy_8x74_destroy(phy);
  130. return ERR_PTR(ret);
  131. }