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
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 | 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
21 --- a/sound/soc/bcm/Kconfig
22 +++ b/sound/soc/bcm/Kconfig
23 @@ -59,6 +59,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 + .owner = THIS_MODULE,
168 + .dai_link = snd_rpi_justboom_dac_dai,
169 + .num_links = ARRAY_SIZE(snd_rpi_justboom_dac_dai),
172 +static int snd_rpi_justboom_dac_probe(struct platform_device *pdev)
176 + snd_rpi_justboom_dac.dev = &pdev->dev;
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);
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;
191 + digital_gain_0db_limit = !of_property_read_bool(
192 + pdev->dev.of_node, "justboom,24db_digital_gain");
195 + ret = snd_soc_register_card(&snd_rpi_justboom_dac);
197 + dev_err(&pdev->dev,
198 + "snd_soc_register_card() failed: %d\n", ret);
203 +static int snd_rpi_justboom_dac_remove(struct platform_device *pdev)
205 + return snd_soc_unregister_card(&snd_rpi_justboom_dac);
208 +static const struct of_device_id snd_rpi_justboom_dac_of_match[] = {
209 + { .compatible = "justboom,justboom-dac", },
212 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_dac_of_match);
214 +static struct platform_driver snd_rpi_justboom_dac_driver = {
216 + .name = "snd-rpi-justboom-dac",
217 + .owner = THIS_MODULE,
218 + .of_match_table = snd_rpi_justboom_dac_of_match,
220 + .probe = snd_rpi_justboom_dac_probe,
221 + .remove = snd_rpi_justboom_dac_remove,
224 +module_platform_driver(snd_rpi_justboom_dac_driver);
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");
230 +++ b/sound/soc/bcm/justboom-digi.c
233 + * ASoC Driver for JustBoom Raspberry Pi Digi HAT Sound Card
235 + * Author: Milan Neskovic
237 + * based on code by Daniel Matuschek <info@crazy-audio.com>
238 + * based on code by Florian Meier <florian.meier@koalo.de>
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.
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.
250 +#include <linux/module.h>
251 +#include <linux/platform_device.h>
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>
259 +#include "../codecs/wm8804.h"
261 +static int snd_rpi_justboom_digi_init(struct snd_soc_pcm_runtime *rtd)
263 + struct snd_soc_codec *codec = rtd->codec;
265 + /* enable TX output */
266 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
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);
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);
286 +static int snd_rpi_justboom_digi_hw_params(struct snd_pcm_substream *substream,
287 + struct snd_pcm_hw_params *params)
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;
294 + int sysclk = 27000000; /* This is fixed on this board */
298 + int sampling_freq=1;
302 + int samplerate = params_rate(params);
304 + if (samplerate<=96000) {
305 + mclk_freq=samplerate*256;
306 + mclk_div=WM8804_MCLKDIV_256FS;
308 + mclk_freq=samplerate*128;
309 + mclk_div=WM8804_MCLKDIV_128FS;
312 + switch (samplerate) {
314 + sampling_freq=0x03;
317 + sampling_freq=0x00;
320 + sampling_freq=0x02;
323 + sampling_freq=0x08;
326 + sampling_freq=0x0a;
329 + sampling_freq=0x0c;
332 + sampling_freq=0x0e;
335 + dev_err(codec->dev,
336 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
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);
343 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
344 + sysclk, SND_SOC_CLOCK_OUT);
346 + dev_err(codec->dev,
347 + "Failed to set WM8804 SYSCLK: %d\n", ret);
351 + /* Enable TX output */
352 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
355 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
357 + /* set sampling frequency status bits */
358 + snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
360 + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
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,
370 +static struct snd_soc_dai_link snd_rpi_justboom_digi_dai[] = {
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,
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),
393 +static int snd_rpi_justboom_digi_probe(struct platform_device *pdev)
397 + snd_rpi_justboom_digi.dev = &pdev->dev;
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);
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;
413 + ret = snd_soc_register_card(&snd_rpi_justboom_digi);
415 + dev_err(&pdev->dev,
416 + "snd_soc_register_card() failed: %d\n", ret);
421 +static int snd_rpi_justboom_digi_remove(struct platform_device *pdev)
423 + return snd_soc_unregister_card(&snd_rpi_justboom_digi);
426 +static const struct of_device_id snd_rpi_justboom_digi_of_match[] = {
427 + { .compatible = "justboom,justboom-digi", },
430 +MODULE_DEVICE_TABLE(of, snd_rpi_justboom_digi_of_match);
432 +static struct platform_driver snd_rpi_justboom_digi_driver = {
434 + .name = "snd-rpi-justboom-digi",
435 + .owner = THIS_MODULE,
436 + .of_match_table = snd_rpi_justboom_digi_of_match,
438 + .probe = snd_rpi_justboom_digi_probe,
439 + .remove = snd_rpi_justboom_digi_remove,
442 +module_platform_driver(snd_rpi_justboom_digi_driver);
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");