1 From 1f7175bb016838bfbac59f80bef52797f7f2af98 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 082/773] 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 audioinjector-octo: Add continuous clock feature
23 By user request, add a switch to prevent the clocks being stopped when
24 the stream is paused, stopped or shutdown. Provide access to the switch
25 by adding a 'non-stop-clocks' parameter to the audioinjector-addons
28 See: https://github.com/raspberrypi/linux/issues/2409
30 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
32 sound/soc/bcm/audioinjector-octo-soundcard.c | 336 +++++++++++++++++++
33 1 file changed, 336 insertions(+)
34 create mode 100644 sound/soc/bcm/audioinjector-octo-soundcard.c
37 +++ b/sound/soc/bcm/audioinjector-octo-soundcard.c
40 + * ASoC Driver for AudioInjector Pi octo channel soundcard (hat)
42 + * Created on: 27-October-2016
43 + * Author: flatmax@flatmax.org
44 + * based on audioinjector-pi-soundcard.c
46 + * Copyright (C) 2016 Flatmax Pty. Ltd.
48 + * This program is free software; you can redistribute it and/or
49 + * modify it under the terms of the GNU General Public License
50 + * version 2 as published by the Free Software Foundation.
52 + * This program is distributed in the hope that it will be useful, but
53 + * WITHOUT ANY WARRANTY; without even the implied warranty of
54 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
55 + * General Public License for more details.
58 +#include <linux/module.h>
59 +#include <linux/types.h>
60 +#include <linux/gpio/consumer.h>
62 +#include <sound/core.h>
63 +#include <sound/soc.h>
64 +#include <sound/pcm_params.h>
65 +#include <sound/control.h>
67 +static struct gpio_descs *mult_gpios;
68 +static struct gpio_desc *codec_rst_gpio;
69 +static unsigned int audioinjector_octo_rate;
70 +static bool non_stop_clocks;
72 +static const unsigned int audioinjector_octo_rates[] = {
73 + 96000, 48000, 32000, 24000, 16000, 8000, 88200, 44100, 29400, 22050, 14700,
76 +static struct snd_pcm_hw_constraint_list audioinjector_octo_constraints = {
77 + .list = audioinjector_octo_rates,
78 + .count = ARRAY_SIZE(audioinjector_octo_rates),
81 +static int audioinjector_octo_dai_init(struct snd_soc_pcm_runtime *rtd)
83 + return snd_soc_dai_set_bclk_ratio(rtd->cpu_dai, 64);
86 +static int audioinjector_octo_startup(struct snd_pcm_substream *substream)
88 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
89 + rtd->cpu_dai->driver->playback.channels_min = 8;
90 + rtd->cpu_dai->driver->playback.channels_max = 8;
91 + rtd->cpu_dai->driver->capture.channels_min = 8;
92 + rtd->cpu_dai->driver->capture.channels_max = 8;
93 + rtd->codec_dai->driver->capture.channels_max = 8;
95 + snd_pcm_hw_constraint_list(substream->runtime, 0,
96 + SNDRV_PCM_HW_PARAM_RATE,
97 + &audioinjector_octo_constraints);
102 +static void audioinjector_octo_shutdown(struct snd_pcm_substream *substream)
104 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
105 + rtd->cpu_dai->driver->playback.channels_min = 2;
106 + rtd->cpu_dai->driver->playback.channels_max = 2;
107 + rtd->cpu_dai->driver->capture.channels_min = 2;
108 + rtd->cpu_dai->driver->capture.channels_max = 2;
109 + rtd->codec_dai->driver->capture.channels_max = 6;
112 +static int audioinjector_octo_hw_params(struct snd_pcm_substream *substream,
113 + struct snd_pcm_hw_params *params)
115 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
117 + // set codec DAI configuration
118 + int ret = snd_soc_dai_set_fmt(rtd->codec_dai,
119 + SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_DSP_A|
120 + SND_SOC_DAIFMT_NB_NF);
124 + // set cpu DAI configuration
125 + ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
126 + SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|
127 + SND_SOC_DAIFMT_NB_NF);
131 + audioinjector_octo_rate = params_rate(params);
133 + // Set the correct sysclock for the codec
134 + switch (audioinjector_octo_rate) {
137 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000,
141 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/2,
146 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/3,
150 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/6,
155 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400,
159 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400/2,
164 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400/3,
172 +static int audioinjector_octo_trigger(struct snd_pcm_substream *substream,
176 + memset(mult, 0, sizeof(mult));
179 + case SNDRV_PCM_TRIGGER_STOP:
180 + case SNDRV_PCM_TRIGGER_SUSPEND:
181 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
182 + if (!non_stop_clocks)
184 + /* Drop through... */
185 + case SNDRV_PCM_TRIGGER_START:
186 + case SNDRV_PCM_TRIGGER_RESUME:
187 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
188 + switch (audioinjector_octo_rate) {
226 + gpiod_set_array_value_cansleep(mult_gpios->ndescs, mult_gpios->desc,
232 +static struct snd_soc_ops audioinjector_octo_ops = {
233 + .startup = audioinjector_octo_startup,
234 + .shutdown = audioinjector_octo_shutdown,
235 + .hw_params = audioinjector_octo_hw_params,
236 + .trigger = audioinjector_octo_trigger,
239 +static struct snd_soc_dai_link audioinjector_octo_dai[] = {
241 + .name = "AudioInjector Octo",
242 + .stream_name = "AudioInject-HIFI",
243 + .codec_dai_name = "cs42448",
244 + .ops = &audioinjector_octo_ops,
245 + .init = audioinjector_octo_dai_init,
246 + .symmetric_rates = 1,
247 + .symmetric_channels = 1,
251 +static const struct snd_soc_dapm_widget audioinjector_octo_widgets[] = {
252 + SND_SOC_DAPM_OUTPUT("OUTPUTS0"),
253 + SND_SOC_DAPM_OUTPUT("OUTPUTS1"),
254 + SND_SOC_DAPM_OUTPUT("OUTPUTS2"),
255 + SND_SOC_DAPM_OUTPUT("OUTPUTS3"),
256 + SND_SOC_DAPM_INPUT("INPUTS0"),
257 + SND_SOC_DAPM_INPUT("INPUTS1"),
258 + SND_SOC_DAPM_INPUT("INPUTS2"),
261 +static const struct snd_soc_dapm_route audioinjector_octo_route[] = {
262 + /* Balanced outputs */
263 + {"OUTPUTS0", NULL, "AOUT1L"},
264 + {"OUTPUTS0", NULL, "AOUT1R"},
265 + {"OUTPUTS1", NULL, "AOUT2L"},
266 + {"OUTPUTS1", NULL, "AOUT2R"},
267 + {"OUTPUTS2", NULL, "AOUT3L"},
268 + {"OUTPUTS2", NULL, "AOUT3R"},
269 + {"OUTPUTS3", NULL, "AOUT4L"},
270 + {"OUTPUTS3", NULL, "AOUT4R"},
272 + /* Balanced inputs */
273 + {"AIN1L", NULL, "INPUTS0"},
274 + {"AIN1R", NULL, "INPUTS0"},
275 + {"AIN2L", NULL, "INPUTS1"},
276 + {"AIN2R", NULL, "INPUTS1"},
277 + {"AIN3L", NULL, "INPUTS2"},
278 + {"AIN3R", NULL, "INPUTS2"},
281 +static struct snd_soc_card snd_soc_audioinjector_octo = {
282 + .name = "audioinjector-octo-soundcard",
283 + .dai_link = audioinjector_octo_dai,
284 + .num_links = ARRAY_SIZE(audioinjector_octo_dai),
286 + .dapm_widgets = audioinjector_octo_widgets,
287 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_octo_widgets),
288 + .dapm_routes = audioinjector_octo_route,
289 + .num_dapm_routes = ARRAY_SIZE(audioinjector_octo_route),
292 +static int audioinjector_octo_probe(struct platform_device *pdev)
294 + struct snd_soc_card *card = &snd_soc_audioinjector_octo;
297 + card->dev = &pdev->dev;
299 + if (pdev->dev.of_node) {
300 + struct snd_soc_dai_link *dai = &audioinjector_octo_dai[0];
301 + struct device_node *i2s_node =
302 + of_parse_phandle(pdev->dev.of_node,
303 + "i2s-controller", 0);
304 + struct device_node *codec_node =
305 + of_parse_phandle(pdev->dev.of_node,
308 + mult_gpios = devm_gpiod_get_array_optional(&pdev->dev, "mult",
310 + if (IS_ERR(mult_gpios))
311 + return PTR_ERR(mult_gpios);
313 + codec_rst_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
315 + if (IS_ERR(codec_rst_gpio))
316 + return PTR_ERR(codec_rst_gpio);
318 + non_stop_clocks = of_property_read_bool(pdev->dev.of_node, "non-stop-clocks");
320 + if (codec_rst_gpio)
321 + gpiod_set_value(codec_rst_gpio, 1);
323 + if (codec_rst_gpio)
324 + gpiod_set_value(codec_rst_gpio, 0);
326 + if (codec_rst_gpio)
327 + gpiod_set_value(codec_rst_gpio, 1);
330 + if (i2s_node && codec_node) {
331 + dai->cpu_dai_name = NULL;
332 + dai->cpu_of_node = i2s_node;
333 + dai->platform_name = NULL;
334 + dai->platform_of_node = i2s_node;
335 + dai->codec_name = NULL;
336 + dai->codec_of_node = codec_node;
338 + if (!dai->cpu_of_node) {
339 + dev_err(&pdev->dev,
340 + "i2s-controller missing or invalid in DT\n");
343 + dev_err(&pdev->dev,
344 + "Property 'codec' missing or invalid\n");
349 + ret = devm_snd_soc_register_card(&pdev->dev, card);
351 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
355 +static const struct of_device_id audioinjector_octo_of_match[] = {
356 + { .compatible = "ai,audioinjector-octo-soundcard", },
359 +MODULE_DEVICE_TABLE(of, audioinjector_octo_of_match);
361 +static struct platform_driver audioinjector_octo_driver = {
363 + .name = "audioinjector-octo",
364 + .owner = THIS_MODULE,
365 + .of_match_table = audioinjector_octo_of_match,
367 + .probe = audioinjector_octo_probe,
370 +module_platform_driver(audioinjector_octo_driver);
371 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
372 +MODULE_DESCRIPTION("AudioInjector.net octo Soundcard");
373 +MODULE_LICENSE("GPL v2");
374 +MODULE_ALIAS("platform:audioinjector-octo-soundcard");