c560d92dbcac76fd8a11e7e299934d755f5f96bf
[openwrt/staging/luka.git] /
1 From cbcb43856238e359086ac491f41d5d38b834268f Mon Sep 17 00:00:00 2001
2 From: BabuSubashChandar <babuenir@gmail.com>
3 Date: Tue, 28 Mar 2017 20:04:42 +0530
4 Subject: [PATCH 081/454] Add support for Allo Boss DAC add-on board for
5 Raspberry Pi. (#1924)
6
7 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
8 Reviewed-by: Deepak <deepak@zilogic.com>
9 Reviewed-by: BabuSubashChandar <babusubashchandar@zilogic.com>
10
11 Add support for new clock rate and mute gpios.
12
13 Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
14 Reviewed-by: Deepak <deepak@zilogic.com>
15 Reviewed-by: BabuSubashChandar <babusubashchandar@zilogic.com>
16 ---
17 drivers/clk/Makefile | 1 +
18 drivers/clk/clk-allo-dac.c | 161 ++++++++++++
19 sound/soc/bcm/Kconfig | 7 +
20 sound/soc/bcm/Makefile | 2 +
21 sound/soc/bcm/allo-boss-dac.c | 461 ++++++++++++++++++++++++++++++++++
22 5 files changed, 632 insertions(+)
23 create mode 100644 drivers/clk/clk-allo-dac.c
24 create mode 100644 sound/soc/bcm/allo-boss-dac.c
25
26 --- a/drivers/clk/Makefile
27 +++ b/drivers/clk/Makefile
28 @@ -18,6 +18,7 @@ endif
29
30 # hardware specific clock types
31 # please keep this section sorted lexicographically by file path name
32 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += clk-allo-dac.o
33 obj-$(CONFIG_MACH_ASM9260) += clk-asm9260.o
34 obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o
35 obj-$(CONFIG_ARCH_AXXIA) += clk-axm5516.o
36 --- /dev/null
37 +++ b/drivers/clk/clk-allo-dac.c
38 @@ -0,0 +1,161 @@
39 +/*
40 + * Clock Driver for Allo DAC
41 + *
42 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
43 + * Copyright 2016
44 + * based on code by Stuart MacLean
45 + *
46 + * This program is free software; you can redistribute it and/or
47 + * modify it under the terms of the GNU General Public License
48 + * version 2 as published by the Free Software Foundation.
49 + *
50 + * This program is distributed in the hope that it will be useful, but
51 + * WITHOUT ANY WARRANTY; without even the implied warranty of
52 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
53 + * General Public License for more details.
54 + */
55 +
56 +#include <linux/clk-provider.h>
57 +#include <linux/clkdev.h>
58 +#include <linux/kernel.h>
59 +#include <linux/module.h>
60 +#include <linux/of.h>
61 +#include <linux/slab.h>
62 +#include <linux/platform_device.h>
63 +
64 +/* Clock rate of CLK44EN attached to GPIO6 pin */
65 +#define CLK_44EN_RATE 45158400UL
66 +/* Clock rate of CLK48EN attached to GPIO3 pin */
67 +#define CLK_48EN_RATE 49152000UL
68 +
69 +/**
70 + * struct allo_dac_clk - Common struct to the Allo DAC
71 + * @hw: clk_hw for the common clk framework
72 + * @mode: 0 => CLK44EN, 1 => CLK48EN
73 + */
74 +struct clk_allo_hw {
75 + struct clk_hw hw;
76 + uint8_t mode;
77 +};
78 +
79 +#define to_allo_clk(_hw) container_of(_hw, struct clk_allo_hw, hw)
80 +
81 +static const struct of_device_id clk_allo_dac_dt_ids[] = {
82 + { .compatible = "allo,dac-clk",},
83 + { }
84 +};
85 +MODULE_DEVICE_TABLE(of, clk_allo_dac_dt_ids);
86 +
87 +static unsigned long clk_allo_dac_recalc_rate(struct clk_hw *hw,
88 + unsigned long parent_rate)
89 +{
90 + return (to_allo_clk(hw)->mode == 0) ? CLK_44EN_RATE :
91 + CLK_48EN_RATE;
92 +}
93 +
94 +static long clk_allo_dac_round_rate(struct clk_hw *hw,
95 + unsigned long rate, unsigned long *parent_rate)
96 +{
97 + long actual_rate;
98 +
99 + if (rate <= CLK_44EN_RATE) {
100 + actual_rate = (long)CLK_44EN_RATE;
101 + } else if (rate >= CLK_48EN_RATE) {
102 + actual_rate = (long)CLK_48EN_RATE;
103 + } else {
104 + long diff44Rate = (long)(rate - CLK_44EN_RATE);
105 + long diff48Rate = (long)(CLK_48EN_RATE - rate);
106 +
107 + if (diff44Rate < diff48Rate)
108 + actual_rate = (long)CLK_44EN_RATE;
109 + else
110 + actual_rate = (long)CLK_48EN_RATE;
111 + }
112 + return actual_rate;
113 +}
114 +
115 +
116 +static int clk_allo_dac_set_rate(struct clk_hw *hw,
117 + unsigned long rate, unsigned long parent_rate)
118 +{
119 + unsigned long actual_rate;
120 + struct clk_allo_hw *clk = to_allo_clk(hw);
121 +
122 + actual_rate = (unsigned long)clk_allo_dac_round_rate(hw, rate,
123 + &parent_rate);
124 + clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
125 + return 0;
126 +}
127 +
128 +
129 +const struct clk_ops clk_allo_dac_rate_ops = {
130 + .recalc_rate = clk_allo_dac_recalc_rate,
131 + .round_rate = clk_allo_dac_round_rate,
132 + .set_rate = clk_allo_dac_set_rate,
133 +};
134 +
135 +static int clk_allo_dac_probe(struct platform_device *pdev)
136 +{
137 + int ret;
138 + struct clk_allo_hw *proclk;
139 + struct clk *clk;
140 + struct device *dev;
141 + struct clk_init_data init;
142 +
143 + dev = &pdev->dev;
144 +
145 + proclk = kzalloc(sizeof(struct clk_allo_hw), GFP_KERNEL);
146 + if (!proclk)
147 + return -ENOMEM;
148 +
149 + init.name = "clk-allo-dac";
150 + init.ops = &clk_allo_dac_rate_ops;
151 + init.flags = CLK_IS_BASIC;
152 + init.parent_names = NULL;
153 + init.num_parents = 0;
154 +
155 + proclk->mode = 0;
156 + proclk->hw.init = &init;
157 +
158 + clk = devm_clk_register(dev, &proclk->hw);
159 + if (!IS_ERR(clk)) {
160 + ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
161 + clk);
162 + } else {
163 + dev_err(dev, "Fail to register clock driver\n");
164 + kfree(proclk);
165 + ret = PTR_ERR(clk);
166 + }
167 + return ret;
168 +}
169 +
170 +static int clk_allo_dac_remove(struct platform_device *pdev)
171 +{
172 + of_clk_del_provider(pdev->dev.of_node);
173 + return 0;
174 +}
175 +
176 +static struct platform_driver clk_allo_dac_driver = {
177 + .probe = clk_allo_dac_probe,
178 + .remove = clk_allo_dac_remove,
179 + .driver = {
180 + .name = "clk-allo-dac",
181 + .of_match_table = clk_allo_dac_dt_ids,
182 + },
183 +};
184 +
185 +static int __init clk_allo_dac_init(void)
186 +{
187 + return platform_driver_register(&clk_allo_dac_driver);
188 +}
189 +core_initcall(clk_allo_dac_init);
190 +
191 +static void __exit clk_allo_dac_exit(void)
192 +{
193 + platform_driver_unregister(&clk_allo_dac_driver);
194 +}
195 +module_exit(clk_allo_dac_exit);
196 +
197 +MODULE_DESCRIPTION("Allo DAC clock driver");
198 +MODULE_LICENSE("GPL v2");
199 +MODULE_ALIAS("platform:clk-allo-dac");
200 --- a/sound/soc/bcm/Kconfig
201 +++ b/sound/soc/bcm/Kconfig
202 @@ -138,3 +138,10 @@ config SND_BCM2708_SOC_ALLO_PIANO_DAC_PL
203 select SND_SOC_PCM512x_I2C
204 help
205 Say Y or M if you want to add support for Allo Piano DAC Plus.
206 +
207 +config SND_BCM2708_SOC_ALLO_BOSS_DAC
208 + tristate "Support for Allo Boss DAC"
209 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
210 + select SND_SOC_PCM512x_I2C
211 + help
212 + Say Y or M if you want to add support for Allo Boss DAC.
213 --- a/sound/soc/bcm/Makefile
214 +++ b/sound/soc/bcm/Makefile
215 @@ -24,6 +24,7 @@ snd-soc-raspidac3-objs := raspidac3.o
216 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
217 snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
218 snd-soc-dionaudio-loco-objs := dionaudio_loco.o
219 +snd-soc-allo-boss-dac-objs := allo-boss-dac.o
220 snd-soc-allo-piano-dac-objs := allo-piano-dac.o
221 snd-soc-allo-piano-dac-plus-objs := allo-piano-dac-plus.o
222
223 @@ -42,5 +43,6 @@ obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3)
224 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
225 obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
226 obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
227 +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += snd-soc-allo-boss-dac.o
228 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
229 obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS) += snd-soc-allo-piano-dac-plus.o
230 --- /dev/null
231 +++ b/sound/soc/bcm/allo-boss-dac.c
232 @@ -0,0 +1,461 @@
233 +/*
234 + * ALSA ASoC Machine Driver for Allo Boss DAC
235 + *
236 + * Author: Baswaraj K <jaikumar@cem-solutions.net>
237 + * Copyright 2017
238 + * based on code by Daniel Matuschek,
239 + * Stuart MacLean <stuart@hifiberry.com>
240 + * based on code by Florian Meier <florian.meier@koalo.de>
241 + *
242 + * This program is free software; you can redistribute it and/or
243 + * modify it under the terms of the GNU General Public License
244 + * version 2 as published by the Free Software Foundation.
245 + *
246 + * This program is distributed in the hope that it will be useful, but
247 + * WITHOUT ANY WARRANTY; without even the implied warranty of
248 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
249 + * General Public License for more details.
250 + */
251 +
252 +#include <linux/module.h>
253 +#include <linux/gpio/consumer.h>
254 +#include <linux/platform_device.h>
255 +#include <linux/clk.h>
256 +#include <linux/delay.h>
257 +
258 +#include <sound/core.h>
259 +#include <sound/pcm.h>
260 +#include <sound/pcm_params.h>
261 +#include <sound/soc.h>
262 +#include "../codecs/pcm512x.h"
263 +
264 +#define ALLO_BOSS_NOCLOCK 0
265 +#define ALLO_BOSS_CLK44EN 1
266 +#define ALLO_BOSS_CLK48EN 2
267 +
268 +struct pcm512x_priv {
269 + struct regmap *regmap;
270 + struct clk *sclk;
271 +};
272 +
273 +static struct gpio_desc *mute_gpio;
274 +
275 +/* Clock rate of CLK44EN attached to GPIO6 pin */
276 +#define CLK_44EN_RATE 45158400UL
277 +/* Clock rate of CLK48EN attached to GPIO3 pin */
278 +#define CLK_48EN_RATE 49152000UL
279 +
280 +static bool slave;
281 +static bool snd_soc_allo_boss_master;
282 +static bool digital_gain_0db_limit = true;
283 +
284 +static void snd_allo_boss_select_clk(struct snd_soc_codec *codec,
285 + int clk_id)
286 +{
287 + switch (clk_id) {
288 + case ALLO_BOSS_NOCLOCK:
289 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x24, 0x00);
290 + break;
291 + case ALLO_BOSS_CLK44EN:
292 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x24, 0x20);
293 + break;
294 + case ALLO_BOSS_CLK48EN:
295 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x24, 0x04);
296 + break;
297 + }
298 +}
299 +
300 +static void snd_allo_boss_clk_gpio(struct snd_soc_codec *codec)
301 +{
302 + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x24, 0x24);
303 + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_3, 0x0f, 0x02);
304 + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_6, 0x0f, 0x02);
305 +}
306 +
307 +static bool snd_allo_boss_is_sclk(struct snd_soc_codec *codec)
308 +{
309 + int sck;
310 +
311 + sck = snd_soc_read(codec, PCM512x_RATE_DET_4);
312 + return (!(sck & 0x40));
313 +}
314 +
315 +static bool snd_allo_boss_is_sclk_sleep(
316 + struct snd_soc_codec *codec)
317 +{
318 + msleep(2);
319 + return snd_allo_boss_is_sclk(codec);
320 +}
321 +
322 +static bool snd_allo_boss_is_master_card(struct snd_soc_codec *codec)
323 +{
324 + bool isClk44EN, isClk48En, isNoClk;
325 +
326 + snd_allo_boss_clk_gpio(codec);
327 +
328 + snd_allo_boss_select_clk(codec, ALLO_BOSS_CLK44EN);
329 + isClk44EN = snd_allo_boss_is_sclk_sleep(codec);
330 +
331 + snd_allo_boss_select_clk(codec, ALLO_BOSS_NOCLOCK);
332 + isNoClk = snd_allo_boss_is_sclk_sleep(codec);
333 +
334 + snd_allo_boss_select_clk(codec, ALLO_BOSS_CLK48EN);
335 + isClk48En = snd_allo_boss_is_sclk_sleep(codec);
336 +
337 + return (isClk44EN && isClk48En && !isNoClk);
338 +}
339 +
340 +static int snd_allo_boss_clk_for_rate(int sample_rate)
341 +{
342 + int type;
343 +
344 + switch (sample_rate) {
345 + case 11025:
346 + case 22050:
347 + case 44100:
348 + case 88200:
349 + case 176400:
350 + case 352800:
351 + type = ALLO_BOSS_CLK44EN;
352 + break;
353 + default:
354 + type = ALLO_BOSS_CLK48EN;
355 + break;
356 + }
357 + return type;
358 +}
359 +
360 +static void snd_allo_boss_set_sclk(struct snd_soc_codec *codec,
361 + int sample_rate)
362 +{
363 + struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
364 +
365 + if (!IS_ERR(pcm512x->sclk)) {
366 + int ctype;
367 +
368 + ctype = snd_allo_boss_clk_for_rate(sample_rate);
369 + clk_set_rate(pcm512x->sclk, (ctype == ALLO_BOSS_CLK44EN)
370 + ? CLK_44EN_RATE : CLK_48EN_RATE);
371 + snd_allo_boss_select_clk(codec, ctype);
372 + }
373 +}
374 +
375 +static int snd_allo_boss_init(struct snd_soc_pcm_runtime *rtd)
376 +{
377 + struct snd_soc_codec *codec = rtd->codec;
378 + struct pcm512x_priv *priv = snd_soc_codec_get_drvdata(codec);
379 +
380 + if (slave)
381 + snd_soc_allo_boss_master = false;
382 + else
383 + snd_soc_allo_boss_master =
384 + snd_allo_boss_is_master_card(codec);
385 +
386 + if (snd_soc_allo_boss_master) {
387 + struct snd_soc_dai_link *dai = rtd->dai_link;
388 +
389 + dai->name = "BossDAC";
390 + dai->stream_name = "Boss DAC HiFi [Master]";
391 + dai->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
392 + | SND_SOC_DAIFMT_CBM_CFM;
393 +
394 + snd_soc_update_bits(codec, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
395 + snd_soc_update_bits(codec, PCM512x_MASTER_MODE, 0x03, 0x03);
396 + snd_soc_update_bits(codec, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
397 + /*
398 + * Default sclk to CLK_48EN_RATE, otherwise codec
399 + * pcm512x_dai_startup_master method could call
400 + * snd_pcm_hw_constraint_ratnums using CLK_44EN/64
401 + * which will mask 384k sample rate.
402 + */
403 + if (!IS_ERR(priv->sclk))
404 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
405 + } else {
406 + priv->sclk = ERR_PTR(-ENOENT);
407 + }
408 +
409 + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
410 + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02);
411 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
412 +
413 + if (digital_gain_0db_limit) {
414 + int ret;
415 + struct snd_soc_card *card = rtd->card;
416 +
417 + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
418 + 207);
419 + if (ret < 0)
420 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
421 + ret);
422 + }
423 +
424 + return 0;
425 +}
426 +
427 +static int snd_allo_boss_update_rate_den(
428 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
429 +{
430 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
431 + struct snd_soc_codec *codec = rtd->codec;
432 + struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
433 + struct snd_ratnum *rats_no_pll;
434 + unsigned int num = 0, den = 0;
435 + int err;
436 +
437 + rats_no_pll = devm_kzalloc(rtd->dev, sizeof(*rats_no_pll), GFP_KERNEL);
438 + if (!rats_no_pll)
439 + return -ENOMEM;
440 +
441 + rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
442 + rats_no_pll->den_min = 1;
443 + rats_no_pll->den_max = 128;
444 + rats_no_pll->den_step = 1;
445 +
446 + err = snd_interval_ratnum(hw_param_interval(params,
447 + SNDRV_PCM_HW_PARAM_RATE), 1, rats_no_pll, &num, &den);
448 + if (err >= 0 && den) {
449 + params->rate_num = num;
450 + params->rate_den = den;
451 + }
452 +
453 + devm_kfree(rtd->dev, rats_no_pll);
454 + return 0;
455 +}
456 +
457 +static int snd_allo_boss_set_bclk_ratio_pro(
458 + struct snd_soc_dai *cpu_dai, struct snd_pcm_hw_params *params)
459 +{
460 + int bratio = snd_pcm_format_physical_width(params_format(params))
461 + * params_channels(params);
462 + return snd_soc_dai_set_bclk_ratio(cpu_dai, bratio);
463 +}
464 +
465 +static void snd_allo_boss_gpio_mute(struct snd_soc_card *card)
466 +{
467 + if (mute_gpio)
468 + gpiod_set_value_cansleep(mute_gpio, 1);
469 +}
470 +
471 +static void snd_allo_boss_gpio_unmute(struct snd_soc_card *card)
472 +{
473 + if (mute_gpio)
474 + gpiod_set_value_cansleep(mute_gpio, 0);
475 +}
476 +
477 +static int snd_allo_boss_set_bias_level(struct snd_soc_card *card,
478 + struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
479 +{
480 + struct snd_soc_pcm_runtime *rtd;
481 + struct snd_soc_dai *codec_dai;
482 +
483 + rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name);
484 + codec_dai = rtd->codec_dai;
485 +
486 + if (dapm->dev != codec_dai->dev)
487 + return 0;
488 +
489 + switch (level) {
490 + case SND_SOC_BIAS_PREPARE:
491 + if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
492 + break;
493 + /* UNMUTE DAC */
494 + snd_allo_boss_gpio_unmute(card);
495 + break;
496 +
497 + case SND_SOC_BIAS_STANDBY:
498 + if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
499 + break;
500 + /* MUTE DAC */
501 + snd_allo_boss_gpio_mute(card);
502 + break;
503 +
504 + default:
505 + break;
506 + }
507 +
508 + return 0;
509 +}
510 +
511 +static int snd_allo_boss_hw_params(
512 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
513 +{
514 + int ret = 0;
515 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
516 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
517 + unsigned int sample_bits =
518 + snd_pcm_format_physical_width(params_format(params));
519 +
520 + if (snd_soc_allo_boss_master) {
521 + struct snd_soc_codec *codec = rtd->codec;
522 +
523 + snd_allo_boss_set_sclk(codec,
524 + params_rate(params));
525 +
526 + ret = snd_allo_boss_set_bclk_ratio_pro(cpu_dai,
527 + params);
528 + if (!ret)
529 + ret = snd_allo_boss_update_rate_den(
530 + substream, params);
531 + } else {
532 + ret = snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
533 + }
534 + return ret;
535 +}
536 +
537 +static int snd_allo_boss_startup(
538 + struct snd_pcm_substream *substream)
539 +{
540 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
541 + struct snd_soc_codec *codec = rtd->codec;
542 + struct snd_soc_card *card = rtd->card;
543 +
544 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08, 0x08);
545 + snd_allo_boss_gpio_mute(card);
546 +
547 + if (snd_soc_allo_boss_master) {
548 + struct pcm512x_priv *priv = snd_soc_codec_get_drvdata(codec);
549 + /*
550 + * Default sclk to CLK_48EN_RATE, otherwise codec
551 + * pcm512x_dai_startup_master method could call
552 + * snd_pcm_hw_constraint_ratnums using CLK_44EN/64
553 + * which will mask 384k sample rate.
554 + */
555 + if (!IS_ERR(priv->sclk))
556 + clk_set_rate(priv->sclk, CLK_48EN_RATE);
557 + }
558 +
559 + return 0;
560 +}
561 +
562 +static void snd_allo_boss_shutdown(
563 + struct snd_pcm_substream *substream)
564 +{
565 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
566 + struct snd_soc_codec *codec = rtd->codec;
567 +
568 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
569 +}
570 +
571 +static int snd_allo_boss_prepare(
572 + struct snd_pcm_substream *substream)
573 +{
574 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
575 + struct snd_soc_card *card = rtd->card;
576 +
577 + snd_allo_boss_gpio_unmute(card);
578 + return 0;
579 +}
580 +/* machine stream operations */
581 +static struct snd_soc_ops snd_allo_boss_ops = {
582 + .hw_params = snd_allo_boss_hw_params,
583 + .startup = snd_allo_boss_startup,
584 + .shutdown = snd_allo_boss_shutdown,
585 + .prepare = snd_allo_boss_prepare,
586 +};
587 +
588 +static struct snd_soc_dai_link snd_allo_boss_dai[] = {
589 +{
590 + .name = "Boss DAC",
591 + .stream_name = "Boss DAC HiFi",
592 + .cpu_dai_name = "bcm2708-i2s.0",
593 + .codec_dai_name = "pcm512x-hifi",
594 + .platform_name = "bcm2708-i2s.0",
595 + .codec_name = "pcm512x.1-004d",
596 + .dai_fmt = SND_SOC_DAIFMT_I2S |
597 + SND_SOC_DAIFMT_NB_NF |
598 + SND_SOC_DAIFMT_CBS_CFS,
599 + .ops = &snd_allo_boss_ops,
600 + .init = snd_allo_boss_init,
601 +},
602 +};
603 +
604 +/* audio machine driver */
605 +static struct snd_soc_card snd_allo_boss = {
606 + .name = "BossDAC",
607 + .owner = THIS_MODULE,
608 + .dai_link = snd_allo_boss_dai,
609 + .num_links = ARRAY_SIZE(snd_allo_boss_dai),
610 +};
611 +
612 +static int snd_allo_boss_probe(struct platform_device *pdev)
613 +{
614 + int ret = 0;
615 +
616 + snd_allo_boss.dev = &pdev->dev;
617 +
618 + if (pdev->dev.of_node) {
619 + struct device_node *i2s_node;
620 + struct snd_soc_dai_link *dai;
621 +
622 + dai = &snd_allo_boss_dai[0];
623 + i2s_node = of_parse_phandle(pdev->dev.of_node,
624 + "i2s-controller", 0);
625 +
626 + if (i2s_node) {
627 + dai->cpu_dai_name = NULL;
628 + dai->cpu_of_node = i2s_node;
629 + dai->platform_name = NULL;
630 + dai->platform_of_node = i2s_node;
631 + }
632 +
633 + digital_gain_0db_limit = !of_property_read_bool(
634 + pdev->dev.of_node, "allo,24db_digital_gain");
635 + slave = of_property_read_bool(pdev->dev.of_node,
636 + "allo,slave");
637 +
638 + mute_gpio = devm_gpiod_get_optional(&pdev->dev, "mute",
639 + GPIOD_OUT_LOW);
640 + if (IS_ERR(mute_gpio)) {
641 + ret = PTR_ERR(mute_gpio);
642 + dev_err(&pdev->dev,
643 + "failed to get mute gpio: %d\n", ret);
644 + return ret;
645 + }
646 +
647 + if (mute_gpio)
648 + snd_allo_boss.set_bias_level =
649 + snd_allo_boss_set_bias_level;
650 +
651 + ret = snd_soc_register_card(&snd_allo_boss);
652 + if (ret) {
653 + dev_err(&pdev->dev,
654 + "snd_soc_register_card() failed: %d\n", ret);
655 + return ret;
656 + }
657 +
658 + if (mute_gpio)
659 + snd_allo_boss_gpio_mute(&snd_allo_boss);
660 +
661 + return 0;
662 + }
663 +
664 + return -EINVAL;
665 +}
666 +
667 +static int snd_allo_boss_remove(struct platform_device *pdev)
668 +{
669 + snd_allo_boss_gpio_mute(&snd_allo_boss);
670 + return snd_soc_unregister_card(&snd_allo_boss);
671 +}
672 +
673 +static const struct of_device_id snd_allo_boss_of_match[] = {
674 + { .compatible = "allo,boss-dac", },
675 + { /* sentinel */ },
676 +};
677 +MODULE_DEVICE_TABLE(of, snd_allo_boss_of_match);
678 +
679 +static struct platform_driver snd_allo_boss_driver = {
680 + .driver = {
681 + .name = "snd-allo-boss-dac",
682 + .owner = THIS_MODULE,
683 + .of_match_table = snd_allo_boss_of_match,
684 + },
685 + .probe = snd_allo_boss_probe,
686 + .remove = snd_allo_boss_remove,
687 +};
688 +
689 +module_platform_driver(snd_allo_boss_driver);
690 +
691 +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
692 +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Boss DAC");
693 +MODULE_LICENSE("GPL v2");