hdmi.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. #define HDMI_MAX_NUM_GPIO 6
  27. struct hdmi_phy;
  28. struct hdmi_platform_config;
  29. struct hdmi_gpio_data {
  30. int num;
  31. bool output;
  32. int value;
  33. const char *label;
  34. };
  35. struct hdmi_audio {
  36. bool enabled;
  37. struct hdmi_audio_infoframe infoframe;
  38. int rate;
  39. };
  40. struct hdmi_hdcp_ctrl;
  41. struct hdmi {
  42. struct drm_device *dev;
  43. struct platform_device *pdev;
  44. const struct hdmi_platform_config *config;
  45. /* audio state: */
  46. struct hdmi_audio audio;
  47. /* video state: */
  48. bool power_on;
  49. unsigned long int pixclock;
  50. void __iomem *mmio;
  51. void __iomem *qfprom_mmio;
  52. phys_addr_t mmio_phy_addr;
  53. struct regulator **hpd_regs;
  54. struct regulator **pwr_regs;
  55. struct clk **hpd_clks;
  56. struct clk **pwr_clks;
  57. struct hdmi_phy *phy;
  58. struct device *phy_dev;
  59. struct i2c_adapter *i2c;
  60. struct drm_connector *connector;
  61. struct drm_bridge *bridge;
  62. /* the encoder we are hooked to (outside of hdmi block) */
  63. struct drm_encoder *encoder;
  64. bool hdmi_mode; /* are we in hdmi mode? */
  65. int irq;
  66. struct workqueue_struct *workq;
  67. struct hdmi_hdcp_ctrl *hdcp_ctrl;
  68. /*
  69. * spinlock to protect registers shared by different execution
  70. * REG_HDMI_CTRL
  71. * REG_HDMI_DDC_ARBITRATION
  72. * REG_HDMI_HDCP_INT_CTRL
  73. * REG_HDMI_HPD_CTRL
  74. */
  75. spinlock_t reg_lock;
  76. };
  77. /* platform config data (ie. from DT, or pdata) */
  78. struct hdmi_platform_config {
  79. const char *mmio_name;
  80. const char *qfprom_mmio_name;
  81. /* regulators that need to be on for hpd: */
  82. const char **hpd_reg_names;
  83. int hpd_reg_cnt;
  84. /* regulators that need to be on for screen pwr: */
  85. const char **pwr_reg_names;
  86. int pwr_reg_cnt;
  87. /* clks that need to be on for hpd: */
  88. const char **hpd_clk_names;
  89. const long unsigned *hpd_freq;
  90. int hpd_clk_cnt;
  91. /* clks that need to be on for screen pwr (ie pixel clk): */
  92. const char **pwr_clk_names;
  93. int pwr_clk_cnt;
  94. /* gpio's: */
  95. struct hdmi_gpio_data gpios[HDMI_MAX_NUM_GPIO];
  96. };
  97. void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on);
  98. static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
  99. {
  100. msm_writel(data, hdmi->mmio + reg);
  101. }
  102. static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
  103. {
  104. return msm_readl(hdmi->mmio + reg);
  105. }
  106. static inline u32 hdmi_qfprom_read(struct hdmi *hdmi, u32 reg)
  107. {
  108. return msm_readl(hdmi->qfprom_mmio + reg);
  109. }
  110. /*
  111. * hdmi phy:
  112. */
  113. enum hdmi_phy_type {
  114. MSM_HDMI_PHY_8x60,
  115. MSM_HDMI_PHY_8960,
  116. MSM_HDMI_PHY_8x74,
  117. MSM_HDMI_PHY_8996,
  118. MSM_HDMI_PHY_MAX,
  119. };
  120. struct hdmi_phy_cfg {
  121. enum hdmi_phy_type type;
  122. void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock);
  123. void (*powerdown)(struct hdmi_phy *phy);
  124. const char * const *reg_names;
  125. int num_regs;
  126. const char * const *clk_names;
  127. int num_clks;
  128. };
  129. extern const struct hdmi_phy_cfg msm_hdmi_phy_8x60_cfg;
  130. extern const struct hdmi_phy_cfg msm_hdmi_phy_8960_cfg;
  131. extern const struct hdmi_phy_cfg msm_hdmi_phy_8x74_cfg;
  132. extern const struct hdmi_phy_cfg msm_hdmi_phy_8996_cfg;
  133. struct hdmi_phy {
  134. struct platform_device *pdev;
  135. void __iomem *mmio;
  136. struct hdmi_phy_cfg *cfg;
  137. const struct hdmi_phy_funcs *funcs;
  138. struct regulator **regs;
  139. struct clk **clks;
  140. };
  141. static inline void hdmi_phy_write(struct hdmi_phy *phy, u32 reg, u32 data)
  142. {
  143. msm_writel(data, phy->mmio + reg);
  144. }
  145. static inline u32 hdmi_phy_read(struct hdmi_phy *phy, u32 reg)
  146. {
  147. return msm_readl(phy->mmio + reg);
  148. }
  149. int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy);
  150. void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy);
  151. void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock);
  152. void msm_hdmi_phy_powerdown(struct hdmi_phy *phy);
  153. void __init msm_hdmi_phy_driver_register(void);
  154. void __exit msm_hdmi_phy_driver_unregister(void);
  155. #ifdef CONFIG_COMMON_CLK
  156. int msm_hdmi_pll_8960_init(struct platform_device *pdev);
  157. int msm_hdmi_pll_8996_init(struct platform_device *pdev);
  158. #else
  159. static inline int msm_hdmi_pll_8960_init(struct platform_device *pdev)
  160. {
  161. return -ENODEV;
  162. }
  163. static inline int msm_hdmi_pll_8996_init(struct platform_device *pdev)
  164. {
  165. return -ENODEV;
  166. }
  167. #endif
  168. /*
  169. * audio:
  170. */
  171. int msm_hdmi_audio_update(struct hdmi *hdmi);
  172. int msm_hdmi_audio_info_setup(struct hdmi *hdmi, bool enabled,
  173. uint32_t num_of_channels, uint32_t channel_allocation,
  174. uint32_t level_shift, bool down_mix);
  175. void msm_hdmi_audio_set_sample_rate(struct hdmi *hdmi, int rate);
  176. /*
  177. * hdmi bridge:
  178. */
  179. struct drm_bridge *msm_hdmi_bridge_init(struct hdmi *hdmi);
  180. void msm_hdmi_bridge_destroy(struct drm_bridge *bridge);
  181. /*
  182. * hdmi connector:
  183. */
  184. void msm_hdmi_connector_irq(struct drm_connector *connector);
  185. struct drm_connector *msm_hdmi_connector_init(struct hdmi *hdmi);
  186. /*
  187. * i2c adapter for ddc:
  188. */
  189. void msm_hdmi_i2c_irq(struct i2c_adapter *i2c);
  190. void msm_hdmi_i2c_destroy(struct i2c_adapter *i2c);
  191. struct i2c_adapter *msm_hdmi_i2c_init(struct hdmi *hdmi);
  192. /*
  193. * hdcp
  194. */
  195. struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi);
  196. void msm_hdmi_hdcp_destroy(struct hdmi *hdmi);
  197. void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl);
  198. void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl);
  199. void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl);
  200. #endif /* __HDMI_CONNECTOR_H__ */