1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
From 471f12c73cf73db88695d5161ec5c29f94fde1d0 Mon Sep 17 00:00:00 2001
From: Matt Flax <flatmax@flatmax.org>
Date: Wed, 8 Mar 2017 20:04:13 +1100
Subject: [PATCH] Add support for the AudioInjector.net Octo sound card
AudioInjector Octo: sample rates, regulators, reset
This patch adds new sample rates to the Audioinjector Octo sound card. The
new supported rates are (in kHz) :
96, 48, 32, 24, 16, 8, 88.2, 44.1, 29.4, 22.05, 14.7
Reference the bcm270x DT regulators in the overlay.
This patch adds a reset GPIO for the AudioInjector.net octo sound card.
Audioinjector octo : Make the playback and capture symmetric
This patch ensures that the sample rate and channel count of the audioinjector
octo sound card are symmetric.
audioinjector-octo: Add continuous clock feature
By user request, add a switch to prevent the clocks being stopped when
the stream is paused, stopped or shutdown. Provide access to the switch
by adding a 'non-stop-clocks' parameter to the audioinjector-addons
overlay.
See: https://github.com/raspberrypi/linux/issues/2409
Signed-off-by: Phil Elwell <phil@raspberrypi.org>
sound: Fixes for audioinjector-octo under 4.19
1. Move the DT alias declaration to the I2C shim in the cases
where the shim is enabled. This works around a problem caused by a
4.19 commit [1] that generates DT/OF uevents for I2C drivers.
2. Fix the diagnostics in an error path of the soundcard driver to
correctly identify the reason for the failure to load.
3. Move the declaration of the clock node in the overlay outside
the I2C node to avoid warnings.
4. Sort the overlay nodes so that dependencies are only to earlier
fragments, in an attempt to get runtime dtoverlay application to
work (it still doesn't...)
See: https://github.com/Audio-Injector/Octo/issues/14
Signed-off-by: Phil Elwell <phil@raspberrypi.org>
[1] af503716ac14 ("i2c: core: report OF style module alias for devices registered via OF")
ASoC: audioinjector-octo-soundcard: use modern dai_link style
Signed-off-by: Hui Wang <hui.wang@canonical.com>
---
sound/soc/bcm/audioinjector-octo-soundcard.c | 341 +++++++++++++++++++
sound/soc/codecs/cs42xx8-i2c.c | 7 +
sound/soc/codecs/cs42xx8.c | 2 +
3 files changed, 350 insertions(+)
create mode 100644 sound/soc/bcm/audioinjector-octo-soundcard.c
--- /dev/null
+++ b/sound/soc/bcm/audioinjector-octo-soundcard.c
@@ -0,0 +1,341 @@
+/*
+ * ASoC Driver for AudioInjector Pi octo channel soundcard (hat)
+ *
+ * Created on: 27-October-2016
+ * Author: flatmax@flatmax.org
+ * based on audioinjector-pi-soundcard.c
+ *
+ * Copyright (C) 2016 Flatmax Pty. Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/gpio/consumer.h>
+
+#include <sound/core.h>
+#include <sound/soc.h>
+#include <sound/pcm_params.h>
+#include <sound/control.h>
+
+static struct gpio_descs *mult_gpios;
+static struct gpio_desc *codec_rst_gpio;
+static unsigned int audioinjector_octo_rate;
+static bool non_stop_clocks;
+
+static const unsigned int audioinjector_octo_rates[] = {
+ 96000, 48000, 32000, 24000, 16000, 8000, 88200, 44100, 29400, 22050, 14700,
+};
+
+static struct snd_pcm_hw_constraint_list audioinjector_octo_constraints = {
+ .list = audioinjector_octo_rates,
+ .count = ARRAY_SIZE(audioinjector_octo_rates),
+};
+
+static int audioinjector_octo_dai_init(struct snd_soc_pcm_runtime *rtd)
+{
+ return snd_soc_dai_set_bclk_ratio(rtd->cpu_dai, 64);
+}
+
+static int audioinjector_octo_startup(struct snd_pcm_substream *substream)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ rtd->cpu_dai->driver->playback.channels_min = 8;
+ rtd->cpu_dai->driver->playback.channels_max = 8;
+ rtd->cpu_dai->driver->capture.channels_min = 8;
+ rtd->cpu_dai->driver->capture.channels_max = 8;
+ rtd->codec_dai->driver->capture.channels_max = 8;
+
+ snd_pcm_hw_constraint_list(substream->runtime, 0,
+ SNDRV_PCM_HW_PARAM_RATE,
+ &audioinjector_octo_constraints);
+
+ return 0;
+}
+
+static void audioinjector_octo_shutdown(struct snd_pcm_substream *substream)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ rtd->cpu_dai->driver->playback.channels_min = 2;
+ rtd->cpu_dai->driver->playback.channels_max = 2;
+ rtd->cpu_dai->driver->capture.channels_min = 2;
+ rtd->cpu_dai->driver->capture.channels_max = 2;
+ rtd->codec_dai->driver->capture.channels_max = 6;
+}
+
+static int audioinjector_octo_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+
+ // set codec DAI configuration
+ int ret = snd_soc_dai_set_fmt(rtd->codec_dai,
+ SND_SOC_DAIFMT_CBS_CFS|SND_SOC_DAIFMT_DSP_A|
+ SND_SOC_DAIFMT_NB_NF);
+ if (ret < 0)
+ return ret;
+
+ // set cpu DAI configuration
+ ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
+ SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|
+ SND_SOC_DAIFMT_NB_NF);
+ if (ret < 0)
+ return ret;
+
+ audioinjector_octo_rate = params_rate(params);
+
+ // Set the correct sysclock for the codec
+ switch (audioinjector_octo_rate) {
+ case 96000:
+ case 48000:
+ return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000,
+ 0);
+ break;
+ case 24000:
+ return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/2,
+ 0);
+ break;
+ case 32000:
+ case 16000:
+ return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/3,
+ 0);
+ break;
+ case 8000:
+ return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 49152000/6,
+ 0);
+ break;
+ case 88200:
+ case 44100:
+ return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400,
+ 0);
+ break;
+ case 22050:
+ return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400/2,
+ 0);
+ break;
+ case 29400:
+ case 14700:
+ return snd_soc_dai_set_sysclk(rtd->codec_dai, 0, 45185400/3,
+ 0);
+ break;
+ default:
+ return -EINVAL;
+ }
+}
+
+static int audioinjector_octo_trigger(struct snd_pcm_substream *substream,
+ int cmd){
+ DECLARE_BITMAP(mult, 4);
+
+ memset(mult, 0, sizeof(mult));
+
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_STOP:
+ case SNDRV_PCM_TRIGGER_SUSPEND:
+ case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+ if (!non_stop_clocks)
+ break;
+ /* Drop through... */
+ case SNDRV_PCM_TRIGGER_START:
+ case SNDRV_PCM_TRIGGER_RESUME:
+ case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+ switch (audioinjector_octo_rate) {
+ case 96000:
+ __assign_bit(3, mult, 1);
+ case 88200:
+ __assign_bit(1, mult, 1);
+ __assign_bit(2, mult, 1);
+ break;
+ case 48000:
+ __assign_bit(3, mult, 1);
+ case 44100:
+ __assign_bit(2, mult, 1);
+ break;
+ case 32000:
+ __assign_bit(3, mult, 1);
+ case 29400:
+ __assign_bit(0, mult, 1);
+ __assign_bit(1, mult, 1);
+ break;
+ case 24000:
+ __assign_bit(3, mult, 1);
+ case 22050:
+ __assign_bit(1, mult, 1);
+ break;
+ case 16000:
+ __assign_bit(3, mult, 1);
+ case 14700:
+ __assign_bit(0, mult, 1);
+ break;
+ case 8000:
+ __assign_bit(3, mult, 1);
+ break;
+ default:
+ return -EINVAL;
+ }
+ break;
+ default:
+ return -EINVAL;
+ }
+ gpiod_set_array_value_cansleep(mult_gpios->ndescs, mult_gpios->desc,
+ NULL, mult);
+
+ return 0;
+}
+
+static struct snd_soc_ops audioinjector_octo_ops = {
+ .startup = audioinjector_octo_startup,
+ .shutdown = audioinjector_octo_shutdown,
+ .hw_params = audioinjector_octo_hw_params,
+ .trigger = audioinjector_octo_trigger,
+};
+
+SND_SOC_DAILINK_DEFS(audioinjector_octo,
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42448")),
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
+static struct snd_soc_dai_link audioinjector_octo_dai[] = {
+ {
+ .name = "AudioInjector Octo",
+ .stream_name = "AudioInject-HIFI",
+ .ops = &audioinjector_octo_ops,
+ .init = audioinjector_octo_dai_init,
+ .symmetric_rates = 1,
+ .symmetric_channels = 1,
+ SND_SOC_DAILINK_REG(audioinjector_octo),
+ },
+};
+
+static const struct snd_soc_dapm_widget audioinjector_octo_widgets[] = {
+ SND_SOC_DAPM_OUTPUT("OUTPUTS0"),
+ SND_SOC_DAPM_OUTPUT("OUTPUTS1"),
+ SND_SOC_DAPM_OUTPUT("OUTPUTS2"),
+ SND_SOC_DAPM_OUTPUT("OUTPUTS3"),
+ SND_SOC_DAPM_INPUT("INPUTS0"),
+ SND_SOC_DAPM_INPUT("INPUTS1"),
+ SND_SOC_DAPM_INPUT("INPUTS2"),
+};
+
+static const struct snd_soc_dapm_route audioinjector_octo_route[] = {
+ /* Balanced outputs */
+ {"OUTPUTS0", NULL, "AOUT1L"},
+ {"OUTPUTS0", NULL, "AOUT1R"},
+ {"OUTPUTS1", NULL, "AOUT2L"},
+ {"OUTPUTS1", NULL, "AOUT2R"},
+ {"OUTPUTS2", NULL, "AOUT3L"},
+ {"OUTPUTS2", NULL, "AOUT3R"},
+ {"OUTPUTS3", NULL, "AOUT4L"},
+ {"OUTPUTS3", NULL, "AOUT4R"},
+
+ /* Balanced inputs */
+ {"AIN1L", NULL, "INPUTS0"},
+ {"AIN1R", NULL, "INPUTS0"},
+ {"AIN2L", NULL, "INPUTS1"},
+ {"AIN2R", NULL, "INPUTS1"},
+ {"AIN3L", NULL, "INPUTS2"},
+ {"AIN3R", NULL, "INPUTS2"},
+};
+
+static struct snd_soc_card snd_soc_audioinjector_octo = {
+ .name = "audioinjector-octo-soundcard",
+ .dai_link = audioinjector_octo_dai,
+ .num_links = ARRAY_SIZE(audioinjector_octo_dai),
+
+ .dapm_widgets = audioinjector_octo_widgets,
+ .num_dapm_widgets = ARRAY_SIZE(audioinjector_octo_widgets),
+ .dapm_routes = audioinjector_octo_route,
+ .num_dapm_routes = ARRAY_SIZE(audioinjector_octo_route),
+};
+
+static int audioinjector_octo_probe(struct platform_device *pdev)
+{
+ struct snd_soc_card *card = &snd_soc_audioinjector_octo;
+ int ret;
+
+ card->dev = &pdev->dev;
+
+ if (pdev->dev.of_node) {
+ struct snd_soc_dai_link *dai = &audioinjector_octo_dai[0];
+ struct device_node *i2s_node =
+ of_parse_phandle(pdev->dev.of_node,
+ "i2s-controller", 0);
+ struct device_node *codec_node =
+ of_parse_phandle(pdev->dev.of_node,
+ "codec", 0);
+
+ mult_gpios = devm_gpiod_get_array_optional(&pdev->dev, "mult",
+ GPIOD_OUT_LOW);
+ if (IS_ERR(mult_gpios))
+ return PTR_ERR(mult_gpios);
+
+ codec_rst_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
+ GPIOD_OUT_LOW);
+ if (IS_ERR(codec_rst_gpio))
+ return PTR_ERR(codec_rst_gpio);
+
+ non_stop_clocks = of_property_read_bool(pdev->dev.of_node, "non-stop-clocks");
+
+ if (codec_rst_gpio)
+ gpiod_set_value(codec_rst_gpio, 1);
+ msleep(500);
+ if (codec_rst_gpio)
+ gpiod_set_value(codec_rst_gpio, 0);
+ msleep(500);
+ if (codec_rst_gpio)
+ gpiod_set_value(codec_rst_gpio, 1);
+ msleep(500);
+
+ if (i2s_node && codec_node) {
+ dai->cpus->dai_name = NULL;
+ dai->cpus->of_node = i2s_node;
+ dai->platforms->name = NULL;
+ dai->platforms->of_node = i2s_node;
+ dai->codecs->name = NULL;
+ dai->codecs->of_node = codec_node;
+ } else
+ if (!i2s_node) {
+ dev_err(&pdev->dev,
+ "i2s-controller missing or invalid in DT\n");
+ return -EINVAL;
+ } else {
+ dev_err(&pdev->dev,
+ "Property 'codec' missing or invalid\n");
+ return -EINVAL;
+ }
+ }
+
+ ret = devm_snd_soc_register_card(&pdev->dev, card);
+ if (ret != 0)
+ dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
+ return ret;
+}
+
+static const struct of_device_id audioinjector_octo_of_match[] = {
+ { .compatible = "ai,audioinjector-octo-soundcard", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, audioinjector_octo_of_match);
+
+static struct platform_driver audioinjector_octo_driver = {
+ .driver = {
+ .name = "audioinjector-octo",
+ .owner = THIS_MODULE,
+ .of_match_table = audioinjector_octo_of_match,
+ },
+ .probe = audioinjector_octo_probe,
+};
+
+module_platform_driver(audioinjector_octo_driver);
+MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
+MODULE_DESCRIPTION("AudioInjector.net octo Soundcard");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:audioinjector-octo-soundcard");
--- a/sound/soc/codecs/cs42xx8-i2c.c
+++ b/sound/soc/codecs/cs42xx8-i2c.c
@@ -45,6 +45,13 @@ static struct i2c_device_id cs42xx8_i2c_
};
MODULE_DEVICE_TABLE(i2c, cs42xx8_i2c_id);
+const struct of_device_id cs42xx8_of_match[] = {
+ { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
+ { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
+
static struct i2c_driver cs42xx8_i2c_driver = {
.driver = {
.name = "cs42xx8",
--- a/sound/soc/codecs/cs42xx8.c
+++ b/sound/soc/codecs/cs42xx8.c
@@ -516,8 +516,10 @@ const struct of_device_id cs42xx8_of_mat
{ .compatible = "cirrus,cs42888", .data = &cs42888_data, },
{ /* sentinel */ }
};
+#if !IS_ENABLED(CONFIG_SND_SOC_CS42XX8_I2C)
MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
EXPORT_SYMBOL_GPL(cs42xx8_of_match);
+#endif
int cs42xx8_probe(struct device *dev, struct regmap *regmap)
{
|