Skip to content

Commit

Permalink
clk: mediatek: clk-gate: Propagate struct device with mtk_clk_registe…
Browse files Browse the repository at this point in the history
…r_gates()

Commit e4c23e1 ("clk: mediatek: Register clock gate with device")
introduces a helper function for the sole purpose of propagating a
struct device pointer to the clk API when registering the mtk-gate
clocks to take advantage of Runtime PM when/where needed and where
a power domain is defined in devicetree.

Function mtk_clk_register_gates() then becomes a wrapper around the
new mtk_clk_register_gates_with_dev() function that will simply pass
NULL as struct device: this is essential when registering drivers
with CLK_OF_DECLARE instead of as a platform device, as there will
be no struct device to pass... but we can as well simply have only
one function that always takes such pointer as a param and pass NULL
when unavoidable.

This commit removes the mtk_clk_register_gates() wrapper and renames
mtk_clk_register_gates_with_dev() to the former and all of the calls
to either of the two functions were fixed in all drivers in order to
reflect this change; also, to improve consistency with other kernel
functions, the pointer to struct device was moved as the first param.

Since a lot of MediaTek clock drivers are actually registering as a
platform device, but were still registering the mtk-gate clocks
without passing any struct device to the clock framework, they've
been changed to pass a valid one now, as to make all those platforms
able to use runtime power management where available.

While at it, some much needed indentation changes were also done.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Markus Schneider-Pargmann <msp@baylibre.com>
Tested-by: Miles Chen <miles.chen@mediatek.com>
Link: https://lore.kernel.org/r/20230120092053.182923-4-angelogioacchino.delregno@collabora.com
Tested-by: Mingming Su <mingming.su@mediatek.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
  • Loading branch information
AngeloGioacchino Del Regno authored and Stephen Boyd committed Jan 31, 2023
1 parent fdc325c commit 20498d5
Show file tree
Hide file tree
Showing 52 changed files with 156 additions and 160 deletions.
23 changes: 7 additions & 16 deletions drivers/clk/mediatek/clk-gate.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ const struct clk_ops mtk_clk_gate_ops_no_setclr_inv = {
};
EXPORT_SYMBOL_GPL(mtk_clk_gate_ops_no_setclr_inv);

static struct clk_hw *mtk_clk_register_gate(const char *name,
static struct clk_hw *mtk_clk_register_gate(struct device *dev, const char *name,
const char *parent_name,
struct regmap *regmap, int set_ofs,
int clr_ofs, int sta_ofs, u8 bit,
const struct clk_ops *ops,
unsigned long flags, struct device *dev)
unsigned long flags)
{
struct mtk_clk_gate *cg;
int ret;
Expand Down Expand Up @@ -202,10 +202,9 @@ static void mtk_clk_unregister_gate(struct clk_hw *hw)
kfree(cg);
}

int mtk_clk_register_gates_with_dev(struct device_node *node,
const struct mtk_gate *clks, int num,
struct clk_hw_onecell_data *clk_data,
struct device *dev)
int mtk_clk_register_gates(struct device *dev, struct device_node *node,
const struct mtk_gate *clks, int num,
struct clk_hw_onecell_data *clk_data)
{
int i;
struct clk_hw *hw;
Expand All @@ -229,13 +228,13 @@ int mtk_clk_register_gates_with_dev(struct device_node *node,
continue;
}

hw = mtk_clk_register_gate(gate->name, gate->parent_name,
hw = mtk_clk_register_gate(dev, gate->name, gate->parent_name,
regmap,
gate->regs->set_ofs,
gate->regs->clr_ofs,
gate->regs->sta_ofs,
gate->shift, gate->ops,
gate->flags, dev);
gate->flags);

if (IS_ERR(hw)) {
pr_err("Failed to register clk %s: %pe\n", gate->name,
Expand All @@ -261,14 +260,6 @@ int mtk_clk_register_gates_with_dev(struct device_node *node,

return PTR_ERR(hw);
}
EXPORT_SYMBOL_GPL(mtk_clk_register_gates_with_dev);

int mtk_clk_register_gates(struct device_node *node,
const struct mtk_gate *clks, int num,
struct clk_hw_onecell_data *clk_data)
{
return mtk_clk_register_gates_with_dev(node, clks, num, clk_data, NULL);
}
EXPORT_SYMBOL_GPL(mtk_clk_register_gates);

void mtk_clk_unregister_gates(const struct mtk_gate *clks, int num,
Expand Down
7 changes: 1 addition & 6 deletions drivers/clk/mediatek/clk-gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,10 @@ struct mtk_gate {
#define GATE_MTK(_id, _name, _parent, _regs, _shift, _ops) \
GATE_MTK_FLAGS(_id, _name, _parent, _regs, _shift, _ops, 0)

int mtk_clk_register_gates(struct device_node *node,
int mtk_clk_register_gates(struct device *dev, struct device_node *node,
const struct mtk_gate *clks, int num,
struct clk_hw_onecell_data *clk_data);

int mtk_clk_register_gates_with_dev(struct device_node *node,
const struct mtk_gate *clks, int num,
struct clk_hw_onecell_data *clk_data,
struct device *dev);

void mtk_clk_unregister_gates(const struct mtk_gate *clks, int num,
struct clk_hw_onecell_data *clk_data);

Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/mediatek/clk-mt2701-aud.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ static int clk_mt2701_aud_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_AUD_NR);

mtk_clk_register_gates(node, audio_clks, ARRAY_SIZE(audio_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, audio_clks,
ARRAY_SIZE(audio_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/mediatek/clk-mt2701-eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ static int clk_mt2701_eth_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_ETHSYS_NR);

mtk_clk_register_gates(node, eth_clks, ARRAY_SIZE(eth_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, eth_clks,
ARRAY_SIZE(eth_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r)
Expand Down
2 changes: 1 addition & 1 deletion drivers/clk/mediatek/clk-mt2701-g3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static int clk_mt2701_g3dsys_init(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_G3DSYS_NR);

mtk_clk_register_gates(node, g3d_clks, ARRAY_SIZE(g3d_clks),
mtk_clk_register_gates(&pdev->dev, node, g3d_clks, ARRAY_SIZE(g3d_clks),
clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/mediatek/clk-mt2701-hif.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ static int clk_mt2701_hif_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_HIFSYS_NR);

mtk_clk_register_gates(node, hif_clks, ARRAY_SIZE(hif_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, hif_clks,
ARRAY_SIZE(hif_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/mediatek/clk-mt2701-mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ static int clk_mt2701_mm_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_MM_NR);

mtk_clk_register_gates(node, mm_clks, ARRAY_SIZE(mm_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, mm_clks,
ARRAY_SIZE(mm_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r)
Expand Down
12 changes: 6 additions & 6 deletions drivers/clk/mediatek/clk-mt2701.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,8 @@ static int mtk_topckgen_init(struct platform_device *pdev)
mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs),
base, &mt2701_clk_lock, clk_data);

mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, top_clks,
ARRAY_SIZE(top_clks), clk_data);

return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
}
Expand Down Expand Up @@ -795,8 +795,8 @@ static int mtk_infrasys_init(struct platform_device *pdev)
}
}

mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
infra_clk_data);
mtk_clk_register_gates(&pdev->dev, node, infra_clks,
ARRAY_SIZE(infra_clks), infra_clk_data);
mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
infra_clk_data);

Expand Down Expand Up @@ -918,8 +918,8 @@ static int mtk_pericfg_init(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_PERI_NR);

mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, peri_clks,
ARRAY_SIZE(peri_clks), clk_data);

mtk_clk_register_composites(peri_muxs, ARRAY_SIZE(peri_muxs), base,
&mt2701_clk_lock, clk_data);
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/mediatek/clk-mt2712-mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ static int clk_mt2712_mm_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_MM_NR_CLK);

mtk_clk_register_gates(node, mm_clks, ARRAY_SIZE(mm_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, mm_clks,
ARRAY_SIZE(mm_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);

Expand Down
12 changes: 6 additions & 6 deletions drivers/clk/mediatek/clk-mt2712.c
Original file line number Diff line number Diff line change
Expand Up @@ -1350,8 +1350,8 @@ static int clk_mt2712_top_probe(struct platform_device *pdev)
&mt2712_clk_lock, top_clk_data);
mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs), base,
&mt2712_clk_lock, top_clk_data);
mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
top_clk_data);
mtk_clk_register_gates(&pdev->dev, node, top_clks,
ARRAY_SIZE(top_clks), top_clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, top_clk_data);

Expand All @@ -1370,8 +1370,8 @@ static int clk_mt2712_infra_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);

mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, infra_clks,
ARRAY_SIZE(infra_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);

Expand All @@ -1392,8 +1392,8 @@ static int clk_mt2712_peri_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);

mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, peri_clks,
ARRAY_SIZE(peri_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);

Expand Down
10 changes: 5 additions & 5 deletions drivers/clk/mediatek/clk-mt6765.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ static int clk_mt6765_apmixed_probe(struct platform_device *pdev)

mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);

mtk_clk_register_gates(node, apmixed_clks,
mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
ARRAY_SIZE(apmixed_clks), clk_data);
r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);

Expand Down Expand Up @@ -828,8 +828,8 @@ static int clk_mt6765_top_probe(struct platform_device *pdev)
clk_data);
mtk_clk_register_muxes(top_muxes, ARRAY_SIZE(top_muxes), node,
&mt6765_clk_lock, clk_data);
mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, top_clks,
ARRAY_SIZE(top_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);

Expand Down Expand Up @@ -862,8 +862,8 @@ static int clk_mt6765_ifr_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_IFR_NR_CLK);

mtk_clk_register_gates(node, ifr_clks, ARRAY_SIZE(ifr_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, ifr_clks,
ARRAY_SIZE(ifr_clks), clk_data);
r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);

if (r)
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/mediatek/clk-mt6779-mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ static int clk_mt6779_mm_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_MM_NR_CLK);

mtk_clk_register_gates(node, mm_clks, ARRAY_SIZE(mm_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, mm_clks,
ARRAY_SIZE(mm_clks), clk_data);

return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/clk/mediatek/clk-mt6779.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ static int clk_mt6779_apmixed_probe(struct platform_device *pdev)

mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);

mtk_clk_register_gates(node, apmixed_clks,
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);
Expand Down Expand Up @@ -1263,8 +1263,8 @@ static int clk_mt6779_infra_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);

mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, infra_clks,
ARRAY_SIZE(infra_clks), clk_data);

return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
}
Expand Down
3 changes: 2 additions & 1 deletion drivers/clk/mediatek/clk-mt6795-infracfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ static int clk_mt6795_infracfg_probe(struct platform_device *pdev)
if (ret)
goto free_clk_data;

ret = mtk_clk_register_gates(node, infra_gates, ARRAY_SIZE(infra_gates), clk_data);
ret = mtk_clk_register_gates(&pdev->dev, node, infra_gates,
ARRAY_SIZE(infra_gates), clk_data);
if (ret)
goto free_clk_data;

Expand Down
3 changes: 2 additions & 1 deletion drivers/clk/mediatek/clk-mt6795-mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ static int clk_mt6795_mm_probe(struct platform_device *pdev)
if (!clk_data)
return -ENOMEM;

ret = mtk_clk_register_gates(node, mm_gates, ARRAY_SIZE(mm_gates), clk_data);
ret = mtk_clk_register_gates(&pdev->dev, node, mm_gates,
ARRAY_SIZE(mm_gates), clk_data);
if (ret)
goto free_clk_data;

Expand Down
3 changes: 2 additions & 1 deletion drivers/clk/mediatek/clk-mt6795-pericfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ static int clk_mt6795_pericfg_probe(struct platform_device *pdev)
if (ret)
goto free_clk_data;

ret = mtk_clk_register_gates(node, peri_gates, ARRAY_SIZE(peri_gates), clk_data);
ret = mtk_clk_register_gates(&pdev->dev, node, peri_gates,
ARRAY_SIZE(peri_gates), clk_data);
if (ret)
goto free_clk_data;

Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/mediatek/clk-mt6797-mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ static int clk_mt6797_mm_probe(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_MM_NR);

mtk_clk_register_gates(node, mm_clks, ARRAY_SIZE(mm_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, mm_clks,
ARRAY_SIZE(mm_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r)
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/mediatek/clk-mt6797.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ static int mtk_infrasys_init(struct platform_device *pdev)
}
}

mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
infra_clk_data);
mtk_clk_register_gates(&pdev->dev, node, infra_clks,
ARRAY_SIZE(infra_clks), infra_clk_data);
mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
infra_clk_data);

Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/mediatek/clk-mt7622-aud.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ static int clk_mt7622_audiosys_init(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_AUDIO_NR_CLK);

mtk_clk_register_gates(node, audio_clks, ARRAY_SIZE(audio_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, audio_clks,
ARRAY_SIZE(audio_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r) {
Expand Down
8 changes: 4 additions & 4 deletions drivers/clk/mediatek/clk-mt7622-eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ static int clk_mt7622_ethsys_init(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_ETH_NR_CLK);

mtk_clk_register_gates(node, eth_clks, ARRAY_SIZE(eth_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, eth_clks,
ARRAY_SIZE(eth_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r)
Expand All @@ -103,8 +103,8 @@ static int clk_mt7622_sgmiisys_init(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_SGMII_NR_CLK);

mtk_clk_register_gates(node, sgmii_clks, ARRAY_SIZE(sgmii_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, sgmii_clks,
ARRAY_SIZE(sgmii_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r)
Expand Down
8 changes: 4 additions & 4 deletions drivers/clk/mediatek/clk-mt7622-hif.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ static int clk_mt7622_ssusbsys_init(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_SSUSB_NR_CLK);

mtk_clk_register_gates(node, ssusb_clks, ARRAY_SIZE(ssusb_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, ssusb_clks,
ARRAY_SIZE(ssusb_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r)
Expand All @@ -114,8 +114,8 @@ static int clk_mt7622_pciesys_init(struct platform_device *pdev)

clk_data = mtk_alloc_clk_data(CLK_PCIE_NR_CLK);

mtk_clk_register_gates(node, pcie_clks, ARRAY_SIZE(pcie_clks),
clk_data);
mtk_clk_register_gates(&pdev->dev, node, pcie_clks,
ARRAY_SIZE(pcie_clks), clk_data);

r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r)
Expand Down
Loading

0 comments on commit 20498d5

Please sign in to comment.