diff options
author | Rasmus Villemoes <rasmus.villemoes@prevas.dk> | 2020-07-06 22:01:10 +0200 |
---|---|---|
committer | Heiko Schocher <hs@denx.de> | 2020-07-09 06:02:44 +0200 |
commit | d8be08805bc03d53b0dd6953792fba543a4f3890 (patch) | |
tree | 1236ca71b86c47aa4c135881018078dc6974a6ef /drivers | |
parent | 35d3982e23d3449d93bcc4f1990e929998d69936 (diff) |
rtc: add dm_rtc_read helper and ->read method
Some users may want to read multiple consecutive 8-bit
registers. Instead of each caller having to implement the loop,
provide a dm_rtc_read() helper. Also, allow a driver to provide a
->read method, which can be more efficient than reading one register
at a time.
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/rtc/rtc-uclass.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-uclass.c b/drivers/rtc/rtc-uclass.c index 926cca234e..4a0e3c5643 100644 --- a/drivers/rtc/rtc-uclass.c +++ b/drivers/rtc/rtc-uclass.c @@ -40,6 +40,25 @@ int dm_rtc_reset(struct udevice *dev) return ops->reset(dev); } +int dm_rtc_read(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len) +{ + struct rtc_ops *ops = rtc_get_ops(dev); + + assert(ops); + if (ops->read) + return ops->read(dev, reg, buf, len); + if (!ops->read8) + return -ENOSYS; + while (len--) { + int ret = ops->read8(dev, reg++); + + if (ret < 0) + return ret; + *buf++ = ret; + } + return 0; +} + int rtc_read8(struct udevice *dev, unsigned int reg) { struct rtc_ops *ops = rtc_get_ops(dev); |