brcm63xx: rename target to bcm63xx
[openwrt/staging/stintel.git] / target / linux / brcm2708 / patches-4.19 / 950-0421-Added-IQaudIO-Pi-Codec-board-support-2969.patch
1 From 930c49de8674acda0f143f7bc182ed2fad8c4f9d Mon Sep 17 00:00:00 2001
2 From: IQaudIO <gordon@iqaudio.com>
3 Date: Mon, 13 May 2019 21:53:05 +0100
4 Subject: [PATCH] Added IQaudIO Pi-Codec board support (#2969)
5
6 Add support for the IQaudIO Pi-Codec board.
7
8 Signed-off-by: Gordon <gordon@iqaudio.com>
9 ---
10 arch/arm/boot/dts/overlays/Makefile | 1 +
11 arch/arm/boot/dts/overlays/README | 6 +
12 .../dts/overlays/iqaudio-codec-overlay.dts | 42 +++
13 sound/soc/bcm/Kconfig | 7 +
14 sound/soc/bcm/Makefile | 2 +
15 sound/soc/bcm/iqaudio-codec.c | 250 ++++++++++++++++++
16 9 files changed, 311 insertions(+)
17 create mode 100644 arch/arm/boot/dts/overlays/iqaudio-codec-overlay.dts
18 create mode 100644 sound/soc/bcm/iqaudio-codec.c
19
20 --- a/arch/arm/boot/dts/overlays/Makefile
21 +++ b/arch/arm/boot/dts/overlays/Makefile
22 @@ -68,6 +68,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
23 i2c1-bcm2708.dtbo \
24 i2s-gpio28-31.dtbo \
25 ilitek251x.dtbo \
26 + iqaudio-codec.dtbo \
27 iqaudio-dac.dtbo \
28 iqaudio-dacplus.dtbo \
29 iqaudio-digi-wm8804-audio.dtbo \
30 --- a/arch/arm/boot/dts/overlays/README
31 +++ b/arch/arm/boot/dts/overlays/README
32 @@ -1160,6 +1160,12 @@ Params: interrupt GPIO use
33 touchscreen (in pixels)
34
35
36 +Name: iqaudio-codec
37 +Info: Configures the IQaudio Codec audio card
38 +Load: dtoverlay=iqaudio-codec
39 +Params: <None>
40 +
41 +
42 Name: iqaudio-dac
43 Info: Configures the IQaudio DAC audio card
44 Load: dtoverlay=iqaudio-dac,<param>
45 --- /dev/null
46 +++ b/arch/arm/boot/dts/overlays/iqaudio-codec-overlay.dts
47 @@ -0,0 +1,42 @@
48 +// Definitions for IQaudIO CODEC
49 +/dts-v1/;
50 +/plugin/;
51 +
52 +/ {
53 + compatible = "brcm,bcm2708";
54 +
55 + fragment@0 {
56 + target = <&i2s>;
57 + __overlay__ {
58 + status = "okay";
59 + };
60 + };
61 +
62 + fragment@1 {
63 + target = <&i2c1>;
64 + __overlay__ {
65 + #address-cells = <1>;
66 + #size-cells = <0>;
67 + status = "okay";
68 +
69 + da2713@1a {
70 + #sound-dai-cells = <0>;
71 + compatible = "dlg,da7213";
72 + reg = <0x1a>;
73 + status = "okay";
74 + };
75 + };
76 + };
77 +
78 + fragment@2 {
79 + target = <&sound>;
80 + iqaudio_dac: __overlay__ {
81 + compatible = "iqaudio,iqaudio-codec";
82 + i2s-controller = <&i2s>;
83 + status = "okay";
84 + };
85 + };
86 +
87 + __overrides__ {
88 + };
89 +};
90 --- a/sound/soc/bcm/Kconfig
91 +++ b/sound/soc/bcm/Kconfig
92 @@ -108,6 +108,13 @@ config SND_BCM2708_SOC_JUSTBOOM_DIGI
93 help
94 Say Y or M if you want to add support for JustBoom Digi.
95
96 +config SND_BCM2708_SOC_IQAUDIO_CODEC
97 + tristate "Support for IQaudIO-CODEC"
98 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
99 + select SND_SOC_DA7213
100 + help
101 + Say Y or M if you want to add support for IQaudIO-CODEC.
102 +
103 config SND_BCM2708_SOC_IQAUDIO_DAC
104 tristate "Support for IQaudIO-DAC"
105 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
106 --- a/sound/soc/bcm/Makefile
107 +++ b/sound/soc/bcm/Makefile
108 @@ -18,6 +18,7 @@ snd-soc-hifiberry-dacplusadc-objs := hif
109 snd-soc-justboom-dac-objs := justboom-dac.o
110 snd-soc-rpi-cirrus-objs := rpi-cirrus.o
111 snd-soc-rpi-proto-objs := rpi-proto.o
112 +snd-soc-iqaudio-codec-objs := iqaudio-codec.o
113 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
114 snd-soc-i-sabre-q2m-objs := i-sabre-q2m.o
115 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
116 @@ -42,6 +43,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_D
117 obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
118 obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
119 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
120 +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_CODEC) += snd-soc-iqaudio-codec.o
121 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
122 obj-$(CONFIG_SND_BCM2708_SOC_I_SABRE_Q2M) += snd-soc-i-sabre-q2m.o
123 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
124 --- /dev/null
125 +++ b/sound/soc/bcm/iqaudio-codec.c
126 @@ -0,0 +1,250 @@
127 +/*
128 + * ASoC Driver for IQaudIO Raspberry Pi Codec board
129 + *
130 + * Author: Gordon Garrity <gordon@iqaudio.com>
131 + * (C) Copyright IQaudio Limited, 2017-2019
132 + *
133 + * This program is free software; you can redistribute it and/or
134 + * modify it under the terms of the GNU General Public License
135 + * version 2 as published by the Free Software Foundation.
136 + *
137 + * This program is distributed in the hope that it will be useful, but
138 + * WITHOUT ANY WARRANTY; without even the implied warranty of
139 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
140 + * General Public License for more details.
141 + */
142 +
143 +#include <linux/module.h>
144 +#include <linux/gpio/consumer.h>
145 +#include <linux/platform_device.h>
146 +
147 +#include <sound/core.h>
148 +#include <sound/pcm.h>
149 +#include <sound/pcm_params.h>
150 +#include <sound/soc.h>
151 +#include <sound/jack.h>
152 +
153 +#include <linux/acpi.h>
154 +#include <linux/slab.h>
155 +#include "../codecs/da7213.h"
156 +
157 +static int pll_out = DA7213_PLL_FREQ_OUT_90316800;
158 +
159 +static int snd_rpi_iqaudio_pll_control(struct snd_soc_dapm_widget *w,
160 + struct snd_kcontrol *k, int event)
161 +{
162 + int ret = 0;
163 + struct snd_soc_dapm_context *dapm = w->dapm;
164 + struct snd_soc_card *card = dapm->card;
165 + struct snd_soc_pcm_runtime *rtd =
166 + snd_soc_get_pcm_runtime(card, card->dai_link[0].name);
167 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
168 +
169 + if (SND_SOC_DAPM_EVENT_OFF(event)) {
170 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_MCLK, 0,
171 + 0);
172 + if (ret)
173 + dev_err(card->dev, "Failed to bypass PLL: %d\n", ret);
174 + } else if (SND_SOC_DAPM_EVENT_ON(event)) {
175 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_PLL, 0,
176 + pll_out);
177 + if (ret)
178 + dev_err(card->dev, "Failed to enable PLL: %d\n", ret);
179 + }
180 +
181 + return ret;
182 +}
183 +
184 +static int snd_rpi_iqaudio_post_dapm_event(struct snd_soc_dapm_widget *w,
185 + struct snd_kcontrol *kcontrol,
186 + int event)
187 +{
188 + switch (event) {
189 + case SND_SOC_DAPM_POST_PMU:
190 + /* Delay for mic bias ramp */
191 + msleep(1000);
192 + break;
193 + default:
194 + break;
195 + }
196 +
197 + return 0;
198 +}
199 +
200 +static const struct snd_soc_dapm_widget dapm_widgets[] = {
201 + SND_SOC_DAPM_HP("HP Jack", NULL),
202 + SND_SOC_DAPM_MIC("MIC Jack", NULL),
203 + SND_SOC_DAPM_MIC("Onboard MIC", NULL),
204 + SND_SOC_DAPM_LINE("AUX Jack", NULL),
205 + SND_SOC_DAPM_SUPPLY("PLL Control", SND_SOC_NOPM, 0, 0,
206 + snd_rpi_iqaudio_pll_control,
207 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
208 + SND_SOC_DAPM_POST("Post Power Up Event", snd_rpi_iqaudio_post_dapm_event),
209 +};
210 +
211 +static const struct snd_soc_dapm_route audio_map[] = {
212 + {"HP Jack", NULL, "HPL"},
213 + {"HP Jack", NULL, "HPR"},
214 + {"HP Jack", NULL, "PLL Control"},
215 +
216 + {"AUX Jack", NULL, "AUXR"},
217 + {"AUX Jack", NULL, "AUXL"},
218 + {"AUX Jack", NULL, "PLL Control"},
219 +
220 + /* Assume Mic1 is linked to Headset and Mic2 to on-board mic */
221 + {"MIC Jack", NULL, "MIC1"},
222 + {"MIC Jack", NULL, "PLL Control"},
223 + {"Onboard MIC", NULL, "MIC2"},
224 + {"Onboard MIC", NULL, "PLL Control"},
225 +};
226 +
227 +/* machine stream operations */
228 +
229 +static int snd_rpi_iqaudio_codec_init(struct snd_soc_pcm_runtime *rtd)
230 +{
231 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
232 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
233 + int ret;
234 +
235 + /* Set bclk ratio to align with codec's BCLK rate */
236 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
237 + if (ret) {
238 + dev_err(rtd->dev, "Failed to set CPU BLCK ratio\n");
239 + return ret;
240 + }
241 +
242 + /* Set MCLK frequency to codec, onboard 11.2896MHz clock */
243 + return snd_soc_dai_set_sysclk(codec_dai, DA7213_CLKSRC_MCLK, 11289600,
244 + SND_SOC_CLOCK_OUT);
245 +}
246 +
247 +static int snd_rpi_iqaudio_codec_hw_params(struct snd_pcm_substream *substream,
248 + struct snd_pcm_hw_params *params)
249 +{
250 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
251 + unsigned int samplerate = params_rate(params);
252 +
253 + switch (samplerate) {
254 + case 8000:
255 + case 16000:
256 + case 32000:
257 + case 48000:
258 + case 96000:
259 + pll_out = DA7213_PLL_FREQ_OUT_98304000;
260 + return 0;
261 + case 44100:
262 + case 88200:
263 + pll_out = DA7213_PLL_FREQ_OUT_90316800;
264 + return 0;
265 + default:
266 + dev_err(rtd->dev,"Unsupported samplerate %d\n", samplerate);
267 + return -EINVAL;
268 + }
269 +}
270 +
271 +static const struct snd_soc_ops snd_rpi_iqaudio_codec_ops = {
272 + .hw_params = snd_rpi_iqaudio_codec_hw_params,
273 +};
274 +
275 +
276 +static struct snd_soc_dai_link snd_rpi_iqaudio_codec_dai[] = {
277 +{
278 + .cpu_dai_name = "bcm2708-i2s.0",
279 + .codec_dai_name = "da7213-hifi",
280 + .platform_name = "bmc2708-i2s.0",
281 + .codec_name = "da7213.1-001a",
282 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
283 + SND_SOC_DAIFMT_CBM_CFM,
284 + .init = snd_rpi_iqaudio_codec_init,
285 + .ops = &snd_rpi_iqaudio_codec_ops,
286 + .symmetric_rates = 1,
287 + .symmetric_channels = 1,
288 + .symmetric_samplebits = 1,
289 +},
290 +};
291 +
292 +/* audio machine driver */
293 +static struct snd_soc_card snd_rpi_iqaudio_codec = {
294 + .owner = THIS_MODULE,
295 + .dai_link = snd_rpi_iqaudio_codec_dai,
296 + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_codec_dai),
297 + .dapm_widgets = dapm_widgets,
298 + .num_dapm_widgets = ARRAY_SIZE(dapm_widgets),
299 + .dapm_routes = audio_map,
300 + .num_dapm_routes = ARRAY_SIZE(audio_map),
301 +};
302 +
303 +static int snd_rpi_iqaudio_codec_probe(struct platform_device *pdev)
304 +{
305 + int ret = 0;
306 +
307 + snd_rpi_iqaudio_codec.dev = &pdev->dev;
308 +
309 + if (pdev->dev.of_node) {
310 + struct device_node *i2s_node;
311 + struct snd_soc_card *card = &snd_rpi_iqaudio_codec;
312 + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_codec_dai[0];
313 +
314 + i2s_node = of_parse_phandle(pdev->dev.of_node,
315 + "i2s-controller", 0);
316 + if (i2s_node) {
317 + dai->cpu_dai_name = NULL;
318 + dai->cpu_of_node = i2s_node;
319 + dai->platform_name = NULL;
320 + dai->platform_of_node = i2s_node;
321 + }
322 +
323 + if (of_property_read_string(pdev->dev.of_node, "card_name",
324 + &card->name))
325 + card->name = "IQaudIOCODEC";
326 +
327 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
328 + &dai->name))
329 + dai->name = "IQaudIO CODEC";
330 +
331 + if (of_property_read_string(pdev->dev.of_node,
332 + "dai_stream_name", &dai->stream_name))
333 + dai->stream_name = "IQaudIO CODEC HiFi v1.1";
334 +
335 + }
336 +
337 + ret = snd_soc_register_card(&snd_rpi_iqaudio_codec);
338 + if (ret) {
339 + if (ret != -EPROBE_DEFER)
340 + dev_err(&pdev->dev,
341 + "snd_soc_register_card() failed: %d\n", ret);
342 + return ret;
343 + }
344 +
345 + return 0;
346 +}
347 +
348 +static int snd_rpi_iqaudio_codec_remove(struct platform_device *pdev)
349 +{
350 + return snd_soc_unregister_card(&snd_rpi_iqaudio_codec);
351 +}
352 +
353 +static const struct of_device_id iqaudio_of_match[] = {
354 + { .compatible = "iqaudio,iqaudio-codec", },
355 + {},
356 +};
357 +
358 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
359 +
360 +static struct platform_driver snd_rpi_iqaudio_codec_driver = {
361 + .driver = {
362 + .name = "snd-rpi-iqaudio-codec",
363 + .owner = THIS_MODULE,
364 + .of_match_table = iqaudio_of_match,
365 + },
366 + .probe = snd_rpi_iqaudio_codec_probe,
367 + .remove = snd_rpi_iqaudio_codec_remove,
368 +};
369 +
370 +
371 +
372 +module_platform_driver(snd_rpi_iqaudio_codec_driver);
373 +
374 +MODULE_AUTHOR("Gordon Garrity <gordon@iqaudio.com>");
375 +MODULE_DESCRIPTION("ASoC Driver for IQaudIO CODEC");
376 +MODULE_LICENSE("GPL v2");