Add System-0 CRG for JHB100 SoC
Subsystems (5)
v3 cover Add System-0 CRG 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
[1]: https://lore.kernel.org/all/[email protected]/
This is a split of the previously sent large series [1]. The original series had too many patches, and there was a lot of similar logic among the patches. To reduce the burden of repeating similar comments and reviews, the original series of patches was split up and a new series was established.
This series is based on the clk-next branch.
changes since v2:
Patch 1:
- Update fixes tag's target commit.
- Add Hal's Acked-by tag.
Patch 2/3/4:
- Add Hal's Acked-by tag.
Patch 5:
- Delete the redundant dev_info.
- Add Philipp's Reviewed-by and Acked-by tags.
- Add Hal's Acked-by tag.
Patch 6:
- Add Philipp's Reviewed-by and Acked-by tags.
- Add Hal's Acked-by tag.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Changhuang Liang (6):
clk: starfive: jh7110-sys: Fix memory leak in reset controller
register
clk: starfive: jh71x0: Move reset controller registration to jh71x0
common code
clk: starfive: jh71x0: Add generic CRG probe helper
clk: starfive: Add JHB100 System-0 clock generator driver
reset: starfive: jh71x0: Support discontiguous reset IDs
reset: starfive: Add StarFive JHB100 System-0 reset driver
MAINTAINERS | 13 ++ drivers/clk/starfive/Kconfig | 12 +- drivers/clk/starfive/Makefile | 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 | 57 +------- .../clk/starfive/clk-starfive-jh7110-vout.c | 2 +- drivers/clk/starfive/clk-starfive-jh7110.h | 4 - drivers/clk/starfive/clk-starfive-jh71x0.c | 116 ++++++++++++++- drivers/clk/starfive/clk-starfive-jh71x0.h | 36 +++++ .../clk/starfive/clk-starfive-jhb100-sys0.c | 137 ++++++++++++++++++ drivers/reset/starfive/Kconfig | 8 + drivers/reset/starfive/Makefile | 1 + .../reset/starfive/reset-starfive-jh7110.c | 19 ++- .../reset/starfive/reset-starfive-jh71x0.c | 58 ++++++++ .../reset/starfive/reset-starfive-jh71x0.h | 24 +++ .../reset/starfive/reset-starfive-jhb100.c | 74 ++++++++++ include/soc/starfive/reset-starfive-jh71x0.h | 12 +- 19 files changed, 496 insertions(+), 85 deletions(-) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys0.c create mode 100644 drivers/reset/starfive/reset-starfive-jhb100.c
base-commit: fd21b9ae59febb9b0d2dfb096a02f316321e5c8b --
2.25.1
PATCH v3 1/6 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 · 1 line
2.25.1
PATCH v3 2/6 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: hand the CRG register base to the reset driver through an auxiliary device.
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.
While at it, replace the open-coded auxiliary device allocation, init, add and release handling with devm_auxiliary_device_create(), which already implements all of it. The register base is now passed to the reset driver as platform data of the auxiliary device, so the embedded auxiliary device and to_jh71x0_reset_adev() go away. As the structure no longer contains an auxiliary device, rename struct jh71x0_reset_adev to struct jh71x0_reset_platform_data.
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.
Since the helper now lives in clk-starfive-jh71x0.c, the auxiliary device names are prefixed with "clk_starfive_jh71x0" instead of "clk_starfive_jh7110_sys". Update the auxiliary_device_id table of the JH7110 reset driver in the same patch to keep the tree bisectable.
--- 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 | 24 ++++++++ drivers/clk/starfive/clk-starfive-jh71x0.h | 2 + .../reset/starfive/reset-starfive-jh7110.c | 19 +++--- include/soc/starfive/reset-starfive-jh71x0.h | 12 ++-- 11 files changed, 46 insertions(+), 84 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
@@ -119,7 +119,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
@@ -178,7 +178,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
@@ -138,7 +138,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
@@ -187,7 +187,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 +24 -0
@@ -5,10 +5,12 @@* Copyright (C) 2021-2022 Emil Renner Berthing <[email protected]> */ +#include <linux/auxiliary_bus.h> #include <linux/clk-provider.h> #include <linux/debugfs.h> #include <linux/device.h> #include <linux/io.h> +#include <soc/starfive/reset-starfive-jh71x0.h> #include "clk-starfive-jh71x0.h"
@@ -337,3 +339,25 @@ struct clk_hw *jh71x0_clk_get(struct of_phandle_args *clkspec, void *data)return ERR_PTR (-EINVAL ); }EXPORT_SYMBOL_GPL (jh71x0_clk_get); + +int jh71x0_reset_controller_register (struct jh71x0_clk_priv *priv, +const char *adev_name) +{ +struct jh71x0_reset_platform_data *pdata; +struct auxiliary_device *adev; + + pdata =devm_kzalloc_obj (priv->dev, *pdata); +if (!pdata) +return -ENOMEM ; + + pdata->base = priv->base; + + adev =devm_auxiliary_device_create (priv->dev, adev_name, pdata); +if (!adev) +return dev_err_probe (priv->dev, -ENODEV , +"failed to create auxiliary device %s\n" , + adev_name); + +return 0 ; +} +EXPORT_SYMBOL_GPL (jh71x0_reset_controller_register);
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
drivers/reset/starfive/reset-starfive-jh7110.c +9 -10
@@ -53,15 +53,14 @@ static int jh7110_reset_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *id) {struct jh7110_reset_info *info = (struct jh7110_reset_info *)(id->driver_data); -struct jh71x0_reset_adev *rdev =to_jh71x0_reset_adev (adev); -void __iomem *base = rdev->base; +struct jh71x0_reset_platform_data *pdata =dev_get_platdata (&adev->dev); -if (!info || !base) +if (!info || !pdata || !pdata->base)return -ENODEV ;return reset_starfive_jh71x0_register (&adev->dev, adev->dev.parent->of_node, - base + info->assert_offset, - base + info->status_offset, + pdata->base + info->assert_offset, + pdata->base + info->status_offset,NULL , info->nr_resets,NULL );
@@ -69,23 +68,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 */ }
include/soc/starfive/reset-starfive-jh71x0.h +5 -7
@@ -2,16 +2,14 @@#ifndef __SOC_STARFIVE_RESET_JH71X0_H#define __SOC_STARFIVE_RESET_JH71X0_H -#include <linux/auxiliary_bus.h> #include <linux/compiler_types.h> -#include <linux/container_of.h> -struct jh71x0_reset_adev { +/* +* Platform data handed to the reset auxiliary device created by the +* StarFive JH71X0 clock drivers. +*/ +struct jh71x0_reset_platform_data {void __iomem *base; -struct auxiliary_device adev; }; -#define to_jh71x0_reset_adev (_adev) \ - container_of((_adev), struct jh71x0_reset_adev, adev) -#endif
Signature · 1 line
2.25.1
PATCH v3 3/6 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 and reset auxiliary device name. The reset auxiliary device is registered with jh71x0_reset_controller_register().
The clock table is made of struct jh71x0_crg_clk_data entries, where each parent is described by a struct jh71x0_parent_data: either the name of an external clock or the index of another clock of the CRG. This way the external clocks need no index of their own, and the number of clocks a CRG can provide is not limited by the width of a parent index. The existing JH71X0_GATE(), JH71X0__DIV(), ... macros can be used to fill the table.
The JH7100 and JH7110 drivers keep their own probe functions and the index based struct jh71x0_clk_data for now.
The clock index space of these CRGs is sparse, so reject parents that refer to an index that is not registered, and also make jh71x0_clk_get() reject such indexes when the domain info is available.
--- drivers/clk/starfive/clk-starfive-jh71x0.c | 92 +++++++++++++++++++++- drivers/clk/starfive/clk-starfive-jh71x0.h | 34 ++++++++ 2 files changed, 123 insertions(+), 3 deletions(-)
drivers/clk/starfive/clk-starfive-jh71x0.c +89 -3
@@ -10,6 +10,7 @@#include <linux/debugfs.h> #include <linux/device.h> #include <linux/io.h> +#include <linux/property.h> #include <soc/starfive/reset-starfive-jh71x0.h> #include "clk-starfive-jh71x0.h"
@@ -333,10 +334,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);
@@ -361,3 +366,84 @@ int jh71x0_reset_controller_register(struct jh71x0_clk_priv *priv,return 0 ; }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_flex (&pdev->dev, *priv, reg, info->num_clk); +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); + +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++) { +const struct jh71x0_parent_data *parent = + &info->clk_data[idx].parents[i]; + +if (parent->fw_name) { + parents[i].fw_name = parent->fw_name; +continue ; + } + +if (parent->idx >= info->num_clk || + !info->clk_data[parent->idx].name) +return dev_err_probe (priv->dev, -EINVAL , +"clock %s: invalid parent index %u\n" , + init.name, parent->idx); + + parents[i].hw = &priv->reg[parent->idx].hw; + } + + 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 +34 -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 */
@@ -29,6 +30,31 @@ struct jh71x0_clk_data {u8 parents[4 ]; }; +/* +* Parent of a clock registered by jh71x0_crg_probe(): either an external clock +* of the CRG, looked up by its name in the "clock-names" property, or another +* clock provided by the CRG itself. +*/ +struct jh71x0_parent_data { +const char *fw_name;/* external clock if not NULL */ +unsigned int idx;/* index of a clock of this CRG */ +}; + +#define JH71X0_EXT_PARENT (_fw_name) { .fw_name = _fw_name } +#define JH71X0_INT_PARENT (_idx) { .idx = _idx } + +/* +* Clock data for jh71x0_crg_probe(). The JH71X0_GATE(), JH71X0__DIV(), ... +* macros below can be used to fill it, with the parents described by +* JH71X0_EXT_PARENT() or JH71X0_INT_PARENT(). +*/ +struct jh71x0_crg_clk_data { +const char *name; +unsigned long flags; +u32 max; +struct jh71x0_parent_data parents[4 ]; +}; +#define JH71X0_GATE (_idx, _name, _flags, _parent) \ [_idx] = { \ .name = _name, \
@@ -109,6 +135,12 @@ struct jh71x0_clk {unsigned int max_div; }; +struct jh71x0_crg_domain_info { +const struct jh71x0_crg_clk_data *clk_data; +unsigned int num_clk; +const char *rst_name; +}; +struct jh71x0_clk_priv {/* protect clk enable and set rate/parent from happening at the same time */ spinlock_t rmw_lock;
@@ -116,6 +148,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 +158,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 · 1 line
2.25.1
PATCH v3 4/6 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 | 137 ++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 drivers/clk/starfive/clk-starfive-jhb100-sys0.c
MAINTAINERS +7 -0
@@ -26921,6 +26921,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: Supported
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 + imply RESET_STARFIVE_JHB100 + 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 +137 -0
137 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 5/6 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 such controllers, a table of hardware reset lines indexed by reset ID. Add reset_starfive_jh71x0_register_with_info() to register a controller described this way.
If a map is provided, install a custom fwnode_xlate callback that translates the reset ID of the reset specifier to the hardware reset line. The translation is thus done once when a reset control is requested, and the reset operations are left untouched since they only ever see hardware reset lines.
Existing users of reset_starfive_jh71x0_register() are unaffected.
--- .../reset/starfive/reset-starfive-jh71x0.c | 58 +++++++++++++++++++ .../reset/starfive/reset-starfive-jh71x0.h | 24 ++++++++ 2 files changed, 82 insertions(+)
drivers/reset/starfive/reset-starfive-jh71x0.c +58 -0
@@ -7,6 +7,7 @@#include <linux/bitmap.h> #include <linux/device.h> +#include <linux/fwnode.h> #include <linux/io.h> #include <linux/iopoll.h> #include <linux/reset-controller.h>
@@ -21,6 +22,8 @@ struct jh71x0_reset {void __iomem *assert;void __iomem *status;const u32 *asserted; +/* optional hardware reset lines indexed by reset ID, rcdev.nr_resets entries */ +const unsigned int *map; }; static inline struct jh71x0_reset *
@@ -29,6 +32,23 @@ jh71x0_reset_from(struct reset_controller_dev *rcdev) return container_of(rcdev, struct jh71x0_reset, rcdev); } +/* +* Translate the reset ID of a reset specifier to the hardware reset line once, +* when the reset control is requested, so that the reset operations only ever +* see hardware reset lines. +*/ +static int jh71x0_reset_fwnode_xlate (struct reset_controller_dev *rcdev, +const struct fwnode_reference_args *reset_spec) +{ +struct jh71x0_reset *data =jh71x0_reset_from (rcdev); +unsigned int id = reset_spec->args[0 ]; + +if (id >= rcdev->nr_resets) +return -EINVAL ; + +return data->map[id]; +} +static int jh71x0_reset_update (struct reset_controller_dev *rcdev,unsigned long id,bool assert) {
@@ -132,3 +152,41 @@ 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; + + data =devm_kzalloc_obj (dev, *data); +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; + +if (info->map) { + data->map = info->map; + data->rcdev.fwnode_xlate = jh71x0_reset_fwnode_xlate; + data->rcdev.fwnode_reset_n_cells =1 ; + } + +spin_lock_init (&data->lock); + data->assert = assert; + data->status = status; + data->asserted = asserted; + + ret =devm_reset_controller_register (dev, &data->rcdev); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to register reset controller\n" ); + +return 0 ; +} +EXPORT_SYMBOL_GPL (reset_starfive_jh71x0_register_with_info);
drivers/reset/starfive/reset-starfive-jh71x0.h +24 -0
@@ -6,9 +6,33 @@#ifndef __RESET_STARFIVE_JH71X0_H#define __RESET_STARFIVE_JH71X0_H +/** +* struct jh71x0_reset_info - description of a reset controller +* @nr_resets: number of resets, which is the number of @map entries if @map +* is set +* @assert_offset: offset of the first assert register +* @status_offset: offset of the first status register +* @map: optional table of hardware reset lines, i.e. bit numbers in the +* assert/status registers, indexed by reset ID, for controllers whose +* reset IDs do not map one-to-one to the hardware reset lines; NULL if +* the reset ID is the hardware reset line +*/ +struct jh71x0_reset_info { +unsigned int nr_resets; +unsigned int assert_offset; +unsigned int status_offset; +const unsigned int *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 · 1 line
2.25.1
PATCH v3 6/6 reset: starfive: Add StarFive JHB100 System-0 reset driver
In reply to Changhuang LiangAdd the auxiliary reset driver for the StarFive JHB100 SoC. It binds to the auxiliary devices registered by the JHB100 clock generator drivers and uses the register base handed over as platform data.
Start with the System-0 clock and reset generator (SYS0CRG). Its reset IDs do not map one-to-one to the hardware reset bits, so the controller is registered with a reset ID map.
The other JHB100 reset controllers are added by follow-up patches, each right after the clock driver of the same CRG.
--- MAINTAINERS | 6 ++ drivers/reset/starfive/Kconfig | 8 ++ drivers/reset/starfive/Makefile | 1 + .../reset/starfive/reset-starfive-jhb100.c | 74 +++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 drivers/reset/starfive/reset-starfive-jhb100.c
MAINTAINERS +6 -0
@@ -26942,6 +26942,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 +8 -0
@@ -19,3 +19,11 @@ 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 ARCH_STARFIVE || COMPILE_TEST + select AUXILIARY_BUS + select RESET_STARFIVE_JH71X0 + 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 +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.25.1