Maxime Ripard | f73100c | 2020-09-03 10:01:11 +0200 | [diff] [blame] | 1 | #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 Ripard | f73100c | 2020-09-03 10:01:11 +0200 | [diff] [blame] | 11 | /* VC4 HDMI encoder KMS struct */ |
| 12 | struct vc4_hdmi_encoder { |
| 13 | struct vc4_encoder base; |
| 14 | bool hdmi_monitor; |
| 15 | bool limited_rgb_range; |
| 16 | }; |
| 17 | |
| 18 | static inline struct vc4_hdmi_encoder * |
| 19 | to_vc4_hdmi_encoder(struct drm_encoder *encoder) |
| 20 | { |
| 21 | return container_of(encoder, struct vc4_hdmi_encoder, base.base); |
| 22 | } |
| 23 | |
Maxime Ripard | c457b8a | 2020-09-03 10:01:25 +0200 | [diff] [blame] | 24 | struct drm_display_mode; |
| 25 | |
Maxime Ripard | 33c773e | 2020-09-03 10:01:22 +0200 | [diff] [blame] | 26 | struct vc4_hdmi; |
Maxime Ripard | 311e305 | 2020-09-03 10:01:23 +0200 | [diff] [blame] | 27 | struct vc4_hdmi_register; |
Maxime Ripard | 33c773e | 2020-09-03 10:01:22 +0200 | [diff] [blame] | 28 | |
| 29 | struct vc4_hdmi_variant { |
Maxime Ripard | 311e305 | 2020-09-03 10:01:23 +0200 | [diff] [blame] | 30 | /* 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 Ripard | 33c773e | 2020-09-03 10:01:22 +0200 | [diff] [blame] | 36 | /* 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 Ripard | 9045e91 | 2020-09-03 10:01:24 +0200 | [diff] [blame] | 40 | |
| 41 | /* Callback to reset the HDMI block */ |
| 42 | void (*reset)(struct vc4_hdmi *vc4_hdmi); |
Maxime Ripard | c457b8a | 2020-09-03 10:01:25 +0200 | [diff] [blame] | 43 | |
Maxime Ripard | 89f31a2 | 2020-09-03 10:01:27 +0200 | [diff] [blame] | 44 | /* Callback to enable / disable the CSC */ |
| 45 | void (*csc_setup)(struct vc4_hdmi *vc4_hdmi, bool enable); |
| 46 | |
Maxime Ripard | 904f668 | 2020-09-03 10:01:28 +0200 | [diff] [blame^] | 47 | /* 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 Ripard | c457b8a | 2020-09-03 10:01:25 +0200 | [diff] [blame] | 51 | /* 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 Ripard | 647b965 | 2020-09-03 10:01:26 +0200 | [diff] [blame] | 57 | |
| 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 Ripard | 33c773e | 2020-09-03 10:01:22 +0200 | [diff] [blame] | 63 | }; |
| 64 | |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 65 | /* HDMI audio information */ |
| 66 | struct 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. */ |
| 79 | struct vc4_hdmi { |
Maxime Ripard | 47c167b | 2020-09-03 10:01:19 +0200 | [diff] [blame] | 80 | struct vc4_hdmi_audio audio; |
| 81 | |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 82 | struct platform_device *pdev; |
Maxime Ripard | 33c773e | 2020-09-03 10:01:22 +0200 | [diff] [blame] | 83 | const struct vc4_hdmi_variant *variant; |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 84 | |
| 85 | struct vc4_hdmi_encoder encoder; |
Maxime Ripard | 0532e5e | 2020-09-03 10:01:21 +0200 | [diff] [blame] | 86 | struct drm_connector connector; |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 87 | |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 88 | 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 Ripard | 5dfbcae | 2020-09-03 10:01:17 +0200 | [diff] [blame] | 106 | static inline struct vc4_hdmi * |
| 107 | connector_to_vc4_hdmi(struct drm_connector *connector) |
| 108 | { |
Maxime Ripard | 0532e5e | 2020-09-03 10:01:21 +0200 | [diff] [blame] | 109 | return container_of(connector, struct vc4_hdmi, connector); |
Maxime Ripard | 5dfbcae | 2020-09-03 10:01:17 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static inline struct vc4_hdmi * |
| 113 | encoder_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 Ripard | c457b8a | 2020-09-03 10:01:25 +0200 | [diff] [blame] | 120 | void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi, |
| 121 | struct drm_display_mode *mode); |
| 122 | void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi); |
Maxime Ripard | 647b965 | 2020-09-03 10:01:26 +0200 | [diff] [blame] | 123 | void vc4_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi); |
| 124 | void vc4_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi); |
Maxime Ripard | c457b8a | 2020-09-03 10:01:25 +0200 | [diff] [blame] | 125 | |
Maxime Ripard | f73100c | 2020-09-03 10:01:11 +0200 | [diff] [blame] | 126 | #endif /* _VC4_HDMI_H_ */ |