Skip to content

Commit b494602

Browse files
prabhakarladSasha Levin
authored andcommitted
clk: renesas: rzg2l-cpg: Refactor Runtime PM clock validation
[ Upstream commit f6f73b8 ] Refactor rzg2l_cpg_attach_dev to delegate clock validation for Runtime PM to the updated rzg2l_cpg_is_pm_clk function. Ensure validation of clocks associated with the power domain while excluding external and core clocks. Prevent incorrect Runtime PM management for clocks outside the domain's scope. Update rzg2l_cpg_is_pm_clk to operate on a per-power-domain basis. Verify clkspec.np against the domain's device node, check argument validity, and validate clock type (CPG_MOD). Use the no_pm_mod_clks array to exclude specific clocks from PM management. Signed-off-by: Lad Prabhakar <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 730106b commit b494602

File tree

1 file changed

+54
-48
lines changed

1 file changed

+54
-48
lines changed

drivers/clk/renesas/rzg2l-cpg.c

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,28 +1549,6 @@ static int rzg2l_cpg_reset_controller_register(struct rzg2l_cpg_priv *priv)
15491549
return devm_reset_controller_register(priv->dev, &priv->rcdev);
15501550
}
15511551

1552-
static bool rzg2l_cpg_is_pm_clk(struct rzg2l_cpg_priv *priv,
1553-
const struct of_phandle_args *clkspec)
1554-
{
1555-
const struct rzg2l_cpg_info *info = priv->info;
1556-
unsigned int id;
1557-
unsigned int i;
1558-
1559-
if (clkspec->args_count != 2)
1560-
return false;
1561-
1562-
if (clkspec->args[0] != CPG_MOD)
1563-
return false;
1564-
1565-
id = clkspec->args[1] + info->num_total_core_clks;
1566-
for (i = 0; i < info->num_no_pm_mod_clks; i++) {
1567-
if (info->no_pm_mod_clks[i] == id)
1568-
return false;
1569-
}
1570-
1571-
return true;
1572-
}
1573-
15741552
/**
15751553
* struct rzg2l_cpg_pm_domains - RZ/G2L PM domains data structure
15761554
* @onecell_data: cell data
@@ -1595,45 +1573,73 @@ struct rzg2l_cpg_pd {
15951573
u16 id;
15961574
};
15971575

1576+
static bool rzg2l_cpg_is_pm_clk(struct rzg2l_cpg_pd *pd,
1577+
const struct of_phandle_args *clkspec)
1578+
{
1579+
if (clkspec->np != pd->genpd.dev.of_node || clkspec->args_count != 2)
1580+
return false;
1581+
1582+
switch (clkspec->args[0]) {
1583+
case CPG_MOD: {
1584+
struct rzg2l_cpg_priv *priv = pd->priv;
1585+
const struct rzg2l_cpg_info *info = priv->info;
1586+
unsigned int id = clkspec->args[1];
1587+
1588+
if (id >= priv->num_mod_clks)
1589+
return false;
1590+
1591+
id += info->num_total_core_clks;
1592+
1593+
for (unsigned int i = 0; i < info->num_no_pm_mod_clks; i++) {
1594+
if (info->no_pm_mod_clks[i] == id)
1595+
return false;
1596+
}
1597+
1598+
return true;
1599+
}
1600+
1601+
case CPG_CORE:
1602+
default:
1603+
return false;
1604+
}
1605+
}
1606+
15981607
static int rzg2l_cpg_attach_dev(struct generic_pm_domain *domain, struct device *dev)
15991608
{
16001609
struct rzg2l_cpg_pd *pd = container_of(domain, struct rzg2l_cpg_pd, genpd);
1601-
struct rzg2l_cpg_priv *priv = pd->priv;
16021610
struct device_node *np = dev->of_node;
16031611
struct of_phandle_args clkspec;
16041612
bool once = true;
16051613
struct clk *clk;
1614+
unsigned int i;
16061615
int error;
1607-
int i = 0;
1608-
1609-
while (!of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
1610-
&clkspec)) {
1611-
if (rzg2l_cpg_is_pm_clk(priv, &clkspec)) {
1612-
if (once) {
1613-
once = false;
1614-
error = pm_clk_create(dev);
1615-
if (error) {
1616-
of_node_put(clkspec.np);
1617-
goto err;
1618-
}
1619-
}
1620-
clk = of_clk_get_from_provider(&clkspec);
1616+
1617+
for (i = 0; !of_parse_phandle_with_args(np, "clocks", "#clock-cells", i, &clkspec); i++) {
1618+
if (!rzg2l_cpg_is_pm_clk(pd, &clkspec)) {
16211619
of_node_put(clkspec.np);
1622-
if (IS_ERR(clk)) {
1623-
error = PTR_ERR(clk);
1624-
goto fail_destroy;
1625-
}
1620+
continue;
1621+
}
16261622

1627-
error = pm_clk_add_clk(dev, clk);
1623+
if (once) {
1624+
once = false;
1625+
error = pm_clk_create(dev);
16281626
if (error) {
1629-
dev_err(dev, "pm_clk_add_clk failed %d\n",
1630-
error);
1631-
goto fail_put;
1627+
of_node_put(clkspec.np);
1628+
goto err;
16321629
}
1633-
} else {
1634-
of_node_put(clkspec.np);
16351630
}
1636-
i++;
1631+
clk = of_clk_get_from_provider(&clkspec);
1632+
of_node_put(clkspec.np);
1633+
if (IS_ERR(clk)) {
1634+
error = PTR_ERR(clk);
1635+
goto fail_destroy;
1636+
}
1637+
1638+
error = pm_clk_add_clk(dev, clk);
1639+
if (error) {
1640+
dev_err(dev, "pm_clk_add_clk failed %d\n", error);
1641+
goto fail_put;
1642+
}
16371643
}
16381644

16391645
return 0;

0 commit comments

Comments
 (0)