From: Hiago De Franco <hfranco@baylibre.com>
To: Zhuxu Ran <zhuxu_ran@zohomail.com>
Cc: u-boot@lists.u-boot-project.org, Yao Zi <me@ziyao.cc>,
Tom Rini <trini@konsulko.com>, Johan Jonker <jbx6244@gmail.com>,
Alexander Koch <akoch@initse.com>,
Kongyang Liu <seashell11234455@gmail.com>,
Thomas Bonnefille <thomas.bonnefille@bootlin.com>,
Quentin Schulz <quentin.schulz@cherry.de>,
Peter Robinson <pbrobinson@gmail.com>,
Leo Yu-Chi Liang <leo.liang@sifive.com>,
Casey Connolly <casey.connolly@linaro.org>,
Varadarajan Narayanan <varadarajan.narayanan@oss.qualcomm.com>,
Sumit Garg <sumit.garg@oss.qualcomm.com>,
Heiko Stuebner <heiko@sntech.de>,
Marek Vasut <marek.vasut+renesas@mailbox.org>,
Marek Vasut <marex@nabladev.com>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>
Subject: Re: [PATCH v2 3/3] sysreset: cv1800b: Use the RTC device node for register access
Date: Tue, 6 Oct 2026 14:28:28 -0300 [thread overview]
Message-ID: <asUuBvxgzECTfr7l@hiagonb> (raw)
In-Reply-To: <20261006-cv18xx-rtc-sysreset-v2-3-67872888384e@zohomail.com>
On Tue, Oct 06, 2026 at 11:45:08PM +0800, Zhuxu Ran wrote:
> The CV1800B system reset driver uses hard-coded RTC register
> addresses. Initialize a register map from the RTC node shared with
> its parent device instead, and propagate register access errors.
> Require the RTC driver that binds the sysreset child. Preserve the
> existing reset requests, including the warm-reset sequence used for
> SYSRESET_COLD.
>
> Signed-off-by: Zhuxu Ran <zhuxu_ran@zohomail.com>
> ---
> drivers/sysreset/Kconfig | 6 ++-
> drivers/sysreset/sysreset_cv1800b.c | 90 +++++++++++++++++++++++--------------
> 2 files changed, 60 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/sysreset/Kconfig b/drivers/sysreset/Kconfig
> index 16ef434a8d9..c9f2a552b47 100644
> --- a/drivers/sysreset/Kconfig
> +++ b/drivers/sysreset/Kconfig
> @@ -60,9 +60,11 @@ config SYSRESET_CMD_POWEROFF
> endif
>
> config SYSRESET_CV1800B
> - bool "Enable support for Sophgo cv1800b System Reset"
> + bool "Enable support for Sophgo CV1800B system reset"
> + depends on RTC_CV1800B
> help
> - Enable system reset support for Sophgo cv1800b SoC.
> + Enable system reset and power control through the RTC subsystem
> + found on Sophgo CV1800 series SoCs.
>
> config POWEROFF_GPIO
> bool "Enable support for GPIO poweroff driver"
> diff --git a/drivers/sysreset/sysreset_cv1800b.c b/drivers/sysreset/sysreset_cv1800b.c
> index 9cd62772ef4..fa76c8cf38e 100644
> --- a/drivers/sysreset/sysreset_cv1800b.c
> +++ b/drivers/sysreset/sysreset_cv1800b.c
> @@ -1,64 +1,86 @@
> // SPDX-License-Identifier: GPL-2.0
> /*
> * Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
> + * Copyright (c) 2026, Zhuxu Ran <zhuxu_ran@zohomail.com>
> */
>
> #include <dm.h>
> -#include <stdbool.h>
> +#include <regmap.h>
> #include <sysreset.h>
> -#include <wait_bit.h>
> -#include <linux/io.h>
> +#include <linux/bitops.h>
> +#include <linux/err.h>
> #include <linux/errno.h>
>
> -#define REG_RTC_BASE (void *)0x05026000
> -#define REG_RTC_CTRL_BASE (void *)0x05025000
> -#define REG_RTC_EN_SHDN_REQ (REG_RTC_BASE + 0xc0)
> -#define REG_RTC_EN_PWR_CYC_REQ (REG_RTC_BASE + 0xc8)
> -#define REG_RTC_EN_WARM_RST_REQ (REG_RTC_BASE + 0xcc)
> -#define REG_RTC_CTRL_UNLOCKKEY (REG_RTC_CTRL_BASE + 0x4)
> -#define REG_RTC_CTRL (REG_RTC_CTRL_BASE + 0x8)
> +#define RTC_CTRL_UNLOCKKEY 0x0004
> +#define RTC_CTRL 0x0008
> +#define RTC_EN_SHDN_REQ 0x10c0
Looks like the tabs for 0x10c0 are not correct.
> +#define RTC_EN_PWR_CYC_REQ 0x10c8
> +#define RTC_EN_WARM_RST_REQ 0x10cc
>
> -#define CTRL_UNLOCKKEY_MAGIC 0xAB18
> +#define CTRL_UNLOCKKEY_MAGIC 0xab18
This line change is purely cosmetic. I think it is fine since you are
changing all the other addresses, but I just wanted to highligth it.
>
> -/* REG_RTC_CTRL */
> -#define BIT_REQ_SHDN BIT(0)
> -#define BIT_REQ_PWR_CYC BIT(3)
> -#define BIT_REQ_WARM_RST BIT(4)
> +#define BIT_REQ_SHDN BIT(0)
> +#define BIT_REQ_PWR_CYC BIT(3)
Same here, looks like the tabs for BIT(3) are not correct.
> +#define BIT_REQ_WARM_RST BIT(4)
>
> -static struct {
> - void *pre_req_reg;
> +struct cv1800b_sysreset_priv {
> + struct regmap *regmap;
> +};
> +
> +static const struct {
> + u32 pre_req_reg;
> u32 req_bit;
> } reset_info[SYSRESET_COUNT] = {
> - [SYSRESET_WARM] = { REG_RTC_EN_WARM_RST_REQ, BIT_REQ_WARM_RST },
> - [SYSRESET_COLD] = { REG_RTC_EN_WARM_RST_REQ, BIT_REQ_WARM_RST },
> - [SYSRESET_POWER] = { REG_RTC_EN_PWR_CYC_REQ, BIT_REQ_PWR_CYC },
> - [SYSRESET_POWER_OFF] = { REG_RTC_EN_SHDN_REQ, BIT_REQ_SHDN },
> + [SYSRESET_WARM] = { RTC_EN_WARM_RST_REQ, BIT_REQ_WARM_RST },
> + [SYSRESET_COLD] = { RTC_EN_WARM_RST_REQ, BIT_REQ_WARM_RST },
> + [SYSRESET_POWER] = { RTC_EN_PWR_CYC_REQ, BIT_REQ_PWR_CYC },
> + [SYSRESET_POWER_OFF] = { RTC_EN_SHDN_REQ, BIT_REQ_SHDN },
> };
>
> static int cv1800b_sysreset_request(struct udevice *dev, enum sysreset_t type)
> {
> - u32 reg;
> + struct cv1800b_sysreset_priv *priv = dev_get_priv(dev);
> + int ret;
> +
> + if (type >= SYSRESET_COUNT)
> + return -EINVAL;
>
> - writel(1, reset_info[type].pre_req_reg);
> - writel(CTRL_UNLOCKKEY_MAGIC, REG_RTC_CTRL_UNLOCKKEY);
> - reg = readl(REG_RTC_CTRL);
> - writel(0xFFFF0800 | reset_info[type].req_bit, REG_RTC_CTRL);
> + ret = regmap_write(priv->regmap, reset_info[type].pre_req_reg, 1);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(priv->regmap, RTC_CTRL_UNLOCKKEY,
> + CTRL_UNLOCKKEY_MAGIC);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(priv->regmap, RTC_CTRL,
> + 0xffff0800 | reset_info[type].req_bit);
> + if (ret)
> + return ret;
>
> return -EINPROGRESS;
> }
>
> +static int cv1800b_sysreset_probe(struct udevice *dev)
> +{
> + struct cv1800b_sysreset_priv *priv = dev_get_priv(dev);
> +
> + priv->regmap = devm_regmap_init(dev, NULL, NULL, NULL);
> + if (IS_ERR(priv->regmap))
> + return PTR_ERR(priv->regmap);
> +
> + return 0;
> +}
> +
> static struct sysreset_ops cv1800b_sysreset = {
> .request = cv1800b_sysreset_request,
> };
>
> -static const struct udevice_id cv1800b_sysreset_ids[] = {
> - { .compatible = "sophgo,cv1800b-sysreset", },
> - {},
> -};
> -
> U_BOOT_DRIVER(sysreset_cv1800b) = {
> .name = "cv1800b_sysreset",
> - .id = UCLASS_SYSRESET,
> - .ops = &cv1800b_sysreset,
> - .of_match = cv1800b_sysreset_ids
> + .id = UCLASS_SYSRESET,
> + .probe = cv1800b_sysreset_probe,
> + .ops = &cv1800b_sysreset,
> + .priv_auto = sizeof(struct cv1800b_sysreset_priv),
> };
>
> --
> 2.55.0
>
Best regards,
--
Hiago
prev parent reply other threads:[~2026-10-06 17:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 15:45 [PATCH v2 0/3] rtc: cv1800b: Use the RTC node for time and system reset Zhuxu Ran
2026-10-06 15:45 ` [PATCH v2 1/3] rtc: cv1800b: Add seconds counter support Zhuxu Ran
2026-10-06 15:45 ` [PATCH v2 2/3] riscv: sophgo: Enable RTC-backed system reset Zhuxu Ran
2026-10-06 15:45 ` [PATCH v2 3/3] sysreset: cv1800b: Use the RTC device node for register access Zhuxu Ran
2026-10-06 17:28 ` Hiago De Franco [this message]
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=asUuBvxgzECTfr7l@hiagonb \
--to=hfranco@baylibre.com \
--cc=akoch@initse.com \
--cc=casey.connolly@linaro.org \
--cc=heiko@sntech.de \
--cc=ilias.apalodimas@linaro.org \
--cc=jbx6244@gmail.com \
--cc=leo.liang@sifive.com \
--cc=marek.vasut+renesas@mailbox.org \
--cc=marex@nabladev.com \
--cc=me@ziyao.cc \
--cc=pbrobinson@gmail.com \
--cc=quentin.schulz@cherry.de \
--cc=seashell11234455@gmail.com \
--cc=sumit.garg@oss.qualcomm.com \
--cc=thomas.bonnefille@bootlin.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
--cc=varadarajan.narayanan@oss.qualcomm.com \
--cc=zhuxu_ran@zohomail.com \
/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