19952f691SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 22d995e5dSJohn Keeping /* 32d995e5dSJohn Keeping * ASoC machine driver for Intel Broadwell platforms with RT5677 codec 42d995e5dSJohn Keeping * 52d995e5dSJohn Keeping * Copyright (c) 2014, The Chromium OS Authors. All rights reserved. 62d995e5dSJohn Keeping */ 72d995e5dSJohn Keeping 855e59aa0SAndy Shevchenko #include <linux/acpi.h> 92d995e5dSJohn Keeping #include <linux/module.h> 102d995e5dSJohn Keeping #include <linux/platform_device.h> 112d995e5dSJohn Keeping #include <linux/gpio/consumer.h> 122d995e5dSJohn Keeping #include <linux/delay.h> 132d995e5dSJohn Keeping #include <sound/core.h> 142d995e5dSJohn Keeping #include <sound/pcm.h> 152d995e5dSJohn Keeping #include <sound/soc.h> 162d995e5dSJohn Keeping #include <sound/pcm_params.h> 172d995e5dSJohn Keeping #include <sound/jack.h> 187e40ddcfSPierre-Louis Bossart #include <sound/soc-acpi.h> 192d995e5dSJohn Keeping 202d995e5dSJohn Keeping #include "../common/sst-dsp.h" 212d995e5dSJohn Keeping #include "../haswell/sst-haswell-ipc.h" 222d995e5dSJohn Keeping 232d995e5dSJohn Keeping #include "../../codecs/rt5677.h" 242d995e5dSJohn Keeping 252d995e5dSJohn Keeping struct bdw_rt5677_priv { 262d995e5dSJohn Keeping struct gpio_desc *gpio_hp_en; 2779223bf1SKuninori Morimoto struct snd_soc_component *component; 282d995e5dSJohn Keeping }; 292d995e5dSJohn Keeping 302d995e5dSJohn Keeping static int bdw_rt5677_event_hp(struct snd_soc_dapm_widget *w, 312d995e5dSJohn Keeping struct snd_kcontrol *k, int event) 322d995e5dSJohn Keeping { 332d995e5dSJohn Keeping struct snd_soc_dapm_context *dapm = w->dapm; 342d995e5dSJohn Keeping struct snd_soc_card *card = dapm->card; 352d995e5dSJohn Keeping struct bdw_rt5677_priv *bdw_rt5677 = snd_soc_card_get_drvdata(card); 362d995e5dSJohn Keeping 372d995e5dSJohn Keeping if (SND_SOC_DAPM_EVENT_ON(event)) 382d995e5dSJohn Keeping msleep(70); 392d995e5dSJohn Keeping 402d995e5dSJohn Keeping gpiod_set_value_cansleep(bdw_rt5677->gpio_hp_en, 412d995e5dSJohn Keeping SND_SOC_DAPM_EVENT_ON(event)); 422d995e5dSJohn Keeping 432d995e5dSJohn Keeping return 0; 442d995e5dSJohn Keeping } 452d995e5dSJohn Keeping 462d995e5dSJohn Keeping static const struct snd_soc_dapm_widget bdw_rt5677_widgets[] = { 472d995e5dSJohn Keeping SND_SOC_DAPM_HP("Headphone", bdw_rt5677_event_hp), 482d995e5dSJohn Keeping SND_SOC_DAPM_SPK("Speaker", NULL), 492d995e5dSJohn Keeping SND_SOC_DAPM_MIC("Headset Mic", NULL), 502d995e5dSJohn Keeping SND_SOC_DAPM_MIC("Local DMICs", NULL), 512d995e5dSJohn Keeping SND_SOC_DAPM_MIC("Remote DMICs", NULL), 522d995e5dSJohn Keeping }; 532d995e5dSJohn Keeping 542d995e5dSJohn Keeping static const struct snd_soc_dapm_route bdw_rt5677_map[] = { 552d995e5dSJohn Keeping /* Speakers */ 562d995e5dSJohn Keeping {"Speaker", NULL, "PDM1L"}, 572d995e5dSJohn Keeping {"Speaker", NULL, "PDM1R"}, 582d995e5dSJohn Keeping 592d995e5dSJohn Keeping /* Headset jack connectors */ 602d995e5dSJohn Keeping {"Headphone", NULL, "LOUT1"}, 612d995e5dSJohn Keeping {"Headphone", NULL, "LOUT2"}, 622d995e5dSJohn Keeping {"IN1P", NULL, "Headset Mic"}, 632d995e5dSJohn Keeping {"IN1N", NULL, "Headset Mic"}, 642d995e5dSJohn Keeping 652d995e5dSJohn Keeping /* Digital MICs 662d995e5dSJohn Keeping * Local DMICs: the two DMICs on the mainboard 672d995e5dSJohn Keeping * Remote DMICs: the two DMICs on the camera module 682d995e5dSJohn Keeping */ 692d995e5dSJohn Keeping {"DMIC L1", NULL, "Remote DMICs"}, 702d995e5dSJohn Keeping {"DMIC R1", NULL, "Remote DMICs"}, 712d995e5dSJohn Keeping {"DMIC L2", NULL, "Local DMICs"}, 722d995e5dSJohn Keeping {"DMIC R2", NULL, "Local DMICs"}, 732d995e5dSJohn Keeping 742d995e5dSJohn Keeping /* CODEC BE connections */ 752d995e5dSJohn Keeping {"SSP0 CODEC IN", NULL, "AIF1 Capture"}, 762d995e5dSJohn Keeping {"AIF1 Playback", NULL, "SSP0 CODEC OUT"}, 77157b006fSBen Zhang {"DSP Capture", NULL, "DSP Buffer"}, 7855229597SCurtis Malainey 7955229597SCurtis Malainey /* DSP Clock Connections */ 8055229597SCurtis Malainey { "DSP Buffer", NULL, "SSP0 CODEC IN" }, 8155229597SCurtis Malainey { "SSP0 CODEC IN", NULL, "DSPTX" }, 822d995e5dSJohn Keeping }; 832d995e5dSJohn Keeping 842d995e5dSJohn Keeping static const struct snd_kcontrol_new bdw_rt5677_controls[] = { 852d995e5dSJohn Keeping SOC_DAPM_PIN_SWITCH("Speaker"), 862d995e5dSJohn Keeping SOC_DAPM_PIN_SWITCH("Headphone"), 872d995e5dSJohn Keeping SOC_DAPM_PIN_SWITCH("Headset Mic"), 882d995e5dSJohn Keeping SOC_DAPM_PIN_SWITCH("Local DMICs"), 892d995e5dSJohn Keeping SOC_DAPM_PIN_SWITCH("Remote DMICs"), 902d995e5dSJohn Keeping }; 912d995e5dSJohn Keeping 922d995e5dSJohn Keeping 932d995e5dSJohn Keeping static struct snd_soc_jack headphone_jack; 942d995e5dSJohn Keeping static struct snd_soc_jack mic_jack; 952d995e5dSJohn Keeping 962d995e5dSJohn Keeping static struct snd_soc_jack_pin headphone_jack_pin = { 972d995e5dSJohn Keeping .pin = "Headphone", 982d995e5dSJohn Keeping .mask = SND_JACK_HEADPHONE, 992d995e5dSJohn Keeping }; 1002d995e5dSJohn Keeping 1012d995e5dSJohn Keeping static struct snd_soc_jack_pin mic_jack_pin = { 1022d995e5dSJohn Keeping .pin = "Headset Mic", 1032d995e5dSJohn Keeping .mask = SND_JACK_MICROPHONE, 1042d995e5dSJohn Keeping }; 1052d995e5dSJohn Keeping 1062d995e5dSJohn Keeping static struct snd_soc_jack_gpio headphone_jack_gpio = { 1072d995e5dSJohn Keeping .name = "plug-det", 1082d995e5dSJohn Keeping .report = SND_JACK_HEADPHONE, 1092d995e5dSJohn Keeping .debounce_time = 200, 1102d995e5dSJohn Keeping }; 1112d995e5dSJohn Keeping 1122d995e5dSJohn Keeping static struct snd_soc_jack_gpio mic_jack_gpio = { 1132d995e5dSJohn Keeping .name = "mic-present", 1142d995e5dSJohn Keeping .report = SND_JACK_MICROPHONE, 1152d995e5dSJohn Keeping .debounce_time = 200, 1162d995e5dSJohn Keeping .invert = 1, 1172d995e5dSJohn Keeping }; 1182d995e5dSJohn Keeping 11955e59aa0SAndy Shevchenko /* GPIO indexes defined by ACPI */ 12055e59aa0SAndy Shevchenko enum { 12155e59aa0SAndy Shevchenko RT5677_GPIO_PLUG_DET = 0, 12255e59aa0SAndy Shevchenko RT5677_GPIO_MIC_PRESENT_L = 1, 12355e59aa0SAndy Shevchenko RT5677_GPIO_HOTWORD_DET_L = 2, 12455e59aa0SAndy Shevchenko RT5677_GPIO_DSP_INT = 3, 12555e59aa0SAndy Shevchenko RT5677_GPIO_HP_AMP_SHDN_L = 4, 12655e59aa0SAndy Shevchenko }; 12755e59aa0SAndy Shevchenko 12855e59aa0SAndy Shevchenko static const struct acpi_gpio_params plug_det_gpio = { RT5677_GPIO_PLUG_DET, 0, false }; 12955e59aa0SAndy Shevchenko static const struct acpi_gpio_params mic_present_gpio = { RT5677_GPIO_MIC_PRESENT_L, 0, false }; 13055e59aa0SAndy Shevchenko static const struct acpi_gpio_params headphone_enable_gpio = { RT5677_GPIO_HP_AMP_SHDN_L, 0, false }; 13155e59aa0SAndy Shevchenko 13255e59aa0SAndy Shevchenko static const struct acpi_gpio_mapping bdw_rt5677_gpios[] = { 13355e59aa0SAndy Shevchenko { "plug-det-gpios", &plug_det_gpio, 1 }, 13455e59aa0SAndy Shevchenko { "mic-present-gpios", &mic_present_gpio, 1 }, 13555e59aa0SAndy Shevchenko { "headphone-enable-gpios", &headphone_enable_gpio, 1 }, 13655e59aa0SAndy Shevchenko { NULL }, 13755e59aa0SAndy Shevchenko }; 13855e59aa0SAndy Shevchenko 1392d995e5dSJohn Keeping static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd, 1402d995e5dSJohn Keeping struct snd_pcm_hw_params *params) 1412d995e5dSJohn Keeping { 1422d995e5dSJohn Keeping struct snd_interval *rate = hw_param_interval(params, 1432d995e5dSJohn Keeping SNDRV_PCM_HW_PARAM_RATE); 1442d995e5dSJohn Keeping struct snd_interval *channels = hw_param_interval(params, 1452d995e5dSJohn Keeping SNDRV_PCM_HW_PARAM_CHANNELS); 1462d995e5dSJohn Keeping 1472d995e5dSJohn Keeping /* The ADSP will covert the FE rate to 48k, stereo */ 1482d995e5dSJohn Keeping rate->min = rate->max = 48000; 1492d995e5dSJohn Keeping channels->min = channels->max = 2; 1502d995e5dSJohn Keeping 1512d995e5dSJohn Keeping /* set SSP0 to 16 bit */ 152b5453e8cSTakashi Iwai params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); 1532d995e5dSJohn Keeping return 0; 1542d995e5dSJohn Keeping } 1552d995e5dSJohn Keeping 1562d995e5dSJohn Keeping static int bdw_rt5677_hw_params(struct snd_pcm_substream *substream, 1572d995e5dSJohn Keeping struct snd_pcm_hw_params *params) 1582d995e5dSJohn Keeping { 1592d995e5dSJohn Keeping struct snd_soc_pcm_runtime *rtd = substream->private_data; 1602d995e5dSJohn Keeping struct snd_soc_dai *codec_dai = rtd->codec_dai; 1612d995e5dSJohn Keeping int ret; 1622d995e5dSJohn Keeping 1632d995e5dSJohn Keeping ret = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_MCLK, 24576000, 1642d995e5dSJohn Keeping SND_SOC_CLOCK_IN); 1652d995e5dSJohn Keeping if (ret < 0) { 1662d995e5dSJohn Keeping dev_err(rtd->dev, "can't set codec sysclk configuration\n"); 1672d995e5dSJohn Keeping return ret; 1682d995e5dSJohn Keeping } 1692d995e5dSJohn Keeping 1702d995e5dSJohn Keeping return ret; 1712d995e5dSJohn Keeping } 1722d995e5dSJohn Keeping 173ba0b3a97SCurtis Malainey static int bdw_rt5677_dsp_hw_params(struct snd_pcm_substream *substream, 174ba0b3a97SCurtis Malainey struct snd_pcm_hw_params *params) 175ba0b3a97SCurtis Malainey { 176ba0b3a97SCurtis Malainey struct snd_soc_pcm_runtime *rtd = substream->private_data; 177ba0b3a97SCurtis Malainey struct snd_soc_dai *codec_dai = rtd->codec_dai; 178ba0b3a97SCurtis Malainey int ret; 179ba0b3a97SCurtis Malainey 180ba0b3a97SCurtis Malainey ret = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_PLL1, 24576000, 181ba0b3a97SCurtis Malainey SND_SOC_CLOCK_IN); 182ba0b3a97SCurtis Malainey if (ret < 0) { 183ba0b3a97SCurtis Malainey dev_err(rtd->dev, "can't set codec sysclk configuration\n"); 184ba0b3a97SCurtis Malainey return ret; 185ba0b3a97SCurtis Malainey } 186ba0b3a97SCurtis Malainey ret = snd_soc_dai_set_pll(codec_dai, 0, RT5677_PLL1_S_MCLK, 187ba0b3a97SCurtis Malainey 24000000, 24576000); 188ba0b3a97SCurtis Malainey if (ret < 0) { 189ba0b3a97SCurtis Malainey dev_err(rtd->dev, "can't set codec pll configuration\n"); 190ba0b3a97SCurtis Malainey return ret; 191ba0b3a97SCurtis Malainey } 192ba0b3a97SCurtis Malainey 193ba0b3a97SCurtis Malainey return 0; 194ba0b3a97SCurtis Malainey } 195ba0b3a97SCurtis Malainey 1969b6fdef6SJulia Lawall static const struct snd_soc_ops bdw_rt5677_ops = { 1972d995e5dSJohn Keeping .hw_params = bdw_rt5677_hw_params, 1982d995e5dSJohn Keeping }; 1992d995e5dSJohn Keeping 200ba0b3a97SCurtis Malainey static const struct snd_soc_ops bdw_rt5677_dsp_ops = { 201ba0b3a97SCurtis Malainey .hw_params = bdw_rt5677_dsp_hw_params, 202ba0b3a97SCurtis Malainey }; 203ba0b3a97SCurtis Malainey 204f35bf70fSLiam Girdwood #if !IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL) 2052d995e5dSJohn Keeping static int bdw_rt5677_rtd_init(struct snd_soc_pcm_runtime *rtd) 2062d995e5dSJohn Keeping { 2072ee178dbSKuninori Morimoto struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); 2082ee178dbSKuninori Morimoto struct sst_pdata *pdata = dev_get_platdata(component->dev); 2092d995e5dSJohn Keeping struct sst_hsw *broadwell = pdata->dsp; 2102d995e5dSJohn Keeping int ret; 2112d995e5dSJohn Keeping 2122d995e5dSJohn Keeping /* Set ADSP SSP port settings */ 2132d995e5dSJohn Keeping ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0, 2142d995e5dSJohn Keeping SST_HSW_DEVICE_MCLK_FREQ_24_MHZ, 2152d995e5dSJohn Keeping SST_HSW_DEVICE_CLOCK_MASTER, 9); 2162d995e5dSJohn Keeping if (ret < 0) { 2172d995e5dSJohn Keeping dev_err(rtd->dev, "error: failed to set device config\n"); 2182d995e5dSJohn Keeping return ret; 2192d995e5dSJohn Keeping } 2202d995e5dSJohn Keeping 2212d995e5dSJohn Keeping return 0; 2222d995e5dSJohn Keeping } 223f35bf70fSLiam Girdwood #endif 2242d995e5dSJohn Keeping 2252d995e5dSJohn Keeping static int bdw_rt5677_init(struct snd_soc_pcm_runtime *rtd) 2262d995e5dSJohn Keeping { 2272d995e5dSJohn Keeping struct bdw_rt5677_priv *bdw_rt5677 = 2282d995e5dSJohn Keeping snd_soc_card_get_drvdata(rtd->card); 22979223bf1SKuninori Morimoto struct snd_soc_component *component = rtd->codec_dai->component; 23079223bf1SKuninori Morimoto struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 23155e59aa0SAndy Shevchenko int ret; 23255e59aa0SAndy Shevchenko 23379223bf1SKuninori Morimoto ret = devm_acpi_dev_add_driver_gpios(component->dev, bdw_rt5677_gpios); 23455e59aa0SAndy Shevchenko if (ret) 23579223bf1SKuninori Morimoto dev_warn(component->dev, "Failed to add driver gpios\n"); 2362d995e5dSJohn Keeping 2372d995e5dSJohn Keeping /* Enable codec ASRC function for Stereo DAC/Stereo1 ADC/DMIC/I2S1. 2382d995e5dSJohn Keeping * The ASRC clock source is clk_i2s1_asrc. 2392d995e5dSJohn Keeping */ 24079223bf1SKuninori Morimoto rt5677_sel_asrc_clk_src(component, RT5677_DA_STEREO_FILTER | 2412d995e5dSJohn Keeping RT5677_AD_STEREO1_FILTER | RT5677_I2S1_SOURCE, 2422d995e5dSJohn Keeping RT5677_CLK_SEL_I2S1_ASRC); 243ba0b3a97SCurtis Malainey /* Enable codec ASRC function for Mono ADC L. 244ba0b3a97SCurtis Malainey * The ASRC clock source is clk_sys2_asrc. 245ba0b3a97SCurtis Malainey */ 246ba0b3a97SCurtis Malainey rt5677_sel_asrc_clk_src(component, RT5677_AD_MONO_L_FILTER, 247ba0b3a97SCurtis Malainey RT5677_CLK_SEL_SYS2); 2482d995e5dSJohn Keeping 2492d995e5dSJohn Keeping /* Request rt5677 GPIO for headphone amp control */ 25079223bf1SKuninori Morimoto bdw_rt5677->gpio_hp_en = devm_gpiod_get(component->dev, "headphone-enable", 251b3ec72acSAndy Shevchenko GPIOD_OUT_LOW); 2522d995e5dSJohn Keeping if (IS_ERR(bdw_rt5677->gpio_hp_en)) { 25379223bf1SKuninori Morimoto dev_err(component->dev, "Can't find HP_AMP_SHDN_L gpio\n"); 2542d995e5dSJohn Keeping return PTR_ERR(bdw_rt5677->gpio_hp_en); 2552d995e5dSJohn Keeping } 2562d995e5dSJohn Keeping 2572d995e5dSJohn Keeping /* Create and initialize headphone jack */ 2582d995e5dSJohn Keeping if (!snd_soc_card_jack_new(rtd->card, "Headphone Jack", 2592d995e5dSJohn Keeping SND_JACK_HEADPHONE, &headphone_jack, 2602d995e5dSJohn Keeping &headphone_jack_pin, 1)) { 26179223bf1SKuninori Morimoto headphone_jack_gpio.gpiod_dev = component->dev; 2622d995e5dSJohn Keeping if (snd_soc_jack_add_gpios(&headphone_jack, 1, 2632d995e5dSJohn Keeping &headphone_jack_gpio)) 26479223bf1SKuninori Morimoto dev_err(component->dev, "Can't add headphone jack gpio\n"); 2652d995e5dSJohn Keeping } else { 26679223bf1SKuninori Morimoto dev_err(component->dev, "Can't create headphone jack\n"); 2672d995e5dSJohn Keeping } 2682d995e5dSJohn Keeping 2692d995e5dSJohn Keeping /* Create and initialize mic jack */ 2702d995e5dSJohn Keeping if (!snd_soc_card_jack_new(rtd->card, "Mic Jack", 2712d995e5dSJohn Keeping SND_JACK_MICROPHONE, &mic_jack, 2722d995e5dSJohn Keeping &mic_jack_pin, 1)) { 27379223bf1SKuninori Morimoto mic_jack_gpio.gpiod_dev = component->dev; 2742d995e5dSJohn Keeping if (snd_soc_jack_add_gpios(&mic_jack, 1, &mic_jack_gpio)) 27579223bf1SKuninori Morimoto dev_err(component->dev, "Can't add mic jack gpio\n"); 2762d995e5dSJohn Keeping } else { 27779223bf1SKuninori Morimoto dev_err(component->dev, "Can't create mic jack\n"); 2782d995e5dSJohn Keeping } 27979223bf1SKuninori Morimoto bdw_rt5677->component = component; 2802d995e5dSJohn Keeping 2812d995e5dSJohn Keeping snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); 2822d995e5dSJohn Keeping return 0; 2832d995e5dSJohn Keeping } 2842d995e5dSJohn Keeping 2852d995e5dSJohn Keeping /* broadwell digital audio interface glue - connects codec <--> CPU */ 2863f6c2a2eSKuninori Morimoto SND_SOC_DAILINK_DEF(dummy, 2873f6c2a2eSKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY())); 2883f6c2a2eSKuninori Morimoto 2893f6c2a2eSKuninori Morimoto SND_SOC_DAILINK_DEF(fe, 2903f6c2a2eSKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("System Pin"))); 2913f6c2a2eSKuninori Morimoto 2923f6c2a2eSKuninori Morimoto SND_SOC_DAILINK_DEF(platform, 2933f6c2a2eSKuninori Morimoto DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio"))); 2943f6c2a2eSKuninori Morimoto 2953f6c2a2eSKuninori Morimoto SND_SOC_DAILINK_DEF(be, 2963f6c2a2eSKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RT5677CE:00", "rt5677-aif1"))); 2973f6c2a2eSKuninori Morimoto 2984865bde1SPierre-Louis Bossart #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL) 2994865bde1SPierre-Louis Bossart SND_SOC_DAILINK_DEF(ssp0_port, 3004865bde1SPierre-Louis Bossart DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port"))); 3014865bde1SPierre-Louis Bossart #else 3024865bde1SPierre-Louis Bossart SND_SOC_DAILINK_DEF(ssp0_port, 3034865bde1SPierre-Louis Bossart DAILINK_COMP_ARRAY(COMP_DUMMY())); 3044865bde1SPierre-Louis Bossart #endif 3054865bde1SPierre-Louis Bossart 306157b006fSBen Zhang /* Wake on voice interface */ 307157b006fSBen Zhang SND_SOC_DAILINK_DEFS(dsp, 308157b006fSBen Zhang DAILINK_COMP_ARRAY(COMP_CPU("spi-RT5677AA:00")), 309157b006fSBen Zhang DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RT5677CE:00", "rt5677-dspbuffer")), 310157b006fSBen Zhang DAILINK_COMP_ARRAY(COMP_PLATFORM("spi-RT5677AA:00"))); 311157b006fSBen Zhang 3122d995e5dSJohn Keeping static struct snd_soc_dai_link bdw_rt5677_dais[] = { 3132d995e5dSJohn Keeping /* Front End DAI links */ 3142d995e5dSJohn Keeping { 3152d995e5dSJohn Keeping .name = "System PCM", 3162d995e5dSJohn Keeping .stream_name = "System Playback/Capture", 3172d995e5dSJohn Keeping .dynamic = 1, 318f35bf70fSLiam Girdwood #if !IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL) 3192d995e5dSJohn Keeping .init = bdw_rt5677_rtd_init, 320f35bf70fSLiam Girdwood #endif 3212d995e5dSJohn Keeping .trigger = { 3222d995e5dSJohn Keeping SND_SOC_DPCM_TRIGGER_POST, 3232d995e5dSJohn Keeping SND_SOC_DPCM_TRIGGER_POST 3242d995e5dSJohn Keeping }, 3252d995e5dSJohn Keeping .dpcm_capture = 1, 3262d995e5dSJohn Keeping .dpcm_playback = 1, 3273f6c2a2eSKuninori Morimoto SND_SOC_DAILINK_REG(fe, dummy, platform), 3282d995e5dSJohn Keeping }, 3292d995e5dSJohn Keeping 330157b006fSBen Zhang /* Non-DPCM links */ 331157b006fSBen Zhang { 332157b006fSBen Zhang .name = "Codec DSP", 333157b006fSBen Zhang .stream_name = "Wake on Voice", 334ba0b3a97SCurtis Malainey .ops = &bdw_rt5677_dsp_ops, 335157b006fSBen Zhang SND_SOC_DAILINK_REG(dsp), 336157b006fSBen Zhang }, 337157b006fSBen Zhang 3382d995e5dSJohn Keeping /* Back End DAI links */ 3392d995e5dSJohn Keeping { 3402d995e5dSJohn Keeping /* SSP0 - Codec */ 3412d995e5dSJohn Keeping .name = "Codec", 3422d995e5dSJohn Keeping .id = 0, 3432d995e5dSJohn Keeping .no_pcm = 1, 3442d995e5dSJohn Keeping .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 3452d995e5dSJohn Keeping SND_SOC_DAIFMT_CBS_CFS, 3462d995e5dSJohn Keeping .ignore_suspend = 1, 3472d995e5dSJohn Keeping .ignore_pmdown_time = 1, 3482d995e5dSJohn Keeping .be_hw_params_fixup = broadwell_ssp0_fixup, 3492d995e5dSJohn Keeping .ops = &bdw_rt5677_ops, 3502d995e5dSJohn Keeping .dpcm_playback = 1, 3512d995e5dSJohn Keeping .dpcm_capture = 1, 3522d995e5dSJohn Keeping .init = bdw_rt5677_init, 3534865bde1SPierre-Louis Bossart SND_SOC_DAILINK_REG(ssp0_port, be, platform), 3542d995e5dSJohn Keeping }, 3552d995e5dSJohn Keeping }; 3562d995e5dSJohn Keeping 3572d995e5dSJohn Keeping static int bdw_rt5677_suspend_pre(struct snd_soc_card *card) 3582d995e5dSJohn Keeping { 3592d995e5dSJohn Keeping struct bdw_rt5677_priv *bdw_rt5677 = snd_soc_card_get_drvdata(card); 3602d995e5dSJohn Keeping struct snd_soc_dapm_context *dapm; 3612d995e5dSJohn Keeping 36279223bf1SKuninori Morimoto if (bdw_rt5677->component) { 36379223bf1SKuninori Morimoto dapm = snd_soc_component_get_dapm(bdw_rt5677->component); 3642d995e5dSJohn Keeping snd_soc_dapm_disable_pin(dapm, "MICBIAS1"); 3652d995e5dSJohn Keeping } 3662d995e5dSJohn Keeping return 0; 3672d995e5dSJohn Keeping } 3682d995e5dSJohn Keeping 3692d995e5dSJohn Keeping static int bdw_rt5677_resume_post(struct snd_soc_card *card) 3702d995e5dSJohn Keeping { 3712d995e5dSJohn Keeping struct bdw_rt5677_priv *bdw_rt5677 = snd_soc_card_get_drvdata(card); 3722d995e5dSJohn Keeping struct snd_soc_dapm_context *dapm; 3732d995e5dSJohn Keeping 37479223bf1SKuninori Morimoto if (bdw_rt5677->component) { 37579223bf1SKuninori Morimoto dapm = snd_soc_component_get_dapm(bdw_rt5677->component); 3762d995e5dSJohn Keeping snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); 3772d995e5dSJohn Keeping } 3782d995e5dSJohn Keeping return 0; 3792d995e5dSJohn Keeping } 3802d995e5dSJohn Keeping 3812d995e5dSJohn Keeping /* ASoC machine driver for Broadwell DSP + RT5677 */ 3822d995e5dSJohn Keeping static struct snd_soc_card bdw_rt5677_card = { 3832d995e5dSJohn Keeping .name = "bdw-rt5677", 3842d995e5dSJohn Keeping .owner = THIS_MODULE, 3852d995e5dSJohn Keeping .dai_link = bdw_rt5677_dais, 3862d995e5dSJohn Keeping .num_links = ARRAY_SIZE(bdw_rt5677_dais), 3872d995e5dSJohn Keeping .dapm_widgets = bdw_rt5677_widgets, 3882d995e5dSJohn Keeping .num_dapm_widgets = ARRAY_SIZE(bdw_rt5677_widgets), 3892d995e5dSJohn Keeping .dapm_routes = bdw_rt5677_map, 3902d995e5dSJohn Keeping .num_dapm_routes = ARRAY_SIZE(bdw_rt5677_map), 3912d995e5dSJohn Keeping .controls = bdw_rt5677_controls, 3922d995e5dSJohn Keeping .num_controls = ARRAY_SIZE(bdw_rt5677_controls), 3932d995e5dSJohn Keeping .fully_routed = true, 3942d995e5dSJohn Keeping .suspend_pre = bdw_rt5677_suspend_pre, 3952d995e5dSJohn Keeping .resume_post = bdw_rt5677_resume_post, 3962d995e5dSJohn Keeping }; 3972d995e5dSJohn Keeping 3982d995e5dSJohn Keeping static int bdw_rt5677_probe(struct platform_device *pdev) 3992d995e5dSJohn Keeping { 4002d995e5dSJohn Keeping struct bdw_rt5677_priv *bdw_rt5677; 4017e40ddcfSPierre-Louis Bossart struct snd_soc_acpi_mach *mach; 4027e40ddcfSPierre-Louis Bossart int ret; 4032d995e5dSJohn Keeping 4042d995e5dSJohn Keeping bdw_rt5677_card.dev = &pdev->dev; 4052d995e5dSJohn Keeping 4062d995e5dSJohn Keeping /* Allocate driver private struct */ 4072d995e5dSJohn Keeping bdw_rt5677 = devm_kzalloc(&pdev->dev, sizeof(struct bdw_rt5677_priv), 4082d995e5dSJohn Keeping GFP_KERNEL); 4092d995e5dSJohn Keeping if (!bdw_rt5677) { 4102d995e5dSJohn Keeping dev_err(&pdev->dev, "Can't allocate bdw_rt5677\n"); 4112d995e5dSJohn Keeping return -ENOMEM; 4122d995e5dSJohn Keeping } 4132d995e5dSJohn Keeping 4147e40ddcfSPierre-Louis Bossart /* override plaform name, if required */ 415*42432196SGuennadi Liakhovetski mach = pdev->dev.platform_data; 4167e40ddcfSPierre-Louis Bossart ret = snd_soc_fixup_dai_links_platform_name(&bdw_rt5677_card, 417c25e93bbSCezary Rojewski mach->mach_params.platform); 4187e40ddcfSPierre-Louis Bossart if (ret) 4197e40ddcfSPierre-Louis Bossart return ret; 4207e40ddcfSPierre-Louis Bossart 4212d995e5dSJohn Keeping snd_soc_card_set_drvdata(&bdw_rt5677_card, bdw_rt5677); 4222d995e5dSJohn Keeping 4232d995e5dSJohn Keeping return devm_snd_soc_register_card(&pdev->dev, &bdw_rt5677_card); 4242d995e5dSJohn Keeping } 4252d995e5dSJohn Keeping 4262d995e5dSJohn Keeping static struct platform_driver bdw_rt5677_audio = { 4272d995e5dSJohn Keeping .probe = bdw_rt5677_probe, 4282d995e5dSJohn Keeping .driver = { 4292d995e5dSJohn Keeping .name = "bdw-rt5677", 4302d995e5dSJohn Keeping }, 4312d995e5dSJohn Keeping }; 4322d995e5dSJohn Keeping 4332d995e5dSJohn Keeping module_platform_driver(bdw_rt5677_audio) 4342d995e5dSJohn Keeping 4352d995e5dSJohn Keeping /* Module information */ 4362d995e5dSJohn Keeping MODULE_AUTHOR("Ben Zhang"); 4372d995e5dSJohn Keeping MODULE_DESCRIPTION("Intel Broadwell RT5677 machine driver"); 4382d995e5dSJohn Keeping MODULE_LICENSE("GPL v2"); 4392d995e5dSJohn Keeping MODULE_ALIAS("platform:bdw-rt5677"); 440