Lines Matching +full:mic +full:- +full:int
1 // SPDX-License-Identifier: GPL-2.0-only
3 * bytcr_wm5102.c - ASoc Machine driver for Intel Baytrail platforms with a
8 * Copyright (C) 2014-2020 Intel Corp
27 #include <sound/soc-acpi.h>
29 #include "../atom/sst-atom-controls.h"
38 int mclk_freq;
51 /* Note these values are pre-shifted for easy use of setting quirks */
59 static int quirk_override = -1;
60 module_param_named(quirk, quirk_override, int, 0444);
61 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
99 static int byt_wm5102_spkvdd_power_event(struct snd_soc_dapm_widget *w,
100 struct snd_kcontrol *kcontrol, int event)
102 struct snd_soc_card *card = w->dapm->card;
105 gpiod_set_value_cansleep(priv->spkvdd_en_gpio,
111 static int byt_wm5102_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai, int rate)
113 struct snd_soc_component *codec_component = codec_dai->component;
114 struct byt_wm5102_private *priv = snd_soc_card_get_drvdata(codec_component->card);
115 int sr_mult = ((rate % 4000) == 0) ?
118 int ret;
126 priv->mclk_freq, rate * sr_mult);
128 dev_err(codec_component->dev, "Error setting PLL: %d\n", ret);
136 dev_err(codec_component->dev, "Error setting SYSCLK: %d\n", ret);
143 dev_err(codec_component->dev, "Error setting clock: %d\n", ret);
150 static int platform_clock_control(struct snd_soc_dapm_widget *w,
151 struct snd_kcontrol *k, int event)
153 struct snd_soc_dapm_context *dapm = w->dapm;
154 struct snd_soc_card *card = dapm->card;
157 int ret;
159 codec_dai = snd_soc_card_get_codec_dai(card, "wm5102-aif1");
161 dev_err(card->dev, "Error codec DAI not found\n");
162 return -EIO;
166 ret = clk_prepare_enable(priv->mclk);
168 dev_err(card->dev, "Error enabling MCLK: %d\n", ret);
173 dev_err(card->dev, "Error setting codec sysclk: %d\n", ret);
178 * The WM5102 has a separate 32KHz clock for jack-detect
180 * platform clock which is the source-clock for the PLL.
183 clk_disable_unprepare(priv->mclk);
191 SND_SOC_DAPM_MIC("Headset Mic", NULL),
192 SND_SOC_DAPM_MIC("Internal Mic", NULL),
205 {"Headset Mic", NULL, "Platform Clock"},
206 {"Internal Mic", NULL, "Platform Clock"},
215 * is connected, as the MICBIAS is applied after the CTIA/OMTP cross-switch.
217 {"Headset Mic", NULL, "MICBIAS1"},
218 {"Headset Mic", NULL, "MICBIAS2"},
219 {"Internal Mic", NULL, "MICBIAS3"},
251 {"IN3L", NULL, "Internal Mic"},
252 {"IN1L", NULL, "Headset Mic"},
256 {"IN1L", NULL, "Internal Mic"},
257 {"IN2L", NULL, "Headset Mic"},
262 SOC_DAPM_PIN_SWITCH("Headset Mic"),
263 SOC_DAPM_PIN_SWITCH("Internal Mic"),
274 .pin = "Headset Mic",
283 static int byt_wm5102_init(struct snd_soc_pcm_runtime *runtime)
285 struct snd_soc_card *card = runtime->card;
287 struct snd_soc_component *component = snd_soc_rtd_to_codec(runtime, 0)->component;
289 int ret, jack_type, num_routes = 0;
291 card->dapm.idle_bias = false;
296 dev_err(card->dev, "Error adding card controls: %d\n", ret);
310 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
324 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
335 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
340 priv->mclk_freq = 19200000;
342 priv->mclk_freq = 25000000;
352 ret = clk_prepare_enable(priv->mclk);
354 clk_disable_unprepare(priv->mclk);
356 ret = clk_set_rate(priv->mclk, priv->mclk_freq);
358 dev_err(card->dev, "Error setting MCLK rate: %d\n", ret);
365 &priv->jack, byt_wm5102_pins,
368 dev_err(card->dev, "Error creating jack: %d\n", ret);
372 snd_soc_component_set_jack(component, &priv->jack, NULL);
377 static int byt_wm5102_codec_fixup(struct snd_soc_pcm_runtime *rtd,
384 int ret, bits;
387 rate->min = 48000;
388 rate->max = 48000;
389 channels->min = 2;
390 channels->max = 2;
393 /* set SSP2 to 24-bit */
397 /* set SSP0 to 16-bit */
404 * with explicit setting to I2S 2ch 16-bit. The word length is set with
412 dev_err(rtd->dev, "Error setting format to I2S: %d\n", ret);
418 dev_err(rtd->dev, "Error setting I2S config: %d\n", ret);
425 static int byt_wm5102_aif1_startup(struct snd_pcm_substream *substream)
427 return snd_pcm_hw_constraint_single(substream->runtime,
439 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
442 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
445 DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port")));
450 * Note there is no need to overwrite the codec-name as is done in
451 * other bytcr machine drivers, because the codec is a MFD child-dev.
453 "wm5102-codec",
454 "wm5102-aif1")));
457 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
470 .name = "Deep-Buffer Audio Port",
471 .stream_name = "Deep-Buffer Audio",
482 * Yet its name is always kept as "SSP2-Codec" because the SOF
483 * tplg files hardcode "SSP2-Codec" even in byt-foo-ssp0.tplg.
485 .name = "SSP2-Codec",
497 #define SOF_CARD_NAME "bytcht wm5102" /* card name will be 'sof-bytcht wm5102' */
500 #define CARD_NAME "bytcr-wm5102"
515 static char byt_wm5102_components[64]; /* = "cfg-spk:* cfg-int-mic:* cfg-hs-mic:* ..." */
517 static int snd_byt_wm5102_mc_probe(struct platform_device *pdev)
523 struct device *dev = &pdev->dev;
529 int dai_index = 0;
531 int i, ret;
535 return -ENOMEM;
538 priv->mclk = devm_clk_get(dev, "pmc_plt_clk_3");
539 if (IS_ERR(priv->mclk))
540 return dev_err_probe(dev, PTR_ERR(priv->mclk), "getting pmc_plt_clk_3\n");
544 * 1. Get codec-device-name
545 * 2. Get codec-device
546 * 3. Get GPIO from codec-device
548 mach = dev->platform_data;
549 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
551 snprintf(codec_name, sizeof(codec_name), "spi-%s", acpi_dev_name(adev));
555 strscpy(codec_name, "spi-wm5102", sizeof(codec_name));
560 return -EPROBE_DEFER;
563 priv->spkvdd_en_gpio = gpiod_get(codec_dev, "wlf,spkvdd-ena", GPIOD_OUT_LOW);
566 if (IS_ERR(priv->spkvdd_en_gpio)) {
567 ret = PTR_ERR(priv->spkvdd_en_gpio);
569 * The spkvdd gpio-lookup is registered by: drivers/mfd/arizona-spi.c,
570 * so -ENOENT means that arizona-spi hasn't probed yet.
572 if (ret == -ENOENT)
573 ret = -EPROBE_DEFER;
575 return dev_err_probe(dev, ret, "getting spkvdd-GPIO\n");
588 if (quirk_override != -1) {
596 "cfg-spk:%s cfg-intmic:%s cfg-hsmic:%s",
605 !strcmp(byt_wm5102_dais[i].codecs->name,
606 "wm5102-codec")) {
614 platform_name = mach->mach_params.platform;
621 byt_wm5102_dais[dai_index].cpus->dai_name = "ssp2-port";
623 /* set card and driver name and pm-ops */
628 dev->driver->pm = &snd_soc_pm_ops;
645 gpiod_put(priv->spkvdd_en_gpio);
654 gpiod_put(priv->spkvdd_en_gpio);