Skip to content

Commit 3ece03b

Browse files
committed
fixup! Add support for all the downstream rpi sound card drivers
Replace the Allo Dac clock driver with an extension of the HiFiBerry clock driver that it cloned. Signed-off-by: Phil Elwell <[email protected]>
1 parent a2d2745 commit 3ece03b

File tree

4 files changed

+40
-180
lines changed

4 files changed

+40
-180
lines changed

drivers/clk/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ endif
1919

2020
# hardware specific clock types
2121
# please keep this section sorted lexicographically by file path name
22-
obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += clk-allo-dac.o
2322
obj-$(CONFIG_COMMON_CLK_APPLE_NCO) += clk-apple-nco.o
2423
obj-$(CONFIG_MACH_ASM9260) += clk-asm9260.o
2524
obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o

drivers/clk/clk-allo-dac.c

Lines changed: 0 additions & 161 deletions
This file was deleted.

drivers/clk/clk-hifiberry-dacpro.c

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
#include <linux/slab.h>
2323
#include <linux/platform_device.h>
2424

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
25+
struct ext_clk_rates {
26+
/* Clock rate of CLK44EN attached to GPIO6 pin */
27+
unsigned long clk_44en;
28+
/* Clock rate of CLK48EN attached to GPIO3 pin */
29+
unsigned long clk_48en;
30+
};
2931

3032
/**
3133
* struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
@@ -35,40 +37,54 @@
3537
struct clk_hifiberry_hw {
3638
struct clk_hw hw;
3739
uint8_t mode;
40+
struct ext_clk_rates clk_rates;
3841
};
3942

4043
#define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
4144

45+
static const struct ext_clk_rates hifiberry_dacpro_clks = {
46+
.clk_44en = 22579200UL,
47+
.clk_48en = 24576000UL,
48+
};
49+
50+
static const struct ext_clk_rates allo_dac_clks = {
51+
.clk_44en = 45158400UL,
52+
.clk_48en = 49152000UL,
53+
};
54+
4255
static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
43-
{ .compatible = "hifiberry,dacpro-clk",},
56+
{ .compatible = "hifiberry,dacpro-clk", &hifiberry_dacpro_clks },
57+
{ .compatible = "allo,dac-clk", &allo_dac_clks },
4458
{ }
4559
};
4660
MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
4761

4862
static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
4963
unsigned long parent_rate)
5064
{
51-
return (to_hifiberry_clk(hw)->mode == 0) ? CLK_44EN_RATE :
52-
CLK_48EN_RATE;
65+
struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
66+
return (clk->mode == 0) ? clk->clk_rates.clk_44en :
67+
clk->clk_rates.clk_48en;
5368
}
5469

5570
static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
5671
unsigned long rate, unsigned long *parent_rate)
5772
{
73+
struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
5874
long actual_rate;
5975

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;
76+
if (rate <= clk->clk_rates.clk_44en) {
77+
actual_rate = (long)clk->clk_rates.clk_44en;
78+
} else if (rate >= clk->clk_rates.clk_48en) {
79+
actual_rate = (long)clk->clk_rates.clk_48en;
6480
} else {
65-
long diff44Rate = (long)(rate - CLK_44EN_RATE);
66-
long diff48Rate = (long)(CLK_48EN_RATE - rate);
81+
long diff44Rate = (long)(rate - clk->clk_rates.clk_44en);
82+
long diff48Rate = (long)(clk->clk_rates.clk_48en - rate);
6783

6884
if (diff44Rate < diff48Rate)
69-
actual_rate = (long)CLK_44EN_RATE;
85+
actual_rate = (long)clk->clk_rates.clk_44en;
7086
else
71-
actual_rate = (long)CLK_48EN_RATE;
87+
actual_rate = (long)clk->clk_rates.clk_48en;
7288
}
7389
return actual_rate;
7490
}
@@ -77,12 +93,12 @@ static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
7793
static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
7894
unsigned long rate, unsigned long parent_rate)
7995
{
80-
unsigned long actual_rate;
8196
struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
97+
unsigned long actual_rate;
8298

8399
actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
84100
&parent_rate);
85-
clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
101+
clk->mode = (actual_rate == clk->clk_rates.clk_44en) ? 0 : 1;
86102
return 0;
87103
}
88104

@@ -95,13 +111,17 @@ const struct clk_ops clk_hifiberry_dacpro_rate_ops = {
95111

96112
static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
97113
{
98-
int ret;
114+
const struct of_device_id *of_id;
99115
struct clk_hifiberry_hw *proclk;
100116
struct clk *clk;
101117
struct device *dev;
102118
struct clk_init_data init;
119+
int ret;
103120

104121
dev = &pdev->dev;
122+
of_id = of_match_node(clk_hifiberry_dacpro_dt_ids, dev->of_node);
123+
if (!of_id)
124+
return -EINVAL;
105125

106126
proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
107127
if (!proclk)
@@ -115,6 +135,7 @@ static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
115135

116136
proclk->mode = 0;
117137
proclk->hw.init = &init;
138+
memcpy(&proclk->clk_rates, of_id->data, sizeof(proclk->clk_rates));
118139

119140
clk = devm_clk_register(dev, &proclk->hw);
120141
if (!IS_ERR(clk)) {

sound/soc/bcm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ config SND_BCM2708_SOC_ALLO_BOSS_DAC
271271
tristate "Support for Allo Boss DAC"
272272
depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
273273
select SND_SOC_PCM512x_I2C
274+
select COMMON_CLK_HIFIBERRY_DACPRO
274275
help
275276
Say Y or M if you want to add support for Allo Boss DAC.
276277

0 commit comments

Comments
 (0)