2022-05-19 15:48:52

by Yassine Oudjana

[permalink] [raw]
Subject: [PATCH 5/6] clk: mediatek: Unregister reset controller on simple remove

From: Yassine Oudjana <[email protected]>

Store clk_data and rst_data pointers in a new wrapper struct,
set it as platform driver data, then use it in mtk_clk_simple_remove
to unregister the reset controller.

Signed-off-by: Yassine Oudjana <[email protected]>
---
Dependencies:
- clk: mediatek: Move to struct clk_hw provider APIs (series)
https://patchwork.kernel.org/project/linux-mediatek/cover/[email protected]/
- Cleanup MediaTek clk reset drivers and support MT8192/MT8195 (series)
https://patchwork.kernel.org/project/linux-mediatek/cover/[email protected]/
- Export required symbols to compile clk drivers as module (single patch)
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

drivers/clk/mediatek/clk-mtk.c | 47 +++++++++++++++++++++-------------
drivers/clk/mediatek/clk-mtk.h | 5 ++++
2 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 1b5591733e2b..3382802663f4 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -422,35 +422,41 @@ void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num,
int mtk_clk_simple_probe(struct platform_device *pdev)
{
const struct mtk_clk_desc *mcd;
- struct clk_hw_onecell_data *clk_data;
+ struct mtk_simple_clk_controller *clk_ctrl;
struct device_node *node = pdev->dev.of_node;
- struct mtk_clk_rst_data *rst_data;
int r;

mcd = of_device_get_match_data(&pdev->dev);
if (!mcd)
return -EINVAL;

- clk_data = mtk_alloc_clk_data(mcd->num_clks);
- if (!clk_data)
+ clk_ctrl = kzalloc(sizeof(*clk_ctrl), GFP_KERNEL);
+ if (!clk_ctrl)
return -ENOMEM;

+ clk_ctrl->clk_data = mtk_alloc_clk_data(mcd->num_clks);
+ if (!clk_ctrl->clk_data) {
+ r = -ENOMEM;
+ goto free_clk_ctrl;
+ }
+
r = mtk_clk_register_gates_with_dev(node, mcd->clks, mcd->num_clks,
- clk_data, &pdev->dev);
+ clk_ctrl->clk_data, &pdev->dev);
if (r)
- goto free_data;
+ goto free_clk_data;

- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
+ r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_ctrl->clk_data);
if (r)
goto unregister_clks;

- platform_set_drvdata(pdev, clk_data);
+ platform_set_drvdata(pdev, clk_ctrl);

if (mcd->rst_desc) {
- rst_data = mtk_register_reset_controller_with_dev(&pdev->dev,
- mcd->rst_desc);
- if (IS_ERR(rst_data)) {
- r = PTR_ERR(rst_data);
+ clk_ctrl->rst_data =
+ mtk_register_reset_controller_with_dev(&pdev->dev,
+ mcd->rst_desc);
+ if (IS_ERR(clk_ctrl->rst_data)) {
+ r = PTR_ERR(clk_ctrl->rst_data);
goto unregister_clks;
}
}
@@ -458,9 +464,11 @@ int mtk_clk_simple_probe(struct platform_device *pdev)
return r;

unregister_clks:
- mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data);
-free_data:
- mtk_free_clk_data(clk_data);
+ mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_ctrl->clk_data);
+free_clk_data:
+ mtk_free_clk_data(clk_ctrl->clk_data);
+free_clk_ctrl:
+ kfree(clk_ctrl);
return r;
}
EXPORT_SYMBOL_GPL(mtk_clk_simple_probe);
@@ -468,12 +476,15 @@ EXPORT_SYMBOL_GPL(mtk_clk_simple_probe);
int mtk_clk_simple_remove(struct platform_device *pdev)
{
const struct mtk_clk_desc *mcd = of_device_get_match_data(&pdev->dev);
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
+ struct mtk_simple_clk_controller *clk_ctrl = platform_get_drvdata(pdev);
struct device_node *node = pdev->dev.of_node;

of_clk_del_provider(node);
- mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data);
- mtk_free_clk_data(clk_data);
+ if (clk_ctrl->rst_data)
+ mtk_unregister_reset_controller(clk_ctrl->rst_data);
+ mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_ctrl->clk_data);
+ mtk_free_clk_data(clk_ctrl->clk_data);
+ kfree(clk_ctrl);

return 0;
}
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index 1b95c484d5aa..fa092bca97c8 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -189,6 +189,11 @@ void mtk_free_clk_data(struct clk_hw_onecell_data *clk_data);
struct clk_hw *mtk_clk_register_ref2usb_tx(const char *name,
const char *parent_name, void __iomem *reg);

+struct mtk_simple_clk_controller {
+ struct clk_hw_onecell_data *clk_data;
+ struct mtk_clk_rst_data *rst_data;
+};
+
struct mtk_clk_desc {
const struct mtk_gate *clks;
size_t num_clks;
--
2.36.1