Skip to content

Commit 314213c

Browse files
Sylwester Nawrockibroonie
authored andcommitted
ASoC: wm8994: Prevent access to invalid VU register bits on WM1811
The ADC2 and DAC2 are not available on WM1811 device. This patch moves the ADC2, DAC2 VU bitfields to a separate array so we can skip accessing them and avoid unreadable register access on WM1811. This allows to get rid of warnings during boot like: wm8994-codec: ASoC: error at soc_component_read_no_lock on wm8994-codec: -5 Signed-off-by: Sylwester Nawrocki <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 796a58f commit 314213c

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

sound/soc/codecs/wm8994.c

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
#define WM8994_NUM_DRC 3
4444
#define WM8994_NUM_EQ 3
4545

46-
static struct {
46+
struct wm8994_reg_mask {
4747
unsigned int reg;
4848
unsigned int mask;
49-
} wm8994_vu_bits[] = {
49+
};
50+
51+
static struct wm8994_reg_mask wm8994_vu_bits[] = {
5052
{ WM8994_LEFT_LINE_INPUT_1_2_VOLUME, WM8994_IN1_VU },
5153
{ WM8994_RIGHT_LINE_INPUT_1_2_VOLUME, WM8994_IN1_VU },
5254
{ WM8994_LEFT_LINE_INPUT_3_4_VOLUME, WM8994_IN2_VU },
@@ -60,14 +62,10 @@ static struct {
6062

6163
{ WM8994_AIF1_DAC1_LEFT_VOLUME, WM8994_AIF1DAC1_VU },
6264
{ WM8994_AIF1_DAC1_RIGHT_VOLUME, WM8994_AIF1DAC1_VU },
63-
{ WM8994_AIF1_DAC2_LEFT_VOLUME, WM8994_AIF1DAC2_VU },
64-
{ WM8994_AIF1_DAC2_RIGHT_VOLUME, WM8994_AIF1DAC2_VU },
6565
{ WM8994_AIF2_DAC_LEFT_VOLUME, WM8994_AIF2DAC_VU },
6666
{ WM8994_AIF2_DAC_RIGHT_VOLUME, WM8994_AIF2DAC_VU },
6767
{ WM8994_AIF1_ADC1_LEFT_VOLUME, WM8994_AIF1ADC1_VU },
6868
{ WM8994_AIF1_ADC1_RIGHT_VOLUME, WM8994_AIF1ADC1_VU },
69-
{ WM8994_AIF1_ADC2_LEFT_VOLUME, WM8994_AIF1ADC2_VU },
70-
{ WM8994_AIF1_ADC2_RIGHT_VOLUME, WM8994_AIF1ADC2_VU },
7169
{ WM8994_AIF2_ADC_LEFT_VOLUME, WM8994_AIF2ADC_VU },
7270
{ WM8994_AIF2_ADC_RIGHT_VOLUME, WM8994_AIF1ADC2_VU },
7371
{ WM8994_DAC1_LEFT_VOLUME, WM8994_DAC1_VU },
@@ -76,6 +74,14 @@ static struct {
7674
{ WM8994_DAC2_RIGHT_VOLUME, WM8994_DAC2_VU },
7775
};
7876

77+
/* VU bitfields for ADC2, DAC2 not available on WM1811 */
78+
static struct wm8994_reg_mask wm8994_adc2_dac2_vu_bits[] = {
79+
{ WM8994_AIF1_DAC2_LEFT_VOLUME, WM8994_AIF1DAC2_VU },
80+
{ WM8994_AIF1_DAC2_RIGHT_VOLUME, WM8994_AIF1DAC2_VU },
81+
{ WM8994_AIF1_ADC2_LEFT_VOLUME, WM8994_AIF1ADC2_VU },
82+
{ WM8994_AIF1_ADC2_RIGHT_VOLUME, WM8994_AIF1ADC2_VU },
83+
};
84+
7985
static int wm8994_drc_base[] = {
8086
WM8994_AIF1_DRC1_1,
8187
WM8994_AIF1_DRC2_1,
@@ -1030,6 +1036,26 @@ static bool wm8994_check_class_w_digital(struct snd_soc_component *component)
10301036
return true;
10311037
}
10321038

1039+
static void wm8994_update_vu_bits(struct snd_soc_component *component)
1040+
{
1041+
struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
1042+
struct wm8994 *control = wm8994->wm8994;
1043+
int i;
1044+
1045+
for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1046+
snd_soc_component_write(component, wm8994_vu_bits[i].reg,
1047+
snd_soc_component_read(component,
1048+
wm8994_vu_bits[i].reg));
1049+
if (control->type == WM1811)
1050+
return;
1051+
1052+
for (i = 0; i < ARRAY_SIZE(wm8994_adc2_dac2_vu_bits); i++)
1053+
snd_soc_component_write(component,
1054+
wm8994_adc2_dac2_vu_bits[i].reg,
1055+
snd_soc_component_read(component,
1056+
wm8994_adc2_dac2_vu_bits[i].reg));
1057+
}
1058+
10331059
static int aif_mclk_set(struct snd_soc_component *component, int aif, bool enable)
10341060
{
10351061
struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
@@ -1076,7 +1102,7 @@ static int aif1clk_ev(struct snd_soc_dapm_widget *w,
10761102
struct wm8994_priv *wm8994 = snd_soc_component_get_drvdata(component);
10771103
struct wm8994 *control = wm8994->wm8994;
10781104
int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA;
1079-
int ret, i;
1105+
int ret;
10801106
int dac;
10811107
int adc;
10821108
int val;
@@ -1144,10 +1170,7 @@ static int aif1clk_ev(struct snd_soc_dapm_widget *w,
11441170
break;
11451171

11461172
case SND_SOC_DAPM_POST_PMU:
1147-
for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1148-
snd_soc_component_write(component, wm8994_vu_bits[i].reg,
1149-
snd_soc_component_read(component,
1150-
wm8994_vu_bits[i].reg));
1173+
wm8994_update_vu_bits(component);
11511174
break;
11521175

11531176
case SND_SOC_DAPM_PRE_PMD:
@@ -1181,7 +1204,7 @@ static int aif2clk_ev(struct snd_soc_dapm_widget *w,
11811204
struct snd_kcontrol *kcontrol, int event)
11821205
{
11831206
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1184-
int ret, i;
1207+
int ret;
11851208
int dac;
11861209
int adc;
11871210
int val;
@@ -1237,10 +1260,7 @@ static int aif2clk_ev(struct snd_soc_dapm_widget *w,
12371260
break;
12381261

12391262
case SND_SOC_DAPM_POST_PMU:
1240-
for (i = 0; i < ARRAY_SIZE(wm8994_vu_bits); i++)
1241-
snd_soc_component_write(component, wm8994_vu_bits[i].reg,
1242-
snd_soc_component_read(component,
1243-
wm8994_vu_bits[i].reg));
1263+
wm8994_update_vu_bits(component);
12441264
break;
12451265

12461266
case SND_SOC_DAPM_PRE_PMD:
@@ -4346,6 +4366,14 @@ static int wm8994_component_probe(struct snd_soc_component *component)
43464366
wm8994_vu_bits[i].mask,
43474367
wm8994_vu_bits[i].mask);
43484368

4369+
if (control->type != WM1811) {
4370+
for (i = 0; i < ARRAY_SIZE(wm8994_adc2_dac2_vu_bits); i++)
4371+
snd_soc_component_update_bits(component,
4372+
wm8994_adc2_dac2_vu_bits[i].reg,
4373+
wm8994_adc2_dac2_vu_bits[i].mask,
4374+
wm8994_adc2_dac2_vu_bits[i].mask);
4375+
}
4376+
43494377
/* Set the low bit of the 3D stereo depth so TLV matches */
43504378
snd_soc_component_update_bits(component, WM8994_AIF1_DAC1_FILTERS_2,
43514379
1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,

0 commit comments

Comments
 (0)