7f4075a34f18308dd515630a1ecd1b58160ecc39
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-3.14 / 0042-ASoC-BCM2708-Add-support-for-RPi-DAC.patch
1 From ab038bbb25bcd86ef59a5f5651ce00d30190d4ad Mon Sep 17 00:00:00 2001
2 From: Florian Meier <florian.meier@koalo.de>
3 Date: Fri, 6 Dec 2013 20:50:28 +0100
4 Subject: [PATCH 42/54] ASoC: BCM2708: Add support for RPi-DAC
5
6 This adds a machine driver for the RPi-DAC.
7
8 Signed-off-by: Florian Meier <florian.meier@koalo.de>
9 ---
10 arch/arm/configs/bcmrpi_defconfig | 2 +
11 arch/arm/mach-bcm2708/bcm2708.c | 19 ++++++++
12 sound/soc/bcm/Kconfig | 7 +++
13 sound/soc/bcm/Makefile | 2 +
14 sound/soc/bcm/rpi-dac.c | 97 +++++++++++++++++++++++++++++++++++++++
15 sound/soc/codecs/Kconfig | 4 ++
16 sound/soc/codecs/Makefile | 2 +
17 sound/soc/codecs/pcm1794a.c | 62 +++++++++++++++++++++++++
18 8 files changed, 195 insertions(+)
19 create mode 100644 sound/soc/bcm/rpi-dac.c
20 create mode 100644 sound/soc/codecs/pcm1794a.c
21
22 diff --git a/arch/arm/configs/bcmrpi_defconfig b/arch/arm/configs/bcmrpi_defconfig
23 index 36e7473..f877ab2 100644
24 --- a/arch/arm/configs/bcmrpi_defconfig
25 +++ b/arch/arm/configs/bcmrpi_defconfig
26 @@ -744,8 +744,10 @@ CONFIG_SND_SOC_DMAENGINE_PCM=y
27 CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
28 CONFIG_SND_BCM2708_SOC_I2S=m
29 CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
30 +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
31 CONFIG_SND_SOC_I2C_AND_SPI=m
32 CONFIG_SND_SOC_PCM5102A=m
33 +CONFIG_SND_SOC_PCM1794A=m
34 CONFIG_SOUND_PRIME=m
35 CONFIG_HIDRAW=y
36 CONFIG_HID_A4TECH=m
37 diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
38 index 82b09a5..cf10f74 100644
39 --- a/arch/arm/mach-bcm2708/bcm2708.c
40 +++ b/arch/arm/mach-bcm2708/bcm2708.c
41 @@ -651,6 +651,20 @@ static struct platform_device snd_pcm5102a_codec_device = {
42 };
43 #endif
44
45 +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
46 +static struct platform_device snd_rpi_dac_device = {
47 + .name = "snd-rpi-dac",
48 + .id = 0,
49 + .num_resources = 0,
50 +};
51 +
52 +static struct platform_device snd_pcm1794a_codec_device = {
53 + .name = "pcm1794a-codec",
54 + .id = -1,
55 + .num_resources = 0,
56 +};
57 +#endif
58 +
59 int __init bcm_register_device(struct platform_device *pdev)
60 {
61 int ret;
62 @@ -783,6 +797,11 @@ void __init bcm2708_init(void)
63 bcm_register_device(&snd_pcm5102a_codec_device);
64 #endif
65
66 +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
67 + bcm_register_device(&snd_rpi_dac_device);
68 + bcm_register_device(&snd_pcm1794a_codec_device);
69 +#endif
70 +
71 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
72 struct amba_device *d = amba_devs[i];
73 amba_device_register(d, &iomem_resource);
74 diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig
75 index b36a62f..714841d 100644
76 --- a/sound/soc/bcm/Kconfig
77 +++ b/sound/soc/bcm/Kconfig
78 @@ -25,3 +25,10 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
79 select SND_SOC_PCM5102A
80 help
81 Say Y or M if you want to add support for HifiBerry DAC.
82 +
83 +config SND_BCM2708_SOC_RPI_DAC
84 + tristate "Support for RPi-DAC"
85 + depends on SND_BCM2708_SOC_I2S
86 + select SND_SOC_PCM1794A
87 + help
88 + Say Y or M if you want to add support for RPi-DAC.
89 diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile
90 index be90a49cb..ccc9809 100644
91 --- a/sound/soc/bcm/Makefile
92 +++ b/sound/soc/bcm/Makefile
93 @@ -10,5 +10,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
94
95 # BCM2708 Machine Support
96 snd-soc-hifiberry-dac-objs := hifiberry_dac.o
97 +snd-soc-rpi-dac-objs := rpi-dac.o
98
99 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
100 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
101 diff --git a/sound/soc/bcm/rpi-dac.c b/sound/soc/bcm/rpi-dac.c
102 new file mode 100644
103 index 0000000..ef3cd93
104 --- /dev/null
105 +++ b/sound/soc/bcm/rpi-dac.c
106 @@ -0,0 +1,97 @@
107 +/*
108 + * ASoC Driver for RPi-DAC.
109 + *
110 + * Author: Florian Meier <florian.meier@koalo.de>
111 + * Copyright 2013
112 + *
113 + * This program is free software; you can redistribute it and/or
114 + * modify it under the terms of the GNU General Public License
115 + * version 2 as published by the Free Software Foundation.
116 + *
117 + * This program is distributed in the hope that it will be useful, but
118 + * WITHOUT ANY WARRANTY; without even the implied warranty of
119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
120 + * General Public License for more details.
121 + */
122 +
123 +#include <linux/module.h>
124 +#include <linux/platform_device.h>
125 +
126 +#include <sound/core.h>
127 +#include <sound/pcm.h>
128 +#include <sound/pcm_params.h>
129 +#include <sound/soc.h>
130 +#include <sound/jack.h>
131 +
132 +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
133 +{
134 + return 0;
135 +}
136 +
137 +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
138 + struct snd_pcm_hw_params *params)
139 +{
140 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
141 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
142 +
143 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
144 +}
145 +
146 +/* machine stream operations */
147 +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
148 + .hw_params = snd_rpi_rpi_dac_hw_params,
149 +};
150 +
151 +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
152 +{
153 + .name = "HifiBerry Mini",
154 + .stream_name = "HifiBerry Mini HiFi",
155 + .cpu_dai_name = "bcm2708-i2s.0",
156 + .codec_dai_name = "pcm1794a-hifi",
157 + .platform_name = "bcm2708-i2s.0",
158 + .codec_name = "pcm1794a-codec",
159 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
160 + SND_SOC_DAIFMT_CBS_CFS,
161 + .ops = &snd_rpi_rpi_dac_ops,
162 + .init = snd_rpi_rpi_dac_init,
163 +},
164 +};
165 +
166 +/* audio machine driver */
167 +static struct snd_soc_card snd_rpi_rpi_dac = {
168 + .name = "snd_rpi_rpi_dac",
169 + .dai_link = snd_rpi_rpi_dac_dai,
170 + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
171 +};
172 +
173 +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
174 +{
175 + int ret = 0;
176 +
177 + snd_rpi_rpi_dac.dev = &pdev->dev;
178 + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
179 + if (ret)
180 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
181 +
182 + return ret;
183 +}
184 +
185 +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
186 +{
187 + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
188 +}
189 +
190 +static struct platform_driver snd_rpi_rpi_dac_driver = {
191 + .driver = {
192 + .name = "snd-rpi-dac",
193 + .owner = THIS_MODULE,
194 + },
195 + .probe = snd_rpi_rpi_dac_probe,
196 + .remove = snd_rpi_rpi_dac_remove,
197 +};
198 +
199 +module_platform_driver(snd_rpi_rpi_dac_driver);
200 +
201 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
202 +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
203 +MODULE_LICENSE("GPL v2");
204 diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
205 index f0d76ec..4d2569e 100644
206 --- a/sound/soc/codecs/Kconfig
207 +++ b/sound/soc/codecs/Kconfig
208 @@ -59,6 +59,7 @@ config SND_SOC_ALL_CODECS
209 select SND_SOC_PCM1681 if I2C
210 select SND_SOC_PCM1792A if SPI_MASTER
211 select SND_SOC_PCM3008
212 + select SND_SOC_PCM1794A
213 select SND_SOC_PCM5102A
214 select SND_SOC_RT5631 if I2C
215 select SND_SOC_RT5640 if I2C
216 @@ -314,6 +315,9 @@ config SND_SOC_PCM1792A
217 config SND_SOC_PCM3008
218 tristate
219
220 +config SND_SOC_PCM1794A
221 + tristate
222 +
223 config SND_SOC_PCM5102A
224 tristate
225
226 diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
227 index 612f414..9b806a2 100644
228 --- a/sound/soc/codecs/Makefile
229 +++ b/sound/soc/codecs/Makefile
230 @@ -46,6 +46,7 @@ snd-soc-hdmi-codec-objs := hdmi.o
231 snd-soc-pcm1681-objs := pcm1681.o
232 snd-soc-pcm1792a-codec-objs := pcm1792a.o
233 snd-soc-pcm3008-objs := pcm3008.o
234 +snd-soc-pcm1794a-objs := pcm1794a.o
235 snd-soc-pcm5102a-objs := pcm5102a.o
236 snd-soc-rt5631-objs := rt5631.o
237 snd-soc-rt5640-objs := rt5640.o
238 @@ -180,6 +181,7 @@ obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-soc-hdmi-codec.o
239 obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
240 obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
241 obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
242 +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
243 obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
244 obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
245 obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
246 diff --git a/sound/soc/codecs/pcm1794a.c b/sound/soc/codecs/pcm1794a.c
247 new file mode 100644
248 index 0000000..b4eaa44
249 --- /dev/null
250 +++ b/sound/soc/codecs/pcm1794a.c
251 @@ -0,0 +1,62 @@
252 +/*
253 + * Driver for the PCM1794A codec
254 + *
255 + * Author: Florian Meier <florian.meier@koalo.de>
256 + * Copyright 2013
257 + *
258 + * This program is free software; you can redistribute it and/or
259 + * modify it under the terms of the GNU General Public License
260 + * version 2 as published by the Free Software Foundation.
261 + *
262 + * This program is distributed in the hope that it will be useful, but
263 + * WITHOUT ANY WARRANTY; without even the implied warranty of
264 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
265 + * General Public License for more details.
266 + */
267 +
268 +
269 +#include <linux/init.h>
270 +#include <linux/module.h>
271 +#include <linux/platform_device.h>
272 +
273 +#include <sound/soc.h>
274 +
275 +static struct snd_soc_dai_driver pcm1794a_dai = {
276 + .name = "pcm1794a-hifi",
277 + .playback = {
278 + .channels_min = 2,
279 + .channels_max = 2,
280 + .rates = SNDRV_PCM_RATE_8000_192000,
281 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
282 + SNDRV_PCM_FMTBIT_S24_LE
283 + },
284 +};
285 +
286 +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
287 +
288 +static int pcm1794a_probe(struct platform_device *pdev)
289 +{
290 + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
291 + &pcm1794a_dai, 1);
292 +}
293 +
294 +static int pcm1794a_remove(struct platform_device *pdev)
295 +{
296 + snd_soc_unregister_codec(&pdev->dev);
297 + return 0;
298 +}
299 +
300 +static struct platform_driver pcm1794a_codec_driver = {
301 + .probe = pcm1794a_probe,
302 + .remove = pcm1794a_remove,
303 + .driver = {
304 + .name = "pcm1794a-codec",
305 + .owner = THIS_MODULE,
306 + },
307 +};
308 +
309 +module_platform_driver(pcm1794a_codec_driver);
310 +
311 +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
312 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
313 +MODULE_LICENSE("GPL v2");
314 --
315 1.9.1
316