kernel: bump 4.9 to 4.9.96
[openwrt/staging/wigyori.git] / target / linux / brcm2708 / patches-4.9 / 950-0192-Add-support-for-Fe-Pi-audio-sound-card.-1867.patch
1 From c646d023c75607a9ebc7296fe424d6eb4e804164 Mon Sep 17 00:00:00 2001
2 From: Fe-Pi <fe-pi@cox.net>
3 Date: Wed, 1 Mar 2017 04:42:43 -0700
4 Subject: [PATCH] Add support for Fe-Pi audio sound card. (#1867)
5
6 Fe-Pi Audio Sound Card is based on NXP SGTL5000 codec.
7 Mechanical specification of the board is the same the Raspberry Pi Zero.
8 3.5mm jacks for Headphone/Mic, Line In, and Line Out.
9
10 Signed-off-by: Henry Kupis <fe-pi@cox.net>
11 ---
12 arch/arm/boot/dts/overlays/Makefile | 1 +
13 arch/arm/boot/dts/overlays/README | 6 +
14 arch/arm/boot/dts/overlays/fe-pi-audio-overlay.dts | 70 +++++++++
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 | 2 +
19 sound/soc/bcm/fe-pi-audio.c | 158 +++++++++++++++++++++
20 8 files changed, 246 insertions(+)
21 create mode 100644 arch/arm/boot/dts/overlays/fe-pi-audio-overlay.dts
22 create mode 100644 sound/soc/bcm/fe-pi-audio.c
23
24 --- a/arch/arm/boot/dts/overlays/Makefile
25 +++ b/arch/arm/boot/dts/overlays/Makefile
26 @@ -20,6 +20,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
27 dwc2.dtbo \
28 enc28j60.dtbo \
29 enc28j60-spi2.dtbo \
30 + fe-pi-audio.dtbo \
31 gpio-ir.dtbo \
32 gpio-poweroff.dtbo \
33 hifiberry-amp.dtbo \
34 --- a/arch/arm/boot/dts/overlays/README
35 +++ b/arch/arm/boot/dts/overlays/README
36 @@ -383,6 +383,12 @@ Params: int_pin GPIO use
37 speed SPI bus speed (default 12000000)
38
39
40 +Name: fe-pi-audio
41 +Info: Configures the Fe-Pi Audio Sound Card
42 +Load: dtoverlay=fe-pi-audio
43 +Params: <None>
44 +
45 +
46 Name: gpio-ir
47 Info: Use GPIO pin as rc-core style infrared receiver input. The rc-core-
48 based gpio_ir_recv driver maps received keys directly to a
49 --- /dev/null
50 +++ b/arch/arm/boot/dts/overlays/fe-pi-audio-overlay.dts
51 @@ -0,0 +1,70 @@
52 +// Definitions for Fe-Pi Audio
53 +/dts-v1/;
54 +/plugin/;
55 +
56 +/ {
57 + compatible = "brcm,bcm2708";
58 +
59 + fragment@0 {
60 + target = <&clocks>;
61 + __overlay__ {
62 + sgtl5000_mclk: sgtl5000_mclk {
63 + compatible = "fixed-clock";
64 + #clock-cells = <0>;
65 + clock-frequency = <12288000>;
66 + clock-output-names = "sgtl5000-mclk";
67 + };
68 + };
69 + };
70 +
71 + fragment@1 {
72 + target = <&soc>;
73 + __overlay__ {
74 + reg_1v8: reg_1v8@0 {
75 + compatible = "regulator-fixed";
76 + regulator-name = "1V8";
77 + regulator-min-microvolt = <1800000>;
78 + regulator-max-microvolt = <1800000>;
79 + regulator-always-on;
80 + };
81 + };
82 + };
83 +
84 + fragment@2 {
85 + target = <&i2c1>;
86 + __overlay__ {
87 + #address-cells = <1>;
88 + #size-cells = <0>;
89 + status = "okay";
90 +
91 + sgtl5000@0a {
92 + #sound-dai-cells = <0>;
93 + compatible = "fepi,sgtl5000";
94 + reg = <0x0a>;
95 + clocks = <&sgtl5000_mclk>;
96 + micbias-resistor-k-ohms = <2>;
97 + micbias-voltage-m-volts = <3000>;
98 + VDDA-supply = <&vdd_3v3_reg>;
99 + VDDIO-supply = <&vdd_3v3_reg>;
100 + VDDD-supply = <&reg_1v8>;
101 + status = "okay";
102 + };
103 + };
104 + };
105 +
106 + fragment@3 {
107 + target = <&i2s>;
108 + __overlay__ {
109 + status = "okay";
110 + };
111 + };
112 +
113 + fragment@4 {
114 + target = <&sound>;
115 + __overlay__ {
116 + compatible = "fe-pi,fe-pi-audio";
117 + i2s-controller = <&i2s>;
118 + status = "okay";
119 + };
120 + };
121 +};
122 --- a/arch/arm/configs/bcm2709_defconfig
123 +++ b/arch/arm/configs/bcm2709_defconfig
124 @@ -891,6 +891,7 @@ CONFIG_SND_DIGIDAC1_SOUNDCARD=m
125 CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
126 CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2=m
127 CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m
128 +CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO=m
129 CONFIG_SND_PISOUND=m
130 CONFIG_SND_SOC_ADAU1701=m
131 CONFIG_SND_SOC_ADAU7002=m
132 --- a/arch/arm/configs/bcmrpi_defconfig
133 +++ b/arch/arm/configs/bcmrpi_defconfig
134 @@ -885,6 +885,7 @@ CONFIG_SND_DIGIDAC1_SOUNDCARD=m
135 CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
136 CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2=m
137 CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m
138 +CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO=m
139 CONFIG_SND_PISOUND=m
140 CONFIG_SND_SOC_ADAU1701=m
141 CONFIG_SND_SOC_ADAU7002=m
142 --- a/sound/soc/bcm/Kconfig
143 +++ b/sound/soc/bcm/Kconfig
144 @@ -147,6 +147,13 @@ config SND_BCM2708_SOC_ALLO_PIANO_DAC
145 help
146 Say Y or M if you want to add support for Allo Piano DAC.
147
148 +config SND_BCM2708_SOC_FE_PI_AUDIO
149 + tristate "Support for Fe-Pi-Audio"
150 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
151 + select SND_SOC_SGTL5000
152 + help
153 + Say Y or M if you want to add support for Fe-Pi-Audio.
154 +
155 config SND_PISOUND
156 tristate "Support for Blokas Labs pisound"
157 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
158 --- a/sound/soc/bcm/Makefile
159 +++ b/sound/soc/bcm/Makefile
160 @@ -28,6 +28,7 @@ snd-soc-dionaudio-loco-objs := dionaudio
161 snd-soc-dionaudio-loco-v2-objs := dionaudio_loco-v2.o
162 snd-soc-allo-piano-dac-objs := allo-piano-dac.o
163 snd-soc-pisound-objs := pisound.o
164 +snd-soc-fe-pi-audio-objs := fe-pi-audio.o
165
166 obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
167 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
168 @@ -48,3 +49,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_L
169 obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2) += snd-soc-dionaudio-loco-v2.o
170 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
171 obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o
172 +obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o
173 --- /dev/null
174 +++ b/sound/soc/bcm/fe-pi-audio.c
175 @@ -0,0 +1,158 @@
176 +/*
177 + * ASoC Driver for Fe-Pi Audio Sound Card
178 + *
179 + * Author: Henry Kupis <kuupaz@gmail.com>
180 + * Copyright 2016
181 + * based on code by Florian Meier <florian.meier@koalo.de>
182 + * based on code by Shawn Guo <shawn.guo@linaro.org>
183 + *
184 + * This program is free software; you can redistribute it and/or
185 + * modify it under the terms of the GNU General Public License
186 + * version 2 as published by the Free Software Foundation.
187 + *
188 + * This program is distributed in the hope that it will be useful, but
189 + * WITHOUT ANY WARRANTY; without even the implied warranty of
190 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
191 + * General Public License for more details.
192 + */
193 +
194 +#include <linux/module.h>
195 +#include <linux/platform_device.h>
196 +#include <linux/io.h>
197 +
198 +#include <sound/core.h>
199 +#include <sound/pcm.h>
200 +#include <sound/pcm_params.h>
201 +#include <sound/soc.h>
202 +#include <sound/jack.h>
203 +
204 +#include "../codecs/sgtl5000.h"
205 +
206 +static int snd_fe_pi_audio_init(struct snd_soc_pcm_runtime *rtd)
207 +{
208 + struct snd_soc_card *card = rtd->card;
209 + struct snd_soc_codec *codec = rtd->codec;
210 +
211 + snd_soc_dapm_force_enable_pin(&card->dapm, "LO");
212 + snd_soc_dapm_force_enable_pin(&card->dapm, "ADC");
213 + snd_soc_dapm_force_enable_pin(&card->dapm, "DAC");
214 + snd_soc_dapm_force_enable_pin(&card->dapm, "HP");
215 + snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
216 + SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
217 +
218 + return 0;
219 +}
220 +
221 +static int snd_fe_pi_audio_hw_params(struct snd_pcm_substream *substream,
222 + struct snd_pcm_hw_params *params)
223 +{
224 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
225 + struct device *dev = rtd->card->dev;
226 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
227 +
228 + int ret;
229 +
230 + /* Set SGTL5000's SYSCLK */
231 + ret = snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 12288000, SND_SOC_CLOCK_IN);
232 + if (ret) {
233 + dev_err(dev, "could not set codec driver clock params\n");
234 + return ret;
235 + }
236 +
237 + return 0;
238 +}
239 +
240 +
241 +static struct snd_soc_ops snd_fe_pi_audio_ops = {
242 + .hw_params = snd_fe_pi_audio_hw_params,
243 +};
244 +
245 +static struct snd_soc_dai_link snd_fe_pi_audio_dai[] = {
246 + {
247 + .name = "FE-PI",
248 + .stream_name = "Fe-Pi HiFi",
249 + .cpu_dai_name = "bcm2708-i2s.0",
250 + .codec_dai_name = "sgtl5000",
251 + .platform_name = "bcm2708-i2s.0",
252 + .codec_name = "sgtl5000.1-000a",
253 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
254 + SND_SOC_DAIFMT_CBM_CFM,
255 + .ops = &snd_fe_pi_audio_ops,
256 + .init = snd_fe_pi_audio_init,
257 + },
258 +};
259 +
260 +static const struct snd_soc_dapm_route fe_pi_audio_dapm_routes[] = {
261 + {"ADC", NULL, "Mic Bias"},
262 +};
263 +
264 +
265 +static struct snd_soc_card fe_pi_audio = {
266 + .name = "Fe-Pi Audio",
267 + .owner = THIS_MODULE,
268 + .dai_link = snd_fe_pi_audio_dai,
269 + .num_links = ARRAY_SIZE(snd_fe_pi_audio_dai),
270 +
271 + .dapm_routes = fe_pi_audio_dapm_routes,
272 + .num_dapm_routes = ARRAY_SIZE(fe_pi_audio_dapm_routes),
273 +};
274 +
275 +static int snd_fe_pi_audio_probe(struct platform_device *pdev)
276 +{
277 + int ret = 0;
278 + struct snd_soc_card *card = &fe_pi_audio;
279 + struct device_node *np = pdev->dev.of_node;
280 + struct device_node *i2s_node;
281 + struct snd_soc_dai_link *dai = &snd_fe_pi_audio_dai[0];
282 +
283 + fe_pi_audio.dev = &pdev->dev;
284 +
285 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
286 + if (!i2s_node) {
287 + dev_err(&pdev->dev, "i2s_node phandle missing or invalid\n");
288 + return -EINVAL;
289 + }
290 +
291 + dai->cpu_dai_name = NULL;
292 + dai->cpu_of_node = i2s_node;
293 + dai->platform_name = NULL;
294 + dai->platform_of_node = i2s_node;
295 +
296 + of_node_put(i2s_node);
297 +
298 + card->dev = &pdev->dev;
299 + platform_set_drvdata(pdev, card);
300 +
301 + ret = snd_soc_register_card(card);
302 + if (ret && ret != -EPROBE_DEFER)
303 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
304 +
305 + return ret;
306 +}
307 +
308 +static int snd_fe_pi_audio_remove(struct platform_device *pdev)
309 +{
310 + return snd_soc_unregister_card(&fe_pi_audio);
311 +}
312 +
313 +static const struct of_device_id snd_fe_pi_audio_of_match[] = {
314 + { .compatible = "fe-pi,fe-pi-audio", },
315 + {},
316 +};
317 +MODULE_DEVICE_TABLE(of, snd_fe_pi_audio_of_match);
318 +
319 +static struct platform_driver snd_fe_pi_audio_driver = {
320 + .driver = {
321 + .name = "snd-fe-pi-audio",
322 + .owner = THIS_MODULE,
323 + .of_match_table = snd_fe_pi_audio_of_match,
324 + },
325 + .probe = snd_fe_pi_audio_probe,
326 + .remove = snd_fe_pi_audio_remove,
327 +};
328 +
329 +module_platform_driver(snd_fe_pi_audio_driver);
330 +
331 +MODULE_AUTHOR("Henry Kupis <fe-pi@cox.net>");
332 +MODULE_DESCRIPTION("ASoC Driver for Fe-Pi Audio");
333 +MODULE_LICENSE("GPL v2");