Skip to content

Commit 853a7a6

Browse files
committed
Merge tag 'thead-clk-for-v6.17-p2' of git://git.kernel.org/pub/scm/linux/kernel/git/fustini/linux into clk-thead
Pull one more T-HEAD clk driver update from Drew Fustini: Yao Zi has fixed an issue where the c910 mux clk could end up as an orphan in CCF when the bootloader reparents it to the c910-i0 mux clk. The solution is to refactor the handling of mux clocks by embedding a clk_mux structure directly in ccu_mux. This allows the mux clocks to be registered with devm_clk_hw_register() without allocating any new clk_hw pointer which solves the orphan issue. This change has been tested in linux-next. The LPi4a still boots okay without clk_ignore_unused and peripherals like serial, emmc and ethernet are functional. The file /sys/kernel/debug/clk/c910/clk_possible_parents now correctly outputs: "c910-i0 cpu-pll1" * tag 'thead-clk-for-v6.17-p2' of git://git.kernel.org/pub/scm/linux/kernel/git/fustini/linux: clk: thead: th1520-ap: Describe mux clocks with clk_mux
2 parents ab8cfde + 54edba9 commit 853a7a6

File tree

1 file changed

+37
-58
lines changed

1 file changed

+37
-58
lines changed

drivers/clk/thead/clk-th1520-ap.c

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ struct ccu_common {
4242
};
4343

4444
struct ccu_mux {
45-
struct ccu_internal mux;
46-
struct ccu_common common;
45+
int clkid;
46+
u32 reg;
47+
struct clk_mux mux;
4748
};
4849

4950
struct ccu_gate {
@@ -75,6 +76,17 @@ struct ccu_pll {
7576
.flags = _flags, \
7677
}
7778

79+
#define TH_CCU_MUX(_name, _parents, _shift, _width) \
80+
{ \
81+
.mask = GENMASK(_width - 1, 0), \
82+
.shift = _shift, \
83+
.hw.init = CLK_HW_INIT_PARENTS_DATA( \
84+
_name, \
85+
_parents, \
86+
&clk_mux_ops, \
87+
0), \
88+
}
89+
7890
#define CCU_GATE(_clkid, _struct, _name, _parent, _reg, _gate, _flags) \
7991
struct ccu_gate _struct = { \
8092
.enable = _gate, \
@@ -94,13 +106,6 @@ static inline struct ccu_common *hw_to_ccu_common(struct clk_hw *hw)
94106
return container_of(hw, struct ccu_common, hw);
95107
}
96108

97-
static inline struct ccu_mux *hw_to_ccu_mux(struct clk_hw *hw)
98-
{
99-
struct ccu_common *common = hw_to_ccu_common(hw);
100-
101-
return container_of(common, struct ccu_mux, common);
102-
}
103-
104109
static inline struct ccu_pll *hw_to_ccu_pll(struct clk_hw *hw)
105110
{
106111
struct ccu_common *common = hw_to_ccu_common(hw);
@@ -415,32 +420,20 @@ static const struct clk_parent_data c910_i0_parents[] = {
415420
};
416421

417422
static struct ccu_mux c910_i0_clk = {
418-
.mux = TH_CCU_ARG(1, 1),
419-
.common = {
420-
.clkid = CLK_C910_I0,
421-
.cfg0 = 0x100,
422-
.hw.init = CLK_HW_INIT_PARENTS_DATA("c910-i0",
423-
c910_i0_parents,
424-
&clk_mux_ops,
425-
0),
426-
}
423+
.clkid = CLK_C910_I0,
424+
.reg = 0x100,
425+
.mux = TH_CCU_MUX("c910-i0", c910_i0_parents, 1, 1),
427426
};
428427

429428
static const struct clk_parent_data c910_parents[] = {
430-
{ .hw = &c910_i0_clk.common.hw },
429+
{ .hw = &c910_i0_clk.mux.hw },
431430
{ .hw = &cpu_pll1_clk.common.hw }
432431
};
433432

434433
static struct ccu_mux c910_clk = {
435-
.mux = TH_CCU_ARG(0, 1),
436-
.common = {
437-
.clkid = CLK_C910,
438-
.cfg0 = 0x100,
439-
.hw.init = CLK_HW_INIT_PARENTS_DATA("c910",
440-
c910_parents,
441-
&clk_mux_ops,
442-
0),
443-
}
434+
.clkid = CLK_C910,
435+
.reg = 0x100,
436+
.mux = TH_CCU_MUX("c910", c910_parents, 0, 1),
444437
};
445438

446439
static const struct clk_parent_data ahb2_cpusys_parents[] = {
@@ -925,15 +918,9 @@ static const struct clk_parent_data uart_sclk_parents[] = {
925918
};
926919

927920
static struct ccu_mux uart_sclk = {
928-
.mux = TH_CCU_ARG(0, 1),
929-
.common = {
930-
.clkid = CLK_UART_SCLK,
931-
.cfg0 = 0x210,
932-
.hw.init = CLK_HW_INIT_PARENTS_DATA("uart-sclk",
933-
uart_sclk_parents,
934-
&clk_mux_ops,
935-
0),
936-
}
921+
.clkid = CLK_UART_SCLK,
922+
.reg = 0x210,
923+
.mux = TH_CCU_MUX("uart-sclk", uart_sclk_parents, 0, 1),
937924
};
938925

939926
static struct ccu_common *th1520_pll_clks[] = {
@@ -970,10 +957,10 @@ static struct ccu_common *th1520_div_clks[] = {
970957
&dpu1_clk.common,
971958
};
972959

973-
static struct ccu_common *th1520_mux_clks[] = {
974-
&c910_i0_clk.common,
975-
&c910_clk.common,
976-
&uart_sclk.common,
960+
static struct ccu_mux *th1520_mux_clks[] = {
961+
&c910_i0_clk,
962+
&c910_clk,
963+
&uart_sclk,
977964
};
978965

979966
static struct ccu_common *th1520_gate_clks[] = {
@@ -1075,7 +1062,7 @@ static const struct regmap_config th1520_clk_regmap_config = {
10751062
struct th1520_plat_data {
10761063
struct ccu_common **th1520_pll_clks;
10771064
struct ccu_common **th1520_div_clks;
1078-
struct ccu_common **th1520_mux_clks;
1065+
struct ccu_mux **th1520_mux_clks;
10791066
struct ccu_common **th1520_gate_clks;
10801067

10811068
int nr_clks;
@@ -1162,23 +1149,15 @@ static int th1520_clk_probe(struct platform_device *pdev)
11621149
}
11631150

11641151
for (i = 0; i < plat_data->nr_mux_clks; i++) {
1165-
struct ccu_mux *cm = hw_to_ccu_mux(&plat_data->th1520_mux_clks[i]->hw);
1166-
const struct clk_init_data *init = cm->common.hw.init;
1167-
1168-
plat_data->th1520_mux_clks[i]->map = map;
1169-
hw = devm_clk_hw_register_mux_parent_data_table(dev,
1170-
init->name,
1171-
init->parent_data,
1172-
init->num_parents,
1173-
0,
1174-
base + cm->common.cfg0,
1175-
cm->mux.shift,
1176-
cm->mux.width,
1177-
0, NULL, NULL);
1178-
if (IS_ERR(hw))
1179-
return PTR_ERR(hw);
1152+
struct ccu_mux *cm = plat_data->th1520_mux_clks[i];
1153+
1154+
cm->mux.reg = base + cm->reg;
1155+
1156+
ret = devm_clk_hw_register(dev, &cm->mux.hw);
1157+
if (ret)
1158+
return ret;
11801159

1181-
priv->hws[cm->common.clkid] = hw;
1160+
priv->hws[cm->clkid] = &cm->mux.hw;
11821161
}
11831162

11841163
for (i = 0; i < plat_data->nr_gate_clks; i++) {

0 commit comments

Comments
 (0)