Skip to content

Commit 3fd6365

Browse files
crojewsk-inteltiwai
authored andcommitted
ASoC: Intel: Drop hdac_ext usage for codec device creation
To make snd_hda_codec_device_init() the only constructor for struct hda_codec instances remaining tasks are: 1) no struct may wrap struct hda_codec as its base type 2) bus drivers (skylake and sof) which are the current hdac_ext users need to be adjusted to make use of newly added codec init and exit routines instead 3) as bus drivers (skylake and sof) are to be responsible for creating codec device and assigning it to hdac_hda_priv->codec, hdac_hda_dev_probe() has to be freed of that job To keep git bisect happy, all of these in made in one-go. Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com> Acked-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20220816111727.3218543-4-cezary.rojewski@intel.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 829c673 commit 3fd6365

File tree

6 files changed

+36
-51
lines changed

6 files changed

+36
-51
lines changed

sound/soc/codecs/hdac_hda.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static int hdac_hda_dai_hw_free(struct snd_pcm_substream *substream,
246246
return -EINVAL;
247247

248248
hda_stream = &pcm->stream[substream->stream];
249-
snd_hda_codec_cleanup(&hda_pvt->codec, hda_stream, substream);
249+
snd_hda_codec_cleanup(hda_pvt->codec, hda_stream, substream);
250250

251251
return 0;
252252
}
@@ -264,7 +264,7 @@ static int hdac_hda_dai_prepare(struct snd_pcm_substream *substream,
264264
int ret = 0;
265265

266266
hda_pvt = snd_soc_component_get_drvdata(component);
267-
hdev = &hda_pvt->codec.core;
267+
hdev = &hda_pvt->codec->core;
268268
pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai);
269269
if (!pcm)
270270
return -EINVAL;
@@ -274,7 +274,7 @@ static int hdac_hda_dai_prepare(struct snd_pcm_substream *substream,
274274
stream = hda_pvt->pcm[dai->id].stream_tag[substream->stream];
275275
format_val = hda_pvt->pcm[dai->id].format_val[substream->stream];
276276

277-
ret = snd_hda_codec_prepare(&hda_pvt->codec, hda_stream,
277+
ret = snd_hda_codec_prepare(hda_pvt->codec, hda_stream,
278278
stream, format_val, substream);
279279
if (ret < 0)
280280
dev_err(&hdev->dev, "codec prepare failed %d\n", ret);
@@ -299,7 +299,7 @@ static int hdac_hda_dai_open(struct snd_pcm_substream *substream,
299299

300300
hda_stream = &pcm->stream[substream->stream];
301301

302-
return hda_stream->ops.open(hda_stream, &hda_pvt->codec, substream);
302+
return hda_stream->ops.open(hda_stream, hda_pvt->codec, substream);
303303
}
304304

305305
static void hdac_hda_dai_close(struct snd_pcm_substream *substream,
@@ -317,15 +317,15 @@ static void hdac_hda_dai_close(struct snd_pcm_substream *substream,
317317

318318
hda_stream = &pcm->stream[substream->stream];
319319

320-
hda_stream->ops.close(hda_stream, &hda_pvt->codec, substream);
320+
hda_stream->ops.close(hda_stream, hda_pvt->codec, substream);
321321

322322
snd_hda_codec_pcm_put(pcm);
323323
}
324324

325325
static struct hda_pcm *snd_soc_find_pcm_from_dai(struct hdac_hda_priv *hda_pvt,
326326
struct snd_soc_dai *dai)
327327
{
328-
struct hda_codec *hcodec = &hda_pvt->codec;
328+
struct hda_codec *hcodec = hda_pvt->codec;
329329
struct hda_pcm *cpcm;
330330
const char *pcm_name;
331331

@@ -394,8 +394,8 @@ static int hdac_hda_codec_probe(struct snd_soc_component *component)
394394
snd_soc_component_get_drvdata(component);
395395
struct snd_soc_dapm_context *dapm =
396396
snd_soc_component_get_dapm(component);
397-
struct hdac_device *hdev = &hda_pvt->codec.core;
398-
struct hda_codec *hcodec = &hda_pvt->codec;
397+
struct hdac_device *hdev = &hda_pvt->codec->core;
398+
struct hda_codec *hcodec = hda_pvt->codec;
399399
struct hdac_ext_link *hlink;
400400
hda_codec_patch_t patch;
401401
int ret;
@@ -515,8 +515,8 @@ static void hdac_hda_codec_remove(struct snd_soc_component *component)
515515
{
516516
struct hdac_hda_priv *hda_pvt =
517517
snd_soc_component_get_drvdata(component);
518-
struct hdac_device *hdev = &hda_pvt->codec.core;
519-
struct hda_codec *codec = &hda_pvt->codec;
518+
struct hdac_device *hdev = &hda_pvt->codec->core;
519+
struct hda_codec *codec = hda_pvt->codec;
520520
struct hdac_ext_link *hlink = NULL;
521521

522522
hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
@@ -584,7 +584,6 @@ static const struct snd_soc_component_driver hdac_hda_codec = {
584584
static int hdac_hda_dev_probe(struct hdac_device *hdev)
585585
{
586586
struct hdac_ext_link *hlink;
587-
struct hdac_hda_priv *hda_pvt;
588587
int ret;
589588

590589
/* hold the ref while we probe */
@@ -595,10 +594,6 @@ static int hdac_hda_dev_probe(struct hdac_device *hdev)
595594
}
596595
snd_hdac_ext_bus_link_get(hdev->bus, hlink);
597596

598-
hda_pvt = hdac_to_hda_priv(hdev);
599-
if (!hda_pvt)
600-
return -ENOMEM;
601-
602597
/* ASoC specific initialization */
603598
ret = devm_snd_soc_register_component(&hdev->dev,
604599
&hdac_hda_codec, hdac_hda_dais,
@@ -608,7 +603,6 @@ static int hdac_hda_dev_probe(struct hdac_device *hdev)
608603
return ret;
609604
}
610605

611-
dev_set_drvdata(&hdev->dev, hda_pvt);
612606
snd_hdac_ext_bus_link_put(hdev->bus, hlink);
613607

614608
return ret;

sound/soc/codecs/hdac_hda.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct hdac_hda_pcm {
2323
};
2424

2525
struct hdac_hda_priv {
26-
struct hda_codec codec;
26+
struct hda_codec *codec;
2727
struct hdac_hda_pcm pcm[HDAC_LAST_DAI_ID];
2828
bool need_display_power;
2929
};

sound/soc/intel/boards/hda_dsp_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int hda_dsp_hdmi_build_controls(struct snd_soc_card *card,
5454
return -EINVAL;
5555

5656
hda_pvt = snd_soc_component_get_drvdata(comp);
57-
hcodec = &hda_pvt->codec;
57+
hcodec = hda_pvt->codec;
5858

5959
list_for_each_entry(hpcm, &hcodec->pcm_list_head, list) {
6060
spcm = hda_dsp_hdmi_pcm_handle(card, i);

sound/soc/intel/boards/skl_hda_dsp_generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static void skl_set_hda_codec_autosuspend_delay(struct snd_soc_card *card)
190190
* all codecs are on the same bus, so it's sufficient
191191
* to look up only the first one
192192
*/
193-
snd_hda_set_power_save(hda_pvt->codec.bus,
193+
snd_hda_set_power_save(hda_pvt->codec->bus,
194194
HDA_CODEC_AUTOSUSPEND_DELAY_MS);
195195
break;
196196
}

sound/soc/intel/skylake/skl.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static void skl_codec_device_exit(struct device *dev)
694694
snd_hdac_device_exit(dev_to_hdac_dev(dev));
695695
}
696696

697-
static __maybe_unused struct hda_codec *skl_codec_device_init(struct hdac_bus *bus, int addr)
697+
static struct hda_codec *skl_codec_device_init(struct hdac_bus *bus, int addr)
698698
{
699699
struct hda_codec *codec;
700700
int ret;
@@ -729,9 +729,8 @@ static int probe_codec(struct hdac_bus *bus, int addr)
729729
struct skl_dev *skl = bus_to_skl(bus);
730730
#if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC)
731731
struct hdac_hda_priv *hda_codec;
732-
int err;
733732
#endif
734-
struct hdac_device *hdev;
733+
struct hda_codec *codec;
735734

736735
mutex_lock(&bus->cmd_mutex);
737736
snd_hdac_bus_send_cmd(bus, cmd);
@@ -747,25 +746,22 @@ static int probe_codec(struct hdac_bus *bus, int addr)
747746
if (!hda_codec)
748747
return -ENOMEM;
749748

750-
hda_codec->codec.bus = skl_to_hbus(skl);
751-
hdev = &hda_codec->codec.core;
749+
codec = skl_codec_device_init(bus, addr);
750+
if (IS_ERR(codec))
751+
return PTR_ERR(codec);
752752

753-
err = snd_hdac_ext_bus_device_init(bus, addr, hdev, HDA_DEV_ASOC);
754-
if (err < 0)
755-
return err;
753+
hda_codec->codec = codec;
754+
dev_set_drvdata(&codec->core.dev, hda_codec);
756755

757756
/* use legacy bus only for HDA codecs, idisp uses ext bus */
758757
if ((res & 0xFFFF0000) != IDISP_INTEL_VENDOR_ID) {
759-
hdev->type = HDA_DEV_LEGACY;
760-
load_codec_module(&hda_codec->codec);
758+
codec->core.type = HDA_DEV_LEGACY;
759+
load_codec_module(hda_codec->codec);
761760
}
762761
return 0;
763762
#else
764-
hdev = devm_kzalloc(&skl->pci->dev, sizeof(*hdev), GFP_KERNEL);
765-
if (!hdev)
766-
return -ENOMEM;
767-
768-
return snd_hdac_ext_bus_device_init(bus, addr, hdev, HDA_DEV_ASOC);
763+
codec = skl_codec_device_init(bus, addr);
764+
return PTR_ERR_OR_ZERO(codec);
769765
#endif /* CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC */
770766
}
771767

sound/soc/sof/intel/hda-codec.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ static void hda_codec_device_exit(struct device *dev)
114114
snd_hdac_device_exit(dev_to_hdac_dev(dev));
115115
}
116116

117-
static __maybe_unused struct hda_codec *
118-
hda_codec_device_init(struct hdac_bus *bus, int addr, int type)
117+
static struct hda_codec *hda_codec_device_init(struct hdac_bus *bus, int addr, int type)
119118
{
120119
struct hda_codec *codec;
121120
int ret;
@@ -145,11 +144,10 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address,
145144
{
146145
#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
147146
struct hdac_hda_priv *hda_priv;
148-
struct hda_codec *codec;
149147
int type = HDA_DEV_LEGACY;
150148
#endif
151149
struct hda_bus *hbus = sof_to_hbus(sdev);
152-
struct hdac_device *hdev;
150+
struct hda_codec *codec;
153151
u32 hda_cmd = (address << 28) | (AC_NODE_ROOT << 20) |
154152
(AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
155153
u32 resp = -1;
@@ -172,20 +170,20 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address,
172170
if (!hda_priv)
173171
return -ENOMEM;
174172

175-
hda_priv->codec.bus = hbus;
176-
hdev = &hda_priv->codec.core;
177-
codec = &hda_priv->codec;
178-
179173
/* only probe ASoC codec drivers for HDAC-HDMI */
180174
if (!hda_codec_use_common_hdmi && (resp & 0xFFFF0000) == IDISP_VID_INTEL)
181175
type = HDA_DEV_ASOC;
182176

183-
ret = snd_hdac_ext_bus_device_init(&hbus->core, address, hdev, type);
177+
codec = hda_codec_device_init(&hbus->core, address, type);
178+
ret = PTR_ERR_OR_ZERO(codec);
184179
if (ret < 0)
185180
return ret;
186181

182+
hda_priv->codec = codec;
183+
dev_set_drvdata(&codec->core.dev, hda_priv);
184+
187185
if ((resp & 0xFFFF0000) == IDISP_VID_INTEL) {
188-
if (!hdev->bus->audio_component) {
186+
if (!hbus->core.audio_component) {
189187
dev_dbg(sdev->dev,
190188
"iDisp hw present but no driver\n");
191189
ret = -ENOENT;
@@ -211,15 +209,12 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address,
211209

212210
out:
213211
if (ret < 0) {
214-
snd_hdac_device_unregister(hdev);
215-
put_device(&hdev->dev);
212+
snd_hdac_device_unregister(&codec->core);
213+
put_device(&codec->core.dev);
216214
}
217215
#else
218-
hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
219-
if (!hdev)
220-
return -ENOMEM;
221-
222-
ret = snd_hdac_ext_bus_device_init(&hbus->core, address, hdev, HDA_DEV_ASOC);
216+
codec = hda_codec_device_init(&hbus->core, address);
217+
ret = PTR_ERR_OR_ZERO(codec);
223218
#endif
224219

225220
return ret;

0 commit comments

Comments
 (0)