1 From 525cdff530e74a8428a60859f9308bca825463fd Mon Sep 17 00:00:00 2001
2 From: sandeepal <alsandeep@cem-solutions.net>
3 Date: Fri, 2 Jun 2017 18:59:46 +0530
4 Subject: [PATCH 088/454] Allo Digione Driver (#2048)
6 Driver for the Allo Digione soundcard
8 allo-digione: 192kHz clicking sound fix
10 See: https://github.com/raspberrypi/linux/pull/2149
12 sound/soc/bcm/Kconfig | 7 +
13 sound/soc/bcm/Makefile | 2 +
14 sound/soc/bcm/allo-digione.c | 265 +++++++++++++++++++++++++++++++++++
15 3 files changed, 274 insertions(+)
16 create mode 100644 sound/soc/bcm/allo-digione.c
18 --- a/sound/soc/bcm/Kconfig
19 +++ b/sound/soc/bcm/Kconfig
20 @@ -176,6 +176,13 @@ config SND_BCM2708_SOC_ALLO_BOSS_DAC
22 Say Y or M if you want to add support for Allo Boss DAC.
24 +config SND_BCM2708_SOC_ALLO_DIGIONE
25 + tristate "Support for Allo DigiOne"
26 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
27 + select SND_SOC_PCM512x_I2C
29 + Say Y or M if you want to add support for Allo DigiOne.
31 config SND_BCM2708_SOC_FE_PI_AUDIO
32 tristate "Support for Fe-Pi-Audio"
33 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
34 --- a/sound/soc/bcm/Makefile
35 +++ b/sound/soc/bcm/Makefile
36 @@ -34,6 +34,7 @@ snd-soc-dionaudio-loco-v2-objs := dionau
37 snd-soc-allo-boss-dac-objs := allo-boss-dac.o
38 snd-soc-allo-piano-dac-objs := allo-piano-dac.o
39 snd-soc-allo-piano-dac-plus-objs := allo-piano-dac-plus.o
40 +snd-soc-allo-digione-objs := allo-digione.o
41 snd-soc-pisound-objs := pisound.o
42 snd-soc-fe-pi-audio-objs := fe-pi-audio.o
44 @@ -60,5 +61,6 @@ obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_L
45 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += snd-soc-allo-boss-dac.o
46 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
47 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS) += snd-soc-allo-piano-dac-plus.o
48 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_DIGIONE) += snd-soc-allo-digione.o
49 obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o
50 obj-$(CONFIG_SND_BCM2708_SOC_FE_PI_AUDIO) += snd-soc-fe-pi-audio.o
52 +++ b/sound/soc/bcm/allo-digione.c
55 + * ASoC Driver for Allo DigiOne
57 + * Author: Baswaraj <jaikumar@cemsolutions.net>
59 + * based on code by Daniel Matuschek <info@crazy-audio.com>
60 + * based on code by Florian Meier <florian.meier@koalo.de>
62 + * This program is free software; you can redistribute it and/or
63 + * modify it under the terms of the GNU General Public License
64 + * version 2 as published by the Free Software Foundation.
66 + * This program is distributed in the hope that it will be useful, but
67 + * WITHOUT ANY WARRANTY; without even the implied warranty of
68 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
69 + * General Public License for more details.
72 +#include <linux/module.h>
73 +#include <linux/platform_device.h>
75 +#include <sound/core.h>
76 +#include <sound/pcm.h>
77 +#include <sound/pcm_params.h>
78 +#include <sound/soc.h>
79 +#include <sound/jack.h>
80 +#include <linux/gpio/consumer.h>
82 +#include "../codecs/wm8804.h"
84 +static short int auto_shutdown_output;
85 +module_param(auto_shutdown_output, short,
86 + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
87 +MODULE_PARM_DESC(auto_shutdown_output, "Shutdown SP/DIF output if playback is stopped");
89 +#define CLK_44EN_RATE 22579200UL
90 +#define CLK_48EN_RATE 24576000UL
92 +static struct gpio_desc *snd_allo_clk44gpio;
93 +static struct gpio_desc *snd_allo_clk48gpio;
95 +static int samplerate = 44100;
97 +static uint32_t snd_allo_digione_enable_clock(int sample_rate)
99 + switch (sample_rate) {
105 + gpiod_set_value_cansleep(snd_allo_clk44gpio, 1);
106 + gpiod_set_value_cansleep(snd_allo_clk48gpio, 0);
107 + return CLK_44EN_RATE;
109 + gpiod_set_value_cansleep(snd_allo_clk48gpio, 1);
110 + gpiod_set_value_cansleep(snd_allo_clk44gpio, 0);
111 + return CLK_48EN_RATE;
116 +static int snd_allo_digione_init(struct snd_soc_pcm_runtime *rtd)
118 + struct snd_soc_codec *codec = rtd->codec;
120 + /* enable TX output */
121 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
126 +static int snd_allo_digione_startup(struct snd_pcm_substream *substream)
128 + /* turn on digital output */
129 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
130 + struct snd_soc_codec *codec = rtd->codec;
132 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
136 +static void snd_allo_digione_shutdown(struct snd_pcm_substream *substream)
138 + /* turn off output */
139 + if (auto_shutdown_output) {
140 + /* turn off output */
141 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
142 + struct snd_soc_codec *codec = rtd->codec;
144 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
148 +static int snd_allo_digione_hw_params(struct snd_pcm_substream *substream,
149 + struct snd_pcm_hw_params *params)
151 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
152 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
153 + struct snd_soc_codec *codec = rtd->codec;
154 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
156 + int sysclk = 27000000; /* This is fixed on this board */
158 + long mclk_freq = 0;
160 + int sampling_freq = 1;
164 + samplerate = params_rate(params);
165 + mclk_freq = samplerate * 256;
166 + mclk_div = WM8804_MCLKDIV_256FS;
168 + sysclk = snd_allo_digione_enable_clock(samplerate);
170 + switch (samplerate) {
172 + sampling_freq = 0x03;
175 + sampling_freq = 0x00;
178 + sampling_freq = 0x02;
181 + sampling_freq = 0x08;
184 + sampling_freq = 0x0a;
187 + sampling_freq = 0x0c;
190 + sampling_freq = 0x0e;
193 + dev_err(codec->dev,
194 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
198 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
199 + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
201 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
202 + sysclk, SND_SOC_CLOCK_OUT);
205 + dev_err(codec->dev,
206 + "Failed to set WM8804 SYSCLK: %d\n", ret);
210 + /* Enable TX output */
211 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
214 + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
216 + /* set sampling frequency status bits */
217 + snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
219 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
222 +/* machine stream operations */
223 +static struct snd_soc_ops snd_allo_digione_ops = {
224 + .hw_params = snd_allo_digione_hw_params,
225 + .startup = snd_allo_digione_startup,
226 + .shutdown = snd_allo_digione_shutdown,
229 +static struct snd_soc_dai_link snd_allo_digione_dai[] = {
231 + .name = "Allo DigiOne",
232 + .stream_name = "Allo DigiOne HiFi",
233 + .cpu_dai_name = "bcm2708-i2s.0",
234 + .codec_dai_name = "wm8804-spdif",
235 + .platform_name = "bcm2708-i2s.0",
236 + .codec_name = "wm8804.1-003b",
237 + .dai_fmt = SND_SOC_DAIFMT_I2S |
238 + SND_SOC_DAIFMT_NB_NF |
239 + SND_SOC_DAIFMT_CBM_CFM,
240 + .ops = &snd_allo_digione_ops,
241 + .init = snd_allo_digione_init,
245 +/* audio machine driver */
246 +static struct snd_soc_card snd_allo_digione = {
247 + .name = "snd_allo_digione",
248 + .driver_name = "AlloDigiOne",
249 + .owner = THIS_MODULE,
250 + .dai_link = snd_allo_digione_dai,
251 + .num_links = ARRAY_SIZE(snd_allo_digione_dai),
254 +static int snd_allo_digione_probe(struct platform_device *pdev)
258 + snd_allo_digione.dev = &pdev->dev;
260 + if (pdev->dev.of_node) {
261 + struct device_node *i2s_node;
262 + struct snd_soc_dai_link *dai = &snd_allo_digione_dai[0];
264 + i2s_node = of_parse_phandle(pdev->dev.of_node,
265 + "i2s-controller", 0);
268 + dai->cpu_dai_name = NULL;
269 + dai->cpu_of_node = i2s_node;
270 + dai->platform_name = NULL;
271 + dai->platform_of_node = i2s_node;
274 + snd_allo_clk44gpio =
275 + devm_gpiod_get(&pdev->dev, "clock44", GPIOD_OUT_LOW);
276 + if (IS_ERR(snd_allo_clk44gpio))
277 + dev_err(&pdev->dev, "devm_gpiod_get() failed\n");
279 + snd_allo_clk48gpio =
280 + devm_gpiod_get(&pdev->dev, "clock48", GPIOD_OUT_LOW);
281 + if (IS_ERR(snd_allo_clk48gpio))
282 + dev_err(&pdev->dev, "devm_gpiod_get() failed\n");
285 + ret = snd_soc_register_card(&snd_allo_digione);
286 + if (ret && ret != -EPROBE_DEFER)
287 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
293 +static int snd_allo_digione_remove(struct platform_device *pdev)
295 + return snd_soc_unregister_card(&snd_allo_digione);
298 +static const struct of_device_id snd_allo_digione_of_match[] = {
299 + { .compatible = "allo,allo-digione", },
302 +MODULE_DEVICE_TABLE(of, snd_allo_digione_of_match);
304 +static struct platform_driver snd_allo_digione_driver = {
306 + .name = "snd-allo-digione",
307 + .owner = THIS_MODULE,
308 + .of_match_table = snd_allo_digione_of_match,
310 + .probe = snd_allo_digione_probe,
311 + .remove = snd_allo_digione_remove,
314 +module_platform_driver(snd_allo_digione_driver);
316 +MODULE_AUTHOR("Baswaraj <jaikumar@cem-solutions.net>");
317 +MODULE_DESCRIPTION("ASoC Driver for Allo DigiOne");
318 +MODULE_LICENSE("GPL v2");