MLK-17367 imx8: pm-domains: fix restore parent for clk_stat_may_lost case
authorDong Aisheng <aisheng.dong@nxp.com>
Fri, 12 Jan 2018 10:38:09 +0000 (18:38 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Tue, 20 Mar 2018 19:52:50 +0000 (14:52 -0500)
imx8_rsrc_clk->parent may be cleared during last probe failure.
So we need explicitly call CLK APIs clk_get_parent to get the cached
parent for the later restore. Otherwise, it may reparent to NULL parent
which results in 0 clk rate.

Fixes: 05caa1390f88cb (" MLK-17363-1 imx8: pm-domain: fix clock parent restore issue after suspend/resume")
Reviewed-by: Anson Huang <anson.huang@nxp.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
drivers/soc/imx/pm-domains.c

index 46de33e..b7ae557 100644 (file)
@@ -147,19 +147,22 @@ static int imx8_pd_power_on(struct generic_pm_domain *domain)
 
                        list_for_each_entry(imx8_rsrc_clk, &pd->clks, node) {
                                clk_stats[i].clk = imx8_rsrc_clk->clk;
-                               clk_stats[i].parent = imx8_rsrc_clk->parent;
+                               clk_stats[i].parent = clk_get_parent(imx8_rsrc_clk->clk);
                                clk_stats[i].rate = clk_hw_get_rate(__clk_get_hw(imx8_rsrc_clk->clk));
                                i++;
                        }
 
-                       for (i = 0; i <= count; i++) {
+                       for (i = 0; i < count; i++) {
                                /* restore parent first */
-                               clk_set_parent(clk_stats[i].clk, clk_stats[i].parent);
-
-                               /* invalid cached rate first by get rate once */
-                               clk_get_rate(clk_stats[i].clk);
-                               /* restore the lost rate */
-                               clk_set_rate(clk_stats[i].clk, clk_stats[i].rate);
+                               if (clk_stats[i].parent)
+                                       clk_set_parent(clk_stats[i].clk, clk_stats[i].parent);
+
+                               if (clk_stats[i].rate) {
+                                       /* invalid cached rate first by get rate once */
+                                       clk_get_rate(clk_stats[i].clk);
+                                       /* restore the lost rate */
+                                       clk_set_rate(clk_stats[i].clk, clk_stats[i].rate);
+                               }
                        }
 
                        kfree(clk_stats);