mediatek: add v4.19 support
[openwrt/staging/lynxis.git] / target / linux / brcm2708 / patches-4.19 / 950-0309-Added-driver-for-the-HiFiBerry-DAC-ADC-2694.patch
1 From e4b9a8f537b069bd3017f30b21bceb811263c979 Mon Sep 17 00:00:00 2001
2 From: HiFiBerry <info@hifiberry.com>
3 Date: Mon, 8 Oct 2018 18:10:12 +0200
4 Subject: [PATCH 309/703] Added driver for the HiFiBerry DAC+ ADC (#2694)
5
6 Signed-off-by: Daniel Matuschek <daniel@hifiberry.com>
7 ---
8 arch/arm/boot/dts/overlays/Makefile | 1 +
9 arch/arm/boot/dts/overlays/README | 21 +
10 .../overlays/hifiberry-dacplusadc-overlay.dts | 71 +++
11 arch/arm/configs/bcm2709_defconfig | 1 +
12 arch/arm/configs/bcmrpi_defconfig | 1 +
13 sound/soc/bcm/Kconfig | 8 +
14 sound/soc/bcm/Makefile | 2 +
15 sound/soc/bcm/hifiberry_dacplusadc.c | 407 ++++++++++++++++++
16 8 files changed, 512 insertions(+)
17 create mode 100644 arch/arm/boot/dts/overlays/hifiberry-dacplusadc-overlay.dts
18 create mode 100644 sound/soc/bcm/hifiberry_dacplusadc.c
19
20 --- a/arch/arm/boot/dts/overlays/Makefile
21 +++ b/arch/arm/boot/dts/overlays/Makefile
22 @@ -49,6 +49,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
23 hifiberry-amp.dtbo \
24 hifiberry-dac.dtbo \
25 hifiberry-dacplus.dtbo \
26 + hifiberry-dacplusadc.dtbo \
27 hifiberry-digi.dtbo \
28 hifiberry-digi-pro.dtbo \
29 hy28a.dtbo \
30 --- a/arch/arm/boot/dts/overlays/README
31 +++ b/arch/arm/boot/dts/overlays/README
32 @@ -779,6 +779,27 @@ Params: 24db_digital_gain Allow ga
33 master for bit clock and frame clock.
34
35
36 +Name: hifiberry-dacplusadc
37 +Info: Configures the HifiBerry DAC+ADC audio card
38 +Load: dtoverlay=hifiberry-dacplusadc,<param>=<val>
39 +Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
40 + Digital volume control. Enable with
41 + "dtoverlay=hifiberry-dacplus,24db_digital_gain"
42 + (The default behaviour is that the Digital
43 + volume control is limited to a maximum of
44 + 0dB. ie. it can attenuate but not provide
45 + gain. For most users, this will be desired
46 + as it will prevent clipping. By appending
47 + the 24dB_digital_gain parameter, the Digital
48 + volume control will allow up to 24dB of
49 + gain. If this parameter is enabled, it is the
50 + responsibility of the user to ensure that
51 + the Digital volume control is set to a value
52 + that does not result in clipping/distortion!)
53 + slave Force DAC+ Pro into slave mode, using Pi as
54 + master for bit clock and frame clock.
55 +
56 +
57 Name: hifiberry-digi
58 Info: Configures the HifiBerry Digi and Digi+ audio card
59 Load: dtoverlay=hifiberry-digi
60 --- /dev/null
61 +++ b/arch/arm/boot/dts/overlays/hifiberry-dacplusadc-overlay.dts
62 @@ -0,0 +1,71 @@
63 +// Definitions for HiFiBerry DAC+ADC
64 +/dts-v1/;
65 +/plugin/;
66 +
67 +/ {
68 + compatible = "brcm,bcm2708";
69 +
70 + fragment@0 {
71 + target-path = "/clocks";
72 + __overlay__ {
73 + dacpro_osc: dacpro_osc {
74 + compatible = "hifiberry,dacpro-clk";
75 + #clock-cells = <0>;
76 + };
77 + };
78 + };
79 +
80 + fragment@1 {
81 + target = <&i2s>;
82 + __overlay__ {
83 + status = "okay";
84 + };
85 + };
86 +
87 + fragment@2 {
88 + target = <&i2c1>;
89 + __overlay__ {
90 + #address-cells = <1>;
91 + #size-cells = <0>;
92 + status = "okay";
93 +
94 + pcm_codec: pcm5122@4d {
95 + #sound-dai-cells = <0>;
96 + compatible = "ti,pcm5122";
97 + reg = <0x4d>;
98 + clocks = <&dacpro_osc>;
99 + AVDD-supply = <&vdd_3v3_reg>;
100 + DVDD-supply = <&vdd_3v3_reg>;
101 + CPVDD-supply = <&vdd_3v3_reg>;
102 + status = "okay";
103 + };
104 + };
105 + };
106 +
107 + fragment@3 {
108 + target-path = "/";
109 + __overlay__ {
110 + dmic {
111 + #sound-dai-cells = <0>;
112 + compatible = "dmic-codec";
113 + num-channels = <2>;
114 + status = "okay";
115 + };
116 + };
117 + };
118 +
119 + fragment@4 {
120 + target = <&sound>;
121 + hifiberry_dacplusadc: __overlay__ {
122 + compatible = "hifiberry,hifiberry-dacplusadc";
123 + i2s-controller = <&i2s>;
124 + status = "okay";
125 + };
126 + };
127 +
128 + __overrides__ {
129 + 24db_digital_gain =
130 + <&hifiberry_dacplusadc>,"hifiberry,24db_digital_gain?";
131 + slave = <&hifiberry_dacplusadc>,"hifiberry-dacplusadc,slave?";
132 + };
133 +};
134 --- a/arch/arm/configs/bcm2709_defconfig
135 +++ b/arch/arm/configs/bcm2709_defconfig
136 @@ -905,6 +905,7 @@ CONFIG_SND_BCM2835_SOC_I2S=m
137 CONFIG_SND_BCM2708_SOC_3DLAB_NANO_PLAYER=m
138 CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD=m
139 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
140 +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC=m
141 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
142 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
143 CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
144 --- a/arch/arm/configs/bcmrpi_defconfig
145 +++ b/arch/arm/configs/bcmrpi_defconfig
146 @@ -898,6 +898,7 @@ CONFIG_SND_BCM2835_SOC_I2S=m
147 CONFIG_SND_BCM2708_SOC_3DLAB_NANO_PLAYER=m
148 CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD=m
149 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
150 +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC=m
151 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
152 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
153 CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
154 --- a/sound/soc/bcm/Kconfig
155 +++ b/sound/soc/bcm/Kconfig
156 @@ -46,6 +46,14 @@ config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
157 help
158 Say Y or M if you want to add support for HifiBerry DAC+.
159
160 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC
161 + tristate "Support for HifiBerry DAC+ADC"
162 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
163 + select SND_SOC_PCM512x_I2C
164 + select SND_SOC_DMIC
165 + help
166 + Say Y or M if you want to add support for HifiBerry DAC+ADC.
167 +
168 config SND_BCM2708_SOC_HIFIBERRY_DIGI
169 tristate "Support for HifiBerry Digi"
170 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
171 --- a/sound/soc/bcm/Makefile
172 +++ b/sound/soc/bcm/Makefile
173 @@ -14,6 +14,7 @@ snd-soc-googlevoicehat-codec-objs := goo
174 # BCM2708 Machine Support
175 snd-soc-3dlab-nano-player-objs := 3dlab-nano-player.o
176 snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
177 +snd-soc-hifiberry-dacplusadc-objs := hifiberry_dacplusadc.o
178 snd-soc-justboom-dac-objs := justboom-dac.o
179 snd-soc-rpi-cirrus-objs := rpi-cirrus.o
180 snd-soc-rpi-proto-objs := rpi-proto.o
181 @@ -36,6 +37,7 @@ snd-soc-rpi-wm8804-soundcard-objs := rpi
182 obj-$(CONFIG_SND_BCM2708_SOC_3DLAB_NANO_PLAYER) += snd-soc-3dlab-nano-player.o
183 obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD) += snd-soc-googlevoicehat-codec.o
184 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
185 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC) += snd-soc-hifiberry-dacplusadc.o
186 obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
187 obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
188 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
189 --- /dev/null
190 +++ b/sound/soc/bcm/hifiberry_dacplusadc.c
191 @@ -0,0 +1,407 @@
192 +/*
193 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro with ADC
194 + *
195 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
196 + * Copyright 2014-2015
197 + * based on code by Florian Meier <florian.meier@koalo.de>
198 + * ADC added by Joerg Schambacher <joscha@schambacher.com>
199 + * Copyright 2018
200 + *
201 + * This program is free software; you can redistribute it and/or
202 + * modify it under the terms of the GNU General Public License
203 + * version 2 as published by the Free Software Foundation.
204 + *
205 + * This program is distributed in the hope that it will be useful, but
206 + * WITHOUT ANY WARRANTY; without even the implied warranty of
207 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
208 + * General Public License for more details.
209 + */
210 +
211 +#include <linux/module.h>
212 +#include <linux/platform_device.h>
213 +#include <linux/kernel.h>
214 +#include <linux/clk.h>
215 +#include <linux/kernel.h>
216 +#include <linux/module.h>
217 +#include <linux/of.h>
218 +#include <linux/slab.h>
219 +#include <linux/delay.h>
220 +
221 +#include <sound/core.h>
222 +#include <sound/pcm.h>
223 +#include <sound/pcm_params.h>
224 +#include <sound/soc.h>
225 +#include <sound/jack.h>
226 +
227 +#include "../codecs/pcm512x.h"
228 +
229 +#define HIFIBERRY_DACPRO_NOCLOCK 0
230 +#define HIFIBERRY_DACPRO_CLK44EN 1
231 +#define HIFIBERRY_DACPRO_CLK48EN 2
232 +
233 +struct platform_device *dmic_codec_dev;
234 +
235 +struct pcm512x_priv {
236 + struct regmap *regmap;
237 + struct clk *sclk;
238 +};
239 +
240 +/* Clock rate of CLK44EN attached to GPIO6 pin */
241 +#define CLK_44EN_RATE 22579200UL
242 +/* Clock rate of CLK48EN attached to GPIO3 pin */
243 +#define CLK_48EN_RATE 24576000UL
244 +
245 +static bool slave;
246 +static bool snd_rpi_hifiberry_is_dacpro;
247 +static bool digital_gain_0db_limit = true;
248 +
249 +static void snd_rpi_hifiberry_dacplusadc_select_clk(struct snd_soc_component *component,
250 + int clk_id)
251 +{
252 + switch (clk_id) {
253 + case HIFIBERRY_DACPRO_NOCLOCK:
254 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
255 + break;
256 + case HIFIBERRY_DACPRO_CLK44EN:
257 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
258 + break;
259 + case HIFIBERRY_DACPRO_CLK48EN:
260 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
261 + break;
262 + }
263 +}
264 +
265 +static void snd_rpi_hifiberry_dacplusadc_clk_gpio(struct snd_soc_component *component)
266 +{
267 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
268 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
269 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
270 +}
271 +
272 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk(struct snd_soc_component *component)
273 +{
274 + unsigned int sck;
275 +
276 + snd_soc_component_read(component, PCM512x_RATE_DET_4, &sck);
277 + return (!(sck & 0x40));
278 +}
279 +
280 +static bool snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(
281 + struct snd_soc_component *component)
282 +{
283 + msleep(2);
284 + return snd_rpi_hifiberry_dacplusadc_is_sclk(component);
285 +}
286 +
287 +static bool snd_rpi_hifiberry_dacplusadc_is_pro_card(struct snd_soc_component *component)
288 +{
289 + bool isClk44EN, isClk48En, isNoClk;
290 +
291 + snd_rpi_hifiberry_dacplusadc_clk_gpio(component);
292 +
293 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
294 + isClk44EN = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
295 +
296 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
297 + isNoClk = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
298 +
299 + snd_rpi_hifiberry_dacplusadc_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
300 + isClk48En = snd_rpi_hifiberry_dacplusadc_is_sclk_sleep(component);
301 +
302 + return (isClk44EN && isClk48En && !isNoClk);
303 +}
304 +
305 +static int snd_rpi_hifiberry_dacplusadc_clk_for_rate(int sample_rate)
306 +{
307 + int type;
308 +
309 + switch (sample_rate) {
310 + case 11025:
311 + case 22050:
312 + case 44100:
313 + case 88200:
314 + case 176400:
315 + case 352800:
316 + type = HIFIBERRY_DACPRO_CLK44EN;
317 + break;
318 + default:
319 + type = HIFIBERRY_DACPRO_CLK48EN;
320 + break;
321 + }
322 + return type;
323 +}
324 +
325 +static void snd_rpi_hifiberry_dacplusadc_set_sclk(struct snd_soc_component *component,
326 + int sample_rate)
327 +{
328 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
329 +
330 + if (!IS_ERR(pcm512x->sclk)) {
331 + int ctype;
332 +
333 + ctype = snd_rpi_hifiberry_dacplusadc_clk_for_rate(sample_rate);
334 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
335 + ? CLK_44EN_RATE : CLK_48EN_RATE);
336 + snd_rpi_hifiberry_dacplusadc_select_clk(component, ctype);
337 + }
338 +}
339 +
340 +static int snd_rpi_hifiberry_dacplusadc_init(struct snd_soc_pcm_runtime *rtd)
341 +{
342 + struct snd_soc_component *component = rtd->codec_dai->component;
343 + struct pcm512x_priv *priv;
344 +
345 + if (slave)
346 + snd_rpi_hifiberry_is_dacpro = false;
347 + else
348 + snd_rpi_hifiberry_is_dacpro =
349 + snd_rpi_hifiberry_dacplusadc_is_pro_card(component);
350 +
351 + if (snd_rpi_hifiberry_is_dacpro) {
352 + struct snd_soc_dai_link *dai = rtd->dai_link;
353 +
354 + dai->name = "HiFiBerry ADCDAC+ Pro";
355 + dai->stream_name = "HiFiBerry ADCDAC+ Pro HiFi";
356 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
357 + | SND_SOC_DAIFMT_CBM_CFM;
358 +
359 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
360 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
361 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
362 + } else {
363 + priv = snd_soc_component_get_drvdata(component);
364 + priv->sclk = ERR_PTR(-ENOENT);
365 + }
366 +
367 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
368 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
369 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
370 +
371 + if (digital_gain_0db_limit) {
372 + int ret;
373 + struct snd_soc_card *card = rtd->card;
374 +
375 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
376 + if (ret < 0)
377 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
378 + }
379 +
380 + return 0;
381 +}
382 +
383 +static int snd_rpi_hifiberry_dacplusadc_update_rate_den(
384 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
385 +{
386 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
387 + struct snd_soc_component *component = rtd->codec_dai->component;
388 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
389 + struct snd_ratnum *rats_no_pll;
390 + unsigned int num = 0, den = 0;
391 + int err;
392 +
393 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
394 + if (!rats_no_pll)
395 + return -ENOMEM;
396 +
397 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
398 + rats_no_pll->den_min = 1;
399 + rats_no_pll->den_max = 128;
400 + rats_no_pll->den_step = 1;
401 +
402 + err = snd_interval_ratnum(hw_param_interval(params,
403 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
404 + if (err >= 0 && den) {
405 + params->rate_num = num;
406 + params->rate_den = den;
407 + }
408 +
409 + devm_kfree(rtd->dev, rats_no_pll);
410 + return 0;
411 +}
412 +
413 +static int snd_rpi_hifiberry_dacplusadc_hw_params(
414 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
415 +{
416 + int ret = 0;
417 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
418 + int channels = params_channels(params);
419 + int width = 32;
420 +
421 + if (snd_rpi_hifiberry_is_dacpro) {
422 + struct snd_soc_component *component = rtd->codec_dai->component;
423 +
424 + width = snd_pcm_format_physical_width(params_format(params));
425 +
426 + snd_rpi_hifiberry_dacplusadc_set_sclk(component,
427 + params_rate(params));
428 +
429 + ret = snd_rpi_hifiberry_dacplusadc_update_rate_den(
430 + substream, params);
431 + }
432 +
433 + ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x03, 0x03,
434 + channels, width);
435 + if (ret)
436 + return ret;
437 + ret = snd_soc_dai_set_tdm_slot(rtd->codec_dai, 0x03, 0x03,
438 + channels, width);
439 + return ret;
440 +}
441 +
442 +static int hifiberry_dacplusadc_LED_cnt;
443 +
444 +static int snd_rpi_hifiberry_dacplusadc_startup(
445 + struct snd_pcm_substream *substream)
446 +{
447 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
448 + struct snd_soc_component *component = rtd->codec_dai->component;
449 +
450 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
451 + 0x08, 0x08);
452 + hifiberry_dacplusadc_LED_cnt++;
453 + return 0;
454 +}
455 +
456 +static void snd_rpi_hifiberry_dacplusadc_shutdown(
457 + struct snd_pcm_substream *substream)
458 +{
459 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
460 + struct snd_soc_component *component = rtd->codec_dai->component;
461 +
462 + hifiberry_dacplusadc_LED_cnt--;
463 + if (!hifiberry_dacplusadc_LED_cnt)
464 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1,
465 + 0x08, 0x00);
466 +}
467 +
468 +/* machine stream operations */
469 +static struct snd_soc_ops snd_rpi_hifiberry_dacplusadc_ops = {
470 + .hw_params = snd_rpi_hifiberry_dacplusadc_hw_params,
471 + .startup = snd_rpi_hifiberry_dacplusadc_startup,
472 + .shutdown = snd_rpi_hifiberry_dacplusadc_shutdown,
473 +};
474 +
475 +static struct snd_soc_dai_link_component snd_rpi_hifiberry_dacplusadc_codecs[] = {
476 + {
477 + .name = "pcm512x.1-004d",
478 + .dai_name = "pcm512x-hifi",
479 + },
480 + {
481 + .name = "dmic-codec",
482 + .dai_name = "dmic-hifi",
483 + },
484 +};
485 +
486 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadc_dai[] = {
487 +{
488 + .name = "HiFiBerry DAC+ADC",
489 + .stream_name = "HiFiBerry DAC+ADC HiFi",
490 + .cpu_dai_name = "bcm2708-i2s.0",
491 + .platform_name = "bcm2708-i2s.0",
492 + .codecs = snd_rpi_hifiberry_dacplusadc_codecs,
493 + .num_codecs = 2,
494 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
495 + SND_SOC_DAIFMT_CBS_CFS,
496 + .ops = &snd_rpi_hifiberry_dacplusadc_ops,
497 + .init = snd_rpi_hifiberry_dacplusadc_init,
498 +},
499 +};
500 +
501 +/* audio machine driver */
502 +static struct snd_soc_card snd_rpi_hifiberry_dacplusadc = {
503 + .name = "snd_rpi_hifiberry_dacplusadc",
504 + .driver_name = "HifiberryDacpAdc",
505 + .owner = THIS_MODULE,
506 + .dai_link = snd_rpi_hifiberry_dacplusadc_dai,
507 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplusadc_dai),
508 +};
509 +
510 +
511 +static int snd_rpi_hifiberry_dacplusadc_probe(struct platform_device *pdev)
512 +{
513 + int ret = 0;
514 +
515 + snd_rpi_hifiberry_dacplusadc.dev = &pdev->dev;
516 + if (pdev->dev.of_node) {
517 + struct device_node *i2s_node;
518 + struct snd_soc_dai_link *dai;
519 +
520 + dai = &snd_rpi_hifiberry_dacplusadc_dai[0];
521 + i2s_node = of_parse_phandle(pdev->dev.of_node,
522 + "i2s-controller", 0);
523 + if (i2s_node) {
524 + dai->cpu_of_node = i2s_node;
525 + dai->platform_of_node = i2s_node;
526 + dai->cpu_dai_name = NULL;
527 + dai->platform_name = NULL;
528 + }
529 + dai = &snd_rpi_hifiberry_dacplusadc_dai[1];
530 + i2s_node = of_parse_phandle(pdev->dev.of_node, "dmic", 0);
531 + if (i2s_node) {
532 + dai->cpu_of_node = i2s_node;
533 + dai->platform_of_node = i2s_node;
534 + }
535 +
536 + }
537 + digital_gain_0db_limit = !of_property_read_bool(
538 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
539 + slave = of_property_read_bool(pdev->dev.of_node,
540 + "hifiberry-dacplusadc,slave");
541 +
542 + ret = devm_snd_soc_register_card(&pdev->dev,
543 + &snd_rpi_hifiberry_dacplusadc);
544 + if (ret && ret != -EPROBE_DEFER)
545 + dev_err(&pdev->dev,
546 + "snd_soc_register_card() failed: %d\n", ret);
547 +
548 + return ret;
549 +}
550 +
551 +static const struct of_device_id snd_rpi_hifiberry_dacplusadc_of_match[] = {
552 + { .compatible = "hifiberry,hifiberry-dacplusadc", },
553 + {},
554 +};
555 +
556 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplusadc_of_match);
557 +
558 +static struct platform_driver snd_rpi_hifiberry_dacplusadc_driver = {
559 + .driver = {
560 + .name = "snd-rpi-hifiberry-dacplusadc",
561 + .owner = THIS_MODULE,
562 + .of_match_table = snd_rpi_hifiberry_dacplusadc_of_match,
563 + },
564 + .probe = snd_rpi_hifiberry_dacplusadc_probe,
565 +};
566 +
567 +static int __init hifiberry_dacplusadc_init(void)
568 +{
569 + int ret;
570 +
571 + dmic_codec_dev = platform_device_register_simple("dmic-codec", -1, NULL,
572 + 0);
573 + if (IS_ERR(dmic_codec_dev)) {
574 + pr_err("%s: dmic-codec device registration failed\n", __func__);
575 + return PTR_ERR(dmic_codec_dev);
576 + }
577 +
578 + ret = platform_driver_register(&snd_rpi_hifiberry_dacplusadc_driver);
579 + if (ret) {
580 + pr_err("%s: platform driver registration failed\n", __func__);
581 + platform_device_unregister(dmic_codec_dev);
582 + }
583 +
584 + return ret;
585 +}
586 +module_init(hifiberry_dacplusadc_init);
587 +
588 +static void __exit hifiberry_dacplusadc_exit(void)
589 +{
590 + platform_driver_unregister(&snd_rpi_hifiberry_dacplusadc_driver);
591 + platform_device_unregister(dmic_codec_dev);
592 +}
593 +module_exit(hifiberry_dacplusadc_exit);
594 +
595 +MODULE_AUTHOR("Joerg Schambacher <joscha@schambacher.com>");
596 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
597 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+ADC");
598 +MODULE_LICENSE("GPL v2");