Lines Matching +full:headset +full:- +full:detect +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0+
12 #include <linux/input-event-codes.h>
17 #include <sound/soc-dapm.h>
47 .pin = "Headset Mic",
77 struct midas_priv *priv = snd_soc_card_get_drvdata(codec->card);
81 if (!gpiod_get_value_cansleep(priv->gpio_headset_detect))
84 /* Enable headset mic bias regulator so that the ADC reading works */
85 ret = snd_soc_dapm_force_enable_pin(dapm, "headset-mic-bias");
87 pr_err("%s: Failed to enable headset mic bias regulator (%d), assuming headphones\n",
96 ret = iio_read_channel_processed(priv->adc_headset_detect, &adc);
105 jack_type = snd_soc_jack_get_type(&priv->headset_jack, adc);
108 ret = snd_soc_dapm_disable_pin(dapm, "headset-mic-bias");
110 pr_err("%s: Failed to disable headset mic bias regulator (%d)\n",
120 struct midas_priv *priv = snd_soc_card_get_drvdata(codec->card);
123 if (!gpiod_get_value_cansleep(priv->gpio_headset_key))
127 if (!(priv->headset_jack.status & SND_JACK_MICROPHONE))
130 ret = iio_read_channel_processed(priv->adc_headset_detect, &adc);
132 pr_err("%s: Failed to read ADC (%d), can't detect key type\n",
150 .name = "Headset Jack",
156 .name = "Headset Key",
165 struct snd_soc_card *card = rtd->card;
172 rate = priv->fll1_rate;
180 if (rate != priv->fll1_rate && priv->fll1_rate) {
185 dev_err(card->dev, "Unable to switch to MCLK2: %d\n", ret);
193 dev_err(card->dev, "Failed to set FLL1 rate: %d\n", ret);
196 priv->fll1_rate = rate;
199 priv->fll1_rate, SND_SOC_CLOCK_IN);
201 dev_err(card->dev, "Failed to set SYSCLK source: %d\n", ret);
208 dev_err(card->dev, "Failed to set OPCLK source: %d\n", ret);
217 struct snd_soc_card *card = rtd->card;
225 dev_err(card->dev, "Unable to switch to MCLK2: %d\n", ret);
231 dev_err(card->dev, "Unable to stop FLL1: %d\n", ret);
235 priv->fll1_rate = 0;
266 struct snd_soc_component *codec = snd_soc_dapm_to_component(w->dapm);
288 struct snd_soc_card *card = w->dapm->card;
291 if (!priv->gpio_fm_sel)
296 gpiod_set_value_cansleep(priv->gpio_fm_sel, 1);
299 gpiod_set_value_cansleep(priv->gpio_fm_sel, 0);
309 struct snd_soc_card *card = w->dapm->card;
312 if (!priv->gpio_lineout_sel)
317 gpiod_set_value_cansleep(priv->gpio_lineout_sel, 1);
320 gpiod_set_value_cansleep(priv->gpio_lineout_sel, 0);
338 SOC_DAPM_PIN_SWITCH("Headset Mic"),
355 SND_SOC_DAPM_MIC("Headset Mic", NULL),
356 SND_SOC_DAPM_REGULATOR_SUPPLY("headset-mic-bias", 0, 0),
358 SND_SOC_DAPM_REGULATOR_SUPPLY("mic-bias", 0, 0),
360 SND_SOC_DAPM_REGULATOR_SUPPLY("submic-bias", 0, 0),
363 /* Default routing; supplemented by audio-routing DT property */
366 {"Main Mic", NULL, "mic-bias"},
367 {"Sub Mic", NULL, "submic-bias"},
368 {"Headset Mic", NULL, "headset-mic-bias"},
376 &card->dai_link[0]);
379 if (dapm->dev != aif1_dai->dev)
397 &card->dai_link[0]);
406 dev_err(aif1_dai->dev, "Failed to switch to MCLK2: %d\n", ret);
410 if (!priv->gpio_headset_detect) {
411 ret = snd_soc_card_jack_new_pins(card, "Headset",
416 &priv->headset_jack,
422 wm8958_mic_detect(aif1_dai->component, &priv->headset_jack,
425 /* Some devices (n8000, t310) use a GPIO to detect the jack. */
426 ret = snd_soc_card_jack_new_pins(card, "Headset",
429 &priv->headset_jack,
433 dev_err(card->dev,
434 "Failed to set up headset pins: %d\n", ret);
438 ret = snd_soc_jack_add_zones(&priv->headset_jack,
442 dev_err(card->dev,
443 "Failed to set up headset zones: %d\n", ret);
447 headset_gpio[0].data = aif1_dai->component;
448 headset_gpio[0].desc = priv->gpio_headset_detect;
450 headset_gpio[1].data = aif1_dai->component;
451 headset_gpio[1].desc = priv->gpio_headset_key;
453 snd_jack_set_key(priv->headset_jack.jack,
455 snd_jack_set_key(priv->headset_jack.jack,
457 snd_jack_set_key(priv->headset_jack.jack,
460 ret = snd_soc_jack_add_gpios(&priv->headset_jack,
464 dev_err(card->dev,
465 "Failed to set up headset jack GPIOs: %d\n",
516 .name = "midas-audio",
521 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8994-aif1")),
526 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8994-aif2")),
531 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8994-aif3")),
577 struct device *dev = &pdev->dev;
587 return -ENOMEM;
590 card->dev = dev;
592 priv->gpio_fm_sel = devm_gpiod_get_optional(dev, "fm-sel", GPIOD_OUT_HIGH);
593 if (IS_ERR(priv->gpio_fm_sel))
594 return dev_err_probe(dev, PTR_ERR(priv->gpio_fm_sel),
597 priv->gpio_lineout_sel = devm_gpiod_get_optional(dev, "lineout-sel",
599 if (IS_ERR(priv->gpio_lineout_sel))
600 return dev_err_probe(dev, PTR_ERR(priv->gpio_lineout_sel),
603 priv->gpio_headset_detect = devm_gpiod_get_optional(dev,
604 "headset-detect", GPIOD_IN);
605 if (IS_ERR(priv->gpio_headset_detect))
606 return dev_err_probe(dev, PTR_ERR(priv->gpio_headset_detect),
607 "Failed to get headset jack detect GPIO\n");
609 if (priv->gpio_headset_detect) {
610 priv->adc_headset_detect = devm_iio_channel_get(dev,
611 "headset-detect");
612 if (IS_ERR(priv->adc_headset_detect))
614 PTR_ERR(priv->adc_headset_detect),
617 ret = iio_get_channel_type(priv->adc_headset_detect,
626 return -EINVAL;
629 priv->gpio_headset_key = devm_gpiod_get(dev, "headset-key",
631 if (IS_ERR(priv->gpio_headset_key))
633 PTR_ERR(priv->gpio_headset_key),
634 "Failed to get headset key GPIO\n");
636 ret = of_property_read_u32_array(dev->of_node,
637 "samsung,headset-4pole-threshold-microvolt",
641 dev_err(dev, "Failed to get 4-pole jack detection threshold\n");
646 dev_err(dev, "Invalid 4-pole jack detection threshold value\n");
647 return -EINVAL;
656 ret = of_property_read_u32_array(dev->of_node,
657 "samsung,headset-button-threshold-microvolt",
661 dev_err(dev, "Failed to get headset button detection threshold\n");
667 dev_err(dev, "Invalid headset button detection threshold value\n");
668 return -EINVAL;
673 dev_err(dev, "Invalid headset button detection threshold value\n");
674 return -EINVAL;
683 (button_threshold[i+1] - 1);
693 ret = snd_soc_of_parse_audio_routing(card, "audio-routing");
696 ret = snd_soc_of_parse_audio_routing(card, "samsung,audio-routing");
703 cpu = of_get_child_by_name(dev->of_node, "cpu");
705 return -EINVAL;
707 codec = of_get_child_by_name(dev->of_node, "codec");
710 return -EINVAL;
713 cpu_dai_node = of_parse_phandle(cpu, "sound-dai", 0);
716 dev_err(dev, "parsing cpu/sound-dai failed\n");
718 return -EINVAL;
721 codec_dai_node = of_parse_phandle(codec, "sound-dai", 0);
724 dev_err(dev, "audio-codec property invalid/missing\n");
725 ret = -EINVAL;
730 dai_link->codecs->of_node = codec_dai_node;
731 dai_link->cpus->of_node = cpu_dai_node;
732 dai_link->platforms->of_node = cpu_dai_node;
758 { .compatible = "samsung,midas-audio" },
765 .name = "midas-audio",