clk: mediatek: cpumux: Implement unregister API
authorChen-Yu Tsai <wenst@chromium.org>
Tue, 8 Feb 2022 12:40:09 +0000 (20:40 +0800)
committerStephen Boyd <sboyd@kernel.org>
Thu, 17 Feb 2022 20:12:22 +0000 (12:12 -0800)
The cpumux clk type within the MediaTek clk driver library only has
a register function, and no corresponding unregister function. This
means there is no way for its users to properly implement cleanup
and removal.

Add a matching unregister function for the cpumux type clk.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Miles Chen <miles.chen@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20220208124034.414635-7-wenst@chromium.org
Reviewed-by: Chun-Jie Chen <chun-jie.chen@mediatek.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/mediatek/clk-cpumux.c
drivers/clk/mediatek/clk-cpumux.h

index cab5095416b6befc869d09aa8e443746d9df5f89..99a819e3673fad42e0ae6e2f11cab6c11c2aa818 100644 (file)
@@ -77,6 +77,21 @@ mtk_clk_register_cpumux(const struct mtk_composite *mux,
        return clk;
 }
 
+static void mtk_clk_unregister_cpumux(struct clk *clk)
+{
+       struct mtk_clk_cpumux *cpumux;
+       struct clk_hw *hw;
+
+       hw = __clk_get_hw(clk);
+       if (!hw)
+               return;
+
+       cpumux = to_mtk_clk_cpumux(hw);
+
+       clk_unregister(clk);
+       kfree(cpumux);
+}
+
 int mtk_clk_register_cpumuxes(struct device_node *node,
                              const struct mtk_composite *clks, int num,
                              struct clk_onecell_data *clk_data)
@@ -106,4 +121,20 @@ int mtk_clk_register_cpumuxes(struct device_node *node,
        return 0;
 }
 
+void mtk_clk_unregister_cpumuxes(const struct mtk_composite *clks, int num,
+                                struct clk_onecell_data *clk_data)
+{
+       int i;
+
+       for (i = num; i > 0; i--) {
+               const struct mtk_composite *mux = &clks[i - 1];
+
+               if (IS_ERR_OR_NULL(clk_data->clks[mux->id]))
+                       continue;
+
+               mtk_clk_unregister_cpumux(clk_data->clks[mux->id]);
+               clk_data->clks[mux->id] = ERR_PTR(-ENOENT);
+       }
+}
+
 MODULE_LICENSE("GPL");
index 2aaf1afd4e5f133259fe5b372ff417a2d6f52211..fda7770fd803b6eb48e343035e2ecec97a7eaa4e 100644 (file)
@@ -19,4 +19,7 @@ int mtk_clk_register_cpumuxes(struct device_node *node,
                              const struct mtk_composite *clks, int num,
                              struct clk_onecell_data *clk_data);
 
+void mtk_clk_unregister_cpumuxes(const struct mtk_composite *clks, int num,
+                                struct clk_onecell_data *clk_data);
+
 #endif /* __DRV_CLK_CPUMUX_H */