1 From 01eedb8b865d19d9cd00799a6e657b0e00b26b2d Mon Sep 17 00:00:00 2001
2 From: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
3 Date: Sat, 2 Jul 2016 16:26:19 +0100
4 Subject: [PATCH] Add support for Dion Audio LOCO DAC-AMP HAT
6 Using dedicated machine driver and pcm5102a codec driver.
8 Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
10 arch/arm/boot/dts/overlays/Makefile | 1 +
11 arch/arm/boot/dts/overlays/README | 6 +
12 .../boot/dts/overlays/dionaudio-loco-overlay.dts | 39 +++++++
13 arch/arm/configs/bcm2709_defconfig | 1 +
14 arch/arm/configs/bcmrpi_defconfig | 1 +
15 sound/soc/bcm/Kconfig | 7 ++
16 sound/soc/bcm/Makefile | 3 +-
17 sound/soc/bcm/dionaudio_loco.c | 121 +++++++++++++++++++++
18 8 files changed, 178 insertions(+), 1 deletion(-)
19 create mode 100644 arch/arm/boot/dts/overlays/dionaudio-loco-overlay.dts
20 create mode 100644 sound/soc/bcm/dionaudio_loco.c
22 --- a/arch/arm/boot/dts/overlays/Makefile
23 +++ b/arch/arm/boot/dts/overlays/Makefile
24 @@ -20,6 +20,7 @@ dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtb
25 dtbo-$(RPI_DT_OVERLAYS) += audioinjector-wm8731-audio.dtbo
26 dtbo-$(RPI_DT_OVERLAYS) += bmp085_i2c-sensor.dtbo
27 dtbo-$(RPI_DT_OVERLAYS) += dht11.dtbo
28 +dtbo-$(RPI_DT_OVERLAYS) += dionaudio-loco.dtbo
29 dtbo-$(RPI_DT_OVERLAYS) += dpi24.dtbo
30 dtbo-$(RPI_DT_OVERLAYS) += dwc-otg.dtbo
31 dtbo-$(RPI_DT_OVERLAYS) += dwc2.dtbo
32 --- a/arch/arm/boot/dts/overlays/README
33 +++ b/arch/arm/boot/dts/overlays/README
34 @@ -268,6 +268,12 @@ Params: gpiopin GPIO con
39 +Info: Configures the Dion Audio LOCO DAC-AMP
40 +Load: dtoverlay=dionaudio-loco
45 Info: Overlay for a generic 24-bit DPI display
46 This uses GPIOs 0-27 (so no I2C, uart etc.), and activates the output
48 +++ b/arch/arm/boot/dts/overlays/dionaudio-loco-overlay.dts
50 +// Definitions for Dion Audio LOCO DAC-AMP
53 + * PCM5242 DAC (in hardware mode) and TPA3118 AMP.
60 + compatible = "brcm,bcm2708";
73 + #sound-dai-cells = <0>;
74 + compatible = "ti,pcm5102a";
83 + compatible = "dionaudio,loco-pcm5242-tpa3118";
84 + i2s-controller = <&i2s>;
89 --- a/arch/arm/configs/bcm2709_defconfig
90 +++ b/arch/arm/configs/bcm2709_defconfig
91 @@ -870,6 +870,7 @@ CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
92 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
93 CONFIG_SND_DIGIDAC1_SOUNDCARD=m
94 CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
95 +CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
96 CONFIG_SND_SOC_ADAU1701=m
97 CONFIG_SND_SOC_WM8804_I2C=m
98 CONFIG_SND_SIMPLE_CARD=m
99 --- a/arch/arm/configs/bcmrpi_defconfig
100 +++ b/arch/arm/configs/bcmrpi_defconfig
101 @@ -862,6 +862,7 @@ CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
102 CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
103 CONFIG_SND_DIGIDAC1_SOUNDCARD=m
104 CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
105 +CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
106 CONFIG_SND_SOC_ADAU1701=m
107 CONFIG_SND_SOC_WM8804_I2C=m
108 CONFIG_SND_SIMPLE_CARD=m
109 --- a/sound/soc/bcm/Kconfig
110 +++ b/sound/soc/bcm/Kconfig
111 @@ -107,3 +107,10 @@ config SND_DIGIDAC1_SOUNDCARD
112 select SND_SOC_WM8741
114 Say Y or M if you want to add support for Red Rocks Audio DigiDAC1 board.
116 +config SND_BCM2708_SOC_DIONAUDIO_LOCO
117 + tristate "Support for Dion Audio LOCO DAC-AMP"
118 + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
119 + select SND_SOC_PCM5102a
121 + Say Y or M if you want to add support for Dion Audio LOCO.
122 --- a/sound/soc/bcm/Makefile
123 +++ b/sound/soc/bcm/Makefile
124 @@ -18,6 +18,7 @@ snd-soc-iqaudio-digi-objs := iqaudio_dig
125 snd-soc-raspidac3-objs := raspidac3.o
126 snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
127 snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
128 +snd-soc-dionaudio-loco-objs := dionaudio_loco.o
130 obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
131 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
132 @@ -33,4 +34,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DIG
133 obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
134 obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
135 obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
137 +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
139 +++ b/sound/soc/bcm/dionaudio_loco.c
142 + * ASoC Driver for Dion Audio LOCO DAC-AMP
144 + * Author: Miquel Blauw <info@dionaudio.nl>
147 + * Based on the software of the RPi-DAC writen by Florian Meier
149 + * This program is free software; you can redistribute it and/or
150 + * modify it under the terms of the GNU General Public License
151 + * version 2 as published by the Free Software Foundation.
153 + * This program is distributed in the hope that it will be useful, but
154 + * WITHOUT ANY WARRANTY; without even the implied warranty of
155 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
156 + * General Public License for more details.
159 +#include <linux/module.h>
160 +#include <linux/platform_device.h>
162 +#include <sound/core.h>
163 +#include <sound/pcm.h>
164 +#include <sound/pcm_params.h>
165 +#include <sound/soc.h>
166 +#include <sound/jack.h>
168 +static int snd_rpi_dionaudio_loco_hw_params(
169 + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
171 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
172 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
174 + unsigned int sample_bits =
175 + snd_pcm_format_physical_width(params_format(params));
177 + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
180 +/* machine stream operations */
181 +static struct snd_soc_ops snd_rpi_dionaudio_loco_ops = {
182 + .hw_params = snd_rpi_dionaudio_loco_hw_params,
185 +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_dai[] = {
187 + .name = "DionAudio LOCO",
188 + .stream_name = "DionAudio LOCO DAC-AMP",
189 + .cpu_dai_name = "bcm2708-i2s.0",
190 + .codec_dai_name = "pcm5102a-hifi",
191 + .platform_name = "bcm2708-i2s.0",
192 + .codec_name = "pcm5102a-codec",
193 + .dai_fmt = SND_SOC_DAIFMT_I2S |
194 + SND_SOC_DAIFMT_NB_NF |
195 + SND_SOC_DAIFMT_CBS_CFS,
196 + .ops = &snd_rpi_dionaudio_loco_ops,
200 +/* audio machine driver */
201 +static struct snd_soc_card snd_rpi_dionaudio_loco = {
202 + .name = "snd_rpi_dionaudio_loco",
203 + .dai_link = snd_rpi_dionaudio_loco_dai,
204 + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_dai),
207 +static int snd_rpi_dionaudio_loco_probe(struct platform_device *pdev)
209 + struct device_node *np;
212 + snd_rpi_dionaudio_loco.dev = &pdev->dev;
214 + np = pdev->dev.of_node;
216 + struct snd_soc_dai_link *dai = &snd_rpi_dionaudio_loco_dai[0];
217 + struct device_node *i2s_np;
219 + i2s_np = of_parse_phandle(np, "i2s-controller", 0);
221 + dai->cpu_dai_name = NULL;
222 + dai->cpu_of_node = i2s_np;
223 + dai->platform_name = NULL;
224 + dai->platform_of_node = i2s_np;
228 + ret = snd_soc_register_card(&snd_rpi_dionaudio_loco);
230 + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
236 +static int snd_rpi_dionaudio_loco_remove(struct platform_device *pdev)
238 + return snd_soc_unregister_card(&snd_rpi_dionaudio_loco);
241 +static const struct of_device_id snd_rpi_dionaudio_loco_of_match[] = {
242 + { .compatible = "dionaudio,loco-pcm5242-tpa3118", },
243 + { /* sentinel */ },
245 +MODULE_DEVICE_TABLE(of, snd_rpi_dionaudio_loco_of_match);
247 +static struct platform_driver snd_rpi_dionaudio_loco_driver = {
249 + .name = "snd-dionaudio-loco",
250 + .owner = THIS_MODULE,
251 + .of_match_table = snd_rpi_dionaudio_loco_of_match,
253 + .probe = snd_rpi_dionaudio_loco_probe,
254 + .remove = snd_rpi_dionaudio_loco_remove,
257 +module_platform_driver(snd_rpi_dionaudio_loco_driver);
259 +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
260 +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO");
261 +MODULE_LICENSE("GPL v2");