blob: 0c32dc46d289a2a2be5c49b5e9a5eb909b616b11 [file] [log] [blame]
Maxime Ripardf73100c2020-09-03 10:01:11 +02001#ifndef _VC4_HDMI_H_
2#define _VC4_HDMI_H_
3
4#include <drm/drm_connector.h>
5#include <media/cec.h>
6#include <sound/dmaengine_pcm.h>
7#include <sound/soc.h>
8
9#include "vc4_drv.h"
10
Maxime Ripardf73100c2020-09-03 10:01:11 +020011/* VC4 HDMI encoder KMS struct */
12struct vc4_hdmi_encoder {
13 struct vc4_encoder base;
14 bool hdmi_monitor;
15 bool limited_rgb_range;
16};
17
18static inline struct vc4_hdmi_encoder *
19to_vc4_hdmi_encoder(struct drm_encoder *encoder)
20{
21 return container_of(encoder, struct vc4_hdmi_encoder, base.base);
22}
23
Maxime Ripardc457b8a2020-09-03 10:01:25 +020024struct drm_display_mode;
25
Maxime Ripard33c773e2020-09-03 10:01:22 +020026struct vc4_hdmi;
Maxime Ripard311e3052020-09-03 10:01:23 +020027struct vc4_hdmi_register;
Maxime Ripard33c773e2020-09-03 10:01:22 +020028
29struct vc4_hdmi_variant {
Maxime Ripard311e3052020-09-03 10:01:23 +020030 /* List of the registers available on that variant */
31 const struct vc4_hdmi_register *registers;
32
33 /* Number of registers on that variant */
34 unsigned int num_registers;
35
Maxime Ripard33c773e2020-09-03 10:01:22 +020036 /* Callback to get the resources (memory region, interrupts,
37 * clocks, etc) for that variant.
38 */
39 int (*init_resources)(struct vc4_hdmi *vc4_hdmi);
Maxime Ripard9045e912020-09-03 10:01:24 +020040
41 /* Callback to reset the HDMI block */
42 void (*reset)(struct vc4_hdmi *vc4_hdmi);
Maxime Ripardc457b8a2020-09-03 10:01:25 +020043
Maxime Ripard89f31a22020-09-03 10:01:27 +020044 /* Callback to enable / disable the CSC */
45 void (*csc_setup)(struct vc4_hdmi *vc4_hdmi, bool enable);
46
Maxime Ripard904f6682020-09-03 10:01:28 +020047 /* Callback to configure the video timings in the HDMI block */
48 void (*set_timings)(struct vc4_hdmi *vc4_hdmi,
49 struct drm_display_mode *mode);
50
Maxime Ripardc457b8a2020-09-03 10:01:25 +020051 /* Callback to initialize the PHY according to the mode */
52 void (*phy_init)(struct vc4_hdmi *vc4_hdmi,
53 struct drm_display_mode *mode);
54
55 /* Callback to disable the PHY */
56 void (*phy_disable)(struct vc4_hdmi *vc4_hdmi);
Maxime Ripard647b9652020-09-03 10:01:26 +020057
58 /* Callback to enable the RNG in the PHY */
59 void (*phy_rng_enable)(struct vc4_hdmi *vc4_hdmi);
60
61 /* Callback to disable the RNG in the PHY */
62 void (*phy_rng_disable)(struct vc4_hdmi *vc4_hdmi);
Maxime Ripard33c773e2020-09-03 10:01:22 +020063};
64
Maxime Ripardc98c85b2020-09-03 10:01:12 +020065/* HDMI audio information */
66struct vc4_hdmi_audio {
67 struct snd_soc_card card;
68 struct snd_soc_dai_link link;
69 struct snd_soc_dai_link_component cpu;
70 struct snd_soc_dai_link_component codec;
71 struct snd_soc_dai_link_component platform;
72 int samplerate;
73 int channels;
74 struct snd_dmaengine_dai_dma_data dma_data;
75 struct snd_pcm_substream *substream;
76};
77
78/* General HDMI hardware state. */
79struct vc4_hdmi {
Maxime Ripard47c167b2020-09-03 10:01:19 +020080 struct vc4_hdmi_audio audio;
81
Maxime Ripardc98c85b2020-09-03 10:01:12 +020082 struct platform_device *pdev;
Maxime Ripard33c773e2020-09-03 10:01:22 +020083 const struct vc4_hdmi_variant *variant;
Maxime Ripardc98c85b2020-09-03 10:01:12 +020084
85 struct vc4_hdmi_encoder encoder;
Maxime Ripard0532e5e2020-09-03 10:01:21 +020086 struct drm_connector connector;
Maxime Ripardc98c85b2020-09-03 10:01:12 +020087
Maxime Ripardc98c85b2020-09-03 10:01:12 +020088 struct i2c_adapter *ddc;
89 void __iomem *hdmicore_regs;
90 void __iomem *hd_regs;
91 int hpd_gpio;
92 bool hpd_active_low;
93
94 struct cec_adapter *cec_adap;
95 struct cec_msg cec_rx_msg;
96 bool cec_tx_ok;
97 bool cec_irq_was_rx;
98
99 struct clk *pixel_clock;
100 struct clk *hsm_clock;
101
102 struct debugfs_regset32 hdmi_regset;
103 struct debugfs_regset32 hd_regset;
104};
105
Maxime Ripard5dfbcae2020-09-03 10:01:17 +0200106static inline struct vc4_hdmi *
107connector_to_vc4_hdmi(struct drm_connector *connector)
108{
Maxime Ripard0532e5e2020-09-03 10:01:21 +0200109 return container_of(connector, struct vc4_hdmi, connector);
Maxime Ripard5dfbcae2020-09-03 10:01:17 +0200110}
111
112static inline struct vc4_hdmi *
113encoder_to_vc4_hdmi(struct drm_encoder *encoder)
114{
115 struct vc4_hdmi_encoder *_encoder = to_vc4_hdmi_encoder(encoder);
116
117 return container_of(_encoder, struct vc4_hdmi, encoder);
118}
119
Maxime Ripardc457b8a2020-09-03 10:01:25 +0200120void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
121 struct drm_display_mode *mode);
122void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi);
Maxime Ripard647b9652020-09-03 10:01:26 +0200123void vc4_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
124void vc4_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
Maxime Ripardc457b8a2020-09-03 10:01:25 +0200125
Maxime Ripardf73100c2020-09-03 10:01:11 +0200126#endif /* _VC4_HDMI_H_ */