mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-04 08:08:54 +00:00
clk: mediatek: mt8173: Migrate pericfg/topckgen to mtk_clk_simple_probe()
Function mtk_clk_simple_probe() gained the ability to register multiple clock types: migrate MT8173's pericfg and topckgen to this common probe function to reduce duplication and code size. Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: Miles Chen <miles.chen@mediatek.com> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org> Link: https://lore.kernel.org/r/20230120092053.182923-14-angelogioacchino.delregno@collabora.com Tested-by: Mingming Su <mingming.su@mediatek.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
parent
7b6183108c
commit
e4078219e9
2 changed files with 29 additions and 128 deletions
|
@ -46,6 +46,7 @@ static const struct mtk_composite peri_clks[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct mtk_gate peri_gates[] = {
|
static const struct mtk_gate peri_gates[] = {
|
||||||
|
GATE_DUMMY(CLK_DUMMY, "peri_gate_dummy"),
|
||||||
/* PERI0 */
|
/* PERI0 */
|
||||||
GATE_PERI0(CLK_PERI_NFI, "peri_nfi", "axi_sel", 0),
|
GATE_PERI0(CLK_PERI_NFI, "peri_nfi", "axi_sel", 0),
|
||||||
GATE_PERI0(CLK_PERI_THERM, "peri_therm", "axi_sel", 1),
|
GATE_PERI0(CLK_PERI_THERM, "peri_therm", "axi_sel", 1),
|
||||||
|
@ -93,78 +94,27 @@ static const struct mtk_clk_rst_desc clk_rst_desc = {
|
||||||
.rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
|
.rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct of_device_id of_match_clk_mt8173_pericfg[] = {
|
static const struct mtk_clk_desc peri_desc = {
|
||||||
{ .compatible = "mediatek,mt8173-pericfg" },
|
.clks = peri_gates,
|
||||||
{ /* sentinel */ }
|
.num_clks = ARRAY_SIZE(peri_gates),
|
||||||
|
.composite_clks = peri_clks,
|
||||||
|
.num_composite_clks = ARRAY_SIZE(peri_clks),
|
||||||
|
.clk_lock = &mt8173_clk_lock,
|
||||||
|
.rst_desc = &clk_rst_desc,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int clk_mt8173_pericfg_probe(struct platform_device *pdev)
|
static const struct of_device_id of_match_clk_mt8173_pericfg[] = {
|
||||||
{
|
{ .compatible = "mediatek,mt8173-pericfg", .data = &peri_desc },
|
||||||
struct device_node *node = pdev->dev.of_node;
|
{ /* sentinel */ }
|
||||||
struct clk_hw_onecell_data *clk_data;
|
};
|
||||||
int r;
|
|
||||||
void __iomem *base;
|
|
||||||
|
|
||||||
base = devm_platform_ioremap_resource(pdev, 0);
|
|
||||||
if (IS_ERR(base))
|
|
||||||
return PTR_ERR(base);
|
|
||||||
|
|
||||||
clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
|
|
||||||
if (IS_ERR_OR_NULL(clk_data))
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
r = mtk_clk_register_gates(&pdev->dev, node, peri_gates,
|
|
||||||
ARRAY_SIZE(peri_gates), clk_data);
|
|
||||||
if (r)
|
|
||||||
goto free_clk_data;
|
|
||||||
|
|
||||||
r = mtk_clk_register_composites(&pdev->dev, peri_clks,
|
|
||||||
ARRAY_SIZE(peri_clks), base,
|
|
||||||
&mt8173_clk_lock, clk_data);
|
|
||||||
if (r)
|
|
||||||
goto unregister_gates;
|
|
||||||
|
|
||||||
r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
|
|
||||||
if (r)
|
|
||||||
goto unregister_composites;
|
|
||||||
|
|
||||||
r = mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
|
|
||||||
if (r)
|
|
||||||
goto unregister_clk_hw;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
unregister_clk_hw:
|
|
||||||
of_clk_del_provider(node);
|
|
||||||
unregister_composites:
|
|
||||||
mtk_clk_unregister_composites(peri_clks, ARRAY_SIZE(peri_clks), clk_data);
|
|
||||||
unregister_gates:
|
|
||||||
mtk_clk_unregister_gates(peri_gates, ARRAY_SIZE(peri_gates), clk_data);
|
|
||||||
free_clk_data:
|
|
||||||
mtk_free_clk_data(clk_data);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int clk_mt8173_pericfg_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_composites(peri_clks, ARRAY_SIZE(peri_clks), clk_data);
|
|
||||||
mtk_clk_unregister_gates(peri_gates, ARRAY_SIZE(peri_gates), clk_data);
|
|
||||||
mtk_free_clk_data(clk_data);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct platform_driver clk_mt8173_pericfg_drv = {
|
static struct platform_driver clk_mt8173_pericfg_drv = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "clk-mt8173-pericfg",
|
.name = "clk-mt8173-pericfg",
|
||||||
.of_match_table = of_match_clk_mt8173_pericfg,
|
.of_match_table = of_match_clk_mt8173_pericfg,
|
||||||
},
|
},
|
||||||
.probe = clk_mt8173_pericfg_probe,
|
.probe = mtk_clk_simple_probe,
|
||||||
.remove = clk_mt8173_pericfg_remove,
|
.remove = mtk_clk_simple_remove,
|
||||||
};
|
};
|
||||||
module_platform_driver(clk_mt8173_pericfg_drv);
|
module_platform_driver(clk_mt8173_pericfg_drv);
|
||||||
|
|
||||||
|
|
|
@ -421,6 +421,7 @@ static const char * const i2s3_b_ck_parents[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct mtk_fixed_clk fixed_clks[] = {
|
static const struct mtk_fixed_clk fixed_clks[] = {
|
||||||
|
FIXED_CLK(CLK_DUMMY, "topck_dummy", "clk26m", DUMMY_RATE),
|
||||||
FIXED_CLK(CLK_TOP_CLKPH_MCK_O, "clkph_mck_o", "clk26m", DUMMY_RATE),
|
FIXED_CLK(CLK_TOP_CLKPH_MCK_O, "clkph_mck_o", "clk26m", DUMMY_RATE),
|
||||||
FIXED_CLK(CLK_TOP_USB_SYSPLL_125M, "usb_syspll_125m", "clk26m", 125 * MHZ),
|
FIXED_CLK(CLK_TOP_USB_SYSPLL_125M, "usb_syspll_125m", "clk26m", 125 * MHZ),
|
||||||
FIXED_CLK(CLK_TOP_DSI0_DIG, "dsi0_dig", "clk26m", DUMMY_RATE),
|
FIXED_CLK(CLK_TOP_DSI0_DIG, "dsi0_dig", "clk26m", DUMMY_RATE),
|
||||||
|
@ -623,78 +624,28 @@ static const struct mtk_composite top_muxes[] = {
|
||||||
MUX(CLK_TOP_I2S3_B_SEL, "i2s3_b_ck_sel", i2s3_b_ck_parents, 0x120, 8, 1),
|
MUX(CLK_TOP_I2S3_B_SEL, "i2s3_b_ck_sel", i2s3_b_ck_parents, 0x120, 8, 1),
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct of_device_id of_match_clk_mt8173_topckgen[] = {
|
static const struct mtk_clk_desc topck_desc = {
|
||||||
{ .compatible = "mediatek,mt8173-topckgen" },
|
.fixed_clks = fixed_clks,
|
||||||
{ /* sentinel */ }
|
.num_fixed_clks = ARRAY_SIZE(fixed_clks),
|
||||||
|
.factor_clks = top_divs,
|
||||||
|
.num_factor_clks = ARRAY_SIZE(top_divs),
|
||||||
|
.composite_clks = top_muxes,
|
||||||
|
.num_composite_clks = ARRAY_SIZE(top_muxes),
|
||||||
|
.clk_lock = &mt8173_top_clk_lock,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int clk_mt8173_topckgen_probe(struct platform_device *pdev)
|
static const struct of_device_id of_match_clk_mt8173_topckgen[] = {
|
||||||
{
|
{ .compatible = "mediatek,mt8173-topckgen", .data = &topck_desc },
|
||||||
struct device_node *node = pdev->dev.of_node;
|
{ /* sentinel */ }
|
||||||
struct clk_hw_onecell_data *clk_data;
|
};
|
||||||
void __iomem *base;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
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 (IS_ERR_OR_NULL(clk_data))
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
r = mtk_clk_register_fixed_clks(fixed_clks, ARRAY_SIZE(fixed_clks), clk_data);
|
|
||||||
if (r)
|
|
||||||
goto free_clk_data;
|
|
||||||
|
|
||||||
r = mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
|
|
||||||
if (r)
|
|
||||||
goto unregister_fixed_clks;
|
|
||||||
|
|
||||||
r = mtk_clk_register_composites(&pdev->dev, top_muxes,
|
|
||||||
ARRAY_SIZE(top_muxes), base,
|
|
||||||
&mt8173_top_clk_lock, clk_data);
|
|
||||||
if (r)
|
|
||||||
goto unregister_factors;
|
|
||||||
|
|
||||||
r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
|
|
||||||
if (r)
|
|
||||||
goto unregister_composites;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
unregister_composites:
|
|
||||||
mtk_clk_unregister_composites(top_muxes, ARRAY_SIZE(top_muxes), clk_data);
|
|
||||||
unregister_factors:
|
|
||||||
mtk_clk_unregister_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
|
|
||||||
unregister_fixed_clks:
|
|
||||||
mtk_clk_unregister_fixed_clks(fixed_clks, ARRAY_SIZE(fixed_clks), clk_data);
|
|
||||||
free_clk_data:
|
|
||||||
mtk_free_clk_data(clk_data);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int clk_mt8173_topckgen_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_composites(top_muxes, ARRAY_SIZE(top_muxes), clk_data);
|
|
||||||
mtk_clk_unregister_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
|
|
||||||
mtk_clk_unregister_fixed_clks(fixed_clks, ARRAY_SIZE(fixed_clks), clk_data);
|
|
||||||
mtk_free_clk_data(clk_data);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct platform_driver clk_mt8173_topckgen_drv = {
|
static struct platform_driver clk_mt8173_topckgen_drv = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "clk-mt8173-topckgen",
|
.name = "clk-mt8173-topckgen",
|
||||||
.of_match_table = of_match_clk_mt8173_topckgen,
|
.of_match_table = of_match_clk_mt8173_topckgen,
|
||||||
},
|
},
|
||||||
.probe = clk_mt8173_topckgen_probe,
|
.probe = mtk_clk_simple_probe,
|
||||||
.remove = clk_mt8173_topckgen_remove,
|
.remove = mtk_clk_simple_remove,
|
||||||
};
|
};
|
||||||
module_platform_driver(clk_mt8173_topckgen_drv);
|
module_platform_driver(clk_mt8173_topckgen_drv);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue