12981d9b0SVijendar Mukunda // SPDX-License-Identifier: GPL-2.0-only 22981d9b0SVijendar Mukunda // Copyright(c) 2024 Advanced Micro Devices, Inc. 32981d9b0SVijendar Mukunda 42981d9b0SVijendar Mukunda /* 52981d9b0SVijendar Mukunda * acp-sdw-legacy-mach - ASoC legacy Machine driver for AMD SoundWire platforms 62981d9b0SVijendar Mukunda */ 72981d9b0SVijendar Mukunda 82981d9b0SVijendar Mukunda #include <linux/bitmap.h> 92981d9b0SVijendar Mukunda #include <linux/device.h> 102981d9b0SVijendar Mukunda #include <linux/dmi.h> 112981d9b0SVijendar Mukunda #include <linux/module.h> 122981d9b0SVijendar Mukunda #include <linux/soundwire/sdw.h> 132981d9b0SVijendar Mukunda #include <linux/soundwire/sdw_type.h> 142981d9b0SVijendar Mukunda #include <sound/soc.h> 152981d9b0SVijendar Mukunda #include <sound/soc-acpi.h> 162981d9b0SVijendar Mukunda #include "soc_amd_sdw_common.h" 172981d9b0SVijendar Mukunda #include "../../codecs/rt711.h" 182981d9b0SVijendar Mukunda 192981d9b0SVijendar Mukunda static unsigned long soc_sdw_quirk = RT711_JD1; 202981d9b0SVijendar Mukunda static int quirk_override = -1; 212981d9b0SVijendar Mukunda module_param_named(quirk, quirk_override, int, 0444); 222981d9b0SVijendar Mukunda MODULE_PARM_DESC(quirk, "Board-specific quirk override"); 232981d9b0SVijendar Mukunda 242981d9b0SVijendar Mukunda static void log_quirks(struct device *dev) 252981d9b0SVijendar Mukunda { 262981d9b0SVijendar Mukunda if (SOC_JACK_JDSRC(soc_sdw_quirk)) 272981d9b0SVijendar Mukunda dev_dbg(dev, "quirk realtek,jack-detect-source %ld\n", 282981d9b0SVijendar Mukunda SOC_JACK_JDSRC(soc_sdw_quirk)); 292981d9b0SVijendar Mukunda if (soc_sdw_quirk & ASOC_SDW_ACP_DMIC) 302981d9b0SVijendar Mukunda dev_dbg(dev, "quirk SOC_SDW_ACP_DMIC enabled\n"); 312981d9b0SVijendar Mukunda } 322981d9b0SVijendar Mukunda 332981d9b0SVijendar Mukunda static int soc_sdw_quirk_cb(const struct dmi_system_id *id) 342981d9b0SVijendar Mukunda { 352981d9b0SVijendar Mukunda soc_sdw_quirk = (unsigned long)id->driver_data; 362981d9b0SVijendar Mukunda return 1; 372981d9b0SVijendar Mukunda } 382981d9b0SVijendar Mukunda 392981d9b0SVijendar Mukunda static const struct dmi_system_id soc_sdw_quirk_table[] = { 402981d9b0SVijendar Mukunda { 412981d9b0SVijendar Mukunda .callback = soc_sdw_quirk_cb, 422981d9b0SVijendar Mukunda .matches = { 432981d9b0SVijendar Mukunda DMI_MATCH(DMI_SYS_VENDOR, "AMD"), 442981d9b0SVijendar Mukunda DMI_MATCH(DMI_PRODUCT_NAME, "Birman-PHX"), 452981d9b0SVijendar Mukunda }, 462981d9b0SVijendar Mukunda .driver_data = (void *)RT711_JD2, 472981d9b0SVijendar Mukunda }, 482981d9b0SVijendar Mukunda {} 492981d9b0SVijendar Mukunda }; 502981d9b0SVijendar Mukunda 512981d9b0SVijendar Mukunda static const struct snd_soc_ops sdw_ops = { 522981d9b0SVijendar Mukunda .startup = asoc_sdw_startup, 532981d9b0SVijendar Mukunda .prepare = asoc_sdw_prepare, 542981d9b0SVijendar Mukunda .trigger = asoc_sdw_trigger, 552981d9b0SVijendar Mukunda .hw_params = asoc_sdw_hw_params, 562981d9b0SVijendar Mukunda .hw_free = asoc_sdw_hw_free, 572981d9b0SVijendar Mukunda .shutdown = asoc_sdw_shutdown, 582981d9b0SVijendar Mukunda }; 592981d9b0SVijendar Mukunda 602981d9b0SVijendar Mukunda static const char * const type_strings[] = {"SimpleJack", "SmartAmp", "SmartMic"}; 612981d9b0SVijendar Mukunda 622981d9b0SVijendar Mukunda static int create_sdw_dailink(struct snd_soc_card *card, 632981d9b0SVijendar Mukunda struct asoc_sdw_dailink *soc_dai, 642981d9b0SVijendar Mukunda struct snd_soc_dai_link **dai_links, 652981d9b0SVijendar Mukunda int *be_id, struct snd_soc_codec_conf **codec_conf, 662981d9b0SVijendar Mukunda struct snd_soc_dai_link_component *sdw_platform_component) 672981d9b0SVijendar Mukunda { 682981d9b0SVijendar Mukunda struct device *dev = card->dev; 692981d9b0SVijendar Mukunda struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); 702981d9b0SVijendar Mukunda struct amd_mc_ctx *amd_ctx = (struct amd_mc_ctx *)ctx->private; 712981d9b0SVijendar Mukunda struct asoc_sdw_endpoint *soc_end; 722981d9b0SVijendar Mukunda int cpu_pin_id; 732981d9b0SVijendar Mukunda int stream; 742981d9b0SVijendar Mukunda int ret; 752981d9b0SVijendar Mukunda 762981d9b0SVijendar Mukunda list_for_each_entry(soc_end, &soc_dai->endpoints, list) { 772981d9b0SVijendar Mukunda if (soc_end->name_prefix) { 782981d9b0SVijendar Mukunda (*codec_conf)->dlc.name = soc_end->codec_name; 792981d9b0SVijendar Mukunda (*codec_conf)->name_prefix = soc_end->name_prefix; 802981d9b0SVijendar Mukunda (*codec_conf)++; 812981d9b0SVijendar Mukunda } 822981d9b0SVijendar Mukunda 832981d9b0SVijendar Mukunda if (soc_end->include_sidecar) { 842981d9b0SVijendar Mukunda ret = soc_end->codec_info->add_sidecar(card, dai_links, codec_conf); 852981d9b0SVijendar Mukunda if (ret) 862981d9b0SVijendar Mukunda return ret; 872981d9b0SVijendar Mukunda } 882981d9b0SVijendar Mukunda } 892981d9b0SVijendar Mukunda 902981d9b0SVijendar Mukunda for_each_pcm_streams(stream) { 912981d9b0SVijendar Mukunda static const char * const sdw_stream_name[] = { 922981d9b0SVijendar Mukunda "SDW%d-PIN%d-PLAYBACK", 932981d9b0SVijendar Mukunda "SDW%d-PIN%d-CAPTURE", 942981d9b0SVijendar Mukunda "SDW%d-PIN%d-PLAYBACK-%s", 952981d9b0SVijendar Mukunda "SDW%d-PIN%d-CAPTURE-%s", 962981d9b0SVijendar Mukunda }; 972981d9b0SVijendar Mukunda struct snd_soc_dai_link_ch_map *codec_maps; 982981d9b0SVijendar Mukunda struct snd_soc_dai_link_component *codecs; 992981d9b0SVijendar Mukunda struct snd_soc_dai_link_component *cpus; 1002981d9b0SVijendar Mukunda int num_cpus = hweight32(soc_dai->link_mask[stream]); 1012981d9b0SVijendar Mukunda int num_codecs = soc_dai->num_devs[stream]; 1022981d9b0SVijendar Mukunda int playback, capture; 1032981d9b0SVijendar Mukunda int j = 0; 1042981d9b0SVijendar Mukunda char *name; 1052981d9b0SVijendar Mukunda 1062981d9b0SVijendar Mukunda if (!soc_dai->num_devs[stream]) 1072981d9b0SVijendar Mukunda continue; 1082981d9b0SVijendar Mukunda 1092981d9b0SVijendar Mukunda soc_end = list_first_entry(&soc_dai->endpoints, 1102981d9b0SVijendar Mukunda struct asoc_sdw_endpoint, list); 1112981d9b0SVijendar Mukunda 1122981d9b0SVijendar Mukunda *be_id = soc_end->dai_info->dailink[stream]; 1132981d9b0SVijendar Mukunda if (*be_id < 0) { 1142981d9b0SVijendar Mukunda dev_err(dev, "Invalid dailink id %d\n", *be_id); 1152981d9b0SVijendar Mukunda return -EINVAL; 1162981d9b0SVijendar Mukunda } 1172981d9b0SVijendar Mukunda 1182981d9b0SVijendar Mukunda switch (amd_ctx->acp_rev) { 1192981d9b0SVijendar Mukunda case ACP63_PCI_REV: 1202981d9b0SVijendar Mukunda ret = get_acp63_cpu_pin_id(ffs(soc_end->link_mask - 1), 1212981d9b0SVijendar Mukunda *be_id, &cpu_pin_id, dev); 1222981d9b0SVijendar Mukunda if (ret) 1232981d9b0SVijendar Mukunda return ret; 1242981d9b0SVijendar Mukunda break; 1252981d9b0SVijendar Mukunda default: 1262981d9b0SVijendar Mukunda return -EINVAL; 1272981d9b0SVijendar Mukunda } 1282981d9b0SVijendar Mukunda /* create stream name according to first link id */ 1292981d9b0SVijendar Mukunda if (ctx->append_dai_type) { 1302981d9b0SVijendar Mukunda name = devm_kasprintf(dev, GFP_KERNEL, 1312981d9b0SVijendar Mukunda sdw_stream_name[stream + 2], 1322981d9b0SVijendar Mukunda ffs(soc_end->link_mask) - 1, 1332981d9b0SVijendar Mukunda cpu_pin_id, 1342981d9b0SVijendar Mukunda type_strings[soc_end->dai_info->dai_type]); 1352981d9b0SVijendar Mukunda } else { 1362981d9b0SVijendar Mukunda name = devm_kasprintf(dev, GFP_KERNEL, 1372981d9b0SVijendar Mukunda sdw_stream_name[stream], 1382981d9b0SVijendar Mukunda ffs(soc_end->link_mask) - 1, 1392981d9b0SVijendar Mukunda cpu_pin_id); 1402981d9b0SVijendar Mukunda } 1412981d9b0SVijendar Mukunda if (!name) 1422981d9b0SVijendar Mukunda return -ENOMEM; 1432981d9b0SVijendar Mukunda 1442981d9b0SVijendar Mukunda cpus = devm_kcalloc(dev, num_cpus, sizeof(*cpus), GFP_KERNEL); 1452981d9b0SVijendar Mukunda if (!cpus) 1462981d9b0SVijendar Mukunda return -ENOMEM; 1472981d9b0SVijendar Mukunda 1482981d9b0SVijendar Mukunda codecs = devm_kcalloc(dev, num_codecs, sizeof(*codecs), GFP_KERNEL); 1492981d9b0SVijendar Mukunda if (!codecs) 1502981d9b0SVijendar Mukunda return -ENOMEM; 1512981d9b0SVijendar Mukunda 1522981d9b0SVijendar Mukunda codec_maps = devm_kcalloc(dev, num_codecs, sizeof(*codec_maps), GFP_KERNEL); 1532981d9b0SVijendar Mukunda if (!codec_maps) 1542981d9b0SVijendar Mukunda return -ENOMEM; 1552981d9b0SVijendar Mukunda 1562981d9b0SVijendar Mukunda list_for_each_entry(soc_end, &soc_dai->endpoints, list) { 1572981d9b0SVijendar Mukunda if (!soc_end->dai_info->direction[stream]) 1582981d9b0SVijendar Mukunda continue; 1592981d9b0SVijendar Mukunda 1602981d9b0SVijendar Mukunda int link_num = ffs(soc_end->link_mask) - 1; 1612981d9b0SVijendar Mukunda 1622981d9b0SVijendar Mukunda cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, 1632981d9b0SVijendar Mukunda "SDW%d Pin%d", 1642981d9b0SVijendar Mukunda link_num, cpu_pin_id); 1652981d9b0SVijendar Mukunda dev_dbg(dev, "cpu->dai_name:%s\n", cpus->dai_name); 1662981d9b0SVijendar Mukunda if (!cpus->dai_name) 1672981d9b0SVijendar Mukunda return -ENOMEM; 1682981d9b0SVijendar Mukunda 1692981d9b0SVijendar Mukunda codec_maps[j].cpu = 0; 1702981d9b0SVijendar Mukunda codec_maps[j].codec = j; 1712981d9b0SVijendar Mukunda 1722981d9b0SVijendar Mukunda codecs[j].name = soc_end->codec_name; 1732981d9b0SVijendar Mukunda codecs[j].dai_name = soc_end->dai_info->dai_name; 1742981d9b0SVijendar Mukunda j++; 1752981d9b0SVijendar Mukunda } 1762981d9b0SVijendar Mukunda 1772981d9b0SVijendar Mukunda WARN_ON(j != num_codecs); 1782981d9b0SVijendar Mukunda 1792981d9b0SVijendar Mukunda playback = (stream == SNDRV_PCM_STREAM_PLAYBACK); 1802981d9b0SVijendar Mukunda capture = (stream == SNDRV_PCM_STREAM_CAPTURE); 1812981d9b0SVijendar Mukunda 1822981d9b0SVijendar Mukunda asoc_sdw_init_dai_link(dev, *dai_links, be_id, name, playback, capture, 1832981d9b0SVijendar Mukunda cpus, num_cpus, sdw_platform_component, 1842981d9b0SVijendar Mukunda 1, codecs, num_codecs, 1852981d9b0SVijendar Mukunda 0, asoc_sdw_rtd_init, &sdw_ops); 1862981d9b0SVijendar Mukunda /* 1872981d9b0SVijendar Mukunda * SoundWire DAILINKs use 'stream' functions and Bank Switch operations 1882981d9b0SVijendar Mukunda * based on wait_for_completion(), tag them as 'nonatomic'. 1892981d9b0SVijendar Mukunda */ 1902981d9b0SVijendar Mukunda (*dai_links)->nonatomic = true; 1912981d9b0SVijendar Mukunda (*dai_links)->ch_maps = codec_maps; 1922981d9b0SVijendar Mukunda 1932981d9b0SVijendar Mukunda list_for_each_entry(soc_end, &soc_dai->endpoints, list) { 1942981d9b0SVijendar Mukunda if (soc_end->dai_info->init) 1952981d9b0SVijendar Mukunda soc_end->dai_info->init(card, *dai_links, 1962981d9b0SVijendar Mukunda soc_end->codec_info, 1972981d9b0SVijendar Mukunda playback); 1982981d9b0SVijendar Mukunda } 1992981d9b0SVijendar Mukunda 2002981d9b0SVijendar Mukunda (*dai_links)++; 2012981d9b0SVijendar Mukunda } 2022981d9b0SVijendar Mukunda 2032981d9b0SVijendar Mukunda return 0; 2042981d9b0SVijendar Mukunda } 2052981d9b0SVijendar Mukunda 2062981d9b0SVijendar Mukunda static int create_sdw_dailinks(struct snd_soc_card *card, 2072981d9b0SVijendar Mukunda struct snd_soc_dai_link **dai_links, int *be_id, 2082981d9b0SVijendar Mukunda struct asoc_sdw_dailink *soc_dais, 2092981d9b0SVijendar Mukunda struct snd_soc_codec_conf **codec_conf) 2102981d9b0SVijendar Mukunda { 2112981d9b0SVijendar Mukunda struct device *dev = card->dev; 2122981d9b0SVijendar Mukunda struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); 2132981d9b0SVijendar Mukunda struct amd_mc_ctx *amd_ctx = (struct amd_mc_ctx *)ctx->private; 2142981d9b0SVijendar Mukunda struct snd_soc_dai_link_component *sdw_platform_component; 2152981d9b0SVijendar Mukunda int ret; 2162981d9b0SVijendar Mukunda 2172981d9b0SVijendar Mukunda sdw_platform_component = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), 2182981d9b0SVijendar Mukunda GFP_KERNEL); 2192981d9b0SVijendar Mukunda if (!sdw_platform_component) 2202981d9b0SVijendar Mukunda return -ENOMEM; 2212981d9b0SVijendar Mukunda 2222981d9b0SVijendar Mukunda switch (amd_ctx->acp_rev) { 2232981d9b0SVijendar Mukunda case ACP63_PCI_REV: 2242981d9b0SVijendar Mukunda sdw_platform_component->name = "amd_ps_sdw_dma.0"; 2252981d9b0SVijendar Mukunda break; 2262981d9b0SVijendar Mukunda default: 2272981d9b0SVijendar Mukunda return -EINVAL; 2282981d9b0SVijendar Mukunda } 2292981d9b0SVijendar Mukunda 2302981d9b0SVijendar Mukunda /* generate DAI links by each sdw link */ 2312981d9b0SVijendar Mukunda while (soc_dais->initialised) { 2322981d9b0SVijendar Mukunda int current_be_id; 2332981d9b0SVijendar Mukunda 2342981d9b0SVijendar Mukunda ret = create_sdw_dailink(card, soc_dais, dai_links, 2352981d9b0SVijendar Mukunda ¤t_be_id, codec_conf, sdw_platform_component); 2362981d9b0SVijendar Mukunda if (ret) 2372981d9b0SVijendar Mukunda return ret; 2382981d9b0SVijendar Mukunda 2392981d9b0SVijendar Mukunda /* Update the be_id to match the highest ID used for SDW link */ 2402981d9b0SVijendar Mukunda if (*be_id < current_be_id) 2412981d9b0SVijendar Mukunda *be_id = current_be_id; 2422981d9b0SVijendar Mukunda 2432981d9b0SVijendar Mukunda soc_dais++; 2442981d9b0SVijendar Mukunda } 2452981d9b0SVijendar Mukunda 2462981d9b0SVijendar Mukunda return 0; 2472981d9b0SVijendar Mukunda } 2482981d9b0SVijendar Mukunda 2492981d9b0SVijendar Mukunda static int create_dmic_dailinks(struct snd_soc_card *card, 2502981d9b0SVijendar Mukunda struct snd_soc_dai_link **dai_links, int *be_id, int no_pcm) 2512981d9b0SVijendar Mukunda { 2522981d9b0SVijendar Mukunda struct device *dev = card->dev; 2532981d9b0SVijendar Mukunda struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); 2542981d9b0SVijendar Mukunda struct amd_mc_ctx *amd_ctx = (struct amd_mc_ctx *)ctx->private; 2552981d9b0SVijendar Mukunda struct snd_soc_dai_link_component *pdm_cpu; 2562981d9b0SVijendar Mukunda struct snd_soc_dai_link_component *pdm_platform; 2572981d9b0SVijendar Mukunda int ret; 2582981d9b0SVijendar Mukunda 2592981d9b0SVijendar Mukunda pdm_cpu = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), GFP_KERNEL); 2602981d9b0SVijendar Mukunda if (!pdm_cpu) 2612981d9b0SVijendar Mukunda return -ENOMEM; 2622981d9b0SVijendar Mukunda 2632981d9b0SVijendar Mukunda pdm_platform = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component), GFP_KERNEL); 2642981d9b0SVijendar Mukunda if (!pdm_platform) 2652981d9b0SVijendar Mukunda return -ENOMEM; 2662981d9b0SVijendar Mukunda 2672981d9b0SVijendar Mukunda switch (amd_ctx->acp_rev) { 2682981d9b0SVijendar Mukunda case ACP63_PCI_REV: 2692981d9b0SVijendar Mukunda pdm_cpu->name = "acp_ps_pdm_dma.0"; 2702981d9b0SVijendar Mukunda pdm_platform->name = "acp_ps_pdm_dma.0"; 2712981d9b0SVijendar Mukunda break; 2722981d9b0SVijendar Mukunda default: 2732981d9b0SVijendar Mukunda return -EINVAL; 2742981d9b0SVijendar Mukunda } 2752981d9b0SVijendar Mukunda 2762981d9b0SVijendar Mukunda *be_id = ACP_DMIC_BE_ID; 2772981d9b0SVijendar Mukunda ret = asoc_sdw_init_simple_dai_link(dev, *dai_links, be_id, "acp-dmic-codec", 2782981d9b0SVijendar Mukunda 0, 1, // DMIC only supports capture 2792981d9b0SVijendar Mukunda pdm_cpu->name, pdm_platform->name, 1, 2802981d9b0SVijendar Mukunda "dmic-codec.0", "dmic-hifi", no_pcm, 2812981d9b0SVijendar Mukunda asoc_sdw_dmic_init, NULL); 2822981d9b0SVijendar Mukunda if (ret) 2832981d9b0SVijendar Mukunda return ret; 2842981d9b0SVijendar Mukunda 2852981d9b0SVijendar Mukunda (*dai_links)++; 2862981d9b0SVijendar Mukunda 2872981d9b0SVijendar Mukunda return 0; 2882981d9b0SVijendar Mukunda } 2892981d9b0SVijendar Mukunda 2902981d9b0SVijendar Mukunda static int soc_card_dai_links_create(struct snd_soc_card *card) 2912981d9b0SVijendar Mukunda { 2922981d9b0SVijendar Mukunda struct device *dev = card->dev; 2932981d9b0SVijendar Mukunda struct snd_soc_acpi_mach *mach = dev_get_platdata(card->dev); 2942981d9b0SVijendar Mukunda int sdw_be_num = 0, dmic_num = 0; 2952981d9b0SVijendar Mukunda struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); 2962981d9b0SVijendar Mukunda struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params; 2972981d9b0SVijendar Mukunda struct asoc_sdw_endpoint *soc_ends __free(kfree) = NULL; 2982981d9b0SVijendar Mukunda struct asoc_sdw_dailink *soc_dais __free(kfree) = NULL; 2992981d9b0SVijendar Mukunda struct snd_soc_codec_conf *codec_conf; 3002981d9b0SVijendar Mukunda struct snd_soc_dai_link *dai_links; 3012981d9b0SVijendar Mukunda int num_devs = 0; 3022981d9b0SVijendar Mukunda int num_ends = 0; 3032981d9b0SVijendar Mukunda int num_links; 3042981d9b0SVijendar Mukunda int be_id = 0; 3052981d9b0SVijendar Mukunda int ret; 3062981d9b0SVijendar Mukunda 3072981d9b0SVijendar Mukunda ret = asoc_sdw_count_sdw_endpoints(card, &num_devs, &num_ends); 3082981d9b0SVijendar Mukunda if (ret < 0) { 3092981d9b0SVijendar Mukunda dev_err(dev, "failed to count devices/endpoints: %d\n", ret); 3102981d9b0SVijendar Mukunda return ret; 3112981d9b0SVijendar Mukunda } 3122981d9b0SVijendar Mukunda 3132981d9b0SVijendar Mukunda /* One per DAI link, worst case is a DAI link for every endpoint */ 3142981d9b0SVijendar Mukunda soc_dais = kcalloc(num_ends, sizeof(*soc_dais), GFP_KERNEL); 3152981d9b0SVijendar Mukunda if (!soc_dais) 3162981d9b0SVijendar Mukunda return -ENOMEM; 3172981d9b0SVijendar Mukunda 3182981d9b0SVijendar Mukunda /* One per endpoint, ie. each DAI on each codec/amp */ 3192981d9b0SVijendar Mukunda soc_ends = kcalloc(num_ends, sizeof(*soc_ends), GFP_KERNEL); 3202981d9b0SVijendar Mukunda if (!soc_ends) 3212981d9b0SVijendar Mukunda return -ENOMEM; 3222981d9b0SVijendar Mukunda 3232981d9b0SVijendar Mukunda ret = asoc_sdw_parse_sdw_endpoints(card, soc_dais, soc_ends, &num_devs); 3242981d9b0SVijendar Mukunda if (ret < 0) 3252981d9b0SVijendar Mukunda return ret; 3262981d9b0SVijendar Mukunda 3272981d9b0SVijendar Mukunda sdw_be_num = ret; 3282981d9b0SVijendar Mukunda 3292981d9b0SVijendar Mukunda /* enable dmic */ 3302981d9b0SVijendar Mukunda if (soc_sdw_quirk & ASOC_SDW_ACP_DMIC || mach_params->dmic_num) 3312981d9b0SVijendar Mukunda dmic_num = 1; 3322981d9b0SVijendar Mukunda 3332981d9b0SVijendar Mukunda dev_dbg(dev, "sdw %d, dmic %d", sdw_be_num, dmic_num); 3342981d9b0SVijendar Mukunda 3352981d9b0SVijendar Mukunda codec_conf = devm_kcalloc(dev, num_devs, sizeof(*codec_conf), GFP_KERNEL); 3362981d9b0SVijendar Mukunda if (!codec_conf) 3372981d9b0SVijendar Mukunda return -ENOMEM; 3382981d9b0SVijendar Mukunda 3392981d9b0SVijendar Mukunda /* allocate BE dailinks */ 3402981d9b0SVijendar Mukunda num_links = sdw_be_num + dmic_num; 3412981d9b0SVijendar Mukunda dai_links = devm_kcalloc(dev, num_links, sizeof(*dai_links), GFP_KERNEL); 3422981d9b0SVijendar Mukunda if (!dai_links) 3432981d9b0SVijendar Mukunda return -ENOMEM; 3442981d9b0SVijendar Mukunda 3452981d9b0SVijendar Mukunda card->codec_conf = codec_conf; 3462981d9b0SVijendar Mukunda card->num_configs = num_devs; 3472981d9b0SVijendar Mukunda card->dai_link = dai_links; 3482981d9b0SVijendar Mukunda card->num_links = num_links; 3492981d9b0SVijendar Mukunda 3502981d9b0SVijendar Mukunda /* SDW */ 3512981d9b0SVijendar Mukunda if (sdw_be_num) { 3522981d9b0SVijendar Mukunda ret = create_sdw_dailinks(card, &dai_links, &be_id, 3532981d9b0SVijendar Mukunda soc_dais, &codec_conf); 3542981d9b0SVijendar Mukunda if (ret) 3552981d9b0SVijendar Mukunda return ret; 3562981d9b0SVijendar Mukunda } 3572981d9b0SVijendar Mukunda 3582981d9b0SVijendar Mukunda /* dmic */ 3592981d9b0SVijendar Mukunda if (dmic_num > 0) { 3602981d9b0SVijendar Mukunda if (ctx->ignore_internal_dmic) { 3612981d9b0SVijendar Mukunda dev_warn(dev, "Ignoring ACP DMIC\n"); 3622981d9b0SVijendar Mukunda } else { 3632981d9b0SVijendar Mukunda ret = create_dmic_dailinks(card, &dai_links, &be_id, 0); 3642981d9b0SVijendar Mukunda if (ret) 3652981d9b0SVijendar Mukunda return ret; 3662981d9b0SVijendar Mukunda } 3672981d9b0SVijendar Mukunda } 3682981d9b0SVijendar Mukunda 3692981d9b0SVijendar Mukunda WARN_ON(codec_conf != card->codec_conf + card->num_configs); 3702981d9b0SVijendar Mukunda WARN_ON(dai_links != card->dai_link + card->num_links); 3712981d9b0SVijendar Mukunda 3722981d9b0SVijendar Mukunda return ret; 3732981d9b0SVijendar Mukunda } 3742981d9b0SVijendar Mukunda 3752981d9b0SVijendar Mukunda static int mc_probe(struct platform_device *pdev) 3762981d9b0SVijendar Mukunda { 3772981d9b0SVijendar Mukunda struct snd_soc_acpi_mach *mach = dev_get_platdata(&pdev->dev); 3782981d9b0SVijendar Mukunda struct snd_soc_card *card; 3792981d9b0SVijendar Mukunda struct amd_mc_ctx *amd_ctx; 3802981d9b0SVijendar Mukunda struct asoc_sdw_mc_private *ctx; 3812981d9b0SVijendar Mukunda int amp_num = 0, i; 3822981d9b0SVijendar Mukunda int ret; 3832981d9b0SVijendar Mukunda 3842981d9b0SVijendar Mukunda amd_ctx = devm_kzalloc(&pdev->dev, sizeof(*amd_ctx), GFP_KERNEL); 3852981d9b0SVijendar Mukunda if (!amd_ctx) 3862981d9b0SVijendar Mukunda return -ENOMEM; 3872981d9b0SVijendar Mukunda 3882981d9b0SVijendar Mukunda amd_ctx->acp_rev = mach->mach_params.subsystem_rev; 3892981d9b0SVijendar Mukunda amd_ctx->max_sdw_links = ACP63_SDW_MAX_LINKS; 3902981d9b0SVijendar Mukunda ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 3912981d9b0SVijendar Mukunda if (!ctx) 3922981d9b0SVijendar Mukunda return -ENOMEM; 3932981d9b0SVijendar Mukunda ctx->codec_info_list_count = asoc_sdw_get_codec_info_list_count(); 3942981d9b0SVijendar Mukunda ctx->private = amd_ctx; 3952981d9b0SVijendar Mukunda card = &ctx->card; 3962981d9b0SVijendar Mukunda card->dev = &pdev->dev; 3972981d9b0SVijendar Mukunda card->name = "amd-soundwire"; 3982981d9b0SVijendar Mukunda card->owner = THIS_MODULE; 3992981d9b0SVijendar Mukunda card->late_probe = asoc_sdw_card_late_probe; 4002981d9b0SVijendar Mukunda 4012981d9b0SVijendar Mukunda snd_soc_card_set_drvdata(card, ctx); 4022981d9b0SVijendar Mukunda 4032981d9b0SVijendar Mukunda dmi_check_system(soc_sdw_quirk_table); 4042981d9b0SVijendar Mukunda 4052981d9b0SVijendar Mukunda if (quirk_override != -1) { 4062981d9b0SVijendar Mukunda dev_info(card->dev, "Overriding quirk 0x%lx => 0x%x\n", 4072981d9b0SVijendar Mukunda soc_sdw_quirk, quirk_override); 4082981d9b0SVijendar Mukunda soc_sdw_quirk = quirk_override; 4092981d9b0SVijendar Mukunda } 4102981d9b0SVijendar Mukunda 4112981d9b0SVijendar Mukunda log_quirks(card->dev); 4122981d9b0SVijendar Mukunda 4132981d9b0SVijendar Mukunda ctx->mc_quirk = soc_sdw_quirk; 4142981d9b0SVijendar Mukunda dev_dbg(card->dev, "legacy quirk 0x%lx\n", ctx->mc_quirk); 4152981d9b0SVijendar Mukunda /* reset amp_num to ensure amp_num++ starts from 0 in each probe */ 4162981d9b0SVijendar Mukunda for (i = 0; i < ctx->codec_info_list_count; i++) 4172981d9b0SVijendar Mukunda codec_info_list[i].amp_num = 0; 4182981d9b0SVijendar Mukunda 4192981d9b0SVijendar Mukunda ret = soc_card_dai_links_create(card); 4202981d9b0SVijendar Mukunda if (ret < 0) 4212981d9b0SVijendar Mukunda return ret; 4222981d9b0SVijendar Mukunda 4232981d9b0SVijendar Mukunda /* 4242981d9b0SVijendar Mukunda * the default amp_num is zero for each codec and 4252981d9b0SVijendar Mukunda * amp_num will only be increased for active amp 4262981d9b0SVijendar Mukunda * codecs on used platform 4272981d9b0SVijendar Mukunda */ 4282981d9b0SVijendar Mukunda for (i = 0; i < ctx->codec_info_list_count; i++) 4292981d9b0SVijendar Mukunda amp_num += codec_info_list[i].amp_num; 4302981d9b0SVijendar Mukunda 4312981d9b0SVijendar Mukunda card->components = devm_kasprintf(card->dev, GFP_KERNEL, 4322981d9b0SVijendar Mukunda " cfg-amp:%d", amp_num); 4332981d9b0SVijendar Mukunda if (!card->components) 4342981d9b0SVijendar Mukunda return -ENOMEM; 4352981d9b0SVijendar Mukunda if (mach->mach_params.dmic_num) { 4362981d9b0SVijendar Mukunda card->components = devm_kasprintf(card->dev, GFP_KERNEL, 4372981d9b0SVijendar Mukunda "%s mic:dmic cfg-mics:%d", 4382981d9b0SVijendar Mukunda card->components, 4392981d9b0SVijendar Mukunda mach->mach_params.dmic_num); 4402981d9b0SVijendar Mukunda if (!card->components) 4412981d9b0SVijendar Mukunda return -ENOMEM; 4422981d9b0SVijendar Mukunda } 4432981d9b0SVijendar Mukunda 4442981d9b0SVijendar Mukunda /* Register the card */ 4452981d9b0SVijendar Mukunda ret = devm_snd_soc_register_card(card->dev, card); 4462981d9b0SVijendar Mukunda if (ret) { 4472981d9b0SVijendar Mukunda dev_err_probe(card->dev, ret, "snd_soc_register_card failed %d\n", ret); 4482981d9b0SVijendar Mukunda asoc_sdw_mc_dailink_exit_loop(card); 4492981d9b0SVijendar Mukunda return ret; 4502981d9b0SVijendar Mukunda } 4512981d9b0SVijendar Mukunda 4522981d9b0SVijendar Mukunda platform_set_drvdata(pdev, card); 4532981d9b0SVijendar Mukunda 4542981d9b0SVijendar Mukunda return ret; 4552981d9b0SVijendar Mukunda } 4562981d9b0SVijendar Mukunda 4572981d9b0SVijendar Mukunda static void mc_remove(struct platform_device *pdev) 4582981d9b0SVijendar Mukunda { 4592981d9b0SVijendar Mukunda struct snd_soc_card *card = platform_get_drvdata(pdev); 4602981d9b0SVijendar Mukunda 4612981d9b0SVijendar Mukunda asoc_sdw_mc_dailink_exit_loop(card); 4622981d9b0SVijendar Mukunda } 4632981d9b0SVijendar Mukunda 4642981d9b0SVijendar Mukunda static const struct platform_device_id mc_id_table[] = { 4652981d9b0SVijendar Mukunda { "amd_sdw", }, 4662981d9b0SVijendar Mukunda {} 4672981d9b0SVijendar Mukunda }; 4682981d9b0SVijendar Mukunda MODULE_DEVICE_TABLE(platform, mc_id_table); 4692981d9b0SVijendar Mukunda 4702981d9b0SVijendar Mukunda static struct platform_driver soc_sdw_driver = { 4712981d9b0SVijendar Mukunda .driver = { 4722981d9b0SVijendar Mukunda .name = "amd_sdw", 4732981d9b0SVijendar Mukunda .pm = &snd_soc_pm_ops, 4742981d9b0SVijendar Mukunda }, 4752981d9b0SVijendar Mukunda .probe = mc_probe, 4762981d9b0SVijendar Mukunda .remove = mc_remove, 4772981d9b0SVijendar Mukunda .id_table = mc_id_table, 4782981d9b0SVijendar Mukunda }; 4792981d9b0SVijendar Mukunda 4802981d9b0SVijendar Mukunda module_platform_driver(soc_sdw_driver); 4812981d9b0SVijendar Mukunda 4822981d9b0SVijendar Mukunda MODULE_DESCRIPTION("ASoC AMD SoundWire Legacy Generic Machine driver"); 4832981d9b0SVijendar Mukunda MODULE_AUTHOR("Vijendar Mukunda <Vijendar.Mukunda@amd.com>"); 4842981d9b0SVijendar Mukunda MODULE_LICENSE("GPL"); 485*cdd30ebbSPeter Zijlstra MODULE_IMPORT_NS("SND_SOC_SDW_UTILS"); 486*cdd30ebbSPeter Zijlstra MODULE_IMPORT_NS("SND_SOC_AMD_SDW_MACH"); 487