ASoC: hdac_hda: add HDA patch loader support
Subsystems (4)
Bard Liao
maintainerPATCH 1/1 ASoC: hdac_hda: add HDA patch loader support
HDA patch loader is supported by legacy HDA driver. Implement it on ASoC HDA driver, too.
--- sound/soc/codecs/hdac_hda.c | 28 ++++++++++++++++++++++++++++ sound/soc/codecs/hdac_hda.h | 4 ++++ sound/soc/intel/skylake/skl.c | 1 + sound/soc/sof/intel/hda-codec.c | 1 + 4 files changed, 34 insertions(+)
sound/soc/codecs/hdac_hda.c +28 -0
@@ -7,6 +7,7 @@* codec drivers using hdac_ext_bus_ops ops. */ +#include <linux/firmware.h> #include <linux/init.h> #include <linux/delay.h> #include <linux/module.h>
@@ -35,6 +36,13 @@ SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\ SNDRV_PCM_RATE_192000) +#ifdef CONFIG_SND_HDA_PATCH_LOADER +static char *loadable_patch[SNDRV_CARDS ]; + +module_param_array_named (patch, loadable_patch, charp,NULL ,0444 ); +MODULE_PARM_DESC (patch,"Patch file for Intel HD audio interface." ); +#endif +static int hdac_hda_dai_open (struct snd_pcm_substream *substream,struct snd_soc_dai *dai); static void hdac_hda_dai_close(struct snd_pcm_substream *substream,
@@ -423,6 +431,26 @@ static int hdac_hda_codec_probe(struct snd_soc_component *component)dev_err (&hdev->dev,"failed to create hda codec %d\n" , ret); goto error_no_pm; } + +#ifdef CONFIG_SND_HDA_PATCH_LOADER +if (loadable_patch[hda_pvt->dev_index] && *loadable_patch[hda_pvt->dev_index]) { +dev_info (&hdev->dev,"Applying patch firmware '%s'\n" , + loadable_patch[hda_pvt->dev_index]); + ret =request_firmware (&hda_pvt->fw, loadable_patch[hda_pvt->dev_index], + &hdev->dev); +if (ret <0 ) + goto error_no_pm; +if (hda_pvt->fw) { + ret =snd_hda_load_patch (hcodec->bus, hda_pvt->fw->size, hda_pvt->fw->data); +if (ret <0 ) { +dev_err (&hdev->dev,"failed to load hda patch %d\n" , ret); + goto error_no_pm; + } +release_firmware (hda_pvt->fw); + hda_pvt->fw =NULL ; + } + } +#endif /* * Overwrite type to HDA_DEV_ASOC since it is a ASoC driver * hda_codec.c will check this flag to determine if unregister
sound/soc/codecs/hdac_hda.h +4 -0
@@ -26,6 +26,10 @@ struct hdac_hda_priv {struct hda_codec *codec;struct hdac_hda_pcm pcm[HDAC_DAI_ID_NUM ];bool need_display_power; +int dev_index; +#ifdef CONFIG_SND_HDA_PATCH_LOADER +const struct firmware *fw; +#endif };struct hdac_ext_bus_ops *snd_soc_hdac_hda_get_ops (void );
sound/soc/intel/skylake/skl.c +1 -0
@@ -736,6 +736,7 @@ static int probe_codec(struct hdac_bus *bus, int addr)return PTR_ERR (codec); hda_codec->codec = codec; + hda_codec->dev_index = addr;dev_set_drvdata (&codec->core.dev, hda_codec);/* use legacy bus only for HDA codecs, idisp uses ext bus */
sound/soc/sof/intel/hda-codec.c +1 -0
@@ -169,6 +169,7 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address)return ret; hda_priv->codec = codec; + hda_priv->dev_index = address;dev_set_drvdata (&codec->core.dev, hda_priv);if ((resp &0xFFFF0000 ) ==IDISP_VID_INTEL ) {
Signature · 1 line
2.25.1
sound/soc/codecs/hdac_hda.c line 40
Quoted 3 lines · Bard Liao
sound/soc/codecs/hdac_hda.c +2
-0+#ifdef CONFIG_SND_HDA_PATCH_LOADER +static char *loadable_patch[SNDRV_CARDS ];
Hm, this size looks wrong.
In the code later in this patch, dev_index points to the codec address, and it's basically irrelevant with SNDRV_CARDS. As SNDRV_CARDS might be 8 depending on the config, it can go beyond the array size, too. Use a different array size to match with the codec address ranges.
sound/soc/codecs/hdac_hda.c line 43
Quoted 2 lines
sound/soc/codecs/hdac_hda.c +2
-0+module_param_array_named (patch, loadable_patch, charp,NULL ,0444 ); +MODULE_PARM_DESC (patch,"Patch file for Intel HD audio interface." );
Better to give a bit more description; when it's a codec address array, it can be non-zero, and user may wonder why it's not applied.
Quoted 6 lines
sound/soc/codecs/hdac_hda.c +6
-0+#ifdef CONFIG_SND_HDA_PATCH_LOADER +if (loadable_patch[hda_pvt->dev_index] && *loadable_patch[hda_pvt->dev_index]) { +dev_info (&hdev->dev,"Applying patch firmware '%s'\n" , + loadable_patch[hda_pvt->dev_index]); + ret =request_firmware (&hda_pvt->fw, loadable_patch[hda_pvt->dev_index], + &hdev->dev);
sound/soc/codecs/hdac_hda.c static int hdac_hda_codec_probe(struct snd_soc_component *component) · line 450
Quoted 10 lines
sound/soc/codecs/hdac_hda.c +10
-0+if (ret <0 ) + goto error_no_pm; +if (hda_pvt->fw) { + ret =snd_hda_load_patch (hcodec->bus, hda_pvt->fw->size, hda_pvt->fw->data); +if (ret <0 ) { +dev_err (&hdev->dev,"failed to load hda patch %d\n" , ret); + goto error_no_pm; + } +release_firmware (hda_pvt->fw); + hda_pvt->fw =NULL ;
So the hda_pvt->fw is only for a temporary use, already released already here. Then...
sound/soc/codecs/hdac_hda.h struct hdac_hda_priv { · line 32
Quoted 10 lines
sound/soc/codecs/hdac_hda.h +4
-0@@ -26,6 +26,10 @@ struct hdac_hda_priv {struct hda_codec *codec;struct hdac_hda_pcm pcm[HDAC_DAI_ID_NUM ];bool need_display_power; +int dev_index; +#ifdef CONFIG_SND_HDA_PATCH_LOADER +const struct firmware *fw; +#endif
... we don't have to add a new extra field, right?
thanks,
Takashi
Quoted 17 lines
-----Original Message-----
From: Takashi Iwai <[email protected]>
Sent: Tuesday, September 19, 2023 8:55 PM
To: Bard Liao <[email protected]>
Cc: [email protected]; [email protected]; pierre- [email protected]; Liao, Bard <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] ASoC:hdac_hda: add HDA patch loader supportsound/soc/codecs/hdac_hda.c line 40
Quoted 3 lines · Bard Liao
sound/soc/codecs/hdac_hda.c +2
-0+#ifdef CONFIG_SND_HDA_PATCH_LOADER +static char *loadable_patch[SNDRV_CARDS ];Hm, this size looks wrong.
Quoted 5 lines
In the code later in this patch,
dev_indexpoints to the codec address, and it's basically irrelevant withSNDRV_CARDS. AsSNDRV_CARDSmight be 8 depending on the config, it can go beyond the array size, too. Use a different array size to match with the codec address ranges.
Thanks for pointing this out. Indeed, the array size is irrelevant with SNDRV_CARDS. I will change it to HDA_MAX_CODECS as it is the available number that we probe the codec.
Quoted 6 lines
sound/soc/codecs/hdac_hda.c line 43
Quoted 3 lines
sound/soc/codecs/hdac_hda.c +2
-0+module_param_array_named (patch, loadable_patch, charp,NULL ,0444 ); +MODULE_PARM_DESC (patch,"Patch file for Intel HD audio interface." );Better to give a bit more description; when it's a codec address array, it can be non-zero, and user may wonder why it's not applied.
Yes, I will do it.
Quoted 25 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+#ifdef CONFIG_SND_HDA_PATCH_LOADER + if (loadable_patch[hda_pvt->dev_index] &&*loadable_patch[hda_pvt->dev_index]) {
sound/soc/codecs/hdac_hda.c static int hdac_hda_codec_probe(struct snd_soc_component *component)
Quoted 3 lines
sound/soc/codecs/hdac_hda.c +3
-0+dev_info (&hdev->dev,"Applying patch firmware '%s'\n" , + loadable_patch[hda_pvt->dev_index]); + ret = request_firmware(&hda_pvt->fw,loadable_patch[hda_pvt->dev_index],
Review
Quoted 8 lines
sound/soc/codecs/hdac_hda.c +5
-0+ &hdev->dev); +if (ret <0 ) + goto error_no_pm; +if (hda_pvt->fw) { + ret = snd_hda_load_patch(hcodec->bus, hda_pvt-
fw->size,hda_pvt->fw->data);(quoted diff) +2
-0+ if (ret < 0) { + dev_err(&hdev->dev, "failed to load hda patch%d\n", ret);
sound/soc/codecs/hdac_hda.c static int hdac_hda_codec_probe(struct snd_soc_component *component) · line 450
Quoted 4 lines
sound/soc/codecs/hdac_hda.c +4
-0+ goto error_no_pm; + } +release_firmware (hda_pvt->fw); + hda_pvt->fw =NULL ;So the
hda_pvt->fwis only for a temporary use, already released already here. Then...
Quoted 12 lines
sound/soc/codecs/hdac_hda.h struct hdac_hda_priv { · line 32
Quoted 10 lines
sound/soc/codecs/hdac_hda.h +4
-0@@ -26,6 +26,10 @@ struct hdac_hda_priv {struct hda_codec *codec;struct hdac_hda_pcm pcm[HDAC_DAI_ID_NUM ];bool need_display_power; +int dev_index; +#ifdef CONFIG_SND_HDA_PATCH_LOADER +const struct firmware *fw; +#endif ... we don't have to add a new extra field, right?
Yes, I will remove it in the follow up patch.
Thanks,
Bard
Quoted 5 lines
thanks,
Takashi
Mark Brown
maintainerQuoted 4 lines · Bard Liao
HDA patch loader is supported by legacy HDA driver. Implement it on ASoC HDA driver, too.
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] ASoC: hdac_hda: add HDA patch loader support
commit: 842a62a75e709b3efb5020a25a225fa51748c5f9
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark