Re: [PATCH v7] drm/bridge: dw-hdmi-qp: serialize HDMI audio callbacks with PHY enable/disable
From: Frank Zhang
Date: Wed Dec 02 2026 - 04:56:49 EST
Hi Cristian,
Thanks for your comments.
On 12/1/26 10:17, Cristian Ciocaltea wrote:
Hi Frank,
On 11/12/26 12:11 PM, Frank Zhang wrote:
The following panic was observed during system reboot, it can also be
triggered by the following sequences:
- Disable the HDMI drm display, open and close the HDMI PCM device.
- Enable the HDMI drm display and start audio stream on the HDMI PCM
device, then switch the HDMI drm display to disable, stop and close
audio stream.
[...]
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c
@@ -76,6 +76,8 @@ struct dw_hdmi_qp {
struct {
const struct dw_hdmi_qp_phy_ops *ops;
void *data;
+ struct mutex lock;
+ bool enabled;
} phy;
I agree the audio callbacks need to be serialized against the atomic
enable/disable paths, but I don't think we need a new mutex, nor a new flag.
struct dw_hdmi_qp already provides hdmi->mutex (currently guards curr_conn), and
could be extended to also guard tmds_char_rate.
The thing is that tmds_char_rate should act as an indicator for the PHY being up
in HDMI mode, which is the only case where audio matters (in DVI mode the DRM
audio helpers bail out early anyway).
Hence, I'd suggest something like this (untested):
- in dw_hdmi_qp_bridge_atomic_enable()
hdmi->phy.ops->init(hdmi, hdmi->phy.data);
[...]
drm_connector_get(connector);
scoped_guard(mutex, &hdmi->mutex) {
hdmi->curr_conn = connector;
hdmi->tmds_char_rate = op_mode ? 0 : conn_state->hdmi.tmds_char_rate;
}
[...]
drm_atomic_helper_connector_hdmi_update_infoframes(connector, state);
- in dw_hdmi_qp_bridge_atomic_disable()
scoped_guard(mutex, &hdmi->mutex) {
if (hdmi->curr_conn) {
drm_connector_put(hdmi->curr_conn);
hdmi->curr_conn = NULL;
}
hdmi->tmds_char_rate = 0;
}
[...]
hdmi->phy.ops->disable(hdmi, hdmi->phy.data);
- in audio/infoframe callbacks simply check tmds_char_rate with hdmi->mutex held
around the register accesses.
Reusing `tmds_char_rate` as phy indicator is reasonable, I will remove `phy.enabled` in the next version.
Regarding `hdmi->mutex`, this mutex is not only used in atomic enable/disable, but also used in dw_hdmi_qp_hpd_notify(). Although the lock scope is very small, it still introduces lock condition for audio callbacks, or am I missing something?
To keep the lock scope cleaner, we can use a dedicated mutex (e.g., `hdmi->audio_mutex`) for tmds_char_rate. Does this sound reasonable to you?
unsigned long ref_clk_rate;
@@ -262,6 +264,10 @@ static int dw_hdmi_qp_audio_enable(struct drm_bridge *bridge,
{
struct dw_hdmi_qp *hdmi = dw_hdmi_qp_from_bridge(bridge);
+ guard(mutex)(&hdmi->phy.lock);
+ if (!hdmi->phy.enabled)
+ return -EOPNOTSUPP;
This is a functional change, as opening the PCM device now fails while the
display is disabled. Commit 247695b19afc ("drm/bridge: dw-hdmi-qp: Return
-EOPNOTSUPP in HDMI audio functions") should already handle this, so please
rebase.
This commit(247695b19afc) is on branch: drm-misc-next, right? I will rebase onto this branch in the next version.
+
if (hdmi->tmds_char_rate)
dw_hdmi_qp_mod(hdmi, 0, AVP_DATAPATH_PACKET_AUDIO_SWDISABLE, GLOBAL_SWDISABLE);
@@ -275,13 +281,23 @@ static int dw_hdmi_qp_audio_prepare(struct drm_bridge *bridge,
{
struct dw_hdmi_qp *hdmi = dw_hdmi_qp_from_bridge(bridge);
bool ref2stream = false;
+ int ret = 0;
+
+ mutex_lock(&hdmi->phy.lock);
+ if (!hdmi->phy.enabled) {
+ ret = -EOPNOTSUPP;
+ goto err_res;
+ }
- if (!hdmi->tmds_char_rate)
- return -ENODEV;
+ if (!hdmi->tmds_char_rate) {
+ ret = -ENODEV;
+ goto err_res;
+ }
if (fmt->bit_clk_provider | fmt->frame_clk_provider) {
dev_err(hdmi->dev, "unsupported clock settings\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_res;
}
if (fmt->bit_fmt == SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE)
@@ -290,9 +306,13 @@ static int dw_hdmi_qp_audio_prepare(struct drm_bridge *bridge,
dw_hdmi_qp_set_audio_interface(hdmi, fmt, hparms);
dw_hdmi_qp_set_sample_rate(hdmi, hdmi->tmds_char_rate, hparms->sample_rate);
dw_hdmi_qp_set_channel_status(hdmi, hparms->iec.status, ref2stream);
- drm_atomic_helper_connector_hdmi_update_audio_infoframe(connector, &hparms->cea);
+ mutex_unlock(&hdmi->phy.lock);
- return 0;
+ return drm_atomic_helper_connector_hdmi_update_audio_infoframe(connector, &hparms->cea);
+
+err_res:
+ mutex_unlock(&hdmi->phy.lock);
+ return ret;
}
static void dw_hdmi_qp_audio_disable_regs(struct dw_hdmi_qp *hdmi)
@@ -321,6 +341,10 @@ static void dw_hdmi_qp_audio_disable(struct drm_bridge *bridge,
drm_atomic_helper_connector_hdmi_clear_audio_infoframe(connector);
+ guard(mutex)(&hdmi->phy.lock);
+ if (!hdmi->phy.enabled)
+ return;
+
if (hdmi->tmds_char_rate)
dw_hdmi_qp_audio_disable_regs(hdmi);
}
@@ -551,6 +575,7 @@ static void dw_hdmi_qp_bridge_atomic_enable(struct drm_bridge *bridge,
if (WARN_ON(!conn_state))
return;
+ mutex_lock(&hdmi->phy.lock);
This is not quite right as it keeps the lock held across
drm_connector_hdmi_enable_scrambling() - which involves SCDC I2C transfers - and
PHY init. Similarly, atomic_disable() holds it across
drm_connector_hdmi_disable_scrambling(), which may call
cancel_delayed_work_sync(). Only the state update needs to happen under the
lock.
Thanks for the suggestion, I will reduce lock scope in the next version.
if (connector->display_info.is_hdmi) {
op_mode = 0;
hdmi->tmds_char_rate = conn_state->hdmi.tmds_char_rate;
@@ -572,10 +597,25 @@ static void dw_hdmi_qp_bridge_atomic_enable(struct drm_bridge *bridge,
scoped_guard(mutex, &hdmi->mutex)
hdmi->curr_conn = connector;
- hdmi->phy.ops->init(hdmi, hdmi->phy.data);
+ ret = hdmi->phy.ops->init(hdmi, hdmi->phy.data);
+ if (unlikely(ret)) {
This is unrelated to the audio issue, and also incomplete, as scrambling and the
SCDC monitoring work are left enabled on the failure path.
Indeed this unlikely failure isn't critical, we can remove the change until the PHY driver actually has failures to handle.
Thanks for the suggestion, I will modify it if the decision is adding a new mutex in the next version.+ dev_err(hdmi->dev, "failed to initialize PHY: %d\n", ret);
+ scoped_guard(mutex, &hdmi->mutex) {
+ drm_connector_put(hdmi->curr_conn);
+ hdmi->curr_conn = NULL;
+ }
+
+ hdmi->phy.enabled = false;
+ hdmi->tmds_char_rate = 0;
+
+ mutex_unlock(&hdmi->phy.lock);
+ return;
+ }
+ hdmi->phy.enabled = true;
dw_hdmi_qp_mod(hdmi, HDCP2_BYPASS, HDCP2_BYPASS, HDCP2LOGIC_CONFIG0);
dw_hdmi_qp_mod(hdmi, op_mode, OPMODE_DVI, LINK_CONFIG0);
+ mutex_unlock(&hdmi->phy.lock);
drm_atomic_helper_connector_hdmi_update_infoframes(connector, state);
}
@@ -593,12 +633,14 @@ static void dw_hdmi_qp_bridge_atomic_disable(struct drm_bridge *bridge,
}
}
+ guard(mutex)(&hdmi->phy.lock);
hdmi->tmds_char_rate = 0;
connector = drm_atomic_get_old_connector_for_encoder(state, bridge->encoder);
drm_connector_hdmi_disable_scrambling(connector);
hdmi->phy.ops->disable(hdmi, hdmi->phy.data);
+ hdmi->phy.enabled = false;
}
static enum drm_connector_status
@@ -689,10 +731,8 @@ static int dw_hdmi_qp_bridge_clear_spd_infoframe(struct drm_bridge *bridge)
return 0;
}
-static int dw_hdmi_qp_bridge_clear_audio_infoframe(struct drm_bridge *bridge)
+static int dw_hdmi_qp_clear_audio_infoframe_regs(struct dw_hdmi_qp *hdmi)
{
- struct dw_hdmi_qp *hdmi = bridge->driver_private;
-
dw_hdmi_qp_mod(hdmi, 0,
PKTSCHED_ACR_TX_EN |
PKTSCHED_AUDS_TX_EN |
@@ -702,6 +742,17 @@ static int dw_hdmi_qp_bridge_clear_audio_infoframe(struct drm_bridge *bridge)
return 0;
}
+static int dw_hdmi_qp_bridge_clear_audio_infoframe(struct drm_bridge *bridge)
+{
+ struct dw_hdmi_qp *hdmi = bridge->driver_private;
+
+ guard(mutex)(&hdmi->phy.lock);
+ if (!hdmi->phy.enabled)
+ return 0;
+
+ return dw_hdmi_qp_clear_audio_infoframe_regs(hdmi);
+}
+
static void dw_hdmi_qp_write_pkt(struct dw_hdmi_qp *hdmi, const u8 *buffer,
size_t start, size_t len, unsigned int reg)
{
@@ -796,7 +847,11 @@ static int dw_hdmi_qp_bridge_write_audio_infoframe(struct drm_bridge *bridge,
{
struct dw_hdmi_qp *hdmi = bridge->driver_private;
- dw_hdmi_qp_bridge_clear_audio_infoframe(bridge);
+ guard(mutex)(&hdmi->phy.lock);
+ if (!hdmi->phy.enabled)
+ return -EOPNOTSUPP;
+
+ dw_hdmi_qp_clear_audio_infoframe_regs(hdmi);
/*
* AUDI_CONTENTS0: { RSV, HB2, HB1, RSV }
@@ -1129,6 +1184,8 @@ struct dw_hdmi_qp *dw_hdmi_qp_bind(struct platform_device *pdev,
hdmi->phy.ops = plat_data->phy_ops;
hdmi->phy.data = plat_data->phy_data;
+ hdmi->phy.enabled = false;
The explicit false assignment is redundant, as the struct is zero-allocated.
+ mutex_init(&hdmi->phy.lock);
Please use devm_mutex_init() and check its return value, if we really need a new
mutex here.
Cristian
Best regards,
Frank Zhang