brcm2708: update linux 4.4 patches to latest version
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0507-Allo-Piano-DAC-boards-Initial-2-channel-stereo-suppo.patch
1 From 655114c25214675520d742f5e86cdd8dd534e6c7 Mon Sep 17 00:00:00 2001
2 From: Clive Messer <clive.m.messer@gmail.com>
3 Date: Mon, 19 Sep 2016 14:01:04 +0100
4 Subject: [PATCH] Allo Piano DAC boards: Initial 2 channel (stereo) support
5 (#1645)
6
7 Add initial 2 channel (stereo) support for Allo Piano DAC (2.0/2.1) boards,
8 using allo-piano-dac-pcm512x-audio overlay and allo-piano-dac ALSA ASoC
9 machine driver.
10
11 NB. The initial support is 2 channel (stereo) ONLY!
12 (The Piano DAC 2.1 will only support 2 channel (stereo) left/right output,
13 pending an update to the upstream pcm512x codec driver, which will have
14 to be submitted via upstream. With the initial downstream support,
15 provided by this patch, the Piano DAC 2.1 subwoofer outputs will
16 not function.)
17
18 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
19 Signed-off-by: Clive Messer <clive.messer@digitaldreamtime.co.uk>
20 Tested-by: Clive Messer <clive.messer@digitaldreamtime.co.uk>
21 ---
22 arch/arm/boot/dts/overlays/Makefile | 1 +
23 arch/arm/boot/dts/overlays/README | 20 +++
24 .../allo-piano-dac-pcm512x-audio-overlay.dts | 54 ++++++++
25 arch/arm/configs/bcm2709_defconfig | 1 +
26 arch/arm/configs/bcmrpi_defconfig | 1 +
27 sound/soc/bcm/Kconfig | 7 +
28 sound/soc/bcm/Makefile | 2 +
29 sound/soc/bcm/allo-piano-dac.c | 144 +++++++++++++++++++++
30 8 files changed, 230 insertions(+)
31 create mode 100644 arch/arm/boot/dts/overlays/allo-piano-dac-pcm512x-audio-overlay.dts
32 create mode 100644 sound/soc/bcm/allo-piano-dac.c
33
34 --- a/arch/arm/boot/dts/overlays/Makefile
35 +++ b/arch/arm/boot/dts/overlays/Makefile
36 @@ -16,6 +16,7 @@ dtbo-$(RPI_DT_OVERLAYS) += adau1977-adc.
37 dtbo-$(RPI_DT_OVERLAYS) += ads1015.dtbo
38 dtbo-$(RPI_DT_OVERLAYS) += ads7846.dtbo
39 dtbo-$(RPI_DT_OVERLAYS) += akkordion-iqdacplus.dtbo
40 +dtbo-$(RPI_DT_OVERLAYS) += allo-piano-dac-pcm512x-audio.dtbo
41 dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtbo
42 dtbo-$(RPI_DT_OVERLAYS) += audioinjector-wm8731-audio.dtbo
43 dtbo-$(RPI_DT_OVERLAYS) += audremap.dtbo
44 --- a/arch/arm/boot/dts/overlays/README
45 +++ b/arch/arm/boot/dts/overlays/README
46 @@ -235,6 +235,26 @@ Params: 24db_digital_gain Allow ga
47 that does not result in clipping/distortion!)
48
49
50 +Name: allo-piano-dac-pcm512x-audio
51 +Info: Configures the Allo Piano DAC (2.0/2.1) audio cards.
52 + (NB. This initial support is for 2.0 channel audio ONLY! ie. stereo.
53 + The subwoofer outputs on the Piano 2.1 are not currently supported!)
54 +Load: dtoverlay=allo-piano-dac-pcm512x-audio,<param>
55 +Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
56 + Digital volume control.
57 + (The default behaviour is that the Digital
58 + volume control is limited to a maximum of
59 + 0dB. ie. it can attenuate but not provide
60 + gain. For most users, this will be desired
61 + as it will prevent clipping. By appending
62 + the 24db_digital_gain parameter, the Digital
63 + volume control will allow up to 24dB of
64 + gain. If this parameter is enabled, it is the
65 + responsibility of the user to ensure that
66 + the Digital volume control is set to a value
67 + that does not result in clipping/distortion!)
68 +
69 +
70 Name: at86rf233
71 Info: Configures the Atmel AT86RF233 802.15.4 low-power WPAN transceiver,
72 connected to spi0.0
73 --- /dev/null
74 +++ b/arch/arm/boot/dts/overlays/allo-piano-dac-pcm512x-audio-overlay.dts
75 @@ -0,0 +1,54 @@
76 +/*
77 + * Definitions for Allo Piano DAC (2.0/2.1) boards
78 + *
79 + * NB. The Piano DAC 2.1 board contains 2x TI PCM5142 DAC's. One DAC is stereo
80 + * (left/right) and the other provides a subwoofer output, using DSP on the
81 + * chip for digital high/low pass crossover.
82 + * The initial support for this hardware, that doesn't require any codec driver
83 + * modifications, uses only one DAC chip for stereo (left/right) output, the
84 + * chip with 0x4c slave address. The other chip at 0x4d is currently ignored!
85 + */
86 +
87 +/dts-v1/;
88 +/plugin/;
89 +
90 +/ {
91 + compatible = "brcm,bcm2708";
92 +
93 + fragment@0 {
94 + target = <&i2s>;
95 + __overlay__ {
96 + status = "okay";
97 + };
98 + };
99 +
100 + fragment@1 {
101 + target = <&i2c1>;
102 + __overlay__ {
103 + #address-cells = <1>;
104 + #size-cells = <0>;
105 + status = "okay";
106 +
107 + pcm5142@4c {
108 + #sound-dai-cells = <0>;
109 + compatible = "ti,pcm5142";
110 + reg = <0x4c>;
111 + status = "okay";
112 + };
113 + };
114 + };
115 +
116 + fragment@2 {
117 + target = <&sound>;
118 + piano_dac: __overlay__ {
119 + compatible = "allo,piano-dac";
120 + i2s-controller = <&i2s>;
121 + status = "okay";
122 + };
123 + };
124 +
125 + __overrides__ {
126 + 24db_digital_gain =
127 + <&piano_dac>,"allo,24db_digital_gain?";
128 + };
129 +};
130 --- a/arch/arm/configs/bcm2709_defconfig
131 +++ b/arch/arm/configs/bcm2709_defconfig
132 @@ -879,6 +879,7 @@ CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
133 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
134 CONFIG_SND_DIGIDAC1_SOUNDCARD=m
135 CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
136 +CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m
137 CONFIG_SND_SOC_ADAU1701=m
138 CONFIG_SND_SOC_WM8804_I2C=m
139 CONFIG_SND_SIMPLE_CARD=m
140 --- a/arch/arm/configs/bcmrpi_defconfig
141 +++ b/arch/arm/configs/bcmrpi_defconfig
142 @@ -871,6 +871,7 @@ CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
143 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
144 CONFIG_SND_DIGIDAC1_SOUNDCARD=m
145 CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
146 +CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m
147 CONFIG_SND_SOC_ADAU1701=m
148 CONFIG_SND_SOC_WM8804_I2C=m
149 CONFIG_SND_SIMPLE_CARD=m
150 --- a/sound/soc/bcm/Kconfig
151 +++ b/sound/soc/bcm/Kconfig
152 @@ -114,3 +114,10 @@ config SND_BCM2708_SOC_DIONAUDIO_LOCO
153 select SND_SOC_PCM5102a
154 help
155 Say Y or M if you want to add support for Dion Audio LOCO.
156 +
157 +config SND_BCM2708_SOC_ALLO_PIANO_DAC
158 + tristate "Support for Allo Piano DAC"
159 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
160 + select SND_SOC_PCM512x_I2C
161 + help
162 + Say Y or M if you want to add support for Allo Piano DAC.
163 --- a/sound/soc/bcm/Makefile
164 +++ b/sound/soc/bcm/Makefile
165 @@ -19,6 +19,7 @@ snd-soc-raspidac3-objs := raspidac3.o
166 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
167 snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
168 snd-soc-dionaudio-loco-objs := dionaudio_loco.o
169 +snd-soc-allo-piano-dac-objs := allo-piano-dac.o
170
171 obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
172 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
173 @@ -35,3 +36,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3)
174 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
175 obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
176 obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
177 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
178 --- /dev/null
179 +++ b/sound/soc/bcm/allo-piano-dac.c
180 @@ -0,0 +1,144 @@
181 +/*
182 + * ALSA ASoC Machine Driver for Allo Piano DAC
183 + *
184 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
185 + * Copyright 2016
186 + * based on code by Daniel Matuschek <info@crazy-audio.com>
187 + * based on code by Florian Meier <florian.meier@koalo.de>
188 + *
189 + * This program is free software; you can redistribute it and/or
190 + * modify it under the terms of the GNU General Public License
191 + * version 2 as published by the Free Software Foundation.
192 + *
193 + * This program is distributed in the hope that it will be useful, but
194 + * WITHOUT ANY WARRANTY; without even the implied warranty of
195 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
196 + * General Public License for more details.
197 + */
198 +
199 +#include <linux/module.h>
200 +#include <linux/platform_device.h>
201 +
202 +#include <sound/core.h>
203 +#include <sound/pcm.h>
204 +#include <sound/pcm_params.h>
205 +#include <sound/soc.h>
206 +
207 +static bool digital_gain_0db_limit = true;
208 +
209 +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
210 +{
211 + if (digital_gain_0db_limit) {
212 + int ret;
213 + struct snd_soc_card *card = rtd->card;
214 +
215 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
216 + 207);
217 + if (ret < 0)
218 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
219 + ret);
220 + }
221 +
222 + return 0;
223 +}
224 +
225 +static int snd_allo_piano_dac_hw_params(
226 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
227 +{
228 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
229 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
230 +
231 + unsigned int sample_bits =
232 + snd_pcm_format_physical_width(params_format(params));
233 +
234 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
235 +}
236 +
237 +/* machine stream operations */
238 +static struct snd_soc_ops snd_allo_piano_dac_ops = {
239 + .hw_params = snd_allo_piano_dac_hw_params,
240 +};
241 +
242 +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
243 +{
244 + .name = "Piano DAC",
245 + .stream_name = "Piano DAC HiFi",
246 + .cpu_dai_name = "bcm2708-i2s.0",
247 + .codec_dai_name = "pcm512x-hifi",
248 + .platform_name = "bcm2708-i2s.0",
249 + .codec_name = "pcm512x.1-004c",
250 + .dai_fmt = SND_SOC_DAIFMT_I2S |
251 + SND_SOC_DAIFMT_NB_NF |
252 + SND_SOC_DAIFMT_CBS_CFS,
253 + .ops = &snd_allo_piano_dac_ops,
254 + .init = snd_allo_piano_dac_init,
255 +},
256 +};
257 +
258 +/* audio machine driver */
259 +static struct snd_soc_card snd_allo_piano_dac = {
260 + .name = "PianoDAC",
261 + .owner = THIS_MODULE,
262 + .dai_link = snd_allo_piano_dac_dai,
263 + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
264 +};
265 +
266 +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
267 +{
268 + int ret = 0;
269 +
270 + snd_allo_piano_dac.dev = &pdev->dev;
271 +
272 + if (pdev->dev.of_node) {
273 + struct device_node *i2s_node;
274 + struct snd_soc_dai_link *dai;
275 +
276 + dai = &snd_allo_piano_dac_dai[0];
277 + i2s_node = of_parse_phandle(pdev->dev.of_node,
278 + "i2s-controller", 0);
279 +
280 + if (i2s_node) {
281 + dai->cpu_dai_name = NULL;
282 + dai->cpu_of_node = i2s_node;
283 + dai->platform_name = NULL;
284 + dai->platform_of_node = i2s_node;
285 + }
286 +
287 + digital_gain_0db_limit = !of_property_read_bool(
288 + pdev->dev.of_node, "allo,24db_digital_gain");
289 + }
290 +
291 + ret = snd_soc_register_card(&snd_allo_piano_dac);
292 + if (ret)
293 + dev_err(&pdev->dev,
294 + "snd_soc_register_card() failed: %d\n", ret);
295 +
296 + return ret;
297 +}
298 +
299 +static int snd_allo_piano_dac_remove(struct platform_device *pdev)
300 +{
301 + return snd_soc_unregister_card(&snd_allo_piano_dac);
302 +}
303 +
304 +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
305 + { .compatible = "allo,piano-dac", },
306 + { /* sentinel */ },
307 +};
308 +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
309 +
310 +static struct platform_driver snd_allo_piano_dac_driver = {
311 + .driver = {
312 + .name = "snd-allo-piano-dac",
313 + .owner = THIS_MODULE,
314 + .of_match_table = snd_allo_piano_dac_of_match,
315 + },
316 + .probe = snd_allo_piano_dac_probe,
317 + .remove = snd_allo_piano_dac_remove,
318 +};
319 +
320 +module_platform_driver(snd_allo_piano_dac_driver);
321 +
322 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
323 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
324 +MODULE_LICENSE("GPL v2");