Skip to content

Commit 250e0dc

Browse files
babuenirPhil Elwell
authored and
Phil Elwell
committed
Add support for Allo Boss DAC add-on board for Raspberry Pi. (#1924)
Signed-off-by: Baswaraj K <[email protected]> Reviewed-by: Deepak <[email protected]> Reviewed-by: BabuSubashChandar <[email protected]>
1 parent bd7ec2b commit 250e0dc

File tree

8 files changed

+629
-0
lines changed

8 files changed

+629
-0
lines changed

arch/arm/boot/dts/overlays/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
77
ads1115.dtbo \
88
ads7846.dtbo \
99
akkordion-iqdacplus.dtbo \
10+
allo-boss-dac-pcm512x-audio.dtbo \
1011
allo-piano-dac-pcm512x-audio.dtbo \
1112
allo-piano-dac-plus-pcm512x-audio.dtbo \
1213
at86rf233.dtbo \

arch/arm/boot/dts/overlays/README

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,30 @@ Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
263263
that does not result in clipping/distortion!)
264264

265265

266+
Name: allo-boss-dac-pcm512x-audio
267+
Info: Configures the Allo Boss DAC audio cards.
268+
Load: dtoverlay=allo-boss-dac-pcm512x-audio,<param>
269+
Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
270+
Digital volume control. Enable with
271+
"dtoverlay=allo-boss-dac-pcm512x-audio,
272+
24db_digital_gain"
273+
(The default behaviour is that the Digital
274+
volume control is limited to a maximum of
275+
0dB. ie. it can attenuate but not provide
276+
gain. For most users, this will be desired
277+
as it will prevent clipping. By appending
278+
the 24db_digital_gain parameter, the Digital
279+
volume control will allow up to 24dB of
280+
gain. If this parameter is enabled, it is the
281+
responsibility of the user to ensure that
282+
the Digital volume control is set to a value
283+
that does not result in clipping/distortion!)
284+
slave Force Boss DAC into slave mode, using Pi a
285+
master for bit clock and frame clock. Enable
286+
with "dtoverlay=allo-boss-dac-pcm512x-audio,
287+
slave"
288+
289+
266290
Name: allo-piano-dac-pcm512x-audio
267291
Info: Configures the Allo Piano DAC (2.0/2.1) audio cards.
268292
(NB. This initial support is for 2.0 channel audio ONLY! ie. stereo.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Definitions for Allo Boss DAC board
3+
*/
4+
5+
/dts-v1/;
6+
/plugin/;
7+
8+
/ {
9+
compatible = "brcm,bcm2708";
10+
11+
fragment@0 {
12+
target-path = "/clocks";
13+
__overlay__ {
14+
boss_osc: boss_osc {
15+
compatible = "allo,dac-clk";
16+
#clock-cells = <0>;
17+
};
18+
};
19+
};
20+
21+
fragment@1 {
22+
target = <&i2s>;
23+
__overlay__ {
24+
status = "okay";
25+
};
26+
};
27+
28+
fragment@2 {
29+
target = <&i2c1>;
30+
__overlay__ {
31+
#address-cells = <1>;
32+
#size-cells = <0>;
33+
status = "okay";
34+
35+
pcm5122@4d {
36+
#sound-dai-cells = <0>;
37+
compatible = "ti,pcm5122";
38+
clocks = <&boss_osc>;
39+
reg = <0x4d>;
40+
status = "okay";
41+
};
42+
};
43+
};
44+
45+
fragment@3 {
46+
target = <&sound>;
47+
boss_dac: __overlay__ {
48+
compatible = "allo,boss-dac";
49+
i2s-controller = <&i2s>;
50+
status = "okay";
51+
};
52+
};
53+
54+
__overrides__ {
55+
24db_digital_gain = <&boss_dac>,"allo,24db_digital_gain?";
56+
slave = <&boss_dac>,"allo,slave?";
57+
};
58+
};

drivers/clk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ endif
1717

1818
# hardware specific clock types
1919
# please keep this section sorted lexicographically by file path name
20+
obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += clk-allo-dac-45Mhz.o
2021
obj-$(CONFIG_MACH_ASM9260) += clk-asm9260.o
2122
obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o
2223
obj-$(CONFIG_ARCH_AXXIA) += clk-axm5516.o

drivers/clk/clk-allo-dac-45Mhz.c

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

sound/soc/bcm/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ config SND_BCM2708_SOC_FE_PI_AUDIO
176176
help
177177
Say Y or M if you want to add support for Fe-Pi-Audio.
178178

179+
config SND_BCM2708_SOC_ALLO_BOSS_DAC
180+
tristate "Support for allo Boss DAC"
181+
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
182+
select SND_SOC_PCM512x_I2C
183+
help
184+
Say Y or M if you want to add support for allo Boss DAC.
185+
186+
179187
config SND_PISOUND
180188
tristate "Support for Blokas Labs pisound"
181189
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
@@ -31,6 +31,7 @@ snd-soc-audioinjector-octo-soundcard-objs := audioinjector-octo-soundcard.o
3131
snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
3232
snd-soc-dionaudio-loco-objs := dionaudio_loco.o
3333
snd-soc-dionaudio-loco-v2-objs := dionaudio_loco-v2.o
34+
snd-soc-allo-boss-dac-objs := allo-boss-dac.o
3435
snd-soc-allo-piano-dac-objs := allo-piano-dac.o
3536
snd-soc-allo-piano-dac-plus-objs := allo-piano-dac-plus.o
3637
snd-soc-pisound-objs := pisound.o
@@ -56,6 +57,7 @@ obj-$(CONFIG_SND_AUDIOINJECTOR_OCTO_SOUNDCARD) += snd-soc-audioinjector-octo-sou
5657
obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
5758
obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
5859
obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO_V2) += snd-soc-dionaudio-loco-v2.o
60+
obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += snd-soc-allo-boss-dac.o
5961
obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
6062
obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC_PLUS) += snd-soc-allo-piano-dac-plus.o
6163
obj-$(CONFIG_SND_PISOUND) += snd-soc-pisound.o

0 commit comments

Comments
 (0)