Skip to content

Commit 8a105f6

Browse files
Angus_Wangjamess-huang
authored andcommitted
Set HiFiBerry DAC+ Pro to i2s master.
SoC is slave, DAC+ Pro is master. Change-Id: Ie5ff673c8d01b4250c936a261d4840c452ff526a Reviewed-on: https://tp-biosrd-v02/gerrit/81958 Reviewed-by: Jamess Huang(黃以民) <Jamess_Huang@asus.com> Tested-by: Jamess Huang(黃以民) <Jamess_Huang@asus.com>
1 parent 7959e31 commit 8a105f6

File tree

4 files changed

+178
-9
lines changed

4 files changed

+178
-9
lines changed

arch/arm/boot/dts/overlays/hifiberry-dacplus-overlay.dts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
};
1313

1414
fragment@1 {
15+
target-path = "/";
16+
__overlay__ {
17+
dacpro_osc: dacpro_osc {
18+
compatible = "hifiberry,dacpro-clk";
19+
#clock-cells = <0>;
20+
};
21+
};
22+
};
23+
24+
fragment@2 {
1525
target = <&i2c1>;
1626
__overlay__ {
1727
#address-cells = <1>;
@@ -22,6 +32,7 @@
2232
#sound-dai-cells = <0>;
2333
compatible = "ti,pcm5122";
2434
reg = <0x4d>;
35+
clocks = <&dacpro_osc>;
2536
AVDD-supply = <&vdd_3v3_reg>;
2637
DVDD-supply = <&vdd_3v3_reg>;
2738
CPVDD-supply = <&vdd_3v3_reg>;
@@ -30,17 +41,16 @@
3041
};
3142
};
3243

33-
fragment@2 {
44+
fragment@3 {
3445
target-path = "/sound-ext-card";
3546
hifiberry_dacplus: __overlay__ {
3647
compatible = "hifiberry,hifiberry-dacplus";
3748
i2s-controller = <&i2s>;
38-
hifiberry-dacplus,slave;
3949
status = "okay";
4050
};
4151
};
4252

43-
fragment@3 {
53+
fragment@4 {
4454
target = <&hdmi>;
4555
__overlay__ {
4656
hdmi-i2s-audio-disable;

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/rockchip/hifiberry_dacplus.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ static int snd_rpi_hifiberry_dacplus_clk_for_rate(int sample_rate)
121121
case 44100:
122122
case 88200:
123123
case 176400:
124+
case 352800:
124125
type = HIFIBERRY_DACPRO_CLK44EN;
125126
break;
126127
default:
@@ -232,7 +233,7 @@ static int snd_rpi_hifiberry_dacplus_set_bclk_ratio_pro(
232233
static int snd_rpi_hifiberry_dacplus_hw_params(
233234
struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
234235
{
235-
int ret;
236+
int ret = 0;
236237
struct snd_soc_pcm_runtime *rtd = substream->private_data;
237238
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
238239
#ifdef ROCKCHIP_AUDIO
@@ -245,11 +246,7 @@ static int snd_rpi_hifiberry_dacplus_hw_params(
245246
snd_rpi_hifiberry_dacplus_set_sclk(codec,
246247
params_rate(params));
247248

248-
#ifdef ROCKCHIP_AUDIO
249-
mclk = params_rate(params) * ROCKCHIP_I2S_MCLK;
250-
ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
251-
SND_SOC_CLOCK_OUT);
252-
#else
249+
#ifndef ROCKCHIP_AUDIO
253250
ret = snd_rpi_hifiberry_dacplus_set_bclk_ratio_pro(cpu_dai,
254251
params);
255252
#endif

0 commit comments

Comments
 (0)