Skip to content

Commit 6dfe70b

Browse files
Sheetalbroonie
authored andcommitted
ASoC: tegra: Fix ADX byte map
Byte mask for channel-1 of stream-1 is not getting enabled and this causes failures during ADX use cases. This happens because the byte map value 0 matches the byte map array and put() callback returns without enabling the corresponding bits in the byte mask. ADX supports 4 output streams and each stream can have a maximum of 16 channels. Each byte in the input frame is uniquely mapped to a byte in one of these 4 outputs. This mapping is done with the help of byte map array via user space control setting. The byte map array size in the driver is 16 and each array element is of size 4 bytes. This corresponds to 64 byte map values. Each byte in the byte map array can have any value between 0 to 255 to enable the corresponding bits in the byte mask. The value 256 is used as a way to disable the byte map. However the byte map array element cannot store this value. The put() callback disables the byte mask for 256 value and byte map value is reset to 0 for this case. This causes problems during subsequent runs since put() callback, for value of 0, just returns without enabling the byte mask. In short, the problem is coming because 0 and 256 control values are stored as 0 in the byte map array. Right now fix the put() callback by actually looking at the byte mask array state to identify if any change is needed and update the fields accordingly. The get() callback needs an update as well to return the correct control value that user has set before. Note that when user set 256, the value is stored as 0 and byte mask is disabled. So byte mask state is used to either return 256 or the value from byte map array. Given above, this looks bit complicated and all this happens because the byte map array is tightly packed and cannot actually store the 256 value. Right now the priority is to fix the existing failure and a TODO item is put to improve this logic. Fixes: 3c97881 ("ASoC: tegra: Fix kcontrol put callback in ADX") Cc: stable@vger.kernel.org Signed-off-by: Sheetal <sheetal@nvidia.com> Reviewed-by: Mohan Kumar D <mkumard@nvidia.com> Reviewed-by: Sameer Pujar <spujar@nvidia.com> Link: https://lore.kernel.org/r/1688015537-31682-3-git-send-email-spujar@nvidia.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 49bd7b0 commit 6dfe70b

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

sound/soc/tegra/tegra210_adx.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// tegra210_adx.c - Tegra210 ADX driver
44
//
5-
// Copyright (c) 2021 NVIDIA CORPORATION. All rights reserved.
5+
// Copyright (c) 2021-2023 NVIDIA CORPORATION. All rights reserved.
66

77
#include <linux/clk.h>
88
#include <linux/device.h>
@@ -175,10 +175,20 @@ static int tegra210_adx_get_byte_map(struct snd_kcontrol *kcontrol,
175175
mc = (struct soc_mixer_control *)kcontrol->private_value;
176176
enabled = adx->byte_mask[mc->reg / 32] & (1 << (mc->reg % 32));
177177

178+
/*
179+
* TODO: Simplify this logic to just return from bytes_map[]
180+
*
181+
* Presently below is required since bytes_map[] is
182+
* tightly packed and cannot store the control value of 256.
183+
* Byte mask state is used to know if 256 needs to be returned.
184+
* Note that for control value of 256, the put() call stores 0
185+
* in the bytes_map[] and disables the corresponding bit in
186+
* byte_mask[].
187+
*/
178188
if (enabled)
179189
ucontrol->value.integer.value[0] = bytes_map[mc->reg];
180190
else
181-
ucontrol->value.integer.value[0] = 0;
191+
ucontrol->value.integer.value[0] = 256;
182192

183193
return 0;
184194
}
@@ -192,19 +202,19 @@ static int tegra210_adx_put_byte_map(struct snd_kcontrol *kcontrol,
192202
int value = ucontrol->value.integer.value[0];
193203
struct soc_mixer_control *mc =
194204
(struct soc_mixer_control *)kcontrol->private_value;
205+
unsigned int mask_val = adx->byte_mask[mc->reg / 32];
195206

196-
if (value == bytes_map[mc->reg])
207+
if (value >= 0 && value <= 255)
208+
mask_val |= (1 << (mc->reg % 32));
209+
else
210+
mask_val &= ~(1 << (mc->reg % 32));
211+
212+
if (mask_val == adx->byte_mask[mc->reg / 32])
197213
return 0;
198214

199-
if (value >= 0 && value <= 255) {
200-
/* update byte map and enable slot */
201-
bytes_map[mc->reg] = value;
202-
adx->byte_mask[mc->reg / 32] |= (1 << (mc->reg % 32));
203-
} else {
204-
/* reset byte map and disable slot */
205-
bytes_map[mc->reg] = 0;
206-
adx->byte_mask[mc->reg / 32] &= ~(1 << (mc->reg % 32));
207-
}
215+
/* Update byte map and slot */
216+
bytes_map[mc->reg] = value % 256;
217+
adx->byte_mask[mc->reg / 32] = mask_val;
208218

209219
return 1;
210220
}

0 commit comments

Comments
 (0)