From: Chen-Yu Tsai <wenst@chromium.org> To: Michael Turquette <mturquette@baylibre.com>, Stephen Boyd <sboyd@kernel.org> Cc: Chen-Yu Tsai <wenst@chromium.org>, Matthias Brugger <matthias.bgg@gmail.com>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>, Rex-BC Chen <rex-bc.chen@mediatek.com>, Chun-Jie Chen <chun-jie.chen@mediatek.com>, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] clk: mediatek: mt8183-audio: Simplify with mtk_clk_simple_*() Date: Fri, 1 Jul 2022 22:51:32 +0800 [thread overview] Message-ID: <20220701145133.1152387-3-wenst@chromium.org> (raw) In-Reply-To: <20220701145133.1152387-1-wenst@chromium.org> mtk_clk_simple_*() was added after the MT8183 clock drivers were merged. They provide shared boiler plate for clock providers that only have clock gates. Since the driver also populates child nodes, which are for the audio subsystem, it can't be completely converted to using the functions. Simplify the MT8183 audio clock driver using mtk_clk_simple_*(), sequencing the of_platform_{populate,unpopulate} calls manually and correctly. This also adds proper remove support for the driver. Since the mtk_clk_simple_probe() function allocates the clk_hw pointer array based on .num_clks given, it effectively requires there are no holes in the clock ID map. Check that the size of the array matches the number of clocks with a static assertion. Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> --- drivers/clk/mediatek/clk-mt8183-audio.c | 40 ++++++++++++++++--------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/clk/mediatek/clk-mt8183-audio.c b/drivers/clk/mediatek/clk-mt8183-audio.c index b2d7746eddbe..b9255e0a36ae 100644 --- a/drivers/clk/mediatek/clk-mt8183-audio.c +++ b/drivers/clk/mediatek/clk-mt8183-audio.c @@ -67,35 +67,47 @@ static const struct mtk_gate audio_clks[] = { 20), }; +static_assert(ARRAY_SIZE(audio_clks) == CLK_AUDIO_NR_CLK); + +static const struct mtk_clk_desc audio_desc = { + .clks = audio_clks, + .num_clks = ARRAY_SIZE(audio_clks), +}; + static int clk_mt8183_audio_probe(struct platform_device *pdev) { - struct clk_hw_onecell_data *clk_data; - int r; - struct device_node *node = pdev->dev.of_node; + int ret; - clk_data = mtk_alloc_clk_data(CLK_AUDIO_NR_CLK); + ret = mtk_clk_simple_probe(pdev); + if (ret) + return ret; - mtk_clk_register_gates(node, audio_clks, ARRAY_SIZE(audio_clks), - clk_data); + ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); + if (ret) + goto err_remove_clks; - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data); - if (r) - return r; + return 0; - r = devm_of_platform_populate(&pdev->dev); - if (r) - of_clk_del_provider(node); +err_remove_clks: + mtk_clk_simple_remove(pdev); + return ret; +} + +static int clk_mt8183_audio_remove(struct platform_device *pdev) +{ + of_platform_depopulate(&pdev->dev); - return r; + return mtk_clk_simple_remove(pdev); } static const struct of_device_id of_match_clk_mt8183_audio[] = { - { .compatible = "mediatek,mt8183-audiosys", }, + { .compatible = "mediatek,mt8183-audiosys", .data = &audio_desc }, {} }; static struct platform_driver clk_mt8183_audio_drv = { .probe = clk_mt8183_audio_probe, + .remove = clk_mt8183_audio_remove, .driver = { .name = "clk-mt8183-audio", .of_match_table = of_match_clk_mt8183_audio, -- 2.37.0.rc0.161.g10f37bed90-goog
WARNING: multiple messages have this Message-ID (diff)
From: Chen-Yu Tsai <wenst@chromium.org> To: Michael Turquette <mturquette@baylibre.com>, Stephen Boyd <sboyd@kernel.org> Cc: Chen-Yu Tsai <wenst@chromium.org>, Matthias Brugger <matthias.bgg@gmail.com>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>, Rex-BC Chen <rex-bc.chen@mediatek.com>, Chun-Jie Chen <chun-jie.chen@mediatek.com>, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] clk: mediatek: mt8183-audio: Simplify with mtk_clk_simple_*() Date: Fri, 1 Jul 2022 22:51:32 +0800 [thread overview] Message-ID: <20220701145133.1152387-3-wenst@chromium.org> (raw) In-Reply-To: <20220701145133.1152387-1-wenst@chromium.org> mtk_clk_simple_*() was added after the MT8183 clock drivers were merged. They provide shared boiler plate for clock providers that only have clock gates. Since the driver also populates child nodes, which are for the audio subsystem, it can't be completely converted to using the functions. Simplify the MT8183 audio clock driver using mtk_clk_simple_*(), sequencing the of_platform_{populate,unpopulate} calls manually and correctly. This also adds proper remove support for the driver. Since the mtk_clk_simple_probe() function allocates the clk_hw pointer array based on .num_clks given, it effectively requires there are no holes in the clock ID map. Check that the size of the array matches the number of clocks with a static assertion. Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> --- drivers/clk/mediatek/clk-mt8183-audio.c | 40 ++++++++++++++++--------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/clk/mediatek/clk-mt8183-audio.c b/drivers/clk/mediatek/clk-mt8183-audio.c index b2d7746eddbe..b9255e0a36ae 100644 --- a/drivers/clk/mediatek/clk-mt8183-audio.c +++ b/drivers/clk/mediatek/clk-mt8183-audio.c @@ -67,35 +67,47 @@ static const struct mtk_gate audio_clks[] = { 20), }; +static_assert(ARRAY_SIZE(audio_clks) == CLK_AUDIO_NR_CLK); + +static const struct mtk_clk_desc audio_desc = { + .clks = audio_clks, + .num_clks = ARRAY_SIZE(audio_clks), +}; + static int clk_mt8183_audio_probe(struct platform_device *pdev) { - struct clk_hw_onecell_data *clk_data; - int r; - struct device_node *node = pdev->dev.of_node; + int ret; - clk_data = mtk_alloc_clk_data(CLK_AUDIO_NR_CLK); + ret = mtk_clk_simple_probe(pdev); + if (ret) + return ret; - mtk_clk_register_gates(node, audio_clks, ARRAY_SIZE(audio_clks), - clk_data); + ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); + if (ret) + goto err_remove_clks; - r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data); - if (r) - return r; + return 0; - r = devm_of_platform_populate(&pdev->dev); - if (r) - of_clk_del_provider(node); +err_remove_clks: + mtk_clk_simple_remove(pdev); + return ret; +} + +static int clk_mt8183_audio_remove(struct platform_device *pdev) +{ + of_platform_depopulate(&pdev->dev); - return r; + return mtk_clk_simple_remove(pdev); } static const struct of_device_id of_match_clk_mt8183_audio[] = { - { .compatible = "mediatek,mt8183-audiosys", }, + { .compatible = "mediatek,mt8183-audiosys", .data = &audio_desc }, {} }; static struct platform_driver clk_mt8183_audio_drv = { .probe = clk_mt8183_audio_probe, + .remove = clk_mt8183_audio_remove, .driver = { .name = "clk-mt8183-audio", .of_match_table = of_match_clk_mt8183_audio, -- 2.37.0.rc0.161.g10f37bed90-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-07-01 14:51 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-01 14:51 [PATCH 0/3] clk: mediatek: mt8183: Simplify with mtk_clk_simple_*() Chen-Yu Tsai 2022-07-01 14:51 ` Chen-Yu Tsai 2022-07-01 14:51 ` [PATCH 1/3] clk: mediatek: mt8183: Convert gate only drivers to mtk_clk_simple_*() Chen-Yu Tsai 2022-07-01 14:51 ` Chen-Yu Tsai 2022-07-01 14:51 ` Chen-Yu Tsai [this message] 2022-07-01 14:51 ` [PATCH 2/3] clk: mediatek: mt8183-audio: Simplify with mtk_clk_simple_*() Chen-Yu Tsai 2022-07-01 14:51 ` [PATCH 3/3] clk: mediatek: mt8183-mfgcfg: " Chen-Yu Tsai 2022-07-01 14:51 ` Chen-Yu Tsai 2022-07-04 8:46 ` [PATCH 0/3] clk: mediatek: mt8183: " AngeloGioacchino Del Regno 2022-07-04 8:46 ` AngeloGioacchino Del Regno
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220701145133.1152387-3-wenst@chromium.org \ --to=wenst@chromium.org \ --cc=angelogioacchino.delregno@collabora.com \ --cc=chun-jie.chen@mediatek.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-clk@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mediatek@lists.infradead.org \ --cc=matthias.bgg@gmail.com \ --cc=mturquette@baylibre.com \ --cc=rex-bc.chen@mediatek.com \ --cc=sboyd@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.