0141-Limit-PCM512x-Digital-gain-to-0dB-by-default-with-Hi.patch 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. From 5eb11c1a6735ddbcb4b37014caf5945123aad8a2 Mon Sep 17 00:00:00 2001
  2. From: Digital Dreamtime <clive.messer@digitaldreamtime.co.uk>
  3. Date: Thu, 4 Feb 2016 20:04:00 +0000
  4. Subject: [PATCH] Limit PCM512x "Digital" gain to 0dB by default with HiFiBerry
  5. DAC+
  6. 24db_digital_gain DT param can be used to specify that PCM512x
  7. codec "Digital" volume control should not be limited to 0dB gain,
  8. and if specified will allow the full 24dB gain.
  9. ---
  10. arch/arm/boot/dts/overlays/README | 17 +++++++++++++++--
  11. .../arm/boot/dts/overlays/hifiberry-dacplus-overlay.dts | 6 +++++-
  12. sound/soc/bcm/hifiberry_dacplus.c | 14 ++++++++++++++
  13. 3 files changed, 34 insertions(+), 3 deletions(-)
  14. --- a/arch/arm/boot/dts/overlays/README
  15. +++ b/arch/arm/boot/dts/overlays/README
  16. @@ -273,8 +273,21 @@ Params: <None>
  17. Name: hifiberry-dacplus
  18. Info: Configures the HifiBerry DAC+ audio card
  19. -Load: dtoverlay=hifiberry-dacplus
  20. -Params: <None>
  21. +Load: dtoverlay=hifiberry-dacplus,<param>=<val>
  22. +Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
  23. + Digital volume control. Enable with
  24. + "dtoverlay=hifiberry-dacplus,24db_digital_gain"
  25. + (The default behaviour is that the Digital
  26. + volume control is limited to a maximum of
  27. + 0dB. ie. it can attenuate but not provide
  28. + gain. For most users, this will be desired
  29. + as it will prevent clipping. By appending
  30. + the 24dB_digital_gain parameter, the Digital
  31. + volume control will allow up to 24dB of
  32. + gain. If this parameter is enabled, it is the
  33. + responsibility of the user to ensure that
  34. + the Digital volume control is set to a value
  35. + that does not result in clipping/distortion!)
  36. Name: hifiberry-digi
  37. --- a/arch/arm/boot/dts/overlays/hifiberry-dacplus-overlay.dts
  38. +++ b/arch/arm/boot/dts/overlays/hifiberry-dacplus-overlay.dts
  39. @@ -17,7 +17,7 @@
  40. fragment@1 {
  41. target = <&sound>;
  42. - __overlay__ {
  43. + frag1: __overlay__ {
  44. compatible = "hifiberry,hifiberry-dacplus";
  45. i2s-controller = <&i2s>;
  46. status = "okay";
  47. @@ -47,4 +47,8 @@
  48. };
  49. };
  50. };
  51. +
  52. + __overrides__ {
  53. + 24db_digital_gain = <&frag1>,"hifiberry,24db_digital_gain?";
  54. + };
  55. };
  56. --- a/sound/soc/bcm/hifiberry_dacplus.c
  57. +++ b/sound/soc/bcm/hifiberry_dacplus.c
  58. @@ -48,6 +48,7 @@ struct pcm512x_priv {
  59. #define CLK_48EN_RATE 24576000UL
  60. static bool snd_rpi_hifiberry_is_dacpro;
  61. +static bool digital_gain_0db_limit = true;
  62. static void snd_rpi_hifiberry_dacplus_select_clk(struct snd_soc_codec *codec,
  63. int clk_id)
  64. @@ -167,6 +168,16 @@ static int snd_rpi_hifiberry_dacplus_ini
  65. snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
  66. snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
  67. + if (digital_gain_0db_limit)
  68. + {
  69. + int ret;
  70. + struct snd_soc_card *card = rtd->card;
  71. +
  72. + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
  73. + if (ret < 0)
  74. + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
  75. + }
  76. +
  77. return 0;
  78. }
  79. @@ -299,6 +310,9 @@ static int snd_rpi_hifiberry_dacplus_pro
  80. dai->platform_name = NULL;
  81. dai->platform_of_node = i2s_node;
  82. }
  83. +
  84. + digital_gain_0db_limit = !of_property_read_bool(
  85. + pdev->dev.of_node, "hifiberry,24db_digital_gain");
  86. }
  87. ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);