Lines Matching +full:gpio +full:- +full:out +full:- +full:pol
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);
283 SND_SOC_DAPM_AIF_OUT("I2S OUT", "I2S1 Capture", 0, SND_SOC_NOPM, 0, 0),
305 {"I2S OUT", NULL, "ADC L"},
306 {"I2S OUT", NULL, "ADC R"},
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, 0x30); 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()
634 regmap_update_bits(es8326->regmap, ES8326_CLK_INV, 0xc0, 0x00); in es8326_mute()
635 regmap_update_bits(es8326->regmap, ES8326_CLK_MUX, 0x80, 0x00); in es8326_mute()
637 regmap_update_bits(es8326->regmap, ES8326_DAC_DSM, 0x01, 0x01); in es8326_mute()
639 regmap_update_bits(es8326->regmap, ES8326_DAC_DSM, 0x01, 0x00); in es8326_mute()
641 regmap_update_bits(es8326->regmap, ES8326_HP_DRIVER_REF, 0x30, 0x20); in es8326_mute()
642 regmap_update_bits(es8326->regmap, ES8326_HP_DRIVER_REF, 0x30, 0x30); in es8326_mute()
643 regmap_write(es8326->regmap, ES8326_HP_DRIVER, 0xa1); in es8326_mute()
644 regmap_write(es8326->regmap, ES8326_HP_CAL, ES8326_HP_ON); in es8326_mute()
645 regmap_update_bits(es8326->regmap, ES8326_DAC_MUTE, in es8326_mute()
649 if (es8326->version > ES8326_VERSION_B) { in es8326_mute()
650 regmap_update_bits(es8326->regmap, ES8326_ANA_MICBIAS, 0x70, 0x70); in es8326_mute()
651 regmap_update_bits(es8326->regmap, ES8326_VMIDSEL, 0x40, 0x00); in es8326_mute()
653 regmap_update_bits(es8326->regmap, ES8326_ADC_MUTE, in es8326_mute()
668 ret = clk_prepare_enable(es8326->mclk); in es8326_set_bias_level()
672 regmap_update_bits(es8326->regmap, ES8326_RESET, 0x02, 0x02); in es8326_set_bias_level()
674 regmap_write(es8326->regmap, ES8326_INTOUT_IO, es8326->interrupt_clk); in es8326_set_bias_level()
675 regmap_write(es8326->regmap, ES8326_SDINOUT1_IO, in es8326_set_bias_level()
677 regmap_write(es8326->regmap, ES8326_PGA_PDN, 0x40); in es8326_set_bias_level()
678 regmap_write(es8326->regmap, ES8326_ANA_PDN, 0x00); in es8326_set_bias_level()
679 regmap_update_bits(es8326->regmap, ES8326_CLK_CTL, 0x20, 0x20); in es8326_set_bias_level()
680 regmap_update_bits(es8326->regmap, ES8326_RESET, 0x02, 0x00); in es8326_set_bias_level()
681 if (es8326->version > ES8326_VERSION_B) { in es8326_set_bias_level()
682 regmap_update_bits(es8326->regmap, ES8326_VMIDSEL, 0x40, 0x40); in es8326_set_bias_level()
683 regmap_update_bits(es8326->regmap, ES8326_ANA_MICBIAS, 0x70, 0x30); in es8326_set_bias_level()
689 regmap_write(es8326->regmap, ES8326_ANA_PDN, 0x3b); in es8326_set_bias_level()
690 regmap_update_bits(es8326->regmap, ES8326_CLK_CTL, 0x20, 0x00); in es8326_set_bias_level()
691 regmap_write(es8326->regmap, ES8326_SDINOUT1_IO, ES8326_IO_INPUT); in es8326_set_bias_level()
692 if (es8326->version > ES8326_VERSION_B) { in es8326_set_bias_level()
693 regmap_update_bits(es8326->regmap, ES8326_VMIDSEL, 0x40, 0x40); in es8326_set_bias_level()
694 regmap_update_bits(es8326->regmap, ES8326_ANA_MICBIAS, 0x70, 0x10); in es8326_set_bias_level()
696 regmap_update_bits(es8326->regmap, ES8326_CLK_INV, 0xc0, 0xc0); in es8326_set_bias_level()
697 regmap_update_bits(es8326->regmap, ES8326_CLK_MUX, 0x80, 0x80); in es8326_set_bias_level()
700 clk_disable_unprepare(es8326->mclk); in es8326_set_bias_level()
762 * snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
763 * snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
764 * snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
770 struct snd_soc_component *comp = es8326->component; in es8326_jack_button_handler()
775 if (!(es8326->jack->status & SND_JACK_HEADSET)) /* Jack unplugged */ in es8326_jack_button_handler()
778 mutex_lock(&es8326->lock); in es8326_jack_button_handler()
788 if ((iface == 0x6f) && (es8326->version > ES8326_VERSION_B)) in es8326_jack_button_handler()
810 snd_soc_jack_report(es8326->jack, cur_button, in es8326_jack_button_handler()
815 queue_delayed_work(system_wq, &es8326->button_press_work, in es8326_jack_button_handler()
820 queue_delayed_work(system_wq, &es8326->button_press_work, in es8326_jack_button_handler()
825 snd_soc_jack_report(es8326->jack, button_to_report, in es8326_jack_button_handler()
827 snd_soc_jack_report(es8326->jack, 0, in es8326_jack_button_handler()
831 es8326_disable_micbias(es8326->component); in es8326_jack_button_handler()
833 mutex_unlock(&es8326->lock); in es8326_jack_button_handler()
840 struct snd_soc_component *comp = es8326->component; in es8326_jack_detect_handler()
843 mutex_lock(&es8326->lock); in es8326_jack_detect_handler()
845 dev_dbg(comp->dev, "gpio flag %#04x", iface); in es8326_jack_detect_handler()
847 if ((es8326->jack_remove_retry == 1) && (es8326->version < ES8326_VERSION_B)) { in es8326_jack_detect_handler()
849 es8326->jack_remove_retry = 2; in es8326_jack_detect_handler()
851 es8326->jack_remove_retry = 0; in es8326_jack_detect_handler()
853 dev_dbg(comp->dev, "remove event check, set HPJACK_POL normal, cnt = %d\n", in es8326_jack_detect_handler()
854 es8326->jack_remove_retry); in es8326_jack_detect_handler()
858 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, in es8326_jack_detect_handler()
859 ES8326_HP_DET_JACK_POL, (es8326->jd_inverted ? in es8326_jack_detect_handler()
860 ~es8326->jack_pol : es8326->jack_pol)); in es8326_jack_detect_handler()
866 dev_dbg(comp->dev, "No headset detected\n"); in es8326_jack_detect_handler()
867 es8326_disable_micbias(es8326->component); in es8326_jack_detect_handler()
868 if (es8326->jack->status & SND_JACK_HEADPHONE) { in es8326_jack_detect_handler()
869 dev_dbg(comp->dev, "Report hp remove event\n"); in es8326_jack_detect_handler()
870 snd_soc_jack_report(es8326->jack, 0, in es8326_jack_detect_handler()
872 snd_soc_jack_report(es8326->jack, 0, SND_JACK_HEADSET); in es8326_jack_detect_handler()
874 regmap_write(es8326->regmap, ES8326_ADC1_SRC, 0x44); in es8326_jack_detect_handler()
875 regmap_write(es8326->regmap, ES8326_ADC2_SRC, 0x66); in es8326_jack_detect_handler()
877 es8326->hp = 0; in es8326_jack_detect_handler()
878 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x01); in es8326_jack_detect_handler()
879 regmap_write(es8326->regmap, ES8326_SYS_BIAS, 0x0a); in es8326_jack_detect_handler()
880 regmap_update_bits(es8326->regmap, ES8326_HP_DRIVER_REF, 0x0f, 0x03); in es8326_jack_detect_handler()
881 regmap_write(es8326->regmap, ES8326_INT_SOURCE, ES8326_INT_SRC_PIN9); in es8326_jack_detect_handler()
885 if ((es8326->jack_remove_retry == 0) && (es8326->version < ES8326_VERSION_B)) { in es8326_jack_detect_handler()
886 es8326->jack_remove_retry = 1; in es8326_jack_detect_handler()
887 dev_dbg(comp->dev, "remove event check, invert HPJACK_POL, cnt = %d\n", in es8326_jack_detect_handler()
888 es8326->jack_remove_retry); in es8326_jack_detect_handler()
889 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, in es8326_jack_detect_handler()
890 ES8326_HP_DET_JACK_POL, (es8326->jd_inverted ? in es8326_jack_detect_handler()
891 es8326->jack_pol : ~es8326->jack_pol)); in es8326_jack_detect_handler()
894 es8326->jack_remove_retry = 0; in es8326_jack_detect_handler()
897 es8326->jack_remove_retry = 0; in es8326_jack_detect_handler()
898 if (es8326->hp == 0) { in es8326_jack_detect_handler()
899 dev_dbg(comp->dev, "First insert, start OMTP/CTIA type check\n"); in es8326_jack_detect_handler()
901 * set auto-check mode, then restart jack_detect_work after 400ms. in es8326_jack_detect_handler()
904 regmap_write(es8326->regmap, ES8326_INT_SOURCE, 0x00); in es8326_jack_detect_handler()
905 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x01); in es8326_jack_detect_handler()
906 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x10, 0x00); in es8326_jack_detect_handler()
908 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x00); in es8326_jack_detect_handler()
909 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x10, 0x10); in es8326_jack_detect_handler()
911 regmap_write(es8326->regmap, ES8326_INT_SOURCE, in es8326_jack_detect_handler()
913 regmap_write(es8326->regmap, ES8326_SYS_BIAS, 0x1f); in es8326_jack_detect_handler()
914 regmap_update_bits(es8326->regmap, ES8326_HP_DRIVER_REF, 0x0f, 0x0d); in es8326_jack_detect_handler()
915 queue_delayed_work(system_wq, &es8326->jack_detect_work, in es8326_jack_detect_handler()
917 es8326->hp = 1; in es8326_jack_detect_handler()
920 if (es8326->jack->status & SND_JACK_HEADSET) { in es8326_jack_detect_handler()
922 dev_dbg(comp->dev, "button pressed\n"); in es8326_jack_detect_handler()
923 regmap_write(es8326->regmap, ES8326_INT_SOURCE, in es8326_jack_detect_handler()
925 es8326_enable_micbias(es8326->component); in es8326_jack_detect_handler()
926 queue_delayed_work(system_wq, &es8326->button_press_work, 10); in es8326_jack_detect_handler()
930 dev_dbg(comp->dev, "Headphone detected\n"); in es8326_jack_detect_handler()
931 snd_soc_jack_report(es8326->jack, in es8326_jack_detect_handler()
934 dev_dbg(comp->dev, "Headset detected\n"); in es8326_jack_detect_handler()
935 snd_soc_jack_report(es8326->jack, in es8326_jack_detect_handler()
938 regmap_update_bits(es8326->regmap, ES8326_PGA_PDN, in es8326_jack_detect_handler()
940 regmap_update_bits(es8326->regmap, ES8326_PGAGAIN, in es8326_jack_detect_handler()
942 regmap_write(es8326->regmap, ES8326_ADC1_SRC, 0x00); in es8326_jack_detect_handler()
943 regmap_write(es8326->regmap, ES8326_ADC2_SRC, 0x00); in es8326_jack_detect_handler()
944 regmap_update_bits(es8326->regmap, ES8326_PGA_PDN, in es8326_jack_detect_handler()
950 mutex_unlock(&es8326->lock); in es8326_jack_detect_handler()
957 if (!es8326->jack) in es8326_irq()
958 goto out; in es8326_irq()
960 if (es8326->jack->status & SND_JACK_HEADSET) in es8326_irq()
961 queue_delayed_work(system_wq, &es8326->jack_detect_work, in es8326_irq()
964 queue_delayed_work(system_wq, &es8326->jack_detect_work, in es8326_irq()
967 out: in es8326_irq()
977 regmap_read(es8326->regmap, ES8326_CHIP_VERSION, ®); in es8326_calibrate()
978 es8326->version = reg; in es8326_calibrate()
980 if ((es8326->version >= ES8326_VERSION_B) && (es8326->calibrated == false)) { in es8326_calibrate()
981 dev_dbg(component->dev, "ES8326_VERSION_B, calibrating\n"); in es8326_calibrate()
982 regmap_write(es8326->regmap, ES8326_CLK_INV, 0xc0); in es8326_calibrate()
983 regmap_write(es8326->regmap, ES8326_CLK_DIV1, 0x03); in es8326_calibrate()
984 regmap_write(es8326->regmap, ES8326_CLK_DLL, 0x30); in es8326_calibrate()
985 regmap_write(es8326->regmap, ES8326_CLK_MUX, 0xed); in es8326_calibrate()
986 regmap_write(es8326->regmap, ES8326_CLK_DAC_SEL, 0x08); in es8326_calibrate()
987 regmap_write(es8326->regmap, ES8326_CLK_TRI, 0xc1); in es8326_calibrate()
988 regmap_write(es8326->regmap, ES8326_DAC_MUTE, 0x03); in es8326_calibrate()
989 regmap_write(es8326->regmap, ES8326_ANA_VSEL, 0x7f); in es8326_calibrate()
990 regmap_write(es8326->regmap, ES8326_VMIDLOW, 0x23); in es8326_calibrate()
991 regmap_write(es8326->regmap, ES8326_DAC2HPMIX, 0x88); in es8326_calibrate()
993 regmap_write(es8326->regmap, ES8326_HP_OFFSET_CAL, 0x8c); in es8326_calibrate()
995 regmap_write(es8326->regmap, ES8326_RESET, 0xc0); in es8326_calibrate()
998 regmap_write(es8326->regmap, ES8326_HP_OFFSET_CAL, ES8326_HP_OFF); in es8326_calibrate()
999 regmap_read(es8326->regmap, ES8326_CSM_MUTE_STA, ®); in es8326_calibrate()
1003 regmap_write(es8326->regmap, ES8326_HP_CAL, 0xd4); in es8326_calibrate()
1005 regmap_write(es8326->regmap, ES8326_HP_CAL, 0x4d); in es8326_calibrate()
1007 regmap_write(es8326->regmap, ES8326_HP_CAL, ES8326_HP_OFF); in es8326_calibrate()
1008 regmap_read(es8326->regmap, ES8326_HPL_OFFSET_INI, &offset_l); in es8326_calibrate()
1009 regmap_read(es8326->regmap, ES8326_HPR_OFFSET_INI, &offset_r); in es8326_calibrate()
1010 regmap_write(es8326->regmap, ES8326_HP_OFFSET_CAL, 0x8c); in es8326_calibrate()
1011 regmap_write(es8326->regmap, ES8326_HPL_OFFSET_INI, offset_l); in es8326_calibrate()
1012 regmap_write(es8326->regmap, ES8326_HPR_OFFSET_INI, offset_r); in es8326_calibrate()
1013 regmap_write(es8326->regmap, ES8326_CLK_INV, 0x00); in es8326_calibrate()
1015 es8326->calibrated = true; in es8326_calibrate()
1025 regmap_write(es8326->regmap, ES8326_RESET, 0x1f); in es8326_init()
1026 regmap_write(es8326->regmap, ES8326_VMIDSEL, 0x3E); in es8326_init()
1027 regmap_write(es8326->regmap, ES8326_ANA_LP, 0xf0); in es8326_init()
1029 regmap_write(es8326->regmap, ES8326_HPJACK_TIMER, 0xd9); in es8326_init()
1030 regmap_write(es8326->regmap, ES8326_ANA_MICBIAS, 0xd8); in es8326_init()
1032 regmap_write(es8326->regmap, ES8326_HPDET_TYPE, 0x83); in es8326_init()
1033 regmap_write(es8326->regmap, ES8326_CLK_RESAMPLE, 0x05); in es8326_init()
1036 regmap_write(es8326->regmap, ES8326_CLK_DIV_CPC, 0x89); in es8326_init()
1037 regmap_write(es8326->regmap, ES8326_CLK_CTL, ES8326_CLK_ON); in es8326_init()
1039 regmap_write(es8326->regmap, ES8326_RESET, 0x17); in es8326_init()
1041 regmap_write(es8326->regmap, ES8326_HP_MISC, 0x3d); in es8326_init()
1042 regmap_write(es8326->regmap, ES8326_PULLUP_CTL, 0x00); in es8326_init()
1045 regmap_write(es8326->regmap, ES8326_HP_VOL, 0xc4); in es8326_init()
1046 regmap_write(es8326->regmap, ES8326_HP_DRIVER, 0xa7); in es8326_init()
1048 regmap_write(es8326->regmap, ES8326_HP_DRIVER_REF, 0x23); in es8326_init()
1049 regmap_write(es8326->regmap, ES8326_HP_DRIVER_REF, 0x33); in es8326_init()
1050 regmap_write(es8326->regmap, ES8326_HP_DRIVER, 0xa1); in es8326_init()
1052 regmap_write(es8326->regmap, ES8326_CLK_INV, 0x00); in es8326_init()
1053 regmap_write(es8326->regmap, ES8326_CLK_VMIDS1, 0xc4); in es8326_init()
1054 regmap_write(es8326->regmap, ES8326_CLK_VMIDS2, 0x81); in es8326_init()
1055 regmap_write(es8326->regmap, ES8326_CLK_CAL_TIME, 0x00); in es8326_init()
1058 regmap_write(es8326->regmap, ES8326_DAC_CROSSTALK, 0xaa); in es8326_init()
1059 regmap_write(es8326->regmap, ES8326_DAC_RAMPRATE, 0x00); in es8326_init()
1060 /* turn off headphone out */ in es8326_init()
1061 regmap_write(es8326->regmap, ES8326_HP_CAL, 0x00); in es8326_init()
1063 regmap_write(es8326->regmap, ES8326_ANA_LP, 0xf0); in es8326_init()
1065 regmap_write(es8326->regmap, ES8326_ANA_VSEL, 0x7F); in es8326_init()
1067 regmap_write(es8326->regmap, ES8326_VMIDLOW, 0x03); in es8326_init()
1069 regmap_write(es8326->regmap, ES8326_DAC_DSM, 0x08); in es8326_init()
1070 regmap_write(es8326->regmap, ES8326_DAC_VPPSCALE, 0x15); in es8326_init()
1072 regmap_write(es8326->regmap, ES8326_HPDET_TYPE, 0x80 | in es8326_init()
1073 ((es8326->version >= ES8326_VERSION_B) ? in es8326_init()
1074 (ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol) : in es8326_init()
1075 (ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol | 0x04))); in es8326_init()
1077 es8326_enable_micbias(es8326->component); in es8326_init()
1079 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x00); in es8326_init()
1080 regmap_write(es8326->regmap, ES8326_INTOUT_IO, in es8326_init()
1081 es8326->interrupt_clk); in es8326_init()
1082 regmap_write(es8326->regmap, ES8326_SDINOUT1_IO, in es8326_init()
1084 regmap_write(es8326->regmap, ES8326_SDINOUT23_IO, ES8326_IO_INPUT); in es8326_init()
1086 regmap_write(es8326->regmap, ES8326_ANA_PDN, 0x00); in es8326_init()
1087 regmap_write(es8326->regmap, ES8326_RESET, ES8326_CSM_ON); in es8326_init()
1088 regmap_update_bits(es8326->regmap, ES8326_PGAGAIN, ES8326_MIC_SEL_MASK, in es8326_init()
1091 regmap_update_bits(es8326->regmap, ES8326_DAC_MUTE, ES8326_MUTE_MASK, in es8326_init()
1094 regmap_write(es8326->regmap, ES8326_ADC_MUTE, 0x0f); in es8326_init()
1095 regmap_write(es8326->regmap, ES8326_CLK_DIV_LRCK, 0xff); in es8326_init()
1096 regmap_write(es8326->regmap, ES8326_ADC1_SRC, 0x44); in es8326_init()
1097 regmap_write(es8326->regmap, ES8326_ADC2_SRC, 0x66); in es8326_init()
1098 es8326_disable_micbias(es8326->component); in es8326_init()
1099 if (es8326->version > ES8326_VERSION_B) { in es8326_init()
1100 regmap_update_bits(es8326->regmap, ES8326_ANA_MICBIAS, 0x73, 0x10); in es8326_init()
1101 regmap_update_bits(es8326->regmap, ES8326_VMIDSEL, 0x40, 0x40); in es8326_init()
1105 regmap_write(es8326->regmap, ES8326_INT_SOURCE, ES8326_INT_SRC_PIN9); in es8326_init()
1113 regcache_cache_only(es8326->regmap, false); in es8326_resume()
1114 regcache_cache_bypass(es8326->regmap, true); in es8326_resume()
1115 regmap_read(es8326->regmap, ES8326_CLK_RESAMPLE, ®); in es8326_resume()
1116 regcache_cache_bypass(es8326->regmap, false); in es8326_resume()
1119 regmap_write(es8326->regmap, ES8326_CLK_CTL, ES8326_CLK_ON); in es8326_resume()
1123 regcache_sync(es8326->regmap); in es8326_resume()
1125 es8326_irq(es8326->irq, es8326); in es8326_resume()
1133 cancel_delayed_work_sync(&es8326->jack_detect_work); in es8326_suspend()
1135 es8326->calibrated = false; in es8326_suspend()
1136 regmap_write(es8326->regmap, ES8326_CLK_MUX, 0x2d); in es8326_suspend()
1137 regmap_write(es8326->regmap, ES8326_DAC2HPMIX, 0x00); in es8326_suspend()
1138 regmap_write(es8326->regmap, ES8326_ANA_PDN, 0x3b); in es8326_suspend()
1139 regmap_write(es8326->regmap, ES8326_CLK_CTL, ES8326_CLK_OFF); in es8326_suspend()
1140 regcache_cache_only(es8326->regmap, true); in es8326_suspend()
1143 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x01); in es8326_suspend()
1145 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x00); in es8326_suspend()
1147 regcache_mark_dirty(es8326->regmap); in es8326_suspend()
1156 es8326->component = component; in es8326_probe()
1157 es8326->jd_inverted = device_property_read_bool(component->dev, in es8326_probe()
1158 "everest,jack-detect-inverted"); in es8326_probe()
1160 ret = device_property_read_u8(component->dev, "everest,jack-pol", &es8326->jack_pol); in es8326_probe()
1162 dev_dbg(component->dev, "jack-pol return %d", ret); in es8326_probe()
1163 es8326->jack_pol = ES8326_HP_TYPE_AUTO; in es8326_probe()
1165 dev_dbg(component->dev, "jack-pol %x", es8326->jack_pol); in es8326_probe()
1167 ret = device_property_read_u8(component->dev, "everest,interrupt-src", in es8326_probe()
1168 &es8326->interrupt_src); in es8326_probe()
1170 dev_dbg(component->dev, "interrupt-src return %d", ret); in es8326_probe()
1171 es8326->interrupt_src = ES8326_HP_DET_SRC_PIN9; in es8326_probe()
1173 dev_dbg(component->dev, "interrupt-src %x", es8326->interrupt_src); in es8326_probe()
1175 ret = device_property_read_u8(component->dev, "everest,interrupt-clk", in es8326_probe()
1176 &es8326->interrupt_clk); in es8326_probe()
1178 dev_dbg(component->dev, "interrupt-clk return %d", ret); in es8326_probe()
1179 es8326->interrupt_clk = 0x00; in es8326_probe()
1181 dev_dbg(component->dev, "interrupt-clk %x", es8326->interrupt_clk); in es8326_probe()
1192 mutex_lock(&es8326->lock); in es8326_enable_jack_detect()
1193 if (es8326->jd_inverted) in es8326_enable_jack_detect()
1195 ES8326_HP_DET_JACK_POL, ~es8326->jack_pol); in es8326_enable_jack_detect()
1196 es8326->jack = jack; in es8326_enable_jack_detect()
1198 mutex_unlock(&es8326->lock); in es8326_enable_jack_detect()
1199 es8326_irq(es8326->irq, es8326); in es8326_enable_jack_detect()
1206 dev_dbg(component->dev, "Enter into %s\n", __func__); in es8326_disable_jack_detect()
1207 if (!es8326->jack) in es8326_disable_jack_detect()
1209 cancel_delayed_work_sync(&es8326->jack_detect_work); in es8326_disable_jack_detect()
1211 mutex_lock(&es8326->lock); in es8326_disable_jack_detect()
1212 if (es8326->jack->status & SND_JACK_MICROPHONE) { in es8326_disable_jack_detect()
1214 snd_soc_jack_report(es8326->jack, 0, SND_JACK_HEADSET); in es8326_disable_jack_detect()
1216 es8326->jack = NULL; in es8326_disable_jack_detect()
1217 mutex_unlock(&es8326->lock); in es8326_disable_jack_detect()
1237 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x01); in es8326_remove()
1239 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x00); in es8326_remove()
1264 es8326 = devm_kzalloc(&i2c->dev, sizeof(struct es8326_priv), GFP_KERNEL); in es8326_i2c_probe()
1266 return -ENOMEM; in es8326_i2c_probe()
1269 es8326->i2c = i2c; in es8326_i2c_probe()
1270 mutex_init(&es8326->lock); in es8326_i2c_probe()
1271 es8326->regmap = devm_regmap_init_i2c(i2c, &es8326_regmap_config); in es8326_i2c_probe()
1272 if (IS_ERR(es8326->regmap)) { in es8326_i2c_probe()
1273 ret = PTR_ERR(es8326->regmap); in es8326_i2c_probe()
1274 dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret); in es8326_i2c_probe()
1278 es8326->irq = i2c->irq; in es8326_i2c_probe()
1279 es8326->jack_remove_retry = 0; in es8326_i2c_probe()
1280 es8326->hp = 0; in es8326_i2c_probe()
1281 es8326->hpl_vol = 0x03; in es8326_i2c_probe()
1282 es8326->hpr_vol = 0x03; in es8326_i2c_probe()
1283 INIT_DELAYED_WORK(&es8326->jack_detect_work, in es8326_i2c_probe()
1285 INIT_DELAYED_WORK(&es8326->button_press_work, in es8326_i2c_probe()
1287 /* ES8316 is level-based while ES8326 is edge-based */ in es8326_i2c_probe()
1288 ret = devm_request_threaded_irq(&i2c->dev, es8326->irq, NULL, es8326_irq, in es8326_i2c_probe()
1292 dev_warn(&i2c->dev, "Failed to request IRQ: %d: %d\n", in es8326_i2c_probe()
1293 es8326->irq, ret); in es8326_i2c_probe()
1294 es8326->irq = -ENXIO; in es8326_i2c_probe()
1297 es8326->mclk = devm_clk_get_optional(&i2c->dev, "mclk"); in es8326_i2c_probe()
1298 if (IS_ERR(es8326->mclk)) { in es8326_i2c_probe()
1299 dev_err(&i2c->dev, "unable to get mclk\n"); in es8326_i2c_probe()
1300 return PTR_ERR(es8326->mclk); in es8326_i2c_probe()
1302 if (!es8326->mclk) in es8326_i2c_probe()
1303 dev_warn(&i2c->dev, "assuming static mclk\n"); in es8326_i2c_probe()
1305 ret = clk_prepare_enable(es8326->mclk); in es8326_i2c_probe()
1307 dev_err(&i2c->dev, "unable to enable mclk\n"); in es8326_i2c_probe()
1310 return devm_snd_soc_register_component(&i2c->dev, in es8326_i2c_probe()
1322 component = es8326->component; in es8326_i2c_shutdown()
1323 dev_dbg(component->dev, "Enter into %s\n", __func__); in es8326_i2c_shutdown()
1324 cancel_delayed_work_sync(&es8326->jack_detect_work); in es8326_i2c_shutdown()
1325 cancel_delayed_work_sync(&es8326->button_press_work); in es8326_i2c_shutdown()
1327 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x01); in es8326_i2c_shutdown()
1329 regmap_write(es8326->regmap, ES8326_CSM_I2C_STA, 0x00); in es8326_i2c_shutdown()
1374 MODULE_AUTHOR("David Yang <yangxiaohua@everest-semi.com>");