kernel: bump 4.9 to 4.9.96
[openwrt/staging/wigyori.git] / target / linux / brcm2708 / patches-4.9 / 950-0190-sound-Support-for-Dion-Audio-LOCO-V2-DAC-AMP-HAT.patch
1 From a20dbe4972ea3df27f24c5397102e1346462a4f4 Mon Sep 17 00:00:00 2001
2 From: Miquel <miquelblauw@hotmail.com>
3 Date: Fri, 24 Feb 2017 20:51:06 +0100
4 Subject: [PATCH] sound: Support for Dion Audio LOCO-V2 DAC-AMP HAT
5
6 Signed-off-by: Miquel Blauw <info@dionaudio.nl>
7 ---
8 arch/arm/boot/dts/overlays/Makefile | 1 +
9 arch/arm/boot/dts/overlays/README | 19 +++++
10 arch/arm/configs/bcm2709_defconfig | 1 +
11 arch/arm/configs/bcmrpi_defconfig | 1 +
12 sound/soc/bcm/Kconfig | 7 ++
13 sound/soc/bcm/Makefile | 2 +
14 sound/soc/bcm/dionaudio_loco-v2.c | 140 ++++++++++++++++++++++++++++++++++++
15 7 files changed, 171 insertions(+)
16 create mode 100644 sound/soc/bcm/dionaudio_loco-v2.c
17
18 --- a/arch/arm/boot/dts/overlays/Makefile
19 +++ b/arch/arm/boot/dts/overlays/Makefile
20 @@ -13,6 +13,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
21 bmp085_i2c-sensor.dtbo \
22 dht11.dtbo \
23 dionaudio-loco.dtbo \
24 + dionaudio-loco-v2.dtbo \
25 dpi18.dtbo \
26 dpi24.dtbo \
27 dwc-otg.dtbo \
28 --- a/arch/arm/boot/dts/overlays/README
29 +++ b/arch/arm/boot/dts/overlays/README
30 @@ -308,6 +308,25 @@ Load: dtoverlay=dionaudio-loco
31 Params: <None>
32
33
34 +Name: dionaudio-loco-v2
35 +Info: Configures the Dion Audio LOCO-V2 DAC-AMP
36 +Load: dtoverlay=dionaudio-loco-v2,<param>=<val>
37 +Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
38 + Digital volume control. Enable with
39 + "dtoverlay=hifiberry-dacplus,24db_digital_gain"
40 + (The default behaviour is that the Digital
41 + volume control is limited to a maximum of
42 + 0dB. ie. it can attenuate but not provide
43 + gain. For most users, this will be desired
44 + as it will prevent clipping. By appending
45 + the 24dB_digital_gain parameter, the Digital
46 + volume control will allow up to 24dB of
47 + gain. If this parameter is enabled, it is the
48 + responsibility of the user to ensure that
49 + the Digital volume control is set to a value
50 + that does not result in clipping/distortion!)
51 +
52 +
53 Name: dpi18
54 Info: Overlay for a generic 18-bit DPI display
55 This uses GPIOs 0-21 (so no I2C, uart etc.), and activates the output
56 --- a/arch/arm/configs/bcm2709_defconfig
57 +++ b/arch/arm/configs/bcm2709_defconfig
58 @@ -889,6 +889,7 @@ CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
59 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
60 CONFIG_SND_DIGIDAC1_SOUNDCARD=m
61 CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
62 +CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2=m
63 CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m
64 CONFIG_SND_PISOUND=m
65 CONFIG_SND_SOC_ADAU1701=m
66 --- a/arch/arm/configs/bcmrpi_defconfig
67 +++ b/arch/arm/configs/bcmrpi_defconfig
68 @@ -883,6 +883,7 @@ CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
69 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
70 CONFIG_SND_DIGIDAC1_SOUNDCARD=m
71 CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
72 +CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2=m
73 CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m
74 CONFIG_SND_PISOUND=m
75 CONFIG_SND_SOC_ADAU1701=m
76 --- a/sound/soc/bcm/Kconfig
77 +++ b/sound/soc/bcm/Kconfig
78 @@ -133,6 +133,13 @@ config SND_BCM2708_SOC_DIONAUDIO_LOCO
79 help
80 Say Y or M if you want to add support for Dion Audio LOCO.
81
82 +config SND_BCM2708_SOC_DIONAUDIO_LOCO_V2
83 + tristate "Support for Dion Audio LOCO-V2 DAC-AMP"
84 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
85 + select SND_SOC_PCM5122
86 + help
87 + Say Y or M if you want to add support for Dion Audio LOCO-V2.
88 +
89 config SND_BCM2708_SOC_ALLO_PIANO_DAC
90 tristate "Support for Allo Piano DAC"
91 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
92 --- a/sound/soc/bcm/Makefile
93 +++ b/sound/soc/bcm/Makefile
94 @@ -25,6 +25,7 @@ snd-soc-raspidac3-objs := raspidac3.o
95 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
96 snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
97 snd-soc-dionaudio-loco-objs := dionaudio_loco.o
98 +snd-soc-dionaudio-loco-v2-objs := dionaudio_loco-v2.o
99 snd-soc-allo-piano-dac-objs := allo-piano-dac.o
100 snd-soc-pisound-objs := pisound.o
101
102 @@ -44,5 +45,6 @@ obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3)
103 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
104 obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
105 obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
106 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2) += snd-soc-dionaudio-loco-v2.o
107 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
108 obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o
109 --- /dev/null
110 +++ b/sound/soc/bcm/dionaudio_loco-v2.c
111 @@ -0,0 +1,140 @@
112 +/*
113 + * ASoC Driver for Dion Audio LOCO-V2 DAC-AMP
114 + *
115 + * Author: Miquel Blauw <info@dionaudio.nl>
116 + * Copyright 2017
117 + *
118 + * Based on the software of the RPi-DAC writen by Florian Meier
119 + *
120 + * This program is free software; you can redistribute it and/or
121 + * modify it under the terms of the GNU General Public License
122 + * version 2 as published by the Free Software Foundation.
123 + *
124 + * This program is distributed in the hope that it will be useful, but
125 + * WITHOUT ANY WARRANTY; without even the implied warranty of
126 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
127 + * General Public License for more details.
128 + */
129 +
130 +#include <linux/module.h>
131 +#include <linux/platform_device.h>
132 +
133 +#include <sound/core.h>
134 +#include <sound/pcm.h>
135 +#include <sound/pcm_params.h>
136 +#include <sound/soc.h>
137 +#include <sound/jack.h>
138 +
139 +static bool digital_gain_0db_limit = true;
140 +
141 +static int snd_rpi_dionaudio_loco_v2_init(struct snd_soc_pcm_runtime *rtd)
142 +{
143 + if (digital_gain_0db_limit) {
144 + int ret;
145 + struct snd_soc_card *card = rtd->card;
146 +
147 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
148 + if (ret < 0)
149 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
150 + }
151 +
152 + return 0;
153 +}
154 +
155 +static int snd_rpi_dionaudio_loco_v2_hw_params(
156 + struct snd_pcm_substream *substream,
157 + struct snd_pcm_hw_params *params)
158 +{
159 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
160 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
161 +
162 + unsigned int sample_bits =
163 + snd_pcm_format_physical_width(params_format(params));
164 +
165 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
166 +}
167 +
168 +/* machine stream operations */
169 +static struct snd_soc_ops snd_rpi_dionaudio_loco_v2_ops = {
170 + .hw_params = snd_rpi_dionaudio_loco_v2_hw_params,
171 +};
172 +
173 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_v2_dai[] = {
174 +{
175 + .name = "DionAudio LOCO-V2",
176 + .stream_name = "DionAudio LOCO-V2 DAC-AMP",
177 + .cpu_dai_name = "bcm2708-i2s.0",
178 + .codec_dai_name = "pcm512x-hifi",
179 + .platform_name = "bcm2708-i2s.0",
180 + .codec_name = "pcm512x.1-004d",
181 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
182 + SND_SOC_DAIFMT_CBS_CFS,
183 + .ops = &snd_rpi_dionaudio_loco_v2_ops,
184 + .init = snd_rpi_dionaudio_loco_v2_init,
185 +},};
186 +
187 +/* audio machine driver */
188 +static struct snd_soc_card snd_rpi_dionaudio_loco_v2 = {
189 + .name = "Dion Audio LOCO-V2",
190 + .dai_link = snd_rpi_dionaudio_loco_v2_dai,
191 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_v2_dai),
192 +};
193 +
194 +static int snd_rpi_dionaudio_loco_v2_probe(struct platform_device *pdev)
195 +{
196 + int ret = 0;
197 +
198 + snd_rpi_dionaudio_loco_v2.dev = &pdev->dev;
199 +
200 + if (pdev->dev.of_node) {
201 + struct device_node *i2s_node;
202 + struct snd_soc_dai_link *dai =
203 + &snd_rpi_dionaudio_loco_v2_dai[0];
204 +
205 + i2s_node = of_parse_phandle(pdev->dev.of_node,
206 + "i2s-controller", 0);
207 + if (i2s_node) {
208 + dai->cpu_dai_name = NULL;
209 + dai->cpu_of_node = i2s_node;
210 + dai->platform_name = NULL;
211 + dai->platform_of_node = i2s_node;
212 + }
213 +
214 + digital_gain_0db_limit = !of_property_read_bool(
215 + pdev->dev.of_node, "dionaudio,24db_digital_gain");
216 + }
217 +
218 + ret = snd_soc_register_card(&snd_rpi_dionaudio_loco_v2);
219 + if (ret)
220 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
221 + ret);
222 +
223 + return ret;
224 +}
225 +
226 +static int snd_rpi_dionaudio_loco_v2_remove(struct platform_device *pdev)
227 +{
228 + return snd_soc_unregister_card(&snd_rpi_dionaudio_loco_v2);
229 +}
230 +
231 +static const struct of_device_id dionaudio_of_match[] = {
232 + { .compatible = "dionaudio,dionaudio-loco-v2", },
233 + {},
234 +};
235 +MODULE_DEVICE_TABLE(of, dionaudio_of_match);
236 +
237 +static struct platform_driver snd_rpi_dionaudio_loco_v2_driver = {
238 + .driver = {
239 + .name = "snd-rpi-dionaudio-loco-v2",
240 + .owner = THIS_MODULE,
241 + .of_match_table = dionaudio_of_match,
242 + },
243 + .probe = snd_rpi_dionaudio_loco_v2_probe,
244 + .remove = snd_rpi_dionaudio_loco_v2_remove,
245 +};
246 +
247 +module_platform_driver(snd_rpi_dionaudio_loco_v2_driver);
248 +
249 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
250 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO-V2");
251 +MODULE_LICENSE("GPL v2");