Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 // Copyright(c) 2019 Intel Corporation.
0003 
0004 /*
0005  * Intel Cometlake I2S Machine driver for RT1011 + RT5682 codec
0006  */
0007 
0008 #include <linux/input.h>
0009 #include <linux/module.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/clk.h>
0012 #include <linux/dmi.h>
0013 #include <linux/slab.h>
0014 #include <linux/acpi.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 <sound/rt5682.h>
0021 #include <sound/soc-acpi.h>
0022 #include "../../codecs/rt1011.h"
0023 #include "../../codecs/rt5682.h"
0024 #include "../../codecs/hdac_hdmi.h"
0025 #include "hda_dsp_common.h"
0026 
0027 /* The platform clock outputs 24Mhz clock to codec as I2S MCLK */
0028 #define CML_PLAT_CLK    24000000
0029 #define CML_RT1011_CODEC_DAI "rt1011-aif"
0030 #define CML_RT5682_CODEC_DAI "rt5682-aif1"
0031 #define NAME_SIZE 32
0032 
0033 #define SOF_RT1011_SPEAKER_WL       BIT(0)
0034 #define SOF_RT1011_SPEAKER_WR       BIT(1)
0035 #define SOF_RT1011_SPEAKER_TL       BIT(2)
0036 #define SOF_RT1011_SPEAKER_TR       BIT(3)
0037 
0038 /* Default: Woofer speakers  */
0039 static unsigned long sof_rt1011_quirk = SOF_RT1011_SPEAKER_WL |
0040                     SOF_RT1011_SPEAKER_WR;
0041 
0042 static int sof_rt1011_quirk_cb(const struct dmi_system_id *id)
0043 {
0044     sof_rt1011_quirk = (unsigned long)id->driver_data;
0045     return 1;
0046 }
0047 
0048 static const struct dmi_system_id sof_rt1011_quirk_table[] = {
0049     {
0050         .callback = sof_rt1011_quirk_cb,
0051         .matches = {
0052             DMI_MATCH(DMI_SYS_VENDOR, "Google"),
0053             DMI_MATCH(DMI_PRODUCT_NAME, "Helios"),
0054     },
0055         .driver_data = (void *)(SOF_RT1011_SPEAKER_WL | SOF_RT1011_SPEAKER_WR |
0056                     SOF_RT1011_SPEAKER_TL | SOF_RT1011_SPEAKER_TR),
0057     },
0058     {
0059     }
0060 };
0061 
0062 static struct snd_soc_jack hdmi_jack[3];
0063 
0064 struct hdmi_pcm {
0065     struct list_head head;
0066     struct snd_soc_dai *codec_dai;
0067     int device;
0068 };
0069 
0070 struct card_private {
0071     char codec_name[SND_ACPI_I2C_ID_LEN];
0072     struct snd_soc_jack headset;
0073     struct list_head hdmi_pcm_list;
0074     bool common_hdmi_codec_drv;
0075 };
0076 
0077 static const struct snd_kcontrol_new cml_controls[] = {
0078     SOC_DAPM_PIN_SWITCH("Headphone Jack"),
0079     SOC_DAPM_PIN_SWITCH("Headset Mic"),
0080     SOC_DAPM_PIN_SWITCH("WL Ext Spk"),
0081     SOC_DAPM_PIN_SWITCH("WR Ext Spk"),
0082 };
0083 
0084 static const struct snd_kcontrol_new cml_rt1011_tt_controls[] = {
0085     SOC_DAPM_PIN_SWITCH("TL Ext Spk"),
0086     SOC_DAPM_PIN_SWITCH("TR Ext Spk"),
0087 };
0088 
0089 static const struct snd_soc_dapm_widget cml_rt1011_rt5682_widgets[] = {
0090     SND_SOC_DAPM_SPK("WL Ext Spk", NULL),
0091     SND_SOC_DAPM_SPK("WR Ext Spk", NULL),
0092     SND_SOC_DAPM_HP("Headphone Jack", NULL),
0093     SND_SOC_DAPM_MIC("Headset Mic", NULL),
0094     SND_SOC_DAPM_MIC("SoC DMIC", NULL),
0095 };
0096 
0097 static const struct snd_soc_dapm_widget cml_rt1011_tt_widgets[] = {
0098     SND_SOC_DAPM_SPK("TL Ext Spk", NULL),
0099     SND_SOC_DAPM_SPK("TR Ext Spk", NULL),
0100 };
0101 
0102 static const struct snd_soc_dapm_route cml_rt1011_rt5682_map[] = {
0103     /*WL/WR speaker*/
0104     {"WL Ext Spk", NULL, "WL SPO"},
0105     {"WR Ext Spk", NULL, "WR SPO"},
0106 
0107     /* HP jack connectors - unknown if we have jack detection */
0108     { "Headphone Jack", NULL, "HPOL" },
0109     { "Headphone Jack", NULL, "HPOR" },
0110 
0111     /* other jacks */
0112     { "IN1P", NULL, "Headset Mic" },
0113 
0114     /* DMIC */
0115     {"DMic", NULL, "SoC DMIC"},
0116 };
0117 
0118 static const struct snd_soc_dapm_route cml_rt1011_tt_map[] = {
0119     /*TL/TR speaker*/
0120     {"TL Ext Spk", NULL, "TL SPO" },
0121     {"TR Ext Spk", NULL, "TR SPO" },
0122 };
0123 
0124 static struct snd_soc_jack_pin jack_pins[] = {
0125     {
0126         .pin    = "Headphone Jack",
0127         .mask   = SND_JACK_HEADPHONE,
0128     },
0129     {
0130         .pin    = "Headset Mic",
0131         .mask   = SND_JACK_MICROPHONE,
0132     },
0133 };
0134 
0135 static int cml_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
0136 {
0137     struct card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
0138     struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
0139     struct snd_soc_jack *jack;
0140     int ret;
0141 
0142     /* need to enable ASRC function for 24MHz mclk rate */
0143     rt5682_sel_asrc_clk_src(component, RT5682_DA_STEREO1_FILTER |
0144                     RT5682_AD_STEREO1_FILTER,
0145                     RT5682_CLK_SEL_I2S1_ASRC);
0146 
0147     /*
0148      * Headset buttons map to the google Reference headset.
0149      * These can be configured by userspace.
0150      */
0151     ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
0152                      SND_JACK_HEADSET | SND_JACK_BTN_0 |
0153                      SND_JACK_BTN_1 | SND_JACK_BTN_2 |
0154                      SND_JACK_BTN_3,
0155                      &ctx->headset,
0156                      jack_pins,
0157                      ARRAY_SIZE(jack_pins));
0158     if (ret) {
0159         dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
0160         return ret;
0161     }
0162 
0163     jack = &ctx->headset;
0164 
0165     snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
0166     snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
0167     snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
0168     snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
0169     ret = snd_soc_component_set_jack(component, jack, NULL);
0170     if (ret)
0171         dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
0172 
0173     return ret;
0174 };
0175 
0176 static void cml_rt5682_codec_exit(struct snd_soc_pcm_runtime *rtd)
0177 {
0178     struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
0179 
0180     snd_soc_component_set_jack(component, NULL, NULL);
0181 }
0182 
0183 static int cml_rt1011_spk_init(struct snd_soc_pcm_runtime *rtd)
0184 {
0185     int ret = 0;
0186     struct snd_soc_card *card = rtd->card;
0187 
0188     if (sof_rt1011_quirk & (SOF_RT1011_SPEAKER_TL |
0189                 SOF_RT1011_SPEAKER_TR)) {
0190 
0191         ret = snd_soc_add_card_controls(card, cml_rt1011_tt_controls,
0192                     ARRAY_SIZE(cml_rt1011_tt_controls));
0193         if (ret)
0194             return ret;
0195 
0196         ret = snd_soc_dapm_new_controls(&card->dapm,
0197                     cml_rt1011_tt_widgets,
0198                     ARRAY_SIZE(cml_rt1011_tt_widgets));
0199         if (ret)
0200             return ret;
0201 
0202         ret = snd_soc_dapm_add_routes(&card->dapm, cml_rt1011_tt_map,
0203                     ARRAY_SIZE(cml_rt1011_tt_map));
0204 
0205         if (ret)
0206             return ret;
0207     }
0208 
0209     return ret;
0210 }
0211 
0212 static int cml_rt5682_hw_params(struct snd_pcm_substream *substream,
0213                 struct snd_pcm_hw_params *params)
0214 {
0215     struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0216     struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0217     int clk_id, clk_freq, pll_out, ret;
0218 
0219     clk_id = RT5682_PLL1_S_MCLK;
0220     clk_freq = CML_PLAT_CLK;
0221 
0222     pll_out = params_rate(params) * 512;
0223 
0224     ret = snd_soc_dai_set_pll(codec_dai, 0, clk_id, clk_freq, pll_out);
0225     if (ret < 0)
0226         dev_warn(rtd->dev, "snd_soc_dai_set_pll err = %d\n", ret);
0227 
0228     /* Configure sysclk for codec */
0229     ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1,
0230                      pll_out, SND_SOC_CLOCK_IN);
0231     if (ret < 0)
0232         dev_warn(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
0233 
0234     /*
0235      * slot_width should be equal or large than data length, set them
0236      * be the same
0237      */
0238     ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2,
0239                        params_width(params));
0240     if (ret < 0)
0241         dev_warn(rtd->dev, "set TDM slot err:%d\n", ret);
0242     return ret;
0243 }
0244 
0245 static int cml_rt1011_hw_params(struct snd_pcm_substream *substream,
0246                 struct snd_pcm_hw_params *params)
0247 {
0248     struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0249     struct snd_soc_dai *codec_dai;
0250     struct snd_soc_card *card = rtd->card;
0251     int srate, i, ret = 0;
0252 
0253     srate = params_rate(params);
0254 
0255     for_each_rtd_codec_dais(rtd, i, codec_dai) {
0256 
0257         /* 100 Fs to drive 24 bit data */
0258         ret = snd_soc_dai_set_pll(codec_dai, 0, RT1011_PLL1_S_BCLK,
0259                       100 * srate, 256 * srate);
0260         if (ret < 0) {
0261             dev_err(card->dev, "codec_dai clock not set\n");
0262             return ret;
0263         }
0264 
0265         ret = snd_soc_dai_set_sysclk(codec_dai,
0266                          RT1011_FS_SYS_PRE_S_PLL1,
0267                          256 * srate, SND_SOC_CLOCK_IN);
0268         if (ret < 0) {
0269             dev_err(card->dev, "codec_dai clock not set\n");
0270             return ret;
0271         }
0272 
0273         /*
0274          * Codec TDM is configured as 24 bit capture/ playback.
0275          * 2 CH PB is done over 4 codecs - 2 Woofers and 2 Tweeters.
0276          * The Left woofer and tweeter plays the Left playback data
0277          * and  similar by the Right.
0278          * Hence 2 codecs (1 T and 1 W pair) share same Rx slot.
0279          * The feedback is captured for each codec individually.
0280          * Hence all 4 codecs use 1 Tx slot each for feedback.
0281          */
0282         if (sof_rt1011_quirk & (SOF_RT1011_SPEAKER_WL |
0283                     SOF_RT1011_SPEAKER_WR)) {
0284             if (!strcmp(codec_dai->component->name, "i2c-10EC1011:00")) {
0285                 ret = snd_soc_dai_set_tdm_slot(codec_dai,
0286                                    0x4, 0x1, 4, 24);
0287                 if (ret < 0)
0288                     break;
0289             }
0290 
0291             if (!strcmp(codec_dai->component->name, "i2c-10EC1011:01")) {
0292                 ret = snd_soc_dai_set_tdm_slot(codec_dai,
0293                                    0x8, 0x2, 4, 24);
0294                 if (ret < 0)
0295                     break;
0296             }
0297         }
0298 
0299         if (sof_rt1011_quirk & (SOF_RT1011_SPEAKER_TL |
0300                     SOF_RT1011_SPEAKER_TR)) {
0301             if (!strcmp(codec_dai->component->name, "i2c-10EC1011:02")) {
0302                 ret = snd_soc_dai_set_tdm_slot(codec_dai,
0303                                    0x1, 0x1, 4, 24);
0304                 if (ret < 0)
0305                     break;
0306             }
0307 
0308             if (!strcmp(codec_dai->component->name, "i2c-10EC1011:03")) {
0309                 ret = snd_soc_dai_set_tdm_slot(codec_dai,
0310                                    0x2, 0x2, 4, 24);
0311                 if (ret < 0)
0312                     break;
0313             }
0314         }
0315     }
0316     if (ret < 0)
0317         dev_err(rtd->dev,
0318             "set codec TDM slot for %s failed with error %d\n",
0319             codec_dai->component->name, ret);
0320     return ret;
0321 }
0322 
0323 static struct snd_soc_ops cml_rt5682_ops = {
0324     .hw_params = cml_rt5682_hw_params,
0325 };
0326 
0327 static const struct snd_soc_ops cml_rt1011_ops = {
0328     .hw_params = cml_rt1011_hw_params,
0329 };
0330 
0331 static int sof_card_late_probe(struct snd_soc_card *card)
0332 {
0333     struct card_private *ctx = snd_soc_card_get_drvdata(card);
0334     struct snd_soc_component *component = NULL;
0335     char jack_name[NAME_SIZE];
0336     struct hdmi_pcm *pcm;
0337     int ret, i = 0;
0338 
0339     if (list_empty(&ctx->hdmi_pcm_list))
0340         return -EINVAL;
0341 
0342     if (ctx->common_hdmi_codec_drv) {
0343         pcm = list_first_entry(&ctx->hdmi_pcm_list, struct hdmi_pcm,
0344                        head);
0345         component = pcm->codec_dai->component;
0346         return hda_dsp_hdmi_build_controls(card, component);
0347     }
0348 
0349     list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
0350         component = pcm->codec_dai->component;
0351         snprintf(jack_name, sizeof(jack_name),
0352              "HDMI/DP, pcm=%d Jack", pcm->device);
0353         ret = snd_soc_card_jack_new(card, jack_name,
0354                         SND_JACK_AVOUT, &hdmi_jack[i]);
0355         if (ret)
0356             return ret;
0357 
0358         ret = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
0359                       &hdmi_jack[i]);
0360         if (ret < 0)
0361             return ret;
0362 
0363         i++;
0364     }
0365 
0366     return hdac_hdmi_jack_port_init(component, &card->dapm);
0367 }
0368 
0369 static int hdmi_init(struct snd_soc_pcm_runtime *rtd)
0370 {
0371     struct card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
0372     struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
0373     struct hdmi_pcm *pcm;
0374 
0375     pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
0376     if (!pcm)
0377         return -ENOMEM;
0378 
0379     pcm->device = dai->id;
0380     pcm->codec_dai = dai;
0381 
0382     list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
0383 
0384     return 0;
0385 }
0386 
0387 /* Cometlake digital audio interface glue - connects codec <--> CPU */
0388 
0389 SND_SOC_DAILINK_DEF(ssp0_pin,
0390     DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
0391 SND_SOC_DAILINK_DEF(ssp0_codec,
0392     DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00",
0393                 CML_RT5682_CODEC_DAI)));
0394 
0395 SND_SOC_DAILINK_DEF(ssp1_pin,
0396     DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
0397 SND_SOC_DAILINK_DEF(ssp1_codec_2spk,
0398     DAILINK_COMP_ARRAY(
0399     /* WL */ COMP_CODEC("i2c-10EC1011:00", CML_RT1011_CODEC_DAI),
0400     /* WR */ COMP_CODEC("i2c-10EC1011:01", CML_RT1011_CODEC_DAI)));
0401 SND_SOC_DAILINK_DEF(ssp1_codec_4spk,
0402     DAILINK_COMP_ARRAY(
0403     /* WL */ COMP_CODEC("i2c-10EC1011:00", CML_RT1011_CODEC_DAI),
0404     /* WR */ COMP_CODEC("i2c-10EC1011:01", CML_RT1011_CODEC_DAI),
0405     /* TL */ COMP_CODEC("i2c-10EC1011:02", CML_RT1011_CODEC_DAI),
0406     /* TR */ COMP_CODEC("i2c-10EC1011:03", CML_RT1011_CODEC_DAI)));
0407 
0408 
0409 SND_SOC_DAILINK_DEF(dmic_pin,
0410     DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
0411 
0412 SND_SOC_DAILINK_DEF(dmic16k_pin,
0413     DAILINK_COMP_ARRAY(COMP_CPU("DMIC16k Pin")));
0414 
0415 SND_SOC_DAILINK_DEF(dmic_codec,
0416     DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
0417 
0418 SND_SOC_DAILINK_DEF(idisp1_pin,
0419     DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
0420 SND_SOC_DAILINK_DEF(idisp1_codec,
0421     DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
0422 
0423 SND_SOC_DAILINK_DEF(idisp2_pin,
0424     DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
0425 SND_SOC_DAILINK_DEF(idisp2_codec,
0426     DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
0427 
0428 SND_SOC_DAILINK_DEF(idisp3_pin,
0429     DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
0430 SND_SOC_DAILINK_DEF(idisp3_codec,
0431     DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
0432 
0433 SND_SOC_DAILINK_DEF(platform,
0434     DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
0435 
0436 static struct snd_soc_dai_link cml_rt1011_rt5682_dailink[] = {
0437     /* Back End DAI links */
0438     {
0439         /* SSP0 - Codec */
0440         .name = "SSP0-Codec",
0441         .id = 0,
0442         .init = cml_rt5682_codec_init,
0443         .exit = cml_rt5682_codec_exit,
0444         .ignore_pmdown_time = 1,
0445         .ops = &cml_rt5682_ops,
0446         .dpcm_playback = 1,
0447         .dpcm_capture = 1,
0448         .no_pcm = 1,
0449         SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
0450     },
0451     {
0452         .name = "dmic01",
0453         .id = 1,
0454         .ignore_suspend = 1,
0455         .dpcm_capture = 1,
0456         .no_pcm = 1,
0457         SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
0458     },
0459     {
0460         .name = "dmic16k",
0461         .id = 2,
0462         .ignore_suspend = 1,
0463         .dpcm_capture = 1,
0464         .no_pcm = 1,
0465         SND_SOC_DAILINK_REG(dmic16k_pin, dmic_codec, platform),
0466     },
0467     {
0468         .name = "iDisp1",
0469         .id = 3,
0470         .init = hdmi_init,
0471         .dpcm_playback = 1,
0472         .no_pcm = 1,
0473         SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
0474     },
0475     {
0476         .name = "iDisp2",
0477         .id = 4,
0478         .init = hdmi_init,
0479         .dpcm_playback = 1,
0480         .no_pcm = 1,
0481         SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
0482     },
0483     {
0484         .name = "iDisp3",
0485         .id = 5,
0486         .init = hdmi_init,
0487         .dpcm_playback = 1,
0488         .no_pcm = 1,
0489         SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
0490     },
0491     {
0492         /*
0493          * SSP1 - Codec : added to end of list ensuring
0494          * reuse of common topologies for other end points
0495          * and changing only SSP1's codec
0496          */
0497         .name = "SSP1-Codec",
0498         .id = 6,
0499         .dpcm_playback = 1,
0500         .dpcm_capture = 1, /* Capture stream provides Feedback */
0501         .no_pcm = 1,
0502         .init = cml_rt1011_spk_init,
0503         .ops = &cml_rt1011_ops,
0504         SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec_2spk, platform),
0505     },
0506 };
0507 
0508 static struct snd_soc_codec_conf rt1011_conf[] = {
0509     {
0510         .dlc = COMP_CODEC_CONF("i2c-10EC1011:00"),
0511         .name_prefix = "WL",
0512     },
0513     {
0514         .dlc = COMP_CODEC_CONF("i2c-10EC1011:01"),
0515         .name_prefix = "WR",
0516     },
0517     /* single configuration structure for 2 and 4 channels */
0518     {
0519         .dlc = COMP_CODEC_CONF("i2c-10EC1011:02"),
0520         .name_prefix = "TL",
0521     },
0522     {
0523         .dlc = COMP_CODEC_CONF("i2c-10EC1011:03"),
0524         .name_prefix = "TR",
0525     },
0526 };
0527 
0528 /* Cometlake audio machine driver for RT1011 and RT5682 */
0529 static struct snd_soc_card snd_soc_card_cml = {
0530     .name = "cml_rt1011_rt5682",
0531     .owner = THIS_MODULE,
0532     .dai_link = cml_rt1011_rt5682_dailink,
0533     .num_links = ARRAY_SIZE(cml_rt1011_rt5682_dailink),
0534     .codec_conf = rt1011_conf,
0535     .num_configs = ARRAY_SIZE(rt1011_conf),
0536     .dapm_widgets = cml_rt1011_rt5682_widgets,
0537     .num_dapm_widgets = ARRAY_SIZE(cml_rt1011_rt5682_widgets),
0538     .dapm_routes = cml_rt1011_rt5682_map,
0539     .num_dapm_routes = ARRAY_SIZE(cml_rt1011_rt5682_map),
0540     .controls = cml_controls,
0541     .num_controls = ARRAY_SIZE(cml_controls),
0542     .fully_routed = true,
0543     .late_probe = sof_card_late_probe,
0544 };
0545 
0546 static int snd_cml_rt1011_probe(struct platform_device *pdev)
0547 {
0548     struct snd_soc_dai_link *dai_link;
0549     struct card_private *ctx;
0550     struct snd_soc_acpi_mach *mach;
0551     const char *platform_name;
0552     int ret, i;
0553 
0554     ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
0555     if (!ctx)
0556         return -ENOMEM;
0557 
0558     INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
0559     mach = pdev->dev.platform_data;
0560     snd_soc_card_cml.dev = &pdev->dev;
0561     platform_name = mach->mach_params.platform;
0562 
0563     dmi_check_system(sof_rt1011_quirk_table);
0564 
0565     dev_dbg(&pdev->dev, "sof_rt1011_quirk = %lx\n", sof_rt1011_quirk);
0566 
0567     /* when 4 speaker is available, update codec config */
0568     if (sof_rt1011_quirk & (SOF_RT1011_SPEAKER_TL |
0569                 SOF_RT1011_SPEAKER_TR)) {
0570         for_each_card_prelinks(&snd_soc_card_cml, i, dai_link) {
0571             if (!strcmp(dai_link->codecs[0].dai_name,
0572                     CML_RT1011_CODEC_DAI)) {
0573                 dai_link->codecs = ssp1_codec_4spk;
0574                 dai_link->num_codecs = ARRAY_SIZE(ssp1_codec_4spk);
0575             }
0576         }
0577     }
0578 
0579     /* set platform name for each dailink */
0580     ret = snd_soc_fixup_dai_links_platform_name(&snd_soc_card_cml,
0581                             platform_name);
0582     if (ret)
0583         return ret;
0584 
0585     ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
0586 
0587     snd_soc_card_set_drvdata(&snd_soc_card_cml, ctx);
0588 
0589     return devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_cml);
0590 }
0591 
0592 static struct platform_driver snd_cml_rt1011_rt5682_driver = {
0593     .probe = snd_cml_rt1011_probe,
0594     .driver = {
0595         .name = "cml_rt1011_rt5682",
0596         .pm = &snd_soc_pm_ops,
0597     },
0598 };
0599 module_platform_driver(snd_cml_rt1011_rt5682_driver);
0600 
0601 /* Module information */
0602 MODULE_DESCRIPTION("Cometlake Audio Machine driver - RT1011 and RT5682 in I2S mode");
0603 MODULE_AUTHOR("Naveen Manohar <naveen.m@intel.com>");
0604 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
0605 MODULE_AUTHOR("Shuming Fan <shumingf@realtek.com>");
0606 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
0607 MODULE_LICENSE("GPL v2");
0608 MODULE_ALIAS("platform:cml_rt1011_rt5682");
0609 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);