Message ID | 20200904074505.24917-1-zhangqing@rock-chips.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | clk: rockchip: Support module build | expand |
Am Freitag, 4. September 2020, 09:45:05 CEST schrieb Elaine Zhang: > support CLK_OF_DECLARE and builtin_platform_driver_probe > double clk init method. > add module author, description and license to support building > Soc Rk3399 clock driver as module. > > Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com> > Reviewed-by: Kever Yang <kever.yang@rock-chips.com> > --- > drivers/clk/rockchip/clk-rk3399.c | 55 +++++++++++++++++++++++++++++++ > 1 file changed, 55 insertions(+) > > diff --git a/drivers/clk/rockchip/clk-rk3399.c b/drivers/clk/rockchip/clk-rk3399.c > index ce1d2446f142..40ff17aee5b6 100644 > --- a/drivers/clk/rockchip/clk-rk3399.c > +++ b/drivers/clk/rockchip/clk-rk3399.c > @@ -5,9 +5,11 @@ > */ > > #include <linux/clk-provider.h> > +#include <linux/module.h> > #include <linux/io.h> > #include <linux/of.h> > #include <linux/of_address.h> > +#include <linux/of_device.h> > #include <linux/platform_device.h> > #include <linux/regmap.h> > #include <dt-bindings/clock/rk3399-cru.h> > @@ -1600,3 +1602,56 @@ static void __init rk3399_pmu_clk_init(struct device_node *np) > rockchip_clk_of_add_provider(np, ctx); > } > CLK_OF_DECLARE(rk3399_cru_pmu, "rockchip,rk3399-pmucru", rk3399_pmu_clk_init); > + > +struct clk_rk3399_inits { > + void (*inits)(struct device_node *np); > +}; > + > +static const struct clk_rk3399_inits clk_rk3399_pmucru_init = { > + .inits = rk3399_pmu_clk_init, > +}; > + > +static const struct clk_rk3399_inits clk_rk3399_cru_init = { > + .inits = rk3399_clk_init, > +}; > + > +static const struct of_device_id clk_rk3399_match_table[] = { > + { > + .compatible = "rockchip,rk3399-cru", > + .data = &clk_rk3399_cru_init, > + }, { > + .compatible = "rockchip,rk3399-pmucru", > + .data = &clk_rk3399_pmucru_init, > + }, > + { } > +}; > +MODULE_DEVICE_TABLE(of, clk_rk3399_match_table); > + > +static int __init clk_rk3399_probe(struct platform_device *pdev) > +{ > + struct device_node *np = pdev->dev.of_node; > + const struct of_device_id *match; > + const struct clk_rk3399_inits *init_data; > + > + match = of_match_device(clk_rk3399_match_table, &pdev->dev); > + if (!match || !match->data) > + return -EINVAL; > + > + init_data = match->data; > + if (init_data->inits) > + init_data->inits(np); > + > + return 0; > +} > + > +static struct platform_driver clk_rk3399_driver = { > + .driver = { > + .name = "clk-rk3399", > + .of_match_table = clk_rk3399_match_table, I guess we probably want .suppress_bind_attrs = true, here, because there is no unloading. Also what happens when you try to rmmod the module? Heiko
hi, 在 2020/9/7 上午6:49, Heiko Stübner 写道: > Am Freitag, 4. September 2020, 09:45:05 CEST schrieb Elaine Zhang: >> support CLK_OF_DECLARE and builtin_platform_driver_probe >> double clk init method. >> add module author, description and license to support building >> Soc Rk3399 clock driver as module. >> >> Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com> >> Reviewed-by: Kever Yang <kever.yang@rock-chips.com> >> --- >> drivers/clk/rockchip/clk-rk3399.c | 55 +++++++++++++++++++++++++++++++ >> 1 file changed, 55 insertions(+) >> >> diff --git a/drivers/clk/rockchip/clk-rk3399.c b/drivers/clk/rockchip/clk-rk3399.c >> index ce1d2446f142..40ff17aee5b6 100644 >> --- a/drivers/clk/rockchip/clk-rk3399.c >> +++ b/drivers/clk/rockchip/clk-rk3399.c >> @@ -5,9 +5,11 @@ >> */ >> >> #include <linux/clk-provider.h> >> +#include <linux/module.h> >> #include <linux/io.h> >> #include <linux/of.h> >> #include <linux/of_address.h> >> +#include <linux/of_device.h> >> #include <linux/platform_device.h> >> #include <linux/regmap.h> >> #include <dt-bindings/clock/rk3399-cru.h> >> @@ -1600,3 +1602,56 @@ static void __init rk3399_pmu_clk_init(struct device_node *np) >> rockchip_clk_of_add_provider(np, ctx); >> } >> CLK_OF_DECLARE(rk3399_cru_pmu, "rockchip,rk3399-pmucru", rk3399_pmu_clk_init); >> + >> +struct clk_rk3399_inits { >> + void (*inits)(struct device_node *np); >> +}; >> + >> +static const struct clk_rk3399_inits clk_rk3399_pmucru_init = { >> + .inits = rk3399_pmu_clk_init, >> +}; >> + >> +static const struct clk_rk3399_inits clk_rk3399_cru_init = { >> + .inits = rk3399_clk_init, >> +}; >> + >> +static const struct of_device_id clk_rk3399_match_table[] = { >> + { >> + .compatible = "rockchip,rk3399-cru", >> + .data = &clk_rk3399_cru_init, >> + }, { >> + .compatible = "rockchip,rk3399-pmucru", >> + .data = &clk_rk3399_pmucru_init, >> + }, >> + { } >> +}; >> +MODULE_DEVICE_TABLE(of, clk_rk3399_match_table); >> + >> +static int __init clk_rk3399_probe(struct platform_device *pdev) >> +{ >> + struct device_node *np = pdev->dev.of_node; >> + const struct of_device_id *match; >> + const struct clk_rk3399_inits *init_data; >> + >> + match = of_match_device(clk_rk3399_match_table, &pdev->dev); >> + if (!match || !match->data) >> + return -EINVAL; >> + >> + init_data = match->data; >> + if (init_data->inits) >> + init_data->inits(np); >> + >> + return 0; >> +} >> + >> +static struct platform_driver clk_rk3399_driver = { >> + .driver = { >> + .name = "clk-rk3399", >> + .of_match_table = clk_rk3399_match_table, > I guess we probably want > .suppress_bind_attrs = true, OK, I will add it in the next version. > > here, because there is no unloading. > Also what happens when you try to rmmod the module? console:/ # lsmod | grep clk clk_rk808 16384 0 clk_rk3399 49152 0 [permanent] clk_rockchip 57344 32 rockchip_dmc,rockchip_opp_select,clk_rk3399 rockchip_sip 24576 6 rk_vcodec,rockchip_pwm_remotectl,rockchip_bus,nvmem_rockchip_efuse,rockchip_pm_config,clk_rockchip console:/ # rmmod clk_rk3399 rmmod: failed to unload clk_rk3399: Device or resource busy console:/ # rmmod -f clk_rk3399 rmmod: failed to unload clk_rk3399: Device or resource busy The builtin_platform_driver_probe() without the __exit parts. > > Heiko > > > >
diff --git a/drivers/clk/rockchip/clk-rk3399.c b/drivers/clk/rockchip/clk-rk3399.c index ce1d2446f142..40ff17aee5b6 100644 --- a/drivers/clk/rockchip/clk-rk3399.c +++ b/drivers/clk/rockchip/clk-rk3399.c @@ -5,9 +5,11 @@ */ #include <linux/clk-provider.h> +#include <linux/module.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_address.h> +#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <dt-bindings/clock/rk3399-cru.h> @@ -1600,3 +1602,56 @@ static void __init rk3399_pmu_clk_init(struct device_node *np) rockchip_clk_of_add_provider(np, ctx); } CLK_OF_DECLARE(rk3399_cru_pmu, "rockchip,rk3399-pmucru", rk3399_pmu_clk_init); + +struct clk_rk3399_inits { + void (*inits)(struct device_node *np); +}; + +static const struct clk_rk3399_inits clk_rk3399_pmucru_init = { + .inits = rk3399_pmu_clk_init, +}; + +static const struct clk_rk3399_inits clk_rk3399_cru_init = { + .inits = rk3399_clk_init, +}; + +static const struct of_device_id clk_rk3399_match_table[] = { + { + .compatible = "rockchip,rk3399-cru", + .data = &clk_rk3399_cru_init, + }, { + .compatible = "rockchip,rk3399-pmucru", + .data = &clk_rk3399_pmucru_init, + }, + { } +}; +MODULE_DEVICE_TABLE(of, clk_rk3399_match_table); + +static int __init clk_rk3399_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + const struct of_device_id *match; + const struct clk_rk3399_inits *init_data; + + match = of_match_device(clk_rk3399_match_table, &pdev->dev); + if (!match || !match->data) + return -EINVAL; + + init_data = match->data; + if (init_data->inits) + init_data->inits(np); + + return 0; +} + +static struct platform_driver clk_rk3399_driver = { + .driver = { + .name = "clk-rk3399", + .of_match_table = clk_rk3399_match_table, + }, +}; +builtin_platform_driver_probe(clk_rk3399_driver, clk_rk3399_probe); + +MODULE_DESCRIPTION("Rockchip RK3399 Clock Driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:clk-rk3399");