U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Zhuxu Ran <zhuxu_ran@zohomail.com>, u-boot@lists.u-boot-project.org
Cc: 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>,
	Hiago De Franco <hfranco@baylibre.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 v3 1/3] rtc: cv1800b: Add seconds counter support
Date: Wed, 7 Oct 2026 22:24:03 +0000	[thread overview]
Message-ID: <asbGg-KcrPRYBT0Y@pie> (raw)
In-Reply-To: <20261007-cv18xx-rtc-sysreset-v3-1-194557fd5e78@zohomail.com>

On Wed, Oct 07, 2026 at 11:33:05AM +0800, Zhuxu Ran wrote:
> Add a driver for the CV1800B RTC seconds counter described by the
> upstream devicetree. Map the node's register range, enable the RTC
> clock, and implement reading and setting the 32-bit counter. Bind
> the existing sysreset driver as a child when enabled.
> 
> Adapt the register definitions and seconds-counter sequence from
> Linux drivers/rtc/rtc-cv1800.c by Jingbao Qiu.
> 
> Link: https://git.kernel.org/linus/d9f82683b123ce315cc36c4b20a5bc3d8644f947
> 
> Signed-off-by: Zhuxu Ran <zhuxu_ran@zohomail.com>
> ---
>  drivers/rtc/Kconfig   |   9 ++++
>  drivers/rtc/Makefile  |   1 +
>  drivers/rtc/cv1800b.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 133 insertions(+)

...

> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index 742481ce185..3c480156498 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -7,6 +7,7 @@
>  obj-$(CONFIG_$(PHASE_)DM_RTC) += rtc-uclass.o
>  
>  obj-$(CONFIG_RTC_ARMADA38X) += armada38x.o
> +obj-$(CONFIG_RTC_CV1800B) += cv1800b.o
>  obj-$(CONFIG_RTC_DAVINCI) += davinci.o
>  obj-$(CONFIG_RTC_DS1307) += ds1307.o
>  obj-$(CONFIG_RTC_DS1337) += ds1337.o
> diff --git a/drivers/rtc/cv1800b.c b/drivers/rtc/cv1800b.c
> new file mode 100644
> index 00000000000..e98efb319d7
> --- /dev/null
> +++ b/drivers/rtc/cv1800b.c
> @@ -0,0 +1,123 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2026 Zhuxu Ran <zhuxu_ran@zohomail.com>
> + *
> + * Based on the Linux driver by Jingbao Qiu <qiujingbao.dlmu@gmail.com>.

If so, it would be good to keep the copyright line :)

> + */

...

> +struct cv1800b_rtc_priv {
> +	struct regmap *regmap;
> +	struct clk clk;

I don't think you make use of clk anymore after exiting probe(), so I
think it makes sense to turn it into a local variable.

> +};
> +
> +static int cv1800b_rtc_get(struct udevice *dev, struct rtc_time *time)
> +{
> +	struct cv1800b_rtc_priv *priv = dev_get_priv(dev);
> +	u32 value;
> +	int ret;
> +
> +	ret = regmap_read(priv->regmap, SEC_PULSE_GEN, &value);
> +	if (ret)
> +		return ret;
> +	if (value & SEL_SEC_PULSE)
> +		return -EINVAL;
> +
> +	ret = regmap_read(priv->regmap, SEC_CNTR_VAL, &value);
> +	if (ret)
> +		return ret;
> +
> +	rtc_to_tm(value, time);
> +
> +	return 0;
> +}
> +
> +static int cv1800b_rtc_set(struct udevice *dev, const struct rtc_time *time)
> +{
> +	struct cv1800b_rtc_priv *priv = dev_get_priv(dev);
> +	time64_t seconds;
> +	int ret;
> +
> +	if (time->tm_year < 1970)
> +		return -EINVAL;
> +
> +	seconds = rtc_mktime(time);
> +	if (seconds < 0 || seconds > U32_MAX)
> +		return -ERANGE;
> +
> +	ret = regmap_write(priv->regmap, SET_SEC_CNTR_VAL, seconds);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_write(priv->regmap, SET_SEC_CNTR_TRIG, 1);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_write(priv->regmap, MACRO_RG_SET_T, seconds);
> +	if (ret)
> +		return ret;
> +
> +	return regmap_update_bits(priv->regmap, SEC_PULSE_GEN,
> +				  SEL_SEC_PULSE, 0);
> +}

It's redundant to check these regmap access, since the regmap is backed
by MMIO, and there's no reason it could fail.

Regards,
Yao Zi

  reply	other threads:[~2026-10-07 22:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07  3:33 [PATCH v3 0/3] rtc: cv1800b: Use the RTC node for time and system reset Zhuxu Ran
2026-10-07  3:33 ` [PATCH v3 1/3] rtc: cv1800b: Add seconds counter support Zhuxu Ran
2026-10-07 22:24   ` Yao Zi [this message]
2026-10-07  3:33 ` [PATCH v3 2/3] riscv: sophgo: Enable RTC-backed system reset Zhuxu Ran
2026-10-07  3:33 ` [PATCH v3 3/3] sysreset: cv1800b: Use the RTC device node for register access Zhuxu Ran
2026-10-07 12:16 ` [PATCH v3 0/3] rtc: cv1800b: Use the RTC node for time and system reset Hiago De Franco

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=asbGg-KcrPRYBT0Y@pie \
    --to=me@ziyao.cc \
    --cc=akoch@initse.com \
    --cc=casey.connolly@linaro.org \
    --cc=heiko@sntech.de \
    --cc=hfranco@baylibre.com \
    --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=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