Lines Matching +full:output +full:- +full:charge +full:- +full:current
1 // SPDX-License-Identifier: GPL-2.0-only
3 * es8316.c -- es8316 ALSA SoC audio driver
6 * Authors: David Yang <yangxiaohua@everest-semi.com>,
21 #include <sound/soc-dapm.h>
51 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(dac_vol_tlv, -9600, 50, 1);
52 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_vol_tlv, -9600, 50, 1);
53 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_max_gain_tlv, -650, 150, 0);
54 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_min_gain_tlv, -1200, 150, 0);
55 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_target_tlv, -1650, 150, 0);
57 0, 4, TLV_DB_SCALE_ITEM(-1200, 150, 0),
58 8, 11, TLV_DB_SCALE_ITEM(-450, 150, 0),
62 0, 0, TLV_DB_SCALE_ITEM(-350, 0, 0),
71 0, 0, TLV_DB_SCALE_ITEM(-4800, 0, 0),
72 1, 3, TLV_DB_SCALE_ITEM(-2400, 1200, 0),
76 { "Constant PGA Gain", "Mute ADC Output" };
132 "lin1-rin1",
133 "lin2-rin2",
134 "lin1-rin1 with 20db Boost",
135 "lin2-rin2 with 20db Boost"
162 "lin1-rin1",
163 "lin2-rin2",
164 "lin-rin with Boost",
165 "lin-rin with Boost and PGA"
180 /* headphone Output Mixer */
240 /* Headphone Output Side */
256 SND_SOC_DAPM_OUT_DRV("Left Headphone Charge Pump", ES8316_CPHP_OUTEN,
258 SND_SOC_DAPM_OUT_DRV("Right Headphone Charge Pump", ES8316_CPHP_OUTEN,
260 SND_SOC_DAPM_SUPPLY("Headphone Charge Pump", ES8316_CPHP_PDN2,
262 SND_SOC_DAPM_SUPPLY("Headphone Charge Pump Clock", ES8316_CLKMGR_CLKSW,
272 * be explicitly unset in order to enable HP output
292 {"Differential Mux", "lin1-rin1", "MIC1"},
293 {"Differential Mux", "lin2-rin2", "MIC2"},
322 {"Left Headphone Mux", "lin-rin with Boost and PGA", "Line input PGA"},
323 {"Right Headphone Mux", "lin-rin with Boost and PGA", "Line input PGA"},
334 {"Left Headphone Charge Pump", NULL, "Left Headphone Mixer Out"},
335 {"Right Headphone Charge Pump", NULL, "Right Headphone Mixer Out"},
337 {"Left Headphone Charge Pump", NULL, "Headphone Charge Pump"},
338 {"Right Headphone Charge Pump", NULL, "Headphone Charge Pump"},
340 {"Left Headphone Charge Pump", NULL, "Headphone Charge Pump Clock"},
341 {"Right Headphone Charge Pump", NULL, "Headphone Charge Pump Clock"},
343 {"Left Headphone Driver", NULL, "Left Headphone Charge Pump"},
344 {"Right Headphone Driver", NULL, "Right Headphone Charge Pump"},
361 struct snd_soc_component *component = codec_dai->component; in es8316_set_dai_sysclk()
366 es8316->sysclk = freq; in es8316_set_dai_sysclk()
369 es8316->sysclk_constraints.list = NULL; in es8316_set_dai_sysclk()
370 es8316->sysclk_constraints.count = 0; in es8316_set_dai_sysclk()
375 ret = clk_set_rate(es8316->mclk, freq); in es8316_set_dai_sysclk()
386 es8316->allowed_rates[count++] = freq / ratio; in es8316_set_dai_sysclk()
389 es8316->sysclk_constraints.list = es8316->allowed_rates; in es8316_set_dai_sysclk()
390 es8316->sysclk_constraints.count = count; in es8316_set_dai_sysclk()
398 struct snd_soc_component *component = codec_dai->component; in es8316_set_dai_fmt()
408 dev_err(component->dev, "Codec driver only supports I2S format\n"); in es8316_set_dai_fmt()
409 return -EINVAL; in es8316_set_dai_fmt()
427 return -EINVAL; in es8316_set_dai_fmt()
447 struct snd_soc_component *component = dai->component; in es8316_pcm_startup()
450 if (es8316->sysclk_constraints.list) in es8316_pcm_startup()
451 snd_pcm_hw_constraint_list(substream->runtime, 0, in es8316_pcm_startup()
453 &es8316->sysclk_constraints); in es8316_pcm_startup()
462 struct snd_soc_component *component = dai->component; in es8316_pcm_hw_params()
473 if (es8316->sysclk % ratio != 0) in es8316_pcm_hw_params()
475 if (es8316->sysclk / ratio == params_rate(params)) in es8316_pcm_hw_params()
479 return -EINVAL; in es8316_pcm_hw_params()
480 lrck_divider = es8316->sysclk / params_rate(params); in es8316_pcm_hw_params()
500 return -EINVAL; in es8316_pcm_hw_params()
517 snd_soc_component_update_bits(dai->component, ES8316_DAC_SET1, 0x20, in es8316_mute()
585 struct snd_soc_component *comp = es8316->component; in es8316_irq()
588 mutex_lock(&es8316->lock); in es8316_irq()
590 regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags); in es8316_irq()
592 goto out; /* Powered-down / reset */ in es8316_irq()
595 if (!es8316->jack) in es8316_irq()
598 if (es8316->jd_inverted) in es8316_irq()
601 dev_dbg(comp->dev, "gpio flags %#04x\n", flags); in es8316_irq()
604 if (es8316->jack->status & SND_JACK_MICROPHONE) in es8316_irq()
607 if (es8316->jack->status & SND_JACK_HEADPHONE) { in es8316_irq()
608 snd_soc_jack_report(es8316->jack, 0, in es8316_irq()
610 dev_dbg(comp->dev, "jack unplugged\n"); in es8316_irq()
612 } else if (!(es8316->jack->status & SND_JACK_HEADPHONE)) { in es8316_irq()
615 regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags); in es8316_irq()
616 if (es8316->jd_inverted) in es8316_irq()
618 dev_dbg(comp->dev, "gpio flags %#04x\n", flags); in es8316_irq()
624 snd_soc_jack_report(es8316->jack, in es8316_irq()
627 /* Keep mic-gnd-short detection on for button press */ in es8316_irq()
630 snd_soc_jack_report(es8316->jack, in es8316_irq()
633 /* No longer need mic-gnd-short detection */ in es8316_irq()
636 } else if (es8316->jack->status & SND_JACK_MICROPHONE) { in es8316_irq()
640 snd_soc_jack_report(es8316->jack, 0, SND_JACK_BTN_0); in es8316_irq()
643 snd_soc_jack_report(es8316->jack, in es8316_irq()
650 mutex_unlock(&es8316->lock); in es8316_irq()
660 * Init es8316->jd_inverted here and not in the probe, as we cannot in es8316_enable_jack_detect()
661 * guarantee that the bytchr-es8316 driver, which might set this in es8316_enable_jack_detect()
664 es8316->jd_inverted = device_property_read_bool(component->dev, in es8316_enable_jack_detect()
665 "everest,jack-detect-inverted"); in es8316_enable_jack_detect()
667 mutex_lock(&es8316->lock); in es8316_enable_jack_detect()
669 es8316->jack = jack; in es8316_enable_jack_detect()
671 if (es8316->jack->status & SND_JACK_MICROPHONE) in es8316_enable_jack_detect()
678 mutex_unlock(&es8316->lock); in es8316_enable_jack_detect()
681 enable_irq(es8316->irq); in es8316_enable_jack_detect()
682 es8316_irq(es8316->irq, es8316); in es8316_enable_jack_detect()
689 if (!es8316->jack) in es8316_disable_jack_detect()
692 disable_irq(es8316->irq); in es8316_disable_jack_detect()
694 mutex_lock(&es8316->lock); in es8316_disable_jack_detect()
699 if (es8316->jack->status & SND_JACK_MICROPHONE) { in es8316_disable_jack_detect()
701 snd_soc_jack_report(es8316->jack, 0, SND_JACK_BTN_0); in es8316_disable_jack_detect()
704 es8316->jack = NULL; in es8316_disable_jack_detect()
706 mutex_unlock(&es8316->lock); in es8316_disable_jack_detect()
725 es8316->component = component; in es8316_probe()
727 es8316->mclk = devm_clk_get_optional(component->dev, "mclk"); in es8316_probe()
728 if (IS_ERR(es8316->mclk)) { in es8316_probe()
729 dev_err(component->dev, "unable to get mclk\n"); in es8316_probe()
730 return PTR_ERR(es8316->mclk); in es8316_probe()
732 if (!es8316->mclk) in es8316_probe()
733 dev_warn(component->dev, "assuming static mclk\n"); in es8316_probe()
735 ret = clk_prepare_enable(es8316->mclk); in es8316_probe()
737 dev_err(component->dev, "unable to enable mclk\n"); in es8316_probe()
741 /* Reset codec and enable current state machine */ in es8316_probe()
749 * needed otherwise audio output is silent. in es8316_probe()
755 * but here is a vendor-provided value that improves volume in es8316_probe()
767 clk_disable_unprepare(es8316->mclk); in es8316_remove()
774 regcache_cache_only(es8316->regmap, false); in es8316_resume()
775 regcache_sync(es8316->regmap); in es8316_resume()
784 regcache_cache_only(es8316->regmap, true); in es8316_suspend()
785 regcache_mark_dirty(es8316->regmap); in es8316_suspend()
827 struct device *dev = &i2c_client->dev; in es8316_i2c_probe()
831 es8316 = devm_kzalloc(&i2c_client->dev, sizeof(struct es8316_priv), in es8316_i2c_probe()
834 return -ENOMEM; in es8316_i2c_probe()
838 es8316->regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap); in es8316_i2c_probe()
839 if (IS_ERR(es8316->regmap)) in es8316_i2c_probe()
840 return PTR_ERR(es8316->regmap); in es8316_i2c_probe()
842 es8316->irq = i2c_client->irq; in es8316_i2c_probe()
843 mutex_init(&es8316->lock); in es8316_i2c_probe()
845 ret = devm_request_threaded_irq(dev, es8316->irq, NULL, es8316_irq, in es8316_i2c_probe()
849 dev_warn(dev, "Failed to get IRQ %d: %d\n", es8316->irq, ret); in es8316_i2c_probe()
850 es8316->irq = -ENXIO; in es8316_i2c_probe()
853 return devm_snd_soc_register_component(&i2c_client->dev, in es8316_i2c_probe()
893 MODULE_AUTHOR("David Yang <yangxiaohua@everest-semi.com>");