1 // SPDX-License-Identifier: GPL-2.0-only 2 // 3 // Copyright(c) 2021-2022 Intel Corporation 4 // 5 // Authors: Cezary Rojewski <cezary.rojewski@intel.com> 6 // Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com> 7 // 8 9 #include <linux/module.h> 10 #include <sound/pcm.h> 11 #include <sound/pcm_params.h> 12 #include <sound/soc.h> 13 #include <sound/soc-acpi.h> 14 #include <sound/soc-dapm.h> 15 #include "../utils.h" 16 17 static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port, 18 int tdm_slot, struct snd_soc_dai_link **dai_link) 19 { 20 struct snd_soc_dai_link_component *platform; 21 struct snd_soc_dai_link *dl; 22 23 dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); 24 platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); 25 if (!dl || !platform) 26 return -ENOMEM; 27 28 platform->name = platform_name; 29 30 dl->name = devm_kasprintf(dev, GFP_KERNEL, 31 AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); 32 dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); 33 if (!dl->name || !dl->cpus) 34 return -ENOMEM; 35 36 dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, 37 AVS_STRING_FMT("SSP", " Pin", ssp_port, tdm_slot)); 38 dl->codecs = &snd_soc_dummy_dlc; 39 if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name) 40 return -ENOMEM; 41 42 dl->num_cpus = 1; 43 dl->num_codecs = 1; 44 dl->platforms = platform; 45 dl->num_platforms = 1; 46 dl->id = 0; 47 dl->nonatomic = 1; 48 dl->no_pcm = 1; 49 50 *dai_link = dl; 51 52 return 0; 53 } 54 55 static int avs_i2s_test_probe(struct platform_device *pdev) 56 { 57 struct snd_soc_dai_link *dai_link; 58 struct snd_soc_acpi_mach *mach; 59 struct snd_soc_card *card; 60 struct device *dev = &pdev->dev; 61 const char *pname; 62 int ssp_port, tdm_slot, ret; 63 64 mach = dev_get_platdata(dev); 65 pname = mach->mach_params.platform; 66 67 if (!avs_mach_singular_ssp(mach)) { 68 dev_err(dev, "Invalid SSP configuration\n"); 69 return -EINVAL; 70 } 71 ssp_port = avs_mach_ssp_port(mach); 72 73 if (!avs_mach_singular_tdm(mach, ssp_port)) { 74 dev_err(dev, "Invalid TDM configuration\n"); 75 return -EINVAL; 76 } 77 tdm_slot = avs_mach_ssp_tdm(mach, ssp_port); 78 79 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); 80 if (!card) 81 return -ENOMEM; 82 83 card->name = devm_kasprintf(dev, GFP_KERNEL, 84 AVS_STRING_FMT("ssp", "-loopback", ssp_port, tdm_slot)); 85 if (!card->name) 86 return -ENOMEM; 87 88 ret = avs_create_dai_link(dev, pname, ssp_port, tdm_slot, &dai_link); 89 if (ret) { 90 dev_err(dev, "Failed to create dai link: %d\n", ret); 91 return ret; 92 } 93 94 card->dev = dev; 95 card->owner = THIS_MODULE; 96 card->dai_link = dai_link; 97 card->num_links = 1; 98 card->fully_routed = true; 99 100 ret = snd_soc_fixup_dai_links_platform_name(card, pname); 101 if (ret) 102 return ret; 103 104 return devm_snd_soc_register_card(dev, card); 105 } 106 107 static const struct platform_device_id avs_i2s_test_driver_ids[] = { 108 { 109 .name = "avs_i2s_test", 110 }, 111 {}, 112 }; 113 MODULE_DEVICE_TABLE(platform, avs_i2s_test_driver_ids); 114 115 static struct platform_driver avs_i2s_test_driver = { 116 .probe = avs_i2s_test_probe, 117 .driver = { 118 .name = "avs_i2s_test", 119 .pm = &snd_soc_pm_ops, 120 }, 121 .id_table = avs_i2s_test_driver_ids, 122 }; 123 124 module_platform_driver(avs_i2s_test_driver); 125 126 MODULE_DESCRIPTION("Intel i2s test machine driver"); 127 MODULE_LICENSE("GPL"); 128