Message ID | 20191207224740.24536-7-matthias.bgg@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | arm/arm64: mediatek: Fix mmsys device probing | expand |
Hi Matthias, On 7/12/19 23:47, matthias.bgg@kernel.org wrote: > From: Matthias Brugger <mbrugger@suse.com> > > Switch probing for the MMSYS to support invocation to a plain > paltform device. The driver will be probed by the DRM subsystem. > > Signed-off-by: Matthias Brugger <mbrugger@suse.com> > --- > drivers/clk/mediatek/clk-mt2701-mm.c | 41 ++++++++++++++++++++-------- > 1 file changed, 29 insertions(+), 12 deletions(-) > > diff --git a/drivers/clk/mediatek/clk-mt2701-mm.c b/drivers/clk/mediatek/clk-mt2701-mm.c > index 054b597d4a73..4a9433c2b2b8 100644 > --- a/drivers/clk/mediatek/clk-mt2701-mm.c > +++ b/drivers/clk/mediatek/clk-mt2701-mm.c > @@ -4,14 +4,20 @@ > * Author: Shunli Wang <shunli.wang@mediatek.com> > */ > > +#include <linux/module.h> > #include <linux/clk-provider.h> > #include <linux/platform_device.h> > +#include <linux/slab.h> > > #include "clk-mtk.h" > #include "clk-gate.h" > > #include <dt-bindings/clock/mt2701-clk.h> > > +struct clk_mt2701_mm_priv { > + struct clk_onecell_data *clk_data; > +}; > + > static const struct mtk_gate_regs disp0_cg_regs = { > .set_ofs = 0x0104, > .clr_ofs = 0x0108, > @@ -79,23 +85,25 @@ static const struct mtk_gate mm_clks[] = { > GATE_DISP1(CLK_MM_TVE_FMM, "mm_tve_fmm", "mm_sel", 14), > }; > > -static const struct of_device_id of_match_clk_mt2701_mm[] = { > - { .compatible = "mediatek,mt2701-mmsys", }, > - {} > -}; > - > static int clk_mt2701_mm_probe(struct platform_device *pdev) > { > - struct clk_onecell_data *clk_data; > int r; > - struct device_node *node = pdev->dev.of_node; > + struct device_node *node = pdev->dev.parent->of_node; > + struct clk_mt2701_mm_priv *private; > + > + private = devm_kzalloc(&pdev->dev, sizeof(*private), GFP_KERNEL); > + if (!private) > + return -ENOMEM; > > - clk_data = mtk_alloc_clk_data(CLK_MM_NR); > + private->clk_data = mtk_alloc_clk_data(CLK_MM_NR); > + > + platform_set_drvdata(pdev, private); > > mtk_clk_register_gates(node, mm_clks, ARRAY_SIZE(mm_clks), > - clk_data); > + private->clk_data); > > - r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); > + r = of_clk_add_provider(node, of_clk_src_onecell_get, > + private->clk_data); > if (r) > dev_err(&pdev->dev, > "could not register clock provider: %s: %d\n", > @@ -104,12 +112,21 @@ static int clk_mt2701_mm_probe(struct platform_device *pdev) > return r; > } > > +static int clk_mt2701_mm_remove(struct platform_device *pdev) > +{ > + struct clk_mt2701_mm_priv *private = platform_get_drvdata(pdev); > + I think that private->clk_data->clks is also kallocated and need to be freed? But I think that the best approach now is to switch to use devm allocations in clk-mt2701-mm.c and this remove function will not be needed. > + kfree(private->clk_data); > + > + return 0; > +} > + > static struct platform_driver clk_mt2701_mm_drv = { > .probe = clk_mt2701_mm_probe, > + .remove = clk_mt2701_mm_remove, > .driver = { > .name = "clk-mt2701-mm", > - .of_match_table = of_match_clk_mt2701_mm, > }, > }; > > -builtin_platform_driver(clk_mt2701_mm_drv); > +module_platform_driver(clk_mt2701_mm_drv); >
On 09/12/2019 10:58, Enric Balletbo i Serra wrote: > Hi Matthias, > > On 7/12/19 23:47, matthias.bgg@kernel.org wrote: >> From: Matthias Brugger <mbrugger@suse.com> >> >> Switch probing for the MMSYS to support invocation to a plain >> paltform device. The driver will be probed by the DRM subsystem. >> >> Signed-off-by: Matthias Brugger <mbrugger@suse.com> >> --- >> drivers/clk/mediatek/clk-mt2701-mm.c | 41 ++++++++++++++++++++-------- >> 1 file changed, 29 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/clk/mediatek/clk-mt2701-mm.c b/drivers/clk/mediatek/clk-mt2701-mm.c >> index 054b597d4a73..4a9433c2b2b8 100644 >> --- a/drivers/clk/mediatek/clk-mt2701-mm.c >> +++ b/drivers/clk/mediatek/clk-mt2701-mm.c >> @@ -4,14 +4,20 @@ >> * Author: Shunli Wang <shunli.wang@mediatek.com> >> */ >> >> +#include <linux/module.h> >> #include <linux/clk-provider.h> >> #include <linux/platform_device.h> >> +#include <linux/slab.h> >> >> #include "clk-mtk.h" >> #include "clk-gate.h" >> >> #include <dt-bindings/clock/mt2701-clk.h> >> >> +struct clk_mt2701_mm_priv { >> + struct clk_onecell_data *clk_data; >> +}; >> + >> static const struct mtk_gate_regs disp0_cg_regs = { >> .set_ofs = 0x0104, >> .clr_ofs = 0x0108, >> @@ -79,23 +85,25 @@ static const struct mtk_gate mm_clks[] = { >> GATE_DISP1(CLK_MM_TVE_FMM, "mm_tve_fmm", "mm_sel", 14), >> }; >> >> -static const struct of_device_id of_match_clk_mt2701_mm[] = { >> - { .compatible = "mediatek,mt2701-mmsys", }, >> - {} >> -}; >> - >> static int clk_mt2701_mm_probe(struct platform_device *pdev) >> { >> - struct clk_onecell_data *clk_data; >> int r; >> - struct device_node *node = pdev->dev.of_node; >> + struct device_node *node = pdev->dev.parent->of_node; >> + struct clk_mt2701_mm_priv *private; >> + >> + private = devm_kzalloc(&pdev->dev, sizeof(*private), GFP_KERNEL); >> + if (!private) >> + return -ENOMEM; >> >> - clk_data = mtk_alloc_clk_data(CLK_MM_NR); >> + private->clk_data = mtk_alloc_clk_data(CLK_MM_NR); >> + >> + platform_set_drvdata(pdev, private); >> >> mtk_clk_register_gates(node, mm_clks, ARRAY_SIZE(mm_clks), >> - clk_data); >> + private->clk_data); >> >> - r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); >> + r = of_clk_add_provider(node, of_clk_src_onecell_get, >> + private->clk_data); >> if (r) >> dev_err(&pdev->dev, >> "could not register clock provider: %s: %d\n", >> @@ -104,12 +112,21 @@ static int clk_mt2701_mm_probe(struct platform_device *pdev) >> return r; >> } >> >> +static int clk_mt2701_mm_remove(struct platform_device *pdev) >> +{ >> + struct clk_mt2701_mm_priv *private = platform_get_drvdata(pdev); >> + > > I think that private->clk_data->clks is also kallocated and need to be freed? > > But I think that the best approach now is to switch to use devm allocations in > clk-mt2701-mm.c and this remove function will not be needed. > This is an API change which will affect over 50 drivers. For now I'll fix it by adding a kfree here. I will send a follow-up patch to fix it in the API. Good catch! Matthias >> + kfree(private->clk_data); >> + >> + return 0; >> +} >> + >> static struct platform_driver clk_mt2701_mm_drv = { >> .probe = clk_mt2701_mm_probe, >> + .remove = clk_mt2701_mm_remove, >> .driver = { >> .name = "clk-mt2701-mm", >> - .of_match_table = of_match_clk_mt2701_mm, >> }, >> }; >> >> -builtin_platform_driver(clk_mt2701_mm_drv); >> +module_platform_driver(clk_mt2701_mm_drv); >>
diff --git a/drivers/clk/mediatek/clk-mt2701-mm.c b/drivers/clk/mediatek/clk-mt2701-mm.c index 054b597d4a73..4a9433c2b2b8 100644 --- a/drivers/clk/mediatek/clk-mt2701-mm.c +++ b/drivers/clk/mediatek/clk-mt2701-mm.c @@ -4,14 +4,20 @@ * Author: Shunli Wang <shunli.wang@mediatek.com> */ +#include <linux/module.h> #include <linux/clk-provider.h> #include <linux/platform_device.h> +#include <linux/slab.h> #include "clk-mtk.h" #include "clk-gate.h" #include <dt-bindings/clock/mt2701-clk.h> +struct clk_mt2701_mm_priv { + struct clk_onecell_data *clk_data; +}; + static const struct mtk_gate_regs disp0_cg_regs = { .set_ofs = 0x0104, .clr_ofs = 0x0108, @@ -79,23 +85,25 @@ static const struct mtk_gate mm_clks[] = { GATE_DISP1(CLK_MM_TVE_FMM, "mm_tve_fmm", "mm_sel", 14), }; -static const struct of_device_id of_match_clk_mt2701_mm[] = { - { .compatible = "mediatek,mt2701-mmsys", }, - {} -}; - static int clk_mt2701_mm_probe(struct platform_device *pdev) { - struct clk_onecell_data *clk_data; int r; - struct device_node *node = pdev->dev.of_node; + struct device_node *node = pdev->dev.parent->of_node; + struct clk_mt2701_mm_priv *private; + + private = devm_kzalloc(&pdev->dev, sizeof(*private), GFP_KERNEL); + if (!private) + return -ENOMEM; - clk_data = mtk_alloc_clk_data(CLK_MM_NR); + private->clk_data = mtk_alloc_clk_data(CLK_MM_NR); + + platform_set_drvdata(pdev, private); mtk_clk_register_gates(node, mm_clks, ARRAY_SIZE(mm_clks), - clk_data); + private->clk_data); - r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); + r = of_clk_add_provider(node, of_clk_src_onecell_get, + private->clk_data); if (r) dev_err(&pdev->dev, "could not register clock provider: %s: %d\n", @@ -104,12 +112,21 @@ static int clk_mt2701_mm_probe(struct platform_device *pdev) return r; } +static int clk_mt2701_mm_remove(struct platform_device *pdev) +{ + struct clk_mt2701_mm_priv *private = platform_get_drvdata(pdev); + + kfree(private->clk_data); + + return 0; +} + static struct platform_driver clk_mt2701_mm_drv = { .probe = clk_mt2701_mm_probe, + .remove = clk_mt2701_mm_remove, .driver = { .name = "clk-mt2701-mm", - .of_match_table = of_match_clk_mt2701_mm, }, }; -builtin_platform_driver(clk_mt2701_mm_drv); +module_platform_driver(clk_mt2701_mm_drv);