Skip to content

Commit 72874cf

Browse files
koalopopcornmix
authored andcommitted
ASoC: Add support for HifiBerry DAC
This adds a machine driver for the HifiBerry DAC. It is a sound card that can be stacked onto the Raspberry Pi. Signed-off-by: Florian Meier <florian.meier@koalo.de>
1 parent a00644d commit 72874cf

3 files changed

Lines changed: 112 additions & 0 deletions

File tree

‎sound/soc/bcm/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ config SND_BCM2708_SOC_I2S
88
Say Y or M if you want to add support for codecs attached to
99
the BCM2708 I2S interface. You will also need
1010
to select the audio interfaces to support below.
11+
12+
config SND_BCM2708_SOC_HIFIBERRY_DAC
13+
tristate "Support for HifiBerry DAC"
14+
depends on SND_BCM2708_SOC_I2S
15+
select SND_SOC_PCM5102A
16+
help
17+
Say Y or M if you want to add support for HifiBerry DAC.

‎sound/soc/bcm/Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
33

44
obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
5+
6+
# BCM2708 Machine Support
7+
snd-soc-hifiberry-dac-objs := hifiberry_dac.o
8+
9+
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o

‎sound/soc/bcm/hifiberry_dac.c‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* ASoC Driver for HifiBerry DAC
3+
*
4+
* Author: Florian Meier <florian.meier@koalo.de>
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_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
27+
{
28+
return 0;
29+
}
30+
31+
static int snd_rpi_hifiberry_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+
unsigned int sample_bits =
38+
snd_pcm_format_physical_width(params_format(params));
39+
40+
return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
41+
}
42+
43+
/* machine stream operations */
44+
static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
45+
.hw_params = snd_rpi_hifiberry_dac_hw_params,
46+
};
47+
48+
static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
49+
{
50+
.name = "HifiBerry DAC",
51+
.stream_name = "HifiBerry DAC HiFi",
52+
.cpu_dai_name = "bcm2708-i2s.0",
53+
.codec_dai_name = "pcm5102a-hifi",
54+
.platform_name = "bcm2708-i2s.0",
55+
.codec_name = "pcm5102a-codec",
56+
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
57+
SND_SOC_DAIFMT_CBS_CFS,
58+
.ops = &snd_rpi_hifiberry_dac_ops,
59+
.init = snd_rpi_hifiberry_dac_init,
60+
},
61+
};
62+
63+
/* audio machine driver */
64+
static struct snd_soc_card snd_rpi_hifiberry_dac = {
65+
.name = "snd_rpi_hifiberry_dac",
66+
.dai_link = snd_rpi_hifiberry_dac_dai,
67+
.num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
68+
};
69+
70+
static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
71+
{
72+
int ret = 0;
73+
74+
snd_rpi_hifiberry_dac.dev = &pdev->dev;
75+
ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
76+
if (ret)
77+
dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
78+
79+
return ret;
80+
}
81+
82+
static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
83+
{
84+
return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
85+
}
86+
87+
static struct platform_driver snd_rpi_hifiberry_dac_driver = {
88+
.driver = {
89+
.name = "snd-hifiberry-dac",
90+
.owner = THIS_MODULE,
91+
},
92+
.probe = snd_rpi_hifiberry_dac_probe,
93+
.remove = snd_rpi_hifiberry_dac_remove,
94+
};
95+
96+
module_platform_driver(snd_rpi_hifiberry_dac_driver);
97+
98+
MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
99+
MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
100+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)