linux/sound/soc/intel/boards/kbl_da7219_max98927.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2// Copyright(c) 2018 Intel Corporation.
   3
   4/*
   5 * Intel Kabylake I2S Machine Driver with MAX98927 & DA7219 Codecs
   6 *
   7 * Modified from:
   8 *   Intel Kabylake I2S Machine driver supporting MAX98927 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 "../skylake/skl.h"
  23#include "../../codecs/da7219-aad.h"
  24
  25#define KBL_DIALOG_CODEC_DAI    "da7219-hifi"
  26#define MAX98927_CODEC_DAI      "max98927-aif1"
  27#define MAXIM_DEV0_NAME         "i2c-MX98927:00"
  28#define MAXIM_DEV1_NAME         "i2c-MX98927:01"
  29#define DUAL_CHANNEL    2
  30#define QUAD_CHANNEL    4
  31#define NAME_SIZE       32
  32
  33static struct snd_soc_card *kabylake_audio_card;
  34static struct snd_soc_jack kabylake_hdmi[3];
  35
  36struct kbl_hdmi_pcm {
  37        struct list_head head;
  38        struct snd_soc_dai *codec_dai;
  39        int device;
  40};
  41
  42struct kbl_codec_private {
  43        struct snd_soc_jack kabylake_headset;
  44        struct list_head hdmi_pcm_list;
  45};
  46
  47enum {
  48        KBL_DPCM_AUDIO_PB = 0,
  49        KBL_DPCM_AUDIO_CP,
  50        KBL_DPCM_AUDIO_ECHO_REF_CP,
  51        KBL_DPCM_AUDIO_REF_CP,
  52        KBL_DPCM_AUDIO_DMIC_CP,
  53        KBL_DPCM_AUDIO_HDMI1_PB,
  54        KBL_DPCM_AUDIO_HDMI2_PB,
  55        KBL_DPCM_AUDIO_HDMI3_PB,
  56        KBL_DPCM_AUDIO_HS_PB,
  57};
  58
  59static int platform_clock_control(struct snd_soc_dapm_widget *w,
  60                                        struct snd_kcontrol *k, int  event)
  61{
  62        struct snd_soc_dapm_context *dapm = w->dapm;
  63        struct snd_soc_card *card = dapm->card;
  64        struct snd_soc_dai *codec_dai;
  65        int ret = 0;
  66
  67        codec_dai = snd_soc_card_get_codec_dai(card, KBL_DIALOG_CODEC_DAI);
  68        if (!codec_dai) {
  69                dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n");
  70                return -EIO;
  71        }
  72
  73        /* Configure sysclk for codec */
  74        ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 24576000,
  75                                     SND_SOC_CLOCK_IN);
  76        if (ret) {
  77                dev_err(card->dev, "can't set codec sysclk configuration\n");
  78                return ret;
  79        }
  80
  81        if (SND_SOC_DAPM_EVENT_OFF(event)) {
  82                ret = snd_soc_dai_set_pll(codec_dai, 0,
  83                                     DA7219_SYSCLK_MCLK, 0, 0);
  84                if (ret)
  85                        dev_err(card->dev, "failed to stop PLL: %d\n", ret);
  86        } else if (SND_SOC_DAPM_EVENT_ON(event)) {
  87                ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL_SRM,
  88                                     0, DA7219_PLL_FREQ_OUT_98304);
  89                if (ret)
  90                        dev_err(card->dev, "failed to start PLL: %d\n", ret);
  91        }
  92
  93        return ret;
  94}
  95
  96static const struct snd_kcontrol_new kabylake_controls[] = {
  97        SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  98        SOC_DAPM_PIN_SWITCH("Headset Mic"),
  99        SOC_DAPM_PIN_SWITCH("Left Spk"),
 100        SOC_DAPM_PIN_SWITCH("Right Spk"),
 101};
 102
 103static const struct snd_soc_dapm_widget kabylake_widgets[] = {
 104        SND_SOC_DAPM_HP("Headphone Jack", NULL),
 105        SND_SOC_DAPM_MIC("Headset Mic", NULL),
 106        SND_SOC_DAPM_SPK("Left Spk", NULL),
 107        SND_SOC_DAPM_SPK("Right Spk", NULL),
 108        SND_SOC_DAPM_MIC("SoC DMIC", NULL),
 109        SND_SOC_DAPM_SPK("DP", NULL),
 110        SND_SOC_DAPM_SPK("HDMI", NULL),
 111        SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
 112                        platform_clock_control, SND_SOC_DAPM_PRE_PMU |
 113                        SND_SOC_DAPM_POST_PMD),
 114};
 115
 116static const struct snd_soc_dapm_route kabylake_map[] = {
 117        /* speaker */
 118        { "Left Spk", NULL, "Left BE_OUT" },
 119        { "Right Spk", NULL, "Right BE_OUT" },
 120
 121        /* other jacks */
 122        { "DMic", NULL, "SoC DMIC" },
 123
 124        { "HDMI", NULL, "hif5 Output" },
 125        { "DP", NULL, "hif6 Output" },
 126
 127        /* CODEC BE connections */
 128        { "Left HiFi Playback", NULL, "ssp0 Tx" },
 129        { "Right HiFi Playback", NULL, "ssp0 Tx" },
 130        { "ssp0 Tx", NULL, "spk_out" },
 131
 132        /* IV feedback path */
 133        { "codec0_fb_in", NULL, "ssp0 Rx"},
 134        { "ssp0 Rx", NULL, "Left HiFi Capture" },
 135        { "ssp0 Rx", NULL, "Right HiFi Capture" },
 136
 137        /* AEC capture path */
 138        { "echo_ref_out", NULL, "ssp0 Rx" },
 139
 140        /* DMIC */
 141        { "dmic01_hifi", NULL, "DMIC01 Rx" },
 142        { "DMIC01 Rx", NULL, "DMIC AIF" },
 143
 144        { "hifi1", NULL, "iDisp1 Tx" },
 145        { "iDisp1 Tx", NULL, "iDisp1_out" },
 146        { "hifi2", NULL, "iDisp2 Tx" },
 147        { "iDisp2 Tx", NULL, "iDisp2_out" },
 148        { "hifi3", NULL, "iDisp3 Tx"},
 149        { "iDisp3 Tx", NULL, "iDisp3_out"},
 150};
 151
 152static const struct snd_soc_dapm_route kabylake_ssp1_map[] = {
 153        { "Headphone Jack", NULL, "HPL" },
 154        { "Headphone Jack", NULL, "HPR" },
 155
 156        /* other jacks */
 157        { "MIC", NULL, "Headset Mic" },
 158
 159        /* CODEC BE connections */
 160        { "Playback", NULL, "ssp1 Tx" },
 161        { "ssp1 Tx", NULL, "codec1_out" },
 162
 163        { "hs_in", NULL, "ssp1 Rx" },
 164        { "ssp1 Rx", NULL, "Capture" },
 165
 166        { "Headphone Jack", NULL, "Platform Clock" },
 167        { "Headset Mic", NULL, "Platform Clock" },
 168};
 169
 170static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
 171        struct snd_pcm_hw_params *params)
 172{
 173        struct snd_soc_pcm_runtime *runtime = substream->private_data;
 174        int ret = 0, j;
 175
 176        for (j = 0; j < runtime->num_codecs; j++) {
 177                struct snd_soc_dai *codec_dai = runtime->codec_dais[j];
 178
 179                if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
 180                        ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
 181                        if (ret < 0) {
 182                                dev_err(runtime->dev, "DEV0 TDM slot err:%d\n", ret);
 183                                return ret;
 184                        }
 185                }
 186                if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
 187                        ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
 188                        if (ret < 0) {
 189                                dev_err(runtime->dev, "DEV1 TDM slot err:%d\n", ret);
 190                                return ret;
 191                        }
 192                }
 193        }
 194
 195        return 0;
 196}
 197
 198static struct snd_soc_ops kabylake_ssp0_ops = {
 199        .hw_params = kabylake_ssp0_hw_params,
 200};
 201
 202static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
 203                        struct snd_pcm_hw_params *params)
 204{
 205        struct snd_interval *rate = hw_param_interval(params,
 206                        SNDRV_PCM_HW_PARAM_RATE);
 207        struct snd_interval *channels = hw_param_interval(params,
 208                        SNDRV_PCM_HW_PARAM_CHANNELS);
 209        struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
 210        struct snd_soc_dpcm *dpcm = container_of(
 211                        params, struct snd_soc_dpcm, hw_params);
 212        struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
 213        struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
 214
 215        /*
 216         * The ADSP will convert the FE rate to 48k, stereo, 24 bit
 217         */
 218        if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
 219            !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
 220            !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
 221                rate->min = rate->max = 48000;
 222                channels->min = channels->max = 2;
 223                snd_mask_none(fmt);
 224                snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
 225        }
 226
 227        /*
 228         * The speaker on the SSP0 supports S16_LE and not S24_LE.
 229         * thus changing the mask here
 230         */
 231        if (!strcmp(be_dai_link->name, "SSP0-Codec"))
 232                snd_mask_set(fmt, SNDRV_PCM_FORMAT_S16_LE);
 233
 234        return 0;
 235}
 236
 237static int kabylake_da7219_codec_init(struct snd_soc_pcm_runtime *rtd)
 238{
 239        struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
 240        struct snd_soc_component *component = rtd->codec_dai->component;
 241        struct snd_soc_jack *jack;
 242        struct snd_soc_card *card = rtd->card;
 243        int ret;
 244
 245
 246        ret = snd_soc_dapm_add_routes(&card->dapm,
 247                        kabylake_ssp1_map,
 248                        ARRAY_SIZE(kabylake_ssp1_map));
 249
 250        /*
 251         * Headset buttons map to the google Reference headset.
 252         * These can be configured by userspace.
 253         */
 254        ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
 255                        SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
 256                        SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT,
 257                        &ctx->kabylake_headset, NULL, 0);
 258        if (ret) {
 259                dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
 260                return ret;
 261        }
 262
 263        jack = &ctx->kabylake_headset;
 264        snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
 265        snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
 266        snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
 267        snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
 268
 269        da7219_aad_jack_det(component, &ctx->kabylake_headset);
 270
 271        ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
 272        if (ret)
 273                dev_err(rtd->dev, "SoC DMIC - Ignore suspend failed %d\n", ret);
 274
 275        return ret;
 276}
 277
 278static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
 279{
 280        struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
 281        struct snd_soc_dai *dai = rtd->codec_dai;
 282        struct kbl_hdmi_pcm *pcm;
 283
 284        pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
 285        if (!pcm)
 286                return -ENOMEM;
 287
 288        pcm->device = device;
 289        pcm->codec_dai = dai;
 290
 291        list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
 292
 293        return 0;
 294}
 295
 296static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
 297{
 298        return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
 299}
 300
 301static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
 302{
 303        return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
 304}
 305
 306static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
 307{
 308        return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
 309}
 310
 311static int kabylake_da7219_fe_init(struct snd_soc_pcm_runtime *rtd)
 312{
 313        struct snd_soc_dapm_context *dapm;
 314        struct snd_soc_component *component = rtd->cpu_dai->component;
 315
 316        dapm = snd_soc_component_get_dapm(component);
 317        snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
 318
 319        return 0;
 320}
 321
 322static const unsigned int rates[] = {
 323        48000,
 324};
 325
 326static const struct snd_pcm_hw_constraint_list constraints_rates = {
 327        .count = ARRAY_SIZE(rates),
 328        .list  = rates,
 329        .mask = 0,
 330};
 331
 332static const unsigned int channels[] = {
 333        DUAL_CHANNEL,
 334};
 335
 336static const struct snd_pcm_hw_constraint_list constraints_channels = {
 337        .count = ARRAY_SIZE(channels),
 338        .list = channels,
 339        .mask = 0,
 340};
 341
 342static unsigned int channels_quad[] = {
 343        QUAD_CHANNEL,
 344};
 345
 346static struct snd_pcm_hw_constraint_list constraints_channels_quad = {
 347        .count = ARRAY_SIZE(channels_quad),
 348        .list = channels_quad,
 349        .mask = 0,
 350};
 351
 352static int kbl_fe_startup(struct snd_pcm_substream *substream)
 353{
 354        struct snd_pcm_runtime *runtime = substream->runtime;
 355
 356        /*
 357         * On this platform for PCM device we support,
 358         * 48Khz
 359         * stereo
 360         * 16 bit audio
 361         */
 362
 363        runtime->hw.channels_max = DUAL_CHANNEL;
 364        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
 365                                           &constraints_channels);
 366
 367        runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
 368        snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
 369
 370        snd_pcm_hw_constraint_list(runtime, 0,
 371                                SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
 372
 373        return 0;
 374}
 375
 376static const struct snd_soc_ops kabylake_da7219_fe_ops = {
 377        .startup = kbl_fe_startup,
 378};
 379
 380static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
 381                struct snd_pcm_hw_params *params)
 382{
 383        struct snd_interval *channels = hw_param_interval(params,
 384                                SNDRV_PCM_HW_PARAM_CHANNELS);
 385
 386        /*
 387         * set BE channel constraint as user FE channels
 388         */
 389
 390        if (params_channels(params) == 2)
 391                channels->min = channels->max = 2;
 392        else
 393                channels->min = channels->max = 4;
 394
 395        return 0;
 396}
 397
 398static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
 399{
 400        struct snd_pcm_runtime *runtime = substream->runtime;
 401
 402        runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL;
 403        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
 404                        &constraints_channels_quad);
 405
 406        return snd_pcm_hw_constraint_list(substream->runtime, 0,
 407                        SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
 408}
 409
 410static struct snd_soc_ops kabylake_dmic_ops = {
 411        .startup = kabylake_dmic_startup,
 412};
 413
 414static const unsigned int rates_16000[] = {
 415        16000,
 416};
 417
 418static const struct snd_pcm_hw_constraint_list constraints_16000 = {
 419        .count = ARRAY_SIZE(rates_16000),
 420        .list  = rates_16000,
 421};
 422
 423static const unsigned int ch_mono[] = {
 424        1,
 425};
 426static const struct snd_pcm_hw_constraint_list constraints_refcap = {
 427        .count = ARRAY_SIZE(ch_mono),
 428        .list  = ch_mono,
 429};
 430
 431static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
 432{
 433        substream->runtime->hw.channels_max = 1;
 434        snd_pcm_hw_constraint_list(substream->runtime, 0,
 435                                        SNDRV_PCM_HW_PARAM_CHANNELS,
 436                                        &constraints_refcap);
 437
 438        return snd_pcm_hw_constraint_list(substream->runtime, 0,
 439                                SNDRV_PCM_HW_PARAM_RATE,
 440                                &constraints_16000);
 441}
 442
 443
 444static struct snd_soc_ops skylaye_refcap_ops = {
 445        .startup = kabylake_refcap_startup,
 446};
 447
 448static struct snd_soc_codec_conf max98927_codec_conf[] = {
 449
 450        {
 451                .dev_name = MAXIM_DEV0_NAME,
 452                .name_prefix = "Right",
 453        },
 454
 455        {
 456                .dev_name = MAXIM_DEV1_NAME,
 457                .name_prefix = "Left",
 458        },
 459};
 460
 461static struct snd_soc_dai_link_component ssp0_codec_components[] = {
 462        { /* Left */
 463                .name = MAXIM_DEV0_NAME,
 464                .dai_name = MAX98927_CODEC_DAI,
 465        },
 466
 467        {  /* For Right */
 468                .name = MAXIM_DEV1_NAME,
 469                .dai_name = MAX98927_CODEC_DAI,
 470        },
 471
 472};
 473
 474/* kabylake digital audio interface glue - connects codec <--> CPU */
 475static struct snd_soc_dai_link kabylake_dais[] = {
 476        /* Front End DAI links */
 477        [KBL_DPCM_AUDIO_PB] = {
 478                .name = "Kbl Audio Port",
 479                .stream_name = "Audio",
 480                .cpu_dai_name = "System Pin",
 481                .platform_name = "0000:00:1f.3",
 482                .dynamic = 1,
 483                .codec_name = "snd-soc-dummy",
 484                .codec_dai_name = "snd-soc-dummy-dai",
 485                .nonatomic = 1,
 486                .init = kabylake_da7219_fe_init,
 487                .trigger = {
 488                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 489                .dpcm_playback = 1,
 490                .ops = &kabylake_da7219_fe_ops,
 491        },
 492        [KBL_DPCM_AUDIO_CP] = {
 493                .name = "Kbl Audio Capture Port",
 494                .stream_name = "Audio Record",
 495                .cpu_dai_name = "System Pin",
 496                .platform_name = "0000:00:1f.3",
 497                .dynamic = 1,
 498                .codec_name = "snd-soc-dummy",
 499                .codec_dai_name = "snd-soc-dummy-dai",
 500                .nonatomic = 1,
 501                .trigger = {
 502                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 503                .dpcm_capture = 1,
 504                .ops = &kabylake_da7219_fe_ops,
 505        },
 506        [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
 507                .name = "Kbl Audio Echo Reference cap",
 508                .stream_name = "Echoreference Capture",
 509                .cpu_dai_name = "Echoref Pin",
 510                .codec_name = "snd-soc-dummy",
 511                .codec_dai_name = "snd-soc-dummy-dai",
 512                .platform_name = "0000:00:1f.3",
 513                .init = NULL,
 514                .capture_only = 1,
 515                .nonatomic = 1,
 516        },
 517        [KBL_DPCM_AUDIO_REF_CP] = {
 518                .name = "Kbl Audio Reference cap",
 519                .stream_name = "Wake on Voice",
 520                .cpu_dai_name = "Reference Pin",
 521                .codec_name = "snd-soc-dummy",
 522                .codec_dai_name = "snd-soc-dummy-dai",
 523                .platform_name = "0000:00:1f.3",
 524                .init = NULL,
 525                .dpcm_capture = 1,
 526                .nonatomic = 1,
 527                .dynamic = 1,
 528                .ops = &skylaye_refcap_ops,
 529        },
 530        [KBL_DPCM_AUDIO_DMIC_CP] = {
 531                .name = "Kbl Audio DMIC cap",
 532                .stream_name = "dmiccap",
 533                .cpu_dai_name = "DMIC Pin",
 534                .codec_name = "snd-soc-dummy",
 535                .codec_dai_name = "snd-soc-dummy-dai",
 536                .platform_name = "0000:00:1f.3",
 537                .init = NULL,
 538                .dpcm_capture = 1,
 539                .nonatomic = 1,
 540                .dynamic = 1,
 541                .ops = &kabylake_dmic_ops,
 542        },
 543        [KBL_DPCM_AUDIO_HDMI1_PB] = {
 544                .name = "Kbl HDMI Port1",
 545                .stream_name = "Hdmi1",
 546                .cpu_dai_name = "HDMI1 Pin",
 547                .codec_name = "snd-soc-dummy",
 548                .codec_dai_name = "snd-soc-dummy-dai",
 549                .platform_name = "0000:00:1f.3",
 550                .dpcm_playback = 1,
 551                .init = NULL,
 552                .trigger = {
 553                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 554                .nonatomic = 1,
 555                .dynamic = 1,
 556        },
 557        [KBL_DPCM_AUDIO_HDMI2_PB] = {
 558                .name = "Kbl HDMI Port2",
 559                .stream_name = "Hdmi2",
 560                .cpu_dai_name = "HDMI2 Pin",
 561                .codec_name = "snd-soc-dummy",
 562                .codec_dai_name = "snd-soc-dummy-dai",
 563                .platform_name = "0000:00:1f.3",
 564                .dpcm_playback = 1,
 565                .init = NULL,
 566                .trigger = {
 567                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 568                .nonatomic = 1,
 569                .dynamic = 1,
 570        },
 571        [KBL_DPCM_AUDIO_HDMI3_PB] = {
 572                .name = "Kbl HDMI Port3",
 573                .stream_name = "Hdmi3",
 574                .cpu_dai_name = "HDMI3 Pin",
 575                .codec_name = "snd-soc-dummy",
 576                .codec_dai_name = "snd-soc-dummy-dai",
 577                .platform_name = "0000:00:1f.3",
 578                .trigger = {
 579                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 580                .dpcm_playback = 1,
 581                .init = NULL,
 582                .nonatomic = 1,
 583                .dynamic = 1,
 584        },
 585        [KBL_DPCM_AUDIO_HS_PB] = {
 586                .name = "Kbl Audio Headset Playback",
 587                .stream_name = "Headset Audio",
 588                .cpu_dai_name = "System Pin2",
 589                .codec_name = "snd-soc-dummy",
 590                .codec_dai_name = "snd-soc-dummy-dai",
 591                .platform_name = "0000:00:1f.3",
 592                .dpcm_playback = 1,
 593                .nonatomic = 1,
 594                .dynamic = 1,
 595                .init = kabylake_da7219_fe_init,
 596                .trigger = {
 597                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 598                .ops = &kabylake_da7219_fe_ops,
 599
 600        },
 601
 602        /* Back End DAI links */
 603        {
 604                /* SSP0 - Codec */
 605                .name = "SSP0-Codec",
 606                .id = 0,
 607                .cpu_dai_name = "SSP0 Pin",
 608                .platform_name = "0000:00:1f.3",
 609                .no_pcm = 1,
 610                .codecs = ssp0_codec_components,
 611                .num_codecs = ARRAY_SIZE(ssp0_codec_components),
 612                .dai_fmt = SND_SOC_DAIFMT_DSP_B |
 613                        SND_SOC_DAIFMT_NB_NF |
 614                        SND_SOC_DAIFMT_CBS_CFS,
 615                .dpcm_playback = 1,
 616                .dpcm_capture = 1,
 617                .ignore_pmdown_time = 1,
 618                .be_hw_params_fixup = kabylake_ssp_fixup,
 619                .ops = &kabylake_ssp0_ops,
 620        },
 621        {
 622                /* SSP1 - Codec */
 623                .name = "SSP1-Codec",
 624                .id = 1,
 625                .cpu_dai_name = "SSP1 Pin",
 626                .platform_name = "0000:00:1f.3",
 627                .no_pcm = 1,
 628                .codec_name = "i2c-DLGS7219:00",
 629                .codec_dai_name = KBL_DIALOG_CODEC_DAI,
 630                .init = kabylake_da7219_codec_init,
 631                .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
 632                        SND_SOC_DAIFMT_CBS_CFS,
 633                .ignore_pmdown_time = 1,
 634                .be_hw_params_fixup = kabylake_ssp_fixup,
 635                .dpcm_playback = 1,
 636                .dpcm_capture = 1,
 637        },
 638        {
 639                .name = "dmic01",
 640                .id = 2,
 641                .cpu_dai_name = "DMIC01 Pin",
 642                .codec_name = "dmic-codec",
 643                .codec_dai_name = "dmic-hifi",
 644                .platform_name = "0000:00:1f.3",
 645                .be_hw_params_fixup = kabylake_dmic_fixup,
 646                .ignore_suspend = 1,
 647                .dpcm_capture = 1,
 648                .no_pcm = 1,
 649        },
 650        {
 651                .name = "iDisp1",
 652                .id = 3,
 653                .cpu_dai_name = "iDisp1 Pin",
 654                .codec_name = "ehdaudio0D2",
 655                .codec_dai_name = "intel-hdmi-hifi1",
 656                .platform_name = "0000:00:1f.3",
 657                .dpcm_playback = 1,
 658                .init = kabylake_hdmi1_init,
 659                .no_pcm = 1,
 660        },
 661        {
 662                .name = "iDisp2",
 663                .id = 4,
 664                .cpu_dai_name = "iDisp2 Pin",
 665                .codec_name = "ehdaudio0D2",
 666                .codec_dai_name = "intel-hdmi-hifi2",
 667                .platform_name = "0000:00:1f.3",
 668                .init = kabylake_hdmi2_init,
 669                .dpcm_playback = 1,
 670                .no_pcm = 1,
 671        },
 672        {
 673                .name = "iDisp3",
 674                .id = 5,
 675                .cpu_dai_name = "iDisp3 Pin",
 676                .codec_name = "ehdaudio0D2",
 677                .codec_dai_name = "intel-hdmi-hifi3",
 678                .platform_name = "0000:00:1f.3",
 679                .init = kabylake_hdmi3_init,
 680                .dpcm_playback = 1,
 681                .no_pcm = 1,
 682        },
 683};
 684
 685/* kabylake digital audio interface glue - connects codec <--> CPU */
 686static struct snd_soc_dai_link kabylake_max98927_dais[] = {
 687        /* Front End DAI links */
 688        [KBL_DPCM_AUDIO_PB] = {
 689                .name = "Kbl Audio Port",
 690                .stream_name = "Audio",
 691                .cpu_dai_name = "System Pin",
 692                .platform_name = "0000:00:1f.3",
 693                .dynamic = 1,
 694                .codec_name = "snd-soc-dummy",
 695                .codec_dai_name = "snd-soc-dummy-dai",
 696                .nonatomic = 1,
 697                .init = kabylake_da7219_fe_init,
 698                .trigger = {
 699                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 700                .dpcm_playback = 1,
 701                .ops = &kabylake_da7219_fe_ops,
 702        },
 703        [KBL_DPCM_AUDIO_CP] = {
 704                .name = "Kbl Audio Capture Port",
 705                .stream_name = "Audio Record",
 706                .cpu_dai_name = "System Pin",
 707                .platform_name = "0000:00:1f.3",
 708                .dynamic = 1,
 709                .codec_name = "snd-soc-dummy",
 710                .codec_dai_name = "snd-soc-dummy-dai",
 711                .nonatomic = 1,
 712                .trigger = {
 713                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 714                .dpcm_capture = 1,
 715                .ops = &kabylake_da7219_fe_ops,
 716        },
 717        [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
 718                .name = "Kbl Audio Echo Reference cap",
 719                .stream_name = "Echoreference Capture",
 720                .cpu_dai_name = "Echoref Pin",
 721                .codec_name = "snd-soc-dummy",
 722                .codec_dai_name = "snd-soc-dummy-dai",
 723                .platform_name = "0000:00:1f.3",
 724                .init = NULL,
 725                .capture_only = 1,
 726                .nonatomic = 1,
 727        },
 728        [KBL_DPCM_AUDIO_REF_CP] = {
 729                .name = "Kbl Audio Reference cap",
 730                .stream_name = "Wake on Voice",
 731                .cpu_dai_name = "Reference Pin",
 732                .codec_name = "snd-soc-dummy",
 733                .codec_dai_name = "snd-soc-dummy-dai",
 734                .platform_name = "0000:00:1f.3",
 735                .init = NULL,
 736                .dpcm_capture = 1,
 737                .nonatomic = 1,
 738                .dynamic = 1,
 739                .ops = &skylaye_refcap_ops,
 740        },
 741        [KBL_DPCM_AUDIO_DMIC_CP] = {
 742                .name = "Kbl Audio DMIC cap",
 743                .stream_name = "dmiccap",
 744                .cpu_dai_name = "DMIC Pin",
 745                .codec_name = "snd-soc-dummy",
 746                .codec_dai_name = "snd-soc-dummy-dai",
 747                .platform_name = "0000:00:1f.3",
 748                .init = NULL,
 749                .dpcm_capture = 1,
 750                .nonatomic = 1,
 751                .dynamic = 1,
 752                .ops = &kabylake_dmic_ops,
 753        },
 754        [KBL_DPCM_AUDIO_HDMI1_PB] = {
 755                .name = "Kbl HDMI Port1",
 756                .stream_name = "Hdmi1",
 757                .cpu_dai_name = "HDMI1 Pin",
 758                .codec_name = "snd-soc-dummy",
 759                .codec_dai_name = "snd-soc-dummy-dai",
 760                .platform_name = "0000:00:1f.3",
 761                .dpcm_playback = 1,
 762                .init = NULL,
 763                .trigger = {
 764                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 765                .nonatomic = 1,
 766                .dynamic = 1,
 767        },
 768        [KBL_DPCM_AUDIO_HDMI2_PB] = {
 769                .name = "Kbl HDMI Port2",
 770                .stream_name = "Hdmi2",
 771                .cpu_dai_name = "HDMI2 Pin",
 772                .codec_name = "snd-soc-dummy",
 773                .codec_dai_name = "snd-soc-dummy-dai",
 774                .platform_name = "0000:00:1f.3",
 775                .dpcm_playback = 1,
 776                .init = NULL,
 777                .trigger = {
 778                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 779                .nonatomic = 1,
 780                .dynamic = 1,
 781        },
 782        [KBL_DPCM_AUDIO_HDMI3_PB] = {
 783                .name = "Kbl HDMI Port3",
 784                .stream_name = "Hdmi3",
 785                .cpu_dai_name = "HDMI3 Pin",
 786                .codec_name = "snd-soc-dummy",
 787                .codec_dai_name = "snd-soc-dummy-dai",
 788                .platform_name = "0000:00:1f.3",
 789                .trigger = {
 790                        SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
 791                .dpcm_playback = 1,
 792                .init = NULL,
 793                .nonatomic = 1,
 794                .dynamic = 1,
 795        },
 796
 797        /* Back End DAI links */
 798        {
 799                /* SSP0 - Codec */
 800                .name = "SSP0-Codec",
 801                .id = 0,
 802                .cpu_dai_name = "SSP0 Pin",
 803                .platform_name = "0000:00:1f.3",
 804                .no_pcm = 1,
 805                .codecs = ssp0_codec_components,
 806                .num_codecs = ARRAY_SIZE(ssp0_codec_components),
 807                .dai_fmt = SND_SOC_DAIFMT_DSP_B |
 808                        SND_SOC_DAIFMT_NB_NF |
 809                        SND_SOC_DAIFMT_CBS_CFS,
 810                .dpcm_playback = 1,
 811                .dpcm_capture = 1,
 812                .ignore_pmdown_time = 1,
 813                .be_hw_params_fixup = kabylake_ssp_fixup,
 814                .ops = &kabylake_ssp0_ops,
 815        },
 816        {
 817                .name = "dmic01",
 818                .id = 1,
 819                .cpu_dai_name = "DMIC01 Pin",
 820                .codec_name = "dmic-codec",
 821                .codec_dai_name = "dmic-hifi",
 822                .platform_name = "0000:00:1f.3",
 823                .be_hw_params_fixup = kabylake_dmic_fixup,
 824                .ignore_suspend = 1,
 825                .dpcm_capture = 1,
 826                .no_pcm = 1,
 827        },
 828        {
 829                .name = "iDisp1",
 830                .id = 2,
 831                .cpu_dai_name = "iDisp1 Pin",
 832                .codec_name = "ehdaudio0D2",
 833                .codec_dai_name = "intel-hdmi-hifi1",
 834                .platform_name = "0000:00:1f.3",
 835                .dpcm_playback = 1,
 836                .init = kabylake_hdmi1_init,
 837                .no_pcm = 1,
 838        },
 839        {
 840                .name = "iDisp2",
 841                .id = 3,
 842                .cpu_dai_name = "iDisp2 Pin",
 843                .codec_name = "ehdaudio0D2",
 844                .codec_dai_name = "intel-hdmi-hifi2",
 845                .platform_name = "0000:00:1f.3",
 846                .init = kabylake_hdmi2_init,
 847                .dpcm_playback = 1,
 848                .no_pcm = 1,
 849        },
 850        {
 851                .name = "iDisp3",
 852                .id = 4,
 853                .cpu_dai_name = "iDisp3 Pin",
 854                .codec_name = "ehdaudio0D2",
 855                .codec_dai_name = "intel-hdmi-hifi3",
 856                .platform_name = "0000:00:1f.3",
 857                .init = kabylake_hdmi3_init,
 858                .dpcm_playback = 1,
 859                .no_pcm = 1,
 860        },
 861};
 862
 863static int kabylake_card_late_probe(struct snd_soc_card *card)
 864{
 865        struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
 866        struct kbl_hdmi_pcm *pcm;
 867        struct snd_soc_component *component = NULL;
 868        int err, i = 0;
 869        char jack_name[NAME_SIZE];
 870
 871        list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
 872                component = pcm->codec_dai->component;
 873                snprintf(jack_name, sizeof(jack_name),
 874                        "HDMI/DP, pcm=%d Jack", pcm->device);
 875                err = snd_soc_card_jack_new(card, jack_name,
 876                                        SND_JACK_AVOUT, &kabylake_hdmi[i],
 877                                        NULL, 0);
 878
 879                if (err)
 880                        return err;
 881
 882                err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
 883                                                &kabylake_hdmi[i]);
 884                if (err < 0)
 885                        return err;
 886
 887                i++;
 888        }
 889
 890        if (!component)
 891                return -EINVAL;
 892
 893        return hdac_hdmi_jack_port_init(component, &card->dapm);
 894
 895        return 0;
 896}
 897
 898/* kabylake audio machine driver for SPT + DA7219 */
 899static struct snd_soc_card kbl_audio_card_da7219_m98927 = {
 900        .name = "kblda7219m98927",
 901        .owner = THIS_MODULE,
 902        .dai_link = kabylake_dais,
 903        .num_links = ARRAY_SIZE(kabylake_dais),
 904        .controls = kabylake_controls,
 905        .num_controls = ARRAY_SIZE(kabylake_controls),
 906        .dapm_widgets = kabylake_widgets,
 907        .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
 908        .dapm_routes = kabylake_map,
 909        .num_dapm_routes = ARRAY_SIZE(kabylake_map),
 910        .codec_conf = max98927_codec_conf,
 911        .num_configs = ARRAY_SIZE(max98927_codec_conf),
 912        .fully_routed = true,
 913        .late_probe = kabylake_card_late_probe,
 914};
 915
 916/* kabylake audio machine driver for Maxim98927 */
 917static struct snd_soc_card kbl_audio_card_max98927 = {
 918        .name = "kblmax98927",
 919        .owner = THIS_MODULE,
 920        .dai_link = kabylake_max98927_dais,
 921        .num_links = ARRAY_SIZE(kabylake_max98927_dais),
 922        .controls = kabylake_controls,
 923        .num_controls = ARRAY_SIZE(kabylake_controls),
 924        .dapm_widgets = kabylake_widgets,
 925        .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
 926        .dapm_routes = kabylake_map,
 927        .num_dapm_routes = ARRAY_SIZE(kabylake_map),
 928        .codec_conf = max98927_codec_conf,
 929        .num_configs = ARRAY_SIZE(max98927_codec_conf),
 930        .fully_routed = true,
 931        .late_probe = kabylake_card_late_probe,
 932};
 933
 934static int kabylake_audio_probe(struct platform_device *pdev)
 935{
 936        struct kbl_codec_private *ctx;
 937
 938        ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
 939        if (!ctx)
 940                return -ENOMEM;
 941
 942        INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
 943
 944        kabylake_audio_card =
 945                (struct snd_soc_card *)pdev->id_entry->driver_data;
 946
 947        kabylake_audio_card->dev = &pdev->dev;
 948        snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
 949
 950        return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
 951}
 952
 953static const struct platform_device_id kbl_board_ids[] = {
 954        {
 955                .name = "kbl_da7219_max98927",
 956                .driver_data =
 957                        (kernel_ulong_t)&kbl_audio_card_da7219_m98927,
 958        },
 959        {
 960                .name = "kbl_max98927",
 961                .driver_data =
 962                        (kernel_ulong_t)&kbl_audio_card_max98927,
 963        },
 964        { }
 965};
 966
 967static struct platform_driver kabylake_audio = {
 968        .probe = kabylake_audio_probe,
 969        .driver = {
 970                .name = "kbl_da7219_max98927",
 971                .pm = &snd_soc_pm_ops,
 972        },
 973        .id_table = kbl_board_ids,
 974};
 975
 976module_platform_driver(kabylake_audio)
 977
 978/* Module information */
 979MODULE_DESCRIPTION("Audio KabyLake Machine driver for MAX98927 & DA7219");
 980MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
 981MODULE_LICENSE("GPL v2");
 982MODULE_ALIAS("platform:kbl_da7219_max98927");
 983MODULE_ALIAS("platform:kbl_max98927");
 984