clk: hisilicon: Migrate devm APIs
v2 cover clk: hisilicon: Migrate devm APIs
Migrate devm APIs for HiSilicon clock drivers and remove redundant codes.
This series is a partial improvement of [1]
v2: fix test robot error
Links:
[1]: https://lore.kernel.org/r/[email protected]
v1: https://lore.kernel.org/r/[email protected]
David Yang (4):
clk: hisilicon: Add helper functions for platform driver
clk: hisilicon: Use helper functions
clk: hisilicon: Convert to platform driver
clk: hisilicon: Migrate devm APIs
drivers/clk/hisilicon/clk-hi3519.c | 134 +------ drivers/clk/hisilicon/clk-hi3559a.c | 253 +++---------- drivers/clk/hisilicon/clk-hi3620.c | 215 +++++------ drivers/clk/hisilicon/clk-hi3660.c | 207 ++++------- drivers/clk/hisilicon/clk-hi3670.c | 270 +++++--------- drivers/clk/hisilicon/clk-hi6220-stub.c | 9 +- drivers/clk/hisilicon/clk-hi6220.c | 230 ++++++------ drivers/clk/hisilicon/clk-hip04.c | 41 ++- drivers/clk/hisilicon/clk-hisi-phase.c | 13 +- drivers/clk/hisilicon/clk-hix5hd2.c | 96 +++-- drivers/clk/hisilicon/clk.c | 429 +++++++++++----------- drivers/clk/hisilicon/clk.h | 147 +++++--- drivers/clk/hisilicon/clkdivider-hi6220.c | 24 +- drivers/clk/hisilicon/clkgate-separated.c | 26 +- drivers/clk/hisilicon/crg-hi3516cv300.c | 177 +-------- drivers/clk/hisilicon/crg-hi3798cv200.c | 206 ++--------- drivers/clk/hisilicon/crg.h | 11 +- drivers/clk/hisilicon/reset.c | 47 ++- 18 files changed, 973 insertions(+), 1562 deletions(-)
base-commit: fff5a5e7f528b2ed2c335991399a766c2cf01103
Signature · 1 line
2.39.2
PATCH v2 1/4 clk: hisilicon: Add helper functions for platform driver
Helper functions extract common operations on platform drivers.
During migration to devm APIs, (virtual) fixed clocks were found hard on devm APIs, since they often depended by crucial peripherals, thus require early initialization before device probing, and cannot use devm APIs.
One solution to this problem is to add a "fixed-clock" node to device tree, independent to clock device, and make those peripherals depend on that. However, there is also some devices that do use fixed clocks provided by drivers, for example clk-hi3660.c .
To simplify codes, we migrate clocks of other types to devm APIs, while keep fixed clocks self-managed, alongside with struct hisi_clock_data, and remove devm-managed hisi_clock_data.
hisi_clk_alloc will be removed in the following patch.
--- drivers/clk/hisilicon/clk.c | 148 ++++++++++++++++++++++++++++++++++ drivers/clk/hisilicon/clk.h | 56 +++++++++++-- drivers/clk/hisilicon/crg.h | 5 ++ drivers/clk/hisilicon/reset.c | 47 ++++++++++- 4 files changed, 248 insertions(+), 8 deletions(-)
drivers/clk/hisilicon/clk.c +148 -0
@@ -88,6 +88,25 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np, }EXPORT_SYMBOL_GPL (hisi_clk_init); +void hisi_clk_free (struct device_node *np,struct hisi_clock_data *data) +{ +if (data->clks) { +if (data->clks->fixed_rate_clks_num) +hisi_clk_unregister_fixed_rate (data->clks->fixed_rate_clks, + data->clks->fixed_rate_clks_num, + data); +if (data->clks->fixed_factor_clks_num) +hisi_clk_unregister_fixed_factor (data->clks->fixed_factor_clks, + data->clks->fixed_factor_clks_num, + data); + } + +of_clk_del_provider (np); +kfree (data->clk_data.clks); +kfree (data); +} +EXPORT_SYMBOL_GPL (hisi_clk_free); +int hisi_clk_register_fixed_rate (const struct hisi_fixed_rate_clock *clks,int nums,struct hisi_clock_data *data) {
@@ -341,3 +360,132 @@ void __init hi6220_clk_register_divider(const struct hi6220_divider_clock *clks, data->clk_data.clks[clks[i].id] = clk; } } + +int hisi_clk_register (struct device *dev,const struct hisi_clocks *clks, +struct hisi_clock_data *data) +{ +int ret; + +if (clks->mux_clks_num) { + ret =hisi_clk_register_mux (clks->mux_clks, + clks->mux_clks_num, data); +if (ret) +return ret; + } + +if (clks->phase_clks_num) { + ret =hisi_clk_register_phase (dev, clks->phase_clks, + clks->phase_clks_num, data); +if (ret) +return ret; + } + +if (clks->divider_clks_num) { + ret =hisi_clk_register_divider (clks->divider_clks, + clks->divider_clks_num, data); +if (ret) +return ret; + } + +if (clks->gate_clks_num) { + ret =hisi_clk_register_gate (clks->gate_clks, + clks->gate_clks_num, data); +if (ret) +return ret; + } + +if (clks->gate_sep_clks_num) { +hisi_clk_register_gate_sep (clks->gate_sep_clks, + clks->gate_sep_clks_num, data); + } + +if (clks->clk_register_customized && clks->customized_clks_num) { + ret = clks->clk_register_customized (dev, clks->customized_clks, + clks->customized_clks_num, data); +if (ret) +return ret; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (hisi_clk_register); + +int hisi_clk_early_init (struct device_node *np,const struct hisi_clocks *clks) +{ +struct hisi_clock_data *data; +int ret; + + data =hisi_clk_init (np, clks->nr); +if (!data) +return -ENOMEM ; + data->clks = clks; + + ret =hisi_clk_register_fixed_rate (clks->fixed_rate_clks, + clks->fixed_rate_clks_num, data); +if (ret) + goto err; + + ret =hisi_clk_register_fixed_factor (clks->fixed_factor_clks, + clks->fixed_factor_clks_num, data); +if (ret) + goto err; + + np->data = data; +return 0 ; + +err: +hisi_clk_free (np, data); +return ret; +} +EXPORT_SYMBOL_GPL (hisi_clk_early_init); + +int hisi_clk_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +const struct hisi_clocks *clks; +struct hisi_clock_data *data; +int ret; + + clks =of_device_get_match_data (dev); +if (!clks) +return -ENOENT ; + +if (!np->data) { + ret =hisi_clk_early_init (np, clks); +if (ret) +return ret; + } + + data = np->data; + np->data =NULL ; + +if (clks->prologue) { + ret = clks->prologue (dev, data); +if (ret) + goto err; + } + + ret =hisi_clk_register (dev, clks, data); +if (ret) + goto err; + +platform_set_drvdata (pdev, data); +return 0 ; + +err: +hisi_clk_free (np, data); +return ret; +} +EXPORT_SYMBOL_GPL (hisi_clk_probe); + +int hisi_clk_remove (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct hisi_clock_data *data =platform_get_drvdata (pdev); + +hisi_clk_free (np, data); +return 0 ; +} +EXPORT_SYMBOL_GPL (hisi_clk_remove);
drivers/clk/hisilicon/clk.h +50 -6
89 lines not on this page · raw message
drivers/clk/hisilicon/crg.h +5 -0
@@ -22,4 +22,9 @@ struct hisi_crg_dev { const struct hisi_crg_funcs *funcs; }; +/* helper functions for platform driver */ + +int hisi_crg_probe (struct platform_device *pdev); +int hisi_crg_remove (struct platform_device *pdev); +#endif /* __HISI_CRG_H */
drivers/clk/hisilicon/reset.c +45 -2
60 lines not on this page · raw message
Signature · 1 line
2.39.2
Stephen Boyd
maintainerRe: [PATCH v2 1/4] clk: hisilicon: Add helper functions for platform driver
Quoting David Yang (2023-03-29 00:50:50)
Quoted 5 lines
drivers/clk/hisilicon/clk.h +0
-0
drivers/clk/hisilicon/clk.h struct hisi_gate_clock { · line 114
Quoted 10 lines
drivers/clk/hisilicon/clk.h +7
-0@@ -103,6 +105,38 @@ struct hisi_gate_clock {const char *alias; }; +struct hisi_clocks { +int nr; + +int (*prologue)(struct device *dev,struct hisi_clock_data *data); + +const struct hisi_fixed_rate_clock *fixed_rate_clks; +int fixed_rate_clks_num;
size_t for all these num types and 'nr'?
Quoted 50 lines
drivers/clk/hisilicon/clk.h +35
-1+ +const struct hisi_fixed_factor_clock *fixed_factor_clks; +int fixed_factor_clks_num; + +const struct hisi_mux_clock *mux_clks; +int mux_clks_num; + +const struct hisi_phase_clock *phase_clks; +int phase_clks_num; + +const struct hisi_divider_clock *divider_clks; +int divider_clks_num; + +const struct hisi_gate_clock *gate_clks; +int gate_clks_num; + +const struct hisi_gate_clock *gate_sep_clks; +int gate_sep_clks_num; + +const void *customized_clks; +int customized_clks_num; +int (*clk_register_customized)(struct device *dev,const void *clks, +int num,struct hisi_clock_data *data); +}; + struct clk *hisi_register_clkgate_sep(struct device *, const char *, const char *, unsigned long, void __iomem *, u8,@@ -134,7 +169,16 @@ void hisi_clk_register_gate_sep(const struct hisi_gate_clock *,void hi6220_clk_register_divider (const struct hi6220_divider_clock *,int ,struct hisi_clock_data *); -#define hisi_clk_unregister (type) \ +int hisi_clk_register (struct device *dev,const struct hisi_clocks *clks, +struct hisi_clock_data *data); + +/* helper functions for platform driver */ + +int hisi_clk_early_init (struct device_node *np,const struct hisi_clocks *clks); +int hisi_clk_probe (struct platform_device *pdev); +int hisi_clk_remove (struct platform_device *pdev); + +#define hisi_clk_unregister_fn (type) \ static inline \ void hisi_clk_unregister_##type(const struct hisi_##type##_clock *clks, \ int nums, struct hisi_clock_data *data) \@@ -148,10 +192,10 @@ void hisi_clk_unregister_##type(const struct hisi_##type##_clock *clks, \ } \ }
drivers/clk/hisilicon/clk.h void hisi_clk_unregister_##type(const struct hisi_##type##_clock *clks, \ · line 199
Quoted 10 lines
drivers/clk/hisilicon/clk.h +5
-5-hisi_clk_unregister(fixed_rate) -hisi_clk_unregister(fixed_factor) -hisi_clk_unregister(mux) -hisi_clk_unregister(divider) -hisi_clk_unregister(gate) +hisi_clk_unregister_fn(fixed_rate) +hisi_clk_unregister_fn(fixed_factor) +hisi_clk_unregister_fn(mux) +hisi_clk_unregister_fn(divider) +hisi_clk_unregister_fn(gate)
What does this hunk have to do with the $subject patch? Can you break this series down into smaller patches? This is probably clearing the way for hisi_clk_unregister() being an actual function, but I don't know. It can
Quoted 21 lines
drivers/clk/hisilicon/clk.h +0
-0#endif /* __HISI_CLK_H */ drivers/clk/hisilicon/crg.h +5
-0@@ -22,4 +22,9 @@ struct hisi_crg_dev { const struct hisi_crg_funcs *funcs; }; +/* helper functions for platform driver */ + +int hisi_crg_probe (struct platform_device *pdev); +int hisi_crg_remove (struct platform_device *pdev); +#endif /* __HISI_CRG_H */ drivers/clk/hisilicon/reset.c +0
-0
drivers/clk/hisilicon/reset.c line 10
Quoted 8 lines
drivers/clk/hisilicon/reset.c +2
-1@@ -5,12 +5,16 @@* Copyright (c) 2015-2016 HiSilicon Technologies Co., Ltd. */ +#include <linux/device.h> #include <linux/io.h> +#include <linux/kernel.h> #include <linux/of_address.h> -#include <linux/platform_device.h>
Why?
drivers/clk/hisilicon/reset.c line 12
Quoted 1 line
drivers/clk/hisilicon/reset.c +1
-0+#include <linux/of_device.h>
Why?
drivers/clk/hisilicon/reset.c line 12
Quoted 2 lines
drivers/clk/hisilicon/reset.c +0
-1#include <linux/reset-controller.h> -#include <linux/slab.h>
Why?
Quoted 7 lines
drivers/clk/hisilicon/reset.c +3
-0#include <linux/spinlock.h> + +#include "clk.h" +#include "crg.h" #include "reset.h" #define HISI_RESET_BIT_MASK 0x1f
PATCH v2 2/4 clk: hisilicon: Use helper functions
In reply to David YangRemove redundant codes.
--- drivers/clk/hisilicon/clk-hi3519.c | 134 ++---------- drivers/clk/hisilicon/clk-hi3559a.c | 228 +++----------------- drivers/clk/hisilicon/clk-hi3660.c | 207 ++++++------------ drivers/clk/hisilicon/clk-hi3670.c | 270 +++++++++--------------- drivers/clk/hisilicon/crg-hi3516cv300.c | 177 ++-------------- drivers/clk/hisilicon/crg-hi3798cv200.c | 206 +++--------------- drivers/clk/hisilicon/crg.h | 6 - 7 files changed, 260 insertions(+), 968 deletions(-)
drivers/clk/hisilicon/clk-hi3519.c +19 -115
@@ -6,11 +6,13 @@*/ #include <dt-bindings/clock/hi3519-clock.h> -#include <linux/clk-provider.h> + +#include <linux/kernel.h> #include <linux/module.h> -#include <linux/platform_device.h> +#include <linux/of_device.h> +#include "clk.h" -#include "reset.h" +#include "crg.h" #define HI3519_INNER_CLK_OFFSET 64#define HI3519_FIXED_24M 65
@@ -73,131 +75,33 @@ static const struct hisi_gate_clock hi3519_gate_clks[] = { CLK_SET_RATE_PARENT, 0xe4, 18, 0, }, }; -static struct hisi_clock_data *hi3519_clk_register (struct platform_device *pdev) -{ -struct hisi_clock_data *clk_data; -int ret; - - clk_data =hisi_clk_alloc (pdev,HI3519_NR_CLKS ); -if (!clk_data) -return ERR_PTR (-ENOMEM ); - - ret =hisi_clk_register_fixed_rate (hi3519_fixed_rate_clks, -ARRAY_SIZE (hi3519_fixed_rate_clks), - clk_data); -if (ret) -return ERR_PTR (ret); - - ret =hisi_clk_register_mux (hi3519_mux_clks, -ARRAY_SIZE (hi3519_mux_clks), - clk_data); -if (ret) - goto unregister_fixed_rate; - - ret =hisi_clk_register_gate (hi3519_gate_clks, -ARRAY_SIZE (hi3519_gate_clks), - clk_data); -if (ret) - goto unregister_mux; - - ret =of_clk_add_provider (pdev->dev.of_node, - of_clk_src_onecell_get, &clk_data->clk_data); -if (ret) - goto unregister_gate; - -return clk_data; - -unregister_fixed_rate: -hisi_clk_unregister_fixed_rate (hi3519_fixed_rate_clks, -ARRAY_SIZE (hi3519_fixed_rate_clks), - clk_data); - -unregister_mux: -hisi_clk_unregister_mux (hi3519_mux_clks, -ARRAY_SIZE (hi3519_mux_clks), - clk_data); -unregister_gate: -hisi_clk_unregister_gate (hi3519_gate_clks, -ARRAY_SIZE (hi3519_gate_clks), - clk_data); -return ERR_PTR (ret); -} - -static void hi3519_clk_unregister (struct platform_device *pdev) -{ -struct hi3519_crg_data *crg =platform_get_drvdata (pdev); - -of_clk_del_provider (pdev->dev.of_node); - -hisi_clk_unregister_gate (hi3519_gate_clks, -ARRAY_SIZE (hi3519_mux_clks), - crg->clk_data); -hisi_clk_unregister_mux (hi3519_mux_clks, -ARRAY_SIZE (hi3519_mux_clks), - crg->clk_data); -hisi_clk_unregister_fixed_rate (hi3519_fixed_rate_clks, -ARRAY_SIZE (hi3519_fixed_rate_clks), - crg->clk_data); -} - -static int hi3519_clk_probe (struct platform_device *pdev) -{ -struct hi3519_crg_data *crg; - - crg =devm_kmalloc (&pdev->dev,sizeof (*crg),GFP_KERNEL ); -if (!crg) -return -ENOMEM ; - - crg->rstc =hisi_reset_init (pdev); -if (!crg->rstc) -return -ENOMEM ; - - crg->clk_data =hi3519_clk_register (pdev); -if (IS_ERR (crg->clk_data)) { -hisi_reset_exit (crg->rstc); -return PTR_ERR (crg->clk_data); - } - -platform_set_drvdata (pdev, crg); -return 0 ; -} - -static int hi3519_clk_remove (struct platform_device *pdev) -{ -struct hi3519_crg_data *crg =platform_get_drvdata (pdev); - -hisi_reset_exit (crg->rstc); -hi3519_clk_unregister (pdev); -return 0 ; -} - +static const struct hisi_clocks hi3519_crg_clks = { + .nr =HI3519_NR_CLKS , + .fixed_rate_clks = hi3519_fixed_rate_clks, + .fixed_rate_clks_num =ARRAY_SIZE (hi3519_fixed_rate_clks), + .mux_clks = hi3519_mux_clks, + .mux_clks_num =ARRAY_SIZE (hi3519_mux_clks), + .gate_clks = hi3519_gate_clks, + .gate_clks_num =ARRAY_SIZE (hi3519_gate_clks), +};static const struct of_device_id hi3519_clk_match_table[] = { - { .compatible ="hisilicon,hi3519-crg" }, + { .compatible ="hisilicon,hi3519-crg" , + .data = &hi3519_crg_clks }, { } };MODULE_DEVICE_TABLE (of, hi3519_clk_match_table);static struct platform_driver hi3519_clk_driver = { - .probe = hi3519_clk_probe, - .remove = hi3519_clk_remove, + .probe = hisi_crg_probe, + .remove = hisi_crg_remove, .driver = { .name ="hi3519-clk" , .of_match_table = hi3519_clk_match_table, }, }; -static int __init hi3519_clk_init (void ) -{ -return platform_driver_register (&hi3519_clk_driver); -} -core_initcall (hi3519_clk_init); - -static void __exit hi3519_clk_exit(void) -{ -platform_driver_unregister (&hi3519_clk_driver); -} -module_exit (hi3519_clk_exit); +module_platform_driver (hi3519_clk_driver);MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("HiSilicon Hi3519 Clock Driver" );
drivers/clk/hisilicon/clk-hi3559a.c +35 -193
292 lines not on this page · raw message
drivers/clk/hisilicon/clk-hi3660.c +66 -141
244 lines not on this page · raw message
drivers/clk/hisilicon/clk-hi3670.c +95 -175
299 lines not on this page · raw message
drivers/clk/hisilicon/crg-hi3516cv300.c +20 -157
219 lines not on this page · raw message
drivers/clk/hisilicon/crg-hi3798cv200.c +25 -181
250 lines not on this page · raw message
drivers/clk/hisilicon/crg.h +0 -6
@@ -11,15 +11,9 @@struct hisi_clock_data ;struct hisi_reset_controller ; -struct hisi_crg_funcs { -struct hisi_clock_data * (*register_clks)(struct platform_device *pdev); -void (*unregister_clks)(struct platform_device *pdev); -}; -struct hisi_crg_dev {struct hisi_clock_data *clk_data;struct hisi_reset_controller *rstc; -const struct hisi_crg_funcs *funcs; };/* helper functions for platform driver */
Signature · 1 line
2.39.2
Stephen Boyd
maintainerRe: [PATCH v2 2/4] clk: hisilicon: Use helper functions
Quoting David Yang (2023-03-29 00:50:51)
Quoted 10 lines
Remove redundant codes.
Signed-off-by David Yang <[email protected]>--- drivers/clk/hisilicon/clk-hi3519.c | 134 ++---------- drivers/clk/hisilicon/clk-hi3559a.c | 228 +++----------------- drivers/clk/hisilicon/clk-hi3660.c | 207 ++++++------------ drivers/clk/hisilicon/clk-hi3670.c | 270 +++++++++--------------- drivers/clk/hisilicon/crg-hi3516cv300.c | 177 ++-------------- drivers/clk/hisilicon/crg-hi3798cv200.c | 206 +++---------------
Maybe you can do this file by file in a different patch? And the commit text can say that you're migrating to the new way of registering clks with a device pointer?
drivers/clk/hisilicon/clk-hi3519.c line 9
Quoted 12 lines
drivers/clk/hisilicon/crg.h | 6 - 7 files changed, 260 insertions(+), 968 deletions(-)drivers/clk/hisilicon/clk-hi3519.c +0
-1@@ -6,11 +6,13 @@*/ #include <dt-bindings/clock/hi3519-clock.h> -#include <linux/clk-provider.h>
It's still a clk provider. Keep this include.
drivers/clk/hisilicon/clk-hi3519.c line 11
Quoted 4 lines
drivers/clk/hisilicon/clk-hi3519.c +2
-1+ +#include <linux/kernel.h> #include <linux/module.h> -#include <linux/platform_device.h>
Also still a platform driver. Keep this include.
drivers/clk/hisilicon/clk-hi3519.c line 12
Quoted 1 line
drivers/clk/hisilicon/clk-hi3519.c +1
-0+#include <linux/of_device.h>
Not sure what this include is for.
Quoted 4 lines
drivers/clk/hisilicon/clk-hi3519.c +2
-1+#include "clk.h" -#include "reset.h" +#include "crg.h"
PATCH v2 3/4 clk: hisilicon: Convert to platform driver
In reply to David YangAnd use common helper functions.
This patch is part of devm APIs migration.
--- drivers/clk/hisilicon/clk-hi3620.c | 195 ++++++++++++------------ drivers/clk/hisilicon/clk-hi6220.c | 225 +++++++++++++--------------- drivers/clk/hisilicon/clk-hip04.c | 41 +++-- drivers/clk/hisilicon/clk-hix5hd2.c | 83 ++++++---- 4 files changed, 281 insertions(+), 263 deletions(-)
drivers/clk/hisilicon/clk-hi3620.c +100 -95
@@ -12,6 +12,7 @@#include <linux/kernel.h> #include <linux/clk-provider.h> #include <linux/io.h> +#include <linux/module.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_device.h>
@@ -22,48 +23,48 @@#include "clk.h" /* clock parent list */ -static const char *const timer0_mux_p[]__initconst = {"osc32k" ,"timerclk01" , }; -static const char *const timer1_mux_p[]__initconst = {"osc32k" ,"timerclk01" , }; -static const char *const timer2_mux_p[]__initconst = {"osc32k" ,"timerclk23" , }; -static const char *const timer3_mux_p[]__initconst = {"osc32k" ,"timerclk23" , }; -static const char *const timer4_mux_p[]__initconst = {"osc32k" ,"timerclk45" , }; -static const char *const timer5_mux_p[]__initconst = {"osc32k" ,"timerclk45" , }; -static const char *const timer6_mux_p[]__initconst = {"osc32k" ,"timerclk67" , }; -static const char *const timer7_mux_p[]__initconst = {"osc32k" ,"timerclk67" , }; -static const char *const timer8_mux_p[]__initconst = {"osc32k" ,"timerclk89" , }; -static const char *const timer9_mux_p[]__initconst = {"osc32k" ,"timerclk89" , }; -static const char *const uart0_mux_p[]__initconst = {"osc26m" ,"pclk" , }; -static const char *const uart1_mux_p[]__initconst = {"osc26m" ,"pclk" , }; -static const char *const uart2_mux_p[]__initconst = {"osc26m" ,"pclk" , }; -static const char *const uart3_mux_p[]__initconst = {"osc26m" ,"pclk" , }; -static const char *const uart4_mux_p[]__initconst = {"osc26m" ,"pclk" , }; -static const char *const spi0_mux_p[]__initconst = {"osc26m" ,"rclk_cfgaxi" , }; -static const char *const spi1_mux_p[]__initconst = {"osc26m" ,"rclk_cfgaxi" , }; -static const char *const spi2_mux_p[]__initconst = {"osc26m" ,"rclk_cfgaxi" , }; +static const char *const timer0_mux_p[] = {"osc32k" ,"timerclk01" , }; +static const char *const timer1_mux_p[] = {"osc32k" ,"timerclk01" , }; +static const char *const timer2_mux_p[] = {"osc32k" ,"timerclk23" , }; +static const char *const timer3_mux_p[] = {"osc32k" ,"timerclk23" , }; +static const char *const timer4_mux_p[] = {"osc32k" ,"timerclk45" , }; +static const char *const timer5_mux_p[] = {"osc32k" ,"timerclk45" , }; +static const char *const timer6_mux_p[] = {"osc32k" ,"timerclk67" , }; +static const char *const timer7_mux_p[] = {"osc32k" ,"timerclk67" , }; +static const char *const timer8_mux_p[] = {"osc32k" ,"timerclk89" , }; +static const char *const timer9_mux_p[] = {"osc32k" ,"timerclk89" , }; +static const char *const uart0_mux_p[] = {"osc26m" ,"pclk" , }; +static const char *const uart1_mux_p[] = {"osc26m" ,"pclk" , }; +static const char *const uart2_mux_p[] = {"osc26m" ,"pclk" , }; +static const char *const uart3_mux_p[] = {"osc26m" ,"pclk" , }; +static const char *const uart4_mux_p[] = {"osc26m" ,"pclk" , }; +static const char *const spi0_mux_p[] = {"osc26m" ,"rclk_cfgaxi" , }; +static const char *const spi1_mux_p[] = {"osc26m" ,"rclk_cfgaxi" , }; +static const char *const spi2_mux_p[] = {"osc26m" ,"rclk_cfgaxi" , };/* share axi parent */ -static const char *const saxi_mux_p[]__initconst = {"armpll3" ,"armpll2" , }; -static const char *const pwm0_mux_p[]__initconst = {"osc32k" ,"osc26m" , }; -static const char *const pwm1_mux_p[]__initconst = {"osc32k" ,"osc26m" , }; -static const char *const sd_mux_p[]__initconst = {"armpll2" ,"armpll3" , }; -static const char *const mmc1_mux_p[]__initconst = {"armpll2" ,"armpll3" , }; -static const char *const mmc1_mux2_p[]__initconst = {"osc26m" ,"mmc1_div" , }; -static const char *const g2d_mux_p[]__initconst = {"armpll2" ,"armpll3" , }; -static const char *const venc_mux_p[]__initconst = {"armpll2" ,"armpll3" , }; -static const char *const vdec_mux_p[]__initconst = {"armpll2" ,"armpll3" , }; -static const char *const vpp_mux_p[]__initconst = {"armpll2" ,"armpll3" , }; -static const char *const edc0_mux_p[]__initconst = {"armpll2" ,"armpll3" , }; -static const char *const ldi0_mux_p[]__initconst = {"armpll2" ,"armpll4" , +static const char *const saxi_mux_p[] = {"armpll3" ,"armpll2" , }; +static const char *const pwm0_mux_p[] = {"osc32k" ,"osc26m" , }; +static const char *const pwm1_mux_p[] = {"osc32k" ,"osc26m" , }; +static const char *const sd_mux_p[] = {"armpll2" ,"armpll3" , }; +static const char *const mmc1_mux_p[] = {"armpll2" ,"armpll3" , }; +static const char *const mmc1_mux2_p[] = {"osc26m" ,"mmc1_div" , }; +static const char *const g2d_mux_p[] = {"armpll2" ,"armpll3" , }; +static const char *const venc_mux_p[] = {"armpll2" ,"armpll3" , }; +static const char *const vdec_mux_p[] = {"armpll2" ,"armpll3" , }; +static const char *const vpp_mux_p[] = {"armpll2" ,"armpll3" , }; +static const char *const edc0_mux_p[] = {"armpll2" ,"armpll3" , }; +static const char *const ldi0_mux_p[] = {"armpll2" ,"armpll4" ,"armpll3" ,"armpll5" , }; -static const char *const edc1_mux_p[]__initconst = {"armpll2" ,"armpll3" , }; -static const char *const ldi1_mux_p[]__initconst = {"armpll2" ,"armpll4" , +static const char *const edc1_mux_p[] = {"armpll2" ,"armpll3" , }; +static const char *const ldi1_mux_p[] = {"armpll2" ,"armpll4" ,"armpll3" ,"armpll5" , }; -static const char *const rclk_hsic_p[]__initconst = {"armpll3" ,"armpll2" , }; -static const char *const mmc2_mux_p[]__initconst = {"armpll2" ,"armpll3" , }; -static const char *const mmc3_mux_p[]__initconst = {"armpll2" ,"armpll3" , }; +static const char *const rclk_hsic_p[] = {"armpll3" ,"armpll2" , }; +static const char *const mmc2_mux_p[] = {"armpll2" ,"armpll3" , }; +static const char *const mmc3_mux_p[] = {"armpll2" ,"armpll3" , };/* fixed rate clocks */ -static struct hisi_fixed_rate_clock hi3620_fixed_rate_clks[]__initdata = { +static struct hisi_fixed_rate_clock hi3620_fixed_rate_clks[] = { {HI3620_OSC32K ,"osc32k" ,NULL ,0 ,32768 , }, {HI3620_OSC26M ,"osc26m" ,NULL ,0 ,26000000 , }, {HI3620_PCLK ,"pclk" ,NULL ,0 ,26000000 , },
@@ -76,13 +77,13 @@ static struct hisi_fixed_rate_clock hi3620_fixed_rate_clks[] __initdata = { };/* fixed factor clocks */ -static struct hisi_fixed_factor_clock hi3620_fixed_factor_clks[]__initdata = { +static struct hisi_fixed_factor_clock hi3620_fixed_factor_clks[] = { {HI3620_RCLK_TCXO ,"rclk_tcxo" ,"osc26m" ,1 ,4 ,0 , }, {HI3620_RCLK_CFGAXI ,"rclk_cfgaxi" ,"armpll2" ,1 ,30 ,0 , }, {HI3620_RCLK_PICO ,"rclk_pico" ,"hsic_div" ,1 ,40 ,0 , }, }; -static struct hisi_mux_clock hi3620_mux_clks[]__initdata = { +static struct hisi_mux_clock hi3620_mux_clks[] = { {HI3620_TIMER0_MUX ,"timer0_mux" , timer0_mux_p,ARRAY_SIZE (timer0_mux_p),CLK_SET_RATE_PARENT ,0 ,15 ,2 ,0 , }, {HI3620_TIMER1_MUX ,"timer1_mux" , timer1_mux_p,ARRAY_SIZE (timer1_mux_p),CLK_SET_RATE_PARENT ,0 ,17 ,2 ,0 , }, {HI3620_TIMER2_MUX ,"timer2_mux" , timer2_mux_p,ARRAY_SIZE (timer2_mux_p),CLK_SET_RATE_PARENT ,0 ,19 ,2 ,0 , },
@@ -120,7 +121,7 @@ static struct hisi_mux_clock hi3620_mux_clks[] __initdata = { { HI3620_MMC3_MUX, "mmc3_mux", mmc3_mux_p, ARRAY_SIZE(mmc3_mux_p), CLK_SET_RATE_PARENT, 0x140, 9, 1, CLK_MUX_HIWORD_MASK, }, }; -static struct hisi_divider_clock hi3620_div_clks[]__initdata = { +static struct hisi_divider_clock hi3620_div_clks[] = { {HI3620_SHAREAXI_DIV ,"saxi_div" ,"saxi_mux" ,0 ,0x100 ,0 ,5 ,CLK_DIVIDER_HIWORD_MASK ,NULL , }, {HI3620_CFGAXI_DIV ,"cfgaxi_div" ,"saxi_div" ,0 ,0x100 ,5 ,2 ,CLK_DIVIDER_HIWORD_MASK ,NULL , }, { HI3620_SD_DIV, "sd_div", "sd_mux", 0, 0x108, 0, 4, CLK_DIVIDER_HIWORD_MASK, NULL, },
@@ -130,7 +131,7 @@ static struct hisi_divider_clock hi3620_div_clks[] __initdata = { { HI3620_MMC3_DIV, "mmc3_div", "mmc3_mux", 0, 0x140, 5, 4, CLK_DIVIDER_HIWORD_MASK, NULL, }, }; -static struct hisi_gate_clock hi3620_separated_gate_clks[]__initdata = { +static struct hisi_gate_clock hi3620_separated_gate_clks[] = { {HI3620_TIMERCLK01 ,"timerclk01" ,"timer_rclk01" ,CLK_SET_RATE_PARENT ,0x20 ,0 ,0 , }, {HI3620_TIMER_RCLK01 ,"timer_rclk01" ,"rclk_tcxo" ,CLK_SET_RATE_PARENT ,0x20 ,1 ,0 , }, { HI3620_TIMERCLK23, "timerclk23", "timer_rclk23", CLK_SET_RATE_PARENT, 0x20, 2, 0, },
@@ -192,29 +193,19 @@ static struct hisi_gate_clock hi3620_separated_gate_clks[] __initdata = { { HI3620_MCU_CLK, "mcu_clk", "acp_clk", CLK_SET_RATE_PARENT, 0x50, 24, 0, }, }; -static void __init hi3620_clk_init (struct device_node *np) -{ -struct hisi_clock_data *clk_data; - - clk_data =hisi_clk_init (np,HI3620_NR_CLKS ); -if (!clk_data) -return ; - -hisi_clk_register_fixed_rate (hi3620_fixed_rate_clks, -ARRAY_SIZE (hi3620_fixed_rate_clks), - clk_data); -hisi_clk_register_fixed_factor (hi3620_fixed_factor_clks, -ARRAY_SIZE (hi3620_fixed_factor_clks), - clk_data); -hisi_clk_register_mux (hi3620_mux_clks,ARRAY_SIZE (hi3620_mux_clks), - clk_data); -hisi_clk_register_divider (hi3620_div_clks,ARRAY_SIZE (hi3620_div_clks), - clk_data); -hisi_clk_register_gate_sep (hi3620_separated_gate_clks, -ARRAY_SIZE (hi3620_separated_gate_clks), - clk_data); -} -CLK_OF_DECLARE (hi3620_clk,"hisilicon,hi3620-clock" , hi3620_clk_init); +static const struct hisi_clocks hi3620_clks = { + .nr =HI3620_NR_CLKS , + .fixed_rate_clks = hi3620_fixed_rate_clks, + .fixed_rate_clks_num =ARRAY_SIZE (hi3620_fixed_rate_clks), + .fixed_factor_clks = hi3620_fixed_factor_clks, + .fixed_factor_clks_num =ARRAY_SIZE (hi3620_fixed_factor_clks), + .mux_clks = hi3620_mux_clks, + .mux_clks_num =ARRAY_SIZE (hi3620_mux_clks), + .divider_clks = hi3620_div_clks, + .divider_clks_num =ARRAY_SIZE (hi3620_div_clks), + .gate_sep_clks = hi3620_separated_gate_clks, + .gate_sep_clks_num =ARRAY_SIZE (hi3620_separated_gate_clks), +}; struct hisi_mmc_clock { unsigned int id;
@@ -252,7 +243,7 @@ struct clk_mmc {#define to_mmc (_hw) container_of(_hw, struct clk_mmc, hw) -static struct hisi_mmc_clock hi3620_mmc_clks[]__initdata = { +static struct hisi_mmc_clock hi3620_mmc_clks[] = { {HI3620_SD_CIUCLK ,"sd_bclk1" ,"sd_clk" ,CLK_SET_RATE_PARENT ,0x1f8 ,0 ,0x1f8 ,1 ,3 ,0x1f8 ,4 ,4 ,0x1f8 ,8 ,4 }, {HI3620_MMC_CIUCLK1 ,"mmc_bclk1" ,"mmc_clk1" ,CLK_SET_RATE_PARENT ,0x1f8 ,12 ,0x1f8 ,13 ,3 ,0x1f8 ,16 ,4 ,0x1f8 ,20 ,4 }, {HI3620_MMC_CIUCLK2 ,"mmc_bclk2" ,"mmc_clk2" ,CLK_SET_RATE_PARENT ,0x1f8 ,24 ,0x1f8 ,25 ,3 ,0x1f8 ,28 ,4 ,0x1fc ,0 ,4 },
@@ -408,8 +399,9 @@ static const struct clk_ops clk_mmc_ops = { .recalc_rate = mmc_clk_recalc_rate, }; -static struct clk *hisi_register_clk_mmc (struct hisi_mmc_clock *mmc_clk, -void __iomem *base,struct device_node *np) +static struct clk * +clk_register_hisi_mmc (struct device *dev,const struct hisi_mmc_clock *mmc_clk, +void __iomem *base) {struct clk_mmc *mclk;struct clk *clk;
@@ -445,39 +437,52 @@ static struct clk *hisi_register_clk_mmc(struct hisi_mmc_clock *mmc_clk,return clk; } -static void __init hi3620_mmc_clk_init (struct device_node *node) +static int hisi_register_clk_mmc (struct device *dev,const void *clocks, +int nums,struct hisi_clock_data *data) { -void __iomem *base; -int i, num =ARRAY_SIZE (hi3620_mmc_clks); -struct clk_onecell_data *clk_data; - -if (!node) { -pr_err ("failed to find pctrl node in DTS\n" ); -return ; - } - - base =of_iomap (node,0 ); -if (!base) { -pr_err ("failed to map pctrl\n" ); -return ; +const struct hisi_mmc_clock *clks = clocks; +struct clk *clk; +int i; + +for (i =0 ; i < nums; i++) { + clk =clk_register_hisi_mmc (dev, &clks[i], data->base); +if (IS_ERR (clk)) { +pr_err ("%s: failed to register clock %s\n" , + __func__, clks[i].name); +return PTR_ERR (clk); + } + data->clk_data.clks[clks[i].id] = clk; } - clk_data =kzalloc (sizeof (*clk_data),GFP_KERNEL ); -if (WARN_ON (!clk_data)) -return ; +return 0 ; +} - clk_data->clks =kcalloc (num,sizeof (*clk_data->clks),GFP_KERNEL ); -if (!clk_data->clks) -return ; +static const struct hisi_clocks hi3620_clks_mmc = { + .nr =ARRAY_SIZE (hi3620_mmc_clks), + .customized_clks = hi3620_mmc_clks, + .customized_clks_num =ARRAY_SIZE (hi3620_mmc_clks), + .clk_register_customized = hisi_register_clk_mmc, +}; -for (i =0 ; i < num; i++) { -struct hisi_mmc_clock *mmc_clk = &hi3620_mmc_clks[i]; - clk_data->clks[mmc_clk->id] = -hisi_register_clk_mmc (mmc_clk, base, node); - } +static const struct of_device_id hi3620_clk_match_table[] = { + { .compatible ="hisilicon,hi3620-clock" , + .data = &hi3620_clks }, + { .compatible ="hisilicon,hi3620-mmc-clock" , + .data = &hi3620_clks_mmc }, + { } +}; +MODULE_DEVICE_TABLE (of, hi3620_clk_match_table); + +static struct platform_driver hi3620_clk_driver = { + .probe = hisi_clk_probe, + .remove = hisi_clk_remove, + .driver = { + .name ="hi3620-clock" , + .of_match_table = hi3620_clk_match_table, + }, +}; - clk_data->clk_num = num; -of_clk_add_provider (node, of_clk_src_onecell_get, clk_data); -} +module_platform_driver (hi3620_clk_driver); -CLK_OF_DECLARE (hi3620_mmc_clk,"hisilicon,hi3620-mmc-clock" , hi3620_mmc_clk_init); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("HiSilicon Hi3620 Clock Driver" );
drivers/clk/hisilicon/clk-hi6220.c +105 -120
317 lines not on this page · raw message
drivers/clk/hisilicon/clk-hip04.c +25 -16
53 lines not on this page · raw message
drivers/clk/hisilicon/clk-hix5hd2.c +51 -32
145 lines not on this page · raw message
Signature · 1 line
2.39.2
Stephen Boyd
maintainerRe: [PATCH v2 3/4] clk: hisilicon: Convert to platform driver
Quoting David Yang (2023-03-29 00:50:52)
Quoted 5 lines
drivers/clk/hisilicon/clk-hi3620.c +0
-5- clk_data); -hisi_clk_register_fixed_factor (hi3620_fixed_factor_clks, -ARRAY_SIZE (hi3620_fixed_factor_clks), - clk_data); - hisi_clk_register_mux(hi3620_mux_clks, ARRAY_SIZE(hi3620_mux_clks),
drivers/clk/hisilicon/clk-hi3620.c static struct hisi_gate_clock hi3620_separated_gate_clks[] __initdata = { · line 197
Quoted 10 lines
drivers/clk/hisilicon/clk-hi3620.c +2
-8- clk_data); -hisi_clk_register_divider (hi3620_div_clks,ARRAY_SIZE (hi3620_div_clks), - clk_data); -hisi_clk_register_gate_sep (hi3620_separated_gate_clks, -ARRAY_SIZE (hi3620_separated_gate_clks), - clk_data); -} -CLK_OF_DECLARE (hi3620_clk,"hisilicon,hi3620-clock" , hi3620_clk_init); +static const struct hisi_clocks hi3620_clks = { + .nr =HI3620_NR_CLKS ,
Can this simply be calculated by adding together all the _num members?
Quoted 7 lines
drivers/clk/hisilicon/clk-hi3620.c +7
-0+ .fixed_rate_clks = hi3620_fixed_rate_clks, + .fixed_rate_clks_num = ARRAY_SIZE(hi3620_fixed_rate_clks), + .fixed_factor_clks = hi3620_fixed_factor_clks, + .fixed_factor_clks_num = ARRAY_SIZE(hi3620_fixed_factor_clks), + .mux_clks = hi3620_mux_clks, + .mux_clks_num =ARRAY_SIZE (hi3620_mux_clks), + .divider_clks = hi3620_div_clks
PATCH v2 4/4 clk: hisilicon: Migrate devm APIs
In reply to David YangMigrates devm APIs for HiSilicon clock drivers.
--- drivers/clk/hisilicon/clk-hi3559a.c | 29 +- drivers/clk/hisilicon/clk-hi3620.c | 28 +- drivers/clk/hisilicon/clk-hi6220-stub.c | 9 +- drivers/clk/hisilicon/clk-hi6220.c | 13 +- drivers/clk/hisilicon/clk-hisi-phase.c | 13 +- drivers/clk/hisilicon/clk-hix5hd2.c | 15 +- drivers/clk/hisilicon/clk.c | 411 +++++++--------------- drivers/clk/hisilicon/clk.h | 97 ++--- drivers/clk/hisilicon/clkdivider-hi6220.c | 24 +- drivers/clk/hisilicon/clkgate-separated.c | 26 +- 10 files changed, 263 insertions(+), 402 deletions(-)
drivers/clk/hisilicon/clk-hi3559a.c +13 -16
@@ -457,17 +457,16 @@ hisi_clk_register_pll(struct device *dev, const void *clocks, {const struct hi3559av100_pll_clock *clks = clocks;void __iomem *base = data->base; -struct hi3559av100_clk_pll *p_clk =NULL ; -struct clk *clk =NULL ; +struct hi3559av100_clk_pll *p_clk;struct clk_init_data init;int i; - - p_clk =devm_kzalloc (dev,sizeof (*p_clk) * nums,GFP_KERNEL ); - -if (!p_clk) -return -ENOMEM ; +int ret;for (i =0 ; i < nums; i++) { + p_clk =devm_kzalloc (dev,sizeof (*p_clk),GFP_KERNEL ); +if (!p_clk) +return -ENOMEM ; + init.name = clks[i].name; init.flags =0 ; init.parent_names =
@@ -490,16 +489,14 @@ hisi_clk_register_pll(struct device *dev, const void *clocks, p_clk->refdiv_width = clks[i].refdiv_width; p_clk->hw.init = &init; - clk =clk_register (NULL , &p_clk->hw); -if (IS_ERR (clk)) { -devm_kfree (dev, p_clk); + ret =devm_clk_hw_register (dev, &p_clk->hw); +if (ret) {dev_err (dev,"%s: failed to register clock %s\n" , - __func__, clks[i].name); -return PTR_ERR (clk); + __func__, clks[i].name); +return ret; } - data->clk_data.clks[clks[i].id] = clk; - p_clk++; + data->clk_data->hws[clks[i].id] = &p_clk->hw; }return 0 ;
@@ -628,7 +625,7 @@ static int hi3559av100_shub_default_clk_set(struct device *dev, struct hisi_clocvoid __iomem *crg_base;unsigned int val; - crg_base =ioremap (CRG_BASE_ADDR ,SZ_4K ); + crg_base =devm_ioremap (dev,CRG_BASE_ADDR ,SZ_4K );/* SSP: 192M/2 */ val =readl_relaxed (crg_base +0x20 );
@@ -640,7 +637,7 @@ static int hi3559av100_shub_default_clk_set(struct device *dev, struct hisi_cloc val |= (0x1 <<28 );writel_relaxed (val, crg_base +0x1C ); -iounmap (crg_base); +devm_iounmap (dev, crg_base); crg_base =NULL ;return 0 ;
drivers/clk/hisilicon/clk-hi3620.c +15 -13
@@ -11,12 +11,10 @@#include <linux/kernel.h> #include <linux/clk-provider.h> +#include <linux/device.h> #include <linux/io.h> #include <linux/module.h> -#include <linux/of.h> -#include <linux/of_address.h> #include <linux/of_device.h> -#include <linux/slab.h> #include <dt-bindings/clock/hi3620-clock.h>
@@ -399,15 +397,15 @@ static const struct clk_ops clk_mmc_ops = { .recalc_rate = mmc_clk_recalc_rate, }; -static struct clk * +static struct clk_hw *clk_register_hisi_mmc (struct device *dev,const struct hisi_mmc_clock *mmc_clk,void __iomem *base) {struct clk_mmc *mclk; -struct clk *clk;struct clk_init_data init; +int ret; - mclk =kzalloc (sizeof (*mclk),GFP_KERNEL ); + mclk =devm_kzalloc (dev,sizeof (*mclk),GFP_KERNEL );if (!mclk)return ERR_PTR (-ENOMEM );
@@ -431,27 +429,31 @@ clk_register_hisi_mmc(struct device *dev, const struct hisi_mmc_clock *mmc_clk, mclk->sam_off = mmc_clk->sam_off; mclk->sam_bits = mmc_clk->sam_bits; - clk =clk_register (NULL , &mclk->hw); -if (WARN_ON (IS_ERR (clk))) -kfree (mclk); -return clk; + ret =devm_clk_hw_register (dev, &mclk->hw); +if (ret) { +dev_err (dev,"%s: failed to register clock %s\n" , + __func__, init.name); +return ERR_PTR (ret); + } + +return &mclk->hw; }static int hisi_register_clk_mmc (struct device *dev,const void *clocks,int nums,struct hisi_clock_data *data) {const struct hisi_mmc_clock *clks = clocks; -struct clk *clk;int i;for (i =0 ; i < nums; i++) { - clk =clk_register_hisi_mmc (dev, &clks[i], data->base); +struct clk_hw *clk =clk_register_hisi_mmc (dev, &clks[i], data->base); +if (IS_ERR (clk)) {pr_err ("%s: failed to register clock %s\n" , __func__, clks[i].name);return PTR_ERR (clk); } - data->clk_data.clks[clks[i].id] = clk; + data->clk_data->hws[clks[i].id] = clk; }return 0 ;
drivers/clk/hisilicon/clk-hi6220-stub.c +4 -5
@@ -195,7 +195,6 @@ static int hi6220_stub_clk_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct clk_init_data init;struct hi6220_stub_clk *stub_clk; -struct clk *clk;struct device_node *np = pdev->dev.of_node;int ret;
@@ -233,11 +232,11 @@ static int hi6220_stub_clk_probe(struct platform_device *pdev) init.num_parents =0 ; init.flags =0 ; - clk =devm_clk_register (dev, &stub_clk->hw); -if (IS_ERR (clk)) -return PTR_ERR (clk); + ret =devm_clk_hw_register (dev, &stub_clk->hw); +if (ret) +return ret; - ret =of_clk_add_provider (np, of_clk_src_simple_get, clk); + ret =devm_of_clk_add_hw_provider (dev, of_clk_hw_simple_get, &stub_clk->hw);if (ret) {dev_err (dev,"failed to register OF clock provider\n" );return ret;
drivers/clk/hisilicon/clk-hi6220.c +10 -3
@@ -16,6 +16,13 @@#include "clk.h" +static int +hi6220_clk_register_divider_stub (struct device *dev,const void *clks, +int num,struct hisi_clock_data *data) +{ +return hi6220_clk_register_divider (dev, clks, num, data); +} +/* clocks in AO (always on) controller */ static struct hisi_fixed_rate_clock hi6220_fixed_rate_clks[] = { {HI6220_REF32K ,"ref32k" ,NULL ,0 ,32764 , },
@@ -176,7 +183,7 @@ static const struct hisi_clocks hi6220_sys_clks = { .gate_sep_clks_num = ARRAY_SIZE(hi6220_separated_gate_clks_sys), .customized_clks = hi6220_div_clks_sys, .customized_clks_num = ARRAY_SIZE(hi6220_div_clks_sys), -/* .clk_register_customized = hi6220_clk_register_divider, */ + .clk_register_customized = hi6220_clk_register_divider_stub, };/* clocks in media controller */
@@ -224,7 +231,7 @@ static const struct hisi_clocks hi6220_media_clks = { .gate_sep_clks_num = ARRAY_SIZE(hi6220_separated_gate_clks_media), .customized_clks = hi6220_div_clks_media, .customized_clks_num = ARRAY_SIZE(hi6220_div_clks_media), -/* .clk_register_customized = hi6220_clk_register_divider, */ + .clk_register_customized = hi6220_clk_register_divider_stub, };/* clocks in pmctrl */
@@ -247,7 +254,7 @@ static const struct hisi_clocks hi6220_power_clks = { .gate_clks_num = ARRAY_SIZE(hi6220_gate_clks_power), .customized_clks = hi6220_div_clks_power, .customized_clks_num = ARRAY_SIZE(hi6220_div_clks_power), -/* .clk_register_customized = hi6220_clk_register_divider, */ + .clk_register_customized = hi6220_clk_register_divider_stub, };/* clocks in acpu */
drivers/clk/hisilicon/clk-hisi-phase.c +9 -4
@@ -5,11 +5,11 @@* Simple HiSilicon phase clock implementation. */ +#include <linux/device.h> #include <linux/err.h> #include <linux/io.h> #include <linux/module.h> #include <linux/platform_device.h> -#include <linux/slab.h> #include "clk.h"
@@ -90,12 +90,13 @@ static const struct clk_ops clk_phase_ops = { .set_phase = hisi_clk_set_phase, }; -struct clk *clk_register_hisi_phase (struct device *dev, +struct clk_hw *devm_clk_hw_register_hisi_phase (struct device *dev,const struct hisi_phase_clock *clks,void __iomem *base,spinlock_t *lock) {struct clk_hisi_phase *phase;struct clk_init_data init; +int ret; phase =devm_kzalloc (dev,sizeof (struct clk_hisi_phase ),GFP_KERNEL );if (!phase)
@@ -116,6 +117,10 @@ struct clk *clk_register_hisi_phase(struct device *dev, phase->phase_num = clks->phase_num; phase->hw.init = &init; -return devm_clk_register (dev, &phase->hw); + ret =devm_clk_hw_register (dev, &phase->hw); +if (ret) +return ERR_PTR (ret); + +return &phase->hw; } -EXPORT_SYMBOL_GPL (clk_register_hisi_phase); +EXPORT_SYMBOL_GPL (devm_clk_hw_register_hisi_phase);
drivers/clk/hisilicon/clk-hix5hd2.c +7 -8
@@ -6,7 +6,7 @@#include <dt-bindings/clock/hix5hd2-clock.h> -#include <linux/slab.h> +#include <linux/device.h> #include <linux/delay.h> #include <linux/kernel.h> #include <linux/module.h>
@@ -260,13 +260,13 @@ hix5hd2_clk_register_complex(struct device *dev, const void *clocks, int nums,const struct hix5hd2_complex_clock *clks = clocks;void __iomem *base = data->base;int i; +int ret;for (i =0 ; i < nums; i++) {struct hix5hd2_clk_complex *p_clk; -struct clk *clk;struct clk_init_data init; - p_clk =kzalloc (sizeof (*p_clk),GFP_KERNEL ); + p_clk =devm_kzalloc (dev,sizeof (*p_clk),GFP_KERNEL );if (!p_clk)return -ENOMEM ;
@@ -289,15 +289,14 @@ hix5hd2_clk_register_complex(struct device *dev, const void *clocks, int nums, p_clk->phy_rst_mask = clks[i].phy_rst_mask; p_clk->hw.init = &init; - clk =clk_register (NULL , &p_clk->hw); -if (IS_ERR (clk)) { -kfree (p_clk); + ret =devm_clk_hw_register (dev, &p_clk->hw); +if (ret) {pr_err ("%s: failed to register clock %s\n" , __func__, clks[i].name); -return PTR_ERR (p_clk); +return ret; } - data->clk_data.clks[clks[i].id] = clk; + data->clk_data->hws[clks[i].id] = &p_clk->hw; }return 0 ;
drivers/clk/hisilicon/clk.c +125 -286
516 lines not on this page · raw message
drivers/clk/hisilicon/clk.h +56 -41
130 lines not on this page · raw message
drivers/clk/hisilicon/clkdivider-hi6220.c +10 -14
@@ -9,7 +9,7 @@#include <linux/kernel.h> #include <linux/clk-provider.h> -#include <linux/slab.h> +#include <linux/device.h> #include <linux/io.h> #include <linux/err.h> #include <linux/spinlock.h>
@@ -97,19 +97,19 @@ static const struct clk_ops hi6220_clkdiv_ops = { .set_rate = hi6220_clkdiv_set_rate, }; -struct clk *hi6220_register_clkdiv (struct device *dev,const char *name, +struct clk_hw *devm_clk_hw_register_hi6220_divider (struct device *dev,const char *name,const char *parent_name,unsigned long flags,void __iomem *reg,u8 shift,u8 width,u32 mask_bit,spinlock_t *lock) {struct hi6220_clk_divider *div; -struct clk *clk;struct clk_init_data init;struct clk_div_table *table;u32 max_div, min_div;int i; +int ret;/* allocate the divider */ - div =kzalloc (sizeof (*div),GFP_KERNEL ); + div =devm_kzalloc (dev,sizeof (*div),GFP_KERNEL );if (!div)return ERR_PTR (-ENOMEM );
@@ -117,11 +117,9 @@ struct clk *hi6220_register_clkdiv(struct device *dev, const char *name, max_div =div_mask (width) +1 ; min_div =1 ; - table =kcalloc (max_div +1 ,sizeof (*table),GFP_KERNEL ); -if (!table) { -kfree (div); + table =devm_kcalloc (dev, max_div +1 ,sizeof (*table),GFP_KERNEL ); +if (!table)return ERR_PTR (-ENOMEM ); - }for (i =0 ; i < max_div; i++) { table[i].div = min_div + i;
@@ -144,11 +142,9 @@ struct clk *hi6220_register_clkdiv(struct device *dev, const char *name, div->table = table;/* register the clock */ - clk =clk_register (dev, &div->hw); -if (IS_ERR (clk)) { -kfree (table); -kfree (div); - } + ret =devm_clk_hw_register (dev, &div->hw); +if (ret) +return ERR_PTR (ret); -return clk; +return &div->hw; }
drivers/clk/hisilicon/clkgate-separated.c +14 -12
@@ -11,8 +11,8 @@#include <linux/kernel.h> #include <linux/clk-provider.h> +#include <linux/device.h> #include <linux/io.h> -#include <linux/slab.h> #include "clk.h"
@@ -80,17 +80,18 @@ static const struct clk_ops clkgate_separated_ops = { .is_enabled = clkgate_separated_is_enabled, }; -struct clk *hisi_register_clkgate_sep (struct device *dev,const char *name, -const char *parent_name, -unsigned long flags, -void __iomem *reg,u8 bit_idx, -u8 clk_gate_flags,spinlock_t *lock) +struct clk_hw * +devm_clk_hw_register_hisi_gate_sep (struct device *dev,const char *name, +const char *parent_name, +unsigned long flags, +void __iomem *reg,u8 bit_idx, +u8 clk_gate_flags,spinlock_t *lock) {struct clkgate_separated *sclk; -struct clk *clk;struct clk_init_data init; +int ret; - sclk =kzalloc (sizeof (*sclk),GFP_KERNEL ); + sclk =devm_kzalloc (dev,sizeof (*sclk),GFP_KERNEL );if (!sclk)return ERR_PTR (-ENOMEM );
@@ -106,8 +107,9 @@ struct clk *hisi_register_clkgate_sep(struct device *dev, const char *name, sclk->hw.init = &init; sclk->lock = lock; - clk =clk_register (dev, &sclk->hw); -if (IS_ERR (clk)) -kfree (sclk); -return clk; + ret =devm_clk_hw_register (dev, &sclk->hw); +if (ret) +return ERR_PTR (ret); + +return &sclk->hw; }
Signature · 1 line
2.39.2
Stephen Boyd
maintainerQuoting David Yang (2023-03-29 00:50:49)
Quoted 4 lines
Migrate devm APIs for HiSilicon clock drivers and remove redundant codes.
This series is a partial improvement of [1]
Run checkpatch.pl
WARNING: Macros with flow control statements should be avoided #591: FILE: drivers/clk/hisilicon/clk.c:146:
+#define hisi_clk_register_fn(fn, type, stmt) \
+int fn(struct device *dev, const struct type *clks, \
+ int num, struct hisi_clock_data *data) \
+{ \
+ void __iomem *base = data->base; \
+ int i; \
+\
+ for (i = 0; i < num; i++) { \
+ const struct type *p_clk = &clks[i]; \
+ struct clk_hw *clk = stmt; \
+\
+ if (IS_ERR(clk)) { \
+ pr_err("%s: failed to register clock %s\n", \
+ __func__, p_clk->name); \
+ return PTR_ERR(clk); \
+ } \
+\
+ if (p_clk->alias) \
+ clk_hw_register_clkdev(clk, p_clk->alias, NULL); \
+\
+ data->clk_data->hws[p_clk->id] = clk; \
+ } \
+\
+ return 0; \
+} \
+EXPORT_SYMBOL_GPL(fn);
WARNING: macros should not use a trailing semicolon #591: FILE: drivers/clk/hisilicon/clk.c:146:
+#define hisi_clk_register_fn(fn, type, stmt) \
+int fn(struct device *dev, const struct type *clks, \
+ int num, struct hisi_clock_data *data) \
+{ \
+ void __iomem *base = data->base; \
+ int i; \
+\
+ for (i = 0; i < num; i++) { \
+ const struct type *p_clk = &clks[i]; \
+ struct clk_hw *clk = stmt; \
+\
+ if (IS_ERR(clk)) { \
+ pr_err("%s: failed to register clock %s\n", \
+ __func__, p_clk->name); \
+ return PTR_ERR(clk); \
+ } \
+\
+ if (p_clk->alias) \
+ clk_hw_register_clkdev(clk, p_clk->alias, NULL); \
+\
+ data->clk_data->hws[p_clk->id] = clk; \
+ } \
+\
+ return 0; \
+} \
+EXPORT_SYMBOL_GPL(fn);
total: 0 errors, 2 warnings, 1019 lines checked
in patch 'clk: hisilicon: Migrate devm APIs' (8d960cbef61a)
WARNING: Prefer "GPL" over "GPL v2" - see commit bf7fbeeae6db ("module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2" bogosity") #627: FILE: drivers/clk/hisilicon/clk-hi6220.c:291:
+MODULE_LICENSE("GPL v2");
WARNING: DT compatible string "hisilicon,hip04-clock" appears un-documented -- check ./Documentation/devicetree/bindings/ #661: FILE: drivers/clk/hisilicon/clk-hip04.c:33:
+ { .compatible = "hisilicon,hip04-clock",
WARNING: Prefer "GPL" over "GPL v2" - see commit bf7fbeeae6db ("module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2" bogosity") #842: FILE: drivers/clk/hisilicon/clk-hix5hd2.c:337:
+MODULE_LICENSE("GPL v2");
total: 0 errors, 3 warnings, 779 lines checked
in patch 'clk: hisilicon: Convert to platform driver' (2681347c2636)
WARNING: Prefer "GPL" over "GPL v2" - see commit bf7fbeeae6db ("module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2" bogosity") #1044: FILE: drivers/clk/hisilicon/clk-hi3670.c:935:
+MODULE_LICENSE("GPL v2");
total: 0 errors, 1 warnings, 1481 lines checked