bcm27xx: add linux 5.4 support
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0321-Add-Hifiberry-DAC-DSP-soundcard-driver-3224.patch
1 From 59c54c8b3b5afe051ca627fb42a685909b58d631 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?J=C3=B6rg=20Schambacher?=
3 <j-schambacher@users.noreply.github.com>
4 Date: Thu, 12 Sep 2019 14:57:32 +0200
5 Subject: [PATCH] Add Hifiberry DAC+DSP soundcard driver (#3224)
6
7 Adds the driver for the Hifiberry DAC+DSP. It supports capture and
8 playback depending on the DSP firmware.
9
10 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
11 ---
12 sound/soc/bcm/Kconfig | 7 ++
13 sound/soc/bcm/Makefile | 2 +
14 sound/soc/bcm/hifiberry_dacplusadcpro.c | 28 +++-----
15 sound/soc/bcm/hifiberry_dacplusdsp.c | 90 +++++++++++++++++++++++++
16 sound/soc/bcm/rpi-simple-soundcard.c | 23 +++++++
17 5 files changed, 132 insertions(+), 18 deletions(-)
18 create mode 100644 sound/soc/bcm/hifiberry_dacplusdsp.c
19
20 --- a/sound/soc/bcm/Kconfig
21 +++ b/sound/soc/bcm/Kconfig
22 @@ -59,6 +59,13 @@ config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
23 help
24 Say Y or M if you want to add support for HifiBerry DAC+ADC PRO.
25
26 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP
27 + tristate "Support for HifiBerry DAC+DSP"
28 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
29 + select SND_RPI_SIMPLE_SOUNDCARD
30 + help
31 + Say Y or M if you want to add support for HifiBerry DSP-DAC.
32 +
33 config SND_BCM2708_SOC_HIFIBERRY_DIGI
34 tristate "Support for HifiBerry Digi"
35 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
36 --- a/sound/soc/bcm/Makefile
37 +++ b/sound/soc/bcm/Makefile
38 @@ -16,6 +16,7 @@ snd-soc-googlevoicehat-codec-objs := goo
39 snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
40 snd-soc-hifiberry-dacplusadc-objs := hifiberry_dacplusadc.o
41 snd-soc-hifiberry-dacplusadcpro-objs := hifiberry_dacplusadcpro.o
42 +snd-soc-hifiberry-dacplusdsp-objs := hifiberry_dacplusdsp.o
43 snd-soc-justboom-dac-objs := justboom-dac.o
44 snd-soc-rpi-cirrus-objs := rpi-cirrus.o
45 snd-soc-rpi-proto-objs := rpi-proto.o
46 @@ -41,6 +42,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICE
47 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
48 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC) += snd-soc-hifiberry-dacplusadc.o
49 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO) += snd-soc-hifiberry-dacplusadcpro.o
50 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP) += snd-soc-hifiberry-dacplusdsp.o
51 obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
52 obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
53 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
54 --- a/sound/soc/bcm/hifiberry_dacplusadcpro.c
55 +++ b/sound/soc/bcm/hifiberry_dacplusadcpro.c
56 @@ -445,29 +445,21 @@ static struct snd_soc_ops snd_rpi_hifibe
57 .shutdown = snd_rpi_hifiberry_dacplusadcpro_shutdown,
58 };
59
60 -static struct snd_soc_dai_link_component snd_rpi_hifiberry_dacplusadcpro_codecs[] = {
61 - {
62 - .name = "pcm512x.1-004d",
63 - .dai_name = "pcm512x-hifi",
64 - },
65 - {
66 - .name = "pcm186x.1-004a",
67 - .dai_name = "pcm1863-aif",
68 - },
69 -};
70 +SND_SOC_DAILINK_DEFS(hifi,
71 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
72 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
73 + COMP_CODEC("pcm186x.1-004a", "pcm1863-aif")),
74 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
75
76 static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadcpro_dai[] = {
77 {
78 .name = "HiFiBerry DAC+ADC PRO",
79 .stream_name = "HiFiBerry DAC+ADC PRO HiFi",
80 - .cpu_dai_name = "bcm2708-i2s.0",
81 - .platform_name = "bcm2708-i2s.0",
82 - .codecs = snd_rpi_hifiberry_dacplusadcpro_codecs,
83 - .num_codecs = 2,
84 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
85 SND_SOC_DAIFMT_CBS_CFS,
86 .ops = &snd_rpi_hifiberry_dacplusadcpro_ops,
87 .init = snd_rpi_hifiberry_dacplusadcpro_init,
88 + SND_SOC_DAILINK_REG(hifi),
89 },
90 };
91
92 @@ -495,10 +487,10 @@ static int snd_rpi_hifiberry_dacplusadcp
93 "i2s-controller", 0);
94 if (i2s_node) {
95 for (i = 0; i < card->num_links; i++) {
96 - dai->cpu_dai_name = NULL;
97 - dai->cpu_of_node = i2s_node;
98 - dai->platform_name = NULL;
99 - dai->platform_of_node = i2s_node;
100 + dai->cpus->dai_name = NULL;
101 + dai->cpus->of_node = i2s_node;
102 + dai->platforms->name = NULL;
103 + dai->platforms->of_node = i2s_node;
104 }
105 }
106 }
107 --- /dev/null
108 +++ b/sound/soc/bcm/hifiberry_dacplusdsp.c
109 @@ -0,0 +1,90 @@
110 +// SPDX-License-Identifier: GPL-2.0
111 +/*
112 + * ASoC Driver for HiFiBerry DAC + DSP
113 + *
114 + * Author: Joerg Schambacher <joscha@schambacher.com>
115 + * Copyright 2018
116 + *
117 + * This program is free software; you can redistribute it and/or
118 + * modify it under the terms of the GNU General Public License
119 + * version 2 as published by the Free Software Foundation.
120 + *
121 + * This program is distributed in the hope that it will be useful, but
122 + * WITHOUT ANY WARRANTY; without even the implied warranty of
123 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
124 + * General Public License for more details.
125 + */
126 +
127 +#include <linux/init.h>
128 +#include <linux/module.h>
129 +#include <linux/of.h>
130 +#include <linux/platform_device.h>
131 +#include <sound/soc.h>
132 +
133 +static struct snd_soc_component_driver dacplusdsp_component_driver;
134 +
135 +static struct snd_soc_dai_driver dacplusdsp_dai = {
136 + .name = "dacplusdsp-hifi",
137 + .capture = {
138 + .stream_name = "DAC+DSP Capture",
139 + .channels_min = 2,
140 + .channels_max = 2,
141 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
142 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
143 + SNDRV_PCM_FMTBIT_S24_LE |
144 + SNDRV_PCM_FMTBIT_S32_LE,
145 + },
146 + .playback = {
147 + .stream_name = "DACP+DSP Playback",
148 + .channels_min = 2,
149 + .channels_max = 2,
150 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
151 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
152 + SNDRV_PCM_FMTBIT_S24_LE |
153 + SNDRV_PCM_FMTBIT_S32_LE,
154 + },
155 + .symmetric_rates = 1};
156 +
157 +#ifdef CONFIG_OF
158 +static const struct of_device_id dacplusdsp_ids[] = {
159 + {
160 + .compatible = "hifiberry,dacplusdsp",
161 + },
162 + {} };
163 +MODULE_DEVICE_TABLE(of, dacplusdsp_ids);
164 +#endif
165 +
166 +static int dacplusdsp_platform_probe(struct platform_device *pdev)
167 +{
168 + int ret;
169 +
170 + ret = snd_soc_register_component(&pdev->dev,
171 + &dacplusdsp_component_driver, &dacplusdsp_dai, 1);
172 + if (ret) {
173 + pr_alert("snd_soc_register_component failed\n");
174 + return ret;
175 + }
176 +
177 + return 0;
178 +}
179 +
180 +static int dacplusdsp_platform_remove(struct platform_device *pdev)
181 +{
182 + snd_soc_unregister_component(&pdev->dev);
183 + return 0;
184 +}
185 +
186 +static struct platform_driver dacplusdsp_driver = {
187 + .driver = {
188 + .name = "hifiberry-dacplusdsp-codec",
189 + .of_match_table = of_match_ptr(dacplusdsp_ids),
190 + },
191 + .probe = dacplusdsp_platform_probe,
192 + .remove = dacplusdsp_platform_remove,
193 +};
194 +
195 +module_platform_driver(dacplusdsp_driver);
196 +
197 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
198 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+DSP");
199 +MODULE_LICENSE("GPL v2");
200 --- a/sound/soc/bcm/rpi-simple-soundcard.c
201 +++ b/sound/soc/bcm/rpi-simple-soundcard.c
202 @@ -144,6 +144,27 @@ static struct snd_rpi_simple_drvdata drv
203 .dai = snd_googlevoicehat_soundcard_dai,
204 };
205
206 +SND_SOC_DAILINK_DEFS(hifiberry_dacplusdsp,
207 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
208 + DAILINK_COMP_ARRAY(COMP_CODEC("dacplusdsp-codec", "dacplusdsp-hifi")),
209 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
210 +
211 +static struct snd_soc_dai_link snd_hifiberrydacplusdsp_soundcard_dai[] = {
212 +{
213 + .name = "Hifiberry DAC+DSP SoundCard",
214 + .stream_name = "Hifiberry DAC+DSP SoundCard HiFi",
215 + .dai_fmt = SND_SOC_DAIFMT_I2S |
216 + SND_SOC_DAIFMT_NB_NF |
217 + SND_SOC_DAIFMT_CBS_CFS,
218 + SND_SOC_DAILINK_REG(hifiberry_dacplusdsp),
219 +},
220 +};
221 +
222 +static struct snd_rpi_simple_drvdata drvdata_hifiberrydacplusdsp = {
223 + .card_name = "snd_rpi_hifiberrydacplusdsp_soundcard",
224 + .dai = snd_hifiberrydacplusdsp_soundcard_dai,
225 +};
226 +
227 SND_SOC_DAILINK_DEFS(hifiberry_amp,
228 DAILINK_COMP_ARRAY(COMP_EMPTY()),
229 DAILINK_COMP_ARRAY(COMP_CODEC("tas5713.1-001b", "tas5713-hifi")),
230 @@ -213,6 +234,8 @@ static const struct of_device_id snd_rpi
231 .data = (void *) &drvdata_adau1977 },
232 { .compatible = "googlevoicehat,googlevoicehat-soundcard",
233 .data = (void *) &drvdata_googlevoicehat },
234 + { .compatible = "hifiberrydacplusdsp,hifiberrydacplusdsp-soundcard",
235 + .data = (void *) &drvdata_hifiberrydacplusdsp },
236 { .compatible = "hifiberry,hifiberry-amp",
237 .data = (void *) &drvdata_hifiberry_amp },
238 { .compatible = "hifiberry,hifiberry-dac",