Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Intel Skylake I2S Machine Driver
0004  *
0005  * Copyright (C) 2014-2015, Intel Corporation. All rights reserved.
0006  *
0007  * Modified from:
0008  *   Intel Broadwell Wildcatpoint SST Audio
0009  *
0010  *   Copyright (C) 2013, Intel Corporation. All rights reserved.
0011  */
0012 
0013 #include <linux/module.h>
0014 #include <linux/platform_device.h>
0015 #include <sound/core.h>
0016 #include <sound/pcm.h>
0017 #include <sound/soc.h>
0018 #include <sound/jack.h>
0019 #include <sound/pcm_params.h>
0020 #include "../../codecs/rt286.h"
0021 #include "../../codecs/hdac_hdmi.h"
0022 
0023 static struct snd_soc_jack skylake_headset;
0024 static struct snd_soc_jack skylake_hdmi[3];
0025 
0026 struct skl_hdmi_pcm {
0027     struct list_head head;
0028     struct snd_soc_dai *codec_dai;
0029     int device;
0030 };
0031 
0032 struct skl_rt286_private {
0033     struct list_head hdmi_pcm_list;
0034 };
0035 
0036 enum {
0037     SKL_DPCM_AUDIO_PB = 0,
0038     SKL_DPCM_AUDIO_DB_PB,
0039     SKL_DPCM_AUDIO_CP,
0040     SKL_DPCM_AUDIO_REF_CP,
0041     SKL_DPCM_AUDIO_DMIC_CP,
0042     SKL_DPCM_AUDIO_HDMI1_PB,
0043     SKL_DPCM_AUDIO_HDMI2_PB,
0044     SKL_DPCM_AUDIO_HDMI3_PB,
0045 };
0046 
0047 /* Headset jack detection DAPM pins */
0048 static struct snd_soc_jack_pin skylake_headset_pins[] = {
0049     {
0050         .pin = "Mic Jack",
0051         .mask = SND_JACK_MICROPHONE,
0052     },
0053     {
0054         .pin = "Headphone Jack",
0055         .mask = SND_JACK_HEADPHONE,
0056     },
0057 };
0058 
0059 static const struct snd_kcontrol_new skylake_controls[] = {
0060     SOC_DAPM_PIN_SWITCH("Speaker"),
0061     SOC_DAPM_PIN_SWITCH("Headphone Jack"),
0062     SOC_DAPM_PIN_SWITCH("Mic Jack"),
0063 };
0064 
0065 static const struct snd_soc_dapm_widget skylake_widgets[] = {
0066     SND_SOC_DAPM_HP("Headphone Jack", NULL),
0067     SND_SOC_DAPM_SPK("Speaker", NULL),
0068     SND_SOC_DAPM_MIC("Mic Jack", NULL),
0069     SND_SOC_DAPM_MIC("DMIC2", NULL),
0070     SND_SOC_DAPM_MIC("SoC DMIC", NULL),
0071     SND_SOC_DAPM_SPK("HDMI1", NULL),
0072     SND_SOC_DAPM_SPK("HDMI2", NULL),
0073     SND_SOC_DAPM_SPK("HDMI3", NULL),
0074 };
0075 
0076 static const struct snd_soc_dapm_route skylake_rt286_map[] = {
0077     /* speaker */
0078     {"Speaker", NULL, "SPOR"},
0079     {"Speaker", NULL, "SPOL"},
0080 
0081     /* HP jack connectors - unknown if we have jack deteck */
0082     {"Headphone Jack", NULL, "HPO Pin"},
0083 
0084     /* other jacks */
0085     {"MIC1", NULL, "Mic Jack"},
0086 
0087     /* digital mics */
0088     {"DMIC1 Pin", NULL, "DMIC2"},
0089     {"DMic", NULL, "SoC DMIC"},
0090 
0091     /* CODEC BE connections */
0092     { "AIF1 Playback", NULL, "ssp0 Tx"},
0093     { "ssp0 Tx", NULL, "codec0_out"},
0094     { "ssp0 Tx", NULL, "codec1_out"},
0095 
0096     { "codec0_in", NULL, "ssp0 Rx" },
0097     { "codec1_in", NULL, "ssp0 Rx" },
0098     { "ssp0 Rx", NULL, "AIF1 Capture" },
0099 
0100     { "dmic01_hifi", NULL, "DMIC01 Rx" },
0101     { "DMIC01 Rx", NULL, "DMIC AIF" },
0102 
0103     { "hifi3", NULL, "iDisp3 Tx"},
0104     { "iDisp3 Tx", NULL, "iDisp3_out"},
0105     { "hifi2", NULL, "iDisp2 Tx"},
0106     { "iDisp2 Tx", NULL, "iDisp2_out"},
0107     { "hifi1", NULL, "iDisp1 Tx"},
0108     { "iDisp1 Tx", NULL, "iDisp1_out"},
0109 
0110 };
0111 
0112 static int skylake_rt286_fe_init(struct snd_soc_pcm_runtime *rtd)
0113 {
0114     struct snd_soc_dapm_context *dapm;
0115     struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component;
0116 
0117     dapm = snd_soc_component_get_dapm(component);
0118     snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
0119 
0120     return 0;
0121 }
0122 
0123 static int skylake_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
0124 {
0125     struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
0126     int ret;
0127 
0128     ret = snd_soc_card_jack_new_pins(rtd->card, "Headset",
0129         SND_JACK_HEADSET | SND_JACK_BTN_0,
0130         &skylake_headset,
0131         skylake_headset_pins, ARRAY_SIZE(skylake_headset_pins));
0132 
0133     if (ret)
0134         return ret;
0135 
0136     snd_soc_component_set_jack(component, &skylake_headset, NULL);
0137 
0138     snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
0139 
0140     return 0;
0141 }
0142 
0143 static int skylake_hdmi_init(struct snd_soc_pcm_runtime *rtd)
0144 {
0145     struct skl_rt286_private *ctx = snd_soc_card_get_drvdata(rtd->card);
0146     struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
0147     struct skl_hdmi_pcm *pcm;
0148 
0149     pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
0150     if (!pcm)
0151         return -ENOMEM;
0152 
0153     pcm->device = SKL_DPCM_AUDIO_HDMI1_PB + dai->id;
0154     pcm->codec_dai = dai;
0155 
0156     list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
0157 
0158     return 0;
0159 }
0160 
0161 static const unsigned int rates[] = {
0162     48000,
0163 };
0164 
0165 static const struct snd_pcm_hw_constraint_list constraints_rates = {
0166     .count = ARRAY_SIZE(rates),
0167     .list  = rates,
0168     .mask = 0,
0169 };
0170 
0171 static const unsigned int channels[] = {
0172     2,
0173 };
0174 
0175 static const struct snd_pcm_hw_constraint_list constraints_channels = {
0176     .count = ARRAY_SIZE(channels),
0177     .list = channels,
0178     .mask = 0,
0179 };
0180 
0181 static int skl_fe_startup(struct snd_pcm_substream *substream)
0182 {
0183     struct snd_pcm_runtime *runtime = substream->runtime;
0184 
0185     /*
0186      * on this platform for PCM device we support,
0187      *  48Khz
0188      *  stereo
0189      *  16 bit audio
0190      */
0191 
0192     runtime->hw.channels_max = 2;
0193     snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
0194                        &constraints_channels);
0195 
0196     runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
0197     snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
0198 
0199     snd_pcm_hw_constraint_list(runtime, 0,
0200                 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
0201 
0202     return 0;
0203 }
0204 
0205 static const struct snd_soc_ops skylake_rt286_fe_ops = {
0206     .startup = skl_fe_startup,
0207 };
0208 
0209 static int skylake_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
0210             struct snd_pcm_hw_params *params)
0211 {
0212     struct snd_interval *rate = hw_param_interval(params,
0213             SNDRV_PCM_HW_PARAM_RATE);
0214     struct snd_interval *chan = hw_param_interval(params,
0215                         SNDRV_PCM_HW_PARAM_CHANNELS);
0216     struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
0217 
0218     /* The output is 48KHz, stereo, 16bits */
0219     rate->min = rate->max = 48000;
0220     chan->min = chan->max = 2;
0221 
0222     /* set SSP0 to 24 bit */
0223     snd_mask_none(fmt);
0224     snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
0225     return 0;
0226 }
0227 
0228 static int skylake_rt286_hw_params(struct snd_pcm_substream *substream,
0229     struct snd_pcm_hw_params *params)
0230 {
0231     struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0232     struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0233     int ret;
0234 
0235     ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
0236         SND_SOC_CLOCK_IN);
0237     if (ret < 0)
0238         dev_err(rtd->dev, "set codec sysclk failed: %d\n", ret);
0239 
0240     return ret;
0241 }
0242 
0243 static const struct snd_soc_ops skylake_rt286_ops = {
0244     .hw_params = skylake_rt286_hw_params,
0245 };
0246 
0247 static int skylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
0248                 struct snd_pcm_hw_params *params)
0249 {
0250     struct snd_interval *chan = hw_param_interval(params,
0251                         SNDRV_PCM_HW_PARAM_CHANNELS);
0252     if (params_channels(params) == 2)
0253         chan->min = chan->max = 2;
0254     else
0255         chan->min = chan->max = 4;
0256 
0257     return 0;
0258 }
0259 
0260 static const unsigned int channels_dmic[] = {
0261     2, 4,
0262 };
0263 
0264 static const struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
0265     .count = ARRAY_SIZE(channels_dmic),
0266     .list = channels_dmic,
0267     .mask = 0,
0268 };
0269 
0270 static int skylake_dmic_startup(struct snd_pcm_substream *substream)
0271 {
0272     struct snd_pcm_runtime *runtime = substream->runtime;
0273 
0274     runtime->hw.channels_max = 4;
0275     snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
0276                        &constraints_dmic_channels);
0277 
0278     return snd_pcm_hw_constraint_list(substream->runtime, 0,
0279             SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
0280 }
0281 
0282 static const struct snd_soc_ops skylake_dmic_ops = {
0283     .startup = skylake_dmic_startup,
0284 };
0285 
0286 SND_SOC_DAILINK_DEF(dummy,
0287     DAILINK_COMP_ARRAY(COMP_DUMMY()));
0288 
0289 SND_SOC_DAILINK_DEF(system,
0290     DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
0291 
0292 SND_SOC_DAILINK_DEF(deepbuffer,
0293     DAILINK_COMP_ARRAY(COMP_CPU("Deepbuffer Pin")));
0294 
0295 SND_SOC_DAILINK_DEF(reference,
0296     DAILINK_COMP_ARRAY(COMP_CPU("Reference Pin")));
0297 
0298 SND_SOC_DAILINK_DEF(dmic,
0299     DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
0300 
0301 SND_SOC_DAILINK_DEF(hdmi1,
0302     DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin")));
0303 
0304 SND_SOC_DAILINK_DEF(hdmi2,
0305     DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin")));
0306 
0307 SND_SOC_DAILINK_DEF(hdmi3,
0308     DAILINK_COMP_ARRAY(COMP_CPU("HDMI3 Pin")));
0309 
0310 SND_SOC_DAILINK_DEF(ssp0_pin,
0311     DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
0312 SND_SOC_DAILINK_DEF(ssp0_codec,
0313     DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT343A:00", "rt286-aif1")));
0314 
0315 SND_SOC_DAILINK_DEF(dmic01_pin,
0316     DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
0317 SND_SOC_DAILINK_DEF(dmic_codec,
0318     DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
0319 
0320 SND_SOC_DAILINK_DEF(idisp1_pin,
0321     DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
0322 SND_SOC_DAILINK_DEF(idisp1_codec,
0323     DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
0324 
0325 SND_SOC_DAILINK_DEF(idisp2_pin,
0326     DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
0327 SND_SOC_DAILINK_DEF(idisp2_codec,
0328     DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
0329 
0330 SND_SOC_DAILINK_DEF(idisp3_pin,
0331     DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
0332 SND_SOC_DAILINK_DEF(idisp3_codec,
0333     DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
0334 
0335 SND_SOC_DAILINK_DEF(platform,
0336     DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
0337 
0338 /* skylake digital audio interface glue - connects codec <--> CPU */
0339 static struct snd_soc_dai_link skylake_rt286_dais[] = {
0340     /* Front End DAI links */
0341     [SKL_DPCM_AUDIO_PB] = {
0342         .name = "Skl Audio Port",
0343         .stream_name = "Audio",
0344         .nonatomic = 1,
0345         .dynamic = 1,
0346         .init = skylake_rt286_fe_init,
0347         .trigger = {
0348             SND_SOC_DPCM_TRIGGER_POST,
0349             SND_SOC_DPCM_TRIGGER_POST
0350         },
0351         .dpcm_playback = 1,
0352         .ops = &skylake_rt286_fe_ops,
0353         SND_SOC_DAILINK_REG(system, dummy, platform),
0354     },
0355     [SKL_DPCM_AUDIO_DB_PB] = {
0356         .name = "Skl Deepbuffer Port",
0357         .stream_name = "Deep Buffer Audio",
0358         .nonatomic = 1,
0359         .dynamic = 1,
0360         .trigger = {
0361             SND_SOC_DPCM_TRIGGER_POST,
0362             SND_SOC_DPCM_TRIGGER_POST
0363         },
0364         .dpcm_playback = 1,
0365         .ops = &skylake_rt286_fe_ops,
0366         SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
0367     },
0368     [SKL_DPCM_AUDIO_CP] = {
0369         .name = "Skl Audio Capture Port",
0370         .stream_name = "Audio Record",
0371         .nonatomic = 1,
0372         .dynamic = 1,
0373         .trigger = {
0374             SND_SOC_DPCM_TRIGGER_POST,
0375             SND_SOC_DPCM_TRIGGER_POST
0376         },
0377         .dpcm_capture = 1,
0378         .ops = &skylake_rt286_fe_ops,
0379         SND_SOC_DAILINK_REG(system, dummy, platform),
0380     },
0381     [SKL_DPCM_AUDIO_REF_CP] = {
0382         .name = "Skl Audio Reference cap",
0383         .stream_name = "refcap",
0384         .init = NULL,
0385         .dpcm_capture = 1,
0386         .nonatomic = 1,
0387         .dynamic = 1,
0388         SND_SOC_DAILINK_REG(reference, dummy, platform),
0389     },
0390     [SKL_DPCM_AUDIO_DMIC_CP] = {
0391         .name = "Skl Audio DMIC cap",
0392         .stream_name = "dmiccap",
0393         .init = NULL,
0394         .dpcm_capture = 1,
0395         .nonatomic = 1,
0396         .dynamic = 1,
0397         .ops = &skylake_dmic_ops,
0398         SND_SOC_DAILINK_REG(dmic, dummy, platform),
0399     },
0400     [SKL_DPCM_AUDIO_HDMI1_PB] = {
0401         .name = "Skl HDMI Port1",
0402         .stream_name = "Hdmi1",
0403         .dpcm_playback = 1,
0404         .init = NULL,
0405         .nonatomic = 1,
0406         .dynamic = 1,
0407         SND_SOC_DAILINK_REG(hdmi1, dummy, platform),
0408     },
0409     [SKL_DPCM_AUDIO_HDMI2_PB] = {
0410         .name = "Skl HDMI Port2",
0411         .stream_name = "Hdmi2",
0412         .dpcm_playback = 1,
0413         .init = NULL,
0414         .nonatomic = 1,
0415         .dynamic = 1,
0416         SND_SOC_DAILINK_REG(hdmi2, dummy, platform),
0417     },
0418     [SKL_DPCM_AUDIO_HDMI3_PB] = {
0419         .name = "Skl HDMI Port3",
0420         .stream_name = "Hdmi3",
0421         .dpcm_playback = 1,
0422         .init = NULL,
0423         .nonatomic = 1,
0424         .dynamic = 1,
0425         SND_SOC_DAILINK_REG(hdmi3, dummy, platform),
0426     },
0427 
0428     /* Back End DAI links */
0429     {
0430         /* SSP0 - Codec */
0431         .name = "SSP0-Codec",
0432         .id = 0,
0433         .no_pcm = 1,
0434         .init = skylake_rt286_codec_init,
0435         .dai_fmt = SND_SOC_DAIFMT_I2S |
0436             SND_SOC_DAIFMT_NB_NF |
0437             SND_SOC_DAIFMT_CBC_CFC,
0438         .ignore_pmdown_time = 1,
0439         .be_hw_params_fixup = skylake_ssp0_fixup,
0440         .ops = &skylake_rt286_ops,
0441         .dpcm_playback = 1,
0442         .dpcm_capture = 1,
0443         SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
0444     },
0445     {
0446         .name = "dmic01",
0447         .id = 1,
0448         .be_hw_params_fixup = skylake_dmic_fixup,
0449         .ignore_suspend = 1,
0450         .dpcm_capture = 1,
0451         .no_pcm = 1,
0452         SND_SOC_DAILINK_REG(dmic01_pin, dmic_codec, platform),
0453     },
0454     {
0455         .name = "iDisp1",
0456         .id = 2,
0457         .init = skylake_hdmi_init,
0458         .dpcm_playback = 1,
0459         .no_pcm = 1,
0460         SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
0461     },
0462     {
0463         .name = "iDisp2",
0464         .id = 3,
0465         .init = skylake_hdmi_init,
0466         .dpcm_playback = 1,
0467         .no_pcm = 1,
0468         SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
0469     },
0470     {
0471         .name = "iDisp3",
0472         .id = 4,
0473         .init = skylake_hdmi_init,
0474         .dpcm_playback = 1,
0475         .no_pcm = 1,
0476         SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
0477     },
0478 };
0479 
0480 #define NAME_SIZE   32
0481 static int skylake_card_late_probe(struct snd_soc_card *card)
0482 {
0483     struct skl_rt286_private *ctx = snd_soc_card_get_drvdata(card);
0484     struct skl_hdmi_pcm *pcm;
0485     struct snd_soc_component *component = NULL;
0486     int err, i = 0;
0487     char jack_name[NAME_SIZE];
0488 
0489     list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
0490         component = pcm->codec_dai->component;
0491         snprintf(jack_name, sizeof(jack_name),
0492             "HDMI/DP, pcm=%d Jack", pcm->device);
0493         err = snd_soc_card_jack_new(card, jack_name,
0494                     SND_JACK_AVOUT, &skylake_hdmi[i]);
0495 
0496         if (err)
0497             return err;
0498 
0499         err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
0500                         &skylake_hdmi[i]);
0501         if (err < 0)
0502             return err;
0503 
0504         i++;
0505     }
0506 
0507     if (!component)
0508         return -EINVAL;
0509 
0510     return hdac_hdmi_jack_port_init(component, &card->dapm);
0511 }
0512 
0513 /* skylake audio machine driver for SPT + RT286S */
0514 static struct snd_soc_card skylake_rt286 = {
0515     .name = "skylake-rt286",
0516     .owner = THIS_MODULE,
0517     .dai_link = skylake_rt286_dais,
0518     .num_links = ARRAY_SIZE(skylake_rt286_dais),
0519     .controls = skylake_controls,
0520     .num_controls = ARRAY_SIZE(skylake_controls),
0521     .dapm_widgets = skylake_widgets,
0522     .num_dapm_widgets = ARRAY_SIZE(skylake_widgets),
0523     .dapm_routes = skylake_rt286_map,
0524     .num_dapm_routes = ARRAY_SIZE(skylake_rt286_map),
0525     .fully_routed = true,
0526     .late_probe = skylake_card_late_probe,
0527 };
0528 
0529 static int skylake_audio_probe(struct platform_device *pdev)
0530 {
0531     struct skl_rt286_private *ctx;
0532 
0533     ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
0534     if (!ctx)
0535         return -ENOMEM;
0536 
0537     INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
0538 
0539     skylake_rt286.dev = &pdev->dev;
0540     snd_soc_card_set_drvdata(&skylake_rt286, ctx);
0541 
0542     return devm_snd_soc_register_card(&pdev->dev, &skylake_rt286);
0543 }
0544 
0545 static const struct platform_device_id skl_board_ids[] = {
0546     { .name = "skl_alc286s_i2s" },
0547     { .name = "kbl_alc286s_i2s" },
0548     { }
0549 };
0550 MODULE_DEVICE_TABLE(platform, skl_board_ids);
0551 
0552 static struct platform_driver skylake_audio = {
0553     .probe = skylake_audio_probe,
0554     .driver = {
0555         .name = "skl_alc286s_i2s",
0556         .pm = &snd_soc_pm_ops,
0557     },
0558     .id_table = skl_board_ids,
0559 
0560 };
0561 
0562 module_platform_driver(skylake_audio)
0563 
0564 /* Module information */
0565 MODULE_AUTHOR("Omair Mohammed Abdullah <omair.m.abdullah@intel.com>");
0566 MODULE_DESCRIPTION("Intel SST Audio for Skylake");
0567 MODULE_LICENSE("GPL v2");