1 From 3ece03b1575b0c3a0989e372aaaa4557ae74dc89 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Thu, 20 Jul 2023 11:28:20 +0100
4 Subject: [PATCH] fixup! Add support for all the downstream rpi sound card
7 Replace the Allo Dac clock driver with an extension of the
8 HiFiBerry clock driver that it cloned.
10 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
12 drivers/clk/Makefile | 1 -
13 drivers/clk/clk-allo-dac.c | 161 -----------------------------
14 drivers/clk/clk-hifiberry-dacpro.c | 57 ++++++----
15 sound/soc/bcm/Kconfig | 1 +
16 4 files changed, 40 insertions(+), 180 deletions(-)
17 delete mode 100644 drivers/clk/clk-allo-dac.c
19 --- a/drivers/clk/Makefile
20 +++ b/drivers/clk/Makefile
21 @@ -19,7 +19,6 @@ endif
23 # hardware specific clock types
24 # please keep this section sorted lexicographically by file path name
25 -obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += clk-allo-dac.o
26 obj-$(CONFIG_COMMON_CLK_APPLE_NCO) += clk-apple-nco.o
27 obj-$(CONFIG_MACH_ASM9260) += clk-asm9260.o
28 obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o
29 --- a/drivers/clk/clk-allo-dac.c
33 - * Clock Driver for Allo DAC
35 - * Author: Baswaraj K <jaikumar@cem-solutions.net>
37 - * based on code by Stuart MacLean
39 - * This program is free software; you can redistribute it and/or
40 - * modify it under the terms of the GNU General Public License
41 - * version 2 as published by the Free Software Foundation.
43 - * This program is distributed in the hope that it will be useful, but
44 - * WITHOUT ANY WARRANTY; without even the implied warranty of
45 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
46 - * General Public License for more details.
49 -#include <linux/clk-provider.h>
50 -#include <linux/clkdev.h>
51 -#include <linux/kernel.h>
52 -#include <linux/module.h>
53 -#include <linux/of.h>
54 -#include <linux/slab.h>
55 -#include <linux/platform_device.h>
57 -/* Clock rate of CLK44EN attached to GPIO6 pin */
58 -#define CLK_44EN_RATE 45158400UL
59 -/* Clock rate of CLK48EN attached to GPIO3 pin */
60 -#define CLK_48EN_RATE 49152000UL
63 - * struct allo_dac_clk - Common struct to the Allo DAC
64 - * @hw: clk_hw for the common clk framework
65 - * @mode: 0 => CLK44EN, 1 => CLK48EN
72 -#define to_allo_clk(_hw) container_of(_hw, struct clk_allo_hw, hw)
74 -static const struct of_device_id clk_allo_dac_dt_ids[] = {
75 - { .compatible = "allo,dac-clk",},
78 -MODULE_DEVICE_TABLE(of, clk_allo_dac_dt_ids);
80 -static unsigned long clk_allo_dac_recalc_rate(struct clk_hw *hw,
81 - unsigned long parent_rate)
83 - return (to_allo_clk(hw)->mode == 0) ? CLK_44EN_RATE :
87 -static long clk_allo_dac_round_rate(struct clk_hw *hw,
88 - unsigned long rate, unsigned long *parent_rate)
92 - if (rate <= CLK_44EN_RATE) {
93 - actual_rate = (long)CLK_44EN_RATE;
94 - } else if (rate >= CLK_48EN_RATE) {
95 - actual_rate = (long)CLK_48EN_RATE;
97 - long diff44Rate = (long)(rate - CLK_44EN_RATE);
98 - long diff48Rate = (long)(CLK_48EN_RATE - rate);
100 - if (diff44Rate < diff48Rate)
101 - actual_rate = (long)CLK_44EN_RATE;
103 - actual_rate = (long)CLK_48EN_RATE;
105 - return actual_rate;
109 -static int clk_allo_dac_set_rate(struct clk_hw *hw,
110 - unsigned long rate, unsigned long parent_rate)
112 - unsigned long actual_rate;
113 - struct clk_allo_hw *clk = to_allo_clk(hw);
115 - actual_rate = (unsigned long)clk_allo_dac_round_rate(hw, rate,
117 - clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
122 -const struct clk_ops clk_allo_dac_rate_ops = {
123 - .recalc_rate = clk_allo_dac_recalc_rate,
124 - .round_rate = clk_allo_dac_round_rate,
125 - .set_rate = clk_allo_dac_set_rate,
128 -static int clk_allo_dac_probe(struct platform_device *pdev)
131 - struct clk_allo_hw *proclk;
133 - struct device *dev;
134 - struct clk_init_data init;
138 - proclk = kzalloc(sizeof(struct clk_allo_hw), GFP_KERNEL);
142 - init.name = "clk-allo-dac";
143 - init.ops = &clk_allo_dac_rate_ops;
145 - init.parent_names = NULL;
146 - init.num_parents = 0;
149 - proclk->hw.init = &init;
151 - clk = devm_clk_register(dev, &proclk->hw);
152 - if (!IS_ERR(clk)) {
153 - ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
156 - dev_err(dev, "Fail to register clock driver\n");
158 - ret = PTR_ERR(clk);
163 -static int clk_allo_dac_remove(struct platform_device *pdev)
165 - of_clk_del_provider(pdev->dev.of_node);
169 -static struct platform_driver clk_allo_dac_driver = {
170 - .probe = clk_allo_dac_probe,
171 - .remove = clk_allo_dac_remove,
173 - .name = "clk-allo-dac",
174 - .of_match_table = clk_allo_dac_dt_ids,
178 -static int __init clk_allo_dac_init(void)
180 - return platform_driver_register(&clk_allo_dac_driver);
182 -core_initcall(clk_allo_dac_init);
184 -static void __exit clk_allo_dac_exit(void)
186 - platform_driver_unregister(&clk_allo_dac_driver);
188 -module_exit(clk_allo_dac_exit);
190 -MODULE_DESCRIPTION("Allo DAC clock driver");
191 -MODULE_LICENSE("GPL v2");
192 -MODULE_ALIAS("platform:clk-allo-dac");
193 --- a/drivers/clk/clk-hifiberry-dacpro.c
194 +++ b/drivers/clk/clk-hifiberry-dacpro.c
196 #include <linux/slab.h>
197 #include <linux/platform_device.h>
199 -/* Clock rate of CLK44EN attached to GPIO6 pin */
200 -#define CLK_44EN_RATE 22579200UL
201 -/* Clock rate of CLK48EN attached to GPIO3 pin */
202 -#define CLK_48EN_RATE 24576000UL
203 +struct ext_clk_rates {
204 + /* Clock rate of CLK44EN attached to GPIO6 pin */
205 + unsigned long clk_44en;
206 + /* Clock rate of CLK48EN attached to GPIO3 pin */
207 + unsigned long clk_48en;
211 * struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
213 struct clk_hifiberry_hw {
216 + struct ext_clk_rates clk_rates;
219 #define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
221 +static const struct ext_clk_rates hifiberry_dacpro_clks = {
222 + .clk_44en = 22579200UL,
223 + .clk_48en = 24576000UL,
226 +static const struct ext_clk_rates allo_dac_clks = {
227 + .clk_44en = 45158400UL,
228 + .clk_48en = 49152000UL,
231 static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
232 - { .compatible = "hifiberry,dacpro-clk",},
233 + { .compatible = "hifiberry,dacpro-clk", &hifiberry_dacpro_clks },
234 + { .compatible = "allo,dac-clk", &allo_dac_clks },
237 MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
238 @@ -48,27 +62,29 @@ MODULE_DEVICE_TABLE(of, clk_hifiberry_da
239 static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
240 unsigned long parent_rate)
242 - return (to_hifiberry_clk(hw)->mode == 0) ? CLK_44EN_RATE :
244 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
245 + return (clk->mode == 0) ? clk->clk_rates.clk_44en :
246 + clk->clk_rates.clk_48en;
249 static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
250 unsigned long rate, unsigned long *parent_rate)
252 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
255 - if (rate <= CLK_44EN_RATE) {
256 - actual_rate = (long)CLK_44EN_RATE;
257 - } else if (rate >= CLK_48EN_RATE) {
258 - actual_rate = (long)CLK_48EN_RATE;
259 + if (rate <= clk->clk_rates.clk_44en) {
260 + actual_rate = (long)clk->clk_rates.clk_44en;
261 + } else if (rate >= clk->clk_rates.clk_48en) {
262 + actual_rate = (long)clk->clk_rates.clk_48en;
264 - long diff44Rate = (long)(rate - CLK_44EN_RATE);
265 - long diff48Rate = (long)(CLK_48EN_RATE - rate);
266 + long diff44Rate = (long)(rate - clk->clk_rates.clk_44en);
267 + long diff48Rate = (long)(clk->clk_rates.clk_48en - rate);
269 if (diff44Rate < diff48Rate)
270 - actual_rate = (long)CLK_44EN_RATE;
271 + actual_rate = (long)clk->clk_rates.clk_44en;
273 - actual_rate = (long)CLK_48EN_RATE;
274 + actual_rate = (long)clk->clk_rates.clk_48en;
278 @@ -77,12 +93,12 @@ static long clk_hifiberry_dacpro_round_r
279 static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
280 unsigned long rate, unsigned long parent_rate)
282 - unsigned long actual_rate;
283 struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
284 + unsigned long actual_rate;
286 actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
288 - clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
289 + clk->mode = (actual_rate == clk->clk_rates.clk_44en) ? 0 : 1;
293 @@ -95,13 +111,17 @@ const struct clk_ops clk_hifiberry_dacpr
295 static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
298 + const struct of_device_id *of_id;
299 struct clk_hifiberry_hw *proclk;
302 struct clk_init_data init;
306 + of_id = of_match_node(clk_hifiberry_dacpro_dt_ids, dev->of_node);
310 proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
312 @@ -115,6 +135,7 @@ static int clk_hifiberry_dacpro_probe(st
315 proclk->hw.init = &init;
316 + memcpy(&proclk->clk_rates, of_id->data, sizeof(proclk->clk_rates));
318 clk = devm_clk_register(dev, &proclk->hw);
320 --- a/sound/soc/bcm/Kconfig
321 +++ b/sound/soc/bcm/Kconfig
322 @@ -271,6 +271,7 @@ config SND_BCM2708_SOC_ALLO_BOSS_DAC
323 tristate "Support for Allo Boss DAC"
324 depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
325 select SND_SOC_PCM512x_I2C
326 + select COMMON_CLK_HIFIBERRY_DACPRO
328 Say Y or M if you want to add support for Allo Boss DAC.