From: Daniel Golle <daniel@makrotopia.org>
To: Neil Armstrong <neil.armstrong@linaro.org>,
Dmitry Baryshkov <lumag@kernel.org>,
Robert Foss <rfoss@kernel.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Hermes Wu <hermes.wu@ite.com.tw>,
Pin-yen Lin <treapking@chromium.org>
Cc: Chen-Yu Tsai <wenst@chromium.org>,
Jiaxin Yu <jiaxin.yu@mediatek.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: [PATCH v9 13/14] drm/bridge: it6505: Add audio support
Date: Fri, 20 Nov 2026 00:06:00 +0000 [thread overview]
Message-ID: <9fa6e149442b5f7294814762b858ecabc3db4d38.1795132452.git.daniel@makrotopia.org> (raw)
In-Reply-To: <cover.1795132452.git.daniel@makrotopia.org>
From: Jiaxin Yu <jiaxin.yu@mediatek.com>
Add audio support for it6505 by bridging to the hdmi-codec: register
an "hdmi-audio-codec" platform device from probe and wire up the
previously unused audio helpers via hdmi_codec_ops. This unblocks the
mt8186-mt6366 sound card which references it6505 as the I2S3 codec.
Audio starts out muted and is only enabled once the stream is
unmuted, since some DP-to-HDMI dongles get into a bad state if the
InfoFrame is sent without audio data. Enable/disable can race between
the FIFO-error IRQ, the delayed enable work, the hdmi-codec ops and
the HPD-low path, so the register sequences, the mute state and the
cached stream parameters are serialised with a new audio_lock mutex.
it6505_poweron() and it6505_poweroff() change it6505->powered under
the same lock, poweron holding it across the logic reset and init
sequence: the codec ops and the delayed work check the flag before
writing registers, and the mute and shutdown ops run from ALSA, where
a work cancel cannot reach them. plugged_cb/codec_dev updates take
mode_lock, the lock it6505_detect() holds when calling back into the
codec.
Signed-off-by: Jiaxin Yu <jiaxin.yu@mediatek.com>
Link: https://lore.kernel.org/all/20230730180803.22570-4-jiaxin.yu@mediatek.com/
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/gpu/drm/bridge/ite-it6505.c | 168 ++++++++++++++++++++++------
1 file changed, 136 insertions(+), 32 deletions(-)
diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c
index 2da58d94127c3..eedc46eaf974b 100644
--- a/drivers/gpu/drm/bridge/ite-it6505.c
+++ b/drivers/gpu/drm/bridge/ite-it6505.c
@@ -407,6 +407,7 @@ struct it6505_audio_data {
u8 i2s_data_delay;
u8 i2s_ws_channel;
u8 i2s_data_sequence;
+ bool mute;
};
struct it6505_audio_sample_rate_map {
@@ -441,6 +442,7 @@ struct it6505 {
struct mutex aux_lock; /* used to aux data transfers */
struct mutex aux_reg_lock; /* protects aux_registered */
bool aux_registered;
+ struct mutex audio_lock; /* audio enable/disable vs. power on/off */
struct regmap *regmap;
struct drm_display_mode source_output_mode;
struct drm_display_mode video_info;
@@ -479,6 +481,7 @@ struct it6505 {
bool enable_enhanced_frame;
hdmi_codec_plugged_cb plugged_cb;
struct device *codec_dev;
+ struct platform_device *audio_pdev;
struct delayed_work delayed_audio;
struct it6505_audio_data audio;
struct dentry *debugfs;
@@ -1601,7 +1604,7 @@ static void it6505_enable_audio_infoframe(struct it6505 *it6505)
EN_AUD_CTRL_PKT);
}
-static void it6505_disable_audio(struct it6505 *it6505)
+static void __it6505_disable_audio(struct it6505 *it6505)
{
it6505_set_bits(it6505, REG_DATA_MUTE_CTRL, EN_AUD_MUTE, EN_AUD_MUTE);
it6505_set_bits(it6505, REG_AUDIO_SRC_CTRL, M_AUDIO_I2S_EN, 0x00);
@@ -1609,12 +1612,20 @@ static void it6505_disable_audio(struct it6505 *it6505)
it6505_set_bits(it6505, REG_RESET_CTRL, AUDIO_RESET, AUDIO_RESET);
}
-static void it6505_enable_audio(struct it6505 *it6505)
+static void it6505_disable_audio(struct it6505 *it6505)
+{
+ mutex_lock(&it6505->audio_lock);
+ __it6505_disable_audio(it6505);
+ mutex_unlock(&it6505->audio_lock);
+}
+
+static void __it6505_enable_audio(struct it6505 *it6505)
{
struct device *dev = it6505->dev;
DRM_DEV_DEBUG_DRIVER(dev, "start");
- it6505_disable_audio(it6505);
+
+ __it6505_disable_audio(it6505);
it6505_setup_audio_channel_status(it6505);
it6505_setup_audio_format(it6505);
@@ -2326,19 +2337,12 @@ static void it6505_stop_link_train(struct it6505 *it6505)
static void it6505_link_train_ok(struct it6505 *it6505)
{
- struct device *dev = it6505->dev;
-
it6505->link_state = LINK_OK;
/* disalbe mute enable avi info frame */
it6505_set_bits(it6505, REG_DATA_MUTE_CTRL, EN_VID_MUTE, 0x00);
it6505_set_bits(it6505, REG_INFOFRAME_CTRL,
EN_VID_CTRL_PKT, EN_VID_CTRL_PKT);
- if (it6505_audio_input(it6505)) {
- DRM_DEV_DEBUG_DRIVER(dev, "Enable audio!");
- it6505_enable_audio(it6505);
- }
-
if (it6505->hdcp_desired)
it6505_start_hdcp(it6505);
}
@@ -2630,8 +2634,10 @@ static void it6505_irq_audio_fifo_error(struct it6505 *it6505)
DRM_DEV_DEBUG_DRIVER(dev, "audio fifo error Interrupt");
- if (it6505_audio_input(it6505))
- it6505_enable_audio(it6505);
+ mutex_lock(&it6505->audio_lock);
+ if (!it6505->audio.mute && it6505_audio_input(it6505))
+ __it6505_enable_audio(it6505);
+ mutex_unlock(&it6505->audio_lock);
}
static void it6505_irq_link_train_fail(struct it6505 *it6505)
@@ -2785,11 +2791,13 @@ static int it6505_poweron(struct it6505 *it6505)
usleep_range(25000, 35000);
}
+ mutex_lock(&it6505->audio_lock);
it6505->powered = true;
it6505_reset_logic(it6505);
it6505_int_mask_enable(it6505);
it6505_init(it6505);
it6505_lane_off(it6505);
+ mutex_unlock(&it6505->audio_lock);
enable_irq(it6505->irq);
@@ -2814,6 +2822,8 @@ static int it6505_poweroff(struct it6505 *it6505)
cancel_work_sync(&it6505->hdcp_wait_ksv_list);
cancel_delayed_work_sync(&it6505->hdcp_work);
+ mutex_lock(&it6505->audio_lock);
+
if (pdata->gpiod_reset)
gpiod_set_value_cansleep(pdata->gpiod_reset, 1);
@@ -2833,6 +2843,7 @@ static int it6505_poweroff(struct it6505 *it6505)
it6505->powered = false;
it6505->sink_count = 0;
+ mutex_unlock(&it6505->audio_lock);
return 0;
}
@@ -2979,25 +2990,28 @@ static void it6505_remove_notifier_module(struct it6505 *it6505)
flush_work(&it6505->extcon_wq);
}
-static void __maybe_unused it6505_delayed_audio(struct work_struct *work)
+static void it6505_delayed_audio(struct work_struct *work)
{
struct it6505 *it6505 = container_of(work, struct it6505,
delayed_audio.work);
DRM_DEV_DEBUG_DRIVER(it6505->dev, "start");
- if (!it6505->powered)
+ if (it6505->enable_drv_hold)
return;
- if (!it6505->enable_drv_hold)
- it6505_enable_audio(it6505);
+ mutex_lock(&it6505->audio_lock);
+ if (it6505->powered && !it6505->audio.mute)
+ __it6505_enable_audio(it6505);
+ mutex_unlock(&it6505->audio_lock);
}
-static int __maybe_unused it6505_audio_setup_hw_params(struct it6505 *it6505,
- struct hdmi_codec_params
- *params)
+static int it6505_audio_setup_hw_params(struct it6505 *it6505,
+ struct hdmi_codec_params
+ *params)
{
struct device *dev = it6505->dev;
+ u8 word_length;
int i = 0;
DRM_DEV_DEBUG_DRIVER(dev, "%s %d Hz, %d bit, %d channels\n", __func__,
@@ -3013,8 +3027,6 @@ static int __maybe_unused it6505_audio_setup_hw_params(struct it6505 *it6505,
return -EINVAL;
}
- it6505->audio.channel_count = params->cea.channels;
-
while (i < ARRAY_SIZE(audio_sample_rate_map) &&
params->sample_rate !=
audio_sample_rate_map[i].sample_rate_value) {
@@ -3025,21 +3037,20 @@ static int __maybe_unused it6505_audio_setup_hw_params(struct it6505 *it6505,
params->sample_rate);
return -EINVAL;
}
- it6505->audio.sample_rate = audio_sample_rate_map[i].rate;
switch (params->sample_width) {
case 16:
- it6505->audio.word_length = WORD_LENGTH_16BIT;
+ word_length = WORD_LENGTH_16BIT;
break;
case 18:
- it6505->audio.word_length = WORD_LENGTH_18BIT;
+ word_length = WORD_LENGTH_18BIT;
break;
case 20:
- it6505->audio.word_length = WORD_LENGTH_20BIT;
+ word_length = WORD_LENGTH_20BIT;
break;
case 24:
case 32:
- it6505->audio.word_length = WORD_LENGTH_24BIT;
+ word_length = WORD_LENGTH_24BIT;
break;
default:
DRM_DEV_DEBUG_DRIVER(dev, "wordlength: %d bit not support",
@@ -3047,27 +3058,111 @@ static int __maybe_unused it6505_audio_setup_hw_params(struct it6505 *it6505,
return -EINVAL;
}
+ mutex_lock(&it6505->audio_lock);
+ it6505->audio.channel_count = params->cea.channels;
+ it6505->audio.sample_rate = audio_sample_rate_map[i].rate;
+ it6505->audio.word_length = word_length;
+ mutex_unlock(&it6505->audio_lock);
+
return 0;
}
-static void __maybe_unused it6505_audio_shutdown(struct device *dev, void *data)
+static void it6505_audio_shutdown(struct device *dev, void *data)
{
struct it6505 *it6505 = dev_get_drvdata(dev);
+ mutex_lock(&it6505->audio_lock);
+ it6505->audio.mute = true;
if (it6505->powered)
- it6505_disable_audio(it6505);
+ __it6505_disable_audio(it6505);
+ mutex_unlock(&it6505->audio_lock);
+ cancel_delayed_work_sync(&it6505->delayed_audio);
+}
+
+static int it6505_audio_hw_params(struct device *dev, void *data,
+ struct hdmi_codec_daifmt *daifmt,
+ struct hdmi_codec_params *params)
+{
+ struct it6505 *it6505 = dev_get_drvdata(dev);
+
+ return it6505_audio_setup_hw_params(it6505, params);
+}
+
+static int it6505_audio_mute(struct device *dev, void *data,
+ bool enable, int direction)
+{
+ struct it6505 *it6505 = dev_get_drvdata(dev);
+
+ DRM_DEV_DEBUG_DRIVER(dev, "mute: %d", enable);
+
+ /*
+ * Delay enabling audio until the stream is unmuted; InfoFrames
+ * without audio data upset some DP-to-HDMI dongles.
+ */
+ if (enable) {
+ mutex_lock(&it6505->audio_lock);
+ it6505->audio.mute = true;
+ if (it6505->powered)
+ __it6505_disable_audio(it6505);
+ mutex_unlock(&it6505->audio_lock);
+ cancel_delayed_work_sync(&it6505->delayed_audio);
+ } else {
+ mutex_lock(&it6505->audio_lock);
+ it6505->audio.mute = false;
+ mutex_unlock(&it6505->audio_lock);
+ queue_delayed_work(system_wq, &it6505->delayed_audio,
+ msecs_to_jiffies(180));
+ }
+
+ return 0;
}
-static int __maybe_unused it6505_audio_hook_plugged_cb(struct device *dev,
- void *data,
- hdmi_codec_plugged_cb fn,
- struct device *codec_dev)
+static int it6505_audio_hook_plugged_cb(struct device *dev,
+ void *data,
+ hdmi_codec_plugged_cb fn,
+ struct device *codec_dev)
{
struct it6505 *it6505 = data;
+ mutex_lock(&it6505->mode_lock);
it6505->plugged_cb = fn;
it6505->codec_dev = codec_dev;
it6505_plugged_status_to_codec(it6505);
+ mutex_unlock(&it6505->mode_lock);
+
+ return 0;
+}
+
+static const struct hdmi_codec_ops it6505_audio_codec_ops = {
+ .hw_params = it6505_audio_hw_params,
+ .mute_stream = it6505_audio_mute,
+ .audio_shutdown = it6505_audio_shutdown,
+ .hook_plugged_cb = it6505_audio_hook_plugged_cb,
+};
+
+static int it6505_register_audio_driver(struct device *dev)
+{
+ struct it6505 *it6505 = dev_get_drvdata(dev);
+ struct hdmi_codec_pdata codec_data = {
+ .ops = &it6505_audio_codec_ops,
+ .max_i2s_channels = 8,
+ .i2s = 1,
+ .no_capture_mute = 1,
+ .data = it6505,
+ };
+ struct platform_device *pdev;
+
+ it6505->audio.mute = true;
+ INIT_DELAYED_WORK(&it6505->delayed_audio, it6505_delayed_audio);
+
+ pdev = platform_device_register_data(dev, HDMI_CODEC_DRV_NAME,
+ PLATFORM_DEVID_AUTO, &codec_data,
+ sizeof(codec_data));
+ if (IS_ERR(pdev))
+ return PTR_ERR(pdev);
+
+ it6505->audio_pdev = pdev;
+ DRM_DEV_DEBUG_DRIVER(dev, "bound to %s", HDMI_CODEC_DRV_NAME);
return 0;
}
@@ -3606,6 +3701,7 @@ static int it6505_i2c_probe(struct i2c_client *client)
mutex_init(&it6505->mode_lock);
mutex_init(&it6505->aux_lock);
mutex_init(&it6505->aux_reg_lock);
+ mutex_init(&it6505->audio_lock);
it6505->bridge.of_node = client->dev.of_node;
it6505->connector_status = connector_status_disconnected;
@@ -3654,6 +3750,12 @@ static int it6505_i2c_probe(struct i2c_client *client)
if (err)
return err;
+ err = it6505_register_audio_driver(dev);
+ if (err < 0) {
+ dev_err(dev, "Failed to register audio driver: %d\n", err);
+ return err;
+ }
+
INIT_WORK(&it6505->link_works, it6505_link_training_work);
INIT_WORK(&it6505->hdcp_wait_ksv_list, it6505_hdcp_wait_ksv_list);
INIT_DELAYED_WORK(&it6505->hdcp_work, it6505_hdcp_work);
@@ -3696,6 +3798,8 @@ static void it6505_i2c_remove(struct i2c_client *client)
cancel_work_sync(&it6505->hdcp_wait_ksv_list);
cancel_delayed_work_sync(&it6505->hdcp_work);
cancel_work_sync(&it6505->extcon_wq);
+ platform_device_unregister(it6505->audio_pdev);
+ cancel_delayed_work_sync(&it6505->delayed_audio);
if (it6505->extcon_state)
pm_runtime_put_sync(&client->dev);
pm_runtime_disable(&client->dev);
--
2.56.1
next prev parent reply other threads:[~2026-11-20 0:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 23:58 [PATCH v9 00/14] drm/bridge: it6505: DP audio support + shared-DAI hw_params fix Daniel Golle
2026-11-19 23:58 ` [PATCH v9 01/14] drm/bridge: it6505: quiesce event sources and work on remove() Daniel Golle
2026-11-19 23:59 ` [PATCH v9 02/14] drm/bridge: it6505: quiesce work items before powering off Daniel Golle
2026-11-19 23:59 ` [PATCH v9 03/14] drm/bridge: it6505: balance and disable runtime PM on remove Daniel Golle
2026-11-19 23:59 ` [PATCH v9 04/14] drm/bridge: it6505: unregister DP AUX adapter on bridge detach Daniel Golle
2026-11-19 23:59 ` [PATCH v9 05/14] drm/bridge: it6505: complete poweroff even if disabling regulators fails Daniel Golle
2026-11-20 0:02 ` [PATCH v9 06/14] drm/bridge: it6505: bail out of the IRQ handler when status reads fail Daniel Golle
2026-11-20 0:03 ` [PATCH v9 07/14] drm/bridge: it6505: avoid division by zero in pixel clock calculation Daniel Golle
2026-11-20 0:03 ` [PATCH v9 08/14] drm/bridge: it6505: drop the audio input FS debug print Daniel Golle
2026-11-20 0:04 ` [PATCH v9 09/14] drm/bridge: it6505: guard against zero channel count in audio infoframe Daniel Golle
2026-11-20 0:04 ` [PATCH v9 10/14] drm/bridge: it6505: hold endpoint OF node reference while parsing it Daniel Golle
2026-11-20 0:05 ` [PATCH v9 11/14] drm/bridge: it6505: reject a too short link-frequencies property Daniel Golle
2026-11-20 0:05 ` [PATCH v9 12/14] drm/bridge: it6505: don't write an error code back to the reset register Daniel Golle
2026-11-20 0:06 ` Daniel Golle [this message]
2026-11-20 0:06 ` [PATCH v9 14/14] drm/bridge: it6505: Don't reject audio hw_params without an encoder Daniel Golle
2026-11-20 0:12 ` [PATCH v9 00/14] drm/bridge: it6505: DP audio support + shared-DAI hw_params fix Daniel Golle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9fa6e149442b5f7294814762b858ecabc3db4d38.1795132452.git.daniel@makrotopia.org \
--to=daniel@makrotopia.org \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hermes.wu@ite.com.tw \
--cc=jernej.skrabec@gmail.com \
--cc=jiaxin.yu@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=luca.ceresoli@bootlin.com \
--cc=lumag@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthias.bgg@gmail.com \
--cc=mripard@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=rfoss@kernel.org \
--cc=simona@ffwll.ch \
--cc=treapking@chromium.org \
--cc=tzimmermann@suse.de \
--cc=wenst@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®