87097d2bbff01d34c2d61d28029fb45e5966ed95
[openwrt/staging/ldir.git] /
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
5 drivers
6
7 Replace the Allo Dac clock driver with an extension of the
8 HiFiBerry clock driver that it cloned.
9
10 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
11 ---
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
18
19 --- a/drivers/clk/Makefile
20 +++ b/drivers/clk/Makefile
21 @@ -19,7 +19,6 @@ endif
22
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
30 +++ /dev/null
31 @@ -1,161 +0,0 @@
32 -/*
33 - * Clock Driver for Allo DAC
34 - *
35 - * Author: Baswaraj K <jaikumar@cem-solutions.net>
36 - * Copyright 2016
37 - * based on code by Stuart MacLean
38 - *
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.
42 - *
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.
47 - */
48 -
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>
56 -
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
61 -
62 -/**
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
66 - */
67 -struct clk_allo_hw {
68 - struct clk_hw hw;
69 - uint8_t mode;
70 -};
71 -
72 -#define to_allo_clk(_hw) container_of(_hw, struct clk_allo_hw, hw)
73 -
74 -static const struct of_device_id clk_allo_dac_dt_ids[] = {
75 - { .compatible = "allo,dac-clk",},
76 - { }
77 -};
78 -MODULE_DEVICE_TABLE(of, clk_allo_dac_dt_ids);
79 -
80 -static unsigned long clk_allo_dac_recalc_rate(struct clk_hw *hw,
81 - unsigned long parent_rate)
82 -{
83 - return (to_allo_clk(hw)->mode == 0) ? CLK_44EN_RATE :
84 - CLK_48EN_RATE;
85 -}
86 -
87 -static long clk_allo_dac_round_rate(struct clk_hw *hw,
88 - unsigned long rate, unsigned long *parent_rate)
89 -{
90 - long actual_rate;
91 -
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;
96 - } else {
97 - long diff44Rate = (long)(rate - CLK_44EN_RATE);
98 - long diff48Rate = (long)(CLK_48EN_RATE - rate);
99 -
100 - if (diff44Rate < diff48Rate)
101 - actual_rate = (long)CLK_44EN_RATE;
102 - else
103 - actual_rate = (long)CLK_48EN_RATE;
104 - }
105 - return actual_rate;
106 -}
107 -
108 -
109 -static int clk_allo_dac_set_rate(struct clk_hw *hw,
110 - unsigned long rate, unsigned long parent_rate)
111 -{
112 - unsigned long actual_rate;
113 - struct clk_allo_hw *clk = to_allo_clk(hw);
114 -
115 - actual_rate = (unsigned long)clk_allo_dac_round_rate(hw, rate,
116 - &parent_rate);
117 - clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
118 - return 0;
119 -}
120 -
121 -
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,
126 -};
127 -
128 -static int clk_allo_dac_probe(struct platform_device *pdev)
129 -{
130 - int ret;
131 - struct clk_allo_hw *proclk;
132 - struct clk *clk;
133 - struct device *dev;
134 - struct clk_init_data init;
135 -
136 - dev = &pdev->dev;
137 -
138 - proclk = kzalloc(sizeof(struct clk_allo_hw), GFP_KERNEL);
139 - if (!proclk)
140 - return -ENOMEM;
141 -
142 - init.name = "clk-allo-dac";
143 - init.ops = &clk_allo_dac_rate_ops;
144 - init.flags = 0;
145 - init.parent_names = NULL;
146 - init.num_parents = 0;
147 -
148 - proclk->mode = 0;
149 - proclk->hw.init = &init;
150 -
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,
154 - clk);
155 - } else {
156 - dev_err(dev, "Fail to register clock driver\n");
157 - kfree(proclk);
158 - ret = PTR_ERR(clk);
159 - }
160 - return ret;
161 -}
162 -
163 -static int clk_allo_dac_remove(struct platform_device *pdev)
164 -{
165 - of_clk_del_provider(pdev->dev.of_node);
166 - return 0;
167 -}
168 -
169 -static struct platform_driver clk_allo_dac_driver = {
170 - .probe = clk_allo_dac_probe,
171 - .remove = clk_allo_dac_remove,
172 - .driver = {
173 - .name = "clk-allo-dac",
174 - .of_match_table = clk_allo_dac_dt_ids,
175 - },
176 -};
177 -
178 -static int __init clk_allo_dac_init(void)
179 -{
180 - return platform_driver_register(&clk_allo_dac_driver);
181 -}
182 -core_initcall(clk_allo_dac_init);
183 -
184 -static void __exit clk_allo_dac_exit(void)
185 -{
186 - platform_driver_unregister(&clk_allo_dac_driver);
187 -}
188 -module_exit(clk_allo_dac_exit);
189 -
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
195 @@ -22,10 +22,12 @@
196 #include <linux/slab.h>
197 #include <linux/platform_device.h>
198
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;
208 +};
209
210 /**
211 * struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
212 @@ -35,12 +37,24 @@
213 struct clk_hifiberry_hw {
214 struct clk_hw hw;
215 uint8_t mode;
216 + struct ext_clk_rates clk_rates;
217 };
218
219 #define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
220
221 +static const struct ext_clk_rates hifiberry_dacpro_clks = {
222 + .clk_44en = 22579200UL,
223 + .clk_48en = 24576000UL,
224 +};
225 +
226 +static const struct ext_clk_rates allo_dac_clks = {
227 + .clk_44en = 45158400UL,
228 + .clk_48en = 49152000UL,
229 +};
230 +
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 },
235 { }
236 };
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)
241 {
242 - return (to_hifiberry_clk(hw)->mode == 0) ? CLK_44EN_RATE :
243 - CLK_48EN_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;
247 }
248
249 static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
250 unsigned long rate, unsigned long *parent_rate)
251 {
252 + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
253 long actual_rate;
254
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;
263 } else {
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);
268
269 if (diff44Rate < diff48Rate)
270 - actual_rate = (long)CLK_44EN_RATE;
271 + actual_rate = (long)clk->clk_rates.clk_44en;
272 else
273 - actual_rate = (long)CLK_48EN_RATE;
274 + actual_rate = (long)clk->clk_rates.clk_48en;
275 }
276 return actual_rate;
277 }
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)
281 {
282 - unsigned long actual_rate;
283 struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
284 + unsigned long actual_rate;
285
286 actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
287 &parent_rate);
288 - clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
289 + clk->mode = (actual_rate == clk->clk_rates.clk_44en) ? 0 : 1;
290 return 0;
291 }
292
293 @@ -95,13 +111,17 @@ const struct clk_ops clk_hifiberry_dacpr
294
295 static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
296 {
297 - int ret;
298 + const struct of_device_id *of_id;
299 struct clk_hifiberry_hw *proclk;
300 struct clk *clk;
301 struct device *dev;
302 struct clk_init_data init;
303 + int ret;
304
305 dev = &pdev->dev;
306 + of_id = of_match_node(clk_hifiberry_dacpro_dt_ids, dev->of_node);
307 + if (!of_id)
308 + return -EINVAL;
309
310 proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
311 if (!proclk)
312 @@ -115,6 +135,7 @@ static int clk_hifiberry_dacpro_probe(st
313
314 proclk->mode = 0;
315 proclk->hw.init = &init;
316 + memcpy(&proclk->clk_rates, of_id->data, sizeof(proclk->clk_rates));
317
318 clk = devm_clk_register(dev, &proclk->hw);
319 if (!IS_ERR(clk)) {
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
327 help
328 Say Y or M if you want to add support for Allo Boss DAC.
329