Add basic clocks and resets for JHB100 SoC
Subsystems (5)
v6 cover Add basic clocks and resets for JHB100 SoC
The JHB100 SoC includes CRG (Clock and Reset Generator) for multiple subsystems:
The JHB100 SoC is divided into multiple subsystems, and basically each subsystem includes a CRG(Clock and Reset Generator):
- sys0crg/sys1crg/sys2crg/
- per0crg/per1crg/per2crg/per3crg/
- voutcrg
- vcecrg
- gpu0crg/gpu1crg
- cpucrg
- usbcrg
- host0crg/host1crg
- pcierpcrg
- husb0crg/husb1crg
- husbcmncrg
- husbd0crg/husbd1crg
- npucrg
In the current series, we will only add the following CRG:
- sys0crg/sys1crg/sys2crg/
- per0crg/per1crg/per2crg/per3crg/
The remaining CRG will be implemented in future series.
changes since v5:
- Remove the bindings related patch.
patch 4 (in v6):
- jh71x0_crg_probe(): report invalid parent indices with dev_err_probe() instead of returning a bare -EINVAL, so the failing clock name and index are visible in the log.
- Add #include <linux/property.h>.
patch 8 (in v6):
- Change the JH71X0_CLK_FRAC_MAX condition check to an else if.
patch 5/6/7/10/11/12/13 (in v6):
- Document the CLK_IS_CRITICAL and CLK_IGNORE_UNUSED policies.
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Changhuang Liang (15):
clk: starfive: jh7110-sys: Fix memory leak in reset controller
register
clk: starfive: jh71x0: Move reset controller registration to jh71x0
common code
reset: starfive: jh7110: Match auxiliary device names to jh71x0 clk
driver
clk: starfive: jh71x0: Add generic CRG probe helper
clk: starfive: Add JHB100 System-0 clock generator driver
clk: starfive: Add JHB100 System-1 clock generator driver
clk: starfive: Add JHB100 System-2 clock generator driver
clk: starfive: Introduce idiv ops for inverted divider clocks
clk: starfive: Expand the storage of clock parent index
clk: starfive: Add StarFive JHB100 Peripheral-0 clock driver
clk: starfive: Add StarFive JHB100 Peripheral-1 clock driver
clk: starfive: Add StarFive JHB100 Peripheral-2 clock driver
clk: starfive: Add StarFive JHB100 Peripheral-3 clock driver
reset: starfive: jh71x0: Support discontiguous reset IDs
reset: starfive: Add StarFive JHB100 reset driver
MAINTAINERS | 13 + drivers/clk/starfive/Kconfig | 72 +- drivers/clk/starfive/Makefile | 8 + .../clk/starfive/clk-starfive-jh7110-aon.c | 2 +- .../clk/starfive/clk-starfive-jh7110-isp.c | 2 +- .../clk/starfive/clk-starfive-jh7110-stg.c | 2 +- .../clk/starfive/clk-starfive-jh7110-sys.c | 57 +- .../clk/starfive/clk-starfive-jh7110-vout.c | 2 +- drivers/clk/starfive/clk-starfive-jh7110.h | 4 - drivers/clk/starfive/clk-starfive-jh71x0.c | 165 ++++- drivers/clk/starfive/clk-starfive-jh71x0.h | 24 +- .../clk/starfive/clk-starfive-jhb100-per0.c | 617 ++++++++++++++++++ .../clk/starfive/clk-starfive-jhb100-per1.c | 162 +++++ .../clk/starfive/clk-starfive-jhb100-per2.c | 182 ++++++ .../clk/starfive/clk-starfive-jhb100-per3.c | 140 ++++ .../clk/starfive/clk-starfive-jhb100-sys0.c | 156 +++++ .../clk/starfive/clk-starfive-jhb100-sys1.c | 118 ++++ .../clk/starfive/clk-starfive-jhb100-sys2.c | 135 ++++ drivers/reset/starfive/Kconfig | 9 + drivers/reset/starfive/Makefile | 1 + .../reset/starfive/reset-starfive-jh7110.c | 10 +- .../reset/starfive/reset-starfive-jh71x0.c | 99 ++- .../reset/starfive/reset-starfive-jh71x0.h | 19 + .../reset/starfive/reset-starfive-jhb100.c | 303 +++++++++ 24 files changed, 2216 insertions(+), 86 deletions(-) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per0.c create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per1.c create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per2.c create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per3.c create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys0.c create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys1.c create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys2.c create mode 100644 drivers/reset/starfive/reset-starfive-jhb100.c
--
2.25.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v6 1/15 clk: starfive: jh7110-sys: Fix memory leak in reset controller register
auxiliary_device_init() returns an error before device_initialize() is called, so the release callback never runs on this path and the rdev allocated in jh7110_reset_controller_register() is leaked.
Free rdev when auxiliary_device_init() fails.
--- drivers/clk/starfive/clk-starfive-jh7110-sys.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/starfive/clk-starfive-jh7110-sys.c +3 -1
@@ -360,8 +360,10 @@ int jh7110_reset_controller_register(struct jh71x0_clk_priv *priv, adev->id = adev_id; ret =auxiliary_device_init (adev); -if (ret) +if (ret) { +kfree (rdev);return ret; + } ret =auxiliary_device_add (adev);if (ret) {
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
RE: [PATCH v6 01/15] clk: starfive: jh7110-sys: Fix memory leak in reset controller register
Quoted 30 lines · Changhuang Liang
auxiliary_device_init()returns an error beforedevice_initialize()is called, so the release callback never runs on this path and the rdev allocated injh7110_reset_controller_register()is leaked.Free rdev when
auxiliary_device_init()fails.Fixes edab7204afe5 ("clk: starfive: Add StarFive JH7110 system clock driver")Signed-off-by Changhuang Liang <[email protected]>--- drivers/clk/starfive/clk-starfive-jh7110-sys.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/clk/starfive/clk-starfive-jh7110-sys.c +3
-1@@ -360,8 +360,10 @@ int jh7110_reset_controller_register(struct jh71x0_clk_priv *priv, adev->id = adev_id; ret =auxiliary_device_init (adev); -if (ret) +if (ret) { +kfree (rdev);return ret; + } ret =auxiliary_device_add (adev);
Quoted 1 line
if (ret) {
Best regards,
Hal
PATCH v6 2/15 clk: starfive: jh71x0: Move reset controller registration to jh71x0 common code
In reply to Changhuang Liangjh7110_reset_controller_register() is only tied to the JH7110 system clock driver by its location. Its logic is generic: allocate a struct jh71x0_reset_adev, point it at the CRG register base and add it as an auxiliary device for the reset driver to bind to.
Move it to clk-starfive-jh71x0.c as jh71x0_reset_controller_register() so that the clock drivers of other StarFive SoCs can reuse it, and make CLK_STARFIVE_JH71X0 select AUXILIARY_BUS accordingly.
The auxiliary device ID is dropped: every CRG already uses a distinct auxiliary device name, so the ID is not needed to keep the device names unique, and it is always 0 now.
--- drivers/clk/starfive/Kconfig | 2 +- .../clk/starfive/clk-starfive-jh7110-aon.c | 2 +- .../clk/starfive/clk-starfive-jh7110-isp.c | 2 +- .../clk/starfive/clk-starfive-jh7110-stg.c | 2 +- .../clk/starfive/clk-starfive-jh7110-sys.c | 59 +------------------ .../clk/starfive/clk-starfive-jh7110-vout.c | 2 +- drivers/clk/starfive/clk-starfive-jh7110.h | 4 -- drivers/clk/starfive/clk-starfive-jh71x0.c | 54 +++++++++++++++++ drivers/clk/starfive/clk-starfive-jh71x0.h | 2 + 9 files changed, 62 insertions(+), 67 deletions(-)
drivers/clk/starfive/Kconfig +1 -1
@@ -2,6 +2,7 @@ config CLK_STARFIVE_JH71X0 bool + select AUXILIARY_BUS config CLK_STARFIVE_JH7100 bool "StarFive JH7100 clock support"
@@ -32,7 +33,6 @@ config CLK_STARFIVE_JH7110_PLL config CLK_STARFIVE_JH7110_SYS bool "StarFive JH7110 system clock support" depends on ARCH_STARFIVE || COMPILE_TEST - select AUXILIARY_BUS select CLK_STARFIVE_JH71X0 select RESET_STARFIVE_JH7110 if RESET_CONTROLLER select CLK_STARFIVE_JH7110_PLL
drivers/clk/starfive/clk-starfive-jh7110-aon.c +1 -1
@@ -121,7 +121,7 @@ static int jh7110_aoncrg_probe(struct platform_device *pdev)if (ret)return ret; -return jh7110_reset_controller_register (priv,"rst-aon" ,1 ); +return jh71x0_reset_controller_register (priv,"rst-aon" ); }static const struct of_device_id jh7110_aoncrg_match[] = {
drivers/clk/starfive/clk-starfive-jh7110-isp.c +1 -1
@@ -180,7 +180,7 @@ static int jh7110_ispcrg_probe(struct platform_device *pdev)if (ret) goto err_exit; - ret =jh7110_reset_controller_register (priv,"rst-isp" ,3 ); + ret =jh71x0_reset_controller_register (priv,"rst-isp" );if (ret) goto err_exit;
drivers/clk/starfive/clk-starfive-jh7110-stg.c +1 -1
@@ -139,7 +139,7 @@ static int jh7110_stgcrg_probe(struct platform_device *pdev)if (ret)return ret; -return jh7110_reset_controller_register (priv,"rst-stg" ,2 ); +return jh71x0_reset_controller_register (priv,"rst-stg" ); }static const struct of_device_id jh7110_stgcrg_match[] = {
drivers/clk/starfive/clk-starfive-jh7110-sys.c +1 -58
82 lines not on this page · raw message
drivers/clk/starfive/clk-starfive-jh7110-vout.c +1 -1
@@ -189,7 +189,7 @@ static int jh7110_voutcrg_probe(struct platform_device *pdev)if (ret) goto err_exit; - ret =jh7110_reset_controller_register (priv,"rst-vo" ,4 ); + ret =jh71x0_reset_controller_register (priv,"rst-vo" );if (ret) goto err_exit;
drivers/clk/starfive/clk-starfive-jh7110.h +0 -4
@@ -10,8 +10,4 @@ struct jh7110_top_sysclk { int top_clks_num; }; -int jh7110_reset_controller_register (struct jh71x0_clk_priv *priv, -const char *adev_name, -u32 adev_id); -#endif
drivers/clk/starfive/clk-starfive-jh71x0.c +54 -0
67 lines not on this page · raw message
drivers/clk/starfive/clk-starfive-jh71x0.h +2 -0
@@ -123,5 +123,7 @@ struct jh71x0_clk_priv {const struct clk_ops *starfive_jh71x0_clk_ops (u32 max);struct clk_hw *jh71x0_clk_get (struct of_phandle_args *clkspec,void *data); +int jh71x0_reset_controller_register (struct jh71x0_clk_priv *priv, +const char *adev_name);#endif
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v6 02/15] clk: starfive: jh71x0: Move reset controller registration to jh71x0 common code
Quoted 27 lines
[ ... 238 lines skipped ... ]
drivers/clk/starfive/clk-starfive-jh71x0.c +25
-0+ +int jh71x0_reset_controller_register (struct jh71x0_clk_priv *priv, +const char *adev_name) +{ +struct jh71x0_reset_adev *rdev; +struct auxiliary_device *adev; +int ret; + + rdev =kzalloc_obj (*rdev); +if (!rdev) +return -ENOMEM ; + + rdev->base = priv->base; + + adev = &rdev->adev; + adev->name = adev_name; + adev->dev.parent = priv->dev; + adev->dev.release = jh71x0_reset_adev_release; + + ret =auxiliary_device_init (adev); +if (ret) { +kfree (rdev); +return ret; + } +
drivers/clk/starfive/clk-starfive-jh71x0.c struct clk_hw *jh71x0_clk_get(struct of_phandle_args *clkspec, void *data) · line 393
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh71x0.c +10
-0+ ret =auxiliary_device_add (adev); +if (ret) { +auxiliary_device_uninit (adev); +return ret; + } + +return devm_add_action_or_reset (priv->dev, + jh71x0_reset_unregister_adev, adev); +} +EXPORT_SYMBOL_GPL (jh71x0_reset_controller_register);
Could you use the helpers provided by the auxiliary bus instead ? such as auxiliary_device_create() or its devm_ variant ?
A lot (if not everything) of the auxiliary related code here seems to implement what auxiliary already provides
Signature · 1 line
Jerome
PATCH v6 3/15 reset: starfive: jh7110: Match auxiliary device names to jh71x0 clk driver
In reply to Changhuang LiangThe JH7110 reset driver binds to auxiliary devices created by the StarFive clock driver. As part of moving the reset controller registration helper into clk-starfive-jh71x0.c so that it can be shared by other StarFive SoCs, the auxiliary device names are now prefixed with "clk_starfive_jh71x0" instead of "clk_starfive_jh7110_sys".
Update the auxiliary_device_id table accordingly, otherwise the reset driver fails to probe.
--- drivers/reset/starfive/reset-starfive-jh7110.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/reset/starfive/reset-starfive-jh7110.c +5 -5
@@ -69,23 +69,23 @@ static int jh7110_reset_probe(struct auxiliary_device *adev,static const struct auxiliary_device_id jh7110_reset_ids[] = { { - .name ="clk_starfive_jh7110_sys.rst-sys" , + .name ="clk_starfive_jh71x0.rst-sys" , .driver_data = (kernel_ulong_t)&jh7110_sys_info, }, { - .name ="clk_starfive_jh7110_sys.rst-aon" , + .name ="clk_starfive_jh71x0.rst-aon" , .driver_data = (kernel_ulong_t)&jh7110_aon_info, }, { - .name ="clk_starfive_jh7110_sys.rst-stg" , + .name ="clk_starfive_jh71x0.rst-stg" , .driver_data = (kernel_ulong_t)&jh7110_stg_info, }, { - .name ="clk_starfive_jh7110_sys.rst-isp" , + .name ="clk_starfive_jh71x0.rst-isp" , .driver_data = (kernel_ulong_t)&jh7110_isp_info, }, { - .name ="clk_starfive_jh7110_sys.rst-vo" , + .name ="clk_starfive_jh71x0.rst-vo" , .driver_data = (kernel_ulong_t)&jh7110_vout_info, }, {/* sentinel */ }
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v6 03/15] reset: starfive: jh7110: Match auxiliary device names to jh71x0 clk driver
Quoted 19 lines
The JH7110 reset driver binds to auxiliary devices created by the StarFive clock driver. As part of moving the reset controller registration helper into
clk-starfive-jh71x0.cso that it can be shared by other StarFive SoCs, the auxiliary device names are now prefixed with "clk_starfive_jh71x0" instead of "clk_starfive_jh7110_sys".Update the
auxiliary_device_idtable accordingly, otherwise the reset driver fails to probe.Signed-off-by Changhuang Liang <[email protected]>--- drivers/reset/starfive/reset-starfive-jh7110.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/reset/starfive/reset-starfive-jh7110.c +0
-0
drivers/reset/starfive/reset-starfive-jh7110.c static int jh7110_reset_probe(struct auxiliary_device *adev, · line 72
Quoted 5 lines
drivers/reset/starfive/reset-starfive-jh7110.c +1
-1@@ -69,23 +69,23 @@ static int jh7110_reset_probe(struct auxiliary_device *adev,static const struct auxiliary_device_id jh7110_reset_ids[] = { { - .name ="clk_starfive_jh7110_sys.rst-sys" , + .name ="clk_starfive_jh71x0.rst-sys" ,
Does this break bisect between the previous change and this one ?
Signature · 1 line
Jerome
PATCH v6 4/15 clk: starfive: jh71x0: Add generic CRG probe helper
In reply to Changhuang LiangThe StarFive JHB100 SoC has several clock and reset generators (CRGs) which share the same probe flow: map the registers, register all the clocks described by a table, add the clock provider and register the auxiliary reset device.
Add jh71x0_crg_probe() together with struct jh71x0_crg_domain_info so that each CRG driver only needs to provide its clock table, external clock names and reset auxiliary device name. The reset auxiliary device is registered with jh71x0_reset_controller_register().
The clock index space of these CRGs is sparse, so also make jh71x0_clk_get() reject indexes that were never registered when the domain info is available.
--- drivers/clk/starfive/clk-starfive-jh71x0.c | 98 +++++++++++++++++++++- drivers/clk/starfive/clk-starfive-jh71x0.h | 12 +++ 2 files changed, 107 insertions(+), 3 deletions(-)
drivers/clk/starfive/clk-starfive-jh71x0.c +95 -3
@@ -10,6 +10,8 @@#include <linux/debugfs.h> #include <linux/device.h> #include <linux/io.h> +#include <linux/pm_runtime.h> +#include <linux/property.h> #include <linux/slab.h> #include <soc/starfive/reset-starfive-jh71x0.h>
@@ -334,10 +336,14 @@ struct clk_hw *jh71x0_clk_get(struct of_phandle_args *clkspec, void *data)struct jh71x0_clk_priv *priv = data;unsigned int idx = clkspec->args[0 ]; -if (idx < priv->num_reg) -return &priv->reg[idx].hw; +if (idx >= priv->num_reg) +return ERR_PTR (-EINVAL ); -return ERR_PTR (-EINVAL ); +/* Index space is sparse: reject holes that were never registered. */ +if (priv->info && !priv->info->clk_data[idx].name) +return ERR_PTR (-ENOENT ); + +return &priv->reg[idx].hw; }EXPORT_SYMBOL_GPL (jh71x0_clk_get);
@@ -391,3 +397,89 @@ int jh71x0_reset_controller_register(struct jh71x0_clk_priv *priv, jh71x0_reset_unregister_adev, adev); }EXPORT_SYMBOL_GPL (jh71x0_reset_controller_register); + +int jh71x0_crg_probe (struct platform_device *pdev) +{ +const struct jh71x0_crg_domain_info *info; +struct jh71x0_clk_priv *priv; +unsigned int idx; +int ret; + + info =device_get_match_data (&pdev->dev); +if (!info) +return -ENODEV ; + + priv =devm_kzalloc (&pdev->dev,struct_size (priv, reg, info->num_clk), +GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +spin_lock_init (&priv->rmw_lock); + priv->info = info; + priv->num_reg = info->num_clk; + priv->dev = &pdev->dev; + priv->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (priv->base)) +return PTR_ERR (priv->base); + +if (info->power_domain) { + ret =devm_pm_runtime_enable (priv->dev); +if (ret) +return dev_err_probe (priv->dev, ret, +"failed to enable runtime PM\n" ); + } + +for (idx =0 ; idx < info->num_clk; idx++) { +u32 max = info->clk_data[idx].max; +struct clk_parent_data parents[4 ] = {}; +struct clk_init_data init = { + .name = info->clk_data[idx].name, + .ops =starfive_jh71x0_clk_ops (max), + .parent_data = parents, + .num_parents = + ((max &JH71X0_CLK_MUX_MASK ) >>JH71X0_CLK_MUX_SHIFT ) +1 , + .flags = info->clk_data[idx].flags, + }; +struct jh71x0_clk *clk = &priv->reg[idx]; +unsigned int i; + +if (!init.name) +continue ; + +if (init.num_parents >ARRAY_SIZE (parents)) +return dev_err_probe (priv->dev, -EINVAL , +"clock %s: too many parents (%u > %zu)\n" , + init.name, init.num_parents,ARRAY_SIZE (parents)); + +for (i =0 ; i < init.num_parents; i++) { +unsigned int pidx = info->clk_data[idx].parents[i]; + +if (pidx < info->num_clk) { + parents[i].hw = &priv->reg[pidx].hw; + }else { +if (pidx - info->num_clk >= info->num_ext_clk) +return dev_err_probe (priv->dev, -EINVAL , +"clock %s: invalid parent index %u\n" , + init.name, pidx); + + parents[i].fw_name = info->ext_clk[pidx - info->num_clk]; + } + } + + clk->hw.init = &init; + clk->idx = idx; + clk->max_div = max &JH71X0_CLK_DIV_MASK ; + + ret =devm_clk_hw_register (&pdev->dev, &clk->hw); +if (ret) +return dev_err_probe (priv->dev, ret,"Failed to register clock %s\n" , + init.name); + } + + ret =devm_of_clk_add_hw_provider (&pdev->dev, jh71x0_clk_get, priv); +if (ret) +return ret; + +return jh71x0_reset_controller_register (priv, info->rst_name); +} +EXPORT_SYMBOL_GPL (jh71x0_crg_probe);
drivers/clk/starfive/clk-starfive-jh71x0.h +12 -0
@@ -5,6 +5,7 @@#include <linux/bits.h> #include <linux/clk-provider.h> #include <linux/device.h> +#include <linux/platform_device.h> #include <linux/spinlock.h> /* register fields */
@@ -109,6 +110,15 @@ struct jh71x0_clk {unsigned int max_div; }; +struct jh71x0_crg_domain_info { +const struct jh71x0_clk_data *clk_data; +unsigned int num_clk; +const char *const *ext_clk; +unsigned int num_ext_clk; +const char *rst_name; +bool power_domain; +}; +struct jh71x0_clk_priv {/* protect clk enable and set rate/parent from happening at the same time */ spinlock_t rmw_lock;
@@ -116,6 +126,7 @@ struct jh71x0_clk_priv {void __iomem *base;struct clk *original_clk;struct notifier_block pll_clk_nb; +const struct jh71x0_crg_domain_info *info;struct clk_hw *pll[3 ];unsigned int num_reg; struct jh71x0_clk reg[] __counted_by(num_reg);
@@ -125,5 +136,6 @@ const struct clk_ops *starfive_jh71x0_clk_ops(u32 max);struct clk_hw *jh71x0_clk_get (struct of_phandle_args *clkspec,void *data);int jh71x0_reset_controller_register (struct jh71x0_clk_priv *priv,const char *adev_name); +int jh71x0_crg_probe (struct platform_device *pdev);#endif
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v6 04/15] clk: starfive: jh71x0: Add generic CRG probe helper
Quoted 71 lines
The StarFive JHB100 SoC has several clock and reset generators (CRGs) which share the same probe flow: map the registers, register all the clocks described by a table, add the clock provider and register the auxiliary reset device.
Add
jh71x0_crg_probe()together with structjh71x0_crg_domain_infoso that each CRG driver only needs to provide its clock table, external clock names and reset auxiliary device name. The reset auxiliary device is registered withjh71x0_reset_controller_register().The clock index space of these CRGs is sparse, so also make
jh71x0_clk_get()reject indexes that were never registered when the domain info is available.Signed-off-by Changhuang Liang <[email protected]>--- drivers/clk/starfive/clk-starfive-jh71x0.c | 98 +++++++++++++++++++++- drivers/clk/starfive/clk-starfive-jh71x0.h | 12 +++ 2 files changed, 107 insertions(+), 3 deletions(-)drivers/clk/starfive/clk-starfive-jh71x0.c +25
-3@@ -10,6 +10,8 @@#include <linux/debugfs.h> #include <linux/device.h> #include <linux/io.h> +#include <linux/pm_runtime.h> +#include <linux/property.h> #include <linux/slab.h> #include <soc/starfive/reset-starfive-jh71x0.h> @@ -334,10 +336,14 @@ struct clk_hw *jh71x0_clk_get(struct of_phandle_args *clkspec, void *data)struct jh71x0_clk_priv *priv = data;unsigned int idx = clkspec->args[0 ]; -if (idx < priv->num_reg) -return &priv->reg[idx].hw; +if (idx >= priv->num_reg) +return ERR_PTR (-EINVAL ); -return ERR_PTR (-EINVAL ); +/* Index space is sparse: reject holes that were never registered. */ +if (priv->info && !priv->info->clk_data[idx].name) +return ERR_PTR (-ENOENT ); + +return &priv->reg[idx].hw; }EXPORT_SYMBOL_GPL (jh71x0_clk_get);@@ -391,3 +397,89 @@ int jh71x0_reset_controller_register(struct jh71x0_clk_priv *priv, jh71x0_reset_unregister_adev, adev); }EXPORT_SYMBOL_GPL (jh71x0_reset_controller_register); + +int jh71x0_crg_probe (struct platform_device *pdev) +{ +const struct jh71x0_crg_domain_info *info; +struct jh71x0_clk_priv *priv; +unsigned int idx; +int ret; + + info =device_get_match_data (&pdev->dev); +if (!info) +return -ENODEV ; + + priv =devm_kzalloc (&pdev->dev,struct_size (priv, reg, info->num_clk), +GFP_KERNEL ); +if (!priv) +return -ENOMEM ;
drivers/clk/starfive/clk-starfive-jh71x0.c int jh71x0_reset_controller_register(struct jh71x0_clk_priv *priv, · line 425
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh71x0.c +10
-0+ +spin_lock_init (&priv->rmw_lock); + priv->info = info; + priv->num_reg = info->num_clk; + priv->dev = &pdev->dev; + priv->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (priv->base)) +return PTR_ERR (priv->base); + +if (info->power_domain) {
At the moment the appears to be dead-code since none of your controller is setting it. I'd prefer if you drop it for now and introduce it when it actually gets used.
Signature · 1 line
Jerome
PATCH v6 5/15 clk: starfive: Add JHB100 System-0 clock generator driver
In reply to Changhuang LiangAdd support for JHB100 System-0 clock generator (SYS0CRG).
--- MAINTAINERS | 7 + drivers/clk/starfive/Kconfig | 10 ++ drivers/clk/starfive/Makefile | 2 + .../clk/starfive/clk-starfive-jhb100-sys0.c | 156 ++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys0.c
MAINTAINERS +7 -0
@@ -26633,6 +26633,13 @@ F: Documentation/devicetree/bindings/phy/starfive,jh7110-usb-phy.yaml F: drivers/phy/starfive/phy-jh7110-pcie.c F: drivers/phy/starfive/phy-jh7110-usb.c +STARFIVE JHB100 CLOCK DRIVERS +M: Changhuang Liang <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/clock/starfive,jhb1*.yaml +F: drivers/clk/starfive/clk-starfive-jhb1* +F: include/dt-bindings/clock/starfive,jhb1*.h + STARFIVE JHB100 DEVICETREES M: Changhuang Liang <[email protected]> L: [email protected]
drivers/clk/starfive/Kconfig +10 -0
@@ -72,3 +72,13 @@ config CLK_STARFIVE_JH7110_VOUT help Say yes here to support the Video-Output clock controller on the StarFive JH7110 SoC. + +config CLK_STARFIVE_JHB100_SYS0 + bool "StarFive JHB100 system-0 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the system-0 clock controller on the + StarFive JHB100 SoC.
drivers/clk/starfive/Makefile +2 -0
@@ -10,3 +10,5 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_AON) += clk-starfive-jh7110-aon.o obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += clk-starfive-jh7110-stg.o obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o + +obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.o
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +156 -0
156 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v6 05/15] clk: starfive: Add JHB100 System-0 clock generator driver
Quoted 34 lines
Add support for JHB100 System-0 clock generator (SYS0CRG).
Signed-off-by Changhuang Liang <[email protected]>--- MAINTAINERS | 7 + drivers/clk/starfive/Kconfig | 10 ++ drivers/clk/starfive/Makefile | 2 + .../clk/starfive/clk-starfive-jhb100-sys0.c | 156 ++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys0.cMAINTAINERS +7
-0@@ -26217,6 +26217,13 @@ F: Documentation/devicetree/bindings/phy/starfive,jh7110-usb-phy.yaml F: drivers/phy/starfive/phy-jh7110-pcie.c F: drivers/phy/starfive/phy-jh7110-usb.c +STARFIVE JHB100 CLOCK DRIVERS +M: Changhuang Liang <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/clock/starfive,jhb1*.yaml +F: drivers/clk/starfive/clk-starfive-jhb1* +F: include/dt-bindings/clock/starfive,jhb1*.h + STARFIVE JHB100 EXTERNAL INTERRUPT CONTROLLER DRIVER M: Changhuang Liang <[email protected]> S: Supporteddrivers/clk/starfive/Kconfig +0
-0
drivers/clk/starfive/Kconfig config CLK_STARFIVE_JH7110_VOUT · line 80
Quoted 9 lines
drivers/clk/starfive/Kconfig +6
-0@@ -72,3 +72,13 @@ config CLK_STARFIVE_JH7110_VOUT help Say yes here to support the Video-Output clock controller on the StarFive JH7110 SoC. + +config CLK_STARFIVE_JHB100_SYS0 + bool "StarFive JHB100 system-0 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER
just imply RESET_STARFIVE_JHB100 ?
It can be disabled if RESET_CONTROLLER is not set, so it is kind of weak already.
Quoted 33 lines
drivers/clk/starfive/Kconfig +4
-0+ default ARCH_STARFIVE + help + Say yes here to support the system-0 clock controller on the + StarFive JHB100 SoC.drivers/clk/starfive/Makefile +2
-0@@ -10,3 +10,5 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_AON) += clk-starfive-jh7110-aon.o obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += clk-starfive-jh7110-stg.o obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o + +obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.odrivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +13
-0@@ -0,0 +1,156 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* StarFive JHB100 System-0 Clock Driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* +* Author: Changhuang Liang <[email protected]> +* +*/ + +#include <dt-bindings/clock/starfive,jhb100-crg.h> +#include <linux/init.h> +#include <linux/platform_device.h>
drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 23
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +10
-0+ +#include "clk-starfive-jh71x0.h" + +#define JHB100_SYS0CLK_NUM_CLKS (JHB100_SYS0CLK_GPU1_NCNOC_INIT + 1) + +/* external clocks */ +#define JHB100_SYS0CLK_OSC (JHB100_SYS0CLK_NUM_CLKS + 0) +#define JHB100_SYS0CLK_PLL0 (JHB100_SYS0CLK_NUM_CLKS + 1) +#define JHB100_SYS0CLK_PLL1 (JHB100_SYS0CLK_NUM_CLKS + 2) +#define JHB100_SYS0CLK_PLL2 (JHB100_SYS0CLK_NUM_CLKS + 3)
Does this mean that if the you ever find out you've forgot an internal clock (which does happen fairly often) the whole external block will shift ?
drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 36
Quoted 13 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +13
-0+ +static const char *const jhb100_sys0_ext_clk[] = { +"osc" , +"pll0" , +"pll1" , +"pll2" , +}; + +/* +* Regarding the CLK_IS_CRITICAL flag: +* Clocks flagged CLK_IS_CRITICAL feed logic that has to keep running whether +* or not a consumer holds them, such as the bus interconnect and always-on +* blocks. Gating them hangs the system, so they must never be disabled.
PCIE and USB are critical below and do not appear to meant this criteria, yet they are critical too.
Signature · 1 line
Jerome
Re: [PATCH v6 05/15] clk: starfive: Add JHB100 System-0 clock generator driver
Hi, Jerome
Quoted 98 lines
MAINTAINERS F:
Quoted 16 lines
Add support for JHB100 System-0 clock generator (SYS0CRG).
Signed-off-by Changhuang Liang <[email protected]>--- MAINTAINERS | 7 + drivers/clk/starfive/Kconfig | 10 ++ drivers/clk/starfive/Makefile | 2 + .../clk/starfive/clk-starfive-jhb100-sys0.c | 156 ++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys0.cMAINTAINERS index renamed from MAINTAINERS +0
-0
66d6c15f1dd2..dff8b819f83e100644MAINTAINERS +0
-0@@ -26217,6 +26217,13 @@ F:
Documentation/devicetree/bindings/phy/starfive,jh7110-usb-phy.yamlQuoted 18 lines
MAINTAINERS +7
-0F: drivers/phy/starfive/phy-jh7110-pcie.c F: drivers/phy/starfive/phy-jh7110-usb.c +STARFIVE JHB100 CLOCK DRIVERS +M: Changhuang Liang <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/clock/starfive,jhb1*.yaml +F: drivers/clk/starfive/clk-starfive-jhb1* +F: include/dt-bindings/clock/starfive,jhb1*.h + STARFIVE JHB100 EXTERNAL INTERRUPT CONTROLLER DRIVER M: Changhuang Liang <[email protected]> S: Supported(quoted diff) +0
-0b/drivers/clk/starfive/Kconfig index
51716655554f..cd5b7754403e100644drivers/clk/starfive/Kconfig config CLK_STARFIVE_JH7110_VOUT · line 80
Quoted 9 lines
drivers/clk/starfive/Kconfig +6
-0@@ -72,3 +72,13 @@ config CLK_STARFIVE_JH7110_VOUT help Say yes here to support the Video-Output clock controller on the StarFive JH7110 SoC. + +config CLK_STARFIVE_JHB100_SYS0 + bool "StarFive JHB100 system-0 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLERjust imply
RESET_STARFIVE_JHB100?It can be disabled if
RESET_CONTROLLERis not set, so it is kind of weak already.drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_AON) +=
Quoted 10 lines
drivers/clk/starfive/Kconfig +4
-0+ default ARCH_STARFIVE + help + Say yes here to support the system-0 clock controller on the + StarFive JHB100 SoC.(quoted diff) +0
-0b/drivers/clk/starfive/Makefile index
199ac0f37a2f..d2ba83d7d02c100644drivers/clk/starfive/Makefile +0
-0@@ -10,3 +10,5 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_AON) +=clk-starfive-jh7110-aon.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_AON) += clk-starfive-jh7110-aon.o
Quoted 3 lines
drivers/clk/starfive/Makefile +0
-0obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += clk-starfive-jh7110-stg.o obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) +=clk-starfive-jh7110-vout.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_AON) += · line 14
Quoted 2 lines
drivers/clk/starfive/Makefile +2
-0+ +obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) +=clk-starfive-jhb100-sys0.o
Quoted 14 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +7
-0@@ -0,0 +1,156 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* StarFive JHB100 System-0 Clock Driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* +* Author: Changhuang Liang <[email protected]> drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 17
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +10
-0+* +*/ + +#include <dt-bindings/clock/starfive,jhb100-crg.h> +#include <linux/init.h> +#include <linux/platform_device.h> + +#include "clk-starfive-jh71x0.h" + +#define JHB100_SYS0CLK_NUM_CLKS (JHB100_SYS0CLK_GPU1_NCNOC_INIT + 1)drivers/clk/starfive/clk-starfive-jhb100-sys0.c
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +3
-0+ +/* external clocks */ +#define JHB100_SYS0CLK_OSC (JHB100_SYS0CLK_NUM_CLKS + 0)drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 21
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +1
-0+#define JHB100_SYS0CLK_PLL0
Quoted 9 lines
(JHB100_SYS0CLK_NUM_CLKS + 1)drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 22
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +1
-0+#define JHB100_SYS0CLK_PLL1 (JHB100_SYS0CLK_NUM_CLKS + 2)drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 23
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +1
-0+#define JHB100_SYS0CLK_PLL2 (JHB100_SYS0CLK_NUM_CLKS + 3)Does this mean that if the you ever find out you've forgot an internal clock (which does happen fairly often) the whole external block will shift ?
Later, I will introduce the following macros to define the external clock, which can avoid this problem.
#define JH71X0_EXT_CLK_FLAG BIT(15)
#define JH71X0_EXT_CLK(_n) (JH71X0_EXT_CLK_FLAG | (_n))
Quoted 12 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c
Quoted 11 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +11
-0+ +static const char *const jhb100_sys0_ext_clk[] = { +"osc" , +"pll0" , +"pll1" , +"pll2" , +}; + +/* +* Regarding the CLK_IS_CRITICAL flag: +* Clocks flagged CLK_IS_CRITICAL feed logic that has to keep running whether
Quoted 7 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 35
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +1
-0+* or not a consumer holds them, such as the bus interconnect and always-on
drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 36
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +1
-0+* blocks. Gating them hangs the system, so they must never be disabled.
PCIE and USB are critical below and do not appear to meant this criteria, yet they are critical too.
Best Regards,
Changhuang
Re: [PATCH v6 05/15] clk: starfive: Add JHB100 System-0 clock generator driver
Quoted 106 lines · Changhuang Liang
Hi, Jerome
Quoted 104 lines
MAINTAINERS F:
Quoted 16 lines
Add support for JHB100 System-0 clock generator (SYS0CRG).
Signed-off-by Changhuang Liang <[email protected]>--- MAINTAINERS | 7 + drivers/clk/starfive/Kconfig | 10 ++ drivers/clk/starfive/Makefile | 2 + .../clk/starfive/clk-starfive-jhb100-sys0.c | 156 ++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys0.cMAINTAINERS index renamed from MAINTAINERS +0
-0
66d6c15f1dd2..dff8b819f83e100644MAINTAINERS +0
-0@@ -26217,6 +26217,13 @@ F:
Documentation/devicetree/bindings/phy/starfive,jh7110-usb-phy.yamlQuoted 18 lines
MAINTAINERS +7
-0F: drivers/phy/starfive/phy-jh7110-pcie.c F: drivers/phy/starfive/phy-jh7110-usb.c +STARFIVE JHB100 CLOCK DRIVERS +M: Changhuang Liang <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/clock/starfive,jhb1*.yaml +F: drivers/clk/starfive/clk-starfive-jhb1* +F: include/dt-bindings/clock/starfive,jhb1*.h + STARFIVE JHB100 EXTERNAL INTERRUPT CONTROLLER DRIVER M: Changhuang Liang <[email protected]> S: Supported(quoted diff) +0
-0b/drivers/clk/starfive/Kconfig index
51716655554f..cd5b7754403e100644drivers/clk/starfive/Kconfig config CLK_STARFIVE_JH7110_VOUT · line 80
Quoted 9 lines
drivers/clk/starfive/Kconfig +6
-0@@ -72,3 +72,13 @@ config CLK_STARFIVE_JH7110_VOUT help Say yes here to support the Video-Output clock controller on the StarFive JH7110 SoC. + +config CLK_STARFIVE_JHB100_SYS0 + bool "StarFive JHB100 system-0 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLERjust imply
RESET_STARFIVE_JHB100?It can be disabled if
RESET_CONTROLLERis not set, so it is kind of weak already.drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_AON) +=
Quoted 10 lines
drivers/clk/starfive/Kconfig +4
-0+ default ARCH_STARFIVE + help + Say yes here to support the system-0 clock controller on the + StarFive JHB100 SoC.(quoted diff) +0
-0b/drivers/clk/starfive/Makefile index
199ac0f37a2f..d2ba83d7d02c100644drivers/clk/starfive/Makefile +0
-0@@ -10,3 +10,5 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_AON) +=clk-starfive-jh7110-aon.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_AON) += clk-starfive-jh7110-aon.o
Quoted 3 lines
drivers/clk/starfive/Makefile +0
-0obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += clk-starfive-jh7110-stg.o obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) +=clk-starfive-jh7110-vout.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_AON) += · line 14
Quoted 2 lines
drivers/clk/starfive/Makefile +2
-0+ +obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) +=clk-starfive-jhb100-sys0.o
Quoted 14 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +7
-0@@ -0,0 +1,156 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* StarFive JHB100 System-0 Clock Driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* +* Author: Changhuang Liang <[email protected]> drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 17
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +10
-0+* +*/ + +#include <dt-bindings/clock/starfive,jhb100-crg.h> +#include <linux/init.h> +#include <linux/platform_device.h> + +#include "clk-starfive-jh71x0.h" + +#define JHB100_SYS0CLK_NUM_CLKS (JHB100_SYS0CLK_GPU1_NCNOC_INIT + 1)drivers/clk/starfive/clk-starfive-jhb100-sys0.c
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +3
-0+ +/* external clocks */ +#define JHB100_SYS0CLK_OSC (JHB100_SYS0CLK_NUM_CLKS + 0)drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 21
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +1
-0+#define JHB100_SYS0CLK_PLL0 (JHB100_SYS0CLK_NUM_CLKS + 1)drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 22
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +1
-0+#define JHB100_SYS0CLK_PLL1 (JHB100_SYS0CLK_NUM_CLKS + 2)drivers/clk/starfive/clk-starfive-jhb100-sys0.c line 23
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-sys0.c new file +1
-0+#define JHB100_SYS0CLK_PLL2 (JHB100_SYS0CLK_NUM_CLKS + 3)
Quoted 9 lines
Quoted 3 lines
Does this mean that if the you ever find out you've forgot an internal clock (which does happen fairly often) the whole external block will shift ?
Later, I will introduce the following macros to define the external clock, which can avoid this problem.
#define
JH71X0_EXT_CLK_FLAGBIT(15)
#defineJH71X0_EXT_CLK(_n)(JH71X0_EXT_CLK_FLAG| (_n))
hummm okay ... still seems hackish to me.
Quoted 1 line
Signature · 1 line
Jerome
PATCH v6 6/15 clk: starfive: Add JHB100 System-1 clock generator driver
In reply to Changhuang LiangAdd support for JHB100 System-1 clock generator (SYS1CRG).
--- drivers/clk/starfive/Kconfig | 10 ++ drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-sys1.c | 118 ++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys1.c
drivers/clk/starfive/Kconfig +10 -0
@@ -82,3 +82,13 @@ config CLK_STARFIVE_JHB100_SYS0 help Say yes here to support the system-0 clock controller on the StarFive JHB100 SoC. + +config CLK_STARFIVE_JHB100_SYS1 + bool "StarFive JHB100 system-1 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the system-1 clock controller on the + StarFive JHB100 SoC.
drivers/clk/starfive/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.o +obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) += clk-starfive-jhb100-sys1.o
drivers/clk/starfive/clk-starfive-jhb100-sys1.c new file +118 -0
118 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v6 06/15] clk: starfive: Add JHB100 System-1 clock generator driver
Quoted 82 lines
Add support for JHB100 System-1 clock generator (SYS1CRG).
Signed-off-by Changhuang Liang <[email protected]>--- drivers/clk/starfive/Kconfig | 10 ++ drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-sys1.c | 118 ++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys1.cdrivers/clk/starfive/Kconfig +10
-0@@ -82,3 +82,13 @@ config CLK_STARFIVE_JHB100_SYS0 help Say yes here to support the system-0 clock controller on the StarFive JHB100 SoC. + +config CLK_STARFIVE_JHB100_SYS1 + bool "StarFive JHB100 system-1 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the system-1 clock controller on the + StarFive JHB100 SoC.drivers/clk/starfive/Makefile +1
-0@@ -12,3 +12,4 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.o +obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) += clk-starfive-jhb100-sys1.odrivers/clk/starfive/clk-starfive-jhb100-sys1.c new file +39
-0@@ -0,0 +1,118 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* StarFive JHB100 System-1 Clock Driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* +* Author: Changhuang Liang <[email protected]> +* +*/ + +#include <dt-bindings/clock/starfive,jhb100-crg.h> +#include <linux/init.h> +#include <linux/platform_device.h> + +#include "clk-starfive-jh71x0.h" + +#define JHB100_SYS1CLK_NUM_CLKS (JHB100_SYS1CLK_BMCPER3_CFG_125 + 1) + +/* external clocks */ +#define JHB100_SYS1CLK_OSC (JHB100_SYS1CLK_NUM_CLKS + 0) +#define JHB100_SYS1CLK_PLL0 (JHB100_SYS1CLK_NUM_CLKS + 1) +#define JHB100_SYS1CLK_PLL1 (JHB100_SYS1CLK_NUM_CLKS + 2) +#define JHB100_SYS1CLK_PLL2 (JHB100_SYS1CLK_NUM_CLKS + 3) +#define JHB100_SYS1CLK_PLL4 (JHB100_SYS1CLK_NUM_CLKS + 4) +#define JHB100_SYS1CLK_PLL5 (JHB100_SYS1CLK_NUM_CLKS + 5) +#define JHB100_SYS1CLK_NPU_NCNOC_INIT (JHB100_SYS1CLK_NUM_CLKS + 6) + +static const char *const jhb100_sys1_ext_clk[] = { +"osc" , +"pll0" , +"pll1" , +"pll2" , +"pll4" , +"pll5" , +"npu_ncnoc_init" , +}; + +/* +* Regarding the CLK_IS_CRITICAL flag:
drivers/clk/starfive/clk-starfive-jhb100-sys1.c line 49
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jhb100-sys1.c new file +10
-0+* Clocks flagged CLK_IS_CRITICAL feed logic that has to keep running whether +* or not a consumer holds them, such as the bus interconnect and always-on +* blocks. Gating them hangs the system, so they must never be disabled. +* +* Regarding the CLK_IGNORE_UNUSED flag: +* Clocks flagged CLK_IGNORE_UNUSED are not consumed by any driver. The flag +* keeps them in their hardware default state (enabled) instead of letting +* the clock framework gate them once it disables unused clocks. If this +* flag needs to be removed later, it must be ensured that these clocks will +* not be disabled even if they are not consumed.
Those comments you are using are too generic and not really helpful as they are.
For example there is no CLK_IGNORE_UNUSED below but the comment mention it.
On the previous patch you've mention CLK_IS_CRITICAL and the fact the clock must stay on. It is the flag definition so it does not help much.
For each clock with this flag, adding a quick comment explain *WHY* is must stay ON would be a lot more helpful for a future contributor wondering why it was put there and how it can possibly be removed. IOW, what device does this clock and why doesn't it have a driver ?
... and again, I don't think a USB clock should be critical.
Signature · 1 line
Jerome
PATCH v6 7/15 clk: starfive: Add JHB100 System-2 clock generator driver
In reply to Changhuang LiangAdd support for JHB100 System-2 clock generator (SYS2CRG).
--- drivers/clk/starfive/Kconfig | 10 ++ drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-sys2.c | 135 ++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys2.c
drivers/clk/starfive/Kconfig +10 -0
@@ -92,3 +92,13 @@ config CLK_STARFIVE_JHB100_SYS1 help Say yes here to support the system-1 clock controller on the StarFive JHB100 SoC. + +config CLK_STARFIVE_JHB100_SYS2 + bool "StarFive JHB100 system-2 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the system-2 clock controller on the + StarFive JHB100 SoC.
drivers/clk/starfive/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) += clk-starfive-jhb100-sys1.o +obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS2) += clk-starfive-jhb100-sys2.o
drivers/clk/starfive/clk-starfive-jhb100-sys2.c new file +135 -0
135 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v6 07/15] clk: starfive: Add JHB100 System-2 clock generator driver
Quoted 100 lines
Add support for JHB100 System-2 clock generator (SYS2CRG).
Signed-off-by Changhuang Liang <[email protected]>--- drivers/clk/starfive/Kconfig | 10 ++ drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-sys2.c | 135 ++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys2.cdrivers/clk/starfive/Kconfig +10
-0@@ -92,3 +92,13 @@ config CLK_STARFIVE_JHB100_SYS1 help Say yes here to support the system-1 clock controller on the StarFive JHB100 SoC. + +config CLK_STARFIVE_JHB100_SYS2 + bool "StarFive JHB100 system-2 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the system-2 clock controller on the + StarFive JHB100 SoC.drivers/clk/starfive/Makefile +1
-0@@ -13,3 +13,4 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) += clk-starfive-jhb100-sys1.o +obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS2) += clk-starfive-jhb100-sys2.odrivers/clk/starfive/clk-starfive-jhb100-sys2.c new file +57
-0@@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* StarFive JHB100 System-2 Clock Driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* +* Author: Changhuang Liang <[email protected]> +* +*/ + +#include <dt-bindings/clock/starfive,jhb100-crg.h> +#include <linux/init.h> +#include <linux/platform_device.h> + +#include "clk-starfive-jh71x0.h" + +#define JHB100_SYS2CLK_NUM_CLKS (JHB100_SYS2CLK_MAIN_ICG_EN_JTAG1 + 1) + +/* external clocks */ +#define JHB100_SYS2CLK_OSC (JHB100_SYS2CLK_NUM_CLKS + 0) +#define JHB100_SYS2CLK_PLL1 (JHB100_SYS2CLK_NUM_CLKS + 1) +#define JHB100_SYS2CLK_GPU0_NCNOC_INIT (JHB100_SYS2CLK_NUM_CLKS + 2) +#define JHB100_SYS2CLK_GPU1_NCNOC_INIT (JHB100_SYS2CLK_NUM_CLKS + 3) + +static const char *const jhb100_sys2_ext_clk[] = { +"osc" , +"pll1" , +"gpu0_ncnoc_init" , +"gpu1_ncnoc_init" , +}; + +/* +* Regarding the CLK_IS_CRITICAL flag: +* Clocks flagged CLK_IS_CRITICAL feed logic that has to keep running whether +* or not a consumer holds them, such as the bus interconnect and always-on +* blocks. Gating them hangs the system, so they must never be disabled. +*/ +static const struct jh71x0_clk_data jhb100_sys2crg_clk_data[] = { +/* jtag mst*/ +JH71X0__DIV (JHB100_SYS2CLK_JTAGM0_HCLK ,"jtagm0_hclk" ,6 , +JHB100_SYS2CLK_PLL1 ), +JH71X0__DIV (JHB100_SYS2CLK_JTAGM1_HCLK ,"jtagm1_hclk" ,6 , +JHB100_SYS2CLK_PLL1 ), +JH71X0__DIV (JHB100_SYS2CLK_JTAGM0_ATPG ,"jtagm0_atpg" ,12 , +JHB100_SYS2CLK_PLL1 ), +JH71X0__DIV (JHB100_SYS2CLK_JTAGM1_ATPG ,"jtagm1_atpg" ,12 , +JHB100_SYS2CLK_PLL1 ), +JH71X0__DIV (JHB100_SYS2CLK_JTAGM0_ATPG_TCLOCK ,"jtagm0_atpg_tclock" ,2 , +JHB100_SYS2CLK_JTAGM0_ATPG ), +JH71X0__DIV (JHB100_SYS2CLK_JTAGM1_ATPG_TCLOCK ,"jtagm1_atpg_tclock" ,2 , +JHB100_SYS2CLK_JTAGM1_ATPG ), +JH71X0_GATE (JHB100_SYS2CLK_JTAG0_MST_WRAP_HCLK ,"jtag0_mst_wrap_hclk" , +CLK_IGNORE_UNUSED ,JHB100_SYS2CLK_JTAGM0_HCLK ), +JH71X0_GATE (JHB100_SYS2CLK_JTAG0_MST_WRAP_CLK_JTAG ,"jtag0_mst_wrap_clk_jtag" , +CLK_IGNORE_UNUSED ,JHB100_SYS2CLK_JTAGM0_HCLK ), +JH71X0_GATE (JHB100_SYS2CLK_JTAG0_MST_WRAP_APB_PCLK ,"jtag0_mst_wrap_apb_pclk" , +CLK_IGNORE_UNUSED ,JHB100_SYS2CLK_JTAGM0_ATPG ),
drivers/clk/starfive/clk-starfive-jhb100-sys2.c line 67
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jhb100-sys2.c new file +10
-0+JH71X0_GATE (JHB100_SYS2CLK_JTAG0_MST_WRAP_ATPG_TCLOCK ,"jtag0_mst_wrap_atpg_tclock" , +CLK_IGNORE_UNUSED ,JHB100_SYS2CLK_JTAGM0_ATPG ), +JH71X0_GATE (JHB100_SYS2CLK_JTAG1_MST_WRAP_HCLK ,"jtag1_mst_wrap_hclk" , +CLK_IGNORE_UNUSED ,JHB100_SYS2CLK_JTAGM1_HCLK ), +JH71X0_GATE (JHB100_SYS2CLK_JTAG1_MST_WRAP_CLK_JTAG ,"jtag1_mst_wrap_clk_jtag" , +CLK_IGNORE_UNUSED ,JHB100_SYS2CLK_JTAGM1_HCLK ), +JH71X0_GATE (JHB100_SYS2CLK_JTAG1_MST_WRAP_APB_PCLK ,"jtag1_mst_wrap_apb_pclk" , +CLK_IGNORE_UNUSED ,JHB100_SYS2CLK_JTAGM1_ATPG ), +JH71X0_GATE (JHB100_SYS2CLK_JTAG1_MST_WRAP_ATPG_TCLOCK ,"jtag1_mst_wrap_atpg_tclock" , + CLK_IGNORE_UNUSED, JHB100_SYS2CLK_JTAGM1_ATPG),
It is really wise to leave the JTAG clocks ON by default ?
There should at least be a comment explaining this. Maybe the device on the field should disable this clock in the bootloader or something.
Quoted 24 lines
drivers/clk/starfive/clk-starfive-jhb100-sys2.c new file +24
-0+/* hostusbcmn */ +JH71X0__DIV (JHB100_SYS2CLK_HOSTUSB_NCNOC_TARG ,"hostusb_ncnoc_targ" ,12 , +JHB100_SYS2CLK_PLL1 ), +JH71X0__DIV (JHB100_SYS2CLK_HOSTUSBCMN_CFG_500 ,"hostusbcmn_cfg_500" ,4 , +JHB100_SYS2CLK_PLL1 ), +/* bmcperiph1 */ +JH71X0__DIV (JHB100_SYS2CLK_BMCPER1_NCNOC_TARG ,"bmcper1_ncnoc_targ" ,6 , +JHB100_SYS2CLK_PLL1 ), +JH71X0__DIV (JHB100_SYS2CLK_BMCPER1_CFG_250 ,"bmcper1_cfg_250" ,5 , +JHB100_SYS2CLK_PLL1 ), +JH71X0__DIV (JHB100_SYS2CLK_BMCPER1_CFG_143_DFT ,"bmcper1_cfg_143_dft" ,8 , +JHB100_SYS2CLK_PLL1 ), +JH71X0_GATE (JHB100_SYS2CLK_BMCPER1_CFG_143 ,"bmcper1_cfg_143" ,CLK_IS_CRITICAL , +JHB100_SYS2CLK_BMCPER1_CFG_143_DFT ), +/* bmcperiph0 */ +JH71X0__DIV (JHB100_SYS2CLK_BMCPER0_NCNOC_TARG ,"bmcper0_ncnoc_targ" ,6 , +JHB100_SYS2CLK_PLL1 ), +/* gpu0 */ +JH71X0__DIV (JHB100_SYS2CLK_GPU0_NCNOC_TARG ,"gpu0_ncnoc_targ" ,12 , +JHB100_SYS2CLK_PLL1 ), +JH71X0_GATE (JHB100_SYS2CLK_GPU0_BUS_CLK ,"gpu0_bus_clk" ,CLK_IS_CRITICAL , +JHB100_SYS2CLK_GPU0_NCNOC_INIT ), +JH71X0_GATE (JHB100_SYS2CLK_GPU0_APB_CLK ,"gpu0_apb_clk" ,CLK_IS_CRITICAL , + JHB100_SYS2CLK_GPU0_NCNOC_TARG),
drivers/clk/starfive/clk-starfive-jhb100-sys2.c line 101
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jhb100-sys2.c new file +10
-0+JH71X0_GATE (JHB100_SYS2CLK_GPU0_OSC_CLK ,"gpu0_osc_clk" ,CLK_IS_CRITICAL , +JHB100_SYS2CLK_OSC ), +/* gpu1 */ +JH71X0__DIV (JHB100_SYS2CLK_GPU1_NCNOC_TARG ,"gpu1_ncnoc_targ" ,12 , +JHB100_SYS2CLK_PLL1 ), +JH71X0_GATE (JHB100_SYS2CLK_GPU1_BUS_CLK ,"gpu1_bus_clk" ,CLK_IS_CRITICAL , +JHB100_SYS2CLK_GPU1_NCNOC_INIT ), +JH71X0_GATE (JHB100_SYS2CLK_GPU1_APB_CLK ,"gpu1_apb_clk" ,CLK_IS_CRITICAL , +JHB100_SYS2CLK_GPU1_NCNOC_TARG ), + JH71X0_GATE(JHB100_SYS2CLK_GPU1_OSC_CLK, "gpu1_osc_clk", CLK_IS_CRITICAL,
No, I don't think a GPU clock is critical. A GPU usually has a driver.
Signature · 1 line
Jerome
PATCH v6 8/15 clk: starfive: Introduce idiv ops for inverted divider clocks
In reply to Changhuang LiangSome StarFive clocks only advertise the divider and invert capabilities (via JH71X0_CLK_INVERT, without ENABLE). Add the JH71X0_IDIV() macro to declare such clocks, and jh71x0_clk_idiv_ops, which combines the divider rate operations with get_phase/set_phase.
--- drivers/clk/starfive/clk-starfive-jh71x0.c | 13 ++++++++++++- drivers/clk/starfive/clk-starfive-jh71x0.h | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/clk/starfive/clk-starfive-jh71x0.c +12 -1
@@ -303,6 +303,15 @@ static const struct clk_ops jh71x0_clk_inv_ops = { .debug_init = jh71x0_clk_debug_init, }; +static const struct clk_ops jh71x0_clk_idiv_ops = { + .get_phase = jh71x0_clk_get_phase, + .set_phase = jh71x0_clk_set_phase, + .recalc_rate = jh71x0_clk_recalc_rate, + .determine_rate = jh71x0_clk_determine_rate, + .set_rate = jh71x0_clk_set_rate, + .debug_init = jh71x0_clk_debug_init, +}; +const struct clk_ops *starfive_jh71x0_clk_ops (u32 max) {if (max &JH71X0_CLK_DIV_MASK ) {
@@ -313,7 +322,9 @@ const struct clk_ops *starfive_jh71x0_clk_ops(u32 max) }if (max &JH71X0_CLK_ENABLE )return &jh71x0_clk_gdiv_ops; -if (max ==JH71X0_CLK_FRAC_MAX ) +else if (max &JH71X0_CLK_INVERT ) +return &jh71x0_clk_idiv_ops; +else if (max ==JH71X0_CLK_FRAC_MAX )return &jh71x0_clk_fdiv_ops;return &jh71x0_clk_div_ops; }
drivers/clk/starfive/clk-starfive-jh71x0.h +8 -0
@@ -104,6 +104,14 @@ struct jh71x0_clk_data { .parents = { [0] = _parent }, \ } +#define JH71X0_IDIV (_idx, _name, _flags, _max, _parent) \ +[_idx] = { \ + .name = _name, \ + .flags = _flags, \ + .max = JH71X0_CLK_INVERT | (_max), \ + .parents = { [0] = _parent }, \ +} +struct jh71x0_clk {struct clk_hw hw;unsigned int idx;
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v6 08/15] clk: starfive: Introduce idiv ops for inverted divider clocks
Quoted 5 lines
Some StarFive clocks only advertise the divider and invert capabilities (via
JH71X0_CLK_INVERT, without ENABLE). Add theJH71X0_IDIV()macro to declare such clocks, andjh71x0_clk_idiv_ops, which combines the divider rate operations with get_phase/set_phase.
Please rephrase, I don't understand what you mean
Quoted 11 lines
Signed-off-by Changhuang Liang <[email protected]>--- drivers/clk/starfive/clk-starfive-jh71x0.c | 13 ++++++++++++- drivers/clk/starfive/clk-starfive-jh71x0.h | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)drivers/clk/starfive/clk-starfive-jh71x0.c +0
-0
drivers/clk/starfive/clk-starfive-jh71x0.c static const struct clk_ops jh71x0_clk_inv_ops = { · line 312
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh71x0.c +7
-0@@ -303,6 +303,15 @@ static const struct clk_ops jh71x0_clk_inv_ops = { .debug_init = jh71x0_clk_debug_init, }; +static const struct clk_ops jh71x0_clk_idiv_ops = { + .get_phase = jh71x0_clk_get_phase, + .set_phase = jh71x0_clk_set_phase, + .recalc_rate = jh71x0_clk_recalc_rate, + .determine_rate = jh71x0_clk_determine_rate, + .set_rate = jh71x0_clk_set_rate, + .debug_init = jh71x0_clk_debug_init,
Instead of trying to cover all the combination that could exist, can you just chain 2 elements ? a div then an inv ?
Quoted 6 lines
drivers/clk/starfive/clk-starfive-jh71x0.c +2
-0+}; +const struct clk_ops *starfive_jh71x0_clk_ops (u32 max) {if (max &JH71X0_CLK_DIV_MASK ) {
drivers/clk/starfive/clk-starfive-jh71x0.c const struct clk_ops *starfive_jh71x0_clk_ops(u32 max) · line 328
Quoted 8 lines
drivers/clk/starfive/clk-starfive-jh71x0.c +3
-1@@ -313,7 +322,9 @@ const struct clk_ops *starfive_jh71x0_clk_ops(u32 max) }if (max &JH71X0_CLK_ENABLE )return &jh71x0_clk_gdiv_ops; -if (max ==JH71X0_CLK_FRAC_MAX ) +else if (max &JH71X0_CLK_INVERT ) +return &jh71x0_clk_idiv_ops; +else if (max ==JH71X0_CLK_FRAC_MAX )return &jh71x0_clk_fdiv_ops;
Given the branches return, if was enough and you did not need to modify the existing path.
Signature · 1 line
Jerome
Re: [PATCH v6 08/15] clk: starfive: Introduce idiv ops for inverted divider clocks
Hi, Jerome
Quoted 22 lines
Quoted 5 lines
Some StarFive clocks only advertise the divider and invert capabilities (via
JH71X0_CLK_INVERT, without ENABLE). Add theJH71X0_IDIV()macro to declare such clocks, andjh71x0_clk_idiv_ops, which combines the divider rate operations with get_phase/set_phase.Please rephrase, I don't understand what you mean
Quoted 14 lines
Signed-off-by Changhuang Liang <[email protected]>--- drivers/clk/starfive/clk-starfive-jh71x0.c | 13 ++++++++++++- drivers/clk/starfive/clk-starfive-jh71x0.h | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)drivers/clk/starfive/clk-starfive-jh71x0.c +0
-0@@ -303,6 +303,15 @@ static const struct clk_ops jh71x0_clk_inv_ops = { .debug_init = jh71x0_clk_debug_init, };
Quoted 11 lines
drivers/clk/starfive/clk-starfive-jh71x0.c static const struct clk_ops jh71x0_clk_inv_ops = { · line 312
Quoted 7 lines
drivers/clk/starfive/clk-starfive-jh71x0.c +7
-0+static const struct clk_ops jh71x0_clk_idiv_ops = { + .get_phase = jh71x0_clk_get_phase, + .set_phase = jh71x0_clk_set_phase, + .recalc_rate = jh71x0_clk_recalc_rate, + .determine_rate = jh71x0_clk_determine_rate, + .set_rate = jh71x0_clk_set_rate, + .debug_init = jh71x0_clk_debug_init,Instead of trying to cover all the combination that could exist, can you just chain 2 elements ?
a div then an inv ?
This may require introducing quite a few new changes.
In the current code, struct clk_hw *hw is used to obtain struct jh71x0_clk *clk through hw, and then the register offset is obtained through clk->idx.
static void jh71x0_clk_reg_rmw(struct jh71x0_clk *clk, u32 mask, u32 value)
{
struct jh71x0_clk_priv *priv = jh71x0_priv_from(clk);
void __iomem *reg = priv->base + 4 * clk->idx;
unsigned long flags;
spin_lock_irqsave(&priv->rmw_lock, flags);
value |= readl_relaxed(reg) & ~mask;
writel_relaxed(value, reg);
spin_unlock_irqrestore(&priv->rmw_lock, flags);
}static int jh71x0_clk_enable(struct clk_hw *hw)
{
struct jh71x0_clk *clk = jh71x0_clk_from(hw);
jh71x0_clk_reg_rmw(clk, JH71X0_CLK_ENABLE, JH71X0_CLK_ENABLE);
return 0;
}Therefore, the existing code has one struct clk_hw corresponding to one register offset.
If it is split into a div and an inv, two struct clk_hw descriptions will be needed. The jh71x0_crg_probe() will need to implement different branches for different clocks:
if (a div and an inv) {
devm_clk_hw_register (div)
devm_clk_hw_register (inv)
} else {
devm_clk_hw_register (other)
}
Do you need me to make this part of the adjustment?
Quoted 6 lines
drivers/clk/starfive/clk-starfive-jh71x0.c const struct clk_ops *starfive_jh71x0_clk_ops(u32
Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh71x0.c +2
-0+}; +const struct clk_ops *starfive_jh71x0_clk_ops (u32 max) {if (max &JH71X0_CLK_DIV_MASK ) {@@ -313,7 +322,9 @@ const struct clk_ops *starfive_jh71x0_clk_ops(u32max)
Quoted 12 lines
drivers/clk/starfive/clk-starfive-jh71x0.c const struct clk_ops *starfive_jh71x0_clk_ops(u32 max) · line 328
Quoted 8 lines
drivers/clk/starfive/clk-starfive-jh71x0.c +3
-1}if (max &JH71X0_CLK_ENABLE )return &jh71x0_clk_gdiv_ops; -if (max ==JH71X0_CLK_FRAC_MAX ) +else if (max &JH71X0_CLK_INVERT ) +return &jh71x0_clk_idiv_ops; +else if (max ==JH71X0_CLK_FRAC_MAX )return &jh71x0_clk_fdiv_ops;Given the branches return, if was enough and you did not need to modify the existing path.
Best Regards,
Changhuang
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v6 08/15] clk: starfive: Introduce idiv ops for inverted divider clocks
Quoted 65 lines · Changhuang Liang
Hi, Jerome
Quoted 22 lines
Quoted 5 lines
Some StarFive clocks only advertise the divider and invert capabilities (via
JH71X0_CLK_INVERT, without ENABLE). Add theJH71X0_IDIV()macro to declare such clocks, andjh71x0_clk_idiv_ops, which combines the divider rate operations with get_phase/set_phase.Please rephrase, I don't understand what you mean
Quoted 14 lines
Signed-off-by Changhuang Liang <[email protected]>--- drivers/clk/starfive/clk-starfive-jh71x0.c | 13 ++++++++++++- drivers/clk/starfive/clk-starfive-jh71x0.h | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)drivers/clk/starfive/clk-starfive-jh71x0.c +0
-0@@ -303,6 +303,15 @@ static const struct clk_ops jh71x0_clk_inv_ops = { .debug_init = jh71x0_clk_debug_init, };Quoted 11 lines
drivers/clk/starfive/clk-starfive-jh71x0.c static const struct clk_ops jh71x0_clk_inv_ops = { · line 312
Quoted 7 lines
drivers/clk/starfive/clk-starfive-jh71x0.c +7
-0+static const struct clk_ops jh71x0_clk_idiv_ops = { + .get_phase = jh71x0_clk_get_phase, + .set_phase = jh71x0_clk_set_phase, + .recalc_rate = jh71x0_clk_recalc_rate, + .determine_rate = jh71x0_clk_determine_rate, + .set_rate = jh71x0_clk_set_rate, + .debug_init = jh71x0_clk_debug_init,Instead of trying to cover all the combination that could exist, can you just chain 2 elements ?
a div then an inv ?This may require introducing quite a few new changes.
In the current code, struct
clk_hw*hw is used to obtain structjh71x0_clk*clk through hw, and then the register offset is obtained throughclk->idx.static void
jh71x0_clk_reg_rmw(struct jh71x0_clk *clk, u32 mask, u32 value){ struct jh71x0_clk_priv *priv = jh71x0_priv_from(clk); void __iomem *reg = priv->base + 4 * clk->idx; unsigned long flags; spin_lock_irqsave(&priv->rmw_lock, flags); value |= readl_relaxed(reg) & ~mask; writel_relaxed(value, reg); spin_unlock_irqrestore(&priv->rmw_lock, flags); }static int
jh71x0_clk_enable(struct clk_hw *hw){ struct jh71x0_clk *clk = jh71x0_clk_from(hw); jh71x0_clk_reg_rmw(clk, JH71X0_CLK_ENABLE, JH71X0_CLK_ENABLE); return 0; }Therefore, the existing code has one struct
clk_hwcorresponding to one register offset.If it is split into a div and an inv, two struct
clk_hwdescriptions will be needed. Thejh71x0_crg_probe()will need to implement different branches for different clocks:
Quoted 8 lines
if (a div and an inv) {
devm_clk_hw_register(div)
devm_clk_hw_register(inv)
} else {
devm_clk_hw_register(other)
}Do you need me to make this part of the adjustment?
No, it is ok this time around but understand that if this patterns repeats, you will have to fix this. Best would be to start thinking about it at least.
Signature · 1 line
Jerome
PATCH v6 9/15 clk: starfive: Expand the storage of clock parent index
In reply to Changhuang LiangExpand the storage of clock parent index for per0 domain, which parent index over 255. So change u8 to u16.
--- drivers/clk/starfive/clk-starfive-jh71x0.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/starfive/clk-starfive-jh71x0.h +1 -1
@@ -27,7 +27,7 @@ struct jh71x0_clk_data {const char *name;unsigned long flags;u32 max; -u8 parents[4 ]; +u16 parents[4 ]; };#define JH71X0_GATE (_idx, _name, _flags, _parent) \
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v6 10/15 clk: starfive: Add StarFive JHB100 Peripheral-0 clock driver
In reply to Changhuang LiangAdd driver for the StarFive JHB100 Peripheral-0 clock controller.
--- drivers/clk/starfive/Kconfig | 10 + drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-per0.c | 617 ++++++++++++++++++ 3 files changed, 628 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per0.c
drivers/clk/starfive/Kconfig +10 -0
@@ -73,6 +73,16 @@ config CLK_STARFIVE_JH7110_VOUT Say yes here to support the Video-Output clock controller on the StarFive JH7110 SoC. +config CLK_STARFIVE_JHB100_PER0 + bool "StarFive JHB100 peripheral-0 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the peripheral-0 clock controller + on the StarFive JHB100 SoC. + config CLK_STARFIVE_JHB100_SYS0 bool "StarFive JHB100 system-0 clock support" depends on ARCH_STARFIVE || COMPILE_TEST
drivers/clk/starfive/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += clk-starfive-jh7110-stg.o obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o +obj-$(CONFIG_CLK_STARFIVE_JHB100_PER0) += clk-starfive-jhb100-per0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) += clk-starfive-jhb100-sys1.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS2) += clk-starfive-jhb100-sys2.o
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +617 -0
617 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v6 10/15] clk: starfive: Add StarFive JHB100 Peripheral-0 clock driver
Quoted 83 lines
Add driver for the StarFive JHB100 Peripheral-0 clock controller.
Signed-off-by Changhuang Liang <[email protected]>--- drivers/clk/starfive/Kconfig | 10 + drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-per0.c | 617 ++++++++++++++++++ 3 files changed, 628 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per0.cdrivers/clk/starfive/Kconfig +10
-0@@ -73,6 +73,16 @@ config CLK_STARFIVE_JH7110_VOUT Say yes here to support the Video-Output clock controller on the StarFive JH7110 SoC. +config CLK_STARFIVE_JHB100_PER0 + bool "StarFive JHB100 peripheral-0 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the peripheral-0 clock controller + on the StarFive JHB100 SoC. + config CLK_STARFIVE_JHB100_SYS0 bool "StarFive JHB100 system-0 clock support" depends on ARCH_STARFIVE || COMPILE_TESTdrivers/clk/starfive/Makefile +1
-0@@ -11,6 +11,7 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += clk-starfive-jh7110-stg.o obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o +obj-$(CONFIG_CLK_STARFIVE_JHB100_PER0) += clk-starfive-jhb100-per0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) += clk-starfive-jhb100-sys1.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS2) += clk-starfive-jhb100-sys2.odrivers/clk/starfive/clk-starfive-jhb100-per0.c new file +34
-0@@ -0,0 +1,617 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* StarFive JHB100 Peripheral-0 Clock Driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* +* Author: Changhuang Liang <[email protected]> +* +*/ + +#include <dt-bindings/clock/starfive,jhb100-crg.h> +#include <linux/platform_device.h> + +#include "clk-starfive-jh71x0.h" + +#define JHB100_PER0CLK_NUM_CLKS (JHB100_PER0CLK_MAIN_ICG_EN_TRNG + 1) + +/* external clocks */ +#define JHB100_PER0CLK_OSC (JHB100_PER0CLK_NUM_CLKS + 0) +#define JHB100_PER0CLK_PLL6 (JHB100_PER0CLK_NUM_CLKS + 1) +#define JHB100_PER0CLK_CFG_400 (JHB100_PER0CLK_NUM_CLKS + 2) +#define JHB100_PER0CLK_CFG_800 (JHB100_PER0CLK_NUM_CLKS + 3) +#define JHB100_PER0CLK_NCNOC_INIT (JHB100_PER0CLK_NUM_CLKS + 4) +#define JHB100_PER0CLK_NCNOC_TARG (JHB100_PER0CLK_NUM_CLKS + 5) + +static const char *const jhb100_per0_ext_clk[] = { +"osc" , +"pll6" , +"cfg_400" , +"cfg_800" , +"ncnoc_init" , +"ncnoc_targ" , +}; +
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 44
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +10
-0+/* +* Regarding the CLK_IS_CRITICAL flag: +* What is special here is the UART*-related clocks. On the JHB100, the secure +* core may consume one UART, while the AP core consumes another. Different +* core boards may select different UARTs, so we usually want to keep all UART* +* clocks always on to prevent the AP core from turning off the clock for the +* secure core's UART. +* UART0-3 are usually used by the HOST side, and there will be no driver on +* the BMC side to consume these clocks. Therefore, these clocks need to be +* enabled for the host to consume.
So you are forcefully enabling 14 clocks for 1 to 4 clocks that may or may not be used. This is not how this should work. You just enable clock randomly hoping it will cover your use case. If you are managing the clock for these secure core, it clearly shows you need a driver for it.
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 51
Quoted 7 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +7
-0+* +* Regarding the CLK_IGNORE_UNUSED flag: +* Clocks flagged CLK_IGNORE_UNUSED are not consumed by any driver. The flag +* keeps them in their hardware default state (enabled) instead of letting +* the clock framework gate them once it disables unused clocks. If this +* flag needs to be removed later, it must be ensured that these clocks will +* not be disabled even if they are not consumed.
Why ? you are ignoring all sorts of thing in there like i3c. If the i3c bus is unused, the clock should be disabled. If it is actively used, why don't you have a driver for it ?
Throwing CLK_IGNORE_UNUSED and CLK_IS_CRITICAL at the majority of your clocks is not OK.
Signature · 1 line
Jerome
Re: [PATCH v6 10/15] clk: starfive: Add StarFive JHB100 Peripheral-0 clock driver
Hi, Jerome
Quoted 111 lines
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) +=
Quoted 36 lines
Add driver for the StarFive JHB100 Peripheral-0 clock controller.
Signed-off-by Changhuang Liang <[email protected]>--- drivers/clk/starfive/Kconfig | 10 + drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-per0.c | 617 ++++++++++++++++++ 3 files changed, 628 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per0.c(quoted diff) +0
-0b/drivers/clk/starfive/Kconfig index
cfaac934a8e0..b2a05bbb450f100644drivers/clk/starfive/Kconfig +10
-0@@ -73,6 +73,16 @@ config CLK_STARFIVE_JH7110_VOUT Say yes here to support the Video-Output clock controller on the StarFive JH7110 SoC. +config CLK_STARFIVE_JHB100_PER0 + bool "StarFive JHB100 peripheral-0 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the peripheral-0 clock controller + on the StarFive JHB100 SoC. + config CLK_STARFIVE_JHB100_SYS0 bool "StarFive JHB100 system-0 clock support" depends on ARCH_STARFIVE || COMPILE_TEST diff --gita/drivers/clk/starfive/Makefile b/drivers/clk/starfive/Makefile index 29cdef20575e..352717886295 100644
drivers/clk/starfive/Makefile +0
-0@@ -11,6 +11,7 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) +=clk-starfive-jh7110-stg.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += · line 12
Quoted 2 lines
drivers/clk/starfive/Makefile +0
-0obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) +=clk-starfive-jh7110-vout.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += · line 13
Quoted 2 lines
drivers/clk/starfive/Makefile +1
-0+obj-$(CONFIG_CLK_STARFIVE_JHB100_PER0) +=clk-starfive-jhb100-per0.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += · line 14
Quoted 1 line
drivers/clk/starfive/Makefile +0
-0obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) +=clk-starfive-jhb100-sys0.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += · line 15
Quoted 1 line
drivers/clk/starfive/Makefile +0
-0obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) +=clk-starfive-jhb100-sys1.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += · line 16
Quoted 1 line
drivers/clk/starfive/Makefile +0
-0obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS2) +=clk-starfive-jhb100-sys2.o
Quoted 13 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +6
-0@@ -0,0 +1,617 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* StarFive JHB100 Peripheral-0 Clock Driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* drivers/clk/starfive/clk-starfive-jhb100-per0.c line 16
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +10
-0+* Author: Changhuang Liang <[email protected]> +* +*/ + +#include <dt-bindings/clock/starfive,jhb100-crg.h> +#include <linux/platform_device.h> + +#include "clk-starfive-jh71x0.h" + +#define JHB100_PER0CLK_NUM_CLKS (JHB100_PER0CLK_MAIN_ICG_EN_TRNG + 1)drivers/clk/starfive/clk-starfive-jhb100-per0.c
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +3
-0+ +/* external clocks */ +#define JHB100_PER0CLK_OSC (JHB100_PER0CLK_NUM_CLKS + 0)drivers/clk/starfive/clk-starfive-jhb100-per0.c line 20
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+#define JHB100_PER0CLK_PLL6 (JHB100_PER0CLK_NUM_CLKS + 1)drivers/clk/starfive/clk-starfive-jhb100-per0.c line 21
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+#define JHB100_PER0CLK_CFG_400 (JHB100_PER0CLK_NUM_CLKS + 2)drivers/clk/starfive/clk-starfive-jhb100-per0.c line 22
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+#define JHB100_PER0CLK_CFG_800 (JHB100_PER0CLK_NUM_CLKS + 3)drivers/clk/starfive/clk-starfive-jhb100-per0.c line 23
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+#define JHB100_PER0CLK_NCNOC_INIT (JHB100_PER0CLK_NUM_CLKS + 4)drivers/clk/starfive/clk-starfive-jhb100-per0.c line 24
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+#define JHB100_PER0CLK_NCNOC_TARG (JHB100_PER0CLK_NUM_CLKS + 5)drivers/clk/starfive/clk-starfive-jhb100-per0.c
Quoted 13 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +13
-0+ +static const char *const jhb100_per0_ext_clk[] = { +"osc" , +"pll6" , +"cfg_400" , +"cfg_800" , +"ncnoc_init" , +"ncnoc_targ" , +}; + +/* +* Regarding the CLK_IS_CRITICAL flag: +* What is special here is the UART*-related clocks. On the JHB100, the secure
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 38
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* core may consume one UART, while the AP core consumes another. Different
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 39
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* core boards may select different UARTs, so we usually want to keep all UART*
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 40
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* clocks always on to prevent the AP core from turning off the clock for the
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 42
Quoted 2 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +2
-0+* secure core's UART. +* UART0-3 are usually used by the HOST side, and there will be no driver on
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 43
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* the BMC side to consume these clocks. Therefore, these clocks need
Quoted 8 lines
to be
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 44
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* enabled for the host to consume. So you are forcefully enabling 14 clocks for 1 to 4 clocks that may or may not be used.
This is not how this should work. You just enable clock randomly hoping it will cover your use case. If you are managing the clock for these secure core, it clearly shows you need a driver for it.
Can I keep the clocks for uart0-3 as CLK_IS_CRITICAL here? On the JHB100 BMC SoC, uart0-3 are provided for the host to read and write registers via eSPI. On our BMC side, we need to ensure the clocks are always on to provide host access.
Quoted 11 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c
Quoted 4 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +3
-0+* +* Regarding the CLK_IGNORE_UNUSED flag: +* Clocks flagged CLK_IGNORE_UNUSED are not consumed by any driver. The flag
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 48
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* keeps them in their hardware default state (enabled) instead of letting
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 49
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* the clock framework gate them once it disables unused clocks. If this
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 50
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* flag needs to be removed later, it must be ensured that these clocks will
Quoted 8 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 51
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* not be disabled even if they are not consumed. Why ? you are ignoring all sorts of thing in there like i3c. If the i3c bus is unused, the clock should be disabled. If it is actively used, why don't you have a driver for it ?
Throwing
CLK_IGNORE_UNUSEDandCLK_IS_CRITICALat the majority of your clocks is not OK.
Will remove CLK_IGNORE_UNUSED flag.
Best Regards,
Changhuang
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v6 10/15] clk: starfive: Add StarFive JHB100 Peripheral-0 clock driver
Quoted 122 lines · Changhuang Liang
Hi, Jerome
Quoted 111 lines
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) +=
Quoted 36 lines
Add driver for the StarFive JHB100 Peripheral-0 clock controller.
Signed-off-by Changhuang Liang <[email protected]>--- drivers/clk/starfive/Kconfig | 10 + drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-per0.c | 617 ++++++++++++++++++ 3 files changed, 628 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per0.c(quoted diff) +0
-0b/drivers/clk/starfive/Kconfig index
cfaac934a8e0..b2a05bbb450f100644drivers/clk/starfive/Kconfig +10
-0@@ -73,6 +73,16 @@ config CLK_STARFIVE_JH7110_VOUT Say yes here to support the Video-Output clock controller on the StarFive JH7110 SoC. +config CLK_STARFIVE_JHB100_PER0 + bool "StarFive JHB100 peripheral-0 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the peripheral-0 clock controller + on the StarFive JHB100 SoC. + config CLK_STARFIVE_JHB100_SYS0 bool "StarFive JHB100 system-0 clock support" depends on ARCH_STARFIVE || COMPILE_TEST diff --gita/drivers/clk/starfive/Makefile b/drivers/clk/starfive/Makefile index 29cdef20575e..352717886295 100644
drivers/clk/starfive/Makefile +0
-0@@ -11,6 +11,7 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) +=clk-starfive-jh7110-stg.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += · line 12
Quoted 2 lines
drivers/clk/starfive/Makefile +0
-0obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) +=clk-starfive-jh7110-vout.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += · line 13
Quoted 2 lines
drivers/clk/starfive/Makefile +1
-0+obj-$(CONFIG_CLK_STARFIVE_JHB100_PER0) +=clk-starfive-jhb100-per0.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += · line 14
Quoted 1 line
drivers/clk/starfive/Makefile +0
-0obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) +=clk-starfive-jhb100-sys0.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += · line 15
Quoted 1 line
drivers/clk/starfive/Makefile +0
-0obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) +=clk-starfive-jhb100-sys1.o
drivers/clk/starfive/Makefile obj-$(CONFIG_CLK_STARFIVE_JH7110_STG) += · line 16
Quoted 1 line
drivers/clk/starfive/Makefile +0
-0obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS2) +=clk-starfive-jhb100-sys2.o
Quoted 13 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +6
-0@@ -0,0 +1,617 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* StarFive JHB100 Peripheral-0 Clock Driver +* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +* drivers/clk/starfive/clk-starfive-jhb100-per0.c line 16
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +10
-0+* Author: Changhuang Liang <[email protected]> +* +*/ + +#include <dt-bindings/clock/starfive,jhb100-crg.h> +#include <linux/platform_device.h> + +#include "clk-starfive-jh71x0.h" + +#define JHB100_PER0CLK_NUM_CLKS (JHB100_PER0CLK_MAIN_ICG_EN_TRNG + 1)drivers/clk/starfive/clk-starfive-jhb100-per0.c
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +3
-0+ +/* external clocks */ +#define JHB100_PER0CLK_OSC (JHB100_PER0CLK_NUM_CLKS + 0)drivers/clk/starfive/clk-starfive-jhb100-per0.c line 20
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+#define JHB100_PER0CLK_PLL6 (JHB100_PER0CLK_NUM_CLKS + 1)drivers/clk/starfive/clk-starfive-jhb100-per0.c line 21
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+#define JHB100_PER0CLK_CFG_400 (JHB100_PER0CLK_NUM_CLKS + 2)drivers/clk/starfive/clk-starfive-jhb100-per0.c line 22
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+#define JHB100_PER0CLK_CFG_800 (JHB100_PER0CLK_NUM_CLKS + 3)drivers/clk/starfive/clk-starfive-jhb100-per0.c line 23
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+#define JHB100_PER0CLK_NCNOC_INIT (JHB100_PER0CLK_NUM_CLKS + 4)drivers/clk/starfive/clk-starfive-jhb100-per0.c line 24
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+#define JHB100_PER0CLK_NCNOC_TARG (JHB100_PER0CLK_NUM_CLKS + 5)drivers/clk/starfive/clk-starfive-jhb100-per0.c
Quoted 13 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +13
-0+ +static const char *const jhb100_per0_ext_clk[] = { +"osc" , +"pll6" , +"cfg_400" , +"cfg_800" , +"ncnoc_init" , +"ncnoc_targ" , +}; + +/* +* Regarding the CLK_IS_CRITICAL flag: +* What is special here is the UART*-related clocks. On the JHB100, the secure
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 38
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* core may consume one UART, while the AP core consumes another. Different
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 39
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* core boards may select different UARTs, so we usually want to keep all UART*
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 40
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* clocks always on to prevent the AP core from turning off the clock for the
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 42
Quoted 2 lines
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +2
-0+* secure core's UART. +* UART0-3 are usually used by the HOST side, and there will be no driver on
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 43
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* the BMC side to consume these clocks. Therefore, these clocks need Quoted 8 lines
to be
drivers/clk/starfive/clk-starfive-jhb100-per0.c line 44
Quoted 1 line
drivers/clk/starfive/clk-starfive-jhb100-per0.c new file +1
-0+* enabled for the host to consume. So you are forcefully enabling 14 clocks for 1 to 4 clocks that may or may not be used.
This is not how this should work. You just enable clock randomly hoping it will cover your use case. If you are managing the clock for these secure core, it clearly shows you need a driver for it.
Quoted 4 lines
Can I keep the clocks for uart0-3 as
CLK_IS_CRITICALhere? On the JHB100 BMC SoC, uart0-3 are provided for the host to read and write registers via eSPI. On our BMC side, we need to ensure the clocks are always on to provide host access.
It would be less problematic, but still I do not understand why a uart end up being critical.
If you are letting the host map the uart memory region and implement some 'userspace' driver, you already know what you are doing is bad. So it is hardly a good reason.
Signature · 1 line
Jerome
PATCH v6 11/15 clk: starfive: Add StarFive JHB100 Peripheral-1 clock driver
In reply to Changhuang LiangAdd driver for the StarFive JHB100 Peripheral-1 clock controller.
--- drivers/clk/starfive/Kconfig | 10 ++ drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-per1.c | 162 ++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per1.c
drivers/clk/starfive/Kconfig +10 -0
@@ -83,6 +83,16 @@ config CLK_STARFIVE_JHB100_PER0 Say yes here to support the peripheral-0 clock controller on the StarFive JHB100 SoC. +config CLK_STARFIVE_JHB100_PER1 + bool "StarFive JHB100 peripheral-1 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the peripheral-1 clock controller + on the StarFive JHB100 SoC. + config CLK_STARFIVE_JHB100_SYS0 bool "StarFive JHB100 system-0 clock support" depends on ARCH_STARFIVE || COMPILE_TEST
drivers/clk/starfive/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_ISP) += clk-starfive-jh7110-isp.o obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o obj-$(CONFIG_CLK_STARFIVE_JHB100_PER0) += clk-starfive-jhb100-per0.o +obj-$(CONFIG_CLK_STARFIVE_JHB100_PER1) += clk-starfive-jhb100-per1.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) += clk-starfive-jhb100-sys1.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS2) += clk-starfive-jhb100-sys2.o
drivers/clk/starfive/clk-starfive-jhb100-per1.c new file +162 -0
162 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v6 12/15 clk: starfive: Add StarFive JHB100 Peripheral-2 clock driver
In reply to Changhuang LiangAdd driver for the StarFive JHB100 Peripheral-2 clock controller.
--- drivers/clk/starfive/Kconfig | 10 + drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-per2.c | 182 ++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per2.c
drivers/clk/starfive/Kconfig +10 -0
@@ -93,6 +93,16 @@ config CLK_STARFIVE_JHB100_PER1 Say yes here to support the peripheral-1 clock controller on the StarFive JHB100 SoC. +config CLK_STARFIVE_JHB100_PER2 + bool "StarFive JHB100 peripheral-2 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the peripheral-2 clock controller + on the StarFive JHB100 SoC. + config CLK_STARFIVE_JHB100_SYS0 bool "StarFive JHB100 system-0 clock support" depends on ARCH_STARFIVE || COMPILE_TEST
drivers/clk/starfive/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o obj-$(CONFIG_CLK_STARFIVE_JHB100_PER0) += clk-starfive-jhb100-per0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_PER1) += clk-starfive-jhb100-per1.o +obj-$(CONFIG_CLK_STARFIVE_JHB100_PER2) += clk-starfive-jhb100-per2.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) += clk-starfive-jhb100-sys1.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS2) += clk-starfive-jhb100-sys2.o
drivers/clk/starfive/clk-starfive-jhb100-per2.c new file +182 -0
182 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v6 13/15 clk: starfive: Add StarFive JHB100 Peripheral-3 clock driver
In reply to Changhuang LiangAdd driver for the StarFive JHB100 Peripheral-3 clock controller.
--- drivers/clk/starfive/Kconfig | 10 ++ drivers/clk/starfive/Makefile | 1 + .../clk/starfive/clk-starfive-jhb100-per3.c | 140 ++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-per3.c
drivers/clk/starfive/Kconfig +10 -0
@@ -103,6 +103,16 @@ config CLK_STARFIVE_JHB100_PER2 Say yes here to support the peripheral-2 clock controller on the StarFive JHB100 SoC. +config CLK_STARFIVE_JHB100_PER3 + bool "StarFive JHB100 peripheral-3 clock support" + depends on ARCH_STARFIVE || COMPILE_TEST + select CLK_STARFIVE_JH71X0 + select RESET_STARFIVE_JHB100 if RESET_CONTROLLER + default ARCH_STARFIVE + help + Say yes here to support the peripheral-3 clock controller + on the StarFive JHB100 SoC. + config CLK_STARFIVE_JHB100_SYS0 bool "StarFive JHB100 system-0 clock support" depends on ARCH_STARFIVE || COMPILE_TEST
drivers/clk/starfive/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_CLK_STARFIVE_JH7110_VOUT) += clk-starfive-jh7110-vout.o obj-$(CONFIG_CLK_STARFIVE_JHB100_PER0) += clk-starfive-jhb100-per0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_PER1) += clk-starfive-jhb100-per1.o obj-$(CONFIG_CLK_STARFIVE_JHB100_PER2) += clk-starfive-jhb100-per2.o +obj-$(CONFIG_CLK_STARFIVE_JHB100_PER3) += clk-starfive-jhb100-per3.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS0) += clk-starfive-jhb100-sys0.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS1) += clk-starfive-jhb100-sys1.o obj-$(CONFIG_CLK_STARFIVE_JHB100_SYS2) += clk-starfive-jhb100-sys2.o
drivers/clk/starfive/clk-starfive-jhb100-per3.c new file +140 -0
140 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v6 14/15 reset: starfive: jh71x0: Support discontiguous reset IDs
In reply to Changhuang LiangThe reset IDs exposed to consumers of the StarFive JHB100 reset controllers do not map one-to-one to the hardware reset bits.
Add struct jh71x0_reset_info, which describes the number of resets, the assert/status register offsets and, for discontiguous controllers, a table mapping reset IDs to hardware bits. Add reset_starfive_jh71x0_register_with_info() to register such a controller, and translate the reset ID in the update and status callbacks when a map is provided.
Existing users of reset_starfive_jh71x0_register() are unaffected.
--- .../reset/starfive/reset-starfive-jh71x0.c | 99 ++++++++++++++++--- .../reset/starfive/reset-starfive-jh71x0.h | 19 ++++ 2 files changed, 107 insertions(+), 11 deletions(-)
drivers/reset/starfive/reset-starfive-jh71x0.c +88 -11
@@ -14,6 +14,8 @@#include "reset-starfive-jh71x0.h" +#define JH71X0_RESET_ID_INVALID ULONG_MAX +struct jh71x0_reset {struct reset_controller_dev rcdev;/* protect registers against concurrent read-modify-write */
@@ -21,6 +23,11 @@ struct jh71x0_reset {void __iomem *assert;void __iomem *status;const u32 *asserted; + +/* Only exists in reset controllers that use the +* reset_starfive_jh71x0_register_with_info helper. +*/ +const struct jh71x0_reset_info *info; }; static inline struct jh71x0_reset *
@@ -29,19 +36,40 @@ jh71x0_reset_from(struct reset_controller_dev *rcdev) return container_of(rcdev, struct jh71x0_reset, rcdev); } +static unsigned long +jh71x0_reset_id_to_hw_id (const struct jh71x0_reset_map *map,unsigned int nr_resets, +unsigned long reset_id) +{ +for (u32 i =0 ; i < nr_resets; i++) { +if (map[i].reset_id == reset_id) +return map[i].hw_id; + } + +return JH71X0_RESET_ID_INVALID ; +} +static int jh71x0_reset_update (struct reset_controller_dev *rcdev,unsigned long id,bool assert) {struct jh71x0_reset *data =jh71x0_reset_from (rcdev); -unsigned long offset = id /32 ; -u32 mask =BIT (id %32 ); -void __iomem *reg_assert = data->assert + offset *sizeof (u32); -void __iomem *reg_status = data->status + offset *sizeof (u32); -u32 done = data->asserted ? data->asserted[offset] & mask :0 ; -u32 value; -unsigned long flags; +unsigned long offset, flags; +void __iomem *reg_assert; +void __iomem *reg_status; +u32 mask, done, value;int ret; +if (data->info && data->info->discontiguous) { + id =jh71x0_reset_id_to_hw_id (data->info->map, data->info->nr_resets, id); +if (id ==JH71X0_RESET_ID_INVALID ) +return -EINVAL ; + } + + offset = id /32 ; + mask =BIT (id %32 ); + reg_assert = data->assert + offset *sizeof (u32); + reg_status = data->status + offset *sizeof (u32); + done = data->asserted ? data->asserted[offset] & mask :0 ; +if (!assert) done ^= mask;
@@ -89,10 +117,20 @@ static int jh71x0_reset_status(struct reset_controller_dev *rcdev, unsigned long id) {struct jh71x0_reset *data =jh71x0_reset_from (rcdev); -unsigned long offset = id /32 ; -u32 mask =BIT (id %32 ); -void __iomem *reg_status = data->status + offset *sizeof (u32); -u32 value =readl (reg_status); +void __iomem *reg_status; +unsigned long offset; +u32 mask, value; + +if (data->info && data->info->discontiguous) { + id =jh71x0_reset_id_to_hw_id (data->info->map, data->info->nr_resets, id); +if (id ==JH71X0_RESET_ID_INVALID ) +return -EINVAL ; + } + + offset = id /32 ; + mask =BIT (id %32 ); + reg_status = data->status + offset *sizeof (u32); + value =readl (reg_status);if (!data->asserted)return !(value & mask);
@@ -132,3 +170,42 @@ int reset_starfive_jh71x0_register(struct device *dev, struct device_node *of_noreturn devm_reset_controller_register (dev, &data->rcdev); }EXPORT_SYMBOL_GPL (reset_starfive_jh71x0_register); + +int reset_starfive_jh71x0_register_with_info (struct device *dev,struct device_node *of_node, +void __iomem *assert,void __iomem *status, +const u32 *asserted, +const struct jh71x0_reset_info *info, +struct module *owner) +{ +struct jh71x0_reset *data; +int ret; + +if (info->discontiguous && (!info->map || !info->nr_resets)) +return dev_err_probe (dev, -EINVAL , +"discontiguous controller without a valid ID map\n" ); + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->rcdev.ops = &jh71x0_reset_ops; + data->rcdev.owner = owner; + data->rcdev.nr_resets = info->nr_resets; + data->rcdev.dev = dev; + data->rcdev.of_node = of_node; + +spin_lock_init (&data->lock); + data->assert = assert; + data->status = status; + data->asserted = asserted; + data->info = info; + + ret =devm_reset_controller_register (dev, &data->rcdev); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to register reset controller\n" ); + +dev_info (dev,"Registered %u resets\n" , data->rcdev.nr_resets); + +return 0 ; +} +EXPORT_SYMBOL_GPL (reset_starfive_jh71x0_register_with_info);
drivers/reset/starfive/reset-starfive-jh71x0.h +19 -0
@@ -6,9 +6,28 @@#ifndef __RESET_STARFIVE_JH71X0_H#define __RESET_STARFIVE_JH71X0_H +struct jh71x0_reset_map { +unsigned long reset_id; +unsigned long hw_id; +}; + +struct jh71x0_reset_info { +unsigned int nr_resets; +unsigned int assert_offset; +unsigned int status_offset; +bool discontiguous; +const struct jh71x0_reset_map *map; +}; +int reset_starfive_jh71x0_register (struct device *dev,struct device_node *of_node,void __iomem *assert,void __iomem *status,const u32 *asserted,unsigned int nr_resets,struct module *owner); +int reset_starfive_jh71x0_register_with_info (struct device *dev,struct device_node *of_node, +void __iomem *assert,void __iomem *status, +const u32 *asserted, +const struct jh71x0_reset_info *info, +struct module *owner); +#endif /* __RESET_STARFIVE_JH71X0_H */
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Philipp Zabel
maintainerRe: [PATCH v6 14/15] reset: starfive: jh71x0: Support discontiguous reset IDs
Quoted 22 lines · Changhuang Liang
The reset IDs exposed to consumers of the StarFive JHB100 reset controllers do not map one-to-one to the hardware reset bits.
Add struct
jh71x0_reset_info, which describes the number of resets, the assert/status register offsets and, for discontiguous controllers, a table mapping reset IDs to hardware bits. Addreset_starfive_jh71x0_register_with_info()to register such a controller, and translate the reset ID in the update and status callbacks when a map is provided.Existing users of
reset_starfive_jh71x0_register()are unaffected.Signed-off-by Changhuang Liang <[email protected]>--- .../reset/starfive/reset-starfive-jh71x0.c | 99 ++++++++++++++++--- .../reset/starfive/reset-starfive-jh71x0.h | 19 ++++ 2 files changed, 107 insertions(+), 11 deletions(-)drivers/reset/starfive/reset-starfive-jh71x0.c +0
-0
[...]
Quoted 28 lines
drivers/reset/starfive/reset-starfive-jh71x0.c +13
-7@@ -29,19 +36,40 @@ jh71x0_reset_from(struct reset_controller_dev *rcdev) return container_of(rcdev, struct jh71x0_reset, rcdev); } +static unsigned long +jh71x0_reset_id_to_hw_id (const struct jh71x0_reset_map *map,unsigned int nr_resets, +unsigned long reset_id) +{ +for (u32 i =0 ; i < nr_resets; i++) { +if (map[i].reset_id == reset_id) +return map[i].hw_id; + } + +return JH71X0_RESET_ID_INVALID ; +} +static int jh71x0_reset_update (struct reset_controller_dev *rcdev,unsigned long id,bool assert) {struct jh71x0_reset *data =jh71x0_reset_from (rcdev); -unsigned long offset = id /32 ; -u32 mask =BIT (id %32 ); -void __iomem *reg_assert = data->assert + offset *sizeof (u32); -void __iomem *reg_status = data->status + offset *sizeof (u32); -u32 done = data->asserted ? data->asserted[offset] & mask :0 ; -u32 value; -unsigned long flags; +unsigned long offset, flags;
drivers/reset/starfive/reset-starfive-jh71x0.c jh71x0_reset_from(struct reset_controller_dev *rcdev) · line 65
Quoted 10 lines
drivers/reset/starfive/reset-starfive-jh71x0.c +8
-0+void __iomem *reg_assert; +void __iomem *reg_status; +u32 mask, done, value;int ret; +if (data->info && data->info->discontiguous) { + id =jh71x0_reset_id_to_hw_id (data->info->map, data->info->nr_resets, id); +if (id ==JH71X0_RESET_ID_INVALID ) +return -EINVAL ; + }
Why is this lookup done in the ops?
It should be done once in fwnode_xlate instead.
Quoted 11 lines
drivers/reset/starfive/reset-starfive-jh71x0.c +7
-0+ + offset = id /32 ; + mask =BIT (id %32 ); + reg_assert = data->assert + offset *sizeof (u32); + reg_status = data->status + offset *sizeof (u32); + done = data->asserted ? data->asserted[offset] & mask :0 ; +if (!assert) done ^= mask;
[...]
Quoted 17 lines
drivers/reset/starfive/reset-starfive-jh71x0.c +13
-0@@ -132,3 +170,42 @@ int reset_starfive_jh71x0_register(struct device *dev, struct device_node *of_noreturn devm_reset_controller_register (dev, &data->rcdev); }EXPORT_SYMBOL_GPL (reset_starfive_jh71x0_register); + +int reset_starfive_jh71x0_register_with_info (struct device *dev,struct device_node *of_node, +void __iomem *assert,void __iomem *status, +const u32 *asserted, +const struct jh71x0_reset_info *info, +struct module *owner) +{ +struct jh71x0_reset *data; +int ret; + +if (info->discontiguous && (!info->map || !info->nr_resets)) +return dev_err_probe (dev, -EINVAL , +"discontiguous controller without a valid ID map\n" );
drivers/reset/starfive/reset-starfive-jh71x0.c int reset_starfive_jh71x0_register(struct device *dev, struct device_node *of_no · line 195
Quoted 10 lines
drivers/reset/starfive/reset-starfive-jh71x0.c +10
-0+ + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->rcdev.ops = &jh71x0_reset_ops; + data->rcdev.owner = owner; + data->rcdev.nr_resets = info->nr_resets; + data->rcdev.dev = dev; + data->rcdev.of_node = of_node;
You can add a custom fwnode_xlate that does the jh71x0_reset_id_to_hw_id() translation if info->map is set.
Quoted 24 lines
drivers/reset/starfive/reset-starfive-jh71x0.c +16
-0+ +spin_lock_init (&data->lock); + data->assert = assert; + data->status = status; + data->asserted = asserted; + data->info = info; + + ret =devm_reset_controller_register (dev, &data->rcdev); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to register reset controller\n" ); + +dev_info (dev,"Registered %u resets\n" , data->rcdev.nr_resets); + +return 0 ; +} +EXPORT_SYMBOL_GPL (reset_starfive_jh71x0_register_with_info);drivers/reset/starfive/reset-starfive-jh71x0.h +0
-0@@ -6,9 +6,28 @@#ifndef __RESET_STARFIVE_JH71X0_H#define __RESET_STARFIVE_JH71X0_H
drivers/reset/starfive/reset-starfive-jh71x0.h line 18
Quoted 10 lines
drivers/reset/starfive/reset-starfive-jh71x0.h +10
-0+struct jh71x0_reset_map { +unsigned long reset_id; +unsigned long hw_id; +}; + +struct jh71x0_reset_info { +unsigned int nr_resets; +unsigned int assert_offset; +unsigned int status_offset; +bool discontiguous;
This seems superfluous, (map != NULL) means discontiguous already.
drivers/reset/starfive/reset-starfive-jh71x0.h line 21
Quoted 3 lines
drivers/reset/starfive/reset-starfive-jh71x0.h +3
-0+const struct jh71x0_reset_map *map; +}; +
regards
Philipp
PATCH v6 15/15 reset: starfive: Add StarFive JHB100 reset driver
In reply to Changhuang LiangAdd auxiliary reset driver to support StarFive JHB100 SoC.
--- MAINTAINERS | 6 + drivers/reset/starfive/Kconfig | 9 + drivers/reset/starfive/Makefile | 1 + .../reset/starfive/reset-starfive-jhb100.c | 303 ++++++++++++++++++ 4 files changed, 319 insertions(+) create mode 100644 drivers/reset/starfive/reset-starfive-jhb100.c
MAINTAINERS +6 -0
@@ -26660,6 +26660,12 @@ S: Maintained F: Documentation/devicetree/bindings/pinctrl/starfive,jhb1*.yaml F: drivers/pinctrl/starfive/pinctrl-starfive-jhb1* +STARFIVE JHB100 RESET CONTROLLER DRIVERS +M: Changhuang Liang <[email protected]> +S: Supported +F: drivers/reset/starfive/reset-starfive-jhb1* +F: include/dt-bindings/reset/starfive,jhb1*.h + STATIC BRANCH/CALL M: Peter Zijlstra <[email protected]> M: Josh Poimboeuf <[email protected]>
drivers/reset/starfive/Kconfig +9 -0
@@ -19,3 +19,12 @@ config RESET_STARFIVE_JH7110 default ARCH_STARFIVE help This enables the reset controller driver for the StarFive JH7110 SoC. + +config RESET_STARFIVE_JHB100 + bool "StarFive JHB100 Reset Driver" + depends on CLK_STARFIVE_JH71X0 || COMPILE_TEST + select AUXILIARY_BUS + select RESET_STARFIVE_JH71X0 + default ARCH_STARFIVE + help + This enables the reset controller driver for the StarFive JHB100 SoC.
drivers/reset/starfive/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-$(CONFIG_RESET_STARFIVE_JH71X0) += reset-starfive-jh71x0.o obj-$(CONFIG_RESET_STARFIVE_JH7100) += reset-starfive-jh7100.o obj-$(CONFIG_RESET_STARFIVE_JH7110) += reset-starfive-jh7110.o +obj-$(CONFIG_RESET_STARFIVE_JHB100) += reset-starfive-jhb100.o
drivers/reset/starfive/reset-starfive-jhb100.c new file +303 -0
303 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 2 lines
The JHB100 SoC includes CRG (Clock and Reset Generator) for multiple subsystems:
Nothing really forces you to send them all together.
In the future, could you try to send one CRG driver at a time ?
It is fine to send big RFC to give context but after that, if you can make you series smaller, it is generally a good idea to do so.
This helps us iterate on the series faster and then you can fold our feedback in following series (instead of repeating the same comments on multiple instances of the same thing) Thanks.
Also your series does not apply on clk-next or -rc1 and no pre-requisite are mentioned in this cover letter. Consider using b4 to point out your pre-requisite if any
Signature · 1 line
Jerome
Quoted 10 lines · Jerome Brunet
Quoted 2 lines
The JHB100 SoC includes CRG (Clock and Reset Generator) for multiple subsystems:
Nothing really forces you to send them all together.
In the future, could you try to send one CRG driver at a time ?
It is fine to send big RFC to give context but after that, if you can make you series smaller, it is generally a good idea to do so.
Quoted 8 lines
This helps us iterate on the series faster and then you can fold our feedback in following series (instead of repeating the same comments on multiple instances of the same thing) Thanks.
Also your series does not apply on clk-next or -rc1 and no pre-requisite are mentioned in this cover letter. Consider using b4 to point out your pre-requisite if any
The dep should be the PR I sent to Brian, but I suspect what's happened here is that the MAINTAINERS parts of those patches (which I had dropped because they were all conflicting with my tree) didn't get reabsorbed into this series. Very annoying for review of course, even if it's a non-functional conflict. Of course rebase on top of clk-next would've highlighted that to the submitter!
Quoted 20 lines · Conor Dooley
Quoted 10 lines · Jerome Brunet
Quoted 2 lines
The JHB100 SoC includes CRG (Clock and Reset Generator) for multiple subsystems:
Nothing really forces you to send them all together.
In the future, could you try to send one CRG driver at a time ?
It is fine to send big RFC to give context but after that, if you can make you series smaller, it is generally a good idea to do so.
Quoted 8 lines
This helps us iterate on the series faster and then you can fold our feedback in following series (instead of repeating the same comments on multiple instances of the same thing) Thanks.
Also your series does not apply on clk-next or -rc1 and no pre-requisite are mentioned in this cover letter. Consider using b4 to point out your pre-requisite if any
Quoted 6 lines
The dep should be the PR I sent to Brian, but I suspect what's happened here is that the
MAINTAINERSparts of those patches (which I had dropped because they were all conflicting with my tree) didn't get reabsorbed into this series. Very annoying for review of course, even if it's a non-functional conflict. Of course rebase on top of clk-next would've highlighted that to the submitter!
Yes it was only the MAINTAINERS file which I did rebase to check if the rest applied correctly.
Signature · 1 line
Jerome
Hi, Jerome
Quoted 29 lines · Conor Dooley
Quoted 21 lines · Jerome Brunet
Quoted 11 lines
Quoted 3 lines
The JHB100 SoC includes CRG (Clock and Reset Generator) for multiple
subsystems:Nothing really forces you to send them all together.
In the future, could you try to send one CRG driver at a time ?
It is fine to send big RFC to give context but after that, if you can make you series smaller, it is generally a good idea to do so.
Quoted 8 lines
This helps us iterate on the series faster and then you can fold our feedback in following series (instead of repeating the same comments on multiple instances of the same thing) Thanks.
Also your series does not apply on clk-next or -rc1 and no pre-requisite are mentioned in this cover letter. Consider using b4 to point out your pre-requisite if any
Quoted 6 lines
The dep should be the PR I sent to Brian, but I suspect what's happened here is that the
MAINTAINERSparts of those patches (which I had dropped because they were all conflicting with my tree) didn't get reabsorbed into this series. Very annoying for review of course, even if it's a non-functional conflict. Of course rebase on top of clk-next would've highlighted that to the submitter!
Quoted 2 lines
Yes it was only the
MAINTAINERSfile which I did rebase to check if the rest applied correctly.
In subsequent versions, I will pay attention to conflicts with this file.
Best Regards,
Changhuang