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