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