lantiq: fix broadcasts and vlans in two iface mode
[oweals/openwrt.git] / target / linux / brcm2708 / patches-4.9 / 0077-Add-Support-for-JustBoom-Audio-boards.patch
1 From 4a8ebf575ea143c14fd815ecd1f5398b6a6aee67 Mon Sep 17 00:00:00 2001
2 From: Aaron Shaw <shawaj@gmail.com>
3 Date: Thu, 7 Apr 2016 21:26:21 +0100
4 Subject: [PATCH] Add Support for JustBoom Audio boards
5
6 justboom-dac: Adjust for ALSA API change
7
8 As of 4.4, snd_soc_limit_volume now takes a struct snd_soc_card *
9 rather than a struct snd_soc_codec *.
10
11 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
12 ---
13  sound/soc/bcm/Kconfig         |  14 +++
14  sound/soc/bcm/Makefile        |   4 +
15  sound/soc/bcm/justboom-dac.c  | 162 +++++++++++++++++++++++++++++++
16  sound/soc/bcm/justboom-digi.c | 215 ++++++++++++++++++++++++++++++++++++++++++
17  4 files changed, 395 insertions(+)
18  create mode 100644 sound/soc/bcm/justboom-dac.c
19  create mode 100644 sound/soc/bcm/justboom-digi.c
20
21 --- a/sound/soc/bcm/Kconfig
22 +++ b/sound/soc/bcm/Kconfig
23 @@ -59,6 +59,20 @@ config SND_BCM2708_SOC_RPI_PROTO
24         help
25           Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
26  
27 +config SND_BCM2708_SOC_JUSTBOOM_DAC
28 +       tristate "Support for JustBoom DAC"
29 +       depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
30 +       select SND_SOC_PCM512x
31 +       help
32 +         Say Y or M if you want to add support for JustBoom DAC.
33 +
34 +config SND_BCM2708_SOC_JUSTBOOM_DIGI
35 +       tristate "Support for JustBoom Digi"
36 +       depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
37 +       select SND_SOC_WM8804
38 +       help
39 +         Say Y or M if you want to add support for JustBoom Digi.
40 +
41  config SND_BCM2708_SOC_IQAUDIO_DAC
42         tristate "Support for IQaudIO-DAC"
43         depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
44 --- a/sound/soc/bcm/Makefile
45 +++ b/sound/soc/bcm/Makefile
46 @@ -13,6 +13,8 @@ snd-soc-hifiberry-amp-objs := hifiberry_
47  snd-soc-hifiberry-dac-objs := hifiberry_dac.o
48  snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
49  snd-soc-hifiberry-digi-objs := hifiberry_digi.o
50 +snd-soc-justboom-dac-objs := justboom-dac.o
51 +snd-soc-justboom-digi-objs := justboom-digi.o
52  snd-soc-rpi-dac-objs := rpi-dac.o
53  snd-soc-rpi-proto-objs := rpi-proto.o
54  snd-soc-iqaudio-dac-objs := iqaudio-dac.o
55 @@ -22,6 +24,8 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_A
56  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
57  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
58  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
59 +obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
60 +obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DIGI) += snd-soc-justboom-digi.o
61  obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
62  obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
63  obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
64 --- /dev/null
65 +++ b/sound/soc/bcm/justboom-dac.c
66 @@ -0,0 +1,162 @@
67 +/*
68 + * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
69 + *
70 + * Author:     Milan Neskovic
71 + *             Copyright 2016
72 + *             based on code by Daniel Matuschek <info@crazy-audio.com>
73 + *             based on code by Florian Meier <florian.meier@koalo.de>
74 + *
75 + * This program is free software; you can redistribute it and/or
76 + * modify it under the terms of the GNU General Public License
77 + * version 2 as published by the Free Software Foundation.
78 + *
79 + * This program is distributed in the hope that it will be useful, but
80 + * WITHOUT ANY WARRANTY; without even the implied warranty of
81 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
82 + * General Public License for more details.
83 + */
84 +
85 +#include <linux/module.h>
86 +#include <linux/platform_device.h>
87 +
88 +#include <sound/core.h>
89 +#include <sound/pcm.h>
90 +#include <sound/pcm_params.h>
91 +#include <sound/soc.h>
92 +#include <sound/jack.h>
93 +
94 +#include "../codecs/pcm512x.h"
95 +
96 +static bool digital_gain_0db_limit = true;
97 +
98 +static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
99 +{
100 +       struct snd_soc_codec *codec = rtd->codec;
101 +       snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
102 +       snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
103 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
104 +
105 +       if (digital_gain_0db_limit)
106 +       {
107 +               int ret;
108 +               struct snd_soc_card *card = rtd->card;
109 +
110 +               ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
111 +               if (ret < 0)
112 +                       dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
113 +       }
114 +
115 +       return 0;
116 +}
117 +
118 +static int snd_rpi_justboom_dac_hw_params(struct snd_pcm_substream *substream,
119 +                                      struct snd_pcm_hw_params *params)
120 +{
121 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
122 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
123 +       /*return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);*/
124 +       unsigned int sample_bits =
125 +               snd_pcm_format_physical_width(params_format(params));
126 +       return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
127 +}
128 +
129 +static int snd_rpi_justboom_dac_startup(struct snd_pcm_substream *substream) {
130 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
131 +       struct snd_soc_codec *codec = rtd->codec;
132 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
133 +       return 0;
134 +}
135 +
136 +static void snd_rpi_justboom_dac_shutdown(struct snd_pcm_substream *substream) {
137 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
138 +       struct snd_soc_codec *codec = rtd->codec;
139 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
140 +}
141 +
142 +/* machine stream operations */
143 +static struct snd_soc_ops snd_rpi_justboom_dac_ops = {
144 +       .hw_params = snd_rpi_justboom_dac_hw_params,
145 +       .startup = snd_rpi_justboom_dac_startup,
146 +       .shutdown = snd_rpi_justboom_dac_shutdown,
147 +};
148 +
149 +static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
150 +{
151 +       .name           = "JustBoom DAC",
152 +       .stream_name    = "JustBoom DAC HiFi",
153 +       .cpu_dai_name   = "bcm2708-i2s.0",
154 +       .codec_dai_name = "pcm512x-hifi",
155 +       .platform_name  = "bcm2708-i2s.0",
156 +       .codec_name     = "pcm512x.1-004d",
157 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
158 +                               SND_SOC_DAIFMT_CBS_CFS,
159 +       .ops            = &snd_rpi_justboom_dac_ops,
160 +       .init           = snd_rpi_justboom_dac_init,
161 +},
162 +};
163 +
164 +/* audio machine driver */
165 +static struct snd_soc_card snd_rpi_justboom_dac = {
166 +       .name         = "snd_rpi_justboom_dac",
167 +       .owner        = THIS_MODULE,
168 +       .dai_link     = snd_rpi_justboom_dac_dai,
169 +       .num_links    = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
170 +};
171 +
172 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
173 +{
174 +       int ret = 0;
175 +
176 +       snd_rpi_justboom_dac.dev = &pdev->dev;
177 +
178 +       if (pdev->dev.of_node) {
179 +           struct device_node *i2s_node;
180 +           struct snd_soc_dai_link *dai = &snd_rpi_justboom_dac_dai[0];
181 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
182 +                                       "i2s-controller", 0);
183 +
184 +           if (i2s_node) {
185 +                       dai->cpu_dai_name = NULL;
186 +                       dai->cpu_of_node = i2s_node;
187 +                       dai->platform_name = NULL;
188 +                       dai->platform_of_node = i2s_node;
189 +           }
190 +
191 +           digital_gain_0db_limit = !of_property_read_bool(
192 +                       pdev->dev.of_node, "justboom,24db_digital_gain");
193 +       }
194 +
195 +       ret = snd_soc_register_card(&snd_rpi_justboom_dac);
196 +       if (ret)
197 +               dev_err(&pdev->dev,
198 +                       "snd_soc_register_card() failed: %d\n", ret);
199 +
200 +       return ret;
201 +}
202 +
203 +static int snd_rpi_justboom_dac_remove(struct platform_device *pdev)
204 +{
205 +       return snd_soc_unregister_card(&snd_rpi_justboom_dac);
206 +}
207 +
208 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
209 +       { .compatible = "justboom,justboom-dac", },
210 +       {},
211 +};
212 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
213 +
214 +static struct platform_driver snd_rpi_justboom_dac_driver = {
215 +       .driver = {
216 +               .name   = "snd-rpi-justboom-dac",
217 +               .owner  = THIS_MODULE,
218 +               .of_match_table = snd_rpi_justboom_dac_of_match,
219 +       },
220 +       .probe          = snd_rpi_justboom_dac_probe,
221 +       .remove         = snd_rpi_justboom_dac_remove,
222 +};
223 +
224 +module_platform_driver(snd_rpi_justboom_dac_driver);
225 +
226 +MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
227 +MODULE_DESCRIPTION("ASoC Driver for JustBoom PI DAC HAT Sound Card");
228 +MODULE_LICENSE("GPL v2");
229 --- /dev/null
230 +++ b/sound/soc/bcm/justboom-digi.c
231 @@ -0,0 +1,215 @@
232 +/*
233 + * ASoC Driver for JustBoom Raspberry Pi Digi HAT Sound Card
234 + *
235 + * Author:     Milan Neskovic
236 + *             Copyright 2016
237 + *             based on code by Daniel Matuschek <info@crazy-audio.com>
238 + *             based on code by Florian Meier <florian.meier@koalo.de>
239 + *
240 + * This program is free software; you can redistribute it and/or
241 + * modify it under the terms of the GNU General Public License
242 + * version 2 as published by the Free Software Foundation.
243 + *
244 + * This program is distributed in the hope that it will be useful, but
245 + * WITHOUT ANY WARRANTY; without even the implied warranty of
246 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
247 + * General Public License for more details.
248 + */
249 +
250 +#include <linux/module.h>
251 +#include <linux/platform_device.h>
252 +
253 +#include <sound/core.h>
254 +#include <sound/pcm.h>
255 +#include <sound/pcm_params.h>
256 +#include <sound/soc.h>
257 +#include <sound/jack.h>
258 +
259 +#include "../codecs/wm8804.h"
260 +
261 +static int snd_rpi_justboom_digi_init(struct snd_soc_pcm_runtime *rtd)
262 +{
263 +       struct snd_soc_codec *codec = rtd->codec;
264 +
265 +       /* enable TX output */
266 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
267 +
268 +       return 0;
269 +}
270 +
271 +static int snd_rpi_justboom_digi_startup(struct snd_pcm_substream *substream) {
272 +       /* turn on digital output */
273 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
274 +       struct snd_soc_codec *codec = rtd->codec;
275 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
276 +       return 0;
277 +}
278 +
279 +static void snd_rpi_justboom_digi_shutdown(struct snd_pcm_substream *substream) {
280 +       /* turn off output */
281 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
282 +       struct snd_soc_codec *codec = rtd->codec;
283 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
284 +}
285 +
286 +static int snd_rpi_justboom_digi_hw_params(struct snd_pcm_substream *substream,
287 +                                      struct snd_pcm_hw_params *params)
288 +{
289 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
290 +       struct snd_soc_dai *codec_dai = rtd->codec_dai;
291 +       struct snd_soc_codec *codec = rtd->codec;
292 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
293 +
294 +       int sysclk = 27000000; /* This is fixed on this board */
295 +
296 +       long mclk_freq=0;
297 +       int mclk_div=1;
298 +       int sampling_freq=1;
299 +
300 +       int ret;
301 +
302 +       int samplerate = params_rate(params);
303 +
304 +       if (samplerate<=96000) {
305 +               mclk_freq=samplerate*256;
306 +               mclk_div=WM8804_MCLKDIV_256FS;
307 +       } else {
308 +               mclk_freq=samplerate*128;
309 +               mclk_div=WM8804_MCLKDIV_128FS;
310 +       }
311 +
312 +       switch (samplerate) {
313 +               case 32000:
314 +                       sampling_freq=0x03;
315 +                       break;
316 +               case 44100:
317 +                       sampling_freq=0x00;
318 +                       break;
319 +               case 48000:
320 +                       sampling_freq=0x02;
321 +                       break;
322 +               case 88200:
323 +                       sampling_freq=0x08;
324 +                       break;
325 +               case 96000:
326 +                       sampling_freq=0x0a;
327 +                       break;
328 +               case 176400:
329 +                       sampling_freq=0x0c;
330 +                       break;
331 +               case 192000:
332 +                       sampling_freq=0x0e;
333 +                       break;
334 +               default:
335 +                       dev_err(codec->dev,
336 +                       "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
337 +                       samplerate);
338 +       }
339 +
340 +       snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
341 +       snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
342 +
343 +       ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
344 +                                       sysclk, SND_SOC_CLOCK_OUT);
345 +       if (ret < 0) {
346 +               dev_err(codec->dev,
347 +               "Failed to set WM8804 SYSCLK: %d\n", ret);
348 +               return ret;
349 +       }
350 +
351 +       /* Enable TX output */
352 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
353 +
354 +       /* Power on */
355 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
356 +
357 +       /* set sampling frequency status bits */
358 +       snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
359 +
360 +       return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
361 +}
362 +
363 +/* machine stream operations */
364 +static struct snd_soc_ops snd_rpi_justboom_digi_ops = {
365 +       .hw_params = snd_rpi_justboom_digi_hw_params,
366 +        .startup = snd_rpi_justboom_digi_startup,
367 +        .shutdown = snd_rpi_justboom_digi_shutdown,
368 +};
369 +
370 +static struct snd_soc_dai_link snd_rpi_justboom_digi_dai[] = {
371 +{
372 +       .name           = "JustBoom Digi",
373 +       .stream_name    = "JustBoom Digi HiFi",
374 +       .cpu_dai_name   = "bcm2708-i2s.0",
375 +       .codec_dai_name = "wm8804-spdif",
376 +       .platform_name  = "bcm2708-i2s.0",
377 +       .codec_name     = "wm8804.1-003b",
378 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
379 +                               SND_SOC_DAIFMT_CBM_CFM,
380 +       .ops            = &snd_rpi_justboom_digi_ops,
381 +       .init           = snd_rpi_justboom_digi_init,
382 +},
383 +};
384 +
385 +/* audio machine driver */
386 +static struct snd_soc_card snd_rpi_justboom_digi = {
387 +       .name         = "snd_rpi_justboom_digi",
388 +       .owner        = THIS_MODULE,
389 +       .dai_link     = snd_rpi_justboom_digi_dai,
390 +       .num_links    = ARRAY_SIZE(snd_rpi_justboom_digi_dai),
391 +};
392 +
393 +static int snd_rpi_justboom_digi_probe(struct platform_device *pdev)
394 +{
395 +       int ret = 0;
396 +
397 +       snd_rpi_justboom_digi.dev = &pdev->dev;
398 +
399 +       if (pdev->dev.of_node) {
400 +           struct device_node *i2s_node;
401 +           struct snd_soc_dai_link *dai = &snd_rpi_justboom_digi_dai[0];
402 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
403 +                                       "i2s-controller", 0);
404 +
405 +           if (i2s_node) {
406 +                       dai->cpu_dai_name = NULL;
407 +                       dai->cpu_of_node = i2s_node;
408 +                       dai->platform_name = NULL;
409 +                       dai->platform_of_node = i2s_node;
410 +           }
411 +       }
412 +
413 +       ret = snd_soc_register_card(&snd_rpi_justboom_digi);
414 +       if (ret)
415 +               dev_err(&pdev->dev,
416 +                       "snd_soc_register_card() failed: %d\n", ret);
417 +
418 +       return ret;
419 +}
420 +
421 +static int snd_rpi_justboom_digi_remove(struct platform_device *pdev)
422 +{
423 +       return snd_soc_unregister_card(&snd_rpi_justboom_digi);
424 +}
425 +
426 +static const struct of_device_id snd_rpi_justboom_digi_of_match[] = {
427 +       { .compatible = "justboom,justboom-digi", },
428 +       {},
429 +};
430 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_digi_of_match);
431 +
432 +static struct platform_driver snd_rpi_justboom_digi_driver = {
433 +       .driver = {
434 +               .name   = "snd-rpi-justboom-digi",
435 +               .owner  = THIS_MODULE,
436 +               .of_match_table = snd_rpi_justboom_digi_of_match,
437 +       },
438 +       .probe          = snd_rpi_justboom_digi_probe,
439 +       .remove         = snd_rpi_justboom_digi_remove,
440 +};
441 +
442 +module_platform_driver(snd_rpi_justboom_digi_driver);
443 +
444 +MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
445 +MODULE_DESCRIPTION("ASoC Driver for JustBoom PI Digi HAT Sound Card");
446 +MODULE_LICENSE("GPL v2");