Skip to content

Commit 792e42f

Browse files
yupei_linasus-leslieyu
authored andcommitted
Audio : add hifiberry_dacplus and clk-hifiberry-dacpro to support hifiberry-dac+.
Change-Id: Ia411521b4eda3d53c98a82b4625d0e71e0197980
1 parent 42397d7 commit 792e42f

8 files changed

Lines changed: 570 additions & 7 deletions

File tree

arch/arm/boot/dts/rk3288-tinker-board.dtsi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@
130130
regulator-boot-on;
131131
};
132132

133+
vdd_3v3_reg: fixedregulator_3v3 {
134+
compatible = "regulator-fixed";
135+
regulator-name = "3v3";
136+
regulator-min-microvolt = <3300000>;
137+
regulator-max-microvolt = <3300000>;
138+
regulator-always-on;
139+
};
140+
133141
vcc_sys: vsys-regulator {
134142
compatible = "regulator-fixed";
135143
regulator-name = "vcc_sys";

arch/arm/configs/rockchip_linux_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ CONFIG_SND_DYNAMIC_MINORS=y
600600
# CONFIG_SND_SPI is not set
601601
CONFIG_SND_USB_AUDIO=y
602602
CONFIG_SND_SOC=y
603+
CONFIG_SND_SOC_HIFIBERRY_DACPLUS=y
603604
CONFIG_SND_SOC_ROCKCHIP=y
604605
CONFIG_SND_SOC_ROCKCHIP_SPDIF=y
605606
CONFIG_SND_SOC_ROCKCHIP_MAX98090=y

drivers/clk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ obj-$(CONFIG_ARCH_STM32) += clk-stm32f4.o
4545
obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o
4646
obj-$(CONFIG_ARCH_U300) += clk-u300.o
4747
obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o
48+
obj-$(CONFIG_SND_SOC_HIFIBERRY_DACPLUS) += clk-hifiberry-dacpro.o
4849
obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o
4950
obj-$(CONFIG_COMMON_CLK_XGENE) += clk-xgene.o
5051
obj-$(CONFIG_COMMON_CLK_PWM) += clk-pwm.o

drivers/clk/clk-hifiberry-dacpro.c

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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.flags = CLK_IS_BASIC | CLK_IS_ROOT;
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_hifiberry_dacpro_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_hifiberry_dacpro_driver = {
139+
.probe = clk_hifiberry_dacpro_probe,
140+
.remove = clk_hifiberry_dacpro_remove,
141+
.driver = {
142+
.name = "clk-hifiberry-dacpro",
143+
.of_match_table = clk_hifiberry_dacpro_dt_ids,
144+
},
145+
};
146+
147+
static int __init clk_hifiberry_dacpro_init(void)
148+
{
149+
return platform_driver_register(&clk_hifiberry_dacpro_driver);
150+
}
151+
core_initcall(clk_hifiberry_dacpro_init);
152+
153+
static void __exit clk_hifiberry_dacpro_exit(void)
154+
{
155+
platform_driver_unregister(&clk_hifiberry_dacpro_driver);
156+
}
157+
module_exit(clk_hifiberry_dacpro_exit);
158+
159+
MODULE_DESCRIPTION("HiFiBerry DAC Pro clock driver");
160+
MODULE_LICENSE("GPL v2");
161+
MODULE_ALIAS("platform:clk-hifiberry-dacpro");

sound/soc/codecs/pcm512x.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,8 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai,
854854
int fssp;
855855
int gpio;
856856

857-
lrclk_div = snd_soc_params_to_frame_size(params);
857+
lrclk_div = snd_pcm_format_physical_width(params_format(params))
858+
* params_channels(params);
858859
if (lrclk_div == 0) {
859860
dev_err(dev, "No LRCLK?\n");
860861
return -EINVAL;
@@ -1348,12 +1349,14 @@ static struct snd_soc_codec_driver pcm512x_codec_driver = {
13481349
.set_bias_level = pcm512x_set_bias_level,
13491350
.idle_bias_off = true,
13501351

1351-
.controls = pcm512x_controls,
1352-
.num_controls = ARRAY_SIZE(pcm512x_controls),
1353-
.dapm_widgets = pcm512x_dapm_widgets,
1354-
.num_dapm_widgets = ARRAY_SIZE(pcm512x_dapm_widgets),
1355-
.dapm_routes = pcm512x_dapm_routes,
1356-
.num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes),
1352+
.component_driver = {
1353+
.controls = pcm512x_controls,
1354+
.num_controls = ARRAY_SIZE(pcm512x_controls),
1355+
.dapm_widgets = pcm512x_dapm_widgets,
1356+
.num_dapm_widgets = ARRAY_SIZE(pcm512x_dapm_widgets),
1357+
.dapm_routes = pcm512x_dapm_routes,
1358+
.num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes),
1359+
},
13571360
};
13581361

13591362
static const struct regmap_range_cfg pcm512x_range = {

sound/soc/rockchip/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ config SND_SOC_ROCKCHIP_HDMI_DP
9797
Say Y or M here if you want to add support for SoC audio on Rockchip
9898
boards using built-in HDMI and DP, such as RK3399 boards.
9999

100+
config SND_SOC_HIFIBERRY_DACPLUS
101+
tristate "Support for HifiBerry DAC+"
102+
select SND_SOC_PCM512x_I2C
103+
help
104+
Say Y or M if you want to add support for HifiBerry DAC+.
105+
100106
config SND_SOC_ROCKCHIP_MAX98090
101107
tristate "ASoC support for Rockchip boards using a MAX98090 codec"
102108
depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP

sound/soc/rockchip/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ obj-$(CONFIG_SND_SOC_ROCKCHIP_SPDIF) += snd-soc-rockchip-spdif.o
2121
obj-$(CONFIG_SND_SOC_ROCKCHIP_SPDIFRX) += snd-soc-rockchip-spdifrx.o
2222
obj-$(CONFIG_SND_SOC_ROCKCHIP_VAD) += snd-soc-rockchip-vad.o
2323

24+
ccflags-y += -DROCKCHIP_AUDIO
25+
2426
snd-soc-rockchip-da7219-objs := rockchip_da7219.o
2527
snd-soc-rockchip-hdmi-analog-objs := rockchip_hdmi_analog.o
2628
snd-soc-rockchip-hdmi-dp-objs := rockchip_hdmi_dp.o
@@ -29,6 +31,7 @@ snd-soc-rockchip-multicodecs-objs := rockchip_multicodecs.o
2931
snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o
3032
snd-soc-rockchip-rt5651-tc358749x-objs := rockchip_rt5651_tc358749x.o
3133
snd-soc-rockchip-cdndp-objs := rockchip_cdndp.o
34+
snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
3235

3336
obj-$(CONFIG_SND_SOC_ROCKCHIP_DA7219) += snd-soc-rockchip-da7219.o
3437
obj-$(CONFIG_SND_SOC_ROCKCHIP_HDMI_ANALOG) += snd-soc-rockchip-hdmi-analog.o
@@ -38,3 +41,4 @@ obj-$(CONFIG_SND_SOC_ROCKCHIP_MULTICODECS) += snd-soc-rockchip-multicodecs.o
3841
obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o
3942
obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5651_TC358749) += snd-soc-rockchip-rt5651-tc358749x.o
4043
obj-$(CONFIG_SND_SOC_ROCKCHIP_CDNDP) += snd-soc-rockchip-cdndp.o
44+
obj-$(CONFIG_SND_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o

0 commit comments

Comments
 (0)