* [PATCH v2 0/6] Add System-0 CRG for JHB100 SoC
@ 2026-11-18 10:05 Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 1/6] clk: starfive: jh7110-sys: Fix memory leak in reset controller register Changhuang Liang
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Changhuang Liang @ 2026-11-18 10:05 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Stephen Boyd, Philipp Zabel,
Emil Renner Berthing
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-clk,
linux-kernel, linux-riscv, Hal Feng, Changhuang Liang
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/20261008123338.11081-1-changhuang.liang@starfivetech.com/
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 v1:
patch 2:
- Rename struct jh71x0_reset_adev to struct jh71x0_reset_platform_data
- Use devm_kzalloc_obj() to allocate the platform data.
- Add Acked-by from Philipp Zabel.
patch 3:
- Describe each clock parent with a struct jh71x0_parent_data. The clock
table is now made of struct jh71x0_crg_clk_data entries, filled with
JH71X0_EXT_PARENT() and JH71X0_INT_PARENT().
- Drop JH71X0_EXT_CLK_FLAG, JH71X0_EXT_CLK() and the ext_clk/num_ext_clk
members of struct jh71x0_crg_domain_info.
- Use devm_kzalloc_flex() to allocate the private data.
patch 4:
- Describe the parents with JH71X0_EXT_PARENT() and JH71X0_INT_PARENT().
- Drop the external clock name table and the static_assert() on the
size of the clock table.
patch 5:
- Translate the reset ID to the hardware reset line once, in a custom
fwnode_xlate callback.
- Index the map by reset ID and make it a plain array of hardware reset
lines. Drop struct jh71x0_reset_map.
- Drop jh71x0_reset_info::discontiguous, JH71X0_RESET_ID_INVALID and
jh71x0_reset::info. A non-NULL map already tells that the controller
needs the translation.
- Use devm_kzalloc_obj() to allocate the reset data.
patch 6 (in v2):
- Index the reset map by reset ID and drop .discontiguous.
- Depend on ARCH_STARFIVE || COMPILE_TEST instead of CLK_STARFIVE_JH71X0
and drop "default ARCH_STARFIVE", the clock driver implies this driver.
- Use struct jh71x0_reset_platform_data.
v1: https://lore.kernel.org/all/20261013102707.9207-1-changhuang.liang@starfivetech.com/
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 | 60 ++++++++
.../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, 498 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: 59841a2d8757b951e8d93f92ffdfaa8c9503435f
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/6] clk: starfive: jh7110-sys: Fix memory leak in reset controller register
2026-11-18 10:05 [PATCH v2 0/6] Add System-0 CRG for JHB100 SoC Changhuang Liang
@ 2026-11-18 10:05 ` Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 2/6] clk: starfive: jh71x0: Move reset controller registration to jh71x0 common code Changhuang Liang
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Changhuang Liang @ 2026-11-18 10:05 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Stephen Boyd, Philipp Zabel,
Emil Renner Berthing
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-clk,
linux-kernel, linux-riscv, Hal Feng, Changhuang Liang
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.
Fixes: edab7204afe5 ("clk: starfive: Add StarFive JH7110 system clock driver")
Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
drivers/clk/starfive/clk-starfive-jh7110-sys.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
index 44766b094b60..c938c62a863a 100644
--- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c
+++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
@@ -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) {
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 2/6] clk: starfive: jh71x0: Move reset controller registration to jh71x0 common code
2026-11-18 10:05 [PATCH v2 0/6] Add System-0 CRG for JHB100 SoC Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 1/6] clk: starfive: jh7110-sys: Fix memory leak in reset controller register Changhuang Liang
@ 2026-11-18 10:05 ` Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 3/6] clk: starfive: jh71x0: Add generic CRG probe helper Changhuang Liang
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Changhuang Liang @ 2026-11-18 10:05 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Stephen Boyd, Philipp Zabel,
Emil Renner Berthing
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-clk,
linux-kernel, linux-riscv, Hal Feng, Changhuang Liang
jh7110_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.
Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
---
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(-)
diff --git a/drivers/clk/starfive/Kconfig b/drivers/clk/starfive/Kconfig
index bd29358ffeec..51716655554f 100644
--- a/drivers/clk/starfive/Kconfig
+++ b/drivers/clk/starfive/Kconfig
@@ -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
diff --git a/drivers/clk/starfive/clk-starfive-jh7110-aon.c b/drivers/clk/starfive/clk-starfive-jh7110-aon.c
index fc8a4e78d5d9..107a81f602a5 100644
--- a/drivers/clk/starfive/clk-starfive-jh7110-aon.c
+++ b/drivers/clk/starfive/clk-starfive-jh7110-aon.c
@@ -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[] = {
diff --git a/drivers/clk/starfive/clk-starfive-jh7110-isp.c b/drivers/clk/starfive/clk-starfive-jh7110-isp.c
index d39ce4a2a8e9..ffc28c466d9b 100644
--- a/drivers/clk/starfive/clk-starfive-jh7110-isp.c
+++ b/drivers/clk/starfive/clk-starfive-jh7110-isp.c
@@ -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;
diff --git a/drivers/clk/starfive/clk-starfive-jh7110-stg.c b/drivers/clk/starfive/clk-starfive-jh7110-stg.c
index 1c11966203ad..5c2638833242 100644
--- a/drivers/clk/starfive/clk-starfive-jh7110-stg.c
+++ b/drivers/clk/starfive/clk-starfive-jh7110-stg.c
@@ -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[] = {
diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
index c938c62a863a..611d58cb6d88 100644
--- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c
+++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
@@ -6,15 +6,11 @@
* Copyright (C) 2022 StarFive Technology Co., Ltd.
*/
-#include <linux/auxiliary_bus.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/platform_device.h>
-#include <linux/slab.h>
-
-#include <soc/starfive/reset-starfive-jh71x0.h>
#include <dt-bindings/clock/starfive,jh7110-crg.h>
@@ -323,59 +319,6 @@ static const struct jh71x0_clk_data jh7110_sysclk_data[] __initconst = {
JH7110_SYSCLK_OSC),
};
-static void jh7110_reset_unregister_adev(void *_adev)
-{
- struct auxiliary_device *adev = _adev;
-
- auxiliary_device_delete(adev);
- auxiliary_device_uninit(adev);
-}
-
-static void jh7110_reset_adev_release(struct device *dev)
-{
- struct auxiliary_device *adev = to_auxiliary_dev(dev);
- struct jh71x0_reset_adev *rdev = to_jh71x0_reset_adev(adev);
-
- kfree(rdev);
-}
-
-int jh7110_reset_controller_register(struct jh71x0_clk_priv *priv,
- const char *adev_name,
- u32 adev_id)
-{
- 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 = jh7110_reset_adev_release;
- adev->id = adev_id;
-
- ret = auxiliary_device_init(adev);
- if (ret) {
- kfree(rdev);
- return ret;
- }
-
- ret = auxiliary_device_add(adev);
- if (ret) {
- auxiliary_device_uninit(adev);
- return ret;
- }
-
- return devm_add_action_or_reset(priv->dev,
- jh7110_reset_unregister_adev, adev);
-}
-EXPORT_SYMBOL_GPL(jh7110_reset_controller_register);
-
/*
* This clock notifier is called when the rate of PLL0 clock is to be changed.
* The cpu_root clock should save the current parent clock and switch its parent
@@ -523,7 +466,7 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev)
if (ret)
return ret;
- return jh7110_reset_controller_register(priv, "rst-sys", 0);
+ return jh71x0_reset_controller_register(priv, "rst-sys");
}
static const struct of_device_id jh7110_syscrg_match[] = {
diff --git a/drivers/clk/starfive/clk-starfive-jh7110-vout.c b/drivers/clk/starfive/clk-starfive-jh7110-vout.c
index d4181cce9c15..c3acf3f4cb46 100644
--- a/drivers/clk/starfive/clk-starfive-jh7110-vout.c
+++ b/drivers/clk/starfive/clk-starfive-jh7110-vout.c
@@ -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;
diff --git a/drivers/clk/starfive/clk-starfive-jh7110.h b/drivers/clk/starfive/clk-starfive-jh7110.h
index 0659adae4d76..55374ee24d4d 100644
--- a/drivers/clk/starfive/clk-starfive-jh7110.h
+++ b/drivers/clk/starfive/clk-starfive-jh7110.h
@@ -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
diff --git a/drivers/clk/starfive/clk-starfive-jh71x0.c b/drivers/clk/starfive/clk-starfive-jh71x0.c
index 2d1713c1693b..db8c3571ea5e 100644
--- a/drivers/clk/starfive/clk-starfive-jh71x0.c
+++ b/drivers/clk/starfive/clk-starfive-jh71x0.c
@@ -5,10 +5,12 @@
* Copyright (C) 2021-2022 Emil Renner Berthing <kernel@esmil.dk>
*/
+#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);
diff --git a/drivers/clk/starfive/clk-starfive-jh71x0.h b/drivers/clk/starfive/clk-starfive-jh71x0.h
index 9d5dec1d5cd1..322a05157faf 100644
--- a/drivers/clk/starfive/clk-starfive-jh71x0.h
+++ b/drivers/clk/starfive/clk-starfive-jh71x0.h
@@ -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
diff --git a/drivers/reset/starfive/reset-starfive-jh7110.c b/drivers/reset/starfive/reset-starfive-jh7110.c
index 29a43f0f2ad6..a4e733432766 100644
--- a/drivers/reset/starfive/reset-starfive-jh7110.c
+++ b/drivers/reset/starfive/reset-starfive-jh7110.c
@@ -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 */ }
diff --git a/include/soc/starfive/reset-starfive-jh71x0.h b/include/soc/starfive/reset-starfive-jh71x0.h
index 47b486ececc5..59ebe57eb5e8 100644
--- a/include/soc/starfive/reset-starfive-jh71x0.h
+++ b/include/soc/starfive/reset-starfive-jh71x0.h
@@ -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
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 3/6] clk: starfive: jh71x0: Add generic CRG probe helper
2026-11-18 10:05 [PATCH v2 0/6] Add System-0 CRG for JHB100 SoC Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 1/6] clk: starfive: jh7110-sys: Fix memory leak in reset controller register Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 2/6] clk: starfive: jh71x0: Move reset controller registration to jh71x0 common code Changhuang Liang
@ 2026-11-18 10:05 ` Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 4/6] clk: starfive: Add JHB100 System-0 clock generator driver Changhuang Liang
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Changhuang Liang @ 2026-11-18 10:05 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Stephen Boyd, Philipp Zabel,
Emil Renner Berthing
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-clk,
linux-kernel, linux-riscv, Hal Feng, Changhuang Liang
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 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.
Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
drivers/clk/starfive/clk-starfive-jh71x0.c | 92 +++++++++++++++++++++-
drivers/clk/starfive/clk-starfive-jh71x0.h | 34 ++++++++
2 files changed, 123 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/starfive/clk-starfive-jh71x0.c b/drivers/clk/starfive/clk-starfive-jh71x0.c
index db8c3571ea5e..97f8782df211 100644
--- a/drivers/clk/starfive/clk-starfive-jh71x0.c
+++ b/drivers/clk/starfive/clk-starfive-jh71x0.c
@@ -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);
diff --git a/drivers/clk/starfive/clk-starfive-jh71x0.h b/drivers/clk/starfive/clk-starfive-jh71x0.h
index 322a05157faf..775c1012a889 100644
--- a/drivers/clk/starfive/clk-starfive-jh71x0.h
+++ b/drivers/clk/starfive/clk-starfive-jh71x0.h
@@ -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
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 4/6] clk: starfive: Add JHB100 System-0 clock generator driver
2026-11-18 10:05 [PATCH v2 0/6] Add System-0 CRG for JHB100 SoC Changhuang Liang
` (2 preceding siblings ...)
2026-11-18 10:05 ` [PATCH v2 3/6] clk: starfive: jh71x0: Add generic CRG probe helper Changhuang Liang
@ 2026-11-18 10:05 ` Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 5/6] reset: starfive: jh71x0: Support discontiguous reset IDs Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 6/6] reset: starfive: Add StarFive JHB100 System-0 reset driver Changhuang Liang
5 siblings, 0 replies; 9+ messages in thread
From: Changhuang Liang @ 2026-11-18 10:05 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Stephen Boyd, Philipp Zabel,
Emil Renner Berthing
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-clk,
linux-kernel, linux-riscv, Hal Feng, Changhuang Liang
Add support for JHB100 System-0 clock generator (SYS0CRG).
Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
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
diff --git a/MAINTAINERS b/MAINTAINERS
index 36461742efb2..a891c9046eca 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -26907,6 +26907,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 <changhuang.liang@starfivetech.com>
+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 <changhuang.liang@starfivetech.com>
S: Supported
diff --git a/drivers/clk/starfive/Kconfig b/drivers/clk/starfive/Kconfig
index 51716655554f..cb246ae12c08 100644
--- a/drivers/clk/starfive/Kconfig
+++ b/drivers/clk/starfive/Kconfig
@@ -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.
diff --git a/drivers/clk/starfive/Makefile b/drivers/clk/starfive/Makefile
index 199ac0f37a2f..d2ba83d7d02c 100644
--- a/drivers/clk/starfive/Makefile
+++ b/drivers/clk/starfive/Makefile
@@ -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
diff --git a/drivers/clk/starfive/clk-starfive-jhb100-sys0.c b/drivers/clk/starfive/clk-starfive-jhb100-sys0.c
new file mode 100644
index 000000000000..74bcc6ffb177
--- /dev/null
+++ b/drivers/clk/starfive/clk-starfive-jhb100-sys0.c
@@ -0,0 +1,137 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * StarFive JHB100 System-0 Clock Driver
+ *
+ * Copyright (C) 2024 StarFive Technology Co., Ltd.
+ *
+ * Author: Changhuang Liang <changhuang.liang@starfivetech.com>
+ *
+ */
+
+#include <dt-bindings/clock/starfive,jhb100-crg.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+
+#include "clk-starfive-jh71x0.h"
+
+/* external clocks */
+#define JHB100_SYS0CLK_OSC JH71X0_EXT_PARENT("osc")
+#define JHB100_SYS0CLK_PLL0 JH71X0_EXT_PARENT("pll0")
+#define JHB100_SYS0CLK_PLL1 JH71X0_EXT_PARENT("pll1")
+#define JHB100_SYS0CLK_PLL2 JH71X0_EXT_PARENT("pll2")
+
+static const struct jh71x0_crg_clk_data jhb100_sys0crg_clk_data[] = {
+ /* bmcpcierp */
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPCIERP_NCNOC_MAIN, "bmcpcierp_ncnoc_main", 6,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPCIERP_NCNOC_CFG, "bmcpcierp_ncnoc_cfg", 12,
+ JHB100_SYS0CLK_PLL1),
+ JH71X0__DIV(JHB100_SYS0CLK_PCIE_REF_CML, "pcie_ref_cml", 24,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0_GATE(JHB100_SYS0CLK_BMCPCIERP_NCNOC_DATA_INIT, "bmcpcierp_ncnoc_data_init",
+ 0, JH71X0_INT_PARENT(JHB100_SYS0CLK_BMCPCIERP_NCNOC_MAIN)),
+ JH71X0_GATE(JHB100_SYS0CLK_BMCPCIERP_NCNOC_CFG_INIT, "bmcpcierp_ncnoc_cfg_init",
+ 0, JH71X0_INT_PARENT(JHB100_SYS0CLK_BMCPCIERP_NCNOC_CFG)),
+ JH71X0_GATE(JHB100_SYS0CLK_BMCPCIERP_NCNOC_TARG, "bmcpcierp_ncnoc_targ",
+ 0, JH71X0_INT_PARENT(JHB100_SYS0CLK_BMCPCIERP_NCNOC_MAIN)),
+ JH71X0_GATE(JHB100_SYS0CLK_BMCPCIERP_PCU, "bmcpcierp_pcu", 0, JHB100_SYS0CLK_OSC),
+ /* hostss0 */
+ JH71X0__DIV(JHB100_SYS0CLK_HOSTSS0_NCNOC_CFG, "hostss0_ncnoc_cfg", 12,
+ JHB100_SYS0CLK_PLL1),
+ JH71X0__DIV(JHB100_SYS0CLK_HOSTSS0_NCNOC_DATA, "hostss0_ncnoc_data", 6,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_HOSTSS0_PHY_SCAN_400, "hostss0_phy_scan_400", 6,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_GPIO_ESPI0_EXT, "gpio_espi0_ext", 14,
+ JHB100_SYS0CLK_PLL2),
+ /* bmcusb */
+ JH71X0__DIV(JHB100_SYS0CLK_BMCUSB_NCNOC_INIT, "bmcusb_ncnoc_init", 6,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_BMCUSB_NCNOC_TARG, "bmcusb_ncnoc_targ", 6,
+ JHB100_SYS0CLK_PLL1),
+ JH71X0__DIV(JHB100_SYS0CLK_BMCUSB_SCANCLK, "bmcusb_scanclk", 5,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0_GATE(JHB100_SYS0CLK_BMCUSB_480M_SCANCLK, "bmcusb_480m_scanclk",
+ 0, JH71X0_INT_PARENT(JHB100_SYS0CLK_BMCUSB_SCANCLK)),
+ /* vce */
+ JH71X0__DIV(JHB100_SYS0CLK_VCE_NCNOC_INIT, "vce_ncnoc_init", 10,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_VCE_NCNOC_TARG, "vce_ncnoc_targ", 12,
+ JHB100_SYS0CLK_PLL1),
+ /* bmcperiph2 */
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPER2_NCNOC_INIT, "bmcper2_ncnoc_init", 6,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPER2_NCNOC_TARG, "bmcper2_ncnoc_targ", 12,
+ JHB100_SYS0CLK_PLL1),
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPER2_CFG_400, "bmcper2_cfg_400", 8,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPER2_CFG_125, "bmcper2_cfg_125", 10,
+ JHB100_SYS0CLK_PLL1),
+ /* hostss1 */
+ JH71X0__DIV(JHB100_SYS0CLK_HOSTSS1_NCNOC_DATA, "hostss1_ncnoc_data", 6,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_HOSTSS1_PHY_SCAN_400, "hostss1_phy_scan_400", 6,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0_GATE(JHB100_SYS0CLK_HOSTSS1_PHY_SCAN_400_ICG_BUF,
+ "hostss1_phy_scan_400_icg_buf", 0,
+ JH71X0_INT_PARENT(JHB100_SYS0CLK_HOSTSS1_PHY_SCAN_400)),
+ /* npu */
+ JH71X0__DIV(JHB100_SYS0CLK_NPU_NCNOC_INIT, "npu_ncnoc_init", 6,
+ JHB100_SYS0CLK_PLL0),
+ /* vout */
+ JH71X0__DIV(JHB100_SYS0CLK_VOUT_NCNOC_INIT, "vout_ncnoc_init", 6,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_VOUT_AUX, "vout_aux", 150,
+ JHB100_SYS0CLK_PLL0),
+ /* bmcperiph3 */
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPER3_NCNOC_INIT, "bmcper3_ncnoc_init", 6,
+ JHB100_SYS0CLK_PLL0),
+ /* hostusb */
+ JH71X0__DIV(JHB100_SYS0CLK_HOSTUSB_NCNOC_INIT, "hostusb_ncnoc_init", 6,
+ JHB100_SYS0CLK_PLL0),
+ /* hostusbcmn */
+ JH71X0__DIV(JHB100_SYS0CLK_HOSTUSBCMN_CFG_480, "hostusbcmn_cfg_480", 5,
+ JHB100_SYS0CLK_PLL0),
+ /* bmcperiph1 */
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPER1_NCNOC_INIT, "bmcper1_ncnoc_init", 6,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPER1_CFG_800, "bmcper1_cfg_800", 4,
+ JHB100_SYS0CLK_PLL0),
+ /* bmcperiph0 */
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPER0_NCNOC_INIT, "bmcper0_ncnoc_init", 6,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPER0_CFG_400, "bmcper0_cfg_400", 8,
+ JHB100_SYS0CLK_PLL0),
+ JH71X0__DIV(JHB100_SYS0CLK_BMCPER0_CFG_800, "bmcper0_cfg_800", 8,
+ JHB100_SYS0CLK_PLL0),
+ /* gpu0 */
+ JH71X0__DIV(JHB100_SYS0CLK_GPU0_NCNOC_INIT, "gpu0_ncnoc_init", 10,
+ JHB100_SYS0CLK_PLL0),
+ /* gpu1 */
+ JH71X0__DIV(JHB100_SYS0CLK_GPU1_NCNOC_INIT, "gpu1_ncnoc_init", 10,
+ JHB100_SYS0CLK_PLL0),
+};
+
+static const struct jh71x0_crg_domain_info jhb100_sys0crg_info = {
+ .clk_data = jhb100_sys0crg_clk_data,
+ .num_clk = ARRAY_SIZE(jhb100_sys0crg_clk_data),
+ .rst_name = "jhb100-r-sys0",
+};
+
+static const struct of_device_id jhb100_sys0crg_match[] = {
+ {
+ .compatible = "starfive,jhb100-sys0crg",
+ .data = &jhb100_sys0crg_info,
+ },
+ { /* sentinel */ }
+};
+
+static struct platform_driver jhb100_sys0crg_driver = {
+ .probe = jh71x0_crg_probe,
+ .driver = {
+ .name = "clk-starfive-jhb100-sys0",
+ .of_match_table = jhb100_sys0crg_match,
+ .suppress_bind_attrs = true,
+ },
+};
+builtin_platform_driver(jhb100_sys0crg_driver);
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 5/6] reset: starfive: jh71x0: Support discontiguous reset IDs
2026-11-18 10:05 [PATCH v2 0/6] Add System-0 CRG for JHB100 SoC Changhuang Liang
` (3 preceding siblings ...)
2026-11-18 10:05 ` [PATCH v2 4/6] clk: starfive: Add JHB100 System-0 clock generator driver Changhuang Liang
@ 2026-11-18 10:05 ` Changhuang Liang
2026-11-18 10:39 ` Philipp Zabel
2026-11-18 10:05 ` [PATCH v2 6/6] reset: starfive: Add StarFive JHB100 System-0 reset driver Changhuang Liang
5 siblings, 1 reply; 9+ messages in thread
From: Changhuang Liang @ 2026-11-18 10:05 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Stephen Boyd, Philipp Zabel,
Emil Renner Berthing
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-clk,
linux-kernel, linux-riscv, Hal Feng, 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 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.
Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
.../reset/starfive/reset-starfive-jh71x0.c | 60 +++++++++++++++++++
.../reset/starfive/reset-starfive-jh71x0.h | 24 ++++++++
2 files changed, 84 insertions(+)
diff --git a/drivers/reset/starfive/reset-starfive-jh71x0.c b/drivers/reset/starfive/reset-starfive-jh71x0.c
index d410a5a0ded4..5c64d47fb530 100644
--- a/drivers/reset/starfive/reset-starfive-jh71x0.c
+++ b/drivers/reset/starfive/reset-starfive-jh71x0.c
@@ -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,43 @@ int reset_starfive_jh71x0_register(struct device *dev, struct device_node *of_no
return 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");
+
+ dev_info(dev, "Registered %u resets\n", data->rcdev.nr_resets);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(reset_starfive_jh71x0_register_with_info);
diff --git a/drivers/reset/starfive/reset-starfive-jh71x0.h b/drivers/reset/starfive/reset-starfive-jh71x0.h
index db7d39a87f87..918ecec3975e 100644
--- a/drivers/reset/starfive/reset-starfive-jh71x0.h
+++ b/drivers/reset/starfive/reset-starfive-jh71x0.h
@@ -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 */
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 6/6] reset: starfive: Add StarFive JHB100 System-0 reset driver
2026-11-18 10:05 [PATCH v2 0/6] Add System-0 CRG for JHB100 SoC Changhuang Liang
` (4 preceding siblings ...)
2026-11-18 10:05 ` [PATCH v2 5/6] reset: starfive: jh71x0: Support discontiguous reset IDs Changhuang Liang
@ 2026-11-18 10:05 ` Changhuang Liang
2026-11-18 10:39 ` Philipp Zabel
5 siblings, 1 reply; 9+ messages in thread
From: Changhuang Liang @ 2026-11-18 10:05 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Stephen Boyd, Philipp Zabel,
Emil Renner Berthing
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-clk,
linux-kernel, linux-riscv, Hal Feng, Changhuang Liang
Add 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.
Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
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
diff --git a/MAINTAINERS b/MAINTAINERS
index a891c9046eca..a77f5049ff55 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -26928,6 +26928,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 <changhuang.liang@starfivetech.com>
+S: Supported
+F: drivers/reset/starfive/reset-starfive-jhb1*
+F: include/dt-bindings/reset/starfive,jhb1*.h
+
STATIC BRANCH/CALL
M: Peter Zijlstra <peterz@infradead.org>
M: Josh Poimboeuf <jpoimboe@kernel.org>
diff --git a/drivers/reset/starfive/Kconfig b/drivers/reset/starfive/Kconfig
index d832339f61bc..d1833f1ee719 100644
--- a/drivers/reset/starfive/Kconfig
+++ b/drivers/reset/starfive/Kconfig
@@ -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.
diff --git a/drivers/reset/starfive/Makefile b/drivers/reset/starfive/Makefile
index 7a44b66fb9d5..d781103355d3 100644
--- a/drivers/reset/starfive/Makefile
+++ b/drivers/reset/starfive/Makefile
@@ -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
diff --git a/drivers/reset/starfive/reset-starfive-jhb100.c b/drivers/reset/starfive/reset-starfive-jhb100.c
new file mode 100644
index 000000000000..883f67ff1fa6
--- /dev/null
+++ b/drivers/reset/starfive/reset-starfive-jhb100.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Reset driver for the StarFive JHB100 SoC
+ *
+ * Copyright (C) 2024 StarFive Technology Co., Ltd.
+ *
+ * Author: Changhuang Liang <changhuang.liang@starfivetech.com>
+ */
+
+#include <dt-bindings/reset/starfive,jhb100-crg.h>
+#include <linux/auxiliary_bus.h>
+#include <soc/starfive/reset-starfive-jh71x0.h>
+
+#include "reset-starfive-jh71x0.h"
+
+static const unsigned int jhb100_sys0_map[] = {
+ [JHB100_SYS0RST_RESOURCE_ARB] = 0,
+ [JHB100_SYS0RST_SYS0_IOMUX_PRESETN] = 3,
+ [JHB100_SYS0RST_SYS0H_IOMUX_PRESETN] = 4,
+ [JHB100_SYS0RST_RST_ADAPTOR_TIMEOUT_RSTN] = 5,
+ [JHB100_SYS0RST_BMCPCIERP_RSTN_BUS] = 14,
+ [JHB100_SYS0RST_BMCPCIERP_RSTN_CRG] = 15,
+ [JHB100_SYS0RST_HOSTSS0_RSTN_BUS_ESPI] = 16,
+ [JHB100_SYS0RST_HOSTSS0_RSTN_BUS_PCIE] = 17,
+ [JHB100_SYS0RST_HOSTSS0_RSTN_CRG] = 18,
+ [JHB100_SYS0RST_BMCPERIPH2_RSTN_CRG] = 19,
+ [JHB100_SYS0RST_BMCPERIPH2_RSTN_BUS] = 20,
+ [JHB100_SYS0RST_VCE_RSTN_CRG] = 21,
+ [JHB100_SYS0RST_VCE_RSTN_BUS] = 22,
+ [JHB100_SYS0RST_BMCUSB_RSTN_BUS] = 23,
+ [JHB100_SYS0RST_BMCUSB_RSTN_CRG] = 24,
+};
+
+static const struct jh71x0_reset_info jhb100_sys0_info = {
+ .nr_resets = ARRAY_SIZE(jhb100_sys0_map),
+ .assert_offset = 0x12c,
+ .status_offset = 0x130,
+ .map = jhb100_sys0_map,
+};
+
+static int jhb100_reset_probe(struct auxiliary_device *adev,
+ const struct auxiliary_device_id *id)
+{
+ const struct jh71x0_reset_info *info =
+ (const struct jh71x0_reset_info *)(id->driver_data);
+ struct jh71x0_reset_platform_data *pdata = dev_get_platdata(&adev->dev);
+
+ if (!info || !pdata || !pdata->base)
+ return -ENODEV;
+
+ return reset_starfive_jh71x0_register_with_info(&adev->dev, adev->dev.parent->of_node,
+ pdata->base + info->assert_offset,
+ pdata->base + info->status_offset,
+ NULL, info, NULL);
+}
+
+static const struct auxiliary_device_id jhb100_reset_ids[] = {
+ {
+ .name = "clk_starfive_jh71x0.jhb100-r-sys0",
+ .driver_data = (kernel_ulong_t)&jhb100_sys0_info,
+ },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(auxiliary, jhb100_reset_ids);
+
+static struct auxiliary_driver jhb100_reset_driver = {
+ .probe = jhb100_reset_probe,
+ .id_table = jhb100_reset_ids,
+};
+module_auxiliary_driver(jhb100_reset_driver);
+
+MODULE_AUTHOR("Changhuang Liang <changhuang.liang@starfivetech.com>");
+MODULE_DESCRIPTION("StarFive JHB100 reset driver");
+MODULE_LICENSE("GPL");
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 5/6] reset: starfive: jh71x0: Support discontiguous reset IDs
2026-11-18 10:05 ` [PATCH v2 5/6] reset: starfive: jh71x0: Support discontiguous reset IDs Changhuang Liang
@ 2026-11-18 10:39 ` Philipp Zabel
0 siblings, 0 replies; 9+ messages in thread
From: Philipp Zabel @ 2026-11-18 10:39 UTC (permalink / raw)
To: Changhuang Liang, Brian Masney, Jerome Brunet, Stephen Boyd,
Emil Renner Berthing
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-clk,
linux-kernel, linux-riscv, Hal Feng
On Mi, 2026-11-18 at 02:05 -0800, Changhuang Liang wrote:
> 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 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.
>
> Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
> ---
> .../reset/starfive/reset-starfive-jh71x0.c | 60 +++++++++++++++++++
> .../reset/starfive/reset-starfive-jh71x0.h | 24 ++++++++
> 2 files changed, 84 insertions(+)
>
> diff --git a/drivers/reset/starfive/reset-starfive-jh71x0.c b/drivers/reset/starfive/reset-starfive-jh71x0.c
> index d410a5a0ded4..5c64d47fb530 100644
> --- a/drivers/reset/starfive/reset-starfive-jh71x0.c
> +++ b/drivers/reset/starfive/reset-starfive-jh71x0.c
[...]
> @@ -132,3 +152,43 @@ int reset_starfive_jh71x0_register(struct device *dev, struct device_node *of_no
> return 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");
> +
> + dev_info(dev, "Registered %u resets\n", data->rcdev.nr_resets);
Does this really need to be this verbose? Otherwise,
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
regards
Philipp
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 6/6] reset: starfive: Add StarFive JHB100 System-0 reset driver
2026-11-18 10:05 ` [PATCH v2 6/6] reset: starfive: Add StarFive JHB100 System-0 reset driver Changhuang Liang
@ 2026-11-18 10:39 ` Philipp Zabel
0 siblings, 0 replies; 9+ messages in thread
From: Philipp Zabel @ 2026-11-18 10:39 UTC (permalink / raw)
To: Changhuang Liang, Brian Masney, Jerome Brunet, Stephen Boyd,
Emil Renner Berthing
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-clk,
linux-kernel, linux-riscv, Hal Feng
On Mi, 2026-11-18 at 02:05 -0800, Changhuang Liang wrote:
> Add 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.
>
> Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
regards
Philipp
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-18 10:39 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 10:05 [PATCH v2 0/6] Add System-0 CRG for JHB100 SoC Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 1/6] clk: starfive: jh7110-sys: Fix memory leak in reset controller register Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 2/6] clk: starfive: jh71x0: Move reset controller registration to jh71x0 common code Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 3/6] clk: starfive: jh71x0: Add generic CRG probe helper Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 4/6] clk: starfive: Add JHB100 System-0 clock generator driver Changhuang Liang
2026-11-18 10:05 ` [PATCH v2 5/6] reset: starfive: jh71x0: Support discontiguous reset IDs Changhuang Liang
2026-11-18 10:39 ` Philipp Zabel
2026-11-18 10:05 ` [PATCH v2 6/6] reset: starfive: Add StarFive JHB100 System-0 reset driver Changhuang Liang
2026-11-18 10:39 ` Philipp Zabel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®