bcm27xx: add linux 5.4 support
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0061-Added-support-for-HiFiBerry-DAC.patch
1 From cd09df67ff15ee1a7c6aa33df6d76d1427ad23f8 Mon Sep 17 00:00:00 2001
2 From: Daniel Matuschek <info@crazy-audio.com>
3 Date: Mon, 4 Aug 2014 10:06:56 +0200
4 Subject: [PATCH] Added support for HiFiBerry DAC+
5
6 The driver is based on the HiFiBerry DAC driver. However HiFiBerry DAC+ uses
7 a different codec chip (PCM5122), therefore a new driver is necessary.
8
9 Add support for the HiFiBerry DAC+ Pro.
10
11 The HiFiBerry DAC+ and DAC+ Pro products both use the existing bcm sound driver with the DAC+ Pro having a special clock device driver representing the two high precision oscillators.
12
13 An addition bug fix is included for the PCM512x codec where by the physical size of the sample frame is used in the calculation of the LRCK divisor as it was found to be wrong when using 24-bit depth sample contained in a little endian 4-byte sample frame.
14
15 Limit PCM512x "Digital" gain to 0dB by default with HiFiBerry DAC+
16
17 24db_digital_gain DT param can be used to specify that PCM512x
18 codec "Digital" volume control should not be limited to 0dB gain,
19 and if specified will allow the full 24dB gain.
20
21 Add dt param to force HiFiBerry DAC+ Pro into slave mode
22
23 "dtoverlay=hifiberry-dacplus,slave"
24
25 Add 'slave' param to use HiFiBerry DAC+ Pro in slave mode,
26 with Pi as master for bit and frame clock.
27
28 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
29
30 Fixed a bug when using 352.8kHz sample rate
31
32 Signed-off-by: Daniel Matuschek <daniel@hifiberry.com>
33
34 ASoC: pcm512x: revert downstream changes
35
36 This partially reverts commit 185ea05465aac8bf02a0d2b2f4289d42c72870b7
37 which was added by https://github.com/raspberrypi/linux/pull/1152
38
39 The downstream pcm512x changes caused a regression, it broke normal
40 use of the 24bit format with the codec, eg when using simple-audio-card.
41
42 The actual bug with 24bit playback is the incorrect usage
43 of physical_width in various drivers in the downstream tree
44 which causes 24bit data to be transmitted with 32 clock
45 cycles. So it's not the pcm512x that needs fixing, it's the
46 soundcard drivers.
47
48 Signed-off-by: Matthias Reichl <hias@horus.com>
49
50 ASoC: hifiberry_dacplus: fix S24_LE format
51
52 Remove set_bclk_ratio call so 24-bit data is transmitted in
53 24 bclk cycles.
54
55 Signed-off-by: Matthias Reichl <hias@horus.com>
56
57 ASoC: hifiberry_dacplus: transmit S24_LE with 64 BCLK cycles
58
59 Signed-off-by: Matthias Reichl <hias@horus.com>
60
61 hifiberry_dacplus: switch to snd_soc_dai_set_bclk_ratio
62
63 Signed-off-by: Matthias Reichl <hias@horus.com>
64
65 ASoC: hifiberry_dacplus: use modern dai_link style
66
67 Signed-off-by: Hui Wang <hui.wang@canonical.com>
68 ---
69 drivers/clk/Kconfig | 3 +
70 drivers/clk/Makefile | 1 +
71 drivers/clk/clk-hifiberry-dacpro.c | 160 +++++++++++++
72 sound/soc/bcm/hifiberry_dacplus.c | 352 +++++++++++++++++++++++++++++
73 4 files changed, 516 insertions(+)
74 create mode 100644 drivers/clk/clk-hifiberry-dacpro.c
75 create mode 100644 sound/soc/bcm/hifiberry_dacplus.c
76
77 --- a/drivers/clk/Kconfig
78 +++ b/drivers/clk/Kconfig
79 @@ -70,6 +70,9 @@ config COMMON_CLK_HI655X
80 multi-function device has one fixed-rate oscillator, clocked
81 at 32KHz.
82
83 +config COMMON_CLK_HIFIBERRY_DACPRO
84 + tristate
85 +
86 config COMMON_CLK_SCMI
87 tristate "Clock driver controlled via SCMI interface"
88 depends on ARM_SCMI_PROTOCOL || COMPILE_TEST
89 --- a/drivers/clk/Makefile
90 +++ b/drivers/clk/Makefile
91 @@ -34,6 +34,7 @@ obj-$(CONFIG_MACH_ASPEED_G6) += clk-ast
92 obj-$(CONFIG_ARCH_HIGHBANK) += clk-highbank.o
93 obj-$(CONFIG_CLK_HSDK) += clk-hsdk-pll.o
94 obj-$(CONFIG_COMMON_CLK_LOCHNAGAR) += clk-lochnagar.o
95 +obj-$(CONFIG_COMMON_CLK_HIFIBERRY_DACPRO) += clk-hifiberry-dacpro.o
96 obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
97 obj-$(CONFIG_COMMON_CLK_MAX9485) += clk-max9485.o
98 obj-$(CONFIG_ARCH_MILBEAUT_M10V) += clk-milbeaut.o
99 --- /dev/null
100 +++ b/drivers/clk/clk-hifiberry-dacpro.c
101 @@ -0,0 +1,160 @@
102 +/*
103 + * Clock Driver for HiFiBerry DAC Pro
104 + *
105 + * Author: Stuart MacLean
106 + * Copyright 2015
107 + *
108 + * This program is free software; you can redistribute it and/or
109 + * modify it under the terms of the GNU General Public License
110 + * version 2 as published by the Free Software Foundation.
111 + *
112 + * This program is distributed in the hope that it will be useful, but
113 + * WITHOUT ANY WARRANTY; without even the implied warranty of
114 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
115 + * General Public License for more details.
116 + */
117 +
118 +#include <linux/clk-provider.h>
119 +#include <linux/clkdev.h>
120 +#include <linux/kernel.h>
121 +#include <linux/module.h>
122 +#include <linux/of.h>
123 +#include <linux/slab.h>
124 +#include <linux/platform_device.h>
125 +
126 +/* Clock rate of CLK44EN attached to GPIO6 pin */
127 +#define CLK_44EN_RATE 22579200UL
128 +/* Clock rate of CLK48EN attached to GPIO3 pin */
129 +#define CLK_48EN_RATE 24576000UL
130 +
131 +/**
132 + * struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
133 + * @hw: clk_hw for the common clk framework
134 + * @mode: 0 => CLK44EN, 1 => CLK48EN
135 + */
136 +struct clk_hifiberry_hw {
137 + struct clk_hw hw;
138 + uint8_t mode;
139 +};
140 +
141 +#define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
142 +
143 +static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
144 + { .compatible = "hifiberry,dacpro-clk",},
145 + { }
146 +};
147 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
148 +
149 +static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
150 + unsigned long parent_rate)
151 +{
152 + return (to_hifiberry_clk(hw)->mode == 0) ? CLK_44EN_RATE :
153 + CLK_48EN_RATE;
154 +}
155 +
156 +static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
157 + unsigned long rate, unsigned long *parent_rate)
158 +{
159 + long actual_rate;
160 +
161 + if (rate <= CLK_44EN_RATE) {
162 + actual_rate = (long)CLK_44EN_RATE;
163 + } else if (rate >= CLK_48EN_RATE) {
164 + actual_rate = (long)CLK_48EN_RATE;
165 + } else {
166 + long diff44Rate = (long)(rate - CLK_44EN_RATE);
167 + long diff48Rate = (long)(CLK_48EN_RATE - rate);
168 +
169 + if (diff44Rate < diff48Rate)
170 + actual_rate = (long)CLK_44EN_RATE;
171 + else
172 + actual_rate = (long)CLK_48EN_RATE;
173 + }
174 + return actual_rate;
175 +}
176 +
177 +
178 +static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
179 + unsigned long rate, unsigned long parent_rate)
180 +{
181 + unsigned long actual_rate;
182 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
183 +
184 + actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
185 + &parent_rate);
186 + clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
187 + return 0;
188 +}
189 +
190 +
191 +const struct clk_ops clk_hifiberry_dacpro_rate_ops = {
192 + .recalc_rate = clk_hifiberry_dacpro_recalc_rate,
193 + .round_rate = clk_hifiberry_dacpro_round_rate,
194 + .set_rate = clk_hifiberry_dacpro_set_rate,
195 +};
196 +
197 +static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
198 +{
199 + int ret;
200 + struct clk_hifiberry_hw *proclk;
201 + struct clk *clk;
202 + struct device *dev;
203 + struct clk_init_data init;
204 +
205 + dev = &pdev->dev;
206 +
207 + proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
208 + if (!proclk)
209 + return -ENOMEM;
210 +
211 + init.name = "clk-hifiberry-dacpro";
212 + init.ops = &clk_hifiberry_dacpro_rate_ops;
213 + init.flags = 0;
214 + init.parent_names = NULL;
215 + init.num_parents = 0;
216 +
217 + proclk->mode = 0;
218 + proclk->hw.init = &init;
219 +
220 + clk = devm_clk_register(dev, &proclk->hw);
221 + if (!IS_ERR(clk)) {
222 + ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
223 + clk);
224 + } else {
225 + dev_err(dev, "Fail to register clock driver\n");
226 + kfree(proclk);
227 + ret = PTR_ERR(clk);
228 + }
229 + return ret;
230 +}
231 +
232 +static int clk_hifiberry_dacpro_remove(struct platform_device *pdev)
233 +{
234 + of_clk_del_provider(pdev->dev.of_node);
235 + return 0;
236 +}
237 +
238 +static struct platform_driver clk_hifiberry_dacpro_driver = {
239 + .probe = clk_hifiberry_dacpro_probe,
240 + .remove = clk_hifiberry_dacpro_remove,
241 + .driver = {
242 + .name = "clk-hifiberry-dacpro",
243 + .of_match_table = clk_hifiberry_dacpro_dt_ids,
244 + },
245 +};
246 +
247 +static int __init clk_hifiberry_dacpro_init(void)
248 +{
249 + return platform_driver_register(&clk_hifiberry_dacpro_driver);
250 +}
251 +core_initcall(clk_hifiberry_dacpro_init);
252 +
253 +static void __exit clk_hifiberry_dacpro_exit(void)
254 +{
255 + platform_driver_unregister(&clk_hifiberry_dacpro_driver);
256 +}
257 +module_exit(clk_hifiberry_dacpro_exit);
258 +
259 +MODULE_DESCRIPTION("HiFiBerry DAC Pro clock driver");
260 +MODULE_LICENSE("GPL v2");
261 +MODULE_ALIAS("platform:clk-hifiberry-dacpro");
262 --- /dev/null
263 +++ b/sound/soc/bcm/hifiberry_dacplus.c
264 @@ -0,0 +1,352 @@
265 +/*
266 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro
267 + *
268 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
269 + * Copyright 2014-2015
270 + * based on code by Florian Meier <florian.meier@koalo.de>
271 + *
272 + * This program is free software; you can redistribute it and/or
273 + * modify it under the terms of the GNU General Public License
274 + * version 2 as published by the Free Software Foundation.
275 + *
276 + * This program is distributed in the hope that it will be useful, but
277 + * WITHOUT ANY WARRANTY; without even the implied warranty of
278 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
279 + * General Public License for more details.
280 + */
281 +
282 +#include <linux/module.h>
283 +#include <linux/platform_device.h>
284 +#include <linux/kernel.h>
285 +#include <linux/clk.h>
286 +#include <linux/kernel.h>
287 +#include <linux/module.h>
288 +#include <linux/of.h>
289 +#include <linux/slab.h>
290 +#include <linux/delay.h>
291 +
292 +#include <sound/core.h>
293 +#include <sound/pcm.h>
294 +#include <sound/pcm_params.h>
295 +#include <sound/soc.h>
296 +#include <sound/jack.h>
297 +
298 +#include "../codecs/pcm512x.h"
299 +
300 +#define HIFIBERRY_DACPRO_NOCLOCK 0
301 +#define HIFIBERRY_DACPRO_CLK44EN 1
302 +#define HIFIBERRY_DACPRO_CLK48EN 2
303 +
304 +struct pcm512x_priv {
305 + struct regmap *regmap;
306 + struct clk *sclk;
307 +};
308 +
309 +/* Clock rate of CLK44EN attached to GPIO6 pin */
310 +#define CLK_44EN_RATE 22579200UL
311 +/* Clock rate of CLK48EN attached to GPIO3 pin */
312 +#define CLK_48EN_RATE 24576000UL
313 +
314 +static bool slave;
315 +static bool snd_rpi_hifiberry_is_dacpro;
316 +static bool digital_gain_0db_limit = true;
317 +
318 +static void snd_rpi_hifiberry_dacplus_select_clk(struct snd_soc_component *component,
319 + int clk_id)
320 +{
321 + switch (clk_id) {
322 + case HIFIBERRY_DACPRO_NOCLOCK:
323 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
324 + break;
325 + case HIFIBERRY_DACPRO_CLK44EN:
326 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
327 + break;
328 + case HIFIBERRY_DACPRO_CLK48EN:
329 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
330 + break;
331 + }
332 +}
333 +
334 +static void snd_rpi_hifiberry_dacplus_clk_gpio(struct snd_soc_component *component)
335 +{
336 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x24, 0x24);
337 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
338 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
339 +}
340 +
341 +static bool snd_rpi_hifiberry_dacplus_is_sclk(struct snd_soc_component *component)
342 +{
343 + unsigned int sck;
344 +
345 + snd_soc_component_read(component, PCM512x_RATE_DET_4, &sck);
346 + return (!(sck & 0x40));
347 +}
348 +
349 +static bool snd_rpi_hifiberry_dacplus_is_sclk_sleep(
350 + struct snd_soc_component *component)
351 +{
352 + msleep(2);
353 + return snd_rpi_hifiberry_dacplus_is_sclk(component);
354 +}
355 +
356 +static bool snd_rpi_hifiberry_dacplus_is_pro_card(struct snd_soc_component *component)
357 +{
358 + bool isClk44EN, isClk48En, isNoClk;
359 +
360 + snd_rpi_hifiberry_dacplus_clk_gpio(component);
361 +
362 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK44EN);
363 + isClk44EN = snd_rpi_hifiberry_dacplus_is_sclk_sleep(component);
364 +
365 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_NOCLOCK);
366 + isNoClk = snd_rpi_hifiberry_dacplus_is_sclk_sleep(component);
367 +
368 + snd_rpi_hifiberry_dacplus_select_clk(component, HIFIBERRY_DACPRO_CLK48EN);
369 + isClk48En = snd_rpi_hifiberry_dacplus_is_sclk_sleep(component);
370 +
371 + return (isClk44EN && isClk48En && !isNoClk);
372 +}
373 +
374 +static int snd_rpi_hifiberry_dacplus_clk_for_rate(int sample_rate)
375 +{
376 + int type;
377 +
378 + switch (sample_rate) {
379 + case 11025:
380 + case 22050:
381 + case 44100:
382 + case 88200:
383 + case 176400:
384 + case 352800:
385 + type = HIFIBERRY_DACPRO_CLK44EN;
386 + break;
387 + default:
388 + type = HIFIBERRY_DACPRO_CLK48EN;
389 + break;
390 + }
391 + return type;
392 +}
393 +
394 +static void snd_rpi_hifiberry_dacplus_set_sclk(struct snd_soc_component *component,
395 + int sample_rate)
396 +{
397 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
398 +
399 + if (!IS_ERR(pcm512x->sclk)) {
400 + int ctype;
401 +
402 + ctype = snd_rpi_hifiberry_dacplus_clk_for_rate(sample_rate);
403 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
404 + ? CLK_44EN_RATE : CLK_48EN_RATE);
405 + snd_rpi_hifiberry_dacplus_select_clk(component, ctype);
406 + }
407 +}
408 +
409 +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
410 +{
411 + struct snd_soc_component *component = rtd->codec_dai->component;
412 + struct pcm512x_priv *priv;
413 +
414 + if (slave)
415 + snd_rpi_hifiberry_is_dacpro = false;
416 + else
417 + snd_rpi_hifiberry_is_dacpro =
418 + snd_rpi_hifiberry_dacplus_is_pro_card(component);
419 +
420 + if (snd_rpi_hifiberry_is_dacpro) {
421 + struct snd_soc_dai_link *dai = rtd->dai_link;
422 +
423 + dai->name = "HiFiBerry DAC+ Pro";
424 + dai->stream_name = "HiFiBerry DAC+ Pro HiFi";
425 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
426 + | SND_SOC_DAIFMT_CBM_CFM;
427 +
428 + snd_soc_component_update_bits(component, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
429 + snd_soc_component_update_bits(component, PCM512x_MASTER_MODE, 0x03, 0x03);
430 + snd_soc_component_update_bits(component, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
431 + } else {
432 + priv = snd_soc_component_get_drvdata(component);
433 + priv->sclk = ERR_PTR(-ENOENT);
434 + }
435 +
436 + snd_soc_component_update_bits(component, PCM512x_GPIO_EN, 0x08, 0x08);
437 + snd_soc_component_update_bits(component, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
438 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
439 +
440 + if (digital_gain_0db_limit)
441 + {
442 + int ret;
443 + struct snd_soc_card *card = rtd->card;
444 +
445 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
446 + if (ret < 0)
447 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
448 + }
449 +
450 + return 0;
451 +}
452 +
453 +static int snd_rpi_hifiberry_dacplus_update_rate_den(
454 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
455 +{
456 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
457 + struct snd_soc_component *component = rtd->codec_dai->component;
458 + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
459 + struct snd_ratnum *rats_no_pll;
460 + unsigned int num = 0, den = 0;
461 + int err;
462 +
463 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
464 + if (!rats_no_pll)
465 + return -ENOMEM;
466 +
467 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
468 + rats_no_pll->den_min = 1;
469 + rats_no_pll->den_max = 128;
470 + rats_no_pll->den_step = 1;
471 +
472 + err = snd_interval_ratnum(hw_param_interval(params,
473 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
474 + if (err >= 0 && den) {
475 + params->rate_num = num;
476 + params->rate_den = den;
477 + }
478 +
479 + devm_kfree(rtd->dev, rats_no_pll);
480 + return 0;
481 +}
482 +
483 +static int snd_rpi_hifiberry_dacplus_hw_params(
484 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
485 +{
486 + int ret = 0;
487 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
488 + int channels = params_channels(params);
489 + int width = 32;
490 +
491 + if (snd_rpi_hifiberry_is_dacpro) {
492 + struct snd_soc_component *component = rtd->codec_dai->component;
493 +
494 + width = snd_pcm_format_physical_width(params_format(params));
495 +
496 + snd_rpi_hifiberry_dacplus_set_sclk(component,
497 + params_rate(params));
498 +
499 + ret = snd_rpi_hifiberry_dacplus_update_rate_den(
500 + substream, params);
501 + }
502 +
503 + ret = snd_soc_dai_set_bclk_ratio(rtd->cpu_dai, channels * width);
504 + if (ret)
505 + return ret;
506 + ret = snd_soc_dai_set_bclk_ratio(rtd->codec_dai, channels * width);
507 + return ret;
508 +}
509 +
510 +static int snd_rpi_hifiberry_dacplus_startup(
511 + struct snd_pcm_substream *substream)
512 +{
513 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
514 + struct snd_soc_component *component = rtd->codec_dai->component;
515 +
516 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
517 + return 0;
518 +}
519 +
520 +static void snd_rpi_hifiberry_dacplus_shutdown(
521 + struct snd_pcm_substream *substream)
522 +{
523 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
524 + struct snd_soc_component *component = rtd->codec_dai->component;
525 +
526 + snd_soc_component_update_bits(component, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
527 +}
528 +
529 +/* machine stream operations */
530 +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
531 + .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
532 + .startup = snd_rpi_hifiberry_dacplus_startup,
533 + .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
534 +};
535 +
536 +SND_SOC_DAILINK_DEFS(rpi_hifiberry_dacplus,
537 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
538 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
539 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
540 +
541 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
542 +{
543 + .name = "HiFiBerry DAC+",
544 + .stream_name = "HiFiBerry DAC+ HiFi",
545 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
546 + SND_SOC_DAIFMT_CBS_CFS,
547 + .ops = &snd_rpi_hifiberry_dacplus_ops,
548 + .init = snd_rpi_hifiberry_dacplus_init,
549 + SND_SOC_DAILINK_REG(rpi_hifiberry_dacplus),
550 +},
551 +};
552 +
553 +/* audio machine driver */
554 +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
555 + .name = "snd_rpi_hifiberry_dacplus",
556 + .driver_name = "HifiberryDacp",
557 + .owner = THIS_MODULE,
558 + .dai_link = snd_rpi_hifiberry_dacplus_dai,
559 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
560 +};
561 +
562 +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
563 +{
564 + int ret = 0;
565 +
566 + snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
567 + if (pdev->dev.of_node) {
568 + struct device_node *i2s_node;
569 + struct snd_soc_dai_link *dai;
570 +
571 + dai = &snd_rpi_hifiberry_dacplus_dai[0];
572 + i2s_node = of_parse_phandle(pdev->dev.of_node,
573 + "i2s-controller", 0);
574 +
575 + if (i2s_node) {
576 + dai->cpus->dai_name = NULL;
577 + dai->cpus->of_node = i2s_node;
578 + dai->platforms->name = NULL;
579 + dai->platforms->of_node = i2s_node;
580 + }
581 +
582 + digital_gain_0db_limit = !of_property_read_bool(
583 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
584 + slave = of_property_read_bool(pdev->dev.of_node,
585 + "hifiberry-dacplus,slave");
586 + }
587 +
588 + ret = devm_snd_soc_register_card(&pdev->dev,
589 + &snd_rpi_hifiberry_dacplus);
590 + if (ret && ret != -EPROBE_DEFER)
591 + dev_err(&pdev->dev,
592 + "snd_soc_register_card() failed: %d\n", ret);
593 +
594 + return ret;
595 +}
596 +
597 +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
598 + { .compatible = "hifiberry,hifiberry-dacplus", },
599 + {},
600 +};
601 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
602 +
603 +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
604 + .driver = {
605 + .name = "snd-rpi-hifiberry-dacplus",
606 + .owner = THIS_MODULE,
607 + .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
608 + },
609 + .probe = snd_rpi_hifiberry_dacplus_probe,
610 +};
611 +
612 +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
613 +
614 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
615 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
616 +MODULE_LICENSE("GPL v2");