Commit 3fd63658 authored by Cezary Rojewski's avatar Cezary Rojewski Committed by Takashi Iwai

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: default avatarKai Vehmanen <kai.vehmanen@linux.intel.com>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: default avatarCezary Rojewski <cezary.rojewski@intel.com>
Acked-by: default avatarMark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20220816111727.3218543-4-cezary.rojewski@intel.comSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 829c6731
...@@ -246,7 +246,7 @@ static int hdac_hda_dai_hw_free(struct snd_pcm_substream *substream, ...@@ -246,7 +246,7 @@ static int hdac_hda_dai_hw_free(struct snd_pcm_substream *substream,
return -EINVAL; return -EINVAL;
hda_stream = &pcm->stream[substream->stream]; hda_stream = &pcm->stream[substream->stream];
snd_hda_codec_cleanup(&hda_pvt->codec, hda_stream, substream); snd_hda_codec_cleanup(hda_pvt->codec, hda_stream, substream);
return 0; return 0;
} }
...@@ -264,7 +264,7 @@ static int hdac_hda_dai_prepare(struct snd_pcm_substream *substream, ...@@ -264,7 +264,7 @@ static int hdac_hda_dai_prepare(struct snd_pcm_substream *substream,
int ret = 0; int ret = 0;
hda_pvt = snd_soc_component_get_drvdata(component); hda_pvt = snd_soc_component_get_drvdata(component);
hdev = &hda_pvt->codec.core; hdev = &hda_pvt->codec->core;
pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai); pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai);
if (!pcm) if (!pcm)
return -EINVAL; return -EINVAL;
...@@ -274,7 +274,7 @@ static int hdac_hda_dai_prepare(struct snd_pcm_substream *substream, ...@@ -274,7 +274,7 @@ static int hdac_hda_dai_prepare(struct snd_pcm_substream *substream,
stream = hda_pvt->pcm[dai->id].stream_tag[substream->stream]; stream = hda_pvt->pcm[dai->id].stream_tag[substream->stream];
format_val = hda_pvt->pcm[dai->id].format_val[substream->stream]; format_val = hda_pvt->pcm[dai->id].format_val[substream->stream];
ret = snd_hda_codec_prepare(&hda_pvt->codec, hda_stream, ret = snd_hda_codec_prepare(hda_pvt->codec, hda_stream,
stream, format_val, substream); stream, format_val, substream);
if (ret < 0) if (ret < 0)
dev_err(&hdev->dev, "codec prepare failed %d\n", ret); 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, ...@@ -299,7 +299,7 @@ static int hdac_hda_dai_open(struct snd_pcm_substream *substream,
hda_stream = &pcm->stream[substream->stream]; hda_stream = &pcm->stream[substream->stream];
return hda_stream->ops.open(hda_stream, &hda_pvt->codec, substream); return hda_stream->ops.open(hda_stream, hda_pvt->codec, substream);
} }
static void hdac_hda_dai_close(struct snd_pcm_substream *substream, static void hdac_hda_dai_close(struct snd_pcm_substream *substream,
...@@ -317,7 +317,7 @@ static void hdac_hda_dai_close(struct snd_pcm_substream *substream, ...@@ -317,7 +317,7 @@ static void hdac_hda_dai_close(struct snd_pcm_substream *substream,
hda_stream = &pcm->stream[substream->stream]; hda_stream = &pcm->stream[substream->stream];
hda_stream->ops.close(hda_stream, &hda_pvt->codec, substream); hda_stream->ops.close(hda_stream, hda_pvt->codec, substream);
snd_hda_codec_pcm_put(pcm); snd_hda_codec_pcm_put(pcm);
} }
...@@ -325,7 +325,7 @@ static void hdac_hda_dai_close(struct snd_pcm_substream *substream, ...@@ -325,7 +325,7 @@ static void hdac_hda_dai_close(struct snd_pcm_substream *substream,
static struct hda_pcm *snd_soc_find_pcm_from_dai(struct hdac_hda_priv *hda_pvt, static struct hda_pcm *snd_soc_find_pcm_from_dai(struct hdac_hda_priv *hda_pvt,
struct snd_soc_dai *dai) struct snd_soc_dai *dai)
{ {
struct hda_codec *hcodec = &hda_pvt->codec; struct hda_codec *hcodec = hda_pvt->codec;
struct hda_pcm *cpcm; struct hda_pcm *cpcm;
const char *pcm_name; const char *pcm_name;
...@@ -394,8 +394,8 @@ static int hdac_hda_codec_probe(struct snd_soc_component *component) ...@@ -394,8 +394,8 @@ static int hdac_hda_codec_probe(struct snd_soc_component *component)
snd_soc_component_get_drvdata(component); snd_soc_component_get_drvdata(component);
struct snd_soc_dapm_context *dapm = struct snd_soc_dapm_context *dapm =
snd_soc_component_get_dapm(component); snd_soc_component_get_dapm(component);
struct hdac_device *hdev = &hda_pvt->codec.core; struct hdac_device *hdev = &hda_pvt->codec->core;
struct hda_codec *hcodec = &hda_pvt->codec; struct hda_codec *hcodec = hda_pvt->codec;
struct hdac_ext_link *hlink; struct hdac_ext_link *hlink;
hda_codec_patch_t patch; hda_codec_patch_t patch;
int ret; int ret;
...@@ -515,8 +515,8 @@ static void hdac_hda_codec_remove(struct snd_soc_component *component) ...@@ -515,8 +515,8 @@ static void hdac_hda_codec_remove(struct snd_soc_component *component)
{ {
struct hdac_hda_priv *hda_pvt = struct hdac_hda_priv *hda_pvt =
snd_soc_component_get_drvdata(component); snd_soc_component_get_drvdata(component);
struct hdac_device *hdev = &hda_pvt->codec.core; struct hdac_device *hdev = &hda_pvt->codec->core;
struct hda_codec *codec = &hda_pvt->codec; struct hda_codec *codec = hda_pvt->codec;
struct hdac_ext_link *hlink = NULL; struct hdac_ext_link *hlink = NULL;
hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev)); 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 = { ...@@ -584,7 +584,6 @@ static const struct snd_soc_component_driver hdac_hda_codec = {
static int hdac_hda_dev_probe(struct hdac_device *hdev) static int hdac_hda_dev_probe(struct hdac_device *hdev)
{ {
struct hdac_ext_link *hlink; struct hdac_ext_link *hlink;
struct hdac_hda_priv *hda_pvt;
int ret; int ret;
/* hold the ref while we probe */ /* hold the ref while we probe */
...@@ -595,10 +594,6 @@ static int hdac_hda_dev_probe(struct hdac_device *hdev) ...@@ -595,10 +594,6 @@ static int hdac_hda_dev_probe(struct hdac_device *hdev)
} }
snd_hdac_ext_bus_link_get(hdev->bus, hlink); snd_hdac_ext_bus_link_get(hdev->bus, hlink);
hda_pvt = hdac_to_hda_priv(hdev);
if (!hda_pvt)
return -ENOMEM;
/* ASoC specific initialization */ /* ASoC specific initialization */
ret = devm_snd_soc_register_component(&hdev->dev, ret = devm_snd_soc_register_component(&hdev->dev,
&hdac_hda_codec, hdac_hda_dais, &hdac_hda_codec, hdac_hda_dais,
...@@ -608,7 +603,6 @@ static int hdac_hda_dev_probe(struct hdac_device *hdev) ...@@ -608,7 +603,6 @@ static int hdac_hda_dev_probe(struct hdac_device *hdev)
return ret; return ret;
} }
dev_set_drvdata(&hdev->dev, hda_pvt);
snd_hdac_ext_bus_link_put(hdev->bus, hlink); snd_hdac_ext_bus_link_put(hdev->bus, hlink);
return ret; return ret;
......
...@@ -23,7 +23,7 @@ struct hdac_hda_pcm { ...@@ -23,7 +23,7 @@ struct hdac_hda_pcm {
}; };
struct hdac_hda_priv { struct hdac_hda_priv {
struct hda_codec codec; struct hda_codec *codec;
struct hdac_hda_pcm pcm[HDAC_LAST_DAI_ID]; struct hdac_hda_pcm pcm[HDAC_LAST_DAI_ID];
bool need_display_power; bool need_display_power;
}; };
......
...@@ -54,7 +54,7 @@ int hda_dsp_hdmi_build_controls(struct snd_soc_card *card, ...@@ -54,7 +54,7 @@ int hda_dsp_hdmi_build_controls(struct snd_soc_card *card,
return -EINVAL; return -EINVAL;
hda_pvt = snd_soc_component_get_drvdata(comp); hda_pvt = snd_soc_component_get_drvdata(comp);
hcodec = &hda_pvt->codec; hcodec = hda_pvt->codec;
list_for_each_entry(hpcm, &hcodec->pcm_list_head, list) { list_for_each_entry(hpcm, &hcodec->pcm_list_head, list) {
spcm = hda_dsp_hdmi_pcm_handle(card, i); spcm = hda_dsp_hdmi_pcm_handle(card, i);
......
...@@ -190,7 +190,7 @@ static void skl_set_hda_codec_autosuspend_delay(struct snd_soc_card *card) ...@@ -190,7 +190,7 @@ static void skl_set_hda_codec_autosuspend_delay(struct snd_soc_card *card)
* all codecs are on the same bus, so it's sufficient * all codecs are on the same bus, so it's sufficient
* to look up only the first one * to look up only the first one
*/ */
snd_hda_set_power_save(hda_pvt->codec.bus, snd_hda_set_power_save(hda_pvt->codec->bus,
HDA_CODEC_AUTOSUSPEND_DELAY_MS); HDA_CODEC_AUTOSUSPEND_DELAY_MS);
break; break;
} }
......
...@@ -694,7 +694,7 @@ static void skl_codec_device_exit(struct device *dev) ...@@ -694,7 +694,7 @@ static void skl_codec_device_exit(struct device *dev)
snd_hdac_device_exit(dev_to_hdac_dev(dev)); snd_hdac_device_exit(dev_to_hdac_dev(dev));
} }
static __maybe_unused struct hda_codec *skl_codec_device_init(struct hdac_bus *bus, int addr) static struct hda_codec *skl_codec_device_init(struct hdac_bus *bus, int addr)
{ {
struct hda_codec *codec; struct hda_codec *codec;
int ret; int ret;
...@@ -729,9 +729,8 @@ static int probe_codec(struct hdac_bus *bus, int addr) ...@@ -729,9 +729,8 @@ static int probe_codec(struct hdac_bus *bus, int addr)
struct skl_dev *skl = bus_to_skl(bus); struct skl_dev *skl = bus_to_skl(bus);
#if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC) #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC)
struct hdac_hda_priv *hda_codec; struct hdac_hda_priv *hda_codec;
int err;
#endif #endif
struct hdac_device *hdev; struct hda_codec *codec;
mutex_lock(&bus->cmd_mutex); mutex_lock(&bus->cmd_mutex);
snd_hdac_bus_send_cmd(bus, cmd); snd_hdac_bus_send_cmd(bus, cmd);
...@@ -747,25 +746,22 @@ static int probe_codec(struct hdac_bus *bus, int addr) ...@@ -747,25 +746,22 @@ static int probe_codec(struct hdac_bus *bus, int addr)
if (!hda_codec) if (!hda_codec)
return -ENOMEM; return -ENOMEM;
hda_codec->codec.bus = skl_to_hbus(skl); codec = skl_codec_device_init(bus, addr);
hdev = &hda_codec->codec.core; if (IS_ERR(codec))
return PTR_ERR(codec);
err = snd_hdac_ext_bus_device_init(bus, addr, hdev, HDA_DEV_ASOC); hda_codec->codec = codec;
if (err < 0) dev_set_drvdata(&codec->core.dev, hda_codec);
return err;
/* use legacy bus only for HDA codecs, idisp uses ext bus */ /* use legacy bus only for HDA codecs, idisp uses ext bus */
if ((res & 0xFFFF0000) != IDISP_INTEL_VENDOR_ID) { if ((res & 0xFFFF0000) != IDISP_INTEL_VENDOR_ID) {
hdev->type = HDA_DEV_LEGACY; codec->core.type = HDA_DEV_LEGACY;
load_codec_module(&hda_codec->codec); load_codec_module(hda_codec->codec);
} }
return 0; return 0;
#else #else
hdev = devm_kzalloc(&skl->pci->dev, sizeof(*hdev), GFP_KERNEL); codec = skl_codec_device_init(bus, addr);
if (!hdev) return PTR_ERR_OR_ZERO(codec);
return -ENOMEM;
return snd_hdac_ext_bus_device_init(bus, addr, hdev, HDA_DEV_ASOC);
#endif /* CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC */ #endif /* CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC */
} }
......
...@@ -114,8 +114,7 @@ static void hda_codec_device_exit(struct device *dev) ...@@ -114,8 +114,7 @@ static void hda_codec_device_exit(struct device *dev)
snd_hdac_device_exit(dev_to_hdac_dev(dev)); snd_hdac_device_exit(dev_to_hdac_dev(dev));
} }
static __maybe_unused struct hda_codec * static struct hda_codec *hda_codec_device_init(struct hdac_bus *bus, int addr, int type)
hda_codec_device_init(struct hdac_bus *bus, int addr, int type)
{ {
struct hda_codec *codec; struct hda_codec *codec;
int ret; int ret;
...@@ -145,11 +144,10 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address, ...@@ -145,11 +144,10 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address,
{ {
#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC) #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
struct hdac_hda_priv *hda_priv; struct hdac_hda_priv *hda_priv;
struct hda_codec *codec;
int type = HDA_DEV_LEGACY; int type = HDA_DEV_LEGACY;
#endif #endif
struct hda_bus *hbus = sof_to_hbus(sdev); struct hda_bus *hbus = sof_to_hbus(sdev);
struct hdac_device *hdev; struct hda_codec *codec;
u32 hda_cmd = (address << 28) | (AC_NODE_ROOT << 20) | u32 hda_cmd = (address << 28) | (AC_NODE_ROOT << 20) |
(AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
u32 resp = -1; u32 resp = -1;
...@@ -172,20 +170,20 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address, ...@@ -172,20 +170,20 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address,
if (!hda_priv) if (!hda_priv)
return -ENOMEM; return -ENOMEM;
hda_priv->codec.bus = hbus;
hdev = &hda_priv->codec.core;
codec = &hda_priv->codec;
/* only probe ASoC codec drivers for HDAC-HDMI */ /* only probe ASoC codec drivers for HDAC-HDMI */
if (!hda_codec_use_common_hdmi && (resp & 0xFFFF0000) == IDISP_VID_INTEL) if (!hda_codec_use_common_hdmi && (resp & 0xFFFF0000) == IDISP_VID_INTEL)
type = HDA_DEV_ASOC; type = HDA_DEV_ASOC;
ret = snd_hdac_ext_bus_device_init(&hbus->core, address, hdev, type); codec = hda_codec_device_init(&hbus->core, address, type);
ret = PTR_ERR_OR_ZERO(codec);
if (ret < 0) if (ret < 0)
return ret; return ret;
hda_priv->codec = codec;
dev_set_drvdata(&codec->core.dev, hda_priv);
if ((resp & 0xFFFF0000) == IDISP_VID_INTEL) { if ((resp & 0xFFFF0000) == IDISP_VID_INTEL) {
if (!hdev->bus->audio_component) { if (!hbus->core.audio_component) {
dev_dbg(sdev->dev, dev_dbg(sdev->dev,
"iDisp hw present but no driver\n"); "iDisp hw present but no driver\n");
ret = -ENOENT; ret = -ENOENT;
...@@ -211,15 +209,12 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address, ...@@ -211,15 +209,12 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address,
out: out:
if (ret < 0) { if (ret < 0) {
snd_hdac_device_unregister(hdev); snd_hdac_device_unregister(&codec->core);
put_device(&hdev->dev); put_device(&codec->core.dev);
} }
#else #else
hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL); codec = hda_codec_device_init(&hbus->core, address);
if (!hdev) ret = PTR_ERR_OR_ZERO(codec);
return -ENOMEM;
ret = snd_hdac_ext_bus_device_init(&hbus->core, address, hdev, HDA_DEV_ASOC);
#endif #endif
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment