Skip to content

Commit fc34453

Browse files
Daniel Matuschekpopcornmix
Daniel Matuschek
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. Add support for the HiFiBerry DAC+ Pro. The HiFiBerry DAC+ and DAC+ Pro products both use the existing bcm sound driver with the DAC+ Pro having a special clock device driver representing the two high precision oscillators. An addition bug fix is included for the PCM512x codec where by the physical size of the sample frame is used in the calculation of the LRCK divisor as it was found to be wrong when using 24-bit depth sample contained in a little endian 4-byte sample frame. Limit PCM512x "Digital" gain to 0dB by default with HiFiBerry DAC+ 24db_digital_gain DT param can be used to specify that PCM512x codec "Digital" volume control should not be limited to 0dB gain, and if specified will allow the full 24dB gain. Add dt param to force HiFiBerry DAC+ Pro into slave mode "dtoverlay=hifiberry-dacplus,slave" Add 'slave' param to use HiFiBerry DAC+ Pro in slave mode, with Pi as master for bit and frame clock. Signed-off-by: DigitalDreamtime <[email protected]>
1 parent 64508dd commit fc34453

File tree

6 files changed

+531
-1
lines changed

6 files changed

+531
-1
lines changed

drivers/clk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ obj-$(CONFIG_ARCH_CLPS711X) += clk-clps711x.o
2626
obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o
2727
obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o
2828
obj-$(CONFIG_ARCH_HIGHBANK) += clk-highbank.o
29+
obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += clk-hifiberry-dacpro.o
2930
obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o
3031
obj-$(CONFIG_ARCH_MB86S7X) += clk-mb86s7x.o
3132
obj-$(CONFIG_ARCH_MOXART) += clk-moxart.o

drivers/clk/clk-hifiberry-dacpro.c

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* Clock Driver for HiFiBerry DAC Pro
3+
*
4+
* Author: Stuart MacLean
5+
* Copyright 2015
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/clk-provider.h>
18+
#include <linux/clkdev.h>
19+
#include <linux/kernel.h>
20+
#include <linux/module.h>
21+
#include <linux/of.h>
22+
#include <linux/slab.h>
23+
#include <linux/platform_device.h>
24+
25+
/* Clock rate of CLK44EN attached to GPIO6 pin */
26+
#define CLK_44EN_RATE 22579200UL
27+
/* Clock rate of CLK48EN attached to GPIO3 pin */
28+
#define CLK_48EN_RATE 24576000UL
29+
30+
/**
31+
* struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
32+
* @hw: clk_hw for the common clk framework
33+
* @mode: 0 => CLK44EN, 1 => CLK48EN
34+
*/
35+
struct clk_hifiberry_hw {
36+
struct clk_hw hw;
37+
uint8_t mode;
38+
};
39+
40+
#define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
41+
42+
static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
43+
{ .compatible = "hifiberry,dacpro-clk",},
44+
{ }
45+
};
46+
MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
47+
48+
static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
49+
unsigned long parent_rate)
50+
{
51+
return (to_hifiberry_clk(hw)->mode == 0) ? CLK_44EN_RATE :
52+
CLK_48EN_RATE;
53+
}
54+
55+
static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
56+
unsigned long rate, unsigned long *parent_rate)
57+
{
58+
long actual_rate;
59+
60+
if (rate <= CLK_44EN_RATE) {
61+
actual_rate = (long)CLK_44EN_RATE;
62+
} else if (rate >= CLK_48EN_RATE) {
63+
actual_rate = (long)CLK_48EN_RATE;
64+
} else {
65+
long diff44Rate = (long)(rate - CLK_44EN_RATE);
66+
long diff48Rate = (long)(CLK_48EN_RATE - rate);
67+
68+
if (diff44Rate < diff48Rate)
69+
actual_rate = (long)CLK_44EN_RATE;
70+
else
71+
actual_rate = (long)CLK_48EN_RATE;
72+
}
73+
return actual_rate;
74+
}
75+
76+
77+
static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
78+
unsigned long rate, unsigned long parent_rate)
79+
{
80+
unsigned long actual_rate;
81+
struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
82+
83+
actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
84+
&parent_rate);
85+
clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
86+
return 0;
87+
}
88+
89+
90+
const struct clk_ops clk_hifiberry_dacpro_rate_ops = {
91+
.recalc_rate = clk_hifiberry_dacpro_recalc_rate,
92+
.round_rate = clk_hifiberry_dacpro_round_rate,
93+
.set_rate = clk_hifiberry_dacpro_set_rate,
94+
};
95+
96+
static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
97+
{
98+
int ret;
99+
struct clk_hifiberry_hw *proclk;
100+
struct clk *clk;
101+
struct device *dev;
102+
struct clk_init_data init;
103+
104+
dev = &pdev->dev;
105+
106+
proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
107+
if (!proclk)
108+
return -ENOMEM;
109+
110+
init.name = "clk-hifiberry-dacpro";
111+
init.ops = &clk_hifiberry_dacpro_rate_ops;
112+
init.flags = CLK_IS_BASIC;
113+
init.parent_names = NULL;
114+
init.num_parents = 0;
115+
116+
proclk->mode = 0;
117+
proclk->hw.init = &init;
118+
119+
clk = devm_clk_register(dev, &proclk->hw);
120+
if (!IS_ERR(clk)) {
121+
ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
122+
clk);
123+
} else {
124+
dev_err(dev, "Fail to register clock driver\n");
125+
kfree(proclk);
126+
ret = PTR_ERR(clk);
127+
}
128+
return ret;
129+
}
130+
131+
static int clk_hifiberry_dacpro_remove(struct platform_device *pdev)
132+
{
133+
of_clk_del_provider(pdev->dev.of_node);
134+
return 0;
135+
}
136+
137+
static struct platform_driver clk_hifiberry_dacpro_driver = {
138+
.probe = clk_hifiberry_dacpro_probe,
139+
.remove = clk_hifiberry_dacpro_remove,
140+
.driver = {
141+
.name = "clk-hifiberry-dacpro",
142+
.of_match_table = clk_hifiberry_dacpro_dt_ids,
143+
},
144+
};
145+
146+
static int __init clk_hifiberry_dacpro_init(void)
147+
{
148+
return platform_driver_register(&clk_hifiberry_dacpro_driver);
149+
}
150+
core_initcall(clk_hifiberry_dacpro_init);
151+
152+
static void __exit clk_hifiberry_dacpro_exit(void)
153+
{
154+
platform_driver_unregister(&clk_hifiberry_dacpro_driver);
155+
}
156+
module_exit(clk_hifiberry_dacpro_exit);
157+
158+
MODULE_DESCRIPTION("HiFiBerry DAC Pro clock driver");
159+
MODULE_LICENSE("GPL v2");
160+
MODULE_ALIAS("platform:clk-hifiberry-dacpro");

sound/soc/bcm/Kconfig

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

27+
config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
28+
tristate "Support for HifiBerry DAC+"
29+
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
30+
select SND_SOC_PCM512x
31+
help
32+
Say Y or M if you want to add support for HifiBerry DAC+.
33+
2734
config SND_BCM2708_SOC_HIFIBERRY_DIGI
2835
tristate "Support for HifiBerry Digi"
2936
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_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_SOC_CYGNUS) += snd-soc-cygnus.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

0 commit comments

Comments
 (0)