0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/input.h>
0012 #include <linux/module.h>
0013 #include <linux/platform_device.h>
0014 #include <sound/core.h>
0015 #include <sound/jack.h>
0016 #include <sound/pcm.h>
0017 #include <sound/pcm_params.h>
0018 #include <sound/soc.h>
0019 #include <sound/soc-acpi.h>
0020 #include "../../codecs/rt5682.h"
0021 #include "../../codecs/rt5682s.h"
0022 #include "../../codecs/hdac_hdmi.h"
0023 #include "hda_dsp_common.h"
0024
0025
0026 #define GLK_PLAT_CLK_FREQ 19200000
0027 #define RT5682_PLL_FREQ (48000 * 512)
0028 #define RT5682_DAI_NAME "rt5682-aif1"
0029 #define RT5682S_DAI_NAME "rt5682s-aif1"
0030 #define GLK_MAXIM_CODEC_DAI "HiFi"
0031 #define RT5682_DEV0_NAME "i2c-10EC5682:00"
0032 #define RT5682S_DEV0_NAME "i2c-RTL5682:00"
0033 #define MAXIM_DEV0_NAME "MX98357A:00"
0034 #define DUAL_CHANNEL 2
0035 #define QUAD_CHANNEL 4
0036 #define NAME_SIZE 32
0037
0038 static struct snd_soc_jack geminilake_hdmi[3];
0039
0040 struct glk_hdmi_pcm {
0041 struct list_head head;
0042 struct snd_soc_dai *codec_dai;
0043 int device;
0044 };
0045
0046 struct glk_card_private {
0047 struct snd_soc_jack geminilake_headset;
0048 struct list_head hdmi_pcm_list;
0049 bool common_hdmi_codec_drv;
0050 int is_rt5682s;
0051 };
0052
0053 enum {
0054 GLK_DPCM_AUDIO_PB = 0,
0055 GLK_DPCM_AUDIO_CP,
0056 GLK_DPCM_AUDIO_HS_PB,
0057 GLK_DPCM_AUDIO_ECHO_REF_CP,
0058 GLK_DPCM_AUDIO_REF_CP,
0059 GLK_DPCM_AUDIO_DMIC_CP,
0060 GLK_DPCM_AUDIO_HDMI1_PB,
0061 GLK_DPCM_AUDIO_HDMI2_PB,
0062 GLK_DPCM_AUDIO_HDMI3_PB,
0063 };
0064
0065 static const struct snd_kcontrol_new geminilake_controls[] = {
0066 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
0067 SOC_DAPM_PIN_SWITCH("Headset Mic"),
0068 SOC_DAPM_PIN_SWITCH("Spk"),
0069 };
0070
0071 static const struct snd_soc_dapm_widget geminilake_widgets[] = {
0072 SND_SOC_DAPM_HP("Headphone Jack", NULL),
0073 SND_SOC_DAPM_MIC("Headset Mic", NULL),
0074 SND_SOC_DAPM_SPK("Spk", NULL),
0075 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
0076 SND_SOC_DAPM_SPK("HDMI1", NULL),
0077 SND_SOC_DAPM_SPK("HDMI2", NULL),
0078 SND_SOC_DAPM_SPK("HDMI3", NULL),
0079 };
0080
0081 static struct snd_soc_jack_pin jack_pins[] = {
0082 {
0083 .pin = "Headphone Jack",
0084 .mask = SND_JACK_HEADPHONE,
0085 },
0086 {
0087 .pin = "Headset Mic",
0088 .mask = SND_JACK_MICROPHONE,
0089 },
0090 };
0091
0092 static const struct snd_soc_dapm_route geminilake_map[] = {
0093
0094 { "Headphone Jack", NULL, "HPOL" },
0095 { "Headphone Jack", NULL, "HPOR" },
0096
0097
0098 { "Spk", NULL, "Speaker" },
0099
0100
0101 { "IN1P", NULL, "Headset Mic" },
0102
0103
0104 { "DMic", NULL, "SoC DMIC" },
0105
0106
0107 { "HiFi Playback", NULL, "ssp1 Tx" },
0108 { "ssp1 Tx", NULL, "codec0_out" },
0109
0110 { "AIF1 Playback", NULL, "ssp2 Tx" },
0111 { "ssp2 Tx", NULL, "codec1_out" },
0112
0113 { "codec0_in", NULL, "ssp2 Rx" },
0114 { "ssp2 Rx", NULL, "AIF1 Capture" },
0115
0116 { "HDMI1", NULL, "hif5-0 Output" },
0117 { "HDMI2", NULL, "hif6-0 Output" },
0118 { "HDMI2", NULL, "hif7-0 Output" },
0119
0120 { "hifi3", NULL, "iDisp3 Tx" },
0121 { "iDisp3 Tx", NULL, "iDisp3_out" },
0122 { "hifi2", NULL, "iDisp2 Tx" },
0123 { "iDisp2 Tx", NULL, "iDisp2_out" },
0124 { "hifi1", NULL, "iDisp1 Tx" },
0125 { "iDisp1 Tx", NULL, "iDisp1_out" },
0126
0127
0128 { "dmic01_hifi", NULL, "DMIC01 Rx" },
0129 { "DMIC01 Rx", NULL, "DMIC AIF" },
0130 };
0131
0132 static int geminilake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
0133 struct snd_pcm_hw_params *params)
0134 {
0135 struct snd_interval *rate = hw_param_interval(params,
0136 SNDRV_PCM_HW_PARAM_RATE);
0137 struct snd_interval *chan = hw_param_interval(params,
0138 SNDRV_PCM_HW_PARAM_CHANNELS);
0139 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
0140
0141
0142 rate->min = rate->max = 48000;
0143 chan->min = chan->max = DUAL_CHANNEL;
0144
0145
0146 snd_mask_none(fmt);
0147 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
0148
0149 return 0;
0150 }
0151
0152 static int geminilake_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
0153 {
0154 struct glk_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
0155 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
0156 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0157 struct snd_soc_jack *jack;
0158 int pll_id, pll_source, clk_id, ret;
0159
0160 if (ctx->is_rt5682s) {
0161 pll_id = RT5682S_PLL2;
0162 pll_source = RT5682S_PLL_S_MCLK;
0163 clk_id = RT5682S_SCLK_S_PLL2;
0164 } else {
0165 pll_id = RT5682_PLL1;
0166 pll_source = RT5682_PLL1_S_MCLK;
0167 clk_id = RT5682_SCLK_S_PLL1;
0168 }
0169
0170 ret = snd_soc_dai_set_pll(codec_dai, pll_id, pll_source,
0171 GLK_PLAT_CLK_FREQ, RT5682_PLL_FREQ);
0172 if (ret < 0) {
0173 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
0174 return ret;
0175 }
0176
0177
0178 ret = snd_soc_dai_set_sysclk(codec_dai, clk_id,
0179 RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
0180 if (ret < 0)
0181 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
0182
0183
0184
0185
0186
0187 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
0188 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
0189 SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT,
0190 &ctx->geminilake_headset,
0191 jack_pins,
0192 ARRAY_SIZE(jack_pins));
0193 if (ret) {
0194 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
0195 return ret;
0196 }
0197
0198 jack = &ctx->geminilake_headset;
0199
0200 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
0201 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
0202 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
0203 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
0204
0205 ret = snd_soc_component_set_jack(component, jack, NULL);
0206
0207 if (ret) {
0208 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
0209 return ret;
0210 }
0211
0212 return ret;
0213 };
0214
0215 static int geminilake_rt5682_hw_params(struct snd_pcm_substream *substream,
0216 struct snd_pcm_hw_params *params)
0217 {
0218 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0219 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0220 int ret;
0221
0222
0223 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2, 24);
0224 if (ret < 0) {
0225 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
0226 return ret;
0227 }
0228
0229 return ret;
0230 }
0231
0232 static struct snd_soc_ops geminilake_rt5682_ops = {
0233 .hw_params = geminilake_rt5682_hw_params,
0234 };
0235
0236 static int geminilake_hdmi_init(struct snd_soc_pcm_runtime *rtd)
0237 {
0238 struct glk_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
0239 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
0240 struct glk_hdmi_pcm *pcm;
0241
0242 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
0243 if (!pcm)
0244 return -ENOMEM;
0245
0246 pcm->device = GLK_DPCM_AUDIO_HDMI1_PB + dai->id;
0247 pcm->codec_dai = dai;
0248
0249 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
0250
0251 return 0;
0252 }
0253
0254 static int geminilake_rt5682_fe_init(struct snd_soc_pcm_runtime *rtd)
0255 {
0256 struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component;
0257 struct snd_soc_dapm_context *dapm;
0258 int ret;
0259
0260 dapm = snd_soc_component_get_dapm(component);
0261 ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
0262 if (ret) {
0263 dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret);
0264 return ret;
0265 }
0266
0267 return ret;
0268 }
0269
0270 static const unsigned int rates[] = {
0271 48000,
0272 };
0273
0274 static const struct snd_pcm_hw_constraint_list constraints_rates = {
0275 .count = ARRAY_SIZE(rates),
0276 .list = rates,
0277 .mask = 0,
0278 };
0279
0280 static unsigned int channels_quad[] = {
0281 QUAD_CHANNEL,
0282 };
0283
0284 static struct snd_pcm_hw_constraint_list constraints_channels_quad = {
0285 .count = ARRAY_SIZE(channels_quad),
0286 .list = channels_quad,
0287 .mask = 0,
0288 };
0289
0290 static int geminilake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
0291 struct snd_pcm_hw_params *params)
0292 {
0293 struct snd_interval *chan = hw_param_interval(params,
0294 SNDRV_PCM_HW_PARAM_CHANNELS);
0295
0296
0297
0298
0299 chan->min = chan->max = 4;
0300
0301 return 0;
0302 }
0303
0304 static int geminilake_dmic_startup(struct snd_pcm_substream *substream)
0305 {
0306 struct snd_pcm_runtime *runtime = substream->runtime;
0307
0308 runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL;
0309 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
0310 &constraints_channels_quad);
0311
0312 return snd_pcm_hw_constraint_list(substream->runtime, 0,
0313 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
0314 }
0315
0316 static const struct snd_soc_ops geminilake_dmic_ops = {
0317 .startup = geminilake_dmic_startup,
0318 };
0319
0320 static const unsigned int rates_16000[] = {
0321 16000,
0322 };
0323
0324 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
0325 .count = ARRAY_SIZE(rates_16000),
0326 .list = rates_16000,
0327 };
0328
0329 static int geminilake_refcap_startup(struct snd_pcm_substream *substream)
0330 {
0331 return snd_pcm_hw_constraint_list(substream->runtime, 0,
0332 SNDRV_PCM_HW_PARAM_RATE,
0333 &constraints_16000);
0334 };
0335
0336 static const struct snd_soc_ops geminilake_refcap_ops = {
0337 .startup = geminilake_refcap_startup,
0338 };
0339
0340 SND_SOC_DAILINK_DEF(dummy,
0341 DAILINK_COMP_ARRAY(COMP_DUMMY()));
0342
0343 SND_SOC_DAILINK_DEF(system,
0344 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
0345
0346 SND_SOC_DAILINK_DEF(system2,
0347 DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
0348
0349 SND_SOC_DAILINK_DEF(echoref,
0350 DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin")));
0351
0352 SND_SOC_DAILINK_DEF(reference,
0353 DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
0354
0355 SND_SOC_DAILINK_DEF(dmic,
0356 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
0357
0358 SND_SOC_DAILINK_DEF(hdmi1,
0359 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
0360
0361 SND_SOC_DAILINK_DEF(hdmi2,
0362 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
0363
0364 SND_SOC_DAILINK_DEF(hdmi3,
0365 DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
0366
0367 SND_SOC_DAILINK_DEF(ssp1_pin,
0368 DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
0369 SND_SOC_DAILINK_DEF(ssp1_codec,
0370 DAILINK_COMP_ARRAY(COMP_CODEC(MAXIM_DEV0_NAME,
0371 GLK_MAXIM_CODEC_DAI)));
0372
0373 SND_SOC_DAILINK_DEF(ssp2_pin,
0374 DAILINK_COMP_ARRAY(COMP_CPU("SSP2 Pin")));
0375 SND_SOC_DAILINK_DEF(ssp2_codec_5682,
0376 DAILINK_COMP_ARRAY(COMP_CODEC(RT5682_DEV0_NAME,
0377 RT5682_DAI_NAME)));
0378 SND_SOC_DAILINK_DEF(ssp2_codec_5682s,
0379 DAILINK_COMP_ARRAY(COMP_CODEC(RT5682S_DEV0_NAME,
0380 RT5682S_DAI_NAME)));
0381
0382 SND_SOC_DAILINK_DEF(dmic_pin,
0383 DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
0384 SND_SOC_DAILINK_DEF(dmic_codec,
0385 DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
0386
0387 SND_SOC_DAILINK_DEF(idisp1_pin,
0388 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
0389 SND_SOC_DAILINK_DEF(idisp1_codec,
0390 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
0391
0392 SND_SOC_DAILINK_DEF(idisp2_pin,
0393 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
0394 SND_SOC_DAILINK_DEF(idisp2_codec,
0395 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
0396
0397 SND_SOC_DAILINK_DEF(idisp3_pin,
0398 DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
0399 SND_SOC_DAILINK_DEF(idisp3_codec,
0400 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
0401
0402 SND_SOC_DAILINK_DEF(platform,
0403 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:0e.0")));
0404
0405
0406 static struct snd_soc_dai_link geminilake_dais[] = {
0407
0408 [GLK_DPCM_AUDIO_PB] = {
0409 .name = "Glk Audio Port",
0410 .stream_name = "Audio",
0411 .dynamic = 1,
0412 .nonatomic = 1,
0413 .init = geminilake_rt5682_fe_init,
0414 .trigger = {
0415 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0416 .dpcm_playback = 1,
0417 SND_SOC_DAILINK_REG(system, dummy, platform),
0418 },
0419 [GLK_DPCM_AUDIO_CP] = {
0420 .name = "Glk Audio Capture Port",
0421 .stream_name = "Audio Record",
0422 .dynamic = 1,
0423 .nonatomic = 1,
0424 .trigger = {
0425 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0426 .dpcm_capture = 1,
0427 SND_SOC_DAILINK_REG(system, dummy, platform),
0428 },
0429 [GLK_DPCM_AUDIO_HS_PB] = {
0430 .name = "Glk Audio Headset Playback",
0431 .stream_name = "Headset Audio",
0432 .dpcm_playback = 1,
0433 .nonatomic = 1,
0434 .dynamic = 1,
0435 SND_SOC_DAILINK_REG(system2, dummy, platform),
0436 },
0437 [GLK_DPCM_AUDIO_ECHO_REF_CP] = {
0438 .name = "Glk Audio Echo Reference cap",
0439 .stream_name = "Echoreference Capture",
0440 .init = NULL,
0441 .dpcm_capture = 1,
0442 .nonatomic = 1,
0443 .dynamic = 1,
0444 SND_SOC_DAILINK_REG(echoref, dummy, platform),
0445 },
0446 [GLK_DPCM_AUDIO_REF_CP] = {
0447 .name = "Glk Audio Reference cap",
0448 .stream_name = "Refcap",
0449 .init = NULL,
0450 .dpcm_capture = 1,
0451 .nonatomic = 1,
0452 .dynamic = 1,
0453 .ops = &geminilake_refcap_ops,
0454 SND_SOC_DAILINK_REG(reference, dummy, platform),
0455 },
0456 [GLK_DPCM_AUDIO_DMIC_CP] = {
0457 .name = "Glk Audio DMIC cap",
0458 .stream_name = "dmiccap",
0459 .init = NULL,
0460 .dpcm_capture = 1,
0461 .nonatomic = 1,
0462 .dynamic = 1,
0463 .ops = &geminilake_dmic_ops,
0464 SND_SOC_DAILINK_REG(dmic, dummy, platform),
0465 },
0466 [GLK_DPCM_AUDIO_HDMI1_PB] = {
0467 .name = "Glk HDMI Port1",
0468 .stream_name = "Hdmi1",
0469 .dpcm_playback = 1,
0470 .init = NULL,
0471 .trigger = {
0472 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0473 .nonatomic = 1,
0474 .dynamic = 1,
0475 SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
0476 },
0477 [GLK_DPCM_AUDIO_HDMI2_PB] = {
0478 .name = "Glk HDMI Port2",
0479 .stream_name = "Hdmi2",
0480 .dpcm_playback = 1,
0481 .init = NULL,
0482 .trigger = {
0483 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0484 .nonatomic = 1,
0485 .dynamic = 1,
0486 SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
0487 },
0488 [GLK_DPCM_AUDIO_HDMI3_PB] = {
0489 .name = "Glk HDMI Port3",
0490 .stream_name = "Hdmi3",
0491 .trigger = {
0492 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0493 .dpcm_playback = 1,
0494 .init = NULL,
0495 .nonatomic = 1,
0496 .dynamic = 1,
0497 SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
0498 },
0499
0500 {
0501
0502 .name = "SSP1-Codec",
0503 .id = 0,
0504 .no_pcm = 1,
0505 .dai_fmt = SND_SOC_DAIFMT_I2S |
0506 SND_SOC_DAIFMT_NB_NF |
0507 SND_SOC_DAIFMT_CBC_CFC,
0508 .ignore_pmdown_time = 1,
0509 .be_hw_params_fixup = geminilake_ssp_fixup,
0510 .dpcm_playback = 1,
0511 SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
0512 },
0513 {
0514
0515 .name = "SSP2-Codec",
0516 .id = 1,
0517 .no_pcm = 1,
0518 .init = geminilake_rt5682_codec_init,
0519 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0520 SND_SOC_DAIFMT_CBC_CFC,
0521 .ignore_pmdown_time = 1,
0522 .be_hw_params_fixup = geminilake_ssp_fixup,
0523 .ops = &geminilake_rt5682_ops,
0524 .dpcm_playback = 1,
0525 .dpcm_capture = 1,
0526 SND_SOC_DAILINK_REG(ssp2_pin, ssp2_codec_5682, platform),
0527 },
0528 {
0529 .name = "dmic01",
0530 .id = 2,
0531 .ignore_suspend = 1,
0532 .be_hw_params_fixup = geminilake_dmic_fixup,
0533 .dpcm_capture = 1,
0534 .no_pcm = 1,
0535 SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
0536 },
0537 {
0538 .name = "iDisp1",
0539 .id = 3,
0540 .init = geminilake_hdmi_init,
0541 .dpcm_playback = 1,
0542 .no_pcm = 1,
0543 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
0544 },
0545 {
0546 .name = "iDisp2",
0547 .id = 4,
0548 .init = geminilake_hdmi_init,
0549 .dpcm_playback = 1,
0550 .no_pcm = 1,
0551 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
0552 },
0553 {
0554 .name = "iDisp3",
0555 .id = 5,
0556 .init = geminilake_hdmi_init,
0557 .dpcm_playback = 1,
0558 .no_pcm = 1,
0559 SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
0560 },
0561 };
0562
0563 static int glk_card_late_probe(struct snd_soc_card *card)
0564 {
0565 struct glk_card_private *ctx = snd_soc_card_get_drvdata(card);
0566 struct snd_soc_component *component = NULL;
0567 char jack_name[NAME_SIZE];
0568 struct glk_hdmi_pcm *pcm;
0569 int err;
0570 int i = 0;
0571
0572 if (list_empty(&ctx->hdmi_pcm_list))
0573 return -EINVAL;
0574
0575 if (ctx->common_hdmi_codec_drv) {
0576 pcm = list_first_entry(&ctx->hdmi_pcm_list, struct glk_hdmi_pcm,
0577 head);
0578 component = pcm->codec_dai->component;
0579 return hda_dsp_hdmi_build_controls(card, component);
0580 }
0581
0582 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
0583 component = pcm->codec_dai->component;
0584 snprintf(jack_name, sizeof(jack_name),
0585 "HDMI/DP, pcm=%d Jack", pcm->device);
0586 err = snd_soc_card_jack_new(card, jack_name,
0587 SND_JACK_AVOUT, &geminilake_hdmi[i]);
0588
0589 if (err)
0590 return err;
0591
0592 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
0593 &geminilake_hdmi[i]);
0594 if (err < 0)
0595 return err;
0596
0597 i++;
0598 }
0599
0600 return hdac_hdmi_jack_port_init(component, &card->dapm);
0601 }
0602
0603
0604 static struct snd_soc_card glk_audio_card_rt5682_m98357a = {
0605 .name = "glkrt5682max",
0606 .owner = THIS_MODULE,
0607 .dai_link = geminilake_dais,
0608 .num_links = ARRAY_SIZE(geminilake_dais),
0609 .controls = geminilake_controls,
0610 .num_controls = ARRAY_SIZE(geminilake_controls),
0611 .dapm_widgets = geminilake_widgets,
0612 .num_dapm_widgets = ARRAY_SIZE(geminilake_widgets),
0613 .dapm_routes = geminilake_map,
0614 .num_dapm_routes = ARRAY_SIZE(geminilake_map),
0615 .fully_routed = true,
0616 .late_probe = glk_card_late_probe,
0617 };
0618
0619 static int geminilake_audio_probe(struct platform_device *pdev)
0620 {
0621 struct glk_card_private *ctx;
0622 struct snd_soc_acpi_mach *mach;
0623 const char *platform_name;
0624 struct snd_soc_card *card;
0625 int ret, i;
0626
0627 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
0628 if (!ctx)
0629 return -ENOMEM;
0630
0631
0632 if (acpi_dev_present("RTL5682", NULL, -1)) {
0633
0634 ctx->is_rt5682s = 1;
0635
0636 for (i = 0; i < glk_audio_card_rt5682_m98357a.num_links; i++) {
0637 if (strcmp(geminilake_dais[i].name, "SSP2-Codec"))
0638 continue;
0639
0640
0641 geminilake_dais[i].codecs = ssp2_codec_5682s;
0642 geminilake_dais[i].num_codecs = ARRAY_SIZE(ssp2_codec_5682s);
0643 break;
0644 }
0645 }
0646
0647 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
0648
0649 card = &glk_audio_card_rt5682_m98357a;
0650 card->dev = &pdev->dev;
0651 snd_soc_card_set_drvdata(card, ctx);
0652
0653
0654 mach = pdev->dev.platform_data;
0655 platform_name = mach->mach_params.platform;
0656
0657 ret = snd_soc_fixup_dai_links_platform_name(card, platform_name);
0658 if (ret)
0659 return ret;
0660
0661 ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
0662
0663 return devm_snd_soc_register_card(&pdev->dev, card);
0664 }
0665
0666 static const struct platform_device_id glk_board_ids[] = {
0667 {
0668 .name = "glk_rt5682_mx98357a",
0669 .driver_data =
0670 (kernel_ulong_t)&glk_audio_card_rt5682_m98357a,
0671 },
0672 { }
0673 };
0674 MODULE_DEVICE_TABLE(platform, glk_board_ids);
0675
0676 static struct platform_driver geminilake_audio = {
0677 .probe = geminilake_audio_probe,
0678 .driver = {
0679 .name = "glk_rt5682_max98357a",
0680 .pm = &snd_soc_pm_ops,
0681 },
0682 .id_table = glk_board_ids,
0683 };
0684 module_platform_driver(geminilake_audio)
0685
0686
0687 MODULE_DESCRIPTION("Geminilake Audio Machine driver-RT5682 & MAX98357A in I2S mode");
0688 MODULE_AUTHOR("Naveen Manohar <naveen.m@intel.com>");
0689 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
0690 MODULE_LICENSE("GPL v2");
0691 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);