1 From 98357bafa929284bbd1046556971c3d4ae9f71d9 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
7 24db_digital_gain DT param can be used to specify that PCM512x
8 codec "Digital" volume control should not be limited to 0dB gain,
9 and if specified will allow the full 24dB gain.
11 arch/arm/boot/dts/overlays/README | 17 +++++++++++++++--
12 .../arm/boot/dts/overlays/hifiberry-dacplus-overlay.dts | 6 +++++-
13 sound/soc/bcm/hifiberry_dacplus.c | 14 ++++++++++++++
14 3 files changed, 34 insertions(+), 3 deletions(-)
16 --- a/arch/arm/boot/dts/overlays/README
17 +++ b/arch/arm/boot/dts/overlays/README
18 @@ -273,8 +273,21 @@ Params: <None>
20 Name: hifiberry-dacplus
21 Info: Configures the HifiBerry DAC+ audio card
22 -Load: dtoverlay=hifiberry-dacplus
24 +Load: dtoverlay=hifiberry-dacplus,<param>=<val>
25 +Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
26 + Digital volume control. Enable with
27 + "dtoverlay=hifiberry-dacplus,24db_digital_gain"
28 + (The default behaviour is that the Digital
29 + volume control is limited to a maximum of
30 + 0dB. ie. it can attenuate but not provide
31 + gain. For most users, this will be desired
32 + as it will prevent clipping. By appending
33 + the 24dB_digital_gain parameter, the Digital
34 + volume control will allow up to 24dB of
35 + gain. If this parameter is enabled, it is the
36 + responsibility of the user to ensure that
37 + the Digital volume control is set to a value
38 + that does not result in clipping/distortion!)
42 --- a/arch/arm/boot/dts/overlays/hifiberry-dacplus-overlay.dts
43 +++ b/arch/arm/boot/dts/overlays/hifiberry-dacplus-overlay.dts
49 + frag1: __overlay__ {
50 compatible = "hifiberry,hifiberry-dacplus";
51 i2s-controller = <&i2s>;
59 + 24db_digital_gain = <&frag1>,"hifiberry,24db_digital_gain?";
62 --- a/sound/soc/bcm/hifiberry_dacplus.c
63 +++ b/sound/soc/bcm/hifiberry_dacplus.c
64 @@ -48,6 +48,7 @@ struct pcm512x_priv {
65 #define CLK_48EN_RATE 24576000UL
67 static bool snd_rpi_hifiberry_is_dacpro;
68 +static bool digital_gain_0db_limit = true;
70 static void snd_rpi_hifiberry_dacplus_select_clk(struct snd_soc_codec *codec,
72 @@ -167,6 +168,16 @@ static int snd_rpi_hifiberry_dacplus_ini
73 snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
74 snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
76 + if (digital_gain_0db_limit)
79 + struct snd_soc_card *card = rtd->card;
81 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
83 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
89 @@ -299,6 +310,9 @@ static int snd_rpi_hifiberry_dacplus_pro
90 dai->platform_name = NULL;
91 dai->platform_of_node = i2s_node;
94 + digital_gain_0db_limit = !of_property_read_bool(
95 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
98 ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);