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 <[email protected]> > --- > 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 <[email protected]> > + * > + * Based on the Linux driver by Jingbao Qiu <[email protected]>. 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
