1 From e064c9d7ec3c51b79c6fdb7f1ff3a07b246ea774 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 241/304] Add Support for BoomBerry Audio boards
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
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
41 +Info: Configures the BoomBerry DAC HAT, Amp HAT, DAC Zero and Amp Zero audio
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!)
61 +Info: Configures the BoomBerry Digi HAT and Digi Zero audio cards
62 +Load: dtoverlay=boomberry-digi
67 Info: Overlay for the DHT11/DHT21/DHT22 humidity/temperature sensors
68 Also sometimes found with the part number(s) AM230x.
70 +++ b/arch/arm/boot/dts/overlays/boomberry-dac-overlay.dts
72 +// Definitions for BoomBerry DAC
77 + compatible = "brcm,bcm2708";
81 + frag0: __overlay__ {
82 + compatible = "boomberry,boomberry-dac";
83 + i2s-controller = <&i2s>;
98 + #address-cells = <1>;
103 + #sound-dai-cells = <0>;
104 + compatible = "ti,pcm5122";
112 + 24db_digital_gain = <&frag0>,"boomberry,24db_digital_gain?";
116 +++ b/arch/arm/boot/dts/overlays/boomberry-digi-overlay.dts
118 +// Definitions for BoomBerry Digi
123 + compatible = "brcm,bcm2708";
128 + compatible = "boomberry,boomberry-digi";
129 + i2s-controller = <&i2s>;
144 + #address-cells = <1>;
149 + #sound-dai-cells = <0>;
150 + compatible = "wlf,wm8804";
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
183 Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
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
190 + Say Y or M if you want to add support for BoomBerry DAC.
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
197 + Say Y or M if you want to add support for BoomBerry Digi.
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
223 +++ b/sound/soc/bcm/boomberry-dac.c
226 + * ASoC Driver for BoomBerry DAC Raspberry Pi HAT Sound Card
228 + * Author: Milan Neskovic
230 + * based on code by Daniel Matuschek <info@crazy-audio.com>
231 + * based on code by Florian Meier <florian.meier@koalo.de>
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.
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.
243 +#include <linux/module.h>
244 +#include <linux/platform_device.h>
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>
252 +#include "../codecs/pcm512x.h"
254 +static bool digital_gain_0db_limit = true;
256 +static int snd_rpi_boomberry_dac_init(struct snd_soc_pcm_runtime *rtd)
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);
263 + if (digital_gain_0db_limit)
266 + struct snd_soc_card *card = rtd->card;
267 + struct snd_soc_codec *codec = rtd->codec;
269 + ret = snd_soc_limit_volume(codec, "Digital Playback Volume", 207);
271 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
277 +static int snd_rpi_boomberry_dac_hw_params(struct snd_pcm_substream *substream,
278 + struct snd_pcm_hw_params *params)
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);
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);
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);
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,
308 +static struct snd_soc_dai_link snd_rpi_boomberry_dac_dai[] = {
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,
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),
331 +static int snd_rpi_boomberry_dac_probe(struct platform_device *pdev)
335 + snd_rpi_boomberry_dac.dev = &pdev->dev;
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);
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;
350 + digital_gain_0db_limit = !of_property_read_bool(
351 + pdev->dev.of_node, "boomberry,24db_digital_gain");
354 + ret = snd_soc_register_card(&snd_rpi_boomberry_dac);
356 + dev_err(&pdev->dev,
357 + "snd_soc_register_card() failed: %d\n", ret);
362 +static int snd_rpi_boomberry_dac_remove(struct platform_device *pdev)
364 + return snd_soc_unregister_card(&snd_rpi_boomberry_dac);
367 +static const struct of_device_id snd_rpi_boomberry_dac_of_match[] = {
368 + { .compatible = "boomberry,boomberry-dac", },
371 +MODULE_DEVICE_TABLE(of, snd_rpi_boomberry_dac_of_match);
373 +static struct platform_driver snd_rpi_boomberry_dac_driver = {
375 + .name = "snd-rpi-boomberry-dac",
376 + .owner = THIS_MODULE,
377 + .of_match_table = snd_rpi_boomberry_dac_of_match,
379 + .probe = snd_rpi_boomberry_dac_probe,
380 + .remove = snd_rpi_boomberry_dac_remove,
383 +module_platform_driver(snd_rpi_boomberry_dac_driver);
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");
389 +++ b/sound/soc/bcm/boomberry-digi.c
392 + * ASoC Driver for BoomBerry Raspberry Pi Digi HAT Sound Card
394 + * Author: Milan Neskovic
396 + * based on code by Daniel Matuschek <info@crazy-audio.com>
397 + * based on code by Florian Meier <florian.meier@koalo.de>
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.
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.
409 +#include <linux/module.h>
410 +#include <linux/platform_device.h>
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>
418 +#include "../codecs/wm8804.h"
420 +static int snd_rpi_boomberry_digi_init(struct snd_soc_pcm_runtime *rtd)
422 + struct snd_soc_codec *codec = rtd->codec;
424 + /* enable TX output */
425 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
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);
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);
445 +static int snd_rpi_boomberry_digi_hw_params(struct snd_pcm_substream *substream,
446 + struct snd_pcm_hw_params *params)
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;
453 + int sysclk = 27000000; /* This is fixed on this board */
457 + int sampling_freq=1;
461 + int samplerate = params_rate(params);
463 + if (samplerate<=96000) {
464 + mclk_freq=samplerate*256;
465 + mclk_div=WM8804_MCLKDIV_256FS;
467 + mclk_freq=samplerate*128;
468 + mclk_div=WM8804_MCLKDIV_128FS;
471 + switch (samplerate) {
473 + sampling_freq=0x03;
476 + sampling_freq=0x00;
479 + sampling_freq=0x02;
482 + sampling_freq=0x08;
485 + sampling_freq=0x0a;
488 + sampling_freq=0x0c;
491 + sampling_freq=0x0e;
494 + dev_err(codec->dev,
495 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
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);
502 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
503 + sysclk, SND_SOC_CLOCK_OUT);
505 + dev_err(codec->dev,
506 + "Failed to set WM8804 SYSCLK: %d\n", ret);
510 + /* Enable TX output */
511 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
514 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
516 + /* set sampling frequency status bits */
517 + snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
519 + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
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,
529 +static struct snd_soc_dai_link snd_rpi_boomberry_digi_dai[] = {
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,
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),
552 +static int snd_rpi_boomberry_digi_probe(struct platform_device *pdev)
556 + snd_rpi_boomberry_digi.dev = &pdev->dev;
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);
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;
572 + ret = snd_soc_register_card(&snd_rpi_boomberry_digi);
574 + dev_err(&pdev->dev,
575 + "snd_soc_register_card() failed: %d\n", ret);
580 +static int snd_rpi_boomberry_digi_remove(struct platform_device *pdev)
582 + return snd_soc_unregister_card(&snd_rpi_boomberry_digi);
585 +static const struct of_device_id snd_rpi_boomberry_digi_of_match[] = {
586 + { .compatible = "boomberry,boomberry-digi", },
589 +MODULE_DEVICE_TABLE(of, snd_rpi_boomberry_digi_of_match);
591 +static struct platform_driver snd_rpi_boomberry_digi_driver = {
593 + .name = "snd-rpi-boomberry-digi",
594 + .owner = THIS_MODULE,
595 + .of_match_table = snd_rpi_boomberry_digi_of_match,
597 + .probe = snd_rpi_boomberry_digi_probe,
598 + .remove = snd_rpi_boomberry_digi_remove,
601 +module_platform_driver(snd_rpi_boomberry_digi_driver);
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");