vc4_hdmi.h 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#ifndef _VC4_HDMI_H_
#define _VC4_HDMI_H_

#include <drm/drm_connector.h>
#include <media/cec.h>
#include <sound/dmaengine_pcm.h>
#include <sound/soc.h>

#include "vc4_drv.h"

11 12 13 14 15 16 17 18 19 20 21 22 23
/* VC4 HDMI encoder KMS struct */
struct vc4_hdmi_encoder {
	struct vc4_encoder base;
	bool hdmi_monitor;
	bool limited_rgb_range;
};

static inline struct vc4_hdmi_encoder *
to_vc4_hdmi_encoder(struct drm_encoder *encoder)
{
	return container_of(encoder, struct vc4_hdmi_encoder, base.base);
}

24 25
struct drm_display_mode;

26
struct vc4_hdmi;
27
struct vc4_hdmi_register;
28 29

struct vc4_hdmi_variant {
30 31 32
	/* Encoder Type for that controller */
	enum vc4_encoder_type encoder_type;

33 34 35
	/* Filename to expose the registers in debugfs */
	const char *debugfs_name;

36 37 38
	/* Set to true when the CEC support is available */
	bool cec_available;

39 40 41
	/* Maximum pixel clock supported by the controller (in Hz) */
	unsigned long long max_pixel_clock;

42 43 44 45 46 47
	/* List of the registers available on that variant */
	const struct vc4_hdmi_register *registers;

	/* Number of registers on that variant */
	unsigned int num_registers;

48 49 50 51
	/* Callback to get the resources (memory region, interrupts,
	 * clocks, etc) for that variant.
	 */
	int (*init_resources)(struct vc4_hdmi *vc4_hdmi);
52 53 54

	/* Callback to reset the HDMI block */
	void (*reset)(struct vc4_hdmi *vc4_hdmi);
55

56 57 58
	/* Callback to enable / disable the CSC */
	void (*csc_setup)(struct vc4_hdmi *vc4_hdmi, bool enable);

59 60 61 62
	/* Callback to configure the video timings in the HDMI block */
	void (*set_timings)(struct vc4_hdmi *vc4_hdmi,
			    struct drm_display_mode *mode);

63 64 65 66 67 68
	/* Callback to initialize the PHY according to the mode */
	void (*phy_init)(struct vc4_hdmi *vc4_hdmi,
			 struct drm_display_mode *mode);

	/* Callback to disable the PHY */
	void (*phy_disable)(struct vc4_hdmi *vc4_hdmi);
69 70 71 72 73 74

	/* Callback to enable the RNG in the PHY */
	void (*phy_rng_enable)(struct vc4_hdmi *vc4_hdmi);

	/* Callback to disable the RNG in the PHY */
	void (*phy_rng_disable)(struct vc4_hdmi *vc4_hdmi);
75 76 77

	/* Callback to get channel map */
	u32 (*channel_map)(struct vc4_hdmi *vc4_hdmi, u32 channel_mask);
78 79
};

80 81 82 83 84 85 86 87 88 89 90
/* HDMI audio information */
struct vc4_hdmi_audio {
	struct snd_soc_card card;
	struct snd_soc_dai_link link;
	struct snd_soc_dai_link_component cpu;
	struct snd_soc_dai_link_component codec;
	struct snd_soc_dai_link_component platform;
	int samplerate;
	int channels;
	struct snd_dmaengine_dai_dma_data dma_data;
	struct snd_pcm_substream *substream;
91 92

	bool streaming;
93 94 95 96
};

/* General HDMI hardware state. */
struct vc4_hdmi {
97 98
	struct vc4_hdmi_audio audio;

99
	struct platform_device *pdev;
100
	const struct vc4_hdmi_variant *variant;
101

102
	struct vc4_hdmi_encoder encoder;
103
	struct drm_connector connector;
104 105 106 107 108 109 110 111 112 113 114 115 116 117

	struct i2c_adapter *ddc;
	void __iomem *hdmicore_regs;
	void __iomem *hd_regs;
	int hpd_gpio;
	bool hpd_active_low;

	struct cec_adapter *cec_adap;
	struct cec_msg cec_rx_msg;
	bool cec_tx_ok;
	bool cec_irq_was_rx;

	struct clk *pixel_clock;
	struct clk *hsm_clock;
118
	struct clk *audio_clock;
119 120 121 122 123

	struct debugfs_regset32 hdmi_regset;
	struct debugfs_regset32 hd_regset;
};

124 125 126
static inline struct vc4_hdmi *
connector_to_vc4_hdmi(struct drm_connector *connector)
{
127
	return container_of(connector, struct vc4_hdmi, connector);
128 129 130 131 132 133 134 135 136 137
}

static inline struct vc4_hdmi *
encoder_to_vc4_hdmi(struct drm_encoder *encoder)
{
	struct vc4_hdmi_encoder *_encoder = to_vc4_hdmi_encoder(encoder);

	return container_of(_encoder, struct vc4_hdmi, encoder);
}

138 139 140
void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
		       struct drm_display_mode *mode);
void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi);
141 142
void vc4_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
void vc4_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
143

144
#endif /* _VC4_HDMI_H_ */