Skip to content

Commit 23b8bb3

Browse files
DigitalDreamtimepopcornmix
authored andcommitted
Add support for Dion Audio LOCO DAC-AMP HAT
Using dedicated machine driver and pcm5102a codec driver. Signed-off-by: DigitalDreamtime <[email protected]>
1 parent ae4d940 commit 23b8bb3

File tree

3 files changed

+130
-1
lines changed

3 files changed

+130
-1
lines changed

sound/soc/bcm/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,10 @@ config SND_DIGIDAC1_SOUNDCARD
109109
select SND_SOC_WM8741
110110
help
111111
Say Y or M if you want to add support for Red Rocks Audio DigiDAC1 board.
112+
113+
config SND_BCM2708_SOC_DIONAUDIO_LOCO
114+
tristate "Support for Dion Audio LOCO DAC-AMP"
115+
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
116+
select SND_SOC_PCM5102a
117+
help
118+
Say Y or M if you want to add support for Dion Audio LOCO.

sound/soc/bcm/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ snd-soc-iqaudio-digi-objs := iqaudio_digi.o
2222
snd-soc-raspidac3-objs := raspidac3.o
2323
snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
2424
snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
25+
snd-soc-dionaudio-loco-objs := dionaudio_loco.o
2526

2627
obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
2728
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
@@ -36,4 +37,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI) += snd-soc-iqaudio-digi.o
3637
obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
3738
obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
3839
obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
39-
40+
obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o

sound/soc/bcm/dionaudio_loco.c

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* ASoC Driver for Dion Audio LOCO DAC-AMP
3+
*
4+
* Author: Miquel Blauw <[email protected]>
5+
* Copyright 2016
6+
*
7+
* Based on the software of the RPi-DAC writen by Florian Meier
8+
*
9+
* This program is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU General Public License
11+
* version 2 as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful, but
14+
* WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* General Public License for more details.
17+
*/
18+
19+
#include <linux/module.h>
20+
#include <linux/platform_device.h>
21+
22+
#include <sound/core.h>
23+
#include <sound/pcm.h>
24+
#include <sound/pcm_params.h>
25+
#include <sound/soc.h>
26+
#include <sound/jack.h>
27+
28+
static int snd_rpi_dionaudio_loco_hw_params(
29+
struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
30+
{
31+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
32+
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
33+
34+
unsigned int sample_bits =
35+
snd_pcm_format_physical_width(params_format(params));
36+
37+
return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
38+
}
39+
40+
/* machine stream operations */
41+
static struct snd_soc_ops snd_rpi_dionaudio_loco_ops = {
42+
.hw_params = snd_rpi_dionaudio_loco_hw_params,
43+
};
44+
45+
static struct snd_soc_dai_link snd_rpi_dionaudio_loco_dai[] = {
46+
{
47+
.name = "DionAudio LOCO",
48+
.stream_name = "DionAudio LOCO DAC-AMP",
49+
.cpu_dai_name = "bcm2708-i2s.0",
50+
.codec_dai_name = "pcm5102a-hifi",
51+
.platform_name = "bcm2708-i2s.0",
52+
.codec_name = "pcm5102a-codec",
53+
.dai_fmt = SND_SOC_DAIFMT_I2S |
54+
SND_SOC_DAIFMT_NB_NF |
55+
SND_SOC_DAIFMT_CBS_CFS,
56+
.ops = &snd_rpi_dionaudio_loco_ops,
57+
},
58+
};
59+
60+
/* audio machine driver */
61+
static struct snd_soc_card snd_rpi_dionaudio_loco = {
62+
.name = "snd_rpi_dionaudio_loco",
63+
.dai_link = snd_rpi_dionaudio_loco_dai,
64+
.num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_dai),
65+
};
66+
67+
static int snd_rpi_dionaudio_loco_probe(struct platform_device *pdev)
68+
{
69+
struct device_node *np;
70+
int ret = 0;
71+
72+
snd_rpi_dionaudio_loco.dev = &pdev->dev;
73+
74+
np = pdev->dev.of_node;
75+
if (np) {
76+
struct snd_soc_dai_link *dai = &snd_rpi_dionaudio_loco_dai[0];
77+
struct device_node *i2s_np;
78+
79+
i2s_np = of_parse_phandle(np, "i2s-controller", 0);
80+
if (i2s_np) {
81+
dai->cpu_dai_name = NULL;
82+
dai->cpu_of_node = i2s_np;
83+
dai->platform_name = NULL;
84+
dai->platform_of_node = i2s_np;
85+
}
86+
}
87+
88+
ret = snd_soc_register_card(&snd_rpi_dionaudio_loco);
89+
if (ret)
90+
dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
91+
ret);
92+
93+
return ret;
94+
}
95+
96+
static int snd_rpi_dionaudio_loco_remove(struct platform_device *pdev)
97+
{
98+
return snd_soc_unregister_card(&snd_rpi_dionaudio_loco);
99+
}
100+
101+
static const struct of_device_id snd_rpi_dionaudio_loco_of_match[] = {
102+
{ .compatible = "dionaudio,loco-pcm5242-tpa3118", },
103+
{ /* sentinel */ },
104+
};
105+
MODULE_DEVICE_TABLE(of, snd_rpi_dionaudio_loco_of_match);
106+
107+
static struct platform_driver snd_rpi_dionaudio_loco_driver = {
108+
.driver = {
109+
.name = "snd-dionaudio-loco",
110+
.owner = THIS_MODULE,
111+
.of_match_table = snd_rpi_dionaudio_loco_of_match,
112+
},
113+
.probe = snd_rpi_dionaudio_loco_probe,
114+
.remove = snd_rpi_dionaudio_loco_remove,
115+
};
116+
117+
module_platform_driver(snd_rpi_dionaudio_loco_driver);
118+
119+
MODULE_AUTHOR("Miquel Blauw <[email protected]>");
120+
MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO");
121+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)