bcm27xx: add linux 5.4 support
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0073-sound-Support-for-Dion-Audio-LOCO-V2-DAC-AMP-HAT.patch
1 From a1a8a4fb0f50f92f1c42164827dbdfb57007f183 Mon Sep 17 00:00:00 2001
2 From: Miquel <miquelblauw@hotmail.com>
3 Date: Fri, 24 Feb 2017 20:51:06 +0100
4 Subject: [PATCH] sound: Support for Dion Audio LOCO-V2 DAC-AMP HAT
5
6 Signed-off-by: Miquel Blauw <info@dionaudio.nl>
7
8 ASoC: dionaudio_loco-v2: fix S24_LE format
9
10 Remove set_bclk_ratio call so 24-bit data is transmitted in
11 24 bclk cycles.
12
13 Also remove hw_params and ops as they are no longer needed.
14
15 Signed-off-by: Matthias Reichl <hias@horus.com>
16
17 ASoC: dionaudio_loco-v2: use modern dai_link style
18
19 Signed-off-by: Hui Wang <hui.wang@canonical.com>
20 ---
21 sound/soc/bcm/dionaudio_loco-v2.c | 117 ++++++++++++++++++++++++++++++
22 1 file changed, 117 insertions(+)
23 create mode 100644 sound/soc/bcm/dionaudio_loco-v2.c
24
25 --- /dev/null
26 +++ b/sound/soc/bcm/dionaudio_loco-v2.c
27 @@ -0,0 +1,117 @@
28 +/*
29 + * ASoC Driver for Dion Audio LOCO-V2 DAC-AMP
30 + *
31 + * Author: Miquel Blauw <info@dionaudio.nl>
32 + * Copyright 2017
33 + *
34 + * Based on the software of the RPi-DAC writen by Florian Meier
35 + *
36 + * This program is free software; you can redistribute it and/or
37 + * modify it under the terms of the GNU General Public License
38 + * version 2 as published by the Free Software Foundation.
39 + *
40 + * This program is distributed in the hope that it will be useful, but
41 + * WITHOUT ANY WARRANTY; without even the implied warranty of
42 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43 + * General Public License for more details.
44 + */
45 +
46 +#include <linux/module.h>
47 +#include <linux/platform_device.h>
48 +
49 +#include <sound/core.h>
50 +#include <sound/pcm.h>
51 +#include <sound/pcm_params.h>
52 +#include <sound/soc.h>
53 +#include <sound/jack.h>
54 +
55 +static bool digital_gain_0db_limit = true;
56 +
57 +static int snd_rpi_dionaudio_loco_v2_init(struct snd_soc_pcm_runtime *rtd)
58 +{
59 + if (digital_gain_0db_limit) {
60 + int ret;
61 + struct snd_soc_card *card = rtd->card;
62 +
63 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
64 + if (ret < 0)
65 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
66 + }
67 +
68 + return 0;
69 +}
70 +
71 +SND_SOC_DAILINK_DEFS(dionaudio_loco_v2,
72 + DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
73 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
74 + DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
75 +
76 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_v2_dai[] = {
77 +{
78 + .name = "DionAudio LOCO-V2",
79 + .stream_name = "DionAudio LOCO-V2 DAC-AMP",
80 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
81 + SND_SOC_DAIFMT_CBS_CFS,
82 + .init = snd_rpi_dionaudio_loco_v2_init,
83 + SND_SOC_DAILINK_REG(dionaudio_loco_v2),
84 +},};
85 +
86 +/* audio machine driver */
87 +static struct snd_soc_card snd_rpi_dionaudio_loco_v2 = {
88 + .name = "Dion Audio LOCO-V2",
89 + .dai_link = snd_rpi_dionaudio_loco_v2_dai,
90 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_v2_dai),
91 +};
92 +
93 +static int snd_rpi_dionaudio_loco_v2_probe(struct platform_device *pdev)
94 +{
95 + int ret = 0;
96 +
97 + snd_rpi_dionaudio_loco_v2.dev = &pdev->dev;
98 +
99 + if (pdev->dev.of_node) {
100 + struct device_node *i2s_node;
101 + struct snd_soc_dai_link *dai =
102 + &snd_rpi_dionaudio_loco_v2_dai[0];
103 +
104 + i2s_node = of_parse_phandle(pdev->dev.of_node,
105 + "i2s-controller", 0);
106 + if (i2s_node) {
107 + dai->cpus->dai_name = NULL;
108 + dai->cpus->of_node = i2s_node;
109 + dai->platforms->name = NULL;
110 + dai->platforms->of_node = i2s_node;
111 + }
112 +
113 + digital_gain_0db_limit = !of_property_read_bool(
114 + pdev->dev.of_node, "dionaudio,24db_digital_gain");
115 + }
116 +
117 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_rpi_dionaudio_loco_v2);
118 + if (ret)
119 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
120 + ret);
121 +
122 + return ret;
123 +}
124 +
125 +static const struct of_device_id dionaudio_of_match[] = {
126 + { .compatible = "dionaudio,dionaudio-loco-v2", },
127 + {},
128 +};
129 +MODULE_DEVICE_TABLE(of, dionaudio_of_match);
130 +
131 +static struct platform_driver snd_rpi_dionaudio_loco_v2_driver = {
132 + .driver = {
133 + .name = "snd-rpi-dionaudio-loco-v2",
134 + .owner = THIS_MODULE,
135 + .of_match_table = dionaudio_of_match,
136 + },
137 + .probe = snd_rpi_dionaudio_loco_v2_probe,
138 +};
139 +
140 +module_platform_driver(snd_rpi_dionaudio_loco_v2_driver);
141 +
142 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
143 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO-V2");
144 +MODULE_LICENSE("GPL v2");