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 | 7d73299 | 2020-09-03 10:01:29 +0200 | [diff] [blame] | 30 | /* Encoder Type for that controller */ |
| 31 | enum vc4_encoder_type encoder_type; |
| 32 | |
Maxime Ripard | 9be43a5 | 2020-09-03 10:01:41 +0200 | [diff] [blame] | 33 | /* ALSA card name */ |
| 34 | const char *card_name; |
| 35 | |
Maxime Ripard | b2405c9 | 2020-09-03 10:01:30 +0200 | [diff] [blame] | 36 | /* Filename to expose the registers in debugfs */ |
| 37 | const char *debugfs_name; |
| 38 | |
Maxime Ripard | 234f421 | 2020-09-03 10:01:32 +0200 | [diff] [blame] | 39 | /* Set to true when the CEC support is available */ |
| 40 | bool cec_available; |
| 41 | |
Maxime Ripard | cd4cb49 | 2020-09-03 10:01:35 +0200 | [diff] [blame] | 42 | /* Maximum pixel clock supported by the controller (in Hz) */ |
| 43 | unsigned long long max_pixel_clock; |
| 44 | |
Maxime Ripard | 311e305 | 2020-09-03 10:01:23 +0200 | [diff] [blame] | 45 | /* List of the registers available on that variant */ |
| 46 | const struct vc4_hdmi_register *registers; |
| 47 | |
| 48 | /* Number of registers on that variant */ |
| 49 | unsigned int num_registers; |
| 50 | |
Maxime Ripard | 33c773e | 2020-09-03 10:01:22 +0200 | [diff] [blame] | 51 | /* Callback to get the resources (memory region, interrupts, |
| 52 | * clocks, etc) for that variant. |
| 53 | */ |
| 54 | int (*init_resources)(struct vc4_hdmi *vc4_hdmi); |
Maxime Ripard | 9045e91 | 2020-09-03 10:01:24 +0200 | [diff] [blame] | 55 | |
| 56 | /* Callback to reset the HDMI block */ |
| 57 | void (*reset)(struct vc4_hdmi *vc4_hdmi); |
Maxime Ripard | c457b8a | 2020-09-03 10:01:25 +0200 | [diff] [blame] | 58 | |
Maxime Ripard | 89f31a2 | 2020-09-03 10:01:27 +0200 | [diff] [blame] | 59 | /* Callback to enable / disable the CSC */ |
| 60 | void (*csc_setup)(struct vc4_hdmi *vc4_hdmi, bool enable); |
| 61 | |
Maxime Ripard | 904f668 | 2020-09-03 10:01:28 +0200 | [diff] [blame] | 62 | /* Callback to configure the video timings in the HDMI block */ |
| 63 | void (*set_timings)(struct vc4_hdmi *vc4_hdmi, |
| 64 | struct drm_display_mode *mode); |
| 65 | |
Maxime Ripard | c457b8a | 2020-09-03 10:01:25 +0200 | [diff] [blame] | 66 | /* Callback to initialize the PHY according to the mode */ |
| 67 | void (*phy_init)(struct vc4_hdmi *vc4_hdmi, |
| 68 | struct drm_display_mode *mode); |
| 69 | |
| 70 | /* Callback to disable the PHY */ |
| 71 | void (*phy_disable)(struct vc4_hdmi *vc4_hdmi); |
Maxime Ripard | 647b965 | 2020-09-03 10:01:26 +0200 | [diff] [blame] | 72 | |
| 73 | /* Callback to enable the RNG in the PHY */ |
| 74 | void (*phy_rng_enable)(struct vc4_hdmi *vc4_hdmi); |
| 75 | |
| 76 | /* Callback to disable the RNG in the PHY */ |
| 77 | void (*phy_rng_disable)(struct vc4_hdmi *vc4_hdmi); |
Dave Stevenson | 632ee3a | 2020-09-03 10:01:40 +0200 | [diff] [blame] | 78 | |
| 79 | /* Callback to get channel map */ |
| 80 | u32 (*channel_map)(struct vc4_hdmi *vc4_hdmi, u32 channel_mask); |
Maxime Ripard | 33c773e | 2020-09-03 10:01:22 +0200 | [diff] [blame] | 81 | }; |
| 82 | |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 83 | /* HDMI audio information */ |
| 84 | struct vc4_hdmi_audio { |
| 85 | struct snd_soc_card card; |
| 86 | struct snd_soc_dai_link link; |
| 87 | struct snd_soc_dai_link_component cpu; |
| 88 | struct snd_soc_dai_link_component codec; |
| 89 | struct snd_soc_dai_link_component platform; |
| 90 | int samplerate; |
| 91 | int channels; |
| 92 | struct snd_dmaengine_dai_dma_data dma_data; |
| 93 | struct snd_pcm_substream *substream; |
Dave Stevenson | 6ac1c75 | 2020-09-03 10:01:38 +0200 | [diff] [blame] | 94 | |
| 95 | bool streaming; |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | /* General HDMI hardware state. */ |
| 99 | struct vc4_hdmi { |
Maxime Ripard | 47c167b | 2020-09-03 10:01:19 +0200 | [diff] [blame] | 100 | struct vc4_hdmi_audio audio; |
| 101 | |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 102 | struct platform_device *pdev; |
Maxime Ripard | 33c773e | 2020-09-03 10:01:22 +0200 | [diff] [blame] | 103 | const struct vc4_hdmi_variant *variant; |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 104 | |
| 105 | struct vc4_hdmi_encoder encoder; |
Maxime Ripard | 0532e5e | 2020-09-03 10:01:21 +0200 | [diff] [blame] | 106 | struct drm_connector connector; |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 107 | |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 108 | struct i2c_adapter *ddc; |
| 109 | void __iomem *hdmicore_regs; |
| 110 | void __iomem *hd_regs; |
| 111 | int hpd_gpio; |
| 112 | bool hpd_active_low; |
| 113 | |
| 114 | struct cec_adapter *cec_adap; |
| 115 | struct cec_msg cec_rx_msg; |
| 116 | bool cec_tx_ok; |
| 117 | bool cec_irq_was_rx; |
| 118 | |
| 119 | struct clk *pixel_clock; |
| 120 | struct clk *hsm_clock; |
Dave Stevenson | 632ee3a | 2020-09-03 10:01:40 +0200 | [diff] [blame] | 121 | struct clk *audio_clock; |
Hoegeun Kwon | 3738742 | 2020-09-03 10:01:47 +0200 | [diff] [blame^] | 122 | struct clk *pixel_bvb_clock; |
Maxime Ripard | c98c85b | 2020-09-03 10:01:12 +0200 | [diff] [blame] | 123 | |
| 124 | struct debugfs_regset32 hdmi_regset; |
| 125 | struct debugfs_regset32 hd_regset; |
| 126 | }; |
| 127 | |
Maxime Ripard | 5dfbcae | 2020-09-03 10:01:17 +0200 | [diff] [blame] | 128 | static inline struct vc4_hdmi * |
| 129 | connector_to_vc4_hdmi(struct drm_connector *connector) |
| 130 | { |
Maxime Ripard | 0532e5e | 2020-09-03 10:01:21 +0200 | [diff] [blame] | 131 | return container_of(connector, struct vc4_hdmi, connector); |
Maxime Ripard | 5dfbcae | 2020-09-03 10:01:17 +0200 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static inline struct vc4_hdmi * |
| 135 | encoder_to_vc4_hdmi(struct drm_encoder *encoder) |
| 136 | { |
| 137 | struct vc4_hdmi_encoder *_encoder = to_vc4_hdmi_encoder(encoder); |
| 138 | |
| 139 | return container_of(_encoder, struct vc4_hdmi, encoder); |
| 140 | } |
| 141 | |
Maxime Ripard | c457b8a | 2020-09-03 10:01:25 +0200 | [diff] [blame] | 142 | void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi, |
| 143 | struct drm_display_mode *mode); |
| 144 | void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi); |
Maxime Ripard | 647b965 | 2020-09-03 10:01:26 +0200 | [diff] [blame] | 145 | void vc4_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi); |
| 146 | void vc4_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi); |
Maxime Ripard | c457b8a | 2020-09-03 10:01:25 +0200 | [diff] [blame] | 147 | |
Maxime Ripard | f73100c | 2020-09-03 10:01:11 +0200 | [diff] [blame] | 148 | #endif /* _VC4_HDMI_H_ */ |