Lines Matching +full:tx +full:- +full:clk +full:- +full:100 +full:- +full:inverted
1 // SPDX-License-Identifier: GPL-2.0-only
3 * bytcr_rt5651.c - ASoc Machine driver for Intel Byt CR platform
18 #include <linux/clk.h>
29 #include <sound/soc-acpi.h>
31 #include "../atom/sst-atom-controls.h"
32 #include "../common/soc-intel-quirks.h"
80 /* jack-detect-source + inv + dmic-en + ovcd-th + -sf + terminating entry */
84 struct clk *mclk;
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()
115 BYT_RT5651_OVCD_TH(byt_rt5651_quirk) * 100); 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()
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()
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()
290 {"ssp0 Tx", NULL, "modem_out"},
293 {"AIF1 Playback", NULL, "ssp0 Tx"},
298 {"ssp0 Tx", NULL, "modem_out"},
301 {"AIF2 Playback", NULL, "ssp0 Tx"},
306 {"ssp2 Tx", NULL, "codec_out0"},
307 {"ssp2 Tx", NULL, "codec_out1"},
311 {"AIF1 Playback", NULL, "ssp2 Tx"},
316 {"ssp2 Tx", NULL, "codec_out0"},
317 {"ssp2 Tx", NULL, "codec_out1"},
321 {"AIF2 Playback", NULL, "ssp2 Tx"},
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
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()
539 BYT_RT5651_OVCD_TH(byt_rt5651_quirk) * 100); 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()
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()
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")));
779 .name = "Deep-Buffer Audio Port",
780 .stream_name = "Deep-Buffer Audio",
787 /* CODEC<->CODEC link */
790 .name = "SSP2-Codec",
807 static char byt_rt5651_long_name[50]; /* = "bytcr-rt5651-*-spk-*-mic[-swapped-hp]" */
809 static char byt_rt5651_components[50]; /* = "cfg-spk:* cfg-mic:*" */
819 if (!strcmp(component->name, byt_rt5651_codec_name)) { in byt_rt5651_suspend()
820 dev_dbg(component->dev, "disabling jack detect before suspend\n"); in byt_rt5651_suspend()
838 if (!strcmp(component->name, byt_rt5651_codec_name)) { in byt_rt5651_resume()
839 dev_dbg(component->dev, "re-enabling jack detect after resume\n"); in byt_rt5651_resume()
840 snd_soc_component_set_jack(component, &priv->jack, in byt_rt5651_resume()
841 priv->hp_detect); in byt_rt5651_resume()
850 #define SOF_CARD_NAME "bytcht rt5651" /* card name will be 'sof-bytcht rt5651' */
853 #define CARD_NAME "bytcr-rt5651"
877 * We want the GpioIo one for the ext-amp-enable-gpio.
879 { "ext-amp-enable-gpios", &ext_amp_enable_gpios, 1, ACPI_GPIO_QUIRK_ONLY_GPIOIO },
890 struct device *dev = &pdev->dev; in snd_byt_rt5651_mc_probe()
905 return -ENOMEM; in snd_byt_rt5651_mc_probe()
914 !strcmp(byt_rt5651_dais[i].codecs->name, in snd_byt_rt5651_mc_probe()
915 "i2c-10EC5651:00")) { in snd_byt_rt5651_mc_probe()
922 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1); in snd_byt_rt5651_mc_probe()
925 "i2c-%s", acpi_dev_name(adev)); in snd_byt_rt5651_mc_probe()
926 byt_rt5651_dais[dai_index].codecs->name = byt_rt5651_codec_name; in snd_byt_rt5651_mc_probe()
928 dev_err(dev, "Error cannot find '%s' dev\n", mach->id); in snd_byt_rt5651_mc_probe()
929 return -ENOENT; in snd_byt_rt5651_mc_probe()
935 return -EPROBE_DEFER; in snd_byt_rt5651_mc_probe()
936 priv->codec_dev = get_device(codec_dev); in snd_byt_rt5651_mc_probe()
943 if (mach->mach_params.acpi_ipc_irq_index == 0) in snd_byt_rt5651_mc_probe()
953 * with the codec driver/pdata are non-existent in snd_byt_rt5651_mc_probe()
958 /* format specified: 2 64-bit integers */ in snd_byt_rt5651_mc_probe()
973 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id, in snd_byt_rt5651_mc_probe()
989 /* no BIOS indications, assume SSP0-AIF2 connection */ in snd_byt_rt5651_mc_probe()
997 if (quirk_override != -1) { in snd_byt_rt5651_mc_probe()
1014 priv->ext_amp_gpio = devm_fwnode_gpiod_get(dev, codec_dev->fwnode, in snd_byt_rt5651_mc_probe()
1015 "ext-amp-enable", in snd_byt_rt5651_mc_probe()
1017 "speaker-amp"); in snd_byt_rt5651_mc_probe()
1018 if (IS_ERR(priv->ext_amp_gpio)) { in snd_byt_rt5651_mc_probe()
1019 ret_val = PTR_ERR(priv->ext_amp_gpio); in snd_byt_rt5651_mc_probe()
1021 case -ENOENT: in snd_byt_rt5651_mc_probe()
1022 priv->ext_amp_gpio = NULL; in snd_byt_rt5651_mc_probe()
1025 dev_err(dev, "Failed to get ext-amp-enable GPIO: %d\n", ret_val); in snd_byt_rt5651_mc_probe()
1027 case -EPROBE_DEFER: in snd_byt_rt5651_mc_probe()
1031 priv->hp_detect = devm_fwnode_gpiod_get(dev, codec_dev->fwnode, in snd_byt_rt5651_mc_probe()
1032 "hp-detect", in snd_byt_rt5651_mc_probe()
1034 "hp-detect"); in snd_byt_rt5651_mc_probe()
1035 if (IS_ERR(priv->hp_detect)) { in snd_byt_rt5651_mc_probe()
1036 ret_val = PTR_ERR(priv->hp_detect); in snd_byt_rt5651_mc_probe()
1038 case -ENOENT: in snd_byt_rt5651_mc_probe()
1039 priv->hp_detect = NULL; in snd_byt_rt5651_mc_probe()
1042 dev_err(dev, "Failed to get hp-detect GPIO: %d\n", ret_val); in snd_byt_rt5651_mc_probe()
1044 case -EPROBE_DEFER: in snd_byt_rt5651_mc_probe()
1054 byt_rt5651_dais[dai_index].codecs->dai_name = "rt5651-aif2"; in snd_byt_rt5651_mc_probe()
1058 byt_rt5651_dais[dai_index].cpus->dai_name = "ssp0-port"; in snd_byt_rt5651_mc_probe()
1061 priv->mclk = devm_clk_get_optional(dev, "pmc_plt_clk_3"); in snd_byt_rt5651_mc_probe()
1062 if (IS_ERR(priv->mclk)) { in snd_byt_rt5651_mc_probe()
1063 ret_val = dev_err_probe(dev, PTR_ERR(priv->mclk), in snd_byt_rt5651_mc_probe()
1071 if (!priv->mclk) in snd_byt_rt5651_mc_probe()
1076 "cfg-spk:%s cfg-mic:%s%s", in snd_byt_rt5651_mc_probe()
1080 " cfg-hp:lrswap" : ""); in snd_byt_rt5651_mc_probe()
1084 "bytcr-rt5651-%s-spk-%s-mic%s", in snd_byt_rt5651_mc_probe()
1089 "-hp-swapped" : ""); in snd_byt_rt5651_mc_probe()
1094 platform_name = mach->mach_params.platform; in snd_byt_rt5651_mc_probe()
1114 dev->driver->pm = &snd_soc_pm_ops; in snd_byt_rt5651_mc_probe()
1125 device_remove_software_node(priv->codec_dev); in snd_byt_rt5651_mc_probe()
1127 put_device(priv->codec_dev); in snd_byt_rt5651_mc_probe()
1136 device_remove_software_node(priv->codec_dev); in snd_byt_rt5651_mc_remove()
1137 put_device(priv->codec_dev); in snd_byt_rt5651_mc_remove()
1151 MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>");