Merge tag 'v5.15.57' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / sound / soc / bcm / allo-piano-dac.c
1 /*
2  * ALSA ASoC Machine Driver for Allo Piano DAC
3  *
4  * Author:      Baswaraj K <jaikumar@cem-solutions.net>
5  *              Copyright 2016
6  *              based on code by Daniel Matuschek <info@crazy-audio.com>
7  *              based on code by Florian Meier <florian.meier@koalo.de>
8  *
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.
12  *
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.
17  */
18
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
26
27 static bool digital_gain_0db_limit = true;
28
29 static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
30 {
31         if (digital_gain_0db_limit) {
32                 int ret;
33                 struct snd_soc_card *card = rtd->card;
34
35                 ret = snd_soc_limit_volume(card, "Digital Playback Volume",
36                                            207);
37                 if (ret < 0)
38                         dev_warn(card->dev, "Failed to set volume limit: %d\n",
39                                  ret);
40         }
41
42         return 0;
43 }
44
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")));
49
50 static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
51 {
52         .name           = "Piano DAC",
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),
59 },
60 };
61
62 /* audio machine driver */
63 static struct snd_soc_card snd_allo_piano_dac = {
64         .name         = "PianoDAC",
65         .owner        = THIS_MODULE,
66         .dai_link     = snd_allo_piano_dac_dai,
67         .num_links    = ARRAY_SIZE(snd_allo_piano_dac_dai),
68 };
69
70 static int snd_allo_piano_dac_probe(struct platform_device *pdev)
71 {
72         int ret = 0;
73
74         snd_allo_piano_dac.dev = &pdev->dev;
75
76         if (pdev->dev.of_node) {
77                 struct device_node *i2s_node;
78                 struct snd_soc_dai_link *dai;
79
80                 dai = &snd_allo_piano_dac_dai[0];
81                 i2s_node = of_parse_phandle(pdev->dev.of_node,
82                                             "i2s-controller", 0);
83
84                 if (i2s_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;
89                 }
90
91                 digital_gain_0db_limit = !of_property_read_bool(
92                         pdev->dev.of_node, "allo,24db_digital_gain");
93         }
94
95         ret = devm_snd_soc_register_card(&pdev->dev, &snd_allo_piano_dac);
96         if (ret && ret != -EPROBE_DEFER)
97                 dev_err(&pdev->dev,
98                         "snd_soc_register_card() failed: %d\n", ret);
99
100         return ret;
101 }
102
103 static const struct of_device_id snd_allo_piano_dac_of_match[] = {
104         { .compatible = "allo,piano-dac", },
105         { /* sentinel */ },
106 };
107 MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
108
109 static struct platform_driver snd_allo_piano_dac_driver = {
110         .driver = {
111                 .name   = "snd-allo-piano-dac",
112                 .owner  = THIS_MODULE,
113                 .of_match_table = snd_allo_piano_dac_of_match,
114         },
115         .probe          = snd_allo_piano_dac_probe,
116 };
117
118 module_platform_driver(snd_allo_piano_dac_driver);
119
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");