diff --git a/include/sound/sof.h b/include/sound/sof.h index bc87e8800ae718..1b0bfc295a78fc 100644 --- a/include/sound/sof.h +++ b/include/sound/sof.h @@ -47,6 +47,7 @@ struct snd_sof_pdata { const struct firmware *fw; const char *drv_name; const char *name; + const char *platform; /* parent device */ struct device *dev; @@ -59,6 +60,9 @@ struct snd_sof_pdata { unsigned int gpio; unsigned int active; + /* hda codec */ + unsigned long codec_mask; + /* machine */ struct platform_device *pdev_mach; union { diff --git a/sound/soc/intel/boards/Kconfig b/sound/soc/intel/boards/Kconfig index ce36a535ac0408..c52fbbb0712e55 100644 --- a/sound/soc/intel/boards/Kconfig +++ b/sound/soc/intel/boards/Kconfig @@ -326,6 +326,10 @@ config SND_SOC_INTEL_KBL_DA7219_MAX98357A_MACH create an alsa sound card for DA7219 + MAX98357A I2S audio codec. Say Y if you have such a device. +endif ## SND_SOC_INTEL_SKYLAKE + +if SND_SOC_INTEL_SKYLAKE || SND_SOC_SOF_HDA + config SND_SOC_INTEL_SKL_HDA_DSP_GENERIC_MACH tristate "SKL/KBL/BXT/APL with HDA Codecs" select SND_SOC_HDAC_HDMI @@ -335,8 +339,7 @@ config SND_SOC_INTEL_SKL_HDA_DSP_GENERIC_MACH SKL/KBL/BXT/APL with iDisp, HDA audio codecs. Say Y or m if you have such a device. This is a recommended option. If unsure select "N". - -endif ## SND_SOC_INTEL_SKYLAKE +endif ## SND_SOC_INTEL_SKYLAKE || SND_SOC_SOF_HDA if SND_SOC_INTEL_SKYLAKE || SND_SOC_SOF_CANNONLAKE diff --git a/sound/soc/intel/boards/skl_hda_dsp_generic.c b/sound/soc/intel/boards/skl_hda_dsp_generic.c index b213e9b47505fb..6f9382db9818c5 100644 --- a/sound/soc/intel/boards/skl_hda_dsp_generic.c +++ b/sound/soc/intel/boards/skl_hda_dsp_generic.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "../../codecs/hdac_hdmi.h" #include "../skylake/skl.h" #include "skl_hda_dsp_common.h" @@ -101,16 +102,16 @@ static struct snd_soc_card hda_soc_card = { #define IDISP_ROUTE_COUNT (IDISP_DAI_COUNT * 2) #define IDISP_CODEC_MASK 0x4 -static int skl_hda_fill_card_info(struct skl_machine_pdata *pdata) +static int skl_hda_fill_card_info(const char *platform, + unsigned long codec_mask) { struct snd_soc_card *card = &hda_soc_card; - u32 codec_count, codec_mask; + u32 codec_count; int i, num_links, num_route; - codec_mask = pdata->codec_mask; codec_count = hweight_long(codec_mask); - if (codec_count == 1 && pdata->codec_mask & IDISP_CODEC_MASK) { + if (codec_count == 1 && codec_mask & IDISP_CODEC_MASK) { num_links = IDISP_DAI_COUNT; num_route = IDISP_ROUTE_COUNT; } else if (codec_count == 2 && codec_mask & IDISP_CODEC_MASK) { @@ -126,17 +127,22 @@ static int skl_hda_fill_card_info(struct skl_machine_pdata *pdata) card->num_dapm_routes = num_route; for (i = 0; i < num_links; i++) - skl_hda_be_dai_links[i].platform_name = pdata->platform; + skl_hda_be_dai_links[i].platform_name = platform; return 0; } static int skl_hda_audio_probe(struct platform_device *pdev) { - struct skl_machine_pdata *pdata; struct skl_hda_private *ctx; int ret; +#if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL) + struct snd_sof_pdata *pdata = dev_get_platdata(&pdev->dev); +#else + struct skl_machine_pdata *pdata = dev_get_drvdata(&pdev->dev); +#endif + dev_dbg(&pdev->dev, "%s: entry\n", __func__); ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC); @@ -145,11 +151,10 @@ static int skl_hda_audio_probe(struct platform_device *pdev) INIT_LIST_HEAD(&ctx->hdmi_pcm_list); - pdata = dev_get_drvdata(&pdev->dev); if (!pdata) return -EINVAL; - ret = skl_hda_fill_card_info(pdata); + ret = skl_hda_fill_card_info(pdata->platform, pdata->codec_mask); if (ret < 0) { dev_err(&pdev->dev, "Unsupported HDAudio/iDisp configuration found\n"); return ret; diff --git a/sound/soc/intel/skylake/skl.h b/sound/soc/intel/skylake/skl.h index 8d48cd7c56c835..9a9688dcf26010 100644 --- a/sound/soc/intel/skylake/skl.h +++ b/sound/soc/intel/skylake/skl.h @@ -122,7 +122,7 @@ struct skl_machine_pdata { u32 dmic_num; bool use_tplg_pcm; /* use dais and dai links from topology */ const char *platform; - u32 codec_mask; + unsigned long codec_mask; }; struct skl_dsp_ops { diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index ac20b901f32369..6ff6aee8a6c349 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -315,6 +315,20 @@ static int sof_probe(struct platform_device *pdev) goto comp_err; } + /* register machine driver */ + plat_data->pdev_mach = + platform_device_register_data(sdev->dev, + plat_data->machine->drv_name, + -1, plat_data, + sizeof(*plat_data)); + if (IS_ERR(plat_data->pdev_mach)) { + ret = PTR_ERR(plat_data->pdev_mach); + goto comp_err; + } + + dev_dbg(sdev->dev, "created machine %s\n", + dev_name(&plat_data->pdev_mach->dev)); + /* init DMA trace */ ret = snd_sof_init_trace(sdev); if (ret < 0) { diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index ba492ac3756658..d467e5db3a1236 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -415,6 +415,9 @@ static int hda_init_caps(struct snd_sof_dev *sdev) if (!bus->codec_mask) dev_info(bus->dev, "no hda codecs found!\n"); + /* used by hda machine driver to create dai links */ + sdev->pdata->codec_mask = bus->codec_mask; + /* create codec instances */ hda_codec_probe_bus(sdev); diff --git a/sound/soc/sof/sof-acpi-dev.c b/sound/soc/sof/sof-acpi-dev.c index 3d6750526860bf..cf8e8cadd47d3b 100644 --- a/sound/soc/sof/sof-acpi-dev.c +++ b/sound/soc/sof/sof-acpi-dev.c @@ -232,8 +232,9 @@ static int sof_acpi_probe(struct platform_device *pdev) if (ret < 0) return ret; #else - dev_err(dev, "No matching ASoC machine driver found - aborting probe\n"); - return -ENODEV; + dev_warn(dev, "No matching ASoC machine driver found - falling back to HDA codec\n"); + mach = snd_soc_acpi_intel_hda_machines; + mach->sof_fw_filename = desc->nocodec_fw_filename; #endif } #endif @@ -251,21 +252,18 @@ static int sof_acpi_probe(struct platform_device *pdev) priv->sof_pdata = sof_pdata; sof_pdata->dev = &pdev->dev; sof_pdata->type = SOF_DEVICE_APCI; + sof_pdata->platform = "sof-audio"; dev_set_drvdata(&pdev->dev, priv); /* do we need to generate any machine plat data ? */ - if (mach->new_mach_data) + if (mach->new_mach_data) { sof_pdata->pdev_mach = mach->new_mach_data(sof_pdata); - else - /* register machine driver, pass machine info as pdata */ - sof_pdata->pdev_mach = - platform_device_register_data(dev, mach->drv_name, -1, - (const void *)mach, - sizeof(*mach)); - if (IS_ERR(sof_pdata->pdev_mach)) - return PTR_ERR(sof_pdata->pdev_mach); - dev_dbg(dev, "created machine %s\n", - dev_name(&sof_pdata->pdev_mach->dev)); + + if (IS_ERR(sof_pdata->pdev_mach)) + return PTR_ERR(sof_pdata->pdev_mach); + dev_dbg(dev, "created machine %s\n", + dev_name(&sof_pdata->pdev_mach->dev)); + } /* register sof-audio platform driver */ ret = sof_create_platform_device(priv); diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c index fcef2bb1318215..cd2be5f4623602 100644 --- a/sound/soc/sof/sof-pci-dev.c +++ b/sound/soc/sof/sof-pci-dev.c @@ -229,9 +229,9 @@ static int sof_pci_probe(struct pci_dev *pci, if (ret < 0) goto release_regions; #else - dev_err(dev, "No matching ASoC machine driver found - aborting probe\n"); - ret = -ENODEV; - goto release_regions; + dev_warn(dev, "No matching ASoC machine driver found - falling back to HDA codec\n"); + mach = snd_soc_acpi_intel_hda_machines; + mach->sof_fw_filename = desc->nocodec_fw_filename; #endif } #endif @@ -245,23 +245,11 @@ static int sof_pci_probe(struct pci_dev *pci, priv->sof_pdata = sof_pdata; sof_pdata->dev = &pci->dev; sof_pdata->type = SOF_DEVICE_PCI; - - /* register machine driver */ - sof_pdata->pdev_mach = - platform_device_register_data(dev, mach->drv_name, -1, - sof_pdata, sizeof(*sof_pdata)); - if (IS_ERR(sof_pdata->pdev_mach)) { - ret = PTR_ERR(sof_pdata->pdev_mach); - goto release_regions; - } - - dev_dbg(dev, "created machine %s\n", - dev_name(&sof_pdata->pdev_mach->dev)); + sof_pdata->platform = "sof-audio"; /* register sof-audio platform driver */ ret = sof_create_platform_device(priv); if (ret) { - platform_device_unregister(sof_pdata->pdev_mach); dev_err(dev, "error: failed to create platform device!\n"); goto release_regions; } diff --git a/sound/soc/sof/sof-spi-dev.c b/sound/soc/sof/sof-spi-dev.c index c5b3befa19e37d..dc5867b7fa4a4e 100644 --- a/sound/soc/sof/sof-spi-dev.c +++ b/sound/soc/sof/sof-spi-dev.c @@ -130,20 +130,9 @@ static int sof_spi_probe(struct spi_device *spi) sof_pdata->dev = dev; sof_pdata->type = SOF_DEVICE_SPI; - /* register machine driver */ - sof_pdata->pdev_mach = - platform_device_register_data(dev, mach->drv_name, -1, - sof_pdata, sizeof(*sof_pdata)); - if (IS_ERR(sof_pdata->pdev_mach)) - return PTR_ERR(sof_pdata->pdev_mach); - - dev_dbg(dev, "created machine %s\n", - dev_name(&sof_pdata->pdev_mach->dev)); - /* register sof-audio platform driver */ ret = sof_create_platform_device(priv); if (ret) { - platform_device_unregister(sof_pdata->pdev_mach); dev_err(dev, "error: failed to create platform device!\n"); return ret; }