From f0a501b81926f3cd91415681feb22a3b8f6f0d83 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Fri, 1 Mar 2024 09:46:23 +0000 Subject: [PATCH 0932/1002] ASoC: bcm: Use the correct sample width value 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 --- sound/soc/bcm/allo-boss-dac.c | 2 +- sound/soc/bcm/dionaudio_loco.c | 2 +- sound/soc/bcm/hifiberry_dacplus.c | 2 +- sound/soc/bcm/hifiberry_dacplusadc.c | 2 +- sound/soc/bcm/hifiberry_dacplusadcpro.c | 2 +- sound/soc/bcm/i-sabre-q2m.c | 2 +- sound/soc/bcm/pifi-40.c | 2 -- sound/soc/bcm/pisound.c | 2 +- sound/soc/bcm/rpi-cirrus.c | 3 +-- sound/soc/bcm/rpi-simple-soundcard.c | 2 +- 10 files changed, 9 insertions(+), 12 deletions(-) diff --git a/sound/soc/bcm/allo-boss-dac.c b/sound/soc/bcm/allo-boss-dac.c index b86ddd4113a6..a9135badffd4 100644 --- a/sound/soc/bcm/allo-boss-dac.c +++ b/sound/soc/bcm/allo-boss-dac.c @@ -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; diff --git a/sound/soc/bcm/dionaudio_loco.c b/sound/soc/bcm/dionaudio_loco.c index b19a06afb6af..48deb4cd3c8e 100644 --- a/sound/soc/bcm/dionaudio_loco.c +++ b/sound/soc/bcm/dionaudio_loco.c @@ -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); } diff --git a/sound/soc/bcm/hifiberry_dacplus.c b/sound/soc/bcm/hifiberry_dacplus.c index 98e52c7a9319..0cd7979dee54 100644 --- a/sound/soc/bcm/hifiberry_dacplus.c +++ b/sound/soc/bcm/hifiberry_dacplus.c @@ -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; diff --git a/sound/soc/bcm/hifiberry_dacplusadc.c b/sound/soc/bcm/hifiberry_dacplusadc.c index 5fe6fd220556..9db1b4cffc66 100644 --- a/sound/soc/bcm/hifiberry_dacplusadc.c +++ b/sound/soc/bcm/hifiberry_dacplusadc.c @@ -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)); diff --git a/sound/soc/bcm/hifiberry_dacplusadcpro.c b/sound/soc/bcm/hifiberry_dacplusadcpro.c index 0c03dfd3a29d..17ca9dfe5442 100644 --- a/sound/soc/bcm/hifiberry_dacplusadcpro.c +++ b/sound/soc/bcm/hifiberry_dacplusadcpro.c @@ -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; diff --git a/sound/soc/bcm/i-sabre-q2m.c b/sound/soc/bcm/i-sabre-q2m.c index bbb7c79693d4..dfd1644cb94a 100644 --- a/sound/soc/bcm/i-sabre-q2m.c +++ b/sound/soc/bcm/i-sabre-q2m.c @@ -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); } diff --git a/sound/soc/bcm/pifi-40.c b/sound/soc/bcm/pifi-40.c index 550908ca6eb7..20f384222fc5 100644 --- a/sound/soc/bcm/pifi-40.c +++ b/sound/soc/bcm/pifi-40.c @@ -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); } diff --git a/sound/soc/bcm/pisound.c b/sound/soc/bcm/pisound.c index b03ea62b4f4d..688be6e189c6 100644 --- a/sound/soc/bcm/pisound.c +++ b/sound/soc/bcm/pisound.c @@ -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); diff --git a/sound/soc/bcm/rpi-cirrus.c b/sound/soc/bcm/rpi-cirrus.c index 6f6047fef8d2..6e317b31d9ac 100644 --- a/sound/soc/bcm/rpi-cirrus.c +++ b/sound/soc/bcm/rpi-cirrus.c @@ -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); diff --git a/sound/soc/bcm/rpi-simple-soundcard.c b/sound/soc/bcm/rpi-simple-soundcard.c index 95d4a0d9ad90..1c6b55b80cae 100644 --- a/sound/soc/bcm/rpi-simple-soundcard.c +++ b/sound/soc/bcm/rpi-simple-soundcard.c @@ -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); } -- 2.44.0