vc4_hdmi.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #ifndef _VC4_HDMI_H_
  2. #define _VC4_HDMI_H_
  3. #include <drm/drm_connector.h>
  4. #include <media/cec.h>
  5. #include <sound/dmaengine_pcm.h>
  6. #include <sound/soc.h>
  7. #include "vc4_drv.h"
  8. struct vc4_hdmi;
  9. struct vc4_hdmi_register;
  10. enum vc4_hdmi_phy_channel {
  11. PHY_LANE_0 = 0,
  12. PHY_LANE_1,
  13. PHY_LANE_2,
  14. PHY_LANE_CK,
  15. };
  16. struct vc4_hdmi_variant {
  17. /* Encoder Type for that controller */
  18. enum vc4_encoder_type encoder_type;
  19. /* ALSA card name */
  20. const char *card_name;
  21. /* Filename to expose the registers in debugfs */
  22. const char *debugfs_name;
  23. /* Maximum pixel clock supported by the controller (in Hz) */
  24. unsigned long long max_pixel_clock;
  25. /* List of the registers available on that variant */
  26. const struct vc4_hdmi_register *registers;
  27. /* Number of registers on that variant */
  28. unsigned int num_registers;
  29. /* BCM2711 Only.
  30. * The variants don't map the lane in the same order in the
  31. * PHY, so this is an array mapping the HDMI channel (index)
  32. * to the PHY lane (value).
  33. */
  34. enum vc4_hdmi_phy_channel phy_lane_mapping[4];
  35. /* The BCM2711 cannot deal with odd horizontal pixel timings */
  36. bool unsupported_odd_h_timings;
  37. /*
  38. * The BCM2711 CEC/hotplug IRQ controller is shared between the
  39. * two HDMI controllers, and we have a proper irqchip driver for
  40. * it.
  41. */
  42. bool external_irq_controller;
  43. /* Callback to get the resources (memory region, interrupts,
  44. * clocks, etc) for that variant.
  45. */
  46. int (*init_resources)(struct drm_device *drm,
  47. struct vc4_hdmi *vc4_hdmi);
  48. /* Callback to reset the HDMI block */
  49. void (*reset)(struct vc4_hdmi *vc4_hdmi);
  50. /* Callback to enable / disable the CSC */
  51. void (*csc_setup)(struct vc4_hdmi *vc4_hdmi,
  52. struct drm_connector_state *state,
  53. const struct drm_display_mode *mode);
  54. /* Callback to configure the video timings in the HDMI block */
  55. void (*set_timings)(struct vc4_hdmi *vc4_hdmi,
  56. struct drm_connector_state *state,
  57. const struct drm_display_mode *mode);
  58. /* Callback to initialize the PHY according to the connector state */
  59. void (*phy_init)(struct vc4_hdmi *vc4_hdmi,
  60. struct drm_connector_state *conn_state);
  61. /* Callback to disable the PHY */
  62. void (*phy_disable)(struct vc4_hdmi *vc4_hdmi);
  63. /* Callback to enable the RNG in the PHY */
  64. void (*phy_rng_enable)(struct vc4_hdmi *vc4_hdmi);
  65. /* Callback to disable the RNG in the PHY */
  66. void (*phy_rng_disable)(struct vc4_hdmi *vc4_hdmi);
  67. /* Callback to get channel map */
  68. u32 (*channel_map)(struct vc4_hdmi *vc4_hdmi, u32 channel_mask);
  69. /* Enables HDR metadata */
  70. bool supports_hdr;
  71. /* Callback for hardware specific hotplug detect */
  72. bool (*hp_detect)(struct vc4_hdmi *vc4_hdmi);
  73. };
  74. /* HDMI audio information */
  75. struct vc4_hdmi_audio {
  76. struct snd_soc_card card;
  77. struct snd_soc_dai_link link;
  78. struct snd_soc_dai_link_component cpu;
  79. struct snd_soc_dai_link_component codec;
  80. struct snd_soc_dai_link_component platform;
  81. struct snd_dmaengine_dai_dma_data dma_data;
  82. struct hdmi_audio_infoframe infoframe;
  83. struct platform_device *codec_pdev;
  84. bool streaming;
  85. };
  86. /* General HDMI hardware state. */
  87. struct vc4_hdmi {
  88. struct vc4_hdmi_audio audio;
  89. struct platform_device *pdev;
  90. const struct vc4_hdmi_variant *variant;
  91. struct vc4_encoder encoder;
  92. struct drm_connector connector;
  93. struct delayed_work scrambling_work;
  94. struct i2c_adapter *ddc;
  95. void __iomem *hdmicore_regs;
  96. void __iomem *hd_regs;
  97. /* VC5 Only */
  98. void __iomem *cec_regs;
  99. /* VC5 Only */
  100. void __iomem *csc_regs;
  101. /* VC5 Only */
  102. void __iomem *dvp_regs;
  103. /* VC5 Only */
  104. void __iomem *phy_regs;
  105. /* VC5 Only */
  106. void __iomem *ram_regs;
  107. /* VC5 Only */
  108. void __iomem *rm_regs;
  109. struct gpio_desc *hpd_gpio;
  110. /*
  111. * On some systems (like the RPi4), some modes are in the same
  112. * frequency range than the WiFi channels (1440p@60Hz for
  113. * example). Should we take evasive actions because that system
  114. * has a wifi adapter?
  115. */
  116. bool disable_wifi_frequencies;
  117. struct cec_adapter *cec_adap;
  118. struct cec_msg cec_rx_msg;
  119. bool cec_tx_ok;
  120. bool cec_irq_was_rx;
  121. struct clk *cec_clock;
  122. struct clk *pixel_clock;
  123. struct clk *hsm_clock;
  124. struct clk *audio_clock;
  125. struct clk *pixel_bvb_clock;
  126. struct reset_control *reset;
  127. struct debugfs_regset32 hdmi_regset;
  128. struct debugfs_regset32 hd_regset;
  129. /* VC5 only */
  130. struct debugfs_regset32 cec_regset;
  131. struct debugfs_regset32 csc_regset;
  132. struct debugfs_regset32 dvp_regset;
  133. struct debugfs_regset32 phy_regset;
  134. struct debugfs_regset32 ram_regset;
  135. struct debugfs_regset32 rm_regset;
  136. /**
  137. * @hw_lock: Spinlock protecting device register access.
  138. */
  139. spinlock_t hw_lock;
  140. /**
  141. * @mutex: Mutex protecting the driver access across multiple
  142. * frameworks (KMS, ALSA, CEC).
  143. */
  144. struct mutex mutex;
  145. /**
  146. * @saved_adjusted_mode: Copy of @drm_crtc_state.adjusted_mode
  147. * for use by ALSA hooks and interrupt handlers. Protected by @mutex.
  148. */
  149. struct drm_display_mode saved_adjusted_mode;
  150. /**
  151. * @packet_ram_enabled: Is the HDMI controller packet RAM currently
  152. * on? Protected by @mutex.
  153. */
  154. bool packet_ram_enabled;
  155. /**
  156. * @scdc_enabled: Is the HDMI controller currently running with
  157. * the scrambler on? Protected by @mutex.
  158. */
  159. bool scdc_enabled;
  160. /**
  161. * @output_bpc: Copy of @drm_connector_state.hdmi.output_bpc for
  162. * use outside of KMS hooks. Protected by @mutex.
  163. */
  164. unsigned int output_bpc;
  165. /**
  166. * @output_format: Copy of
  167. * @drm_connector_state.hdmi.output_format for use outside of
  168. * KMS hooks. Protected by @mutex.
  169. */
  170. enum hdmi_colorspace output_format;
  171. };
  172. #define connector_to_vc4_hdmi(_connector) \
  173. container_of_const(_connector, struct vc4_hdmi, connector)
  174. static inline struct vc4_hdmi *
  175. encoder_to_vc4_hdmi(struct drm_encoder *encoder)
  176. {
  177. struct vc4_encoder *_encoder = to_vc4_encoder(encoder);
  178. return container_of_const(_encoder, struct vc4_hdmi, encoder);
  179. }
  180. void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
  181. struct drm_connector_state *conn_state);
  182. void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi);
  183. void vc4_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
  184. void vc4_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
  185. void vc5_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
  186. struct drm_connector_state *conn_state);
  187. void vc5_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi);
  188. void vc5_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
  189. void vc5_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
  190. #endif /* _VC4_HDMI_H_ */