Skip to content

Commit 21ed19d

Browse files
committed
clk: amlogic: get regmap with clk_regmap_init
Add clk_regmap_init() and use it with all clock types which derive from clk_regmap. This helps initialise clk_regmap clocks without requiring tables to keep track of the clock using this type. The way it is done couples clk_regmap with the controllers, which is not ideal. This is a temporary solution to get rid of the tables. The situation will eventually be improved. Link: https://lore.kernel.org/r/20250623-amlogic-clk-drop-clk-regmap-tables-v4-1-ff04918211cc@baylibre.com Signed-off-by: Jerome Brunet <[email protected]>
1 parent 328d4a7 commit 21ed19d

File tree

11 files changed

+89
-0
lines changed

11 files changed

+89
-0
lines changed

drivers/clk/meson/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ menu "Clock support for Amlogic platforms"
55
config COMMON_CLK_MESON_REGMAP
66
tristate
77
select REGMAP
8+
select MFD_SYSCON
89

910
config COMMON_CLK_MESON_DUALDIV
1011
tristate

drivers/clk/meson/clk-cpu-dyndiv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static int meson_clk_cpu_dyndiv_set_rate(struct clk_hw *hw, unsigned long rate,
6161
};
6262

6363
const struct clk_ops meson_clk_cpu_dyndiv_ops = {
64+
.init = clk_regmap_init,
6465
.recalc_rate = meson_clk_cpu_dyndiv_recalc_rate,
6566
.determine_rate = meson_clk_cpu_dyndiv_determine_rate,
6667
.set_rate = meson_clk_cpu_dyndiv_set_rate,

drivers/clk/meson/clk-dualdiv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,15 @@ static int meson_clk_dualdiv_set_rate(struct clk_hw *hw, unsigned long rate,
126126
}
127127

128128
const struct clk_ops meson_clk_dualdiv_ops = {
129+
.init = clk_regmap_init,
129130
.recalc_rate = meson_clk_dualdiv_recalc_rate,
130131
.determine_rate = meson_clk_dualdiv_determine_rate,
131132
.set_rate = meson_clk_dualdiv_set_rate,
132133
};
133134
EXPORT_SYMBOL_NS_GPL(meson_clk_dualdiv_ops, "CLK_MESON");
134135

135136
const struct clk_ops meson_clk_dualdiv_ro_ops = {
137+
.init = clk_regmap_init,
136138
.recalc_rate = meson_clk_dualdiv_recalc_rate,
137139
};
138140
EXPORT_SYMBOL_NS_GPL(meson_clk_dualdiv_ro_ops, "CLK_MESON");

drivers/clk/meson/clk-mpll.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ static int mpll_init(struct clk_hw *hw)
128128
{
129129
struct clk_regmap *clk = to_clk_regmap(hw);
130130
struct meson_clk_mpll_data *mpll = meson_clk_mpll_data(clk);
131+
int ret;
132+
133+
ret = clk_regmap_init(hw);
134+
if (ret)
135+
return ret;
131136

132137
if (mpll->init_count)
133138
regmap_multi_reg_write(clk->map, mpll->init_regs,
@@ -151,6 +156,7 @@ static int mpll_init(struct clk_hw *hw)
151156
}
152157

153158
const struct clk_ops meson_clk_mpll_ro_ops = {
159+
.init = clk_regmap_init,
154160
.recalc_rate = mpll_recalc_rate,
155161
.determine_rate = mpll_determine_rate,
156162
};

drivers/clk/meson/clk-phase.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static int meson_clk_phase_set_phase(struct clk_hw *hw, int degrees)
5858
}
5959

6060
const struct clk_ops meson_clk_phase_ops = {
61+
.init = clk_regmap_init,
6162
.get_phase = meson_clk_phase_get_phase,
6263
.set_phase = meson_clk_phase_set_phase,
6364
};
@@ -83,6 +84,11 @@ static int meson_clk_triphase_sync(struct clk_hw *hw)
8384
struct clk_regmap *clk = to_clk_regmap(hw);
8485
struct meson_clk_triphase_data *tph = meson_clk_triphase_data(clk);
8586
unsigned int val;
87+
int ret;
88+
89+
ret = clk_regmap_init(hw);
90+
if (ret)
91+
return ret;
8692

8793
/* Get phase 0 and sync it to phase 1 and 2 */
8894
val = meson_parm_read(clk->map, &tph->ph0);
@@ -142,6 +148,11 @@ static int meson_sclk_ws_inv_sync(struct clk_hw *hw)
142148
struct clk_regmap *clk = to_clk_regmap(hw);
143149
struct meson_sclk_ws_inv_data *tph = meson_sclk_ws_inv_data(clk);
144150
unsigned int val;
151+
int ret;
152+
153+
ret = clk_regmap_init(hw);
154+
if (ret)
155+
return ret;
145156

146157
/* Get phase and sync the inverted value to ws */
147158
val = meson_parm_read(clk->map, &tph->ph);

drivers/clk/meson/clk-pll.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ static int meson_clk_pll_init(struct clk_hw *hw)
311311
{
312312
struct clk_regmap *clk = to_clk_regmap(hw);
313313
struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
314+
int ret;
315+
316+
ret = clk_regmap_init(hw);
317+
if (ret)
318+
return ret;
314319

315320
/*
316321
* Keep the clock running, which was already initialized and enabled
@@ -468,6 +473,7 @@ static int meson_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
468473
* the other ops except set_rate since the rate is fixed.
469474
*/
470475
const struct clk_ops meson_clk_pcie_pll_ops = {
476+
.init = clk_regmap_init,
471477
.recalc_rate = meson_clk_pll_recalc_rate,
472478
.determine_rate = meson_clk_pll_determine_rate,
473479
.is_enabled = meson_clk_pll_is_enabled,
@@ -488,6 +494,7 @@ const struct clk_ops meson_clk_pll_ops = {
488494
EXPORT_SYMBOL_NS_GPL(meson_clk_pll_ops, "CLK_MESON");
489495

490496
const struct clk_ops meson_clk_pll_ro_ops = {
497+
.init = clk_regmap_init,
491498
.recalc_rate = meson_clk_pll_recalc_rate,
492499
.is_enabled = meson_clk_pll_is_enabled,
493500
};

drivers/clk/meson/clk-regmap.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,52 @@
44
* Author: Jerome Brunet <[email protected]>
55
*/
66

7+
#include <linux/device.h>
78
#include <linux/module.h>
9+
#include <linux/mfd/syscon.h>
810
#include "clk-regmap.h"
911

12+
int clk_regmap_init(struct clk_hw *hw)
13+
{
14+
struct clk_regmap *clk = to_clk_regmap(hw);
15+
struct device_node *np, *parent_np;
16+
struct device *dev;
17+
18+
/* Allow regmap to be preset as it was historically done */
19+
if (clk->map)
20+
return 0;
21+
22+
/*
23+
* FIXME: what follows couples the controller implementation
24+
* and clk_regmap clock type. This situation is not desirable
25+
* but temporary, until the controller is able to register
26+
* a hook to initialize a clock type
27+
*/
28+
29+
/* Check the usual dev enabled controller with an basic IO regmap */
30+
dev = clk_hw_get_dev(hw);
31+
if (dev) {
32+
clk->map = dev_get_regmap(dev, NULL);
33+
if (clk->map)
34+
return 0;
35+
}
36+
37+
/* Move on to early and syscon based controllers */
38+
np = clk_hw_get_of_node(hw);
39+
if (np) {
40+
parent_np = of_get_parent(np);
41+
clk->map = syscon_node_to_regmap(parent_np);
42+
of_node_put(parent_np);
43+
44+
if (!IS_ERR_OR_NULL(clk->map))
45+
return 0;
46+
}
47+
48+
/* Bail out if regmap can't be found */
49+
return -EINVAL;
50+
}
51+
EXPORT_SYMBOL_NS_GPL(clk_regmap_init, "CLK_MESON");
52+
1053
static int clk_regmap_gate_endisable(struct clk_hw *hw, int enable)
1154
{
1255
struct clk_regmap *clk = to_clk_regmap(hw);
@@ -45,13 +88,15 @@ static int clk_regmap_gate_is_enabled(struct clk_hw *hw)
4588
}
4689

4790
const struct clk_ops clk_regmap_gate_ops = {
91+
.init = clk_regmap_init,
4892
.enable = clk_regmap_gate_enable,
4993
.disable = clk_regmap_gate_disable,
5094
.is_enabled = clk_regmap_gate_is_enabled,
5195
};
5296
EXPORT_SYMBOL_NS_GPL(clk_regmap_gate_ops, "CLK_MESON");
5397

5498
const struct clk_ops clk_regmap_gate_ro_ops = {
99+
.init = clk_regmap_init,
55100
.is_enabled = clk_regmap_gate_is_enabled,
56101
};
57102
EXPORT_SYMBOL_NS_GPL(clk_regmap_gate_ro_ops, "CLK_MESON");
@@ -121,13 +166,15 @@ static int clk_regmap_div_set_rate(struct clk_hw *hw, unsigned long rate,
121166
/* Would prefer clk_regmap_div_ro_ops but clashes with qcom */
122167

123168
const struct clk_ops clk_regmap_divider_ops = {
169+
.init = clk_regmap_init,
124170
.recalc_rate = clk_regmap_div_recalc_rate,
125171
.determine_rate = clk_regmap_div_determine_rate,
126172
.set_rate = clk_regmap_div_set_rate,
127173
};
128174
EXPORT_SYMBOL_NS_GPL(clk_regmap_divider_ops, "CLK_MESON");
129175

130176
const struct clk_ops clk_regmap_divider_ro_ops = {
177+
.init = clk_regmap_init,
131178
.recalc_rate = clk_regmap_div_recalc_rate,
132179
.determine_rate = clk_regmap_div_determine_rate,
133180
};
@@ -170,13 +217,15 @@ static int clk_regmap_mux_determine_rate(struct clk_hw *hw,
170217
}
171218

172219
const struct clk_ops clk_regmap_mux_ops = {
220+
.init = clk_regmap_init,
173221
.get_parent = clk_regmap_mux_get_parent,
174222
.set_parent = clk_regmap_mux_set_parent,
175223
.determine_rate = clk_regmap_mux_determine_rate,
176224
};
177225
EXPORT_SYMBOL_NS_GPL(clk_regmap_mux_ops, "CLK_MESON");
178226

179227
const struct clk_ops clk_regmap_mux_ro_ops = {
228+
.init = clk_regmap_init,
180229
.get_parent = clk_regmap_mux_get_parent,
181230
};
182231
EXPORT_SYMBOL_NS_GPL(clk_regmap_mux_ro_ops, "CLK_MESON");

drivers/clk/meson/clk-regmap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef __CLK_REGMAP_H
88
#define __CLK_REGMAP_H
99

10+
#include <linux/device.h>
1011
#include <linux/clk-provider.h>
1112
#include <linux/regmap.h>
1213

@@ -31,6 +32,9 @@ static inline struct clk_regmap *to_clk_regmap(struct clk_hw *hw)
3132
return container_of(hw, struct clk_regmap, hw);
3233
}
3334

35+
/* clk_regmap init op to get and cache regmap from the controllers */
36+
int clk_regmap_init(struct clk_hw *hw);
37+
3438
/**
3539
* struct clk_regmap_gate_data - regmap backed gate specific data
3640
*

drivers/clk/meson/sclk-div.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ static int sclk_div_init(struct clk_hw *hw)
222222
struct clk_regmap *clk = to_clk_regmap(hw);
223223
struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk);
224224
unsigned int val;
225+
int ret;
226+
227+
ret = clk_regmap_init(hw);
228+
if (ret)
229+
return ret;
225230

226231
val = meson_parm_read(clk->map, &sclk->div);
227232

drivers/clk/meson/vclk.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static int meson_vclk_gate_is_enabled(struct clk_hw *hw)
4545
}
4646

4747
const struct clk_ops meson_vclk_gate_ops = {
48+
.init = clk_regmap_init,
4849
.enable = meson_vclk_gate_enable,
4950
.disable = meson_vclk_gate_disable,
5051
.is_enabled = meson_vclk_gate_is_enabled,
@@ -127,6 +128,7 @@ static int meson_vclk_div_is_enabled(struct clk_hw *hw)
127128
}
128129

129130
const struct clk_ops meson_vclk_div_ops = {
131+
.init = clk_regmap_init,
130132
.recalc_rate = meson_vclk_div_recalc_rate,
131133
.determine_rate = meson_vclk_div_determine_rate,
132134
.set_rate = meson_vclk_div_set_rate,

0 commit comments

Comments
 (0)