1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2019-2020 Intel Corporation.
3
4 /*
5 * Intel SOF Machine Driver with Realtek rt5682 Codec
6 * and speaker codec MAX98357A or RT1015.
7 */
8 #include <linux/i2c.h>
9 #include <linux/input.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/clk.h>
13 #include <linux/dmi.h>
14 #include <sound/core.h>
15 #include <sound/jack.h>
16 #include <sound/pcm.h>
17 #include <sound/pcm_params.h>
18 #include <sound/soc.h>
19 #include <sound/sof.h>
20 #include <sound/rt5682.h>
21 #include <sound/rt5682s.h>
22 #include <sound/soc-acpi.h>
23 #include "../../codecs/rt5682.h"
24 #include "../../codecs/rt5682s.h"
25 #include "../../codecs/rt5645.h"
26 #include "../../codecs/hdac_hdmi.h"
27 #include "../common/soc-intel-quirks.h"
28 #include "hda_dsp_common.h"
29 #include "sof_maxim_common.h"
30 #include "sof_realtek_common.h"
31
32 #define NAME_SIZE 32
33
34 #define SOF_RT5682_SSP_CODEC(quirk) ((quirk) & GENMASK(2, 0))
35 #define SOF_RT5682_SSP_CODEC_MASK (GENMASK(2, 0))
36 #define SOF_RT5682_MCLK_EN BIT(3)
37 #define SOF_RT5682_MCLK_24MHZ BIT(4)
38 #define SOF_SPEAKER_AMP_PRESENT BIT(5)
39 #define SOF_RT5682_SSP_AMP_SHIFT 6
40 #define SOF_RT5682_SSP_AMP_MASK (GENMASK(8, 6))
41 #define SOF_RT5682_SSP_AMP(quirk) \
42 (((quirk) << SOF_RT5682_SSP_AMP_SHIFT) & SOF_RT5682_SSP_AMP_MASK)
43 #define SOF_RT5682_MCLK_BYTCHT_EN BIT(9)
44 #define SOF_RT5682_NUM_HDMIDEV_SHIFT 10
45 #define SOF_RT5682_NUM_HDMIDEV_MASK (GENMASK(12, 10))
46 #define SOF_RT5682_NUM_HDMIDEV(quirk) \
47 ((quirk << SOF_RT5682_NUM_HDMIDEV_SHIFT) & SOF_RT5682_NUM_HDMIDEV_MASK)
48 #define SOF_RT1011_SPEAKER_AMP_PRESENT BIT(13)
49 #define SOF_RT1015_SPEAKER_AMP_PRESENT BIT(14)
50 #define SOF_RT1015P_SPEAKER_AMP_PRESENT BIT(16)
51 #define SOF_MAX98373_SPEAKER_AMP_PRESENT BIT(17)
52 #define SOF_MAX98360A_SPEAKER_AMP_PRESENT BIT(18)
53
54 /* BT audio offload: reserve 3 bits for future */
55 #define SOF_BT_OFFLOAD_SSP_SHIFT 19
56 #define SOF_BT_OFFLOAD_SSP_MASK (GENMASK(21, 19))
57 #define SOF_BT_OFFLOAD_SSP(quirk) \
58 (((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK)
59 #define SOF_SSP_BT_OFFLOAD_PRESENT BIT(22)
60 #define SOF_RT5682S_HEADPHONE_CODEC_PRESENT BIT(23)
61 #define SOF_MAX98390_SPEAKER_AMP_PRESENT BIT(24)
62 #define SOF_RT1019_SPEAKER_AMP_PRESENT BIT(26)
63 #define SOF_RT5650_HEADPHONE_CODEC_PRESENT BIT(27)
64
65 /* HDMI capture*/
66 #define SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT 27
67 #define SOF_SSP_HDMI_CAPTURE_PRESENT_MASK (GENMASK(30, 27))
68 #define SOF_HDMI_CAPTURE_SSP_MASK(quirk) \
69 (((quirk) << SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT) & SOF_SSP_HDMI_CAPTURE_PRESENT_MASK)
70
71 /* Default: MCLK on, MCLK 19.2M, SSP0 */
72 static unsigned long sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
73 SOF_RT5682_SSP_CODEC(0);
74
75 static int is_legacy_cpu;
76
77 struct sof_hdmi_pcm {
78 struct list_head head;
79 struct snd_soc_dai *codec_dai;
80 struct snd_soc_jack hdmi_jack;
81 int device;
82 };
83
84 struct sof_card_private {
85 struct clk *mclk;
86 struct snd_soc_jack sof_headset;
87 struct list_head hdmi_pcm_list;
88 bool common_hdmi_codec_drv;
89 bool idisp_codec;
90 };
91
sof_rt5682_quirk_cb(const struct dmi_system_id * id)92 static int sof_rt5682_quirk_cb(const struct dmi_system_id *id)
93 {
94 sof_rt5682_quirk = (unsigned long)id->driver_data;
95 return 1;
96 }
97
98 static const struct dmi_system_id sof_rt5682_quirk_table[] = {
99 {
100 .callback = sof_rt5682_quirk_cb,
101 .matches = {
102 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
103 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max"),
104 },
105 .driver_data = (void *)(SOF_RT5682_SSP_CODEC(2)),
106 },
107 {
108 .callback = sof_rt5682_quirk_cb,
109 .matches = {
110 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
111 DMI_MATCH(DMI_PRODUCT_NAME, "UP-CHT01"),
112 },
113 .driver_data = (void *)(SOF_RT5682_SSP_CODEC(2)),
114 },
115 {
116 .callback = sof_rt5682_quirk_cb,
117 .matches = {
118 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
119 DMI_MATCH(DMI_PRODUCT_NAME, "WhiskeyLake Client"),
120 },
121 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
122 SOF_RT5682_MCLK_24MHZ |
123 SOF_RT5682_SSP_CODEC(1)),
124 },
125 {
126 /*
127 * Dooly is hatch family but using rt1015 amp so it
128 * requires a quirk before "Google_Hatch".
129 */
130 .callback = sof_rt5682_quirk_cb,
131 .matches = {
132 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
133 DMI_MATCH(DMI_PRODUCT_NAME, "Dooly"),
134 },
135 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
136 SOF_RT5682_MCLK_24MHZ |
137 SOF_RT5682_SSP_CODEC(0) |
138 SOF_SPEAKER_AMP_PRESENT |
139 SOF_RT1015_SPEAKER_AMP_PRESENT |
140 SOF_RT5682_SSP_AMP(1)),
141 },
142 {
143 .callback = sof_rt5682_quirk_cb,
144 .matches = {
145 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Hatch"),
146 },
147 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
148 SOF_RT5682_MCLK_24MHZ |
149 SOF_RT5682_SSP_CODEC(0) |
150 SOF_SPEAKER_AMP_PRESENT |
151 SOF_RT5682_SSP_AMP(1)),
152 },
153 {
154 .callback = sof_rt5682_quirk_cb,
155 .matches = {
156 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
157 DMI_MATCH(DMI_PRODUCT_NAME, "Ice Lake Client"),
158 },
159 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
160 SOF_RT5682_SSP_CODEC(0)),
161 },
162 {
163 .callback = sof_rt5682_quirk_cb,
164 .matches = {
165 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
166 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
167 },
168 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
169 SOF_RT5682_SSP_CODEC(0) |
170 SOF_SPEAKER_AMP_PRESENT |
171 SOF_MAX98373_SPEAKER_AMP_PRESENT |
172 SOF_RT5682_SSP_AMP(2) |
173 SOF_RT5682_NUM_HDMIDEV(4)),
174 },
175 {
176 .callback = sof_rt5682_quirk_cb,
177 .matches = {
178 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
179 DMI_MATCH(DMI_PRODUCT_NAME, "Alder Lake Client Platform"),
180 DMI_MATCH(DMI_OEM_STRING, "AUDIO-ADL_MAX98373_ALC5682I_I2S"),
181 },
182 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
183 SOF_RT5682_SSP_CODEC(0) |
184 SOF_SPEAKER_AMP_PRESENT |
185 SOF_MAX98373_SPEAKER_AMP_PRESENT |
186 SOF_RT5682_SSP_AMP(2) |
187 SOF_RT5682_NUM_HDMIDEV(4)),
188 },
189 {
190 .callback = sof_rt5682_quirk_cb,
191 .matches = {
192 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
193 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S"),
194 },
195 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
196 SOF_RT5682_SSP_CODEC(0) |
197 SOF_SPEAKER_AMP_PRESENT |
198 SOF_MAX98390_SPEAKER_AMP_PRESENT |
199 SOF_RT5682_SSP_AMP(2) |
200 SOF_RT5682_NUM_HDMIDEV(4)),
201 },
202 {
203 .callback = sof_rt5682_quirk_cb,
204 .matches = {
205 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
206 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S_AMP_SSP2"),
207 },
208 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
209 SOF_RT5682_SSP_CODEC(0) |
210 SOF_SPEAKER_AMP_PRESENT |
211 SOF_MAX98360A_SPEAKER_AMP_PRESENT |
212 SOF_RT5682_SSP_AMP(2) |
213 SOF_RT5682_NUM_HDMIDEV(4)),
214 },
215 {
216 .callback = sof_rt5682_quirk_cb,
217 .matches = {
218 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Rex"),
219 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S"),
220 },
221 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
222 SOF_RT5682_SSP_CODEC(2) |
223 SOF_SPEAKER_AMP_PRESENT |
224 SOF_MAX98360A_SPEAKER_AMP_PRESENT |
225 SOF_RT5682_SSP_AMP(0) |
226 SOF_RT5682_NUM_HDMIDEV(4) |
227 SOF_BT_OFFLOAD_SSP(1) |
228 SOF_SSP_BT_OFFLOAD_PRESENT
229 ),
230 },
231 {
232 .callback = sof_rt5682_quirk_cb,
233 .matches = {
234 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Rex"),
235 DMI_MATCH(DMI_OEM_STRING, "AUDIO-ALC1019_ALC5682I_I2S"),
236 },
237 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
238 SOF_RT5682_SSP_CODEC(2) |
239 SOF_SPEAKER_AMP_PRESENT |
240 SOF_RT1019_SPEAKER_AMP_PRESENT |
241 SOF_RT5682_SSP_AMP(0) |
242 SOF_RT5682_NUM_HDMIDEV(3)
243 ),
244 },
245 {
246 .callback = sof_rt5682_quirk_cb,
247 .matches = {
248 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Rex"),
249 },
250 .driver_data = (void *)(SOF_RT5682_MCLK_EN |
251 SOF_RT5682_SSP_CODEC(2) |
252 SOF_SPEAKER_AMP_PRESENT |
253 SOF_RT5682_SSP_AMP(0) |
254 SOF_RT5682_NUM_HDMIDEV(4) |
255 SOF_BT_OFFLOAD_SSP(1) |
256 SOF_SSP_BT_OFFLOAD_PRESENT
257 ),
258 },
259 {}
260 };
261
sof_hdmi_init(struct snd_soc_pcm_runtime * rtd)262 static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
263 {
264 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
265 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
266 struct sof_hdmi_pcm *pcm;
267
268 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
269 if (!pcm)
270 return -ENOMEM;
271
272 /* dai_link id is 1:1 mapped to the PCM device */
273 pcm->device = rtd->dai_link->id;
274 pcm->codec_dai = dai;
275
276 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
277
278 return 0;
279 }
280
281 static struct snd_soc_jack_pin jack_pins[] = {
282 {
283 .pin = "Headphone Jack",
284 .mask = SND_JACK_HEADPHONE,
285 },
286 {
287 .pin = "Headset Mic",
288 .mask = SND_JACK_MICROPHONE,
289 },
290 };
291
sof_rt5682_codec_init(struct snd_soc_pcm_runtime * rtd)292 static int sof_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
293 {
294 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
295 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
296 struct snd_soc_jack *jack;
297 int extra_jack_data;
298 int ret;
299
300 /* need to enable ASRC function for 24MHz mclk rate */
301 if ((sof_rt5682_quirk & SOF_RT5682_MCLK_EN) &&
302 (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ)) {
303 if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT)
304 rt5682s_sel_asrc_clk_src(component,
305 RT5682S_DA_STEREO1_FILTER |
306 RT5682S_AD_STEREO1_FILTER,
307 RT5682S_CLK_SEL_I2S1_ASRC);
308 else if (sof_rt5682_quirk & SOF_RT5650_HEADPHONE_CODEC_PRESENT) {
309 rt5645_sel_asrc_clk_src(component,
310 RT5645_DA_STEREO_FILTER |
311 RT5645_AD_STEREO_FILTER,
312 RT5645_CLK_SEL_I2S1_ASRC);
313 rt5645_sel_asrc_clk_src(component,
314 RT5645_DA_MONO_L_FILTER |
315 RT5645_DA_MONO_R_FILTER,
316 RT5645_CLK_SEL_I2S2_ASRC);
317 } else
318 rt5682_sel_asrc_clk_src(component,
319 RT5682_DA_STEREO1_FILTER |
320 RT5682_AD_STEREO1_FILTER,
321 RT5682_CLK_SEL_I2S1_ASRC);
322 }
323
324 if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
325 /*
326 * The firmware might enable the clock at
327 * boot (this information may or may not
328 * be reflected in the enable clock register).
329 * To change the rate we must disable the clock
330 * first to cover these cases. Due to common
331 * clock framework restrictions that do not allow
332 * to disable a clock that has not been enabled,
333 * we need to enable the clock first.
334 */
335 ret = clk_prepare_enable(ctx->mclk);
336 if (!ret)
337 clk_disable_unprepare(ctx->mclk);
338
339 ret = clk_set_rate(ctx->mclk, 19200000);
340
341 if (ret)
342 dev_err(rtd->dev, "unable to set MCLK rate\n");
343 }
344
345 /*
346 * Headset buttons map to the google Reference headset.
347 * These can be configured by userspace.
348 */
349 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
350 SND_JACK_HEADSET | SND_JACK_BTN_0 |
351 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
352 SND_JACK_BTN_3,
353 &ctx->sof_headset,
354 jack_pins,
355 ARRAY_SIZE(jack_pins));
356 if (ret) {
357 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
358 return ret;
359 }
360
361 jack = &ctx->sof_headset;
362
363 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
364 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
365 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
366 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
367
368 if (sof_rt5682_quirk & SOF_RT5650_HEADPHONE_CODEC_PRESENT) {
369 extra_jack_data = SND_JACK_MICROPHONE | SND_JACK_BTN_0;
370 ret = snd_soc_component_set_jack(component, jack, &extra_jack_data);
371 } else
372 ret = snd_soc_component_set_jack(component, jack, NULL);
373
374 if (ret) {
375 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
376 return ret;
377 }
378
379 return ret;
380 };
381
sof_rt5682_codec_exit(struct snd_soc_pcm_runtime * rtd)382 static void sof_rt5682_codec_exit(struct snd_soc_pcm_runtime *rtd)
383 {
384 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
385
386 snd_soc_component_set_jack(component, NULL, NULL);
387 }
388
sof_rt5682_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)389 static int sof_rt5682_hw_params(struct snd_pcm_substream *substream,
390 struct snd_pcm_hw_params *params)
391 {
392 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
393 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
394 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
395 int pll_id, pll_source, pll_in, pll_out, clk_id, ret;
396
397 if (sof_rt5682_quirk & SOF_RT5682_MCLK_EN) {
398 if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
399 ret = clk_prepare_enable(ctx->mclk);
400 if (ret < 0) {
401 dev_err(rtd->dev,
402 "could not configure MCLK state");
403 return ret;
404 }
405 }
406
407 if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT)
408 pll_source = RT5682S_PLL_S_MCLK;
409 else if (sof_rt5682_quirk & SOF_RT5650_HEADPHONE_CODEC_PRESENT)
410 pll_source = RT5645_PLL1_S_MCLK;
411 else
412 pll_source = RT5682_PLL1_S_MCLK;
413
414 /* get the tplg configured mclk. */
415 pll_in = sof_dai_get_mclk(rtd);
416
417 /* mclk from the quirk is the first choice */
418 if (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ) {
419 if (pll_in != 24000000)
420 dev_warn(rtd->dev, "configure wrong mclk in tplg, please use 24MHz.\n");
421 pll_in = 24000000;
422 } else if (pll_in == 0) {
423 /* use default mclk if not specified correct in topology */
424 pll_in = 19200000;
425 } else if (pll_in < 0) {
426 return pll_in;
427 }
428 } else {
429 if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT)
430 pll_source = RT5682S_PLL_S_BCLK1;
431 else if (sof_rt5682_quirk & SOF_RT5650_HEADPHONE_CODEC_PRESENT)
432 pll_source = RT5645_PLL1_S_BCLK1;
433 else
434 pll_source = RT5682_PLL1_S_BCLK1;
435
436 pll_in = params_rate(params) * 50;
437 }
438
439 if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT) {
440 pll_id = RT5682S_PLL2;
441 clk_id = RT5682S_SCLK_S_PLL2;
442 } else if (sof_rt5682_quirk & SOF_RT5650_HEADPHONE_CODEC_PRESENT) {
443 pll_id = 0; /* not used in codec driver */
444 clk_id = RT5645_SCLK_S_PLL1;
445 } else {
446 pll_id = RT5682_PLL1;
447 clk_id = RT5682_SCLK_S_PLL1;
448 }
449
450 pll_out = params_rate(params) * 512;
451
452 /* when MCLK is 512FS, no need to set PLL configuration additionally. */
453 if (pll_in == pll_out)
454 clk_id = RT5682S_SCLK_S_MCLK;
455 else {
456 /* Configure pll for codec */
457 ret = snd_soc_dai_set_pll(codec_dai, pll_id, pll_source, pll_in,
458 pll_out);
459 if (ret < 0)
460 dev_err(rtd->dev, "snd_soc_dai_set_pll err = %d\n", ret);
461 }
462
463 /* Configure sysclk for codec */
464 ret = snd_soc_dai_set_sysclk(codec_dai, clk_id,
465 pll_out, SND_SOC_CLOCK_IN);
466 if (ret < 0)
467 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
468
469 /*
470 * slot_width should equal or large than data length, set them
471 * be the same
472 */
473 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2,
474 params_width(params));
475 if (ret < 0) {
476 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
477 return ret;
478 }
479
480 return ret;
481 }
482
483 static struct snd_soc_ops sof_rt5682_ops = {
484 .hw_params = sof_rt5682_hw_params,
485 };
486
487 static struct snd_soc_dai_link_component platform_component[] = {
488 {
489 /* name might be overridden during probe */
490 .name = "0000:00:1f.3"
491 }
492 };
493
sof_card_late_probe(struct snd_soc_card * card)494 static int sof_card_late_probe(struct snd_soc_card *card)
495 {
496 struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
497 struct snd_soc_component *component = NULL;
498 struct snd_soc_dapm_context *dapm = &card->dapm;
499 char jack_name[NAME_SIZE];
500 struct sof_hdmi_pcm *pcm;
501 int err;
502
503 if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT) {
504 /* Disable Left and Right Spk pin after boot */
505 snd_soc_dapm_disable_pin(dapm, "Left Spk");
506 snd_soc_dapm_disable_pin(dapm, "Right Spk");
507 err = snd_soc_dapm_sync(dapm);
508 if (err < 0)
509 return err;
510 }
511
512 /* HDMI is not supported by SOF on Baytrail/CherryTrail */
513 if (is_legacy_cpu || !ctx->idisp_codec)
514 return 0;
515
516 if (list_empty(&ctx->hdmi_pcm_list))
517 return -EINVAL;
518
519 if (ctx->common_hdmi_codec_drv) {
520 pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm,
521 head);
522 component = pcm->codec_dai->component;
523 return hda_dsp_hdmi_build_controls(card, component);
524 }
525
526 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
527 component = pcm->codec_dai->component;
528 snprintf(jack_name, sizeof(jack_name),
529 "HDMI/DP, pcm=%d Jack", pcm->device);
530 err = snd_soc_card_jack_new(card, jack_name,
531 SND_JACK_AVOUT, &pcm->hdmi_jack);
532
533 if (err)
534 return err;
535
536 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
537 &pcm->hdmi_jack);
538 if (err < 0)
539 return err;
540 }
541
542 return hdac_hdmi_jack_port_init(component, &card->dapm);
543 }
544
545 static const struct snd_kcontrol_new sof_controls[] = {
546 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
547 SOC_DAPM_PIN_SWITCH("Headset Mic"),
548 SOC_DAPM_PIN_SWITCH("Left Spk"),
549 SOC_DAPM_PIN_SWITCH("Right Spk"),
550
551 };
552
553 static const struct snd_soc_dapm_widget sof_widgets[] = {
554 SND_SOC_DAPM_HP("Headphone Jack", NULL),
555 SND_SOC_DAPM_MIC("Headset Mic", NULL),
556 SND_SOC_DAPM_SPK("Left Spk", NULL),
557 SND_SOC_DAPM_SPK("Right Spk", NULL),
558 };
559
560 static const struct snd_soc_dapm_widget dmic_widgets[] = {
561 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
562 };
563
564 static const struct snd_soc_dapm_route sof_map[] = {
565 /* HP jack connectors - unknown if we have jack detection */
566 { "Headphone Jack", NULL, "HPOL" },
567 { "Headphone Jack", NULL, "HPOR" },
568
569 /* other jacks */
570 { "IN1P", NULL, "Headset Mic" },
571 };
572
573 static const struct snd_soc_dapm_route rt5650_spk_dapm_routes[] = {
574 /* speaker */
575 { "Left Spk", NULL, "SPOL" },
576 { "Right Spk", NULL, "SPOR" },
577 };
578
579 static const struct snd_soc_dapm_route dmic_map[] = {
580 /* digital mics */
581 {"DMic", NULL, "SoC DMIC"},
582 };
583
rt5650_spk_init(struct snd_soc_pcm_runtime * rtd)584 static int rt5650_spk_init(struct snd_soc_pcm_runtime *rtd)
585 {
586 struct snd_soc_card *card = rtd->card;
587 int ret;
588
589 ret = snd_soc_dapm_add_routes(&card->dapm, rt5650_spk_dapm_routes,
590 ARRAY_SIZE(rt5650_spk_dapm_routes));
591 if (ret)
592 dev_err(rtd->dev, "fail to add dapm routes, ret=%d\n", ret);
593
594 return ret;
595 }
596
dmic_init(struct snd_soc_pcm_runtime * rtd)597 static int dmic_init(struct snd_soc_pcm_runtime *rtd)
598 {
599 struct snd_soc_card *card = rtd->card;
600 int ret;
601
602 ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
603 ARRAY_SIZE(dmic_widgets));
604 if (ret) {
605 dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
606 /* Don't need to add routes if widget addition failed */
607 return ret;
608 }
609
610 ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
611 ARRAY_SIZE(dmic_map));
612
613 if (ret)
614 dev_err(card->dev, "DMic map addition failed: %d\n", ret);
615
616 return ret;
617 }
618
619 /* sof audio machine driver for rt5682 codec */
620 static struct snd_soc_card sof_audio_card_rt5682 = {
621 .name = "rt5682", /* the sof- prefix is added by the core */
622 .owner = THIS_MODULE,
623 .controls = sof_controls,
624 .num_controls = ARRAY_SIZE(sof_controls),
625 .dapm_widgets = sof_widgets,
626 .num_dapm_widgets = ARRAY_SIZE(sof_widgets),
627 .dapm_routes = sof_map,
628 .num_dapm_routes = ARRAY_SIZE(sof_map),
629 .fully_routed = true,
630 .late_probe = sof_card_late_probe,
631 };
632
633 static struct snd_soc_dai_link_component rt5682_component[] = {
634 {
635 .name = "i2c-10EC5682:00",
636 .dai_name = "rt5682-aif1",
637 }
638 };
639
640 static struct snd_soc_dai_link_component rt5682s_component[] = {
641 {
642 .name = "i2c-RTL5682:00",
643 .dai_name = "rt5682s-aif1",
644 }
645 };
646
647 static struct snd_soc_dai_link_component rt5650_components[] = {
648 {
649 .name = "i2c-10EC5650:00",
650 .dai_name = "rt5645-aif1",
651 },
652 {
653 .name = "i2c-10EC5650:00",
654 .dai_name = "rt5645-aif2",
655 }
656 };
657
658 static struct snd_soc_dai_link_component dmic_component[] = {
659 {
660 .name = "dmic-codec",
661 .dai_name = "dmic-hifi",
662 }
663 };
664
665 #define IDISP_CODEC_MASK 0x4
666
sof_card_dai_links_create(struct device * dev,int ssp_codec,int ssp_amp,int dmic_be_num,int hdmi_num,bool idisp_codec)667 static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
668 int ssp_codec,
669 int ssp_amp,
670 int dmic_be_num,
671 int hdmi_num,
672 bool idisp_codec)
673 {
674 struct snd_soc_dai_link_component *idisp_components;
675 struct snd_soc_dai_link_component *cpus;
676 struct snd_soc_dai_link *links;
677 int i, id = 0;
678 int hdmi_id_offset = 0;
679
680 links = devm_kcalloc(dev, sof_audio_card_rt5682.num_links,
681 sizeof(struct snd_soc_dai_link), GFP_KERNEL);
682 cpus = devm_kcalloc(dev, sof_audio_card_rt5682.num_links,
683 sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
684 if (!links || !cpus)
685 goto devm_err;
686
687 /* codec SSP */
688 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
689 "SSP%d-Codec", ssp_codec);
690 if (!links[id].name)
691 goto devm_err;
692
693 links[id].id = id;
694 if (sof_rt5682_quirk & SOF_RT5682S_HEADPHONE_CODEC_PRESENT) {
695 links[id].codecs = rt5682s_component;
696 links[id].num_codecs = ARRAY_SIZE(rt5682s_component);
697 } else if (sof_rt5682_quirk & SOF_RT5650_HEADPHONE_CODEC_PRESENT) {
698 links[id].codecs = &rt5650_components[0];
699 links[id].num_codecs = 1;
700 } else {
701 links[id].codecs = rt5682_component;
702 links[id].num_codecs = ARRAY_SIZE(rt5682_component);
703 }
704 links[id].platforms = platform_component;
705 links[id].num_platforms = ARRAY_SIZE(platform_component);
706 links[id].init = sof_rt5682_codec_init;
707 links[id].exit = sof_rt5682_codec_exit;
708 links[id].ops = &sof_rt5682_ops;
709 links[id].dpcm_playback = 1;
710 links[id].dpcm_capture = 1;
711 links[id].no_pcm = 1;
712 links[id].cpus = &cpus[id];
713 links[id].num_cpus = 1;
714 if (is_legacy_cpu) {
715 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
716 "ssp%d-port",
717 ssp_codec);
718 if (!links[id].cpus->dai_name)
719 goto devm_err;
720 } else {
721 /*
722 * Currently, On SKL+ platforms MCLK will be turned off in sof
723 * runtime suspended, and it will go into runtime suspended
724 * right after playback is stop. However, rt5682 will output
725 * static noise if sysclk turns off during playback. Set
726 * ignore_pmdown_time to power down rt5682 immediately and
727 * avoid the noise.
728 * It can be removed once we can control MCLK by driver.
729 */
730 links[id].ignore_pmdown_time = 1;
731 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
732 "SSP%d Pin",
733 ssp_codec);
734 if (!links[id].cpus->dai_name)
735 goto devm_err;
736 }
737 id++;
738
739 /* dmic */
740 if (dmic_be_num > 0) {
741 /* at least we have dmic01 */
742 links[id].name = "dmic01";
743 links[id].cpus = &cpus[id];
744 links[id].cpus->dai_name = "DMIC01 Pin";
745 links[id].init = dmic_init;
746 if (dmic_be_num > 1) {
747 /* set up 2 BE links at most */
748 links[id + 1].name = "dmic16k";
749 links[id + 1].cpus = &cpus[id + 1];
750 links[id + 1].cpus->dai_name = "DMIC16k Pin";
751 dmic_be_num = 2;
752 }
753 }
754
755 for (i = 0; i < dmic_be_num; i++) {
756 links[id].id = id;
757 links[id].num_cpus = 1;
758 links[id].codecs = dmic_component;
759 links[id].num_codecs = ARRAY_SIZE(dmic_component);
760 links[id].platforms = platform_component;
761 links[id].num_platforms = ARRAY_SIZE(platform_component);
762 links[id].ignore_suspend = 1;
763 links[id].dpcm_capture = 1;
764 links[id].no_pcm = 1;
765 id++;
766 }
767
768 /* HDMI */
769 if (hdmi_num > 0) {
770 idisp_components = devm_kcalloc(dev,
771 hdmi_num,
772 sizeof(struct snd_soc_dai_link_component),
773 GFP_KERNEL);
774 if (!idisp_components)
775 goto devm_err;
776 }
777 for (i = 1; i <= hdmi_num; i++) {
778 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
779 "iDisp%d", i);
780 if (!links[id].name)
781 goto devm_err;
782
783 links[id].id = id;
784 links[id].cpus = &cpus[id];
785 links[id].num_cpus = 1;
786 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
787 "iDisp%d Pin", i);
788 if (!links[id].cpus->dai_name)
789 goto devm_err;
790
791 if (idisp_codec) {
792 idisp_components[i - 1].name = "ehdaudio0D2";
793 idisp_components[i - 1].dai_name = devm_kasprintf(dev,
794 GFP_KERNEL,
795 "intel-hdmi-hifi%d",
796 i);
797 if (!idisp_components[i - 1].dai_name)
798 goto devm_err;
799 } else {
800 idisp_components[i - 1] = asoc_dummy_dlc;
801 }
802
803 links[id].codecs = &idisp_components[i - 1];
804 links[id].num_codecs = 1;
805 links[id].platforms = platform_component;
806 links[id].num_platforms = ARRAY_SIZE(platform_component);
807 links[id].init = sof_hdmi_init;
808 links[id].dpcm_playback = 1;
809 links[id].no_pcm = 1;
810 id++;
811 }
812
813 /* speaker amp */
814 if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT) {
815 links[id].name = devm_kasprintf(dev, GFP_KERNEL,
816 "SSP%d-Codec", ssp_amp);
817 if (!links[id].name)
818 goto devm_err;
819
820 links[id].id = id;
821 if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_PRESENT) {
822 sof_rt1015_dai_link(&links[id]);
823 } else if (sof_rt5682_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT) {
824 sof_rt1015p_dai_link(&links[id]);
825 } else if (sof_rt5682_quirk & SOF_RT1019_SPEAKER_AMP_PRESENT) {
826 sof_rt1019p_dai_link(&links[id]);
827 } else if (sof_rt5682_quirk &
828 SOF_MAX98373_SPEAKER_AMP_PRESENT) {
829 links[id].codecs = max_98373_components;
830 links[id].num_codecs = ARRAY_SIZE(max_98373_components);
831 links[id].init = max_98373_spk_codec_init;
832 links[id].ops = &max_98373_ops;
833 } else if (sof_rt5682_quirk &
834 SOF_MAX98360A_SPEAKER_AMP_PRESENT) {
835 max_98360a_dai_link(&links[id]);
836 } else if (sof_rt5682_quirk &
837 SOF_RT1011_SPEAKER_AMP_PRESENT) {
838 sof_rt1011_dai_link(&links[id]);
839 } else if (sof_rt5682_quirk &
840 SOF_MAX98390_SPEAKER_AMP_PRESENT) {
841 max_98390_dai_link(dev, &links[id]);
842 } else if (sof_rt5682_quirk & SOF_RT5650_HEADPHONE_CODEC_PRESENT) {
843 links[id].codecs = &rt5650_components[1];
844 links[id].num_codecs = 1;
845 links[id].init = rt5650_spk_init;
846 links[id].ops = &sof_rt5682_ops;
847 } else {
848 max_98357a_dai_link(&links[id]);
849 }
850 links[id].platforms = platform_component;
851 links[id].num_platforms = ARRAY_SIZE(platform_component);
852 links[id].dpcm_playback = 1;
853 /* feedback stream or firmware-generated echo reference */
854 links[id].dpcm_capture = 1;
855
856 links[id].no_pcm = 1;
857 links[id].cpus = &cpus[id];
858 links[id].num_cpus = 1;
859 if (is_legacy_cpu) {
860 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
861 "ssp%d-port",
862 ssp_amp);
863 if (!links[id].cpus->dai_name)
864 goto devm_err;
865
866 } else {
867 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
868 "SSP%d Pin",
869 ssp_amp);
870 if (!links[id].cpus->dai_name)
871 goto devm_err;
872 }
873 id++;
874 }
875
876 /* BT audio offload */
877 if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) {
878 int port = (sof_rt5682_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
879 SOF_BT_OFFLOAD_SSP_SHIFT;
880
881 links[id].id = id;
882 links[id].cpus = &cpus[id];
883 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
884 "SSP%d Pin", port);
885 if (!links[id].cpus->dai_name)
886 goto devm_err;
887 links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
888 if (!links[id].name)
889 goto devm_err;
890 links[id].codecs = &asoc_dummy_dlc;
891 links[id].num_codecs = 1;
892 links[id].platforms = platform_component;
893 links[id].num_platforms = ARRAY_SIZE(platform_component);
894 links[id].dpcm_playback = 1;
895 links[id].dpcm_capture = 1;
896 links[id].no_pcm = 1;
897 links[id].num_cpus = 1;
898 }
899
900 /* HDMI-In SSP */
901 if (sof_rt5682_quirk & SOF_SSP_HDMI_CAPTURE_PRESENT_MASK) {
902 unsigned long hdmi_in_ssp = (sof_rt5682_quirk &
903 SOF_SSP_HDMI_CAPTURE_PRESENT_MASK) >>
904 SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT;
905 int port = 0;
906
907 for_each_set_bit(port, &hdmi_in_ssp, 32) {
908 links[id].cpus = &cpus[id];
909 links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
910 "SSP%d Pin", port);
911 if (!links[id].cpus->dai_name)
912 return NULL;
913 links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-HDMI", port);
914 if (!links[id].name)
915 return NULL;
916 links[id].id = id + hdmi_id_offset;
917 links[id].codecs = &asoc_dummy_dlc;
918 links[id].num_codecs = 1;
919 links[id].platforms = platform_component;
920 links[id].num_platforms = ARRAY_SIZE(platform_component);
921 links[id].dpcm_capture = 1;
922 links[id].no_pcm = 1;
923 links[id].num_cpus = 1;
924 id++;
925 }
926 }
927
928 return links;
929 devm_err:
930 return NULL;
931 }
932
sof_audio_probe(struct platform_device * pdev)933 static int sof_audio_probe(struct platform_device *pdev)
934 {
935 struct snd_soc_dai_link *dai_links;
936 struct snd_soc_acpi_mach *mach;
937 struct sof_card_private *ctx;
938 int dmic_be_num, hdmi_num;
939 int ret, ssp_amp, ssp_codec;
940
941 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
942 if (!ctx)
943 return -ENOMEM;
944
945 if (pdev->id_entry && pdev->id_entry->driver_data)
946 sof_rt5682_quirk = (unsigned long)pdev->id_entry->driver_data;
947
948 dmi_check_system(sof_rt5682_quirk_table);
949
950 mach = pdev->dev.platform_data;
951
952 /* A speaker amp might not be present when the quirk claims one is.
953 * Detect this via whether the machine driver match includes quirk_data.
954 */
955 if ((sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT) && !mach->quirk_data)
956 sof_rt5682_quirk &= ~SOF_SPEAKER_AMP_PRESENT;
957
958 /* Detect the headset codec variant */
959 if (acpi_dev_present("RTL5682", NULL, -1))
960 sof_rt5682_quirk |= SOF_RT5682S_HEADPHONE_CODEC_PRESENT;
961 else if (acpi_dev_present("10EC5650", NULL, -1)) {
962 sof_rt5682_quirk |= SOF_RT5650_HEADPHONE_CODEC_PRESENT;
963
964 sof_audio_card_rt5682.name = devm_kstrdup(&pdev->dev, "rt5650",
965 GFP_KERNEL);
966 }
967
968 if (soc_intel_is_byt() || soc_intel_is_cht()) {
969 is_legacy_cpu = 1;
970 dmic_be_num = 0;
971 hdmi_num = 0;
972 /* default quirk for legacy cpu */
973 sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
974 SOF_RT5682_MCLK_BYTCHT_EN |
975 SOF_RT5682_SSP_CODEC(2);
976 } else {
977 dmic_be_num = 2;
978 hdmi_num = (sof_rt5682_quirk & SOF_RT5682_NUM_HDMIDEV_MASK) >>
979 SOF_RT5682_NUM_HDMIDEV_SHIFT;
980 /* default number of HDMI DAI's */
981 if (!hdmi_num)
982 hdmi_num = 3;
983
984 if (mach->mach_params.codec_mask & IDISP_CODEC_MASK)
985 ctx->idisp_codec = true;
986 }
987
988 /* need to get main clock from pmc */
989 if (sof_rt5682_quirk & SOF_RT5682_MCLK_BYTCHT_EN) {
990 ctx->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
991 if (IS_ERR(ctx->mclk)) {
992 ret = PTR_ERR(ctx->mclk);
993
994 dev_err(&pdev->dev,
995 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
996 ret);
997 return ret;
998 }
999
1000 ret = clk_prepare_enable(ctx->mclk);
1001 if (ret < 0) {
1002 dev_err(&pdev->dev,
1003 "could not configure MCLK state");
1004 return ret;
1005 }
1006 }
1007
1008 dev_dbg(&pdev->dev, "sof_rt5682_quirk = %lx\n", sof_rt5682_quirk);
1009
1010 ssp_amp = (sof_rt5682_quirk & SOF_RT5682_SSP_AMP_MASK) >>
1011 SOF_RT5682_SSP_AMP_SHIFT;
1012
1013 ssp_codec = sof_rt5682_quirk & SOF_RT5682_SSP_CODEC_MASK;
1014
1015 /* compute number of dai links */
1016 sof_audio_card_rt5682.num_links = 1 + dmic_be_num + hdmi_num;
1017
1018 if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT)
1019 sof_audio_card_rt5682.num_links++;
1020
1021 if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT)
1022 max_98373_set_codec_conf(&sof_audio_card_rt5682);
1023 else if (sof_rt5682_quirk & SOF_RT1011_SPEAKER_AMP_PRESENT)
1024 sof_rt1011_codec_conf(&sof_audio_card_rt5682);
1025 else if (sof_rt5682_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT)
1026 sof_rt1015p_codec_conf(&sof_audio_card_rt5682);
1027 else if (sof_rt5682_quirk & SOF_MAX98390_SPEAKER_AMP_PRESENT) {
1028 max_98390_set_codec_conf(&pdev->dev, &sof_audio_card_rt5682);
1029 }
1030
1031 if (sof_rt5682_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
1032 sof_audio_card_rt5682.num_links++;
1033
1034 if (sof_rt5682_quirk & SOF_SSP_HDMI_CAPTURE_PRESENT_MASK)
1035 sof_audio_card_rt5682.num_links +=
1036 hweight32((sof_rt5682_quirk & SOF_SSP_HDMI_CAPTURE_PRESENT_MASK) >>
1037 SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT);
1038
1039 dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, ssp_amp,
1040 dmic_be_num, hdmi_num, ctx->idisp_codec);
1041 if (!dai_links)
1042 return -ENOMEM;
1043
1044 sof_audio_card_rt5682.dai_link = dai_links;
1045
1046 if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_PRESENT)
1047 sof_rt1015_codec_conf(&sof_audio_card_rt5682);
1048
1049 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
1050
1051 sof_audio_card_rt5682.dev = &pdev->dev;
1052
1053 /* set platform name for each dailink */
1054 ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_rt5682,
1055 mach->mach_params.platform);
1056 if (ret)
1057 return ret;
1058
1059 ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
1060
1061 snd_soc_card_set_drvdata(&sof_audio_card_rt5682, ctx);
1062
1063 return devm_snd_soc_register_card(&pdev->dev,
1064 &sof_audio_card_rt5682);
1065 }
1066
1067 static const struct platform_device_id board_ids[] = {
1068 {
1069 .name = "sof_rt5682",
1070 },
1071 {
1072 .name = "cml_rt1015_rt5682",
1073 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1074 SOF_RT5682_MCLK_24MHZ |
1075 SOF_RT5682_SSP_CODEC(0) |
1076 SOF_SPEAKER_AMP_PRESENT |
1077 SOF_RT1015_SPEAKER_AMP_PRESENT |
1078 SOF_RT5682_SSP_AMP(1)),
1079 },
1080 {
1081 .name = "jsl_rt5682_rt1015",
1082 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1083 SOF_RT5682_MCLK_24MHZ |
1084 SOF_RT5682_SSP_CODEC(0) |
1085 SOF_SPEAKER_AMP_PRESENT |
1086 SOF_RT1015_SPEAKER_AMP_PRESENT |
1087 SOF_RT5682_SSP_AMP(1)),
1088 },
1089 {
1090 .name = "jsl_rt5682_mx98360",
1091 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1092 SOF_RT5682_MCLK_24MHZ |
1093 SOF_RT5682_SSP_CODEC(0) |
1094 SOF_SPEAKER_AMP_PRESENT |
1095 SOF_MAX98360A_SPEAKER_AMP_PRESENT |
1096 SOF_RT5682_SSP_AMP(1)),
1097 },
1098 {
1099 .name = "jsl_rt5682_rt1015p",
1100 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1101 SOF_RT5682_MCLK_24MHZ |
1102 SOF_RT5682_SSP_CODEC(0) |
1103 SOF_SPEAKER_AMP_PRESENT |
1104 SOF_RT1015P_SPEAKER_AMP_PRESENT |
1105 SOF_RT5682_SSP_AMP(1)),
1106 },
1107 {
1108 .name = "jsl_rt5682",
1109 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1110 SOF_RT5682_MCLK_24MHZ |
1111 SOF_RT5682_SSP_CODEC(0)),
1112 },
1113 {
1114 .name = "tgl_mx98357_rt5682",
1115 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1116 SOF_RT5682_SSP_CODEC(0) |
1117 SOF_SPEAKER_AMP_PRESENT |
1118 SOF_RT5682_SSP_AMP(1) |
1119 SOF_RT5682_NUM_HDMIDEV(4) |
1120 SOF_BT_OFFLOAD_SSP(2) |
1121 SOF_SSP_BT_OFFLOAD_PRESENT),
1122 },
1123 {
1124 .name = "tgl_rt1011_rt5682",
1125 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1126 SOF_RT5682_SSP_CODEC(0) |
1127 SOF_SPEAKER_AMP_PRESENT |
1128 SOF_RT1011_SPEAKER_AMP_PRESENT |
1129 SOF_RT5682_SSP_AMP(1) |
1130 SOF_RT5682_NUM_HDMIDEV(4) |
1131 SOF_BT_OFFLOAD_SSP(2) |
1132 SOF_SSP_BT_OFFLOAD_PRESENT),
1133 },
1134 {
1135 .name = "tgl_mx98373_rt5682",
1136 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1137 SOF_RT5682_SSP_CODEC(0) |
1138 SOF_SPEAKER_AMP_PRESENT |
1139 SOF_MAX98373_SPEAKER_AMP_PRESENT |
1140 SOF_RT5682_SSP_AMP(1) |
1141 SOF_RT5682_NUM_HDMIDEV(4) |
1142 SOF_BT_OFFLOAD_SSP(2) |
1143 SOF_SSP_BT_OFFLOAD_PRESENT),
1144 },
1145 {
1146 .name = "adl_mx98373_rt5682",
1147 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1148 SOF_RT5682_SSP_CODEC(0) |
1149 SOF_SPEAKER_AMP_PRESENT |
1150 SOF_MAX98373_SPEAKER_AMP_PRESENT |
1151 SOF_RT5682_SSP_AMP(1) |
1152 SOF_RT5682_NUM_HDMIDEV(4) |
1153 SOF_BT_OFFLOAD_SSP(2) |
1154 SOF_SSP_BT_OFFLOAD_PRESENT),
1155 },
1156 {
1157 .name = "adl_mx98357_rt5682",
1158 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1159 SOF_RT5682_SSP_CODEC(0) |
1160 SOF_SPEAKER_AMP_PRESENT |
1161 SOF_RT5682_SSP_AMP(2) |
1162 SOF_RT5682_NUM_HDMIDEV(4)),
1163 },
1164 {
1165 .name = "adl_max98390_rt5682",
1166 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1167 SOF_RT5682_SSP_CODEC(0) |
1168 SOF_SPEAKER_AMP_PRESENT |
1169 SOF_MAX98390_SPEAKER_AMP_PRESENT |
1170 SOF_RT5682_SSP_AMP(1) |
1171 SOF_RT5682_NUM_HDMIDEV(4) |
1172 SOF_BT_OFFLOAD_SSP(2) |
1173 SOF_SSP_BT_OFFLOAD_PRESENT),
1174 },
1175 {
1176 .name = "adl_mx98360_rt5682",
1177 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1178 SOF_RT5682_SSP_CODEC(0) |
1179 SOF_SPEAKER_AMP_PRESENT |
1180 SOF_MAX98360A_SPEAKER_AMP_PRESENT |
1181 SOF_RT5682_SSP_AMP(1) |
1182 SOF_RT5682_NUM_HDMIDEV(4) |
1183 SOF_BT_OFFLOAD_SSP(2) |
1184 SOF_SSP_BT_OFFLOAD_PRESENT),
1185 },
1186 {
1187 .name = "adl_rt5682",
1188 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1189 SOF_RT5682_SSP_CODEC(0) |
1190 SOF_RT5682_NUM_HDMIDEV(4) |
1191 SOF_BT_OFFLOAD_SSP(2) |
1192 SOF_SSP_BT_OFFLOAD_PRESENT),
1193 },
1194 {
1195 .name = "adl_rt1019_rt5682",
1196 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1197 SOF_RT5682_SSP_CODEC(0) |
1198 SOF_SPEAKER_AMP_PRESENT |
1199 SOF_RT1019_SPEAKER_AMP_PRESENT |
1200 SOF_RT5682_SSP_AMP(1) |
1201 SOF_RT5682_NUM_HDMIDEV(4) |
1202 SOF_BT_OFFLOAD_SSP(2) |
1203 SOF_SSP_BT_OFFLOAD_PRESENT),
1204 },
1205 {
1206 .name = "adl_rt5682_c1_h02",
1207 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1208 SOF_RT5682_SSP_CODEC(1) |
1209 SOF_RT5682_NUM_HDMIDEV(3) |
1210 /* SSP 0 and SSP 2 are used for HDMI IN */
1211 SOF_HDMI_CAPTURE_SSP_MASK(0x5)),
1212 },
1213 {
1214 .name = "rpl_mx98357_rt5682",
1215 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1216 SOF_RT5682_SSP_CODEC(0) |
1217 SOF_SPEAKER_AMP_PRESENT |
1218 SOF_RT5682_SSP_AMP(2) |
1219 SOF_RT5682_NUM_HDMIDEV(4)),
1220 },
1221 {
1222 .name = "rpl_mx98360_rt5682",
1223 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1224 SOF_RT5682_SSP_CODEC(0) |
1225 SOF_SPEAKER_AMP_PRESENT |
1226 SOF_MAX98360A_SPEAKER_AMP_PRESENT |
1227 SOF_RT5682_SSP_AMP(1) |
1228 SOF_RT5682_NUM_HDMIDEV(4) |
1229 SOF_BT_OFFLOAD_SSP(2) |
1230 SOF_SSP_BT_OFFLOAD_PRESENT),
1231 },
1232 {
1233 .name = "rpl_rt1019_rt5682",
1234 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1235 SOF_RT5682_SSP_CODEC(0) |
1236 SOF_SPEAKER_AMP_PRESENT |
1237 SOF_RT1019_SPEAKER_AMP_PRESENT |
1238 SOF_RT5682_SSP_AMP(1) |
1239 SOF_RT5682_NUM_HDMIDEV(4) |
1240 SOF_BT_OFFLOAD_SSP(2) |
1241 SOF_SSP_BT_OFFLOAD_PRESENT),
1242 },
1243 {
1244 .name = "mtl_mx98357_rt5682",
1245 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1246 SOF_RT5682_SSP_CODEC(0) |
1247 SOF_SPEAKER_AMP_PRESENT |
1248 SOF_RT5682_SSP_AMP(1) |
1249 SOF_RT5682_NUM_HDMIDEV(4) |
1250 SOF_BT_OFFLOAD_SSP(2) |
1251 SOF_SSP_BT_OFFLOAD_PRESENT),
1252 },
1253 {
1254 .name = "mtl_mx98360_rt5682",
1255 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1256 SOF_RT5682_SSP_CODEC(0) |
1257 SOF_SPEAKER_AMP_PRESENT |
1258 SOF_MAX98360A_SPEAKER_AMP_PRESENT |
1259 SOF_RT5682_SSP_AMP(1) |
1260 SOF_RT5682_NUM_HDMIDEV(4)),
1261 },
1262 {
1263 .name = "mtl_rt1019_rt5682",
1264 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1265 SOF_RT5682_SSP_CODEC(2) |
1266 SOF_SPEAKER_AMP_PRESENT |
1267 SOF_RT1019_SPEAKER_AMP_PRESENT |
1268 SOF_RT5682_SSP_AMP(0) |
1269 SOF_RT5682_NUM_HDMIDEV(3)),
1270 },
1271 {
1272 .name = "jsl_rt5650",
1273 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
1274 SOF_RT5682_MCLK_24MHZ |
1275 SOF_RT5682_SSP_CODEC(0) |
1276 SOF_SPEAKER_AMP_PRESENT |
1277 SOF_RT5682_SSP_AMP(1)),
1278 },
1279 { }
1280 };
1281 MODULE_DEVICE_TABLE(platform, board_ids);
1282
1283 static struct platform_driver sof_audio = {
1284 .probe = sof_audio_probe,
1285 .driver = {
1286 .name = "sof_rt5682",
1287 .pm = &snd_soc_pm_ops,
1288 },
1289 .id_table = board_ids,
1290 };
1291 module_platform_driver(sof_audio)
1292
1293 /* Module information */
1294 MODULE_DESCRIPTION("SOF Audio Machine driver");
1295 MODULE_AUTHOR("Bard Liao <bard.liao@intel.com>");
1296 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
1297 MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
1298 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
1299 MODULE_LICENSE("GPL v2");
1300 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
1301 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
1302 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_REALTEK_COMMON);
1303