1 From 471f12c73cf73db88695d5161ec5c29f94fde1d0 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] 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: Fixes for audioinjector-octo under 4.19
34 1. Move the DT alias declaration to the I2C shim in the cases
35 where the shim is enabled. This works around a problem caused by a
36 4.19 commit [1] that generates DT/OF uevents for I2C drivers.
38 2. Fix the diagnostics in an error path of the soundcard driver to
39 correctly identify the reason for the failure to load.
41 3. Move the declaration of the clock node in the overlay outside
42 the I2C node to avoid warnings.
44 4. Sort the overlay nodes so that dependencies are only to earlier
45 fragments, in an attempt to get runtime dtoverlay application to
46 work (it still doesn't...)
48 See: https://github.com/Audio-Injector/Octo/issues/14
49 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
51 [1] af503716ac14 ("i2c: core: report OF style module alias for devices registered via OF")
53 ASoC: audioinjector-octo-soundcard: use modern dai_link style
55 Signed-off-by: Hui Wang <hui.wang@canonical.com>
57 sound/soc/bcm/audioinjector-octo-soundcard.c | 341 +++++++++++++++++++
58 sound/soc/codecs/cs42xx8-i2c.c | 7 +
59 sound/soc/codecs/cs42xx8.c | 2 +
60 3 files changed, 350 insertions(+)
61 create mode 100644 sound/soc/bcm/audioinjector-octo-soundcard.c
64 +++ b/sound/soc/bcm/audioinjector-octo-soundcard.c
67 + * ASoC Driver for AudioInjector Pi octo channel soundcard (hat)
69 + * Created on: 27-October-2016
70 + * Author: flatmax@flatmax.org
71 + * based on audioinjector-pi-soundcard.c
73 + * Copyright (C) 2016 Flatmax Pty. Ltd.
75 + * This program is free software; you can redistribute it and/or
76 + * modify it under the terms of the GNU General Public License
77 + * version 2 as published by the Free Software Foundation.
79 + * This program is distributed in the hope that it will be useful, but
80 + * WITHOUT ANY WARRANTY; without even the implied warranty of
81 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
82 + * General Public License for more details.
85 +#include <linux/module.h>
86 +#include <linux/types.h>
87 +#include <linux/gpio/consumer.h>
89 +#include <sound/core.h>
90 +#include <sound/soc.h>
91 +#include <sound/pcm_params.h>
92 +#include <sound/control.h>
94 +static struct gpio_descs *mult_gpios;
95 +static struct gpio_desc *codec_rst_gpio;
96 +static unsigned int audioinjector_octo_rate;
97 +static bool non_stop_clocks;
99 +static const unsigned int audioinjector_octo_rates[] = {
100 + 96000, 48000, 32000, 24000, 16000, 8000, 88200, 44100, 29400, 22050, 14700,
103 +static struct snd_pcm_hw_constraint_list audioinjector_octo_constraints = {
104 + .list = audioinjector_octo_rates,
105 + .count = ARRAY_SIZE(audioinjector_octo_rates),
108 +static int audioinjector_octo_dai_init(struct snd_soc_pcm_runtime *rtd)
110 + return snd_soc_dai_set_bclk_ratio(rtd->cpu_dai, 64);
113 +static int audioinjector_octo_startup(struct snd_pcm_substream *substream)
115 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
116 + rtd->cpu_dai->driver->playback.channels_min = 8;
117 + rtd->cpu_dai->driver->playback.channels_max = 8;
118 + rtd->cpu_dai->driver->capture.channels_min = 8;
119 + rtd->cpu_dai->driver->capture.channels_max = 8;
120 + rtd->codec_dai->driver->capture.channels_max = 8;
122 + snd_pcm_hw_constraint_list(substream->runtime, 0,
123 + SNDRV_PCM_HW_PARAM_RATE,
124 + &audioinjector_octo_constraints);
129 +static void audioinjector_octo_shutdown(struct snd_pcm_substream *substream)
131 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
132 + rtd->cpu_dai->driver->playback.channels_min = 2;
133 + rtd->cpu_dai->driver->playback.channels_max = 2;
134 + rtd->cpu_dai->driver->capture.channels_min = 2;
135 + rtd->cpu_dai->driver->capture.channels_max = 2;
136 + rtd->codec_dai->driver->capture.channels_max = 6;
139 +static int audioinjector_octo_hw_params(struct snd_pcm_substream *substream,
140 + struct snd_pcm_hw_params *params)
142 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
144 + // set codec DAI configuration
145 + int ret = snd_soc_dai_set_fmt(rtd->codec_dai,
146 + SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_DSP_A|
147 + SND_SOC_DAIFMT_NB_NF);
151 + // set cpu DAI configuration
152 + ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
153 + SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|
154 + SND_SOC_DAIFMT_NB_NF);
158 + audioinjector_octo_rate = params_rate(params);
160 + // Set the correct sysclock for the codec
161 + switch (audioinjector_octo_rate) {
164 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000,
168 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/2,
173 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/3,
177 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/6,
182 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400,
186 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400/2,
191 + return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400/3,
199 +static int audioinjector_octo_trigger(struct snd_pcm_substream *substream,
201 + DECLARE_BITMAP(mult, 4);
203 + memset(mult, 0, sizeof(mult));
206 + case SNDRV_PCM_TRIGGER_STOP:
207 + case SNDRV_PCM_TRIGGER_SUSPEND:
208 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
209 + if (!non_stop_clocks)
211 + /* Drop through... */
212 + case SNDRV_PCM_TRIGGER_START:
213 + case SNDRV_PCM_TRIGGER_RESUME:
214 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
215 + switch (audioinjector_octo_rate) {
217 + __assign_bit(3, mult, 1);
219 + __assign_bit(1, mult, 1);
220 + __assign_bit(2, mult, 1);
223 + __assign_bit(3, mult, 1);
225 + __assign_bit(2, mult, 1);
228 + __assign_bit(3, mult, 1);
230 + __assign_bit(0, mult, 1);
231 + __assign_bit(1, mult, 1);
234 + __assign_bit(3, mult, 1);
236 + __assign_bit(1, mult, 1);
239 + __assign_bit(3, mult, 1);
241 + __assign_bit(0, mult, 1);
244 + __assign_bit(3, mult, 1);
253 + gpiod_set_array_value_cansleep(mult_gpios->ndescs, mult_gpios->desc,
259 +static struct snd_soc_ops audioinjector_octo_ops = {
260 + .startup = audioinjector_octo_startup,
261 + .shutdown = audioinjector_octo_shutdown,
262 + .hw_params = audioinjector_octo_hw_params,
263 + .trigger = audioinjector_octo_trigger,
266 +SND_SOC_DAILINK_DEFS(audioinjector_octo,
267 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
268 + DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42448")),
269 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
271 +static struct snd_soc_dai_link audioinjector_octo_dai[] = {
273 + .name = "AudioInjector Octo",
274 + .stream_name = "AudioInject-HIFI",
275 + .ops = &audioinjector_octo_ops,
276 + .init = audioinjector_octo_dai_init,
277 + .symmetric_rates = 1,
278 + .symmetric_channels = 1,
279 + SND_SOC_DAILINK_REG(audioinjector_octo),
283 +static const struct snd_soc_dapm_widget audioinjector_octo_widgets[] = {
284 + SND_SOC_DAPM_OUTPUT("OUTPUTS0"),
285 + SND_SOC_DAPM_OUTPUT("OUTPUTS1"),
286 + SND_SOC_DAPM_OUTPUT("OUTPUTS2"),
287 + SND_SOC_DAPM_OUTPUT("OUTPUTS3"),
288 + SND_SOC_DAPM_INPUT("INPUTS0"),
289 + SND_SOC_DAPM_INPUT("INPUTS1"),
290 + SND_SOC_DAPM_INPUT("INPUTS2"),
293 +static const struct snd_soc_dapm_route audioinjector_octo_route[] = {
294 + /* Balanced outputs */
295 + {"OUTPUTS0", NULL, "AOUT1L"},
296 + {"OUTPUTS0", NULL, "AOUT1R"},
297 + {"OUTPUTS1", NULL, "AOUT2L"},
298 + {"OUTPUTS1", NULL, "AOUT2R"},
299 + {"OUTPUTS2", NULL, "AOUT3L"},
300 + {"OUTPUTS2", NULL, "AOUT3R"},
301 + {"OUTPUTS3", NULL, "AOUT4L"},
302 + {"OUTPUTS3", NULL, "AOUT4R"},
304 + /* Balanced inputs */
305 + {"AIN1L", NULL, "INPUTS0"},
306 + {"AIN1R", NULL, "INPUTS0"},
307 + {"AIN2L", NULL, "INPUTS1"},
308 + {"AIN2R", NULL, "INPUTS1"},
309 + {"AIN3L", NULL, "INPUTS2"},
310 + {"AIN3R", NULL, "INPUTS2"},
313 +static struct snd_soc_card snd_soc_audioinjector_octo = {
314 + .name = "audioinjector-octo-soundcard",
315 + .dai_link = audioinjector_octo_dai,
316 + .num_links = ARRAY_SIZE(audioinjector_octo_dai),
318 + .dapm_widgets = audioinjector_octo_widgets,
319 + .num_dapm_widgets = ARRAY_SIZE(audioinjector_octo_widgets),
320 + .dapm_routes = audioinjector_octo_route,
321 + .num_dapm_routes = ARRAY_SIZE(audioinjector_octo_route),
324 +static int audioinjector_octo_probe(struct platform_device *pdev)
326 + struct snd_soc_card *card = &snd_soc_audioinjector_octo;
329 + card->dev = &pdev->dev;
331 + if (pdev->dev.of_node) {
332 + struct snd_soc_dai_link *dai = &audioinjector_octo_dai[0];
333 + struct device_node *i2s_node =
334 + of_parse_phandle(pdev->dev.of_node,
335 + "i2s-controller", 0);
336 + struct device_node *codec_node =
337 + of_parse_phandle(pdev->dev.of_node,
340 + mult_gpios = devm_gpiod_get_array_optional(&pdev->dev, "mult",
342 + if (IS_ERR(mult_gpios))
343 + return PTR_ERR(mult_gpios);
345 + codec_rst_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
347 + if (IS_ERR(codec_rst_gpio))
348 + return PTR_ERR(codec_rst_gpio);
350 + non_stop_clocks = of_property_read_bool(pdev->dev.of_node, "non-stop-clocks");
352 + if (codec_rst_gpio)
353 + gpiod_set_value(codec_rst_gpio, 1);
355 + if (codec_rst_gpio)
356 + gpiod_set_value(codec_rst_gpio, 0);
358 + if (codec_rst_gpio)
359 + gpiod_set_value(codec_rst_gpio, 1);
362 + if (i2s_node && codec_node) {
363 + dai->cpus->dai_name = NULL;
364 + dai->cpus->of_node = i2s_node;
365 + dai->platforms->name = NULL;
366 + dai->platforms->of_node = i2s_node;
367 + dai->codecs->name = NULL;
368 + dai->codecs->of_node = codec_node;
371 + dev_err(&pdev->dev,
372 + "i2s-controller missing or invalid in DT\n");
375 + dev_err(&pdev->dev,
376 + "Property 'codec' missing or invalid\n");
381 + ret = devm_snd_soc_register_card(&pdev->dev, card);
383 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
387 +static const struct of_device_id audioinjector_octo_of_match[] = {
388 + { .compatible = "ai,audioinjector-octo-soundcard", },
391 +MODULE_DEVICE_TABLE(of, audioinjector_octo_of_match);
393 +static struct platform_driver audioinjector_octo_driver = {
395 + .name = "audioinjector-octo",
396 + .owner = THIS_MODULE,
397 + .of_match_table = audioinjector_octo_of_match,
399 + .probe = audioinjector_octo_probe,
402 +module_platform_driver(audioinjector_octo_driver);
403 +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
404 +MODULE_DESCRIPTION("AudioInjector.net octo Soundcard");
405 +MODULE_LICENSE("GPL v2");
406 +MODULE_ALIAS("platform:audioinjector-octo-soundcard");
407 --- a/sound/soc/codecs/cs42xx8-i2c.c
408 +++ b/sound/soc/codecs/cs42xx8-i2c.c
409 @@ -45,6 +45,13 @@ static struct i2c_device_id cs42xx8_i2c_
411 MODULE_DEVICE_TABLE(i2c, cs42xx8_i2c_id);
413 +const struct of_device_id cs42xx8_of_match[] = {
414 + { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
415 + { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
418 +MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
420 static struct i2c_driver cs42xx8_i2c_driver = {
423 --- a/sound/soc/codecs/cs42xx8.c
424 +++ b/sound/soc/codecs/cs42xx8.c
425 @@ -516,8 +516,10 @@ const struct of_device_id cs42xx8_of_mat
426 { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
429 +#if !IS_ENABLED(CONFIG_SND_SOC_CS42XX8_I2C)
430 MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
431 EXPORT_SYMBOL_GPL(cs42xx8_of_match);
434 int cs42xx8_probe(struct device *dev, struct regmap *regmap)