| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
// |
| 3 |
// Copyright(c) 2021-2022 Intel Corporation |
| 4 |
// |
| 5 |
// Authors: Cezary Rojewski <[email protected]> |
| 6 |
// Amadeusz Slawinski <[email protected]> |
| 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, int ssp_port, int tdm_slot, |
| 18 |
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 |
dl->name = devm_kasprintf(dev, GFP_KERNEL, |
| 29 |
AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); |
| 30 |
dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); |
| 31 |
if (!dl->name || !dl->cpus) |
| 32 |
return -ENOMEM; |
| 33 |
|
| 34 |
dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, |
| 35 |
AVS_STRING_FMT("SSP", " Pin", ssp_port, tdm_slot)); |
| 36 |
dl->codecs = &snd_soc_dummy_dlc; |
| 37 |
if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name) |
| 38 |
return -ENOMEM; |
| 39 |
|
| 40 |
platform->name = dev_name(dev); |
| 41 |
dl->num_cpus = 1; |
| 42 |
dl->num_codecs = 1; |
| 43 |
dl->platforms = platform; |
| 44 |
dl->num_platforms = 1; |
| 45 |
dl->id = 0; |
| 46 |
dl->nonatomic = 1; |
| 47 |
dl->no_pcm = 1; |
| 48 |
|
| 49 |
*dai_link = dl; |
| 50 |
|
| 51 |
return 0; |
| 52 |
} |
| 53 |
|
| 54 |
static int avs_i2s_test_probe(struct platform_device *pdev) |
| 55 |
{ |
| 56 |
struct snd_soc_dai_link *dai_link; |
| 57 |
struct snd_soc_acpi_mach *mach; |
| 58 |
struct avs_mach_pdata *pdata; |
| 59 |
struct snd_soc_card *card; |
| 60 |
struct device *dev = &pdev->dev; |
| 61 |
int ssp_port, tdm_slot, ret; |
| 62 |
|
| 63 |
mach = dev_get_platdata(dev); |
| 64 |
pdata = mach->pdata; |
| 65 |
|
| 66 |
if (!avs_mach_singular_ssp(mach)) { |
| 67 |
dev_err(dev, "Invalid SSP configuration\n"); |
| 68 |
return -EINVAL; |
| 69 |
} |
| 70 |
ssp_port = avs_mach_ssp_port(mach); |
| 71 |
|
| 72 |
if (!avs_mach_singular_tdm(mach, ssp_port)) { |
| 73 |
dev_err(dev, "Invalid TDM configuration\n"); |
| 74 |
return -EINVAL; |
| 75 |
} |
| 76 |
tdm_slot = avs_mach_ssp_tdm(mach, ssp_port); |
| 77 |
|
| 78 |
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); |
| 79 |
if (!card) |
| 80 |
return -ENOMEM; |
| 81 |
|
| 82 |
if (pdata->obsolete_card_names) { |
| 83 |
card->name = devm_kasprintf(dev, GFP_KERNEL, |
| 84 |
AVS_STRING_FMT("ssp", "-loopback", ssp_port, tdm_slot)); |
| 85 |
} else { |
| 86 |
card->driver_name = "avs_i2s_test"; |
| 87 |
card->long_name = card->name = devm_kasprintf(dev, GFP_KERNEL, |
| 88 |
AVS_STRING_FMT("AVS I2S TEST-", "", |
| 89 |
ssp_port, tdm_slot)); |
| 90 |
} |
| 91 |
if (!card->name) |
| 92 |
return -ENOMEM; |
| 93 |
|
| 94 |
ret = avs_create_dai_link(dev, ssp_port, tdm_slot, &dai_link); |
| 95 |
if (ret) { |
| 96 |
dev_err(dev, "Failed to create dai link: %d\n", ret); |
| 97 |
return ret; |
| 98 |
} |
| 99 |
|
| 100 |
card->dev = dev; |
| 101 |
card->owner = THIS_MODULE; |
| 102 |
card->dai_link = dai_link; |
| 103 |
card->num_links = 1; |
| 104 |
card->fully_routed = true; |
| 105 |
|
| 106 |
return devm_snd_soc_register_deferrable_card(dev, card); |
| 107 |
} |
| 108 |
|
| 109 |
static const struct platform_device_id avs_i2s_test_driver_ids[] = { |
| 110 |
{ |
| 111 |
.name = "avs_i2s_test", |
| 112 |
}, |
| 113 |
{}, |
| 114 |
}; |
| 115 |
MODULE_DEVICE_TABLE(platform, avs_i2s_test_driver_ids); |
| 116 |
|
| 117 |
static struct platform_driver avs_i2s_test_driver = { |
| 118 |
.probe = avs_i2s_test_probe, |
| 119 |
.driver = { |
| 120 |
.name = "avs_i2s_test", |
| 121 |
.pm = &snd_soc_pm_ops, |
| 122 |
}, |
| 123 |
.id_table = avs_i2s_test_driver_ids, |
| 124 |
}; |
| 125 |
|
| 126 |
module_platform_driver(avs_i2s_test_driver); |
| 127 |
|
| 128 |
MODULE_DESCRIPTION("Intel i2s test machine driver"); |
| 129 |
MODULE_LICENSE("GPL"); |