1 From cebfb216daf7118a86d4b07086baedaa4ee298e7 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/171] 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/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
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
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",
34 +static struct platform_device snd_pcm1794a_codec_device = {
35 + .name = "pcm1794a-codec",
41 int __init bcm_register_device(struct platform_device *pdev)
44 @@ -825,6 +839,11 @@ void __init bcm2708_init(void)
45 bcm_register_device_dt(&snd_pcm5102a_codec_device);
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);
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
61 Say Y or M if you want to add support for HifiBerry DAC.
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
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
73 # BCM2708 Machine Support
74 snd-soc-hifiberry-dac-objs := hifiberry_dac.o
75 +snd-soc-rpi-dac-objs := rpi-dac.o
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
80 +++ b/sound/soc/bcm/rpi-dac.c
83 + * ASoC Driver for RPi-DAC.
85 + * Author: Florian Meier <florian.meier@koalo.de>
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.
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.
98 +#include <linux/module.h>
99 +#include <linux/platform_device.h>
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>
107 +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
112 +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
113 + struct snd_pcm_hw_params *params)
115 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
116 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
118 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
121 +/* machine stream operations */
122 +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
123 + .hw_params = snd_rpi_rpi_dac_hw_params,
126 +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
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,
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),
148 +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
152 + snd_rpi_rpi_dac.dev = &pdev->dev;
153 + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
155 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
160 +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
162 + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
165 +static struct platform_driver snd_rpi_rpi_dac_driver = {
167 + .name = "snd-rpi-dac",
168 + .owner = THIS_MODULE,
170 + .probe = snd_rpi_rpi_dac_probe,
171 + .remove = snd_rpi_rpi_dac_remove,
174 +module_platform_driver(snd_rpi_rpi_dac_driver);
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
193 +config SND_SOC_PCM1794A
196 config SND_SOC_PCM5102A
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
218 +++ b/sound/soc/codecs/pcm1794a.c
221 + * Driver for the PCM1794A codec
223 + * Author: Florian Meier <florian.meier@koalo.de>
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.
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.
237 +#include <linux/init.h>
238 +#include <linux/module.h>
239 +#include <linux/platform_device.h>
241 +#include <sound/soc.h>
243 +static struct snd_soc_dai_driver pcm1794a_dai = {
244 + .name = "pcm1794a-hifi",
248 + .rates = SNDRV_PCM_RATE_8000_192000,
249 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
250 + SNDRV_PCM_FMTBIT_S24_LE
254 +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
256 +static int pcm1794a_probe(struct platform_device *pdev)
258 + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
262 +static int pcm1794a_remove(struct platform_device *pdev)
264 + snd_soc_unregister_codec(&pdev->dev);
268 +static struct platform_driver pcm1794a_codec_driver = {
269 + .probe = pcm1794a_probe,
270 + .remove = pcm1794a_remove,
272 + .name = "pcm1794a-codec",
273 + .owner = THIS_MODULE,
277 +module_platform_driver(pcm1794a_codec_driver);
279 +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
280 +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
281 +MODULE_LICENSE("GPL v2");