0132-bcm2835-only-allow-stereo-if-analogue-jack-is-select.patch 2.1 KB

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