c90222637282ab41823055a2f8af68e840130f4f
[openwrt/staging/wigyori.git] / target / linux / brcm2708 / patches-4.4 / 0132-bcm2835-only-allow-stereo-if-analogue-jack-is-select.patch
1 From f54692dc8ff6e0aecf27fdd2ebaed8e22d04f053 Mon Sep 17 00:00:00 2001
2 From: wm4 <wm4@nowhere>
3 Date: Wed, 13 Jan 2016 19:44:24 +0100
4 Subject: [PATCH] bcm2835: only allow stereo if analogue jack is selected
5
6 Sending more than 2 channels to videocore while outputting to analogue
7 mysteriously outputs heavy artifacts. So just paint it over with a
8 hack: if analogue is explicitly selected as destination, do not
9 reporting support for anything other than stereo.
10
11 I'm not sure how to deal with the auto case (destination 0). There's
12 probably way to retrieve this and even to listen to plug events, but
13 I didn't find one yet, and it's probably not worth the trouble. Just
14 don't use this setting, I guess. Unless you like noise.
15
16 Changing the setting while an audio stream is active also doesn't
17 work properly. We could probably interrupt running streams by
18 returning ENODEV or using kernel hotplug stuff (maybe), but that
19 also doesn't seem worth the trouble.
20 ---
21 sound/arm/bcm2835-ctl.c | 12 ++++++++++++
22 1 file changed, 12 insertions(+)
23
24 --- a/sound/arm/bcm2835-ctl.c
25 +++ b/sound/arm/bcm2835-ctl.c
26 @@ -423,9 +423,16 @@ static struct cea_channel_speaker_alloca
27 { .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
28 };
29
30 +static int uses_analogue(bcm2835_chip_t *chip)
31 +{
32 + return chip->dest == 1;
33 +}
34 +
35 static int snd_bcm2835_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
36 unsigned int size, unsigned int __user *tlv)
37 {
38 + struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
39 + bcm2835_chip_t *chip = info->private_data;
40 unsigned int __user *dst;
41 int count = 0;
42 int i;
43 @@ -442,6 +449,9 @@ static int snd_bcm2835_chmap_ctl_tlv(str
44 int chs_bytes;
45 int c;
46
47 + if (i > 0 && uses_analogue(chip))
48 + break;
49 +
50 for (c = 0; c < 8; c++) {
51 if (ch->speakers[c])
52 num_chs++;
53 @@ -552,6 +562,8 @@ static int snd_bcm2835_chmap_ctl_put(str
54 int matches = 1;
55 int cur = 0;
56 int x;
57 + if (i > 0 && uses_analogue(chip))
58 + break;
59 memset(remap, 0, sizeof(remap));
60 for (x = 0; x < substream->runtime->channels; x++) {
61 int sp = ucontrol->value.integer.value[x];