1 --- linux-5.9.orig/sound/soc/bcm/Kconfig 2020-10-11 23:15:50.000000000 +0200
2 +++ linux-5.9/sound/soc/bcm/Kconfig 2020-12-14 01:08:25.450035831 +0100
4 DSL/PON chips (bcm63158, bcm63178)
6 If you don't know what to do here, say N
8 +config SND_BCM2708_SOC_HIFIBERRY_DIGI
9 + tristate "Support for HifiBerry Digi"
10 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
11 + select SND_SOC_WM8804
13 + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
14 --- linux-5.9.orig/sound/soc/bcm/Makefile 2020-10-11 23:15:50.000000000 +0200
15 +++ linux-5.9/sound/soc/bcm/Makefile 2020-12-14 01:05:51.274295380 +0100
17 # BCM63XX Platform Support
18 snd-soc-63xx-objs := bcm63xx-i2s-whistler.o bcm63xx-pcm-whistler.o
20 -obj-$(CONFIG_SND_BCM63XX_I2S_WHISTLER) += snd-soc-63xx.o
21 \ No newline at end of file
22 +obj-$(CONFIG_SND_BCM63XX_I2S_WHISTLER) += snd-soc-63xx.o
24 +snd-soc-rpi-wm8804-soundcard-objs := rpi-wm8804-soundcard.o
26 +obj-$(CONFIG_SND_RPI_WM8804_SOUNDCARD) += snd-soc-rpi-wm8804-soundcard.o
27 --- linux-5.9.orig/sound/soc/bcm/rpi-wm8804-soundcard.c 1970-01-01 01:00:00.000000000 +0100
28 +++ linux-5.9/sound/soc/bcm/rpi-wm8804-soundcard.c 2020-12-14 01:02:38.688758934 +0100
30 +// SPDX-License-Identifier: GPL-2.0
32 + * rpi--wm8804.c -- ALSA SoC Raspberry Pi soundcard.
34 + * Copyright (C) 2018 Raspberry Pi.
36 + * Authors: Tim Gover <tim.gover@raspberrypi.org>
38 + * Generic driver for Pi Hat WM8804 digi sounds cards
40 + * Based upon code from:
42 + * by Milan Neskovic <info@justboom.co>
45 + * by Daniel Matuschek <info@crazy-audio.com>
48 + * by Baswaraj <jaikumar@cem-solutions.net>
51 + * Daniel Matuschek <info@crazy-audio.com>
53 + * This program is free software; you can redistribute it and/or
54 + * modify it under the terms of the GNU General Public License
55 + * version 2 as published by the Free Software Foundation.
57 + * This program is distributed in the hope that it will be useful, but
58 + * WITHOUT ANY WARRANTY; without even the implied warranty of
59 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60 + * General Public License for more details.
63 +#include <linux/gpio/consumer.h>
64 +#include <linux/platform_device.h>
65 +#include <linux/module.h>
67 +#include <sound/core.h>
68 +#include <sound/pcm.h>
69 +#include <sound/pcm_params.h>
70 +#include <sound/soc.h>
72 +#include "../codecs/wm8804.h"
74 +struct wm8804_clk_cfg {
75 + unsigned int sysclk_freq;
76 + unsigned int mclk_freq;
77 + unsigned int mclk_div;
80 +/* Parameters for generic functions */
81 +struct snd_rpi_wm8804_drvdata {
82 + /* Required - pointer to the DAI structure */
83 + struct snd_soc_dai_link *dai;
84 + /* Required - snd_soc_card name */
85 + const char *card_name;
86 + /* Optional DT node names if card info is defined in DT */
87 + const char *card_name_dt;
88 + const char *dai_name_dt;
89 + const char *dai_stream_name_dt;
90 + /* Optional probe extension - called prior to register_card */
91 + int (*probe)(struct platform_device *pdev);
94 +static struct gpio_desc *snd_clk44gpio;
95 +static struct gpio_desc *snd_clk48gpio;
96 +static int wm8804_samplerate = 0;
98 +/* Forward declarations */
99 +static struct snd_soc_dai_link snd_allo_digione_dai[];
100 +static struct snd_soc_card snd_rpi_wm8804;
103 +#define CLK_44EN_RATE 22579200UL
104 +#define CLK_48EN_RATE 24576000UL
106 +static unsigned int snd_rpi_wm8804_enable_clock(unsigned int samplerate)
108 + switch (samplerate) {
114 + gpiod_set_value_cansleep(snd_clk44gpio, 1);
115 + gpiod_set_value_cansleep(snd_clk48gpio, 0);
116 + return CLK_44EN_RATE;
118 + gpiod_set_value_cansleep(snd_clk48gpio, 1);
119 + gpiod_set_value_cansleep(snd_clk44gpio, 0);
120 + return CLK_48EN_RATE;
124 +static void snd_rpi_wm8804_clk_cfg(unsigned int samplerate,
125 + struct wm8804_clk_cfg *clk_cfg)
127 + clk_cfg->sysclk_freq = 27000000;
129 + if (samplerate <= 96000 ||
130 + snd_rpi_wm8804.dai_link == snd_allo_digione_dai) {
131 + clk_cfg->mclk_freq = samplerate * 256;
132 + clk_cfg->mclk_div = WM8804_MCLKDIV_256FS;
134 + clk_cfg->mclk_freq = samplerate * 128;
135 + clk_cfg->mclk_div = WM8804_MCLKDIV_128FS;
138 + if (!(IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)))
139 + clk_cfg->sysclk_freq = snd_rpi_wm8804_enable_clock(samplerate);
142 +static int snd_rpi_wm8804_hw_params(struct snd_pcm_substream *substream,
143 + struct snd_pcm_hw_params *params)
145 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
146 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
147 + struct snd_soc_component *component = rtd->codec_dai->component;
148 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
149 + int sampling_freq = 1;
151 + struct wm8804_clk_cfg clk_cfg;
152 + int samplerate = params_rate(params);
154 + if (samplerate == wm8804_samplerate)
157 + /* clear until all clocks are setup properly */
158 + wm8804_samplerate = 0;
160 + snd_rpi_wm8804_clk_cfg(samplerate, &clk_cfg);
162 + pr_debug("%s samplerate: %d mclk_freq: %u mclk_div: %u sysclk: %u\n",
163 + __func__, samplerate, clk_cfg.mclk_freq,
164 + clk_cfg.mclk_div, clk_cfg.sysclk_freq);
166 + switch (samplerate) {
168 + sampling_freq = 0x03;
171 + sampling_freq = 0x00;
174 + sampling_freq = 0x02;
177 + sampling_freq = 0x08;
180 + sampling_freq = 0x0a;
183 + sampling_freq = 0x0c;
186 + sampling_freq = 0x0e;
189 + dev_err(rtd->card->dev,
190 + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
194 + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, clk_cfg.mclk_div);
195 + snd_soc_dai_set_pll(codec_dai, 0, 0,
196 + clk_cfg.sysclk_freq, clk_cfg.mclk_freq);
198 + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
199 + clk_cfg.sysclk_freq, SND_SOC_CLOCK_OUT);
201 + dev_err(rtd->card->dev,
202 + "Failed to set WM8804 SYSCLK: %d\n", ret);
206 + wm8804_samplerate = samplerate;
208 + /* set sampling frequency status bits */
209 + snd_soc_component_update_bits(component, WM8804_SPDTX4, 0x0f,
212 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
215 +static struct snd_soc_ops snd_rpi_wm8804_ops = {
216 + .hw_params = snd_rpi_wm8804_hw_params,
219 +SND_SOC_DAILINK_DEFS(justboom_digi,
220 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
221 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
222 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
224 +static struct snd_soc_dai_link snd_justboom_digi_dai[] = {
226 + .name = "JustBoom Digi",
227 + .stream_name = "JustBoom Digi HiFi",
228 + SND_SOC_DAILINK_REG(justboom_digi),
232 +static struct snd_rpi_wm8804_drvdata drvdata_justboom_digi = {
233 + .card_name = "snd_rpi_justboom_digi",
234 + .dai = snd_justboom_digi_dai,
237 +SND_SOC_DAILINK_DEFS(iqaudio_digi,
238 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
239 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
240 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
242 +static struct snd_soc_dai_link snd_iqaudio_digi_dai[] = {
244 + .name = "IQAudIO Digi",
245 + .stream_name = "IQAudIO Digi HiFi",
246 + SND_SOC_DAILINK_REG(iqaudio_digi),
250 +static struct snd_rpi_wm8804_drvdata drvdata_iqaudio_digi = {
251 + .card_name = "IQAudIODigi",
252 + .dai = snd_iqaudio_digi_dai,
253 + .card_name_dt = "wm8804-digi,card-name",
254 + .dai_name_dt = "wm8804-digi,dai-name",
255 + .dai_stream_name_dt = "wm8804-digi,dai-stream-name",
258 +static int snd_allo_digione_probe(struct platform_device *pdev)
260 + pr_debug("%s\n", __func__);
262 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio)) {
263 + dev_err(&pdev->dev, "devm_gpiod_get() failed\n");
269 +SND_SOC_DAILINK_DEFS(allo_digione,
270 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
271 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
272 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
274 +static struct snd_soc_dai_link snd_allo_digione_dai[] = {
276 + .name = "Allo DigiOne",
277 + .stream_name = "Allo DigiOne HiFi",
278 + SND_SOC_DAILINK_REG(allo_digione),
282 +static struct snd_rpi_wm8804_drvdata drvdata_allo_digione = {
283 + .card_name = "snd_allo_digione",
284 + .dai = snd_allo_digione_dai,
285 + .probe = snd_allo_digione_probe,
288 +SND_SOC_DAILINK_DEFS(hifiberry_digi,
289 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
290 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
291 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
293 +static struct snd_soc_dai_link snd_hifiberry_digi_dai[] = {
295 + .name = "HifiBerry Digi",
296 + .stream_name = "HifiBerry Digi HiFi",
297 + SND_SOC_DAILINK_REG(hifiberry_digi),
301 +static int snd_hifiberry_digi_probe(struct platform_device *pdev)
303 + pr_debug("%s\n", __func__);
305 + if (IS_ERR(snd_clk44gpio) || IS_ERR(snd_clk48gpio))
308 + snd_hifiberry_digi_dai->name = "HiFiBerry Digi+ Pro";
309 + snd_hifiberry_digi_dai->stream_name = "HiFiBerry Digi+ Pro HiFi";
313 +static struct snd_rpi_wm8804_drvdata drvdata_hifiberry_digi = {
314 + .card_name = "snd_rpi_hifiberry_digi",
315 + .dai = snd_hifiberry_digi_dai,
316 + .probe = snd_hifiberry_digi_probe,
319 +static const struct of_device_id snd_rpi_wm8804_of_match[] = {
320 + { .compatible = "justboom,justboom-digi",
321 + .data = (void *) &drvdata_justboom_digi },
322 + { .compatible = "iqaudio,wm8804-digi",
323 + .data = (void *) &drvdata_iqaudio_digi },
324 + { .compatible = "allo,allo-digione",
325 + .data = (void *) &drvdata_allo_digione },
326 + { .compatible = "hifiberry,hifiberry-digi",
327 + .data = (void *) &drvdata_hifiberry_digi },
331 +static struct snd_soc_card snd_rpi_wm8804 = {
332 + .driver_name = "RPi-WM8804",
333 + .owner = THIS_MODULE,
338 +static int snd_rpi_wm8804_probe(struct platform_device *pdev)
341 + const struct of_device_id *of_id;
343 + snd_rpi_wm8804.dev = &pdev->dev;
344 + of_id = of_match_node(snd_rpi_wm8804_of_match, pdev->dev.of_node);
346 + if (pdev->dev.of_node && of_id->data) {
347 + struct device_node *i2s_node;
348 + struct snd_rpi_wm8804_drvdata *drvdata =
349 + (struct snd_rpi_wm8804_drvdata *) of_id->data;
350 + struct snd_soc_dai_link *dai = drvdata->dai;
352 + snd_soc_card_set_drvdata(&snd_rpi_wm8804, drvdata);
355 + dai->ops = &snd_rpi_wm8804_ops;
356 + if (!dai->codecs->dai_name)
357 + dai->codecs->dai_name = "wm8804-spdif";
358 + if (!dai->codecs->name)
359 + dai->codecs->name = "wm8804.1-003b";
361 + dai->dai_fmt = SND_SOC_DAIFMT_I2S |
362 + SND_SOC_DAIFMT_NB_NF |
363 + SND_SOC_DAIFMT_CBM_CFM;
365 + snd_rpi_wm8804.dai_link = dai;
366 + i2s_node = of_parse_phandle(pdev->dev.of_node,
367 + "i2s-controller", 0);
369 + pr_err("Failed to find i2s-controller DT node\n");
373 + snd_rpi_wm8804.name = drvdata->card_name;
375 + /* If requested by in drvdata get card & DAI names from DT */
376 + if (drvdata->card_name_dt)
377 + of_property_read_string(i2s_node,
378 + drvdata->card_name_dt,
379 + &snd_rpi_wm8804.name);
381 + if (drvdata->dai_name_dt)
382 + of_property_read_string(i2s_node,
383 + drvdata->dai_name_dt,
386 + if (drvdata->dai_stream_name_dt)
387 + of_property_read_string(i2s_node,
388 + drvdata->dai_stream_name_dt,
389 + &dai->stream_name);
391 + dai->cpus->of_node = i2s_node;
392 + dai->platforms->of_node = i2s_node;
395 + * clk44gpio and clk48gpio are not required by all cards so
396 + * don't check the error status.
399 + devm_gpiod_get(&pdev->dev, "clock44", GPIOD_OUT_LOW);
402 + devm_gpiod_get(&pdev->dev, "clock48", GPIOD_OUT_LOW);
404 + if (drvdata->probe) {
405 + ret = drvdata->probe(pdev);
407 + dev_err(&pdev->dev, "Custom probe failed %d\n",
413 + pr_debug("%s card: %s dai: %s stream: %s\n", __func__,
414 + snd_rpi_wm8804.name,
415 + dai->name, dai->stream_name);
418 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_wm8804);
419 + if (ret && ret != -EPROBE_DEFER)
420 + dev_err(&pdev->dev, "Failed to register card %d\n", ret);
425 +static struct platform_driver snd_rpi_wm8804_driver = {
427 + .name = "snd-rpi-wm8804",
428 + .owner = THIS_MODULE,
429 + .of_match_table = snd_rpi_wm8804_of_match,
431 + .probe = snd_rpi_wm8804_probe,
433 +MODULE_DEVICE_TABLE(of, snd_rpi_wm8804_of_match);
435 +module_platform_driver(snd_rpi_wm8804_driver);
437 +MODULE_AUTHOR("Tim Gover <tim.gover@raspberrypi.org>");
438 +MODULE_DESCRIPTION("ASoC Raspberry Pi Hat generic digi driver for WM8804 based cards");
439 +MODULE_LICENSE("GPL v2");