kernel: update kernel 4.4 to 4.4.52
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.9 / 0077-RaspiDAC3-support.patch
1 From 26084a968083e88298416426576dbd4c006e5dea Mon Sep 17 00:00:00 2001
2 From: Jan Grulich <jan@grulich.eu>
3 Date: Mon, 24 Aug 2015 16:03:47 +0100
4 Subject: [PATCH] RaspiDAC3 support
5
6 Signed-off-by: Jan Grulich <jan@grulich.eu>
7
8 config: fix RaspiDAC Rev.3x dependencies
9
10 Change depends to SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
11 like the other I2S soundcard drivers.
12
13 Signed-off-by: Matthias Reichl <hias@horus.com>
14 ---
15 sound/soc/bcm/Kconfig | 8 ++
16 sound/soc/bcm/Makefile | 2 +
17 sound/soc/bcm/raspidac3.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++
18 3 files changed, 196 insertions(+)
19 create mode 100644 sound/soc/bcm/raspidac3.c
20
21 --- a/sound/soc/bcm/Kconfig
22 +++ b/sound/soc/bcm/Kconfig
23 @@ -58,3 +58,11 @@ config SND_BCM2708_SOC_IQAUDIO_DAC
24 select SND_SOC_PCM512x_I2C
25 help
26 Say Y or M if you want to add support for IQaudIO-DAC.
27 +
28 +config SND_BCM2708_SOC_RASPIDAC3
29 + tristate "Support for RaspiDAC Rev.3x"
30 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
31 + select SND_SOC_PCM512x_I2C
32 + select SND_SOC_TPA6130A2
33 + help
34 + Say Y or M if you want to add support for RaspiDAC Rev.3x.
35 --- a/sound/soc/bcm/Makefile
36 +++ b/sound/soc/bcm/Makefile
37 @@ -15,6 +15,7 @@ snd-soc-hifiberry-digi-objs := hifiberry
38 snd-soc-rpi-dac-objs := rpi-dac.o
39 snd-soc-rpi-proto-objs := rpi-proto.o
40 snd-soc-iqaudio-dac-objs := iqaudio-dac.o
41 +snd-soc-raspidac3-objs := raspidac3.o
42
43 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
44 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
45 @@ -22,3 +23,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_D
46 obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
47 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
48 obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
49 +obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
50 --- /dev/null
51 +++ b/sound/soc/bcm/raspidac3.c
52 @@ -0,0 +1,186 @@
53 +/*
54 + * ASoC Driver for RaspiDAC v3
55 + *
56 + * Author: Jan Grulich <jan@grulich.eu>
57 + * Copyright 2015
58 + * based on code by Daniel Matuschek <daniel@hifiberry.com>
59 + * based on code by Florian Meier <florian.meier@koalo.de>
60 + *
61 + * This program is free software; you can redistribute it and/or
62 + * modify it under the terms of the GNU General Public License
63 + * version 2 as published by the Free Software Foundation.
64 + *
65 + * This program is distributed in the hope that it will be useful, but
66 + * WITHOUT ANY WARRANTY; without even the implied warranty of
67 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
68 + * General Public License for more details.
69 + */
70 +
71 +#include <linux/module.h>
72 +#include <linux/platform_device.h>
73 +
74 +#include <sound/core.h>
75 +#include <sound/pcm.h>
76 +#include <sound/pcm_params.h>
77 +#include <sound/soc.h>
78 +#include <sound/jack.h>
79 +#include <sound/soc-dapm.h>
80 +
81 +#include "../codecs/pcm512x.h"
82 +#include "../codecs/tpa6130a2.h"
83 +
84 +/* sound card init */
85 +static int snd_rpi_raspidac3_init(struct snd_soc_pcm_runtime *rtd)
86 +{
87 + int ret;
88 + struct snd_soc_card *card = rtd->card;
89 + struct snd_soc_codec *codec = rtd->codec;
90 + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
91 + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
92 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
93 +
94 + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
95 + if (ret < 0)
96 + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
97 + else {
98 + struct snd_kcontrol *kctl;
99 +
100 + ret = snd_soc_limit_volume(card,
101 + "TPA6130A2 Headphone Playback Volume",
102 + 54);
103 + if (ret < 0)
104 + dev_warn(card->dev, "Failed to set TPA6130A2 volume limit: %d\n",
105 + ret);
106 + kctl = snd_soc_card_get_kcontrol(card,
107 + "TPA6130A2 Headphone Playback Volume");
108 + if (kctl) {
109 + strcpy(kctl->id.name, "Headphones Playback Volume");
110 + /* disable the volume dB scale so alsamixer works */
111 + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
112 + }
113 +
114 + kctl = snd_soc_card_get_kcontrol(card,
115 + "TPA6130A2 Headphone Playback Switch");
116 + if (kctl)
117 + strcpy(kctl->id.name, "Headphones Playback Switch");
118 + }
119 +
120 + return 0;
121 +}
122 +
123 +/* set hw parameters */
124 +static int snd_rpi_raspidac3_hw_params(struct snd_pcm_substream *substream,
125 + struct snd_pcm_hw_params *params)
126 +{
127 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
128 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
129 +
130 + unsigned int sample_bits =
131 + snd_pcm_format_physical_width(params_format(params));
132 +
133 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
134 +}
135 +
136 +/* startup */
137 +static int snd_rpi_raspidac3_startup(struct snd_pcm_substream *substream) {
138 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
139 + struct snd_soc_codec *codec = rtd->codec;
140 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
141 + return 0;
142 +}
143 +
144 +/* shutdown */
145 +static void snd_rpi_raspidac3_shutdown(struct snd_pcm_substream *substream) {
146 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
147 + struct snd_soc_codec *codec = rtd->codec;
148 + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
149 +}
150 +
151 +/* machine stream operations */
152 +static struct snd_soc_ops snd_rpi_raspidac3_ops = {
153 + .hw_params = snd_rpi_raspidac3_hw_params,
154 + .startup = snd_rpi_raspidac3_startup,
155 + .shutdown = snd_rpi_raspidac3_shutdown,
156 +};
157 +
158 +/* interface setup */
159 +static struct snd_soc_dai_link snd_rpi_raspidac3_dai[] = {
160 +{
161 + .name = "RaspiDAC Rev.3x",
162 + .stream_name = "RaspiDAC HiFi",
163 + .cpu_dai_name = "bcm2708-i2s.0",
164 + .codec_dai_name = "pcm512x-hifi",
165 + .platform_name = "bcm2708-i2s.0",
166 + .codec_name = "pcm512x.1-004c",
167 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
168 + SND_SOC_DAIFMT_CBS_CFS,
169 + .ops = &snd_rpi_raspidac3_ops,
170 + .init = snd_rpi_raspidac3_init,
171 +},
172 +};
173 +
174 +/* audio machine driver */
175 +static struct snd_soc_card snd_rpi_raspidac3 = {
176 + .name = "RaspiDAC Rev.3x HiFi Audio Card",
177 + .owner = THIS_MODULE,
178 + .dai_link = snd_rpi_raspidac3_dai,
179 + .num_links = ARRAY_SIZE(snd_rpi_raspidac3_dai),
180 +};
181 +
182 +/* sound card test */
183 +static int snd_rpi_raspidac3_probe(struct platform_device *pdev)
184 +{
185 + int ret = 0;
186 +
187 + snd_rpi_raspidac3.dev = &pdev->dev;
188 +
189 + if (pdev->dev.of_node) {
190 + struct device_node *i2s_node;
191 + struct snd_soc_dai_link *dai = &snd_rpi_raspidac3_dai[0];
192 + i2s_node = of_parse_phandle(pdev->dev.of_node,
193 + "i2s-controller", 0);
194 +
195 + if (i2s_node) {
196 + dai->cpu_dai_name = NULL;
197 + dai->cpu_of_node = i2s_node;
198 + dai->platform_name = NULL;
199 + dai->platform_of_node = i2s_node;
200 + }
201 + }
202 +
203 + ret = snd_soc_register_card(&snd_rpi_raspidac3);
204 + if (ret)
205 + dev_err(&pdev->dev,
206 + "snd_soc_register_card() failed: %d\n", ret);
207 +
208 + return ret;
209 +}
210 +
211 +/* sound card disconnect */
212 +static int snd_rpi_raspidac3_remove(struct platform_device *pdev)
213 +{
214 + return snd_soc_unregister_card(&snd_rpi_raspidac3);
215 +}
216 +
217 +static const struct of_device_id raspidac3_of_match[] = {
218 + { .compatible = "jg,raspidacv3", },
219 + {},
220 +};
221 +MODULE_DEVICE_TABLE(of, raspidac3_of_match);
222 +
223 +/* sound card platform driver */
224 +static struct platform_driver snd_rpi_raspidac3_driver = {
225 + .driver = {
226 + .name = "snd-rpi-raspidac3",
227 + .owner = THIS_MODULE,
228 + .of_match_table = raspidac3_of_match,
229 + },
230 + .probe = snd_rpi_raspidac3_probe,
231 + .remove = snd_rpi_raspidac3_remove,
232 +};
233 +
234 +module_platform_driver(snd_rpi_raspidac3_driver);
235 +
236 +MODULE_AUTHOR("Jan Grulich <jan@grulich.eu>");
237 +MODULE_DESCRIPTION("ASoC Driver for RaspiDAC Rev.3x");
238 +MODULE_LICENSE("GPL v2");