Lines Matching +full:codec +full:- +full:aif1
1 // SPDX-License-Identifier: GPL-2.0-only
3 * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
30 #include <sound/soc-acpi.h>
31 #include <dt-bindings/sound/rt5640.h>
33 #include "../atom/sst-atom-controls.h"
34 #include "../common/soc-intel-quirks.h"
36 #define BYT_RT5640_FALLBACK_CODEC_DEV_NAME "i2c-rt5640"
77 #define BYT_RT5640_DIFF_MIC BIT(18) /* default is single-ended */
78 #define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
98 /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
112 static int quirk_override = -1;
114 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
149 dev_info(dev, "quirk realtek,jack-detect-source %ld\n", in log_quirks()
151 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n", in log_quirks()
153 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n", in log_quirks()
187 …dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2… in log_quirks()
189 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n"); in log_quirks()
191 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n"); in log_quirks()
238 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret); in byt_rt5640_prepare_and_enable_pll1()
245 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret); in byt_rt5640_prepare_and_enable_pll1()
252 #define BYT_CODEC_DAI1 "rt5640-aif1"
253 #define BYT_CODEC_DAI2 "rt5640-aif2"
257 struct snd_soc_card *card = dapm->card; in byt_rt5640_get_codec_dai()
264 dev_err(card->dev, "Error codec dai not found\n"); in byt_rt5640_get_codec_dai()
272 struct snd_soc_dapm_context *dapm = w->dapm; in platform_clock_control()
273 struct snd_soc_card *card = dapm->card; in platform_clock_control()
280 return -EIO; in platform_clock_control()
283 ret = clk_prepare_enable(priv->mclk); in platform_clock_control()
285 dev_err(card->dev, "could not configure MCLK state\n"); in platform_clock_control()
291 * Set codec clock source to internal clock before in platform_clock_control()
292 * turning off the platform clock. Codec needs clock in platform_clock_control()
299 clk_disable_unprepare(priv->mclk); in platform_clock_control()
303 dev_err(card->dev, "can't set codec sysclk: %d\n", ret); in platform_clock_control()
320 * On devices which use line-out as a second headphones output, in byt_rt5640_event_lineout()
321 * the codec's GPIO1 pin is used to enable an external HP-amp. in byt_rt5640_event_lineout()
324 codec_dai = byt_rt5640_get_codec_dai(w->dapm); in byt_rt5640_event_lineout()
326 return -EIO; in byt_rt5640_event_lineout()
331 snd_soc_component_update_bits(codec_dai->component, RT5640_GPIO_CTRL3, in byt_rt5640_event_lineout()
392 {"AIF1 Playback", NULL, "ssp2 Tx"},
393 {"ssp2 Rx", NULL, "AIF1 Capture"},
410 {"AIF1 Playback", NULL, "ssp0 Tx"},
411 {"ssp0 Rx", NULL, "AIF1 Capture"},
464 /* The 2nd headset jack uses lineout with an external HP-amp */
475 .name = "hp-detect",
482 .name = "hp2-detect",
493 { "hp-detect-gpios", &acpi_gpio0, 1, },
494 { "headset-mic-detect-gpios", &acpi_gpio1, 1, },
495 { "hp2-detect-gpios", &acpi_gpio2, 1, },
508 mic_status = gpiod_get_value_cansleep(priv->hsmic_detect); in byt_rt5640_hp_elitepad_1000g2_jack1_check()
542 { /* Acer Iconia One 7 B1-750 */
554 { /* Acer Iconia Tab 8 W1-810 */
557 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
582 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
592 /* Advantech MICA-071 */
595 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MICA-071"),
597 /* OVCD Th = 1500uA to reliable detect head-phones vs -set */
704 { /* Chuwi Vi8 dual-boot (CWI506) */
720 DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
736 DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
793 DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
801 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
811 { /* HP Pavilion x2 10-k0XX, 10-n0XX */
813 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
823 { /* HP Pavilion x2 10-p0XX */
826 DMI_MATCH(DMI_PRODUCT_NAME, "HP x2 Detachable 10-p0XX"),
836 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
848 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
859 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
903 { /* Lenovo Miix 3-830 */
906 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 3-830"),
950 { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
973 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
1025 { /* Point of View Mobii TAB-P800W (V2.0) */
1042 { /* Point of View Mobii TAB-P800W (V2.1) */
1059 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
1099 { /* Toshiba Satellite Click Mini L9W-B */
1102 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
1111 { /* Toshiba Encore WT8-A */
1114 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
1123 { /* Toshiba Encore WT10-A */
1126 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
1164 { /* Catch-all for generic Insyde tablets, must be last */
1178 * are in place before the codec component driver's probe function parses them.
1190 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin", in byt_rt5640_add_codec_device_props()
1194 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin", in byt_rt5640_add_codec_device_props()
1200 PROPERTY_ENTRY_BOOL("realtek,in1-differential"); in byt_rt5640_add_codec_device_props()
1205 PROPERTY_ENTRY_BOOL("realtek,in3-differential"); in byt_rt5640_add_codec_device_props()
1212 "realtek,jack-detect-source", in byt_rt5640_add_codec_device_props()
1217 "realtek,over-current-threshold-microamp", in byt_rt5640_add_codec_device_props()
1221 "realtek,over-current-scale-factor", in byt_rt5640_add_codec_device_props()
1226 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted"); in byt_rt5640_add_codec_device_props()
1245 { "rt5640-jd-gpios", &amcr0f28_jd_gpio, 1 },
1252 struct rt5640_set_jack_data *data = &priv->jack_data; in byt_rt5640_get_amcr0f28_settings()
1256 adev = acpi_dev_get_first_match_dev("AMCR0F28", "1", -1); in byt_rt5640_get_amcr0f28_settings()
1258 dev_err(card->dev, "error cannot find AMCR0F28 adev\n"); in byt_rt5640_get_amcr0f28_settings()
1259 return -ENOENT; in byt_rt5640_get_amcr0f28_settings()
1262 data->codec_irq_override = acpi_dev_gpio_irq_get(adev, 0); in byt_rt5640_get_amcr0f28_settings()
1263 if (data->codec_irq_override < 0) { in byt_rt5640_get_amcr0f28_settings()
1264 ret = data->codec_irq_override; in byt_rt5640_get_amcr0f28_settings()
1265 dev_err(card->dev, "error %d getting codec IRQ\n", ret); in byt_rt5640_get_amcr0f28_settings()
1271 data->jd_gpio = devm_fwnode_gpiod_get(card->dev, acpi_fwnode_handle(adev), in byt_rt5640_get_amcr0f28_settings()
1272 "rt5640-jd", GPIOD_IN, "rt5640-jd"); in byt_rt5640_get_amcr0f28_settings()
1275 if (IS_ERR(data->jd_gpio)) { in byt_rt5640_get_amcr0f28_settings()
1276 ret = PTR_ERR(data->jd_gpio); in byt_rt5640_get_amcr0f28_settings()
1277 dev_err(card->dev, "error %d getting jd GPIO\n", ret); in byt_rt5640_get_amcr0f28_settings()
1288 struct snd_soc_card *card = runtime->card; in byt_rt5640_init()
1290 struct rt5640_set_jack_data *jack_data = &priv->jack_data; in byt_rt5640_init()
1291 struct snd_soc_component *component = snd_soc_rtd_to_codec(runtime, 0)->component; in byt_rt5640_init()
1296 card->dapm.idle_bias_off = true; in byt_rt5640_init()
1297 jack_data->use_platform_clock = true; in byt_rt5640_init()
1299 /* Start with RC clk for jack-detect (we disable MCLK below) */ in byt_rt5640_init()
1316 dev_err(card->dev, "unable to add card controls\n"); in byt_rt5640_init()
1339 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); in byt_rt5640_init()
1344 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1352 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1356 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1360 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1364 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1372 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1376 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1384 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1399 ret = clk_prepare_enable(priv->mclk); in byt_rt5640_init()
1401 clk_disable_unprepare(priv->mclk); in byt_rt5640_init()
1404 ret = clk_set_rate(priv->mclk, 25000000); in byt_rt5640_init()
1406 ret = clk_set_rate(priv->mclk, 19200000); in byt_rt5640_init()
1408 dev_err(card->dev, "unable to set MCLK rate\n"); in byt_rt5640_init()
1415 &priv->jack, rt5640_pins, in byt_rt5640_init()
1418 dev_err(card->dev, "Jack creation failed %d\n", ret); in byt_rt5640_init()
1421 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, in byt_rt5640_init()
1430 snd_soc_component_set_jack(component, &priv->jack, &priv->jack_data); in byt_rt5640_init()
1436 &priv->jack, rt5640_pins, in byt_rt5640_init()
1443 &priv->jack2, rt5640_pins2, in byt_rt5640_init()
1449 rt5640_jack_gpio.gpiod_dev = priv->codec_dev; in byt_rt5640_init()
1451 ret = snd_soc_jack_add_gpios(&priv->jack, 1, &rt5640_jack_gpio); in byt_rt5640_init()
1457 rt5640_jack2_gpio.gpiod_dev = priv->codec_dev; in byt_rt5640_init()
1459 ret = snd_soc_jack_add_gpios(&priv->jack2, 1, &rt5640_jack2_gpio); in byt_rt5640_init()
1461 snd_soc_jack_free_gpios(&priv->jack, 1, &rt5640_jack_gpio); in byt_rt5640_init()
1471 struct snd_soc_card *card = runtime->card; in byt_rt5640_exit()
1475 snd_soc_jack_free_gpios(&priv->jack2, 1, &rt5640_jack2_gpio); in byt_rt5640_exit()
1476 snd_soc_jack_free_gpios(&priv->jack, 1, &rt5640_jack_gpio); in byt_rt5640_exit()
1490 rate->min = rate->max = 48000; in byt_rt5640_codec_fixup()
1491 channels->min = channels->max = 2; in byt_rt5640_codec_fixup()
1495 /* set SSP0 to 16-bit */ in byt_rt5640_codec_fixup()
1499 /* set SSP2 to 24-bit */ in byt_rt5640_codec_fixup()
1514 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); in byt_rt5640_codec_fixup()
1520 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); in byt_rt5640_codec_fixup()
1529 return snd_pcm_hw_constraint_single(substream->runtime, in byt_rt5640_aif1_startup()
1545 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1548 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1552 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1555 /* overwritten with HID */ "i2c-10EC5640:00",
1556 /* changed w/ quirk */ "rt5640-aif1")));
1559 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1571 .name = "Deep-Buffer Audio Port",
1572 .stream_name = "Deep-Buffer Audio",
1581 .name = "SSP2-Codec",
1597 static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
1599 static char byt_rt5640_components[64]; /* = "cfg-spk:* cfg-mic:* ..." */
1609 if (!strcmp(component->name, byt_rt5640_codec_name)) { in byt_rt5640_suspend()
1610 dev_dbg(component->dev, "disabling jack detect before suspend\n"); in byt_rt5640_suspend()
1628 if (!strcmp(component->name, byt_rt5640_codec_name)) { in byt_rt5640_resume()
1629 dev_dbg(component->dev, "re-enabling jack detect after resume\n"); in byt_rt5640_resume()
1630 snd_soc_component_set_jack(component, &priv->jack, in byt_rt5640_resume()
1631 &priv->jack_data); in byt_rt5640_resume()
1639 /* use space before codec name to simplify card ID, and simplify driver name */
1640 #define SOF_CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1643 #define CARD_NAME "bytcr-rt5640"
1660 u64 aif_value; /* 1: AIF1, 2: AIF2 */
1666 struct device *dev = &pdev->dev; in snd_byt_rt5640_mc_probe()
1686 return -ENOMEM; in snd_byt_rt5640_mc_probe()
1692 /* fix index of codec dai */ in snd_byt_rt5640_mc_probe()
1695 !strcmp(byt_rt5640_dais[i].codecs->name, in snd_byt_rt5640_mc_probe()
1696 "i2c-10EC5640:00")) { in snd_byt_rt5640_mc_probe()
1702 /* fixup codec name based on HID */ in snd_byt_rt5640_mc_probe()
1703 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1); in snd_byt_rt5640_mc_probe()
1706 "i2c-%s", acpi_dev_name(adev)); in snd_byt_rt5640_mc_probe()
1707 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name; in snd_byt_rt5640_mc_probe()
1709 dev_err(dev, "Error cannot find '%s' dev\n", mach->id); in snd_byt_rt5640_mc_probe()
1710 return -ENOENT; in snd_byt_rt5640_mc_probe()
1717 priv->codec_dev = get_device(codec_dev); in snd_byt_rt5640_mc_probe()
1720 * Special case for Android tablets where the codec i2c_client in snd_byt_rt5640_mc_probe()
1727 return -EPROBE_DEFER; in snd_byt_rt5640_mc_probe()
1735 /* fixup codec name */ in snd_byt_rt5640_mc_probe()
1740 priv->codec_dev = codec_dev; in snd_byt_rt5640_mc_probe()
1748 if (mach->mach_params.acpi_ipc_irq_index == 0) in snd_byt_rt5640_mc_probe()
1758 * with the codec driver/pdata are non-existent in snd_byt_rt5640_mc_probe()
1763 /* format specified: 2 64-bit integers */ in snd_byt_rt5640_mc_probe()
1778 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id, in snd_byt_rt5640_mc_probe()
1782 dev_info(dev, "BIOS Routing: AIF1 connected\n"); in snd_byt_rt5640_mc_probe()
1794 /* no BIOS indications, assume SSP0-AIF2 connection */ in snd_byt_rt5640_mc_probe()
1798 /* change defaults for Baytrail-CR capture */ in snd_byt_rt5640_mc_probe()
1810 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data; in snd_byt_rt5640_mc_probe()
1811 if (quirk_override != -1) { in snd_byt_rt5640_mc_probe()
1818 acpi_dev_add_driver_gpios(ACPI_COMPANION(priv->codec_dev), in snd_byt_rt5640_mc_probe()
1821 priv->hsmic_detect = devm_fwnode_gpiod_get(dev, codec_dev->fwnode, in snd_byt_rt5640_mc_probe()
1822 "headset-mic-detect", GPIOD_IN, in snd_byt_rt5640_mc_probe()
1823 "headset-mic-detect"); in snd_byt_rt5640_mc_probe()
1824 if (IS_ERR(priv->hsmic_detect)) { in snd_byt_rt5640_mc_probe()
1825 ret_val = dev_err_probe(dev, PTR_ERR(priv->hsmic_detect), in snd_byt_rt5640_mc_probe()
1826 "getting hsmic-detect GPIO\n"); in snd_byt_rt5640_mc_probe()
1840 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2"; in snd_byt_rt5640_mc_probe()
1848 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port"; in snd_byt_rt5640_mc_probe()
1851 priv->mclk = devm_clk_get_optional(dev, "pmc_plt_clk_3"); in snd_byt_rt5640_mc_probe()
1852 if (IS_ERR(priv->mclk)) { in snd_byt_rt5640_mc_probe()
1853 ret_val = dev_err_probe(dev, PTR_ERR(priv->mclk), in snd_byt_rt5640_mc_probe()
1861 if (!priv->mclk) in snd_byt_rt5640_mc_probe()
1881 lineout_string = " cfg-hp2:lineout"; in snd_byt_rt5640_mc_probe()
1883 lineout_string = " cfg-lineout:2"; in snd_byt_rt5640_mc_probe()
1887 headset2_string = " cfg-hs2:in1"; in snd_byt_rt5640_mc_probe()
1890 "cfg-spk:%s cfg-mic:%s aif:%d%s%s", cfg_spk, in snd_byt_rt5640_mc_probe()
1896 "bytcr-rt5640-%s-spk-%s-mic", spk_type, in snd_byt_rt5640_mc_probe()
1902 platform_name = mach->mach_params.platform; in snd_byt_rt5640_mc_probe()
1922 dev->driver->pm = &snd_soc_pm_ops; in snd_byt_rt5640_mc_probe()
1933 device_remove_software_node(priv->codec_dev); in snd_byt_rt5640_mc_probe()
1936 acpi_dev_remove_driver_gpios(ACPI_COMPANION(priv->codec_dev)); in snd_byt_rt5640_mc_probe()
1938 put_device(priv->codec_dev); in snd_byt_rt5640_mc_probe()
1948 acpi_dev_remove_driver_gpios(ACPI_COMPANION(priv->codec_dev)); in snd_byt_rt5640_mc_remove()
1950 device_remove_software_node(priv->codec_dev); in snd_byt_rt5640_mc_remove()
1951 put_device(priv->codec_dev); in snd_byt_rt5640_mc_remove()