0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/input.h>
0013 #include <linux/module.h>
0014 #include <linux/platform_device.h>
0015 #include <sound/core.h>
0016 #include <sound/jack.h>
0017 #include <sound/pcm.h>
0018 #include <sound/pcm_params.h>
0019 #include <sound/soc.h>
0020 #include "../../codecs/da7219.h"
0021 #include "../../codecs/hdac_hdmi.h"
0022 #include "../../codecs/da7219-aad.h"
0023
0024 #define KBL_DIALOG_CODEC_DAI "da7219-hifi"
0025 #define MAX98927_CODEC_DAI "max98927-aif1"
0026 #define MAX98927_DEV0_NAME "i2c-MX98927:00"
0027 #define MAX98927_DEV1_NAME "i2c-MX98927:01"
0028
0029 #define MAX98373_CODEC_DAI "max98373-aif1"
0030 #define MAX98373_DEV0_NAME "i2c-MX98373:00"
0031 #define MAX98373_DEV1_NAME "i2c-MX98373:01"
0032
0033
0034 #define DUAL_CHANNEL 2
0035 #define QUAD_CHANNEL 4
0036 #define NAME_SIZE 32
0037
0038 static struct snd_soc_card *kabylake_audio_card;
0039 static struct snd_soc_jack kabylake_hdmi[3];
0040
0041 struct kbl_hdmi_pcm {
0042 struct list_head head;
0043 struct snd_soc_dai *codec_dai;
0044 int device;
0045 };
0046
0047 struct kbl_codec_private {
0048 struct snd_soc_jack kabylake_headset;
0049 struct list_head hdmi_pcm_list;
0050 };
0051
0052 enum {
0053 KBL_DPCM_AUDIO_PB = 0,
0054 KBL_DPCM_AUDIO_ECHO_REF_CP,
0055 KBL_DPCM_AUDIO_REF_CP,
0056 KBL_DPCM_AUDIO_DMIC_CP,
0057 KBL_DPCM_AUDIO_HDMI1_PB,
0058 KBL_DPCM_AUDIO_HDMI2_PB,
0059 KBL_DPCM_AUDIO_HDMI3_PB,
0060 KBL_DPCM_AUDIO_HS_PB,
0061 KBL_DPCM_AUDIO_CP,
0062 };
0063
0064 static int platform_clock_control(struct snd_soc_dapm_widget *w,
0065 struct snd_kcontrol *k, int event)
0066 {
0067 struct snd_soc_dapm_context *dapm = w->dapm;
0068 struct snd_soc_card *card = dapm->card;
0069 struct snd_soc_dai *codec_dai;
0070 int ret = 0;
0071
0072 codec_dai = snd_soc_card_get_codec_dai(card, KBL_DIALOG_CODEC_DAI);
0073 if (!codec_dai) {
0074 dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n");
0075 return -EIO;
0076 }
0077
0078
0079 ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 24576000,
0080 SND_SOC_CLOCK_IN);
0081 if (ret) {
0082 dev_err(card->dev, "can't set codec sysclk configuration\n");
0083 return ret;
0084 }
0085
0086 if (SND_SOC_DAPM_EVENT_OFF(event)) {
0087 ret = snd_soc_dai_set_pll(codec_dai, 0,
0088 DA7219_SYSCLK_MCLK, 0, 0);
0089 if (ret)
0090 dev_err(card->dev, "failed to stop PLL: %d\n", ret);
0091 } else if (SND_SOC_DAPM_EVENT_ON(event)) {
0092 ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL_SRM,
0093 0, DA7219_PLL_FREQ_OUT_98304);
0094 if (ret)
0095 dev_err(card->dev, "failed to start PLL: %d\n", ret);
0096 }
0097
0098 return ret;
0099 }
0100
0101 static const struct snd_kcontrol_new kabylake_controls[] = {
0102 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
0103 SOC_DAPM_PIN_SWITCH("Headset Mic"),
0104 SOC_DAPM_PIN_SWITCH("Left Spk"),
0105 SOC_DAPM_PIN_SWITCH("Right Spk"),
0106 };
0107
0108 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
0109 SND_SOC_DAPM_HP("Headphone Jack", NULL),
0110 SND_SOC_DAPM_MIC("Headset Mic", NULL),
0111 SND_SOC_DAPM_SPK("Left Spk", NULL),
0112 SND_SOC_DAPM_SPK("Right Spk", NULL),
0113 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
0114 SND_SOC_DAPM_SPK("HDMI1", NULL),
0115 SND_SOC_DAPM_SPK("HDMI2", NULL),
0116 SND_SOC_DAPM_SPK("HDMI3", NULL),
0117 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
0118 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
0119 SND_SOC_DAPM_POST_PMD),
0120 };
0121
0122 static struct snd_soc_jack_pin jack_pins[] = {
0123 {
0124 .pin = "Headphone Jack",
0125 .mask = SND_JACK_HEADPHONE,
0126 },
0127 {
0128 .pin = "Headset Mic",
0129 .mask = SND_JACK_MICROPHONE,
0130 },
0131 };
0132
0133 static const struct snd_soc_dapm_route kabylake_map[] = {
0134
0135 { "Left Spk", NULL, "Left BE_OUT" },
0136 { "Right Spk", NULL, "Right BE_OUT" },
0137
0138
0139 { "DMic", NULL, "SoC DMIC" },
0140
0141 {"HDMI1", NULL, "hif5-0 Output"},
0142 {"HDMI2", NULL, "hif6-0 Output"},
0143 {"HDMI3", NULL, "hif7-0 Output"},
0144
0145
0146 { "Left HiFi Playback", NULL, "ssp0 Tx" },
0147 { "Right HiFi Playback", NULL, "ssp0 Tx" },
0148 { "ssp0 Tx", NULL, "spk_out" },
0149
0150
0151 { "codec0_fb_in", NULL, "ssp0 Rx"},
0152 { "ssp0 Rx", NULL, "Left HiFi Capture" },
0153 { "ssp0 Rx", NULL, "Right HiFi Capture" },
0154
0155
0156 { "echo_ref_out", NULL, "ssp0 Rx" },
0157
0158
0159 { "dmic01_hifi", NULL, "DMIC01 Rx" },
0160 { "DMIC01 Rx", NULL, "DMIC AIF" },
0161
0162 { "hifi1", NULL, "iDisp1 Tx" },
0163 { "iDisp1 Tx", NULL, "iDisp1_out" },
0164 { "hifi2", NULL, "iDisp2 Tx" },
0165 { "iDisp2 Tx", NULL, "iDisp2_out" },
0166 { "hifi3", NULL, "iDisp3 Tx"},
0167 { "iDisp3 Tx", NULL, "iDisp3_out"},
0168 };
0169
0170 static const struct snd_soc_dapm_route kabylake_ssp1_map[] = {
0171 { "Headphone Jack", NULL, "HPL" },
0172 { "Headphone Jack", NULL, "HPR" },
0173
0174
0175 { "MIC", NULL, "Headset Mic" },
0176
0177
0178 { "Playback", NULL, "ssp1 Tx" },
0179 { "ssp1 Tx", NULL, "codec1_out" },
0180
0181 { "hs_in", NULL, "ssp1 Rx" },
0182 { "ssp1 Rx", NULL, "Capture" },
0183
0184 { "Headphone Jack", NULL, "Platform Clock" },
0185 { "Headset Mic", NULL, "Platform Clock" },
0186 };
0187
0188 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
0189 struct snd_pcm_hw_params *params)
0190 {
0191 struct snd_soc_pcm_runtime *runtime = asoc_substream_to_rtd(substream);
0192 struct snd_soc_dai *codec_dai;
0193 int ret, j;
0194
0195 for_each_rtd_codec_dais(runtime, j, codec_dai) {
0196
0197 if (!strcmp(codec_dai->component->name, MAX98927_DEV0_NAME)) {
0198 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
0199 if (ret < 0) {
0200 dev_err(runtime->dev, "DEV0 TDM slot err:%d\n", ret);
0201 return ret;
0202 }
0203 }
0204 if (!strcmp(codec_dai->component->name, MAX98927_DEV1_NAME)) {
0205 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
0206 if (ret < 0) {
0207 dev_err(runtime->dev, "DEV1 TDM slot err:%d\n", ret);
0208 return ret;
0209 }
0210 }
0211 if (!strcmp(codec_dai->component->name, MAX98373_DEV0_NAME)) {
0212 ret = snd_soc_dai_set_tdm_slot(codec_dai,
0213 0x30, 3, 8, 16);
0214 if (ret < 0) {
0215 dev_err(runtime->dev,
0216 "DEV0 TDM slot err:%d\n", ret);
0217 return ret;
0218 }
0219 }
0220 if (!strcmp(codec_dai->component->name, MAX98373_DEV1_NAME)) {
0221 ret = snd_soc_dai_set_tdm_slot(codec_dai,
0222 0xC0, 3, 8, 16);
0223 if (ret < 0) {
0224 dev_err(runtime->dev,
0225 "DEV1 TDM slot err:%d\n", ret);
0226 return ret;
0227 }
0228 }
0229 }
0230
0231 return 0;
0232 }
0233
0234 static int kabylake_ssp0_trigger(struct snd_pcm_substream *substream, int cmd)
0235 {
0236 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0237 struct snd_soc_dai *codec_dai;
0238 int j, ret;
0239
0240 for_each_rtd_codec_dais(rtd, j, codec_dai) {
0241 const char *name = codec_dai->component->name;
0242 struct snd_soc_component *component = codec_dai->component;
0243 struct snd_soc_dapm_context *dapm =
0244 snd_soc_component_get_dapm(component);
0245 char pin_name[20];
0246
0247 if (strcmp(name, MAX98927_DEV0_NAME) &&
0248 strcmp(name, MAX98927_DEV1_NAME) &&
0249 strcmp(name, MAX98373_DEV0_NAME) &&
0250 strcmp(name, MAX98373_DEV1_NAME))
0251 continue;
0252
0253 snprintf(pin_name, ARRAY_SIZE(pin_name), "%s Spk",
0254 codec_dai->component->name_prefix);
0255
0256 switch (cmd) {
0257 case SNDRV_PCM_TRIGGER_START:
0258 case SNDRV_PCM_TRIGGER_RESUME:
0259 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
0260 ret = snd_soc_dapm_enable_pin(dapm, pin_name);
0261 if (ret) {
0262 dev_err(rtd->dev, "failed to enable %s: %d\n",
0263 pin_name, ret);
0264 return ret;
0265 }
0266 snd_soc_dapm_sync(dapm);
0267 break;
0268 case SNDRV_PCM_TRIGGER_STOP:
0269 case SNDRV_PCM_TRIGGER_SUSPEND:
0270 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
0271 ret = snd_soc_dapm_disable_pin(dapm, pin_name);
0272 if (ret) {
0273 dev_err(rtd->dev, "failed to disable %s: %d\n",
0274 pin_name, ret);
0275 return ret;
0276 }
0277 snd_soc_dapm_sync(dapm);
0278 break;
0279 }
0280 }
0281
0282 return 0;
0283 }
0284
0285 static struct snd_soc_ops kabylake_ssp0_ops = {
0286 .hw_params = kabylake_ssp0_hw_params,
0287 .trigger = kabylake_ssp0_trigger,
0288 };
0289
0290 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
0291 struct snd_pcm_hw_params *params)
0292 {
0293 struct snd_interval *rate = hw_param_interval(params,
0294 SNDRV_PCM_HW_PARAM_RATE);
0295 struct snd_interval *chan = hw_param_interval(params,
0296 SNDRV_PCM_HW_PARAM_CHANNELS);
0297 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
0298 struct snd_soc_dpcm *dpcm, *rtd_dpcm = NULL;
0299
0300
0301
0302
0303
0304 for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {
0305 rtd_dpcm = dpcm;
0306 break;
0307 }
0308
0309
0310
0311
0312
0313 for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
0314 rtd_dpcm = dpcm;
0315 break;
0316 }
0317
0318 if (!rtd_dpcm)
0319 return -EINVAL;
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329 if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Port") ||
0330 !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Headset Playback") ||
0331 !strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Capture Port")) {
0332 rate->min = rate->max = 48000;
0333 chan->min = chan->max = 2;
0334 snd_mask_none(fmt);
0335 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
0336 }
0337
0338
0339
0340
0341
0342 if (!strcmp(rtd_dpcm->be->dai_link->name, "SSP0-Codec"))
0343 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
0344
0345 return 0;
0346 }
0347
0348 static int kabylake_da7219_codec_init(struct snd_soc_pcm_runtime *rtd)
0349 {
0350 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
0351 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
0352 struct snd_soc_jack *jack;
0353 struct snd_soc_card *card = rtd->card;
0354 int ret;
0355
0356
0357 ret = snd_soc_dapm_add_routes(&card->dapm,
0358 kabylake_ssp1_map,
0359 ARRAY_SIZE(kabylake_ssp1_map));
0360
0361 if (ret)
0362 return ret;
0363
0364
0365
0366
0367
0368 ret = snd_soc_card_jack_new_pins(kabylake_audio_card, "Headset Jack",
0369 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
0370 SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT,
0371 &ctx->kabylake_headset,
0372 jack_pins,
0373 ARRAY_SIZE(jack_pins));
0374 if (ret) {
0375 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
0376 return ret;
0377 }
0378
0379 jack = &ctx->kabylake_headset;
0380 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
0381 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
0382 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
0383 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
0384
0385 da7219_aad_jack_det(component, &ctx->kabylake_headset);
0386
0387 return 0;
0388 }
0389
0390 static int kabylake_dmic_init(struct snd_soc_pcm_runtime *rtd)
0391 {
0392 int ret;
0393 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
0394 if (ret)
0395 dev_err(rtd->dev, "SoC DMIC - Ignore suspend failed %d\n", ret);
0396
0397 return ret;
0398 }
0399
0400 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
0401 {
0402 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
0403 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
0404 struct kbl_hdmi_pcm *pcm;
0405
0406 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
0407 if (!pcm)
0408 return -ENOMEM;
0409
0410 pcm->device = device;
0411 pcm->codec_dai = dai;
0412
0413 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
0414
0415 return 0;
0416 }
0417
0418 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
0419 {
0420 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
0421 }
0422
0423 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
0424 {
0425 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
0426 }
0427
0428 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
0429 {
0430 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
0431 }
0432
0433 static int kabylake_da7219_fe_init(struct snd_soc_pcm_runtime *rtd)
0434 {
0435 struct snd_soc_dapm_context *dapm;
0436 struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component;
0437
0438 dapm = snd_soc_component_get_dapm(component);
0439 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
0440
0441 return 0;
0442 }
0443
0444 static const unsigned int rates[] = {
0445 48000,
0446 };
0447
0448 static const struct snd_pcm_hw_constraint_list constraints_rates = {
0449 .count = ARRAY_SIZE(rates),
0450 .list = rates,
0451 .mask = 0,
0452 };
0453
0454 static const unsigned int channels[] = {
0455 DUAL_CHANNEL,
0456 };
0457
0458 static const struct snd_pcm_hw_constraint_list constraints_channels = {
0459 .count = ARRAY_SIZE(channels),
0460 .list = channels,
0461 .mask = 0,
0462 };
0463
0464 static unsigned int channels_quad[] = {
0465 QUAD_CHANNEL,
0466 };
0467
0468 static struct snd_pcm_hw_constraint_list constraints_channels_quad = {
0469 .count = ARRAY_SIZE(channels_quad),
0470 .list = channels_quad,
0471 .mask = 0,
0472 };
0473
0474 static int kbl_fe_startup(struct snd_pcm_substream *substream)
0475 {
0476 struct snd_pcm_runtime *runtime = substream->runtime;
0477
0478
0479
0480
0481
0482
0483
0484
0485 runtime->hw.channels_max = DUAL_CHANNEL;
0486 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
0487 &constraints_channels);
0488
0489 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
0490 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
0491
0492 snd_pcm_hw_constraint_list(runtime, 0,
0493 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
0494
0495 return 0;
0496 }
0497
0498 static const struct snd_soc_ops kabylake_da7219_fe_ops = {
0499 .startup = kbl_fe_startup,
0500 };
0501
0502 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
0503 struct snd_pcm_hw_params *params)
0504 {
0505 struct snd_interval *chan = hw_param_interval(params,
0506 SNDRV_PCM_HW_PARAM_CHANNELS);
0507
0508
0509
0510
0511
0512 if (params_channels(params) == 2)
0513 chan->min = chan->max = 2;
0514 else
0515 chan->min = chan->max = 4;
0516
0517 return 0;
0518 }
0519
0520 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
0521 {
0522 struct snd_pcm_runtime *runtime = substream->runtime;
0523
0524 runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL;
0525 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
0526 &constraints_channels_quad);
0527
0528 return snd_pcm_hw_constraint_list(substream->runtime, 0,
0529 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
0530 }
0531
0532 static struct snd_soc_ops kabylake_dmic_ops = {
0533 .startup = kabylake_dmic_startup,
0534 };
0535
0536 static const unsigned int rates_16000[] = {
0537 16000,
0538 };
0539
0540 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
0541 .count = ARRAY_SIZE(rates_16000),
0542 .list = rates_16000,
0543 };
0544
0545 static const unsigned int ch_mono[] = {
0546 1,
0547 };
0548 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
0549 .count = ARRAY_SIZE(ch_mono),
0550 .list = ch_mono,
0551 };
0552
0553 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
0554 {
0555 substream->runtime->hw.channels_max = 1;
0556 snd_pcm_hw_constraint_list(substream->runtime, 0,
0557 SNDRV_PCM_HW_PARAM_CHANNELS,
0558 &constraints_refcap);
0559
0560 return snd_pcm_hw_constraint_list(substream->runtime, 0,
0561 SNDRV_PCM_HW_PARAM_RATE,
0562 &constraints_16000);
0563 }
0564
0565
0566 static struct snd_soc_ops skylake_refcap_ops = {
0567 .startup = kabylake_refcap_startup,
0568 };
0569
0570 static struct snd_soc_codec_conf max98927_codec_conf[] = {
0571
0572 {
0573 .dlc = COMP_CODEC_CONF(MAX98927_DEV0_NAME),
0574 .name_prefix = "Right",
0575 },
0576
0577 {
0578 .dlc = COMP_CODEC_CONF(MAX98927_DEV1_NAME),
0579 .name_prefix = "Left",
0580 },
0581 };
0582
0583 static struct snd_soc_codec_conf max98373_codec_conf[] = {
0584
0585 {
0586 .dlc = COMP_CODEC_CONF(MAX98373_DEV0_NAME),
0587 .name_prefix = "Right",
0588 },
0589
0590 {
0591 .dlc = COMP_CODEC_CONF(MAX98373_DEV1_NAME),
0592 .name_prefix = "Left",
0593 },
0594 };
0595
0596 static struct snd_soc_dai_link_component max98373_ssp0_codec_components[] = {
0597 {
0598 .name = MAX98373_DEV0_NAME,
0599 .dai_name = MAX98373_CODEC_DAI,
0600 },
0601
0602 {
0603 .name = MAX98373_DEV1_NAME,
0604 .dai_name = MAX98373_CODEC_DAI,
0605 },
0606
0607 };
0608
0609 SND_SOC_DAILINK_DEF(dummy,
0610 DAILINK_COMP_ARRAY(COMP_DUMMY()));
0611
0612 SND_SOC_DAILINK_DEF(system,
0613 DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
0614
0615 SND_SOC_DAILINK_DEF(echoref,
0616 DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin")));
0617
0618 SND_SOC_DAILINK_DEF(reference,
0619 DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
0620
0621 SND_SOC_DAILINK_DEF(dmic,
0622 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
0623
0624 SND_SOC_DAILINK_DEF(hdmi1,
0625 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
0626
0627 SND_SOC_DAILINK_DEF(hdmi2,
0628 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
0629
0630 SND_SOC_DAILINK_DEF(hdmi3,
0631 DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
0632
0633 SND_SOC_DAILINK_DEF(system2,
0634 DAILINK_COMP_ARRAY(COMP_CPU("System Pin2")));
0635
0636 SND_SOC_DAILINK_DEF(ssp0_pin,
0637 DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
0638 SND_SOC_DAILINK_DEF(ssp0_codec,
0639 DAILINK_COMP_ARRAY(
0640 COMP_CODEC(MAX98927_DEV0_NAME, MAX98927_CODEC_DAI),
0641 COMP_CODEC(MAX98927_DEV1_NAME, MAX98927_CODEC_DAI)));
0642
0643 SND_SOC_DAILINK_DEF(ssp1_pin,
0644 DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
0645 SND_SOC_DAILINK_DEF(ssp1_codec,
0646 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00",
0647 KBL_DIALOG_CODEC_DAI)));
0648
0649 SND_SOC_DAILINK_DEF(dmic_pin,
0650 DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
0651 SND_SOC_DAILINK_DEF(dmic_codec,
0652 DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
0653
0654 SND_SOC_DAILINK_DEF(idisp1_pin,
0655 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
0656 SND_SOC_DAILINK_DEF(idisp1_codec,
0657 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
0658
0659 SND_SOC_DAILINK_DEF(idisp2_pin,
0660 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
0661 SND_SOC_DAILINK_DEF(idisp2_codec,
0662 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
0663
0664 SND_SOC_DAILINK_DEF(idisp3_pin,
0665 DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
0666 SND_SOC_DAILINK_DEF(idisp3_codec,
0667 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
0668
0669 SND_SOC_DAILINK_DEF(platform,
0670 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
0671
0672
0673 static struct snd_soc_dai_link kabylake_dais[] = {
0674
0675 [KBL_DPCM_AUDIO_PB] = {
0676 .name = "Kbl Audio Port",
0677 .stream_name = "Audio",
0678 .dynamic = 1,
0679 .nonatomic = 1,
0680 .init = kabylake_da7219_fe_init,
0681 .trigger = {
0682 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0683 .dpcm_playback = 1,
0684 .ops = &kabylake_da7219_fe_ops,
0685 SND_SOC_DAILINK_REG(system, dummy, platform),
0686 },
0687 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
0688 .name = "Kbl Audio Echo Reference cap",
0689 .stream_name = "Echoreference Capture",
0690 .init = NULL,
0691 .dpcm_capture = 1,
0692 .nonatomic = 1,
0693 SND_SOC_DAILINK_REG(echoref, dummy, platform),
0694 },
0695 [KBL_DPCM_AUDIO_REF_CP] = {
0696 .name = "Kbl Audio Reference cap",
0697 .stream_name = "Wake on Voice",
0698 .init = NULL,
0699 .dpcm_capture = 1,
0700 .nonatomic = 1,
0701 .dynamic = 1,
0702 .ops = &skylake_refcap_ops,
0703 SND_SOC_DAILINK_REG(reference, dummy, platform),
0704 },
0705 [KBL_DPCM_AUDIO_DMIC_CP] = {
0706 .name = "Kbl Audio DMIC cap",
0707 .stream_name = "dmiccap",
0708 .init = NULL,
0709 .dpcm_capture = 1,
0710 .nonatomic = 1,
0711 .dynamic = 1,
0712 .ops = &kabylake_dmic_ops,
0713 SND_SOC_DAILINK_REG(dmic, dummy, platform),
0714 },
0715 [KBL_DPCM_AUDIO_HDMI1_PB] = {
0716 .name = "Kbl HDMI Port1",
0717 .stream_name = "Hdmi1",
0718 .dpcm_playback = 1,
0719 .init = NULL,
0720 .trigger = {
0721 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0722 .nonatomic = 1,
0723 .dynamic = 1,
0724 SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
0725 },
0726 [KBL_DPCM_AUDIO_HDMI2_PB] = {
0727 .name = "Kbl HDMI Port2",
0728 .stream_name = "Hdmi2",
0729 .dpcm_playback = 1,
0730 .init = NULL,
0731 .trigger = {
0732 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0733 .nonatomic = 1,
0734 .dynamic = 1,
0735 SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
0736 },
0737 [KBL_DPCM_AUDIO_HDMI3_PB] = {
0738 .name = "Kbl HDMI Port3",
0739 .stream_name = "Hdmi3",
0740 .trigger = {
0741 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0742 .dpcm_playback = 1,
0743 .init = NULL,
0744 .nonatomic = 1,
0745 .dynamic = 1,
0746 SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
0747 },
0748 [KBL_DPCM_AUDIO_HS_PB] = {
0749 .name = "Kbl Audio Headset Playback",
0750 .stream_name = "Headset Audio",
0751 .dpcm_playback = 1,
0752 .nonatomic = 1,
0753 .dynamic = 1,
0754 .init = kabylake_da7219_fe_init,
0755 .trigger = {
0756 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0757 .ops = &kabylake_da7219_fe_ops,
0758 SND_SOC_DAILINK_REG(system2, dummy, platform),
0759 },
0760 [KBL_DPCM_AUDIO_CP] = {
0761 .name = "Kbl Audio Capture Port",
0762 .stream_name = "Audio Record",
0763 .dynamic = 1,
0764 .nonatomic = 1,
0765 .trigger = {
0766 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0767 .dpcm_capture = 1,
0768 .ops = &kabylake_da7219_fe_ops,
0769 SND_SOC_DAILINK_REG(system, dummy, platform),
0770 },
0771
0772
0773 {
0774
0775 .name = "SSP0-Codec",
0776 .id = 0,
0777 .no_pcm = 1,
0778 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
0779 SND_SOC_DAIFMT_NB_NF |
0780 SND_SOC_DAIFMT_CBC_CFC,
0781 .dpcm_playback = 1,
0782 .dpcm_capture = 1,
0783 .ignore_pmdown_time = 1,
0784 .be_hw_params_fixup = kabylake_ssp_fixup,
0785 .ops = &kabylake_ssp0_ops,
0786 SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
0787 },
0788 {
0789
0790 .name = "SSP1-Codec",
0791 .id = 1,
0792 .no_pcm = 1,
0793 .init = kabylake_da7219_codec_init,
0794 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0795 SND_SOC_DAIFMT_CBC_CFC,
0796 .ignore_pmdown_time = 1,
0797 .be_hw_params_fixup = kabylake_ssp_fixup,
0798 .dpcm_playback = 1,
0799 .dpcm_capture = 1,
0800 SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
0801 },
0802 {
0803 .name = "dmic01",
0804 .id = 2,
0805 .init = kabylake_dmic_init,
0806 .be_hw_params_fixup = kabylake_dmic_fixup,
0807 .ignore_suspend = 1,
0808 .dpcm_capture = 1,
0809 .no_pcm = 1,
0810 SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
0811 },
0812 {
0813 .name = "iDisp1",
0814 .id = 3,
0815 .dpcm_playback = 1,
0816 .init = kabylake_hdmi1_init,
0817 .no_pcm = 1,
0818 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
0819 },
0820 {
0821 .name = "iDisp2",
0822 .id = 4,
0823 .init = kabylake_hdmi2_init,
0824 .dpcm_playback = 1,
0825 .no_pcm = 1,
0826 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
0827 },
0828 {
0829 .name = "iDisp3",
0830 .id = 5,
0831 .init = kabylake_hdmi3_init,
0832 .dpcm_playback = 1,
0833 .no_pcm = 1,
0834 SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
0835 },
0836 };
0837
0838
0839 static struct snd_soc_dai_link kabylake_max98_927_373_dais[] = {
0840
0841 [KBL_DPCM_AUDIO_PB] = {
0842 .name = "Kbl Audio Port",
0843 .stream_name = "Audio",
0844 .dynamic = 1,
0845 .nonatomic = 1,
0846 .init = kabylake_da7219_fe_init,
0847 .trigger = {
0848 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0849 .dpcm_playback = 1,
0850 .ops = &kabylake_da7219_fe_ops,
0851 SND_SOC_DAILINK_REG(system, dummy, platform),
0852 },
0853 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
0854 .name = "Kbl Audio Echo Reference cap",
0855 .stream_name = "Echoreference Capture",
0856 .init = NULL,
0857 .dpcm_capture = 1,
0858 .nonatomic = 1,
0859 SND_SOC_DAILINK_REG(echoref, dummy, platform),
0860 },
0861 [KBL_DPCM_AUDIO_REF_CP] = {
0862 .name = "Kbl Audio Reference cap",
0863 .stream_name = "Wake on Voice",
0864 .init = NULL,
0865 .dpcm_capture = 1,
0866 .nonatomic = 1,
0867 .dynamic = 1,
0868 .ops = &skylake_refcap_ops,
0869 SND_SOC_DAILINK_REG(reference, dummy, platform),
0870 },
0871 [KBL_DPCM_AUDIO_DMIC_CP] = {
0872 .name = "Kbl Audio DMIC cap",
0873 .stream_name = "dmiccap",
0874 .init = NULL,
0875 .dpcm_capture = 1,
0876 .nonatomic = 1,
0877 .dynamic = 1,
0878 .ops = &kabylake_dmic_ops,
0879 SND_SOC_DAILINK_REG(dmic, dummy, platform),
0880 },
0881 [KBL_DPCM_AUDIO_HDMI1_PB] = {
0882 .name = "Kbl HDMI Port1",
0883 .stream_name = "Hdmi1",
0884 .dpcm_playback = 1,
0885 .init = NULL,
0886 .trigger = {
0887 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0888 .nonatomic = 1,
0889 .dynamic = 1,
0890 SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
0891 },
0892 [KBL_DPCM_AUDIO_HDMI2_PB] = {
0893 .name = "Kbl HDMI Port2",
0894 .stream_name = "Hdmi2",
0895 .dpcm_playback = 1,
0896 .init = NULL,
0897 .trigger = {
0898 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0899 .nonatomic = 1,
0900 .dynamic = 1,
0901 SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
0902 },
0903 [KBL_DPCM_AUDIO_HDMI3_PB] = {
0904 .name = "Kbl HDMI Port3",
0905 .stream_name = "Hdmi3",
0906 .trigger = {
0907 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0908 .dpcm_playback = 1,
0909 .init = NULL,
0910 .nonatomic = 1,
0911 .dynamic = 1,
0912 SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
0913 },
0914
0915
0916 {
0917
0918 .name = "SSP0-Codec",
0919 .id = 0,
0920 .no_pcm = 1,
0921 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
0922 SND_SOC_DAIFMT_NB_NF |
0923 SND_SOC_DAIFMT_CBC_CFC,
0924 .dpcm_playback = 1,
0925 .dpcm_capture = 1,
0926 .ignore_pmdown_time = 1,
0927 .be_hw_params_fixup = kabylake_ssp_fixup,
0928 .ops = &kabylake_ssp0_ops,
0929 SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec),
0930 },
0931 {
0932 .name = "dmic01",
0933 .id = 1,
0934 .init = kabylake_dmic_init,
0935 .be_hw_params_fixup = kabylake_dmic_fixup,
0936 .ignore_suspend = 1,
0937 .dpcm_capture = 1,
0938 .no_pcm = 1,
0939 SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
0940 },
0941 {
0942 .name = "iDisp1",
0943 .id = 2,
0944 .dpcm_playback = 1,
0945 .init = kabylake_hdmi1_init,
0946 .no_pcm = 1,
0947 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
0948 },
0949 {
0950 .name = "iDisp2",
0951 .id = 3,
0952 .init = kabylake_hdmi2_init,
0953 .dpcm_playback = 1,
0954 .no_pcm = 1,
0955 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
0956 },
0957 {
0958 .name = "iDisp3",
0959 .id = 4,
0960 .init = kabylake_hdmi3_init,
0961 .dpcm_playback = 1,
0962 .no_pcm = 1,
0963 SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
0964 },
0965 };
0966
0967 static int kabylake_card_late_probe(struct snd_soc_card *card)
0968 {
0969 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
0970 struct kbl_hdmi_pcm *pcm;
0971 struct snd_soc_dapm_context *dapm = &card->dapm;
0972 struct snd_soc_component *component = NULL;
0973 int err, i = 0;
0974 char jack_name[NAME_SIZE];
0975
0976 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
0977 component = pcm->codec_dai->component;
0978 snprintf(jack_name, sizeof(jack_name),
0979 "HDMI/DP, pcm=%d Jack", pcm->device);
0980 err = snd_soc_card_jack_new(card, jack_name,
0981 SND_JACK_AVOUT, &kabylake_hdmi[i]);
0982
0983 if (err)
0984 return err;
0985
0986 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
0987 &kabylake_hdmi[i]);
0988 if (err < 0)
0989 return err;
0990
0991 i++;
0992 }
0993
0994 if (!component)
0995 return -EINVAL;
0996
0997
0998 err = hdac_hdmi_jack_port_init(component, &card->dapm);
0999
1000 if (err < 0)
1001 return err;
1002
1003 err = snd_soc_dapm_disable_pin(dapm, "Left Spk");
1004 if (err) {
1005 dev_err(card->dev, "failed to disable Left Spk: %d\n", err);
1006 return err;
1007 }
1008
1009 err = snd_soc_dapm_disable_pin(dapm, "Right Spk");
1010 if (err) {
1011 dev_err(card->dev, "failed to disable Right Spk: %d\n", err);
1012 return err;
1013 }
1014
1015 return snd_soc_dapm_sync(dapm);
1016 }
1017
1018
1019 static struct snd_soc_card kbl_audio_card_da7219_m98927 = {
1020 .name = "kblda7219m98927",
1021 .owner = THIS_MODULE,
1022 .dai_link = kabylake_dais,
1023 .num_links = ARRAY_SIZE(kabylake_dais),
1024 .controls = kabylake_controls,
1025 .num_controls = ARRAY_SIZE(kabylake_controls),
1026 .dapm_widgets = kabylake_widgets,
1027 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
1028 .dapm_routes = kabylake_map,
1029 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
1030 .codec_conf = max98927_codec_conf,
1031 .num_configs = ARRAY_SIZE(max98927_codec_conf),
1032 .fully_routed = true,
1033 .late_probe = kabylake_card_late_probe,
1034 };
1035
1036
1037 static struct snd_soc_card kbl_audio_card_max98927 = {
1038 .name = "kblmax98927",
1039 .owner = THIS_MODULE,
1040 .dai_link = kabylake_max98_927_373_dais,
1041 .num_links = ARRAY_SIZE(kabylake_max98_927_373_dais),
1042 .controls = kabylake_controls,
1043 .num_controls = ARRAY_SIZE(kabylake_controls),
1044 .dapm_widgets = kabylake_widgets,
1045 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
1046 .dapm_routes = kabylake_map,
1047 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
1048 .codec_conf = max98927_codec_conf,
1049 .num_configs = ARRAY_SIZE(max98927_codec_conf),
1050 .fully_routed = true,
1051 .late_probe = kabylake_card_late_probe,
1052 };
1053
1054 static struct snd_soc_card kbl_audio_card_da7219_m98373 = {
1055 .name = "kblda7219m98373",
1056 .owner = THIS_MODULE,
1057 .dai_link = kabylake_dais,
1058 .num_links = ARRAY_SIZE(kabylake_dais),
1059 .controls = kabylake_controls,
1060 .num_controls = ARRAY_SIZE(kabylake_controls),
1061 .dapm_widgets = kabylake_widgets,
1062 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
1063 .dapm_routes = kabylake_map,
1064 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
1065 .codec_conf = max98373_codec_conf,
1066 .num_configs = ARRAY_SIZE(max98373_codec_conf),
1067 .fully_routed = true,
1068 .late_probe = kabylake_card_late_probe,
1069 };
1070
1071 static struct snd_soc_card kbl_audio_card_max98373 = {
1072 .name = "kblmax98373",
1073 .owner = THIS_MODULE,
1074 .dai_link = kabylake_max98_927_373_dais,
1075 .num_links = ARRAY_SIZE(kabylake_max98_927_373_dais),
1076 .controls = kabylake_controls,
1077 .num_controls = ARRAY_SIZE(kabylake_controls),
1078 .dapm_widgets = kabylake_widgets,
1079 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
1080 .dapm_routes = kabylake_map,
1081 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
1082 .codec_conf = max98373_codec_conf,
1083 .num_configs = ARRAY_SIZE(max98373_codec_conf),
1084 .fully_routed = true,
1085 .late_probe = kabylake_card_late_probe,
1086 };
1087
1088 static int kabylake_audio_probe(struct platform_device *pdev)
1089 {
1090 struct kbl_codec_private *ctx;
1091 struct snd_soc_dai_link *kbl_dai_link;
1092 struct snd_soc_dai_link_component **codecs;
1093 int i;
1094
1095 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1096 if (!ctx)
1097 return -ENOMEM;
1098
1099 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
1100
1101 kabylake_audio_card =
1102 (struct snd_soc_card *)pdev->id_entry->driver_data;
1103
1104 kbl_dai_link = kabylake_audio_card->dai_link;
1105
1106
1107 if (!strcmp(pdev->name, "kbl_da7219_max98373") ||
1108 (!strcmp(pdev->name, "kbl_max98373"))) {
1109 for (i = 0; i < kabylake_audio_card->num_links; ++i) {
1110 if (strcmp(kbl_dai_link[i].name, "SSP0-Codec"))
1111 continue;
1112
1113 codecs = &(kbl_dai_link[i].codecs);
1114 *codecs = max98373_ssp0_codec_components;
1115 kbl_dai_link[i].num_codecs =
1116 ARRAY_SIZE(max98373_ssp0_codec_components);
1117 break;
1118 }
1119 }
1120 kabylake_audio_card->dev = &pdev->dev;
1121 snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
1122
1123 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
1124 }
1125
1126 static const struct platform_device_id kbl_board_ids[] = {
1127 {
1128 .name = "kbl_da7219_max98927",
1129 .driver_data =
1130 (kernel_ulong_t)&kbl_audio_card_da7219_m98927,
1131 },
1132 {
1133 .name = "kbl_max98927",
1134 .driver_data =
1135 (kernel_ulong_t)&kbl_audio_card_max98927,
1136 },
1137 {
1138 .name = "kbl_da7219_max98373",
1139 .driver_data =
1140 (kernel_ulong_t)&kbl_audio_card_da7219_m98373,
1141 },
1142 {
1143 .name = "kbl_max98373",
1144 .driver_data =
1145 (kernel_ulong_t)&kbl_audio_card_max98373,
1146 },
1147 { }
1148 };
1149 MODULE_DEVICE_TABLE(platform, kbl_board_ids);
1150
1151 static struct platform_driver kabylake_audio = {
1152 .probe = kabylake_audio_probe,
1153 .driver = {
1154 .name = "kbl_da7219_max98_927_373",
1155 .pm = &snd_soc_pm_ops,
1156 },
1157 .id_table = kbl_board_ids,
1158 };
1159
1160 module_platform_driver(kabylake_audio)
1161
1162
1163 MODULE_DESCRIPTION("Audio KabyLake Machine driver for MAX98927/MAX98373 & DA7219");
1164 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
1165 MODULE_LICENSE("GPL v2");