hdmi.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  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. int rate;
  22. int channels;
  23. };
  24. struct hdmi_hdcp_ctrl;
  25. struct hdmi {
  26. struct drm_device *dev;
  27. struct platform_device *pdev;
  28. const struct hdmi_platform_config *config;
  29. /* audio state: */
  30. struct hdmi_audio audio;
  31. /* video state: */
  32. bool power_on;
  33. bool hpd_enabled;
  34. struct mutex state_mutex; /* protects two booleans */
  35. unsigned long int pixclock;
  36. void __iomem *mmio;
  37. void __iomem *qfprom_mmio;
  38. phys_addr_t mmio_phy_addr;
  39. struct regulator_bulk_data *pwr_regs;
  40. struct clk_bulk_data *pwr_clks;
  41. struct clk *extp_clk;
  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. int irq;
  52. struct workqueue_struct *workq;
  53. struct hdmi_hdcp_ctrl *hdcp_ctrl;
  54. /*
  55. * spinlock to protect registers shared by different execution
  56. * REG_HDMI_CTRL
  57. * REG_HDMI_DDC_ARBITRATION
  58. * REG_HDMI_HDCP_INT_CTRL
  59. * REG_HDMI_HPD_CTRL
  60. */
  61. spinlock_t reg_lock;
  62. };
  63. /* platform config data (ie. from DT, or pdata) */
  64. struct hdmi_platform_config {
  65. /* regulators that need to be on for screen pwr: */
  66. const char * const *pwr_reg_names;
  67. int pwr_reg_cnt;
  68. /* clks that need to be on: */
  69. const char * const *pwr_clk_names;
  70. int pwr_clk_cnt;
  71. };
  72. struct hdmi_bridge {
  73. struct drm_bridge base;
  74. struct hdmi *hdmi;
  75. struct work_struct hpd_work;
  76. };
  77. #define to_hdmi_bridge(x) container_of(x, struct hdmi_bridge, base)
  78. void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on);
  79. static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
  80. {
  81. writel(data, hdmi->mmio + reg);
  82. }
  83. static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
  84. {
  85. return readl(hdmi->mmio + reg);
  86. }
  87. static inline u32 hdmi_qfprom_read(struct hdmi *hdmi, u32 reg)
  88. {
  89. return readl(hdmi->qfprom_mmio + reg);
  90. }
  91. /*
  92. * hdmi phy:
  93. */
  94. enum hdmi_phy_type {
  95. MSM_HDMI_PHY_8x60,
  96. MSM_HDMI_PHY_8960,
  97. MSM_HDMI_PHY_8x74,
  98. MSM_HDMI_PHY_8996,
  99. MSM_HDMI_PHY_8998,
  100. MSM_HDMI_PHY_MAX,
  101. };
  102. struct hdmi_phy_cfg {
  103. enum hdmi_phy_type type;
  104. void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock);
  105. void (*powerdown)(struct hdmi_phy *phy);
  106. const char * const *reg_names;
  107. int num_regs;
  108. const char * const *clk_names;
  109. int num_clks;
  110. };
  111. extern const struct hdmi_phy_cfg msm_hdmi_phy_8x60_cfg;
  112. extern const struct hdmi_phy_cfg msm_hdmi_phy_8960_cfg;
  113. extern const struct hdmi_phy_cfg msm_hdmi_phy_8x74_cfg;
  114. extern const struct hdmi_phy_cfg msm_hdmi_phy_8996_cfg;
  115. extern const struct hdmi_phy_cfg msm_hdmi_phy_8998_cfg;
  116. struct hdmi_phy {
  117. struct platform_device *pdev;
  118. void __iomem *mmio;
  119. struct hdmi_phy_cfg *cfg;
  120. const struct hdmi_phy_funcs *funcs;
  121. struct regulator_bulk_data *regs;
  122. struct clk **clks;
  123. };
  124. static inline void hdmi_phy_write(struct hdmi_phy *phy, u32 reg, u32 data)
  125. {
  126. writel(data, phy->mmio + reg);
  127. }
  128. static inline u32 hdmi_phy_read(struct hdmi_phy *phy, u32 reg)
  129. {
  130. return readl(phy->mmio + reg);
  131. }
  132. int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy);
  133. void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy);
  134. void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock);
  135. void msm_hdmi_phy_powerdown(struct hdmi_phy *phy);
  136. void __init msm_hdmi_phy_driver_register(void);
  137. void __exit msm_hdmi_phy_driver_unregister(void);
  138. #ifdef CONFIG_COMMON_CLK
  139. int msm_hdmi_pll_8960_init(struct platform_device *pdev);
  140. int msm_hdmi_pll_8996_init(struct platform_device *pdev);
  141. int msm_hdmi_pll_8998_init(struct platform_device *pdev);
  142. #else
  143. static inline int msm_hdmi_pll_8960_init(struct platform_device *pdev)
  144. {
  145. return -ENODEV;
  146. }
  147. static inline int msm_hdmi_pll_8996_init(struct platform_device *pdev)
  148. {
  149. return -ENODEV;
  150. }
  151. static inline int msm_hdmi_pll_8998_init(struct platform_device *pdev)
  152. {
  153. return -ENODEV;
  154. }
  155. #endif
  156. /*
  157. * audio:
  158. */
  159. struct hdmi_codec_daifmt;
  160. struct hdmi_codec_params;
  161. int msm_hdmi_audio_update(struct hdmi *hdmi);
  162. int msm_hdmi_bridge_audio_prepare(struct drm_bridge *bridge,
  163. struct drm_connector *connector,
  164. struct hdmi_codec_daifmt *daifmt,
  165. struct hdmi_codec_params *params);
  166. void msm_hdmi_bridge_audio_shutdown(struct drm_bridge *bridge,
  167. struct drm_connector *connector);
  168. /*
  169. * hdmi bridge:
  170. */
  171. int msm_hdmi_bridge_init(struct hdmi *hdmi);
  172. void msm_hdmi_hpd_irq(struct drm_bridge *bridge);
  173. enum drm_connector_status msm_hdmi_bridge_detect(
  174. struct drm_bridge *bridge, struct drm_connector *connector);
  175. void msm_hdmi_hpd_enable(struct drm_bridge *bridge);
  176. void msm_hdmi_hpd_disable(struct drm_bridge *bridge);
  177. /*
  178. * i2c adapter for ddc:
  179. */
  180. void msm_hdmi_i2c_irq(struct i2c_adapter *i2c);
  181. void msm_hdmi_i2c_destroy(struct i2c_adapter *i2c);
  182. struct i2c_adapter *msm_hdmi_i2c_init(struct hdmi *hdmi);
  183. /*
  184. * hdcp
  185. */
  186. #ifdef CONFIG_DRM_MSM_HDMI_HDCP
  187. struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi);
  188. void msm_hdmi_hdcp_destroy(struct hdmi *hdmi);
  189. void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl);
  190. void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl);
  191. void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl);
  192. #else
  193. static inline struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi)
  194. {
  195. return ERR_PTR(-ENXIO);
  196. }
  197. static inline void msm_hdmi_hdcp_destroy(struct hdmi *hdmi) {}
  198. static inline void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
  199. static inline void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
  200. static inline void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
  201. #endif
  202. #endif /* __HDMI_CONNECTOR_H__ */