brcm2708-gpu-fw: update to latest version
[openwrt/staging/dedeckeh.git] / target / linux / brcm2708 / patches-4.4 / 0419-Add-IQAudIO-Digi-WM8804-board-support.patch
1 From c0b9e2c502269ef126969709f54e4489b87e3923 Mon Sep 17 00:00:00 2001
2 From: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
3 Date: Thu, 30 Jun 2016 18:38:42 +0100
4 Subject: [PATCH 419/423] Add IQAudIO Digi WM8804 board support
5
6 Support IQAudIO Digi board with iqaudio_digi machine driver and
7 iqaudio-digi-wm8804-audio overlay.
8
9 NB. Machine driver is a cut and paste of hifiberry_digi code, with format
10 and general cleanup to comply with kernel coding standards.
11
12 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
13 ---
14 arch/arm/boot/dts/overlays/Makefile | 1 +
15 arch/arm/boot/dts/overlays/README | 9 +
16 .../overlays/iqaudio-digi-wm8804-audio-overlay.dts | 47 ++++
17 arch/arm/configs/bcm2709_defconfig | 1 +
18 arch/arm/configs/bcmrpi_defconfig | 1 +
19 sound/soc/bcm/Kconfig | 7 +
20 sound/soc/bcm/Makefile | 2 +
21 sound/soc/bcm/iqaudio_digi.c | 239 +++++++++++++++++++++
22 8 files changed, 307 insertions(+)
23 create mode 100644 arch/arm/boot/dts/overlays/iqaudio-digi-wm8804-audio-overlay.dts
24 create mode 100644 sound/soc/bcm/iqaudio_digi.c
25
26 --- a/arch/arm/boot/dts/overlays/Makefile
27 +++ b/arch/arm/boot/dts/overlays/Makefile
28 @@ -42,6 +42,7 @@ dtbo-$(RPI_DT_OVERLAYS) += i2s-gpio28-31
29 dtbo-$(RPI_DT_OVERLAYS) += i2s-mmap.dtbo
30 dtbo-$(RPI_DT_OVERLAYS) += iqaudio-dac.dtbo
31 dtbo-$(RPI_DT_OVERLAYS) += iqaudio-dacplus.dtbo
32 +dtbo-$(RPI_DT_OVERLAYS) += iqaudio-digi-wm8804-audio.dtbo
33 dtbo-$(RPI_DT_OVERLAYS) += justboom-dac.dtbo
34 dtbo-$(RPI_DT_OVERLAYS) += justboom-digi.dtbo
35 dtbo-$(RPI_DT_OVERLAYS) += lirc-rpi.dtbo
36 --- a/arch/arm/boot/dts/overlays/README
37 +++ b/arch/arm/boot/dts/overlays/README
38 @@ -546,6 +546,15 @@ Params: 24db_digital_gain Allow ga
39 the DAC driver module loads.
40
41
42 +Name: iqaudio-digi-wm8804-audio
43 +Info: Configures the IQAudIO Digi WM8804 audio card
44 +Load: dtoverlay=iqaudio-digi-wm8804-audio,<param>=<val>
45 +Params: card_name Override the default, "IQAudIODigi", card name.
46 + dai_name Override the default, "IQAudIO Digi", dai name.
47 + dai_stream_name Override the default, "IQAudIO Digi HiFi",
48 + dai stream name.
49 +
50 +
51 Name: justboom-dac
52 Info: Configures the JustBoom DAC HAT, Amp HAT, DAC Zero and Amp Zero audio
53 cards
54 --- /dev/null
55 +++ b/arch/arm/boot/dts/overlays/iqaudio-digi-wm8804-audio-overlay.dts
56 @@ -0,0 +1,47 @@
57 +// Definitions for IQAudIO Digi WM8804 audio board
58 +/dts-v1/;
59 +/plugin/;
60 +
61 +/ {
62 + compatible = "brcm,bcm2708";
63 +
64 + fragment@0 {
65 + target = <&i2s>;
66 + __overlay__ {
67 + status = "okay";
68 + };
69 + };
70 +
71 + fragment@1 {
72 + target = <&i2c1>;
73 + __overlay__ {
74 + #address-cells = <1>;
75 + #size-cells = <0>;
76 + status = "okay";
77 +
78 + wm8804@3b {
79 + #sound-dai-cells = <0>;
80 + compatible = "wlf,wm8804";
81 + reg = <0x3b>;
82 + status = "okay";
83 + // DVDD-supply = <&reg_3v3>;
84 + // PVDD-supply = <&reg_3v3>;
85 + };
86 + };
87 + };
88 +
89 + fragment@2 {
90 + target = <&sound>;
91 + wm8804_digi: __overlay__ {
92 + compatible = "iqaudio,wm8804-digi";
93 + i2s-controller = <&i2s>;
94 + status = "okay";
95 + };
96 + };
97 +
98 + __overrides__ {
99 + card_name = <&wm8804_digi>,"wm8804-digi,card-name";
100 + dai_name = <&wm8804_digi>,"wm8804-digi,dai-name";
101 + dai_stream_name = <&wm8804_digi>,"wm8804-digi,dai-stream-name";
102 + };
103 +};
104 --- a/arch/arm/configs/bcm2709_defconfig
105 +++ b/arch/arm/configs/bcm2709_defconfig
106 @@ -865,6 +865,7 @@ CONFIG_SND_BCM2708_SOC_RPI_PROTO=m
107 CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC=m
108 CONFIG_SND_BCM2708_SOC_JUSTBOOM_DIGI=m
109 CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
110 +CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI=m
111 CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
112 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
113 CONFIG_SND_DIGIDAC1_SOUNDCARD=m
114 --- a/arch/arm/configs/bcmrpi_defconfig
115 +++ b/arch/arm/configs/bcmrpi_defconfig
116 @@ -857,6 +857,7 @@ CONFIG_SND_BCM2708_SOC_RPI_PROTO=m
117 CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC=m
118 CONFIG_SND_BCM2708_SOC_JUSTBOOM_DIGI=m
119 CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
120 +CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI=m
121 CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
122 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
123 CONFIG_SND_DIGIDAC1_SOUNDCARD=m
124 --- a/sound/soc/bcm/Kconfig
125 +++ b/sound/soc/bcm/Kconfig
126 @@ -71,6 +71,13 @@ config SND_BCM2708_SOC_IQAUDIO_DAC
127 help
128 Say Y or M if you want to add support for IQaudIO-DAC.
129
130 +config SND_BCM2708_SOC_IQAUDIO_DIGI
131 + tristate "Support for IQAudIO Digi"
132 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
133 + select SND_SOC_WM8804
134 + help
135 + Say Y or M if you want to add support for IQAudIO Digital IO board.
136 +
137 config SND_BCM2708_SOC_RASPIDAC3
138 tristate "Support for RaspiDAC Rev.3x"
139 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
140 --- a/sound/soc/bcm/Makefile
141 +++ b/sound/soc/bcm/Makefile
142 @@ -14,6 +14,7 @@ snd-soc-justboom-digi-objs := justboom-d
143 snd-soc-rpi-dac-objs := rpi-dac.o
144 snd-soc-rpi-proto-objs := rpi-proto.o
145 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
146 +snd-soc-iqaudio-digi-objs := iqaudio_digi.o
147 snd-soc-raspidac3-objs := raspidac3.o
148 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
149 snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
150 @@ -28,6 +29,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DI
151 obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
152 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
153 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
154 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI) += snd-soc-iqaudio-digi.o
155 obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
156 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
157 obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
158 --- /dev/null
159 +++ b/sound/soc/bcm/iqaudio_digi.c
160 @@ -0,0 +1,239 @@
161 +/*
162 + * ASoC Driver for IQAudIO WM8804 Digi
163 + *
164 + * Author: Daniel Matuschek <info@crazy-audio.com>
165 + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
166 + * Copyright 2013
167 + *
168 + * This program is free software; you can redistribute it and/or
169 + * modify it under the terms of the GNU General Public License
170 + * version 2 as published by the Free Software Foundation.
171 + *
172 + * This program is distributed in the hope that it will be useful, but
173 + * WITHOUT ANY WARRANTY; without even the implied warranty of
174 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
175 + * General Public License for more details.
176 + */
177 +
178 +#include <linux/module.h>
179 +#include <linux/platform_device.h>
180 +
181 +#include <sound/core.h>
182 +#include <sound/pcm.h>
183 +#include <sound/pcm_params.h>
184 +#include <sound/soc.h>
185 +#include <sound/jack.h>
186 +
187 +#include "../codecs/wm8804.h"
188 +
189 +static short int auto_shutdown_output;
190 +module_param(auto_shutdown_output, short,
191 + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
192 +MODULE_PARM_DESC(auto_shutdown_output, "Shutdown SP/DIF output if playback is stopped");
193 +
194 +static int snd_rpi_iqaudio_digi_init(struct snd_soc_pcm_runtime *rtd)
195 +{
196 + struct snd_soc_codec *codec = rtd->codec;
197 +
198 + /* enable TX output */
199 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
200 +
201 + return 0;
202 +}
203 +
204 +static int snd_rpi_iqaudio_digi_startup(struct snd_pcm_substream *substream)
205 +{
206 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
207 + struct snd_soc_codec *codec = rtd->codec;
208 +
209 + /* turn on digital output */
210 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
211 +
212 + return 0;
213 +}
214 +
215 +static void snd_rpi_iqaudio_digi_shutdown(struct snd_pcm_substream *substream)
216 +{
217 + if (auto_shutdown_output) {
218 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
219 + struct snd_soc_codec *codec = rtd->codec;
220 +
221 + /* turn off digital output */
222 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
223 + }
224 +}
225 +
226 +
227 +static int snd_rpi_iqaudio_digi_hw_params(struct snd_pcm_substream *substream,
228 + struct snd_pcm_hw_params *params)
229 +{
230 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
231 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
232 + struct snd_soc_codec *codec = rtd->codec;
233 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
234 +
235 + int sysclk = 27000000; /* This is fixed on this board */
236 +
237 + long mclk_freq = 0;
238 + int mclk_div = 1;
239 + int sampling_freq = 1;
240 +
241 + int ret;
242 +
243 + int samplerate = params_rate(params);
244 +
245 + if (samplerate <= 96000) {
246 + mclk_freq = samplerate * 256;
247 + mclk_div = WM8804_MCLKDIV_256FS;
248 + } else {
249 + mclk_freq = samplerate * 128;
250 + mclk_div = WM8804_MCLKDIV_128FS;
251 + }
252 +
253 + switch (samplerate) {
254 + case 32000:
255 + sampling_freq = 0x03;
256 + break;
257 + case 44100:
258 + sampling_freq = 0x00;
259 + break;
260 + case 48000:
261 + sampling_freq = 0x02;
262 + break;
263 + case 88200:
264 + sampling_freq = 0x08;
265 + break;
266 + case 96000:
267 + sampling_freq = 0x0a;
268 + break;
269 + case 176400:
270 + sampling_freq = 0x0c;
271 + break;
272 + case 192000:
273 + sampling_freq = 0x0e;
274 + break;
275 + default:
276 + dev_err(codec->dev, "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
277 + samplerate);
278 + }
279 +
280 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
281 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
282 +
283 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
284 + sysclk, SND_SOC_CLOCK_OUT);
285 + if (ret < 0) {
286 + dev_err(codec->dev, "Failed to set WM8804 SYSCLK: %d\n", ret);
287 + return ret;
288 + }
289 +
290 + /* Enable TX output */
291 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
292 +
293 + /* Power on */
294 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
295 +
296 + /* set sampling frequency status bits */
297 + snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
298 +
299 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
300 +}
301 +
302 +/* machine stream operations */
303 +static struct snd_soc_ops snd_rpi_iqaudio_digi_ops = {
304 + .hw_params = snd_rpi_iqaudio_digi_hw_params,
305 + .startup = snd_rpi_iqaudio_digi_startup,
306 + .shutdown = snd_rpi_iqaudio_digi_shutdown,
307 +};
308 +
309 +static struct snd_soc_dai_link snd_rpi_iqaudio_digi_dai[] = {
310 +{
311 + .name = "IQAudIO Digi",
312 + .stream_name = "IQAudIO Digi HiFi",
313 + .cpu_dai_name = "bcm2708-i2s.0",
314 + .codec_dai_name = "wm8804-spdif",
315 + .platform_name = "bcm2708-i2s.0",
316 + .codec_name = "wm8804.1-003b",
317 + .dai_fmt = SND_SOC_DAIFMT_I2S |
318 + SND_SOC_DAIFMT_NB_NF |
319 + SND_SOC_DAIFMT_CBM_CFM,
320 + .ops = &snd_rpi_iqaudio_digi_ops,
321 + .init = snd_rpi_iqaudio_digi_init,
322 +},
323 +};
324 +
325 +/* audio machine driver */
326 +static struct snd_soc_card snd_rpi_iqaudio_digi = {
327 + .name = "IQAudIODigi",
328 + .owner = THIS_MODULE,
329 + .dai_link = snd_rpi_iqaudio_digi_dai,
330 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_digi_dai),
331 +};
332 +
333 +static int snd_rpi_iqaudio_digi_probe(struct platform_device *pdev)
334 +{
335 + struct snd_soc_card *card = &snd_rpi_iqaudio_digi;
336 + char *prefix = "wm8804-digi,";
337 + char prop[128];
338 + struct device_node *np;
339 + int ret = 0;
340 +
341 + snd_rpi_iqaudio_digi.dev = &pdev->dev;
342 +
343 + np = pdev->dev.of_node;
344 + if (np) {
345 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_digi_dai[0];
346 + struct device_node *i2s_node;
347 +
348 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
349 + if (i2s_node) {
350 + dai->cpu_dai_name = NULL;
351 + dai->cpu_of_node = i2s_node;
352 + dai->platform_name = NULL;
353 + dai->platform_of_node = i2s_node;
354 + }
355 +
356 + snprintf(prop, sizeof(prop), "%scard-name", prefix);
357 + of_property_read_string(np, prop, &card->name);
358 +
359 + snprintf(prop, sizeof(prop), "%sdai-name", prefix);
360 + of_property_read_string(np, prop, &dai->name);
361 +
362 + snprintf(prop, sizeof(prop), "%sdai-stream-name", prefix);
363 + of_property_read_string(np, prop, &dai->stream_name);
364 + }
365 +
366 + ret = snd_soc_register_card(card);
367 + if (ret)
368 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
369 + ret);
370 +
371 + return ret;
372 +}
373 +
374 +static int snd_rpi_iqaudio_digi_remove(struct platform_device *pdev)
375 +{
376 + return snd_soc_unregister_card(&snd_rpi_iqaudio_digi);
377 +}
378 +
379 +static const struct of_device_id snd_rpi_iqaudio_digi_of_match[] = {
380 + { .compatible = "iqaudio,wm8804-digi", },
381 + {},
382 +};
383 +MODULE_DEVICE_TABLE(of, snd_rpi_iqaudio_digi_of_match);
384 +
385 +static struct platform_driver snd_rpi_iqaudio_digi_driver = {
386 + .driver = {
387 + .name = "IQAudIODigi",
388 + .owner = THIS_MODULE,
389 + .of_match_table = snd_rpi_iqaudio_digi_of_match,
390 + },
391 + .probe = snd_rpi_iqaudio_digi_probe,
392 + .remove = snd_rpi_iqaudio_digi_remove,
393 +};
394 +
395 +module_platform_driver(snd_rpi_iqaudio_digi_driver);
396 +
397 +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
398 +MODULE_DESCRIPTION("ASoC Driver for IQAudIO WM8804 Digi");
399 +MODULE_LICENSE("GPL v2");