Merge tag 'v5.15.57' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / sound / soc / bcm / dionaudio_loco-v2.c
1 /*
2  * ASoC Driver for Dion Audio LOCO-V2 DAC-AMP
3  *
4  * Author:      Miquel Blauw <info@dionaudio.nl>
5  *              Copyright 2017
6  *
7  * Based on the software of the RPi-DAC writen by Florian Meier
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 #include <sound/jack.h>
27
28 static bool digital_gain_0db_limit = true;
29
30 static int snd_rpi_dionaudio_loco_v2_init(struct snd_soc_pcm_runtime *rtd)
31 {
32         if (digital_gain_0db_limit) {
33                 int ret;
34                 struct snd_soc_card *card = rtd->card;
35
36                 ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
37                 if (ret < 0)
38                         dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
39         }
40
41         return 0;
42 }
43
44 SND_SOC_DAILINK_DEFS(dionaudio_loco_v2,
45         DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
46         DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
47         DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
48
49 static struct snd_soc_dai_link snd_rpi_dionaudio_loco_v2_dai[] = {
50 {
51         .name           = "DionAudio LOCO-V2",
52         .stream_name    = "DionAudio LOCO-V2 DAC-AMP",
53         .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
54                           SND_SOC_DAIFMT_CBS_CFS,
55         .init           = snd_rpi_dionaudio_loco_v2_init,
56         SND_SOC_DAILINK_REG(dionaudio_loco_v2),
57 },};
58
59 /* audio machine driver */
60 static struct snd_soc_card snd_rpi_dionaudio_loco_v2 = {
61         .name         = "Dion Audio LOCO-V2",
62         .dai_link     = snd_rpi_dionaudio_loco_v2_dai,
63         .num_links    = ARRAY_SIZE(snd_rpi_dionaudio_loco_v2_dai),
64 };
65
66 static int snd_rpi_dionaudio_loco_v2_probe(struct platform_device *pdev)
67 {
68         int ret = 0;
69
70         snd_rpi_dionaudio_loco_v2.dev = &pdev->dev;
71
72         if (pdev->dev.of_node) {
73                 struct device_node *i2s_node;
74                 struct snd_soc_dai_link *dai =
75                                         &snd_rpi_dionaudio_loco_v2_dai[0];
76
77                 i2s_node = of_parse_phandle(pdev->dev.of_node,
78                                             "i2s-controller", 0);
79                 if (i2s_node) {
80                         dai->cpus->dai_name = NULL;
81                         dai->cpus->of_node = i2s_node;
82                         dai->platforms->name = NULL;
83                         dai->platforms->of_node = i2s_node;
84                 }
85
86                 digital_gain_0db_limit = !of_property_read_bool(
87                         pdev->dev.of_node, "dionaudio,24db_digital_gain");
88         }
89
90         ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco_v2);
91         if (ret)
92                 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
93                         ret);
94
95         return ret;
96 }
97
98 static const struct of_device_id dionaudio_of_match[] = {
99         { .compatible = "dionaudio,dionaudio-loco-v2", },
100         {},
101 };
102 MODULE_DEVICE_TABLE(of, dionaudio_of_match);
103
104 static struct platform_driver snd_rpi_dionaudio_loco_v2_driver = {
105         .driver = {
106                 .name   = "snd-rpi-dionaudio-loco-v2",
107                 .owner  = THIS_MODULE,
108                 .of_match_table = dionaudio_of_match,
109         },
110         .probe          = snd_rpi_dionaudio_loco_v2_probe,
111 };
112
113 module_platform_driver(snd_rpi_dionaudio_loco_v2_driver);
114
115 MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
116 MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO-V2");
117 MODULE_LICENSE("GPL v2");