Skip to content

Commit dcab368

Browse files
pelwellpopcornmix
authored andcommitted
ASoC: bcm: Use power-of-2 bclk_ratios
The soundcard drivers originally used snd_pcm_format_physical_width, but a later commit changed that to snd_pcm_format_width because the in-memory sample storage width should not be a factor in determining the bclk_ratio. However, the physical width rounds the sample bits up to the nearest power of 2, which makes it easier to find integer clock divisors. Restore the old behaviour, but with an implementation that makes it clear what is going on. See: #6104 Signed-off-by: Phil Elwell <[email protected]>
1 parent ffd8189 commit dcab368

8 files changed

+25
-3
lines changed

sound/soc/bcm/allo-boss-dac.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ static int snd_allo_boss_hw_params(
278278
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
279279
struct snd_soc_card *card = rtd->card;
280280

281+
/* Using powers of 2 allows for an integer clock divisor */
282+
width = width <= 16 ? 16 : 32;
283+
281284
/* Mute before changing sample rate */
282285
snd_allo_boss_gpio_mute(card);
283286

sound/soc/bcm/dionaudio_loco.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ static int snd_rpi_dionaudio_loco_hw_params(
3434
unsigned int sample_bits =
3535
snd_pcm_format_width(params_format(params));
3636

37+
/* Using powers of 2 allows for an integer clock divisor */
38+
sample_bits = sample_bits <= 16 ? 16 : 32;
39+
3740
return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
3841
}
3942

sound/soc/bcm/hifiberry_dacplus.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ static int snd_rpi_hifiberry_dacplus_hw_params(
297297
int channels = params_channels(params);
298298
int width = snd_pcm_format_width(params_format(params));
299299

300+
/* Using powers of 2 allows for an integer clock divisor */
301+
width = width <= 16 ? 16 : 32;
302+
300303
if (snd_rpi_hifiberry_is_dacpro) {
301304
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
302305

sound/soc/bcm/hifiberry_dacplusadc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ static int snd_rpi_hifiberry_dacplusadc_hw_params(
231231
int channels = params_channels(params);
232232
int width = snd_pcm_format_width(params_format(params));
233233

234+
/* Using powers of 2 allows for an integer clock divisor */
235+
width = width <= 16 ? 16 : 32;
236+
234237
if (snd_rpi_hifiberry_is_dacpro) {
235238
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
236239

sound/soc/bcm/hifiberry_dacplusadcpro.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ static int snd_rpi_hifiberry_dacplusadcpro_hw_params(
389389
struct snd_soc_dai_driver *drv = dai->driver;
390390
const struct snd_soc_dai_ops *ops = drv->ops;
391391

392+
/* Using powers of 2 allows for an integer clock divisor */
393+
width = width <= 16 ? 16 : 32;
394+
392395
if (snd_rpi_hifiberry_is_dacpro) {
393396
snd_rpi_hifiberry_dacplusadcpro_set_sclk(dac,
394397
params_rate(params));

sound/soc/bcm/i-sabre-q2m.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ static int snd_rpi_i_sabre_q2m_hw_params(
5353
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
5454
int bclk_ratio;
5555

56-
bclk_ratio = snd_pcm_format_width(
57-
params_format(params)) * params_channels(params);
56+
/* Using powers of 2 allows for an integer clock divisor */
57+
bclk_ratio = (snd_pcm_format_width(params_format(params)) <= 16 ? 16 : 32) *
58+
params_channels(params);
5859
return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
5960
}
6061

sound/soc/bcm/rpi-cirrus.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ static int rpi_cirrus_hw_params(struct snd_pcm_substream *substream,
708708
unsigned int rate = params_rate(params);
709709
unsigned int clk_freq = calc_sysclk(rate);
710710

711+
/* Using powers of 2 allows for an integer clock divisor */
712+
width = width <= 16 ? 16 : 32;
713+
711714
mutex_lock(&priv->lock);
712715

713716
dev_dbg(card->dev, "hw_params: setting rate to %d\n", rate);

sound/soc/bcm/rpi-simple-soundcard.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,13 @@ static int snd_rpi_simple_hw_params(struct snd_pcm_substream *substream,
134134
return 0; // BCLK is configured in .init
135135

136136
/* The simple drivers just set the bclk_ratio to sample_bits * 2 so
137-
* hard-code this for now. More complex drivers could just replace
137+
* hard-code this for now, but sticking to powers of 2 to allow for
138+
* integer clock divisors. More complex drivers could just replace
138139
* the hw_params routine.
139140
*/
140141
sample_bits = snd_pcm_format_width(params_format(params));
142+
sample_bits = sample_bits <= 16 ? 16 : 32;
143+
141144
return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
142145
}
143146

0 commit comments

Comments
 (0)