public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
To: Philipp Zabel <p.zabel@pengutronix.de>
Cc: tomm.merciai@gmail.com, peda@axentia.se,
	linux-renesas-soc@vger.kernel.org, biju.das.jz@bp.renesas.com,
	Fabrizio Castro <fabrizio.castro.jz@renesas.com>,
	Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Magnus Damm <magnus.damm@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Josua Mayer <josua@solid-run.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v9 5/6] reset: rzv2h-usb2phy: Convert to regmap API
Date: Wed, 1 Apr 2026 10:04:51 +0200	[thread overview]
Message-ID: <aczRo8HVUFqXKfG_@tom-desktop> (raw)
In-Reply-To: <283a6336658045be8906ee219620c994e85c7fb8.camel@pengutronix.de>

Hi Philipp,
Thanks for your review.

On Tue, Mar 31, 2026 at 06:36:45PM +0200, Philipp Zabel wrote:
> On Fr, 2026-03-27 at 19:08 +0100, Tommaso Merciai wrote:
> > Replace raw MMIO accesses (void __iomem *, readl/writel) with
> > regmap_read/regmap_write via devm_regmap_init_mmio(). Regmap
> > provides its own internal locking, so the manual spinlock and
> > scoped_guard() wrappers are no longer needed.
> > 
> > Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
> > ---
> > v8->v9:
> >  - New patch
> > 
> >  drivers/reset/Kconfig               |  1 +
> >  drivers/reset/reset-rzv2h-usb2phy.c | 42 ++++++++++++++++-------------
> >  2 files changed, 24 insertions(+), 19 deletions(-)
> > 
> > diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
> > index 5165006be693..c539ca88518f 100644
> > --- a/drivers/reset/Kconfig
> > +++ b/drivers/reset/Kconfig
> > @@ -257,6 +257,7 @@ config RESET_RZG2L_USBPHY_CTRL
> >  config RESET_RZV2H_USB2PHY
> >  	tristate "Renesas RZ/V2H(P) (and similar SoCs) USB2PHY Reset driver"
> >  	depends on ARCH_RENESAS || COMPILE_TEST
> > +	select REGMAP_MMIO
> >  	help
> >  	  Support for USB2PHY Port reset Control found on the RZ/V2H(P) SoC
> >  	  (and similar SoCs).
> > diff --git a/drivers/reset/reset-rzv2h-usb2phy.c b/drivers/reset/reset-rzv2h-usb2phy.c
> > index 5bdd39274612..4014eff0f017 100644
> > --- a/drivers/reset/reset-rzv2h-usb2phy.c
> > +++ b/drivers/reset/reset-rzv2h-usb2phy.c
> > @@ -5,13 +5,13 @@
> >   * Copyright (C) 2025 Renesas Electronics Corporation
> >   */
> >  
> > -#include <linux/cleanup.h>
> >  #include <linux/delay.h>
> >  #include <linux/io.h>
> >  #include <linux/module.h>
> >  #include <linux/of.h>
> >  #include <linux/platform_device.h>
> >  #include <linux/pm_runtime.h>
> > +#include <linux/regmap.h>
> >  #include <linux/reset.h>
> >  #include <linux/reset-controller.h>
> >  
> > @@ -37,10 +37,9 @@ struct rzv2h_usb2phy_reset_of_data {
> >  
> >  struct rzv2h_usb2phy_reset_priv {
> >  	const struct rzv2h_usb2phy_reset_of_data *data;
> > -	void __iomem *base;
> > +	struct regmap *regmap;
> >  	struct device *dev;
> >  	struct reset_controller_dev rcdev;
> > -	spinlock_t lock; /* protects register accesses */
> >  };
> >  
> >  static inline struct rzv2h_usb2phy_reset_priv
> > @@ -55,10 +54,8 @@ static int rzv2h_usbphy_reset_assert(struct reset_controller_dev *rcdev,
> >  	struct rzv2h_usb2phy_reset_priv *priv = rzv2h_usbphy_rcdev_to_priv(rcdev);
> >  	const struct rzv2h_usb2phy_reset_of_data *data = priv->data;
> >  
> > -	scoped_guard(spinlock, &priv->lock) {
> > -		writel(data->reset2_acquire_val, priv->base + data->reset2_reg);
> > -		writel(data->reset_assert_val, priv->base + data->reset_reg);
> > -	}
> > +	regmap_write(priv->regmap, data->reset2_reg, data->reset2_acquire_val);
> > +	regmap_write(priv->regmap, data->reset_reg, data->reset_assert_val);
> 
> What is the spinlock protecting? acquire/assert registers being set
> together, without another acquire/assert or deassert/release register
> access pair interleaving?
> In that case you still need the lock. Or use regmap_multi_reg_write().
> You could even directly store the sequences as struct reg_sequence in
> rzv2h_usb2phy_reset_of_data.

You are correct. Thank you.
As per your suggestion I'm planning to use regmap_multi_reg_write().

Plan is to have the:

static const struct reg_sequence rzv2h_init_seqs[] = {
	{ .reg = 0xc10, .def = 0x67c },
	{ .reg = 0xc14, .def = 0x1f },
	{ .reg = 0x600, .def = 0x909 },
};

static const struct reg_sequence rzv2h_assert_seqs[] = {
	{ .reg = 0xb04, .def = 0x303 },
	{ .reg = 0x000, .def = 0x206 },
};

static const struct reg_sequence rzv2h_deassert_seqs[] = {
	{ .reg = 0x000, .def = 0x200 },
	{ .reg = 0xb04, .def = 0x003 },
	{ .reg = 0x000, .def = 0x000 },
};

static const struct rzv2h_usb2phy_reset_of_data rzv2h_reset_of_data = {
	.init_seqs = rzv2h_init_seqs,
	.init_nseqs = ARRAY_SIZE(rzv2h_init_seqs),
	.assert_seqs = rzv2h_assert_seqs,
	.assert_nseqs = ARRAY_SIZE(rzv2h_assert_seqs),
	.deassert_seqs = rzv2h_deassert_seqs,
	.deassert_nseqs = ARRAY_SIZE(rzv2h_deassert_seqs),
	.reset_reg = 0,
	.reset_status_bits = BIT(2),
};

With that I can use:

static int rzv2h_usbphy_reset_assert(struct reset_controller_dev *rcdev,
				     unsigned long id)
{
	struct rzv2h_usb2phy_reset_priv *priv = rzv2h_usbphy_rcdev_to_priv(rcdev);
	const struct rzv2h_usb2phy_reset_of_data *data = priv->data;
	int ret;

	ret = regmap_multi_reg_write(priv->regmap, data->assert_seqs,
				     data->assert_nseqs);
	if (ret)
		return ret;

	usleep_range(11, 20);

	return 0;
}

static int rzv2h_usbphy_reset_deassert(struct reset_controller_dev *rcdev,
				       unsigned long id)
{
	struct rzv2h_usb2phy_reset_priv *priv = rzv2h_usbphy_rcdev_to_priv(rcdev);

	return regmap_multi_reg_write(priv->regmap, priv->data->deassert_seqs,
				      priv->data->deassert_nseqs);
}



> 
> >  	usleep_range(11, 20);
> >  
> > @@ -71,11 +68,9 @@ static int rzv2h_usbphy_reset_deassert(struct reset_controller_dev *rcdev,
> >  	struct rzv2h_usb2phy_reset_priv *priv = rzv2h_usbphy_rcdev_to_priv(rcdev);
> >  	const struct rzv2h_usb2phy_reset_of_data *data = priv->data;
> >  
> > -	scoped_guard(spinlock, &priv->lock) {
> > -		writel(data->reset_deassert_val, priv->base + data->reset_reg);
> > -		writel(data->reset2_release_val, priv->base + data->reset2_reg);
> > -		writel(data->reset_release_val, priv->base + data->reset_reg);
> > -	}
> > +	regmap_write(priv->regmap, data->reset_reg, data->reset_deassert_val);
> > +	regmap_write(priv->regmap, data->reset2_reg, data->reset2_release_val);
> > +	regmap_write(priv->regmap, data->reset_reg, data->reset_release_val);
> 
> Same as above.

	return regmap_multi_reg_write(priv->regmap, priv->data->deassert_seqs,
                                      priv->data->deassert_nseqs);
> 
> [...]
> 
> > @@ -149,7 +153,7 @@ static int rzv2h_usb2phy_reset_probe(struct platform_device *pdev)
> >  		return dev_err_probe(dev, error, "unable to register cleanup action\n");
> >  
> >  	for (unsigned int i = 0; i < data->init_val_count; i++)
> > -		writel(data->init_vals[i].val, priv->base + data->init_vals[i].reg);
> > +		regmap_write(priv->regmap, data->init_vals[i].reg, data->init_vals[i].val);
> 
> Not required for locking, but this could use regmap_multi_reg_write()
> as well.
>

And here we can use:

	error = regmap_multi_reg_write(priv->regmap, data->init_seqs, data->init_nseqs);
	if (error)
		return dev_err_probe(dev, error, "failed to initialize PHY registers\n");

Will send new version hope later today.
Thanks again for the hint!

Kind Regards,
Tommaso


> regards
> Philipp

  reply	other threads:[~2026-04-01  8:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-27 18:08 [PATCH v9 0/6] Add USB2.0 VBUS mux driver and extend rzv2h-usb2phy reset for RZ/G3E support Tommaso Merciai
2026-03-27 18:08 ` [PATCH v9 1/6] mux: Add driver for Renesas RZ/V2H USB VBENCTL VBUS_SEL mux Tommaso Merciai
2026-03-27 18:08 ` [PATCH v9 2/6] dt-bindings: reset: renesas,rzv2h-usb2phy: Add '#mux-state-cells' property Tommaso Merciai
2026-03-27 18:08 ` [PATCH v9 3/6] dt-bindings: reset: renesas,rzv2h-usb2phy: Document RZ/G3E USB2PHY reset Tommaso Merciai
2026-03-27 18:08 ` [PATCH v9 4/6] reset: rzv2h-usb2phy: Keep PHY clock enabled for entire device lifetime Tommaso Merciai
2026-03-27 18:08 ` [PATCH v9 5/6] reset: rzv2h-usb2phy: Convert to regmap API Tommaso Merciai
2026-03-31 16:36   ` Philipp Zabel
2026-04-01  8:04     ` Tommaso Merciai [this message]
2026-04-01  8:23       ` Philipp Zabel
2026-04-01  9:10         ` Tommaso Merciai
2026-04-01  9:25           ` Philipp Zabel
2026-04-01 10:25             ` Tommaso Merciai
2026-03-27 18:08 ` [PATCH v9 6/6] reset: rzv2h-usb2phy: Add support for VBUS mux controller registration Tommaso Merciai
2026-03-31 16:16 ` [PATCH v9 0/6] Add USB2.0 VBUS mux driver and extend rzv2h-usb2phy reset for RZ/G3E support Ulf Hansson

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=aczRo8HVUFqXKfG_@tom-desktop \
    --to=tommaso.merciai.xr@bp.renesas.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fabrizio.castro.jz@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=josua@solid-run.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=peda@axentia.se \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=robh@kernel.org \
    --cc=tomm.merciai@gmail.com \
    --cc=ulf.hansson@linaro.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