Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: Intel: avs: Add support for rt5514 codec

Merge series from Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>:

There are machines which use codec rt5514 as DMIC, add support for them.

+208
+9
sound/soc/intel/avs/board_selection.c
··· 136 136 .tplg_filename = "max98927-tplg.bin", 137 137 }, 138 138 { 139 + .id = "10EC5514", 140 + .drv_name = "avs_rt5514", 141 + .mach_params = { 142 + .i2s_link_mask = AVS_SSP(0), 143 + }, 144 + .pdata = (unsigned long[]){ 0x2, 0, 0, 0, 0, 0 }, /* SSP0 TDMs */ 145 + .tplg_filename = "rt5514-tplg.bin", 146 + }, 147 + { 139 148 .id = "10EC5663", 140 149 .drv_name = "avs_rt5663", 141 150 .mach_params = {
+10
sound/soc/intel/avs/boards/Kconfig
··· 125 125 Say Y or m if you have such a device. This is a recommended option. 126 126 If unsure select "N". 127 127 128 + config SND_SOC_INTEL_AVS_MACH_RT5514 129 + tristate "rt5514 in I2S mode" 130 + depends on I2C 131 + depends on MFD_INTEL_LPSS || COMPILE_TEST 132 + select SND_SOC_RT5514 133 + help 134 + This adds support for ASoC machine driver with RT5514 I2S audio codec. 135 + Say Y or m if you have such a device. This is a recommended option. 136 + If unsure select "N". 137 + 128 138 config SND_SOC_INTEL_AVS_MACH_RT5663 129 139 tristate "rt5663 in I2S mode" 130 140 depends on I2C
+2
sound/soc/intel/avs/boards/Makefile
··· 13 13 snd-soc-avs-rt274-objs := rt274.o 14 14 snd-soc-avs-rt286-objs := rt286.o 15 15 snd-soc-avs-rt298-objs := rt298.o 16 + snd-soc-avs-rt5514-objs := rt5514.o 16 17 snd-soc-avs-rt5663-objs := rt5663.o 17 18 snd-soc-avs-rt5682-objs := rt5682.o 18 19 snd-soc-avs-ssm4567-objs := ssm4567.o ··· 31 30 obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_RT274) += snd-soc-avs-rt274.o 32 31 obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_RT286) += snd-soc-avs-rt286.o 33 32 obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_RT298) += snd-soc-avs-rt298.o 33 + obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_RT5514) += snd-soc-avs-rt5514.o 34 34 obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_RT5663) += snd-soc-avs-rt5663.o 35 35 obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_RT5682) += snd-soc-avs-rt5682.o 36 36 obj-$(CONFIG_SND_SOC_INTEL_AVS_MACH_SSM4567) += snd-soc-avs-ssm4567.o
+187
sound/soc/intel/avs/boards/rt5514.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + // 3 + // Copyright(c) 2021-2023 Intel Corporation. All rights reserved. 4 + // 5 + // Authors: Cezary Rojewski <cezary.rojewski@intel.com> 6 + // Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com> 7 + // 8 + 9 + #include <linux/clk.h> 10 + #include <linux/input.h> 11 + #include <linux/module.h> 12 + #include <sound/jack.h> 13 + #include <sound/pcm.h> 14 + #include <sound/pcm_params.h> 15 + #include <sound/soc.h> 16 + #include <sound/soc-acpi.h> 17 + #include "../../../codecs/rt5514.h" 18 + #include "../utils.h" 19 + 20 + #define RT5514_CODEC_DAI "rt5514-aif1" 21 + 22 + static const struct snd_soc_dapm_widget card_widgets[] = { 23 + SND_SOC_DAPM_MIC("DMIC", NULL), 24 + }; 25 + 26 + static const struct snd_soc_dapm_route card_base_routes[] = { 27 + /* DMIC */ 28 + { "DMIC1L", NULL, "DMIC" }, 29 + { "DMIC1R", NULL, "DMIC" }, 30 + { "DMIC2L", NULL, "DMIC" }, 31 + { "DMIC2R", NULL, "DMIC" }, 32 + }; 33 + 34 + static int avs_rt5514_codec_init(struct snd_soc_pcm_runtime *runtime) 35 + { 36 + int ret = snd_soc_dapm_ignore_suspend(&runtime->card->dapm, "DMIC"); 37 + 38 + if (ret) 39 + dev_err(runtime->dev, "DMIC - Ignore suspend failed = %d\n", ret); 40 + 41 + return ret; 42 + } 43 + 44 + static int avs_rt5514_be_fixup(struct snd_soc_pcm_runtime *runtime, 45 + struct snd_pcm_hw_params *params) 46 + { 47 + struct snd_interval *rate, *channels; 48 + struct snd_mask *fmt; 49 + 50 + rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 51 + channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 52 + fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 53 + 54 + rate->min = rate->max = 48000; 55 + channels->min = channels->max = 4; 56 + 57 + snd_mask_none(fmt); 58 + snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE); 59 + 60 + return 0; 61 + } 62 + 63 + static int avs_rt5514_hw_params(struct snd_pcm_substream *substream, 64 + struct snd_pcm_hw_params *params) 65 + { 66 + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 67 + struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); 68 + int ret; 69 + 70 + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16); 71 + if (ret < 0) { 72 + dev_err(rtd->dev, "set TDM slot err:%d\n", ret); 73 + return ret; 74 + } 75 + 76 + ret = snd_soc_dai_set_sysclk(codec_dai, RT5514_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN); 77 + if (ret < 0) 78 + dev_err(rtd->dev, "set sysclk err: %d\n", ret); 79 + 80 + return ret; 81 + } 82 + 83 + static const struct snd_soc_ops avs_rt5514_ops = { 84 + .hw_params = avs_rt5514_hw_params, 85 + }; 86 + 87 + static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port, 88 + int tdm_slot, struct snd_soc_dai_link **dai_link) 89 + { 90 + struct snd_soc_dai_link_component *platform; 91 + struct snd_soc_dai_link *dl; 92 + 93 + dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); 94 + platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); 95 + if (!dl || !platform) 96 + return -ENOMEM; 97 + 98 + platform->name = platform_name; 99 + 100 + dl->name = devm_kasprintf(dev, GFP_KERNEL, 101 + AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); 102 + dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); 103 + dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); 104 + if (!dl->name || !dl->cpus || !dl->codecs) 105 + return -ENOMEM; 106 + 107 + dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, 108 + AVS_STRING_FMT("SSP", " Pin", ssp_port, tdm_slot)); 109 + dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "i2c-10EC5514:00"); 110 + dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, RT5514_CODEC_DAI); 111 + if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name) 112 + return -ENOMEM; 113 + 114 + dl->num_cpus = 1; 115 + dl->num_codecs = 1; 116 + dl->platforms = platform; 117 + dl->num_platforms = 1; 118 + dl->id = 0; 119 + dl->dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS; 120 + dl->init = avs_rt5514_codec_init; 121 + dl->be_hw_params_fixup = avs_rt5514_be_fixup; 122 + dl->nonatomic = 1; 123 + dl->no_pcm = 1; 124 + dl->dpcm_capture = 1; 125 + dl->ops = &avs_rt5514_ops; 126 + 127 + *dai_link = dl; 128 + 129 + return 0; 130 + } 131 + 132 + static int avs_rt5514_probe(struct platform_device *pdev) 133 + { 134 + struct snd_soc_dai_link *dai_link; 135 + struct snd_soc_acpi_mach *mach; 136 + struct snd_soc_card *card; 137 + struct device *dev = &pdev->dev; 138 + const char *pname; 139 + int ssp_port, tdm_slot, ret; 140 + 141 + mach = dev_get_platdata(dev); 142 + pname = mach->mach_params.platform; 143 + 144 + ret = avs_mach_get_ssp_tdm(dev, mach, &ssp_port, &tdm_slot); 145 + if (ret) 146 + return ret; 147 + 148 + ret = avs_create_dai_link(dev, pname, ssp_port, tdm_slot, &dai_link); 149 + if (ret) { 150 + dev_err(dev, "Failed to create dai link: %d", ret); 151 + return ret; 152 + } 153 + 154 + card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); 155 + if (!card) 156 + return -ENOMEM; 157 + 158 + card->name = "avs_rt5514"; 159 + card->dev = dev; 160 + card->owner = THIS_MODULE; 161 + card->dai_link = dai_link; 162 + card->num_links = 1; 163 + card->dapm_widgets = card_widgets; 164 + card->num_dapm_widgets = ARRAY_SIZE(card_widgets); 165 + card->dapm_routes = card_base_routes; 166 + card->num_dapm_routes = ARRAY_SIZE(card_base_routes); 167 + card->fully_routed = true; 168 + 169 + ret = snd_soc_fixup_dai_links_platform_name(card, pname); 170 + if (ret) 171 + return ret; 172 + 173 + return devm_snd_soc_register_card(dev, card); 174 + } 175 + 176 + static struct platform_driver avs_rt5514_driver = { 177 + .probe = avs_rt5514_probe, 178 + .driver = { 179 + .name = "avs_rt5514", 180 + .pm = &snd_soc_pm_ops, 181 + }, 182 + }; 183 + 184 + module_platform_driver(avs_rt5514_driver); 185 + 186 + MODULE_LICENSE("GPL"); 187 + MODULE_ALIAS("platform:avs_rt5514");