hdmi_phy_8960.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_8960 {
  19. struct hdmi_phy base;
  20. struct hdmi *hdmi;
  21. };
  22. #define to_hdmi_phy_8960(x) container_of(x, struct hdmi_phy_8960, base)
  23. static void hdmi_phy_8960_destroy(struct hdmi_phy *phy)
  24. {
  25. struct hdmi_phy_8960 *phy_8960 = to_hdmi_phy_8960(phy);
  26. kfree(phy_8960);
  27. }
  28. static void hdmi_phy_8960_reset(struct hdmi_phy *phy)
  29. {
  30. struct hdmi_phy_8960 *phy_8960 = to_hdmi_phy_8960(phy);
  31. struct hdmi *hdmi = phy_8960->hdmi;
  32. unsigned int val;
  33. val = hdmi_read(hdmi, REG_HDMI_PHY_CTRL);
  34. if (val & HDMI_PHY_CTRL_SW_RESET_LOW) {
  35. /* pull low */
  36. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  37. val & ~HDMI_PHY_CTRL_SW_RESET);
  38. } else {
  39. /* pull high */
  40. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  41. val | HDMI_PHY_CTRL_SW_RESET);
  42. }
  43. if (val & HDMI_PHY_CTRL_SW_RESET_PLL_LOW) {
  44. /* pull low */
  45. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  46. val & ~HDMI_PHY_CTRL_SW_RESET_PLL);
  47. } else {
  48. /* pull high */
  49. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  50. val | HDMI_PHY_CTRL_SW_RESET_PLL);
  51. }
  52. msleep(100);
  53. if (val & HDMI_PHY_CTRL_SW_RESET_LOW) {
  54. /* pull high */
  55. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  56. val | HDMI_PHY_CTRL_SW_RESET);
  57. } else {
  58. /* pull low */
  59. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  60. val & ~HDMI_PHY_CTRL_SW_RESET);
  61. }
  62. if (val & HDMI_PHY_CTRL_SW_RESET_PLL_LOW) {
  63. /* pull high */
  64. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  65. val | HDMI_PHY_CTRL_SW_RESET_PLL);
  66. } else {
  67. /* pull low */
  68. hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
  69. val & ~HDMI_PHY_CTRL_SW_RESET_PLL);
  70. }
  71. }
  72. static void hdmi_phy_8960_powerup(struct hdmi_phy *phy,
  73. unsigned long int pixclock)
  74. {
  75. struct hdmi_phy_8960 *phy_8960 = to_hdmi_phy_8960(phy);
  76. struct hdmi *hdmi = phy_8960->hdmi;
  77. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG0, 0x1b);
  78. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG1, 0xf2);
  79. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG4, 0x00);
  80. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG5, 0x00);
  81. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG6, 0x00);
  82. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG7, 0x00);
  83. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG8, 0x00);
  84. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG9, 0x00);
  85. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG10, 0x00);
  86. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG11, 0x00);
  87. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG3, 0x20);
  88. }
  89. static void hdmi_phy_8960_powerdown(struct hdmi_phy *phy)
  90. {
  91. struct hdmi_phy_8960 *phy_8960 = to_hdmi_phy_8960(phy);
  92. struct hdmi *hdmi = phy_8960->hdmi;
  93. hdmi_write(hdmi, REG_HDMI_8960_PHY_REG2, 0x7f);
  94. }
  95. static const struct hdmi_phy_funcs hdmi_phy_8960_funcs = {
  96. .destroy = hdmi_phy_8960_destroy,
  97. .reset = hdmi_phy_8960_reset,
  98. .powerup = hdmi_phy_8960_powerup,
  99. .powerdown = hdmi_phy_8960_powerdown,
  100. };
  101. struct hdmi_phy *hdmi_phy_8960_init(struct hdmi *hdmi)
  102. {
  103. struct hdmi_phy_8960 *phy_8960;
  104. struct hdmi_phy *phy = NULL;
  105. int ret;
  106. phy_8960 = kzalloc(sizeof(*phy_8960), GFP_KERNEL);
  107. if (!phy_8960) {
  108. ret = -ENOMEM;
  109. goto fail;
  110. }
  111. phy = &phy_8960->base;
  112. phy->funcs = &hdmi_phy_8960_funcs;
  113. phy_8960->hdmi = hdmi;
  114. return phy;
  115. fail:
  116. if (phy)
  117. hdmi_phy_8960_destroy(phy);
  118. return ERR_PTR(ret);
  119. }