Skip to content

Commit f6f73b8

Browse files
prabhakarladgeertu
authored andcommitted
clk: renesas: rzg2l-cpg: Refactor Runtime PM clock validation
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]>
1 parent 2014c95 commit f6f73b8

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
@@ -1538,28 +1538,6 @@ static int rzg2l_cpg_reset_controller_register(struct rzg2l_cpg_priv *priv)
15381538
return devm_reset_controller_register(priv->dev, &priv->rcdev);
15391539
}
15401540

1541-
static bool rzg2l_cpg_is_pm_clk(struct rzg2l_cpg_priv *priv,
1542-
const struct of_phandle_args *clkspec)
1543-
{
1544-
const struct rzg2l_cpg_info *info = priv->info;
1545-
unsigned int id;
1546-
unsigned int i;
1547-
1548-
if (clkspec->args_count != 2)
1549-
return false;
1550-
1551-
if (clkspec->args[0] != CPG_MOD)
1552-
return false;
1553-
1554-
id = clkspec->args[1] + info->num_total_core_clks;
1555-
for (i = 0; i < info->num_no_pm_mod_clks; i++) {
1556-
if (info->no_pm_mod_clks[i] == id)
1557-
return false;
1558-
}
1559-
1560-
return true;
1561-
}
1562-
15631541
/**
15641542
* struct rzg2l_cpg_pm_domains - RZ/G2L PM domains data structure
15651543
* @onecell_data: cell data
@@ -1584,45 +1562,73 @@ struct rzg2l_cpg_pd {
15841562
u16 id;
15851563
};
15861564

1565+
static bool rzg2l_cpg_is_pm_clk(struct rzg2l_cpg_pd *pd,
1566+
const struct of_phandle_args *clkspec)
1567+
{
1568+
if (clkspec->np != pd->genpd.dev.of_node || clkspec->args_count != 2)
1569+
return false;
1570+
1571+
switch (clkspec->args[0]) {
1572+
case CPG_MOD: {
1573+
struct rzg2l_cpg_priv *priv = pd->priv;
1574+
const struct rzg2l_cpg_info *info = priv->info;
1575+
unsigned int id = clkspec->args[1];
1576+
1577+
if (id >= priv->num_mod_clks)
1578+
return false;
1579+
1580+
id += info->num_total_core_clks;
1581+
1582+
for (unsigned int i = 0; i < info->num_no_pm_mod_clks; i++) {
1583+
if (info->no_pm_mod_clks[i] == id)
1584+
return false;
1585+
}
1586+
1587+
return true;
1588+
}
1589+
1590+
case CPG_CORE:
1591+
default:
1592+
return false;
1593+
}
1594+
}
1595+
15871596
static int rzg2l_cpg_attach_dev(struct generic_pm_domain *domain, struct device *dev)
15881597
{
15891598
struct rzg2l_cpg_pd *pd = container_of(domain, struct rzg2l_cpg_pd, genpd);
1590-
struct rzg2l_cpg_priv *priv = pd->priv;
15911599
struct device_node *np = dev->of_node;
15921600
struct of_phandle_args clkspec;
15931601
bool once = true;
15941602
struct clk *clk;
1603+
unsigned int i;
15951604
int error;
1596-
int i = 0;
1597-
1598-
while (!of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
1599-
&clkspec)) {
1600-
if (rzg2l_cpg_is_pm_clk(priv, &clkspec)) {
1601-
if (once) {
1602-
once = false;
1603-
error = pm_clk_create(dev);
1604-
if (error) {
1605-
of_node_put(clkspec.np);
1606-
goto err;
1607-
}
1608-
}
1609-
clk = of_clk_get_from_provider(&clkspec);
1605+
1606+
for (i = 0; !of_parse_phandle_with_args(np, "clocks", "#clock-cells", i, &clkspec); i++) {
1607+
if (!rzg2l_cpg_is_pm_clk(pd, &clkspec)) {
16101608
of_node_put(clkspec.np);
1611-
if (IS_ERR(clk)) {
1612-
error = PTR_ERR(clk);
1613-
goto fail_destroy;
1614-
}
1609+
continue;
1610+
}
16151611

1616-
error = pm_clk_add_clk(dev, clk);
1612+
if (once) {
1613+
once = false;
1614+
error = pm_clk_create(dev);
16171615
if (error) {
1618-
dev_err(dev, "pm_clk_add_clk failed %d\n",
1619-
error);
1620-
goto fail_put;
1616+
of_node_put(clkspec.np);
1617+
goto err;
16211618
}
1622-
} else {
1623-
of_node_put(clkspec.np);
16241619
}
1625-
i++;
1620+
clk = of_clk_get_from_provider(&clkspec);
1621+
of_node_put(clkspec.np);
1622+
if (IS_ERR(clk)) {
1623+
error = PTR_ERR(clk);
1624+
goto fail_destroy;
1625+
}
1626+
1627+
error = pm_clk_add_clk(dev, clk);
1628+
if (error) {
1629+
dev_err(dev, "pm_clk_add_clk failed %d\n", error);
1630+
goto fail_put;
1631+
}
16261632
}
16271633

16281634
return 0;

0 commit comments

Comments
 (0)