blob: dad70436d063b734aaeebffc354f55da0eb5f080 [file] [log] [blame]
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +05301// SPDX-License-Identifier: GPL-2.0+
2//
3// Machine driver for AMD ACP Audio engine using DA7219 & MAX98357 codec.
4//
5//Copyright 2016 Advanced Micro Devices, Inc.
6
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>
13#include <linux/clk.h>
14#include <linux/gpio.h>
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +053015#include <linux/gpio/consumer.h>
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +053016#include <linux/module.h>
17#include <linux/i2c.h>
18#include <linux/input.h>
YueHaibing14beacc2020-03-04 16:40:57 +080019#include <linux/io.h>
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +053020#include <linux/acpi.h>
21
22#include "raven/acp3x.h"
23#include "../codecs/rt5682.h"
Ravulapati Vishnu vardhan rao414e3ca2020-07-28 21:32:53 +053024#include "../codecs/rt1015.h"
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +053025
26#define PCO_PLAT_CLK 48000000
27#define RT5682_PLL_FREQ (48000 * 512)
28#define DUAL_CHANNEL 2
29
30static struct snd_soc_jack pco_jack;
31static struct clk *rt5682_dai_wclk;
32static struct clk *rt5682_dai_bclk;
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +053033static struct gpio_desc *dmic_sel;
Ravulapati Vishnu vardhan rao0fe4b562020-07-28 21:32:52 +053034void *soc_is_rltk_max(struct device *dev);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +053035
Ravulapati Vishnu vardhan raof7b26512020-07-28 21:32:54 +053036enum {
37 RT5682 = 0,
38 MAX,
39 EC,
40};
41
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +053042static int acp3x_5682_init(struct snd_soc_pcm_runtime *rtd)
43{
44 int ret;
45 struct snd_soc_card *card = rtd->card;
Kuninori Morimotob09b22f2020-03-23 14:17:13 +090046 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +053047 struct snd_soc_component *component = codec_dai->component;
48
49 dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
50
51 /* set rt5682 dai fmt */
52 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
53 | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +010054 | SND_SOC_DAIFMT_CBP_CFP);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +053055 if (ret < 0) {
56 dev_err(rtd->card->dev,
57 "Failed to set rt5682 dai fmt: %d\n", ret);
58 return ret;
59 }
60
61 /* set codec PLL */
62 ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL2, RT5682_PLL2_S_MCLK,
63 PCO_PLAT_CLK, RT5682_PLL_FREQ);
64 if (ret < 0) {
65 dev_err(rtd->dev, "can't set rt5682 PLL: %d\n", ret);
66 return ret;
67 }
68
69 /* Set codec sysclk */
70 ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL2,
71 RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
72 if (ret < 0) {
73 dev_err(rtd->dev,
74 "Failed to set rt5682 SYSCLK: %d\n", ret);
75 return ret;
76 }
77
78 /* Set tdm/i2s1 master bclk ratio */
79 ret = snd_soc_dai_set_bclk_ratio(codec_dai, 64);
80 if (ret < 0) {
81 dev_err(rtd->dev,
82 "Failed to set rt5682 tdm bclk ratio: %d\n", ret);
83 return ret;
84 }
85
86 rt5682_dai_wclk = clk_get(component->dev, "rt5682-dai-wclk");
87 rt5682_dai_bclk = clk_get(component->dev, "rt5682-dai-bclk");
88
89 ret = snd_soc_card_jack_new(card, "Headset Jack",
90 SND_JACK_HEADSET | SND_JACK_LINEOUT |
91 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
92 SND_JACK_BTN_2 | SND_JACK_BTN_3,
93 &pco_jack, NULL, 0);
94 if (ret) {
95 dev_err(card->dev, "HP jack creation failed %d\n", ret);
96 return ret;
97 }
98
99 snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
Akshu Agrawal8dbcfcf2020-04-14 05:35:23 -0600100 snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
101 snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
102 snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530103
104 ret = snd_soc_component_set_jack(component, &pco_jack, NULL);
105 if (ret) {
106 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
107 return ret;
108 }
109
110 return ret;
111}
112
113static int rt5682_clk_enable(struct snd_pcm_substream *substream)
114{
115 int ret = 0;
Kuninori Morimotoded00542020-07-20 10:18:34 +0900116 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530117
118 /* RT5682 will support only 48K output with 48M mclk */
119 clk_set_rate(rt5682_dai_wclk, 48000);
120 clk_set_rate(rt5682_dai_bclk, 48000 * 64);
121 ret = clk_prepare_enable(rt5682_dai_wclk);
122 if (ret < 0) {
123 dev_err(rtd->dev, "can't enable wclk %d\n", ret);
124 return ret;
125 }
126
127 return ret;
128}
129
Ravulapati Vishnu vardhan raoc3936ba92020-07-28 21:32:55 +0530130static int acp3x_1015_hw_params(struct snd_pcm_substream *substream,
131 struct snd_pcm_hw_params *params)
132{
133 struct snd_soc_pcm_runtime *rtd = substream->private_data;
134 struct snd_soc_dai *codec_dai;
135 int srate, i, ret;
136
137 ret = 0;
138 srate = params_rate(params);
139
140 for_each_rtd_codec_dais(rtd, i, codec_dai) {
Ravulapati Vishnu vardhan raoea7dc092020-08-07 21:40:17 +0530141 if (strcmp(codec_dai->name, "rt1015-aif"))
Ravulapati Vishnu vardhan raoc3936ba92020-07-28 21:32:55 +0530142 continue;
Tzung-Bi Shih81a63202020-12-24 18:18:54 +0800143
Ravulapati Vishnu vardhan raoc3936ba92020-07-28 21:32:55 +0530144 ret = snd_soc_dai_set_pll(codec_dai, 0, RT1015_PLL_S_BCLK,
145 64 * srate, 256 * srate);
146 if (ret < 0)
147 return ret;
148 ret = snd_soc_dai_set_sysclk(codec_dai, RT1015_SCLK_S_PLL,
149 256 * srate, SND_SOC_CLOCK_IN);
150 if (ret < 0)
151 return ret;
152 }
153 return ret;
154}
155
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530156static void rt5682_clk_disable(void)
157{
158 clk_disable_unprepare(rt5682_dai_wclk);
159}
160
161static const unsigned int channels[] = {
162 DUAL_CHANNEL,
163};
164
165static const unsigned int rates[] = {
166 48000,
167};
168
169static const struct snd_pcm_hw_constraint_list constraints_rates = {
170 .count = ARRAY_SIZE(rates),
171 .list = rates,
172 .mask = 0,
173};
174
175static const struct snd_pcm_hw_constraint_list constraints_channels = {
176 .count = ARRAY_SIZE(channels),
177 .list = channels,
178 .mask = 0,
179};
180
181static int acp3x_5682_startup(struct snd_pcm_substream *substream)
182{
183 struct snd_pcm_runtime *runtime = substream->runtime;
Kuninori Morimotoded00542020-07-20 10:18:34 +0900184 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530185 struct snd_soc_card *card = rtd->card;
186 struct acp3x_platform_info *machine = snd_soc_card_get_drvdata(card);
187
188 machine->play_i2s_instance = I2S_SP_INSTANCE;
189 machine->cap_i2s_instance = I2S_SP_INSTANCE;
190
191 runtime->hw.channels_max = DUAL_CHANNEL;
192 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
193 &constraints_channels);
194 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
195 &constraints_rates);
196 return rt5682_clk_enable(substream);
197}
198
199static int acp3x_max_startup(struct snd_pcm_substream *substream)
200{
201 struct snd_pcm_runtime *runtime = substream->runtime;
Kuninori Morimotoded00542020-07-20 10:18:34 +0900202 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530203 struct snd_soc_card *card = rtd->card;
204 struct acp3x_platform_info *machine = snd_soc_card_get_drvdata(card);
205
206 machine->play_i2s_instance = I2S_BT_INSTANCE;
207
208 runtime->hw.channels_max = DUAL_CHANNEL;
209 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
210 &constraints_channels);
211 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
212 &constraints_rates);
213 return rt5682_clk_enable(substream);
214}
215
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +0530216static int acp3x_ec_dmic0_startup(struct snd_pcm_substream *substream)
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530217{
Kuninori Morimotoded00542020-07-20 10:18:34 +0900218 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530219 struct snd_soc_card *card = rtd->card;
Kuninori Morimotob09b22f2020-03-23 14:17:13 +0900220 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530221 struct acp3x_platform_info *machine = snd_soc_card_get_drvdata(card);
222
223 machine->cap_i2s_instance = I2S_BT_INSTANCE;
224 snd_soc_dai_set_bclk_ratio(codec_dai, 64);
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +0530225
226 return rt5682_clk_enable(substream);
227}
228
Akshu Agrawalb7a742c2020-05-30 15:25:06 +0530229static int dmic_switch;
230
231static int dmic_get(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_value *ucontrol)
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +0530233{
Akshu Agrawalb7a742c2020-05-30 15:25:06 +0530234 ucontrol->value.integer.value[0] = dmic_switch;
235 return 0;
236}
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +0530237
Akshu Agrawalb7a742c2020-05-30 15:25:06 +0530238static int dmic_set(struct snd_kcontrol *kcontrol,
239 struct snd_ctl_elem_value *ucontrol)
240{
241 if (dmic_sel) {
242 dmic_switch = ucontrol->value.integer.value[0];
243 gpiod_set_value(dmic_sel, dmic_switch);
244 }
245 return 0;
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530246}
247
248static void rt5682_shutdown(struct snd_pcm_substream *substream)
249{
250 rt5682_clk_disable();
251}
252
253static const struct snd_soc_ops acp3x_5682_ops = {
254 .startup = acp3x_5682_startup,
255 .shutdown = rt5682_shutdown,
256};
257
258static const struct snd_soc_ops acp3x_max_play_ops = {
259 .startup = acp3x_max_startup,
260 .shutdown = rt5682_shutdown,
Ravulapati Vishnu vardhan raoc3936ba92020-07-28 21:32:55 +0530261 .hw_params = acp3x_1015_hw_params,
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530262};
263
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +0530264static const struct snd_soc_ops acp3x_ec_cap0_ops = {
265 .startup = acp3x_ec_dmic0_startup,
266 .shutdown = rt5682_shutdown,
267};
268
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530269SND_SOC_DAILINK_DEF(acp3x_i2s,
270 DAILINK_COMP_ARRAY(COMP_CPU("acp3x_i2s_playcap.0")));
271SND_SOC_DAILINK_DEF(acp3x_bt,
272 DAILINK_COMP_ARRAY(COMP_CPU("acp3x_i2s_playcap.2")));
273
274SND_SOC_DAILINK_DEF(rt5682,
275 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1")));
276SND_SOC_DAILINK_DEF(max,
277 DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi")));
Vijendar Mukunda26e33ed2021-04-08 18:32:36 +0530278SND_SOC_DAILINK_DEF(rt1015p,
279 DAILINK_COMP_ARRAY(COMP_CODEC("RTL1015:00", "HiFi")));
Ravulapati Vishnu vardhan raof7b26512020-07-28 21:32:54 +0530280SND_SOC_DAILINK_DEF(rt1015,
281 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC1015:00", "rt1015-aif"),
282 COMP_CODEC("i2c-10EC1015:01", "rt1015-aif")));
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530283SND_SOC_DAILINK_DEF(cros_ec,
284 DAILINK_COMP_ARRAY(COMP_CODEC("GOOG0013:00", "EC Codec I2S RX")));
285
286SND_SOC_DAILINK_DEF(platform,
287 DAILINK_COMP_ARRAY(COMP_PLATFORM("acp3x_rv_i2s_dma.0")));
288
Ravulapati Vishnu vardhan rao414e3ca2020-07-28 21:32:53 +0530289static struct snd_soc_codec_conf rt1015_conf[] = {
290 {
291 .dlc = COMP_CODEC_CONF("i2c-10EC1015:00"),
292 .name_prefix = "Left",
293 },
294 {
295 .dlc = COMP_CODEC_CONF("i2c-10EC1015:01"),
296 .name_prefix = "Right",
297 },
298};
299
300static struct snd_soc_dai_link acp3x_dai[] = {
Ravulapati Vishnu vardhan raof7b26512020-07-28 21:32:54 +0530301 [RT5682] = {
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530302 .name = "acp3x-5682-play",
303 .stream_name = "Playback",
304 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100305 | SND_SOC_DAIFMT_CBP_CFP,
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530306 .init = acp3x_5682_init,
307 .dpcm_playback = 1,
308 .dpcm_capture = 1,
309 .ops = &acp3x_5682_ops,
310 SND_SOC_DAILINK_REG(acp3x_i2s, rt5682, platform),
311 },
Ravulapati Vishnu vardhan raof7b26512020-07-28 21:32:54 +0530312 [MAX] = {
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530313 .name = "acp3x-max98357-play",
314 .stream_name = "HiFi Playback",
315 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100316 | SND_SOC_DAIFMT_CBC_CFC,
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530317 .dpcm_playback = 1,
318 .ops = &acp3x_max_play_ops,
Ravulapati Vishnu vardhan raof7b26512020-07-28 21:32:54 +0530319 .cpus = acp3x_bt,
320 .num_cpus = ARRAY_SIZE(acp3x_bt),
321 .platforms = platform,
322 .num_platforms = ARRAY_SIZE(platform),
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530323 },
Ravulapati Vishnu vardhan raof7b26512020-07-28 21:32:54 +0530324 [EC] = {
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +0530325 .name = "acp3x-ec-dmic0-capture",
326 .stream_name = "Capture DMIC0",
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530327 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
Mark Brown62df2232021-09-15 19:09:57 +0100328 | SND_SOC_DAIFMT_CBC_CFC,
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530329 .dpcm_capture = 1,
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +0530330 .ops = &acp3x_ec_cap0_ops,
331 SND_SOC_DAILINK_REG(acp3x_bt, cros_ec, platform),
332 },
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530333};
334
Akshu Agrawalb7a742c2020-05-30 15:25:06 +0530335static const char * const dmic_mux_text[] = {
336 "Front Mic",
337 "Rear Mic",
338};
339
340static SOC_ENUM_SINGLE_DECL(
341 acp3x_dmic_enum, SND_SOC_NOPM, 0, dmic_mux_text);
342
343static const struct snd_kcontrol_new acp3x_dmic_mux_control =
344 SOC_DAPM_ENUM_EXT("DMIC Select Mux", acp3x_dmic_enum,
345 dmic_get, dmic_set);
346
Ravulapati Vishnu vardhan rao9c04b5a2020-07-28 21:32:51 +0530347static const struct snd_soc_dapm_widget acp3x_5682_widgets[] = {
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530348 SND_SOC_DAPM_HP("Headphone Jack", NULL),
349 SND_SOC_DAPM_SPK("Spk", NULL),
350 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Akshu Agrawalb7a742c2020-05-30 15:25:06 +0530351 SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0,
352 &acp3x_dmic_mux_control),
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530353};
354
Ravulapati Vishnu vardhan rao9c04b5a2020-07-28 21:32:51 +0530355static const struct snd_soc_dapm_route acp3x_5682_audio_route[] = {
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530356 {"Headphone Jack", NULL, "HPOL"},
357 {"Headphone Jack", NULL, "HPOR"},
358 {"IN1P", NULL, "Headset Mic"},
359 {"Spk", NULL, "Speaker"},
Akshu Agrawalb7a742c2020-05-30 15:25:06 +0530360 {"Dmic Mux", "Front Mic", "DMIC"},
361 {"Dmic Mux", "Rear Mic", "DMIC"},
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530362};
363
Ravulapati Vishnu vardhan rao9c04b5a2020-07-28 21:32:51 +0530364static const struct snd_kcontrol_new acp3x_5682_mc_controls[] = {
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530365 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
366 SOC_DAPM_PIN_SWITCH("Spk"),
367 SOC_DAPM_PIN_SWITCH("Headset Mic"),
368};
369
Ravulapati Vishnu vardhan rao9c04b5a2020-07-28 21:32:51 +0530370static struct snd_soc_card acp3x_5682 = {
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530371 .name = "acp3xalc5682m98357",
372 .owner = THIS_MODULE,
Ravulapati Vishnu vardhan rao414e3ca2020-07-28 21:32:53 +0530373 .dai_link = acp3x_dai,
374 .num_links = ARRAY_SIZE(acp3x_dai),
Ravulapati Vishnu vardhan rao9c04b5a2020-07-28 21:32:51 +0530375 .dapm_widgets = acp3x_5682_widgets,
376 .num_dapm_widgets = ARRAY_SIZE(acp3x_5682_widgets),
377 .dapm_routes = acp3x_5682_audio_route,
378 .num_dapm_routes = ARRAY_SIZE(acp3x_5682_audio_route),
379 .controls = acp3x_5682_mc_controls,
380 .num_controls = ARRAY_SIZE(acp3x_5682_mc_controls),
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530381};
382
Ravulapati Vishnu vardhan rao414e3ca2020-07-28 21:32:53 +0530383static const struct snd_soc_dapm_widget acp3x_1015_widgets[] = {
384 SND_SOC_DAPM_HP("Headphone Jack", NULL),
385 SND_SOC_DAPM_MIC("Headset Mic", NULL),
386 SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0,
387 &acp3x_dmic_mux_control),
388 SND_SOC_DAPM_SPK("Left Spk", NULL),
389 SND_SOC_DAPM_SPK("Right Spk", NULL),
390};
391
392static const struct snd_soc_dapm_route acp3x_1015_route[] = {
393 {"Headphone Jack", NULL, "HPOL"},
394 {"Headphone Jack", NULL, "HPOR"},
395 {"IN1P", NULL, "Headset Mic"},
396 {"Dmic Mux", "Front Mic", "DMIC"},
397 {"Dmic Mux", "Rear Mic", "DMIC"},
398 {"Left Spk", NULL, "Left SPO"},
399 {"Right Spk", NULL, "Right SPO"},
400};
401
402static const struct snd_kcontrol_new acp3x_mc_1015_controls[] = {
403 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
404 SOC_DAPM_PIN_SWITCH("Headset Mic"),
405 SOC_DAPM_PIN_SWITCH("Left Spk"),
406 SOC_DAPM_PIN_SWITCH("Right Spk"),
407};
408
409static struct snd_soc_card acp3x_1015 = {
410 .name = "acp3xalc56821015",
411 .owner = THIS_MODULE,
412 .dai_link = acp3x_dai,
413 .num_links = ARRAY_SIZE(acp3x_dai),
414 .dapm_widgets = acp3x_1015_widgets,
415 .num_dapm_widgets = ARRAY_SIZE(acp3x_1015_widgets),
416 .dapm_routes = acp3x_1015_route,
417 .num_dapm_routes = ARRAY_SIZE(acp3x_1015_route),
418 .codec_conf = rt1015_conf,
419 .num_configs = ARRAY_SIZE(rt1015_conf),
420 .controls = acp3x_mc_1015_controls,
421 .num_controls = ARRAY_SIZE(acp3x_mc_1015_controls),
422};
423
Vijendar Mukunda26e33ed2021-04-08 18:32:36 +0530424static const struct snd_soc_dapm_widget acp3x_1015p_widgets[] = {
425 SND_SOC_DAPM_HP("Headphone Jack", NULL),
426 SND_SOC_DAPM_MIC("Headset Mic", NULL),
427 SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0,
428 &acp3x_dmic_mux_control),
429 SND_SOC_DAPM_SPK("Speakers", NULL),
430};
431
432static const struct snd_soc_dapm_route acp3x_1015p_route[] = {
433 {"Headphone Jack", NULL, "HPOL"},
434 {"Headphone Jack", NULL, "HPOR"},
435 {"IN1P", NULL, "Headset Mic"},
436 {"Dmic Mux", "Front Mic", "DMIC"},
437 {"Dmic Mux", "Rear Mic", "DMIC"},
438 /* speaker */
439 { "Speakers", NULL, "Speaker" },
440};
441
442static const struct snd_kcontrol_new acp3x_mc_1015p_controls[] = {
443 SOC_DAPM_PIN_SWITCH("Speakers"),
444 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
445 SOC_DAPM_PIN_SWITCH("Headset Mic"),
446};
447
448static struct snd_soc_card acp3x_1015p = {
449 .name = "acp3xalc56821015p",
450 .owner = THIS_MODULE,
451 .dai_link = acp3x_dai,
452 .num_links = ARRAY_SIZE(acp3x_dai),
453 .dapm_widgets = acp3x_1015p_widgets,
454 .num_dapm_widgets = ARRAY_SIZE(acp3x_1015p_widgets),
455 .dapm_routes = acp3x_1015p_route,
456 .num_dapm_routes = ARRAY_SIZE(acp3x_1015p_route),
457 .controls = acp3x_mc_1015p_controls,
458 .num_controls = ARRAY_SIZE(acp3x_mc_1015p_controls),
459};
460
Ravulapati Vishnu vardhan rao0fe4b562020-07-28 21:32:52 +0530461void *soc_is_rltk_max(struct device *dev)
462{
463 const struct acpi_device_id *match;
464
465 match = acpi_match_device(dev->driver->acpi_match_table, dev);
466 if (!match)
467 return NULL;
468 return (void *)match->driver_data;
469}
470
Ravulapati Vishnu vardhan raof7b26512020-07-28 21:32:54 +0530471static void card_spk_dai_link_present(struct snd_soc_dai_link *links,
472 const char *card_name)
473{
474 if (!strcmp(card_name, "acp3xalc56821015")) {
475 links[1].codecs = rt1015;
476 links[1].num_codecs = ARRAY_SIZE(rt1015);
Vijendar Mukunda26e33ed2021-04-08 18:32:36 +0530477 } else if (!strcmp(card_name, "acp3xalc56821015p")) {
478 links[1].codecs = rt1015p;
479 links[1].num_codecs = ARRAY_SIZE(rt1015p);
Ravulapati Vishnu vardhan raof7b26512020-07-28 21:32:54 +0530480 } else {
481 links[1].codecs = max;
482 links[1].num_codecs = ARRAY_SIZE(max);
483 }
484}
485
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530486static int acp3x_probe(struct platform_device *pdev)
487{
488 int ret;
489 struct snd_soc_card *card;
490 struct acp3x_platform_info *machine;
Ravulapati Vishnu vardhan rao0fe4b562020-07-28 21:32:52 +0530491 struct device *dev = &pdev->dev;
492
493 card = (struct snd_soc_card *)soc_is_rltk_max(dev);
494 if (!card)
495 return -ENODEV;
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530496
497 machine = devm_kzalloc(&pdev->dev, sizeof(*machine), GFP_KERNEL);
498 if (!machine)
499 return -ENOMEM;
500
Ravulapati Vishnu vardhan raof7b26512020-07-28 21:32:54 +0530501 card_spk_dai_link_present(card->dai_link, card->name);
Ravulapati Vishnu vardhan rao0fe4b562020-07-28 21:32:52 +0530502 card->dev = &pdev->dev;
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530503 platform_set_drvdata(pdev, card);
504 snd_soc_card_set_drvdata(card, machine);
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +0530505
506 dmic_sel = devm_gpiod_get(&pdev->dev, "dmic", GPIOD_OUT_LOW);
507 if (IS_ERR(dmic_sel)) {
Akshu Agrawald7729c42020-03-03 14:34:37 +0530508 dev_err(&pdev->dev, "DMIC gpio failed err=%ld\n",
Akshu Agrawal72c3b2b2020-03-02 13:54:36 +0530509 PTR_ERR(dmic_sel));
510 return PTR_ERR(dmic_sel);
511 }
512
Ravulapati Vishnu vardhan rao0fe4b562020-07-28 21:32:52 +0530513 ret = devm_snd_soc_register_card(&pdev->dev, card);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530514 if (ret) {
Mario Limonciello71869332021-07-22 08:27:28 -0500515 return dev_err_probe(&pdev->dev, ret,
516 "devm_snd_soc_register_card(%s) failed\n",
517 card->name);
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530518 }
Mario Limonciello71869332021-07-22 08:27:28 -0500519 return 0;
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530520}
521
522static const struct acpi_device_id acp3x_audio_acpi_match[] = {
Ravulapati Vishnu vardhan rao0fe4b562020-07-28 21:32:52 +0530523 { "AMDI5682", (unsigned long)&acp3x_5682},
Ravulapati Vishnu vardhan rao414e3ca2020-07-28 21:32:53 +0530524 { "AMDI1015", (unsigned long)&acp3x_1015},
Vijendar Mukunda26e33ed2021-04-08 18:32:36 +0530525 { "10021015", (unsigned long)&acp3x_1015p},
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530526 {},
527};
528MODULE_DEVICE_TABLE(acpi, acp3x_audio_acpi_match);
529
530static struct platform_driver acp3x_audio = {
531 .driver = {
532 .name = "acp3x-alc5682-max98357",
533 .acpi_match_table = ACPI_PTR(acp3x_audio_acpi_match),
534 .pm = &snd_soc_pm_ops,
535 },
536 .probe = acp3x_probe,
537};
538
539module_platform_driver(acp3x_audio);
540
541MODULE_AUTHOR("akshu.agrawal@amd.com");
Ravulapati Vishnu vardhan rao414e3ca2020-07-28 21:32:53 +0530542MODULE_AUTHOR("Vishnuvardhanrao.Ravulapati@amd.com");
Vijendar Mukunda26e33ed2021-04-08 18:32:36 +0530543MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
544MODULE_DESCRIPTION("ALC5682 ALC1015, ALC1015P & MAX98357 audio support");
Akshu Agrawal6b8e4e72020-02-17 10:35:01 +0530545MODULE_LICENSE("GPL v2");