kernel: update kernel 4.4 to 4.4.52
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.9 / 0081-Add-IQAudIO-Digi-WM8804-board-support.patch
1 From 1b18f3be9f034c2e9aefab9b97c5100d5f914a89 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] 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 sound/soc/bcm/Kconfig | 7 ++
15 sound/soc/bcm/Makefile | 2 +
16 sound/soc/bcm/iqaudio_digi.c | 239 +++++++++++++++++++++++++++++++++++++++++++
17 3 files changed, 248 insertions(+)
18 create mode 100644 sound/soc/bcm/iqaudio_digi.c
19
20 --- a/sound/soc/bcm/Kconfig
21 +++ b/sound/soc/bcm/Kconfig
22 @@ -73,6 +73,13 @@ config SND_BCM2708_SOC_IQAUDIO_DAC
23 help
24 Say Y or M if you want to add support for IQaudIO-DAC.
25
26 +config SND_BCM2708_SOC_IQAUDIO_DIGI
27 + tristate "Support for IQAudIO Digi"
28 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
29 + select SND_SOC_WM8804
30 + help
31 + Say Y or M if you want to add support for IQAudIO Digital IO board.
32 +
33 config SND_BCM2708_SOC_RASPIDAC3
34 tristate "Support for RaspiDAC Rev.3x"
35 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
36 --- a/sound/soc/bcm/Makefile
37 +++ b/sound/soc/bcm/Makefile
38 @@ -18,6 +18,7 @@ snd-soc-justboom-digi-objs := justboom-d
39 snd-soc-rpi-dac-objs := rpi-dac.o
40 snd-soc-rpi-proto-objs := rpi-proto.o
41 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
42 +snd-soc-iqaudio-digi-objs := iqaudio_digi.o
43 snd-soc-raspidac3-objs := raspidac3.o
44 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
45
46 @@ -30,6 +31,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DI
47 obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
48 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
49 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
50 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI) += snd-soc-iqaudio-digi.o
51 obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
52 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
53
54 --- /dev/null
55 +++ b/sound/soc/bcm/iqaudio_digi.c
56 @@ -0,0 +1,239 @@
57 +/*
58 + * ASoC Driver for IQAudIO WM8804 Digi
59 + *
60 + * Author: Daniel Matuschek <info@crazy-audio.com>
61 + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
62 + * Copyright 2013
63 + *
64 + * This program is free software; you can redistribute it and/or
65 + * modify it under the terms of the GNU General Public License
66 + * version 2 as published by the Free Software Foundation.
67 + *
68 + * This program is distributed in the hope that it will be useful, but
69 + * WITHOUT ANY WARRANTY; without even the implied warranty of
70 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
71 + * General Public License for more details.
72 + */
73 +
74 +#include <linux/module.h>
75 +#include <linux/platform_device.h>
76 +
77 +#include <sound/core.h>
78 +#include <sound/pcm.h>
79 +#include <sound/pcm_params.h>
80 +#include <sound/soc.h>
81 +#include <sound/jack.h>
82 +
83 +#include "../codecs/wm8804.h"
84 +
85 +static short int auto_shutdown_output;
86 +module_param(auto_shutdown_output, short,
87 + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
88 +MODULE_PARM_DESC(auto_shutdown_output, "Shutdown SP/DIF output if playback is stopped");
89 +
90 +static int snd_rpi_iqaudio_digi_init(struct snd_soc_pcm_runtime *rtd)
91 +{
92 + struct snd_soc_codec *codec = rtd->codec;
93 +
94 + /* enable TX output */
95 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
96 +
97 + return 0;
98 +}
99 +
100 +static int snd_rpi_iqaudio_digi_startup(struct snd_pcm_substream *substream)
101 +{
102 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
103 + struct snd_soc_codec *codec = rtd->codec;
104 +
105 + /* turn on digital output */
106 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
107 +
108 + return 0;
109 +}
110 +
111 +static void snd_rpi_iqaudio_digi_shutdown(struct snd_pcm_substream *substream)
112 +{
113 + if (auto_shutdown_output) {
114 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
115 + struct snd_soc_codec *codec = rtd->codec;
116 +
117 + /* turn off digital output */
118 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
119 + }
120 +}
121 +
122 +
123 +static int snd_rpi_iqaudio_digi_hw_params(struct snd_pcm_substream *substream,
124 + struct snd_pcm_hw_params *params)
125 +{
126 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
127 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
128 + struct snd_soc_codec *codec = rtd->codec;
129 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
130 +
131 + int sysclk = 27000000; /* This is fixed on this board */
132 +
133 + long mclk_freq = 0;
134 + int mclk_div = 1;
135 + int sampling_freq = 1;
136 +
137 + int ret;
138 +
139 + int samplerate = params_rate(params);
140 +
141 + if (samplerate <= 96000) {
142 + mclk_freq = samplerate * 256;
143 + mclk_div = WM8804_MCLKDIV_256FS;
144 + } else {
145 + mclk_freq = samplerate * 128;
146 + mclk_div = WM8804_MCLKDIV_128FS;
147 + }
148 +
149 + switch (samplerate) {
150 + case 32000:
151 + sampling_freq = 0x03;
152 + break;
153 + case 44100:
154 + sampling_freq = 0x00;
155 + break;
156 + case 48000:
157 + sampling_freq = 0x02;
158 + break;
159 + case 88200:
160 + sampling_freq = 0x08;
161 + break;
162 + case 96000:
163 + sampling_freq = 0x0a;
164 + break;
165 + case 176400:
166 + sampling_freq = 0x0c;
167 + break;
168 + case 192000:
169 + sampling_freq = 0x0e;
170 + break;
171 + default:
172 + dev_err(codec->dev, "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
173 + samplerate);
174 + }
175 +
176 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
177 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
178 +
179 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
180 + sysclk, SND_SOC_CLOCK_OUT);
181 + if (ret < 0) {
182 + dev_err(codec->dev, "Failed to set WM8804 SYSCLK: %d\n", ret);
183 + return ret;
184 + }
185 +
186 + /* Enable TX output */
187 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
188 +
189 + /* Power on */
190 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
191 +
192 + /* set sampling frequency status bits */
193 + snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
194 +
195 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
196 +}
197 +
198 +/* machine stream operations */
199 +static struct snd_soc_ops snd_rpi_iqaudio_digi_ops = {
200 + .hw_params = snd_rpi_iqaudio_digi_hw_params,
201 + .startup = snd_rpi_iqaudio_digi_startup,
202 + .shutdown = snd_rpi_iqaudio_digi_shutdown,
203 +};
204 +
205 +static struct snd_soc_dai_link snd_rpi_iqaudio_digi_dai[] = {
206 +{
207 + .name = "IQAudIO Digi",
208 + .stream_name = "IQAudIO Digi HiFi",
209 + .cpu_dai_name = "bcm2708-i2s.0",
210 + .codec_dai_name = "wm8804-spdif",
211 + .platform_name = "bcm2708-i2s.0",
212 + .codec_name = "wm8804.1-003b",
213 + .dai_fmt = SND_SOC_DAIFMT_I2S |
214 + SND_SOC_DAIFMT_NB_NF |
215 + SND_SOC_DAIFMT_CBM_CFM,
216 + .ops = &snd_rpi_iqaudio_digi_ops,
217 + .init = snd_rpi_iqaudio_digi_init,
218 +},
219 +};
220 +
221 +/* audio machine driver */
222 +static struct snd_soc_card snd_rpi_iqaudio_digi = {
223 + .name = "IQAudIODigi",
224 + .owner = THIS_MODULE,
225 + .dai_link = snd_rpi_iqaudio_digi_dai,
226 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_digi_dai),
227 +};
228 +
229 +static int snd_rpi_iqaudio_digi_probe(struct platform_device *pdev)
230 +{
231 + struct snd_soc_card *card = &snd_rpi_iqaudio_digi;
232 + char *prefix = "wm8804-digi,";
233 + char prop[128];
234 + struct device_node *np;
235 + int ret = 0;
236 +
237 + snd_rpi_iqaudio_digi.dev = &pdev->dev;
238 +
239 + np = pdev->dev.of_node;
240 + if (np) {
241 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_digi_dai[0];
242 + struct device_node *i2s_node;
243 +
244 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
245 + if (i2s_node) {
246 + dai->cpu_dai_name = NULL;
247 + dai->cpu_of_node = i2s_node;
248 + dai->platform_name = NULL;
249 + dai->platform_of_node = i2s_node;
250 + }
251 +
252 + snprintf(prop, sizeof(prop), "%scard-name", prefix);
253 + of_property_read_string(np, prop, &card->name);
254 +
255 + snprintf(prop, sizeof(prop), "%sdai-name", prefix);
256 + of_property_read_string(np, prop, &dai->name);
257 +
258 + snprintf(prop, sizeof(prop), "%sdai-stream-name", prefix);
259 + of_property_read_string(np, prop, &dai->stream_name);
260 + }
261 +
262 + ret = snd_soc_register_card(card);
263 + if (ret)
264 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
265 + ret);
266 +
267 + return ret;
268 +}
269 +
270 +static int snd_rpi_iqaudio_digi_remove(struct platform_device *pdev)
271 +{
272 + return snd_soc_unregister_card(&snd_rpi_iqaudio_digi);
273 +}
274 +
275 +static const struct of_device_id snd_rpi_iqaudio_digi_of_match[] = {
276 + { .compatible = "iqaudio,wm8804-digi", },
277 + {},
278 +};
279 +MODULE_DEVICE_TABLE(of, snd_rpi_iqaudio_digi_of_match);
280 +
281 +static struct platform_driver snd_rpi_iqaudio_digi_driver = {
282 + .driver = {
283 + .name = "IQAudIODigi",
284 + .owner = THIS_MODULE,
285 + .of_match_table = snd_rpi_iqaudio_digi_of_match,
286 + },
287 + .probe = snd_rpi_iqaudio_digi_probe,
288 + .remove = snd_rpi_iqaudio_digi_remove,
289 +};
290 +
291 +module_platform_driver(snd_rpi_iqaudio_digi_driver);
292 +
293 +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
294 +MODULE_DESCRIPTION("ASoC Driver for IQAudIO WM8804 Digi");
295 +MODULE_LICENSE("GPL v2");