blob: 3bf86c2424ae9c3601be2d982d3d9772d931d3f1 [file] [log] [blame]
Vijendar Mukunda23f23db2021-03-26 22:14:30 +05301// SPDX-License-Identifier: MIT
2//
3// Machine driver for AMD ACP Audio engine using DA7219, RT5682 & MAX98357 codec
4//
5//Copyright 2017-2021 Advanced Micro Devices, Inc.
Akshu Agrawal608a300f2018-02-16 13:11:13 +05306
7#include <sound/core.h>
8#include <sound/soc.h>
9#include <sound/pcm.h>
10#include <sound/pcm_params.h>
11#include <sound/soc-dapm.h>
12#include <sound/jack.h>
Akshu Agrawalc88d3112018-03-19 11:07:42 +053013#include <linux/clk.h>
Akshu Agrawal608a300f2018-02-16 13:11:13 +053014#include <linux/gpio.h>
15#include <linux/module.h>
Akshu Agrawalc183fec2018-07-25 17:00:59 +080016#include <linux/regulator/machine.h>
17#include <linux/regulator/driver.h>
Akshu Agrawal608a300f2018-02-16 13:11:13 +053018#include <linux/i2c.h>
Agrawal, Akshu923859e2018-04-12 17:57:11 +080019#include <linux/input.h>
Akshu Agrawal608a300f2018-02-16 13:11:13 +053020#include <linux/acpi.h>
21
Mukunda, Vijendarccfbb4f2018-05-08 10:17:53 +053022#include "acp.h"
Akshu Agrawal608a300f2018-02-16 13:11:13 +053023#include "../codecs/da7219.h"
24#include "../codecs/da7219-aad.h"
Vijendar Mukunda7e71b482021-03-19 07:10:42 +053025#include "../codecs/rt5682.h"
Akshu Agrawal608a300f2018-02-16 13:11:13 +053026
Akshu Agrawala1b1e982018-08-21 12:29:43 +053027#define CZ_PLAT_CLK 48000000
Akshu Agrawal608a300f2018-02-16 13:11:13 +053028#define DUAL_CHANNEL 2
Vijendar Mukunda7e71b482021-03-19 07:10:42 +053029#define RT5682_PLL_FREQ (48000 * 512)
Akshu Agrawal608a300f2018-02-16 13:11:13 +053030
31static struct snd_soc_jack cz_jack;
Agrawal, Akshubb24a312019-04-17 10:05:13 +000032static struct clk *da7219_dai_wclk;
33static struct clk *da7219_dai_bclk;
Vijendar Mukunda7e71b482021-03-19 07:10:42 +053034static struct clk *rt5682_dai_wclk;
35static struct clk *rt5682_dai_bclk;
Pierre-Louis Bossart19843302021-09-07 13:42:14 -050036
Vijendar Mukunda7e71b482021-03-19 07:10:42 +053037void *acp_soc_is_rltk_max(struct device *dev);
Akshu Agrawal608a300f2018-02-16 13:11:13 +053038
39static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd)
40{
41 int ret;
42 struct snd_soc_card *card = rtd->card;
Kuninori Morimotob09b22f2020-03-23 14:17:13 +090043 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
Kuninori Morimoto9a60cde2018-02-19 04:16:06 +000044 struct snd_soc_component *component = codec_dai->component;
Akshu Agrawal608a300f2018-02-16 13:11:13 +053045
46 dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
47
48 ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK,
49 CZ_PLAT_CLK, SND_SOC_CLOCK_IN);
50 if (ret < 0) {
51 dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret);
52 return ret;
53 }
54
55 ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL,
Akshu Agrawal6e554072018-05-08 10:17:51 +053056 CZ_PLAT_CLK, DA7219_PLL_FREQ_OUT_98304);
Akshu Agrawal608a300f2018-02-16 13:11:13 +053057 if (ret < 0) {
58 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
59 return ret;
60 }
61
Chuhong Yuan95d3bef2020-12-04 14:36:10 +080062 da7219_dai_wclk = devm_clk_get(component->dev, "da7219-dai-wclk");
63 if (IS_ERR(da7219_dai_wclk))
64 return PTR_ERR(da7219_dai_wclk);
65
66 da7219_dai_bclk = devm_clk_get(component->dev, "da7219-dai-bclk");
67 if (IS_ERR(da7219_dai_bclk))
68 return PTR_ERR(da7219_dai_bclk);
Akshu Agrawalc88d3112018-03-19 11:07:42 +053069
Akshu Agrawal608a300f2018-02-16 13:11:13 +053070 ret = snd_soc_card_jack_new(card, "Headset Jack",
Akshu Agrawal2657c6a2018-10-15 12:24:44 +053071 SND_JACK_HEADSET | SND_JACK_LINEOUT |
Akshu Agrawal608a300f2018-02-16 13:11:13 +053072 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
73 SND_JACK_BTN_2 | SND_JACK_BTN_3,
74 &cz_jack, NULL, 0);
75 if (ret) {
76 dev_err(card->dev, "HP jack creation failed %d\n", ret);
77 return ret;
78 }
79
Agrawal, Akshu923859e2018-04-12 17:57:11 +080080 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
81 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
82 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
83 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
84
Kuninori Morimoto9a60cde2018-02-19 04:16:06 +000085 da7219_aad_jack_det(component, &cz_jack);
Akshu Agrawal608a300f2018-02-16 13:11:13 +053086
87 return 0;
88}
89
Yu-Hsuan Hsu756ae8f2019-11-26 15:54:24 +080090static int da7219_clk_enable(struct snd_pcm_substream *substream)
Akshu Agrawalc88d3112018-03-19 11:07:42 +053091{
92 int ret = 0;
Kuninori Morimotoded00542020-07-20 10:18:34 +090093 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Akshu Agrawalc88d3112018-03-19 11:07:42 +053094
Yu-Hsuan Hsu756ae8f2019-11-26 15:54:24 +080095 /*
96 * Set wclk to 48000 because the rate constraint of this driver is
97 * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is
98 * minimum of 64x the LRCLK sample rate." DA7219 is the only clk
99 * source so for all codecs we have to limit bclk to 64X lrclk.
100 */
101 clk_set_rate(da7219_dai_wclk, 48000);
102 clk_set_rate(da7219_dai_bclk, 48000 * 64);
Agrawal, Akshubb24a312019-04-17 10:05:13 +0000103 ret = clk_prepare_enable(da7219_dai_bclk);
Akshu Agrawalc88d3112018-03-19 11:07:42 +0530104 if (ret < 0) {
105 dev_err(rtd->dev, "can't enable master clock %d\n", ret);
106 return ret;
107 }
108
109 return ret;
110}
111
Akshu Agrawale9716ff2018-05-08 10:17:50 +0530112static void da7219_clk_disable(void)
Akshu Agrawalc88d3112018-03-19 11:07:42 +0530113{
Agrawal, Akshubb24a312019-04-17 10:05:13 +0000114 clk_disable_unprepare(da7219_dai_bclk);
Akshu Agrawalc88d3112018-03-19 11:07:42 +0530115}
116
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530117static int cz_rt5682_init(struct snd_soc_pcm_runtime *rtd)
118{
119 int ret;
120 struct snd_soc_card *card = rtd->card;
121 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
122 struct snd_soc_component *component = codec_dai->component;
123
124 dev_info(codec_dai->dev, "codec dai name = %s\n", codec_dai->name);
125
126 /* Set codec sysclk */
127 ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL2,
128 RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
129 if (ret < 0) {
130 dev_err(codec_dai->dev,
131 "Failed to set rt5682 SYSCLK: %d\n", ret);
132 return ret;
133 }
134 /* set codec PLL */
135 ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL2, RT5682_PLL2_S_MCLK,
136 CZ_PLAT_CLK, RT5682_PLL_FREQ);
137 if (ret < 0) {
138 dev_err(codec_dai->dev, "can't set rt5682 PLL: %d\n", ret);
139 return ret;
140 }
141
142 rt5682_dai_wclk = devm_clk_get(component->dev, "rt5682-dai-wclk");
143 if (IS_ERR(rt5682_dai_wclk))
144 return PTR_ERR(rt5682_dai_wclk);
145
146 rt5682_dai_bclk = devm_clk_get(component->dev, "rt5682-dai-bclk");
147 if (IS_ERR(rt5682_dai_bclk))
148 return PTR_ERR(rt5682_dai_bclk);
149
150 ret = snd_soc_card_jack_new(card, "Headset Jack",
151 SND_JACK_HEADSET | SND_JACK_LINEOUT |
152 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
153 SND_JACK_BTN_2 | SND_JACK_BTN_3,
154 &cz_jack, NULL, 0);
155 if (ret) {
156 dev_err(card->dev, "HP jack creation failed %d\n", ret);
157 return ret;
158 }
159
160 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
161 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
162 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
163 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
164
165 ret = snd_soc_component_set_jack(component, &cz_jack, NULL);
166 if (ret) {
167 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
168 return ret;
169 }
170 return 0;
171}
172
173static int rt5682_clk_enable(struct snd_pcm_substream *substream)
174{
175 int ret;
176 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
177
178 /*
179 * Set wclk to 48000 because the rate constraint of this driver is
180 * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is
181 * minimum of 64x the LRCLK sample rate." RT5682 is the only clk
182 * source so for all codecs we have to limit bclk to 64X lrclk.
183 */
184 ret = clk_set_rate(rt5682_dai_wclk, 48000);
185 if (ret) {
186 dev_err(rtd->dev, "Error setting wclk rate: %d\n", ret);
187 return ret;
188 }
189 ret = clk_set_rate(rt5682_dai_bclk, 48000 * 64);
190 if (ret) {
191 dev_err(rtd->dev, "Error setting bclk rate: %d\n", ret);
192 return ret;
193 }
194 ret = clk_prepare_enable(rt5682_dai_wclk);
195 if (ret < 0) {
196 dev_err(rtd->dev, "can't enable wclk %d\n", ret);
197 return ret;
198 }
199 return ret;
200}
201
202static void rt5682_clk_disable(void)
203{
204 clk_disable_unprepare(rt5682_dai_wclk);
205}
206
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530207static const unsigned int channels[] = {
208 DUAL_CHANNEL,
209};
210
211static const unsigned int rates[] = {
212 48000,
213};
214
215static const struct snd_pcm_hw_constraint_list constraints_rates = {
216 .count = ARRAY_SIZE(rates),
217 .list = rates,
218 .mask = 0,
219};
220
221static const struct snd_pcm_hw_constraint_list constraints_channels = {
222 .count = ARRAY_SIZE(channels),
223 .list = channels,
224 .mask = 0,
225};
226
Akshu Agrawal8dcb0c92018-09-10 22:50:27 +0530227static int cz_da7219_play_startup(struct snd_pcm_substream *substream)
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530228{
229 struct snd_pcm_runtime *runtime = substream->runtime;
Kuninori Morimotoded00542020-07-20 10:18:34 +0900230 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Mukunda, Vijendarccfbb4f2018-05-08 10:17:53 +0530231 struct snd_soc_card *card = rtd->card;
232 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530233
234 /*
235 * On this platform for PCM device we support stereo
236 */
237
238 runtime->hw.channels_max = DUAL_CHANNEL;
239 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
240 &constraints_channels);
241 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
242 &constraints_rates);
243
Akshu Agrawal8dcb0c92018-09-10 22:50:27 +0530244 machine->play_i2s_instance = I2S_SP_INSTANCE;
Yu-Hsuan Hsu756ae8f2019-11-26 15:54:24 +0800245 return da7219_clk_enable(substream);
Akshu Agrawal8dcb0c92018-09-10 22:50:27 +0530246}
247
248static int cz_da7219_cap_startup(struct snd_pcm_substream *substream)
249{
250 struct snd_pcm_runtime *runtime = substream->runtime;
Kuninori Morimotoded00542020-07-20 10:18:34 +0900251 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Akshu Agrawal8dcb0c92018-09-10 22:50:27 +0530252 struct snd_soc_card *card = rtd->card;
253 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
254
255 /*
256 * On this platform for PCM device we support stereo
257 */
258
259 runtime->hw.channels_max = DUAL_CHANNEL;
260 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
261 &constraints_channels);
262 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
263 &constraints_rates);
264
265 machine->cap_i2s_instance = I2S_SP_INSTANCE;
Akshu Agrawal2718c892018-06-21 12:58:17 +0800266 machine->capture_channel = CAP_CHANNEL1;
Yu-Hsuan Hsu756ae8f2019-11-26 15:54:24 +0800267 return da7219_clk_enable(substream);
Akshu Agrawale9716ff2018-05-08 10:17:50 +0530268}
269
270static int cz_max_startup(struct snd_pcm_substream *substream)
271{
Akshu Agrawalc736cbd2018-08-21 12:25:05 +0530272 struct snd_pcm_runtime *runtime = substream->runtime;
Kuninori Morimotoded00542020-07-20 10:18:34 +0900273 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Mukunda, Vijendarccfbb4f2018-05-08 10:17:53 +0530274 struct snd_soc_card *card = rtd->card;
275 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
276
Akshu Agrawalc736cbd2018-08-21 12:25:05 +0530277 /*
278 * On this platform for PCM device we support stereo
279 */
280
281 runtime->hw.channels_max = DUAL_CHANNEL;
282 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
283 &constraints_channels);
284 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
285 &constraints_rates);
286
Akshu Agrawal8dcb0c92018-09-10 22:50:27 +0530287 machine->play_i2s_instance = I2S_BT_INSTANCE;
Yu-Hsuan Hsu756ae8f2019-11-26 15:54:24 +0800288 return da7219_clk_enable(substream);
Akshu Agrawale9716ff2018-05-08 10:17:50 +0530289}
290
Akshu Agrawal2718c892018-06-21 12:58:17 +0800291static int cz_dmic0_startup(struct snd_pcm_substream *substream)
Akshu Agrawale9716ff2018-05-08 10:17:50 +0530292{
Akshu Agrawalc736cbd2018-08-21 12:25:05 +0530293 struct snd_pcm_runtime *runtime = substream->runtime;
Kuninori Morimotoded00542020-07-20 10:18:34 +0900294 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Mukunda, Vijendarccfbb4f2018-05-08 10:17:53 +0530295 struct snd_soc_card *card = rtd->card;
296 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
297
Akshu Agrawalc736cbd2018-08-21 12:25:05 +0530298 /*
299 * On this platform for PCM device we support stereo
300 */
301
302 runtime->hw.channels_max = DUAL_CHANNEL;
303 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
304 &constraints_channels);
305 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
306 &constraints_rates);
307
Akshu Agrawal8dcb0c92018-09-10 22:50:27 +0530308 machine->cap_i2s_instance = I2S_BT_INSTANCE;
Yu-Hsuan Hsu756ae8f2019-11-26 15:54:24 +0800309 return da7219_clk_enable(substream);
Akshu Agrawale9716ff2018-05-08 10:17:50 +0530310}
311
Akshu Agrawal2718c892018-06-21 12:58:17 +0800312static int cz_dmic1_startup(struct snd_pcm_substream *substream)
313{
Akshu Agrawalc736cbd2018-08-21 12:25:05 +0530314 struct snd_pcm_runtime *runtime = substream->runtime;
Kuninori Morimotoded00542020-07-20 10:18:34 +0900315 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Akshu Agrawal2718c892018-06-21 12:58:17 +0800316 struct snd_soc_card *card = rtd->card;
317 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
318
Akshu Agrawalc736cbd2018-08-21 12:25:05 +0530319 /*
320 * On this platform for PCM device we support stereo
321 */
322
323 runtime->hw.channels_max = DUAL_CHANNEL;
324 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
325 &constraints_channels);
326 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
327 &constraints_rates);
328
Akshu Agrawal8dcb0c92018-09-10 22:50:27 +0530329 machine->cap_i2s_instance = I2S_SP_INSTANCE;
Akshu Agrawal2718c892018-06-21 12:58:17 +0800330 machine->capture_channel = CAP_CHANNEL0;
Yu-Hsuan Hsu756ae8f2019-11-26 15:54:24 +0800331 return da7219_clk_enable(substream);
Agrawal, Akshubb24a312019-04-17 10:05:13 +0000332}
333
334static void cz_da7219_shutdown(struct snd_pcm_substream *substream)
Akshu Agrawale9716ff2018-05-08 10:17:50 +0530335{
336 da7219_clk_disable();
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530337}
338
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530339static int cz_rt5682_play_startup(struct snd_pcm_substream *substream)
340{
341 struct snd_pcm_runtime *runtime = substream->runtime;
342 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
343 struct snd_soc_card *card = rtd->card;
344 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
345
346 /*
347 * On this platform for PCM device we support stereo
348 */
349
350 runtime->hw.channels_max = DUAL_CHANNEL;
351 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
352 &constraints_channels);
353 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
354 &constraints_rates);
355
356 machine->play_i2s_instance = I2S_SP_INSTANCE;
357 return rt5682_clk_enable(substream);
358}
359
360static int cz_rt5682_cap_startup(struct snd_pcm_substream *substream)
361{
362 struct snd_pcm_runtime *runtime = substream->runtime;
363 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
364 struct snd_soc_card *card = rtd->card;
365 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
366
367 /*
368 * On this platform for PCM device we support stereo
369 */
370
371 runtime->hw.channels_max = DUAL_CHANNEL;
372 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
373 &constraints_channels);
374 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
375 &constraints_rates);
376
377 machine->cap_i2s_instance = I2S_SP_INSTANCE;
378 machine->capture_channel = CAP_CHANNEL1;
379 return rt5682_clk_enable(substream);
380}
381
382static int cz_rt5682_max_startup(struct snd_pcm_substream *substream)
383{
384 struct snd_pcm_runtime *runtime = substream->runtime;
385 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
386 struct snd_soc_card *card = rtd->card;
387 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
388
389 /*
390 * On this platform for PCM device we support stereo
391 */
392
393 runtime->hw.channels_max = DUAL_CHANNEL;
394 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
395 &constraints_channels);
396 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
397 &constraints_rates);
398
399 machine->play_i2s_instance = I2S_BT_INSTANCE;
400 return rt5682_clk_enable(substream);
401}
402
403static int cz_rt5682_dmic0_startup(struct snd_pcm_substream *substream)
404{
405 struct snd_pcm_runtime *runtime = substream->runtime;
406 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
407 struct snd_soc_card *card = rtd->card;
408 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
409
410 /*
411 * On this platform for PCM device we support stereo
412 */
413
414 runtime->hw.channels_max = DUAL_CHANNEL;
415 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
416 &constraints_channels);
417 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
418 &constraints_rates);
419
420 machine->cap_i2s_instance = I2S_BT_INSTANCE;
421 return rt5682_clk_enable(substream);
422}
423
424static int cz_rt5682_dmic1_startup(struct snd_pcm_substream *substream)
425{
426 struct snd_pcm_runtime *runtime = substream->runtime;
427 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
428 struct snd_soc_card *card = rtd->card;
429 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
430
431 /*
432 * On this platform for PCM device we support stereo
433 */
434
435 runtime->hw.channels_max = DUAL_CHANNEL;
436 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
437 &constraints_channels);
438 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
439 &constraints_rates);
440
441 machine->cap_i2s_instance = I2S_SP_INSTANCE;
442 machine->capture_channel = CAP_CHANNEL0;
443 return rt5682_clk_enable(substream);
444}
445
446static void cz_rt5682_shutdown(struct snd_pcm_substream *substream)
447{
448 rt5682_clk_disable();
449}
450
Akshu Agrawal8dcb0c92018-09-10 22:50:27 +0530451static const struct snd_soc_ops cz_da7219_play_ops = {
452 .startup = cz_da7219_play_startup,
453 .shutdown = cz_da7219_shutdown,
454};
455
Akshu Agrawal839a12c2018-05-08 10:17:52 +0530456static const struct snd_soc_ops cz_da7219_cap_ops = {
Akshu Agrawal8dcb0c92018-09-10 22:50:27 +0530457 .startup = cz_da7219_cap_startup,
Akshu Agrawale9716ff2018-05-08 10:17:50 +0530458 .shutdown = cz_da7219_shutdown,
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530459};
460
Akshu Agrawal839a12c2018-05-08 10:17:52 +0530461static const struct snd_soc_ops cz_max_play_ops = {
Akshu Agrawale9716ff2018-05-08 10:17:50 +0530462 .startup = cz_max_startup,
Agrawal, Akshubb24a312019-04-17 10:05:13 +0000463 .shutdown = cz_da7219_shutdown,
Akshu Agrawalc88d3112018-03-19 11:07:42 +0530464};
465
Akshu Agrawal2718c892018-06-21 12:58:17 +0800466static const struct snd_soc_ops cz_dmic0_cap_ops = {
467 .startup = cz_dmic0_startup,
Agrawal, Akshubb24a312019-04-17 10:05:13 +0000468 .shutdown = cz_da7219_shutdown,
Akshu Agrawal2718c892018-06-21 12:58:17 +0800469};
470
471static const struct snd_soc_ops cz_dmic1_cap_ops = {
472 .startup = cz_dmic1_startup,
Agrawal, Akshubb24a312019-04-17 10:05:13 +0000473 .shutdown = cz_da7219_shutdown,
Akshu Agrawalc88d3112018-03-19 11:07:42 +0530474};
475
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530476static const struct snd_soc_ops cz_rt5682_play_ops = {
477 .startup = cz_rt5682_play_startup,
478 .shutdown = cz_rt5682_shutdown,
479};
480
481static const struct snd_soc_ops cz_rt5682_cap_ops = {
482 .startup = cz_rt5682_cap_startup,
483 .shutdown = cz_rt5682_shutdown,
484};
485
486static const struct snd_soc_ops cz_rt5682_max_play_ops = {
487 .startup = cz_rt5682_max_startup,
488 .shutdown = cz_rt5682_shutdown,
489};
490
491static const struct snd_soc_ops cz_rt5682_dmic0_cap_ops = {
492 .startup = cz_rt5682_dmic0_startup,
493 .shutdown = cz_rt5682_shutdown,
494};
495
496static const struct snd_soc_ops cz_rt5682_dmic1_cap_ops = {
497 .startup = cz_rt5682_dmic1_startup,
498 .shutdown = cz_rt5682_shutdown,
499};
500
Kuninori Morimoto48696d02019-06-06 13:13:29 +0900501SND_SOC_DAILINK_DEF(designware1,
502 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.1.auto")));
503SND_SOC_DAILINK_DEF(designware2,
504 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.2.auto")));
505SND_SOC_DAILINK_DEF(designware3,
506 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.3.auto")));
507
508SND_SOC_DAILINK_DEF(dlgs,
509 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00", "da7219-hifi")));
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530510SND_SOC_DAILINK_DEF(rt5682,
511 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1")));
Kuninori Morimoto48696d02019-06-06 13:13:29 +0900512SND_SOC_DAILINK_DEF(mx,
513 DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi")));
514SND_SOC_DAILINK_DEF(adau,
515 DAILINK_COMP_ARRAY(COMP_CODEC("ADAU7002:00", "adau7002-hifi")));
516
517SND_SOC_DAILINK_DEF(platform,
518 DAILINK_COMP_ARRAY(COMP_PLATFORM("acp_audio_dma.0.auto")));
519
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530520static struct snd_soc_dai_link cz_dai_7219_98357[] = {
521 {
Agrawal, Akshu3bec6fa2018-06-21 12:58:16 +0800522 .name = "amd-da7219-play",
523 .stream_name = "Playback",
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530524 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100525 | SND_SOC_DAIFMT_CBP_CFP,
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530526 .init = cz_da7219_init,
527 .dpcm_playback = 1,
Vijendar Mukunda5434d0d2021-07-22 18:33:15 +0530528 .stop_dma_first = 1,
Akshu Agrawal8dcb0c92018-09-10 22:50:27 +0530529 .ops = &cz_da7219_play_ops,
Kuninori Morimoto48696d02019-06-06 13:13:29 +0900530 SND_SOC_DAILINK_REG(designware1, dlgs, platform),
Agrawal, Akshu3bec6fa2018-06-21 12:58:16 +0800531 },
532 {
533 .name = "amd-da7219-cap",
534 .stream_name = "Capture",
Agrawal, Akshu3bec6fa2018-06-21 12:58:16 +0800535 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100536 | SND_SOC_DAIFMT_CBP_CFP,
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530537 .dpcm_capture = 1,
Vijendar Mukunda5434d0d2021-07-22 18:33:15 +0530538 .stop_dma_first = 1,
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530539 .ops = &cz_da7219_cap_ops,
Kuninori Morimoto48696d02019-06-06 13:13:29 +0900540 SND_SOC_DAILINK_REG(designware2, dlgs, platform),
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530541 },
542 {
543 .name = "amd-max98357-play",
544 .stream_name = "HiFi Playback",
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530545 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100546 | SND_SOC_DAIFMT_CBP_CFP,
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530547 .dpcm_playback = 1,
Vijendar Mukunda5434d0d2021-07-22 18:33:15 +0530548 .stop_dma_first = 1,
Akshu Agrawalc88d3112018-03-19 11:07:42 +0530549 .ops = &cz_max_play_ops,
Kuninori Morimoto48696d02019-06-06 13:13:29 +0900550 SND_SOC_DAILINK_REG(designware3, mx, platform),
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530551 },
552 {
Akshu Agrawal2718c892018-06-21 12:58:17 +0800553 /* C panel DMIC */
554 .name = "dmic0",
555 .stream_name = "DMIC0 Capture",
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530556 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100557 | SND_SOC_DAIFMT_CBP_CFP,
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530558 .dpcm_capture = 1,
Vijendar Mukunda5434d0d2021-07-22 18:33:15 +0530559 .stop_dma_first = 1,
Akshu Agrawal2718c892018-06-21 12:58:17 +0800560 .ops = &cz_dmic0_cap_ops,
Kuninori Morimoto48696d02019-06-06 13:13:29 +0900561 SND_SOC_DAILINK_REG(designware3, adau, platform),
Akshu Agrawal2718c892018-06-21 12:58:17 +0800562 },
563 {
564 /* A/B panel DMIC */
565 .name = "dmic1",
566 .stream_name = "DMIC1 Capture",
Akshu Agrawal2718c892018-06-21 12:58:17 +0800567 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100568 | SND_SOC_DAIFMT_CBP_CFP,
Akshu Agrawal2718c892018-06-21 12:58:17 +0800569 .dpcm_capture = 1,
Vijendar Mukunda5434d0d2021-07-22 18:33:15 +0530570 .stop_dma_first = 1,
Akshu Agrawal2718c892018-06-21 12:58:17 +0800571 .ops = &cz_dmic1_cap_ops,
Kuninori Morimoto48696d02019-06-06 13:13:29 +0900572 SND_SOC_DAILINK_REG(designware2, adau, platform),
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530573 },
574};
575
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530576static struct snd_soc_dai_link cz_dai_5682_98357[] = {
577 {
578 .name = "amd-rt5682-play",
579 .stream_name = "Playback",
580 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100581 | SND_SOC_DAIFMT_CBP_CFP,
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530582 .init = cz_rt5682_init,
583 .dpcm_playback = 1,
Vijendar Mukunda78834902021-07-16 18:00:13 +0530584 .stop_dma_first = 1,
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530585 .ops = &cz_rt5682_play_ops,
586 SND_SOC_DAILINK_REG(designware1, rt5682, platform),
587 },
588 {
589 .name = "amd-rt5682-cap",
590 .stream_name = "Capture",
591 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100592 | SND_SOC_DAIFMT_CBP_CFP,
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530593 .dpcm_capture = 1,
Vijendar Mukunda78834902021-07-16 18:00:13 +0530594 .stop_dma_first = 1,
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530595 .ops = &cz_rt5682_cap_ops,
596 SND_SOC_DAILINK_REG(designware2, rt5682, platform),
597 },
598 {
599 .name = "amd-max98357-play",
600 .stream_name = "HiFi Playback",
601 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100602 | SND_SOC_DAIFMT_CBP_CFP,
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530603 .dpcm_playback = 1,
Vijendar Mukunda78834902021-07-16 18:00:13 +0530604 .stop_dma_first = 1,
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530605 .ops = &cz_rt5682_max_play_ops,
606 SND_SOC_DAILINK_REG(designware3, mx, platform),
607 },
608 {
609 /* C panel DMIC */
610 .name = "dmic0",
611 .stream_name = "DMIC0 Capture",
612 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100613 | SND_SOC_DAIFMT_CBP_CFP,
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530614 .dpcm_capture = 1,
Vijendar Mukunda78834902021-07-16 18:00:13 +0530615 .stop_dma_first = 1,
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530616 .ops = &cz_rt5682_dmic0_cap_ops,
617 SND_SOC_DAILINK_REG(designware3, adau, platform),
618 },
619 {
620 /* A/B panel DMIC */
621 .name = "dmic1",
622 .stream_name = "DMIC1 Capture",
623 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100624 | SND_SOC_DAIFMT_CBP_CFP,
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530625 .dpcm_capture = 1,
Vijendar Mukunda78834902021-07-16 18:00:13 +0530626 .stop_dma_first = 1,
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530627 .ops = &cz_rt5682_dmic1_cap_ops,
628 SND_SOC_DAILINK_REG(designware2, adau, platform),
629 },
630};
631
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530632static const struct snd_soc_dapm_widget cz_widgets[] = {
633 SND_SOC_DAPM_HP("Headphones", NULL),
634 SND_SOC_DAPM_SPK("Speakers", NULL),
635 SND_SOC_DAPM_MIC("Headset Mic", NULL),
636 SND_SOC_DAPM_MIC("Int Mic", NULL),
637};
638
639static const struct snd_soc_dapm_route cz_audio_route[] = {
640 {"Headphones", NULL, "HPL"},
641 {"Headphones", NULL, "HPR"},
642 {"MIC", NULL, "Headset Mic"},
643 {"Speakers", NULL, "Speaker"},
644 {"PDM_DAT", NULL, "Int Mic"},
645};
646
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530647static const struct snd_soc_dapm_route cz_rt5682_audio_route[] = {
648 {"Headphones", NULL, "HPOL"},
649 {"Headphones", NULL, "HPOR"},
650 {"IN1P", NULL, "Headset Mic"},
651 {"Speakers", NULL, "Speaker"},
652 {"PDM_DAT", NULL, "Int Mic"},
653};
654
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530655static const struct snd_kcontrol_new cz_mc_controls[] = {
656 SOC_DAPM_PIN_SWITCH("Headphones"),
657 SOC_DAPM_PIN_SWITCH("Speakers"),
658 SOC_DAPM_PIN_SWITCH("Headset Mic"),
659 SOC_DAPM_PIN_SWITCH("Int Mic"),
660};
661
662static struct snd_soc_card cz_card = {
663 .name = "acpd7219m98357",
664 .owner = THIS_MODULE,
665 .dai_link = cz_dai_7219_98357,
666 .num_links = ARRAY_SIZE(cz_dai_7219_98357),
667 .dapm_widgets = cz_widgets,
668 .num_dapm_widgets = ARRAY_SIZE(cz_widgets),
669 .dapm_routes = cz_audio_route,
670 .num_dapm_routes = ARRAY_SIZE(cz_audio_route),
671 .controls = cz_mc_controls,
672 .num_controls = ARRAY_SIZE(cz_mc_controls),
673};
674
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530675static struct snd_soc_card cz_rt5682_card = {
676 .name = "acpr5682m98357",
677 .owner = THIS_MODULE,
678 .dai_link = cz_dai_5682_98357,
679 .num_links = ARRAY_SIZE(cz_dai_5682_98357),
680 .dapm_widgets = cz_widgets,
681 .num_dapm_widgets = ARRAY_SIZE(cz_widgets),
682 .dapm_routes = cz_rt5682_audio_route,
683 .controls = cz_mc_controls,
684 .num_controls = ARRAY_SIZE(cz_mc_controls),
685};
686
687void *acp_soc_is_rltk_max(struct device *dev)
688{
689 const struct acpi_device_id *match;
690
691 match = acpi_match_device(dev->driver->acpi_match_table, dev);
692 if (!match)
693 return NULL;
694 return (void *)match->driver_data;
695}
696
Akshu Agrawalc183fec2018-07-25 17:00:59 +0800697static struct regulator_consumer_supply acp_da7219_supplies[] = {
698 REGULATOR_SUPPLY("VDD", "i2c-DLGS7219:00"),
699 REGULATOR_SUPPLY("VDDMIC", "i2c-DLGS7219:00"),
700 REGULATOR_SUPPLY("VDDIO", "i2c-DLGS7219:00"),
701 REGULATOR_SUPPLY("IOVDD", "ADAU7002:00"),
702};
703
704static struct regulator_init_data acp_da7219_data = {
705 .constraints = {
706 .always_on = 1,
707 },
708 .num_consumer_supplies = ARRAY_SIZE(acp_da7219_supplies),
709 .consumer_supplies = acp_da7219_supplies,
710};
711
712static struct regulator_config acp_da7219_cfg = {
713 .init_data = &acp_da7219_data,
714};
715
716static struct regulator_ops acp_da7219_ops = {
717};
718
Julia Lawallde363642018-10-28 06:56:08 +0100719static const struct regulator_desc acp_da7219_desc = {
Akshu Agrawalc183fec2018-07-25 17:00:59 +0800720 .name = "reg-fixed-1.8V",
721 .type = REGULATOR_VOLTAGE,
722 .owner = THIS_MODULE,
723 .ops = &acp_da7219_ops,
724 .fixed_uV = 1800000, /* 1.8V */
725 .n_voltages = 1,
726};
727
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530728static int cz_probe(struct platform_device *pdev)
729{
730 int ret;
731 struct snd_soc_card *card;
Mukunda, Vijendarccfbb4f2018-05-08 10:17:53 +0530732 struct acp_platform_info *machine;
Akshu Agrawalc183fec2018-07-25 17:00:59 +0800733 struct regulator_dev *rdev;
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530734 struct device *dev = &pdev->dev;
Akshu Agrawalc183fec2018-07-25 17:00:59 +0800735
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530736 card = (struct snd_soc_card *)acp_soc_is_rltk_max(dev);
737 if (!card)
738 return -ENODEV;
739 if (!strcmp(card->name, "acpd7219m98357")) {
740 acp_da7219_cfg.dev = &pdev->dev;
741 rdev = devm_regulator_register(&pdev->dev, &acp_da7219_desc,
742 &acp_da7219_cfg);
743 if (IS_ERR(rdev)) {
744 dev_err(&pdev->dev, "Failed to register regulator: %d\n",
745 (int)PTR_ERR(rdev));
746 return -EINVAL;
747 }
Akshu Agrawalc183fec2018-07-25 17:00:59 +0800748 }
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530749
Mukunda, Vijendarccfbb4f2018-05-08 10:17:53 +0530750 machine = devm_kzalloc(&pdev->dev, sizeof(struct acp_platform_info),
751 GFP_KERNEL);
752 if (!machine)
753 return -ENOMEM;
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530754 card->dev = &pdev->dev;
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530755 platform_set_drvdata(pdev, card);
Mukunda, Vijendarccfbb4f2018-05-08 10:17:53 +0530756 snd_soc_card_set_drvdata(card, machine);
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530757 ret = devm_snd_soc_register_card(&pdev->dev, card);
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530758 if (ret) {
Mario Limonciello71869332021-07-22 08:27:28 -0500759 return dev_err_probe(&pdev->dev, ret,
760 "devm_snd_soc_register_card(%s) failed\n",
761 card->name);
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530762 }
Pierre-Louis Bossart19843302021-09-07 13:42:14 -0500763 acp_bt_uart_enable = !device_property_read_bool(&pdev->dev,
764 "bt-pad-enable");
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530765 return 0;
766}
767
Pierre-Louis Bossartdc1aff72020-07-02 11:44:28 -0500768#ifdef CONFIG_ACPI
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530769static const struct acpi_device_id cz_audio_acpi_match[] = {
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530770 { "AMD7219", (unsigned long)&cz_card },
771 { "AMDI5682", (unsigned long)&cz_rt5682_card},
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530772 {},
773};
774MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match);
Pierre-Louis Bossartdc1aff72020-07-02 11:44:28 -0500775#endif
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530776
777static struct platform_driver cz_pcm_driver = {
778 .driver = {
779 .name = "cz-da7219-max98357a",
780 .acpi_match_table = ACPI_PTR(cz_audio_acpi_match),
781 .pm = &snd_soc_pm_ops,
782 },
783 .probe = cz_probe,
784};
785
786module_platform_driver(cz_pcm_driver);
787
788MODULE_AUTHOR("akshu.agrawal@amd.com");
Vijendar Mukunda7e71b482021-03-19 07:10:42 +0530789MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
790MODULE_DESCRIPTION("DA7219, RT5682 & MAX98357A audio support");
Akshu Agrawal608a300f2018-02-16 13:11:13 +0530791MODULE_LICENSE("GPL v2");