vc4_hdmi.h 7.1 KB

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