Skip to content

Commit e41c7cc

Browse files
GuEe-GUIRbb666
authored andcommitted
[dm][clk][rockchip] fixup rockchip clk
Signed-off-by: GuEe-GUI <2991707448@qq.com>
1 parent 2529550 commit e41c7cc

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

bsp/rockchip/dm/clk/clk-rk-gate.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@
2727
.gate_flags = gf, \
2828
}
2929

30+
#define GATE_NO_SET_RATE(_id, cname, pname, f, o, b, gf) \
31+
(void *)&(struct rockchip_clk_cell) \
32+
{ \
33+
.cell.name = cname, \
34+
.cell.ops = &rockchip_gate_clk_ops, \
35+
.cell.parent_name = pname, \
36+
.cell.parents_nr = 1, \
37+
.cell.flags = f | RT_CLK_F_SET_RATE_PARENT, \
38+
.id = _id, \
39+
.gate_offset = o, \
40+
.gate_shift = b, \
41+
.gate_flags = gf, \
42+
}
43+
3044
extern const struct rt_clk_ops rockchip_gate_clk_ops;
3145

3246
#endif /* __CLK_RK_GATE_H__ */

bsp/rockchip/dm/clk/clk-rk-half-divider.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct rockchip_half_divider_clk_cell
6363
.rk_cell.init = rockchip_half_divider_clk_cell_init,\
6464
}
6565

66-
#define COMPOSITE_NOGATE_HALFDIV(_id, cname, pnames, f, mo, ms, mw, mf, ds, dw, df) \
66+
#define COMPOSITE_NOGATE_HALFDIV(_id, cname, pnames, f, mo, ms, mw, mf, ds, dw, df) \
6767
(void *)&(struct rockchip_half_divider_clk_cell) \
6868
{ \
6969
.rk_cell.cell.name = cname, \
@@ -82,7 +82,8 @@ struct rockchip_half_divider_clk_cell
8282
.rk_cell.init = rockchip_half_divider_clk_cell_init,\
8383
}
8484

85-
#define COMPOSITE_NOMUX_HALFDIV(_id, cname, pname, f, mo, ds, dw, df, go, gs, gf) \
85+
#define COMPOSITE_NOMUX_HALFDIV(_id, cname, pname, f, mo, ds, dw, df, go, gs, gf) \
86+
(void *)&(struct rockchip_half_divider_clk_cell) \
8687
{ \
8788
.rk_cell.cell.name = cname, \
8889
.rk_cell.cell.parent_name = pname, \

components/drivers/clk/clk-scmi.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static rt_err_t scmi_clk_probe(struct rt_scmi_device *sdev)
230230
for (int id = 0; id < cell_count; ++id)
231231
{
232232
const char *clk_name;
233-
rt_uint32_t flags, rates_nr, rate_discrete;
233+
rt_uint32_t flags, rate_discrete;
234234

235235
in.id = rt_cpu_to_le32(id);
236236
in.rate_index = rt_cpu_to_le32(0);
@@ -242,7 +242,6 @@ static rt_err_t scmi_clk_probe(struct rt_scmi_device *sdev)
242242
}
243243

244244
flags = rt_le32_to_cpu(out->num_rates_flags);
245-
rates_nr = SCMI_NUM_REMAINING(flags);
246245
rate_discrete = SCMI_RATE_DISCRETE(flags);
247246

248247
if (rate_discrete)
@@ -263,12 +262,40 @@ static rt_err_t scmi_clk_probe(struct rt_scmi_device *sdev)
263262

264263
if (rate_discrete)
265264
{
266-
for (int i = 0; i < rates_nr; ++i)
265+
/*
266+
* SCMI: [11:0] = rates in this message, [31:16] = remaining to query.
267+
* Using REMAINING as the copy count overflows rates[] and corrupts heap.
268+
*/
269+
int idx = 0;
270+
271+
for (;;)
267272
{
268-
clk_data->info.list.rates[i] = SCMI_RATE_TO_U64(out->rate[i]);
273+
rt_uint32_t nr = SCMI_NUM_RETURNED(flags);
274+
rt_uint32_t remaining = SCMI_NUM_REMAINING(flags);
275+
276+
for (rt_uint32_t i = 0; i < nr && idx < SCMI_MAX_NUM_RATES; ++i, ++idx)
277+
{
278+
clk_data->info.list.rates[idx] = SCMI_RATE_TO_U64(out->rate[i]);
279+
}
280+
281+
if (remaining == 0 || idx >= SCMI_MAX_NUM_RATES)
282+
{
283+
break;
284+
}
285+
286+
in.rate_index = rt_cpu_to_le32(idx);
287+
msg = RT_SCMI_MSG_RAW(SCMI_CLOCK_DESCRIBE_RATES, &in, sizeof(in), out, out_size);
288+
289+
if ((err = rt_scmi_process_msg(sclk->sdev, &msg)))
290+
{
291+
rt_free(clk_data);
292+
goto _fail;
293+
}
294+
295+
flags = rt_le32_to_cpu(out->num_rates_flags);
269296
}
270297

271-
clk_data->info.list.rates_nr = rates_nr;
298+
clk_data->info.list.rates_nr = idx;
272299
}
273300
else
274301
{

0 commit comments

Comments
 (0)