Lines Matching +full:clock +full:- +full:error +full:- +full:detect

1 // SPDX-License-Identifier: GPL-2.0-only
3 * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
29 #include <sound/soc-acpi.h>
30 #include <dt-bindings/sound/rt5640.h>
32 #include "../atom/sst-atom-controls.h"
33 #include "../common/soc-intel-quirks.h"
71 #define BYT_RT5640_DIFF_MIC BIT(18) /* default is single-ended */
90 /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
103 static int quirk_override = -1;
105 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
140 dev_info(dev, "quirk realtek,jack-detect-source %ld\n", in log_quirks()
142 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n", in log_quirks()
144 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n", in log_quirks()
176 …dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2… in log_quirks()
227 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret); in byt_rt5640_prepare_and_enable_pll1()
234 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret); in byt_rt5640_prepare_and_enable_pll1()
241 #define BYT_CODEC_DAI1 "rt5640-aif1"
242 #define BYT_CODEC_DAI2 "rt5640-aif2"
246 struct snd_soc_card *card = dapm->card; in byt_rt5640_get_codec_dai()
253 dev_err(card->dev, "Error codec dai not found\n"); in byt_rt5640_get_codec_dai()
261 struct snd_soc_dapm_context *dapm = w->dapm; in platform_clock_control()
262 struct snd_soc_card *card = dapm->card; in platform_clock_control()
269 return -EIO; in platform_clock_control()
273 ret = clk_prepare_enable(priv->mclk); in platform_clock_control()
275 dev_err(card->dev, in platform_clock_control()
283 * Set codec clock source to internal clock before in platform_clock_control()
284 * turning off the platform clock. Codec needs clock in platform_clock_control()
292 clk_disable_unprepare(priv->mclk); in platform_clock_control()
297 dev_err(card->dev, "can't set codec sysclk: %d\n", ret); in platform_clock_control()
314 * On devices which use line-out as a second headphones output, in byt_rt5640_event_lineout()
315 * the codec's GPIO1 pin is used to enable an external HP-amp. in byt_rt5640_event_lineout()
318 codec_dai = byt_rt5640_get_codec_dai(w->dapm); in byt_rt5640_event_lineout()
320 return -EIO; in byt_rt5640_event_lineout()
325 snd_soc_component_update_bits(codec_dai->component, RT5640_GPIO_CTRL3, in byt_rt5640_event_lineout()
338 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
344 {"Headphone", NULL, "Platform Clock"},
345 {"Headset Mic", NULL, "Platform Clock"},
353 {"Internal Mic", NULL, "Platform Clock"},
358 {"Internal Mic", NULL, "Platform Clock"},
363 {"Internal Mic", NULL, "Platform Clock"},
369 {"Internal Mic", NULL, "Platform Clock"},
375 {"Headset Mic 2", NULL, "Platform Clock"},
417 {"Speaker", NULL, "Platform Clock"},
425 {"Speaker", NULL, "Platform Clock"},
431 {"Line Out", NULL, "Platform Clock"},
458 /* The 2nd headset jack uses lineout with an external HP-amp */
469 .name = "hp-detect",
476 .name = "hp2-detect",
487 { "hp-detect-gpios", &acpi_gpio0, 1, },
488 { "headset-mic-detect-gpios", &acpi_gpio1, 1, },
489 { "hp2-detect-gpios", &acpi_gpio2, 1, },
502 mic_status = gpiod_get_value_cansleep(priv->hsmic_detect); in byt_rt5640_hp_elitepad_1000g2_jack1_check()
536 { /* Acer Iconia Tab 8 W1-810 */
539 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
564 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
648 DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
664 DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
721 DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
729 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
739 { /* HP Pavilion x2 10-k0XX, 10-n0XX */
741 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
751 { /* HP Pavilion x2 10-p0XX */
754 DMI_MATCH(DMI_PRODUCT_NAME, "HP x2 Detachable 10-p0XX"),
764 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
809 { /* Lenovo Miix 3-830 */
812 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 3-830"),
843 { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
866 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
918 { /* Point of View Mobii TAB-P800W (V2.0) */
935 { /* Point of View Mobii TAB-P800W (V2.1) */
952 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
992 { /* Toshiba Satellite Click Mini L9W-B */
995 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
1004 { /* Toshiba Encore WT8-A */
1007 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
1016 { /* Toshiba Encore WT10-A */
1019 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
1042 { /* Catch-all for generic Insyde tablets, must be last */
1068 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin", in byt_rt5640_add_codec_device_props()
1072 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin", in byt_rt5640_add_codec_device_props()
1078 PROPERTY_ENTRY_BOOL("realtek,in1-differential"); in byt_rt5640_add_codec_device_props()
1083 PROPERTY_ENTRY_BOOL("realtek,in3-differential"); in byt_rt5640_add_codec_device_props()
1089 "realtek,jack-detect-source", in byt_rt5640_add_codec_device_props()
1093 "realtek,over-current-threshold-microamp", in byt_rt5640_add_codec_device_props()
1097 "realtek,over-current-scale-factor", in byt_rt5640_add_codec_device_props()
1102 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted"); in byt_rt5640_add_codec_device_props()
1119 struct snd_soc_card *card = runtime->card; in byt_rt5640_init()
1121 struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component; in byt_rt5640_init()
1126 card->dapm.idle_bias_off = true; in byt_rt5640_init()
1128 /* Start with RC clk for jack-detect (we disable MCLK below) */ in byt_rt5640_init()
1145 dev_err(card->dev, "unable to add card controls\n"); in byt_rt5640_init()
1168 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); in byt_rt5640_init()
1173 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1181 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1185 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1189 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1193 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1201 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1205 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1213 ret = snd_soc_dapm_add_routes(&card->dapm, in byt_rt5640_init()
1222 * The firmware might enable the clock at in byt_rt5640_init()
1224 * be reflected in the enable clock register). in byt_rt5640_init()
1225 * To change the rate we must disable the clock in byt_rt5640_init()
1227 * clock framework restrictions that do not allow in byt_rt5640_init()
1228 * to disable a clock that has not been enabled, in byt_rt5640_init()
1229 * we need to enable the clock first. in byt_rt5640_init()
1231 ret = clk_prepare_enable(priv->mclk); in byt_rt5640_init()
1233 clk_disable_unprepare(priv->mclk); in byt_rt5640_init()
1236 ret = clk_set_rate(priv->mclk, 25000000); in byt_rt5640_init()
1238 ret = clk_set_rate(priv->mclk, 19200000); in byt_rt5640_init()
1241 dev_err(card->dev, "unable to set MCLK rate\n"); in byt_rt5640_init()
1249 &priv->jack, rt5640_pins, in byt_rt5640_init()
1252 dev_err(card->dev, "Jack creation failed %d\n", ret); in byt_rt5640_init()
1255 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, in byt_rt5640_init()
1257 snd_soc_component_set_jack(component, &priv->jack, NULL); in byt_rt5640_init()
1263 &priv->jack, rt5640_pins, in byt_rt5640_init()
1270 &priv->jack2, rt5640_pins2, in byt_rt5640_init()
1276 rt5640_jack_gpio.gpiod_dev = priv->codec_dev; in byt_rt5640_init()
1278 ret = snd_soc_jack_add_gpios(&priv->jack, 1, &rt5640_jack_gpio); in byt_rt5640_init()
1284 rt5640_jack2_gpio.gpiod_dev = priv->codec_dev; in byt_rt5640_init()
1286 ret = snd_soc_jack_add_gpios(&priv->jack2, 1, &rt5640_jack2_gpio); in byt_rt5640_init()
1288 snd_soc_jack_free_gpios(&priv->jack, 1, &rt5640_jack_gpio); in byt_rt5640_init()
1298 struct snd_soc_card *card = runtime->card; in byt_rt5640_exit()
1302 snd_soc_jack_free_gpios(&priv->jack2, 1, &rt5640_jack2_gpio); in byt_rt5640_exit()
1303 snd_soc_jack_free_gpios(&priv->jack, 1, &rt5640_jack_gpio); in byt_rt5640_exit()
1317 rate->min = rate->max = 48000; in byt_rt5640_codec_fixup()
1318 channels->min = channels->max = 2; in byt_rt5640_codec_fixup()
1322 /* set SSP0 to 16-bit */ in byt_rt5640_codec_fixup()
1326 /* set SSP2 to 24-bit */ in byt_rt5640_codec_fixup()
1341 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret); in byt_rt5640_codec_fixup()
1347 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret); in byt_rt5640_codec_fixup()
1356 return snd_pcm_hw_constraint_single(substream->runtime, in byt_rt5640_aif1_startup()
1372 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1375 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1379 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1382 /* overwritten with HID */ "i2c-10EC5640:00",
1383 /* changed w/ quirk */ "rt5640-aif1")));
1386 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1400 .name = "Deep-Buffer Audio Port",
1401 .stream_name = "Deep-Buffer Audio",
1410 .name = "SSP2-Codec",
1428 static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
1430 static char byt_rt5640_components[64]; /* = "cfg-spk:* cfg-mic:* ..." */
1440 if (!strcmp(component->name, byt_rt5640_codec_name)) { in byt_rt5640_suspend()
1441 dev_dbg(component->dev, "disabling jack detect before suspend\n"); in byt_rt5640_suspend()
1459 if (!strcmp(component->name, byt_rt5640_codec_name)) { in byt_rt5640_resume()
1460 dev_dbg(component->dev, "re-enabling jack detect after resume\n"); in byt_rt5640_resume()
1461 snd_soc_component_set_jack(component, &priv->jack, NULL); in byt_rt5640_resume()
1470 #define SOF_CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1473 #define CARD_NAME "bytcr-rt5640"
1496 struct device *dev = &pdev->dev; in snd_byt_rt5640_mc_probe()
1514 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in snd_byt_rt5640_mc_probe()
1516 return -ENOMEM; in snd_byt_rt5640_mc_probe()
1519 byt_rt5640_card.dev = &pdev->dev; in snd_byt_rt5640_mc_probe()
1520 mach = byt_rt5640_card.dev->platform_data; in snd_byt_rt5640_mc_probe()
1525 if (!strcmp(byt_rt5640_dais[i].codecs->name, in snd_byt_rt5640_mc_probe()
1526 "i2c-10EC5640:00")) { in snd_byt_rt5640_mc_probe()
1533 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1); in snd_byt_rt5640_mc_probe()
1536 "i2c-%s", acpi_dev_name(adev)); in snd_byt_rt5640_mc_probe()
1537 put_device(&adev->dev); in snd_byt_rt5640_mc_probe()
1538 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name; in snd_byt_rt5640_mc_probe()
1540 dev_err(&pdev->dev, "Error cannot find '%s' dev\n", mach->id); in snd_byt_rt5640_mc_probe()
1541 return -ENXIO; in snd_byt_rt5640_mc_probe()
1549 if (mach->mach_params.acpi_ipc_irq_index == 0) in snd_byt_rt5640_mc_probe()
1559 * with the codec driver/pdata are non-existent in snd_byt_rt5640_mc_probe()
1564 /* format specified: 2 64-bit integers */ in snd_byt_rt5640_mc_probe()
1579 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id, in snd_byt_rt5640_mc_probe()
1583 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n"); in snd_byt_rt5640_mc_probe()
1586 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n"); in snd_byt_rt5640_mc_probe()
1589 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n"); in snd_byt_rt5640_mc_probe()
1595 /* no BIOS indications, assume SSP0-AIF2 connection */ in snd_byt_rt5640_mc_probe()
1599 /* change defaults for Baytrail-CR capture */ in snd_byt_rt5640_mc_probe()
1611 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data; in snd_byt_rt5640_mc_probe()
1612 if (quirk_override != -1) { in snd_byt_rt5640_mc_probe()
1613 dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n", in snd_byt_rt5640_mc_probe()
1620 return -EPROBE_DEFER; in snd_byt_rt5640_mc_probe()
1621 priv->codec_dev = get_device(codec_dev); in snd_byt_rt5640_mc_probe()
1624 acpi_dev_add_driver_gpios(ACPI_COMPANION(priv->codec_dev), in snd_byt_rt5640_mc_probe()
1627 priv->hsmic_detect = devm_fwnode_gpiod_get(&pdev->dev, codec_dev->fwnode, in snd_byt_rt5640_mc_probe()
1628 "headset-mic-detect", GPIOD_IN, in snd_byt_rt5640_mc_probe()
1629 "headset-mic-detect"); in snd_byt_rt5640_mc_probe()
1630 if (IS_ERR(priv->hsmic_detect)) { in snd_byt_rt5640_mc_probe()
1631 ret_val = PTR_ERR(priv->hsmic_detect); in snd_byt_rt5640_mc_probe()
1632 dev_err_probe(&pdev->dev, ret_val, "getting hsmic-detect GPIO\n"); in snd_byt_rt5640_mc_probe()
1642 log_quirks(&pdev->dev); in snd_byt_rt5640_mc_probe()
1646 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2"; in snd_byt_rt5640_mc_probe()
1654 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port"; in snd_byt_rt5640_mc_probe()
1657 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); in snd_byt_rt5640_mc_probe()
1658 if (IS_ERR(priv->mclk)) { in snd_byt_rt5640_mc_probe()
1659 ret_val = PTR_ERR(priv->mclk); in snd_byt_rt5640_mc_probe()
1661 dev_err(&pdev->dev, in snd_byt_rt5640_mc_probe()
1666 * Fall back to bit clock usage for -ENOENT (clock not in snd_byt_rt5640_mc_probe()
1668 * for all other errors, including -EPROBE_DEFER in snd_byt_rt5640_mc_probe()
1670 if (ret_val != -ENOENT) in snd_byt_rt5640_mc_probe()
1689 lineout_string = " cfg-hp2:lineout"; in snd_byt_rt5640_mc_probe()
1691 lineout_string = " cfg-lineout:2"; in snd_byt_rt5640_mc_probe()
1695 headset2_string = " cfg-hs2:in1"; in snd_byt_rt5640_mc_probe()
1698 "cfg-spk:%d cfg-mic:%s aif:%d%s%s", cfg_spk, in snd_byt_rt5640_mc_probe()
1704 "bytcr-rt5640-%s-spk-%s-mic", spk_type, in snd_byt_rt5640_mc_probe()
1710 platform_name = mach->mach_params.platform; in snd_byt_rt5640_mc_probe()
1717 sof_parent = snd_soc_acpi_sof_parent(&pdev->dev); in snd_byt_rt5640_mc_probe()
1730 dev->driver->pm = &snd_soc_pm_ops; in snd_byt_rt5640_mc_probe()
1732 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card); in snd_byt_rt5640_mc_probe()
1735 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n", in snd_byt_rt5640_mc_probe()
1743 device_remove_software_node(priv->codec_dev); in snd_byt_rt5640_mc_probe()
1746 acpi_dev_remove_driver_gpios(ACPI_COMPANION(priv->codec_dev)); in snd_byt_rt5640_mc_probe()
1748 put_device(priv->codec_dev); in snd_byt_rt5640_mc_probe()
1758 acpi_dev_remove_driver_gpios(ACPI_COMPANION(priv->codec_dev)); in snd_byt_rt5640_mc_remove()
1760 device_remove_software_node(priv->codec_dev); in snd_byt_rt5640_mc_remove()
1761 put_device(priv->codec_dev); in snd_byt_rt5640_mc_remove()