* [PATCH v2 0/2] Add hwspinlock driver for StarFive JHB100 SoC
@ 2026-05-15 9:53 Xingyu Wu
2026-05-15 9:53 ` [PATCH v2 1/2] dt-bindings: hwlock: Add StarFive JHB100 HW lock Xingyu Wu
2026-05-15 9:53 ` [PATCH v2 2/2] hwspinlock: Add StarFive hwspinlock device Xingyu Wu
0 siblings, 2 replies; 4+ messages in thread
From: Xingyu Wu @ 2026-05-15 9:53 UTC (permalink / raw)
To: Bjorn Andersson, Baolin Wang, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Xingyu Wu, devicetree, linux-kernel, linux-remoteproc
This patch serises are to add hardware spinlock driver for the StarFive
JHB100 SoC. The first patch adds documentation for StarFive Hardware
Spinlock. The subsequent patch adds hwspinlock driver and support JHB100
SoC.
The StarFive hwspinlock supports 16 channels for using by secur core and
AP core to restrict access and protect the memory area.
Changes since v1:
- Simplified the subject.
- Added 'StarFive JHB100' in documentation title.
- Modified the name of example.
- Added the property of 'clocks'.
v1: https://lore.kernel.org/all/20260424032026.62301-1-xingyu.wu@starfivetech.com/
Xingyu Wu (2):
dt-bindings: hwlock: Add StarFive JHB100 HW lock
hwspinlock: Add StarFive hwspinlock device
.../hwlock/starfive,jhb100-hwspinlock.yaml | 43 ++++++
MAINTAINERS | 6 +
drivers/hwspinlock/Kconfig | 8 ++
drivers/hwspinlock/Makefile | 1 +
drivers/hwspinlock/starfive_hwspinlock.c | 130 ++++++++++++++++++
5 files changed, 188 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwlock/starfive,jhb100-hwspinlock.yaml
create mode 100644 drivers/hwspinlock/starfive_hwspinlock.c
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] dt-bindings: hwlock: Add StarFive JHB100 HW lock
2026-05-15 9:53 [PATCH v2 0/2] Add hwspinlock driver for StarFive JHB100 SoC Xingyu Wu
@ 2026-05-15 9:53 ` Xingyu Wu
2026-05-15 17:16 ` Conor Dooley
2026-05-15 9:53 ` [PATCH v2 2/2] hwspinlock: Add StarFive hwspinlock device Xingyu Wu
1 sibling, 1 reply; 4+ messages in thread
From: Xingyu Wu @ 2026-05-15 9:53 UTC (permalink / raw)
To: Bjorn Andersson, Baolin Wang, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Xingyu Wu, devicetree, linux-kernel, linux-remoteproc
Add the new documentation of hardware spinlock for the StarFive JHB100 SoC.
Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com>
---
.../hwlock/starfive,jhb100-hwspinlock.yaml | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwlock/starfive,jhb100-hwspinlock.yaml
diff --git a/Documentation/devicetree/bindings/hwlock/starfive,jhb100-hwspinlock.yaml b/Documentation/devicetree/bindings/hwlock/starfive,jhb100-hwspinlock.yaml
new file mode 100644
index 000000000000..af09aeb072b3
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwlock/starfive,jhb100-hwspinlock.yaml
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwlock/starfive,jhb100-hwspinlock.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: StarFive JHB100 Hardware Spinlock
+
+maintainers:
+ - Xingyu Wu <xingyu.wu@starfivetech.com>
+
+properties:
+ compatible:
+ const: starfive,jhb100-hwspinlock
+
+ reg:
+ maxItems: 1
+
+ clocks:
+ maxItems: 1
+
+ resets:
+ maxItems: 1
+
+ "#hwlock-cells":
+ const: 1
+
+required:
+ - compatible
+ - reg
+ - resets
+ - "#hwlock-cells"
+
+additionalProperties: false
+
+examples:
+ - |
+ hwlock@13012000 {
+ compatible = "starfive,jhb100-hwspinlock";
+ reg = <0x13012000 0x400>;
+ resets = <&sys0crg 0>;
+ #hwlock-cells = <1>;
+ };
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] hwspinlock: Add StarFive hwspinlock device
2026-05-15 9:53 [PATCH v2 0/2] Add hwspinlock driver for StarFive JHB100 SoC Xingyu Wu
2026-05-15 9:53 ` [PATCH v2 1/2] dt-bindings: hwlock: Add StarFive JHB100 HW lock Xingyu Wu
@ 2026-05-15 9:53 ` Xingyu Wu
1 sibling, 0 replies; 4+ messages in thread
From: Xingyu Wu @ 2026-05-15 9:53 UTC (permalink / raw)
To: Bjorn Andersson, Baolin Wang, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Xingyu Wu, devicetree, linux-kernel, linux-remoteproc
Add support of hardware spinlock for the StarFive JHB100 SoC.
The hwspinlock provides 16 channels for using by secur core and AP core.
Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com>
---
MAINTAINERS | 6 ++
drivers/hwspinlock/Kconfig | 8 ++
drivers/hwspinlock/Makefile | 1 +
drivers/hwspinlock/starfive_hwspinlock.c | 130 +++++++++++++++++++++++
4 files changed, 145 insertions(+)
create mode 100644 drivers/hwspinlock/starfive_hwspinlock.c
diff --git a/MAINTAINERS b/MAINTAINERS
index c3fe46d7c4bc..4ff12806ba09 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25275,6 +25275,12 @@ F: Documentation/devicetree/bindings/power/starfive*
F: drivers/pmdomain/starfive/
F: include/dt-bindings/power/starfive,jh7110-pmu.h
+STARFIVE JHB100 HARDWARE SPINLOCK DRIVER
+M: Xingyu Wu <xingyu.wu@starfivetech.com>
+S: Supported
+F: Documentation/devicetree/bindings/hwlock/starfive,jhb100-hwspinlock.yaml
+F: drivers/hwspinlock/starfive_hwspinlock.c
+
STARFIVE SOC DRIVERS
M: Conor Dooley <conor@kernel.org>
S: Maintained
diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
index 3874d15b0e9b..797f5a833547 100644
--- a/drivers/hwspinlock/Kconfig
+++ b/drivers/hwspinlock/Kconfig
@@ -36,6 +36,14 @@ config HWSPINLOCK_SPRD
If unsure, say N.
+config HWSPINLOCK_STARFIVE
+ tristate "StarFive Hardware Spinlock device"
+ depends on ARCH_STARFIVE || COMPILE_TEST
+ help
+ Say y here to support the StarFive Hardware Spinlock device.
+
+ If unsure, say N.
+
config HWSPINLOCK_STM32
tristate "STM32 Hardware Spinlock device"
depends on MACH_STM32MP157 || COMPILE_TEST
diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile
index a0f16c9aaa82..bc713bdc7e04 100644
--- a/drivers/hwspinlock/Makefile
+++ b/drivers/hwspinlock/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_HWSPINLOCK) += hwspinlock_core.o
obj-$(CONFIG_HWSPINLOCK_OMAP) += omap_hwspinlock.o
obj-$(CONFIG_HWSPINLOCK_QCOM) += qcom_hwspinlock.o
obj-$(CONFIG_HWSPINLOCK_SPRD) += sprd_hwspinlock.o
+obj-$(CONFIG_HWSPINLOCK_STARFIVE) += starfive_hwspinlock.o
obj-$(CONFIG_HWSPINLOCK_STM32) += stm32_hwspinlock.o
obj-$(CONFIG_HWSPINLOCK_SUN6I) += sun6i_hwspinlock.o
obj-$(CONFIG_HSEM_U8500) += u8500_hsem.o
diff --git a/drivers/hwspinlock/starfive_hwspinlock.c b/drivers/hwspinlock/starfive_hwspinlock.c
new file mode 100644
index 000000000000..d85f43a48013
--- /dev/null
+++ b/drivers/hwspinlock/starfive_hwspinlock.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Hardware spinlock driver for StarFive JHB100 SoC
+ *
+ * Copyright (C) 2026 StarFive Technology Co., Ltd.
+ */
+
+#include <linux/delay.h>
+#include <linux/hwspinlock.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+
+#include "hwspinlock_internal.h"
+
+/* reg offset */
+#define STARFIVE_REG_APP_LOCK_REQ 0x08
+#define STARFIVE_REG_APP_LOCK_RLS 0x0C
+#define STARFIVE_REG_LOCK_STA 0x10
+
+/* macro STARFIVE_REG_LOCK_STA reg*/
+#define STARFIVE_STA_APP_OWN BIT(1)
+#define STARFIVE_STA_OWN_MSK 0x3
+
+#define STARFIVE_NUM_LOCKS 16
+
+struct starfive_hwspinlock {
+ void __iomem *base;
+ struct reset_control *rst;
+ struct hwspinlock_device bank;
+};
+
+static int starfive_hwspinlock_trylock(struct hwspinlock *lock)
+{
+ struct starfive_hwspinlock *priv = dev_get_drvdata(lock->bank->dev);
+ int id = hwlock_to_id(lock);
+ u32 status;
+
+ writel(BIT(id), priv->base + STARFIVE_REG_APP_LOCK_REQ);
+ status = (readl(priv->base + STARFIVE_REG_LOCK_STA) >> (2 * id)) &
+ STARFIVE_STA_OWN_MSK;
+
+ return (status == STARFIVE_STA_APP_OWN);
+}
+
+static void starfive_hwspinlock_unlock(struct hwspinlock *lock)
+{
+ struct starfive_hwspinlock *priv = dev_get_drvdata(lock->bank->dev);
+ int id = hwlock_to_id(lock);
+
+ writel(BIT(id), priv->base + STARFIVE_REG_APP_LOCK_RLS);
+}
+
+static void starfive_hwspinlock_relax(struct hwspinlock *lock)
+{
+ ndelay(50);
+}
+
+static const struct hwspinlock_ops starfive_hwspinlock_ops = {
+ .trylock = starfive_hwspinlock_trylock,
+ .unlock = starfive_hwspinlock_unlock,
+ .relax = starfive_hwspinlock_relax,
+};
+
+static void starfive_hwspinlock_disable(void *data)
+{
+ struct starfive_hwspinlock *priv = data;
+
+ reset_control_assert(priv->rst);
+}
+
+static int starfive_hwspinlock_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct starfive_hwspinlock *priv;
+ int ret;
+
+ priv = devm_kzalloc(dev, struct_size(priv, bank.lock, STARFIVE_NUM_LOCKS),
+ GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ priv->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(priv->base))
+ return PTR_ERR(priv->base);
+
+ priv->rst = devm_reset_control_array_get_exclusive(dev);
+ if (IS_ERR(priv->rst))
+ return dev_err_probe(dev, PTR_ERR(priv->rst),
+ "failed to get reset\n");
+
+ ret = reset_control_deassert(priv->rst);
+ if (ret)
+ return ret;
+
+ platform_set_drvdata(pdev, priv);
+
+ ret = devm_add_action_or_reset(dev, starfive_hwspinlock_disable, priv);
+ if (ret)
+ goto fail_action;
+
+ return devm_hwspin_lock_register(dev, &priv->bank, &starfive_hwspinlock_ops,
+ 0, STARFIVE_NUM_LOCKS);
+
+fail_action:
+ reset_control_assert(priv->rst);
+ return ret;
+}
+
+static const struct of_device_id starfive_hwpinlock_ids[] = {
+ { .compatible = "starfive,jhb100-hwspinlock", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, starfive_hwpinlock_ids);
+
+static struct platform_driver starfive_hwspinlock_driver = {
+ .probe = starfive_hwspinlock_probe,
+ .driver = {
+ .name = "starfive_hwspinlock",
+ .of_match_table = starfive_hwpinlock_ids,
+ },
+};
+module_platform_driver(starfive_hwspinlock_driver);
+
+MODULE_AUTHOR("Xingyu Wu <xingyu.wu@starfivetech.com>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Hardware spinlock driver for StarFive JHB100 SoC");
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: hwlock: Add StarFive JHB100 HW lock
2026-05-15 9:53 ` [PATCH v2 1/2] dt-bindings: hwlock: Add StarFive JHB100 HW lock Xingyu Wu
@ 2026-05-15 17:16 ` Conor Dooley
0 siblings, 0 replies; 4+ messages in thread
From: Conor Dooley @ 2026-05-15 17:16 UTC (permalink / raw)
To: Xingyu Wu
Cc: Bjorn Andersson, Baolin Wang, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, devicetree, linux-kernel, linux-remoteproc
[-- Attachment #1: Type: text/plain, Size: 78 bytes --]
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
pw-bot: not-applicable
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-15 17:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-15 9:53 [PATCH v2 0/2] Add hwspinlock driver for StarFive JHB100 SoC Xingyu Wu
2026-05-15 9:53 ` [PATCH v2 1/2] dt-bindings: hwlock: Add StarFive JHB100 HW lock Xingyu Wu
2026-05-15 17:16 ` Conor Dooley
2026-05-15 9:53 ` [PATCH v2 2/2] hwspinlock: Add StarFive hwspinlock device Xingyu Wu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox