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