0084-Add-a-parameter-to-turn-off-SPDIF-output-if-no-audio.patch 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From a09a8ebce7251e2a42668bd5ae57c12ed24fdca8 Mon Sep 17 00:00:00 2001
  2. From: Daniel Matuschek <daniel@hifiberry.com>
  3. Date: Sat, 31 Jan 2015 16:07:56 +0100
  4. Subject: [PATCH 084/114] Add a parameter to turn off SPDIF output if no audio
  5. is playing
  6. This patch adds the paramater auto_shutdown_output to the kernel module.
  7. Default behaviour of the module is the same, but when auto_shutdown_output
  8. is set to 1, the SPDIF oputput will shutdown if no stream is playing.
  9. ---
  10. sound/soc/bcm/hifiberry_digi.c | 29 ++++++++++++++++++++++++++++-
  11. 1 file changed, 28 insertions(+), 1 deletion(-)
  12. --- a/sound/soc/bcm/hifiberry_digi.c
  13. +++ b/sound/soc/bcm/hifiberry_digi.c
  14. @@ -26,6 +26,11 @@
  15. #include "../codecs/wm8804.h"
  16. +static short int auto_shutdown_output = 0;
  17. +module_param(auto_shutdown_output, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  18. +MODULE_PARM_DESC(auto_shutdown_output, "Shutdown SP/DIF output if playback is stopped");
  19. +
  20. +
  21. static int samplerate=44100;
  22. static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  23. @@ -38,6 +43,25 @@ static int snd_rpi_hifiberry_digi_init(s
  24. return 0;
  25. }
  26. +static int snd_rpi_hifiberry_digi_startup(struct snd_pcm_substream *substream) {
  27. + /* turn on digital output */
  28. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  29. + struct snd_soc_codec *codec = rtd->codec;
  30. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
  31. + return 0;
  32. +}
  33. +
  34. +static void snd_rpi_hifiberry_digi_shutdown(struct snd_pcm_substream *substream) {
  35. + /* turn off output */
  36. + if (auto_shutdown_output) {
  37. + /* turn off output */
  38. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  39. + struct snd_soc_codec *codec = rtd->codec;
  40. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
  41. + }
  42. +}
  43. +
  44. +
  45. static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  46. struct snd_pcm_hw_params *params)
  47. {
  48. @@ -70,7 +94,8 @@ static int snd_rpi_hifiberry_digi_hw_par
  49. break;
  50. default:
  51. dev_err(substream->pcm->dev,
  52. - "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
  53. + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
  54. + samplerate);
  55. }
  56. snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  57. @@ -96,6 +121,8 @@ static int snd_rpi_hifiberry_digi_hw_par
  58. /* machine stream operations */
  59. static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  60. .hw_params = snd_rpi_hifiberry_digi_hw_params,
  61. + .startup = snd_rpi_hifiberry_digi_startup,
  62. + .shutdown = snd_rpi_hifiberry_digi_shutdown,
  63. };
  64. static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {