forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/codecs/wm8961.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * wm8961.c -- WM8961 ALSA SoC Audio driver
34 *
45 * Copyright 2009-10 Wolfson Microelectronics, plc
56 *
67 * Author: Mark Brown
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 *
129 * Currently unimplemented features:
1310 * - ALC
....@@ -195,10 +192,10 @@
195192 struct snd_kcontrol *kcontrol, int event)
196193 {
197194 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
198
- u16 hp_reg = snd_soc_component_read32(component, WM8961_ANALOGUE_HP_0);
199
- u16 cp_reg = snd_soc_component_read32(component, WM8961_CHARGE_PUMP_1);
200
- u16 pwr_reg = snd_soc_component_read32(component, WM8961_PWR_MGMT_2);
201
- u16 dcs_reg = snd_soc_component_read32(component, WM8961_DC_SERVO_1);
195
+ u16 hp_reg = snd_soc_component_read(component, WM8961_ANALOGUE_HP_0);
196
+ u16 cp_reg = snd_soc_component_read(component, WM8961_CHARGE_PUMP_1);
197
+ u16 pwr_reg = snd_soc_component_read(component, WM8961_PWR_MGMT_2);
198
+ u16 dcs_reg = snd_soc_component_read(component, WM8961_DC_SERVO_1);
202199 int timeout = 500;
203200
204201 if (event & SND_SOC_DAPM_POST_PMU) {
....@@ -232,7 +229,7 @@
232229 snd_soc_component_write(component, WM8961_DC_SERVO_1, dcs_reg);
233230 do {
234231 msleep(1);
235
- dcs_reg = snd_soc_component_read32(component, WM8961_DC_SERVO_1);
232
+ dcs_reg = snd_soc_component_read(component, WM8961_DC_SERVO_1);
236233 } while (--timeout &&
237234 dcs_reg & (WM8961_DCS_TRIG_STARTUP_HPR |
238235 WM8961_DCS_TRIG_STARTUP_HPL));
....@@ -287,8 +284,8 @@
287284 struct snd_kcontrol *kcontrol, int event)
288285 {
289286 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
290
- u16 pwr_reg = snd_soc_component_read32(component, WM8961_PWR_MGMT_2);
291
- u16 spk_reg = snd_soc_component_read32(component, WM8961_CLASS_D_CONTROL_1);
287
+ u16 pwr_reg = snd_soc_component_read(component, WM8961_PWR_MGMT_2);
288
+ u16 spk_reg = snd_soc_component_read(component, WM8961_CLASS_D_CONTROL_1);
292289
293290 if (event & SND_SOC_DAPM_POST_PMU) {
294291 /* Enable the PGA */
....@@ -524,7 +521,7 @@
524521 abs(wm8961_srate[best].rate - fs))
525522 best = i;
526523 }
527
- reg = snd_soc_component_read32(component, WM8961_ADDITIONAL_CONTROL_3);
524
+ reg = snd_soc_component_read(component, WM8961_ADDITIONAL_CONTROL_3);
528525 reg &= ~WM8961_SAMPLE_RATE_MASK;
529526 reg |= wm8961_srate[best].val;
530527 snd_soc_component_write(component, WM8961_ADDITIONAL_CONTROL_3, reg);
....@@ -557,12 +554,12 @@
557554 wm8961_clk_sys_ratio[i].ratio, wm8961->sysclk, fs,
558555 wm8961->sysclk / fs);
559556
560
- reg = snd_soc_component_read32(component, WM8961_CLOCKING_4);
557
+ reg = snd_soc_component_read(component, WM8961_CLOCKING_4);
561558 reg &= ~WM8961_CLK_SYS_RATE_MASK;
562559 reg |= wm8961_clk_sys_ratio[i].val << WM8961_CLK_SYS_RATE_SHIFT;
563560 snd_soc_component_write(component, WM8961_CLOCKING_4, reg);
564561
565
- reg = snd_soc_component_read32(component, WM8961_AUDIO_INTERFACE_0);
562
+ reg = snd_soc_component_read(component, WM8961_AUDIO_INTERFACE_0);
566563 reg &= ~WM8961_WL_MASK;
567564 switch (params_width(params)) {
568565 case 16:
....@@ -582,7 +579,7 @@
582579 snd_soc_component_write(component, WM8961_AUDIO_INTERFACE_0, reg);
583580
584581 /* Sloping stop-band filter is recommended for <= 24kHz */
585
- reg = snd_soc_component_read32(component, WM8961_ADC_DAC_CONTROL_2);
582
+ reg = snd_soc_component_read(component, WM8961_ADC_DAC_CONTROL_2);
586583 if (fs <= 24000)
587584 reg |= WM8961_DACSLOPE;
588585 else
....@@ -598,7 +595,7 @@
598595 {
599596 struct snd_soc_component *component = dai->component;
600597 struct wm8961_priv *wm8961 = snd_soc_component_get_drvdata(component);
601
- u16 reg = snd_soc_component_read32(component, WM8961_CLOCKING1);
598
+ u16 reg = snd_soc_component_read(component, WM8961_CLOCKING1);
602599
603600 if (freq > 33000000) {
604601 dev_err(component->dev, "MCLK must be <33MHz\n");
....@@ -624,7 +621,7 @@
624621 static int wm8961_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
625622 {
626623 struct snd_soc_component *component = dai->component;
627
- u16 aif = snd_soc_component_read32(component, WM8961_AUDIO_INTERFACE_0);
624
+ u16 aif = snd_soc_component_read(component, WM8961_AUDIO_INTERFACE_0);
628625
629626 aif &= ~(WM8961_BCLKINV | WM8961_LRP |
630627 WM8961_MS | WM8961_FORMAT_MASK);
....@@ -653,7 +650,7 @@
653650
654651 case SND_SOC_DAIFMT_DSP_B:
655652 aif |= WM8961_LRP;
656
- /* fall through */
653
+ fallthrough;
657654 case SND_SOC_DAIFMT_DSP_A:
658655 aif |= 3;
659656 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
....@@ -691,7 +688,7 @@
691688 static int wm8961_set_tristate(struct snd_soc_dai *dai, int tristate)
692689 {
693690 struct snd_soc_component *component = dai->component;
694
- u16 reg = snd_soc_component_read32(component, WM8961_ADDITIONAL_CONTROL_2);
691
+ u16 reg = snd_soc_component_read(component, WM8961_ADDITIONAL_CONTROL_2);
695692
696693 if (tristate)
697694 reg |= WM8961_TRIS;
....@@ -701,10 +698,10 @@
701698 return snd_soc_component_write(component, WM8961_ADDITIONAL_CONTROL_2, reg);
702699 }
703700
704
-static int wm8961_digital_mute(struct snd_soc_dai *dai, int mute)
701
+static int wm8961_mute(struct snd_soc_dai *dai, int mute, int direction)
705702 {
706703 struct snd_soc_component *component = dai->component;
707
- u16 reg = snd_soc_component_read32(component, WM8961_ADC_DAC_CONTROL_1);
704
+ u16 reg = snd_soc_component_read(component, WM8961_ADC_DAC_CONTROL_1);
708705
709706 if (mute)
710707 reg |= WM8961_DACMU;
....@@ -723,14 +720,14 @@
723720
724721 switch (div_id) {
725722 case WM8961_BCLK:
726
- reg = snd_soc_component_read32(component, WM8961_CLOCKING2);
723
+ reg = snd_soc_component_read(component, WM8961_CLOCKING2);
727724 reg &= ~WM8961_BCLKDIV_MASK;
728725 reg |= div;
729726 snd_soc_component_write(component, WM8961_CLOCKING2, reg);
730727 break;
731728
732729 case WM8961_LRCLK:
733
- reg = snd_soc_component_read32(component, WM8961_AUDIO_INTERFACE_2);
730
+ reg = snd_soc_component_read(component, WM8961_AUDIO_INTERFACE_2);
734731 reg &= ~WM8961_LRCLK_RATE_MASK;
735732 reg |= div;
736733 snd_soc_component_write(component, WM8961_AUDIO_INTERFACE_2, reg);
....@@ -760,12 +757,12 @@
760757 case SND_SOC_BIAS_PREPARE:
761758 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY) {
762759 /* Enable bias generation */
763
- reg = snd_soc_component_read32(component, WM8961_ANTI_POP);
760
+ reg = snd_soc_component_read(component, WM8961_ANTI_POP);
764761 reg |= WM8961_BUFIOEN | WM8961_BUFDCOPEN;
765762 snd_soc_component_write(component, WM8961_ANTI_POP, reg);
766763
767764 /* VMID=2*50k, VREF */
768
- reg = snd_soc_component_read32(component, WM8961_PWR_MGMT_1);
765
+ reg = snd_soc_component_read(component, WM8961_PWR_MGMT_1);
769766 reg &= ~WM8961_VMIDSEL_MASK;
770767 reg |= (1 << WM8961_VMIDSEL_SHIFT) | WM8961_VREF;
771768 snd_soc_component_write(component, WM8961_PWR_MGMT_1, reg);
....@@ -775,17 +772,17 @@
775772 case SND_SOC_BIAS_STANDBY:
776773 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_PREPARE) {
777774 /* VREF off */
778
- reg = snd_soc_component_read32(component, WM8961_PWR_MGMT_1);
775
+ reg = snd_soc_component_read(component, WM8961_PWR_MGMT_1);
779776 reg &= ~WM8961_VREF;
780777 snd_soc_component_write(component, WM8961_PWR_MGMT_1, reg);
781778
782779 /* Bias generation off */
783
- reg = snd_soc_component_read32(component, WM8961_ANTI_POP);
780
+ reg = snd_soc_component_read(component, WM8961_ANTI_POP);
784781 reg &= ~(WM8961_BUFIOEN | WM8961_BUFDCOPEN);
785782 snd_soc_component_write(component, WM8961_ANTI_POP, reg);
786783
787784 /* VMID off */
788
- reg = snd_soc_component_read32(component, WM8961_PWR_MGMT_1);
785
+ reg = snd_soc_component_read(component, WM8961_PWR_MGMT_1);
789786 reg &= ~WM8961_VMIDSEL_MASK;
790787 snd_soc_component_write(component, WM8961_PWR_MGMT_1, reg);
791788 }
....@@ -809,9 +806,10 @@
809806 .hw_params = wm8961_hw_params,
810807 .set_sysclk = wm8961_set_sysclk,
811808 .set_fmt = wm8961_set_fmt,
812
- .digital_mute = wm8961_digital_mute,
809
+ .mute_stream = wm8961_mute,
813810 .set_tristate = wm8961_set_tristate,
814811 .set_clkdiv = wm8961_set_clkdiv,
812
+ .no_capture_mute = 1,
815813 };
816814
817815 static struct snd_soc_dai_driver wm8961_dai = {
....@@ -836,35 +834,35 @@
836834 u16 reg;
837835
838836 /* Enable class W */
839
- reg = snd_soc_component_read32(component, WM8961_CHARGE_PUMP_B);
837
+ reg = snd_soc_component_read(component, WM8961_CHARGE_PUMP_B);
840838 reg |= WM8961_CP_DYN_PWR_MASK;
841839 snd_soc_component_write(component, WM8961_CHARGE_PUMP_B, reg);
842840
843841 /* Latch volume update bits (right channel only, we always
844842 * write both out) and default ZC on. */
845
- reg = snd_soc_component_read32(component, WM8961_ROUT1_VOLUME);
843
+ reg = snd_soc_component_read(component, WM8961_ROUT1_VOLUME);
846844 snd_soc_component_write(component, WM8961_ROUT1_VOLUME,
847845 reg | WM8961_LO1ZC | WM8961_OUT1VU);
848846 snd_soc_component_write(component, WM8961_LOUT1_VOLUME, reg | WM8961_LO1ZC);
849
- reg = snd_soc_component_read32(component, WM8961_ROUT2_VOLUME);
847
+ reg = snd_soc_component_read(component, WM8961_ROUT2_VOLUME);
850848 snd_soc_component_write(component, WM8961_ROUT2_VOLUME,
851849 reg | WM8961_SPKRZC | WM8961_SPKVU);
852850 snd_soc_component_write(component, WM8961_LOUT2_VOLUME, reg | WM8961_SPKLZC);
853851
854
- reg = snd_soc_component_read32(component, WM8961_RIGHT_ADC_VOLUME);
852
+ reg = snd_soc_component_read(component, WM8961_RIGHT_ADC_VOLUME);
855853 snd_soc_component_write(component, WM8961_RIGHT_ADC_VOLUME, reg | WM8961_ADCVU);
856
- reg = snd_soc_component_read32(component, WM8961_RIGHT_INPUT_VOLUME);
854
+ reg = snd_soc_component_read(component, WM8961_RIGHT_INPUT_VOLUME);
857855 snd_soc_component_write(component, WM8961_RIGHT_INPUT_VOLUME, reg | WM8961_IPVU);
858856
859857 /* Use soft mute by default */
860
- reg = snd_soc_component_read32(component, WM8961_ADC_DAC_CONTROL_2);
858
+ reg = snd_soc_component_read(component, WM8961_ADC_DAC_CONTROL_2);
861859 reg |= WM8961_DACSMM;
862860 snd_soc_component_write(component, WM8961_ADC_DAC_CONTROL_2, reg);
863861
864862 /* Use automatic clocking mode by default; for now this is all
865863 * we support.
866864 */
867
- reg = snd_soc_component_read32(component, WM8961_CLOCKING_3);
865
+ reg = snd_soc_component_read(component, WM8961_CLOCKING_3);
868866 reg &= ~WM8961_MANUAL_MODE;
869867 snd_soc_component_write(component, WM8961_CLOCKING_3, reg);
870868