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