Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Sound card driver for Intel Broadwell Wildcat Point with Realtek 286
0004  *
0005  * Copyright (C) 2013, Intel Corporation. All rights reserved.
0006  */
0007 
0008 #include <linux/module.h>
0009 #include <linux/platform_device.h>
0010 #include <sound/core.h>
0011 #include <sound/jack.h>
0012 #include <sound/pcm.h>
0013 #include <sound/pcm_params.h>
0014 #include <sound/soc.h>
0015 #include <sound/soc-acpi.h>
0016 #include "../../codecs/rt286.h"
0017 
0018 static struct snd_soc_jack card_headset;
0019 
0020 static struct snd_soc_jack_pin card_headset_pins[] = {
0021     {
0022         .pin = "Mic Jack",
0023         .mask = SND_JACK_MICROPHONE,
0024     },
0025     {
0026         .pin = "Headphone Jack",
0027         .mask = SND_JACK_HEADPHONE,
0028     },
0029 };
0030 
0031 static const struct snd_kcontrol_new card_controls[] = {
0032     SOC_DAPM_PIN_SWITCH("Speaker"),
0033     SOC_DAPM_PIN_SWITCH("Headphone Jack"),
0034 };
0035 
0036 static const struct snd_soc_dapm_widget card_widgets[] = {
0037     SND_SOC_DAPM_HP("Headphone Jack", NULL),
0038     SND_SOC_DAPM_SPK("Speaker", NULL),
0039     SND_SOC_DAPM_MIC("Mic Jack", NULL),
0040     SND_SOC_DAPM_MIC("DMIC1", NULL),
0041     SND_SOC_DAPM_MIC("DMIC2", NULL),
0042     SND_SOC_DAPM_LINE("Line Jack", NULL),
0043 };
0044 
0045 static const struct snd_soc_dapm_route card_routes[] = {
0046     {"Speaker", NULL, "SPOR"},
0047     {"Speaker", NULL, "SPOL"},
0048 
0049     {"Headphone Jack", NULL, "HPO Pin"},
0050 
0051     {"MIC1", NULL, "Mic Jack"},
0052     {"LINE1", NULL, "Line Jack"},
0053 
0054     {"DMIC1 Pin", NULL, "DMIC1"},
0055     {"DMIC2 Pin", NULL, "DMIC2"},
0056 
0057     /* CODEC BE connections */
0058     {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
0059     {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
0060 };
0061 
0062 static int codec_link_init(struct snd_soc_pcm_runtime *rtd)
0063 {
0064     struct snd_soc_component *codec = asoc_rtd_to_codec(rtd, 0)->component;
0065     int ret;
0066 
0067     ret = snd_soc_card_jack_new_pins(rtd->card, "Headset", SND_JACK_HEADSET | SND_JACK_BTN_0,
0068                      &card_headset, card_headset_pins,
0069                      ARRAY_SIZE(card_headset_pins));
0070     if (ret)
0071         return ret;
0072 
0073     return snd_soc_component_set_jack(codec, &card_headset, NULL);
0074 }
0075 
0076 static int codec_link_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
0077                       struct snd_pcm_hw_params *params)
0078 {
0079     struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
0080     struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
0081 
0082     /* The ADSP will convert the FE rate to 48kHz, stereo. */
0083     rate->min = rate->max = 48000;
0084     channels->min = channels->max = 2;
0085     /* Set SSP0 to 16 bit. */
0086     params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
0087 
0088     return 0;
0089 }
0090 
0091 static int codec_link_hw_params(struct snd_pcm_substream *substream,
0092                 struct snd_pcm_hw_params *params)
0093 {
0094     struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0095     struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0096     int ret;
0097 
0098     ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000, SND_SOC_CLOCK_IN);
0099     if (ret < 0) {
0100         dev_err(rtd->dev, "set codec sysclk failed: %d\n", ret);
0101         return ret;
0102     }
0103 
0104     return ret;
0105 }
0106 
0107 static const struct snd_soc_ops codec_link_ops = {
0108     .hw_params = codec_link_hw_params,
0109 };
0110 
0111 SND_SOC_DAILINK_DEF(system, DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
0112 SND_SOC_DAILINK_DEF(offload0, DAILINK_COMP_ARRAY(COMP_CPU("Offload0 Pin")));
0113 SND_SOC_DAILINK_DEF(offload1, DAILINK_COMP_ARRAY(COMP_CPU("Offload1 Pin")));
0114 SND_SOC_DAILINK_DEF(loopback, DAILINK_COMP_ARRAY(COMP_CPU("Loopback Pin")));
0115 
0116 SND_SOC_DAILINK_DEF(dummy, DAILINK_COMP_ARRAY(COMP_DUMMY()));
0117 SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio")));
0118 SND_SOC_DAILINK_DEF(codec, DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT343A:00", "rt286-aif1")));
0119 SND_SOC_DAILINK_DEF(ssp0_port, DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port")));
0120 
0121 static struct snd_soc_dai_link card_dai_links[] = {
0122     /* Front End DAI links */
0123     {
0124         .name = "System PCM",
0125         .stream_name = "System Playback/Capture",
0126         .nonatomic = 1,
0127         .dynamic = 1,
0128         .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0129         .dpcm_playback = 1,
0130         .dpcm_capture = 1,
0131         SND_SOC_DAILINK_REG(system, dummy, platform),
0132     },
0133     {
0134         .name = "Offload0",
0135         .stream_name = "Offload0 Playback",
0136         .nonatomic = 1,
0137         .dynamic = 1,
0138         .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0139         .dpcm_playback = 1,
0140         SND_SOC_DAILINK_REG(offload0, dummy, platform),
0141     },
0142     {
0143         .name = "Offload1",
0144         .stream_name = "Offload1 Playback",
0145         .nonatomic = 1,
0146         .dynamic = 1,
0147         .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0148         .dpcm_playback = 1,
0149         SND_SOC_DAILINK_REG(offload1, dummy, platform),
0150     },
0151     {
0152         .name = "Loopback PCM",
0153         .stream_name = "Loopback",
0154         .nonatomic = 1,
0155         .dynamic = 1,
0156         .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
0157         .dpcm_capture = 1,
0158         SND_SOC_DAILINK_REG(loopback, dummy, platform),
0159     },
0160     /* Back End DAI links */
0161     {
0162         /* SSP0 - Codec */
0163         .name = "Codec",
0164         .id = 0,
0165         .nonatomic = 1,
0166         .no_pcm = 1,
0167         .init = codec_link_init,
0168         .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC,
0169         .ignore_pmdown_time = 1,
0170         .be_hw_params_fixup = codec_link_hw_params_fixup,
0171         .ops = &codec_link_ops,
0172         .dpcm_playback = 1,
0173         .dpcm_capture = 1,
0174         SND_SOC_DAILINK_REG(ssp0_port, codec, platform),
0175     },
0176 };
0177 
0178 static void bdw_rt286_disable_jack(struct snd_soc_card *card)
0179 {
0180     struct snd_soc_component *component;
0181 
0182     for_each_card_components(card, component) {
0183         if (!strcmp(component->name, "i2c-INT343A:00")) {
0184             dev_dbg(component->dev, "disabling jack detect before going to suspend.\n");
0185             snd_soc_component_set_jack(component, NULL, NULL);
0186             break;
0187         }
0188     }
0189 }
0190 
0191 static int bdw_rt286_suspend(struct snd_soc_card *card)
0192 {
0193     bdw_rt286_disable_jack(card);
0194 
0195     return 0;
0196 }
0197 
0198 static int bdw_rt286_resume(struct snd_soc_card *card)
0199 {
0200     struct snd_soc_component *component;
0201 
0202     for_each_card_components(card, component) {
0203         if (!strcmp(component->name, "i2c-INT343A:00")) {
0204             dev_dbg(component->dev, "enabling jack detect for resume.\n");
0205             snd_soc_component_set_jack(component, &card_headset, NULL);
0206             break;
0207         }
0208     }
0209 
0210     return 0;
0211 }
0212 
0213 static struct snd_soc_card bdw_rt286_card = {
0214     .owner = THIS_MODULE,
0215     .dai_link = card_dai_links,
0216     .num_links = ARRAY_SIZE(card_dai_links),
0217     .controls = card_controls,
0218     .num_controls = ARRAY_SIZE(card_controls),
0219     .dapm_widgets = card_widgets,
0220     .num_dapm_widgets = ARRAY_SIZE(card_widgets),
0221     .dapm_routes = card_routes,
0222     .num_dapm_routes = ARRAY_SIZE(card_routes),
0223     .fully_routed = true,
0224     .suspend_pre = bdw_rt286_suspend,
0225     .resume_post = bdw_rt286_resume,
0226 };
0227 
0228 /* Use space before codec name to simplify card ID, and simplify driver name. */
0229 #define SOF_CARD_NAME "bdw rt286" /* card name will be 'sof-bdw rt286' */
0230 #define SOF_DRIVER_NAME "SOF"
0231 
0232 #define CARD_NAME "broadwell-rt286"
0233 
0234 static int bdw_rt286_probe(struct platform_device *pdev)
0235 {
0236     struct snd_soc_acpi_mach *mach;
0237     struct device *dev = &pdev->dev;
0238     int ret;
0239 
0240     bdw_rt286_card.dev = dev;
0241     mach = dev_get_platdata(dev);
0242 
0243     ret = snd_soc_fixup_dai_links_platform_name(&bdw_rt286_card, mach->mach_params.platform);
0244     if (ret)
0245         return ret;
0246 
0247     if (snd_soc_acpi_sof_parent(dev)) {
0248         bdw_rt286_card.name = SOF_CARD_NAME;
0249         bdw_rt286_card.driver_name = SOF_DRIVER_NAME;
0250     } else {
0251         bdw_rt286_card.name = CARD_NAME;
0252     }
0253 
0254     return devm_snd_soc_register_card(dev, &bdw_rt286_card);
0255 }
0256 
0257 static int bdw_rt286_remove(struct platform_device *pdev)
0258 {
0259     struct snd_soc_card *card = platform_get_drvdata(pdev);
0260 
0261     bdw_rt286_disable_jack(card);
0262 
0263     return 0;
0264 }
0265 
0266 static struct platform_driver bdw_rt286_driver = {
0267     .probe = bdw_rt286_probe,
0268     .remove = bdw_rt286_remove,
0269     .driver = {
0270         .name = "bdw_rt286",
0271         .pm = &snd_soc_pm_ops
0272     },
0273 };
0274 
0275 module_platform_driver(bdw_rt286_driver)
0276 
0277 MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
0278 MODULE_DESCRIPTION("Sound card driver for Intel Broadwell Wildcat Point with Realtek 286");
0279 MODULE_LICENSE("GPL");
0280 MODULE_ALIAS("platform:bdw_rt286");