hdmi.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <[email protected]>
  5. */
  6. #ifndef __HDMI_CONNECTOR_H__
  7. #define __HDMI_CONNECTOR_H__
  8. #include <linux/i2c.h>
  9. #include <linux/clk.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/regulator/consumer.h>
  12. #include <linux/gpio/consumer.h>
  13. #include <linux/hdmi.h>
  14. #include <drm/drm_bridge.h>
  15. #include "msm_drv.h"
  16. #include "hdmi.xml.h"
  17. struct hdmi_phy;
  18. struct hdmi_platform_config;
  19. struct hdmi_audio {
  20. bool enabled;
  21. struct hdmi_audio_infoframe infoframe;
  22. int rate;
  23. };
  24. struct hdmi_hdcp_ctrl;
  25. struct hdmi {
  26. struct drm_device *dev;
  27. struct platform_device *pdev;
  28. struct platform_device *audio_pdev;
  29. const struct hdmi_platform_config *config;
  30. /* audio state: */
  31. struct hdmi_audio audio;
  32. /* video state: */
  33. bool power_on;
  34. unsigned long int pixclock;
  35. void __iomem *mmio;
  36. void __iomem *qfprom_mmio;
  37. phys_addr_t mmio_phy_addr;
  38. struct regulator_bulk_data *hpd_regs;
  39. struct regulator_bulk_data *pwr_regs;
  40. struct clk **hpd_clks;
  41. struct clk **pwr_clks;
  42. struct gpio_desc *hpd_gpiod;
  43. struct hdmi_phy *phy;
  44. struct device *phy_dev;
  45. struct i2c_adapter *i2c;
  46. struct drm_connector *connector;
  47. struct drm_bridge *bridge;
  48. struct drm_bridge *next_bridge;
  49. /* the encoder we are hooked to (outside of hdmi block) */
  50. struct drm_encoder *encoder;
  51. bool hdmi_mode; /* are we in hdmi mode? */
  52. int irq;
  53. struct workqueue_struct *workq;
  54. struct hdmi_hdcp_ctrl *hdcp_ctrl;
  55. /*
  56. * spinlock to protect registers shared by different execution
  57. * REG_HDMI_CTRL
  58. * REG_HDMI_DDC_ARBITRATION
  59. * REG_HDMI_HDCP_INT_CTRL
  60. * REG_HDMI_HPD_CTRL
  61. */
  62. spinlock_t reg_lock;
  63. };
  64. /* platform config data (ie. from DT, or pdata) */
  65. struct hdmi_platform_config {
  66. const char *mmio_name;
  67. const char *qfprom_mmio_name;
  68. /* regulators that need to be on for hpd: */
  69. const char **hpd_reg_names;
  70. int hpd_reg_cnt;
  71. /* regulators that need to be on for screen pwr: */
  72. const char **pwr_reg_names;
  73. int pwr_reg_cnt;
  74. /* clks that need to be on for hpd: */
  75. const char **hpd_clk_names;
  76. const long unsigned *hpd_freq;
  77. int hpd_clk_cnt;
  78. /* clks that need to be on for screen pwr (ie pixel clk): */
  79. const char **pwr_clk_names;
  80. int pwr_clk_cnt;
  81. };
  82. struct hdmi_bridge {
  83. struct drm_bridge base;
  84. struct hdmi *hdmi;
  85. struct work_struct hpd_work;
  86. };
  87. #define to_hdmi_bridge(x) container_of(x, struct hdmi_bridge, base)
  88. void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on);
  89. static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
  90. {
  91. msm_writel(data, hdmi->mmio + reg);
  92. }
  93. static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
  94. {
  95. return msm_readl(hdmi->mmio + reg);
  96. }
  97. static inline u32 hdmi_qfprom_read(struct hdmi *hdmi, u32 reg)
  98. {
  99. return msm_readl(hdmi->qfprom_mmio + reg);
  100. }
  101. /*
  102. * hdmi phy:
  103. */
  104. enum hdmi_phy_type {
  105. MSM_HDMI_PHY_8x60,
  106. MSM_HDMI_PHY_8960,
  107. MSM_HDMI_PHY_8x74,
  108. MSM_HDMI_PHY_8996,
  109. MSM_HDMI_PHY_MAX,
  110. };
  111. struct hdmi_phy_cfg {
  112. enum hdmi_phy_type type;
  113. void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock);
  114. void (*powerdown)(struct hdmi_phy *phy);
  115. const char * const *reg_names;
  116. int num_regs;
  117. const char * const *clk_names;
  118. int num_clks;
  119. };
  120. extern const struct hdmi_phy_cfg msm_hdmi_phy_8x60_cfg;
  121. extern const struct hdmi_phy_cfg msm_hdmi_phy_8960_cfg;
  122. extern const struct hdmi_phy_cfg msm_hdmi_phy_8x74_cfg;
  123. extern const struct hdmi_phy_cfg msm_hdmi_phy_8996_cfg;
  124. struct hdmi_phy {
  125. struct platform_device *pdev;
  126. void __iomem *mmio;
  127. struct hdmi_phy_cfg *cfg;
  128. const struct hdmi_phy_funcs *funcs;
  129. struct regulator_bulk_data *regs;
  130. struct clk **clks;
  131. };
  132. static inline void hdmi_phy_write(struct hdmi_phy *phy, u32 reg, u32 data)
  133. {
  134. msm_writel(data, phy->mmio + reg);
  135. }
  136. static inline u32 hdmi_phy_read(struct hdmi_phy *phy, u32 reg)
  137. {
  138. return msm_readl(phy->mmio + reg);
  139. }
  140. int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy);
  141. void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy);
  142. void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock);
  143. void msm_hdmi_phy_powerdown(struct hdmi_phy *phy);
  144. void __init msm_hdmi_phy_driver_register(void);
  145. void __exit msm_hdmi_phy_driver_unregister(void);
  146. #ifdef CONFIG_COMMON_CLK
  147. int msm_hdmi_pll_8960_init(struct platform_device *pdev);
  148. int msm_hdmi_pll_8996_init(struct platform_device *pdev);
  149. #else
  150. static inline int msm_hdmi_pll_8960_init(struct platform_device *pdev)
  151. {
  152. return -ENODEV;
  153. }
  154. static inline int msm_hdmi_pll_8996_init(struct platform_device *pdev)
  155. {
  156. return -ENODEV;
  157. }
  158. #endif
  159. /*
  160. * audio:
  161. */
  162. /* Supported HDMI Audio channels and rates */
  163. #define MSM_HDMI_AUDIO_CHANNEL_2 0
  164. #define MSM_HDMI_AUDIO_CHANNEL_4 1
  165. #define MSM_HDMI_AUDIO_CHANNEL_6 2
  166. #define MSM_HDMI_AUDIO_CHANNEL_8 3
  167. #define HDMI_SAMPLE_RATE_32KHZ 0
  168. #define HDMI_SAMPLE_RATE_44_1KHZ 1
  169. #define HDMI_SAMPLE_RATE_48KHZ 2
  170. #define HDMI_SAMPLE_RATE_88_2KHZ 3
  171. #define HDMI_SAMPLE_RATE_96KHZ 4
  172. #define HDMI_SAMPLE_RATE_176_4KHZ 5
  173. #define HDMI_SAMPLE_RATE_192KHZ 6
  174. int msm_hdmi_audio_update(struct hdmi *hdmi);
  175. int msm_hdmi_audio_info_setup(struct hdmi *hdmi, bool enabled,
  176. uint32_t num_of_channels, uint32_t channel_allocation,
  177. uint32_t level_shift, bool down_mix);
  178. void msm_hdmi_audio_set_sample_rate(struct hdmi *hdmi, int rate);
  179. /*
  180. * hdmi bridge:
  181. */
  182. struct drm_bridge *msm_hdmi_bridge_init(struct hdmi *hdmi);
  183. void msm_hdmi_bridge_destroy(struct drm_bridge *bridge);
  184. void msm_hdmi_hpd_irq(struct drm_bridge *bridge);
  185. enum drm_connector_status msm_hdmi_bridge_detect(
  186. struct drm_bridge *bridge);
  187. int msm_hdmi_hpd_enable(struct drm_bridge *bridge);
  188. void msm_hdmi_hpd_disable(struct hdmi_bridge *hdmi_bridge);
  189. /*
  190. * i2c adapter for ddc:
  191. */
  192. void msm_hdmi_i2c_irq(struct i2c_adapter *i2c);
  193. void msm_hdmi_i2c_destroy(struct i2c_adapter *i2c);
  194. struct i2c_adapter *msm_hdmi_i2c_init(struct hdmi *hdmi);
  195. /*
  196. * hdcp
  197. */
  198. #ifdef CONFIG_DRM_MSM_HDMI_HDCP
  199. struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi);
  200. void msm_hdmi_hdcp_destroy(struct hdmi *hdmi);
  201. void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl);
  202. void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl);
  203. void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl);
  204. #else
  205. static inline struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi)
  206. {
  207. return ERR_PTR(-ENXIO);
  208. }
  209. static inline void msm_hdmi_hdcp_destroy(struct hdmi *hdmi) {}
  210. static inline void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
  211. static inline void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
  212. static inline void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
  213. #endif
  214. #endif /* __HDMI_CONNECTOR_H__ */