Lines Matching +full:codec +full:- +full:aif1
1 // SPDX-License-Identifier: GPL-2.0-only
3 * bytcr_rt5651.c - ASoc Machine driver for Intel Byt CR platform
29 #include <sound/soc-acpi.h>
31 #include "../atom/sst-atom-controls.h"
32 #include "../common/soc-intel-quirks.h"
68 #define BYT_RT5651_SSP2_AIF2 BIT(19) /* default is using AIF1 */
80 /* jack-detect-source + inv + dmic-en + ovcd-th + -sf + terminating entry */
93 /* Default: jack-detect on JD1_1, internal mic on in2, headsetmic on in3 */
97 static int quirk_override = -1;
99 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
112 dev_info(dev, "quirk realtek,jack-detect-source %ld\n", in log_quirks()
114 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n", in log_quirks()
116 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n", in log_quirks()
137 #define BYT_CODEC_DAI1 "rt5651-aif1"
138 #define BYT_CODEC_DAI2 "rt5651-aif2"
158 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret); in byt_rt5651_prepare_and_enable_pll1()
165 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret); in byt_rt5651_prepare_and_enable_pll1()
175 struct snd_soc_dapm_context *dapm = w->dapm; in platform_clock_control()
176 struct snd_soc_card *card = dapm->card; in platform_clock_control()
185 dev_err(card->dev, in platform_clock_control()
186 "Codec dai not found; Unable to set platform clock\n"); in platform_clock_control()
187 return -EIO; in platform_clock_control()
191 ret = clk_prepare_enable(priv->mclk); in platform_clock_control()
193 dev_err(card->dev, "could not configure MCLK state"); in platform_clock_control()
199 * Set codec clock source to internal clock before in platform_clock_control()
200 * turning off the platform clock. Codec needs clock in platform_clock_control()
207 clk_disable_unprepare(priv->mclk); in platform_clock_control()
211 dev_err(card->dev, "can't set codec sysclk: %d\n", ret); in platform_clock_control()
221 struct snd_soc_card *card = w->dapm->card; in rt5651_ext_amp_power_event()
225 gpiod_set_value_cansleep(priv->ext_amp_gpio, 1); in rt5651_ext_amp_power_event()
227 gpiod_set_value_cansleep(priv->ext_amp_gpio, 0); in rt5651_ext_amp_power_event()
293 {"AIF1 Playback", NULL, "ssp0 Tx"},
294 {"ssp0 Rx", NULL, "AIF1 Capture"},
311 {"AIF1 Playback", NULL, "ssp2 Tx"},
312 {"ssp2 Rx", NULL, "AIF1 Capture"},
365 { "hp-detect-gpios", &pov_p1006w_hp_detect, 1, },
366 { "ext-amp-enable-gpios", &pov_p1006w_ext_amp_en, 1, },
372 byt_rt5651_quirk = (unsigned long)id->driver_data; in byt_rt5651_pov_p1006w_quirk_cb()
379 byt_rt5651_quirk = (unsigned long)id->driver_data; in byt_rt5651_quirk_cb()
421 /* I.T.Works TW701, Ployer Momo7w and Trekstor ST70416-6
525 * are in place before the codec component driver's probe function parses them.
535 props[cnt++] = PROPERTY_ENTRY_U32("realtek,jack-detect-source", in byt_rt5651_add_codec_device_props()
538 props[cnt++] = PROPERTY_ENTRY_U32("realtek,over-current-threshold-microamp", in byt_rt5651_add_codec_device_props()
541 props[cnt++] = PROPERTY_ENTRY_U32("realtek,over-current-scale-factor", in byt_rt5651_add_codec_device_props()
545 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,dmic-en"); in byt_rt5651_add_codec_device_props()
548 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted"); in byt_rt5651_add_codec_device_props()
565 struct snd_soc_card *card = runtime->card; in byt_rt5651_init()
566 struct snd_soc_component *codec = snd_soc_rtd_to_codec(runtime, 0)->component; in byt_rt5651_init() local
573 card->dapm.idle_bias_off = true; in byt_rt5651_init()
575 /* Start with RC clk for jack-detect (we disable MCLK below) */ in byt_rt5651_init()
577 snd_soc_component_update_bits(codec, RT5651_GLB_CLK, in byt_rt5651_init()
597 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); in byt_rt5651_init()
602 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5651_init()
606 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5651_init()
610 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5651_init()
614 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5651_init()
624 dev_err(card->dev, "unable to add card controls\n"); in byt_rt5651_init()
636 ret = clk_prepare_enable(priv->mclk); in byt_rt5651_init()
638 clk_disable_unprepare(priv->mclk); in byt_rt5651_init()
641 ret = clk_set_rate(priv->mclk, 25000000); in byt_rt5651_init()
643 ret = clk_set_rate(priv->mclk, 19200000); in byt_rt5651_init()
646 dev_err(card->dev, "unable to set MCLK rate\n"); in byt_rt5651_init()
651 else if (priv->hp_detect) in byt_rt5651_init()
655 ret = snd_soc_card_jack_new_pins(runtime->card, "Headset", in byt_rt5651_init()
656 report, &priv->jack, in byt_rt5651_init()
660 dev_err(runtime->dev, "jack creation failed %d\n", ret); in byt_rt5651_init()
665 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, in byt_rt5651_init()
668 ret = snd_soc_component_set_jack(codec, &priv->jack, in byt_rt5651_init()
669 priv->hp_detect); in byt_rt5651_init()
687 rate->min = rate->max = 48000; in byt_rt5651_codec_fixup()
688 channels->min = channels->max = 2; in byt_rt5651_codec_fixup()
692 /* set SSP0 to 16-bit */ in byt_rt5651_codec_fixup()
696 /* set SSP2 to 24-bit */ in byt_rt5651_codec_fixup()
713 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); in byt_rt5651_codec_fixup()
719 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); in byt_rt5651_codec_fixup()
737 return snd_pcm_hw_constraint_list(substream->runtime, 0, in byt_rt5651_aif1_startup()
754 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
757 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
760 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
762 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5651:00", "rt5651-aif1")));
765 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
777 .name = "Deep-Buffer Audio Port",
778 .stream_name = "Deep-Buffer Audio",
785 /* CODEC<->CODEC link */
788 .name = "SSP2-Codec",
803 static char byt_rt5651_long_name[50]; /* = "bytcr-rt5651-*-spk-*-mic[-swapped-hp]" */
805 static char byt_rt5651_components[50]; /* = "cfg-spk:* cfg-mic:*" */
815 if (!strcmp(component->name, byt_rt5651_codec_name)) { in byt_rt5651_suspend()
816 dev_dbg(component->dev, "disabling jack detect before suspend\n"); in byt_rt5651_suspend()
834 if (!strcmp(component->name, byt_rt5651_codec_name)) { in byt_rt5651_resume()
835 dev_dbg(component->dev, "re-enabling jack detect after resume\n"); in byt_rt5651_resume()
836 snd_soc_component_set_jack(component, &priv->jack, in byt_rt5651_resume()
837 priv->hp_detect); in byt_rt5651_resume()
845 /* use space before codec name to simplify card ID, and simplify driver name */
846 #define SOF_CARD_NAME "bytcht rt5651" /* card name will be 'sof-bytcht rt5651' */
849 #define CARD_NAME "bytcr-rt5651"
873 * We want the GpioIo one for the ext-amp-enable-gpio.
875 { "ext-amp-enable-gpios", &ext_amp_enable_gpios, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO },
880 u64 aif_value; /* 1: AIF1, 2: AIF2 */
886 struct device *dev = &pdev->dev; in snd_byt_rt5651_mc_probe()
901 return -ENOMEM; in snd_byt_rt5651_mc_probe()
907 /* fix index of codec dai */ in snd_byt_rt5651_mc_probe()
910 !strcmp(byt_rt5651_dais[i].codecs->name, in snd_byt_rt5651_mc_probe()
911 "i2c-10EC5651:00")) { in snd_byt_rt5651_mc_probe()
917 /* fixup codec name based on HID */ in snd_byt_rt5651_mc_probe()
918 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1); in snd_byt_rt5651_mc_probe()
921 "i2c-%s", acpi_dev_name(adev)); in snd_byt_rt5651_mc_probe()
922 byt_rt5651_dais[dai_index].codecs->name = byt_rt5651_codec_name; in snd_byt_rt5651_mc_probe()
924 dev_err(dev, "Error cannot find '%s' dev\n", mach->id); in snd_byt_rt5651_mc_probe()
925 return -ENOENT; in snd_byt_rt5651_mc_probe()
931 return -EPROBE_DEFER; in snd_byt_rt5651_mc_probe()
932 priv->codec_dev = get_device(codec_dev); in snd_byt_rt5651_mc_probe()
939 if (mach->mach_params.acpi_ipc_irq_index == 0) in snd_byt_rt5651_mc_probe()
949 * with the codec driver/pdata are non-existent in snd_byt_rt5651_mc_probe()
954 /* format specified: 2 64-bit integers */ in snd_byt_rt5651_mc_probe()
969 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id, in snd_byt_rt5651_mc_probe()
973 dev_info(dev, "BIOS Routing: AIF1 connected\n"); in snd_byt_rt5651_mc_probe()
985 /* no BIOS indications, assume SSP0-AIF2 connection */ in snd_byt_rt5651_mc_probe()
993 if (quirk_override != -1) { in snd_byt_rt5651_mc_probe()
1010 priv->ext_amp_gpio = devm_fwnode_gpiod_get(dev, codec_dev->fwnode, in snd_byt_rt5651_mc_probe()
1011 "ext-amp-enable", in snd_byt_rt5651_mc_probe()
1013 "speaker-amp"); in snd_byt_rt5651_mc_probe()
1014 if (IS_ERR(priv->ext_amp_gpio)) { in snd_byt_rt5651_mc_probe()
1015 ret_val = PTR_ERR(priv->ext_amp_gpio); in snd_byt_rt5651_mc_probe()
1017 case -ENOENT: in snd_byt_rt5651_mc_probe()
1018 priv->ext_amp_gpio = NULL; in snd_byt_rt5651_mc_probe()
1021 dev_err(dev, "Failed to get ext-amp-enable GPIO: %d\n", ret_val); in snd_byt_rt5651_mc_probe()
1023 case -EPROBE_DEFER: in snd_byt_rt5651_mc_probe()
1027 priv->hp_detect = devm_fwnode_gpiod_get(dev, codec_dev->fwnode, in snd_byt_rt5651_mc_probe()
1028 "hp-detect", in snd_byt_rt5651_mc_probe()
1030 "hp-detect"); in snd_byt_rt5651_mc_probe()
1031 if (IS_ERR(priv->hp_detect)) { in snd_byt_rt5651_mc_probe()
1032 ret_val = PTR_ERR(priv->hp_detect); in snd_byt_rt5651_mc_probe()
1034 case -ENOENT: in snd_byt_rt5651_mc_probe()
1035 priv->hp_detect = NULL; in snd_byt_rt5651_mc_probe()
1038 dev_err(dev, "Failed to get hp-detect GPIO: %d\n", ret_val); in snd_byt_rt5651_mc_probe()
1040 case -EPROBE_DEFER: in snd_byt_rt5651_mc_probe()
1050 byt_rt5651_dais[dai_index].codecs->dai_name = "rt5651-aif2"; in snd_byt_rt5651_mc_probe()
1054 byt_rt5651_dais[dai_index].cpus->dai_name = "ssp0-port"; in snd_byt_rt5651_mc_probe()
1057 priv->mclk = devm_clk_get_optional(dev, "pmc_plt_clk_3"); in snd_byt_rt5651_mc_probe()
1058 if (IS_ERR(priv->mclk)) { in snd_byt_rt5651_mc_probe()
1059 ret_val = dev_err_probe(dev, PTR_ERR(priv->mclk), in snd_byt_rt5651_mc_probe()
1067 if (!priv->mclk) in snd_byt_rt5651_mc_probe()
1072 "cfg-spk:%s cfg-mic:%s%s", in snd_byt_rt5651_mc_probe()
1076 " cfg-hp:lrswap" : ""); in snd_byt_rt5651_mc_probe()
1080 "bytcr-rt5651-%s-spk-%s-mic%s", in snd_byt_rt5651_mc_probe()
1085 "-hp-swapped" : ""); in snd_byt_rt5651_mc_probe()
1090 platform_name = mach->mach_params.platform; in snd_byt_rt5651_mc_probe()
1110 dev->driver->pm = &snd_soc_pm_ops; in snd_byt_rt5651_mc_probe()
1121 device_remove_software_node(priv->codec_dev); in snd_byt_rt5651_mc_probe()
1123 put_device(priv->codec_dev); in snd_byt_rt5651_mc_probe()
1132 device_remove_software_node(priv->codec_dev); in snd_byt_rt5651_mc_remove()
1133 put_device(priv->codec_dev); in snd_byt_rt5651_mc_remove()
1147 MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>");