hdmi_phy_8x60.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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_8x60 {
  19. struct hdmi_phy base;
  20. struct hdmi *hdmi;
  21. };
  22. #define to_hdmi_phy_8x60(x) container_of(x, struct hdmi_phy_8x60, base)
  23. static void hdmi_phy_8x60_destroy(struct hdmi_phy *phy)
  24. {
  25. struct hdmi_phy_8x60 *phy_8x60 = to_hdmi_phy_8x60(phy);
  26. kfree(phy_8x60);
  27. }
  28. static void hdmi_phy_8x60_powerup(struct hdmi_phy *phy,
  29. unsigned long int pixclock)
  30. {
  31. struct hdmi_phy_8x60 *phy_8x60 = to_hdmi_phy_8x60(phy);
  32. struct hdmi *hdmi = phy_8x60->hdmi;
  33. /* De-serializer delay D/C for non-lbk mode: */
  34. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG0,
  35. HDMI_8x60_PHY_REG0_DESER_DEL_CTRL(3));
  36. if (pixclock == 27000000) {
  37. /* video_format == HDMI_VFRMT_720x480p60_16_9 */
  38. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG1,
  39. HDMI_8x60_PHY_REG1_DTEST_MUX_SEL(5) |
  40. HDMI_8x60_PHY_REG1_OUTVOL_SWING_CTRL(3));
  41. } else {
  42. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG1,
  43. HDMI_8x60_PHY_REG1_DTEST_MUX_SEL(5) |
  44. HDMI_8x60_PHY_REG1_OUTVOL_SWING_CTRL(4));
  45. }
  46. /* No matter what, start from the power down mode: */
  47. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG2,
  48. HDMI_8x60_PHY_REG2_PD_PWRGEN |
  49. HDMI_8x60_PHY_REG2_PD_PLL |
  50. HDMI_8x60_PHY_REG2_PD_DRIVE_4 |
  51. HDMI_8x60_PHY_REG2_PD_DRIVE_3 |
  52. HDMI_8x60_PHY_REG2_PD_DRIVE_2 |
  53. HDMI_8x60_PHY_REG2_PD_DRIVE_1 |
  54. HDMI_8x60_PHY_REG2_PD_DESER);
  55. /* Turn PowerGen on: */
  56. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG2,
  57. HDMI_8x60_PHY_REG2_PD_PLL |
  58. HDMI_8x60_PHY_REG2_PD_DRIVE_4 |
  59. HDMI_8x60_PHY_REG2_PD_DRIVE_3 |
  60. HDMI_8x60_PHY_REG2_PD_DRIVE_2 |
  61. HDMI_8x60_PHY_REG2_PD_DRIVE_1 |
  62. HDMI_8x60_PHY_REG2_PD_DESER);
  63. /* Turn PLL power on: */
  64. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG2,
  65. HDMI_8x60_PHY_REG2_PD_DRIVE_4 |
  66. HDMI_8x60_PHY_REG2_PD_DRIVE_3 |
  67. HDMI_8x60_PHY_REG2_PD_DRIVE_2 |
  68. HDMI_8x60_PHY_REG2_PD_DRIVE_1 |
  69. HDMI_8x60_PHY_REG2_PD_DESER);
  70. /* Write to HIGH after PLL power down de-assert: */
  71. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG3,
  72. HDMI_8x60_PHY_REG3_PLL_ENABLE);
  73. /* ASIC power on; PHY REG9 = 0 */
  74. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG9, 0);
  75. /* Enable PLL lock detect, PLL lock det will go high after lock
  76. * Enable the re-time logic
  77. */
  78. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG12,
  79. HDMI_8x60_PHY_REG12_RETIMING_EN |
  80. HDMI_8x60_PHY_REG12_PLL_LOCK_DETECT_EN);
  81. /* Drivers are on: */
  82. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG2,
  83. HDMI_8x60_PHY_REG2_PD_DESER);
  84. /* If the RX detector is needed: */
  85. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG2,
  86. HDMI_8x60_PHY_REG2_RCV_SENSE_EN |
  87. HDMI_8x60_PHY_REG2_PD_DESER);
  88. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG4, 0);
  89. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG5, 0);
  90. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG6, 0);
  91. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG7, 0);
  92. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG8, 0);
  93. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG9, 0);
  94. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG10, 0);
  95. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG11, 0);
  96. /* If we want to use lock enable based on counting: */
  97. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG12,
  98. HDMI_8x60_PHY_REG12_RETIMING_EN |
  99. HDMI_8x60_PHY_REG12_PLL_LOCK_DETECT_EN |
  100. HDMI_8x60_PHY_REG12_FORCE_LOCK);
  101. }
  102. static void hdmi_phy_8x60_powerdown(struct hdmi_phy *phy)
  103. {
  104. struct hdmi_phy_8x60 *phy_8x60 = to_hdmi_phy_8x60(phy);
  105. struct hdmi *hdmi = phy_8x60->hdmi;
  106. /* Assert RESET PHY from controller */
  107. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  108. HDMI_PHY_CTRL_SW_RESET);
  109. udelay(10);
  110. /* De-assert RESET PHY from controller */
  111. hdmi_write(hdmi, REG_HDMI_PHY_CTRL, 0);
  112. /* Turn off Driver */
  113. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG2,
  114. HDMI_8x60_PHY_REG2_PD_DRIVE_4 |
  115. HDMI_8x60_PHY_REG2_PD_DRIVE_3 |
  116. HDMI_8x60_PHY_REG2_PD_DRIVE_2 |
  117. HDMI_8x60_PHY_REG2_PD_DRIVE_1 |
  118. HDMI_8x60_PHY_REG2_PD_DESER);
  119. udelay(10);
  120. /* Disable PLL */
  121. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG3, 0);
  122. /* Power down PHY, but keep RX-sense: */
  123. hdmi_write(hdmi, REG_HDMI_8x60_PHY_REG2,
  124. HDMI_8x60_PHY_REG2_RCV_SENSE_EN |
  125. HDMI_8x60_PHY_REG2_PD_PWRGEN |
  126. HDMI_8x60_PHY_REG2_PD_PLL |
  127. HDMI_8x60_PHY_REG2_PD_DRIVE_4 |
  128. HDMI_8x60_PHY_REG2_PD_DRIVE_3 |
  129. HDMI_8x60_PHY_REG2_PD_DRIVE_2 |
  130. HDMI_8x60_PHY_REG2_PD_DRIVE_1 |
  131. HDMI_8x60_PHY_REG2_PD_DESER);
  132. }
  133. static const struct hdmi_phy_funcs hdmi_phy_8x60_funcs = {
  134. .destroy = hdmi_phy_8x60_destroy,
  135. .powerup = hdmi_phy_8x60_powerup,
  136. .powerdown = hdmi_phy_8x60_powerdown,
  137. };
  138. struct hdmi_phy *hdmi_phy_8x60_init(struct hdmi *hdmi)
  139. {
  140. struct hdmi_phy_8x60 *phy_8x60;
  141. struct hdmi_phy *phy = NULL;
  142. int ret;
  143. phy_8x60 = kzalloc(sizeof(*phy_8x60), GFP_KERNEL);
  144. if (!phy_8x60) {
  145. ret = -ENOMEM;
  146. goto fail;
  147. }
  148. phy = &phy_8x60->base;
  149. phy->funcs = &hdmi_phy_8x60_funcs;
  150. phy_8x60->hdmi = hdmi;
  151. return phy;
  152. fail:
  153. if (phy)
  154. hdmi_phy_8x60_destroy(phy);
  155. return ERR_PTR(ret);
  156. }