Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 3c97881b8c8a ("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>

authored by

Sheetal and committed by
Mark Brown
6dfe70be 49bd7b08

+22 -12
+22 -12
sound/soc/tegra/tegra210_adx.c
··· 2 2 // 3 3 // tegra210_adx.c - Tegra210 ADX driver 4 4 // 5 - // Copyright (c) 2021 NVIDIA CORPORATION. All rights reserved. 5 + // Copyright (c) 2021-2023 NVIDIA CORPORATION. All rights reserved. 6 6 7 7 #include <linux/clk.h> 8 8 #include <linux/device.h> ··· 175 175 mc = (struct soc_mixer_control *)kcontrol->private_value; 176 176 enabled = adx->byte_mask[mc->reg / 32] & (1 << (mc->reg % 32)); 177 177 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 + */ 178 188 if (enabled) 179 189 ucontrol->value.integer.value[0] = bytes_map[mc->reg]; 180 190 else 181 - ucontrol->value.integer.value[0] = 0; 191 + ucontrol->value.integer.value[0] = 256; 182 192 183 193 return 0; 184 194 } ··· 202 192 int value = ucontrol->value.integer.value[0]; 203 193 struct soc_mixer_control *mc = 204 194 (struct soc_mixer_control *)kcontrol->private_value; 195 + unsigned int mask_val = adx->byte_mask[mc->reg / 32]; 205 196 206 - if (value == bytes_map[mc->reg]) 197 + if (value >= 0 && value <= 255) 198 + mask_val |= (1 << (mc->reg % 32)); 199 + else 200 + mask_val &= ~(1 << (mc->reg % 32)); 201 + 202 + if (mask_val == adx->byte_mask[mc->reg / 32]) 207 203 return 0; 208 204 209 - if (value >= 0 && value <= 255) { 210 - /* update byte map and enable slot */ 211 - bytes_map[mc->reg] = value; 212 - adx->byte_mask[mc->reg / 32] |= (1 << (mc->reg % 32)); 213 - } else { 214 - /* reset byte map and disable slot */ 215 - bytes_map[mc->reg] = 0; 216 - adx->byte_mask[mc->reg / 32] &= ~(1 << (mc->reg % 32)); 217 - } 205 + /* Update byte map and slot */ 206 + bytes_map[mc->reg] = value % 256; 207 + adx->byte_mask[mc->reg / 32] = mask_val; 218 208 219 209 return 1; 220 210 }