4 #include <drm/drm_connector.h>
6 #include <sound/dmaengine_pcm.h>
12 struct vc4_hdmi_register;
13 struct vc4_hdmi_connector_state;
19 enum vc4_hdmi_phy_channel {
26 struct vc4_hdmi_variant {
27 /* Encoder Type for that controller */
28 enum vc4_encoder_type encoder_type;
31 const char *card_name;
33 /* Filename to expose the registers in debugfs */
34 const char *debugfs_name;
36 /* Maximum pixel clock supported by the controller (in Hz) */
37 unsigned long long max_pixel_clock;
39 /* List of the registers available on that variant */
40 const struct vc4_hdmi_register *registers;
42 /* Number of registers on that variant */
43 unsigned int num_registers;
46 * The variants don't map the lane in the same order in the
47 * PHY, so this is an array mapping the HDMI channel (index)
48 * to the PHY lane (value).
50 enum vc4_hdmi_phy_channel phy_lane_mapping[4];
52 /* The BCM2711 cannot deal with odd horizontal pixel timings */
53 bool unsupported_odd_h_timings;
56 * The BCM2711 CEC/hotplug IRQ controller is shared between the
57 * two HDMI controllers, and we have a proper irqchip driver for
60 bool external_irq_controller;
62 /* Callback to get the resources (memory region, interrupts,
63 * clocks, etc) for that variant.
65 int (*init_resources)(struct drm_device *drm,
66 struct vc4_hdmi *vc4_hdmi);
68 /* Callback to reset the HDMI block */
69 void (*reset)(struct vc4_hdmi *vc4_hdmi);
71 /* Callback to enable / disable the CSC */
72 void (*csc_setup)(struct vc4_hdmi *vc4_hdmi,
73 struct drm_connector_state *state,
74 const struct drm_display_mode *mode);
76 /* Callback to configure the video timings in the HDMI block */
77 void (*set_timings)(struct vc4_hdmi *vc4_hdmi,
78 struct drm_connector_state *state,
79 const struct drm_display_mode *mode);
81 /* Callback to initialize the PHY according to the connector state */
82 void (*phy_init)(struct vc4_hdmi *vc4_hdmi,
83 struct vc4_hdmi_connector_state *vc4_conn_state);
85 /* Callback to disable the PHY */
86 void (*phy_disable)(struct vc4_hdmi *vc4_hdmi);
88 /* Callback to enable the RNG in the PHY */
89 void (*phy_rng_enable)(struct vc4_hdmi *vc4_hdmi);
91 /* Callback to disable the RNG in the PHY */
92 void (*phy_rng_disable)(struct vc4_hdmi *vc4_hdmi);
94 /* Callback to get channel map */
95 u32 (*channel_map)(struct vc4_hdmi *vc4_hdmi, u32 channel_mask);
97 /* Enables HDR metadata */
100 /* Callback for hardware specific hotplug detect */
101 bool (*hp_detect)(struct vc4_hdmi *vc4_hdmi);
104 /* HDMI audio information */
105 struct vc4_hdmi_audio {
106 struct snd_soc_card card;
107 struct snd_soc_dai_link link;
108 struct snd_soc_dai_link_component cpu;
109 struct snd_soc_dai_link_component codec;
110 struct snd_soc_dai_link_component platform;
111 struct snd_dmaengine_dai_dma_data dma_data;
112 struct hdmi_audio_infoframe infoframe;
113 struct platform_device *codec_pdev;
117 enum vc4_hdmi_output_format {
118 VC4_HDMI_OUTPUT_AUTO,
120 VC4_HDMI_OUTPUT_YUV422,
121 VC4_HDMI_OUTPUT_YUV444,
122 VC4_HDMI_OUTPUT_YUV420,
125 /* General HDMI hardware state. */
127 struct vc4_hdmi_audio audio;
129 struct platform_device *pdev;
130 const struct vc4_hdmi_variant *variant;
132 struct vc4_encoder encoder;
133 struct drm_connector connector;
135 struct delayed_work scrambling_work;
137 struct drm_property *broadcast_rgb_property;
138 struct drm_property *output_format_property;
140 struct i2c_adapter *ddc;
141 void __iomem *hdmicore_regs;
142 void __iomem *hd_regs;
145 void __iomem *cec_regs;
147 void __iomem *csc_regs;
149 void __iomem *dvp_regs;
151 void __iomem *phy_regs;
153 void __iomem *ram_regs;
155 void __iomem *rm_regs;
157 struct gpio_desc *hpd_gpio;
160 * On some systems (like the RPi4), some modes are in the same
161 * frequency range than the WiFi channels (1440p@60Hz for
162 * example). Should we take evasive actions because that system
163 * has a wifi adapter?
165 bool disable_wifi_frequencies;
167 struct cec_adapter *cec_adap;
168 struct cec_msg cec_rx_msg;
172 struct clk *cec_clock;
173 struct clk *pixel_clock;
174 struct clk *hsm_clock;
175 struct clk *audio_clock;
176 struct clk *pixel_bvb_clock;
178 struct reset_control *reset;
180 struct debugfs_regset32 hdmi_regset;
181 struct debugfs_regset32 hd_regset;
184 * @hw_lock: Spinlock protecting device register access.
189 * @mutex: Mutex protecting the driver access across multiple
190 * frameworks (KMS, ALSA, CEC).
195 * @saved_adjusted_mode: Copy of @drm_crtc_state.adjusted_mode
196 * for use by ALSA hooks and interrupt handlers. Protected by @mutex.
198 struct drm_display_mode saved_adjusted_mode;
201 * @output_enabled: Is the HDMI controller currently active?
202 * Protected by @mutex.
207 * @scdc_enabled: Is the HDMI controller currently running with
208 * the scrambler on? Protected by @mutex.
213 * @output_bpc: Copy of @vc4_connector_state.output_bpc for use
214 * outside of KMS hooks. Protected by @mutex.
216 unsigned int output_bpc;
219 * @output_format: Copy of @vc4_connector_state.output_format
220 * for use outside of KMS hooks. Protected by @mutex.
222 enum vc4_hdmi_output_format output_format;
224 * @requested_output_format: Copy of @vc4_connector_state.requested_output_format
225 * for use outside of KMS hooks. Protected by @mutex.
227 enum vc4_hdmi_output_format requested_output_format;
230 * @broadcast_rgb: Copy of @vc4_connector_state.broadcast_rgb
231 * for use outside of KMS hooks. Protected by @mutex.
235 /* VC5 debugfs regset */
236 struct debugfs_regset32 cec_regset;
237 struct debugfs_regset32 csc_regset;
238 struct debugfs_regset32 dvp_regset;
239 struct debugfs_regset32 phy_regset;
240 struct debugfs_regset32 ram_regset;
241 struct debugfs_regset32 rm_regset;
244 enum drm_connector_status status;
245 struct extcon_dev *edev;
249 static inline struct vc4_hdmi *
250 connector_to_vc4_hdmi(struct drm_connector *connector)
252 return container_of(connector, struct vc4_hdmi, connector);
255 static inline struct vc4_hdmi *
256 encoder_to_vc4_hdmi(struct drm_encoder *encoder)
258 struct vc4_encoder *_encoder = to_vc4_encoder(encoder);
259 return container_of(_encoder, struct vc4_hdmi, encoder);
262 struct vc4_hdmi_connector_state {
263 struct drm_connector_state base;
264 unsigned long long pixel_rate;
265 unsigned int output_bpc;
266 enum vc4_hdmi_output_format output_format;
267 enum vc4_hdmi_output_format requested_output_format;
271 static inline struct vc4_hdmi_connector_state *
272 conn_state_to_vc4_hdmi_conn_state(struct drm_connector_state *conn_state)
274 return container_of(conn_state, struct vc4_hdmi_connector_state, base);
277 static inline const struct vc4_hdmi_connector_state *
278 const_conn_state_to_vc4_hdmi_conn_state(const struct drm_connector_state *conn_state)
280 return container_of(conn_state, struct vc4_hdmi_connector_state, base);
283 void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
284 struct vc4_hdmi_connector_state *vc4_conn_state);
285 void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi);
286 void vc4_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
287 void vc4_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
289 void vc5_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
290 struct vc4_hdmi_connector_state *vc4_conn_state);
291 void vc5_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi);
292 void vc5_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
293 void vc5_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
295 #endif /* _VC4_HDMI_H_ */