[PATCH 30/32] clk: mediatek: mt8195: Switch to common probe/remove helpers
From: Akari Tsuyukusa
Date: Mon Aug 03 2026 - 11:12:16 EST
The MT8195 apusys_pll and apmixedsys drivers can use the MediaTek clock
framework common initialization sequence. Reduce boilerplate code by
creating struct mtk_clk_desc and using the mtk_clk_simple_probe/remove
helpers.
Note that the topckgen driver is excluded from this conversion because
it requires devm_mtk_clk_mux_notifier_register(), which is not
currently supported by the common simple probe helper.
Since all MT8195 clock drivers can now be built as modules,
change Kconfig setting to "tristate".
Signed-off-by: Akari Tsuyukusa <akkun11.open@xxxxxxxxx>
---
drivers/clk/mediatek/Kconfig | 12 ++--
drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 67 ++++----------------
drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 49 ++------------
3 files changed, 25 insertions(+), 103 deletions(-)
diff --git a/drivers/clk/mediatek/Kconfig b/drivers/clk/mediatek/Kconfig
index 6449b77d56ed..ac992cfc6c3e 100644
--- a/drivers/clk/mediatek/Kconfig
+++ b/drivers/clk/mediatek/Kconfig
@@ -909,13 +909,13 @@ config COMMON_CLK_MT8192_VENCSYS
This driver supports MediaTek MT8192 vencsys clocks.
config COMMON_CLK_MT8195
- bool "Clock driver for MediaTek MT8195"
- depends on ARM64 || COMPILE_TEST
- select COMMON_CLK_MEDIATEK
+ tristate "Clock driver for MediaTek MT8195"
+ depends on ARM64 || COMPILE_TEST
+ select COMMON_CLK_MEDIATEK
select COMMON_CLK_MEDIATEK_FHCTL
- default ARCH_MEDIATEK
- help
- This driver supports MediaTek MT8195 clocks.
+ default ARCH_MEDIATEK
+ help
+ This driver supports MediaTek MT8195 clocks.
config COMMON_CLK_MT8195_APUSYS
tristate "Clock driver for MediaTek MT8195 apusys"
diff --git a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c
index a120c3305547..fc60cd4d9382 100644
--- a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c
@@ -161,68 +161,25 @@ static struct mtk_pllfh_data pllfhs[] = {
FH(CLK_APMIXED_TVDPLL2, FH_TVDPLL1, 0x154),
};
+static const struct mtk_clk_desc apmixed_desc = {
+ .clks = apmixed_clks,
+ .num_clks = ARRAY_SIZE(apmixed_clks),
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+ .fhctl_node = "mediatek,mt8195-fhctl",
+ .pllfhs = pllfhs,
+ .num_pllfhs = ARRAY_SIZE(pllfhs),
+};
+
static const struct of_device_id of_match_clk_mt8195_apmixed[] = {
{ .compatible = "mediatek,mt8195-apmixedsys", },
{}
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8195_apmixed);
-static int clk_mt8195_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- const u8 *fhctl_node = "mediatek,mt8195-fhctl";
- int r;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- fhctl_parse_dt(fhctl_node, pllfhs, ARRAY_SIZE(pllfhs));
-
- r = mtk_clk_register_pllfhs(&pdev->dev, plls, ARRAY_SIZE(plls),
- pllfhs, ARRAY_SIZE(pllfhs), clk_data);
- if (r)
- goto free_apmixed_data;
-
- r = mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
- ARRAY_SIZE(apmixed_clks), clk_data);
- if (r)
- goto unregister_plls;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_gates;
-
- platform_set_drvdata(pdev, clk_data);
-
- return r;
-
-unregister_gates:
- mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
-unregister_plls:
- mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs,
- ARRAY_SIZE(pllfhs), clk_data);
-free_apmixed_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
-static void clk_mt8195_apmixed_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
- mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs,
- ARRAY_SIZE(pllfhs), clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt8195_apmixed_drv = {
- .probe = clk_mt8195_apmixed_probe,
- .remove = clk_mt8195_apmixed_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8195-apmixed",
.of_match_table = of_match_clk_mt8195_apmixed,
diff --git a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c
index a2d98ed58e34..36d358141ecb 100644
--- a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c
+++ b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c
@@ -56,55 +56,20 @@ static const struct mtk_pll_data apusys_plls[] = {
PLL(CLK_APUSYS_PLL_APUPLL2, "apusys_pll_apupll2", 0x038, 0x044, 0x03c, 0x03c),
};
-static int clk_mt8195_apusys_pll_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- int r;
-
- clk_data = mtk_alloc_clk_data(CLK_APUSYS_PLL_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- r = mtk_clk_register_plls(&pdev->dev, apusys_plls,
- ARRAY_SIZE(apusys_plls), clk_data);
- if (r)
- goto free_apusys_pll_data;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_plls;
-
- platform_set_drvdata(pdev, clk_data);
-
- return r;
-
-unregister_plls:
- mtk_clk_unregister_plls(apusys_plls, ARRAY_SIZE(apusys_plls), clk_data);
-free_apusys_pll_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
-static void clk_mt8195_apusys_pll_remove(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
- struct device_node *node = pdev->dev.of_node;
-
- of_clk_del_provider(node);
- mtk_clk_unregister_plls(apusys_plls, ARRAY_SIZE(apusys_plls), clk_data);
- mtk_free_clk_data(clk_data);
-}
+static const struct mtk_clk_desc apu_pll_desc = {
+ .plls = apusys_plls,
+ .num_plls = ARRAY_SIZE(apusys_plls),
+};
static const struct of_device_id of_match_clk_mt8195_apusys_pll[] = {
- { .compatible = "mediatek,mt8195-apusys_pll", },
+ { .compatible = "mediatek,mt8195-apusys_pll", .data = &apu_pll_desc },
{}
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8195_apusys_pll);
static struct platform_driver clk_mt8195_apusys_pll_drv = {
- .probe = clk_mt8195_apusys_pll_probe,
- .remove = clk_mt8195_apusys_pll_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8195-apusys_pll",
.of_match_table = of_match_clk_mt8195_apusys_pll,
--
2.55.0