blob: c8fd58548ea2b4eb8d4bb48d5d840627906e71c6 [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 Ripardc457b8a2020-09-03 10:01:25 +020047 /* Callback to initialize the PHY according to the mode */
48 void (*phy_init)(struct vc4_hdmi *vc4_hdmi,
49 struct drm_display_mode *mode);
50
51 /* Callback to disable the PHY */
52 void (*phy_disable)(struct vc4_hdmi *vc4_hdmi);
Maxime Ripard647b9652020-09-03 10:01:26 +020053
54 /* Callback to enable the RNG in the PHY */
55 void (*phy_rng_enable)(struct vc4_hdmi *vc4_hdmi);
56
57 /* Callback to disable the RNG in the PHY */
58 void (*phy_rng_disable)(struct vc4_hdmi *vc4_hdmi);
Maxime Ripard33c773e2020-09-03 10:01:22 +020059};
60
Maxime Ripardc98c85b2020-09-03 10:01:12 +020061/* HDMI audio information */
62struct vc4_hdmi_audio {
63 struct snd_soc_card card;
64 struct snd_soc_dai_link link;
65 struct snd_soc_dai_link_component cpu;
66 struct snd_soc_dai_link_component codec;
67 struct snd_soc_dai_link_component platform;
68 int samplerate;
69 int channels;
70 struct snd_dmaengine_dai_dma_data dma_data;
71 struct snd_pcm_substream *substream;
72};
73
74/* General HDMI hardware state. */
75struct vc4_hdmi {
Maxime Ripard47c167b2020-09-03 10:01:19 +020076 struct vc4_hdmi_audio audio;
77
Maxime Ripardc98c85b2020-09-03 10:01:12 +020078 struct platform_device *pdev;
Maxime Ripard33c773e2020-09-03 10:01:22 +020079 const struct vc4_hdmi_variant *variant;
Maxime Ripardc98c85b2020-09-03 10:01:12 +020080
81 struct vc4_hdmi_encoder encoder;
Maxime Ripard0532e5e2020-09-03 10:01:21 +020082 struct drm_connector connector;
Maxime Ripardc98c85b2020-09-03 10:01:12 +020083
Maxime Ripardc98c85b2020-09-03 10:01:12 +020084 struct i2c_adapter *ddc;
85 void __iomem *hdmicore_regs;
86 void __iomem *hd_regs;
87 int hpd_gpio;
88 bool hpd_active_low;
89
90 struct cec_adapter *cec_adap;
91 struct cec_msg cec_rx_msg;
92 bool cec_tx_ok;
93 bool cec_irq_was_rx;
94
95 struct clk *pixel_clock;
96 struct clk *hsm_clock;
97
98 struct debugfs_regset32 hdmi_regset;
99 struct debugfs_regset32 hd_regset;
100};
101
Maxime Ripard5dfbcae2020-09-03 10:01:17 +0200102static inline struct vc4_hdmi *
103connector_to_vc4_hdmi(struct drm_connector *connector)
104{
Maxime Ripard0532e5e2020-09-03 10:01:21 +0200105 return container_of(connector, struct vc4_hdmi, connector);
Maxime Ripard5dfbcae2020-09-03 10:01:17 +0200106}
107
108static inline struct vc4_hdmi *
109encoder_to_vc4_hdmi(struct drm_encoder *encoder)
110{
111 struct vc4_hdmi_encoder *_encoder = to_vc4_hdmi_encoder(encoder);
112
113 return container_of(_encoder, struct vc4_hdmi, encoder);
114}
115
Maxime Ripardc457b8a2020-09-03 10:01:25 +0200116void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
117 struct drm_display_mode *mode);
118void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi);
Maxime Ripard647b9652020-09-03 10:01:26 +0200119void vc4_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
120void vc4_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
Maxime Ripardc457b8a2020-09-03 10:01:25 +0200121
Maxime Ripardf73100c2020-09-03 10:01:11 +0200122#endif /* _VC4_HDMI_H_ */