linux/sound/soc/intel/boards/kbl_da7219_max98357a.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-only
   2// Copyright(c) 2017-18 Intel Corporation.
   3
   4/*
   5 * Intel Kabylake I2S Machine Driver with MAX98357A & DA7219 Codecs
   6 *
   7 * Modified from:
   8 *   Intel Kabylake I2S Machine driver supporting MAXIM98927 and
   9 *   RT5663 codecs
  10 */
  11
  12#include <linux/input.h>
  13#include <linux/module.h>
  14#include <linux/platform_device.h>
  15#include <sound/core.h>
  16#include <sound/jack.h>
  17#include <sound/pcm.h>
  18#include <sound/pcm_params.h>
  19#include <sound/soc.h>
  20#include "../../codecs/da7219.h"
  21#include "../../codecs/hdac_hdmi.h"
  22#include "../../codecs/da7219-aad.h"
  23
  24#define KBL_DIALOG_CODEC_DAI "da7219-hifi"
  25#define KBL_MAXIM_CODEC_DAI "HiFi"
  26#define MAXIM_DEV0_NAME "MX98357A:00"
  27#define DUAL_CHANNEL 2
  28#define QUAD_CHANNEL 4
  29
  30static struct snd_soc_card *kabylake_audio_card;
  31static struct snd_soc_jack skylake_hdmi[3];
  32
  33struct kbl_hdmi_pcm {
  34        struct list_head head;
  35        struct snd_soc_dai *codec_dai;
  36        int device;
  37};
  38
  39struct kbl_codec_private {
  40        struct snd_soc_jack kabylake_headset;
  41        struct list_head hdmi_pcm_list;
  42};
  43
  44enum {
  45        KBL_DPCM_AUDIO_PB = 0,
  46        KBL_DPCM_AUDIO_CP,
  47        KBL_DPCM_AUDIO_REF_CP,
  48        KBL_DPCM_AUDIO_DMIC_CP,
  49        KBL_DPCM_AUDIO_HDMI1_PB,
  50        KBL_DPCM_AUDIO_HDMI2_PB,
  51        KBL_DPCM_AUDIO_HDMI3_PB,
  52};
  53
  54static int platform_clock_control(struct snd_soc_dapm_widget *w,
  55                                        struct snd_kcontrol *k, int  event)
  56{
  57        struct snd_soc_dapm_context *dapm = w->dapm;
  58        struct snd_soc_card *card = dapm->card;
  59        struct snd_soc_dai *codec_dai;
  60        int ret = 0;
  61
  62        codec_dai = snd_soc_card_get_codec_dai(card, KBL_DIALOG_CODEC_DAI);
  63        if (!codec_dai) {
  64                dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n");
  65                return -EIO;
  66        }
  67
  68        if (SND_SOC_DAPM_EVENT_OFF(event)) {
  69                ret = snd_soc_dai_set_pll(codec_dai, 0,
  70                                     DA7219_SYSCLK_MCLK, 0, 0);
  71                if (ret)
  72                        dev_err(card->dev, "failed to stop PLL: %d\n", ret);
  73        } else if (SND_SOC_DAPM_EVENT_ON(event)) {
  74                ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL_SRM,
  75                                     0, DA7219_PLL_FREQ_OUT_98304);
  76                if (ret)
  77                        dev_err(card->dev, "failed to start PLL: %d\n", ret);
  78        }
  79
  80        return ret;
  81}
  82
  83static const struct snd_kcontrol_new kabylake_controls[] = {
  84        SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  85        SOC_DAPM_PIN_SWITCH("Headset Mic"),
  86        SOC_DAPM_PIN_SWITCH("Spk"),
  87};
  88
  89static const struct snd_soc_dapm_widget kabylake_widgets[] = {
  90        SND_SOC_DAPM_HP("Headphone Jack", NULL),
  91        SND_SOC_DAPM_MIC("Headset Mic", NULL),
  92        SND_SOC_DAPM_SPK("Spk", NULL),
  93        SND_SOC_DAPM_MIC("SoC DMIC", NULL),
  94        SND_SOC_DAPM_SPK("HDMI1", NULL),
  95        SND_SOC_DAPM_SPK("HDMI2", NULL),
  96        SND_SOC_DAPM_SPK("HDMI3", NULL),
  97        SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
  98                        platform_clock_control, SND_SOC_DAPM_PRE_PMU |
  99                        SND_SOC_DAPM_POST_PMD),
 100};
 101
 102static const struct snd_soc_dapm_route kabylake_map[] = {
 103        { "Headphone Jack", NULL, "HPL" },
 104        { "Headphone Jack", NULL, "HPR" },
 105
 106        /* speaker */
 107        { "Spk", NULL, "Speaker" },
 108
 109        /* other jacks */
 110        { "MIC", NULL, "Headset Mic" },
 111        { "DMic", NULL, "SoC DMIC" },
 112
 113        {"HDMI1", NULL, "hif5-0 Output"},
 114        {"HDMI2", NULL, "hif6-0 Output"},
 115        {"HDMI3", NULL, "hif7-0 Output"},
 116
 117        /* CODEC BE connections */
 118        { "HiFi Playback", NULL, "ssp0 Tx" },
 119        { "ssp0 Tx", NULL, "codec0_out" },
 120
 121        { "Playback", NULL, "ssp1 Tx" },
 122        { "ssp1 Tx", NULL, "codec1_out" },
 123
 124        { "codec0_in", NULL, "ssp1 Rx" },
 125        { "ssp1 Rx", NULL, "Capture" },
 126
 127        /* DMIC */
 128        { "dmic01_hifi", NULL, "DMIC01 Rx" },
 129        { "DMIC01 Rx", NULL, "DMIC AIF" },
 130
 131        { "hifi1", NULL, "iDisp1 Tx" },
 132        { "iDisp1 Tx", NULL, "iDisp1_out" },
 133        { "hifi2", NULL, "iDisp2 Tx" },
 134        { "iDisp2 Tx", NULL, "iDisp2_out" },
 135        { "hifi3", NULL, "iDisp3 Tx"},
 136        { "iDisp3 Tx", NULL, "iDisp3_out"},
 137
 138        { "Headphone Jack", NULL, "Platform Clock" },
 139        { "Headset Mic", NULL, "Platform Clock" },
 140};
 141
 142static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
 143                        struct snd_pcm_hw_params *params)
 144{
 145        struct snd_interval *rate = hw_param_interval(params,
 146                        SNDRV_PCM_HW_PARAM_RATE);
 147        struct snd_interval *chan = hw_param_interval(params,
 148                        SNDRV_PCM_HW_PARAM_CHANNELS);
 149        struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
 150
 151        /* The ADSP will convert the FE rate to 48k, stereo */
 152        rate->min = rate->max = 48000;
 153        chan->min = chan->max = DUAL_CHANNEL;
 154
 155        /* set SSP to 24 bit */
 156        snd_mask_none(fmt);
 157        snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
 158
 159        return 0;
 160}
 161
 162static int kabylake_da7219_codec_init(struct snd_soc_pcm_runtime *rtd)
 163{
 164        struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
 165        struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
 166        struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
 167        struct snd_soc_jack *jack;
 168        int ret;
 169
 170        /* Configure sysclk for codec */
 171        ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 24576000,
 172                                                SND_SOC_CLOCK_IN);
 173        if (ret) {
 174                dev_err(rtd->dev, "can't set codec sysclk configuration\n");
 175                return ret;
 176        }
 177
 178        /*
 179         * Headset buttons map to the google Reference headset.
 180         * These can be configured by userspace.
 181         */
 182        ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
 183                        SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
 184                        SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT,
 185                        &ctx->kabylake_headset);
 186        if (ret) {
 187                dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
 188                return ret;
 189        }
 190
 191        jack = &ctx->kabylake_headset;
 192
 193        snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
 194        snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
 195        snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
 196        snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
 197        da7219_aad_jack_det(component, &ctx->kabylake_headset);
 198
 199        ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
 200        if (ret)
 201                dev_err(rtd->dev, "SoC DMIC - Ignore suspend failed %d\n", ret);
 202
 203        return ret;
 204}
 205
 206static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
 207{
 208        struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
 209        struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
 210        struct kbl_hdmi_pcm *pcm;
 211
 212        pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
 213        if (!pcm)
 214                return -ENOMEM;
 215
 216        pcm->device = device;
 217        pcm->codec_dai = dai;
 218
 219        list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
 220
 221        return 0;
 222}
 223
 224static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
 225{
 226        return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
 227}
 228
 229static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
 230{
 231        return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
 232}
 233
 234static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
 235{
 236        return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
 237}
 238
 239static int kabylake_da7219_fe_init(struct snd_soc_pcm_runtime *rtd)
 240{
 241        struct snd_soc_dapm_context *dapm;
 242        struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component;
 243
 244        dapm = snd_soc_component_get_dapm(component);
 245        snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
 246
 247        return 0;
 248}
 249
 250static const unsigned int rates[] = {
 251        48000,
 252};
 253
 254static const struct snd_pcm_hw_constraint_list constraints_rates = {
 255        .count = ARRAY_SIZE(rates),
 256        .list  = rates,
 257        .mask = 0,
 258};
 259
 260static const unsigned int channels[] = {
 261        DUAL_CHANNEL,
 262};
 263
 264static const struct snd_pcm_hw_constraint_list constraints_channels = {
 265        .count = ARRAY_SIZE(channels),
 266        .list = channels,
 267        .mask = 0,
 268};
 269
 270static unsigned int channels_quad[] = {
 271        QUAD_CHANNEL,
 272};
 273
 274static struct snd_pcm_hw_constraint_list constraints_channels_quad = {
 275        .count = ARRAY_SIZE(channels_quad),
 276        .list = channels_quad,
 277        .mask = 0,
 278};
 279
 280static int kbl_fe_startup(struct snd_pcm_substream *substream)
 281{
 282        struct snd_pcm_runtime *runtime = substream->runtime;
 283
 284        /*
 285         * On this platform for PCM device we support,
 286         * 48Khz
 287         * stereo
 288         * 16 bit audio
 289         */
 290
 291        runtime->hw.channels_max = DUAL_CHANNEL;
 292        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
 293                                           &constraints_channels);
 294
 295        runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
 296        snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
 297
 298        snd_pcm_hw_constraint_list(runtime, 0,
 299                                SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
 300
 301        return 0;
 302}
 303
 304static const struct snd_soc_ops kabylake_da7219_fe_ops = {
 305        .startup = kbl_fe_startup,
 306};
 307
 308static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
 309                struct snd_pcm_hw_params *params)
 310{
 311        struct snd_interval *chan = hw_param_interval(params,
 312                                SNDRV_PCM_HW_PARAM_CHANNELS);
 313
 314        /*
 315         * set BE channel constraint as user FE channels
 316         */
 317
 318        if (params_channels(params) == 2)
 319                chan->min = chan->max = 2;
 320        else
 321                chan->min = chan->max = 4;
 322
 323        return 0;
 324}
 325
 326static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
 327{
 328        struct snd_pcm_runtime *runtime = substream->runtime;
 329
 330        runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL;
 331        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
 332                        &constraints_channels_quad);
 333
 334        return snd_pcm_hw_constraint_list(substream->runtime, 0,
 335                        SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
 336}
 337
 338static struct snd_soc_ops kabylake_dmic_ops = {
 339        .startup = kabylake_dmic_startup,
 340};
 341
 342static unsigned int rates_16000[] = {
 343        16000,
 344};
 345
 346static const struct snd_pcm_hw_constraint_list constraints_16000 = {
 347        .count = ARRAY_SIZE(rates_16000),
 348        .list  = rates_16000,
 349};
 350
 351static const unsigned int ch_mono[] = {
 352        1,
 353};
 354
 355static const struct snd_pcm_hw_constraint_list constraints_refcap = {
 356        .count = ARRAY_SIZE(ch_mono),
 357        .list  = ch_mono,
 358};
 359
 360static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
 361{
 362        substream->runtime->hw.channels_max = 1;
 363        snd_pcm_hw_constraint_list(substream->runtime, 0,
 364                                        SNDRV_PCM_HW_PARAM_CHANNELS,
 365                                        &constraints_refcap);
 366
 367        return snd_pcm_hw_constraint_list(substream->runtime, 0,
 368                                        SNDRV_PCM_HW_PARAM_RATE,
 369                                        &constraints_16000);
 370}
 371
 372static struct snd_soc_ops skylake_refcap_ops = {
 373        .startup = kabylake_refcap_startup,
 374};
 375
 376SND_SOC_DAILINK_DEF(dummy,
 377        DAILINK_COMP_ARRAY(COMP_DUMMY()));
 378
 379SND_SOC_DAILINK_DEF(system,
 380        DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
 381
 382SND_SOC_DAILINK_DEF(reference,
 383        DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
 384
 385SND_SOC_DAILINK_DEF(dmic,
 386        DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
 387
 388SND_SOC_DAILINK_DEF(hdmi1,
 389        DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
 390
 391SND_SOC_DAILINK_DEF(hdmi2,
 392        DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
 393
 394SND_SOC_DAILINK_DEF(hdmi3,
 395        DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
 396
 397SND_SOC_DAILINK_DEF(ssp0_pin,
 398        DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
 399SND_SOC_DAILINK_DEF(ssp0_codec,
 400        DAILINK_COMP_ARRAY(COMP_CODEC(MAXIM_DEV0_NAME,
 401                                      KBL_MAXIM_CODEC_DAI)));
 402
 403SND_SOC_DAILINK_DEF(ssp1_pin,
 404        DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
 405SND_SOC_DAILINK_DEF(ssp1_codec,
 406        DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00",
 407                                      KBL_DIALOG_CODEC_DAI)));
 408
 409SND_SOC_DAILINK_DEF(dmic_pin,
 410        DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
 411SND_SOC_DAILINK_DEF(dmic_codec,
 412        DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
 413
 414SND_SOC_DAILINK_DEF(idisp1_pin,
 415        DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
 416SND_SOC_DAILINK_DEF(idisp1_codec,
 417        DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2",
 418                                      "intel-hdmi-hifi1")));
 419
 420SND_SOC_DAILINK_DEF(idisp2_pin,
 421        DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
 422SND_SOC_DAILINK_DEF(idisp2_codec,
 423        DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
 424
 425SND_SOC_DAILINK_DEF(idisp3_pin,
 426        DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
 427SND_SOC_DAILINK_DEF(idisp3_codec,
 428        DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
 429
 430SND_SOC_DAILINK_DEF(platform,
 431        DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
 432
 433/* kabylake digital audio interface glue - connects codec <--> CPU */
 434static struct snd_soc_dai_link kabylake_dais[] = {
 435        /* Front End DAI links */
 436        [KBL_DPCM_AUDIO_PB] = {
 437                .name = "Kbl Audio Port",
 438                .stream_name = "Audio",
 439                .dynamic = 1,
 440                .nonatomic = 1,
 441                .init = kabylake_da7219_fe_init,
 442                .trigger = {
 443                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 444                .dpcm_playback = 1,
 445                .ops = &kabylake_da7219_fe_ops,
 446                SND_SOC_DAILINK_REG(system, dummy, platform),
 447        },
 448        [KBL_DPCM_AUDIO_CP] = {
 449                .name = "Kbl Audio Capture Port",
 450                .stream_name = "Audio Record",
 451                .dynamic = 1,
 452                .nonatomic = 1,
 453                .trigger = {
 454                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 455                .dpcm_capture = 1,
 456                .ops = &kabylake_da7219_fe_ops,
 457                SND_SOC_DAILINK_REG(system, dummy, platform),
 458        },
 459        [KBL_DPCM_AUDIO_REF_CP] = {
 460                .name = "Kbl Audio Reference cap",
 461                .stream_name = "Wake on Voice",
 462                .init = NULL,
 463                .dpcm_capture = 1,
 464                .nonatomic = 1,
 465                .dynamic = 1,
 466                .ops = &skylake_refcap_ops,
 467                SND_SOC_DAILINK_REG(reference, dummy, platform),
 468        },
 469        [KBL_DPCM_AUDIO_DMIC_CP] = {
 470                .name = "Kbl Audio DMIC cap",
 471                .stream_name = "dmiccap",
 472                .init = NULL,
 473                .dpcm_capture = 1,
 474                .nonatomic = 1,
 475                .dynamic = 1,
 476                .ops = &kabylake_dmic_ops,
 477                SND_SOC_DAILINK_REG(dmic, dummy, platform),
 478        },
 479        [KBL_DPCM_AUDIO_HDMI1_PB] = {
 480                .name = "Kbl HDMI Port1",
 481                .stream_name = "Hdmi1",
 482                .dpcm_playback = 1,
 483                .init = NULL,
 484                .trigger = {
 485                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 486                .nonatomic = 1,
 487                .dynamic = 1,
 488                SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
 489        },
 490        [KBL_DPCM_AUDIO_HDMI2_PB] = {
 491                .name = "Kbl HDMI Port2",
 492                .stream_name = "Hdmi2",
 493                .dpcm_playback = 1,
 494                .init = NULL,
 495                .trigger = {
 496                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 497                .nonatomic = 1,
 498                .dynamic = 1,
 499                SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
 500        },
 501        [KBL_DPCM_AUDIO_HDMI3_PB] = {
 502                .name = "Kbl HDMI Port3",
 503                .stream_name = "Hdmi3",
 504                .trigger = {
 505                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 506                .dpcm_playback = 1,
 507                .init = NULL,
 508                .nonatomic = 1,
 509                .dynamic = 1,
 510                SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
 511        },
 512
 513        /* Back End DAI links */
 514        {
 515                /* SSP0 - Codec */
 516                .name = "SSP0-Codec",
 517                .id = 0,
 518                .no_pcm = 1,
 519                .dai_fmt = SND_SOC_DAIFMT_I2S |
 520                        SND_SOC_DAIFMT_NB_NF |
 521                        SND_SOC_DAIFMT_CBC_CFC,
 522                .ignore_pmdown_time = 1,
 523                .be_hw_params_fixup = kabylake_ssp_fixup,
 524                .dpcm_playback = 1,
 525                SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
 526        },
 527        {
 528                /* SSP1 - Codec */
 529                .name = "SSP1-Codec",
 530                .id = 1,
 531                .no_pcm = 1,
 532                .init = kabylake_da7219_codec_init,
 533                .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
 534                        SND_SOC_DAIFMT_CBC_CFC,
 535                .ignore_pmdown_time = 1,
 536                .be_hw_params_fixup = kabylake_ssp_fixup,
 537                .dpcm_playback = 1,
 538                .dpcm_capture = 1,
 539                SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform),
 540        },
 541        {
 542                .name = "dmic01",
 543                .id = 2,
 544                .be_hw_params_fixup = kabylake_dmic_fixup,
 545                .ignore_suspend = 1,
 546                .dpcm_capture = 1,
 547                .no_pcm = 1,
 548                SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
 549        },
 550        {
 551                .name = "iDisp1",
 552                .id = 3,
 553                .dpcm_playback = 1,
 554                .init = kabylake_hdmi1_init,
 555                .no_pcm = 1,
 556                SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
 557        },
 558        {
 559                .name = "iDisp2",
 560                .id = 4,
 561                .init = kabylake_hdmi2_init,
 562                .dpcm_playback = 1,
 563                .no_pcm = 1,
 564                SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
 565        },
 566        {
 567                .name = "iDisp3",
 568                .id = 5,
 569                .init = kabylake_hdmi3_init,
 570                .dpcm_playback = 1,
 571                .no_pcm = 1,
 572                SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
 573        },
 574};
 575
 576#define NAME_SIZE       32
 577static int kabylake_card_late_probe(struct snd_soc_card *card)
 578{
 579        struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
 580        struct kbl_hdmi_pcm *pcm;
 581        struct snd_soc_component *component = NULL;
 582        int err, i = 0;
 583        char jack_name[NAME_SIZE];
 584
 585        list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
 586                component = pcm->codec_dai->component;
 587                snprintf(jack_name, sizeof(jack_name),
 588                        "HDMI/DP, pcm=%d Jack", pcm->device);
 589                err = snd_soc_card_jack_new(card, jack_name,
 590                                        SND_JACK_AVOUT, &skylake_hdmi[i]);
 591
 592                if (err)
 593                        return err;
 594
 595                err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
 596                                &skylake_hdmi[i]);
 597                if (err < 0)
 598                        return err;
 599
 600                i++;
 601
 602        }
 603
 604        if (!component)
 605                return -EINVAL;
 606
 607        return hdac_hdmi_jack_port_init(component, &card->dapm);
 608}
 609
 610/* kabylake audio machine driver for SPT + DA7219 */
 611static struct snd_soc_card kabylake_audio_card_da7219_m98357a = {
 612        .name = "kblda7219max",
 613        .owner = THIS_MODULE,
 614        .dai_link = kabylake_dais,
 615        .num_links = ARRAY_SIZE(kabylake_dais),
 616        .controls = kabylake_controls,
 617        .num_controls = ARRAY_SIZE(kabylake_controls),
 618        .dapm_widgets = kabylake_widgets,
 619        .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
 620        .dapm_routes = kabylake_map,
 621        .num_dapm_routes = ARRAY_SIZE(kabylake_map),
 622        .fully_routed = true,
 623        .late_probe = kabylake_card_late_probe,
 624};
 625
 626static int kabylake_audio_probe(struct platform_device *pdev)
 627{
 628        struct kbl_codec_private *ctx;
 629
 630        ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
 631        if (!ctx)
 632                return -ENOMEM;
 633
 634        INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
 635
 636        kabylake_audio_card =
 637                (struct snd_soc_card *)pdev->id_entry->driver_data;
 638
 639        kabylake_audio_card->dev = &pdev->dev;
 640        snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
 641        return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
 642}
 643
 644static const struct platform_device_id kbl_board_ids[] = {
 645        {
 646                .name = "kbl_da7219_mx98357a",
 647                .driver_data =
 648                        (kernel_ulong_t)&kabylake_audio_card_da7219_m98357a,
 649        },
 650        { }
 651};
 652MODULE_DEVICE_TABLE(platform, kbl_board_ids);
 653
 654static struct platform_driver kabylake_audio = {
 655        .probe = kabylake_audio_probe,
 656        .driver = {
 657                .name = "kbl_da7219_max98357a",
 658                .pm = &snd_soc_pm_ops,
 659        },
 660        .id_table = kbl_board_ids,
 661};
 662
 663module_platform_driver(kabylake_audio)
 664
 665/* Module information */
 666MODULE_DESCRIPTION("Audio Machine driver-DA7219 & MAX98357A in I2S mode");
 667MODULE_AUTHOR("Naveen Manohar <naveen.m@intel.com>");
 668MODULE_LICENSE("GPL v2");
 669