1 From 1b18f3be9f034c2e9aefab9b97c5100d5f914a89 Mon Sep 17 00:00:00 2001
2 From: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
3 Date: Thu, 30 Jun 2016 18:38:42 +0100
4 Subject: [PATCH] Add IQAudIO Digi WM8804 board support
6 Support IQAudIO Digi board with iqaudio_digi machine driver and
7 iqaudio-digi-wm8804-audio overlay.
9 NB. Machine driver is a cut and paste of hifiberry_digi code, with format
10 and general cleanup to comply with kernel coding standards.
12 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
14 sound/soc/bcm/Kconfig | 7 ++
15 sound/soc/bcm/Makefile | 2 +
16 sound/soc/bcm/iqaudio_digi.c | 239 +++++++++++++++++++++++++++++++++++++++++++
17 3 files changed, 248 insertions(+)
18 create mode 100644 sound/soc/bcm/iqaudio_digi.c
20 --- a/sound/soc/bcm/Kconfig
21 +++ b/sound/soc/bcm/Kconfig
22 @@ -73,6 +73,13 @@ config SND_BCM2708_SOC_IQAUDIO_DAC
24 Say Y or M if you want to add support for IQaudIO-DAC.
26 +config SND_BCM2708_SOC_IQAUDIO_DIGI
27 + tristate "Support for IQAudIO Digi"
28 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
29 + select SND_SOC_WM8804
31 + Say Y or M if you want to add support for IQAudIO Digital IO board.
33 config SND_BCM2708_SOC_RASPIDAC3
34 tristate "Support for RaspiDAC Rev.3x"
35 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
36 --- a/sound/soc/bcm/Makefile
37 +++ b/sound/soc/bcm/Makefile
38 @@ -18,6 +18,7 @@ snd-soc-justboom-digi-objs := justboom-d
39 snd-soc-rpi-dac-objs := rpi-dac.o
40 snd-soc-rpi-proto-objs := rpi-proto.o
41 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
42 +snd-soc-iqaudio-digi-objs := iqaudio_digi.o
43 snd-soc-raspidac3-objs := raspidac3.o
44 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
46 @@ -30,6 +31,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DI
47 obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
48 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
49 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
50 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI) += snd-soc-iqaudio-digi.o
51 obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
52 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
55 +++ b/sound/soc/bcm/iqaudio_digi.c
58 + * ASoC Driver for IQAudIO WM8804 Digi
60 + * Author: Daniel Matuschek <info@crazy-audio.com>
61 + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
64 + * This program is free software; you can redistribute it and/or
65 + * modify it under the terms of the GNU General Public License
66 + * version 2 as published by the Free Software Foundation.
68 + * This program is distributed in the hope that it will be useful, but
69 + * WITHOUT ANY WARRANTY; without even the implied warranty of
70 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
71 + * General Public License for more details.
74 +#include <linux/module.h>
75 +#include <linux/platform_device.h>
77 +#include <sound/core.h>
78 +#include <sound/pcm.h>
79 +#include <sound/pcm_params.h>
80 +#include <sound/soc.h>
81 +#include <sound/jack.h>
83 +#include "../codecs/wm8804.h"
85 +static short int auto_shutdown_output;
86 +module_param(auto_shutdown_output, short,
87 + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
88 +MODULE_PARM_DESC(auto_shutdown_output, "Shutdown SP/DIF output if playback is stopped");
90 +static int snd_rpi_iqaudio_digi_init(struct snd_soc_pcm_runtime *rtd)
92 + struct snd_soc_codec *codec = rtd->codec;
94 + /* enable TX output */
95 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
100 +static int snd_rpi_iqaudio_digi_startup(struct snd_pcm_substream *substream)
102 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
103 + struct snd_soc_codec *codec = rtd->codec;
105 + /* turn on digital output */
106 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
111 +static void snd_rpi_iqaudio_digi_shutdown(struct snd_pcm_substream *substream)
113 + if (auto_shutdown_output) {
114 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
115 + struct snd_soc_codec *codec = rtd->codec;
117 + /* turn off digital output */
118 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
123 +static int snd_rpi_iqaudio_digi_hw_params(struct snd_pcm_substream *substream,
124 + struct snd_pcm_hw_params *params)
126 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
127 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
128 + struct snd_soc_codec *codec = rtd->codec;
129 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
131 + int sysclk = 27000000; /* This is fixed on this board */
133 + long mclk_freq = 0;
135 + int sampling_freq = 1;
139 + int samplerate = params_rate(params);
141 + if (samplerate <= 96000) {
142 + mclk_freq = samplerate * 256;
143 + mclk_div = WM8804_MCLKDIV_256FS;
145 + mclk_freq = samplerate * 128;
146 + mclk_div = WM8804_MCLKDIV_128FS;
149 + switch (samplerate) {
151 + sampling_freq = 0x03;
154 + sampling_freq = 0x00;
157 + sampling_freq = 0x02;
160 + sampling_freq = 0x08;
163 + sampling_freq = 0x0a;
166 + sampling_freq = 0x0c;
169 + sampling_freq = 0x0e;
172 + dev_err(codec->dev, "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
176 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
177 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
179 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
180 + sysclk, SND_SOC_CLOCK_OUT);
182 + dev_err(codec->dev, "Failed to set WM8804 SYSCLK: %d\n", ret);
186 + /* Enable TX output */
187 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
190 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
192 + /* set sampling frequency status bits */
193 + snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
195 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
198 +/* machine stream operations */
199 +static struct snd_soc_ops snd_rpi_iqaudio_digi_ops = {
200 + .hw_params = snd_rpi_iqaudio_digi_hw_params,
201 + .startup = snd_rpi_iqaudio_digi_startup,
202 + .shutdown = snd_rpi_iqaudio_digi_shutdown,
205 +static struct snd_soc_dai_link snd_rpi_iqaudio_digi_dai[] = {
207 + .name = "IQAudIO Digi",
208 + .stream_name = "IQAudIO Digi HiFi",
209 + .cpu_dai_name = "bcm2708-i2s.0",
210 + .codec_dai_name = "wm8804-spdif",
211 + .platform_name = "bcm2708-i2s.0",
212 + .codec_name = "wm8804.1-003b",
213 + .dai_fmt = SND_SOC_DAIFMT_I2S |
214 + SND_SOC_DAIFMT_NB_NF |
215 + SND_SOC_DAIFMT_CBM_CFM,
216 + .ops = &snd_rpi_iqaudio_digi_ops,
217 + .init = snd_rpi_iqaudio_digi_init,
221 +/* audio machine driver */
222 +static struct snd_soc_card snd_rpi_iqaudio_digi = {
223 + .name = "IQAudIODigi",
224 + .owner = THIS_MODULE,
225 + .dai_link = snd_rpi_iqaudio_digi_dai,
226 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_digi_dai),
229 +static int snd_rpi_iqaudio_digi_probe(struct platform_device *pdev)
231 + struct snd_soc_card *card = &snd_rpi_iqaudio_digi;
232 + char *prefix = "wm8804-digi,";
234 + struct device_node *np;
237 + snd_rpi_iqaudio_digi.dev = &pdev->dev;
239 + np = pdev->dev.of_node;
241 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_digi_dai[0];
242 + struct device_node *i2s_node;
244 + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
246 + dai->cpu_dai_name = NULL;
247 + dai->cpu_of_node = i2s_node;
248 + dai->platform_name = NULL;
249 + dai->platform_of_node = i2s_node;
252 + snprintf(prop, sizeof(prop), "%scard-name", prefix);
253 + of_property_read_string(np, prop, &card->name);
255 + snprintf(prop, sizeof(prop), "%sdai-name", prefix);
256 + of_property_read_string(np, prop, &dai->name);
258 + snprintf(prop, sizeof(prop), "%sdai-stream-name", prefix);
259 + of_property_read_string(np, prop, &dai->stream_name);
262 + ret = snd_soc_register_card(card);
264 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
270 +static int snd_rpi_iqaudio_digi_remove(struct platform_device *pdev)
272 + return snd_soc_unregister_card(&snd_rpi_iqaudio_digi);
275 +static const struct of_device_id snd_rpi_iqaudio_digi_of_match[] = {
276 + { .compatible = "iqaudio,wm8804-digi", },
279 +MODULE_DEVICE_TABLE(of, snd_rpi_iqaudio_digi_of_match);
281 +static struct platform_driver snd_rpi_iqaudio_digi_driver = {
283 + .name = "IQAudIODigi",
284 + .owner = THIS_MODULE,
285 + .of_match_table = snd_rpi_iqaudio_digi_of_match,
287 + .probe = snd_rpi_iqaudio_digi_probe,
288 + .remove = snd_rpi_iqaudio_digi_remove,
291 +module_platform_driver(snd_rpi_iqaudio_digi_driver);
293 +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
294 +MODULE_DESCRIPTION("ASoC Driver for IQAudIO WM8804 Digi");
295 +MODULE_LICENSE("GPL v2");