From patchwork Tue May 19 22:01:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 246028 List-Id: U-Boot discussion From: rasmus.villemoes at prevas.dk (Rasmus Villemoes) Date: Wed, 20 May 2020 00:01:09 +0200 Subject: [PATCH v2 02/10] rtc: add rtc_write() helper In-Reply-To: <20200519220117.24448-1-rasmus.villemoes@prevas.dk> References: <20200504212032.3759-1-rasmus.villemoes@prevas.dk> <20200519220117.24448-1-rasmus.villemoes@prevas.dk> Message-ID: <20200519220117.24448-3-rasmus.villemoes@prevas.dk> Similar to 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 Signed-off-by: Rasmus Villemoes --- drivers/rtc/rtc-uclass.c | 18 ++++++++++++++++++ include/rtc.h | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/rtc/rtc-uclass.c b/drivers/rtc/rtc-uclass.c index 44d76bb70f..cc5f9c7baa 100644 --- a/drivers/rtc/rtc-uclass.c +++ b/drivers/rtc/rtc-uclass.c @@ -57,6 +57,24 @@ int rtc_read(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len) return 0; } +int 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); diff --git a/include/rtc.h b/include/rtc.h index 1c9c09fef8..8c66d37703 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -67,6 +67,18 @@ struct rtc_ops { int (*read)(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len); + /** + * write() - Write multiple 8-bit registers + * + * @dev: Device to write to + * @reg: First register to write + * @buf: Input buffer + * @len: Number of registers to write + * @return 0 if OK, -ve on error + */ + int (*write)(struct udevice *dev, unsigned int reg, + const u8 *buf, unsigned int len); + /** * read8() - Read an 8-bit register * @@ -132,6 +144,18 @@ int dm_rtc_reset(struct udevice *dev); */ int rtc_read(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len); +/** + * rtc_write() - Write multiple 8-bit registers + * + * @dev: Device to write to + * @reg: First register to write + * @buf: Input buffer + * @len: Number of registers to write + * @return 0 if OK, -ve on error + */ +int rtc_write(struct udevice *dev, unsigned int reg, + const u8 *buf, unsigned int len); + /** * rtc_read8() - Read an 8-bit register *