kernel: bump 4.9 to 4.9.96
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.9 / 950-0072-Added-support-for-HiFiBerry-DAC.patch
1 From 9c6b8bd0db7564a2124290e3bc30215906371fa9 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 drivers/clk/Makefile | 1 +
31 drivers/clk/clk-hifiberry-dacpro.c | 160 +++++++++++++++++
32 sound/soc/bcm/Kconfig | 7 +
33 sound/soc/bcm/Makefile | 2 +
34 sound/soc/bcm/hifiberry_dacplus.c | 359 +++++++++++++++++++++++++++++++++++++
35 sound/soc/codecs/pcm512x.c | 3 +-
36 6 files changed, 531 insertions(+), 1 deletion(-)
37 create mode 100644 drivers/clk/clk-hifiberry-dacpro.c
38 create mode 100644 sound/soc/bcm/hifiberry_dacplus.c
39
40 --- a/drivers/clk/Makefile
41 +++ b/drivers/clk/Makefile
42 @@ -26,6 +26,7 @@ obj-$(CONFIG_ARCH_CLPS711X) += clk-clps
43 obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o
44 obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o
45 obj-$(CONFIG_ARCH_HIGHBANK) += clk-highbank.o
46 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += clk-hifiberry-dacpro.o
47 obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
48 obj-$(CONFIG_ARCH_MB86S7X) += clk-mb86s7x.o
49 obj-$(CONFIG_ARCH_MOXART) += clk-moxart.o
50 --- /dev/null
51 +++ b/drivers/clk/clk-hifiberry-dacpro.c
52 @@ -0,0 +1,160 @@
53 +/*
54 + * Clock Driver for HiFiBerry DAC Pro
55 + *
56 + * Author: Stuart MacLean
57 + * Copyright 2015
58 + *
59 + * This program is free software; you can redistribute it and/or
60 + * modify it under the terms of the GNU General Public License
61 + * version 2 as published by the Free Software Foundation.
62 + *
63 + * This program is distributed in the hope that it will be useful, but
64 + * WITHOUT ANY WARRANTY; without even the implied warranty of
65 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
66 + * General Public License for more details.
67 + */
68 +
69 +#include <linux/clk-provider.h>
70 +#include <linux/clkdev.h>
71 +#include <linux/kernel.h>
72 +#include <linux/module.h>
73 +#include <linux/of.h>
74 +#include <linux/slab.h>
75 +#include <linux/platform_device.h>
76 +
77 +/* Clock rate of CLK44EN attached to GPIO6 pin */
78 +#define CLK_44EN_RATE 22579200UL
79 +/* Clock rate of CLK48EN attached to GPIO3 pin */
80 +#define CLK_48EN_RATE 24576000UL
81 +
82 +/**
83 + * struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
84 + * @hw: clk_hw for the common clk framework
85 + * @mode: 0 => CLK44EN, 1 => CLK48EN
86 + */
87 +struct clk_hifiberry_hw {
88 + struct clk_hw hw;
89 + uint8_t mode;
90 +};
91 +
92 +#define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
93 +
94 +static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
95 + { .compatible = "hifiberry,dacpro-clk",},
96 + { }
97 +};
98 +MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
99 +
100 +static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
101 + unsigned long parent_rate)
102 +{
103 + return (to_hifiberry_clk(hw)->mode == 0) ? CLK_44EN_RATE :
104 + CLK_48EN_RATE;
105 +}
106 +
107 +static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
108 + unsigned long rate, unsigned long *parent_rate)
109 +{
110 + long actual_rate;
111 +
112 + if (rate <= CLK_44EN_RATE) {
113 + actual_rate = (long)CLK_44EN_RATE;
114 + } else if (rate >= CLK_48EN_RATE) {
115 + actual_rate = (long)CLK_48EN_RATE;
116 + } else {
117 + long diff44Rate = (long)(rate - CLK_44EN_RATE);
118 + long diff48Rate = (long)(CLK_48EN_RATE - rate);
119 +
120 + if (diff44Rate < diff48Rate)
121 + actual_rate = (long)CLK_44EN_RATE;
122 + else
123 + actual_rate = (long)CLK_48EN_RATE;
124 + }
125 + return actual_rate;
126 +}
127 +
128 +
129 +static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
130 + unsigned long rate, unsigned long parent_rate)
131 +{
132 + unsigned long actual_rate;
133 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
134 +
135 + actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
136 + &parent_rate);
137 + clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
138 + return 0;
139 +}
140 +
141 +
142 +const struct clk_ops clk_hifiberry_dacpro_rate_ops = {
143 + .recalc_rate = clk_hifiberry_dacpro_recalc_rate,
144 + .round_rate = clk_hifiberry_dacpro_round_rate,
145 + .set_rate = clk_hifiberry_dacpro_set_rate,
146 +};
147 +
148 +static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
149 +{
150 + int ret;
151 + struct clk_hifiberry_hw *proclk;
152 + struct clk *clk;
153 + struct device *dev;
154 + struct clk_init_data init;
155 +
156 + dev = &pdev->dev;
157 +
158 + proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
159 + if (!proclk)
160 + return -ENOMEM;
161 +
162 + init.name = "clk-hifiberry-dacpro";
163 + init.ops = &clk_hifiberry_dacpro_rate_ops;
164 + init.flags = CLK_IS_BASIC;
165 + init.parent_names = NULL;
166 + init.num_parents = 0;
167 +
168 + proclk->mode = 0;
169 + proclk->hw.init = &init;
170 +
171 + clk = devm_clk_register(dev, &proclk->hw);
172 + if (!IS_ERR(clk)) {
173 + ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
174 + clk);
175 + } else {
176 + dev_err(dev, "Fail to register clock driver\n");
177 + kfree(proclk);
178 + ret = PTR_ERR(clk);
179 + }
180 + return ret;
181 +}
182 +
183 +static int clk_hifiberry_dacpro_remove(struct platform_device *pdev)
184 +{
185 + of_clk_del_provider(pdev->dev.of_node);
186 + return 0;
187 +}
188 +
189 +static struct platform_driver clk_hifiberry_dacpro_driver = {
190 + .probe = clk_hifiberry_dacpro_probe,
191 + .remove = clk_hifiberry_dacpro_remove,
192 + .driver = {
193 + .name = "clk-hifiberry-dacpro",
194 + .of_match_table = clk_hifiberry_dacpro_dt_ids,
195 + },
196 +};
197 +
198 +static int __init clk_hifiberry_dacpro_init(void)
199 +{
200 + return platform_driver_register(&clk_hifiberry_dacpro_driver);
201 +}
202 +core_initcall(clk_hifiberry_dacpro_init);
203 +
204 +static void __exit clk_hifiberry_dacpro_exit(void)
205 +{
206 + platform_driver_unregister(&clk_hifiberry_dacpro_driver);
207 +}
208 +module_exit(clk_hifiberry_dacpro_exit);
209 +
210 +MODULE_DESCRIPTION("HiFiBerry DAC Pro clock driver");
211 +MODULE_LICENSE("GPL v2");
212 +MODULE_ALIAS("platform:clk-hifiberry-dacpro");
213 --- a/sound/soc/bcm/Kconfig
214 +++ b/sound/soc/bcm/Kconfig
215 @@ -24,6 +24,13 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
216 help
217 Say Y or M if you want to add support for HifiBerry DAC.
218
219 +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
220 + tristate "Support for HifiBerry DAC+"
221 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
222 + select SND_SOC_PCM512x
223 + help
224 + Say Y or M if you want to add support for HifiBerry DAC+.
225 +
226 config SND_BCM2708_SOC_HIFIBERRY_DIGI
227 tristate "Support for HifiBerry Digi"
228 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
229 --- a/sound/soc/bcm/Makefile
230 +++ b/sound/soc/bcm/Makefile
231 @@ -10,11 +10,13 @@ obj-$(CONFIG_SND_SOC_CYGNUS) += snd-soc-
232
233 # BCM2708 Machine Support
234 snd-soc-hifiberry-dac-objs := hifiberry_dac.o
235 +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
236 snd-soc-hifiberry-digi-objs := hifiberry_digi.o
237 snd-soc-rpi-dac-objs := rpi-dac.o
238 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
239
240 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
241 +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
242 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
243 obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
244 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
245 --- /dev/null
246 +++ b/sound/soc/bcm/hifiberry_dacplus.c
247 @@ -0,0 +1,359 @@
248 +/*
249 + * ASoC Driver for HiFiBerry DAC+ / DAC Pro
250 + *
251 + * Author: Daniel Matuschek, Stuart MacLean <stuart@hifiberry.com>
252 + * Copyright 2014-2015
253 + * based on code by Florian Meier <florian.meier@koalo.de>
254 + *
255 + * This program is free software; you can redistribute it and/or
256 + * modify it under the terms of the GNU General Public License
257 + * version 2 as published by the Free Software Foundation.
258 + *
259 + * This program is distributed in the hope that it will be useful, but
260 + * WITHOUT ANY WARRANTY; without even the implied warranty of
261 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
262 + * General Public License for more details.
263 + */
264 +
265 +#include <linux/module.h>
266 +#include <linux/platform_device.h>
267 +#include <linux/kernel.h>
268 +#include <linux/clk.h>
269 +#include <linux/kernel.h>
270 +#include <linux/module.h>
271 +#include <linux/of.h>
272 +#include <linux/slab.h>
273 +#include <linux/delay.h>
274 +
275 +#include <sound/core.h>
276 +#include <sound/pcm.h>
277 +#include <sound/pcm_params.h>
278 +#include <sound/soc.h>
279 +#include <sound/jack.h>
280 +
281 +#include "../codecs/pcm512x.h"
282 +
283 +#define HIFIBERRY_DACPRO_NOCLOCK 0
284 +#define HIFIBERRY_DACPRO_CLK44EN 1
285 +#define HIFIBERRY_DACPRO_CLK48EN 2
286 +
287 +struct pcm512x_priv {
288 + struct regmap *regmap;
289 + struct clk *sclk;
290 +};
291 +
292 +/* Clock rate of CLK44EN attached to GPIO6 pin */
293 +#define CLK_44EN_RATE 22579200UL
294 +/* Clock rate of CLK48EN attached to GPIO3 pin */
295 +#define CLK_48EN_RATE 24576000UL
296 +
297 +static bool slave;
298 +static bool snd_rpi_hifiberry_is_dacpro;
299 +static bool digital_gain_0db_limit = true;
300 +
301 +static void snd_rpi_hifiberry_dacplus_select_clk(struct snd_soc_codec *codec,
302 + int clk_id)
303 +{
304 + switch (clk_id) {
305 + case HIFIBERRY_DACPRO_NOCLOCK:
306 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
307 + break;
308 + case HIFIBERRY_DACPRO_CLK44EN:
309 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
310 + break;
311 + case HIFIBERRY_DACPRO_CLK48EN:
312 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
313 + break;
314 + }
315 +}
316 +
317 +static void snd_rpi_hifiberry_dacplus_clk_gpio(struct snd_soc_codec *codec)
318 +{
319 + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x24, 0x24);
320 + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
321 + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
322 +}
323 +
324 +static bool snd_rpi_hifiberry_dacplus_is_sclk(struct snd_soc_codec *codec)
325 +{
326 + int sck;
327 +
328 + sck = snd_soc_read(codec, PCM512x_RATE_DET_4);
329 + return (!(sck & 0x40));
330 +}
331 +
332 +static bool snd_rpi_hifiberry_dacplus_is_sclk_sleep(
333 + struct snd_soc_codec *codec)
334 +{
335 + msleep(2);
336 + return snd_rpi_hifiberry_dacplus_is_sclk(codec);
337 +}
338 +
339 +static bool snd_rpi_hifiberry_dacplus_is_pro_card(struct snd_soc_codec *codec)
340 +{
341 + bool isClk44EN, isClk48En, isNoClk;
342 +
343 + snd_rpi_hifiberry_dacplus_clk_gpio(codec);
344 +
345 + snd_rpi_hifiberry_dacplus_select_clk(codec, HIFIBERRY_DACPRO_CLK44EN);
346 + isClk44EN = snd_rpi_hifiberry_dacplus_is_sclk_sleep(codec);
347 +
348 + snd_rpi_hifiberry_dacplus_select_clk(codec, HIFIBERRY_DACPRO_NOCLOCK);
349 + isNoClk = snd_rpi_hifiberry_dacplus_is_sclk_sleep(codec);
350 +
351 + snd_rpi_hifiberry_dacplus_select_clk(codec, HIFIBERRY_DACPRO_CLK48EN);
352 + isClk48En = snd_rpi_hifiberry_dacplus_is_sclk_sleep(codec);
353 +
354 + return (isClk44EN && isClk48En && !isNoClk);
355 +}
356 +
357 +static int snd_rpi_hifiberry_dacplus_clk_for_rate(int sample_rate)
358 +{
359 + int type;
360 +
361 + switch (sample_rate) {
362 + case 11025:
363 + case 22050:
364 + case 44100:
365 + case 88200:
366 + case 176400:
367 + type = HIFIBERRY_DACPRO_CLK44EN;
368 + break;
369 + default:
370 + type = HIFIBERRY_DACPRO_CLK48EN;
371 + break;
372 + }
373 + return type;
374 +}
375 +
376 +static void snd_rpi_hifiberry_dacplus_set_sclk(struct snd_soc_codec *codec,
377 + int sample_rate)
378 +{
379 + struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
380 +
381 + if (!IS_ERR(pcm512x->sclk)) {
382 + int ctype;
383 +
384 + ctype = snd_rpi_hifiberry_dacplus_clk_for_rate(sample_rate);
385 + clk_set_rate(pcm512x->sclk, (ctype == HIFIBERRY_DACPRO_CLK44EN)
386 + ? CLK_44EN_RATE : CLK_48EN_RATE);
387 + snd_rpi_hifiberry_dacplus_select_clk(codec, ctype);
388 + }
389 +}
390 +
391 +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
392 +{
393 + struct snd_soc_codec *codec = rtd->codec;
394 + struct pcm512x_priv *priv;
395 +
396 + if (slave)
397 + snd_rpi_hifiberry_is_dacpro = false;
398 + else
399 + snd_rpi_hifiberry_is_dacpro =
400 + snd_rpi_hifiberry_dacplus_is_pro_card(codec);
401 +
402 + if (snd_rpi_hifiberry_is_dacpro) {
403 + struct snd_soc_dai_link *dai = rtd->dai_link;
404 +
405 + dai->name = "HiFiBerry DAC+ Pro";
406 + dai->stream_name = "HiFiBerry DAC+ Pro HiFi";
407 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
408 + | SND_SOC_DAIFMT_CBM_CFM;
409 +
410 + snd_soc_update_bits(codec, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
411 + snd_soc_update_bits(codec, PCM512x_MASTER_MODE, 0x03, 0x03);
412 + snd_soc_update_bits(codec, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
413 + } else {
414 + priv = snd_soc_codec_get_drvdata(codec);
415 + priv->sclk = ERR_PTR(-ENOENT);
416 + }
417 +
418 + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
419 + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
420 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
421 +
422 + if (digital_gain_0db_limit)
423 + {
424 + int ret;
425 + struct snd_soc_card *card = rtd->card;
426 +
427 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
428 + if (ret < 0)
429 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
430 + }
431 +
432 + return 0;
433 +}
434 +
435 +static int snd_rpi_hifiberry_dacplus_update_rate_den(
436 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
437 +{
438 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
439 + struct snd_soc_codec *codec = rtd->codec;
440 + struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
441 + struct snd_ratnum *rats_no_pll;
442 + unsigned int num = 0, den = 0;
443 + int err;
444 +
445 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
446 + if (!rats_no_pll)
447 + return -ENOMEM;
448 +
449 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
450 + rats_no_pll->den_min = 1;
451 + rats_no_pll->den_max = 128;
452 + rats_no_pll->den_step = 1;
453 +
454 + err = snd_interval_ratnum(hw_param_interval(params,
455 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
456 + if (err >= 0 && den) {
457 + params->rate_num = num;
458 + params->rate_den = den;
459 + }
460 +
461 + devm_kfree(rtd->dev, rats_no_pll);
462 + return 0;
463 +}
464 +
465 +static int snd_rpi_hifiberry_dacplus_set_bclk_ratio_pro(
466 + struct snd_soc_dai *cpu_dai, struct snd_pcm_hw_params *params)
467 +{
468 + int bratio = snd_pcm_format_physical_width(params_format(params))
469 + * params_channels(params);
470 + return snd_soc_dai_set_bclk_ratio(cpu_dai, bratio);
471 +}
472 +
473 +static int snd_rpi_hifiberry_dacplus_hw_params(
474 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
475 +{
476 + int ret;
477 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
478 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
479 +
480 + if (snd_rpi_hifiberry_is_dacpro) {
481 + struct snd_soc_codec *codec = rtd->codec;
482 +
483 + snd_rpi_hifiberry_dacplus_set_sclk(codec,
484 + params_rate(params));
485 +
486 + ret = snd_rpi_hifiberry_dacplus_set_bclk_ratio_pro(cpu_dai,
487 + params);
488 + if (!ret)
489 + ret = snd_rpi_hifiberry_dacplus_update_rate_den(
490 + substream, params);
491 + } else {
492 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
493 + }
494 + return ret;
495 +}
496 +
497 +static int snd_rpi_hifiberry_dacplus_startup(
498 + struct snd_pcm_substream *substream)
499 +{
500 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
501 + struct snd_soc_codec *codec = rtd->codec;
502 +
503 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
504 + return 0;
505 +}
506 +
507 +static void snd_rpi_hifiberry_dacplus_shutdown(
508 + struct snd_pcm_substream *substream)
509 +{
510 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
511 + struct snd_soc_codec *codec = rtd->codec;
512 +
513 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
514 +}
515 +
516 +/* machine stream operations */
517 +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
518 + .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
519 + .startup = snd_rpi_hifiberry_dacplus_startup,
520 + .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
521 +};
522 +
523 +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
524 +{
525 + .name = "HiFiBerry DAC+",
526 + .stream_name = "HiFiBerry DAC+ HiFi",
527 + .cpu_dai_name = "bcm2708-i2s.0",
528 + .codec_dai_name = "pcm512x-hifi",
529 + .platform_name = "bcm2708-i2s.0",
530 + .codec_name = "pcm512x.1-004d",
531 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
532 + SND_SOC_DAIFMT_CBS_CFS,
533 + .ops = &snd_rpi_hifiberry_dacplus_ops,
534 + .init = snd_rpi_hifiberry_dacplus_init,
535 +},
536 +};
537 +
538 +/* audio machine driver */
539 +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
540 + .name = "snd_rpi_hifiberry_dacplus",
541 + .driver_name = "HifiberryDacp",
542 + .owner = THIS_MODULE,
543 + .dai_link = snd_rpi_hifiberry_dacplus_dai,
544 + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
545 +};
546 +
547 +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
548 +{
549 + int ret = 0;
550 +
551 + snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
552 + if (pdev->dev.of_node) {
553 + struct device_node *i2s_node;
554 + struct snd_soc_dai_link *dai;
555 +
556 + dai = &snd_rpi_hifiberry_dacplus_dai[0];
557 + i2s_node = of_parse_phandle(pdev->dev.of_node,
558 + "i2s-controller", 0);
559 +
560 + if (i2s_node) {
561 + dai->cpu_dai_name = NULL;
562 + dai->cpu_of_node = i2s_node;
563 + dai->platform_name = NULL;
564 + dai->platform_of_node = i2s_node;
565 + }
566 +
567 + digital_gain_0db_limit = !of_property_read_bool(
568 + pdev->dev.of_node, "hifiberry,24db_digital_gain");
569 + slave = of_property_read_bool(pdev->dev.of_node,
570 + "hifiberry-dacplus,slave");
571 + }
572 +
573 + ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);
574 + if (ret)
575 + dev_err(&pdev->dev,
576 + "snd_soc_register_card() failed: %d\n", ret);
577 +
578 + return ret;
579 +}
580 +
581 +static int snd_rpi_hifiberry_dacplus_remove(struct platform_device *pdev)
582 +{
583 + return snd_soc_unregister_card(&snd_rpi_hifiberry_dacplus);
584 +}
585 +
586 +static const struct of_device_id snd_rpi_hifiberry_dacplus_of_match[] = {
587 + { .compatible = "hifiberry,hifiberry-dacplus", },
588 + {},
589 +};
590 +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dacplus_of_match);
591 +
592 +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
593 + .driver = {
594 + .name = "snd-rpi-hifiberry-dacplus",
595 + .owner = THIS_MODULE,
596 + .of_match_table = snd_rpi_hifiberry_dacplus_of_match,
597 + },
598 + .probe = snd_rpi_hifiberry_dacplus_probe,
599 + .remove = snd_rpi_hifiberry_dacplus_remove,
600 +};
601 +
602 +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
603 +
604 +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
605 +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
606 +MODULE_LICENSE("GPL v2");
607 --- a/sound/soc/codecs/pcm512x.c
608 +++ b/sound/soc/codecs/pcm512x.c
609 @@ -854,7 +854,8 @@ static int pcm512x_set_dividers(struct s
610 int fssp;
611 int gpio;
612
613 - lrclk_div = snd_soc_params_to_frame_size(params);
614 + lrclk_div = snd_pcm_format_physical_width(params_format(params))
615 + * params_channels(params);
616 if (lrclk_div == 0) {
617 dev_err(dev, "No LRCLK?\n");
618 return -EINVAL;