From 2fc06d132517c1dbcd61235de3553aabe5c1331e Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Thu, 27 Sep 2018 15:52:51 +0800 Subject: [PATCH 1/4] ASoC: SOF: Refine registeration of platform device Machine driver may check some HW features which are probed by SOF core driver. So platform device for machine driver should be registered after SOF core is ready. And at this time, dais of SOF have been registered to ASOC. It is better to register card now. Signed-off-by: Rander Wang --- sound/soc/sof/core.c | 14 ++++++++++++++ sound/soc/sof/sof-acpi-dev.c | 18 +++++++----------- sound/soc/sof/sof-pci-dev.c | 13 ------------- 3 files changed, 21 insertions(+), 24 deletions(-) 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/sof-acpi-dev.c b/sound/soc/sof/sof-acpi-dev.c index 3d6750526860bf..2f04b09efd3f5b 100644 --- a/sound/soc/sof/sof-acpi-dev.c +++ b/sound/soc/sof/sof-acpi-dev.c @@ -254,18 +254,14 @@ static int sof_acpi_probe(struct platform_device *pdev) 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..e10a86598ad146 100644 --- a/sound/soc/sof/sof-pci-dev.c +++ b/sound/soc/sof/sof-pci-dev.c @@ -246,22 +246,9 @@ static int sof_pci_probe(struct pci_dev *pci, 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)); - /* 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; } From e17f5222ab57b2b218f019e0c35cd3d8acc41030 Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Thu, 27 Sep 2018 16:17:23 +0800 Subject: [PATCH 2/4] ASOC: SOF: add info for hda machine driver (1)Hda codec status and platform name are used by machine driver to create dai links, so it need to be set in sof core (2)Try HDA codec if no I2S codec is found Signed-off-by: Rander Wang --- include/sound/sof.h | 4 ++++ sound/soc/sof/intel/hda.c | 3 +++ sound/soc/sof/sof-acpi-dev.c | 6 ++++-- sound/soc/sof/sof-pci-dev.c | 7 ++++--- sound/soc/sof/sof-spi-dev.c | 11 ----------- 5 files changed, 15 insertions(+), 16 deletions(-) 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/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 2f04b09efd3f5b..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,6 +252,7 @@ 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 ? */ diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c index e10a86598ad146..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,6 +245,7 @@ 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; + sof_pdata->platform = "sof-audio"; /* register sof-audio platform driver */ ret = sof_create_platform_device(priv); 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; } From 2d5058274d805eb7891023c75d30f7f64aa5d46c Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Thu, 27 Sep 2018 16:23:27 +0800 Subject: [PATCH 3/4] ASOC: Intel: refine the type of codec_mask from u32 to unsigned long The default type of codec_mask in HDA system is unsigned long Signed-off-by: Rander Wang --- sound/soc/intel/skylake/skl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { From ab851fc56a841cd4bc2e28887fd462d81b3f252a Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Thu, 27 Sep 2018 16:30:21 +0800 Subject: [PATCH 4/4] ASOC: Intel: refine hda machine driver to make it work with SOF Signed-off-by: Rander Wang Signed-off-by: Mengdong Lin --- sound/soc/intel/boards/Kconfig | 7 +++++-- sound/soc/intel/boards/skl_hda_dsp_generic.c | 21 ++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) 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;