18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ASoC machine driver for Intel Broadwell platforms with RT5677 codec 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2014, The Chromium OS Authors. All rights reserved. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/acpi.h> 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 118c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h> 128c2ecf20Sopenharmony_ci#include <linux/delay.h> 138c2ecf20Sopenharmony_ci#include <sound/core.h> 148c2ecf20Sopenharmony_ci#include <sound/pcm.h> 158c2ecf20Sopenharmony_ci#include <sound/soc.h> 168c2ecf20Sopenharmony_ci#include <sound/pcm_params.h> 178c2ecf20Sopenharmony_ci#include <sound/jack.h> 188c2ecf20Sopenharmony_ci#include <sound/soc-acpi.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include "../../codecs/rt5677.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistruct bdw_rt5677_priv { 238c2ecf20Sopenharmony_ci struct gpio_desc *gpio_hp_en; 248c2ecf20Sopenharmony_ci struct snd_soc_component *component; 258c2ecf20Sopenharmony_ci}; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic int bdw_rt5677_event_hp(struct snd_soc_dapm_widget *w, 288c2ecf20Sopenharmony_ci struct snd_kcontrol *k, int event) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci struct snd_soc_dapm_context *dapm = w->dapm; 318c2ecf20Sopenharmony_ci struct snd_soc_card *card = dapm->card; 328c2ecf20Sopenharmony_ci struct bdw_rt5677_priv *bdw_rt5677 = snd_soc_card_get_drvdata(card); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci if (SND_SOC_DAPM_EVENT_ON(event)) 358c2ecf20Sopenharmony_ci msleep(70); 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci gpiod_set_value_cansleep(bdw_rt5677->gpio_hp_en, 388c2ecf20Sopenharmony_ci SND_SOC_DAPM_EVENT_ON(event)); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci return 0; 418c2ecf20Sopenharmony_ci} 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget bdw_rt5677_widgets[] = { 448c2ecf20Sopenharmony_ci SND_SOC_DAPM_HP("Headphone", bdw_rt5677_event_hp), 458c2ecf20Sopenharmony_ci SND_SOC_DAPM_SPK("Speaker", NULL), 468c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIC("Headset Mic", NULL), 478c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIC("Local DMICs", NULL), 488c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIC("Remote DMICs", NULL), 498c2ecf20Sopenharmony_ci}; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route bdw_rt5677_map[] = { 528c2ecf20Sopenharmony_ci /* Speakers */ 538c2ecf20Sopenharmony_ci {"Speaker", NULL, "PDM1L"}, 548c2ecf20Sopenharmony_ci {"Speaker", NULL, "PDM1R"}, 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci /* Headset jack connectors */ 578c2ecf20Sopenharmony_ci {"Headphone", NULL, "LOUT1"}, 588c2ecf20Sopenharmony_ci {"Headphone", NULL, "LOUT2"}, 598c2ecf20Sopenharmony_ci {"IN1P", NULL, "Headset Mic"}, 608c2ecf20Sopenharmony_ci {"IN1N", NULL, "Headset Mic"}, 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci /* Digital MICs 638c2ecf20Sopenharmony_ci * Local DMICs: the two DMICs on the mainboard 648c2ecf20Sopenharmony_ci * Remote DMICs: the two DMICs on the camera module 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_ci {"DMIC L1", NULL, "Remote DMICs"}, 678c2ecf20Sopenharmony_ci {"DMIC R1", NULL, "Remote DMICs"}, 688c2ecf20Sopenharmony_ci {"DMIC L2", NULL, "Local DMICs"}, 698c2ecf20Sopenharmony_ci {"DMIC R2", NULL, "Local DMICs"}, 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci /* CODEC BE connections */ 728c2ecf20Sopenharmony_ci {"SSP0 CODEC IN", NULL, "AIF1 Capture"}, 738c2ecf20Sopenharmony_ci {"AIF1 Playback", NULL, "SSP0 CODEC OUT"}, 748c2ecf20Sopenharmony_ci {"DSP Capture", NULL, "DSP Buffer"}, 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci /* DSP Clock Connections */ 778c2ecf20Sopenharmony_ci { "DSP Buffer", NULL, "SSP0 CODEC IN" }, 788c2ecf20Sopenharmony_ci { "SSP0 CODEC IN", NULL, "DSPTX" }, 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new bdw_rt5677_controls[] = { 828c2ecf20Sopenharmony_ci SOC_DAPM_PIN_SWITCH("Speaker"), 838c2ecf20Sopenharmony_ci SOC_DAPM_PIN_SWITCH("Headphone"), 848c2ecf20Sopenharmony_ci SOC_DAPM_PIN_SWITCH("Headset Mic"), 858c2ecf20Sopenharmony_ci SOC_DAPM_PIN_SWITCH("Local DMICs"), 868c2ecf20Sopenharmony_ci SOC_DAPM_PIN_SWITCH("Remote DMICs"), 878c2ecf20Sopenharmony_ci}; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cistatic struct snd_soc_jack headphone_jack; 918c2ecf20Sopenharmony_cistatic struct snd_soc_jack mic_jack; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic struct snd_soc_jack_pin headphone_jack_pin = { 948c2ecf20Sopenharmony_ci .pin = "Headphone", 958c2ecf20Sopenharmony_ci .mask = SND_JACK_HEADPHONE, 968c2ecf20Sopenharmony_ci}; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistatic struct snd_soc_jack_pin mic_jack_pin = { 998c2ecf20Sopenharmony_ci .pin = "Headset Mic", 1008c2ecf20Sopenharmony_ci .mask = SND_JACK_MICROPHONE, 1018c2ecf20Sopenharmony_ci}; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_cistatic struct snd_soc_jack_gpio headphone_jack_gpio = { 1048c2ecf20Sopenharmony_ci .name = "plug-det", 1058c2ecf20Sopenharmony_ci .report = SND_JACK_HEADPHONE, 1068c2ecf20Sopenharmony_ci .debounce_time = 200, 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic struct snd_soc_jack_gpio mic_jack_gpio = { 1108c2ecf20Sopenharmony_ci .name = "mic-present", 1118c2ecf20Sopenharmony_ci .report = SND_JACK_MICROPHONE, 1128c2ecf20Sopenharmony_ci .debounce_time = 200, 1138c2ecf20Sopenharmony_ci .invert = 1, 1148c2ecf20Sopenharmony_ci}; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci/* GPIO indexes defined by ACPI */ 1178c2ecf20Sopenharmony_cienum { 1188c2ecf20Sopenharmony_ci RT5677_GPIO_PLUG_DET = 0, 1198c2ecf20Sopenharmony_ci RT5677_GPIO_MIC_PRESENT_L = 1, 1208c2ecf20Sopenharmony_ci RT5677_GPIO_HOTWORD_DET_L = 2, 1218c2ecf20Sopenharmony_ci RT5677_GPIO_DSP_INT = 3, 1228c2ecf20Sopenharmony_ci RT5677_GPIO_HP_AMP_SHDN_L = 4, 1238c2ecf20Sopenharmony_ci}; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistatic const struct acpi_gpio_params plug_det_gpio = { RT5677_GPIO_PLUG_DET, 0, false }; 1268c2ecf20Sopenharmony_cistatic const struct acpi_gpio_params mic_present_gpio = { RT5677_GPIO_MIC_PRESENT_L, 0, false }; 1278c2ecf20Sopenharmony_cistatic const struct acpi_gpio_params headphone_enable_gpio = { RT5677_GPIO_HP_AMP_SHDN_L, 0, false }; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic const struct acpi_gpio_mapping bdw_rt5677_gpios[] = { 1308c2ecf20Sopenharmony_ci { "plug-det-gpios", &plug_det_gpio, 1 }, 1318c2ecf20Sopenharmony_ci { "mic-present-gpios", &mic_present_gpio, 1 }, 1328c2ecf20Sopenharmony_ci { "headphone-enable-gpios", &headphone_enable_gpio, 1 }, 1338c2ecf20Sopenharmony_ci { NULL }, 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistatic int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd, 1378c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params) 1388c2ecf20Sopenharmony_ci{ 1398c2ecf20Sopenharmony_ci struct snd_interval *rate = hw_param_interval(params, 1408c2ecf20Sopenharmony_ci SNDRV_PCM_HW_PARAM_RATE); 1418c2ecf20Sopenharmony_ci struct snd_interval *chan = hw_param_interval(params, 1428c2ecf20Sopenharmony_ci SNDRV_PCM_HW_PARAM_CHANNELS); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci /* The ADSP will covert the FE rate to 48k, stereo */ 1458c2ecf20Sopenharmony_ci rate->min = rate->max = 48000; 1468c2ecf20Sopenharmony_ci chan->min = chan->max = 2; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci /* set SSP0 to 16 bit */ 1498c2ecf20Sopenharmony_ci params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); 1508c2ecf20Sopenharmony_ci return 0; 1518c2ecf20Sopenharmony_ci} 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cistatic int bdw_rt5677_hw_params(struct snd_pcm_substream *substream, 1548c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 1578c2ecf20Sopenharmony_ci struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 1588c2ecf20Sopenharmony_ci int ret; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci ret = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_MCLK, 24576000, 1618c2ecf20Sopenharmony_ci SND_SOC_CLOCK_IN); 1628c2ecf20Sopenharmony_ci if (ret < 0) { 1638c2ecf20Sopenharmony_ci dev_err(rtd->dev, "can't set codec sysclk configuration\n"); 1648c2ecf20Sopenharmony_ci return ret; 1658c2ecf20Sopenharmony_ci } 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci return ret; 1688c2ecf20Sopenharmony_ci} 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cistatic int bdw_rt5677_dsp_hw_params(struct snd_pcm_substream *substream, 1718c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params) 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 1748c2ecf20Sopenharmony_ci struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 1758c2ecf20Sopenharmony_ci int ret; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci ret = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_PLL1, 24576000, 1788c2ecf20Sopenharmony_ci SND_SOC_CLOCK_IN); 1798c2ecf20Sopenharmony_ci if (ret < 0) { 1808c2ecf20Sopenharmony_ci dev_err(rtd->dev, "can't set codec sysclk configuration\n"); 1818c2ecf20Sopenharmony_ci return ret; 1828c2ecf20Sopenharmony_ci } 1838c2ecf20Sopenharmony_ci ret = snd_soc_dai_set_pll(codec_dai, 0, RT5677_PLL1_S_MCLK, 1848c2ecf20Sopenharmony_ci 24000000, 24576000); 1858c2ecf20Sopenharmony_ci if (ret < 0) { 1868c2ecf20Sopenharmony_ci dev_err(rtd->dev, "can't set codec pll configuration\n"); 1878c2ecf20Sopenharmony_ci return ret; 1888c2ecf20Sopenharmony_ci } 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci return 0; 1918c2ecf20Sopenharmony_ci} 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistatic const struct snd_soc_ops bdw_rt5677_ops = { 1948c2ecf20Sopenharmony_ci .hw_params = bdw_rt5677_hw_params, 1958c2ecf20Sopenharmony_ci}; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_cistatic const struct snd_soc_ops bdw_rt5677_dsp_ops = { 1988c2ecf20Sopenharmony_ci .hw_params = bdw_rt5677_dsp_hw_params, 1998c2ecf20Sopenharmony_ci}; 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cistatic const unsigned int channels[] = { 2028c2ecf20Sopenharmony_ci 2, 2038c2ecf20Sopenharmony_ci}; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_cistatic const struct snd_pcm_hw_constraint_list constraints_channels = { 2068c2ecf20Sopenharmony_ci .count = ARRAY_SIZE(channels), 2078c2ecf20Sopenharmony_ci .list = channels, 2088c2ecf20Sopenharmony_ci .mask = 0, 2098c2ecf20Sopenharmony_ci}; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_cistatic int bdw_rt5677_fe_startup(struct snd_pcm_substream *substream) 2128c2ecf20Sopenharmony_ci{ 2138c2ecf20Sopenharmony_ci struct snd_pcm_runtime *runtime = substream->runtime; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci /* Board supports stereo configuration only */ 2168c2ecf20Sopenharmony_ci runtime->hw.channels_max = 2; 2178c2ecf20Sopenharmony_ci return snd_pcm_hw_constraint_list(runtime, 0, 2188c2ecf20Sopenharmony_ci SNDRV_PCM_HW_PARAM_CHANNELS, 2198c2ecf20Sopenharmony_ci &constraints_channels); 2208c2ecf20Sopenharmony_ci} 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_cistatic const struct snd_soc_ops bdw_rt5677_fe_ops = { 2238c2ecf20Sopenharmony_ci .startup = bdw_rt5677_fe_startup, 2248c2ecf20Sopenharmony_ci}; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_cistatic int bdw_rt5677_init(struct snd_soc_pcm_runtime *rtd) 2278c2ecf20Sopenharmony_ci{ 2288c2ecf20Sopenharmony_ci struct bdw_rt5677_priv *bdw_rt5677 = 2298c2ecf20Sopenharmony_ci snd_soc_card_get_drvdata(rtd->card); 2308c2ecf20Sopenharmony_ci struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component; 2318c2ecf20Sopenharmony_ci struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 2328c2ecf20Sopenharmony_ci int ret; 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci ret = devm_acpi_dev_add_driver_gpios(component->dev, bdw_rt5677_gpios); 2358c2ecf20Sopenharmony_ci if (ret) 2368c2ecf20Sopenharmony_ci dev_warn(component->dev, "Failed to add driver gpios\n"); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci /* Enable codec ASRC function for Stereo DAC/Stereo1 ADC/DMIC/I2S1. 2398c2ecf20Sopenharmony_ci * The ASRC clock source is clk_i2s1_asrc. 2408c2ecf20Sopenharmony_ci */ 2418c2ecf20Sopenharmony_ci rt5677_sel_asrc_clk_src(component, RT5677_DA_STEREO_FILTER | 2428c2ecf20Sopenharmony_ci RT5677_AD_STEREO1_FILTER | RT5677_I2S1_SOURCE, 2438c2ecf20Sopenharmony_ci RT5677_CLK_SEL_I2S1_ASRC); 2448c2ecf20Sopenharmony_ci /* Enable codec ASRC function for Mono ADC L. 2458c2ecf20Sopenharmony_ci * The ASRC clock source is clk_sys2_asrc. 2468c2ecf20Sopenharmony_ci */ 2478c2ecf20Sopenharmony_ci rt5677_sel_asrc_clk_src(component, RT5677_AD_MONO_L_FILTER, 2488c2ecf20Sopenharmony_ci RT5677_CLK_SEL_SYS2); 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci /* Request rt5677 GPIO for headphone amp control */ 2518c2ecf20Sopenharmony_ci bdw_rt5677->gpio_hp_en = gpiod_get(component->dev, "headphone-enable", 2528c2ecf20Sopenharmony_ci GPIOD_OUT_LOW); 2538c2ecf20Sopenharmony_ci if (IS_ERR(bdw_rt5677->gpio_hp_en)) { 2548c2ecf20Sopenharmony_ci dev_err(component->dev, "Can't find HP_AMP_SHDN_L gpio\n"); 2558c2ecf20Sopenharmony_ci return PTR_ERR(bdw_rt5677->gpio_hp_en); 2568c2ecf20Sopenharmony_ci } 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci /* Create and initialize headphone jack */ 2598c2ecf20Sopenharmony_ci if (!snd_soc_card_jack_new(rtd->card, "Headphone Jack", 2608c2ecf20Sopenharmony_ci SND_JACK_HEADPHONE, &headphone_jack, 2618c2ecf20Sopenharmony_ci &headphone_jack_pin, 1)) { 2628c2ecf20Sopenharmony_ci headphone_jack_gpio.gpiod_dev = component->dev; 2638c2ecf20Sopenharmony_ci if (snd_soc_jack_add_gpios(&headphone_jack, 1, 2648c2ecf20Sopenharmony_ci &headphone_jack_gpio)) 2658c2ecf20Sopenharmony_ci dev_err(component->dev, "Can't add headphone jack gpio\n"); 2668c2ecf20Sopenharmony_ci } else { 2678c2ecf20Sopenharmony_ci dev_err(component->dev, "Can't create headphone jack\n"); 2688c2ecf20Sopenharmony_ci } 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci /* Create and initialize mic jack */ 2718c2ecf20Sopenharmony_ci if (!snd_soc_card_jack_new(rtd->card, "Mic Jack", 2728c2ecf20Sopenharmony_ci SND_JACK_MICROPHONE, &mic_jack, 2738c2ecf20Sopenharmony_ci &mic_jack_pin, 1)) { 2748c2ecf20Sopenharmony_ci mic_jack_gpio.gpiod_dev = component->dev; 2758c2ecf20Sopenharmony_ci if (snd_soc_jack_add_gpios(&mic_jack, 1, &mic_jack_gpio)) 2768c2ecf20Sopenharmony_ci dev_err(component->dev, "Can't add mic jack gpio\n"); 2778c2ecf20Sopenharmony_ci } else { 2788c2ecf20Sopenharmony_ci dev_err(component->dev, "Can't create mic jack\n"); 2798c2ecf20Sopenharmony_ci } 2808c2ecf20Sopenharmony_ci bdw_rt5677->component = component; 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); 2838c2ecf20Sopenharmony_ci return 0; 2848c2ecf20Sopenharmony_ci} 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_cistatic void bdw_rt5677_exit(struct snd_soc_pcm_runtime *rtd) 2878c2ecf20Sopenharmony_ci{ 2888c2ecf20Sopenharmony_ci struct bdw_rt5677_priv *bdw_rt5677 = 2898c2ecf20Sopenharmony_ci snd_soc_card_get_drvdata(rtd->card); 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci /* 2928c2ecf20Sopenharmony_ci * The .exit() can be reached without going through the .init() 2938c2ecf20Sopenharmony_ci * so explicitly test if the gpiod is valid 2948c2ecf20Sopenharmony_ci */ 2958c2ecf20Sopenharmony_ci if (!IS_ERR_OR_NULL(bdw_rt5677->gpio_hp_en)) 2968c2ecf20Sopenharmony_ci gpiod_put(bdw_rt5677->gpio_hp_en); 2978c2ecf20Sopenharmony_ci} 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci/* broadwell digital audio interface glue - connects codec <--> CPU */ 3008c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(dummy, 3018c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_DUMMY())); 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(fe, 3048c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("System Pin"))); 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(platform, 3078c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio"))); 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(be, 3108c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RT5677CE:00", "rt5677-aif1"))); 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(ssp0_port, 3138c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port"))); 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci/* Wake on voice interface */ 3168c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(dsp, 3178c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("spi-RT5677AA:00")), 3188c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RT5677CE:00", "rt5677-dspbuffer")), 3198c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_PLATFORM("spi-RT5677AA:00"))); 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_cistatic struct snd_soc_dai_link bdw_rt5677_dais[] = { 3228c2ecf20Sopenharmony_ci /* Front End DAI links */ 3238c2ecf20Sopenharmony_ci { 3248c2ecf20Sopenharmony_ci .name = "System PCM", 3258c2ecf20Sopenharmony_ci .stream_name = "System Playback/Capture", 3268c2ecf20Sopenharmony_ci .nonatomic = 1, 3278c2ecf20Sopenharmony_ci .dynamic = 1, 3288c2ecf20Sopenharmony_ci .trigger = { 3298c2ecf20Sopenharmony_ci SND_SOC_DPCM_TRIGGER_POST, 3308c2ecf20Sopenharmony_ci SND_SOC_DPCM_TRIGGER_POST 3318c2ecf20Sopenharmony_ci }, 3328c2ecf20Sopenharmony_ci .dpcm_capture = 1, 3338c2ecf20Sopenharmony_ci .dpcm_playback = 1, 3348c2ecf20Sopenharmony_ci .ops = &bdw_rt5677_fe_ops, 3358c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(fe, dummy, platform), 3368c2ecf20Sopenharmony_ci }, 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci /* Non-DPCM links */ 3398c2ecf20Sopenharmony_ci { 3408c2ecf20Sopenharmony_ci .name = "Codec DSP", 3418c2ecf20Sopenharmony_ci .stream_name = "Wake on Voice", 3428c2ecf20Sopenharmony_ci .capture_only = 1, 3438c2ecf20Sopenharmony_ci .ops = &bdw_rt5677_dsp_ops, 3448c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(dsp), 3458c2ecf20Sopenharmony_ci }, 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci /* Back End DAI links */ 3488c2ecf20Sopenharmony_ci { 3498c2ecf20Sopenharmony_ci /* SSP0 - Codec */ 3508c2ecf20Sopenharmony_ci .name = "Codec", 3518c2ecf20Sopenharmony_ci .id = 0, 3528c2ecf20Sopenharmony_ci .no_pcm = 1, 3538c2ecf20Sopenharmony_ci .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 3548c2ecf20Sopenharmony_ci SND_SOC_DAIFMT_CBS_CFS, 3558c2ecf20Sopenharmony_ci .ignore_pmdown_time = 1, 3568c2ecf20Sopenharmony_ci .be_hw_params_fixup = broadwell_ssp0_fixup, 3578c2ecf20Sopenharmony_ci .ops = &bdw_rt5677_ops, 3588c2ecf20Sopenharmony_ci .dpcm_playback = 1, 3598c2ecf20Sopenharmony_ci .dpcm_capture = 1, 3608c2ecf20Sopenharmony_ci .init = bdw_rt5677_init, 3618c2ecf20Sopenharmony_ci .exit = bdw_rt5677_exit, 3628c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(ssp0_port, be, platform), 3638c2ecf20Sopenharmony_ci }, 3648c2ecf20Sopenharmony_ci}; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_cistatic int bdw_rt5677_suspend_pre(struct snd_soc_card *card) 3678c2ecf20Sopenharmony_ci{ 3688c2ecf20Sopenharmony_ci struct bdw_rt5677_priv *bdw_rt5677 = snd_soc_card_get_drvdata(card); 3698c2ecf20Sopenharmony_ci struct snd_soc_dapm_context *dapm; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci if (bdw_rt5677->component) { 3728c2ecf20Sopenharmony_ci dapm = snd_soc_component_get_dapm(bdw_rt5677->component); 3738c2ecf20Sopenharmony_ci snd_soc_dapm_disable_pin(dapm, "MICBIAS1"); 3748c2ecf20Sopenharmony_ci } 3758c2ecf20Sopenharmony_ci return 0; 3768c2ecf20Sopenharmony_ci} 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_cistatic int bdw_rt5677_resume_post(struct snd_soc_card *card) 3798c2ecf20Sopenharmony_ci{ 3808c2ecf20Sopenharmony_ci struct bdw_rt5677_priv *bdw_rt5677 = snd_soc_card_get_drvdata(card); 3818c2ecf20Sopenharmony_ci struct snd_soc_dapm_context *dapm; 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci if (bdw_rt5677->component) { 3848c2ecf20Sopenharmony_ci dapm = snd_soc_component_get_dapm(bdw_rt5677->component); 3858c2ecf20Sopenharmony_ci snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); 3868c2ecf20Sopenharmony_ci } 3878c2ecf20Sopenharmony_ci return 0; 3888c2ecf20Sopenharmony_ci} 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL) 3918c2ecf20Sopenharmony_ci/* use space before codec name to simplify card ID, and simplify driver name */ 3928c2ecf20Sopenharmony_ci#define CARD_NAME "bdw rt5677" /* card name will be 'sof-bdw rt5677' */ 3938c2ecf20Sopenharmony_ci#define DRIVER_NAME "SOF" 3948c2ecf20Sopenharmony_ci#else 3958c2ecf20Sopenharmony_ci#define CARD_NAME "bdw-rt5677" 3968c2ecf20Sopenharmony_ci#define DRIVER_NAME NULL /* card name will be used for driver name */ 3978c2ecf20Sopenharmony_ci#endif 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci/* ASoC machine driver for Broadwell DSP + RT5677 */ 4008c2ecf20Sopenharmony_cistatic struct snd_soc_card bdw_rt5677_card = { 4018c2ecf20Sopenharmony_ci .name = CARD_NAME, 4028c2ecf20Sopenharmony_ci .driver_name = DRIVER_NAME, 4038c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 4048c2ecf20Sopenharmony_ci .dai_link = bdw_rt5677_dais, 4058c2ecf20Sopenharmony_ci .num_links = ARRAY_SIZE(bdw_rt5677_dais), 4068c2ecf20Sopenharmony_ci .dapm_widgets = bdw_rt5677_widgets, 4078c2ecf20Sopenharmony_ci .num_dapm_widgets = ARRAY_SIZE(bdw_rt5677_widgets), 4088c2ecf20Sopenharmony_ci .dapm_routes = bdw_rt5677_map, 4098c2ecf20Sopenharmony_ci .num_dapm_routes = ARRAY_SIZE(bdw_rt5677_map), 4108c2ecf20Sopenharmony_ci .controls = bdw_rt5677_controls, 4118c2ecf20Sopenharmony_ci .num_controls = ARRAY_SIZE(bdw_rt5677_controls), 4128c2ecf20Sopenharmony_ci .fully_routed = true, 4138c2ecf20Sopenharmony_ci .suspend_pre = bdw_rt5677_suspend_pre, 4148c2ecf20Sopenharmony_ci .resume_post = bdw_rt5677_resume_post, 4158c2ecf20Sopenharmony_ci}; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_cistatic int bdw_rt5677_probe(struct platform_device *pdev) 4188c2ecf20Sopenharmony_ci{ 4198c2ecf20Sopenharmony_ci struct bdw_rt5677_priv *bdw_rt5677; 4208c2ecf20Sopenharmony_ci struct snd_soc_acpi_mach *mach; 4218c2ecf20Sopenharmony_ci int ret; 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci bdw_rt5677_card.dev = &pdev->dev; 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci /* Allocate driver private struct */ 4268c2ecf20Sopenharmony_ci bdw_rt5677 = devm_kzalloc(&pdev->dev, sizeof(struct bdw_rt5677_priv), 4278c2ecf20Sopenharmony_ci GFP_KERNEL); 4288c2ecf20Sopenharmony_ci if (!bdw_rt5677) { 4298c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "Can't allocate bdw_rt5677\n"); 4308c2ecf20Sopenharmony_ci return -ENOMEM; 4318c2ecf20Sopenharmony_ci } 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci /* override plaform name, if required */ 4348c2ecf20Sopenharmony_ci mach = pdev->dev.platform_data; 4358c2ecf20Sopenharmony_ci ret = snd_soc_fixup_dai_links_platform_name(&bdw_rt5677_card, 4368c2ecf20Sopenharmony_ci mach->mach_params.platform); 4378c2ecf20Sopenharmony_ci if (ret) 4388c2ecf20Sopenharmony_ci return ret; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci snd_soc_card_set_drvdata(&bdw_rt5677_card, bdw_rt5677); 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci return devm_snd_soc_register_card(&pdev->dev, &bdw_rt5677_card); 4438c2ecf20Sopenharmony_ci} 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_cistatic struct platform_driver bdw_rt5677_audio = { 4468c2ecf20Sopenharmony_ci .probe = bdw_rt5677_probe, 4478c2ecf20Sopenharmony_ci .driver = { 4488c2ecf20Sopenharmony_ci .name = "bdw-rt5677", 4498c2ecf20Sopenharmony_ci }, 4508c2ecf20Sopenharmony_ci}; 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_cimodule_platform_driver(bdw_rt5677_audio) 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci/* Module information */ 4558c2ecf20Sopenharmony_ciMODULE_AUTHOR("Ben Zhang"); 4568c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Intel Broadwell RT5677 machine driver"); 4578c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 4588c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:bdw-rt5677"); 459