brcm2708: update linux 4.4 patches to latest version
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0350-New-AudioInjector.net-Pi-soundcard-with-low-jitter-a.patch
1 From ea3e9f892437a7afc78ac04e899fa35c155f198e Mon Sep 17 00:00:00 2001
2 From: Matt Flax <flatmax@flatmax.org>
3 Date: Mon, 16 May 2016 21:36:31 +1000
4 Subject: [PATCH 350/423] New AudioInjector.net Pi soundcard with low jitter
5 audio in and out.
6
7 Contains the sound/soc/bcm ALSA machine driver and necessary alterations to the Kconfig and Makefile.
8 Adds the dts overlay and updates the Makefile and README.
9 Updates the relevant defconfig files to enable building for the Raspberry Pi.
10 Thanks to Phil Elwell (pelwell) for the review, simple-card concepts and discussion. Thanks to Clive Messer for overlay naming suggestions.
11 ---
12 arch/arm/boot/dts/overlays/Makefile | 1 +
13 arch/arm/boot/dts/overlays/README | 6 +
14 .../audioinjector-wm8731-audio-overlay.dts | 39 ++++++
15 arch/arm/configs/bcm2709_defconfig | 1 +
16 arch/arm/configs/bcmrpi_defconfig | 1 +
17 sound/soc/bcm/Kconfig | 7 +
18 sound/soc/bcm/Makefile | 3 +
19 sound/soc/bcm/audioinjector-pi-soundcard.c | 142 +++++++++++++++++++++
20 8 files changed, 200 insertions(+)
21 create mode 100644 arch/arm/boot/dts/overlays/audioinjector-wm8731-audio-overlay.dts
22 create mode 100644 sound/soc/bcm/audioinjector-pi-soundcard.c
23
24 --- a/arch/arm/boot/dts/overlays/Makefile
25 +++ b/arch/arm/boot/dts/overlays/Makefile
26 @@ -16,6 +16,7 @@ dtbo-$(RPI_DT_OVERLAYS) += adau1977-adc.
27 dtbo-$(RPI_DT_OVERLAYS) += ads7846.dtbo
28 dtbo-$(RPI_DT_OVERLAYS) += akkordion-iqdacplus.dtbo
29 dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtbo
30 +dtbo-$(RPI_DT_OVERLAYS) += audioinjector-wm8731-audio.dtbo
31 dtbo-$(RPI_DT_OVERLAYS) += bmp085_i2c-sensor.dtbo
32 dtbo-$(RPI_DT_OVERLAYS) += boomberry-dac.dtbo
33 dtbo-$(RPI_DT_OVERLAYS) += boomberry-digi.dtbo
34 --- a/arch/arm/boot/dts/overlays/README
35 +++ b/arch/arm/boot/dts/overlays/README
36 @@ -225,6 +225,12 @@ Params: interrupt GPIO use
37 arrays (0=+0pF, 15=+4.5pF, default 15)
38
39
40 +Name: audioinjector-wm8731-audio
41 +Info: Configures the audioinjector.net audio add on soundcard
42 +Load: dtoverlay=audioinjector-wm8731-audio
43 +Params: <None>
44 +
45 +
46 Name: bmp085_i2c-sensor
47 Info: Configures the BMP085/BMP180 digital barometric pressure and temperature
48 sensors from Bosch Sensortec
49 --- /dev/null
50 +++ b/arch/arm/boot/dts/overlays/audioinjector-wm8731-audio-overlay.dts
51 @@ -0,0 +1,39 @@
52 +// Definitions for audioinjector.net audio add on soundcard
53 +/dts-v1/;
54 +/plugin/;
55 +
56 +/ {
57 + compatible = "brcm,bcm2708";
58 +
59 + fragment@0 {
60 + target = <&i2s>;
61 + __overlay__ {
62 + status = "okay";
63 + };
64 + };
65 +
66 + fragment@1 {
67 + target = <&i2c1>;
68 + __overlay__ {
69 + #address-cells = <1>;
70 + #size-cells = <0>;
71 + status = "okay";
72 +
73 + wm8731@1a {
74 + #sound-dai-cells = <0>;
75 + compatible = "wlf,wm8731";
76 + reg = <0x1a>;
77 + status = "okay";
78 + };
79 + };
80 + };
81 +
82 + fragment@2 {
83 + target = <&sound>;
84 + __overlay__ {
85 + compatible = "ai,audioinjector-pi-soundcard";
86 + i2s-controller = <&i2s>;
87 + status = "okay";
88 + };
89 + };
90 +};
91 --- a/arch/arm/configs/bcm2709_defconfig
92 +++ b/arch/arm/configs/bcm2709_defconfig
93 @@ -863,6 +863,7 @@ CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
94 CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
95 CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
96 CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
97 +CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
98 CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
99 CONFIG_SND_SOC_ADAU1701=m
100 CONFIG_SND_SOC_WM8804_I2C=m
101 --- a/arch/arm/configs/bcmrpi_defconfig
102 +++ b/arch/arm/configs/bcmrpi_defconfig
103 @@ -855,6 +855,7 @@ CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
104 CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
105 CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
106 CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
107 +CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
108 CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
109 CONFIG_SND_SOC_ADAU1701=m
110 CONFIG_SND_SOC_WM8804_I2C=m
111 --- a/sound/soc/bcm/Kconfig
112 +++ b/sound/soc/bcm/Kconfig
113 @@ -85,3 +85,10 @@ config SND_BCM2708_SOC_ADAU1977_ADC
114 select SND_SOC_ADAU1977_I2C
115 help
116 Say Y or M if you want to add support for ADAU1977 ADC.
117 +
118 +config SND_AUDIOINJECTOR_PI_SOUNDCARD
119 + tristate "Support for audioinjector.net Pi add on soundcard"
120 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
121 + select SND_SOC_WM8731
122 + help
123 + Say Y or M if you want to add support for audioinjector.net Pi Hat
124 --- a/sound/soc/bcm/Makefile
125 +++ b/sound/soc/bcm/Makefile
126 @@ -15,6 +15,7 @@ snd-soc-rpi-dac-objs := rpi-dac.o
127 snd-soc-rpi-proto-objs := rpi-proto.o
128 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
129 snd-soc-raspidac3-objs := raspidac3.o
130 +snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
131
132 obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
133 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
134 @@ -27,3 +28,5 @@ obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) +=
135 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
136 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
137 obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
138 +obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
139 +
140 --- /dev/null
141 +++ b/sound/soc/bcm/audioinjector-pi-soundcard.c
142 @@ -0,0 +1,142 @@
143 +/*
144 + * ASoC Driver for AudioInjector Pi add on soundcard
145 + *
146 + * Created on: 13-May-2016
147 + * Author: flatmax@flatmax.org
148 + * based on code by Cliff Cai <Cliff.Cai@analog.com> for the ssm2602 machine blackfin.
149 + * with help from Lars-Peter Clausen for simplifying the original code to use the dai_fmt field.
150 + * i2s_node code taken from the other sound/soc/bcm machine drivers.
151 + *
152 + * Copyright (C) 2016 Flatmax Pty. Ltd.
153 + *
154 + * This program is free software; you can redistribute it and/or
155 + * modify it under the terms of the GNU General Public License
156 + * version 2 as published by the Free Software Foundation.
157 + *
158 + * This program is distributed in the hope that it will be useful, but
159 + * WITHOUT ANY WARRANTY; without even the implied warranty of
160 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
161 + * General Public License for more details.
162 + */
163 +
164 +#include <linux/module.h>
165 +#include <linux/types.h>
166 +
167 +#include <sound/core.h>
168 +#include <sound/soc.h>
169 +#include <sound/pcm_params.h>
170 +#include <sound/control.h>
171 +
172 +#include "../codecs/wm8731.h"
173 +
174 +static int audioinjector_pi_soundcard_dai_init(struct snd_soc_pcm_runtime *rtd)
175 +{
176 + struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
177 +
178 + // not connected
179 + snd_soc_dapm_nc_pin(dapm, "Mic Bias");
180 + snd_soc_dapm_nc_pin(dapm, "MICIN");
181 + snd_soc_dapm_nc_pin(dapm, "RHPOUT");
182 + snd_soc_dapm_nc_pin(dapm, "LHPOUT");
183 +
184 + return snd_soc_dai_set_sysclk(rtd->codec_dai, WM8731_SYSCLK_XTAL, 12000000, SND_SOC_CLOCK_IN);
185 +}
186 +
187 +static struct snd_soc_dai_link audioinjector_pi_soundcard_dai[] = {
188 + {
189 + .name = "AudioInjector audio",
190 + .stream_name = "AudioInjector audio",
191 + .cpu_dai_name = "bcm2708-i2s.0",
192 + .codec_dai_name = "wm8731-hifi",
193 + .platform_name = "bcm2835-i2s.0",
194 + .codec_name = "wm8731.1-001a",
195 + .init = audioinjector_pi_soundcard_dai_init,
196 + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
197 + },
198 +};
199 +
200 +static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
201 + SND_SOC_DAPM_SPK("Ext Spk", NULL),
202 + SND_SOC_DAPM_LINE("Line In Jacks", NULL),
203 +};
204 +
205 +/* Corgi machine connections to the codec pins */
206 +static const struct snd_soc_dapm_route audioinjector_audio_map[] = {
207 + /* speaker connected to LOUT, ROUT */
208 + {"Ext Spk", NULL, "ROUT"},
209 + {"Ext Spk", NULL, "LOUT"},
210 +
211 + /* line inputs */
212 + {"Line In Jacks", NULL, "Line Input"},
213 +};
214 +
215 +static struct snd_soc_card snd_soc_audioinjector = {
216 + .name = "audioinjector-pi-soundcard",
217 + .dai_link = audioinjector_pi_soundcard_dai,
218 + .num_links = 1,
219 +
220 + .dapm_widgets = wm8731_dapm_widgets,
221 + .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
222 + .dapm_routes = audioinjector_audio_map,
223 + .num_dapm_routes = ARRAY_SIZE(audioinjector_audio_map),
224 +};
225 +
226 +static int audioinjector_pi_soundcard_probe(struct platform_device *pdev)
227 +{
228 + struct snd_soc_card *card = &snd_soc_audioinjector;
229 + int ret;
230 +
231 + card->dev = &pdev->dev;
232 +
233 + if (pdev->dev.of_node) {
234 + struct snd_soc_dai_link *dai = &audioinjector_pi_soundcard_dai[0];
235 + struct device_node *i2s_node = of_parse_phandle(pdev->dev.of_node,
236 + "i2s-controller", 0);
237 +
238 + if (i2s_node) {
239 + dai->cpu_dai_name = NULL;
240 + dai->cpu_of_node = i2s_node;
241 + dai->platform_name = NULL;
242 + dai->platform_of_node = i2s_node;
243 + } else
244 + if (!dai->cpu_of_node) {
245 + dev_err(&pdev->dev, "Property 'i2s-controller' missing or invalid\n");
246 + return -EINVAL;
247 + }
248 + }
249 +
250 + if ((ret = snd_soc_register_card(card))) {
251 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
252 + }
253 + return ret;
254 +}
255 +
256 +static int audioinjector_pi_soundcard_remove(struct platform_device *pdev)
257 +{
258 + struct snd_soc_card *card = platform_get_drvdata(pdev);
259 + return snd_soc_unregister_card(card);
260 +
261 +}
262 +
263 +static const struct of_device_id audioinjector_pi_soundcard_of_match[] = {
264 + { .compatible = "ai,audioinjector-pi-soundcard", },
265 + {},
266 +};
267 +MODULE_DEVICE_TABLE(of, audioinjector_pi_soundcard_of_match);
268 +
269 +static struct platform_driver audioinjector_pi_soundcard_driver = {
270 + .driver = {
271 + .name = "audioinjector-audio",
272 + .owner = THIS_MODULE,
273 + .of_match_table = audioinjector_pi_soundcard_of_match,
274 + },
275 + .probe = audioinjector_pi_soundcard_probe,
276 + .remove = audioinjector_pi_soundcard_remove,
277 +};
278 +
279 +module_platform_driver(audioinjector_pi_soundcard_driver);
280 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
281 +MODULE_DESCRIPTION("AudioInjector.net Pi Soundcard");
282 +MODULE_LICENSE("GPL v2");
283 +MODULE_ALIAS("platform:audioinjector-pi-soundcard");
284 +