From 09381829a231f5d2b95568f3178c2bd125a93fac Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Mon, 6 Jul 2020 22:01:11 +0200 Subject: rtc: add dm_rtc_write() helper Similar to dm_rtc_read(), introduce a helper that allows the caller to write multiple consecutive 8-bit registers with one call. If the driver provides the ->write method, use that, otherwise loop using ->write8. Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher Signed-off-by: Rasmus Villemoes --- drivers/rtc/rtc-uclass.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'drivers/rtc') diff --git a/drivers/rtc/rtc-uclass.c b/drivers/rtc/rtc-uclass.c index 4a0e3c5..44da500 100644 --- a/drivers/rtc/rtc-uclass.c +++ b/drivers/rtc/rtc-uclass.c @@ -59,6 +59,25 @@ int dm_rtc_read(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len return 0; } +int dm_rtc_write(struct udevice *dev, unsigned int reg, + const u8 *buf, unsigned int len) +{ + struct rtc_ops *ops = rtc_get_ops(dev); + + assert(ops); + if (ops->write) + return ops->write(dev, reg, buf, len); + if (!ops->write8) + return -ENOSYS; + while (len--) { + int ret = ops->write8(dev, reg++, *buf++); + + if (ret < 0) + return ret; + } + return 0; +} + int rtc_read8(struct udevice *dev, unsigned int reg) { struct rtc_ops *ops = rtc_get_ops(dev); -- cgit v1.1