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