Skip to content

Commit cb50864

Browse files
wensbebarino
authored andcommitted
clk: mediatek: Implement mtk_clk_unregister_composites() API
mtk_clk_register_composites(), as the name suggests, is used to register a given list of composite clks. However it is lacking a counterpart unregister API. Implement said unregister API so that the various clock platform drivers can utilize it to do proper unregistration, cleanup and removal. In the header file, the register function's declaration is also reformatted to fit code style guidelines. Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: Miles Chen <miles.chen@mediatek.com> Link: https://lore.kernel.org/r/20220208124034.414635-19-wenst@chromium.org Reviewed-by: Chun-Jie Chen <chun-jie.chen@mediatek.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent b87385e commit cb50864

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

drivers/clk/mediatek/clk-mtk.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,32 @@ struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
233233
return ERR_PTR(ret);
234234
}
235235

236+
static void mtk_clk_unregister_composite(struct clk *clk)
237+
{
238+
struct clk_hw *hw;
239+
struct clk_composite *composite;
240+
struct clk_mux *mux = NULL;
241+
struct clk_gate *gate = NULL;
242+
struct clk_divider *div = NULL;
243+
244+
hw = __clk_get_hw(clk);
245+
if (!hw)
246+
return;
247+
248+
composite = to_clk_composite(hw);
249+
if (composite->mux_hw)
250+
mux = to_clk_mux(composite->mux_hw);
251+
if (composite->gate_hw)
252+
gate = to_clk_gate(composite->gate_hw);
253+
if (composite->rate_hw)
254+
div = to_clk_divider(composite->rate_hw);
255+
256+
clk_unregister_composite(clk);
257+
kfree(div);
258+
kfree(gate);
259+
kfree(mux);
260+
}
261+
236262
void mtk_clk_register_composites(const struct mtk_composite *mcs,
237263
int num, void __iomem *base, spinlock_t *lock,
238264
struct clk_onecell_data *clk_data)
@@ -259,6 +285,26 @@ void mtk_clk_register_composites(const struct mtk_composite *mcs,
259285
}
260286
EXPORT_SYMBOL_GPL(mtk_clk_register_composites);
261287

288+
void mtk_clk_unregister_composites(const struct mtk_composite *mcs, int num,
289+
struct clk_onecell_data *clk_data)
290+
{
291+
int i;
292+
293+
if (!clk_data)
294+
return;
295+
296+
for (i = num; i > 0; i--) {
297+
const struct mtk_composite *mc = &mcs[i - 1];
298+
299+
if (IS_ERR_OR_NULL(clk_data->clks[mc->id]))
300+
continue;
301+
302+
mtk_clk_unregister_composite(clk_data->clks[mc->id]);
303+
clk_data->clks[mc->id] = ERR_PTR(-ENOENT);
304+
}
305+
}
306+
EXPORT_SYMBOL_GPL(mtk_clk_unregister_composites);
307+
262308
void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
263309
int num, void __iomem *base, spinlock_t *lock,
264310
struct clk_onecell_data *clk_data)

drivers/clk/mediatek/clk-mtk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
153153
void mtk_clk_register_composites(const struct mtk_composite *mcs,
154154
int num, void __iomem *base, spinlock_t *lock,
155155
struct clk_onecell_data *clk_data);
156+
void mtk_clk_unregister_composites(const struct mtk_composite *mcs, int num,
157+
struct clk_onecell_data *clk_data);
156158

157159
struct mtk_clk_divider {
158160
int id;

0 commit comments

Comments
 (0)