FILE
rt5514.c
File preview with syntax highlighting.
linux-6.19.14/sound/soc/intel/avs/boards/rt5514.c
1// SPDX-License-Identifier: GPL-2.0-only 2// 3// Copyright(c) 2021-2023 Intel Corporation 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 22static const struct snd_soc_dapm_widget card_widgets[] = { 23 SND_SOC_DAPM_MIC("DMIC", NULL), 24}; 25 26static 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 34static int avs_rt5514_codec_init(struct snd_soc_pcm_runtime *runtime) 35{ 36 struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(runtime->card); 37 int ret = snd_soc_dapm_ignore_suspend(dapm, "DMIC"); 38 39 if (ret) 40 dev_err(runtime->dev, "DMIC - Ignore suspend failed = %d\n", ret); 41 42 return ret; 43} 44 45static int avs_rt5514_be_fixup(struct snd_soc_pcm_runtime *runtime, 46 struct snd_pcm_hw_params *params) 47{ 48 struct snd_interval *rate, *channels; 49 struct snd_mask *fmt; 50 51 rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 52 channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 53 fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 54 55 rate->min = rate->max = 48000; 56 channels->min = channels->max = 4; 57 58 snd_mask_none(fmt); 59 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE); 60 61 return 0; 62} 63 64static int avs_rt5514_hw_params(struct snd_pcm_substream *substream, 65 struct snd_pcm_hw_params *params) 66{ 67 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 68 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); 69 int ret; 70 71 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16); 72 if (ret < 0) { 73 dev_err(rtd->dev, "set TDM slot err:%d\n", ret); 74 return ret; 75 } 76 77 ret = snd_soc_dai_set_sysclk(codec_dai, RT5514_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN); 78 if (ret < 0) 79 dev_err(rtd->dev, "set sysclk err: %d\n", ret); 80 81 return ret; 82} 83 84static const struct snd_soc_ops avs_rt5514_ops = { 85 .hw_params = avs_rt5514_hw_params, 86}; 87 88static int avs_create_dai_link(struct device *dev, int ssp_port, int tdm_slot, 89 struct snd_soc_dai_link **dai_link) 90{ 91 struct snd_soc_dai_link_component *platform; 92 struct snd_soc_dai_link *dl; 93 94 dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL); 95 platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); 96 if (!dl || !platform) 97 return -ENOMEM; 98 99 dl->name = devm_kasprintf(dev, GFP_KERNEL, 100 AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot)); 101 dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL); 102 dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL); 103 if (!dl->name || !dl->cpus || !dl->codecs) 104 return -ENOMEM; 105 106 dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, 107 AVS_STRING_FMT("SSP", " Pin", ssp_port, tdm_slot)); 108 dl->codecs->name = devm_kasprintf(dev, GFP_KERNEL, "i2c-10EC5514:00"); 109 dl->codecs->dai_name = devm_kasprintf(dev, GFP_KERNEL, RT5514_CODEC_DAI); 110 if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name) 111 return -ENOMEM; 112 113 platform->name = dev_name(dev); 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_CBC_CFC; 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->capture_only = 1; 125 dl->ops = &avs_rt5514_ops; 126 127 *dai_link = dl; 128 129 return 0; 130} 131 132static 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 avs_mach_pdata *pdata; 137 struct snd_soc_card *card; 138 struct device *dev = &pdev->dev; 139 int ssp_port, tdm_slot, ret; 140 141 mach = dev_get_platdata(dev); 142 pdata = mach->pdata; 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, 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 if (pdata->obsolete_card_names) { 159 card->name = "avs_rt5514"; 160 } else { 161 card->driver_name = "avs_rt5514"; 162 card->long_name = card->name = "AVS I2S ALC5514"; 163 } 164 card->dev = dev; 165 card->owner = THIS_MODULE; 166 card->dai_link = dai_link; 167 card->num_links = 1; 168 card->dapm_widgets = card_widgets; 169 card->num_dapm_widgets = ARRAY_SIZE(card_widgets); 170 card->dapm_routes = card_base_routes; 171 card->num_dapm_routes = ARRAY_SIZE(card_base_routes); 172 card->fully_routed = true; 173 174 return devm_snd_soc_register_deferrable_card(dev, card); 175} 176 177static const struct platform_device_id avs_rt5514_driver_ids[] = { 178 { 179 .name = "avs_rt5514", 180 }, 181 {}, 182}; 183MODULE_DEVICE_TABLE(platform, avs_rt5514_driver_ids); 184 185static struct platform_driver avs_rt5514_driver = { 186 .probe = avs_rt5514_probe, 187 .driver = { 188 .name = "avs_rt5514", 189 .pm = &snd_soc_pm_ops, 190 }, 191 .id_table = avs_rt5514_driver_ids, 192}; 193 194module_platform_driver(avs_rt5514_driver); 195 196MODULE_DESCRIPTION("Intel rt5514 machine driver"); 197MODULE_LICENSE("GPL");
~/
Read-only file preview.