52b3bca434e30e6b5a3b1f67ff1ebc9553bcd218
[openwrt/staging/noltari.git] / target / linux / brcm2708 / patches-4.19 / 950-0799-Add-Hifiberry-DAC-DSP-soundcard-driver-3224.patch
1 From f0715f5e178f2f7c0afb719a3a35c8ac250b7586 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 799/806] 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 arch/arm/boot/dts/overlays/Makefile | 1 +
13 arch/arm/boot/dts/overlays/README | 6 ++
14 .../overlays/hifiberry-dacplusdsp-overlay.dts | 34 +++++++
15 arch/arm/configs/bcm2709_defconfig | 1 +
16 arch/arm/configs/bcm2711_defconfig | 1 +
17 arch/arm/configs/bcmrpi_defconfig | 1 +
18 sound/soc/bcm/Kconfig | 7 ++
19 sound/soc/bcm/Makefile | 2 +
20 sound/soc/bcm/hifiberry_dacplusdsp.c | 90 +++++++++++++++++++
21 sound/soc/bcm/rpi-simple-soundcard.c | 19 ++++
22 10 files changed, 162 insertions(+)
23 create mode 100644 arch/arm/boot/dts/overlays/hifiberry-dacplusdsp-overlay.dts
24 create mode 100644 sound/soc/bcm/hifiberry_dacplusdsp.c
25
26 --- a/arch/arm/boot/dts/overlays/Makefile
27 +++ b/arch/arm/boot/dts/overlays/Makefile
28 @@ -54,6 +54,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
29 hifiberry-dacplus.dtbo \
30 hifiberry-dacplusadc.dtbo \
31 hifiberry-dacplusadcpro.dtbo \
32 + hifiberry-dacplusdsp.dtbo \
33 hifiberry-digi.dtbo \
34 hifiberry-digi-pro.dtbo \
35 hy28a.dtbo \
36 --- a/arch/arm/boot/dts/overlays/README
37 +++ b/arch/arm/boot/dts/overlays/README
38 @@ -904,6 +904,12 @@ Params: 24db_digital_gain Allow ga
39 master for bit clock and frame clock.
40
41
42 +Name: hifiberry-dacplusdsp
43 +Info: Configures the HifiBerry DAC+DSP audio card
44 +Load: dtoverlay=hifiberry-dacplusdsp
45 +Params: <None>
46 +
47 +
48 Name: hifiberry-digi
49 Info: Configures the HifiBerry Digi and Digi+ audio card
50 Load: dtoverlay=hifiberry-digi
51 --- /dev/null
52 +++ b/arch/arm/boot/dts/overlays/hifiberry-dacplusdsp-overlay.dts
53 @@ -0,0 +1,34 @@
54 +// Definitions for hifiberry DAC+DSP soundcard overlay
55 +/dts-v1/;
56 +/plugin/;
57 +
58 +/ {
59 + compatible = "brcm,bcm2835";
60 +
61 + fragment@0 {
62 + target = <&i2s>;
63 + __overlay__ {
64 + status = "okay";
65 + };
66 + };
67 +
68 + fragment@1 {
69 + target-path = "/";
70 + __overlay__ {
71 + dacplusdsp-codec {
72 + #sound-dai-cells = <0>;
73 + compatible = "hifiberry,dacplusdsp";
74 + status = "okay";
75 + };
76 + };
77 + };
78 +
79 + fragment@2 {
80 + target = <&sound>;
81 + __overlay__ {
82 + compatible = "hifiberrydacplusdsp,hifiberrydacplusdsp-soundcard";
83 + i2s-controller = <&i2s>;
84 + status = "okay";
85 + };
86 + };
87 +};
88 --- a/arch/arm/configs/bcm2709_defconfig
89 +++ b/arch/arm/configs/bcm2709_defconfig
90 @@ -970,6 +970,7 @@ CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
91 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
92 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC=m
93 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO=m
94 +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP=m
95 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
96 CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
97 CONFIG_SND_BCM2708_SOC_RPI_CIRRUS=m
98 --- a/arch/arm/configs/bcm2711_defconfig
99 +++ b/arch/arm/configs/bcm2711_defconfig
100 @@ -981,6 +981,7 @@ CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
101 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
102 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC=m
103 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO=m
104 +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP=m
105 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
106 CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
107 CONFIG_SND_BCM2708_SOC_RPI_CIRRUS=m
108 --- a/arch/arm/configs/bcmrpi_defconfig
109 +++ b/arch/arm/configs/bcmrpi_defconfig
110 @@ -962,6 +962,7 @@ CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
111 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
112 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC=m
113 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO=m
114 +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP=m
115 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
116 CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
117 CONFIG_SND_BCM2708_SOC_RPI_CIRRUS=m
118 --- a/sound/soc/bcm/Kconfig
119 +++ b/sound/soc/bcm/Kconfig
120 @@ -56,6 +56,13 @@ config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
121 help
122 Say Y or M if you want to add support for HifiBerry DAC+ADC PRO.
123
124 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP
125 + tristate "Support for HifiBerry DAC+DSP"
126 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
127 + select SND_RPI_SIMPLE_SOUNDCARD
128 + help
129 + Say Y or M if you want to add support for HifiBerry DSP-DAC.
130 +
131 config SND_BCM2708_SOC_HIFIBERRY_DIGI
132 tristate "Support for HifiBerry Digi"
133 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
134 --- a/sound/soc/bcm/Makefile
135 +++ b/sound/soc/bcm/Makefile
136 @@ -15,6 +15,7 @@ snd-soc-googlevoicehat-codec-objs := goo
137 snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
138 snd-soc-hifiberry-dacplusadc-objs := hifiberry_dacplusadc.o
139 snd-soc-hifiberry-dacplusadcpro-objs := hifiberry_dacplusadcpro.o
140 +snd-soc-hifiberry-dacplusdsp-objs := hifiberry_dacplusdsp.o
141 snd-soc-justboom-dac-objs := justboom-dac.o
142 snd-soc-rpi-cirrus-objs := rpi-cirrus.o
143 snd-soc-rpi-proto-objs := rpi-proto.o
144 @@ -40,6 +41,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICE
145 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
146 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC) += snd-soc-hifiberry-dacplusadc.o
147 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO) += snd-soc-hifiberry-dacplusadcpro.o
148 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP) += snd-soc-hifiberry-dacplusdsp.o
149 obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
150 obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
151 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
152 --- /dev/null
153 +++ b/sound/soc/bcm/hifiberry_dacplusdsp.c
154 @@ -0,0 +1,90 @@
155 +// SPDX-License-Identifier: GPL-2.0
156 +/*
157 + * ASoC Driver for HiFiBerry DAC + DSP
158 + *
159 + * Author: Joerg Schambacher <joscha@schambacher.com>
160 + * Copyright 2018
161 + *
162 + * This program is free software; you can redistribute it and/or
163 + * modify it under the terms of the GNU General Public License
164 + * version 2 as published by the Free Software Foundation.
165 + *
166 + * This program is distributed in the hope that it will be useful, but
167 + * WITHOUT ANY WARRANTY; without even the implied warranty of
168 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
169 + * General Public License for more details.
170 + */
171 +
172 +#include <linux/init.h>
173 +#include <linux/module.h>
174 +#include <linux/of.h>
175 +#include <linux/platform_device.h>
176 +#include <sound/soc.h>
177 +
178 +static struct snd_soc_component_driver dacplusdsp_component_driver;
179 +
180 +static struct snd_soc_dai_driver dacplusdsp_dai = {
181 + .name = "dacplusdsp-hifi",
182 + .capture = {
183 + .stream_name = "DAC+DSP Capture",
184 + .channels_min = 2,
185 + .channels_max = 2,
186 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
187 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
188 + SNDRV_PCM_FMTBIT_S24_LE |
189 + SNDRV_PCM_FMTBIT_S32_LE,
190 + },
191 + .playback = {
192 + .stream_name = "DACP+DSP Playback",
193 + .channels_min = 2,
194 + .channels_max = 2,
195 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
196 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
197 + SNDRV_PCM_FMTBIT_S24_LE |
198 + SNDRV_PCM_FMTBIT_S32_LE,
199 + },
200 + .symmetric_rates = 1};
201 +
202 +#ifdef CONFIG_OF
203 +static const struct of_device_id dacplusdsp_ids[] = {
204 + {
205 + .compatible = "hifiberry,dacplusdsp",
206 + },
207 + {} };
208 +MODULE_DEVICE_TABLE(of, dacplusdsp_ids);
209 +#endif
210 +
211 +static int dacplusdsp_platform_probe(struct platform_device *pdev)
212 +{
213 + int ret;
214 +
215 + ret = snd_soc_register_component(&pdev->dev,
216 + &dacplusdsp_component_driver, &dacplusdsp_dai, 1);
217 + if (ret) {
218 + pr_alert("snd_soc_register_component failed\n");
219 + return ret;
220 + }
221 +
222 + return 0;
223 +}
224 +
225 +static int dacplusdsp_platform_remove(struct platform_device *pdev)
226 +{
227 + snd_soc_unregister_component(&pdev->dev);
228 + return 0;
229 +}
230 +
231 +static struct platform_driver dacplusdsp_driver = {
232 + .driver = {
233 + .name = "hifiberry-dacplusdsp-codec",
234 + .of_match_table = of_match_ptr(dacplusdsp_ids),
235 + },
236 + .probe = dacplusdsp_platform_probe,
237 + .remove = dacplusdsp_platform_remove,
238 +};
239 +
240 +module_platform_driver(dacplusdsp_driver);
241 +
242 +MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
243 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+DSP");
244 +MODULE_LICENSE("GPL v2");
245 --- a/sound/soc/bcm/rpi-simple-soundcard.c
246 +++ b/sound/soc/bcm/rpi-simple-soundcard.c
247 @@ -136,6 +136,23 @@ static struct snd_rpi_simple_drvdata drv
248 .dai = snd_googlevoicehat_soundcard_dai,
249 };
250
251 +static struct snd_soc_dai_link snd_hifiberrydacplusdsp_soundcard_dai[] = {
252 +{
253 + .name = "Hifiberry DAC+DSP SoundCard",
254 + .stream_name = "Hifiberry DAC+DSP SoundCard HiFi",
255 + .codec_dai_name = "dacplusdsp-hifi",
256 + .codec_name = "dacplusdsp-codec",
257 + .dai_fmt = SND_SOC_DAIFMT_I2S |
258 + SND_SOC_DAIFMT_NB_NF |
259 + SND_SOC_DAIFMT_CBS_CFS,
260 +},
261 +};
262 +
263 +static struct snd_rpi_simple_drvdata drvdata_hifiberrydacplusdsp = {
264 + .card_name = "snd_rpi_hifiberrydacplusdsp_soundcard",
265 + .dai = snd_hifiberrydacplusdsp_soundcard_dai,
266 +};
267 +
268 static struct snd_soc_dai_link snd_hifiberry_amp_dai[] = {
269 {
270 .name = "HifiBerry AMP",
271 @@ -193,6 +210,8 @@ static const struct of_device_id snd_rpi
272 .data = (void *) &drvdata_adau1977 },
273 { .compatible = "googlevoicehat,googlevoicehat-soundcard",
274 .data = (void *) &drvdata_googlevoicehat },
275 + { .compatible = "hifiberrydacplusdsp,hifiberrydacplusdsp-soundcard",
276 + .data = (void *) &drvdata_hifiberrydacplusdsp },
277 { .compatible = "hifiberry,hifiberry-amp",
278 .data = (void *) &drvdata_hifiberry_amp },
279 { .compatible = "hifiberry,hifiberry-dac",