e35806962ebf422a28d5fa3525f66e1e041f6765
[openwrt/staging/ldir.git] /
1 From 5b37b08ff1c29e7386eb8a29b168e94e33cf82c3 Mon Sep 17 00:00:00 2001
2 From: Matt Flax <flatmax@flatmax.org>
3 Date: Wed, 8 Apr 2020 20:00:30 +1000
4 Subject: [PATCH] Add support for the AudioInjector.net Isolated sound
5 card
6
7 This patch adds support for the Audio Injector Isolated sound card.
8
9 Signed-off-by: Matt Flax <flatmax@flatmax.org>
10 ---
11 arch/arm/boot/dts/overlays/Makefile | 1 +
12 arch/arm/boot/dts/overlays/README | 6 +
13 ...dioinjector-isolated-soundcard-overlay.dts | 55 ++++++
14 sound/soc/bcm/Kconfig | 7 +
15 sound/soc/bcm/Makefile | 2 +
16 .../bcm/audioinjector-isolated-soundcard.c | 183 ++++++++++++++++++
17 11 files changed, 259 insertions(+), 5 deletions(-)
18 create mode 100644 arch/arm/boot/dts/overlays/audioinjector-isolated-soundcard-overlay.dts
19 create mode 100644 sound/soc/bcm/audioinjector-isolated-soundcard.c
20
21 --- a/arch/arm/boot/dts/overlays/Makefile
22 +++ b/arch/arm/boot/dts/overlays/Makefile
23 @@ -22,6 +22,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
24 applepi-dac.dtbo \
25 at86rf233.dtbo \
26 audioinjector-addons.dtbo \
27 + audioinjector-isolated-soundcard.dtbo \
28 audioinjector-ultra.dtbo \
29 audioinjector-wm8731-audio.dtbo \
30 audiosense-pi.dtbo \
31 --- a/arch/arm/boot/dts/overlays/README
32 +++ b/arch/arm/boot/dts/overlays/README
33 @@ -505,6 +505,12 @@ Params: non-stop-clocks Keeps th
34 is paused or stopped (default off)
35
36
37 +Name: audioinjector-isolated-soundcard
38 +Info: Configures the audioinjector.net isolated soundcard
39 +Load: dtoverlay=audioinjector-isolated-soundcard
40 +Params: <None>
41 +
42 +
43 Name: audioinjector-ultra
44 Info: Configures the audioinjector.net ultra soundcard
45 Load: dtoverlay=audioinjector-ultra
46 --- /dev/null
47 +++ b/arch/arm/boot/dts/overlays/audioinjector-isolated-soundcard-overlay.dts
48 @@ -0,0 +1,55 @@
49 +// Definitions for audioinjector.net audio isolated soundcard
50 +/dts-v1/;
51 +/plugin/;
52 +
53 +/ {
54 + compatible = "brcm,bcm2835";
55 +
56 + fragment@0 {
57 + target = <&i2s>;
58 + __overlay__ {
59 + status = "okay";
60 + };
61 + };
62 +
63 + fragment@1 {
64 + target-path = "/";
65 + __overlay__ {
66 + cs4272_mclk: codec-mclk {
67 + compatible = "fixed-clock";
68 + #clock-cells = <0>;
69 + clock-frequency = <24576000>;
70 + };
71 + };
72 + };
73 +
74 + fragment@2 {
75 + target = <&i2c1>;
76 + __overlay__ {
77 + #address-cells = <1>;
78 + #size-cells = <0>;
79 + status = "okay";
80 +
81 + cs4272: cs4271@10 {
82 + #sound-dai-cells = <0>;
83 + compatible = "cirrus,cs4271";
84 + reg = <0x10>;
85 + reset-gpio = <&gpio 5 0>;
86 + clocks = <&cs4272_mclk>;
87 + clock-names = "mclk";
88 + status = "okay";
89 + };
90 + };
91 + };
92 +
93 + fragment@3 {
94 + target = <&sound>;
95 + snd: __overlay__ {
96 + compatible = "ai,audioinjector-isolated-soundcard";
97 + mute-gpios = <&gpio 17 0>;
98 + i2s-controller = <&i2s>;
99 + codec = <&cs4272>;
100 + status = "okay";
101 + };
102 + };
103 +};
104 --- a/sound/soc/bcm/Kconfig
105 +++ b/sound/soc/bcm/Kconfig
106 @@ -192,6 +192,13 @@ config SND_AUDIOINJECTOR_OCTO_SOUNDCARD
107 help
108 Say Y or M if you want to add support for audioinjector.net octo add on
109
110 +config SND_AUDIOINJECTOR_ISOLATED_SOUNDCARD
111 + tristate "Support for audioinjector.net isolated DAC and ADC soundcard"
112 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
113 + select SND_SOC_CS4271_I2C
114 + help
115 + Say Y or M if you want to add support for audioinjector.net isolated soundcard
116 +
117 config SND_AUDIOSENSE_PI
118 tristate "Support for AudioSense Add-On Soundcard"
119 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
120 --- a/sound/soc/bcm/Makefile
121 +++ b/sound/soc/bcm/Makefile
122 @@ -27,6 +27,7 @@ snd-soc-iqaudio-dac-objs := iqaudio-dac.
123 snd-soc-i-sabre-q2m-objs := i-sabre-q2m.o
124 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
125 snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
126 +snd-soc-audioinjector-isolated-soundcard-objs := audioinjector-isolated-soundcard.o
127 snd-soc-audiosense-pi-objs := audiosense-pi.o
128 snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
129 snd-soc-dionaudio-loco-objs := dionaudio_loco.o
130 @@ -55,6 +56,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC
131 obj-$(CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M) += snd-soc-i-sabre-q2m.o
132 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
133 obj-$(CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD) += snd-soc-audioinjector-octo-soundcard.o
134 +obj-$(CONFIG_SND_AUDIOINJECTOR_ISOLATED_SOUNDCARD) += snd-soc-audioinjector-isolated-soundcard.o
135 obj-$(CONFIG_SND_AUDIOSENSE_PI) += snd-soc-audiosense-pi.o
136 obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
137 obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
138 --- /dev/null
139 +++ b/sound/soc/bcm/audioinjector-isolated-soundcard.c
140 @@ -0,0 +1,183 @@
141 +/*
142 + * ASoC Driver for AudioInjector.net isolated soundcard
143 + *
144 + * Created on: 20-February-2020
145 + * Author: flatmax@flatmax.org
146 + * based on audioinjector-octo-soundcard.c
147 + *
148 + * Copyright (C) 2020 Flatmax Pty. Ltd.
149 + *
150 + * This program is free software; you can redistribute it and/or
151 + * modify it under the terms of the GNU General Public License
152 + * version 2 as published by the Free Software Foundation.
153 + *
154 + * This program is distributed in the hope that it will be useful, but
155 + * WITHOUT ANY WARRANTY; without even the implied warranty of
156 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
157 + * General Public License for more details.
158 + */
159 +
160 +#include <linux/module.h>
161 +#include <linux/types.h>
162 +#include <linux/gpio/consumer.h>
163 +
164 +#include <sound/core.h>
165 +#include <sound/soc.h>
166 +#include <sound/pcm_params.h>
167 +#include <sound/control.h>
168 +
169 +static struct gpio_desc *mute_gpio;
170 +
171 +static const unsigned int audioinjector_isolated_rates[] = {
172 + 192000, 96000, 48000, 32000, 24000, 16000, 8000
173 +};
174 +
175 +static struct snd_pcm_hw_constraint_list audioinjector_isolated_constraints = {
176 + .list = audioinjector_isolated_rates,
177 + .count = ARRAY_SIZE(audioinjector_isolated_rates),
178 +};
179 +
180 +static int audioinjector_isolated_dai_init(struct snd_soc_pcm_runtime *rtd)
181 +{
182 + int ret=snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 24576000, 0);
183 + if (ret)
184 + return ret;
185 +
186 + return snd_soc_dai_set_bclk_ratio(rtd->cpu_dai, 64);
187 +}
188 +
189 +static int audioinjector_isolated_startup(struct snd_pcm_substream *substream)
190 +{
191 + snd_pcm_hw_constraint_list(substream->runtime, 0,
192 + SNDRV_PCM_HW_PARAM_RATE, &audioinjector_isolated_constraints);
193 +
194 + return 0;
195 +}
196 +
197 +static int audioinjector_isolated_trigger(struct snd_pcm_substream *substream,
198 + int cmd){
199 +
200 + switch (cmd) {
201 + case SNDRV_PCM_TRIGGER_STOP:
202 + case SNDRV_PCM_TRIGGER_SUSPEND:
203 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
204 + gpiod_set_value(mute_gpio, 0);
205 + break;
206 + case SNDRV_PCM_TRIGGER_START:
207 + case SNDRV_PCM_TRIGGER_RESUME:
208 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
209 + gpiod_set_value(mute_gpio, 1);
210 + break;
211 + default:
212 + return -EINVAL;
213 + }
214 + return 0;
215 +}
216 +
217 +static struct snd_soc_ops audioinjector_isolated_ops = {
218 + .startup = audioinjector_isolated_startup,
219 + .trigger = audioinjector_isolated_trigger,
220 +};
221 +
222 +SND_SOC_DAILINK_DEFS(audioinjector_isolated,
223 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
224 + DAILINK_COMP_ARRAY(COMP_CODEC("cs4271.1-0010", "cs4271-hifi")),
225 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
226 +
227 +static struct snd_soc_dai_link audioinjector_isolated_dai[] = {
228 + {
229 + .name = "AudioInjector ISO",
230 + .stream_name = "AI-HIFI",
231 + .ops = &audioinjector_isolated_ops,
232 + .init = audioinjector_isolated_dai_init,
233 + .symmetric_rates = 1,
234 + .symmetric_channels = 1,
235 + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
236 + SND_SOC_DAILINK_REG(audioinjector_isolated),
237 + }
238 +};
239 +
240 +static const struct snd_soc_dapm_widget audioinjector_isolated_widgets[] = {
241 + SND_SOC_DAPM_OUTPUT("OUTPUTS"),
242 + SND_SOC_DAPM_INPUT("INPUTS"),
243 +};
244 +
245 +static const struct snd_soc_dapm_route audioinjector_isolated_route[] = {
246 + /* Balanced outputs */
247 + {"OUTPUTS", NULL, "AOUTA+"},
248 + {"OUTPUTS", NULL, "AOUTA-"},
249 + {"OUTPUTS", NULL, "AOUTB+"},
250 + {"OUTPUTS", NULL, "AOUTB-"},
251 +
252 + /* Balanced inputs */
253 + {"AINA", NULL, "INPUTS"},
254 + {"AINB", NULL, "INPUTS"},
255 +};
256 +
257 +static struct snd_soc_card snd_soc_audioinjector_isolated = {
258 + .name = "audioinjector-isolated-soundcard",
259 + .dai_link = audioinjector_isolated_dai,
260 + .num_links = ARRAY_SIZE(audioinjector_isolated_dai),
261 +
262 + .dapm_widgets = audioinjector_isolated_widgets,
263 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_isolated_widgets),
264 + .dapm_routes = audioinjector_isolated_route,
265 + .num_dapm_routes = ARRAY_SIZE(audioinjector_isolated_route),
266 +};
267 +
268 +static int audioinjector_isolated_probe(struct platform_device *pdev)
269 +{
270 + struct snd_soc_card *card = &snd_soc_audioinjector_isolated;
271 + int ret;
272 +
273 + card->dev = &pdev->dev;
274 +
275 + if (pdev->dev.of_node) {
276 + struct snd_soc_dai_link *dai = &audioinjector_isolated_dai[0];
277 + struct device_node *i2s_node =
278 + of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
279 +
280 + if (i2s_node) {
281 + dai->cpus->dai_name = NULL;
282 + dai->cpus->of_node = i2s_node;
283 + dai->platforms->name = NULL;
284 + dai->platforms->of_node = i2s_node;
285 + } else {
286 + dev_err(&pdev->dev,
287 + "i2s-controller missing or invalid in DT\n");
288 + return -EINVAL;
289 + }
290 +
291 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_LOW);
292 + if (IS_ERR(mute_gpio)){
293 + dev_err(&pdev->dev, "mute gpio not found in dt overlay\n");
294 + return PTR_ERR(mute_gpio);
295 + }
296 + }
297 +
298 + ret = devm_snd_soc_register_card(&pdev->dev, card);
299 + if (ret && ret != -EPROBE_DEFER)
300 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
301 + return ret;
302 +}
303 +
304 +static const struct of_device_id audioinjector_isolated_of_match[] = {
305 + { .compatible = "ai,audioinjector-isolated-soundcard", },
306 + {},
307 +};
308 +MODULE_DEVICE_TABLE(of, audioinjector_isolated_of_match);
309 +
310 +static struct platform_driver audioinjector_isolated_driver = {
311 + .driver = {
312 + .name = "audioinjector-isolated",
313 + .owner = THIS_MODULE,
314 + .of_match_table = audioinjector_isolated_of_match,
315 + },
316 + .probe = audioinjector_isolated_probe,
317 +};
318 +
319 +module_platform_driver(audioinjector_isolated_driver);
320 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
321 +MODULE_DESCRIPTION("AudioInjector.net isolated Soundcard");
322 +MODULE_LICENSE("GPL v2");
323 +MODULE_ALIAS("platform:audioinjector-isolated-soundcard");