Skip to content

Commit e774dac

Browse files
Daniel Matuschekpopcornmix
authored andcommitted
Added support for HiFiBerry DAC+
The driver is based on the HiFiBerry DAC driver. However HiFiBerry DAC+ uses a different codec chip (PCM5122), therefore a new driver is necessary.
1 parent 326c837 commit e774dac

5 files changed

Lines changed: 148 additions & 0 deletions

File tree

‎arch/arm/configs/bcmrpi_defconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
747747
CONFIG_SND_SOC_WM8804=m
748748
CONFIG_SND_BCM2708_SOC_I2S=m
749749
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
750+
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
750751
CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
751752
CONFIG_SND_BCM2708_SOC_RPI_DAC=m
752753
CONFIG_SND_SOC_I2C_AND_SPI=m

‎arch/arm/mach-bcm2708/bcm2708.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,20 @@ static struct platform_device snd_pcm5102a_codec_device = {
674674
};
675675
#endif
676676

677+
#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
678+
static struct platform_device snd_rpi_hifiberry_dacplus_device = {
679+
.name = "snd-rpi-hifiberry-dacplus",
680+
.id = 0,
681+
.num_resources = 0,
682+
};
683+
684+
static struct i2c_board_info __initdata snd_pcm512x_hbdacplus_i2c_devices[] = {
685+
{
686+
I2C_BOARD_INFO("pcm5122", 0x4d)
687+
},
688+
};
689+
#endif
690+
677691
#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
678692
static struct platform_device snd_hifiberry_digi_device = {
679693
.name = "snd-hifiberry-digi",
@@ -879,6 +893,11 @@ void __init bcm2708_init(void)
879893
bcm_register_device(&snd_pcm5102a_codec_device);
880894
#endif
881895

896+
#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
897+
bcm_register_device(&snd_rpi_hifiberry_dacplus_device);
898+
i2c_register_board_info(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
899+
#endif
900+
882901
#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
883902
bcm_register_device(&snd_hifiberry_digi_device);
884903
i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));

‎sound/soc/bcm/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
2626
help
2727
Say Y or M if you want to add support for HifiBerry DAC.
2828

29+
config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
30+
tristate "Support for HifiBerry DAC+"
31+
depends on SND_BCM2708_SOC_I2S
32+
select SND_SOC_PCM512x
33+
help
34+
Say Y or M if you want to add support for HifiBerry DAC+.
35+
2936
config SND_BCM2708_SOC_HIFIBERRY_DIGI
3037
tristate "Support for HifiBerry Digi"
3138
depends on SND_BCM2708_SOC_I2S

‎sound/soc/bcm/Makefile‎

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

1111
# BCM2708 Machine Support
1212
snd-soc-hifiberry-dac-objs := hifiberry_dac.o
13+
snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
1314
snd-soc-hifiberry-digi-objs := hifiberry_digi.o
1415
snd-soc-rpi-dac-objs := rpi-dac.o
1516
snd-soc-iqaudio-dac-objs := iqaudio-dac.o
1617

1718
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
19+
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
1820
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
1921
obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
2022
obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o

‎sound/soc/bcm/hifiberry_dacplus.c‎

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* ASoC Driver for HiFiBerry DAC+
3+
*
4+
* Author: Daniel Matuschek
5+
* Copyright 2014
6+
* based on code by Florian Meier <florian.meier@koalo.de>
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License
10+
* version 2 as published by the Free Software Foundation.
11+
*
12+
* This program is distributed in the hope that it will be useful, but
13+
* WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* General Public License for more details.
16+
*/
17+
18+
#include <linux/module.h>
19+
#include <linux/platform_device.h>
20+
21+
#include <sound/core.h>
22+
#include <sound/pcm.h>
23+
#include <sound/pcm_params.h>
24+
#include <sound/soc.h>
25+
#include <sound/jack.h>
26+
27+
#include "../codecs/pcm512x.h"
28+
29+
static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
30+
{
31+
struct snd_soc_codec *codec = rtd->codec;
32+
snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
33+
snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
34+
snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
35+
return 0;
36+
}
37+
38+
static int snd_rpi_hifiberry_dacplus_hw_params(struct snd_pcm_substream *substream,
39+
struct snd_pcm_hw_params *params)
40+
{
41+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
42+
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
43+
return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
44+
}
45+
46+
static int snd_rpi_hifiberry_dacplus_startup(struct snd_pcm_substream *substream) {
47+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
48+
struct snd_soc_codec *codec = rtd->codec;
49+
snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
50+
return 0;
51+
}
52+
53+
static void snd_rpi_hifiberry_dacplus_shutdown(struct snd_pcm_substream *substream) {
54+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
55+
struct snd_soc_codec *codec = rtd->codec;
56+
snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
57+
}
58+
59+
/* machine stream operations */
60+
static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
61+
.hw_params = snd_rpi_hifiberry_dacplus_hw_params,
62+
.startup = snd_rpi_hifiberry_dacplus_startup,
63+
.shutdown = snd_rpi_hifiberry_dacplus_shutdown,
64+
};
65+
66+
static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
67+
{
68+
.name = "HiFiBerry DAC+",
69+
.stream_name = "HiFiBerry DAC+ HiFi",
70+
.cpu_dai_name = "bcm2708-i2s.0",
71+
.codec_dai_name = "pcm512x-hifi",
72+
.platform_name = "bcm2708-i2s.0",
73+
.codec_name = "pcm512x.1-004d",
74+
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
75+
SND_SOC_DAIFMT_CBS_CFS,
76+
.ops = &snd_rpi_hifiberry_dacplus_ops,
77+
.init = snd_rpi_hifiberry_dacplus_init,
78+
},
79+
};
80+
81+
/* audio machine driver */
82+
static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
83+
.name = "snd_rpi_hifiberry_dacplus",
84+
.dai_link = snd_rpi_hifiberry_dacplus_dai,
85+
.num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
86+
};
87+
88+
static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
89+
{
90+
int ret = 0;
91+
92+
snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
93+
ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);
94+
if (ret)
95+
dev_err(&pdev->dev,
96+
"snd_soc_register_card() failed: %d\n", ret);
97+
98+
return ret;
99+
}
100+
101+
static int snd_rpi_hifiberry_dacplus_remove(struct platform_device *pdev)
102+
{
103+
return snd_soc_unregister_card(&snd_rpi_hifiberry_dacplus);
104+
}
105+
106+
static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
107+
.driver = {
108+
.name = "snd-rpi-hifiberry-dacplus",
109+
.owner = THIS_MODULE,
110+
},
111+
.probe = snd_rpi_hifiberry_dacplus_probe,
112+
.remove = snd_rpi_hifiberry_dacplus_remove,
113+
};
114+
115+
module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
116+
117+
MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
118+
MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
119+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)