Lines Matching +full:adc +full:- +full:channel +full:- +full:clk +full:- +full:src
1 // SPDX-License-Identifier: GPL-2.0-only
3 // es8326.c -- es8326 ALSA SoC audio driver
6 // Authors: David Yang <yangxiaohua@everest-semi.com>
9 #include <linux/clk.h>
17 #include <sound/soc-dapm.h>
22 struct clk *mclk;
43 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(dac_vol_tlv, -9550, 50, 0);
44 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_vol_tlv, -9550, 50, 0);
48 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(drc_target_tlv, -3200, 200, 0);
49 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(drc_recovery_tlv, -125, 250, 0);
88 SOC_DOUBLE_R_TLV("ADC Capture Volume", ES8326_ADC1_VOL, ES8326_ADC2_VOL, 0, 0xff, 0,
90 SOC_DOUBLE_TLV("ADC PGA Volume", ES8326_ADC_SCALE, 4, 0, 5, 0, adc_pga_tlv),
91 SOC_SINGLE_TLV("ADC PGA Gain Volume", ES8326_PGAGAIN, 0, 10, 0, adc_analog_pga_tlv),
92 SOC_SINGLE_TLV("ADC Ramp Rate", ES8326_ADC_RAMPRATE, 0, 0x0f, 0, softramp_rate),
108 SND_SOC_DAPM_ADC("ADC L", NULL, SND_SOC_NOPM, 0, 0),
109 SND_SOC_DAPM_ADC("ADC R", NULL, SND_SOC_NOPM, 0, 0),
115 /* ADC Digital Mute */
116 SND_SOC_DAPM_PGA("ADC L1", ES8326_ADC_MUTE, 0, 1, NULL, 0),
117 SND_SOC_DAPM_PGA("ADC R1", ES8326_ADC_MUTE, 1, 1, NULL, 0),
118 SND_SOC_DAPM_PGA("ADC L2", ES8326_ADC_MUTE, 2, 1, NULL, 0),
119 SND_SOC_DAPM_PGA("ADC R2", ES8326_ADC_MUTE, 3, 1, NULL, 0),
126 SND_SOC_DAPM_SUPPLY("ADC Vref", ES8326_ANA_PDN, 5, 1, NULL, 0),
156 {"ADC L1", NULL, "MIC1"},
157 {"ADC R1", NULL, "MIC2"},
158 {"ADC L2", NULL, "MIC3"},
159 {"ADC R2", NULL, "MIC4"},
161 {"ADC L", NULL, "ADC L1"},
162 {"ADC R", NULL, "ADC R1"},
163 {"ADC L", NULL, "ADC L2"},
164 {"ADC R", NULL, "ADC R2"},
166 {"I2S OUT", NULL, "ADC L"},
167 {"I2S OUT", NULL, "ADC R"},
170 {"I2S OUT", NULL, "ADC Vref"},
309 return -EINVAL; in get_coeff()
315 struct snd_soc_component *codec = codec_dai->component; in es8326_set_dai_sysclk()
318 es8326->sysclk = freq; in es8326_set_dai_sysclk()
325 struct snd_soc_component *component = codec_dai->component; in es8326_set_dai_fmt()
336 return -EINVAL; in es8326_set_dai_fmt()
344 dev_err(component->dev, "Codec driver does not support right justified\n"); in es8326_set_dai_fmt()
345 return -EINVAL; in es8326_set_dai_fmt()
356 return -EINVAL; in es8326_set_dai_fmt()
368 struct snd_soc_component *component = dai->component; in es8326_pcm_hw_params()
373 coeff = get_coeff(es8326->sysclk, params_rate(params)); in es8326_pcm_hw_params()
392 return -EINVAL; in es8326_pcm_hw_params()
399 regmap_write(es8326->regmap, ES8326_CLK_DIV1, in es8326_pcm_hw_params()
401 regmap_write(es8326->regmap, ES8326_CLK_DIV2, in es8326_pcm_hw_params()
403 regmap_write(es8326->regmap, ES8326_CLK_DLL, in es8326_pcm_hw_params()
405 regmap_write(es8326->regmap, ES8326_CLK_MUX, in es8326_pcm_hw_params()
407 regmap_write(es8326->regmap, ES8326_CLK_ADC_SEL, in es8326_pcm_hw_params()
409 regmap_write(es8326->regmap, ES8326_CLK_DAC_SEL, in es8326_pcm_hw_params()
411 regmap_write(es8326->regmap, ES8326_CLK_ADC_OSR, in es8326_pcm_hw_params()
413 regmap_write(es8326->regmap, ES8326_CLK_DAC_OSR, in es8326_pcm_hw_params()
416 dev_warn(component->dev, "Clock coefficients do not match"); in es8326_pcm_hw_params()
430 ret = clk_prepare_enable(es8326->mclk); in es8326_set_bias_level()
433 regmap_write(es8326->regmap, ES8326_RESET, ES8326_PWRUP_SEQ_EN); in es8326_set_bias_level()
434 regmap_write(es8326->regmap, ES8326_INTOUT_IO, 0x45); in es8326_set_bias_level()
435 regmap_write(es8326->regmap, ES8326_SDINOUT1_IO, in es8326_set_bias_level()
437 regmap_write(es8326->regmap, ES8326_SDINOUT23_IO, ES8326_IO_INPUT); in es8326_set_bias_level()
438 regmap_write(es8326->regmap, ES8326_CLK_RESAMPLE, 0x05); in es8326_set_bias_level()
439 regmap_write(es8326->regmap, ES8326_VMIDSEL, 0x02); in es8326_set_bias_level()
440 regmap_write(es8326->regmap, ES8326_PGA_PDN, 0x40); in es8326_set_bias_level()
441 regmap_write(es8326->regmap, ES8326_DAC2HPMIX, 0xAA); in es8326_set_bias_level()
442 regmap_write(es8326->regmap, ES8326_RESET, ES8326_CSM_ON); in es8326_set_bias_level()
449 clk_disable_unprepare(es8326->mclk); in es8326_set_bias_level()
450 regmap_write(es8326->regmap, ES8326_DAC2HPMIX, 0x11); in es8326_set_bias_level()
451 regmap_write(es8326->regmap, ES8326_RESET, ES8326_CSM_OFF); in es8326_set_bias_level()
452 regmap_write(es8326->regmap, ES8326_PGA_PDN, 0xF8); in es8326_set_bias_level()
453 regmap_write(es8326->regmap, ES8326_VMIDSEL, 0x00); in es8326_set_bias_level()
454 regmap_write(es8326->regmap, ES8326_INT_SOURCE, 0x08); in es8326_set_bias_level()
455 regmap_write(es8326->regmap, ES8326_SDINOUT1_IO, ES8326_IO_INPUT); in es8326_set_bias_level()
456 regmap_write(es8326->regmap, ES8326_SDINOUT23_IO, ES8326_IO_INPUT); in es8326_set_bias_level()
457 regmap_write(es8326->regmap, ES8326_RESET, in es8326_set_bias_level()
518 * snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
519 * snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
520 * snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
526 struct snd_soc_component *comp = es8326->component; in es8326_jack_button_handler()
531 if (!(es8326->jack->status & SND_JACK_HEADSET)) /* Jack unplugged */ in es8326_jack_button_handler()
534 mutex_lock(&es8326->lock); in es8326_jack_button_handler()
561 snd_soc_jack_report(es8326->jack, cur_button, in es8326_jack_button_handler()
566 queue_delayed_work(system_wq, &es8326->button_press_work, in es8326_jack_button_handler()
571 queue_delayed_work(system_wq, &es8326->button_press_work, in es8326_jack_button_handler()
576 snd_soc_jack_report(es8326->jack, button_to_report, in es8326_jack_button_handler()
578 snd_soc_jack_report(es8326->jack, 0, in es8326_jack_button_handler()
583 mutex_unlock(&es8326->lock); in es8326_jack_button_handler()
590 struct snd_soc_component *comp = es8326->component; in es8326_jack_detect_handler()
593 mutex_lock(&es8326->lock); in es8326_jack_detect_handler()
595 dev_dbg(comp->dev, "gpio flag %#04x", iface); in es8326_jack_detect_handler()
598 dev_dbg(comp->dev, "No headset detected"); in es8326_jack_detect_handler()
599 if (es8326->jack->status & SND_JACK_HEADPHONE) { in es8326_jack_detect_handler()
600 snd_soc_jack_report(es8326->jack, 0, SND_JACK_HEADSET); in es8326_jack_detect_handler()
601 snd_soc_component_write(comp, ES8326_ADC1_SRC, es8326->mic2_src); in es8326_jack_detect_handler()
605 if (es8326->jack->status & SND_JACK_HEADSET) { in es8326_jack_detect_handler()
607 queue_delayed_work(system_wq, &es8326->button_press_work, 10); in es8326_jack_detect_handler()
610 dev_dbg(comp->dev, "Headset detected"); in es8326_jack_detect_handler()
611 snd_soc_jack_report(es8326->jack, in es8326_jack_detect_handler()
614 ES8326_ADC1_SRC, es8326->mic1_src); in es8326_jack_detect_handler()
616 dev_dbg(comp->dev, "Headphone detected"); in es8326_jack_detect_handler()
617 snd_soc_jack_report(es8326->jack, in es8326_jack_detect_handler()
622 mutex_unlock(&es8326->lock); in es8326_jack_detect_handler()
628 struct snd_soc_component *comp = es8326->component; in es8326_irq()
630 if (!es8326->jack) in es8326_irq()
635 if (es8326->jack->status & SND_JACK_HEADSET) in es8326_irq()
636 queue_delayed_work(system_wq, &es8326->jack_detect_work, in es8326_irq()
639 queue_delayed_work(system_wq, &es8326->jack_detect_work, in es8326_irq()
651 regcache_cache_only(es8326->regmap, false); in es8326_resume()
652 regcache_sync(es8326->regmap); in es8326_resume()
654 regmap_write(es8326->regmap, ES8326_CLK_CTL, ES8326_CLK_ON); in es8326_resume()
655 /* Two channel ADC */ in es8326_resume()
656 regmap_write(es8326->regmap, ES8326_PULLUP_CTL, 0x02); in es8326_resume()
657 regmap_write(es8326->regmap, ES8326_CLK_INV, 0x00); in es8326_resume()
658 regmap_write(es8326->regmap, ES8326_CLK_DIV_CPC, 0x1F); in es8326_resume()
659 regmap_write(es8326->regmap, ES8326_CLK_VMIDS1, 0xC8); in es8326_resume()
660 regmap_write(es8326->regmap, ES8326_CLK_VMIDS2, 0x88); in es8326_resume()
661 regmap_write(es8326->regmap, ES8326_CLK_CAL_TIME, 0x20); in es8326_resume()
662 regmap_write(es8326->regmap, ES8326_SYS_BIAS, 0x08); in es8326_resume()
663 regmap_write(es8326->regmap, ES8326_DAC2HPMIX, 0x22); in es8326_resume()
664 regmap_write(es8326->regmap, ES8326_ADC1_SRC, es8326->mic1_src); in es8326_resume()
665 regmap_write(es8326->regmap, ES8326_ADC2_SRC, es8326->mic2_src); in es8326_resume()
666 regmap_write(es8326->regmap, ES8326_HPJACK_TIMER, 0x88); in es8326_resume()
667 regmap_write(es8326->regmap, ES8326_HP_DET, in es8326_resume()
668 ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol); in es8326_resume()
669 regmap_write(es8326->regmap, ES8326_INT_SOURCE, es8326->interrupt_src); in es8326_resume()
670 regmap_write(es8326->regmap, ES8326_INTOUT_IO, es8326->interrupt_clk); in es8326_resume()
671 regmap_write(es8326->regmap, ES8326_RESET, ES8326_CSM_ON); in es8326_resume()
675 regmap_read(es8326->regmap, ES8326_CHIP_VERSION, ®); in es8326_resume()
677 regmap_write(es8326->regmap, ES8326_ANA_MICBIAS, 0xDD); in es8326_resume()
678 regmap_write(es8326->regmap, ES8326_ANA_VSEL, 0x7F); in es8326_resume()
679 regmap_write(es8326->regmap, ES8326_VMIDLOW, 0x0F); in es8326_resume()
681 regmap_write(es8326->regmap, ES8326_HP_DRIVER, 0xA0); in es8326_resume()
684 es8326_irq(es8326->irq, es8326); in es8326_resume()
692 cancel_delayed_work_sync(&es8326->jack_detect_work); in es8326_suspend()
695 regmap_write(es8326->regmap, ES8326_CLK_CTL, ES8326_CLK_OFF); in es8326_suspend()
696 regcache_cache_only(es8326->regmap, true); in es8326_suspend()
697 regcache_mark_dirty(es8326->regmap); in es8326_suspend()
707 es8326->component = component; in es8326_probe()
708 es8326->jd_inverted = device_property_read_bool(component->dev, in es8326_probe()
709 "everest,jack-detect-inverted"); in es8326_probe()
711 ret = device_property_read_u8(component->dev, "everest,mic1-src", &es8326->mic1_src); in es8326_probe()
713 dev_dbg(component->dev, "mic1-src return %d", ret); in es8326_probe()
714 es8326->mic1_src = ES8326_ADC_AMIC; in es8326_probe()
716 dev_dbg(component->dev, "mic1-src %x", es8326->mic1_src); in es8326_probe()
718 ret = device_property_read_u8(component->dev, "everest,mic2-src", &es8326->mic2_src); in es8326_probe()
720 dev_dbg(component->dev, "mic2-src return %d", ret); in es8326_probe()
721 es8326->mic2_src = ES8326_ADC_DMIC; in es8326_probe()
723 dev_dbg(component->dev, "mic2-src %x", es8326->mic2_src); in es8326_probe()
725 ret = device_property_read_u8(component->dev, "everest,jack-pol", &es8326->jack_pol); in es8326_probe()
727 dev_dbg(component->dev, "jack-pol return %d", ret); in es8326_probe()
728 es8326->jack_pol = ES8326_HP_DET_BUTTON_POL | ES8326_HP_TYPE_OMTP; in es8326_probe()
730 dev_dbg(component->dev, "jack-pol %x", es8326->jack_pol); in es8326_probe()
732 ret = device_property_read_u8(component->dev, "everest,interrupt-src", &es8326->jack_pol); in es8326_probe()
734 dev_dbg(component->dev, "interrupt-src return %d", ret); in es8326_probe()
735 es8326->interrupt_src = ES8326_HP_DET_SRC_PIN9; in es8326_probe()
737 dev_dbg(component->dev, "interrupt-src %x", es8326->interrupt_src); in es8326_probe()
739 ret = device_property_read_u8(component->dev, "everest,interrupt-clk", &es8326->jack_pol); in es8326_probe()
741 dev_dbg(component->dev, "interrupt-clk return %d", ret); in es8326_probe()
742 es8326->interrupt_clk = 0x45; in es8326_probe()
744 dev_dbg(component->dev, "interrupt-clk %x", es8326->interrupt_clk); in es8326_probe()
755 mutex_lock(&es8326->lock); in es8326_enable_jack_detect()
756 if (es8326->jd_inverted) in es8326_enable_jack_detect()
758 ES8326_HP_DET_JACK_POL, ~es8326->jack_pol); in es8326_enable_jack_detect()
759 es8326->jack = jack; in es8326_enable_jack_detect()
761 mutex_unlock(&es8326->lock); in es8326_enable_jack_detect()
762 es8326_irq(es8326->irq, es8326); in es8326_enable_jack_detect()
769 dev_dbg(component->dev, "Enter into %s\n", __func__); in es8326_disable_jack_detect()
770 if (!es8326->jack) in es8326_disable_jack_detect()
772 cancel_delayed_work_sync(&es8326->jack_detect_work); in es8326_disable_jack_detect()
774 mutex_lock(&es8326->lock); in es8326_disable_jack_detect()
775 if (es8326->jack->status & SND_JACK_MICROPHONE) { in es8326_disable_jack_detect()
777 snd_soc_jack_report(es8326->jack, 0, SND_JACK_HEADSET); in es8326_disable_jack_detect()
779 es8326->jack = NULL; in es8326_disable_jack_detect()
780 mutex_unlock(&es8326->lock); in es8326_disable_jack_detect()
823 es8326 = devm_kzalloc(&i2c->dev, sizeof(struct es8326_priv), GFP_KERNEL); in es8326_i2c_probe()
825 return -ENOMEM; in es8326_i2c_probe()
828 es8326->i2c = i2c; in es8326_i2c_probe()
829 mutex_init(&es8326->lock); in es8326_i2c_probe()
830 es8326->regmap = devm_regmap_init_i2c(i2c, &es8326_regmap_config); in es8326_i2c_probe()
831 if (IS_ERR(es8326->regmap)) { in es8326_i2c_probe()
832 ret = PTR_ERR(es8326->regmap); in es8326_i2c_probe()
833 dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret); in es8326_i2c_probe()
837 es8326->irq = i2c->irq; in es8326_i2c_probe()
838 INIT_DELAYED_WORK(&es8326->jack_detect_work, in es8326_i2c_probe()
840 INIT_DELAYED_WORK(&es8326->button_press_work, in es8326_i2c_probe()
842 /* ES8316 is level-based while ES8326 is edge-based */ in es8326_i2c_probe()
843 ret = devm_request_threaded_irq(&i2c->dev, es8326->irq, NULL, es8326_irq, in es8326_i2c_probe()
847 dev_warn(&i2c->dev, "Failed to request IRQ: %d: %d\n", in es8326_i2c_probe()
848 es8326->irq, ret); in es8326_i2c_probe()
849 es8326->irq = -ENXIO; in es8326_i2c_probe()
852 es8326->mclk = devm_clk_get_optional(&i2c->dev, "mclk"); in es8326_i2c_probe()
853 if (IS_ERR(es8326->mclk)) { in es8326_i2c_probe()
854 dev_err(&i2c->dev, "unable to get mclk\n"); in es8326_i2c_probe()
855 return PTR_ERR(es8326->mclk); in es8326_i2c_probe()
857 if (!es8326->mclk) in es8326_i2c_probe()
858 dev_warn(&i2c->dev, "assuming static mclk\n"); in es8326_i2c_probe()
860 ret = clk_prepare_enable(es8326->mclk); in es8326_i2c_probe()
862 dev_err(&i2c->dev, "unable to enable mclk\n"); in es8326_i2c_probe()
865 return devm_snd_soc_register_component(&i2c->dev, in es8326_i2c_probe()
904 MODULE_AUTHOR("David Yang <yangxiaohua@everest-semi.com>");