es8326.c (61b7369483efb5e0a9f3b48e75fac00d46d661e0) es8326.c (4ddad00c609bdcd6635537d3acb9bd57a5fc79e6)
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// es8326.c -- es8326 ALSA SoC audio driver
4// Copyright Everest Semiconductor Co., Ltd
5//
6// Authors: David Yang <yangxiaohua@everest-semi.com>
7//
8

--- 24 unchanged lines hidden (view full) ---

33 struct mutex lock;
34 u8 mic1_src;
35 u8 mic2_src;
36 u8 jack_pol;
37 u8 interrupt_src;
38 u8 interrupt_clk;
39 bool jd_inverted;
40 unsigned int sysclk;
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// es8326.c -- es8326 ALSA SoC audio driver
4// Copyright Everest Semiconductor Co., Ltd
5//
6// Authors: David Yang <yangxiaohua@everest-semi.com>
7//
8

--- 24 unchanged lines hidden (view full) ---

33 struct mutex lock;
34 u8 mic1_src;
35 u8 mic2_src;
36 u8 jack_pol;
37 u8 interrupt_src;
38 u8 interrupt_clk;
39 bool jd_inverted;
40 unsigned int sysclk;
41
42 bool calibrated;
43 int version;
41};
42
43static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(dac_vol_tlv, -9550, 50, 0);
44static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_vol_tlv, -9550, 50, 0);
45static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_analog_pga_tlv, 0, 300, 0);
46static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_pga_tlv, 0, 600, 0);
47static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(softramp_rate, 0, 100, 0);
48static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(drc_target_tlv, -3200, 200, 0);

--- 67 unchanged lines hidden (view full) ---

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),
120
121 /* Analog Power Supply*/
122 SND_SOC_DAPM_DAC("Right DAC", NULL, ES8326_ANA_PDN, 0, 1),
123 SND_SOC_DAPM_DAC("Left DAC", NULL, ES8326_ANA_PDN, 1, 1),
44};
45
46static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(dac_vol_tlv, -9550, 50, 0);
47static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_vol_tlv, -9550, 50, 0);
48static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_analog_pga_tlv, 0, 300, 0);
49static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_pga_tlv, 0, 600, 0);
50static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(softramp_rate, 0, 100, 0);
51static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(drc_target_tlv, -3200, 200, 0);

--- 67 unchanged lines hidden (view full) ---

119 SND_SOC_DAPM_PGA("ADC L1", ES8326_ADC_MUTE, 0, 1, NULL, 0),
120 SND_SOC_DAPM_PGA("ADC R1", ES8326_ADC_MUTE, 1, 1, NULL, 0),
121 SND_SOC_DAPM_PGA("ADC L2", ES8326_ADC_MUTE, 2, 1, NULL, 0),
122 SND_SOC_DAPM_PGA("ADC R2", ES8326_ADC_MUTE, 3, 1, NULL, 0),
123
124 /* Analog Power Supply*/
125 SND_SOC_DAPM_DAC("Right DAC", NULL, ES8326_ANA_PDN, 0, 1),
126 SND_SOC_DAPM_DAC("Left DAC", NULL, ES8326_ANA_PDN, 1, 1),
124 SND_SOC_DAPM_SUPPLY("Analog Power", ES8326_ANA_PDN, 7, 1, NULL, 0),
125 SND_SOC_DAPM_SUPPLY("IBias Power", ES8326_ANA_PDN, 6, 1, NULL, 0),
126 SND_SOC_DAPM_SUPPLY("ADC Vref", ES8326_ANA_PDN, 5, 1, NULL, 0),
127 SND_SOC_DAPM_SUPPLY("DAC Vref", ES8326_ANA_PDN, 4, 1, NULL, 0),
128 SND_SOC_DAPM_SUPPLY("Vref Power", ES8326_ANA_PDN, 3, 1, NULL, 0),
129 SND_SOC_DAPM_SUPPLY("MICBIAS1", ES8326_ANA_MICBIAS, 2, 0, NULL, 0),
130 SND_SOC_DAPM_SUPPLY("MICBIAS2", ES8326_ANA_MICBIAS, 3, 0, NULL, 0),
131
132 SND_SOC_DAPM_PGA("LHPMIX", ES8326_DAC2HPMIX, 7, 0, NULL, 0),
133 SND_SOC_DAPM_PGA("RHPMIX", ES8326_DAC2HPMIX, 3, 0, NULL, 0),
134
127 SND_SOC_DAPM_SUPPLY("MICBIAS1", ES8326_ANA_MICBIAS, 2, 0, NULL, 0),
128 SND_SOC_DAPM_SUPPLY("MICBIAS2", ES8326_ANA_MICBIAS, 3, 0, NULL, 0),
129
130 SND_SOC_DAPM_PGA("LHPMIX", ES8326_DAC2HPMIX, 7, 0, NULL, 0),
131 SND_SOC_DAPM_PGA("RHPMIX", ES8326_DAC2HPMIX, 3, 0, NULL, 0),
132
135 /* Headphone Charge Pump and Output */
136 SND_SOC_DAPM_SUPPLY("HPOR Cal", ES8326_HP_CAL, 7, 1, NULL, 0),
137 SND_SOC_DAPM_SUPPLY("HPOL Cal", ES8326_HP_CAL, 3, 1, NULL, 0),
138 SND_SOC_DAPM_SUPPLY("Headphone Charge Pump", ES8326_HP_DRIVER,
139 3, 1, NULL, 0),
140 SND_SOC_DAPM_SUPPLY("Headphone Driver Bias", ES8326_HP_DRIVER,
141 2, 1, NULL, 0),
142 SND_SOC_DAPM_SUPPLY("Headphone LDO", ES8326_HP_DRIVER,
143 1, 1, NULL, 0),
144 SND_SOC_DAPM_SUPPLY("Headphone Reference", ES8326_HP_DRIVER,
145 0, 1, NULL, 0),
146 SND_SOC_DAPM_REG(snd_soc_dapm_supply, "HPOR Supply", ES8326_HP_CAL,
147 ES8326_HPOR_SHIFT, 7, 7, 0),
148 SND_SOC_DAPM_REG(snd_soc_dapm_supply, "HPOL Supply", ES8326_HP_CAL,
149 0, 7, 7, 0),
150
151 SND_SOC_DAPM_OUTPUT("HPOL"),
152 SND_SOC_DAPM_OUTPUT("HPOR"),
153};
154
155static const struct snd_soc_dapm_route es8326_dapm_routes[] = {
156 {"ADC L1", NULL, "MIC1"},
157 {"ADC R1", NULL, "MIC2"},
158 {"ADC L2", NULL, "MIC3"},
159 {"ADC R2", NULL, "MIC4"},
160
161 {"ADC L", NULL, "ADC L1"},
162 {"ADC R", NULL, "ADC R1"},
163 {"ADC L", NULL, "ADC L2"},
164 {"ADC R", NULL, "ADC R2"},
165
166 {"I2S OUT", NULL, "ADC L"},
167 {"I2S OUT", NULL, "ADC R"},
168
133 SND_SOC_DAPM_OUTPUT("HPOL"),
134 SND_SOC_DAPM_OUTPUT("HPOR"),
135};
136
137static const struct snd_soc_dapm_route es8326_dapm_routes[] = {
138 {"ADC L1", NULL, "MIC1"},
139 {"ADC R1", NULL, "MIC2"},
140 {"ADC L2", NULL, "MIC3"},
141 {"ADC R2", NULL, "MIC4"},
142
143 {"ADC L", NULL, "ADC L1"},
144 {"ADC R", NULL, "ADC R1"},
145 {"ADC L", NULL, "ADC L2"},
146 {"ADC R", NULL, "ADC R2"},
147
148 {"I2S OUT", NULL, "ADC L"},
149 {"I2S OUT", NULL, "ADC R"},
150
169 {"I2S OUT", NULL, "Analog Power"},
170 {"I2S OUT", NULL, "ADC Vref"},
171 {"I2S OUT", NULL, "Vref Power"},
172 {"I2S OUT", NULL, "IBias Power"},
173 {"I2S IN", NULL, "Analog Power"},
174 {"I2S IN", NULL, "DAC Vref"},
175 {"I2S IN", NULL, "Vref Power"},
176 {"I2S IN", NULL, "IBias Power"},
177
178 {"Right DAC", NULL, "I2S IN"},
179 {"Left DAC", NULL, "I2S IN"},
180
181 {"LHPMIX", NULL, "Left DAC"},
182 {"RHPMIX", NULL, "Right DAC"},
183
151 {"Right DAC", NULL, "I2S IN"},
152 {"Left DAC", NULL, "I2S IN"},
153
154 {"LHPMIX", NULL, "Left DAC"},
155 {"RHPMIX", NULL, "Right DAC"},
156
184 {"HPOR", NULL, "HPOR Cal"},
185 {"HPOL", NULL, "HPOL Cal"},
186 {"HPOR", NULL, "HPOR Supply"},
187 {"HPOL", NULL, "HPOL Supply"},
188 {"HPOL", NULL, "Headphone Charge Pump"},
189 {"HPOR", NULL, "Headphone Charge Pump"},
190 {"HPOL", NULL, "Headphone Driver Bias"},
191 {"HPOR", NULL, "Headphone Driver Bias"},
192 {"HPOL", NULL, "Headphone LDO"},
193 {"HPOR", NULL, "Headphone LDO"},
194 {"HPOL", NULL, "Headphone Reference"},
195 {"HPOR", NULL, "Headphone Reference"},
196
197 {"HPOL", NULL, "LHPMIX"},
198 {"HPOR", NULL, "RHPMIX"},
199};
200
201static const struct regmap_range es8326_volatile_ranges[] = {
157 {"HPOL", NULL, "LHPMIX"},
158 {"HPOR", NULL, "RHPMIX"},
159};
160
161static const struct regmap_range es8326_volatile_ranges[] = {
202 regmap_reg_range(ES8326_HP_DETECT, ES8326_HP_DETECT),
162 regmap_reg_range(ES8326_HPDET_STA, ES8326_HPDET_STA),
203};
204
205static const struct regmap_access_table es8326_volatile_table = {
206 .yes_ranges = es8326_volatile_ranges,
207 .n_yes_ranges = ARRAY_SIZE(es8326_volatile_ranges),
208};
209
210static const struct regmap_config es8326_regmap_config = {

--- 203 unchanged lines hidden (view full) ---

414 coeff_div[coeff].regb);
415 } else {
416 dev_warn(component->dev, "Clock coefficients do not match");
417 }
418
419 return 0;
420}
421
163};
164
165static const struct regmap_access_table es8326_volatile_table = {
166 .yes_ranges = es8326_volatile_ranges,
167 .n_yes_ranges = ARRAY_SIZE(es8326_volatile_ranges),
168};
169
170static const struct regmap_config es8326_regmap_config = {

--- 203 unchanged lines hidden (view full) ---

374 coeff_div[coeff].regb);
375 } else {
376 dev_warn(component->dev, "Clock coefficients do not match");
377 }
378
379 return 0;
380}
381
382static int es8326_mute(struct snd_soc_dai *dai, int mute, int direction)
383{
384 struct snd_soc_component *component = dai->component;
385 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component);
386
387 if (mute) {
388 regmap_write(es8326->regmap, ES8326_HP_CAL, ES8326_HP_OFF);
389 regmap_update_bits(es8326->regmap, ES8326_DAC_MUTE,
390 ES8326_MUTE_MASK, ES8326_MUTE);
391 regmap_write(es8326->regmap, ES8326_HP_DRIVER, 0xf0);
392 } else {
393 if (!es8326->calibrated) {
394 regmap_write(es8326->regmap, ES8326_HP_CAL, ES8326_HP_FORCE_CAL);
395 msleep(30);
396 es8326->calibrated = true;
397 }
398 regmap_write(es8326->regmap, ES8326_HP_DRIVER, 0xa0);
399 regmap_write(es8326->regmap, ES8326_HP_VOL, 0x00);
400 regmap_write(es8326->regmap, ES8326_HP_CAL, ES8326_HP_ON);
401 regmap_update_bits(es8326->regmap, ES8326_DAC_MUTE,
402 ES8326_MUTE_MASK, ~(ES8326_MUTE));
403 }
404 return 0;
405}
406
422static int es8326_set_bias_level(struct snd_soc_component *codec,
423 enum snd_soc_bias_level level)
424{
425 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(codec);
426 int ret;
427
428 switch (level) {
429 case SND_SOC_BIAS_ON:

--- 34 unchanged lines hidden (view full) ---

464
465#define es8326_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
466 SNDRV_PCM_FMTBIT_S24_LE)
467
468static const struct snd_soc_dai_ops es8326_ops = {
469 .hw_params = es8326_pcm_hw_params,
470 .set_fmt = es8326_set_dai_fmt,
471 .set_sysclk = es8326_set_dai_sysclk,
407static int es8326_set_bias_level(struct snd_soc_component *codec,
408 enum snd_soc_bias_level level)
409{
410 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(codec);
411 int ret;
412
413 switch (level) {
414 case SND_SOC_BIAS_ON:

--- 34 unchanged lines hidden (view full) ---

449
450#define es8326_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
451 SNDRV_PCM_FMTBIT_S24_LE)
452
453static const struct snd_soc_dai_ops es8326_ops = {
454 .hw_params = es8326_pcm_hw_params,
455 .set_fmt = es8326_set_dai_fmt,
456 .set_sysclk = es8326_set_dai_sysclk,
457 .mute_stream = es8326_mute,
458 .no_capture_mute = 1,
472};
473
474static struct snd_soc_dai_driver es8326_dai = {
475 .name = "ES8326 HiFi",
476 .playback = {
477 .stream_name = "Playback",
478 .channels_min = 1,
479 .channels_max = 2,

--- 47 unchanged lines hidden (view full) ---

527 unsigned int iface;
528 static int button_to_report, press_count;
529 static int prev_button, cur_button;
530
531 if (!(es8326->jack->status & SND_JACK_HEADSET)) /* Jack unplugged */
532 return;
533
534 mutex_lock(&es8326->lock);
459};
460
461static struct snd_soc_dai_driver es8326_dai = {
462 .name = "ES8326 HiFi",
463 .playback = {
464 .stream_name = "Playback",
465 .channels_min = 1,
466 .channels_max = 2,

--- 47 unchanged lines hidden (view full) ---

514 unsigned int iface;
515 static int button_to_report, press_count;
516 static int prev_button, cur_button;
517
518 if (!(es8326->jack->status & SND_JACK_HEADSET)) /* Jack unplugged */
519 return;
520
521 mutex_lock(&es8326->lock);
535 iface = snd_soc_component_read(comp, ES8326_HP_DETECT);
522 iface = snd_soc_component_read(comp, ES8326_HPDET_STA);
536 switch (iface) {
537 case 0x93:
538 /* pause button detected */
539 cur_button = SND_JACK_BTN_0;
540 break;
541 case 0x6f:
542 /* button volume up */
543 cur_button = SND_JACK_BTN_1;

--- 42 unchanged lines hidden (view full) ---

586static void es8326_jack_detect_handler(struct work_struct *work)
587{
588 struct es8326_priv *es8326 =
589 container_of(work, struct es8326_priv, jack_detect_work.work);
590 struct snd_soc_component *comp = es8326->component;
591 unsigned int iface;
592
593 mutex_lock(&es8326->lock);
523 switch (iface) {
524 case 0x93:
525 /* pause button detected */
526 cur_button = SND_JACK_BTN_0;
527 break;
528 case 0x6f:
529 /* button volume up */
530 cur_button = SND_JACK_BTN_1;

--- 42 unchanged lines hidden (view full) ---

573static void es8326_jack_detect_handler(struct work_struct *work)
574{
575 struct es8326_priv *es8326 =
576 container_of(work, struct es8326_priv, jack_detect_work.work);
577 struct snd_soc_component *comp = es8326->component;
578 unsigned int iface;
579
580 mutex_lock(&es8326->lock);
594 iface = snd_soc_component_read(comp, ES8326_HP_DETECT);
581 iface = snd_soc_component_read(comp, ES8326_HPDET_STA);
595 dev_dbg(comp->dev, "gpio flag %#04x", iface);
596 if ((iface & ES8326_HPINSERT_FLAG) == 0) {
597 /* Jack unplugged or spurious IRQ */
598 dev_dbg(comp->dev, "No headset detected");
599 if (es8326->jack->status & SND_JACK_HEADPHONE) {
600 snd_soc_jack_report(es8326->jack, 0, SND_JACK_HEADSET);
601 snd_soc_component_write(comp, ES8326_ADC1_SRC, es8326->mic2_src);
602 es8326_disable_micbias(comp);

--- 56 unchanged lines hidden (view full) ---

659 regmap_write(es8326->regmap, ES8326_CLK_VMIDS1, 0xC8);
660 regmap_write(es8326->regmap, ES8326_CLK_VMIDS2, 0x88);
661 regmap_write(es8326->regmap, ES8326_CLK_CAL_TIME, 0x20);
662 regmap_write(es8326->regmap, ES8326_SYS_BIAS, 0x08);
663 regmap_write(es8326->regmap, ES8326_DAC2HPMIX, 0x22);
664 regmap_write(es8326->regmap, ES8326_ADC1_SRC, es8326->mic1_src);
665 regmap_write(es8326->regmap, ES8326_ADC2_SRC, es8326->mic2_src);
666 regmap_write(es8326->regmap, ES8326_HPJACK_TIMER, 0x88);
582 dev_dbg(comp->dev, "gpio flag %#04x", iface);
583 if ((iface & ES8326_HPINSERT_FLAG) == 0) {
584 /* Jack unplugged or spurious IRQ */
585 dev_dbg(comp->dev, "No headset detected");
586 if (es8326->jack->status & SND_JACK_HEADPHONE) {
587 snd_soc_jack_report(es8326->jack, 0, SND_JACK_HEADSET);
588 snd_soc_component_write(comp, ES8326_ADC1_SRC, es8326->mic2_src);
589 es8326_disable_micbias(comp);

--- 56 unchanged lines hidden (view full) ---

646 regmap_write(es8326->regmap, ES8326_CLK_VMIDS1, 0xC8);
647 regmap_write(es8326->regmap, ES8326_CLK_VMIDS2, 0x88);
648 regmap_write(es8326->regmap, ES8326_CLK_CAL_TIME, 0x20);
649 regmap_write(es8326->regmap, ES8326_SYS_BIAS, 0x08);
650 regmap_write(es8326->regmap, ES8326_DAC2HPMIX, 0x22);
651 regmap_write(es8326->regmap, ES8326_ADC1_SRC, es8326->mic1_src);
652 regmap_write(es8326->regmap, ES8326_ADC2_SRC, es8326->mic2_src);
653 regmap_write(es8326->regmap, ES8326_HPJACK_TIMER, 0x88);
667 regmap_write(es8326->regmap, ES8326_HP_DET,
654 regmap_write(es8326->regmap, ES8326_HPDET_TYPE,
668 ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol);
669 regmap_write(es8326->regmap, ES8326_INT_SOURCE, es8326->interrupt_src);
670 regmap_write(es8326->regmap, ES8326_INTOUT_IO, es8326->interrupt_clk);
671 regmap_write(es8326->regmap, ES8326_RESET, ES8326_CSM_ON);
672 snd_soc_component_update_bits(component, ES8326_PGAGAIN,
673 ES8326_MIC_SEL_MASK, ES8326_MIC1_SEL);
674
675 regmap_read(es8326->regmap, ES8326_CHIP_VERSION, &reg);

--- 10 unchanged lines hidden (view full) ---

686}
687
688static int es8326_suspend(struct snd_soc_component *component)
689{
690 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component);
691
692 cancel_delayed_work_sync(&es8326->jack_detect_work);
693 es8326_disable_micbias(component);
655 ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol);
656 regmap_write(es8326->regmap, ES8326_INT_SOURCE, es8326->interrupt_src);
657 regmap_write(es8326->regmap, ES8326_INTOUT_IO, es8326->interrupt_clk);
658 regmap_write(es8326->regmap, ES8326_RESET, ES8326_CSM_ON);
659 snd_soc_component_update_bits(component, ES8326_PGAGAIN,
660 ES8326_MIC_SEL_MASK, ES8326_MIC1_SEL);
661
662 regmap_read(es8326->regmap, ES8326_CHIP_VERSION, &reg);

--- 10 unchanged lines hidden (view full) ---

673}
674
675static int es8326_suspend(struct snd_soc_component *component)
676{
677 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component);
678
679 cancel_delayed_work_sync(&es8326->jack_detect_work);
680 es8326_disable_micbias(component);
694
681 es8326->calibrated = false;
695 regmap_write(es8326->regmap, ES8326_CLK_CTL, ES8326_CLK_OFF);
696 regcache_cache_only(es8326->regmap, true);
697 regcache_mark_dirty(es8326->regmap);
698
699 return 0;
700}
701
702static int es8326_probe(struct snd_soc_component *component)

--- 48 unchanged lines hidden (view full) ---

751
752static void es8326_enable_jack_detect(struct snd_soc_component *component,
753 struct snd_soc_jack *jack)
754{
755 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component);
756
757 mutex_lock(&es8326->lock);
758 if (es8326->jd_inverted)
682 regmap_write(es8326->regmap, ES8326_CLK_CTL, ES8326_CLK_OFF);
683 regcache_cache_only(es8326->regmap, true);
684 regcache_mark_dirty(es8326->regmap);
685
686 return 0;
687}
688
689static int es8326_probe(struct snd_soc_component *component)

--- 48 unchanged lines hidden (view full) ---

738
739static void es8326_enable_jack_detect(struct snd_soc_component *component,
740 struct snd_soc_jack *jack)
741{
742 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component);
743
744 mutex_lock(&es8326->lock);
745 if (es8326->jd_inverted)
759 snd_soc_component_update_bits(component, ES8326_HP_DET,
746 snd_soc_component_update_bits(component, ES8326_HPDET_TYPE,
760 ES8326_HP_DET_JACK_POL, ~es8326->jack_pol);
761 es8326->jack = jack;
762
763 mutex_unlock(&es8326->lock);
764 es8326_irq(es8326->irq, es8326);
765}
766
767static void es8326_disable_jack_detect(struct snd_soc_component *component)

--- 139 unchanged lines hidden ---
747 ES8326_HP_DET_JACK_POL, ~es8326->jack_pol);
748 es8326->jack = jack;
749
750 mutex_unlock(&es8326->lock);
751 es8326_irq(es8326->irq, es8326);
752}
753
754static void es8326_disable_jack_detect(struct snd_soc_component *component)

--- 139 unchanged lines hidden ---