Skip to content

Commit 7b658f5

Browse files
koalopopcornmix
authored andcommitted
ASoC: BCM2708: Add support for RPi-DAC
This adds a machine driver for the RPi-DAC. Signed-off-by: Florian Meier <[email protected]>
1 parent 937016e commit 7b658f5

File tree

8 files changed

+195
-0
lines changed

8 files changed

+195
-0
lines changed

arch/arm/configs/bcmrpi_defconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,10 @@ CONFIG_SND_SOC_DMAENGINE_PCM=y
738738
CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
739739
CONFIG_SND_BCM2708_SOC_I2S=m
740740
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
741+
CONFIG_SND_BCM2708_SOC_RPI_DAC=m
741742
CONFIG_SND_SOC_I2C_AND_SPI=m
742743
CONFIG_SND_SOC_PCM5102A=m
744+
CONFIG_SND_SOC_PCM1794A=m
743745
CONFIG_SOUND_PRIME=m
744746
CONFIG_HIDRAW=y
745747
CONFIG_HID_A4TECH=m

arch/arm/mach-bcm2708/bcm2708.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,20 @@ static struct platform_device snd_pcm5102a_codec_device = {
653653
};
654654
#endif
655655

656+
#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
657+
static struct platform_device snd_rpi_dac_device = {
658+
.name = "snd-rpi-dac",
659+
.id = 0,
660+
.num_resources = 0,
661+
};
662+
663+
static struct platform_device snd_pcm1794a_codec_device = {
664+
.name = "pcm1794a-codec",
665+
.id = -1,
666+
.num_resources = 0,
667+
};
668+
#endif
669+
656670
int __init bcm_register_device(struct platform_device *pdev)
657671
{
658672
int ret;
@@ -788,6 +802,11 @@ void __init bcm2708_init(void)
788802
bcm_register_device(&snd_pcm5102a_codec_device);
789803
#endif
790804

805+
#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
806+
bcm_register_device(&snd_rpi_dac_device);
807+
bcm_register_device(&snd_pcm1794a_codec_device);
808+
#endif
809+
791810
for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
792811
struct amba_device *d = amba_devs[i];
793812
amba_device_register(d, &iomem_resource);

sound/soc/bcm/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
1515
select SND_SOC_PCM5102A
1616
help
1717
Say Y or M if you want to add support for HifiBerry DAC.
18+
19+
config SND_BCM2708_SOC_RPI_DAC
20+
tristate "Support for RPi-DAC"
21+
depends on SND_BCM2708_SOC_I2S
22+
select SND_SOC_PCM1794A
23+
help
24+
Say Y or M if you want to add support for RPi-DAC.

sound/soc/bcm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
55

66
# BCM2708 Machine Support
77
snd-soc-hifiberry-dac-objs := hifiberry_dac.o
8+
snd-soc-rpi-dac-objs := rpi-dac.o
89

910
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
11+
obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o

sound/soc/bcm/rpi-dac.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* ASoC Driver for RPi-DAC.
3+
*
4+
* Author: Florian Meier <[email protected]>
5+
* Copyright 2013
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* version 2 as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* General Public License for more details.
15+
*/
16+
17+
#include <linux/module.h>
18+
#include <linux/platform_device.h>
19+
20+
#include <sound/core.h>
21+
#include <sound/pcm.h>
22+
#include <sound/pcm_params.h>
23+
#include <sound/soc.h>
24+
#include <sound/jack.h>
25+
26+
static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
27+
{
28+
return 0;
29+
}
30+
31+
static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
32+
struct snd_pcm_hw_params *params)
33+
{
34+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
35+
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
36+
37+
return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
38+
}
39+
40+
/* machine stream operations */
41+
static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
42+
.hw_params = snd_rpi_rpi_dac_hw_params,
43+
};
44+
45+
static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
46+
{
47+
.name = "HifiBerry Mini",
48+
.stream_name = "HifiBerry Mini HiFi",
49+
.cpu_dai_name = "bcm2708-i2s.0",
50+
.codec_dai_name = "pcm1794a-hifi",
51+
.platform_name = "bcm2708-i2s.0",
52+
.codec_name = "pcm1794a-codec",
53+
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
54+
SND_SOC_DAIFMT_CBS_CFS,
55+
.ops = &snd_rpi_rpi_dac_ops,
56+
.init = snd_rpi_rpi_dac_init,
57+
},
58+
};
59+
60+
/* audio machine driver */
61+
static struct snd_soc_card snd_rpi_rpi_dac = {
62+
.name = "snd_rpi_rpi_dac",
63+
.dai_link = snd_rpi_rpi_dac_dai,
64+
.num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
65+
};
66+
67+
static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
68+
{
69+
int ret = 0;
70+
71+
snd_rpi_rpi_dac.dev = &pdev->dev;
72+
ret = snd_soc_register_card(&snd_rpi_rpi_dac);
73+
if (ret)
74+
dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
75+
76+
return ret;
77+
}
78+
79+
static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
80+
{
81+
return snd_soc_unregister_card(&snd_rpi_rpi_dac);
82+
}
83+
84+
static struct platform_driver snd_rpi_rpi_dac_driver = {
85+
.driver = {
86+
.name = "snd-rpi-dac",
87+
.owner = THIS_MODULE,
88+
},
89+
.probe = snd_rpi_rpi_dac_probe,
90+
.remove = snd_rpi_rpi_dac_remove,
91+
};
92+
93+
module_platform_driver(snd_rpi_rpi_dac_driver);
94+
95+
MODULE_AUTHOR("Florian Meier <[email protected]>");
96+
MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
97+
MODULE_LICENSE("GPL v2");

sound/soc/codecs/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ config SND_SOC_ALL_CODECS
5959
select SND_SOC_PCM1681 if I2C
6060
select SND_SOC_PCM1792A if SPI_MASTER
6161
select SND_SOC_PCM3008
62+
select SND_SOC_PCM1794A
6263
select SND_SOC_PCM5102A
6364
select SND_SOC_RT5631 if I2C
6465
select SND_SOC_RT5640 if I2C
@@ -312,6 +313,9 @@ config SND_SOC_PCM1792A
312313
config SND_SOC_PCM3008
313314
tristate
314315

316+
config SND_SOC_PCM1794A
317+
tristate
318+
315319
config SND_SOC_PCM5102A
316320
tristate
317321

sound/soc/codecs/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ snd-soc-hdmi-codec-objs := hdmi.o
4646
snd-soc-pcm1681-objs := pcm1681.o
4747
snd-soc-pcm1792a-codec-objs := pcm1792a.o
4848
snd-soc-pcm3008-objs := pcm3008.o
49+
snd-soc-pcm1794a-objs := pcm1794a.o
4950
snd-soc-pcm5102a-objs := pcm5102a.o
5051
snd-soc-rt5631-objs := rt5631.o
5152
snd-soc-rt5640-objs := rt5640.o
@@ -180,6 +181,7 @@ obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-soc-hdmi-codec.o
180181
obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
181182
obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
182183
obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
184+
obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
183185
obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
184186
obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
185187
obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o

sound/soc/codecs/pcm1794a.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Driver for the PCM1794A codec
3+
*
4+
* Author: Florian Meier <[email protected]>
5+
* Copyright 2013
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* version 2 as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* General Public License for more details.
15+
*/
16+
17+
18+
#include <linux/init.h>
19+
#include <linux/module.h>
20+
#include <linux/platform_device.h>
21+
22+
#include <sound/soc.h>
23+
24+
static struct snd_soc_dai_driver pcm1794a_dai = {
25+
.name = "pcm1794a-hifi",
26+
.playback = {
27+
.channels_min = 2,
28+
.channels_max = 2,
29+
.rates = SNDRV_PCM_RATE_8000_192000,
30+
.formats = SNDRV_PCM_FMTBIT_S16_LE |
31+
SNDRV_PCM_FMTBIT_S24_LE
32+
},
33+
};
34+
35+
static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
36+
37+
static int pcm1794a_probe(struct platform_device *pdev)
38+
{
39+
return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
40+
&pcm1794a_dai, 1);
41+
}
42+
43+
static int pcm1794a_remove(struct platform_device *pdev)
44+
{
45+
snd_soc_unregister_codec(&pdev->dev);
46+
return 0;
47+
}
48+
49+
static struct platform_driver pcm1794a_codec_driver = {
50+
.probe = pcm1794a_probe,
51+
.remove = pcm1794a_remove,
52+
.driver = {
53+
.name = "pcm1794a-codec",
54+
.owner = THIS_MODULE,
55+
},
56+
};
57+
58+
module_platform_driver(pcm1794a_codec_driver);
59+
60+
MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
61+
MODULE_AUTHOR("Florian Meier <[email protected]>");
62+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)