1 From 52fceff596533a847231d1f9b8ea13d4e6ee829b 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 036/114] ASoC: BCM2708: Add support for RPi-DAC
6 This adds a machine driver for the RPi-DAC.
8 Signed-off-by: Florian Meier <florian.meier@koalo.de>
10 arch/arm/configs/bcmrpi_defconfig | 1 +
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, 194 insertions(+)
19 create mode 100644 sound/soc/bcm/rpi-dac.c
20 create mode 100644 sound/soc/codecs/pcm1794a.c
22 diff --git a/arch/arm/configs/bcmrpi_defconfig b/arch/arm/configs/bcmrpi_defconfig
23 index dfd98df..f688da5 100644
24 --- a/arch/arm/configs/bcmrpi_defconfig
25 +++ b/arch/arm/configs/bcmrpi_defconfig
26 @@ -756,6 +756,7 @@ CONFIG_SND_USB_6FIRE=m
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_SIMPLE_CARD=m
34 diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
35 index 50d4991..100c223 100644
36 --- a/arch/arm/mach-bcm2708/bcm2708.c
37 +++ b/arch/arm/mach-bcm2708/bcm2708.c
38 @@ -623,6 +623,20 @@ static struct platform_device snd_pcm5102a_codec_device = {
42 +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
43 +static struct platform_device snd_rpi_dac_device = {
44 + .name = "snd-rpi-dac",
49 +static struct platform_device snd_pcm1794a_codec_device = {
50 + .name = "pcm1794a-codec",
56 int __init bcm_register_device(struct platform_device *pdev)
59 @@ -752,6 +766,11 @@ void __init bcm2708_init(void)
60 bcm_register_device(&snd_pcm5102a_codec_device);
63 +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
64 + bcm_register_device(&snd_rpi_dac_device);
65 + bcm_register_device(&snd_pcm1794a_codec_device);
68 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
69 struct amba_device *d = amba_devs[i];
70 amba_device_register(d, &iomem_resource);
71 diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig
72 index b36a62f..714841d 100644
73 --- a/sound/soc/bcm/Kconfig
74 +++ b/sound/soc/bcm/Kconfig
75 @@ -25,3 +25,10 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
76 select SND_SOC_PCM5102A
78 Say Y or M if you want to add support for HifiBerry DAC.
80 +config SND_BCM2708_SOC_RPI_DAC
81 + tristate "Support for RPi-DAC"
82 + depends on SND_BCM2708_SOC_I2S
83 + select SND_SOC_PCM1794A
85 + Say Y or M if you want to add support for RPi-DAC.
86 diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile
87 index be90a49cb..ccc9809 100644
88 --- a/sound/soc/bcm/Makefile
89 +++ b/sound/soc/bcm/Makefile
90 @@ -10,5 +10,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
92 # BCM2708 Machine Support
93 snd-soc-hifiberry-dac-objs := hifiberry_dac.o
94 +snd-soc-rpi-dac-objs := rpi-dac.o
96 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
97 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
98 diff --git a/sound/soc/bcm/rpi-dac.c b/sound/soc/bcm/rpi-dac.c
100 index 0000000..6d6e0ba
102 +++ b/sound/soc/bcm/rpi-dac.c
105 + * ASoC Driver for RPi-DAC.
107 + * Author: Florian Meier <florian.meier@koalo.de>
110 + * This program is free software; you can redistribute it and/or
111 + * modify it under the terms of the GNU General Public License
112 + * version 2 as published by the Free Software Foundation.
114 + * This program is distributed in the hope that it will be useful, but
115 + * WITHOUT ANY WARRANTY; without even the implied warranty of
116 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
117 + * General Public License for more details.
120 +#include <linux/module.h>
121 +#include <linux/platform_device.h>
123 +#include <sound/core.h>
124 +#include <sound/pcm.h>
125 +#include <sound/pcm_params.h>
126 +#include <sound/soc.h>
127 +#include <sound/jack.h>
129 +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
134 +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
135 + struct snd_pcm_hw_params *params)
137 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
138 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
140 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
143 +/* machine stream operations */
144 +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
145 + .hw_params = snd_rpi_rpi_dac_hw_params,
148 +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
151 + .stream_name = "RPi-DAC HiFi",
152 + .cpu_dai_name = "bcm2708-i2s.0",
153 + .codec_dai_name = "pcm1794a-hifi",
154 + .platform_name = "bcm2708-i2s.0",
155 + .codec_name = "pcm1794a-codec",
156 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
157 + SND_SOC_DAIFMT_CBS_CFS,
158 + .ops = &snd_rpi_rpi_dac_ops,
159 + .init = snd_rpi_rpi_dac_init,
163 +/* audio machine driver */
164 +static struct snd_soc_card snd_rpi_rpi_dac = {
165 + .name = "snd_rpi_rpi_dac",
166 + .dai_link = snd_rpi_rpi_dac_dai,
167 + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
170 +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
174 + snd_rpi_rpi_dac.dev = &pdev->dev;
175 + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
177 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
182 +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
184 + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
187 +static struct platform_driver snd_rpi_rpi_dac_driver = {
189 + .name = "snd-rpi-dac",
190 + .owner = THIS_MODULE,
192 + .probe = snd_rpi_rpi_dac_probe,
193 + .remove = snd_rpi_rpi_dac_remove,
196 +module_platform_driver(snd_rpi_rpi_dac_driver);
198 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
199 +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
200 +MODULE_LICENSE("GPL v2");
201 diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
202 index 0ef8bb7..3c236a6 100644
203 --- a/sound/soc/codecs/Kconfig
204 +++ b/sound/soc/codecs/Kconfig
205 @@ -81,6 +81,7 @@ config SND_SOC_ALL_CODECS
206 select SND_SOC_PCM512x_SPI if SPI_MASTER
207 select SND_SOC_RT286 if I2C
208 select SND_SOC_PCM5102A if I2C
209 + select SND_SOC_PCM1794A if I2C
210 select SND_SOC_RT5631 if I2C
211 select SND_SOC_RT5640 if I2C
212 select SND_SOC_RT5645 if I2C
213 @@ -487,6 +488,9 @@ config SND_SOC_RT286
217 +config SND_SOC_PCM1794A
220 config SND_SOC_PCM5102A
223 diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
224 index 7b606e6..2a7f823 100644
225 --- a/sound/soc/codecs/Makefile
226 +++ b/sound/soc/codecs/Makefile
227 @@ -74,6 +74,7 @@ snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o
228 snd-soc-pcm512x-spi-objs := pcm512x-spi.o
229 snd-soc-rl6231-objs := rl6231.o
230 snd-soc-rt286-objs := rt286.o
231 +snd-soc-pcm1794a-objs := pcm1794a.o
232 snd-soc-pcm5102a-objs := pcm5102a.o
233 snd-soc-rt5631-objs := rt5631.o
234 snd-soc-rt5640-objs := rt5640.o
235 @@ -251,6 +252,7 @@ obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o
236 obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
237 obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o
238 obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o
239 +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
240 obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
241 obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
242 obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
243 diff --git a/sound/soc/codecs/pcm1794a.c b/sound/soc/codecs/pcm1794a.c
245 index 0000000..b4eaa44
247 +++ b/sound/soc/codecs/pcm1794a.c
250 + * Driver for the PCM1794A codec
252 + * Author: Florian Meier <florian.meier@koalo.de>
255 + * This program is free software; you can redistribute it and/or
256 + * modify it under the terms of the GNU General Public License
257 + * version 2 as published by the Free Software Foundation.
259 + * This program is distributed in the hope that it will be useful, but
260 + * WITHOUT ANY WARRANTY; without even the implied warranty of
261 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
262 + * General Public License for more details.
266 +#include <linux/init.h>
267 +#include <linux/module.h>
268 +#include <linux/platform_device.h>
270 +#include <sound/soc.h>
272 +static struct snd_soc_dai_driver pcm1794a_dai = {
273 + .name = "pcm1794a-hifi",
277 + .rates = SNDRV_PCM_RATE_8000_192000,
278 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
279 + SNDRV_PCM_FMTBIT_S24_LE
283 +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
285 +static int pcm1794a_probe(struct platform_device *pdev)
287 + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
291 +static int pcm1794a_remove(struct platform_device *pdev)
293 + snd_soc_unregister_codec(&pdev->dev);
297 +static struct platform_driver pcm1794a_codec_driver = {
298 + .probe = pcm1794a_probe,
299 + .remove = pcm1794a_remove,
301 + .name = "pcm1794a-codec",
302 + .owner = THIS_MODULE,
306 +module_platform_driver(pcm1794a_codec_driver);
308 +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
309 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
310 +MODULE_LICENSE("GPL v2");