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
7 This patch adds support for the Audio Injector Isolated sound card.
9 Signed-off-by: Matt Flax <flatmax@flatmax.org>
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
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) += \
26 audioinjector-addons.dtbo \
27 + audioinjector-isolated-soundcard.dtbo \
28 audioinjector-ultra.dtbo \
29 audioinjector-wm8731-audio.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)
37 +Name: audioinjector-isolated-soundcard
38 +Info: Configures the audioinjector.net isolated soundcard
39 +Load: dtoverlay=audioinjector-isolated-soundcard
43 Name: audioinjector-ultra
44 Info: Configures the audioinjector.net ultra soundcard
45 Load: dtoverlay=audioinjector-ultra
47 +++ b/arch/arm/boot/dts/overlays/audioinjector-isolated-soundcard-overlay.dts
49 +// Definitions for audioinjector.net audio isolated soundcard
54 + compatible = "brcm,bcm2835";
66 + cs4272_mclk: codec-mclk {
67 + compatible = "fixed-clock";
69 + clock-frequency = <24576000>;
77 + #address-cells = <1>;
82 + #sound-dai-cells = <0>;
83 + compatible = "cirrus,cs4271";
85 + reset-gpio = <&gpio 5 0>;
86 + clocks = <&cs4272_mclk>;
87 + clock-names = "mclk";
96 + compatible = "ai,audioinjector-isolated-soundcard";
97 + mute-gpios = <&gpio 17 0>;
98 + i2s-controller = <&i2s>;
104 --- a/sound/soc/bcm/Kconfig
105 +++ b/sound/soc/bcm/Kconfig
106 @@ -192,6 +192,13 @@ config SND_AUDIOINJECTOR_OCTO_SOUNDCARD
108 Say Y or M if you want to add support for audioinjector.net octo add on
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
115 + Say Y or M if you want to add support for audioinjector.net isolated soundcard
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
139 +++ b/sound/soc/bcm/audioinjector-isolated-soundcard.c
142 + * ASoC Driver for AudioInjector.net isolated soundcard
144 + * Created on: 20-February-2020
145 + * Author: flatmax@flatmax.org
146 + * based on audioinjector-octo-soundcard.c
148 + * Copyright (C) 2020 Flatmax Pty. Ltd.
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.
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.
160 +#include <linux/module.h>
161 +#include <linux/types.h>
162 +#include <linux/gpio/consumer.h>
164 +#include <sound/core.h>
165 +#include <sound/soc.h>
166 +#include <sound/pcm_params.h>
167 +#include <sound/control.h>
169 +static struct gpio_desc *mute_gpio;
171 +static const unsigned int audioinjector_isolated_rates[] = {
172 + 192000, 96000, 48000, 32000, 24000, 16000, 8000
175 +static struct snd_pcm_hw_constraint_list audioinjector_isolated_constraints = {
176 + .list = audioinjector_isolated_rates,
177 + .count = ARRAY_SIZE(audioinjector_isolated_rates),
180 +static int audioinjector_isolated_dai_init(struct snd_soc_pcm_runtime *rtd)
182 + int ret=snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 24576000, 0);
186 + return snd_soc_dai_set_bclk_ratio(rtd->cpu_dai, 64);
189 +static int audioinjector_isolated_startup(struct snd_pcm_substream *substream)
191 + snd_pcm_hw_constraint_list(substream->runtime, 0,
192 + SNDRV_PCM_HW_PARAM_RATE, &audioinjector_isolated_constraints);
197 +static int audioinjector_isolated_trigger(struct snd_pcm_substream *substream,
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);
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);
217 +static struct snd_soc_ops audioinjector_isolated_ops = {
218 + .startup = audioinjector_isolated_startup,
219 + .trigger = audioinjector_isolated_trigger,
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")));
227 +static struct snd_soc_dai_link audioinjector_isolated_dai[] = {
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),
240 +static const struct snd_soc_dapm_widget audioinjector_isolated_widgets[] = {
241 + SND_SOC_DAPM_OUTPUT("OUTPUTS"),
242 + SND_SOC_DAPM_INPUT("INPUTS"),
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-"},
252 + /* Balanced inputs */
253 + {"AINA", NULL, "INPUTS"},
254 + {"AINB", NULL, "INPUTS"},
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),
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),
268 +static int audioinjector_isolated_probe(struct platform_device *pdev)
270 + struct snd_soc_card *card = &snd_soc_audioinjector_isolated;
273 + card->dev = &pdev->dev;
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);
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;
286 + dev_err(&pdev->dev,
287 + "i2s-controller missing or invalid in DT\n");
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);
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);
304 +static const struct of_device_id audioinjector_isolated_of_match[] = {
305 + { .compatible = "ai,audioinjector-isolated-soundcard", },
308 +MODULE_DEVICE_TABLE(of, audioinjector_isolated_of_match);
310 +static struct platform_driver audioinjector_isolated_driver = {
312 + .name = "audioinjector-isolated",
313 + .owner = THIS_MODULE,
314 + .of_match_table = audioinjector_isolated_of_match,
316 + .probe = audioinjector_isolated_probe,
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");