From nobody Sat Jul 25 02:10:55 2026 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 861B243149F for ; Mon, 20 Jul 2026 15:44:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784562249; cv=none; b=Ur7uwZjzcYWPRYk49m/jjzsAdf5f0Zz54T3zUwySKt0oM4XDA1FlUsnWbWL88JXXH7KvgycCPZJrD57hQP0cYlptVPCIjJGKvP+giU3t3fUEyK/BRA/Yq/raA2pBWP+QaetN4QcgnnzXOK8BOjwlrIhvOd8LhH4BNWGDW+Vc4A4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784562249; c=relaxed/simple; bh=J/Ke1CDIqxdhnwUHcO1J9YWlfFsQsC74X8A5M0zev4s=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oSdmzM24cFOQ2qvIQdI93btOY231XI5+8dLKcUthma1CI9CjuNG38FrZW/MgFNNCuPVxK7YkxtyTQfEjQN00MH7Vi1OqvhyFvQTli/4nDmla04gV+c9VzVi3rrgyXc8LSBryfHJiNMnFrG7g1fzKCFLE2WMWlUOQg9E2sUCdAPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.99) (envelope-from ) id 1wlq9v-000000004FQ-1J1Z; Mon, 20 Jul 2026 15:43:59 +0000 Date: Mon, 20 Jul 2026 16:43:56 +0100 From: Daniel Golle To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Luca Ceresoli , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Matthias Brugger , AngeloGioacchino Del Regno , Hermes Wu , Allen Chen , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH v2 1/2] drm/bridge: it6505: Add audio support Message-ID: <47c469b0e62513997236b8c4f6779159c1998143.1784561622.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jiaxin Yu Add audio support for it6505 by bridging to the hdmi-codec, registering an "hdmi-audio-codec" platform device from probe. The it6505's audio setup/shutdown helpers were merged earlier as unused code; wire them up via hdmi_codec_ops so the DAI actually appears, which unblocks the mt8186-mt6366 sound card that references it6505 as the I2S3 codec. Some DP-to-HDMI dongles get into a bad state if InfoFrame is sent without audio data, so it6505's audio is only enabled once the stream is unmuted. Signed-off-by: Jiaxin Yu Link: https://lore.kernel.org/all/20230730180803.22570-4-jiaxin.yu@mediatek= .com/ Signed-off-by: Daniel Golle --- djg: respin of Jiaxin Yu's v3, rebased onto current mainline. Changes from v3: hdmi_codec_ops lost .trigger, so drive enable/disable from .mute_stream; drop the now-redundant __maybe_unused; use it6505->dev instead of &client->dev, addressing AngeloGioacchino Del Regno's v3 review. Also fix issues in v3: initialise delayed_audio before registering the codec device; keep and unregister the platform_device and cancel delayed_audio on remove to avoid a leak and a use-after-free; cancel the delayed work on audio shutdown; and actually disable audio (not just cancel the pending enable) when the stream is muted. Note: it6505_enable_audio()/it6505_disable_audio() can still run concurrently from the delayed work, the .mute_stream / .audio_shutdown callbacks and the audio-FIFO-error IRQ; as in v3 these are left unserialised -- input welcome on whether a lock is warranted. v2: * store the hdmi-codec platform_device and unregister it on i2c remove, fixing a resource leak and use-after-free on unbind * initialise the delayed audio work before registering the codec device instead of after * synchronously cancel the delayed audio work on audio shutdown and on driver remove (cancel_delayed_work_sync) * rework the mute path to cancel pending work synchronously and disable audio immediately when muting, removing a race with the delayed enable work drivers/gpu/drm/bridge/ite-it6505.c | 101 +++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/i= te-it6505.c index 8ecb43611dba..d84441926e8e 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -476,6 +476,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; @@ -2320,19 +2321,12 @@ static void it6505_stop_link_train(struct it6505 *i= t6505) =20 static void it6505_link_train_ok(struct it6505 *it6505) { - struct device *dev =3D it6505->dev; - it6505->link_state =3D 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); =20 - if (it6505_audio_input(it6505)) { - DRM_DEV_DEBUG_DRIVER(dev, "Enable audio!"); - it6505_enable_audio(it6505); - } - if (it6505->hdcp_desired) it6505_start_hdcp(it6505); } @@ -2960,7 +2954,7 @@ static void it6505_remove_notifier_module(struct it65= 05 *it6505) } } =20 -static void __maybe_unused it6505_delayed_audio(struct work_struct *work) +static void it6505_delayed_audio(struct work_struct *work) { struct it6505 *it6505 =3D container_of(work, struct it6505, delayed_audio.work); @@ -2974,9 +2968,9 @@ static void __maybe_unused it6505_delayed_audio(struc= t work_struct *work) it6505_enable_audio(it6505); } =20 -static int __maybe_unused it6505_audio_setup_hw_params(struct it6505 *it65= 05, - struct hdmi_codec_params - *params) +static int it6505_audio_setup_hw_params(struct it6505 *it6505, + struct hdmi_codec_params + *params) { struct device *dev =3D it6505->dev; int i =3D 0; @@ -3031,18 +3025,52 @@ static int __maybe_unused it6505_audio_setup_hw_par= ams(struct it6505 *it6505, return 0; } =20 -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 =3D dev_get_drvdata(dev); =20 + cancel_delayed_work_sync(&it6505->delayed_audio); if (it6505->powered) it6505_disable_audio(it6505); } =20 -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_hw_params(struct device *dev, void *data, + struct hdmi_codec_daifmt *daifmt, + struct hdmi_codec_params *params) +{ + struct it6505 *it6505 =3D 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 =3D dev_get_drvdata(dev); + + DRM_DEV_DEBUG_DRIVER(dev, "mute: %d", enable); + + /* + * Some DP-to-HDMI dongles get into a bad state if the InfoFrame is + * sent without audio data, so only enable it6505's audio once the + * stream is unmuted (i.e. actually playing). + */ + if (enable) { + cancel_delayed_work_sync(&it6505->delayed_audio); + if (it6505->powered) + it6505_disable_audio(it6505); + } else { + queue_delayed_work(system_wq, &it6505->delayed_audio, + msecs_to_jiffies(180)); + } + + return 0; +} + +static int it6505_audio_hook_plugged_cb(struct device *dev, + void *data, + hdmi_codec_plugged_cb fn, + struct device *codec_dev) { struct it6505 *it6505 =3D data; =20 @@ -3053,6 +3081,39 @@ static int __maybe_unused it6505_audio_hook_plugged_= cb(struct device *dev, return 0; } =20 +static const struct hdmi_codec_ops it6505_audio_codec_ops =3D { + .hw_params =3D it6505_audio_hw_params, + .mute_stream =3D it6505_audio_mute, + .audio_shutdown =3D it6505_audio_shutdown, + .hook_plugged_cb =3D it6505_audio_hook_plugged_cb, +}; + +static int it6505_register_audio_driver(struct device *dev) +{ + struct it6505 *it6505 =3D dev_get_drvdata(dev); + struct hdmi_codec_pdata codec_data =3D { + .ops =3D &it6505_audio_codec_ops, + .max_i2s_channels =3D 8, + .i2s =3D 1, + .no_capture_mute =3D 1, + .data =3D it6505, + }; + struct platform_device *pdev; + + INIT_DELAYED_WORK(&it6505->delayed_audio, it6505_delayed_audio); + + pdev =3D 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 =3D pdev; + DRM_DEV_DEBUG_DRIVER(dev, "bound to %s", HDMI_CODEC_DRV_NAME); + + return 0; +} + static inline struct it6505 *bridge_to_it6505(struct drm_bridge *bridge) { return container_of(bridge, struct it6505, bridge); @@ -3612,6 +3673,12 @@ static int it6505_i2c_probe(struct i2c_client *clien= t) return err; } =20 + err =3D it6505_register_audio_driver(dev); + if (err < 0) { + dev_err(dev, "Failed to register audio driver: %d", 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); @@ -3644,6 +3711,8 @@ static void it6505_i2c_remove(struct i2c_client *clie= nt) { struct it6505 *it6505 =3D i2c_get_clientdata(client); =20 + platform_device_unregister(it6505->audio_pdev); + cancel_delayed_work_sync(&it6505->delayed_audio); drm_bridge_remove(&it6505->bridge); drm_dp_aux_unregister(&it6505->aux); it6505_debugfs_remove(it6505); --=20 2.55.0 From nobody Sat Jul 25 02:10:55 2026 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DA1B43149F for ; Mon, 20 Jul 2026 15:44:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784562264; cv=none; b=iSwE04+eIu2tZYKEhHQD02aoBGoUqQnWUYdMSznHAzrhN/DSCMonPBpcMNV7KsggIoMi1sFwP5zC5EXbCDbEXkMd9/mGCtmy5zpe1Tu71DbHBUSB6plij3LGG6n+Sh6jLyeO32yFyYPZsiVt0CKWHO55iweWPsyZx2KfZ7/dSzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784562264; c=relaxed/simple; bh=vr4THfjcYpdwQosbOISzw1I0KHXOpuk9ZEEpUi7sWPo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cnFwkmZET2Xf6AseuHhAnNR91b0AdRCCyR5r36FCD6vthK6F6Tw9RsI3rf0CXoyWOKlSkwiPN4OWG6dww2wES8tPyS8oBYjemdUruiVPeGTjOf8WUUochBy0b452460AT3eg9UsQ5leu+1gQOq1BSiFhM7j4wHJfi55M6M2w/pc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.99) (envelope-from ) id 1wlqAC-000000004GF-1w0u; Mon, 20 Jul 2026 15:44:16 +0000 Date: Mon, 20 Jul 2026 16:44:13 +0100 From: Daniel Golle To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Luca Ceresoli , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Matthias Brugger , AngeloGioacchino Del Regno , Hermes Wu , Allen Chen , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH v2 2/2] drm/bridge: it6505: Don't reject audio hw_params without an encoder Message-ID: <11d86a39a66ad81f29bb6d9274419e993d58337a.1784561622.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" it6505_audio_setup_hw_params() returns -ENODEV when the bridge is not attached to a DRM encoder. Now that it6505 registers an hdmi-audio-codec, this callback runs whenever a stream is configured on the I2S DAI it is wired to, including when that DAI is shared with another codec. On mt8186-corsola the speaker amplifier (rt1019) and it6505 share I2S3, so when the it6505 DP output has no display attached (bridge.encoder is NULL) the -ENODEV propagates up through dpcm_be_dai_hw_params() and tears down the whole backend, breaking speaker playback. The check is harmful in its own right: the rest of the function only caches the stream parameters (channel count, rate, word length) in software, none of which needs an encoder. Returning early leaves it6505->audio.channel_count at 0, which would then index audio_info_ca[-1] in it6505_enable_audio_infoframe() should a display be hotplugged while a stream is running, and makes such a hotplug play with stale parameters. Drop the encoder check so the parameters are always cached; the actual audio output is already gated by it6505->powered. Fixes: b5c84a9edcd4 ("drm/bridge: add it6505 driver") Signed-off-by: Daniel Golle --- v2: * drop the encoder check entirely instead of returning 0 early, so the stream parameters are always cached even while no display is attached; rewrite the commit message to explain why the check is harmful drivers/gpu/drm/bridge/ite-it6505.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/i= te-it6505.c index d84441926e8e..e20edbbb7c13 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -2979,9 +2979,6 @@ static int it6505_audio_setup_hw_params(struct it6505= *it6505, params->sample_rate, params->sample_width, params->cea.channels); =20 - if (!it6505->bridge.encoder) - return -ENODEV; - if (params->cea.channels <=3D 1 || params->cea.channels > 8) { DRM_DEV_DEBUG_DRIVER(dev, "channel number: %d not support", it6505->audio.channel_count); --=20 2.55.0