From: Peng Fan <peng.fan@oss.nxp.com>
To: Kamal Dasu <kamal.dasu@broadcom.com>
Cc: bcm-kernel-feedback-list@broadcom.com, andersson@kernel.org,
baolin.wang@linux.alibaba.com, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org,
florian.fainelli@broadcom.com, linux-remoteproc@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] hwspinlock: brcmstb hardware semaphore support
Date: Wed, 1 Oct 2025 10:53:05 +0800 [thread overview]
Message-ID: <20251001025305.GA23170@nxa18884-linux.ap.freescale.net> (raw)
In-Reply-To: <20250929200628.3699525-4-kamal.dasu@broadcom.com>
On Mon, Sep 29, 2025 at 04:06:26PM -0400, Kamal Dasu wrote:
>Added support for brmstb_hwspinlock driver that makes use of
>the hwspinlock framework. Driver uses SUN_TOP_CTRL_SEMAPHORE_[1:15]
>registers to implement the hardware semaphore. With this change
>other brcmstb drivers can use hwspin_trylock() and hwspin_unlock()
>apis and make use of this hwspinlock framework. Other driver dt nodes
>just need to use a reference to the &hwspinlock and the lock id
>they want to use.
>e.g. hwlocks = <&hwspinlock0 0>;
>
>Signed-off-by: Kamal Dasu <kamal.dasu@broadcom.com>
>---
> drivers/hwspinlock/Kconfig | 9 +++
> drivers/hwspinlock/Makefile | 1 +
> drivers/hwspinlock/brcmstb_hwspinlock.c | 98 +++++++++++++++++++++++++
> 3 files changed, 108 insertions(+)
> create mode 100644 drivers/hwspinlock/brcmstb_hwspinlock.c
>
>diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
>index 3874d15b0e9b..551afa8df2d0 100644
>--- a/drivers/hwspinlock/Kconfig
>+++ b/drivers/hwspinlock/Kconfig
>@@ -63,4 +63,13 @@ config HSEM_U8500
>
> If unsure, say N.
>
>+config HWSPINLOCK_BRCMSTB
Should be put above "config HWSPINLOCK_OMAP" to follow the order.
>+ tristate "Broadcom Setttop Hardware Semaphore functionality"
...
>--- a/drivers/hwspinlock/Makefile
>+++ b/drivers/hwspinlock/Makefile
>@@ -10,3 +10,4 @@ obj-$(CONFIG_HWSPINLOCK_SPRD) += sprd_hwspinlock.o
> obj-$(CONFIG_HWSPINLOCK_STM32) += stm32_hwspinlock.o
> obj-$(CONFIG_HWSPINLOCK_SUN6I) += sun6i_hwspinlock.o
> obj-$(CONFIG_HSEM_U8500) += u8500_hsem.o
>+obj-$(CONFIG_HWSPINLOCK_BRCMSTB) += brcmstb_hwspinlock.o
Put above "obj-$(CONFIG_HWSPINLOCK_OMAP) += omap_hwspinlock.o"
>diff --git a/drivers/hwspinlock/brcmstb_hwspinlock.c b/drivers/hwspinlock/brcmstb_hwspinlock.c
>new file mode 100644
>index 000000000000..56206431a94c
>--- /dev/null
>+++ b/drivers/hwspinlock/brcmstb_hwspinlock.c
>@@ -0,0 +1,98 @@
>+// SPDX-License-Identifier: GPL-2.0
>+/*
>+ * brcmstb HWSEM driver
>+ *
>+ * Copyright (C) 2025 Broadcom
>+ *
>+ */
>+
>+#include <linux/module.h>
>+#include <linux/delay.h>
>+#include <linux/io.h>
>+#include <linux/slab.h>
>+#include <linux/spinlock.h>
>+#include <linux/hwspinlock.h>
>+#include <linux/platform_device.h>
>+#include <linux/mod_devicetable.h>
Sort the included headers.
>+#include "hwspinlock_internal.h"
>+
>+#define BRCMSTB_MAX_SEMAPHORES 16
>+#define RESET_SEMAPHORE 0
>+
>+#define HWSPINLOCK_VAL 'L'
>+
>+static int brcmstb_hwspinlock_trylock(struct hwspinlock *lock)
>+{
>+ void __iomem *lock_addr = (void __iomem *)lock->priv;
>+
>+ writel(HWSPINLOCK_VAL, lock_addr);
>+
>+ return (readl(lock_addr) == HWSPINLOCK_VAL);
>+}
>+
>+static void brcmstb_hwspinlock_unlock(struct hwspinlock *lock)
>+{
>+ void __iomem *lock_addr = (void __iomem *)lock->priv;
>+
>+ /* release the lock by writing 0 to it */
>+ writel(RESET_SEMAPHORE, lock_addr);
>+}
>+
>+static void brcmstb_hwspinlock_relax(struct hwspinlock *lock)
>+{
>+ ndelay(50);
>+}
>+
>+static const struct hwspinlock_ops brcmstb_hwspinlock_ops = {
>+ .trylock = brcmstb_hwspinlock_trylock,
>+ .unlock = brcmstb_hwspinlock_unlock,
>+ .relax = brcmstb_hwspinlock_relax,
>+};
>+
>+static int brcmstb_hwspinlock_probe(struct platform_device *pdev)
>+{
>+ struct hwspinlock_device *bank;
>+ struct hwspinlock *hwlock;
>+ void __iomem *io_base;
>+ int i, num_locks = BRCMSTB_MAX_SEMAPHORES;
>+
>+ io_base = devm_platform_ioremap_resource(pdev, 0);
>+ if (IS_ERR(io_base)) {
>+ dev_err(&pdev->dev, "semaphore iobase mapping error\n");
>+ return PTR_ERR(io_base);
>+ }
>+
>+ bank = devm_kzalloc(&pdev->dev, struct_size(bank, lock, num_locks),
>+ GFP_KERNEL);
>+ if (!bank)
>+ return -ENOMEM;
>+
>+ platform_set_drvdata(pdev, bank);
I not see users of drvdata in this driver, is this needed or I miss something?
>+
>+ for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++)
>+ hwlock->priv = (void __iomem *)(io_base + sizeof(u32) * i);
>+
>+ return devm_hwspin_lock_register(&pdev->dev, bank,
>+ &brcmstb_hwspinlock_ops,
>+ 0, num_locks);
Seems all "brcm,brcmstb-hwspinlock" compatible devices have 16 sema locks.
If this is true, it is ok. Otherwise better not fix num_locks to
BRCMSTB_MAX_SEMAPHORES. "MAX" implys that not all devices have 16 sema locks.
Thanks,
Peng
next prev parent reply other threads:[~2025-10-01 1:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 20:06 [PATCH 0/3] Adding brcmstb-hwspinlock support Kamal Dasu
2025-09-29 20:06 ` [PATCH 1/3] dt-bindings: hwlock: " Kamal Dasu
2025-09-30 19:03 ` Conor Dooley
2025-09-30 19:09 ` Florian Fainelli
2025-09-30 19:34 ` Conor Dooley
2025-10-01 2:58 ` Peng Fan
2025-10-01 15:17 ` Kamal Dasu
2025-10-01 15:28 ` Florian Fainelli
2025-10-10 10:11 ` Peng Fan
2025-09-29 20:06 ` [PATCH 1/3] dt-bindings: hwlock: support for brcmstb-hwspinlock Kamal Dasu
2025-09-30 19:04 ` Conor Dooley
2025-09-30 20:25 ` Kamal Dasu
2025-09-29 20:06 ` [PATCH 2/3] hwspinlock: brcmstb hardware semaphore support Kamal Dasu
2025-10-01 2:53 ` Peng Fan [this message]
2025-09-29 20:06 ` [PATCH 3/3] MAINTAINERS: adding entry for BRCMSTB HWSPINLOCK driver Kamal Dasu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251001025305.GA23170@nxa18884-linux.ap.freescale.net \
--to=peng.fan@oss.nxp.com \
--cc=andersson@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=florian.fainelli@broadcom.com \
--cc=kamal.dasu@broadcom.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox