[PATCH 16/32] clk: mediatek: mt6779: Switch to common probe/remove helpers
Akari Tsuyukusa
akkun11.open at gmail.com
Mon Aug 3 07:16:43 PDT 2026
The MT6779 main clock driver 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.
Additionally, merge the separate infracfg and other drivers into
a single platform driver, and add support for the apmixed and
topckgen clock controllers using the consolidated of_match_table.
Finally, replace the custom arch_initcall() initialization loop with
the module_platform_driver() macro.
Signed-off-by: Akari Tsuyukusa <akkun11.open at gmail.com>
---
drivers/clk/mediatek/clk-mt6779.c | 124 ++++++------------------------
1 file changed, 22 insertions(+), 102 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt6779.c b/drivers/clk/mediatek/clk-mt6779.c
index 4b9dcb910b03..a806789ae27c 100644
--- a/drivers/clk/mediatek/clk-mt6779.c
+++ b/drivers/clk/mediatek/clk-mt6779.c
@@ -808,7 +808,7 @@ static const char * const i2s5_m_ck_parents[] = {
"aud_2_sel"
};
-static const struct mtk_composite top_aud_muxes[] = {
+static const struct mtk_composite top_aud_muxes_divs[] = {
MUX(CLK_TOP_I2S0_M_SEL, "i2s0_m_ck_sel", i2s0_m_ck_parents,
0x320, 8, 1),
MUX(CLK_TOP_I2S1_M_SEL, "i2s1_m_ck_sel", i2s1_m_ck_parents,
@@ -821,9 +821,7 @@ static const struct mtk_composite top_aud_muxes[] = {
0x320, 12, 1),
MUX(CLK_TOP_I2S5_M_SEL, "i2s5_m_ck_sel", i2s5_m_ck_parents,
0x328, 20, 1),
-};
-static struct mtk_composite top_aud_divs[] = {
DIV_GATE(CLK_TOP_APLL12_DIV0, "apll12_div0", "i2s0_m_ck_sel",
0x320, 2, 0x324, 8, 0),
DIV_GATE(CLK_TOP_APLL12_DIV1, "apll12_div1", "i2s1_m_ck_sel",
@@ -1211,125 +1209,47 @@ static const struct mtk_pll_data plls[] = {
0, 0, 32, 8, 0x02D4, 1, 0, 0x14, 1, 0x02D8, 0, 0x02D4),
};
-static int clk_mt6779_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
-
- mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
- ARRAY_SIZE(apmixed_clks), clk_data);
-
- return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
-}
-
-static int clk_mt6779_top_probe(struct platform_device *pdev)
-{
- void __iomem *base;
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
- clk_data);
-
- mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
-
- mtk_clk_register_muxes(&pdev->dev, top_muxes,
- ARRAY_SIZE(top_muxes), node,
- &mt6779_clk_lock, clk_data);
-
- mtk_clk_register_composites(&pdev->dev, top_aud_muxes,
- ARRAY_SIZE(top_aud_muxes), base,
- &mt6779_clk_lock, clk_data);
-
- mtk_clk_register_composites(&pdev->dev, top_aud_divs,
- ARRAY_SIZE(top_aud_divs), base,
- &mt6779_clk_lock, clk_data);
-
- return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
-}
-
-static const struct of_device_id of_match_clk_mt6779[] = {
- {
- .compatible = "mediatek,mt6779-apmixed",
- .data = clk_mt6779_apmixed_probe,
- }, {
- .compatible = "mediatek,mt6779-topckgen",
- .data = clk_mt6779_top_probe,
- }, {
- /* sentinel */
- }
+static const struct mtk_clk_desc apmixed_desc = {
+ .clks = apmixed_clks,
+ .num_clks = ARRAY_SIZE(apmixed_clks),
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
};
-static int clk_mt6779_probe(struct platform_device *pdev)
-{
- int (*clk_probe)(struct platform_device *pdev);
- int r;
-
- clk_probe = of_device_get_match_data(&pdev->dev);
- if (!clk_probe)
- return -EINVAL;
-
- r = clk_probe(pdev);
- if (r)
- dev_err(&pdev->dev,
- "could not register clock provider: %s: %d\n",
- pdev->name, r);
-
- return r;
-}
+static const struct mtk_clk_desc topck_desc = {
+ .fixed_clks = top_fixed_clks,
+ .num_fixed_clks = ARRAY_SIZE(top_fixed_clks),
+ .factor_clks = top_divs,
+ .num_factor_clks = ARRAY_SIZE(top_divs),
+ .mux_clks = top_muxes,
+ .num_mux_clks = ARRAY_SIZE(top_muxes),
+ .composite_clks = top_aud_muxes_divs,
+ .num_composite_clks = ARRAY_SIZE(top_aud_muxes_divs),
+ .clk_lock = &mt6779_clk_lock,
+};
static const struct mtk_clk_desc infra_desc = {
.clks = infra_clks,
.num_clks = ARRAY_SIZE(infra_clks),
};
-static const struct of_device_id of_match_clk_mt6779_infra[] = {
+static const struct of_device_id of_match_clk_mt6779[] = {
+ { .compatible = "mediatek,mt6779-apmixed", .data = &apmixed_desc },
+ { .compatible = "mediatek,mt6779-topckgen", .data = &topck_desc },
{ .compatible = "mediatek,mt6779-infracfg_ao", .data = &infra_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt6779);
-static struct platform_driver clk_mt6779_infra_drv = {
+static struct platform_driver clk_mt6779_drv = {
.probe = mtk_clk_simple_probe,
.remove = mtk_clk_simple_remove,
- .driver = {
- .name = "clk-mt6779-infra",
- .of_match_table = of_match_clk_mt6779_infra,
- },
-};
-
-static struct platform_driver clk_mt6779_drv = {
- .probe = clk_mt6779_probe,
.driver = {
.name = "clk-mt6779",
.of_match_table = of_match_clk_mt6779,
},
};
-
-static int __init clk_mt6779_init(void)
-{
- int ret = platform_driver_register(&clk_mt6779_drv);
-
- if (ret)
- return ret;
- return platform_driver_register(&clk_mt6779_infra_drv);
-}
-
-arch_initcall(clk_mt6779_init);
+module_platform_driver(clk_mt6779_drv);
MODULE_DESCRIPTION("MediaTek MT6779 main clocks driver");
MODULE_LICENSE("GPL");
--
2.55.0
More information about the linux-arm-kernel
mailing list