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
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 | 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
22 --- a/arch/arm/configs/bcmrpi_defconfig
23 +++ b/arch/arm/configs/bcmrpi_defconfig
24 @@ -744,8 +744,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
35 --- a/arch/arm/mach-bcm2708/bcm2708.c
36 +++ b/arch/arm/mach-bcm2708/bcm2708.c
37 @@ -651,6 +651,20 @@ static struct platform_device snd_pcm510
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",
48 +static struct platform_device snd_pcm1794a_codec_device = {
49 + .name = "pcm1794a-codec",
55 int __init bcm_register_device(struct platform_device *pdev)
58 @@ -783,6 +797,11 @@ void __init bcm2708_init(void)
59 bcm_register_device(&snd_pcm5102a_codec_device);
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);
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 @@ -25,3 +25,10 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
73 select SND_SOC_PCM5102A
75 Say Y or M if you want to add support for HifiBerry DAC.
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
82 + Say Y or M if you want to add support for RPi-DAC.
83 --- a/sound/soc/bcm/Makefile
84 +++ b/sound/soc/bcm/Makefile
85 @@ -10,5 +10,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd
87 # BCM2708 Machine Support
88 snd-soc-hifiberry-dac-objs := hifiberry_dac.o
89 +snd-soc-rpi-dac-objs := rpi-dac.o
91 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
92 +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
94 +++ b/sound/soc/bcm/rpi-dac.c
97 + * ASoC Driver for RPi-DAC.
99 + * Author: Florian Meier <florian.meier@koalo.de>
102 + * This program is free software; you can redistribute it and/or
103 + * modify it under the terms of the GNU General Public License
104 + * version 2 as published by the Free Software Foundation.
106 + * This program is distributed in the hope that it will be useful, but
107 + * WITHOUT ANY WARRANTY; without even the implied warranty of
108 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
109 + * General Public License for more details.
112 +#include <linux/module.h>
113 +#include <linux/platform_device.h>
115 +#include <sound/core.h>
116 +#include <sound/pcm.h>
117 +#include <sound/pcm_params.h>
118 +#include <sound/soc.h>
119 +#include <sound/jack.h>
121 +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
126 +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
127 + struct snd_pcm_hw_params *params)
129 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
130 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
132 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
135 +/* machine stream operations */
136 +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
137 + .hw_params = snd_rpi_rpi_dac_hw_params,
140 +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
142 + .name = "HifiBerry Mini",
143 + .stream_name = "HifiBerry Mini HiFi",
144 + .cpu_dai_name = "bcm2708-i2s.0",
145 + .codec_dai_name = "pcm1794a-hifi",
146 + .platform_name = "bcm2708-i2s.0",
147 + .codec_name = "pcm1794a-codec",
148 + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
149 + SND_SOC_DAIFMT_CBS_CFS,
150 + .ops = &snd_rpi_rpi_dac_ops,
151 + .init = snd_rpi_rpi_dac_init,
155 +/* audio machine driver */
156 +static struct snd_soc_card snd_rpi_rpi_dac = {
157 + .name = "snd_rpi_rpi_dac",
158 + .dai_link = snd_rpi_rpi_dac_dai,
159 + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
162 +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
166 + snd_rpi_rpi_dac.dev = &pdev->dev;
167 + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
169 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
174 +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
176 + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
179 +static struct platform_driver snd_rpi_rpi_dac_driver = {
181 + .name = "snd-rpi-dac",
182 + .owner = THIS_MODULE,
184 + .probe = snd_rpi_rpi_dac_probe,
185 + .remove = snd_rpi_rpi_dac_remove,
188 +module_platform_driver(snd_rpi_rpi_dac_driver);
190 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
191 +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
192 +MODULE_LICENSE("GPL v2");
193 --- a/sound/soc/codecs/Kconfig
194 +++ b/sound/soc/codecs/Kconfig
195 @@ -59,6 +59,7 @@ config SND_SOC_ALL_CODECS
196 select SND_SOC_PCM1681 if I2C
197 select SND_SOC_PCM1792A if SPI_MASTER
198 select SND_SOC_PCM3008
199 + select SND_SOC_PCM1794A
200 select SND_SOC_PCM5102A
201 select SND_SOC_RT5631 if I2C
202 select SND_SOC_RT5640 if I2C
203 @@ -314,6 +315,9 @@ config SND_SOC_PCM1792A
204 config SND_SOC_PCM3008
207 +config SND_SOC_PCM1794A
210 config SND_SOC_PCM5102A
213 --- a/sound/soc/codecs/Makefile
214 +++ b/sound/soc/codecs/Makefile
215 @@ -46,6 +46,7 @@ snd-soc-hdmi-codec-objs := hdmi.o
216 snd-soc-pcm1681-objs := pcm1681.o
217 snd-soc-pcm1792a-codec-objs := pcm1792a.o
218 snd-soc-pcm3008-objs := pcm3008.o
219 +snd-soc-pcm1794a-objs := pcm1794a.o
220 snd-soc-pcm5102a-objs := pcm5102a.o
221 snd-soc-rt5631-objs := rt5631.o
222 snd-soc-rt5640-objs := rt5640.o
223 @@ -180,6 +181,7 @@ obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-
224 obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
225 obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
226 obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
227 +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
228 obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
229 obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
230 obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
232 +++ b/sound/soc/codecs/pcm1794a.c
235 + * Driver for the PCM1794A codec
237 + * Author: Florian Meier <florian.meier@koalo.de>
240 + * This program is free software; you can redistribute it and/or
241 + * modify it under the terms of the GNU General Public License
242 + * version 2 as published by the Free Software Foundation.
244 + * This program is distributed in the hope that it will be useful, but
245 + * WITHOUT ANY WARRANTY; without even the implied warranty of
246 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
247 + * General Public License for more details.
251 +#include <linux/init.h>
252 +#include <linux/module.h>
253 +#include <linux/platform_device.h>
255 +#include <sound/soc.h>
257 +static struct snd_soc_dai_driver pcm1794a_dai = {
258 + .name = "pcm1794a-hifi",
262 + .rates = SNDRV_PCM_RATE_8000_192000,
263 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
264 + SNDRV_PCM_FMTBIT_S24_LE
268 +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
270 +static int pcm1794a_probe(struct platform_device *pdev)
272 + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
276 +static int pcm1794a_remove(struct platform_device *pdev)
278 + snd_soc_unregister_codec(&pdev->dev);
282 +static struct platform_driver pcm1794a_codec_driver = {
283 + .probe = pcm1794a_probe,
284 + .remove = pcm1794a_remove,
286 + .name = "pcm1794a-codec",
287 + .owner = THIS_MODULE,
291 +module_platform_driver(pcm1794a_codec_driver);
293 +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
294 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
295 +MODULE_LICENSE("GPL v2");