1d4c750f2SAjit Kumar Pandey // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2d4c750f2SAjit Kumar Pandey //
3d4c750f2SAjit Kumar Pandey // This file is provided under a dual BSD/GPLv2 license. When using or
4d4c750f2SAjit Kumar Pandey // redistributing this file, you may do so under either license.
5d4c750f2SAjit Kumar Pandey //
6671dd2ffSVenkata Prasad Potturu // Copyright(c) 2021, 2023 Advanced Micro Devices, Inc.
7d4c750f2SAjit Kumar Pandey //
8d4c750f2SAjit Kumar Pandey // Authors: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
9d4c750f2SAjit Kumar Pandey // Vijendar Mukunda <Vijendar.Mukunda@amd.com>
10d4c750f2SAjit Kumar Pandey //
11d4c750f2SAjit Kumar Pandey
12d4c750f2SAjit Kumar Pandey /*
13d4c750f2SAjit Kumar Pandey * Machine Driver Interface for ACP HW block
14d4c750f2SAjit Kumar Pandey */
15d4c750f2SAjit Kumar Pandey
16d4c750f2SAjit Kumar Pandey #include <sound/core.h>
17d4c750f2SAjit Kumar Pandey #include <sound/jack.h>
18d4c750f2SAjit Kumar Pandey #include <sound/pcm_params.h>
19d4c750f2SAjit Kumar Pandey #include <sound/soc-dapm.h>
20d4c750f2SAjit Kumar Pandey #include <sound/soc.h>
21d4c750f2SAjit Kumar Pandey #include <linux/input.h>
22d4c750f2SAjit Kumar Pandey #include <linux/module.h>
23d4c750f2SAjit Kumar Pandey
24d4c750f2SAjit Kumar Pandey #include "../../codecs/rt5682.h"
25d4c750f2SAjit Kumar Pandey #include "../../codecs/rt1019.h"
268b725626SAjit Kumar Pandey #include "../../codecs/rt5682s.h"
270439eb4dSV sujith kumar Reddy #include "../../codecs/nau8825.h"
284b526b32SVenkata Prasad Potturu #include "../../codecs/nau8821.h"
29d4c750f2SAjit Kumar Pandey #include "acp-mach.h"
30d4c750f2SAjit Kumar Pandey
31d4c750f2SAjit Kumar Pandey #define PCO_PLAT_CLK 48000000
32d4c750f2SAjit Kumar Pandey #define RT5682_PLL_FREQ (48000 * 512)
33d4c750f2SAjit Kumar Pandey #define DUAL_CHANNEL 2
34d4c750f2SAjit Kumar Pandey #define FOUR_CHANNEL 4
354b526b32SVenkata Prasad Potturu #define NAU8821_CODEC_DAI "nau8821-hifi"
364b526b32SVenkata Prasad Potturu #define NAU8821_BCLK 1536000
374b526b32SVenkata Prasad Potturu #define NAU8821_FREQ_OUT 12288000
38ac91c8c8SVenkata Prasad Potturu #define MAX98388_CODEC_DAI "max98388-aif1"
39d4c750f2SAjit Kumar Pandey
40d386a10cSVenkata Prasad Potturu #define TDM_MODE_ENABLE 1
41d386a10cSVenkata Prasad Potturu
42d386a10cSVenkata Prasad Potturu const struct dmi_system_id acp_quirk_table[] = {
43d386a10cSVenkata Prasad Potturu {
44d386a10cSVenkata Prasad Potturu /* Google skyrim proto-0 */
45d386a10cSVenkata Prasad Potturu .matches = {
46d386a10cSVenkata Prasad Potturu DMI_EXACT_MATCH(DMI_PRODUCT_FAMILY, "Google_Skyrim"),
47d386a10cSVenkata Prasad Potturu },
48d386a10cSVenkata Prasad Potturu .driver_data = (void *)TDM_MODE_ENABLE,
49d386a10cSVenkata Prasad Potturu },
50d386a10cSVenkata Prasad Potturu {}
51d386a10cSVenkata Prasad Potturu };
52d386a10cSVenkata Prasad Potturu EXPORT_SYMBOL_GPL(acp_quirk_table);
53d386a10cSVenkata Prasad Potturu
54d4c750f2SAjit Kumar Pandey static const unsigned int channels[] = {
55d4c750f2SAjit Kumar Pandey DUAL_CHANNEL,
56d4c750f2SAjit Kumar Pandey };
57d4c750f2SAjit Kumar Pandey
58d4c750f2SAjit Kumar Pandey static const unsigned int rates[] = {
59d4c750f2SAjit Kumar Pandey 48000,
60d4c750f2SAjit Kumar Pandey };
61d4c750f2SAjit Kumar Pandey
62d4c750f2SAjit Kumar Pandey static const struct snd_pcm_hw_constraint_list constraints_rates = {
63d4c750f2SAjit Kumar Pandey .count = ARRAY_SIZE(rates),
64d4c750f2SAjit Kumar Pandey .list = rates,
65d4c750f2SAjit Kumar Pandey .mask = 0,
66d4c750f2SAjit Kumar Pandey };
67d4c750f2SAjit Kumar Pandey
68d4c750f2SAjit Kumar Pandey static const struct snd_pcm_hw_constraint_list constraints_channels = {
69d4c750f2SAjit Kumar Pandey .count = ARRAY_SIZE(channels),
70d4c750f2SAjit Kumar Pandey .list = channels,
71d4c750f2SAjit Kumar Pandey .mask = 0,
72d4c750f2SAjit Kumar Pandey };
73d4c750f2SAjit Kumar Pandey
acp_clk_enable(struct acp_card_drvdata * drvdata,unsigned int srate,unsigned int bclk_ratio)74ca9d2379SVenkata Prasad Potturu static int acp_clk_enable(struct acp_card_drvdata *drvdata,
75ca9d2379SVenkata Prasad Potturu unsigned int srate, unsigned int bclk_ratio)
76d4c750f2SAjit Kumar Pandey {
77ca9d2379SVenkata Prasad Potturu clk_set_rate(drvdata->wclk, srate);
78ca9d2379SVenkata Prasad Potturu clk_set_rate(drvdata->bclk, srate * bclk_ratio);
79d4c750f2SAjit Kumar Pandey
80d4c750f2SAjit Kumar Pandey return clk_prepare_enable(drvdata->wclk);
81d4c750f2SAjit Kumar Pandey }
82d4c750f2SAjit Kumar Pandey
83d4c750f2SAjit Kumar Pandey /* Declare RT5682 codec components */
84d4c750f2SAjit Kumar Pandey SND_SOC_DAILINK_DEF(rt5682,
85d4c750f2SAjit Kumar Pandey DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1")));
86d4c750f2SAjit Kumar Pandey
877ac3404cSAlper Nebi Yasak static struct snd_soc_jack rt5682_jack;
887ac3404cSAlper Nebi Yasak static struct snd_soc_jack_pin rt5682_jack_pins[] = {
897ac3404cSAlper Nebi Yasak {
907ac3404cSAlper Nebi Yasak .pin = "Headphone Jack",
917ac3404cSAlper Nebi Yasak .mask = SND_JACK_HEADPHONE,
927ac3404cSAlper Nebi Yasak },
937ac3404cSAlper Nebi Yasak {
947ac3404cSAlper Nebi Yasak .pin = "Headset Mic",
957ac3404cSAlper Nebi Yasak .mask = SND_JACK_MICROPHONE,
967ac3404cSAlper Nebi Yasak },
977ac3404cSAlper Nebi Yasak };
987ac3404cSAlper Nebi Yasak
997ac3404cSAlper Nebi Yasak static const struct snd_kcontrol_new rt5682_controls[] = {
1007ac3404cSAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Headphone Jack"),
1017ac3404cSAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Headset Mic"),
1027ac3404cSAlper Nebi Yasak };
1037ac3404cSAlper Nebi Yasak
1047ac3404cSAlper Nebi Yasak static const struct snd_soc_dapm_widget rt5682_widgets[] = {
1057ac3404cSAlper Nebi Yasak SND_SOC_DAPM_HP("Headphone Jack", NULL),
1067ac3404cSAlper Nebi Yasak SND_SOC_DAPM_MIC("Headset Mic", NULL),
1077ac3404cSAlper Nebi Yasak };
1087ac3404cSAlper Nebi Yasak
109d4c750f2SAjit Kumar Pandey static const struct snd_soc_dapm_route rt5682_map[] = {
110d4c750f2SAjit Kumar Pandey { "Headphone Jack", NULL, "HPOL" },
111d4c750f2SAjit Kumar Pandey { "Headphone Jack", NULL, "HPOR" },
112d4c750f2SAjit Kumar Pandey { "IN1P", NULL, "Headset Mic" },
113d4c750f2SAjit Kumar Pandey };
114d4c750f2SAjit Kumar Pandey
115d4c750f2SAjit Kumar Pandey /* Define card ops for RT5682 CODEC */
acp_card_rt5682_init(struct snd_soc_pcm_runtime * rtd)116d4c750f2SAjit Kumar Pandey static int acp_card_rt5682_init(struct snd_soc_pcm_runtime *rtd)
117d4c750f2SAjit Kumar Pandey {
118d4c750f2SAjit Kumar Pandey struct snd_soc_card *card = rtd->card;
119d4c750f2SAjit Kumar Pandey struct acp_card_drvdata *drvdata = card->drvdata;
120d4f23dcdSKuninori Morimoto struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
121d4c750f2SAjit Kumar Pandey struct snd_soc_component *component = codec_dai->component;
122d4c750f2SAjit Kumar Pandey int ret;
123d4c750f2SAjit Kumar Pandey
124d4c750f2SAjit Kumar Pandey dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
125d4c750f2SAjit Kumar Pandey
126d4c750f2SAjit Kumar Pandey if (drvdata->hs_codec_id != RT5682)
127d4c750f2SAjit Kumar Pandey return -EINVAL;
128d4c750f2SAjit Kumar Pandey
129d4c750f2SAjit Kumar Pandey drvdata->wclk = clk_get(component->dev, "rt5682-dai-wclk");
130d4c750f2SAjit Kumar Pandey drvdata->bclk = clk_get(component->dev, "rt5682-dai-bclk");
131d4c750f2SAjit Kumar Pandey
1327ac3404cSAlper Nebi Yasak ret = snd_soc_dapm_new_controls(&card->dapm, rt5682_widgets,
1337ac3404cSAlper Nebi Yasak ARRAY_SIZE(rt5682_widgets));
1347ac3404cSAlper Nebi Yasak if (ret) {
1357ac3404cSAlper Nebi Yasak dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
1367ac3404cSAlper Nebi Yasak return ret;
1377ac3404cSAlper Nebi Yasak }
1387ac3404cSAlper Nebi Yasak
1397ac3404cSAlper Nebi Yasak ret = snd_soc_add_card_controls(card, rt5682_controls,
1407ac3404cSAlper Nebi Yasak ARRAY_SIZE(rt5682_controls));
1417ac3404cSAlper Nebi Yasak if (ret) {
1427ac3404cSAlper Nebi Yasak dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
1437ac3404cSAlper Nebi Yasak return ret;
1447ac3404cSAlper Nebi Yasak }
1457ac3404cSAlper Nebi Yasak
1467ac3404cSAlper Nebi Yasak ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
147d4c750f2SAjit Kumar Pandey SND_JACK_HEADSET | SND_JACK_LINEOUT |
148d4c750f2SAjit Kumar Pandey SND_JACK_BTN_0 | SND_JACK_BTN_1 |
149d4c750f2SAjit Kumar Pandey SND_JACK_BTN_2 | SND_JACK_BTN_3,
1507ac3404cSAlper Nebi Yasak &rt5682_jack,
1517ac3404cSAlper Nebi Yasak rt5682_jack_pins,
1527ac3404cSAlper Nebi Yasak ARRAY_SIZE(rt5682_jack_pins));
153d4c750f2SAjit Kumar Pandey if (ret) {
154d4c750f2SAjit Kumar Pandey dev_err(card->dev, "HP jack creation failed %d\n", ret);
155d4c750f2SAjit Kumar Pandey return ret;
156d4c750f2SAjit Kumar Pandey }
157d4c750f2SAjit Kumar Pandey
1587ac3404cSAlper Nebi Yasak snd_jack_set_key(rt5682_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
1597ac3404cSAlper Nebi Yasak snd_jack_set_key(rt5682_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
1607ac3404cSAlper Nebi Yasak snd_jack_set_key(rt5682_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
1617ac3404cSAlper Nebi Yasak snd_jack_set_key(rt5682_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
162d4c750f2SAjit Kumar Pandey
1637ac3404cSAlper Nebi Yasak ret = snd_soc_component_set_jack(component, &rt5682_jack, NULL);
164d4c750f2SAjit Kumar Pandey if (ret) {
165d4c750f2SAjit Kumar Pandey dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
166d4c750f2SAjit Kumar Pandey return ret;
167d4c750f2SAjit Kumar Pandey }
168d4c750f2SAjit Kumar Pandey
169d4c750f2SAjit Kumar Pandey return snd_soc_dapm_add_routes(&rtd->card->dapm, rt5682_map, ARRAY_SIZE(rt5682_map));
170d4c750f2SAjit Kumar Pandey }
171d4c750f2SAjit Kumar Pandey
acp_card_hs_startup(struct snd_pcm_substream * substream)172d4c750f2SAjit Kumar Pandey static int acp_card_hs_startup(struct snd_pcm_substream *substream)
173d4c750f2SAjit Kumar Pandey {
174d4c750f2SAjit Kumar Pandey struct snd_pcm_runtime *runtime = substream->runtime;
175d4f23dcdSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
176d4c750f2SAjit Kumar Pandey struct snd_soc_card *card = rtd->card;
177d4c750f2SAjit Kumar Pandey struct acp_card_drvdata *drvdata = card->drvdata;
178d4f23dcdSKuninori Morimoto struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
179d4c750f2SAjit Kumar Pandey int ret;
1804dc6737cSV sujith kumar Reddy unsigned int fmt;
181d4c750f2SAjit Kumar Pandey
18220055300SVenkata Prasad Potturu if (drvdata->tdm_mode)
18320055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_DSP_A;
1844dc6737cSV sujith kumar Reddy else
18520055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_I2S;
18620055300SVenkata Prasad Potturu
18720055300SVenkata Prasad Potturu if (drvdata->soc_mclk)
18820055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
18920055300SVenkata Prasad Potturu else
19020055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
1914dc6737cSV sujith kumar Reddy
1924dc6737cSV sujith kumar Reddy ret = snd_soc_dai_set_fmt(codec_dai, fmt);
193d4c750f2SAjit Kumar Pandey if (ret < 0) {
194d4c750f2SAjit Kumar Pandey dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
195d4c750f2SAjit Kumar Pandey return ret;
196d4c750f2SAjit Kumar Pandey }
197d4c750f2SAjit Kumar Pandey
198d4c750f2SAjit Kumar Pandey runtime->hw.channels_max = DUAL_CHANNEL;
199d4c750f2SAjit Kumar Pandey snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
200d4c750f2SAjit Kumar Pandey &constraints_channels);
201d4c750f2SAjit Kumar Pandey snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
202d4c750f2SAjit Kumar Pandey &constraints_rates);
2039e693e81SVenkata Prasad Potturu
204d4c750f2SAjit Kumar Pandey return ret;
205d4c750f2SAjit Kumar Pandey }
206d4c750f2SAjit Kumar Pandey
acp_card_shutdown(struct snd_pcm_substream * substream)207d4c750f2SAjit Kumar Pandey static void acp_card_shutdown(struct snd_pcm_substream *substream)
208d4c750f2SAjit Kumar Pandey {
209d4f23dcdSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
210d4c750f2SAjit Kumar Pandey struct snd_soc_card *card = rtd->card;
211d4c750f2SAjit Kumar Pandey struct acp_card_drvdata *drvdata = card->drvdata;
212d4c750f2SAjit Kumar Pandey
2130439eb4dSV sujith kumar Reddy if (!drvdata->soc_mclk)
214d4c750f2SAjit Kumar Pandey clk_disable_unprepare(drvdata->wclk);
215d4c750f2SAjit Kumar Pandey }
216d4c750f2SAjit Kumar Pandey
acp_card_rt5682_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)217af830fc4SVenkata Prasad Potturu static int acp_card_rt5682_hw_params(struct snd_pcm_substream *substream,
218af830fc4SVenkata Prasad Potturu struct snd_pcm_hw_params *params)
219af830fc4SVenkata Prasad Potturu {
220a84d8407SKrzysztof Kozlowski struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
221af830fc4SVenkata Prasad Potturu struct snd_soc_card *card = rtd->card;
222af830fc4SVenkata Prasad Potturu struct acp_card_drvdata *drvdata = card->drvdata;
223d4f23dcdSKuninori Morimoto struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
224d4f23dcdSKuninori Morimoto struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
225af830fc4SVenkata Prasad Potturu int ret;
226ca9d2379SVenkata Prasad Potturu unsigned int fmt, srate, ch, format;
227ca9d2379SVenkata Prasad Potturu
228ca9d2379SVenkata Prasad Potturu srate = params_rate(params);
229ca9d2379SVenkata Prasad Potturu ch = params_channels(params);
23055e681c9SVenkata Prasad Potturu format = params_physical_width(params);
231af830fc4SVenkata Prasad Potturu
23220055300SVenkata Prasad Potturu if (drvdata->tdm_mode)
23320055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_DSP_A;
234af830fc4SVenkata Prasad Potturu else
23520055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_I2S;
23620055300SVenkata Prasad Potturu
23720055300SVenkata Prasad Potturu if (drvdata->soc_mclk)
23820055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
23920055300SVenkata Prasad Potturu else
24020055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
241af830fc4SVenkata Prasad Potturu
242af830fc4SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
243af830fc4SVenkata Prasad Potturu if (ret && ret != -ENOTSUPP) {
244af830fc4SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set dai fmt: %d\n", ret);
245af830fc4SVenkata Prasad Potturu return ret;
246af830fc4SVenkata Prasad Potturu }
247af830fc4SVenkata Prasad Potturu
248af830fc4SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(codec_dai, fmt);
249af830fc4SVenkata Prasad Potturu if (ret < 0) {
250af830fc4SVenkata Prasad Potturu dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
251af830fc4SVenkata Prasad Potturu return ret;
252af830fc4SVenkata Prasad Potturu }
253af830fc4SVenkata Prasad Potturu
25420055300SVenkata Prasad Potturu if (drvdata->tdm_mode) {
25520055300SVenkata Prasad Potturu /**
25620055300SVenkata Prasad Potturu * As codec supports slot 0 and slot 1 for playback and capture.
25720055300SVenkata Prasad Potturu */
25820055300SVenkata Prasad Potturu ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 8, 16);
25920055300SVenkata Prasad Potturu if (ret && ret != -ENOTSUPP) {
26020055300SVenkata Prasad Potturu dev_err(rtd->dev, "set TDM slot err: %d\n", ret);
26120055300SVenkata Prasad Potturu return ret;
26220055300SVenkata Prasad Potturu }
26320055300SVenkata Prasad Potturu
26420055300SVenkata Prasad Potturu ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 0x3, 8, 16);
26520055300SVenkata Prasad Potturu if (ret < 0) {
26620055300SVenkata Prasad Potturu dev_warn(rtd->dev, "set TDM slot err:%d\n", ret);
26720055300SVenkata Prasad Potturu return ret;
26820055300SVenkata Prasad Potturu }
26920055300SVenkata Prasad Potturu }
27020055300SVenkata Prasad Potturu
271ca9d2379SVenkata Prasad Potturu ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL2, RT5682_PLL2_S_MCLK,
272ca9d2379SVenkata Prasad Potturu PCO_PLAT_CLK, RT5682_PLL_FREQ);
273ca9d2379SVenkata Prasad Potturu if (ret < 0) {
274ca9d2379SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set codec PLL: %d\n", ret);
275ca9d2379SVenkata Prasad Potturu return ret;
276ca9d2379SVenkata Prasad Potturu }
277ca9d2379SVenkata Prasad Potturu
278ca9d2379SVenkata Prasad Potturu ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL2,
279ca9d2379SVenkata Prasad Potturu RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
280ca9d2379SVenkata Prasad Potturu if (ret < 0) {
281ca9d2379SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set codec SYSCLK: %d\n", ret);
282ca9d2379SVenkata Prasad Potturu return ret;
283ca9d2379SVenkata Prasad Potturu }
284ca9d2379SVenkata Prasad Potturu
28514b4b5fdSVenkata Prasad Potturu if (drvdata->tdm_mode) {
28614b4b5fdSVenkata Prasad Potturu ret = snd_soc_dai_set_pll(codec_dai, RT5682S_PLL1, RT5682S_PLL_S_BCLK1,
28714b4b5fdSVenkata Prasad Potturu 6144000, 49152000);
28814b4b5fdSVenkata Prasad Potturu if (ret < 0) {
28914b4b5fdSVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set codec PLL: %d\n", ret);
29014b4b5fdSVenkata Prasad Potturu return ret;
29114b4b5fdSVenkata Prasad Potturu }
29214b4b5fdSVenkata Prasad Potturu
29314b4b5fdSVenkata Prasad Potturu ret = snd_soc_dai_set_sysclk(codec_dai, RT5682S_SCLK_S_PLL1,
29414b4b5fdSVenkata Prasad Potturu 49152000, SND_SOC_CLOCK_IN);
29514b4b5fdSVenkata Prasad Potturu if (ret < 0) {
29614b4b5fdSVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set codec SYSCLK: %d\n", ret);
29714b4b5fdSVenkata Prasad Potturu return ret;
29814b4b5fdSVenkata Prasad Potturu }
29914b4b5fdSVenkata Prasad Potturu }
30014b4b5fdSVenkata Prasad Potturu
301ca9d2379SVenkata Prasad Potturu /* Set tdm/i2s1 master bclk ratio */
302ca9d2379SVenkata Prasad Potturu ret = snd_soc_dai_set_bclk_ratio(codec_dai, ch * format);
303ca9d2379SVenkata Prasad Potturu if (ret < 0) {
304ca9d2379SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set rt5682 tdm bclk ratio: %d\n", ret);
305ca9d2379SVenkata Prasad Potturu return ret;
306ca9d2379SVenkata Prasad Potturu }
307ca9d2379SVenkata Prasad Potturu
308ca9d2379SVenkata Prasad Potturu if (!drvdata->soc_mclk) {
309ca9d2379SVenkata Prasad Potturu ret = acp_clk_enable(drvdata, srate, ch * format);
310ca9d2379SVenkata Prasad Potturu if (ret < 0) {
311ca9d2379SVenkata Prasad Potturu dev_err(rtd->card->dev, "Failed to enable HS clk: %d\n", ret);
312ca9d2379SVenkata Prasad Potturu return ret;
313ca9d2379SVenkata Prasad Potturu }
314ca9d2379SVenkata Prasad Potturu }
315ca9d2379SVenkata Prasad Potturu
316af830fc4SVenkata Prasad Potturu return 0;
317af830fc4SVenkata Prasad Potturu }
318af830fc4SVenkata Prasad Potturu
319d4c750f2SAjit Kumar Pandey static const struct snd_soc_ops acp_card_rt5682_ops = {
320d4c750f2SAjit Kumar Pandey .startup = acp_card_hs_startup,
321d4c750f2SAjit Kumar Pandey .shutdown = acp_card_shutdown,
322af830fc4SVenkata Prasad Potturu .hw_params = acp_card_rt5682_hw_params,
323d4c750f2SAjit Kumar Pandey };
324d4c750f2SAjit Kumar Pandey
3258b725626SAjit Kumar Pandey /* Define RT5682S CODEC component*/
3268b725626SAjit Kumar Pandey SND_SOC_DAILINK_DEF(rt5682s,
3278b725626SAjit Kumar Pandey DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RTL5682:00", "rt5682s-aif1")));
3288b725626SAjit Kumar Pandey
3297ac3404cSAlper Nebi Yasak static struct snd_soc_jack rt5682s_jack;
3307ac3404cSAlper Nebi Yasak static struct snd_soc_jack_pin rt5682s_jack_pins[] = {
3317ac3404cSAlper Nebi Yasak {
3327ac3404cSAlper Nebi Yasak .pin = "Headphone Jack",
3337ac3404cSAlper Nebi Yasak .mask = SND_JACK_HEADPHONE,
3347ac3404cSAlper Nebi Yasak },
3357ac3404cSAlper Nebi Yasak {
3367ac3404cSAlper Nebi Yasak .pin = "Headset Mic",
3377ac3404cSAlper Nebi Yasak .mask = SND_JACK_MICROPHONE,
3387ac3404cSAlper Nebi Yasak },
3397ac3404cSAlper Nebi Yasak };
3407ac3404cSAlper Nebi Yasak
3417ac3404cSAlper Nebi Yasak static const struct snd_kcontrol_new rt5682s_controls[] = {
3427ac3404cSAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Headphone Jack"),
3437ac3404cSAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Headset Mic"),
3447ac3404cSAlper Nebi Yasak };
3457ac3404cSAlper Nebi Yasak
3467ac3404cSAlper Nebi Yasak static const struct snd_soc_dapm_widget rt5682s_widgets[] = {
3477ac3404cSAlper Nebi Yasak SND_SOC_DAPM_HP("Headphone Jack", NULL),
3487ac3404cSAlper Nebi Yasak SND_SOC_DAPM_MIC("Headset Mic", NULL),
3497ac3404cSAlper Nebi Yasak };
3507ac3404cSAlper Nebi Yasak
3518b725626SAjit Kumar Pandey static const struct snd_soc_dapm_route rt5682s_map[] = {
3528b725626SAjit Kumar Pandey { "Headphone Jack", NULL, "HPOL" },
3538b725626SAjit Kumar Pandey { "Headphone Jack", NULL, "HPOR" },
3548b725626SAjit Kumar Pandey { "IN1P", NULL, "Headset Mic" },
3558b725626SAjit Kumar Pandey };
3568b725626SAjit Kumar Pandey
acp_card_rt5682s_init(struct snd_soc_pcm_runtime * rtd)3578b725626SAjit Kumar Pandey static int acp_card_rt5682s_init(struct snd_soc_pcm_runtime *rtd)
3588b725626SAjit Kumar Pandey {
3598b725626SAjit Kumar Pandey struct snd_soc_card *card = rtd->card;
3608b725626SAjit Kumar Pandey struct acp_card_drvdata *drvdata = card->drvdata;
361d4f23dcdSKuninori Morimoto struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
3628b725626SAjit Kumar Pandey struct snd_soc_component *component = codec_dai->component;
3638b725626SAjit Kumar Pandey int ret;
3648b725626SAjit Kumar Pandey
3658b725626SAjit Kumar Pandey dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
3668b725626SAjit Kumar Pandey
3678b725626SAjit Kumar Pandey if (drvdata->hs_codec_id != RT5682S)
3688b725626SAjit Kumar Pandey return -EINVAL;
3698b725626SAjit Kumar Pandey
3704dc6737cSV sujith kumar Reddy if (!drvdata->soc_mclk) {
3718b725626SAjit Kumar Pandey drvdata->wclk = clk_get(component->dev, "rt5682-dai-wclk");
3728b725626SAjit Kumar Pandey drvdata->bclk = clk_get(component->dev, "rt5682-dai-bclk");
3734dc6737cSV sujith kumar Reddy }
3748b725626SAjit Kumar Pandey
3757ac3404cSAlper Nebi Yasak ret = snd_soc_dapm_new_controls(&card->dapm, rt5682s_widgets,
3767ac3404cSAlper Nebi Yasak ARRAY_SIZE(rt5682s_widgets));
3777ac3404cSAlper Nebi Yasak if (ret) {
3787ac3404cSAlper Nebi Yasak dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
3797ac3404cSAlper Nebi Yasak return ret;
3807ac3404cSAlper Nebi Yasak }
3817ac3404cSAlper Nebi Yasak
3827ac3404cSAlper Nebi Yasak ret = snd_soc_add_card_controls(card, rt5682s_controls,
3837ac3404cSAlper Nebi Yasak ARRAY_SIZE(rt5682s_controls));
3847ac3404cSAlper Nebi Yasak if (ret) {
3857ac3404cSAlper Nebi Yasak dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
3867ac3404cSAlper Nebi Yasak return ret;
3877ac3404cSAlper Nebi Yasak }
3887ac3404cSAlper Nebi Yasak
3897ac3404cSAlper Nebi Yasak ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
3908b725626SAjit Kumar Pandey SND_JACK_HEADSET | SND_JACK_LINEOUT |
3918b725626SAjit Kumar Pandey SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3928b725626SAjit Kumar Pandey SND_JACK_BTN_2 | SND_JACK_BTN_3,
3937ac3404cSAlper Nebi Yasak &rt5682s_jack,
3947ac3404cSAlper Nebi Yasak rt5682s_jack_pins,
3957ac3404cSAlper Nebi Yasak ARRAY_SIZE(rt5682s_jack_pins));
3968b725626SAjit Kumar Pandey if (ret) {
3978b725626SAjit Kumar Pandey dev_err(card->dev, "HP jack creation failed %d\n", ret);
3988b725626SAjit Kumar Pandey return ret;
3998b725626SAjit Kumar Pandey }
4008b725626SAjit Kumar Pandey
4017ac3404cSAlper Nebi Yasak snd_jack_set_key(rt5682s_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
4027ac3404cSAlper Nebi Yasak snd_jack_set_key(rt5682s_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
4037ac3404cSAlper Nebi Yasak snd_jack_set_key(rt5682s_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
4047ac3404cSAlper Nebi Yasak snd_jack_set_key(rt5682s_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
4058b725626SAjit Kumar Pandey
4067ac3404cSAlper Nebi Yasak ret = snd_soc_component_set_jack(component, &rt5682s_jack, NULL);
4078b725626SAjit Kumar Pandey if (ret) {
4088b725626SAjit Kumar Pandey dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
4098b725626SAjit Kumar Pandey return ret;
4108b725626SAjit Kumar Pandey }
4118b725626SAjit Kumar Pandey
4128b725626SAjit Kumar Pandey return snd_soc_dapm_add_routes(&rtd->card->dapm, rt5682s_map, ARRAY_SIZE(rt5682s_map));
4138b725626SAjit Kumar Pandey }
4148b725626SAjit Kumar Pandey
acp_card_rt5682s_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)415af830fc4SVenkata Prasad Potturu static int acp_card_rt5682s_hw_params(struct snd_pcm_substream *substream,
416af830fc4SVenkata Prasad Potturu struct snd_pcm_hw_params *params)
417af830fc4SVenkata Prasad Potturu {
418af830fc4SVenkata Prasad Potturu struct snd_soc_pcm_runtime *rtd = substream->private_data;
419af830fc4SVenkata Prasad Potturu struct snd_soc_card *card = rtd->card;
420af830fc4SVenkata Prasad Potturu struct acp_card_drvdata *drvdata = card->drvdata;
421d4f23dcdSKuninori Morimoto struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
422d4f23dcdSKuninori Morimoto struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
423af830fc4SVenkata Prasad Potturu int ret;
424ca9d2379SVenkata Prasad Potturu unsigned int fmt, srate, ch, format;
425ca9d2379SVenkata Prasad Potturu
426ca9d2379SVenkata Prasad Potturu srate = params_rate(params);
427ca9d2379SVenkata Prasad Potturu ch = params_channels(params);
42855e681c9SVenkata Prasad Potturu format = params_physical_width(params);
429af830fc4SVenkata Prasad Potturu
43020055300SVenkata Prasad Potturu if (drvdata->tdm_mode)
43120055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_DSP_A;
432af830fc4SVenkata Prasad Potturu else
43320055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_I2S;
43420055300SVenkata Prasad Potturu
43520055300SVenkata Prasad Potturu if (drvdata->soc_mclk)
43620055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
43720055300SVenkata Prasad Potturu else
43820055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
439af830fc4SVenkata Prasad Potturu
440af830fc4SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
441af830fc4SVenkata Prasad Potturu if (ret && ret != -ENOTSUPP) {
442af830fc4SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set dai fmt: %d\n", ret);
443af830fc4SVenkata Prasad Potturu return ret;
444af830fc4SVenkata Prasad Potturu }
445af830fc4SVenkata Prasad Potturu
446af830fc4SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(codec_dai, fmt);
447af830fc4SVenkata Prasad Potturu if (ret < 0) {
448af830fc4SVenkata Prasad Potturu dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
449af830fc4SVenkata Prasad Potturu return ret;
450af830fc4SVenkata Prasad Potturu }
451af830fc4SVenkata Prasad Potturu
45220055300SVenkata Prasad Potturu if (drvdata->tdm_mode) {
45320055300SVenkata Prasad Potturu /**
45420055300SVenkata Prasad Potturu * As codec supports slot 0 and slot 1 for playback and capture.
45520055300SVenkata Prasad Potturu */
45620055300SVenkata Prasad Potturu ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 8, 16);
45720055300SVenkata Prasad Potturu if (ret && ret != -ENOTSUPP) {
45820055300SVenkata Prasad Potturu dev_err(rtd->dev, "set TDM slot err: %d\n", ret);
45920055300SVenkata Prasad Potturu return ret;
46020055300SVenkata Prasad Potturu }
46120055300SVenkata Prasad Potturu
46220055300SVenkata Prasad Potturu ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 0x3, 8, 16);
46320055300SVenkata Prasad Potturu if (ret < 0) {
46420055300SVenkata Prasad Potturu dev_warn(rtd->dev, "set TDM slot err:%d\n", ret);
46520055300SVenkata Prasad Potturu return ret;
46620055300SVenkata Prasad Potturu }
46720055300SVenkata Prasad Potturu }
46820055300SVenkata Prasad Potturu
469ca9d2379SVenkata Prasad Potturu ret = snd_soc_dai_set_pll(codec_dai, RT5682S_PLL2, RT5682S_PLL_S_MCLK,
470ca9d2379SVenkata Prasad Potturu PCO_PLAT_CLK, RT5682_PLL_FREQ);
471ca9d2379SVenkata Prasad Potturu if (ret < 0) {
472ca9d2379SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set codec PLL: %d\n", ret);
473ca9d2379SVenkata Prasad Potturu return ret;
474ca9d2379SVenkata Prasad Potturu }
475ca9d2379SVenkata Prasad Potturu
476ca9d2379SVenkata Prasad Potturu ret = snd_soc_dai_set_sysclk(codec_dai, RT5682S_SCLK_S_PLL2,
477ca9d2379SVenkata Prasad Potturu RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
478ca9d2379SVenkata Prasad Potturu if (ret < 0) {
479ca9d2379SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set codec SYSCLK: %d\n", ret);
480ca9d2379SVenkata Prasad Potturu return ret;
481ca9d2379SVenkata Prasad Potturu }
482ca9d2379SVenkata Prasad Potturu
483ff5a698cSVenkata Prasad Potturu if (drvdata->tdm_mode) {
484ff5a698cSVenkata Prasad Potturu ret = snd_soc_dai_set_pll(codec_dai, RT5682S_PLL1, RT5682S_PLL_S_BCLK1,
485ff5a698cSVenkata Prasad Potturu 6144000, 49152000);
486ff5a698cSVenkata Prasad Potturu if (ret < 0) {
487ff5a698cSVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set codec PLL: %d\n", ret);
488ff5a698cSVenkata Prasad Potturu return ret;
489ff5a698cSVenkata Prasad Potturu }
490ff5a698cSVenkata Prasad Potturu
491ff5a698cSVenkata Prasad Potturu ret = snd_soc_dai_set_sysclk(codec_dai, RT5682S_SCLK_S_PLL1,
492ff5a698cSVenkata Prasad Potturu 49152000, SND_SOC_CLOCK_IN);
493ff5a698cSVenkata Prasad Potturu if (ret < 0) {
494ff5a698cSVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set codec SYSCLK: %d\n", ret);
495ff5a698cSVenkata Prasad Potturu return ret;
496ff5a698cSVenkata Prasad Potturu }
497ff5a698cSVenkata Prasad Potturu }
498ff5a698cSVenkata Prasad Potturu
499ca9d2379SVenkata Prasad Potturu /* Set tdm/i2s1 master bclk ratio */
500ca9d2379SVenkata Prasad Potturu ret = snd_soc_dai_set_bclk_ratio(codec_dai, ch * format);
501ca9d2379SVenkata Prasad Potturu if (ret < 0) {
502ca9d2379SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set rt5682 tdm bclk ratio: %d\n", ret);
503ca9d2379SVenkata Prasad Potturu return ret;
504ca9d2379SVenkata Prasad Potturu }
505ca9d2379SVenkata Prasad Potturu
506ca9d2379SVenkata Prasad Potturu clk_set_rate(drvdata->wclk, srate);
507ca9d2379SVenkata Prasad Potturu clk_set_rate(drvdata->bclk, srate * ch * format);
5081d565de8SVenkata Prasad Potturu if (!drvdata->soc_mclk) {
5091d565de8SVenkata Prasad Potturu ret = acp_clk_enable(drvdata, srate, ch * format);
5101d565de8SVenkata Prasad Potturu if (ret < 0) {
5111d565de8SVenkata Prasad Potturu dev_err(rtd->card->dev, "Failed to enable HS clk: %d\n", ret);
5121d565de8SVenkata Prasad Potturu return ret;
5131d565de8SVenkata Prasad Potturu }
5141d565de8SVenkata Prasad Potturu }
515ca9d2379SVenkata Prasad Potturu
516af830fc4SVenkata Prasad Potturu return 0;
517af830fc4SVenkata Prasad Potturu }
518af830fc4SVenkata Prasad Potturu
5198b725626SAjit Kumar Pandey static const struct snd_soc_ops acp_card_rt5682s_ops = {
5208b725626SAjit Kumar Pandey .startup = acp_card_hs_startup,
521af830fc4SVenkata Prasad Potturu .hw_params = acp_card_rt5682s_hw_params,
5228b725626SAjit Kumar Pandey };
5238b725626SAjit Kumar Pandey
5241f197351SAjit Kumar Pandey static const unsigned int dmic_channels[] = {
5251f197351SAjit Kumar Pandey DUAL_CHANNEL, FOUR_CHANNEL,
5261f197351SAjit Kumar Pandey };
5271f197351SAjit Kumar Pandey
5281f197351SAjit Kumar Pandey static const struct snd_pcm_hw_constraint_list dmic_constraints_channels = {
5291f197351SAjit Kumar Pandey .count = ARRAY_SIZE(dmic_channels),
5301f197351SAjit Kumar Pandey .list = dmic_channels,
5311f197351SAjit Kumar Pandey .mask = 0,
5321f197351SAjit Kumar Pandey };
5331f197351SAjit Kumar Pandey
acp_card_dmic_startup(struct snd_pcm_substream * substream)5341f197351SAjit Kumar Pandey static int acp_card_dmic_startup(struct snd_pcm_substream *substream)
5351f197351SAjit Kumar Pandey {
5361f197351SAjit Kumar Pandey struct snd_pcm_runtime *runtime = substream->runtime;
5371f197351SAjit Kumar Pandey
5381f197351SAjit Kumar Pandey snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
5391f197351SAjit Kumar Pandey &dmic_constraints_channels);
5401f197351SAjit Kumar Pandey snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
5411f197351SAjit Kumar Pandey &constraints_rates);
5421f197351SAjit Kumar Pandey
5431f197351SAjit Kumar Pandey return 0;
5441f197351SAjit Kumar Pandey }
5451f197351SAjit Kumar Pandey
5461f197351SAjit Kumar Pandey static const struct snd_soc_ops acp_card_dmic_ops = {
5471f197351SAjit Kumar Pandey .startup = acp_card_dmic_startup,
5481f197351SAjit Kumar Pandey };
5491f197351SAjit Kumar Pandey
550d4c750f2SAjit Kumar Pandey /* Declare RT1019 codec components */
551d4c750f2SAjit Kumar Pandey SND_SOC_DAILINK_DEF(rt1019,
55271125508SAjit Kumar Pandey DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC1019:00", "rt1019-aif"),
55371125508SAjit Kumar Pandey COMP_CODEC("i2c-10EC1019:01", "rt1019-aif")));
554d4c750f2SAjit Kumar Pandey
555919a4a94SAlper Nebi Yasak static const struct snd_kcontrol_new rt1019_controls[] = {
556919a4a94SAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Left Spk"),
557919a4a94SAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Right Spk"),
558919a4a94SAlper Nebi Yasak };
559919a4a94SAlper Nebi Yasak
560919a4a94SAlper Nebi Yasak static const struct snd_soc_dapm_widget rt1019_widgets[] = {
561919a4a94SAlper Nebi Yasak SND_SOC_DAPM_SPK("Left Spk", NULL),
562919a4a94SAlper Nebi Yasak SND_SOC_DAPM_SPK("Right Spk", NULL),
563919a4a94SAlper Nebi Yasak };
564919a4a94SAlper Nebi Yasak
565d4c750f2SAjit Kumar Pandey static const struct snd_soc_dapm_route rt1019_map_lr[] = {
566d4c750f2SAjit Kumar Pandey { "Left Spk", NULL, "Left SPO" },
567d4c750f2SAjit Kumar Pandey { "Right Spk", NULL, "Right SPO" },
568d4c750f2SAjit Kumar Pandey };
569d4c750f2SAjit Kumar Pandey
570d4c750f2SAjit Kumar Pandey static struct snd_soc_codec_conf rt1019_conf[] = {
571d4c750f2SAjit Kumar Pandey {
572248be352SAjit Kumar Pandey .dlc = COMP_CODEC_CONF("i2c-10EC1019:01"),
573d4c750f2SAjit Kumar Pandey .name_prefix = "Left",
574d4c750f2SAjit Kumar Pandey },
575d4c750f2SAjit Kumar Pandey {
576248be352SAjit Kumar Pandey .dlc = COMP_CODEC_CONF("i2c-10EC1019:00"),
577d4c750f2SAjit Kumar Pandey .name_prefix = "Right",
578d4c750f2SAjit Kumar Pandey },
579d4c750f2SAjit Kumar Pandey };
580d4c750f2SAjit Kumar Pandey
acp_card_rt1019_init(struct snd_soc_pcm_runtime * rtd)581d4c750f2SAjit Kumar Pandey static int acp_card_rt1019_init(struct snd_soc_pcm_runtime *rtd)
582d4c750f2SAjit Kumar Pandey {
583d4c750f2SAjit Kumar Pandey struct snd_soc_card *card = rtd->card;
584d4c750f2SAjit Kumar Pandey struct acp_card_drvdata *drvdata = card->drvdata;
585919a4a94SAlper Nebi Yasak int ret;
586d4c750f2SAjit Kumar Pandey
587d4c750f2SAjit Kumar Pandey if (drvdata->amp_codec_id != RT1019)
588d4c750f2SAjit Kumar Pandey return -EINVAL;
589d4c750f2SAjit Kumar Pandey
590919a4a94SAlper Nebi Yasak ret = snd_soc_dapm_new_controls(&card->dapm, rt1019_widgets,
591919a4a94SAlper Nebi Yasak ARRAY_SIZE(rt1019_widgets));
592919a4a94SAlper Nebi Yasak if (ret) {
593919a4a94SAlper Nebi Yasak dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
594919a4a94SAlper Nebi Yasak return ret;
595919a4a94SAlper Nebi Yasak }
596919a4a94SAlper Nebi Yasak
597919a4a94SAlper Nebi Yasak ret = snd_soc_add_card_controls(card, rt1019_controls,
598919a4a94SAlper Nebi Yasak ARRAY_SIZE(rt1019_controls));
599919a4a94SAlper Nebi Yasak if (ret) {
600919a4a94SAlper Nebi Yasak dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
601919a4a94SAlper Nebi Yasak return ret;
602919a4a94SAlper Nebi Yasak }
603919a4a94SAlper Nebi Yasak
604d4c750f2SAjit Kumar Pandey return snd_soc_dapm_add_routes(&rtd->card->dapm, rt1019_map_lr,
605d4c750f2SAjit Kumar Pandey ARRAY_SIZE(rt1019_map_lr));
606d4c750f2SAjit Kumar Pandey }
607d4c750f2SAjit Kumar Pandey
acp_card_rt1019_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)608d4c750f2SAjit Kumar Pandey static int acp_card_rt1019_hw_params(struct snd_pcm_substream *substream,
609d4c750f2SAjit Kumar Pandey struct snd_pcm_hw_params *params)
610d4c750f2SAjit Kumar Pandey {
611d4c750f2SAjit Kumar Pandey struct snd_soc_pcm_runtime *rtd = substream->private_data;
612d4c750f2SAjit Kumar Pandey struct snd_soc_card *card = rtd->card;
613d4c750f2SAjit Kumar Pandey struct acp_card_drvdata *drvdata = card->drvdata;
614d4c750f2SAjit Kumar Pandey struct snd_soc_dai *codec_dai;
615d4f23dcdSKuninori Morimoto struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
616ca9d2379SVenkata Prasad Potturu int i, ret = 0;
617ca9d2379SVenkata Prasad Potturu unsigned int fmt, srate, ch, format;
618d4c750f2SAjit Kumar Pandey
619d4c750f2SAjit Kumar Pandey srate = params_rate(params);
620ca9d2379SVenkata Prasad Potturu ch = params_channels(params);
62155e681c9SVenkata Prasad Potturu format = params_physical_width(params);
622d4c750f2SAjit Kumar Pandey
623d4c750f2SAjit Kumar Pandey if (drvdata->amp_codec_id != RT1019)
624d4c750f2SAjit Kumar Pandey return -EINVAL;
625d4c750f2SAjit Kumar Pandey
62620055300SVenkata Prasad Potturu if (drvdata->tdm_mode)
62720055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_DSP_A;
628af830fc4SVenkata Prasad Potturu else
62920055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_I2S;
63020055300SVenkata Prasad Potturu
63120055300SVenkata Prasad Potturu if (drvdata->soc_mclk)
63220055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
63320055300SVenkata Prasad Potturu else
63420055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
635af830fc4SVenkata Prasad Potturu
636af830fc4SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
637af830fc4SVenkata Prasad Potturu if (ret && ret != -ENOTSUPP) {
638af830fc4SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set dai fmt: %d\n", ret);
639af830fc4SVenkata Prasad Potturu return ret;
640af830fc4SVenkata Prasad Potturu }
641af830fc4SVenkata Prasad Potturu
64220055300SVenkata Prasad Potturu if (drvdata->tdm_mode) {
64320055300SVenkata Prasad Potturu /**
64420055300SVenkata Prasad Potturu * As codec supports slot 2 and slot 3 for playback.
64520055300SVenkata Prasad Potturu */
64620055300SVenkata Prasad Potturu ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xC, 0, 8, 16);
64720055300SVenkata Prasad Potturu if (ret && ret != -ENOTSUPP) {
64820055300SVenkata Prasad Potturu dev_err(rtd->dev, "set TDM slot err: %d\n", ret);
64920055300SVenkata Prasad Potturu return ret;
65020055300SVenkata Prasad Potturu }
65120055300SVenkata Prasad Potturu }
65220055300SVenkata Prasad Potturu
653d4c750f2SAjit Kumar Pandey for_each_rtd_codec_dais(rtd, i, codec_dai) {
654d4c750f2SAjit Kumar Pandey if (strcmp(codec_dai->name, "rt1019-aif"))
655d4c750f2SAjit Kumar Pandey continue;
656d4c750f2SAjit Kumar Pandey
65720055300SVenkata Prasad Potturu if (drvdata->tdm_mode)
65820055300SVenkata Prasad Potturu ret = snd_soc_dai_set_pll(codec_dai, 0, RT1019_PLL_S_BCLK,
65920055300SVenkata Prasad Potturu TDM_CHANNELS * format * srate, 256 * srate);
66020055300SVenkata Prasad Potturu else
661d4c750f2SAjit Kumar Pandey ret = snd_soc_dai_set_pll(codec_dai, 0, RT1019_PLL_S_BCLK,
662ca9d2379SVenkata Prasad Potturu ch * format * srate, 256 * srate);
66320055300SVenkata Prasad Potturu
664d4c750f2SAjit Kumar Pandey if (ret < 0)
665d4c750f2SAjit Kumar Pandey return ret;
666d4c750f2SAjit Kumar Pandey
667d4c750f2SAjit Kumar Pandey ret = snd_soc_dai_set_sysclk(codec_dai, RT1019_SCLK_S_PLL,
668d4c750f2SAjit Kumar Pandey 256 * srate, SND_SOC_CLOCK_IN);
669d4c750f2SAjit Kumar Pandey if (ret < 0)
670d4c750f2SAjit Kumar Pandey return ret;
67120055300SVenkata Prasad Potturu
67220055300SVenkata Prasad Potturu if (drvdata->tdm_mode) {
67320055300SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
67420055300SVenkata Prasad Potturu | SND_SOC_DAIFMT_NB_NF);
67520055300SVenkata Prasad Potturu if (ret < 0) {
67620055300SVenkata Prasad Potturu dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
67720055300SVenkata Prasad Potturu return ret;
67820055300SVenkata Prasad Potturu }
67920055300SVenkata Prasad Potturu
68020055300SVenkata Prasad Potturu /**
68120055300SVenkata Prasad Potturu * As codec supports slot 2 for left channel playback.
68220055300SVenkata Prasad Potturu */
68320055300SVenkata Prasad Potturu if (!strcmp(codec_dai->component->name, "i2c-10EC1019:00")) {
68420055300SVenkata Prasad Potturu ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x4, 0x4, 8, 16);
68520055300SVenkata Prasad Potturu if (ret < 0)
68620055300SVenkata Prasad Potturu break;
68720055300SVenkata Prasad Potturu }
68820055300SVenkata Prasad Potturu
68920055300SVenkata Prasad Potturu /**
69020055300SVenkata Prasad Potturu * As codec supports slot 3 for right channel playback.
69120055300SVenkata Prasad Potturu */
69220055300SVenkata Prasad Potturu if (!strcmp(codec_dai->component->name, "i2c-10EC1019:01")) {
69320055300SVenkata Prasad Potturu ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x8, 0x8, 8, 16);
69420055300SVenkata Prasad Potturu if (ret < 0)
69520055300SVenkata Prasad Potturu break;
69620055300SVenkata Prasad Potturu }
69720055300SVenkata Prasad Potturu }
698d4c750f2SAjit Kumar Pandey }
699d4c750f2SAjit Kumar Pandey
700ca9d2379SVenkata Prasad Potturu if (!drvdata->soc_mclk) {
701ca9d2379SVenkata Prasad Potturu ret = acp_clk_enable(drvdata, srate, ch * format);
702ca9d2379SVenkata Prasad Potturu if (ret < 0) {
703ca9d2379SVenkata Prasad Potturu dev_err(rtd->card->dev, "Failed to enable AMP clk: %d\n", ret);
704ca9d2379SVenkata Prasad Potturu return ret;
705ca9d2379SVenkata Prasad Potturu }
706ca9d2379SVenkata Prasad Potturu }
707ca9d2379SVenkata Prasad Potturu
708d4c750f2SAjit Kumar Pandey return 0;
709d4c750f2SAjit Kumar Pandey }
710d4c750f2SAjit Kumar Pandey
acp_card_amp_startup(struct snd_pcm_substream * substream)711d4c750f2SAjit Kumar Pandey static int acp_card_amp_startup(struct snd_pcm_substream *substream)
712d4c750f2SAjit Kumar Pandey {
713d4c750f2SAjit Kumar Pandey struct snd_pcm_runtime *runtime = substream->runtime;
714d4c750f2SAjit Kumar Pandey
715d4c750f2SAjit Kumar Pandey runtime->hw.channels_max = DUAL_CHANNEL;
716d4c750f2SAjit Kumar Pandey snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
717d4c750f2SAjit Kumar Pandey &constraints_channels);
718d4c750f2SAjit Kumar Pandey snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
719d4c750f2SAjit Kumar Pandey &constraints_rates);
720d4c750f2SAjit Kumar Pandey
721ca9d2379SVenkata Prasad Potturu return 0;
722d4c750f2SAjit Kumar Pandey }
723d4c750f2SAjit Kumar Pandey
724d4c750f2SAjit Kumar Pandey static const struct snd_soc_ops acp_card_rt1019_ops = {
725d4c750f2SAjit Kumar Pandey .startup = acp_card_amp_startup,
726d4c750f2SAjit Kumar Pandey .shutdown = acp_card_shutdown,
727d4c750f2SAjit Kumar Pandey .hw_params = acp_card_rt1019_hw_params,
728d4c750f2SAjit Kumar Pandey };
729d4c750f2SAjit Kumar Pandey
730cabc3aceSAjit Kumar Pandey /* Declare Maxim codec components */
731cabc3aceSAjit Kumar Pandey SND_SOC_DAILINK_DEF(max98360a,
732cabc3aceSAjit Kumar Pandey DAILINK_COMP_ARRAY(COMP_CODEC("MX98360A:00", "HiFi")));
733cabc3aceSAjit Kumar Pandey
734919a4a94SAlper Nebi Yasak static const struct snd_kcontrol_new max98360a_controls[] = {
735919a4a94SAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Spk"),
736919a4a94SAlper Nebi Yasak };
737919a4a94SAlper Nebi Yasak
738919a4a94SAlper Nebi Yasak static const struct snd_soc_dapm_widget max98360a_widgets[] = {
739919a4a94SAlper Nebi Yasak SND_SOC_DAPM_SPK("Spk", NULL),
740919a4a94SAlper Nebi Yasak };
741919a4a94SAlper Nebi Yasak
742cabc3aceSAjit Kumar Pandey static const struct snd_soc_dapm_route max98360a_map[] = {
743cabc3aceSAjit Kumar Pandey {"Spk", NULL, "Speaker"},
744cabc3aceSAjit Kumar Pandey };
745cabc3aceSAjit Kumar Pandey
acp_card_maxim_init(struct snd_soc_pcm_runtime * rtd)746cabc3aceSAjit Kumar Pandey static int acp_card_maxim_init(struct snd_soc_pcm_runtime *rtd)
747cabc3aceSAjit Kumar Pandey {
748cabc3aceSAjit Kumar Pandey struct snd_soc_card *card = rtd->card;
749cabc3aceSAjit Kumar Pandey struct acp_card_drvdata *drvdata = card->drvdata;
750919a4a94SAlper Nebi Yasak int ret;
751cabc3aceSAjit Kumar Pandey
752cabc3aceSAjit Kumar Pandey if (drvdata->amp_codec_id != MAX98360A)
753cabc3aceSAjit Kumar Pandey return -EINVAL;
754cabc3aceSAjit Kumar Pandey
755919a4a94SAlper Nebi Yasak ret = snd_soc_dapm_new_controls(&card->dapm, max98360a_widgets,
756919a4a94SAlper Nebi Yasak ARRAY_SIZE(max98360a_widgets));
757919a4a94SAlper Nebi Yasak if (ret) {
758919a4a94SAlper Nebi Yasak dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
759919a4a94SAlper Nebi Yasak return ret;
760919a4a94SAlper Nebi Yasak }
761919a4a94SAlper Nebi Yasak
762919a4a94SAlper Nebi Yasak ret = snd_soc_add_card_controls(card, max98360a_controls,
763919a4a94SAlper Nebi Yasak ARRAY_SIZE(max98360a_controls));
764919a4a94SAlper Nebi Yasak if (ret) {
765919a4a94SAlper Nebi Yasak dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
766919a4a94SAlper Nebi Yasak return ret;
767919a4a94SAlper Nebi Yasak }
768919a4a94SAlper Nebi Yasak
769cabc3aceSAjit Kumar Pandey return snd_soc_dapm_add_routes(&rtd->card->dapm, max98360a_map,
770cabc3aceSAjit Kumar Pandey ARRAY_SIZE(max98360a_map));
771cabc3aceSAjit Kumar Pandey }
772cabc3aceSAjit Kumar Pandey
acp_card_maxim_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)773af830fc4SVenkata Prasad Potturu static int acp_card_maxim_hw_params(struct snd_pcm_substream *substream,
774af830fc4SVenkata Prasad Potturu struct snd_pcm_hw_params *params)
775af830fc4SVenkata Prasad Potturu {
776af830fc4SVenkata Prasad Potturu struct snd_soc_pcm_runtime *rtd = substream->private_data;
777af830fc4SVenkata Prasad Potturu struct snd_soc_card *card = rtd->card;
778af830fc4SVenkata Prasad Potturu struct acp_card_drvdata *drvdata = card->drvdata;
779d4f23dcdSKuninori Morimoto struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
780ca9d2379SVenkata Prasad Potturu unsigned int fmt, srate, ch, format;
781af830fc4SVenkata Prasad Potturu int ret;
782af830fc4SVenkata Prasad Potturu
783ca9d2379SVenkata Prasad Potturu srate = params_rate(params);
784ca9d2379SVenkata Prasad Potturu ch = params_channels(params);
78555e681c9SVenkata Prasad Potturu format = params_physical_width(params);
786ca9d2379SVenkata Prasad Potturu
78720055300SVenkata Prasad Potturu if (drvdata->tdm_mode)
78820055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_DSP_A;
789af830fc4SVenkata Prasad Potturu else
79020055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_I2S;
79120055300SVenkata Prasad Potturu
79220055300SVenkata Prasad Potturu if (drvdata->soc_mclk)
79320055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
79420055300SVenkata Prasad Potturu else
79520055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
796af830fc4SVenkata Prasad Potturu
797af830fc4SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
798af830fc4SVenkata Prasad Potturu if (ret && ret != -ENOTSUPP) {
799af830fc4SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set dai fmt: %d\n", ret);
800af830fc4SVenkata Prasad Potturu return ret;
801af830fc4SVenkata Prasad Potturu }
802ca9d2379SVenkata Prasad Potturu
80320055300SVenkata Prasad Potturu if (drvdata->tdm_mode) {
80420055300SVenkata Prasad Potturu /**
80520055300SVenkata Prasad Potturu * As codec supports slot 2 and slot 3 for playback.
80620055300SVenkata Prasad Potturu */
80720055300SVenkata Prasad Potturu ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xC, 0, 8, 16);
80820055300SVenkata Prasad Potturu if (ret && ret != -ENOTSUPP) {
80920055300SVenkata Prasad Potturu dev_err(rtd->dev, "set TDM slot err: %d\n", ret);
81020055300SVenkata Prasad Potturu return ret;
81120055300SVenkata Prasad Potturu }
81220055300SVenkata Prasad Potturu }
81320055300SVenkata Prasad Potturu
814ca9d2379SVenkata Prasad Potturu if (!drvdata->soc_mclk) {
815ca9d2379SVenkata Prasad Potturu ret = acp_clk_enable(drvdata, srate, ch * format);
816ca9d2379SVenkata Prasad Potturu if (ret < 0) {
817ca9d2379SVenkata Prasad Potturu dev_err(rtd->card->dev, "Failed to enable AMP clk: %d\n", ret);
818ca9d2379SVenkata Prasad Potturu return ret;
819ca9d2379SVenkata Prasad Potturu }
820ca9d2379SVenkata Prasad Potturu }
821af830fc4SVenkata Prasad Potturu return 0;
822af830fc4SVenkata Prasad Potturu }
823af830fc4SVenkata Prasad Potturu
824cabc3aceSAjit Kumar Pandey static const struct snd_soc_ops acp_card_maxim_ops = {
825cabc3aceSAjit Kumar Pandey .startup = acp_card_amp_startup,
826cabc3aceSAjit Kumar Pandey .shutdown = acp_card_shutdown,
827af830fc4SVenkata Prasad Potturu .hw_params = acp_card_maxim_hw_params,
828cabc3aceSAjit Kumar Pandey };
829cabc3aceSAjit Kumar Pandey
830ac91c8c8SVenkata Prasad Potturu SND_SOC_DAILINK_DEF(max98388,
83168ab2942SCristian Ciocaltea DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ADS8388:00", MAX98388_CODEC_DAI),
83268ab2942SCristian Ciocaltea COMP_CODEC("i2c-ADS8388:01", MAX98388_CODEC_DAI)));
833ac91c8c8SVenkata Prasad Potturu
834919a4a94SAlper Nebi Yasak static const struct snd_kcontrol_new max98388_controls[] = {
835919a4a94SAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Left Spk"),
836919a4a94SAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Right Spk"),
837919a4a94SAlper Nebi Yasak };
838919a4a94SAlper Nebi Yasak
839ac91c8c8SVenkata Prasad Potturu static const struct snd_soc_dapm_widget max98388_widgets[] = {
840919a4a94SAlper Nebi Yasak SND_SOC_DAPM_SPK("Left Spk", NULL),
841919a4a94SAlper Nebi Yasak SND_SOC_DAPM_SPK("Right Spk", NULL),
842ac91c8c8SVenkata Prasad Potturu };
843ac91c8c8SVenkata Prasad Potturu
844ac91c8c8SVenkata Prasad Potturu static const struct snd_soc_dapm_route max98388_map[] = {
845919a4a94SAlper Nebi Yasak { "Left Spk", NULL, "Left BE_OUT" },
846919a4a94SAlper Nebi Yasak { "Right Spk", NULL, "Right BE_OUT" },
847ac91c8c8SVenkata Prasad Potturu };
848ac91c8c8SVenkata Prasad Potturu
849ac91c8c8SVenkata Prasad Potturu static struct snd_soc_codec_conf max98388_conf[] = {
850ac91c8c8SVenkata Prasad Potturu {
851ac91c8c8SVenkata Prasad Potturu .dlc = COMP_CODEC_CONF("i2c-ADS8388:00"),
852ac91c8c8SVenkata Prasad Potturu .name_prefix = "Left",
853ac91c8c8SVenkata Prasad Potturu },
854ac91c8c8SVenkata Prasad Potturu {
855ac91c8c8SVenkata Prasad Potturu .dlc = COMP_CODEC_CONF("i2c-ADS8388:01"),
856ac91c8c8SVenkata Prasad Potturu .name_prefix = "Right",
857ac91c8c8SVenkata Prasad Potturu },
858ac91c8c8SVenkata Prasad Potturu };
859ac91c8c8SVenkata Prasad Potturu
860ac91c8c8SVenkata Prasad Potturu static const unsigned int max98388_format[] = {16};
861ac91c8c8SVenkata Prasad Potturu
862ac91c8c8SVenkata Prasad Potturu static struct snd_pcm_hw_constraint_list constraints_sample_bits_max = {
863ac91c8c8SVenkata Prasad Potturu .list = max98388_format,
864ac91c8c8SVenkata Prasad Potturu .count = ARRAY_SIZE(max98388_format),
865ac91c8c8SVenkata Prasad Potturu };
866ac91c8c8SVenkata Prasad Potturu
acp_card_max98388_startup(struct snd_pcm_substream * substream)867ac91c8c8SVenkata Prasad Potturu static int acp_card_max98388_startup(struct snd_pcm_substream *substream)
868ac91c8c8SVenkata Prasad Potturu {
869ac91c8c8SVenkata Prasad Potturu struct snd_pcm_runtime *runtime = substream->runtime;
870ac91c8c8SVenkata Prasad Potturu
871ac91c8c8SVenkata Prasad Potturu runtime->hw.channels_max = DUAL_CHANNEL;
872ac91c8c8SVenkata Prasad Potturu snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
873ac91c8c8SVenkata Prasad Potturu &constraints_channels);
874ac91c8c8SVenkata Prasad Potturu snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
875ac91c8c8SVenkata Prasad Potturu &constraints_rates);
876ac91c8c8SVenkata Prasad Potturu snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
877ac91c8c8SVenkata Prasad Potturu &constraints_sample_bits_max);
878ac91c8c8SVenkata Prasad Potturu
879ac91c8c8SVenkata Prasad Potturu return 0;
880ac91c8c8SVenkata Prasad Potturu }
881ac91c8c8SVenkata Prasad Potturu
acp_card_max98388_init(struct snd_soc_pcm_runtime * rtd)882ac91c8c8SVenkata Prasad Potturu static int acp_card_max98388_init(struct snd_soc_pcm_runtime *rtd)
883ac91c8c8SVenkata Prasad Potturu {
884ac91c8c8SVenkata Prasad Potturu struct snd_soc_card *card = rtd->card;
885ac91c8c8SVenkata Prasad Potturu struct acp_card_drvdata *drvdata = card->drvdata;
886ac91c8c8SVenkata Prasad Potturu int ret;
887ac91c8c8SVenkata Prasad Potturu
888ac91c8c8SVenkata Prasad Potturu if (drvdata->amp_codec_id != MAX98388)
889ac91c8c8SVenkata Prasad Potturu return -EINVAL;
890ac91c8c8SVenkata Prasad Potturu
891ac91c8c8SVenkata Prasad Potturu ret = snd_soc_dapm_new_controls(&card->dapm, max98388_widgets,
892ac91c8c8SVenkata Prasad Potturu ARRAY_SIZE(max98388_widgets));
893ac91c8c8SVenkata Prasad Potturu
894ac91c8c8SVenkata Prasad Potturu if (ret) {
895ac91c8c8SVenkata Prasad Potturu dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
896ac91c8c8SVenkata Prasad Potturu /* Don't need to add routes if widget addition failed */
897ac91c8c8SVenkata Prasad Potturu return ret;
898ac91c8c8SVenkata Prasad Potturu }
899919a4a94SAlper Nebi Yasak
900919a4a94SAlper Nebi Yasak ret = snd_soc_add_card_controls(card, max98388_controls,
901919a4a94SAlper Nebi Yasak ARRAY_SIZE(max98388_controls));
902919a4a94SAlper Nebi Yasak if (ret) {
903919a4a94SAlper Nebi Yasak dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
904919a4a94SAlper Nebi Yasak return ret;
905919a4a94SAlper Nebi Yasak }
906919a4a94SAlper Nebi Yasak
907ac91c8c8SVenkata Prasad Potturu return snd_soc_dapm_add_routes(&rtd->card->dapm, max98388_map,
908ac91c8c8SVenkata Prasad Potturu ARRAY_SIZE(max98388_map));
909ac91c8c8SVenkata Prasad Potturu }
910ac91c8c8SVenkata Prasad Potturu
acp_max98388_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)911ac91c8c8SVenkata Prasad Potturu static int acp_max98388_hw_params(struct snd_pcm_substream *substream,
912ac91c8c8SVenkata Prasad Potturu struct snd_pcm_hw_params *params)
913ac91c8c8SVenkata Prasad Potturu {
914ac91c8c8SVenkata Prasad Potturu struct snd_soc_pcm_runtime *rtd = substream->private_data;
915ac91c8c8SVenkata Prasad Potturu struct snd_soc_card *card = rtd->card;
916ac91c8c8SVenkata Prasad Potturu struct snd_soc_dai *codec_dai =
917ac91c8c8SVenkata Prasad Potturu snd_soc_card_get_codec_dai(card,
918ac91c8c8SVenkata Prasad Potturu MAX98388_CODEC_DAI);
919ac91c8c8SVenkata Prasad Potturu int ret;
920ac91c8c8SVenkata Prasad Potturu
921ac91c8c8SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(codec_dai,
922ac91c8c8SVenkata Prasad Potturu SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_I2S |
923ac91c8c8SVenkata Prasad Potturu SND_SOC_DAIFMT_NB_NF);
924ac91c8c8SVenkata Prasad Potturu if (ret < 0)
925ac91c8c8SVenkata Prasad Potturu return ret;
926ac91c8c8SVenkata Prasad Potturu
927ac91c8c8SVenkata Prasad Potturu return ret;
928ac91c8c8SVenkata Prasad Potturu }
929ac91c8c8SVenkata Prasad Potturu
930ac91c8c8SVenkata Prasad Potturu static const struct snd_soc_ops acp_max98388_ops = {
931ac91c8c8SVenkata Prasad Potturu .startup = acp_card_max98388_startup,
932ac91c8c8SVenkata Prasad Potturu .hw_params = acp_max98388_hw_params,
933ac91c8c8SVenkata Prasad Potturu };
934ac91c8c8SVenkata Prasad Potturu
9350439eb4dSV sujith kumar Reddy /* Declare nau8825 codec components */
9360439eb4dSV sujith kumar Reddy SND_SOC_DAILINK_DEF(nau8825,
9370439eb4dSV sujith kumar Reddy DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10508825:00", "nau8825-hifi")));
9380439eb4dSV sujith kumar Reddy
9397ac3404cSAlper Nebi Yasak static struct snd_soc_jack nau8825_jack;
9407ac3404cSAlper Nebi Yasak static struct snd_soc_jack_pin nau8825_jack_pins[] = {
9417ac3404cSAlper Nebi Yasak {
9427ac3404cSAlper Nebi Yasak .pin = "Headphone Jack",
9437ac3404cSAlper Nebi Yasak .mask = SND_JACK_HEADPHONE,
9447ac3404cSAlper Nebi Yasak },
9457ac3404cSAlper Nebi Yasak {
9467ac3404cSAlper Nebi Yasak .pin = "Headset Mic",
9477ac3404cSAlper Nebi Yasak .mask = SND_JACK_MICROPHONE,
9487ac3404cSAlper Nebi Yasak },
9497ac3404cSAlper Nebi Yasak };
9507ac3404cSAlper Nebi Yasak
9517ac3404cSAlper Nebi Yasak static const struct snd_kcontrol_new nau8825_controls[] = {
9527ac3404cSAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Headphone Jack"),
9537ac3404cSAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Headset Mic"),
9547ac3404cSAlper Nebi Yasak };
9557ac3404cSAlper Nebi Yasak
9567ac3404cSAlper Nebi Yasak static const struct snd_soc_dapm_widget nau8825_widgets[] = {
9577ac3404cSAlper Nebi Yasak SND_SOC_DAPM_HP("Headphone Jack", NULL),
9587ac3404cSAlper Nebi Yasak SND_SOC_DAPM_MIC("Headset Mic", NULL),
9597ac3404cSAlper Nebi Yasak };
9607ac3404cSAlper Nebi Yasak
9610439eb4dSV sujith kumar Reddy static const struct snd_soc_dapm_route nau8825_map[] = {
9620439eb4dSV sujith kumar Reddy { "Headphone Jack", NULL, "HPOL" },
9630439eb4dSV sujith kumar Reddy { "Headphone Jack", NULL, "HPOR" },
9640439eb4dSV sujith kumar Reddy };
9650439eb4dSV sujith kumar Reddy
acp_card_nau8825_init(struct snd_soc_pcm_runtime * rtd)9660439eb4dSV sujith kumar Reddy static int acp_card_nau8825_init(struct snd_soc_pcm_runtime *rtd)
9670439eb4dSV sujith kumar Reddy {
9680439eb4dSV sujith kumar Reddy struct snd_soc_card *card = rtd->card;
9690439eb4dSV sujith kumar Reddy struct acp_card_drvdata *drvdata = card->drvdata;
970d4f23dcdSKuninori Morimoto struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
9710439eb4dSV sujith kumar Reddy struct snd_soc_component *component = codec_dai->component;
9720439eb4dSV sujith kumar Reddy int ret;
9730439eb4dSV sujith kumar Reddy
9740439eb4dSV sujith kumar Reddy dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
9750439eb4dSV sujith kumar Reddy
9760439eb4dSV sujith kumar Reddy if (drvdata->hs_codec_id != NAU8825)
9770439eb4dSV sujith kumar Reddy return -EINVAL;
9780439eb4dSV sujith kumar Reddy
9797ac3404cSAlper Nebi Yasak ret = snd_soc_dapm_new_controls(&card->dapm, nau8825_widgets,
9807ac3404cSAlper Nebi Yasak ARRAY_SIZE(nau8825_widgets));
9817ac3404cSAlper Nebi Yasak if (ret) {
9827ac3404cSAlper Nebi Yasak dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
9837ac3404cSAlper Nebi Yasak return ret;
9847ac3404cSAlper Nebi Yasak }
9857ac3404cSAlper Nebi Yasak
9867ac3404cSAlper Nebi Yasak ret = snd_soc_add_card_controls(card, nau8825_controls,
9877ac3404cSAlper Nebi Yasak ARRAY_SIZE(nau8825_controls));
9887ac3404cSAlper Nebi Yasak if (ret) {
9897ac3404cSAlper Nebi Yasak dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
9907ac3404cSAlper Nebi Yasak return ret;
9917ac3404cSAlper Nebi Yasak }
9927ac3404cSAlper Nebi Yasak
9937ac3404cSAlper Nebi Yasak ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
9940439eb4dSV sujith kumar Reddy SND_JACK_HEADSET | SND_JACK_LINEOUT |
9950439eb4dSV sujith kumar Reddy SND_JACK_BTN_0 | SND_JACK_BTN_1 |
9960439eb4dSV sujith kumar Reddy SND_JACK_BTN_2 | SND_JACK_BTN_3,
9977ac3404cSAlper Nebi Yasak &nau8825_jack,
9987ac3404cSAlper Nebi Yasak nau8825_jack_pins,
9997ac3404cSAlper Nebi Yasak ARRAY_SIZE(nau8825_jack_pins));
10000439eb4dSV sujith kumar Reddy if (ret) {
10010439eb4dSV sujith kumar Reddy dev_err(card->dev, "HP jack creation failed %d\n", ret);
10020439eb4dSV sujith kumar Reddy return ret;
10030439eb4dSV sujith kumar Reddy }
10040439eb4dSV sujith kumar Reddy
10057ac3404cSAlper Nebi Yasak snd_jack_set_key(nau8825_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
10067ac3404cSAlper Nebi Yasak snd_jack_set_key(nau8825_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
10077ac3404cSAlper Nebi Yasak snd_jack_set_key(nau8825_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
10087ac3404cSAlper Nebi Yasak snd_jack_set_key(nau8825_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
10090439eb4dSV sujith kumar Reddy
10107ac3404cSAlper Nebi Yasak ret = snd_soc_component_set_jack(component, &nau8825_jack, NULL);
10110439eb4dSV sujith kumar Reddy if (ret) {
10120439eb4dSV sujith kumar Reddy dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
10130439eb4dSV sujith kumar Reddy return ret;
10140439eb4dSV sujith kumar Reddy }
10150439eb4dSV sujith kumar Reddy
10160439eb4dSV sujith kumar Reddy return snd_soc_dapm_add_routes(&rtd->card->dapm, nau8825_map, ARRAY_SIZE(nau8825_map));
10170439eb4dSV sujith kumar Reddy }
10180439eb4dSV sujith kumar Reddy
acp_nau8825_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)10190439eb4dSV sujith kumar Reddy static int acp_nau8825_hw_params(struct snd_pcm_substream *substream,
10200439eb4dSV sujith kumar Reddy struct snd_pcm_hw_params *params)
10210439eb4dSV sujith kumar Reddy {
1022d4f23dcdSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
1023af830fc4SVenkata Prasad Potturu struct snd_soc_card *card = rtd->card;
1024af830fc4SVenkata Prasad Potturu struct acp_card_drvdata *drvdata = card->drvdata;
1025d4f23dcdSKuninori Morimoto struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
1026d4f23dcdSKuninori Morimoto struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
10270439eb4dSV sujith kumar Reddy int ret;
1028af830fc4SVenkata Prasad Potturu unsigned int fmt;
10290439eb4dSV sujith kumar Reddy
10300439eb4dSV sujith kumar Reddy ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_FS,
10310439eb4dSV sujith kumar Reddy (48000 * 256), SND_SOC_CLOCK_IN);
10320439eb4dSV sujith kumar Reddy if (ret < 0)
10330439eb4dSV sujith kumar Reddy dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
10340439eb4dSV sujith kumar Reddy
10350439eb4dSV sujith kumar Reddy ret = snd_soc_dai_set_pll(codec_dai, 0, 0, params_rate(params),
10360439eb4dSV sujith kumar Reddy params_rate(params) * 256);
10370439eb4dSV sujith kumar Reddy if (ret < 0) {
10380439eb4dSV sujith kumar Reddy dev_err(rtd->dev, "can't set FLL: %d\n", ret);
10390439eb4dSV sujith kumar Reddy return ret;
10400439eb4dSV sujith kumar Reddy }
10410439eb4dSV sujith kumar Reddy
104220055300SVenkata Prasad Potturu if (drvdata->tdm_mode)
104320055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_DSP_A;
1044af830fc4SVenkata Prasad Potturu else
104520055300SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_I2S;
104620055300SVenkata Prasad Potturu
104720055300SVenkata Prasad Potturu if (drvdata->soc_mclk)
104820055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
104920055300SVenkata Prasad Potturu else
105020055300SVenkata Prasad Potturu fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
1051af830fc4SVenkata Prasad Potturu
1052af830fc4SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
1053af830fc4SVenkata Prasad Potturu if (ret && ret != -ENOTSUPP) {
1054af830fc4SVenkata Prasad Potturu dev_err(rtd->dev, "Failed to set dai fmt: %d\n", ret);
1055af830fc4SVenkata Prasad Potturu return ret;
1056af830fc4SVenkata Prasad Potturu }
1057af830fc4SVenkata Prasad Potturu
1058af830fc4SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(codec_dai, fmt);
1059af830fc4SVenkata Prasad Potturu if (ret < 0) {
1060af830fc4SVenkata Prasad Potturu dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
1061af830fc4SVenkata Prasad Potturu return ret;
1062af830fc4SVenkata Prasad Potturu }
1063af830fc4SVenkata Prasad Potturu
106420055300SVenkata Prasad Potturu if (drvdata->tdm_mode) {
106520055300SVenkata Prasad Potturu /**
106620055300SVenkata Prasad Potturu * As codec supports slot 4 and slot 5 for playback and slot 6 for capture.
106720055300SVenkata Prasad Potturu */
106820055300SVenkata Prasad Potturu ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x30, 0xC0, 8, 16);
106920055300SVenkata Prasad Potturu if (ret && ret != -ENOTSUPP) {
107020055300SVenkata Prasad Potturu dev_err(rtd->dev, "set TDM slot err: %d\n", ret);
107120055300SVenkata Prasad Potturu return ret;
107220055300SVenkata Prasad Potturu }
107320055300SVenkata Prasad Potturu
107420055300SVenkata Prasad Potturu ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x40, 0x30, 8, 16);
107520055300SVenkata Prasad Potturu if (ret < 0) {
107620055300SVenkata Prasad Potturu dev_warn(rtd->dev, "set TDM slot err:%d\n", ret);
107720055300SVenkata Prasad Potturu return ret;
107820055300SVenkata Prasad Potturu }
107920055300SVenkata Prasad Potturu }
10800439eb4dSV sujith kumar Reddy return ret;
10810439eb4dSV sujith kumar Reddy }
10820439eb4dSV sujith kumar Reddy
acp_nau8825_startup(struct snd_pcm_substream * substream)10830439eb4dSV sujith kumar Reddy static int acp_nau8825_startup(struct snd_pcm_substream *substream)
10840439eb4dSV sujith kumar Reddy {
10850439eb4dSV sujith kumar Reddy struct snd_pcm_runtime *runtime = substream->runtime;
10860439eb4dSV sujith kumar Reddy
10870439eb4dSV sujith kumar Reddy runtime->hw.channels_max = 2;
10880439eb4dSV sujith kumar Reddy snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
10890439eb4dSV sujith kumar Reddy &constraints_channels);
10900439eb4dSV sujith kumar Reddy
10910439eb4dSV sujith kumar Reddy runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
10920439eb4dSV sujith kumar Reddy snd_pcm_hw_constraint_list(runtime, 0,
10930439eb4dSV sujith kumar Reddy SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
10940439eb4dSV sujith kumar Reddy return 0;
10950439eb4dSV sujith kumar Reddy }
10960439eb4dSV sujith kumar Reddy
10970439eb4dSV sujith kumar Reddy static const struct snd_soc_ops acp_card_nau8825_ops = {
10980439eb4dSV sujith kumar Reddy .startup = acp_nau8825_startup,
10990439eb4dSV sujith kumar Reddy .hw_params = acp_nau8825_hw_params,
11000439eb4dSV sujith kumar Reddy };
11010439eb4dSV sujith kumar Reddy
platform_clock_control(struct snd_soc_dapm_widget * w,struct snd_kcontrol * k,int event)11024b526b32SVenkata Prasad Potturu static int platform_clock_control(struct snd_soc_dapm_widget *w,
11034b526b32SVenkata Prasad Potturu struct snd_kcontrol *k, int event)
11044b526b32SVenkata Prasad Potturu {
11054b526b32SVenkata Prasad Potturu struct snd_soc_dapm_context *dapm = w->dapm;
11064b526b32SVenkata Prasad Potturu struct snd_soc_card *card = dapm->card;
11074b526b32SVenkata Prasad Potturu struct snd_soc_dai *codec_dai;
11084b526b32SVenkata Prasad Potturu int ret = 0;
11094b526b32SVenkata Prasad Potturu
11104b526b32SVenkata Prasad Potturu codec_dai = snd_soc_card_get_codec_dai(card, NAU8821_CODEC_DAI);
11114b526b32SVenkata Prasad Potturu if (!codec_dai) {
11124b526b32SVenkata Prasad Potturu dev_err(card->dev, "Codec dai not found\n");
11134b526b32SVenkata Prasad Potturu return -EIO;
11144b526b32SVenkata Prasad Potturu }
11154b526b32SVenkata Prasad Potturu
11164b526b32SVenkata Prasad Potturu if (SND_SOC_DAPM_EVENT_OFF(event)) {
11174b526b32SVenkata Prasad Potturu ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_INTERNAL,
11184b526b32SVenkata Prasad Potturu 0, SND_SOC_CLOCK_IN);
11194b526b32SVenkata Prasad Potturu if (ret < 0) {
11204b526b32SVenkata Prasad Potturu dev_err(card->dev, "set sysclk err = %d\n", ret);
11214b526b32SVenkata Prasad Potturu return -EIO;
11224b526b32SVenkata Prasad Potturu }
11234b526b32SVenkata Prasad Potturu } else {
11244b526b32SVenkata Prasad Potturu ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_FLL_BLK, 0,
11254b526b32SVenkata Prasad Potturu SND_SOC_CLOCK_IN);
11264b526b32SVenkata Prasad Potturu if (ret < 0)
11274b526b32SVenkata Prasad Potturu dev_err(codec_dai->dev, "can't set FS clock %d\n", ret);
11284b526b32SVenkata Prasad Potturu ret = snd_soc_dai_set_pll(codec_dai, 0, 0, NAU8821_BCLK,
11294b526b32SVenkata Prasad Potturu NAU8821_FREQ_OUT);
11304b526b32SVenkata Prasad Potturu if (ret < 0)
11314b526b32SVenkata Prasad Potturu dev_err(codec_dai->dev, "can't set FLL: %d\n", ret);
11324b526b32SVenkata Prasad Potturu }
11334b526b32SVenkata Prasad Potturu return ret;
11344b526b32SVenkata Prasad Potturu }
11354b526b32SVenkata Prasad Potturu
11367ac3404cSAlper Nebi Yasak static struct snd_soc_jack nau8821_jack;
11377ac3404cSAlper Nebi Yasak static struct snd_soc_jack_pin nau8821_jack_pins[] = {
11387ac3404cSAlper Nebi Yasak {
11397ac3404cSAlper Nebi Yasak .pin = "Headphone Jack",
11407ac3404cSAlper Nebi Yasak .mask = SND_JACK_HEADPHONE,
11417ac3404cSAlper Nebi Yasak },
11427ac3404cSAlper Nebi Yasak {
11437ac3404cSAlper Nebi Yasak .pin = "Headset Mic",
11447ac3404cSAlper Nebi Yasak .mask = SND_JACK_MICROPHONE,
11457ac3404cSAlper Nebi Yasak },
11467ac3404cSAlper Nebi Yasak };
11477ac3404cSAlper Nebi Yasak
11487ac3404cSAlper Nebi Yasak static const struct snd_kcontrol_new nau8821_controls[] = {
11497ac3404cSAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Headphone Jack"),
11507ac3404cSAlper Nebi Yasak SOC_DAPM_PIN_SWITCH("Headset Mic"),
11517ac3404cSAlper Nebi Yasak };
11527ac3404cSAlper Nebi Yasak
11534b526b32SVenkata Prasad Potturu static const struct snd_soc_dapm_widget nau8821_widgets[] = {
11547ac3404cSAlper Nebi Yasak SND_SOC_DAPM_HP("Headphone Jack", NULL),
11554b526b32SVenkata Prasad Potturu SND_SOC_DAPM_MIC("Headset Mic", NULL),
11564b526b32SVenkata Prasad Potturu SND_SOC_DAPM_MIC("Int Mic", NULL),
11574b526b32SVenkata Prasad Potturu SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
11584b526b32SVenkata Prasad Potturu platform_clock_control, SND_SOC_DAPM_PRE_PMU |
11594b526b32SVenkata Prasad Potturu SND_SOC_DAPM_POST_PMD),
11604b526b32SVenkata Prasad Potturu };
11614b526b32SVenkata Prasad Potturu
11624b526b32SVenkata Prasad Potturu static const struct snd_soc_dapm_route nau8821_audio_route[] = {
11634b526b32SVenkata Prasad Potturu /* HP jack connectors - unknown if we have jack detection */
11647ac3404cSAlper Nebi Yasak { "Headphone Jack", NULL, "HPOL" },
11657ac3404cSAlper Nebi Yasak { "Headphone Jack", NULL, "HPOR" },
11664b526b32SVenkata Prasad Potturu { "MICL", NULL, "Headset Mic" },
11674b526b32SVenkata Prasad Potturu { "MICR", NULL, "Headset Mic" },
11684b526b32SVenkata Prasad Potturu { "DMIC", NULL, "Int Mic" },
11697ac3404cSAlper Nebi Yasak { "Headphone Jack", NULL, "Platform Clock" },
11704b526b32SVenkata Prasad Potturu { "Headset Mic", NULL, "Platform Clock" },
11714b526b32SVenkata Prasad Potturu { "Int Mic", NULL, "Platform Clock" },
11724b526b32SVenkata Prasad Potturu };
11734b526b32SVenkata Prasad Potturu
11744b526b32SVenkata Prasad Potturu static const unsigned int nau8821_format[] = {16};
11754b526b32SVenkata Prasad Potturu
11764b526b32SVenkata Prasad Potturu static struct snd_pcm_hw_constraint_list constraints_sample_bits = {
11774b526b32SVenkata Prasad Potturu .list = nau8821_format,
11784b526b32SVenkata Prasad Potturu .count = ARRAY_SIZE(nau8821_format),
11794b526b32SVenkata Prasad Potturu };
11804b526b32SVenkata Prasad Potturu
acp_8821_init(struct snd_soc_pcm_runtime * rtd)11814b526b32SVenkata Prasad Potturu static int acp_8821_init(struct snd_soc_pcm_runtime *rtd)
11824b526b32SVenkata Prasad Potturu {
11834b526b32SVenkata Prasad Potturu struct snd_soc_card *card = rtd->card;
1184d4f23dcdSKuninori Morimoto struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
11854b526b32SVenkata Prasad Potturu struct snd_soc_component *component = codec_dai->component;
11864b526b32SVenkata Prasad Potturu int ret;
11874b526b32SVenkata Prasad Potturu
11884b526b32SVenkata Prasad Potturu dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
11894b526b32SVenkata Prasad Potturu
11904b526b32SVenkata Prasad Potturu ret = snd_soc_dapm_new_controls(&card->dapm, nau8821_widgets,
11914b526b32SVenkata Prasad Potturu ARRAY_SIZE(nau8821_widgets));
11924b526b32SVenkata Prasad Potturu if (ret) {
11934b526b32SVenkata Prasad Potturu dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
11944b526b32SVenkata Prasad Potturu // Don't need to add routes if widget addition failed
11954b526b32SVenkata Prasad Potturu return ret;
11964b526b32SVenkata Prasad Potturu }
11974b526b32SVenkata Prasad Potturu
11987ac3404cSAlper Nebi Yasak ret = snd_soc_add_card_controls(card, nau8821_controls,
11997ac3404cSAlper Nebi Yasak ARRAY_SIZE(nau8821_controls));
12007ac3404cSAlper Nebi Yasak if (ret) {
12017ac3404cSAlper Nebi Yasak dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
12027ac3404cSAlper Nebi Yasak return ret;
12037ac3404cSAlper Nebi Yasak }
12047ac3404cSAlper Nebi Yasak
12057ac3404cSAlper Nebi Yasak ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
12064b526b32SVenkata Prasad Potturu SND_JACK_HEADSET | SND_JACK_LINEOUT |
12074b526b32SVenkata Prasad Potturu SND_JACK_BTN_0 | SND_JACK_BTN_1 |
12084b526b32SVenkata Prasad Potturu SND_JACK_BTN_2 | SND_JACK_BTN_3,
12097ac3404cSAlper Nebi Yasak &nau8821_jack,
12107ac3404cSAlper Nebi Yasak nau8821_jack_pins,
12117ac3404cSAlper Nebi Yasak ARRAY_SIZE(nau8821_jack_pins));
12124b526b32SVenkata Prasad Potturu if (ret) {
12134b526b32SVenkata Prasad Potturu dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
12144b526b32SVenkata Prasad Potturu return ret;
12154b526b32SVenkata Prasad Potturu }
12164b526b32SVenkata Prasad Potturu
12177ac3404cSAlper Nebi Yasak snd_jack_set_key(nau8821_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
12187ac3404cSAlper Nebi Yasak snd_jack_set_key(nau8821_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
12197ac3404cSAlper Nebi Yasak snd_jack_set_key(nau8821_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
12207ac3404cSAlper Nebi Yasak snd_jack_set_key(nau8821_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
12217ac3404cSAlper Nebi Yasak
12227ac3404cSAlper Nebi Yasak nau8821_enable_jack_detect(component, &nau8821_jack);
12234b526b32SVenkata Prasad Potturu
12244b526b32SVenkata Prasad Potturu return snd_soc_dapm_add_routes(&rtd->card->dapm, nau8821_audio_route,
12254b526b32SVenkata Prasad Potturu ARRAY_SIZE(nau8821_audio_route));
12264b526b32SVenkata Prasad Potturu }
12274b526b32SVenkata Prasad Potturu
acp_8821_startup(struct snd_pcm_substream * substream)12284b526b32SVenkata Prasad Potturu static int acp_8821_startup(struct snd_pcm_substream *substream)
12294b526b32SVenkata Prasad Potturu {
12304b526b32SVenkata Prasad Potturu struct snd_pcm_runtime *runtime = substream->runtime;
12314b526b32SVenkata Prasad Potturu
12324b526b32SVenkata Prasad Potturu runtime->hw.channels_max = DUAL_CHANNEL;
12334b526b32SVenkata Prasad Potturu snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
12344b526b32SVenkata Prasad Potturu &constraints_channels);
12354b526b32SVenkata Prasad Potturu snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
12364b526b32SVenkata Prasad Potturu &constraints_rates);
12374b526b32SVenkata Prasad Potturu snd_pcm_hw_constraint_list(substream->runtime, 0,
12384b526b32SVenkata Prasad Potturu SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
12394b526b32SVenkata Prasad Potturu &constraints_sample_bits);
12404b526b32SVenkata Prasad Potturu return 0;
12414b526b32SVenkata Prasad Potturu }
12424b526b32SVenkata Prasad Potturu
acp_nau8821_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)12434b526b32SVenkata Prasad Potturu static int acp_nau8821_hw_params(struct snd_pcm_substream *substream,
12444b526b32SVenkata Prasad Potturu struct snd_pcm_hw_params *params)
12454b526b32SVenkata Prasad Potturu {
1246d4f23dcdSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
12474b526b32SVenkata Prasad Potturu struct snd_soc_card *card = rtd->card;
12484b526b32SVenkata Prasad Potturu struct acp_card_drvdata *drvdata = card->drvdata;
1249d4f23dcdSKuninori Morimoto struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
12504b526b32SVenkata Prasad Potturu int ret;
12514b526b32SVenkata Prasad Potturu unsigned int fmt;
12524b526b32SVenkata Prasad Potturu
12534b526b32SVenkata Prasad Potturu if (drvdata->soc_mclk)
12544b526b32SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
12554b526b32SVenkata Prasad Potturu else
12564b526b32SVenkata Prasad Potturu fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
12574b526b32SVenkata Prasad Potturu
12584b526b32SVenkata Prasad Potturu ret = snd_soc_dai_set_fmt(codec_dai, fmt);
12594b526b32SVenkata Prasad Potturu if (ret < 0) {
12604b526b32SVenkata Prasad Potturu dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
12614b526b32SVenkata Prasad Potturu return ret;
12624b526b32SVenkata Prasad Potturu }
12634b526b32SVenkata Prasad Potturu
12644b526b32SVenkata Prasad Potturu ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_FLL_BLK, 0,
12654b526b32SVenkata Prasad Potturu SND_SOC_CLOCK_IN);
12664b526b32SVenkata Prasad Potturu if (ret < 0)
12674b526b32SVenkata Prasad Potturu dev_err(card->dev, "can't set FS clock %d\n", ret);
12684b526b32SVenkata Prasad Potturu ret = snd_soc_dai_set_pll(codec_dai, 0, 0, snd_soc_params_to_bclk(params),
12694b526b32SVenkata Prasad Potturu params_rate(params) * 256);
12704b526b32SVenkata Prasad Potturu if (ret < 0)
12714b526b32SVenkata Prasad Potturu dev_err(card->dev, "can't set FLL: %d\n", ret);
12724b526b32SVenkata Prasad Potturu
12734b526b32SVenkata Prasad Potturu return ret;
12744b526b32SVenkata Prasad Potturu }
12754b526b32SVenkata Prasad Potturu
12764b526b32SVenkata Prasad Potturu static const struct snd_soc_ops acp_8821_ops = {
12774b526b32SVenkata Prasad Potturu .startup = acp_8821_startup,
12784b526b32SVenkata Prasad Potturu .hw_params = acp_nau8821_hw_params,
12794b526b32SVenkata Prasad Potturu };
12804b526b32SVenkata Prasad Potturu
12814b526b32SVenkata Prasad Potturu SND_SOC_DAILINK_DEF(nau8821,
12824b526b32SVenkata Prasad Potturu DAILINK_COMP_ARRAY(COMP_CODEC("i2c-NVTN2020:00",
128368ab2942SCristian Ciocaltea NAU8821_CODEC_DAI)));
12844b526b32SVenkata Prasad Potturu
1285d4c750f2SAjit Kumar Pandey /* Declare DMIC codec components */
1286d4c750f2SAjit Kumar Pandey SND_SOC_DAILINK_DEF(dmic_codec,
1287d4c750f2SAjit Kumar Pandey DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
1288d4c750f2SAjit Kumar Pandey
1289d4c750f2SAjit Kumar Pandey /* Declare ACP CPU components */
1290d4c750f2SAjit Kumar Pandey static struct snd_soc_dai_link_component platform_component[] = {
1291d4c750f2SAjit Kumar Pandey {
1292d4c750f2SAjit Kumar Pandey .name = "acp_asoc_renoir.0",
1293d4c750f2SAjit Kumar Pandey }
1294d4c750f2SAjit Kumar Pandey };
1295d4c750f2SAjit Kumar Pandey
1296e8a33a94SV sujith kumar Reddy static struct snd_soc_dai_link_component platform_rmb_component[] = {
1297e8a33a94SV sujith kumar Reddy {
1298e8a33a94SV sujith kumar Reddy .name = "acp_asoc_rembrandt.0",
1299e8a33a94SV sujith kumar Reddy }
1300e8a33a94SV sujith kumar Reddy };
1301e8a33a94SV sujith kumar Reddy
13029393bfb4SSyed Saba Kareem static struct snd_soc_dai_link_component platform_acp63_component[] = {
13039393bfb4SSyed Saba Kareem {
13049393bfb4SSyed Saba Kareem .name = "acp_asoc_acp63.0",
13059393bfb4SSyed Saba Kareem }
13069393bfb4SSyed Saba Kareem };
13079393bfb4SSyed Saba Kareem
1308b97f4dacSSyed Saba Kareem static struct snd_soc_dai_link_component platform_acp70_component[] = {
1309b97f4dacSSyed Saba Kareem {
1310b97f4dacSSyed Saba Kareem .name = "acp_asoc_acp70.0",
1311b97f4dacSSyed Saba Kareem }
1312b97f4dacSSyed Saba Kareem };
1313b97f4dacSSyed Saba Kareem
1314d4c750f2SAjit Kumar Pandey static struct snd_soc_dai_link_component sof_component[] = {
1315d4c750f2SAjit Kumar Pandey {
1316d4c750f2SAjit Kumar Pandey .name = "0000:04:00.5",
1317d4c750f2SAjit Kumar Pandey }
1318d4c750f2SAjit Kumar Pandey };
1319d4c750f2SAjit Kumar Pandey
1320d4c750f2SAjit Kumar Pandey SND_SOC_DAILINK_DEF(i2s_sp,
1321d4c750f2SAjit Kumar Pandey DAILINK_COMP_ARRAY(COMP_CPU("acp-i2s-sp")));
1322e8a33a94SV sujith kumar Reddy SND_SOC_DAILINK_DEF(i2s_hs,
1323e8a33a94SV sujith kumar Reddy DAILINK_COMP_ARRAY(COMP_CPU("acp-i2s-hs")));
1324d4c750f2SAjit Kumar Pandey SND_SOC_DAILINK_DEF(sof_sp,
1325d4c750f2SAjit Kumar Pandey DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-sp")));
1326099b923fSVenkata Prasad Potturu SND_SOC_DAILINK_DEF(sof_sp_virtual,
1327099b923fSVenkata Prasad Potturu DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-sp-virtual")));
13280439eb4dSV sujith kumar Reddy SND_SOC_DAILINK_DEF(sof_hs,
13290439eb4dSV sujith kumar Reddy DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-hs")));
1330099b923fSVenkata Prasad Potturu SND_SOC_DAILINK_DEF(sof_hs_virtual,
1331099b923fSVenkata Prasad Potturu DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-hs-virtual")));
1332671dd2ffSVenkata Prasad Potturu SND_SOC_DAILINK_DEF(sof_bt,
1333671dd2ffSVenkata Prasad Potturu DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-bt")));
1334d4c750f2SAjit Kumar Pandey SND_SOC_DAILINK_DEF(sof_dmic,
1335d4c750f2SAjit Kumar Pandey DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-dmic")));
1336611ba05eSAjit Kumar Pandey SND_SOC_DAILINK_DEF(pdm_dmic,
1337611ba05eSAjit Kumar Pandey DAILINK_COMP_ARRAY(COMP_CPU("acp-pdm-dmic")));
1338d4c750f2SAjit Kumar Pandey
acp_rtk_set_bias_level(struct snd_soc_card * card,struct snd_soc_dapm_context * dapm,enum snd_soc_bias_level level)13399e693e81SVenkata Prasad Potturu static int acp_rtk_set_bias_level(struct snd_soc_card *card,
13409e693e81SVenkata Prasad Potturu struct snd_soc_dapm_context *dapm,
13419e693e81SVenkata Prasad Potturu enum snd_soc_bias_level level)
13429e693e81SVenkata Prasad Potturu {
13439e693e81SVenkata Prasad Potturu struct snd_soc_component *component = dapm->component;
13449e693e81SVenkata Prasad Potturu struct acp_card_drvdata *drvdata = card->drvdata;
13459e693e81SVenkata Prasad Potturu int ret = 0;
13469e693e81SVenkata Prasad Potturu
13479e693e81SVenkata Prasad Potturu if (!component)
13489e693e81SVenkata Prasad Potturu return 0;
13499e693e81SVenkata Prasad Potturu
13509e693e81SVenkata Prasad Potturu if (strncmp(component->name, "i2c-RTL5682", 11) &&
13519e693e81SVenkata Prasad Potturu strncmp(component->name, "i2c-10EC1019", 12))
13529e693e81SVenkata Prasad Potturu return 0;
13539e693e81SVenkata Prasad Potturu
13549e693e81SVenkata Prasad Potturu /*
13559e693e81SVenkata Prasad Potturu * For Realtek's codec and amplifier components,
13569e693e81SVenkata Prasad Potturu * the lrck and bclk must be enabled brfore their all dapms be powered on,
13579e693e81SVenkata Prasad Potturu * and must be disabled after their all dapms be powered down
13589e693e81SVenkata Prasad Potturu * to avoid any pop.
13599e693e81SVenkata Prasad Potturu */
13609e693e81SVenkata Prasad Potturu switch (level) {
13619e693e81SVenkata Prasad Potturu case SND_SOC_BIAS_STANDBY:
13629e693e81SVenkata Prasad Potturu if (snd_soc_dapm_get_bias_level(dapm) == SND_SOC_BIAS_OFF) {
13639e693e81SVenkata Prasad Potturu
13649e693e81SVenkata Prasad Potturu /* Increase bclk's enable_count */
13659e693e81SVenkata Prasad Potturu ret = clk_prepare_enable(drvdata->bclk);
13669e693e81SVenkata Prasad Potturu if (ret < 0)
13679e693e81SVenkata Prasad Potturu dev_err(component->dev, "Failed to enable bclk %d\n", ret);
13689e693e81SVenkata Prasad Potturu } else {
13699e693e81SVenkata Prasad Potturu /*
13709e693e81SVenkata Prasad Potturu * Decrease bclk's enable_count.
13719e693e81SVenkata Prasad Potturu * While the enable_count is 0, the bclk would be closed.
13729e693e81SVenkata Prasad Potturu */
13739e693e81SVenkata Prasad Potturu clk_disable_unprepare(drvdata->bclk);
13749e693e81SVenkata Prasad Potturu }
13759e693e81SVenkata Prasad Potturu break;
13769e693e81SVenkata Prasad Potturu default:
13779e693e81SVenkata Prasad Potturu break;
13789e693e81SVenkata Prasad Potturu }
13799e693e81SVenkata Prasad Potturu
13809e693e81SVenkata Prasad Potturu return ret;
13819e693e81SVenkata Prasad Potturu }
13829e693e81SVenkata Prasad Potturu
acp_sofdsp_dai_links_create(struct snd_soc_card * card)1383d4c750f2SAjit Kumar Pandey int acp_sofdsp_dai_links_create(struct snd_soc_card *card)
1384d4c750f2SAjit Kumar Pandey {
1385d4c750f2SAjit Kumar Pandey struct snd_soc_dai_link *links;
1386d4c750f2SAjit Kumar Pandey struct device *dev = card->dev;
1387d4c750f2SAjit Kumar Pandey struct acp_card_drvdata *drv_data = card->drvdata;
1388d4c750f2SAjit Kumar Pandey int i = 0, num_links = 0;
1389d4c750f2SAjit Kumar Pandey
1390d4c750f2SAjit Kumar Pandey if (drv_data->hs_cpu_id)
1391d4c750f2SAjit Kumar Pandey num_links++;
1392671dd2ffSVenkata Prasad Potturu if (drv_data->bt_cpu_id)
1393671dd2ffSVenkata Prasad Potturu num_links++;
1394d4c750f2SAjit Kumar Pandey if (drv_data->amp_cpu_id)
1395d4c750f2SAjit Kumar Pandey num_links++;
1396d4c750f2SAjit Kumar Pandey if (drv_data->dmic_cpu_id)
1397d4c750f2SAjit Kumar Pandey num_links++;
1398d4c750f2SAjit Kumar Pandey
1399f047199eSye xingchen links = devm_kcalloc(dev, num_links, sizeof(struct snd_soc_dai_link), GFP_KERNEL);
1400d4c750f2SAjit Kumar Pandey if (!links)
1401d4c750f2SAjit Kumar Pandey return -ENOMEM;
1402d4c750f2SAjit Kumar Pandey
1403d4c750f2SAjit Kumar Pandey if (drv_data->hs_cpu_id == I2S_SP) {
1404d4c750f2SAjit Kumar Pandey links[i].name = "acp-headset-codec";
1405d4c750f2SAjit Kumar Pandey links[i].id = HEADSET_BE_ID;
1406d4c750f2SAjit Kumar Pandey links[i].cpus = sof_sp;
1407d4c750f2SAjit Kumar Pandey links[i].num_cpus = ARRAY_SIZE(sof_sp);
1408d4c750f2SAjit Kumar Pandey links[i].platforms = sof_component;
1409d4c750f2SAjit Kumar Pandey links[i].num_platforms = ARRAY_SIZE(sof_component);
1410d4c750f2SAjit Kumar Pandey links[i].dpcm_playback = 1;
1411d4c750f2SAjit Kumar Pandey links[i].dpcm_capture = 1;
1412d4c750f2SAjit Kumar Pandey links[i].nonatomic = true;
1413d4c750f2SAjit Kumar Pandey links[i].no_pcm = 1;
1414d4c750f2SAjit Kumar Pandey if (!drv_data->hs_codec_id) {
1415d4c750f2SAjit Kumar Pandey /* Use dummy codec if codec id not specified */
1416d4f23dcdSKuninori Morimoto links[i].codecs = &snd_soc_dummy_dlc;
141742e0861dSKuninori Morimoto links[i].num_codecs = 1;
1418d4c750f2SAjit Kumar Pandey }
1419d4c750f2SAjit Kumar Pandey if (drv_data->hs_codec_id == RT5682) {
1420d4c750f2SAjit Kumar Pandey links[i].codecs = rt5682;
1421d4c750f2SAjit Kumar Pandey links[i].num_codecs = ARRAY_SIZE(rt5682);
1422d4c750f2SAjit Kumar Pandey links[i].init = acp_card_rt5682_init;
1423d4c750f2SAjit Kumar Pandey links[i].ops = &acp_card_rt5682_ops;
1424d4c750f2SAjit Kumar Pandey }
14258b725626SAjit Kumar Pandey if (drv_data->hs_codec_id == RT5682S) {
14268b725626SAjit Kumar Pandey links[i].codecs = rt5682s;
14278b725626SAjit Kumar Pandey links[i].num_codecs = ARRAY_SIZE(rt5682s);
14288b725626SAjit Kumar Pandey links[i].init = acp_card_rt5682s_init;
14298b725626SAjit Kumar Pandey links[i].ops = &acp_card_rt5682s_ops;
14308b725626SAjit Kumar Pandey }
14314b526b32SVenkata Prasad Potturu if (drv_data->hs_codec_id == NAU8821) {
14324b526b32SVenkata Prasad Potturu links[i].codecs = nau8821;
14334b526b32SVenkata Prasad Potturu links[i].num_codecs = ARRAY_SIZE(nau8821);
14344b526b32SVenkata Prasad Potturu links[i].init = acp_8821_init;
14354b526b32SVenkata Prasad Potturu links[i].ops = &acp_8821_ops;
14364b526b32SVenkata Prasad Potturu }
1437d4c750f2SAjit Kumar Pandey i++;
1438d4c750f2SAjit Kumar Pandey }
1439d4c750f2SAjit Kumar Pandey
14400439eb4dSV sujith kumar Reddy if (drv_data->hs_cpu_id == I2S_HS) {
14410439eb4dSV sujith kumar Reddy links[i].name = "acp-headset-codec";
14420439eb4dSV sujith kumar Reddy links[i].id = HEADSET_BE_ID;
14430439eb4dSV sujith kumar Reddy links[i].cpus = sof_hs;
14440439eb4dSV sujith kumar Reddy links[i].num_cpus = ARRAY_SIZE(sof_hs);
14450439eb4dSV sujith kumar Reddy links[i].platforms = sof_component;
14460439eb4dSV sujith kumar Reddy links[i].num_platforms = ARRAY_SIZE(sof_component);
14470439eb4dSV sujith kumar Reddy links[i].dpcm_playback = 1;
14480439eb4dSV sujith kumar Reddy links[i].dpcm_capture = 1;
14490439eb4dSV sujith kumar Reddy links[i].nonatomic = true;
14500439eb4dSV sujith kumar Reddy links[i].no_pcm = 1;
14510439eb4dSV sujith kumar Reddy if (!drv_data->hs_codec_id) {
14520439eb4dSV sujith kumar Reddy /* Use dummy codec if codec id not specified */
1453d4f23dcdSKuninori Morimoto links[i].codecs = &snd_soc_dummy_dlc;
145442e0861dSKuninori Morimoto links[i].num_codecs = 1;
14550439eb4dSV sujith kumar Reddy }
14560439eb4dSV sujith kumar Reddy if (drv_data->hs_codec_id == NAU8825) {
14570439eb4dSV sujith kumar Reddy links[i].codecs = nau8825;
14580439eb4dSV sujith kumar Reddy links[i].num_codecs = ARRAY_SIZE(nau8825);
14590439eb4dSV sujith kumar Reddy links[i].init = acp_card_nau8825_init;
14600439eb4dSV sujith kumar Reddy links[i].ops = &acp_card_nau8825_ops;
14610439eb4dSV sujith kumar Reddy }
14624dc6737cSV sujith kumar Reddy if (drv_data->hs_codec_id == RT5682S) {
14634dc6737cSV sujith kumar Reddy links[i].codecs = rt5682s;
14644dc6737cSV sujith kumar Reddy links[i].num_codecs = ARRAY_SIZE(rt5682s);
14654dc6737cSV sujith kumar Reddy links[i].init = acp_card_rt5682s_init;
14664dc6737cSV sujith kumar Reddy links[i].ops = &acp_card_rt5682s_ops;
14674dc6737cSV sujith kumar Reddy }
14680439eb4dSV sujith kumar Reddy i++;
14690439eb4dSV sujith kumar Reddy }
14700439eb4dSV sujith kumar Reddy
1471d4c750f2SAjit Kumar Pandey if (drv_data->amp_cpu_id == I2S_SP) {
1472d4c750f2SAjit Kumar Pandey links[i].name = "acp-amp-codec";
1473d4c750f2SAjit Kumar Pandey links[i].id = AMP_BE_ID;
14746cc2aa9aSVenkata Prasad Potturu if (drv_data->platform == RENOIR) {
14756cc2aa9aSVenkata Prasad Potturu links[i].cpus = sof_sp;
14766cc2aa9aSVenkata Prasad Potturu links[i].num_cpus = ARRAY_SIZE(sof_sp);
14776cc2aa9aSVenkata Prasad Potturu } else {
1478099b923fSVenkata Prasad Potturu links[i].cpus = sof_sp_virtual;
1479099b923fSVenkata Prasad Potturu links[i].num_cpus = ARRAY_SIZE(sof_sp_virtual);
14806cc2aa9aSVenkata Prasad Potturu }
1481d4c750f2SAjit Kumar Pandey links[i].platforms = sof_component;
1482d4c750f2SAjit Kumar Pandey links[i].num_platforms = ARRAY_SIZE(sof_component);
1483d4c750f2SAjit Kumar Pandey links[i].dpcm_playback = 1;
1484d4c750f2SAjit Kumar Pandey links[i].nonatomic = true;
1485d4c750f2SAjit Kumar Pandey links[i].no_pcm = 1;
1486d4c750f2SAjit Kumar Pandey if (!drv_data->amp_codec_id) {
1487d4c750f2SAjit Kumar Pandey /* Use dummy codec if codec id not specified */
1488d4f23dcdSKuninori Morimoto links[i].codecs = &snd_soc_dummy_dlc;
148942e0861dSKuninori Morimoto links[i].num_codecs = 1;
1490d4c750f2SAjit Kumar Pandey }
1491d4c750f2SAjit Kumar Pandey if (drv_data->amp_codec_id == RT1019) {
1492d4c750f2SAjit Kumar Pandey links[i].codecs = rt1019;
1493d4c750f2SAjit Kumar Pandey links[i].num_codecs = ARRAY_SIZE(rt1019);
1494d4c750f2SAjit Kumar Pandey links[i].ops = &acp_card_rt1019_ops;
1495d4c750f2SAjit Kumar Pandey links[i].init = acp_card_rt1019_init;
1496d4c750f2SAjit Kumar Pandey card->codec_conf = rt1019_conf;
1497d4c750f2SAjit Kumar Pandey card->num_configs = ARRAY_SIZE(rt1019_conf);
1498d4c750f2SAjit Kumar Pandey }
1499cabc3aceSAjit Kumar Pandey if (drv_data->amp_codec_id == MAX98360A) {
1500cabc3aceSAjit Kumar Pandey links[i].codecs = max98360a;
1501cabc3aceSAjit Kumar Pandey links[i].num_codecs = ARRAY_SIZE(max98360a);
1502cabc3aceSAjit Kumar Pandey links[i].ops = &acp_card_maxim_ops;
1503cabc3aceSAjit Kumar Pandey links[i].init = acp_card_maxim_init;
1504cabc3aceSAjit Kumar Pandey }
1505d4c750f2SAjit Kumar Pandey i++;
1506d4c750f2SAjit Kumar Pandey }
1507d4c750f2SAjit Kumar Pandey
15080439eb4dSV sujith kumar Reddy if (drv_data->amp_cpu_id == I2S_HS) {
15090439eb4dSV sujith kumar Reddy links[i].name = "acp-amp-codec";
15100439eb4dSV sujith kumar Reddy links[i].id = AMP_BE_ID;
1511099b923fSVenkata Prasad Potturu links[i].cpus = sof_hs_virtual;
1512099b923fSVenkata Prasad Potturu links[i].num_cpus = ARRAY_SIZE(sof_hs_virtual);
15130439eb4dSV sujith kumar Reddy links[i].platforms = sof_component;
15140439eb4dSV sujith kumar Reddy links[i].num_platforms = ARRAY_SIZE(sof_component);
15150439eb4dSV sujith kumar Reddy links[i].dpcm_playback = 1;
15160439eb4dSV sujith kumar Reddy links[i].nonatomic = true;
15170439eb4dSV sujith kumar Reddy links[i].no_pcm = 1;
15180439eb4dSV sujith kumar Reddy if (!drv_data->amp_codec_id) {
15190439eb4dSV sujith kumar Reddy /* Use dummy codec if codec id not specified */
1520d4f23dcdSKuninori Morimoto links[i].codecs = &snd_soc_dummy_dlc;
152142e0861dSKuninori Morimoto links[i].num_codecs = 1;
15220439eb4dSV sujith kumar Reddy }
15230439eb4dSV sujith kumar Reddy if (drv_data->amp_codec_id == MAX98360A) {
15240439eb4dSV sujith kumar Reddy links[i].codecs = max98360a;
15250439eb4dSV sujith kumar Reddy links[i].num_codecs = ARRAY_SIZE(max98360a);
15260439eb4dSV sujith kumar Reddy links[i].ops = &acp_card_maxim_ops;
15270439eb4dSV sujith kumar Reddy links[i].init = acp_card_maxim_init;
15280439eb4dSV sujith kumar Reddy }
1529ac91c8c8SVenkata Prasad Potturu if (drv_data->amp_codec_id == MAX98388) {
1530e249839bSVenkata Prasad Potturu links[i].dpcm_capture = 1;
1531ac91c8c8SVenkata Prasad Potturu links[i].codecs = max98388;
1532ac91c8c8SVenkata Prasad Potturu links[i].num_codecs = ARRAY_SIZE(max98388);
1533ac91c8c8SVenkata Prasad Potturu links[i].ops = &acp_max98388_ops;
1534ac91c8c8SVenkata Prasad Potturu links[i].init = acp_card_max98388_init;
1535ac91c8c8SVenkata Prasad Potturu card->codec_conf = max98388_conf;
1536ac91c8c8SVenkata Prasad Potturu card->num_configs = ARRAY_SIZE(max98388_conf);
1537ac91c8c8SVenkata Prasad Potturu }
15384dc6737cSV sujith kumar Reddy if (drv_data->amp_codec_id == RT1019) {
15394dc6737cSV sujith kumar Reddy links[i].codecs = rt1019;
15404dc6737cSV sujith kumar Reddy links[i].num_codecs = ARRAY_SIZE(rt1019);
15414dc6737cSV sujith kumar Reddy links[i].ops = &acp_card_rt1019_ops;
15424dc6737cSV sujith kumar Reddy links[i].init = acp_card_rt1019_init;
15434dc6737cSV sujith kumar Reddy card->codec_conf = rt1019_conf;
15444dc6737cSV sujith kumar Reddy card->num_configs = ARRAY_SIZE(rt1019_conf);
15454dc6737cSV sujith kumar Reddy }
15460439eb4dSV sujith kumar Reddy i++;
15470439eb4dSV sujith kumar Reddy }
15480439eb4dSV sujith kumar Reddy
1549671dd2ffSVenkata Prasad Potturu if (drv_data->bt_cpu_id == I2S_BT) {
1550671dd2ffSVenkata Prasad Potturu links[i].name = "acp-bt-codec";
1551671dd2ffSVenkata Prasad Potturu links[i].id = BT_BE_ID;
1552671dd2ffSVenkata Prasad Potturu links[i].cpus = sof_bt;
1553671dd2ffSVenkata Prasad Potturu links[i].num_cpus = ARRAY_SIZE(sof_bt);
1554671dd2ffSVenkata Prasad Potturu links[i].platforms = sof_component;
1555671dd2ffSVenkata Prasad Potturu links[i].num_platforms = ARRAY_SIZE(sof_component);
1556671dd2ffSVenkata Prasad Potturu links[i].dpcm_playback = 1;
1557671dd2ffSVenkata Prasad Potturu links[i].dpcm_capture = 1;
1558671dd2ffSVenkata Prasad Potturu links[i].nonatomic = true;
1559671dd2ffSVenkata Prasad Potturu links[i].no_pcm = 1;
1560671dd2ffSVenkata Prasad Potturu if (!drv_data->bt_codec_id) {
1561671dd2ffSVenkata Prasad Potturu /* Use dummy codec if codec id not specified */
1562671dd2ffSVenkata Prasad Potturu links[i].codecs = &snd_soc_dummy_dlc;
1563671dd2ffSVenkata Prasad Potturu links[i].num_codecs = 1;
1564671dd2ffSVenkata Prasad Potturu }
1565671dd2ffSVenkata Prasad Potturu i++;
1566671dd2ffSVenkata Prasad Potturu }
1567671dd2ffSVenkata Prasad Potturu
1568d4c750f2SAjit Kumar Pandey if (drv_data->dmic_cpu_id == DMIC) {
1569d4c750f2SAjit Kumar Pandey links[i].name = "acp-dmic-codec";
1570d4c750f2SAjit Kumar Pandey links[i].id = DMIC_BE_ID;
1571d4c750f2SAjit Kumar Pandey links[i].codecs = dmic_codec;
1572d4c750f2SAjit Kumar Pandey links[i].num_codecs = ARRAY_SIZE(dmic_codec);
1573d4c750f2SAjit Kumar Pandey links[i].cpus = sof_dmic;
1574d4c750f2SAjit Kumar Pandey links[i].num_cpus = ARRAY_SIZE(sof_dmic);
1575d4c750f2SAjit Kumar Pandey links[i].platforms = sof_component;
1576d4c750f2SAjit Kumar Pandey links[i].num_platforms = ARRAY_SIZE(sof_component);
1577d4c750f2SAjit Kumar Pandey links[i].dpcm_capture = 1;
1578d4c750f2SAjit Kumar Pandey links[i].nonatomic = true;
1579d4c750f2SAjit Kumar Pandey links[i].no_pcm = 1;
1580d4c750f2SAjit Kumar Pandey }
1581d4c750f2SAjit Kumar Pandey
1582d4c750f2SAjit Kumar Pandey card->dai_link = links;
1583d4c750f2SAjit Kumar Pandey card->num_links = num_links;
15849e693e81SVenkata Prasad Potturu card->set_bias_level = acp_rtk_set_bias_level;
1585d4c750f2SAjit Kumar Pandey
1586d4c750f2SAjit Kumar Pandey return 0;
1587d4c750f2SAjit Kumar Pandey }
1588d4c750f2SAjit Kumar Pandey EXPORT_SYMBOL_NS_GPL(acp_sofdsp_dai_links_create, SND_SOC_AMD_MACH);
1589d4c750f2SAjit Kumar Pandey
acp_legacy_dai_links_create(struct snd_soc_card * card)1590d4c750f2SAjit Kumar Pandey int acp_legacy_dai_links_create(struct snd_soc_card *card)
1591d4c750f2SAjit Kumar Pandey {
1592d4c750f2SAjit Kumar Pandey struct snd_soc_dai_link *links;
1593d4c750f2SAjit Kumar Pandey struct device *dev = card->dev;
1594d4c750f2SAjit Kumar Pandey struct acp_card_drvdata *drv_data = card->drvdata;
1595d4c750f2SAjit Kumar Pandey int i = 0, num_links = 0;
159654fcd9ddSMarian Postevca int rc;
1597d4c750f2SAjit Kumar Pandey
1598d4c750f2SAjit Kumar Pandey if (drv_data->hs_cpu_id)
1599d4c750f2SAjit Kumar Pandey num_links++;
1600d4c750f2SAjit Kumar Pandey if (drv_data->amp_cpu_id)
1601d4c750f2SAjit Kumar Pandey num_links++;
1602d4c750f2SAjit Kumar Pandey if (drv_data->dmic_cpu_id)
1603d4c750f2SAjit Kumar Pandey num_links++;
1604d4c750f2SAjit Kumar Pandey
1605f047199eSye xingchen links = devm_kcalloc(dev, num_links, sizeof(struct snd_soc_dai_link), GFP_KERNEL);
1606431f9a77SJia-Ju Bai if (!links)
1607431f9a77SJia-Ju Bai return -ENOMEM;
1608d4c750f2SAjit Kumar Pandey
1609d4c750f2SAjit Kumar Pandey if (drv_data->hs_cpu_id == I2S_SP) {
1610d4c750f2SAjit Kumar Pandey links[i].name = "acp-headset-codec";
1611d4c750f2SAjit Kumar Pandey links[i].id = HEADSET_BE_ID;
1612d4c750f2SAjit Kumar Pandey links[i].cpus = i2s_sp;
1613d4c750f2SAjit Kumar Pandey links[i].num_cpus = ARRAY_SIZE(i2s_sp);
1614d4c750f2SAjit Kumar Pandey links[i].platforms = platform_component;
1615d4c750f2SAjit Kumar Pandey links[i].num_platforms = ARRAY_SIZE(platform_component);
1616d4c750f2SAjit Kumar Pandey links[i].dpcm_playback = 1;
1617d4c750f2SAjit Kumar Pandey links[i].dpcm_capture = 1;
1618d4c750f2SAjit Kumar Pandey if (!drv_data->hs_codec_id) {
1619d4c750f2SAjit Kumar Pandey /* Use dummy codec if codec id not specified */
1620d4f23dcdSKuninori Morimoto links[i].codecs = &snd_soc_dummy_dlc;
162142e0861dSKuninori Morimoto links[i].num_codecs = 1;
1622d4c750f2SAjit Kumar Pandey }
1623d4c750f2SAjit Kumar Pandey if (drv_data->hs_codec_id == RT5682) {
1624d4c750f2SAjit Kumar Pandey links[i].codecs = rt5682;
1625d4c750f2SAjit Kumar Pandey links[i].num_codecs = ARRAY_SIZE(rt5682);
1626d4c750f2SAjit Kumar Pandey links[i].init = acp_card_rt5682_init;
1627d4c750f2SAjit Kumar Pandey links[i].ops = &acp_card_rt5682_ops;
1628d4c750f2SAjit Kumar Pandey }
16298b725626SAjit Kumar Pandey if (drv_data->hs_codec_id == RT5682S) {
16308b725626SAjit Kumar Pandey links[i].codecs = rt5682s;
16318b725626SAjit Kumar Pandey links[i].num_codecs = ARRAY_SIZE(rt5682s);
16328b725626SAjit Kumar Pandey links[i].init = acp_card_rt5682s_init;
16338b725626SAjit Kumar Pandey links[i].ops = &acp_card_rt5682s_ops;
16348b725626SAjit Kumar Pandey }
163554fcd9ddSMarian Postevca if (drv_data->hs_codec_id == ES83XX) {
163654fcd9ddSMarian Postevca rc = acp_ops_configure_link(card, &links[i]);
163754fcd9ddSMarian Postevca if (rc != 0) {
163854fcd9ddSMarian Postevca dev_err(dev, "Failed to configure link for ES83XX: %d\n", rc);
163954fcd9ddSMarian Postevca return rc;
164054fcd9ddSMarian Postevca }
164154fcd9ddSMarian Postevca }
1642d4c750f2SAjit Kumar Pandey i++;
1643d4c750f2SAjit Kumar Pandey }
1644d4c750f2SAjit Kumar Pandey
1645e8a33a94SV sujith kumar Reddy if (drv_data->hs_cpu_id == I2S_HS) {
1646e8a33a94SV sujith kumar Reddy links[i].name = "acp-headset-codec";
1647e8a33a94SV sujith kumar Reddy links[i].id = HEADSET_BE_ID;
1648e8a33a94SV sujith kumar Reddy links[i].cpus = i2s_hs;
1649e8a33a94SV sujith kumar Reddy links[i].num_cpus = ARRAY_SIZE(i2s_hs);
1650e8a33a94SV sujith kumar Reddy if (drv_data->platform == REMBRANDT) {
1651e8a33a94SV sujith kumar Reddy links[i].platforms = platform_rmb_component;
1652e8a33a94SV sujith kumar Reddy links[i].num_platforms = ARRAY_SIZE(platform_rmb_component);
16539393bfb4SSyed Saba Kareem } else if (drv_data->platform == ACP63) {
16549393bfb4SSyed Saba Kareem links[i].platforms = platform_acp63_component;
16559393bfb4SSyed Saba Kareem links[i].num_platforms = ARRAY_SIZE(platform_acp63_component);
1656e8a33a94SV sujith kumar Reddy } else {
1657e8a33a94SV sujith kumar Reddy links[i].platforms = platform_component;
1658e8a33a94SV sujith kumar Reddy links[i].num_platforms = ARRAY_SIZE(platform_component);
1659e8a33a94SV sujith kumar Reddy }
1660e8a33a94SV sujith kumar Reddy links[i].dpcm_playback = 1;
1661e8a33a94SV sujith kumar Reddy links[i].dpcm_capture = 1;
1662e8a33a94SV sujith kumar Reddy if (!drv_data->hs_codec_id) {
1663e8a33a94SV sujith kumar Reddy /* Use dummy codec if codec id not specified */
1664d4f23dcdSKuninori Morimoto links[i].codecs = &snd_soc_dummy_dlc;
166542e0861dSKuninori Morimoto links[i].num_codecs = 1;
1666e8a33a94SV sujith kumar Reddy }
1667e8a33a94SV sujith kumar Reddy if (drv_data->hs_codec_id == NAU8825) {
1668e8a33a94SV sujith kumar Reddy links[i].codecs = nau8825;
1669e8a33a94SV sujith kumar Reddy links[i].num_codecs = ARRAY_SIZE(nau8825);
1670e8a33a94SV sujith kumar Reddy links[i].init = acp_card_nau8825_init;
1671e8a33a94SV sujith kumar Reddy links[i].ops = &acp_card_nau8825_ops;
1672e8a33a94SV sujith kumar Reddy }
1673e8a33a94SV sujith kumar Reddy if (drv_data->hs_codec_id == RT5682S) {
1674e8a33a94SV sujith kumar Reddy links[i].codecs = rt5682s;
1675e8a33a94SV sujith kumar Reddy links[i].num_codecs = ARRAY_SIZE(rt5682s);
1676e8a33a94SV sujith kumar Reddy links[i].init = acp_card_rt5682s_init;
1677e8a33a94SV sujith kumar Reddy links[i].ops = &acp_card_rt5682s_ops;
1678e8a33a94SV sujith kumar Reddy }
1679e8a33a94SV sujith kumar Reddy i++;
1680e8a33a94SV sujith kumar Reddy }
1681e8a33a94SV sujith kumar Reddy
1682d4c750f2SAjit Kumar Pandey if (drv_data->amp_cpu_id == I2S_SP) {
1683d4c750f2SAjit Kumar Pandey links[i].name = "acp-amp-codec";
1684d4c750f2SAjit Kumar Pandey links[i].id = AMP_BE_ID;
1685d4c750f2SAjit Kumar Pandey links[i].cpus = i2s_sp;
1686d4c750f2SAjit Kumar Pandey links[i].num_cpus = ARRAY_SIZE(i2s_sp);
1687d4c750f2SAjit Kumar Pandey links[i].platforms = platform_component;
1688d4c750f2SAjit Kumar Pandey links[i].num_platforms = ARRAY_SIZE(platform_component);
1689d4c750f2SAjit Kumar Pandey links[i].dpcm_playback = 1;
1690d4c750f2SAjit Kumar Pandey if (!drv_data->amp_codec_id) {
1691d4c750f2SAjit Kumar Pandey /* Use dummy codec if codec id not specified */
1692d4f23dcdSKuninori Morimoto links[i].codecs = &snd_soc_dummy_dlc;
169342e0861dSKuninori Morimoto links[i].num_codecs = 1;
1694d4c750f2SAjit Kumar Pandey }
1695d4c750f2SAjit Kumar Pandey if (drv_data->amp_codec_id == RT1019) {
1696d4c750f2SAjit Kumar Pandey links[i].codecs = rt1019;
1697d4c750f2SAjit Kumar Pandey links[i].num_codecs = ARRAY_SIZE(rt1019);
1698d4c750f2SAjit Kumar Pandey links[i].ops = &acp_card_rt1019_ops;
1699d4c750f2SAjit Kumar Pandey links[i].init = acp_card_rt1019_init;
1700d4c750f2SAjit Kumar Pandey card->codec_conf = rt1019_conf;
1701d4c750f2SAjit Kumar Pandey card->num_configs = ARRAY_SIZE(rt1019_conf);
1702d4c750f2SAjit Kumar Pandey }
1703cabc3aceSAjit Kumar Pandey if (drv_data->amp_codec_id == MAX98360A) {
1704cabc3aceSAjit Kumar Pandey links[i].codecs = max98360a;
1705cabc3aceSAjit Kumar Pandey links[i].num_codecs = ARRAY_SIZE(max98360a);
1706cabc3aceSAjit Kumar Pandey links[i].ops = &acp_card_maxim_ops;
1707cabc3aceSAjit Kumar Pandey links[i].init = acp_card_maxim_init;
1708cabc3aceSAjit Kumar Pandey }
1709611ba05eSAjit Kumar Pandey i++;
1710611ba05eSAjit Kumar Pandey }
1711611ba05eSAjit Kumar Pandey
1712e8a33a94SV sujith kumar Reddy if (drv_data->amp_cpu_id == I2S_HS) {
1713e8a33a94SV sujith kumar Reddy links[i].name = "acp-amp-codec";
1714e8a33a94SV sujith kumar Reddy links[i].id = AMP_BE_ID;
1715e8a33a94SV sujith kumar Reddy links[i].cpus = i2s_hs;
1716e8a33a94SV sujith kumar Reddy links[i].num_cpus = ARRAY_SIZE(i2s_hs);
1717e8a33a94SV sujith kumar Reddy if (drv_data->platform == REMBRANDT) {
1718e8a33a94SV sujith kumar Reddy links[i].platforms = platform_rmb_component;
1719e8a33a94SV sujith kumar Reddy links[i].num_platforms = ARRAY_SIZE(platform_rmb_component);
17209393bfb4SSyed Saba Kareem } else if (drv_data->platform == ACP63) {
17219393bfb4SSyed Saba Kareem links[i].platforms = platform_acp63_component;
17229393bfb4SSyed Saba Kareem links[i].num_platforms = ARRAY_SIZE(platform_acp63_component);
1723e8a33a94SV sujith kumar Reddy } else {
1724e8a33a94SV sujith kumar Reddy links[i].platforms = platform_component;
1725e8a33a94SV sujith kumar Reddy links[i].num_platforms = ARRAY_SIZE(platform_component);
1726e8a33a94SV sujith kumar Reddy }
1727e8a33a94SV sujith kumar Reddy links[i].dpcm_playback = 1;
1728e8a33a94SV sujith kumar Reddy if (!drv_data->amp_codec_id) {
1729e8a33a94SV sujith kumar Reddy /* Use dummy codec if codec id not specified */
1730d4f23dcdSKuninori Morimoto links[i].codecs = &snd_soc_dummy_dlc;
173142e0861dSKuninori Morimoto links[i].num_codecs = 1;
1732e8a33a94SV sujith kumar Reddy }
1733e8a33a94SV sujith kumar Reddy if (drv_data->amp_codec_id == MAX98360A) {
1734e8a33a94SV sujith kumar Reddy links[i].codecs = max98360a;
1735e8a33a94SV sujith kumar Reddy links[i].num_codecs = ARRAY_SIZE(max98360a);
1736e8a33a94SV sujith kumar Reddy links[i].ops = &acp_card_maxim_ops;
1737e8a33a94SV sujith kumar Reddy links[i].init = acp_card_maxim_init;
1738e8a33a94SV sujith kumar Reddy }
1739e8a33a94SV sujith kumar Reddy if (drv_data->amp_codec_id == RT1019) {
1740e8a33a94SV sujith kumar Reddy links[i].codecs = rt1019;
1741e8a33a94SV sujith kumar Reddy links[i].num_codecs = ARRAY_SIZE(rt1019);
1742e8a33a94SV sujith kumar Reddy links[i].ops = &acp_card_rt1019_ops;
1743e8a33a94SV sujith kumar Reddy links[i].init = acp_card_rt1019_init;
1744e8a33a94SV sujith kumar Reddy card->codec_conf = rt1019_conf;
1745e8a33a94SV sujith kumar Reddy card->num_configs = ARRAY_SIZE(rt1019_conf);
1746e8a33a94SV sujith kumar Reddy }
1747e8a33a94SV sujith kumar Reddy i++;
1748e8a33a94SV sujith kumar Reddy }
1749e8a33a94SV sujith kumar Reddy
1750611ba05eSAjit Kumar Pandey if (drv_data->dmic_cpu_id == DMIC) {
1751611ba05eSAjit Kumar Pandey links[i].name = "acp-dmic-codec";
1752611ba05eSAjit Kumar Pandey links[i].id = DMIC_BE_ID;
1753611ba05eSAjit Kumar Pandey if (drv_data->dmic_codec_id == DMIC) {
1754611ba05eSAjit Kumar Pandey links[i].codecs = dmic_codec;
1755611ba05eSAjit Kumar Pandey links[i].num_codecs = ARRAY_SIZE(dmic_codec);
1756611ba05eSAjit Kumar Pandey } else {
1757611ba05eSAjit Kumar Pandey /* Use dummy codec if codec id not specified */
1758d4f23dcdSKuninori Morimoto links[i].codecs = &snd_soc_dummy_dlc;
175942e0861dSKuninori Morimoto links[i].num_codecs = 1;
1760611ba05eSAjit Kumar Pandey }
1761611ba05eSAjit Kumar Pandey links[i].cpus = pdm_dmic;
1762611ba05eSAjit Kumar Pandey links[i].num_cpus = ARRAY_SIZE(pdm_dmic);
1763e8a33a94SV sujith kumar Reddy if (drv_data->platform == REMBRANDT) {
1764e8a33a94SV sujith kumar Reddy links[i].platforms = platform_rmb_component;
1765e8a33a94SV sujith kumar Reddy links[i].num_platforms = ARRAY_SIZE(platform_rmb_component);
17669393bfb4SSyed Saba Kareem } else if (drv_data->platform == ACP63) {
17679393bfb4SSyed Saba Kareem links[i].platforms = platform_acp63_component;
17689393bfb4SSyed Saba Kareem links[i].num_platforms = ARRAY_SIZE(platform_acp63_component);
1769*c6f3abbbSVijendar Mukunda } else if ((drv_data->platform == ACP70) || (drv_data->platform == ACP71)) {
1770b97f4dacSSyed Saba Kareem links[i].platforms = platform_acp70_component;
1771b97f4dacSSyed Saba Kareem links[i].num_platforms = ARRAY_SIZE(platform_acp70_component);
1772e8a33a94SV sujith kumar Reddy } else {
1773611ba05eSAjit Kumar Pandey links[i].platforms = platform_component;
1774611ba05eSAjit Kumar Pandey links[i].num_platforms = ARRAY_SIZE(platform_component);
1775e8a33a94SV sujith kumar Reddy }
17761f197351SAjit Kumar Pandey links[i].ops = &acp_card_dmic_ops;
1777611ba05eSAjit Kumar Pandey links[i].dpcm_capture = 1;
1778d4c750f2SAjit Kumar Pandey }
1779d4c750f2SAjit Kumar Pandey
1780d4c750f2SAjit Kumar Pandey card->dai_link = links;
1781d4c750f2SAjit Kumar Pandey card->num_links = num_links;
17829e693e81SVenkata Prasad Potturu card->set_bias_level = acp_rtk_set_bias_level;
1783d4c750f2SAjit Kumar Pandey
1784d4c750f2SAjit Kumar Pandey return 0;
1785d4c750f2SAjit Kumar Pandey }
1786d4c750f2SAjit Kumar Pandey EXPORT_SYMBOL_NS_GPL(acp_legacy_dai_links_create, SND_SOC_AMD_MACH);
1787d4c750f2SAjit Kumar Pandey
1788576f3aefSCristian Ciocaltea MODULE_DESCRIPTION("AMD ACP Common Machine driver");
1789d4c750f2SAjit Kumar Pandey MODULE_LICENSE("GPL v2");
1790