1 From c86b5cd0c5a5ba9b9937bc9cecbc3b25a4f037ad 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 073/454] Add Support for JustBoom Audio boards
6 justboom-dac: Adjust for ALSA API change
8 As of 4.4, snd_soc_limit_volume now takes a struct snd_soc_card *
9 rather than a struct snd_soc_codec *.
11 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
13 sound/soc/bcm/Kconfig | 14 +++
14 sound/soc/bcm/Makefile | 4 +
15 sound/soc/bcm/justboom-dac.c | 163 +++++++++++++++++++++++++
16 sound/soc/bcm/justboom-digi.c | 216 ++++++++++++++++++++++++++++++++++
17 4 files changed, 397 insertions(+)
18 create mode 100644 sound/soc/bcm/justboom-dac.c
19 create mode 100644 sound/soc/bcm/justboom-digi.c
21 --- a/sound/soc/bcm/Kconfig
22 +++ b/sound/soc/bcm/Kconfig
23 @@ -60,6 +60,20 @@ config SND_BCM2708_SOC_RPI_PROTO
25 Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
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
32 + Say Y or M if you want to add support for JustBoom DAC.
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
39 + Say Y or M if you want to add support for JustBoom Digi.
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
65 +++ b/sound/soc/bcm/justboom-dac.c
68 + * ASoC Driver for JustBoom DAC Raspberry Pi HAT Sound Card
70 + * Author: Milan Neskovic
72 + * based on code by Daniel Matuschek <info@crazy-audio.com>
73 + * based on code by Florian Meier <florian.meier@koalo.de>
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.
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.
85 +#include <linux/module.h>
86 +#include <linux/platform_device.h>
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>
94 +#include "../codecs/pcm512x.h"
96 +static bool digital_gain_0db_limit = true;
98 +static int snd_rpi_justboom_dac_init(struct snd_soc_pcm_runtime *rtd)
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);
105 + if (digital_gain_0db_limit)
108 + struct snd_soc_card *card = rtd->card;
110 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
112 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
118 +static int snd_rpi_justboom_dac_hw_params(struct snd_pcm_substream *substream,
119 + struct snd_pcm_hw_params *params)
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);
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);
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);
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,
149 +static struct snd_soc_dai_link snd_rpi_justboom_dac_dai[] = {
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,
164 +/* audio machine driver */
165 +static struct snd_soc_card snd_rpi_justboom_dac = {
166 + .name = "snd_rpi_justboom_dac",
167 + .driver_name = "JustBoomDac",
168 + .owner = THIS_MODULE,
169 + .dai_link = snd_rpi_justboom_dac_dai,
170 + .num_links = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
173 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
177 + snd_rpi_justboom_dac.dev = &pdev->dev;
179 + if (pdev->dev.of_node) {
180 + struct device_node *i2s_node;
181 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_dac_dai[0];
182 + i2s_node = of_parse_phandle(pdev->dev.of_node,
183 + "i2s-controller", 0);
186 + dai->cpu_dai_name = NULL;
187 + dai->cpu_of_node = i2s_node;
188 + dai->platform_name = NULL;
189 + dai->platform_of_node = i2s_node;
192 + digital_gain_0db_limit = !of_property_read_bool(
193 + pdev->dev.of_node, "justboom,24db_digital_gain");
196 + ret = snd_soc_register_card(&snd_rpi_justboom_dac);
197 + if (ret && ret != -EPROBE_DEFER)
198 + dev_err(&pdev->dev,
199 + "snd_soc_register_card() failed: %d\n", ret);
204 +static int snd_rpi_justboom_dac_remove(struct platform_device *pdev)
206 + return snd_soc_unregister_card(&snd_rpi_justboom_dac);
209 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
210 + { .compatible = "justboom,justboom-dac", },
213 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
215 +static struct platform_driver snd_rpi_justboom_dac_driver = {
217 + .name = "snd-rpi-justboom-dac",
218 + .owner = THIS_MODULE,
219 + .of_match_table = snd_rpi_justboom_dac_of_match,
221 + .probe = snd_rpi_justboom_dac_probe,
222 + .remove = snd_rpi_justboom_dac_remove,
225 +module_platform_driver(snd_rpi_justboom_dac_driver);
227 +MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
228 +MODULE_DESCRIPTION("ASoC Driver for JustBoom PI DAC HAT Sound Card");
229 +MODULE_LICENSE("GPL v2");
231 +++ b/sound/soc/bcm/justboom-digi.c
234 + * ASoC Driver for JustBoom Raspberry Pi Digi HAT Sound Card
236 + * Author: Milan Neskovic
238 + * based on code by Daniel Matuschek <info@crazy-audio.com>
239 + * based on code by Florian Meier <florian.meier@koalo.de>
241 + * This program is free software; you can redistribute it and/or
242 + * modify it under the terms of the GNU General Public License
243 + * version 2 as published by the Free Software Foundation.
245 + * This program is distributed in the hope that it will be useful, but
246 + * WITHOUT ANY WARRANTY; without even the implied warranty of
247 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
248 + * General Public License for more details.
251 +#include <linux/module.h>
252 +#include <linux/platform_device.h>
254 +#include <sound/core.h>
255 +#include <sound/pcm.h>
256 +#include <sound/pcm_params.h>
257 +#include <sound/soc.h>
258 +#include <sound/jack.h>
260 +#include "../codecs/wm8804.h"
262 +static int snd_rpi_justboom_digi_init(struct snd_soc_pcm_runtime *rtd)
264 + struct snd_soc_codec *codec = rtd->codec;
266 + /* enable TX output */
267 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
272 +static int snd_rpi_justboom_digi_startup(struct snd_pcm_substream *substream) {
273 + /* turn on digital output */
274 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
275 + struct snd_soc_codec *codec = rtd->codec;
276 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
280 +static void snd_rpi_justboom_digi_shutdown(struct snd_pcm_substream *substream) {
281 + /* turn off output */
282 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
283 + struct snd_soc_codec *codec = rtd->codec;
284 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
287 +static int snd_rpi_justboom_digi_hw_params(struct snd_pcm_substream *substream,
288 + struct snd_pcm_hw_params *params)
290 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
291 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
292 + struct snd_soc_codec *codec = rtd->codec;
293 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
295 + int sysclk = 27000000; /* This is fixed on this board */
299 + int sampling_freq=1;
303 + int samplerate = params_rate(params);
305 + if (samplerate<=96000) {
306 + mclk_freq=samplerate*256;
307 + mclk_div=WM8804_MCLKDIV_256FS;
309 + mclk_freq=samplerate*128;
310 + mclk_div=WM8804_MCLKDIV_128FS;
313 + switch (samplerate) {
315 + sampling_freq=0x03;
318 + sampling_freq=0x00;
321 + sampling_freq=0x02;
324 + sampling_freq=0x08;
327 + sampling_freq=0x0a;
330 + sampling_freq=0x0c;
333 + sampling_freq=0x0e;
336 + dev_err(codec->dev,
337 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
341 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
342 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
344 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
345 + sysclk, SND_SOC_CLOCK_OUT);
347 + dev_err(codec->dev,
348 + "Failed to set WM8804 SYSCLK: %d\n", ret);
352 + /* Enable TX output */
353 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
356 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
358 + /* set sampling frequency status bits */
359 + snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
361 + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
364 +/* machine stream operations */
365 +static struct snd_soc_ops snd_rpi_justboom_digi_ops = {
366 + .hw_params = snd_rpi_justboom_digi_hw_params,
367 + .startup = snd_rpi_justboom_digi_startup,
368 + .shutdown = snd_rpi_justboom_digi_shutdown,
371 +static struct snd_soc_dai_link snd_rpi_justboom_digi_dai[] = {
373 + .name = "JustBoom Digi",
374 + .stream_name = "JustBoom Digi HiFi",
375 + .cpu_dai_name = "bcm2708-i2s.0",
376 + .codec_dai_name = "wm8804-spdif",
377 + .platform_name = "bcm2708-i2s.0",
378 + .codec_name = "wm8804.1-003b",
379 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
380 + SND_SOC_DAIFMT_CBM_CFM,
381 + .ops = &snd_rpi_justboom_digi_ops,
382 + .init = snd_rpi_justboom_digi_init,
386 +/* audio machine driver */
387 +static struct snd_soc_card snd_rpi_justboom_digi = {
388 + .name = "snd_rpi_justboom_digi",
389 + .driver_name = "JustBoomDigi",
390 + .owner = THIS_MODULE,
391 + .dai_link = snd_rpi_justboom_digi_dai,
392 + .num_links = ARRAY_SIZE(snd_rpi_justboom_digi_dai),
395 +static int snd_rpi_justboom_digi_probe(struct platform_device *pdev)
399 + snd_rpi_justboom_digi.dev = &pdev->dev;
401 + if (pdev->dev.of_node) {
402 + struct device_node *i2s_node;
403 + struct snd_soc_dai_link *dai = &snd_rpi_justboom_digi_dai[0];
404 + i2s_node = of_parse_phandle(pdev->dev.of_node,
405 + "i2s-controller", 0);
408 + dai->cpu_dai_name = NULL;
409 + dai->cpu_of_node = i2s_node;
410 + dai->platform_name = NULL;
411 + dai->platform_of_node = i2s_node;
415 + ret = snd_soc_register_card(&snd_rpi_justboom_digi);
416 + if (ret && ret != -EPROBE_DEFER)
417 + dev_err(&pdev->dev,
418 + "snd_soc_register_card() failed: %d\n", ret);
423 +static int snd_rpi_justboom_digi_remove(struct platform_device *pdev)
425 + return snd_soc_unregister_card(&snd_rpi_justboom_digi);
428 +static const struct of_device_id snd_rpi_justboom_digi_of_match[] = {
429 + { .compatible = "justboom,justboom-digi", },
432 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_digi_of_match);
434 +static struct platform_driver snd_rpi_justboom_digi_driver = {
436 + .name = "snd-rpi-justboom-digi",
437 + .owner = THIS_MODULE,
438 + .of_match_table = snd_rpi_justboom_digi_of_match,
440 + .probe = snd_rpi_justboom_digi_probe,
441 + .remove = snd_rpi_justboom_digi_remove,
444 +module_platform_driver(snd_rpi_justboom_digi_driver);
446 +MODULE_AUTHOR("Milan Neskovic <info@justboom.co>");
447 +MODULE_DESCRIPTION("ASoC Driver for JustBoom PI Digi HAT Sound Card");
448 +MODULE_LICENSE("GPL v2");