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 "../../codecs/rt5677.h" 212d995e5dSJohn Keeping 222d995e5dSJohn Keeping struct bdw_rt5677_priv { 232d995e5dSJohn Keeping struct gpio_desc *gpio_hp_en; 2479223bf1SKuninori Morimoto struct snd_soc_component *component; 252d995e5dSJohn Keeping }; 262d995e5dSJohn Keeping 272d995e5dSJohn Keeping static int bdw_rt5677_event_hp(struct snd_soc_dapm_widget *w, 282d995e5dSJohn Keeping struct snd_kcontrol *k, int event) 292d995e5dSJohn Keeping { 302d995e5dSJohn Keeping struct snd_soc_dapm_context *dapm = w->dapm; 312d995e5dSJohn Keeping struct snd_soc_card *card = dapm->card; 322d995e5dSJohn Keeping struct bdw_rt5677_priv *bdw_rt5677 = snd_soc_card_get_drvdata(card); 332d995e5dSJohn Keeping 342d995e5dSJohn Keeping if (SND_SOC_DAPM_EVENT_ON(event)) 352d995e5dSJohn Keeping msleep(70); 362d995e5dSJohn Keeping 372d995e5dSJohn Keeping gpiod_set_value_cansleep(bdw_rt5677->gpio_hp_en, 382d995e5dSJohn Keeping SND_SOC_DAPM_EVENT_ON(event)); 392d995e5dSJohn Keeping 402d995e5dSJohn Keeping return 0; 412d995e5dSJohn Keeping } 422d995e5dSJohn Keeping 432d995e5dSJohn Keeping static const struct snd_soc_dapm_widget bdw_rt5677_widgets[] = { 442d995e5dSJohn Keeping SND_SOC_DAPM_HP("Headphone", bdw_rt5677_event_hp), 452d995e5dSJohn Keeping SND_SOC_DAPM_SPK("Speaker", NULL), 462d995e5dSJohn Keeping SND_SOC_DAPM_MIC("Headset Mic", NULL), 472d995e5dSJohn Keeping SND_SOC_DAPM_MIC("Local DMICs", NULL), 482d995e5dSJohn Keeping SND_SOC_DAPM_MIC("Remote DMICs", NULL), 492d995e5dSJohn Keeping }; 502d995e5dSJohn Keeping 512d995e5dSJohn Keeping static const struct snd_soc_dapm_route bdw_rt5677_map[] = { 522d995e5dSJohn Keeping /* Speakers */ 532d995e5dSJohn Keeping {"Speaker", NULL, "PDM1L"}, 542d995e5dSJohn Keeping {"Speaker", NULL, "PDM1R"}, 552d995e5dSJohn Keeping 562d995e5dSJohn Keeping /* Headset jack connectors */ 572d995e5dSJohn Keeping {"Headphone", NULL, "LOUT1"}, 582d995e5dSJohn Keeping {"Headphone", NULL, "LOUT2"}, 592d995e5dSJohn Keeping {"IN1P", NULL, "Headset Mic"}, 602d995e5dSJohn Keeping {"IN1N", NULL, "Headset Mic"}, 612d995e5dSJohn Keeping 622d995e5dSJohn Keeping /* Digital MICs 632d995e5dSJohn Keeping * Local DMICs: the two DMICs on the mainboard 642d995e5dSJohn Keeping * Remote DMICs: the two DMICs on the camera module 652d995e5dSJohn Keeping */ 662d995e5dSJohn Keeping {"DMIC L1", NULL, "Remote DMICs"}, 672d995e5dSJohn Keeping {"DMIC R1", NULL, "Remote DMICs"}, 682d995e5dSJohn Keeping {"DMIC L2", NULL, "Local DMICs"}, 692d995e5dSJohn Keeping {"DMIC R2", NULL, "Local DMICs"}, 702d995e5dSJohn Keeping 712d995e5dSJohn Keeping /* CODEC BE connections */ 722d995e5dSJohn Keeping {"SSP0 CODEC IN", NULL, "AIF1 Capture"}, 732d995e5dSJohn Keeping {"AIF1 Playback", NULL, "SSP0 CODEC OUT"}, 74157b006fSBen Zhang {"DSP Capture", NULL, "DSP Buffer"}, 7555229597SCurtis Malainey 7655229597SCurtis Malainey /* DSP Clock Connections */ 7755229597SCurtis Malainey { "DSP Buffer", NULL, "SSP0 CODEC IN" }, 7855229597SCurtis Malainey { "SSP0 CODEC IN", NULL, "DSPTX" }, 792d995e5dSJohn Keeping }; 802d995e5dSJohn Keeping 812d995e5dSJohn Keeping static const struct snd_kcontrol_new bdw_rt5677_controls[] = { 822d995e5dSJohn Keeping SOC_DAPM_PIN_SWITCH("Speaker"), 832d995e5dSJohn Keeping SOC_DAPM_PIN_SWITCH("Headphone"), 842d995e5dSJohn Keeping SOC_DAPM_PIN_SWITCH("Headset Mic"), 852d995e5dSJohn Keeping SOC_DAPM_PIN_SWITCH("Local DMICs"), 862d995e5dSJohn Keeping SOC_DAPM_PIN_SWITCH("Remote DMICs"), 872d995e5dSJohn Keeping }; 882d995e5dSJohn Keeping 892d995e5dSJohn Keeping 902d995e5dSJohn Keeping static struct snd_soc_jack headphone_jack; 912d995e5dSJohn Keeping static struct snd_soc_jack mic_jack; 922d995e5dSJohn Keeping 932d995e5dSJohn Keeping static struct snd_soc_jack_pin headphone_jack_pin = { 942d995e5dSJohn Keeping .pin = "Headphone", 952d995e5dSJohn Keeping .mask = SND_JACK_HEADPHONE, 962d995e5dSJohn Keeping }; 972d995e5dSJohn Keeping 982d995e5dSJohn Keeping static struct snd_soc_jack_pin mic_jack_pin = { 992d995e5dSJohn Keeping .pin = "Headset Mic", 1002d995e5dSJohn Keeping .mask = SND_JACK_MICROPHONE, 1012d995e5dSJohn Keeping }; 1022d995e5dSJohn Keeping 1032d995e5dSJohn Keeping static struct snd_soc_jack_gpio headphone_jack_gpio = { 1042d995e5dSJohn Keeping .name = "plug-det", 1052d995e5dSJohn Keeping .report = SND_JACK_HEADPHONE, 1062d995e5dSJohn Keeping .debounce_time = 200, 1072d995e5dSJohn Keeping }; 1082d995e5dSJohn Keeping 1092d995e5dSJohn Keeping static struct snd_soc_jack_gpio mic_jack_gpio = { 1102d995e5dSJohn Keeping .name = "mic-present", 1112d995e5dSJohn Keeping .report = SND_JACK_MICROPHONE, 1122d995e5dSJohn Keeping .debounce_time = 200, 1132d995e5dSJohn Keeping .invert = 1, 1142d995e5dSJohn Keeping }; 1152d995e5dSJohn Keeping 11655e59aa0SAndy Shevchenko /* GPIO indexes defined by ACPI */ 11755e59aa0SAndy Shevchenko enum { 11855e59aa0SAndy Shevchenko RT5677_GPIO_PLUG_DET = 0, 11955e59aa0SAndy Shevchenko RT5677_GPIO_MIC_PRESENT_L = 1, 12055e59aa0SAndy Shevchenko RT5677_GPIO_HOTWORD_DET_L = 2, 12155e59aa0SAndy Shevchenko RT5677_GPIO_DSP_INT = 3, 12255e59aa0SAndy Shevchenko RT5677_GPIO_HP_AMP_SHDN_L = 4, 12355e59aa0SAndy Shevchenko }; 12455e59aa0SAndy Shevchenko 12555e59aa0SAndy Shevchenko static const struct acpi_gpio_params plug_det_gpio = { RT5677_GPIO_PLUG_DET, 0, false }; 12655e59aa0SAndy Shevchenko static const struct acpi_gpio_params mic_present_gpio = { RT5677_GPIO_MIC_PRESENT_L, 0, false }; 12755e59aa0SAndy Shevchenko static const struct acpi_gpio_params headphone_enable_gpio = { RT5677_GPIO_HP_AMP_SHDN_L, 0, false }; 12855e59aa0SAndy Shevchenko 12955e59aa0SAndy Shevchenko static const struct acpi_gpio_mapping bdw_rt5677_gpios[] = { 13055e59aa0SAndy Shevchenko { "plug-det-gpios", &plug_det_gpio, 1 }, 13155e59aa0SAndy Shevchenko { "mic-present-gpios", &mic_present_gpio, 1 }, 13255e59aa0SAndy Shevchenko { "headphone-enable-gpios", &headphone_enable_gpio, 1 }, 13355e59aa0SAndy Shevchenko { NULL }, 13455e59aa0SAndy Shevchenko }; 13555e59aa0SAndy Shevchenko 1362d995e5dSJohn Keeping static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd, 1372d995e5dSJohn Keeping struct snd_pcm_hw_params *params) 1382d995e5dSJohn Keeping { 1392d995e5dSJohn Keeping struct snd_interval *rate = hw_param_interval(params, 1402d995e5dSJohn Keeping SNDRV_PCM_HW_PARAM_RATE); 1411e644427SPierre-Louis Bossart struct snd_interval *chan = hw_param_interval(params, 1422d995e5dSJohn Keeping SNDRV_PCM_HW_PARAM_CHANNELS); 1432d995e5dSJohn Keeping 1442d995e5dSJohn Keeping /* The ADSP will covert the FE rate to 48k, stereo */ 1452d995e5dSJohn Keeping rate->min = rate->max = 48000; 1461e644427SPierre-Louis Bossart chan->min = chan->max = 2; 1472d995e5dSJohn Keeping 1482d995e5dSJohn Keeping /* set SSP0 to 16 bit */ 149b5453e8cSTakashi Iwai params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); 1502d995e5dSJohn Keeping return 0; 1512d995e5dSJohn Keeping } 1522d995e5dSJohn Keeping 1532d995e5dSJohn Keeping static int bdw_rt5677_hw_params(struct snd_pcm_substream *substream, 1542d995e5dSJohn Keeping struct snd_pcm_hw_params *params) 1552d995e5dSJohn Keeping { 1562207b93bSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 1570d1571c1SKuninori Morimoto struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 1582d995e5dSJohn Keeping int ret; 1592d995e5dSJohn Keeping 1602d995e5dSJohn Keeping ret = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_MCLK, 24576000, 1612d995e5dSJohn Keeping SND_SOC_CLOCK_IN); 1622d995e5dSJohn Keeping if (ret < 0) { 1632d995e5dSJohn Keeping dev_err(rtd->dev, "can't set codec sysclk configuration\n"); 1642d995e5dSJohn Keeping return ret; 1652d995e5dSJohn Keeping } 1662d995e5dSJohn Keeping 1672d995e5dSJohn Keeping return ret; 1682d995e5dSJohn Keeping } 1692d995e5dSJohn Keeping 170ba0b3a97SCurtis Malainey static int bdw_rt5677_dsp_hw_params(struct snd_pcm_substream *substream, 171ba0b3a97SCurtis Malainey struct snd_pcm_hw_params *params) 172ba0b3a97SCurtis Malainey { 1732207b93bSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 1740d1571c1SKuninori Morimoto struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 175ba0b3a97SCurtis Malainey int ret; 176ba0b3a97SCurtis Malainey 177ba0b3a97SCurtis Malainey ret = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_PLL1, 24576000, 178ba0b3a97SCurtis Malainey SND_SOC_CLOCK_IN); 179ba0b3a97SCurtis Malainey if (ret < 0) { 180ba0b3a97SCurtis Malainey dev_err(rtd->dev, "can't set codec sysclk configuration\n"); 181ba0b3a97SCurtis Malainey return ret; 182ba0b3a97SCurtis Malainey } 183ba0b3a97SCurtis Malainey ret = snd_soc_dai_set_pll(codec_dai, 0, RT5677_PLL1_S_MCLK, 184ba0b3a97SCurtis Malainey 24000000, 24576000); 185ba0b3a97SCurtis Malainey if (ret < 0) { 186ba0b3a97SCurtis Malainey dev_err(rtd->dev, "can't set codec pll configuration\n"); 187ba0b3a97SCurtis Malainey return ret; 188ba0b3a97SCurtis Malainey } 189ba0b3a97SCurtis Malainey 190ba0b3a97SCurtis Malainey return 0; 191ba0b3a97SCurtis Malainey } 192ba0b3a97SCurtis Malainey 1939b6fdef6SJulia Lawall static const struct snd_soc_ops bdw_rt5677_ops = { 1942d995e5dSJohn Keeping .hw_params = bdw_rt5677_hw_params, 1952d995e5dSJohn Keeping }; 1962d995e5dSJohn Keeping 197ba0b3a97SCurtis Malainey static const struct snd_soc_ops bdw_rt5677_dsp_ops = { 198ba0b3a97SCurtis Malainey .hw_params = bdw_rt5677_dsp_hw_params, 199ba0b3a97SCurtis Malainey }; 200ba0b3a97SCurtis Malainey 201e241f8e7SBrent Lu static const unsigned int channels[] = { 202e241f8e7SBrent Lu 2, 203e241f8e7SBrent Lu }; 204e241f8e7SBrent Lu 205e241f8e7SBrent Lu static const struct snd_pcm_hw_constraint_list constraints_channels = { 206e241f8e7SBrent Lu .count = ARRAY_SIZE(channels), 207e241f8e7SBrent Lu .list = channels, 208e241f8e7SBrent Lu .mask = 0, 209e241f8e7SBrent Lu }; 210e241f8e7SBrent Lu 211e241f8e7SBrent Lu static int bdw_rt5677_fe_startup(struct snd_pcm_substream *substream) 212e241f8e7SBrent Lu { 213e241f8e7SBrent Lu struct snd_pcm_runtime *runtime = substream->runtime; 214e241f8e7SBrent Lu 215e241f8e7SBrent Lu /* Board supports stereo configuration only */ 216e241f8e7SBrent Lu runtime->hw.channels_max = 2; 217e241f8e7SBrent Lu return snd_pcm_hw_constraint_list(runtime, 0, 218e241f8e7SBrent Lu SNDRV_PCM_HW_PARAM_CHANNELS, 219e241f8e7SBrent Lu &constraints_channels); 220e241f8e7SBrent Lu } 221e241f8e7SBrent Lu 222e241f8e7SBrent Lu static const struct snd_soc_ops bdw_rt5677_fe_ops = { 223e241f8e7SBrent Lu .startup = bdw_rt5677_fe_startup, 224e241f8e7SBrent Lu }; 225e241f8e7SBrent Lu 2262d995e5dSJohn Keeping static int bdw_rt5677_init(struct snd_soc_pcm_runtime *rtd) 2272d995e5dSJohn Keeping { 2282d995e5dSJohn Keeping struct bdw_rt5677_priv *bdw_rt5677 = 2292d995e5dSJohn Keeping snd_soc_card_get_drvdata(rtd->card); 2300d1571c1SKuninori Morimoto struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component; 23179223bf1SKuninori Morimoto struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 23255e59aa0SAndy Shevchenko int ret; 23355e59aa0SAndy Shevchenko 23479223bf1SKuninori Morimoto ret = devm_acpi_dev_add_driver_gpios(component->dev, bdw_rt5677_gpios); 23555e59aa0SAndy Shevchenko if (ret) 23679223bf1SKuninori Morimoto dev_warn(component->dev, "Failed to add driver gpios\n"); 2372d995e5dSJohn Keeping 2382d995e5dSJohn Keeping /* Enable codec ASRC function for Stereo DAC/Stereo1 ADC/DMIC/I2S1. 2392d995e5dSJohn Keeping * The ASRC clock source is clk_i2s1_asrc. 2402d995e5dSJohn Keeping */ 24179223bf1SKuninori Morimoto rt5677_sel_asrc_clk_src(component, RT5677_DA_STEREO_FILTER | 2422d995e5dSJohn Keeping RT5677_AD_STEREO1_FILTER | RT5677_I2S1_SOURCE, 2432d995e5dSJohn Keeping RT5677_CLK_SEL_I2S1_ASRC); 244ba0b3a97SCurtis Malainey /* Enable codec ASRC function for Mono ADC L. 245ba0b3a97SCurtis Malainey * The ASRC clock source is clk_sys2_asrc. 246ba0b3a97SCurtis Malainey */ 247ba0b3a97SCurtis Malainey rt5677_sel_asrc_clk_src(component, RT5677_AD_MONO_L_FILTER, 248ba0b3a97SCurtis Malainey RT5677_CLK_SEL_SYS2); 2492d995e5dSJohn Keeping 2502d995e5dSJohn Keeping /* Request rt5677 GPIO for headphone amp control */ 251bcb43fdaSPierre-Louis Bossart bdw_rt5677->gpio_hp_en = gpiod_get(component->dev, "headphone-enable", 252b3ec72acSAndy Shevchenko GPIOD_OUT_LOW); 2532d995e5dSJohn Keeping if (IS_ERR(bdw_rt5677->gpio_hp_en)) { 25479223bf1SKuninori Morimoto dev_err(component->dev, "Can't find HP_AMP_SHDN_L gpio\n"); 2552d995e5dSJohn Keeping return PTR_ERR(bdw_rt5677->gpio_hp_en); 2562d995e5dSJohn Keeping } 2572d995e5dSJohn Keeping 2582d995e5dSJohn Keeping /* Create and initialize headphone jack */ 25919aed2d6SAkihiko Odaki if (!snd_soc_card_jack_new_pins(rtd->card, "Headphone Jack", 2602d995e5dSJohn Keeping SND_JACK_HEADPHONE, &headphone_jack, 2612d995e5dSJohn Keeping &headphone_jack_pin, 1)) { 26279223bf1SKuninori Morimoto headphone_jack_gpio.gpiod_dev = component->dev; 2632d995e5dSJohn Keeping if (snd_soc_jack_add_gpios(&headphone_jack, 1, 2642d995e5dSJohn Keeping &headphone_jack_gpio)) 26579223bf1SKuninori Morimoto dev_err(component->dev, "Can't add headphone jack gpio\n"); 2662d995e5dSJohn Keeping } else { 26779223bf1SKuninori Morimoto dev_err(component->dev, "Can't create headphone jack\n"); 2682d995e5dSJohn Keeping } 2692d995e5dSJohn Keeping 2702d995e5dSJohn Keeping /* Create and initialize mic jack */ 27119aed2d6SAkihiko Odaki if (!snd_soc_card_jack_new_pins(rtd->card, "Mic Jack", 2722d995e5dSJohn Keeping SND_JACK_MICROPHONE, &mic_jack, 2732d995e5dSJohn Keeping &mic_jack_pin, 1)) { 27479223bf1SKuninori Morimoto mic_jack_gpio.gpiod_dev = component->dev; 2752d995e5dSJohn Keeping if (snd_soc_jack_add_gpios(&mic_jack, 1, &mic_jack_gpio)) 27679223bf1SKuninori Morimoto dev_err(component->dev, "Can't add mic jack gpio\n"); 2772d995e5dSJohn Keeping } else { 27879223bf1SKuninori Morimoto dev_err(component->dev, "Can't create mic jack\n"); 2792d995e5dSJohn Keeping } 28079223bf1SKuninori Morimoto bdw_rt5677->component = component; 2812d995e5dSJohn Keeping 2822d995e5dSJohn Keeping snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); 2832d995e5dSJohn Keeping return 0; 2842d995e5dSJohn Keeping } 2852d995e5dSJohn Keeping 286bcb43fdaSPierre-Louis Bossart static void bdw_rt5677_exit(struct snd_soc_pcm_runtime *rtd) 287bcb43fdaSPierre-Louis Bossart { 288bcb43fdaSPierre-Louis Bossart struct bdw_rt5677_priv *bdw_rt5677 = 289bcb43fdaSPierre-Louis Bossart snd_soc_card_get_drvdata(rtd->card); 290bcb43fdaSPierre-Louis Bossart 291bcb43fdaSPierre-Louis Bossart /* 292bcb43fdaSPierre-Louis Bossart * The .exit() can be reached without going through the .init() 293bcb43fdaSPierre-Louis Bossart * so explicitly test if the gpiod is valid 294bcb43fdaSPierre-Louis Bossart */ 295bcb43fdaSPierre-Louis Bossart if (!IS_ERR_OR_NULL(bdw_rt5677->gpio_hp_en)) 296bcb43fdaSPierre-Louis Bossart gpiod_put(bdw_rt5677->gpio_hp_en); 297bcb43fdaSPierre-Louis Bossart } 298bcb43fdaSPierre-Louis Bossart 2992d995e5dSJohn Keeping /* broadwell digital audio interface glue - connects codec <--> CPU */ 3003f6c2a2eSKuninori Morimoto SND_SOC_DAILINK_DEF(dummy, 3013f6c2a2eSKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY())); 3023f6c2a2eSKuninori Morimoto 3033f6c2a2eSKuninori Morimoto SND_SOC_DAILINK_DEF(fe, 3043f6c2a2eSKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("System Pin"))); 3053f6c2a2eSKuninori Morimoto 3063f6c2a2eSKuninori Morimoto SND_SOC_DAILINK_DEF(platform, 3073f6c2a2eSKuninori Morimoto DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio"))); 3083f6c2a2eSKuninori Morimoto 3093f6c2a2eSKuninori Morimoto SND_SOC_DAILINK_DEF(be, 3103f6c2a2eSKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RT5677CE:00", "rt5677-aif1"))); 3113f6c2a2eSKuninori Morimoto 3124865bde1SPierre-Louis Bossart SND_SOC_DAILINK_DEF(ssp0_port, 3134865bde1SPierre-Louis Bossart DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port"))); 3144865bde1SPierre-Louis Bossart 315157b006fSBen Zhang /* Wake on voice interface */ 316157b006fSBen Zhang SND_SOC_DAILINK_DEFS(dsp, 317157b006fSBen Zhang DAILINK_COMP_ARRAY(COMP_CPU("spi-RT5677AA:00")), 318157b006fSBen Zhang DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RT5677CE:00", "rt5677-dspbuffer")), 319157b006fSBen Zhang DAILINK_COMP_ARRAY(COMP_PLATFORM("spi-RT5677AA:00"))); 320157b006fSBen Zhang 3212d995e5dSJohn Keeping static struct snd_soc_dai_link bdw_rt5677_dais[] = { 3222d995e5dSJohn Keeping /* Front End DAI links */ 3232d995e5dSJohn Keeping { 3242d995e5dSJohn Keeping .name = "System PCM", 3252d995e5dSJohn Keeping .stream_name = "System Playback/Capture", 326fc5c8729SCezary Rojewski .nonatomic = 1, 3272d995e5dSJohn Keeping .dynamic = 1, 3282d995e5dSJohn Keeping .trigger = { 3292d995e5dSJohn Keeping SND_SOC_DPCM_TRIGGER_POST, 3302d995e5dSJohn Keeping SND_SOC_DPCM_TRIGGER_POST 3312d995e5dSJohn Keeping }, 3322d995e5dSJohn Keeping .dpcm_capture = 1, 3332d995e5dSJohn Keeping .dpcm_playback = 1, 334e241f8e7SBrent Lu .ops = &bdw_rt5677_fe_ops, 3353f6c2a2eSKuninori Morimoto SND_SOC_DAILINK_REG(fe, dummy, platform), 3362d995e5dSJohn Keeping }, 3372d995e5dSJohn Keeping 338157b006fSBen Zhang /* Non-DPCM links */ 339157b006fSBen Zhang { 340157b006fSBen Zhang .name = "Codec DSP", 341157b006fSBen Zhang .stream_name = "Wake on Voice", 342fffebe8aSPierre-Louis Bossart .capture_only = 1, 343ba0b3a97SCurtis Malainey .ops = &bdw_rt5677_dsp_ops, 344157b006fSBen Zhang SND_SOC_DAILINK_REG(dsp), 345157b006fSBen Zhang }, 346157b006fSBen Zhang 3472d995e5dSJohn Keeping /* Back End DAI links */ 3482d995e5dSJohn Keeping { 3492d995e5dSJohn Keeping /* SSP0 - Codec */ 3502d995e5dSJohn Keeping .name = "Codec", 3512d995e5dSJohn Keeping .id = 0, 352*bdd15ec4SCezary Rojewski .nonatomic = 1, 3532d995e5dSJohn Keeping .no_pcm = 1, 3542d995e5dSJohn Keeping .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 3555374b921SPeter Ujfalusi SND_SOC_DAIFMT_CBC_CFC, 3562d995e5dSJohn Keeping .ignore_pmdown_time = 1, 3572d995e5dSJohn Keeping .be_hw_params_fixup = broadwell_ssp0_fixup, 3582d995e5dSJohn Keeping .ops = &bdw_rt5677_ops, 3592d995e5dSJohn Keeping .dpcm_playback = 1, 3602d995e5dSJohn Keeping .dpcm_capture = 1, 3612d995e5dSJohn Keeping .init = bdw_rt5677_init, 362bcb43fdaSPierre-Louis Bossart .exit = bdw_rt5677_exit, 3634865bde1SPierre-Louis Bossart SND_SOC_DAILINK_REG(ssp0_port, be, platform), 3642d995e5dSJohn Keeping }, 3652d995e5dSJohn Keeping }; 3662d995e5dSJohn Keeping 3672d995e5dSJohn Keeping static int bdw_rt5677_suspend_pre(struct snd_soc_card *card) 3682d995e5dSJohn Keeping { 3692d995e5dSJohn Keeping struct bdw_rt5677_priv *bdw_rt5677 = snd_soc_card_get_drvdata(card); 3702d995e5dSJohn Keeping struct snd_soc_dapm_context *dapm; 3712d995e5dSJohn Keeping 37279223bf1SKuninori Morimoto if (bdw_rt5677->component) { 37379223bf1SKuninori Morimoto dapm = snd_soc_component_get_dapm(bdw_rt5677->component); 3742d995e5dSJohn Keeping snd_soc_dapm_disable_pin(dapm, "MICBIAS1"); 3752d995e5dSJohn Keeping } 3762d995e5dSJohn Keeping return 0; 3772d995e5dSJohn Keeping } 3782d995e5dSJohn Keeping 3792d995e5dSJohn Keeping static int bdw_rt5677_resume_post(struct snd_soc_card *card) 3802d995e5dSJohn Keeping { 3812d995e5dSJohn Keeping struct bdw_rt5677_priv *bdw_rt5677 = snd_soc_card_get_drvdata(card); 3822d995e5dSJohn Keeping struct snd_soc_dapm_context *dapm; 3832d995e5dSJohn Keeping 38479223bf1SKuninori Morimoto if (bdw_rt5677->component) { 38579223bf1SKuninori Morimoto dapm = snd_soc_component_get_dapm(bdw_rt5677->component); 3862d995e5dSJohn Keeping snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); 3872d995e5dSJohn Keeping } 3882d995e5dSJohn Keeping return 0; 3892d995e5dSJohn Keeping } 3902d995e5dSJohn Keeping 391a5f610c0SPierre-Louis Bossart /* use space before codec name to simplify card ID, and simplify driver name */ 3928643e85aSPierre-Louis Bossart #define SOF_CARD_NAME "bdw rt5677" /* card name will be 'sof-bdw rt5677' */ 3938643e85aSPierre-Louis Bossart #define SOF_DRIVER_NAME "SOF" 3948643e85aSPierre-Louis Bossart 395a5f610c0SPierre-Louis Bossart #define CARD_NAME "bdw-rt5677" 396a5f610c0SPierre-Louis Bossart #define DRIVER_NAME NULL /* card name will be used for driver name */ 397a5f610c0SPierre-Louis Bossart 3982d995e5dSJohn Keeping /* ASoC machine driver for Broadwell DSP + RT5677 */ 3992d995e5dSJohn Keeping static struct snd_soc_card bdw_rt5677_card = { 400a5f610c0SPierre-Louis Bossart .name = CARD_NAME, 401a5f610c0SPierre-Louis Bossart .driver_name = DRIVER_NAME, 4022d995e5dSJohn Keeping .owner = THIS_MODULE, 4032d995e5dSJohn Keeping .dai_link = bdw_rt5677_dais, 4042d995e5dSJohn Keeping .num_links = ARRAY_SIZE(bdw_rt5677_dais), 4052d995e5dSJohn Keeping .dapm_widgets = bdw_rt5677_widgets, 4062d995e5dSJohn Keeping .num_dapm_widgets = ARRAY_SIZE(bdw_rt5677_widgets), 4072d995e5dSJohn Keeping .dapm_routes = bdw_rt5677_map, 4082d995e5dSJohn Keeping .num_dapm_routes = ARRAY_SIZE(bdw_rt5677_map), 4092d995e5dSJohn Keeping .controls = bdw_rt5677_controls, 4102d995e5dSJohn Keeping .num_controls = ARRAY_SIZE(bdw_rt5677_controls), 4112d995e5dSJohn Keeping .fully_routed = true, 4122d995e5dSJohn Keeping .suspend_pre = bdw_rt5677_suspend_pre, 4132d995e5dSJohn Keeping .resume_post = bdw_rt5677_resume_post, 4142d995e5dSJohn Keeping }; 4152d995e5dSJohn Keeping 4162d995e5dSJohn Keeping static int bdw_rt5677_probe(struct platform_device *pdev) 4172d995e5dSJohn Keeping { 4182d995e5dSJohn Keeping struct bdw_rt5677_priv *bdw_rt5677; 4197e40ddcfSPierre-Louis Bossart struct snd_soc_acpi_mach *mach; 4207e40ddcfSPierre-Louis Bossart int ret; 4212d995e5dSJohn Keeping 4222d995e5dSJohn Keeping bdw_rt5677_card.dev = &pdev->dev; 4232d995e5dSJohn Keeping 4242d995e5dSJohn Keeping /* Allocate driver private struct */ 4252d995e5dSJohn Keeping bdw_rt5677 = devm_kzalloc(&pdev->dev, sizeof(struct bdw_rt5677_priv), 4262d995e5dSJohn Keeping GFP_KERNEL); 427c5ad09a3SZhen Lei if (!bdw_rt5677) 4282d995e5dSJohn Keeping return -ENOMEM; 4292d995e5dSJohn Keeping 430f1eebb3bSPierre-Louis Bossart /* override platform name, if required */ 43142432196SGuennadi Liakhovetski mach = pdev->dev.platform_data; 4327e40ddcfSPierre-Louis Bossart ret = snd_soc_fixup_dai_links_platform_name(&bdw_rt5677_card, 433c25e93bbSCezary Rojewski mach->mach_params.platform); 4347e40ddcfSPierre-Louis Bossart if (ret) 4357e40ddcfSPierre-Louis Bossart return ret; 4367e40ddcfSPierre-Louis Bossart 4378643e85aSPierre-Louis Bossart /* set card and driver name */ 4388643e85aSPierre-Louis Bossart if (snd_soc_acpi_sof_parent(&pdev->dev)) { 4398643e85aSPierre-Louis Bossart bdw_rt5677_card.name = SOF_CARD_NAME; 4408643e85aSPierre-Louis Bossart bdw_rt5677_card.driver_name = SOF_DRIVER_NAME; 4418643e85aSPierre-Louis Bossart } else { 4428643e85aSPierre-Louis Bossart bdw_rt5677_card.name = CARD_NAME; 4438643e85aSPierre-Louis Bossart bdw_rt5677_card.driver_name = DRIVER_NAME; 4448643e85aSPierre-Louis Bossart } 4458643e85aSPierre-Louis Bossart 4462d995e5dSJohn Keeping snd_soc_card_set_drvdata(&bdw_rt5677_card, bdw_rt5677); 4472d995e5dSJohn Keeping 4482d995e5dSJohn Keeping return devm_snd_soc_register_card(&pdev->dev, &bdw_rt5677_card); 4492d995e5dSJohn Keeping } 4502d995e5dSJohn Keeping 4512d995e5dSJohn Keeping static struct platform_driver bdw_rt5677_audio = { 4522d995e5dSJohn Keeping .probe = bdw_rt5677_probe, 4532d995e5dSJohn Keeping .driver = { 4542d995e5dSJohn Keeping .name = "bdw-rt5677", 455cf7f4a53SPierre-Louis Bossart .pm = &snd_soc_pm_ops 4562d995e5dSJohn Keeping }, 4572d995e5dSJohn Keeping }; 4582d995e5dSJohn Keeping 4592d995e5dSJohn Keeping module_platform_driver(bdw_rt5677_audio) 4602d995e5dSJohn Keeping 4612d995e5dSJohn Keeping /* Module information */ 4622d995e5dSJohn Keeping MODULE_AUTHOR("Ben Zhang"); 4632d995e5dSJohn Keeping MODULE_DESCRIPTION("Intel Broadwell RT5677 machine driver"); 4642d995e5dSJohn Keeping MODULE_LICENSE("GPL v2"); 4652d995e5dSJohn Keeping MODULE_ALIAS("platform:bdw-rt5677"); 466