brcm2708: update linux 4.4 patches to latest version
[oweals/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0241-Add-Support-for-BoomBerry-Audio-boards.patch
1 From 3120b4247e34e255f4f43d291df4b779b3e9d4c8 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 BoomBerry Audio boards
5
6 ---
7  arch/arm/boot/dts/overlays/Makefile                |   2 +
8  arch/arm/boot/dts/overlays/README                  |  26 +++
9  .../boot/dts/overlays/boomberry-dac-overlay.dts    |  43 +++++
10  .../boot/dts/overlays/boomberry-digi-overlay.dts   |  39 ++++
11  arch/arm/configs/bcm2709_defconfig                 |   2 +
12  arch/arm/configs/bcmrpi_defconfig                  |   2 +
13  sound/soc/bcm/Kconfig                              |  14 ++
14  sound/soc/bcm/Makefile                             |   4 +
15  sound/soc/bcm/boomberry-dac.c                      | 163 ++++++++++++++++
16  sound/soc/bcm/boomberry-digi.c                     | 215 +++++++++++++++++++++
17  10 files changed, 510 insertions(+)
18  create mode 100644 arch/arm/boot/dts/overlays/boomberry-dac-overlay.dts
19  create mode 100644 arch/arm/boot/dts/overlays/boomberry-digi-overlay.dts
20  create mode 100644 sound/soc/bcm/boomberry-dac.c
21  create mode 100644 sound/soc/bcm/boomberry-digi.c
22
23 --- a/arch/arm/boot/dts/overlays/Makefile
24 +++ b/arch/arm/boot/dts/overlays/Makefile
25 @@ -16,6 +16,8 @@ dtbo-$(RPI_DT_OVERLAYS) += ads7846.dtbo
26  dtbo-$(RPI_DT_OVERLAYS) += akkordion-iqdacplus.dtbo
27  dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtbo
28  dtbo-$(RPI_DT_OVERLAYS) += bmp085_i2c-sensor.dtbo
29 +dtbo-$(RPI_DT_OVERLAYS) += boomberry-dac.dtbo
30 +dtbo-$(RPI_DT_OVERLAYS) += boomberry-digi.dtbo
31  dtbo-$(RPI_DT_OVERLAYS) += dpi24.dtbo
32  dtbo-$(RPI_DT_OVERLAYS) += dwc2.dtbo
33  dtbo-$(RPI_DT_OVERLAYS) += dwc-otg.dtbo
34 --- a/arch/arm/boot/dts/overlays/README
35 +++ b/arch/arm/boot/dts/overlays/README
36 @@ -225,6 +225,32 @@ Load:   dtoverlay=bmp085_i2c-sensor
37  Params: <None>
38  
39  
40 +Name:   boomberry-dac
41 +Info:   Configures the BoomBerry DAC HAT, Amp HAT, DAC Zero and Amp Zero audio
42 +        cards
43 +Load:   dtoverlay=boomberry-dac,<param>=<val>
44 +Params: 24db_digital_gain       Allow gain to be applied via the PCM512x codec
45 +                                Digital volume control. Enable with
46 +                                "dtoverlay=boomberry-dac,24db_digital_gain"
47 +                                (The default behaviour is that the Digital
48 +                                volume control is limited to a maximum of
49 +                                0dB. ie. it can attenuate but not provide
50 +                                gain. For most users, this will be desired
51 +                                as it will prevent clipping. By appending
52 +                                the 24dB_digital_gain parameter, the Digital
53 +                                volume control will allow up to 24dB of
54 +                                gain. If this parameter is enabled, it is the
55 +                                responsibility of the user to ensure that
56 +                                the Digital volume control is set to a value
57 +                                that does not result in clipping/distortion!)
58 +
59 +
60 +Name:   boomberry-digi
61 +Info:   Configures the BoomBerry Digi HAT and Digi Zero audio cards
62 +Load:   dtoverlay=boomberry-digi
63 +Params: <None>
64 +
65 +
66  Name:   dht11
67  Info:   Overlay for the DHT11/DHT21/DHT22 humidity/temperature sensors
68          Also sometimes found with the part number(s) AM230x.
69 --- /dev/null
70 +++ b/arch/arm/boot/dts/overlays/boomberry-dac-overlay.dts
71 @@ -0,0 +1,43 @@
72 +// Definitions for BoomBerry DAC
73 +/dts-v1/;
74 +/plugin/;
75 +
76 +/ {
77 +       compatible = "brcm,bcm2708";
78 +
79 +       fragment@0 {
80 +               target = <&sound>;
81 +               frag0: __overlay__ {
82 +                       compatible = "boomberry,boomberry-dac";
83 +                       i2s-controller = <&i2s>;
84 +                       status = "okay";
85 +               };
86 +       };
87 +
88 +       fragment@1 {
89 +               target = <&i2s>;
90 +               __overlay__ {
91 +                       status = "okay";
92 +               };
93 +       };
94 +
95 +       fragment@2 {
96 +               target = <&i2c1>;
97 +               __overlay__ {
98 +                       #address-cells = <1>;
99 +                       #size-cells = <0>;
100 +                       status = "okay";
101 +
102 +                       pcm5122@4d {
103 +                               #sound-dai-cells = <0>;
104 +                               compatible = "ti,pcm5122";
105 +                               reg = <0x4d>;
106 +                               status = "okay";
107 +                       };
108 +               };
109 +       };
110 +
111 +       __overrides__ {
112 +               24db_digital_gain = <&frag0>,"boomberry,24db_digital_gain?";
113 +       };
114 +};
115 --- /dev/null
116 +++ b/arch/arm/boot/dts/overlays/boomberry-digi-overlay.dts
117 @@ -0,0 +1,39 @@
118 +// Definitions for BoomBerry Digi
119 +/dts-v1/;
120 +/plugin/;
121 +
122 +/ {
123 +       compatible = "brcm,bcm2708";
124 +
125 +       fragment@0 {
126 +               target = <&sound>;
127 +               __overlay__ {
128 +                       compatible = "boomberry,boomberry-digi";
129 +                       i2s-controller = <&i2s>;
130 +                       status = "okay";
131 +               };
132 +       };
133 +
134 +       fragment@1 {
135 +               target = <&i2s>;
136 +               __overlay__ {
137 +                       status = "okay";
138 +               };
139 +       };
140 +
141 +       fragment@2 {
142 +               target = <&i2c1>;
143 +               __overlay__ {
144 +                       #address-cells = <1>;
145 +                       #size-cells = <0>;
146 +                       status = "okay";
147 +
148 +                       wm8804@3b {
149 +                               #sound-dai-cells = <0>;
150 +                               compatible = "wlf,wm8804";
151 +                               reg = <0x3b>;
152 +                               status = "okay";
153 +                       };
154 +               };
155 +       };
156 +};
157 --- a/arch/arm/configs/bcm2709_defconfig
158 +++ b/arch/arm/configs/bcm2709_defconfig
159 @@ -853,6 +853,8 @@ CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
160  CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
161  CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
162  CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
163 +CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
164 +CONFIG_SNG_BCM2708_SOC_BOOMBERRY_DIGI=m
165  CONFIG_SND_BCM2708_SOC_RPI_DAC=m
166  CONFIG_SND_BCM2708_SOC_RPI_PROTO=m
167  CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
168 --- a/arch/arm/configs/bcmrpi_defconfig
169 +++ b/arch/arm/configs/bcmrpi_defconfig
170 @@ -845,6 +845,8 @@ CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
171  CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
172  CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
173  CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
174 +CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
175 +CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
176  CONFIG_SND_BCM2708_SOC_RPI_DAC=m
177  CONFIG_SND_BCM2708_SOC_RPI_PROTO=m
178  CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
179 --- a/sound/soc/bcm/Kconfig
180 +++ b/sound/soc/bcm/Kconfig
181 @@ -50,6 +50,20 @@ config SND_BCM2708_SOC_RPI_PROTO
182         help
183           Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
184  
185 +config SND_BCM2708_SOC_BOOMBERRY_DAC
186 +       tristate "Support for BoomBerry DAC"
187 +       depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
188 +       select SND_SOC_PCM512x
189 +       help
190 +         Say Y or M if you want to add support for BoomBerry DAC.
191 +
192 +config SND_BCM2708_SOC_BOOMBERRY_DIGI
193 +       tristate "Support for BoomBerry Digi"
194 +       depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
195 +       select SND_SOC_WM8804
196 +       help
197 +         Say Y or M if you want to add support for BoomBerry Digi.
198 +
199  config SND_BCM2708_SOC_IQAUDIO_DAC
200         tristate "Support for IQaudIO-DAC"
201         depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
202 --- a/sound/soc/bcm/Makefile
203 +++ b/sound/soc/bcm/Makefile
204 @@ -8,6 +8,8 @@ snd-soc-hifiberry-dac-objs := hifiberry_
205  snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
206  snd-soc-hifiberry-digi-objs := hifiberry_digi.o
207  snd-soc-hifiberry-amp-objs := hifiberry_amp.o
208 +snd-soc-boomberry-dac-objs := boomberry-dac.o
209 +snd-soc-boomberry-digi-objs := boomberry-digi.o
210  snd-soc-rpi-dac-objs := rpi-dac.o
211  snd-soc-rpi-proto-objs := rpi-proto.o
212  snd-soc-iqaudio-dac-objs := iqaudio-dac.o
213 @@ -17,6 +19,8 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_D
214  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
215  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
216  obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
217 +obj-$(CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC) += snd-soc-boomberry-dac.o
218 +obj-$(CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI) += snd-soc-boomberry-digi.o
219  obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
220  obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
221  obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
222 --- /dev/null
223 +++ b/sound/soc/bcm/boomberry-dac.c
224 @@ -0,0 +1,163 @@
225 +/*
226 + * ASoC Driver for BoomBerry DAC Raspberry Pi HAT Sound Card
227 + *
228 + * Author:     Milan Neskovic
229 + *             Copyright 2016
230 + *             based on code by Daniel Matuschek <info@crazy-audio.com>
231 + *             based on code by Florian Meier <florian.meier@koalo.de>
232 + *
233 + * This program is free software; you can redistribute it and/or
234 + * modify it under the terms of the GNU General Public License
235 + * version 2 as published by the Free Software Foundation.
236 + *
237 + * This program is distributed in the hope that it will be useful, but
238 + * WITHOUT ANY WARRANTY; without even the implied warranty of
239 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
240 + * General Public License for more details.
241 + */
242 +
243 +#include <linux/module.h>
244 +#include <linux/platform_device.h>
245 +
246 +#include <sound/core.h>
247 +#include <sound/pcm.h>
248 +#include <sound/pcm_params.h>
249 +#include <sound/soc.h>
250 +#include <sound/jack.h>
251 +
252 +#include "../codecs/pcm512x.h"
253 +
254 +static bool digital_gain_0db_limit = true;
255 +
256 +static int snd_rpi_boomberry_dac_init(struct snd_soc_pcm_runtime *rtd)
257 +{
258 +       struct snd_soc_codec *codec = rtd->codec;
259 +       snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
260 +       snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
261 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
262 +
263 +       if (digital_gain_0db_limit)
264 +       {
265 +               int ret;
266 +               struct snd_soc_card *card = rtd->card;
267 +               struct snd_soc_codec *codec = rtd->codec;
268 +
269 +               ret = snd_soc_limit_volume(codec, "Digital Playback Volume", 207);
270 +               if (ret < 0)
271 +                       dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
272 +       }
273 +
274 +       return 0;
275 +}
276 +
277 +static int snd_rpi_boomberry_dac_hw_params(struct snd_pcm_substream *substream,
278 +                                      struct snd_pcm_hw_params *params)
279 +{
280 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
281 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
282 +       /*return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);*/
283 +       unsigned int sample_bits =
284 +               snd_pcm_format_physical_width(params_format(params));
285 +       return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
286 +}
287 +
288 +static int snd_rpi_boomberry_dac_startup(struct snd_pcm_substream *substream) {
289 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
290 +       struct snd_soc_codec *codec = rtd->codec;
291 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
292 +       return 0;
293 +}
294 +
295 +static void snd_rpi_boomberry_dac_shutdown(struct snd_pcm_substream *substream) {
296 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
297 +       struct snd_soc_codec *codec = rtd->codec;
298 +       snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
299 +}
300 +
301 +/* machine stream operations */
302 +static struct snd_soc_ops snd_rpi_boomberry_dac_ops = {
303 +       .hw_params = snd_rpi_boomberry_dac_hw_params,
304 +       .startup = snd_rpi_boomberry_dac_startup,
305 +       .shutdown = snd_rpi_boomberry_dac_shutdown,
306 +};
307 +
308 +static struct snd_soc_dai_link snd_rpi_boomberry_dac_dai[] = {
309 +{
310 +       .name           = "BoomBerry DAC",
311 +       .stream_name    = "BoomBerry DAC HiFi",
312 +       .cpu_dai_name   = "bcm2708-i2s.0",
313 +       .codec_dai_name = "pcm512x-hifi",
314 +       .platform_name  = "bcm2708-i2s.0",
315 +       .codec_name     = "pcm512x.1-004d",
316 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
317 +                               SND_SOC_DAIFMT_CBS_CFS,
318 +       .ops            = &snd_rpi_boomberry_dac_ops,
319 +       .init           = snd_rpi_boomberry_dac_init,
320 +},
321 +};
322 +
323 +/* audio machine driver */
324 +static struct snd_soc_card snd_rpi_boomberry_dac = {
325 +       .name         = "snd_rpi_boomberry_dac",
326 +       .owner        = THIS_MODULE,
327 +       .dai_link     = snd_rpi_boomberry_dac_dai,
328 +       .num_links    = ARRAY_SIZE(snd_rpi_boomberry_dac_dai),
329 +};
330 +
331 +static int snd_rpi_boomberry_dac_probe(struct platform_device *pdev)
332 +{
333 +       int ret = 0;
334 +
335 +       snd_rpi_boomberry_dac.dev = &pdev->dev;
336 +
337 +       if (pdev->dev.of_node) {
338 +           struct device_node *i2s_node;
339 +           struct snd_soc_dai_link *dai = &snd_rpi_boomberry_dac_dai[0];
340 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
341 +                                       "i2s-controller", 0);
342 +
343 +           if (i2s_node) {
344 +                       dai->cpu_dai_name = NULL;
345 +                       dai->cpu_of_node = i2s_node;
346 +                       dai->platform_name = NULL;
347 +                       dai->platform_of_node = i2s_node;
348 +           }
349 +
350 +           digital_gain_0db_limit = !of_property_read_bool(
351 +                       pdev->dev.of_node, "boomberry,24db_digital_gain");
352 +       }
353 +
354 +       ret = snd_soc_register_card(&snd_rpi_boomberry_dac);
355 +       if (ret)
356 +               dev_err(&pdev->dev,
357 +                       "snd_soc_register_card() failed: %d\n", ret);
358 +
359 +       return ret;
360 +}
361 +
362 +static int snd_rpi_boomberry_dac_remove(struct platform_device *pdev)
363 +{
364 +       return snd_soc_unregister_card(&snd_rpi_boomberry_dac);
365 +}
366 +
367 +static const struct of_device_id snd_rpi_boomberry_dac_of_match[] = {
368 +       { .compatible = "boomberry,boomberry-dac", },
369 +       {},
370 +};
371 +MODULE_DEVICE_TABLE(of, snd_rpi_boomberry_dac_of_match);
372 +
373 +static struct platform_driver snd_rpi_boomberry_dac_driver = {
374 +       .driver = {
375 +               .name   = "snd-rpi-boomberry-dac",
376 +               .owner  = THIS_MODULE,
377 +               .of_match_table = snd_rpi_boomberry_dac_of_match,
378 +       },
379 +       .probe          = snd_rpi_boomberry_dac_probe,
380 +       .remove         = snd_rpi_boomberry_dac_remove,
381 +};
382 +
383 +module_platform_driver(snd_rpi_boomberry_dac_driver);
384 +
385 +MODULE_AUTHOR("Milan Neskovic <info@boomberry.co>");
386 +MODULE_DESCRIPTION("ASoC Driver for BoomBerry PI DAC HAT Sound Card");
387 +MODULE_LICENSE("GPL v2");
388 --- /dev/null
389 +++ b/sound/soc/bcm/boomberry-digi.c
390 @@ -0,0 +1,215 @@
391 +/*
392 + * ASoC Driver for BoomBerry Raspberry Pi Digi HAT Sound Card
393 + *
394 + * Author:     Milan Neskovic
395 + *             Copyright 2016
396 + *             based on code by Daniel Matuschek <info@crazy-audio.com>
397 + *             based on code by Florian Meier <florian.meier@koalo.de>
398 + *
399 + * This program is free software; you can redistribute it and/or
400 + * modify it under the terms of the GNU General Public License
401 + * version 2 as published by the Free Software Foundation.
402 + *
403 + * This program is distributed in the hope that it will be useful, but
404 + * WITHOUT ANY WARRANTY; without even the implied warranty of
405 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
406 + * General Public License for more details.
407 + */
408 +
409 +#include <linux/module.h>
410 +#include <linux/platform_device.h>
411 +
412 +#include <sound/core.h>
413 +#include <sound/pcm.h>
414 +#include <sound/pcm_params.h>
415 +#include <sound/soc.h>
416 +#include <sound/jack.h>
417 +
418 +#include "../codecs/wm8804.h"
419 +
420 +static int snd_rpi_boomberry_digi_init(struct snd_soc_pcm_runtime *rtd)
421 +{
422 +       struct snd_soc_codec *codec = rtd->codec;
423 +
424 +       /* enable TX output */
425 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
426 +
427 +       return 0;
428 +}
429 +
430 +static int snd_rpi_boomberry_digi_startup(struct snd_pcm_substream *substream) {
431 +       /* turn on digital output */
432 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
433 +       struct snd_soc_codec *codec = rtd->codec;
434 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
435 +       return 0;
436 +}
437 +
438 +static void snd_rpi_boomberry_digi_shutdown(struct snd_pcm_substream *substream) {
439 +       /* turn off output */
440 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
441 +       struct snd_soc_codec *codec = rtd->codec;
442 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
443 +}
444 +
445 +static int snd_rpi_boomberry_digi_hw_params(struct snd_pcm_substream *substream,
446 +                                      struct snd_pcm_hw_params *params)
447 +{
448 +       struct snd_soc_pcm_runtime *rtd = substream->private_data;
449 +       struct snd_soc_dai *codec_dai = rtd->codec_dai;
450 +       struct snd_soc_codec *codec = rtd->codec;
451 +       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
452 +
453 +       int sysclk = 27000000; /* This is fixed on this board */
454 +
455 +       long mclk_freq=0;
456 +       int mclk_div=1;
457 +       int sampling_freq=1;
458 +
459 +       int ret;
460 +
461 +       int samplerate = params_rate(params);
462 +
463 +       if (samplerate<=96000) {
464 +               mclk_freq=samplerate*256;
465 +               mclk_div=WM8804_MCLKDIV_256FS;
466 +       } else {
467 +               mclk_freq=samplerate*128;
468 +               mclk_div=WM8804_MCLKDIV_128FS;
469 +       }
470 +
471 +       switch (samplerate) {
472 +               case 32000:
473 +                       sampling_freq=0x03;
474 +                       break;
475 +               case 44100:
476 +                       sampling_freq=0x00;
477 +                       break;
478 +               case 48000:
479 +                       sampling_freq=0x02;
480 +                       break;
481 +               case 88200:
482 +                       sampling_freq=0x08;
483 +                       break;
484 +               case 96000:
485 +                       sampling_freq=0x0a;
486 +                       break;
487 +               case 176400:
488 +                       sampling_freq=0x0c;
489 +                       break;
490 +               case 192000:
491 +                       sampling_freq=0x0e;
492 +                       break;
493 +               default:
494 +                       dev_err(codec->dev,
495 +                       "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
496 +                       samplerate);
497 +       }
498 +
499 +       snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
500 +       snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
501 +
502 +       ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
503 +                                       sysclk, SND_SOC_CLOCK_OUT);
504 +       if (ret < 0) {
505 +               dev_err(codec->dev,
506 +               "Failed to set WM8804 SYSCLK: %d\n", ret);
507 +               return ret;
508 +       }
509 +
510 +       /* Enable TX output */
511 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
512 +
513 +       /* Power on */
514 +       snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
515 +
516 +       /* set sampling frequency status bits */
517 +       snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
518 +
519 +       return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
520 +}
521 +
522 +/* machine stream operations */
523 +static struct snd_soc_ops snd_rpi_boomberry_digi_ops = {
524 +       .hw_params = snd_rpi_boomberry_digi_hw_params,
525 +        .startup = snd_rpi_boomberry_digi_startup,
526 +        .shutdown = snd_rpi_boomberry_digi_shutdown,
527 +};
528 +
529 +static struct snd_soc_dai_link snd_rpi_boomberry_digi_dai[] = {
530 +{
531 +       .name           = "BoomBerry Digi",
532 +       .stream_name    = "BoomBerry Digi HiFi",
533 +       .cpu_dai_name   = "bcm2708-i2s.0",
534 +       .codec_dai_name = "wm8804-spdif",
535 +       .platform_name  = "bcm2708-i2s.0",
536 +       .codec_name     = "wm8804.1-003b",
537 +       .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
538 +                               SND_SOC_DAIFMT_CBM_CFM,
539 +       .ops            = &snd_rpi_boomberry_digi_ops,
540 +       .init           = snd_rpi_boomberry_digi_init,
541 +},
542 +};
543 +
544 +/* audio machine driver */
545 +static struct snd_soc_card snd_rpi_boomberry_digi = {
546 +       .name         = "snd_rpi_boomberry_digi",
547 +       .owner        = THIS_MODULE,
548 +       .dai_link     = snd_rpi_boomberry_digi_dai,
549 +       .num_links    = ARRAY_SIZE(snd_rpi_boomberry_digi_dai),
550 +};
551 +
552 +static int snd_rpi_boomberry_digi_probe(struct platform_device *pdev)
553 +{
554 +       int ret = 0;
555 +
556 +       snd_rpi_boomberry_digi.dev = &pdev->dev;
557 +
558 +       if (pdev->dev.of_node) {
559 +           struct device_node *i2s_node;
560 +           struct snd_soc_dai_link *dai = &snd_rpi_boomberry_digi_dai[0];
561 +           i2s_node = of_parse_phandle(pdev->dev.of_node,
562 +                                       "i2s-controller", 0);
563 +
564 +           if (i2s_node) {
565 +                       dai->cpu_dai_name = NULL;
566 +                       dai->cpu_of_node = i2s_node;
567 +                       dai->platform_name = NULL;
568 +                       dai->platform_of_node = i2s_node;
569 +           }
570 +       }
571 +
572 +       ret = snd_soc_register_card(&snd_rpi_boomberry_digi);
573 +       if (ret)
574 +               dev_err(&pdev->dev,
575 +                       "snd_soc_register_card() failed: %d\n", ret);
576 +
577 +       return ret;
578 +}
579 +
580 +static int snd_rpi_boomberry_digi_remove(struct platform_device *pdev)
581 +{
582 +       return snd_soc_unregister_card(&snd_rpi_boomberry_digi);
583 +}
584 +
585 +static const struct of_device_id snd_rpi_boomberry_digi_of_match[] = {
586 +       { .compatible = "boomberry,boomberry-digi", },
587 +       {},
588 +};
589 +MODULE_DEVICE_TABLE(of, snd_rpi_boomberry_digi_of_match);
590 +
591 +static struct platform_driver snd_rpi_boomberry_digi_driver = {
592 +       .driver = {
593 +               .name   = "snd-rpi-boomberry-digi",
594 +               .owner  = THIS_MODULE,
595 +               .of_match_table = snd_rpi_boomberry_digi_of_match,
596 +       },
597 +       .probe          = snd_rpi_boomberry_digi_probe,
598 +       .remove         = snd_rpi_boomberry_digi_remove,
599 +};
600 +
601 +module_platform_driver(snd_rpi_boomberry_digi_driver);
602 +
603 +MODULE_AUTHOR("Milan Neskovic <info@boomberry.co>");
604 +MODULE_DESCRIPTION("ASoC Driver for BoomBerry PI Digi HAT Sound Card");
605 +MODULE_LICENSE("GPL v2");