Skip to content

Commit

Permalink
ASoC: bcm: Use the correct sample width value
Browse files Browse the repository at this point in the history
ALSA's concept of the physical width of a sample is how much memory it
occupies, including any padding. This not the same as the count of bits
of actual sample content. In particular, S24_LE has a width of 24 bits
but a physical width of 32 bits because there is a byte of padding with
each sample.

When calculating bclk_ratio, etc., it is width that matters, not
physical width. Correct the error that has been replicated across the
drivers for many Raspberry Pi-compatible soundcards.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
  • Loading branch information
pelwell committed Mar 1, 2024
1 parent 328415f commit 1470ec2
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion sound/soc/bcm/allo-boss-dac.c
Expand Up @@ -274,7 +274,7 @@ static int snd_allo_boss_hw_params(
int ret = 0;
struct snd_soc_pcm_runtime *rtd = substream->private_data;
int channels = params_channels(params);
int width = snd_pcm_format_physical_width(params_format(params));
int width = snd_pcm_format_width(params_format(params));

if (snd_soc_allo_boss_master) {
struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/bcm/dionaudio_loco.c
Expand Up @@ -32,7 +32,7 @@ static int snd_rpi_dionaudio_loco_hw_params(
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);

unsigned int sample_bits =
snd_pcm_format_physical_width(params_format(params));
snd_pcm_format_width(params_format(params));

return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
}
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/bcm/hifiberry_dacplus.c
Expand Up @@ -295,7 +295,7 @@ static int snd_rpi_hifiberry_dacplus_hw_params(
int ret = 0;
struct snd_soc_pcm_runtime *rtd = substream->private_data;
int channels = params_channels(params);
int width = snd_pcm_format_physical_width(params_format(params));
int width = snd_pcm_format_width(params_format(params));

if (snd_rpi_hifiberry_is_dacpro) {
struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/bcm/hifiberry_dacplusadc.c
Expand Up @@ -234,7 +234,7 @@ static int snd_rpi_hifiberry_dacplusadc_hw_params(
if (snd_rpi_hifiberry_is_dacpro) {
struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;

width = snd_pcm_format_physical_width(params_format(params));
width = snd_pcm_format_width(params_format(params));

snd_rpi_hifiberry_dacplusadc_set_sclk(component,
params_rate(params));
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/bcm/hifiberry_dacplusadcpro.c
Expand Up @@ -383,7 +383,7 @@ static int snd_rpi_hifiberry_dacplusadcpro_hw_params(
int ret = 0;
struct snd_soc_pcm_runtime *rtd = substream->private_data;
int channels = params_channels(params);
int width = snd_pcm_format_physical_width(params_format(params));
int width = snd_pcm_format_width(params_format(params));
struct snd_soc_component *dac = asoc_rtd_to_codec(rtd, 0)->component;
struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
struct snd_soc_dai_driver *drv = dai->driver;
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/bcm/i-sabre-q2m.c
Expand Up @@ -53,7 +53,7 @@ static int snd_rpi_i_sabre_q2m_hw_params(
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
int bclk_ratio;

bclk_ratio = snd_pcm_format_physical_width(
bclk_ratio = snd_pcm_format_width(
params_format(params)) * params_channels(params);
return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
}
Expand Down
2 changes: 0 additions & 2 deletions sound/soc/bcm/pifi-40.c
Expand Up @@ -140,9 +140,7 @@ static int snd_pifi_40_hw_params(struct snd_pcm_substream *substream,
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
unsigned int sample_bits;

sample_bits = snd_pcm_format_physical_width(params_format(params));
return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
}

Expand Down
2 changes: 1 addition & 1 deletion sound/soc/bcm/pisound.c
Expand Up @@ -895,7 +895,7 @@ static int pisnd_hw_params(
printd("rate = %d\n", params_rate(params));
printd("ch = %d\n", params_channels(params));
printd("bits = %u\n",
snd_pcm_format_physical_width(params_format(params)));
snd_pcm_format_width(params_format(params)));
printd("format = %d\n", params_format(params));

gpiod_set_value(reset, false);
Expand Down
3 changes: 1 addition & 2 deletions sound/soc/bcm/rpi-cirrus.c
Expand Up @@ -704,8 +704,7 @@ static int rpi_cirrus_hw_params(struct snd_pcm_substream *substream,

int ret;

unsigned int width = snd_pcm_format_physical_width(
params_format(params));
unsigned int width = snd_pcm_format_width(params_format(params));
unsigned int rate = params_rate(params);
unsigned int clk_freq = calc_sysclk(rate);

Expand Down
2 changes: 1 addition & 1 deletion sound/soc/bcm/rpi-simple-soundcard.c
Expand Up @@ -137,7 +137,7 @@ static int snd_rpi_simple_hw_params(struct snd_pcm_substream *substream,
* hard-code this for now. More complex drivers could just replace
* the hw_params routine.
*/
sample_bits = snd_pcm_format_physical_width(params_format(params));
sample_bits = snd_pcm_format_width(params_format(params));
return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
}

Expand Down

0 comments on commit 1470ec2

Please sign in to comment.