hdmi.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #ifndef __HDMI_CONNECTOR_H__
  18. #define __HDMI_CONNECTOR_H__
  19. #include <linux/i2c.h>
  20. #include <linux/clk.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/regulator/consumer.h>
  23. #include <linux/hdmi.h>
  24. #include "msm_drv.h"
  25. #include "hdmi.xml.h"
  26. struct hdmi_phy;
  27. struct hdmi_platform_config;
  28. struct hdmi_audio {
  29. bool enabled;
  30. struct hdmi_audio_infoframe infoframe;
  31. int rate;
  32. };
  33. struct hdmi {
  34. struct kref refcount;
  35. struct drm_device *dev;
  36. struct platform_device *pdev;
  37. const struct hdmi_platform_config *config;
  38. /* audio state: */
  39. struct hdmi_audio audio;
  40. /* video state: */
  41. bool power_on;
  42. unsigned long int pixclock;
  43. void __iomem *mmio;
  44. struct regulator *hpd_regs[2];
  45. struct regulator *pwr_regs[2];
  46. struct clk *hpd_clks[3];
  47. struct clk *pwr_clks[2];
  48. struct hdmi_phy *phy;
  49. struct i2c_adapter *i2c;
  50. struct drm_connector *connector;
  51. struct drm_bridge *bridge;
  52. /* the encoder we are hooked to (outside of hdmi block) */
  53. struct drm_encoder *encoder;
  54. bool hdmi_mode; /* are we in hdmi mode? */
  55. int irq;
  56. };
  57. /* platform config data (ie. from DT, or pdata) */
  58. struct hdmi_platform_config {
  59. struct hdmi_phy *(*phy_init)(struct hdmi *hdmi);
  60. const char *mmio_name;
  61. /* regulators that need to be on for hpd: */
  62. const char **hpd_reg_names;
  63. int hpd_reg_cnt;
  64. /* regulators that need to be on for screen pwr: */
  65. const char **pwr_reg_names;
  66. int pwr_reg_cnt;
  67. /* clks that need to be on for hpd: */
  68. const char **hpd_clk_names;
  69. const long unsigned *hpd_freq;
  70. int hpd_clk_cnt;
  71. /* clks that need to be on for screen pwr (ie pixel clk): */
  72. const char **pwr_clk_names;
  73. int pwr_clk_cnt;
  74. /* gpio's: */
  75. int ddc_clk_gpio, ddc_data_gpio, hpd_gpio, mux_en_gpio, mux_sel_gpio;
  76. /* older devices had their own irq, mdp5+ it is shared w/ mdp: */
  77. bool shared_irq;
  78. };
  79. void hdmi_set_mode(struct hdmi *hdmi, bool power_on);
  80. void hdmi_destroy(struct kref *kref);
  81. static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
  82. {
  83. msm_writel(data, hdmi->mmio + reg);
  84. }
  85. static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
  86. {
  87. return msm_readl(hdmi->mmio + reg);
  88. }
  89. static inline struct hdmi * hdmi_reference(struct hdmi *hdmi)
  90. {
  91. kref_get(&hdmi->refcount);
  92. return hdmi;
  93. }
  94. static inline void hdmi_unreference(struct hdmi *hdmi)
  95. {
  96. kref_put(&hdmi->refcount, hdmi_destroy);
  97. }
  98. /*
  99. * The phy appears to be different, for example between 8960 and 8x60,
  100. * so split the phy related functions out and load the correct one at
  101. * runtime:
  102. */
  103. struct hdmi_phy_funcs {
  104. void (*destroy)(struct hdmi_phy *phy);
  105. void (*reset)(struct hdmi_phy *phy);
  106. void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock);
  107. void (*powerdown)(struct hdmi_phy *phy);
  108. };
  109. struct hdmi_phy {
  110. const struct hdmi_phy_funcs *funcs;
  111. };
  112. struct hdmi_phy *hdmi_phy_8960_init(struct hdmi *hdmi);
  113. struct hdmi_phy *hdmi_phy_8x60_init(struct hdmi *hdmi);
  114. struct hdmi_phy *hdmi_phy_8x74_init(struct hdmi *hdmi);
  115. /*
  116. * audio:
  117. */
  118. int hdmi_audio_update(struct hdmi *hdmi);
  119. int hdmi_audio_info_setup(struct hdmi *hdmi, bool enabled,
  120. uint32_t num_of_channels, uint32_t channel_allocation,
  121. uint32_t level_shift, bool down_mix);
  122. void hdmi_audio_set_sample_rate(struct hdmi *hdmi, int rate);
  123. /*
  124. * hdmi bridge:
  125. */
  126. struct drm_bridge *hdmi_bridge_init(struct hdmi *hdmi);
  127. /*
  128. * hdmi connector:
  129. */
  130. void hdmi_connector_irq(struct drm_connector *connector);
  131. struct drm_connector *hdmi_connector_init(struct hdmi *hdmi);
  132. /*
  133. * i2c adapter for ddc:
  134. */
  135. void hdmi_i2c_irq(struct i2c_adapter *i2c);
  136. void hdmi_i2c_destroy(struct i2c_adapter *i2c);
  137. struct i2c_adapter *hdmi_i2c_init(struct hdmi *hdmi);
  138. #endif /* __HDMI_CONNECTOR_H__ */