Lines Matching +full:120 +full:- +full:db
1 // SPDX-License-Identifier: GPL-2.0-only
3 // es8326.c -- es8326 ALSA SoC audio driver
6 // Authors: David Yang <yangxiaohua@everest-semi.com>
17 #include <sound/soc-dapm.h>
56 regmap_read(es8326->regmap, ES8326_DAC_RAMPRATE, &crosstalk_h); in es8326_crosstalk1_get()
57 regmap_read(es8326->regmap, ES8326_DAC_CROSSTALK, &crosstalk_l); in es8326_crosstalk1_get()
61 ucontrol->value.integer.value[0] = crosstalk; in es8326_crosstalk1_get()
74 crosstalk = ucontrol->value.integer.value[0]; in es8326_crosstalk1_set()
75 regmap_read(es8326->regmap, ES8326_DAC_CROSSTALK, &crosstalk_l); in es8326_crosstalk1_set()
79 regmap_update_bits(es8326->regmap, ES8326_DAC_RAMPRATE, in es8326_crosstalk1_set()
81 regmap_write(es8326->regmap, ES8326_DAC_CROSSTALK, crosstalk_l); in es8326_crosstalk1_set()
94 regmap_read(es8326->regmap, ES8326_DAC_RAMPRATE, &crosstalk_h); in es8326_crosstalk2_get()
95 regmap_read(es8326->regmap, ES8326_DAC_CROSSTALK, &crosstalk_l); in es8326_crosstalk2_get()
99 ucontrol->value.integer.value[0] = crosstalk; in es8326_crosstalk2_get()
112 crosstalk = ucontrol->value.integer.value[0]; in es8326_crosstalk2_set()
113 regmap_read(es8326->regmap, ES8326_DAC_CROSSTALK, &crosstalk_l); in es8326_crosstalk2_set()
117 regmap_update_bits(es8326->regmap, ES8326_DAC_RAMPRATE, in es8326_crosstalk2_set()
119 regmap_write(es8326->regmap, ES8326_DAC_CROSSTALK, crosstalk_l); in es8326_crosstalk2_set()
130 ucontrol->value.integer.value[0] = es8326->hpl_vol; in es8326_hplvol_get()
142 hp_vol = ucontrol->value.integer.value[0]; in es8326_hplvol_set()
144 return -EINVAL; in es8326_hplvol_set()
145 if (es8326->hpl_vol != hp_vol) { in es8326_hplvol_set()
146 es8326->hpl_vol = hp_vol; in es8326_hplvol_set()
149 regmap_update_bits(es8326->regmap, ES8326_HP_VOL, in es8326_hplvol_set()
163 ucontrol->value.integer.value[0] = es8326->hpr_vol; in es8326_hprvol_get()
175 hp_vol = ucontrol->value.integer.value[0]; in es8326_hprvol_set()
177 return -EINVAL; in es8326_hprvol_set()
178 if (es8326->hpr_vol != hp_vol) { in es8326_hprvol_set()
179 es8326->hpr_vol = hp_vol; in es8326_hprvol_set()
182 regmap_update_bits(es8326->regmap, ES8326_HP_VOL, in es8326_hprvol_set()
190 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(dac_vol_tlv, -9550, 50, 0);
191 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_vol_tlv, -9550, 50, 0);
195 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(drc_target_tlv, -3200, 200, 0);
196 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(drc_recovery_tlv, -125, 250, 0);
199 "0.25db/2 LRCK",
200 "0.25db/4 LRCK",
201 "0.25db/8 LRCK",
202 "0.25db/16 LRCK",
203 "0.25db/32 LRCK",
204 "0.25db/64 LRCK",
205 "0.25db/128 LRCK",
206 "0.25db/256 LRCK",
207 "0.25db/512 LRCK",
208 "0.25db/1024 LRCK",
209 "0.25db/2048 LRCK",
210 "0.25db/4096 LRCK",
211 "0.25db/8192 LRCK",
212 "0.25db/16384 LRCK",
213 "0.25db/32768 LRCK",
214 "0.25db/65536 LRCK",
480 return -EINVAL; in get_coeff()
486 struct snd_soc_component *codec = codec_dai->component; in es8326_set_dai_sysclk()
489 es8326->sysclk = freq; in es8326_set_dai_sysclk()
496 struct snd_soc_component *component = codec_dai->component; in es8326_set_dai_fmt()
507 return -EINVAL; in es8326_set_dai_fmt()
515 dev_err(component->dev, "Codec driver does not support right justified\n"); in es8326_set_dai_fmt()
516 return -EINVAL; in es8326_set_dai_fmt()
527 return -EINVAL; in es8326_set_dai_fmt()
539 struct snd_soc_component *component = dai->component; in es8326_pcm_hw_params()
545 if (es8326->version == 0) { in es8326_pcm_hw_params()
552 coeff = get_coeff(es8326->sysclk, params_rate(params), array, coeff_div); in es8326_pcm_hw_params()
571 return -EINVAL; in es8326_pcm_hw_params()
578 regmap_write(es8326->regmap, ES8326_CLK_DIV1, in es8326_pcm_hw_params()
580 regmap_write(es8326->regmap, ES8326_CLK_DIV2, in es8326_pcm_hw_params()
582 regmap_write(es8326->regmap, ES8326_CLK_DLL, in es8326_pcm_hw_params()
584 regmap_write(es8326->regmap, ES8326_CLK_MUX, in es8326_pcm_hw_params()
586 regmap_write(es8326->regmap, ES8326_CLK_ADC_SEL, in es8326_pcm_hw_params()
588 regmap_write(es8326->regmap, ES8326_CLK_DAC_SEL, in es8326_pcm_hw_params()
590 regmap_write(es8326->regmap, ES8326_CLK_ADC_OSR, in es8326_pcm_hw_params()
592 regmap_write(es8326->regmap, ES8326_CLK_DAC_OSR, in es8326_pcm_hw_params()
595 dev_warn(component->dev, "Clock coefficients do not match"); in es8326_pcm_hw_params()
603 struct snd_soc_component *component = dai->component; in es8326_mute()
609 regmap_write(es8326->regmap, ES8326_HP_CAL, ES8326_HP_OFF); in es8326_mute()
610 regmap_update_bits(es8326->regmap, ES8326_DAC_MUTE, in es8326_mute()
612 regmap_update_bits(es8326->regmap, ES8326_HP_DRIVER_REF, in es8326_mute()
615 regmap_update_bits(es8326->regmap, ES8326_ADC_MUTE, in es8326_mute()
617 if (es8326->version > ES8326_VERSION_B) { in es8326_mute()
618 regmap_update_bits(es8326->regmap, ES8326_VMIDSEL, 0x40, 0x40); in es8326_mute()
619 regmap_update_bits(es8326->regmap, ES8326_ANA_MICBIAS, 0x70, 0x10); in es8326_mute()
623 if (!es8326->calibrated) { in es8326_mute()
624 regmap_write(es8326->regmap, ES8326_HP_CAL, ES8326_HP_FORCE_CAL); in es8326_mute()
626 regmap_write(es8326->regmap, ES8326_HP_CAL, ES8326_HP_OFF); in es8326_mute()
627 regmap_read(es8326->regmap, ES8326_HPL_OFFSET_INI, &offset_l); in es8326_mute()
628 regmap_read(es8326->regmap, ES8326_HPR_OFFSET_INI, &offset_r); in es8326_mute()
629 regmap_write(es8326->regmap, ES8326_HP_OFFSET_CAL, 0x8c); in es8326_mute()
630 regmap_write(es8326->regmap, ES8326_HPL_OFFSET_INI, offset_l); in es8326_mute()
631 regmap_write(es8326->regmap, ES8326_HPR_OFFSET_INI, offset_r); in es8326_mute()
632 es8326->calibrated = true; in es8326_mute()
635 regmap_update_bits(es8326->regmap, ES8326_DAC_DSM, 0x01, 0x01); in es8326_mute()
637 regmap_update_bits(es8326->regmap, ES8326_DAC_DSM, 0x01, 0x00); in es8326_mute()
639 regmap_update_bits(es8326->regmap, ES8326_HP_DRIVER_REF, 0x30, 0x20); in es8326_mute()
640 regmap_update_bits(es8326->regmap, ES8326_HP_DRIVER_REF, 0x30, 0x30); in es8326_mute()
641 regmap_write(es8326->regmap, ES8326_HP_DRIVER, 0xa1); in es8326_mute()
642 regmap_write(es8326->regmap, ES8326_HP_CAL, ES8326_HP_ON); in es8326_mute()
643 regmap_update_bits(es8326->regmap, ES8326_DAC_MUTE, in es8326_mute()
647 if (es8326->version > ES8326_VERSION_B) { in es8326_mute()
648 regmap_update_bits(es8326->regmap, ES8326_ANA_MICBIAS, 0x70, 0x50); in es8326_mute()
649 regmap_update_bits(es8326->regmap, ES8326_VMIDSEL, 0x40, 0x00); in es8326_mute()
651 regmap_update_bits(es8326->regmap, ES8326_ADC_MUTE, in es8326_mute()
666 ret = clk_prepare_enable(es8326->mclk); in es8326_set_bias_level()
670 regmap_update_bits(es8326->regmap, ES8326_RESET, 0x02, 0x02); in es8326_set_bias_level()
672 regmap_write(es8326->regmap, ES8326_INTOUT_IO, es8326->interrupt_clk); in es8326_set_bias_level()
673 regmap_write(es8326->regmap, ES8326_SDINOUT1_IO, in es8326_set_bias_level()
675 regmap_write(es8326->regmap, ES8326_PGA_PDN, 0x40); in es8326_set_bias_level()
676 regmap_write(es8326->regmap, ES8326_ANA_PDN, 0x00); in es8326_set_bias_level()
677 regmap_update_bits(es8326->regmap, ES8326_CLK_CTL, 0x20, 0x20); in es8326_set_bias_level()
678 regmap_update_bits(es8326->regmap, ES8326_RESET, 0x02, 0x00); in es8326_set_bias_level()
683 regmap_write(es8326->regmap, ES8326_ANA_PDN, 0x3b); in es8326_set_bias_level()
684 regmap_update_bits(es8326->regmap, ES8326_CLK_CTL, 0x20, 0x00); in es8326_set_bias_level()
685 regmap_write(es8326->regmap, ES8326_SDINOUT1_IO, ES8326_IO_INPUT); in es8326_set_bias_level()
688 clk_disable_unprepare(es8326->mclk); in es8326_set_bias_level()
750 * snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
751 * snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
752 * snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
758 struct snd_soc_component *comp = es8326->component; in es8326_jack_button_handler()
763 if (!(es8326->jack->status & SND_JACK_HEADSET)) /* Jack unplugged */ in es8326_jack_button_handler()
766 mutex_lock(&es8326->lock); in es8326_jack_button_handler()
794 /* report a press every 120ms */ in es8326_jack_button_handler()
795 snd_soc_jack_report(es8326->jack, cur_button, in es8326_jack_button_handler()
800 queue_delayed_work(system_wq, &es8326->button_press_work, in es8326_jack_button_handler()
805 queue_delayed_work(system_wq, &es8326->button_press_work, in es8326_jack_button_handler()
810 snd_soc_jack_report(es8326->jack, button_to_report, in es8326_jack_button_handler()
812 snd_soc_jack_report(es8326->jack, 0, in es8326_jack_button_handler()
816 es8326_disable_micbias(es8326->component); in es8326_jack_button_handler()
818 mutex_unlock(&es8326->lock); in es8326_jack_button_handler()
825 struct snd_soc_component *comp = es8326->component; in es8326_jack_detect_handler()
828 mutex_lock(&es8326->lock); in es8326_jack_detect_handler()
830 dev_dbg(comp->dev, "gpio flag %#04x", iface); in es8326_jack_detect_handler()
832 if ((es8326->jack_remove_retry == 1) && (es8326->version < ES8326_VERSION_B)) { in es8326_jack_detect_handler()
834 es8326->jack_remove_retry = 2; in es8326_jack_detect_handler()
836 es8326->jack_remove_retry = 0; in es8326_jack_detect_handler()
838 dev_dbg(comp->dev, "remove event check, set HPJACK_POL normal, cnt = %d\n", in es8326_jack_detect_handler()
839 es8326->jack_remove_retry); in es8326_jack_detect_handler()
843 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, in es8326_jack_detect_handler()
844 ES8326_HP_DET_JACK_POL, (es8326->jd_inverted ? in es8326_jack_detect_handler()
845 ~es8326->jack_pol : es8326->jack_pol)); in es8326_jack_detect_handler()
851 dev_dbg(comp->dev, "No headset detected\n"); in es8326_jack_detect_handler()
852 es8326_disable_micbias(es8326->component); in es8326_jack_detect_handler()
853 if (es8326->jack->status & SND_JACK_HEADPHONE) { in es8326_jack_detect_handler()
854 dev_dbg(comp->dev, "Report hp remove event\n"); in es8326_jack_detect_handler()
855 snd_soc_jack_report(es8326->jack, 0, in es8326_jack_detect_handler()
857 snd_soc_jack_report(es8326->jack, 0, SND_JACK_HEADSET); in es8326_jack_detect_handler()
859 regmap_write(es8326->regmap, ES8326_ADC1_SRC, 0x44); in es8326_jack_detect_handler()
860 regmap_write(es8326->regmap, ES8326_ADC2_SRC, 0x66); in es8326_jack_detect_handler()
862 es8326->hp = 0; in es8326_jack_detect_handler()
863 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x01); in es8326_jack_detect_handler()
864 regmap_write(es8326->regmap, ES8326_SYS_BIAS, 0x0a); in es8326_jack_detect_handler()
865 regmap_update_bits(es8326->regmap, ES8326_HP_DRIVER_REF, 0x0f, 0x03); in es8326_jack_detect_handler()
866 regmap_write(es8326->regmap, ES8326_INT_SOURCE, ES8326_INT_SRC_PIN9); in es8326_jack_detect_handler()
870 if ((es8326->jack_remove_retry == 0) && (es8326->version < ES8326_VERSION_B)) { in es8326_jack_detect_handler()
871 es8326->jack_remove_retry = 1; in es8326_jack_detect_handler()
872 dev_dbg(comp->dev, "remove event check, invert HPJACK_POL, cnt = %d\n", in es8326_jack_detect_handler()
873 es8326->jack_remove_retry); in es8326_jack_detect_handler()
874 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, in es8326_jack_detect_handler()
875 ES8326_HP_DET_JACK_POL, (es8326->jd_inverted ? in es8326_jack_detect_handler()
876 es8326->jack_pol : ~es8326->jack_pol)); in es8326_jack_detect_handler()
879 es8326->jack_remove_retry = 0; in es8326_jack_detect_handler()
882 es8326->jack_remove_retry = 0; in es8326_jack_detect_handler()
883 if (es8326->hp == 0) { in es8326_jack_detect_handler()
884 dev_dbg(comp->dev, "First insert, start OMTP/CTIA type check\n"); in es8326_jack_detect_handler()
886 * set auto-check mode, then restart jack_detect_work after 400ms. in es8326_jack_detect_handler()
889 regmap_write(es8326->regmap, ES8326_INT_SOURCE, 0x00); in es8326_jack_detect_handler()
890 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x01); in es8326_jack_detect_handler()
891 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x10, 0x00); in es8326_jack_detect_handler()
893 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x00); in es8326_jack_detect_handler()
894 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x10, 0x10); in es8326_jack_detect_handler()
896 regmap_write(es8326->regmap, ES8326_INT_SOURCE, in es8326_jack_detect_handler()
898 regmap_write(es8326->regmap, ES8326_SYS_BIAS, 0x1f); in es8326_jack_detect_handler()
899 regmap_update_bits(es8326->regmap, ES8326_HP_DRIVER_REF, 0x0f, 0x08); in es8326_jack_detect_handler()
900 queue_delayed_work(system_wq, &es8326->jack_detect_work, in es8326_jack_detect_handler()
902 es8326->hp = 1; in es8326_jack_detect_handler()
905 if (es8326->jack->status & SND_JACK_HEADSET) { in es8326_jack_detect_handler()
907 dev_dbg(comp->dev, "button pressed\n"); in es8326_jack_detect_handler()
908 regmap_write(es8326->regmap, ES8326_INT_SOURCE, in es8326_jack_detect_handler()
910 es8326_enable_micbias(es8326->component); in es8326_jack_detect_handler()
911 queue_delayed_work(system_wq, &es8326->button_press_work, 10); in es8326_jack_detect_handler()
915 dev_dbg(comp->dev, "Headphone detected\n"); in es8326_jack_detect_handler()
916 snd_soc_jack_report(es8326->jack, in es8326_jack_detect_handler()
919 dev_dbg(comp->dev, "Headset detected\n"); in es8326_jack_detect_handler()
920 snd_soc_jack_report(es8326->jack, in es8326_jack_detect_handler()
923 regmap_update_bits(es8326->regmap, ES8326_PGA_PDN, in es8326_jack_detect_handler()
925 regmap_update_bits(es8326->regmap, ES8326_PGAGAIN, in es8326_jack_detect_handler()
927 regmap_write(es8326->regmap, ES8326_ADC1_SRC, 0x00); in es8326_jack_detect_handler()
928 regmap_write(es8326->regmap, ES8326_ADC2_SRC, 0x00); in es8326_jack_detect_handler()
929 regmap_update_bits(es8326->regmap, ES8326_PGA_PDN, in es8326_jack_detect_handler()
935 mutex_unlock(&es8326->lock); in es8326_jack_detect_handler()
942 if (!es8326->jack) in es8326_irq()
945 if (es8326->jack->status & SND_JACK_HEADSET) in es8326_irq()
946 queue_delayed_work(system_wq, &es8326->jack_detect_work, in es8326_irq()
949 queue_delayed_work(system_wq, &es8326->jack_detect_work, in es8326_irq()
962 regmap_read(es8326->regmap, ES8326_CHIP_VERSION, ®); in es8326_calibrate()
963 es8326->version = reg; in es8326_calibrate()
965 if ((es8326->version >= ES8326_VERSION_B) && (es8326->calibrated == false)) { in es8326_calibrate()
966 dev_dbg(component->dev, "ES8326_VERSION_B, calibrating\n"); in es8326_calibrate()
967 regmap_write(es8326->regmap, ES8326_CLK_INV, 0xc0); in es8326_calibrate()
968 regmap_write(es8326->regmap, ES8326_CLK_DIV1, 0x03); in es8326_calibrate()
969 regmap_write(es8326->regmap, ES8326_CLK_DLL, 0x30); in es8326_calibrate()
970 regmap_write(es8326->regmap, ES8326_CLK_MUX, 0xed); in es8326_calibrate()
971 regmap_write(es8326->regmap, ES8326_CLK_DAC_SEL, 0x08); in es8326_calibrate()
972 regmap_write(es8326->regmap, ES8326_CLK_TRI, 0xc1); in es8326_calibrate()
973 regmap_write(es8326->regmap, ES8326_DAC_MUTE, 0x03); in es8326_calibrate()
974 regmap_write(es8326->regmap, ES8326_ANA_VSEL, 0x7f); in es8326_calibrate()
975 regmap_write(es8326->regmap, ES8326_VMIDLOW, 0x23); in es8326_calibrate()
976 regmap_write(es8326->regmap, ES8326_DAC2HPMIX, 0x88); in es8326_calibrate()
978 regmap_write(es8326->regmap, ES8326_HP_OFFSET_CAL, 0x8c); in es8326_calibrate()
980 regmap_write(es8326->regmap, ES8326_RESET, 0xc0); in es8326_calibrate()
983 regmap_write(es8326->regmap, ES8326_HP_OFFSET_CAL, ES8326_HP_OFF); in es8326_calibrate()
984 regmap_read(es8326->regmap, ES8326_CSM_MUTE_STA, ®); in es8326_calibrate()
988 regmap_write(es8326->regmap, ES8326_HP_CAL, 0xd4); in es8326_calibrate()
990 regmap_write(es8326->regmap, ES8326_HP_CAL, 0x4d); in es8326_calibrate()
992 regmap_write(es8326->regmap, ES8326_HP_CAL, ES8326_HP_OFF); in es8326_calibrate()
993 regmap_read(es8326->regmap, ES8326_HPL_OFFSET_INI, &offset_l); in es8326_calibrate()
994 regmap_read(es8326->regmap, ES8326_HPR_OFFSET_INI, &offset_r); in es8326_calibrate()
995 regmap_write(es8326->regmap, ES8326_HP_OFFSET_CAL, 0x8c); in es8326_calibrate()
996 regmap_write(es8326->regmap, ES8326_HPL_OFFSET_INI, offset_l); in es8326_calibrate()
997 regmap_write(es8326->regmap, ES8326_HPR_OFFSET_INI, offset_r); in es8326_calibrate()
998 regmap_write(es8326->regmap, ES8326_CLK_INV, 0x00); in es8326_calibrate()
1000 es8326->calibrated = true; in es8326_calibrate()
1010 regmap_write(es8326->regmap, ES8326_RESET, 0x1f); in es8326_init()
1011 regmap_write(es8326->regmap, ES8326_VMIDSEL, 0x0E); in es8326_init()
1012 regmap_write(es8326->regmap, ES8326_ANA_LP, 0xf0); in es8326_init()
1014 regmap_write(es8326->regmap, ES8326_HPJACK_TIMER, 0xd9); in es8326_init()
1015 regmap_write(es8326->regmap, ES8326_ANA_MICBIAS, 0xd8); in es8326_init()
1017 regmap_write(es8326->regmap, ES8326_HPDET_TYPE, 0x83); in es8326_init()
1018 regmap_write(es8326->regmap, ES8326_CLK_RESAMPLE, 0x05); in es8326_init()
1021 regmap_write(es8326->regmap, ES8326_CLK_DIV_CPC, 0x89); in es8326_init()
1022 regmap_write(es8326->regmap, ES8326_CLK_CTL, ES8326_CLK_ON); in es8326_init()
1024 regmap_write(es8326->regmap, ES8326_RESET, 0x17); in es8326_init()
1026 regmap_write(es8326->regmap, ES8326_HP_MISC, 0x3d); in es8326_init()
1027 regmap_write(es8326->regmap, ES8326_PULLUP_CTL, 0x00); in es8326_init()
1030 regmap_write(es8326->regmap, ES8326_HP_VOL, 0xc4); in es8326_init()
1031 regmap_write(es8326->regmap, ES8326_HP_DRIVER, 0xa7); in es8326_init()
1033 regmap_write(es8326->regmap, ES8326_HP_DRIVER_REF, 0x23); in es8326_init()
1034 regmap_write(es8326->regmap, ES8326_HP_DRIVER_REF, 0x33); in es8326_init()
1035 regmap_write(es8326->regmap, ES8326_HP_DRIVER, 0xa1); in es8326_init()
1037 regmap_write(es8326->regmap, ES8326_CLK_INV, 0x00); in es8326_init()
1038 regmap_write(es8326->regmap, ES8326_CLK_VMIDS1, 0xc4); in es8326_init()
1039 regmap_write(es8326->regmap, ES8326_CLK_VMIDS2, 0x81); in es8326_init()
1040 regmap_write(es8326->regmap, ES8326_CLK_CAL_TIME, 0x00); in es8326_init()
1043 regmap_write(es8326->regmap, ES8326_DAC_CROSSTALK, 0xaa); in es8326_init()
1044 regmap_write(es8326->regmap, ES8326_DAC_RAMPRATE, 0x00); in es8326_init()
1046 regmap_write(es8326->regmap, ES8326_HP_CAL, 0x00); in es8326_init()
1048 regmap_write(es8326->regmap, ES8326_ANA_LP, 0xf0); in es8326_init()
1050 regmap_write(es8326->regmap, ES8326_ANA_VSEL, 0x7F); in es8326_init()
1052 regmap_write(es8326->regmap, ES8326_VMIDLOW, 0x03); in es8326_init()
1054 regmap_write(es8326->regmap, ES8326_DAC_DSM, 0x08); in es8326_init()
1055 regmap_write(es8326->regmap, ES8326_DAC_VPPSCALE, 0x15); in es8326_init()
1057 regmap_write(es8326->regmap, ES8326_HPDET_TYPE, 0x80 | in es8326_init()
1058 ((es8326->version >= ES8326_VERSION_B) ? in es8326_init()
1059 (ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol) : in es8326_init()
1060 (ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol | 0x04))); in es8326_init()
1062 es8326_enable_micbias(es8326->component); in es8326_init()
1064 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x00); in es8326_init()
1065 regmap_write(es8326->regmap, ES8326_INTOUT_IO, in es8326_init()
1066 es8326->interrupt_clk); in es8326_init()
1067 regmap_write(es8326->regmap, ES8326_SDINOUT1_IO, in es8326_init()
1069 regmap_write(es8326->regmap, ES8326_SDINOUT23_IO, ES8326_IO_INPUT); in es8326_init()
1071 regmap_write(es8326->regmap, ES8326_ANA_PDN, 0x00); in es8326_init()
1072 regmap_write(es8326->regmap, ES8326_RESET, ES8326_CSM_ON); in es8326_init()
1073 regmap_update_bits(es8326->regmap, ES8326_PGAGAIN, ES8326_MIC_SEL_MASK, in es8326_init()
1076 regmap_update_bits(es8326->regmap, ES8326_DAC_MUTE, ES8326_MUTE_MASK, in es8326_init()
1079 regmap_write(es8326->regmap, ES8326_ADC_MUTE, 0x0f); in es8326_init()
1080 regmap_write(es8326->regmap, ES8326_CLK_DIV_LRCK, 0xff); in es8326_init()
1081 regmap_write(es8326->regmap, ES8326_ADC1_SRC, 0x44); in es8326_init()
1082 regmap_write(es8326->regmap, ES8326_ADC2_SRC, 0x66); in es8326_init()
1083 es8326_disable_micbias(es8326->component); in es8326_init()
1084 if (es8326->version > ES8326_VERSION_B) { in es8326_init()
1085 regmap_update_bits(es8326->regmap, ES8326_ANA_MICBIAS, 0x73, 0x13); in es8326_init()
1086 regmap_update_bits(es8326->regmap, ES8326_VMIDSEL, 0x40, 0x40); in es8326_init()
1090 regmap_write(es8326->regmap, ES8326_INT_SOURCE, ES8326_INT_SRC_PIN9); in es8326_init()
1098 regcache_cache_only(es8326->regmap, false); in es8326_resume()
1099 regcache_cache_bypass(es8326->regmap, true); in es8326_resume()
1100 regmap_read(es8326->regmap, ES8326_CLK_RESAMPLE, ®); in es8326_resume()
1101 regcache_cache_bypass(es8326->regmap, false); in es8326_resume()
1104 regmap_write(es8326->regmap, ES8326_CLK_CTL, ES8326_CLK_ON); in es8326_resume()
1108 regcache_sync(es8326->regmap); in es8326_resume()
1110 es8326_irq(es8326->irq, es8326); in es8326_resume()
1118 cancel_delayed_work_sync(&es8326->jack_detect_work); in es8326_suspend()
1120 es8326->calibrated = false; in es8326_suspend()
1121 regmap_write(es8326->regmap, ES8326_CLK_MUX, 0x2d); in es8326_suspend()
1122 regmap_write(es8326->regmap, ES8326_DAC2HPMIX, 0x00); in es8326_suspend()
1123 regmap_write(es8326->regmap, ES8326_ANA_PDN, 0x3b); in es8326_suspend()
1124 regmap_write(es8326->regmap, ES8326_CLK_CTL, ES8326_CLK_OFF); in es8326_suspend()
1125 regcache_cache_only(es8326->regmap, true); in es8326_suspend()
1128 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x01); in es8326_suspend()
1130 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x00); in es8326_suspend()
1132 regcache_mark_dirty(es8326->regmap); in es8326_suspend()
1141 es8326->component = component; in es8326_probe()
1142 es8326->jd_inverted = device_property_read_bool(component->dev, in es8326_probe()
1143 "everest,jack-detect-inverted"); in es8326_probe()
1145 ret = device_property_read_u8(component->dev, "everest,jack-pol", &es8326->jack_pol); in es8326_probe()
1147 dev_dbg(component->dev, "jack-pol return %d", ret); in es8326_probe()
1148 es8326->jack_pol = ES8326_HP_TYPE_AUTO; in es8326_probe()
1150 dev_dbg(component->dev, "jack-pol %x", es8326->jack_pol); in es8326_probe()
1152 ret = device_property_read_u8(component->dev, "everest,interrupt-src", in es8326_probe()
1153 &es8326->interrupt_src); in es8326_probe()
1155 dev_dbg(component->dev, "interrupt-src return %d", ret); in es8326_probe()
1156 es8326->interrupt_src = ES8326_HP_DET_SRC_PIN9; in es8326_probe()
1158 dev_dbg(component->dev, "interrupt-src %x", es8326->interrupt_src); in es8326_probe()
1160 ret = device_property_read_u8(component->dev, "everest,interrupt-clk", in es8326_probe()
1161 &es8326->interrupt_clk); in es8326_probe()
1163 dev_dbg(component->dev, "interrupt-clk return %d", ret); in es8326_probe()
1164 es8326->interrupt_clk = 0x00; in es8326_probe()
1166 dev_dbg(component->dev, "interrupt-clk %x", es8326->interrupt_clk); in es8326_probe()
1177 mutex_lock(&es8326->lock); in es8326_enable_jack_detect()
1178 if (es8326->jd_inverted) in es8326_enable_jack_detect()
1180 ES8326_HP_DET_JACK_POL, ~es8326->jack_pol); in es8326_enable_jack_detect()
1181 es8326->jack = jack; in es8326_enable_jack_detect()
1183 mutex_unlock(&es8326->lock); in es8326_enable_jack_detect()
1184 es8326_irq(es8326->irq, es8326); in es8326_enable_jack_detect()
1191 dev_dbg(component->dev, "Enter into %s\n", __func__); in es8326_disable_jack_detect()
1192 if (!es8326->jack) in es8326_disable_jack_detect()
1194 cancel_delayed_work_sync(&es8326->jack_detect_work); in es8326_disable_jack_detect()
1196 mutex_lock(&es8326->lock); in es8326_disable_jack_detect()
1197 if (es8326->jack->status & SND_JACK_MICROPHONE) { in es8326_disable_jack_detect()
1199 snd_soc_jack_report(es8326->jack, 0, SND_JACK_HEADSET); in es8326_disable_jack_detect()
1201 es8326->jack = NULL; in es8326_disable_jack_detect()
1202 mutex_unlock(&es8326->lock); in es8326_disable_jack_detect()
1222 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x01); in es8326_remove()
1224 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x00); in es8326_remove()
1249 es8326 = devm_kzalloc(&i2c->dev, sizeof(struct es8326_priv), GFP_KERNEL); in es8326_i2c_probe()
1251 return -ENOMEM; in es8326_i2c_probe()
1254 es8326->i2c = i2c; in es8326_i2c_probe()
1255 mutex_init(&es8326->lock); in es8326_i2c_probe()
1256 es8326->regmap = devm_regmap_init_i2c(i2c, &es8326_regmap_config); in es8326_i2c_probe()
1257 if (IS_ERR(es8326->regmap)) { in es8326_i2c_probe()
1258 ret = PTR_ERR(es8326->regmap); in es8326_i2c_probe()
1259 dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret); in es8326_i2c_probe()
1263 es8326->irq = i2c->irq; in es8326_i2c_probe()
1264 es8326->jack_remove_retry = 0; in es8326_i2c_probe()
1265 es8326->hp = 0; in es8326_i2c_probe()
1266 es8326->hpl_vol = 0x03; in es8326_i2c_probe()
1267 es8326->hpr_vol = 0x03; in es8326_i2c_probe()
1268 INIT_DELAYED_WORK(&es8326->jack_detect_work, in es8326_i2c_probe()
1270 INIT_DELAYED_WORK(&es8326->button_press_work, in es8326_i2c_probe()
1272 /* ES8316 is level-based while ES8326 is edge-based */ in es8326_i2c_probe()
1273 ret = devm_request_threaded_irq(&i2c->dev, es8326->irq, NULL, es8326_irq, in es8326_i2c_probe()
1277 dev_warn(&i2c->dev, "Failed to request IRQ: %d: %d\n", in es8326_i2c_probe()
1278 es8326->irq, ret); in es8326_i2c_probe()
1279 es8326->irq = -ENXIO; in es8326_i2c_probe()
1282 es8326->mclk = devm_clk_get_optional(&i2c->dev, "mclk"); in es8326_i2c_probe()
1283 if (IS_ERR(es8326->mclk)) { in es8326_i2c_probe()
1284 dev_err(&i2c->dev, "unable to get mclk\n"); in es8326_i2c_probe()
1285 return PTR_ERR(es8326->mclk); in es8326_i2c_probe()
1287 if (!es8326->mclk) in es8326_i2c_probe()
1288 dev_warn(&i2c->dev, "assuming static mclk\n"); in es8326_i2c_probe()
1290 ret = clk_prepare_enable(es8326->mclk); in es8326_i2c_probe()
1292 dev_err(&i2c->dev, "unable to enable mclk\n"); in es8326_i2c_probe()
1295 return devm_snd_soc_register_component(&i2c->dev, in es8326_i2c_probe()
1307 component = es8326->component; in es8326_i2c_shutdown()
1308 dev_dbg(component->dev, "Enter into %s\n", __func__); in es8326_i2c_shutdown()
1309 cancel_delayed_work_sync(&es8326->jack_detect_work); in es8326_i2c_shutdown()
1310 cancel_delayed_work_sync(&es8326->button_press_work); in es8326_i2c_shutdown()
1312 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x01); in es8326_i2c_shutdown()
1314 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x00); in es8326_i2c_shutdown()
1359 MODULE_AUTHOR("David Yang <yangxiaohua@everest-semi.com>");