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