1 From 9dc67d61a5cd72eb80482aa1540e08a51e37172c Mon Sep 17 00:00:00 2001
2 From: Matt Flax <flatmax@flatmax.org>
3 Date: Wed, 8 Mar 2017 20:04:13 +1100
4 Subject: [PATCH 086/454] Add support for the AudioInjector.net Octo sound card
6 AudioInjector Octo: sample rates, regulators, reset
8 This patch adds new sample rates to the Audioinjector Octo sound card. The
9 new supported rates are (in kHz) :
10 96, 48, 32, 24, 16, 8, 88.2, 44.1, 29.4, 22.05, 14.7
12 Reference the bcm270x DT regulators in the overlay.
14 This patch adds a reset GPIO for the AudioInjector.net octo sound card.
16 Audioinjector octo : Make the playback and capture symmetric
18 This patch ensures that the sample rate and channel count of the audioinjector
19 octo sound card are symmetric.
21 sound/soc/bcm/Kconfig | 7 +
22 sound/soc/bcm/Makefile | 2 +
23 sound/soc/bcm/audioinjector-octo-soundcard.c | 341 +++++++++++++++++++
24 3 files changed, 350 insertions(+)
25 create mode 100644 sound/soc/bcm/audioinjector-octo-soundcard.c
27 --- a/sound/soc/bcm/Kconfig
28 +++ b/sound/soc/bcm/Kconfig
29 @@ -119,6 +119,13 @@ config SND_AUDIOINJECTOR_PI_SOUNDCARD
31 Say Y or M if you want to add support for audioinjector.net Pi Hat
33 +config SND_AUDIOINJECTOR_OCTO_SOUNDCARD
34 + tristate "Support for audioinjector.net Octo channel (Hat) soundcard"
35 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
36 + select SND_SOC_CS42XX8_I2C
38 + Say Y or M if you want to add support for audioinjector.net octo add on
40 config SND_DIGIDAC1_SOUNDCARD
41 tristate "Support for Red Rocks Audio DigiDAC1"
42 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
43 --- a/sound/soc/bcm/Makefile
44 +++ b/sound/soc/bcm/Makefile
45 @@ -23,6 +23,7 @@ snd-soc-iqaudio-dac-objs := iqaudio-dac.
46 snd-soc-iqaudio-digi-objs := iqaudio_digi.o
47 snd-soc-raspidac3-objs := raspidac3.o
48 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
49 +snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
50 snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
51 snd-soc-dionaudio-loco-objs := dionaudio_loco.o
52 snd-soc-dionaudio-loco-v2-objs := dionaudio_loco-v2.o
53 @@ -46,6 +47,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC
54 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI) += snd-soc-iqaudio-digi.o
55 obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
56 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
57 +obj-$(CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD) += snd-soc-audioinjector-octo-soundcard.o
58 obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
59 obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
60 obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2) += snd-soc-dionaudio-loco-v2.o
62 +++ b/sound/soc/bcm/audioinjector-octo-soundcard.c
65 + * ASoC Driver for AudioInjector Pi octo channel soundcard (hat)
67 + * Created on: 27-October-2016
68 + * Author: flatmax@flatmax.org
69 + * based on audioinjector-pi-soundcard.c
71 + * Copyright (C) 2016 Flatmax Pty. Ltd.
73 + * This program is free software; you can redistribute it and/or
74 + * modify it under the terms of the GNU General Public License
75 + * version 2 as published by the Free Software Foundation.
77 + * This program is distributed in the hope that it will be useful, but
78 + * WITHOUT ANY WARRANTY; without even the implied warranty of
79 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
80 + * General Public License for more details.
83 +#include <linux/module.h>
84 +#include <linux/types.h>
85 +#include <linux/gpio/consumer.h>
87 +#include <sound/core.h>
88 +#include <sound/soc.h>
89 +#include <sound/pcm_params.h>
90 +#include <sound/control.h>
92 +static struct gpio_descs *mult_gpios;
93 +static struct gpio_desc *codec_rst_gpio;
94 +static unsigned int audioinjector_octo_rate;
96 +static const unsigned int audioinjector_octo_rates[] = {
97 + 96000, 48000, 32000, 24000, 16000, 8000, 88200, 44100, 29400, 22050, 14700,
100 +static struct snd_pcm_hw_constraint_list audioinjector_octo_constraints = {
101 + .list = audioinjector_octo_rates,
102 + .count = ARRAY_SIZE(audioinjector_octo_rates),
105 +static int audioinjector_octo_dai_init(struct snd_soc_pcm_runtime *rtd)
107 + return snd_soc_dai_set_bclk_ratio(rtd->cpu_dai, 64);
110 +static int audioinjector_octo_startup(struct snd_pcm_substream *substream)
112 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
113 + rtd->cpu_dai->driver->playback.channels_min = 8;
114 + rtd->cpu_dai->driver->playback.channels_max = 8;
115 + rtd->cpu_dai->driver->capture.channels_min = 8;
116 + rtd->cpu_dai->driver->capture.channels_max = 8;
117 + rtd->codec_dai->driver->capture.channels_max = 8;
119 + snd_pcm_hw_constraint_list(substream->runtime, 0,
120 + SNDRV_PCM_HW_PARAM_RATE,
121 + &audioinjector_octo_constraints);
126 +static void audioinjector_octo_shutdown(struct snd_pcm_substream *substream)
128 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
129 + rtd->cpu_dai->driver->playback.channels_min = 2;
130 + rtd->cpu_dai->driver->playback.channels_max = 2;
131 + rtd->cpu_dai->driver->capture.channels_min = 2;
132 + rtd->cpu_dai->driver->capture.channels_max = 2;
133 + rtd->codec_dai->driver->capture.channels_max = 6;
136 +static int audioinjector_octo_hw_params(struct snd_pcm_substream *substream,
137 + struct snd_pcm_hw_params *params)
139 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
141 + // set codec DAI configuration
142 + int ret = snd_soc_dai_set_fmt(rtd->codec_dai,
143 + SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_DSP_A|
144 + SND_SOC_DAIFMT_NB_NF);
148 + // set cpu DAI configuration
149 + ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
150 + SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|
151 + SND_SOC_DAIFMT_NB_NF);
155 + audioinjector_octo_rate = params_rate(params);
157 + // Set the correct sysclock for the codec
158 + switch (audioinjector_octo_rate) {
161 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000,
165 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/2,
170 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/3,
174 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/6,
179 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400,
183 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400/2,
188 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400/3,
196 +static int audioinjector_octo_trigger(struct snd_pcm_substream *substream,
205 + case SNDRV_PCM_TRIGGER_START:
206 + case SNDRV_PCM_TRIGGER_RESUME:
207 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
208 + switch (audioinjector_octo_rate) {
243 + case SNDRV_PCM_TRIGGER_STOP:
244 + case SNDRV_PCM_TRIGGER_SUSPEND:
245 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
250 + gpiod_set_array_value_cansleep(mult_gpios->ndescs, mult_gpios->desc,
256 +static struct snd_soc_ops audioinjector_octo_ops = {
257 + .startup = audioinjector_octo_startup,
258 + .shutdown = audioinjector_octo_shutdown,
259 + .hw_params = audioinjector_octo_hw_params,
260 + .trigger = audioinjector_octo_trigger,
263 +static struct snd_soc_dai_link audioinjector_octo_dai[] = {
265 + .name = "AudioInjector Octo",
266 + .stream_name = "AudioInject-HIFI",
267 + .codec_dai_name = "cs42448",
268 + .ops = &audioinjector_octo_ops,
269 + .init = audioinjector_octo_dai_init,
270 + .symmetric_rates = 1,
271 + .symmetric_channels = 1,
275 +static const struct snd_soc_dapm_widget audioinjector_octo_widgets[] = {
276 + SND_SOC_DAPM_OUTPUT("OUTPUTS0"),
277 + SND_SOC_DAPM_OUTPUT("OUTPUTS1"),
278 + SND_SOC_DAPM_OUTPUT("OUTPUTS2"),
279 + SND_SOC_DAPM_OUTPUT("OUTPUTS3"),
280 + SND_SOC_DAPM_INPUT("INPUTS0"),
281 + SND_SOC_DAPM_INPUT("INPUTS1"),
282 + SND_SOC_DAPM_INPUT("INPUTS2"),
285 +static const struct snd_soc_dapm_route audioinjector_octo_route[] = {
286 + /* Balanced outputs */
287 + {"OUTPUTS0", NULL, "AOUT1L"},
288 + {"OUTPUTS0", NULL, "AOUT1R"},
289 + {"OUTPUTS1", NULL, "AOUT2L"},
290 + {"OUTPUTS1", NULL, "AOUT2R"},
291 + {"OUTPUTS2", NULL, "AOUT3L"},
292 + {"OUTPUTS2", NULL, "AOUT3R"},
293 + {"OUTPUTS3", NULL, "AOUT4L"},
294 + {"OUTPUTS3", NULL, "AOUT4R"},
296 + /* Balanced inputs */
297 + {"AIN1L", NULL, "INPUTS0"},
298 + {"AIN1R", NULL, "INPUTS0"},
299 + {"AIN2L", NULL, "INPUTS1"},
300 + {"AIN2R", NULL, "INPUTS1"},
301 + {"AIN3L", NULL, "INPUTS2"},
302 + {"AIN3R", NULL, "INPUTS2"},
305 +static struct snd_soc_card snd_soc_audioinjector_octo = {
306 + .name = "audioinjector-octo-soundcard",
307 + .dai_link = audioinjector_octo_dai,
308 + .num_links = ARRAY_SIZE(audioinjector_octo_dai),
310 + .dapm_widgets = audioinjector_octo_widgets,
311 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_octo_widgets),
312 + .dapm_routes = audioinjector_octo_route,
313 + .num_dapm_routes = ARRAY_SIZE(audioinjector_octo_route),
316 +static int audioinjector_octo_probe(struct platform_device *pdev)
318 + struct snd_soc_card *card = &snd_soc_audioinjector_octo;
321 + card->dev = &pdev->dev;
323 + if (pdev->dev.of_node) {
324 + struct snd_soc_dai_link *dai = &audioinjector_octo_dai[0];
325 + struct device_node *i2s_node =
326 + of_parse_phandle(pdev->dev.of_node,
327 + "i2s-controller", 0);
328 + struct device_node *codec_node =
329 + of_parse_phandle(pdev->dev.of_node,
332 + mult_gpios = devm_gpiod_get_array_optional(&pdev->dev, "mult",
334 + if (IS_ERR(mult_gpios))
335 + return PTR_ERR(mult_gpios);
337 + codec_rst_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
339 + if (IS_ERR(codec_rst_gpio))
340 + return PTR_ERR(codec_rst_gpio);
342 + if (codec_rst_gpio)
343 + gpiod_set_value(codec_rst_gpio, 1);
345 + if (codec_rst_gpio)
346 + gpiod_set_value(codec_rst_gpio, 0);
348 + if (codec_rst_gpio)
349 + gpiod_set_value(codec_rst_gpio, 1);
352 + if (i2s_node && codec_node) {
353 + dai->cpu_dai_name = NULL;
354 + dai->cpu_of_node = i2s_node;
355 + dai->platform_name = NULL;
356 + dai->platform_of_node = i2s_node;
357 + dai->codec_name = NULL;
358 + dai->codec_of_node = codec_node;
360 + if (!dai->cpu_of_node) {
361 + dev_err(&pdev->dev,
362 + "i2s-controller missing or invalid in DT\n");
365 + dev_err(&pdev->dev,
366 + "Property 'codec' missing or invalid\n");
371 + ret = snd_soc_register_card(card);
373 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
377 +static int audioinjector_octo_remove(struct platform_device *pdev)
379 + struct snd_soc_card *card = platform_get_drvdata(pdev);
381 + return snd_soc_unregister_card(card);
384 +static const struct of_device_id audioinjector_octo_of_match[] = {
385 + { .compatible = "ai,audioinjector-octo-soundcard", },
388 +MODULE_DEVICE_TABLE(of, audioinjector_octo_of_match);
390 +static struct platform_driver audioinjector_octo_driver = {
392 + .name = "audioinjector-octo",
393 + .owner = THIS_MODULE,
394 + .of_match_table = audioinjector_octo_of_match,
396 + .probe = audioinjector_octo_probe,
397 + .remove = audioinjector_octo_remove,
400 +module_platform_driver(audioinjector_octo_driver);
401 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
402 +MODULE_DESCRIPTION("AudioInjector.net octo Soundcard");
403 +MODULE_LICENSE("GPL v2");
404 +MODULE_ALIAS("platform:audioinjector-octo-soundcard");