1 From 8148bc7d4147c2197d13425686a56b7c40c78157 Mon Sep 17 00:00:00 2001
2 From: wm4 <wm4@nowhere>
3 Date: Wed, 13 Jan 2016 19:42:18 +0100
4 Subject: [PATCH 127/381] bcm2835: restrict channels*rate to 8*960000
6 This is required at least for SPDIF. If the bitrate goes above,
7 videocore will either resample the audio or corrupt it due to
8 underruns. Supposedly the hardware isn't designed to output
9 higher rates, but it can still resample it down to supported
12 Some code is based on ac97_pcm.c.
14 sound/arm/bcm2835-pcm.c | 41 +++++++++++++++++++++++++++++++++++++++++
15 1 file changed, 41 insertions(+)
17 --- a/sound/arm/bcm2835-pcm.c
18 +++ b/sound/arm/bcm2835-pcm.c
23 +/* The hardware can not do much more num_channels*samplerate then this value */
24 +#define MAX_COMBINED_RATE 768000
26 /* hardware definition */
27 static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
28 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
29 @@ -107,6 +110,31 @@ static irqreturn_t bcm2835_playback_fifo
34 +static int rate_hw_constraint_rate(struct snd_pcm_hw_params *params,
35 + struct snd_pcm_hw_rule *rule)
37 + struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
38 + struct snd_interval rates = {
40 + .max = min(192000u, MAX_COMBINED_RATE / max(channels->min, 1u)),
42 + struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
43 + return snd_interval_refine(rate, &rates);
46 +static int rate_hw_constraint_channels(struct snd_pcm_hw_params *params,
47 + struct snd_pcm_hw_rule *rule)
49 + struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
50 + struct snd_interval channels_interval = {
52 + .max = min(8u, MAX_COMBINED_RATE / max(rate->min, 1u)),
54 + struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
55 + return snd_interval_refine(channels, &channels_interval);
59 static int snd_bcm2835_playback_open_generic(
60 struct snd_pcm_substream *substream, int spdif)
61 @@ -188,6 +216,19 @@ static int snd_bcm2835_playback_open_gen
62 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
65 + /* When playing PCM, pretend that we support the full range of channels
66 + * and sample rates. The GPU can't output it, but is able to resample
67 + * the data to a rate the hardware can handle it. This won't work with
68 + * compressed data; the resampler would just destroy it. */
70 + err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
71 + rate_hw_constraint_rate, NULL,
72 + SNDRV_PCM_HW_PARAM_CHANNELS, -1);
73 + err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
74 + rate_hw_constraint_channels, NULL,
75 + SNDRV_PCM_HW_PARAM_RATE, -1);
78 chip->alsa_stream[idx] = alsa_stream;
80 chip->opened |= (1 << idx);