[PATCH v4 09/15] hwspinlock: sun6i: use new callback to initialize hwspinlock priv

Wolfram Sang posted 15 patches 4 weeks, 1 day ago
There is a newer version of this series
[PATCH v4 09/15] hwspinlock: sun6i: use new callback to initialize hwspinlock priv
Posted by Wolfram Sang 4 weeks, 1 day ago
Apply the new helper to avoid using internal structures from the core.
Remove superfluous setting of drvdata while here.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Chen-Yu Tsai <wens@kernel.org>
---
 drivers/hwspinlock/sun6i_hwspinlock.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/hwspinlock/sun6i_hwspinlock.c b/drivers/hwspinlock/sun6i_hwspinlock.c
index a0c76bba3f05..c3db81cb1793 100644
--- a/drivers/hwspinlock/sun6i_hwspinlock.c
+++ b/drivers/hwspinlock/sun6i_hwspinlock.c
@@ -74,9 +74,15 @@ static void sun6i_hwspinlock_unlock(struct hwspinlock *lock)
 	writel(SPINLOCK_NOTTAKEN, lock_addr);
 }
 
+static void *sun6i_hwspinlock_init_priv(int local_id, void *init_data)
+{
+	return init_data + sizeof(u32) * local_id;
+}
+
 static const struct hwspinlock_ops sun6i_hwspinlock_ops = {
 	.trylock	= sun6i_hwspinlock_trylock,
 	.unlock		= sun6i_hwspinlock_unlock,
+	.init_priv	= sun6i_hwspinlock_init_priv,
 };
 
 static void sun6i_hwspinlock_disable(void *data)
@@ -91,10 +97,9 @@ static void sun6i_hwspinlock_disable(void *data)
 static int sun6i_hwspinlock_probe(struct platform_device *pdev)
 {
 	struct sun6i_hwspinlock_data *priv;
-	struct hwspinlock *hwlock;
 	void __iomem *io_base;
 	u32 num_banks;
-	int err, i;
+	int err;
 
 	io_base = devm_platform_ioremap_resource(pdev, SPINLOCK_BASE_ID);
 	if (IS_ERR(io_base))
@@ -161,11 +166,6 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev)
 		goto bank_fail;
 	}
 
-	for (i = 0; i < priv->nlocks; ++i) {
-		hwlock = &priv->bank->lock[i];
-		hwlock->priv = io_base + SPINLOCK_LOCK_REGN + sizeof(u32) * i;
-	}
-
 	/* failure of debugfs is considered non-fatal */
 	sun6i_hwspinlock_debugfs_init(priv);
 	if (IS_ERR(priv->debugfs))
@@ -177,10 +177,8 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev)
 		goto bank_fail;
 	}
 
-	platform_set_drvdata(pdev, priv);
-
 	return devm_hwspin_lock_register(&pdev->dev, priv->bank, &sun6i_hwspinlock_ops,
-					 SPINLOCK_BASE_ID, priv->nlocks, NULL);
+					 SPINLOCK_BASE_ID, priv->nlocks, io_base + SPINLOCK_LOCK_REGN);
 
 bank_fail:
 	clk_disable_unprepare(priv->ahb_clk);
-- 
2.47.3
Re: [PATCH v4 09/15] hwspinlock: sun6i: use new callback to initialize hwspinlock priv
Posted by Chen-Yu Tsai 4 weeks, 1 day ago
On Tue, Mar 10, 2026 at 3:56 PM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
>
> Apply the new helper to avoid using internal structures from the core.
> Remove superfluous setting of drvdata while here.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Reviewed-by: Chen-Yu Tsai <wens@kernel.org>
> ---
>  drivers/hwspinlock/sun6i_hwspinlock.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/hwspinlock/sun6i_hwspinlock.c b/drivers/hwspinlock/sun6i_hwspinlock.c
> index a0c76bba3f05..c3db81cb1793 100644
> --- a/drivers/hwspinlock/sun6i_hwspinlock.c
> +++ b/drivers/hwspinlock/sun6i_hwspinlock.c
> @@ -74,9 +74,15 @@ static void sun6i_hwspinlock_unlock(struct hwspinlock *lock)
>         writel(SPINLOCK_NOTTAKEN, lock_addr);
>  }
>
> +static void *sun6i_hwspinlock_init_priv(int local_id, void *init_data)
> +{
> +       return init_data + sizeof(u32) * local_id;
> +}
> +
>  static const struct hwspinlock_ops sun6i_hwspinlock_ops = {
>         .trylock        = sun6i_hwspinlock_trylock,
>         .unlock         = sun6i_hwspinlock_unlock,
> +       .init_priv      = sun6i_hwspinlock_init_priv,
>  };
>
>  static void sun6i_hwspinlock_disable(void *data)
> @@ -91,10 +97,9 @@ static void sun6i_hwspinlock_disable(void *data)
>  static int sun6i_hwspinlock_probe(struct platform_device *pdev)
>  {
>         struct sun6i_hwspinlock_data *priv;
> -       struct hwspinlock *hwlock;
>         void __iomem *io_base;
>         u32 num_banks;
> -       int err, i;
> +       int err;
>
>         io_base = devm_platform_ioremap_resource(pdev, SPINLOCK_BASE_ID);
>         if (IS_ERR(io_base))
> @@ -161,11 +166,6 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev)
>                 goto bank_fail;
>         }
>
> -       for (i = 0; i < priv->nlocks; ++i) {
> -               hwlock = &priv->bank->lock[i];
> -               hwlock->priv = io_base + SPINLOCK_LOCK_REGN + sizeof(u32) * i;
> -       }
> -
>         /* failure of debugfs is considered non-fatal */
>         sun6i_hwspinlock_debugfs_init(priv);
>         if (IS_ERR(priv->debugfs))
> @@ -177,10 +177,8 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev)
>                 goto bank_fail;
>         }
>
> -       platform_set_drvdata(pdev, priv);
> -
>         return devm_hwspin_lock_register(&pdev->dev, priv->bank, &sun6i_hwspinlock_ops,
> -                                        SPINLOCK_BASE_ID, priv->nlocks, NULL);
> +                                        SPINLOCK_BASE_ID, priv->nlocks, io_base + SPINLOCK_LOCK_REGN);
>
>  bank_fail:
>         clk_disable_unprepare(priv->ahb_clk);

Just a note, I see further code savings in using the clk and reset devm_
helpers. I'll do this after this series is merged, as the context overlaps.


ChenYu
Re: [PATCH v4 09/15] hwspinlock: sun6i: use new callback to initialize hwspinlock priv
Posted by Wolfram Sang 4 weeks, 1 day ago
Hi ChenYu,

> >  bank_fail:
> >         clk_disable_unprepare(priv->ahb_clk);
> 
> Just a note, I see further code savings in using the clk and reset devm_
> helpers. I'll do this after this series is merged, as the context overlaps.

Yes, I saw this, too, but thought that this needs HW for proper testing.
Great that you are up for it!

Happy hacking,

   Wolfram
Re: [PATCH v4 09/15] hwspinlock: sun6i: use new callback to initialize hwspinlock priv
Posted by Wilken Gottwalt 4 weeks, 1 day ago
On Tue, 10 Mar 2026 11:03:30 +0100
Wolfram Sang <wsa+renesas@sang-engineering.com> wrote:

> Hi ChenYu,
> 
> > >  bank_fail:
> > >         clk_disable_unprepare(priv->ahb_clk);
> > 
> > Just a note, I see further code savings in using the clk and reset devm_
> > helpers. I'll do this after this series is merged, as the context overlaps.
> 
> Yes, I saw this, too, but thought that this needs HW for proper testing.
> Great that you are up for it!

Not only that. You may also need to run the CRUST firmware on the OpenRISC
companion core. Getting that hwspinlock driver done and tested was some real
pain in the past. I still have everything on github for this
(https://github.com/wgottwalt/sunxi_hwspinlock). But I may not be able to test
that in time. I moved a while ago and, uhm, quite some hardware disappeared.

greetings