hdmi.h 6.7 KB

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