Skip to content

Commit e98839f

Browse files
Aidan MacDonaldbebarino
authored andcommitted
clk: ingenic-tcu: Fix missing TCU clock for X1000 SoCs
The TCU clock gate on X1000 wasn't requested by the driver and could be gated automatically later on in boot, which prevents timers from running and breaks PWM. Add a workaround to support old device trees that don't specify the "tcu" clock gate. In this case the kernel will print a warning and attempt to continue without the clock, which is wrong, but it could work if "clk_ignore_unused" is in the kernel arguments. Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com> Link: https://lore.kernel.org/r/20220412122750.279058-3-aidanmacdonald.0x0@gmail.com Reviewed-by: Paul Cercueil <paul@crapouillou.net> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 2b0f3d7 commit e98839f

1 file changed

Lines changed: 25 additions & 10 deletions

File tree

drivers/clk/ingenic/tcu.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct ingenic_soc_info {
3131
unsigned int num_channels;
3232
bool has_ost;
3333
bool has_tcu_clk;
34+
bool allow_missing_tcu_clk;
3435
};
3536

3637
struct ingenic_tcu_clk_info {
@@ -320,7 +321,8 @@ static const struct ingenic_soc_info jz4770_soc_info = {
320321
static const struct ingenic_soc_info x1000_soc_info = {
321322
.num_channels = 8,
322323
.has_ost = false, /* X1000 has OST, but it not belong TCU */
323-
.has_tcu_clk = false,
324+
.has_tcu_clk = true,
325+
.allow_missing_tcu_clk = true,
324326
};
325327

326328
static const struct of_device_id __maybe_unused ingenic_tcu_of_match[] __initconst = {
@@ -355,14 +357,27 @@ static int __init ingenic_tcu_probe(struct device_node *np)
355357
tcu->clk = of_clk_get_by_name(np, "tcu");
356358
if (IS_ERR(tcu->clk)) {
357359
ret = PTR_ERR(tcu->clk);
358-
pr_crit("Cannot get TCU clock\n");
359-
goto err_free_tcu;
360-
}
361360

362-
ret = clk_prepare_enable(tcu->clk);
363-
if (ret) {
364-
pr_crit("Unable to enable TCU clock\n");
365-
goto err_put_clk;
361+
/*
362+
* Old device trees for some SoCs did not include the
363+
* TCU clock because this driver (incorrectly) didn't
364+
* use it. In this case we complain loudly and attempt
365+
* to continue without the clock, which might work if
366+
* booting with workarounds like "clk_ignore_unused".
367+
*/
368+
if (tcu->soc_info->allow_missing_tcu_clk && ret == -EINVAL) {
369+
pr_warn("TCU clock missing from device tree, please update your device tree\n");
370+
tcu->clk = NULL;
371+
} else {
372+
pr_crit("Cannot get TCU clock from device tree\n");
373+
goto err_free_tcu;
374+
}
375+
} else {
376+
ret = clk_prepare_enable(tcu->clk);
377+
if (ret) {
378+
pr_crit("Unable to enable TCU clock\n");
379+
goto err_put_clk;
380+
}
366381
}
367382
}
368383

@@ -432,10 +447,10 @@ static int __init ingenic_tcu_probe(struct device_node *np)
432447
clk_hw_unregister(tcu->clocks->hws[i]);
433448
kfree(tcu->clocks);
434449
err_clk_disable:
435-
if (tcu->soc_info->has_tcu_clk)
450+
if (tcu->clk)
436451
clk_disable_unprepare(tcu->clk);
437452
err_put_clk:
438-
if (tcu->soc_info->has_tcu_clk)
453+
if (tcu->clk)
439454
clk_put(tcu->clk);
440455
err_free_tcu:
441456
kfree(tcu);

0 commit comments

Comments
 (0)