Re: [PATCH 2/6] clk: renesas: r9a06g032: Add reset controller
From: Philipp Zabel
Date: Fri Nov 20 2026 - 05:00:54 EST
On Do, 2026-11-19 at 09:57 -0800, Kyle Hendry via B4 Relay wrote:
> From: Kyle Hendry <khendry@xxxxxxxxxxxxxxxxxxxx>
>
> The rzn1 system controller has two resets that need to be cleared for the
> mii converter to work. They are not directly associated with any clocks
> so they need a reset controller to set them.
>
> They are documented in the PWRCTRL_SWITCHCTRL (0x4000C188) register as:
>
> Bit 3: RSTN_CLK25 - Active low Reset for Timestamp signal selection logic
> Bit 4: RSTN_ETH - Active low Reset for RGMII/RMII Converter (50 MHz).
>
> Add a reset controller and add resets for those bits.
>
> Signed-off-by: Kyle Hendry <khendry@xxxxxxxxxxxxxxxxxxxx>
> ---
> drivers/clk/renesas/r9a06g032-clocks.c | 64 ++++++++++++++++++++++++++++++++++
> 1 file changed, 64 insertions(+)
>
> diff --git a/drivers/clk/renesas/r9a06g032-clocks.c b/drivers/clk/renesas/r9a06g032-clocks.c
> index 3df3f2b2c6de..547e8d82f1cf 100644
> --- a/drivers/clk/renesas/r9a06g032-clocks.c
> +++ b/drivers/clk/renesas/r9a06g032-clocks.c
> @@ -21,6 +21,7 @@
> #include <linux/pm_clock.h>
> #include <linux/pm_domain.h>
> #include <linux/reboot.h>
> +#include <linux/reset-controller.h>
> #include <linux/slab.h>
> #include <linux/soc/renesas/r9a06g032-sysctrl.h>
> #include <linux/spinlock.h>
> @@ -675,6 +676,11 @@ static const struct r9a06g032_clkdesc r9a06g032_clocks[] = {
> RB(0xec, 16), RB(0xec, 17), RB(0xec, 18), RB(0xec, 19)),
> };
>
> +static const struct regbit r9a06g032_resets[] = {
> + RB(0x188, 3),
> + RB(0x188, 4),
I suggest to use designated initializers:
[R9A06G032_RST_TS] = RB(0x188, 3),
[R9A06G032_RST_MIIC] = RB(0x188, 4),
to document the association and make sure there are no off-by-one
errors.
> +};
> +
> struct r9a06g032_priv {
> struct clk_onecell_data data;
> spinlock_t lock; /* protects concurrent access to gates */
> @@ -1307,6 +1313,56 @@ static void __init r9a06g032_init_h2mode(struct r9a06g032_priv *clocks)
> writel(usb, clocks->reg + R9A06G032_SYSCTRL_USB);
> }
>
> +
> +#define rcdev_to_priv(x) container_of(x, struct r9a06g032_priv, rcdev)
I'd use a static inline function for this.
> +
> +static int r9a06g032_reset_set(struct reset_controller_dev *rcdev,
> + const char *func, bool set, unsigned long id)
> +{
> + struct r9a06g032_priv *priv = rcdev_to_priv(rcdev);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&priv->lock, flags);
> + clk_rdesc_set(priv, r9a06g032_resets[id], set);
> + spin_unlock_irqrestore(&priv->lock, flags);
> +
> + return 0;
> +}
> +
> +static int r9a06g032_reset(struct reset_controller_dev *rcdev,
> + unsigned long id)
> +{
> + r9a06g032_reset_set(rcdev, "reset", true, id);
> + udelay(5);
> + return r9a06g032_reset_set(rcdev, NULL, false, id);
> +}
Please don't implement the reset op unless really needed for
compatibility with actual, self-clearing reset controllers.
If it is needed, please explain why. If so, is this delay enough for
both resets? Is it enough for any other resets this reset controller
driver may support in the future?
> +
> +static int r9a06g032_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
> +{
> + return r9a06g032_reset_set(rcdev, "assert", false, id);
> +}
> +
> +static int r9a06g032_reset_deassert(struct reset_controller_dev *rcdev,
> + unsigned long id)
> +{
> + return r9a06g032_reset_set(rcdev, "deassert", true, id);
> +}
> +
> +static int r9a06g032_reset_status(struct reset_controller_dev *rcdev,
> + unsigned long id)
> +{
> + struct r9a06g032_priv *priv = rcdev_to_priv(rcdev);
> +
> + return clk_rdesc_get(priv, r9a06g032_resets[id]);
> +}
> +
> +static const struct reset_control_ops r9a06g032_reset_ops = {
> + .reset = r9a06g032_reset,
> + .assert = r9a06g032_reset_assert,
> + .deassert = r9a06g032_reset_deassert,
> + .status = r9a06g032_reset_status,
> +};
> +
> static int __init r9a06g032_clocks_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> @@ -1404,6 +1460,14 @@ static int __init r9a06g032_clocks_probe(struct platform_device *pdev)
> if (error)
> dev_err(dev, "Failed to populate children (%d)\n", error);
>
> + clocks->rcdev.ops = &r9a06g032_reset_ops;
> + clocks->rcdev.of_node = np;
> + clocks->rcdev.of_reset_n_cells = 1;
Don't set of_reset_n_cells, as of_xlate isn't set either.
fwnode_reset_n_cells will be set to 1 by default in
reset_controller_register().
> + clocks->rcdev.nr_resets = ARRAY_SIZE(r9a06g032_resets);
> + error = devm_reset_controller_register(dev, &clocks->rcdev);
^
Superfluous whitespace.
> + if (error)
> + return error;
> +
> return 0;
Could be simplified to just:
return devm_reset_controller_register(dev, &clocks->rcdev);
regards
Philipp