2020-09-03 16:01:11 +08:00
|
|
|
#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"
|
|
|
|
|
2020-09-03 16:01:12 +08:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2020-09-03 16:01:22 +08:00
|
|
|
struct vc4_hdmi;
|
2020-09-03 16:01:23 +08:00
|
|
|
struct vc4_hdmi_register;
|
2020-12-15 23:42:41 +08:00
|
|
|
struct vc4_hdmi_connector_state;
|
2020-09-03 16:01:22 +08:00
|
|
|
|
2020-09-03 16:01:48 +08:00
|
|
|
enum vc4_hdmi_phy_channel {
|
|
|
|
PHY_LANE_0 = 0,
|
|
|
|
PHY_LANE_1,
|
|
|
|
PHY_LANE_2,
|
|
|
|
PHY_LANE_CK,
|
|
|
|
};
|
|
|
|
|
2020-09-03 16:01:22 +08:00
|
|
|
struct vc4_hdmi_variant {
|
2020-09-03 16:01:29 +08:00
|
|
|
/* Encoder Type for that controller */
|
|
|
|
enum vc4_encoder_type encoder_type;
|
|
|
|
|
2020-09-03 16:01:41 +08:00
|
|
|
/* ALSA card name */
|
|
|
|
const char *card_name;
|
|
|
|
|
2020-09-03 16:01:30 +08:00
|
|
|
/* Filename to expose the registers in debugfs */
|
|
|
|
const char *debugfs_name;
|
|
|
|
|
2020-09-03 16:01:35 +08:00
|
|
|
/* Maximum pixel clock supported by the controller (in Hz) */
|
|
|
|
unsigned long long max_pixel_clock;
|
|
|
|
|
2020-09-03 16:01:23 +08:00
|
|
|
/* List of the registers available on that variant */
|
|
|
|
const struct vc4_hdmi_register *registers;
|
|
|
|
|
|
|
|
/* Number of registers on that variant */
|
|
|
|
unsigned int num_registers;
|
|
|
|
|
2020-09-03 16:01:48 +08:00
|
|
|
/* BCM2711 Only.
|
|
|
|
* The variants don't map the lane in the same order in the
|
|
|
|
* PHY, so this is an array mapping the HDMI channel (index)
|
|
|
|
* to the PHY lane (value).
|
|
|
|
*/
|
|
|
|
enum vc4_hdmi_phy_channel phy_lane_mapping[4];
|
|
|
|
|
2020-10-29 20:25:22 +08:00
|
|
|
/* The BCM2711 cannot deal with odd horizontal pixel timings */
|
|
|
|
bool unsupported_odd_h_timings;
|
|
|
|
|
2021-01-11 22:23:04 +08:00
|
|
|
/*
|
|
|
|
* The BCM2711 CEC/hotplug IRQ controller is shared between the
|
|
|
|
* two HDMI controllers, and we have a proper irqchip driver for
|
|
|
|
* it.
|
|
|
|
*/
|
|
|
|
bool external_irq_controller;
|
|
|
|
|
2020-09-03 16:01:22 +08:00
|
|
|
/* Callback to get the resources (memory region, interrupts,
|
|
|
|
* clocks, etc) for that variant.
|
|
|
|
*/
|
|
|
|
int (*init_resources)(struct vc4_hdmi *vc4_hdmi);
|
2020-09-03 16:01:24 +08:00
|
|
|
|
|
|
|
/* Callback to reset the HDMI block */
|
|
|
|
void (*reset)(struct vc4_hdmi *vc4_hdmi);
|
2020-09-03 16:01:25 +08:00
|
|
|
|
2020-09-03 16:01:27 +08:00
|
|
|
/* Callback to enable / disable the CSC */
|
|
|
|
void (*csc_setup)(struct vc4_hdmi *vc4_hdmi, bool enable);
|
|
|
|
|
2020-09-03 16:01:28 +08:00
|
|
|
/* Callback to configure the video timings in the HDMI block */
|
|
|
|
void (*set_timings)(struct vc4_hdmi *vc4_hdmi,
|
2020-12-15 23:42:43 +08:00
|
|
|
struct drm_connector_state *state,
|
2020-09-03 16:01:28 +08:00
|
|
|
struct drm_display_mode *mode);
|
|
|
|
|
2020-12-15 23:42:41 +08:00
|
|
|
/* Callback to initialize the PHY according to the connector state */
|
2020-09-03 16:01:25 +08:00
|
|
|
void (*phy_init)(struct vc4_hdmi *vc4_hdmi,
|
2020-12-15 23:42:41 +08:00
|
|
|
struct vc4_hdmi_connector_state *vc4_conn_state);
|
2020-09-03 16:01:25 +08:00
|
|
|
|
|
|
|
/* Callback to disable the PHY */
|
|
|
|
void (*phy_disable)(struct vc4_hdmi *vc4_hdmi);
|
2020-09-03 16:01:26 +08:00
|
|
|
|
|
|
|
/* 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);
|
2020-09-03 16:01:40 +08:00
|
|
|
|
|
|
|
/* Callback to get channel map */
|
|
|
|
u32 (*channel_map)(struct vc4_hdmi *vc4_hdmi, u32 channel_mask);
|
2021-04-30 17:44:49 +08:00
|
|
|
|
|
|
|
/* Enables HDR metadata */
|
|
|
|
bool supports_hdr;
|
2022-01-27 21:17:54 +08:00
|
|
|
|
|
|
|
/* Callback for hardware specific hotplug detect */
|
|
|
|
bool (*hp_detect)(struct vc4_hdmi *vc4_hdmi);
|
2020-09-03 16:01:22 +08:00
|
|
|
};
|
|
|
|
|
2020-09-03 16:01:11 +08:00
|
|
|
/* 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;
|
|
|
|
struct snd_dmaengine_dai_dma_data dma_data;
|
2021-05-25 21:23:52 +08:00
|
|
|
struct hdmi_audio_infoframe infoframe;
|
2022-01-27 19:14:52 +08:00
|
|
|
struct platform_device *codec_pdev;
|
2020-09-03 16:01:38 +08:00
|
|
|
bool streaming;
|
2020-09-03 16:01:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* General HDMI hardware state. */
|
|
|
|
struct vc4_hdmi {
|
2020-09-03 16:01:19 +08:00
|
|
|
struct vc4_hdmi_audio audio;
|
|
|
|
|
2020-09-03 16:01:11 +08:00
|
|
|
struct platform_device *pdev;
|
2020-09-03 16:01:22 +08:00
|
|
|
const struct vc4_hdmi_variant *variant;
|
2020-09-03 16:01:11 +08:00
|
|
|
|
2020-09-03 16:01:12 +08:00
|
|
|
struct vc4_hdmi_encoder encoder;
|
2020-09-03 16:01:21 +08:00
|
|
|
struct drm_connector connector;
|
2020-09-03 16:01:11 +08:00
|
|
|
|
2021-05-07 23:05:14 +08:00
|
|
|
struct delayed_work scrambling_work;
|
|
|
|
|
2020-09-03 16:01:11 +08:00
|
|
|
struct i2c_adapter *ddc;
|
|
|
|
void __iomem *hdmicore_regs;
|
|
|
|
void __iomem *hd_regs;
|
2020-09-03 16:01:48 +08:00
|
|
|
|
|
|
|
/* VC5 Only */
|
|
|
|
void __iomem *cec_regs;
|
|
|
|
/* VC5 Only */
|
|
|
|
void __iomem *csc_regs;
|
|
|
|
/* VC5 Only */
|
|
|
|
void __iomem *dvp_regs;
|
|
|
|
/* VC5 Only */
|
|
|
|
void __iomem *phy_regs;
|
|
|
|
/* VC5 Only */
|
|
|
|
void __iomem *ram_regs;
|
|
|
|
/* VC5 Only */
|
|
|
|
void __iomem *rm_regs;
|
|
|
|
|
2021-05-24 21:18:52 +08:00
|
|
|
struct gpio_desc *hpd_gpio;
|
2020-09-03 16:01:11 +08:00
|
|
|
|
2020-10-29 21:40:17 +08:00
|
|
|
/*
|
|
|
|
* On some systems (like the RPi4), some modes are in the same
|
|
|
|
* frequency range than the WiFi channels (1440p@60Hz for
|
|
|
|
* example). Should we take evasive actions because that system
|
|
|
|
* has a wifi adapter?
|
|
|
|
*/
|
|
|
|
bool disable_wifi_frequencies;
|
|
|
|
|
2021-05-07 23:05:12 +08:00
|
|
|
/*
|
|
|
|
* Even if HDMI0 on the RPi4 can output modes requiring a pixel
|
|
|
|
* rate higher than 297MHz, it needs some adjustments in the
|
|
|
|
* config.txt file to be able to do so and thus won't always be
|
|
|
|
* available.
|
|
|
|
*/
|
|
|
|
bool disable_4kp60;
|
|
|
|
|
2020-09-03 16:01:11 +08:00
|
|
|
struct cec_adapter *cec_adap;
|
|
|
|
struct cec_msg cec_rx_msg;
|
|
|
|
bool cec_tx_ok;
|
|
|
|
bool cec_irq_was_rx;
|
|
|
|
|
2021-01-11 22:23:02 +08:00
|
|
|
struct clk *cec_clock;
|
2020-09-03 16:01:11 +08:00
|
|
|
struct clk *pixel_clock;
|
|
|
|
struct clk *hsm_clock;
|
2020-09-03 16:01:40 +08:00
|
|
|
struct clk *audio_clock;
|
2020-09-03 16:01:47 +08:00
|
|
|
struct clk *pixel_bvb_clock;
|
2020-09-03 16:01:11 +08:00
|
|
|
|
2020-09-03 16:01:48 +08:00
|
|
|
struct reset_control *reset;
|
|
|
|
|
2020-09-03 16:01:11 +08:00
|
|
|
struct debugfs_regset32 hdmi_regset;
|
|
|
|
struct debugfs_regset32 hd_regset;
|
2021-10-25 22:11:08 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @hw_lock: Spinlock protecting device register access.
|
|
|
|
*/
|
|
|
|
spinlock_t hw_lock;
|
drm/vc4: hdmi: Use a mutex to prevent concurrent framework access
The vc4 HDMI controller registers into the KMS, CEC and ALSA
frameworks.
However, no particular care is done to prevent the concurrent execution
of different framework hooks from happening at the same time.
In order to protect against that scenario, let's introduce a mutex that
relevant ALSA and KMS hooks will need to take to prevent concurrent
execution.
CEC is left out at the moment though, since the .get_modes and .detect
KMS hooks, when running cec_s_phys_addr_from_edid, can end up calling
CEC's .adap_enable hook. This introduces some reentrancy that isn't easy
to deal with properly.
The CEC hooks also don't share much state with the rest of the driver:
the registers are entirely separate, we don't share any variable, the
only thing that can conflict is the CEC clock divider setup that can be
affected by a mode set.
However, after discussing it, it looks like CEC should be able to
recover from this if it was to happen.
Link: https://lore.kernel.org/r/20211025141113.702757-6-maxime@cerno.tech
Fixes: bb7d78568814 ("drm/vc4: Add HDMI audio support")
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2021-10-25 22:11:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @mutex: Mutex protecting the driver access across multiple
|
|
|
|
* frameworks (KMS, ALSA).
|
|
|
|
*
|
|
|
|
* NOTE: While supported, CEC has been left out since
|
|
|
|
* cec_s_phys_addr_from_edid() might call .adap_enable and lead to a
|
|
|
|
* reentrancy issue between .get_modes (or .detect) and .adap_enable.
|
|
|
|
* Since we don't share any state between the CEC hooks and KMS', it's
|
|
|
|
* not a big deal. The only trouble might come from updating the CEC
|
|
|
|
* clock divider which might be affected by a modeset, but CEC should
|
|
|
|
* be resilient to that.
|
|
|
|
*/
|
|
|
|
struct mutex mutex;
|
2021-10-25 22:11:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @saved_adjusted_mode: Copy of @drm_crtc_state.adjusted_mode
|
|
|
|
* for use by ALSA hooks and interrupt handlers. Protected by @mutex.
|
|
|
|
*/
|
|
|
|
struct drm_display_mode saved_adjusted_mode;
|
2021-10-25 22:11:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @output_enabled: Is the HDMI controller currently active?
|
|
|
|
* Protected by @mutex.
|
|
|
|
*/
|
|
|
|
bool output_enabled;
|
2021-10-25 22:11:13 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @scdc_enabled: Is the HDMI controller currently running with
|
|
|
|
* the scrambler on? Protected by @mutex.
|
|
|
|
*/
|
|
|
|
bool scdc_enabled;
|
2020-09-03 16:01:11 +08:00
|
|
|
};
|
|
|
|
|
2020-09-03 16:01:17 +08:00
|
|
|
static inline struct vc4_hdmi *
|
|
|
|
connector_to_vc4_hdmi(struct drm_connector *connector)
|
|
|
|
{
|
2020-09-03 16:01:21 +08:00
|
|
|
return container_of(connector, struct vc4_hdmi, connector);
|
2020-09-03 16:01:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-12-15 23:42:39 +08:00
|
|
|
struct vc4_hdmi_connector_state {
|
|
|
|
struct drm_connector_state base;
|
2020-12-15 23:42:40 +08:00
|
|
|
unsigned long long pixel_rate;
|
2020-12-15 23:42:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct vc4_hdmi_connector_state *
|
|
|
|
conn_state_to_vc4_hdmi_conn_state(struct drm_connector_state *conn_state)
|
|
|
|
{
|
|
|
|
return container_of(conn_state, struct vc4_hdmi_connector_state, base);
|
|
|
|
}
|
|
|
|
|
2020-09-03 16:01:25 +08:00
|
|
|
void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
|
2020-12-15 23:42:41 +08:00
|
|
|
struct vc4_hdmi_connector_state *vc4_conn_state);
|
2020-09-03 16:01:25 +08:00
|
|
|
void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi);
|
2020-09-03 16:01:26 +08:00
|
|
|
void vc4_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
|
|
|
|
void vc4_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
|
2020-09-03 16:01:25 +08:00
|
|
|
|
2020-09-03 16:01:48 +08:00
|
|
|
void vc5_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
|
2020-12-15 23:42:41 +08:00
|
|
|
struct vc4_hdmi_connector_state *vc4_conn_state);
|
2020-09-03 16:01:48 +08:00
|
|
|
void vc5_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi);
|
|
|
|
void vc5_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
|
|
|
|
void vc5_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
|
|
|
|
|
2020-09-03 16:01:11 +08:00
|
|
|
#endif /* _VC4_HDMI_H_ */
|