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 489/806] Added IQaudIO Pi-Codec board support (#2969)
6 Add support for the IQaudIO Pi-Codec board.
8 Signed-off-by: Gordon <gordon@iqaudio.com>
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
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) += \
29 + iqaudio-codec.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)
40 +Info: Configures the IQaudio Codec audio card
41 +Load: dtoverlay=iqaudio-codec
46 Info: Configures the IQaudio DAC audio card
47 Load: dtoverlay=iqaudio-dac,<param>
49 +++ b/arch/arm/boot/dts/overlays/iqaudio-codec-overlay.dts
51 +// Definitions for IQaudIO CODEC
56 + compatible = "brcm,bcm2708";
68 + #address-cells = <1>;
73 + #sound-dai-cells = <0>;
74 + compatible = "dlg,da7213";
83 + iqaudio_dac: __overlay__ {
84 + compatible = "iqaudio,iqaudio-codec";
85 + i2s-controller = <&i2s>;
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
127 Say Y or M if you want to add support for JustBoom Digi.
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
134 + Say Y or M if you want to add support for IQaudIO-CODEC.
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
158 +++ b/sound/soc/bcm/iqaudio-codec.c
161 + * ASoC Driver for IQaudIO Raspberry Pi Codec board
163 + * Author: Gordon Garrity <gordon@iqaudio.com>
164 + * (C) Copyright IQaudio Limited, 2017-2019
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.
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.
176 +#include <linux/module.h>
177 +#include <linux/gpio/consumer.h>
178 +#include <linux/platform_device.h>
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>
186 +#include <linux/acpi.h>
187 +#include <linux/slab.h>
188 +#include "../codecs/da7213.h"
190 +static int pll_out = DA7213_PLL_FREQ_OUT_90316800;
192 +static int snd_rpi_iqaudio_pll_control(struct snd_soc_dapm_widget *w,
193 + struct snd_kcontrol *k, int event)
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;
202 + if (SND_SOC_DAPM_EVENT_OFF(event)) {
203 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_MCLK, 0,
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,
211 + dev_err(card->dev, "Failed to enable PLL: %d\n", ret);
217 +static int snd_rpi_iqaudio_post_dapm_event(struct snd_soc_dapm_widget *w,
218 + struct snd_kcontrol *kcontrol,
222 + case SND_SOC_DAPM_POST_PMU:
223 + /* Delay for mic bias ramp */
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),
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"},
249 + {"AUX Jack", NULL, "AUXR"},
250 + {"AUX Jack", NULL, "AUXL"},
251 + {"AUX Jack", NULL, "PLL Control"},
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"},
260 +/* machine stream operations */
262 +static int snd_rpi_iqaudio_codec_init(struct snd_soc_pcm_runtime *rtd)
264 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
265 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
268 + /* Set bclk ratio to align with codec's BCLK rate */
269 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
271 + dev_err(rtd->dev, "Failed to set CPU BLCK ratio\n");
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);
280 +static int snd_rpi_iqaudio_codec_hw_params(struct snd_pcm_substream *substream,
281 + struct snd_pcm_hw_params *params)
283 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
284 + unsigned int samplerate = params_rate(params);
286 + switch (samplerate) {
292 + pll_out = DA7213_PLL_FREQ_OUT_98304000;
296 + pll_out = DA7213_PLL_FREQ_OUT_90316800;
299 + dev_err(rtd->dev,"Unsupported samplerate %d\n", samplerate);
304 +static const struct snd_soc_ops snd_rpi_iqaudio_codec_ops = {
305 + .hw_params = snd_rpi_iqaudio_codec_hw_params,
309 +static struct snd_soc_dai_link snd_rpi_iqaudio_codec_dai[] = {
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,
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),
336 +static int snd_rpi_iqaudio_codec_probe(struct platform_device *pdev)
340 + snd_rpi_iqaudio_codec.dev = &pdev->dev;
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];
347 + i2s_node = of_parse_phandle(pdev->dev.of_node,
348 + "i2s-controller", 0);
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;
356 + if (of_property_read_string(pdev->dev.of_node, "card_name",
358 + card->name = "IQaudIOCODEC";
360 + if (of_property_read_string(pdev->dev.of_node, "dai_name",
362 + dai->name = "IQaudIO CODEC";
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";
370 + ret = snd_soc_register_card(&snd_rpi_iqaudio_codec);
372 + if (ret != -EPROBE_DEFER)
373 + dev_err(&pdev->dev,
374 + "snd_soc_register_card() failed: %d\n", ret);
381 +static int snd_rpi_iqaudio_codec_remove(struct platform_device *pdev)
383 + return snd_soc_unregister_card(&snd_rpi_iqaudio_codec);
386 +static const struct of_device_id iqaudio_of_match[] = {
387 + { .compatible = "iqaudio,iqaudio-codec", },
391 +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
393 +static struct platform_driver snd_rpi_iqaudio_codec_driver = {
395 + .name = "snd-rpi-iqaudio-codec",
396 + .owner = THIS_MODULE,
397 + .of_match_table = iqaudio_of_match,
399 + .probe = snd_rpi_iqaudio_codec_probe,
400 + .remove = snd_rpi_iqaudio_codec_remove,
405 +module_platform_driver(snd_rpi_iqaudio_codec_driver);
407 +MODULE_AUTHOR("Gordon Garrity <gordon@iqaudio.com>");
408 +MODULE_DESCRIPTION("ASoC Driver for IQaudIO CODEC");
409 +MODULE_LICENSE("GPL v2");