2 * ALSA ASoC Machine Driver for Allo Piano DAC
4 * Author: Baswaraj K <jaikumar@cem-solutions.net>
6 * based on code by Daniel Matuschek <info@crazy-audio.com>
7 * based on code by Florian Meier <florian.meier@koalo.de>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
27 static bool digital_gain_0db_limit = true;
29 static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
31 if (digital_gain_0db_limit) {
33 struct snd_soc_card *card = rtd->card;
35 ret = snd_soc_limit_volume(card, "Digital Playback Volume",
38 dev_warn(card->dev, "Failed to set volume limit: %d\n",
45 SND_SOC_DAILINK_DEFS(allo_piano_dai,
46 DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
47 DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi")),
48 DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
50 static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
53 .stream_name = "Piano DAC HiFi",
54 .dai_fmt = SND_SOC_DAIFMT_I2S |
55 SND_SOC_DAIFMT_NB_NF |
56 SND_SOC_DAIFMT_CBS_CFS,
57 .init = snd_allo_piano_dac_init,
58 SND_SOC_DAILINK_REG(allo_piano_dai),
62 /* audio machine driver */
63 static struct snd_soc_card snd_allo_piano_dac = {
66 .dai_link = snd_allo_piano_dac_dai,
67 .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
70 static int snd_allo_piano_dac_probe(struct platform_device *pdev)
74 snd_allo_piano_dac.dev = &pdev->dev;
76 if (pdev->dev.of_node) {
77 struct device_node *i2s_node;
78 struct snd_soc_dai_link *dai;
80 dai = &snd_allo_piano_dac_dai[0];
81 i2s_node = of_parse_phandle(pdev->dev.of_node,
85 dai->cpus->dai_name = NULL;
86 dai->cpus->of_node = i2s_node;
87 dai->platforms->name = NULL;
88 dai->platforms->of_node = i2s_node;
91 digital_gain_0db_limit = !of_property_read_bool(
92 pdev->dev.of_node, "allo,24db_digital_gain");
95 ret = devm_snd_soc_register_card(&pdev->dev, &snd_allo_piano_dac);
96 if (ret && ret != -EPROBE_DEFER)
98 "snd_soc_register_card() failed: %d\n", ret);
103 static const struct of_device_id snd_allo_piano_dac_of_match[] = {
104 { .compatible = "allo,piano-dac", },
107 MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
109 static struct platform_driver snd_allo_piano_dac_driver = {
111 .name = "snd-allo-piano-dac",
112 .owner = THIS_MODULE,
113 .of_match_table = snd_allo_piano_dac_of_match,
115 .probe = snd_allo_piano_dac_probe,
118 module_platform_driver(snd_allo_piano_dac_driver);
120 MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
121 MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
122 MODULE_LICENSE("GPL v2");