From patchwork Mon May 4 21:20:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 245052 List-Id: U-Boot discussion From: rasmus.villemoes at prevas.dk (Rasmus Villemoes) Date: Mon, 4 May 2020 23:20:28 +0200 Subject: [PATCH 2/6] rtc: add rtc_write8_array() helper In-Reply-To: <20200504212032.3759-1-rasmus.villemoes@prevas.dk> References: <20200504212032.3759-1-rasmus.villemoes@prevas.dk> Message-ID: <20200504212032.3759-3-rasmus.villemoes@prevas.dk> Similar to the rtc_read8_array(), introduce a helper that allows the caller to write multiple consecutive 8-bit registers with one call. If the driver provides the ->write8_array method, use that, otherwise loop using ->write8. Signed-off-by: Rasmus Villemoes Reviewed-by: Simon Glass --- 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 5070fb416d..56490a876f 100644 --- a/drivers/rtc/rtc-uclass.c +++ b/drivers/rtc/rtc-uclass.c @@ -78,6 +78,24 @@ int rtc_write8(struct udevice *dev, unsigned int reg, int val) return ops->write8(dev, reg, val); } +int rtc_write8_array(struct udevice *dev, unsigned int reg, + const u8 *buf, unsigned int len) +{ + struct rtc_ops *ops = rtc_get_ops(dev); + + assert(ops); + if (ops->write8_array) + return ops->write8_array(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_read16(struct udevice *dev, unsigned int reg, u16 *valuep) { u16 value = 0; diff --git a/include/rtc.h b/include/rtc.h index f7f622c1db..08b2a00567 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -85,6 +85,18 @@ struct rtc_ops { * @return 0 if OK, -ve on error */ int (*write8)(struct udevice *dev, unsigned int reg, int val); + + /** + * write8_array() - 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 (*write8_array)(struct udevice *dev, unsigned int reg, + const u8 *buf, unsigned int len); }; /* Access the operations for an RTC device */ @@ -152,6 +164,18 @@ int rtc_read8_array(struct udevice *dev, unsigned int reg, */ int rtc_write8(struct udevice *dev, unsigned int reg, int val); +/** + * rtc_write8_array() - 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_write8_array(struct udevice *dev, unsigned int reg, + const u8 *buf, unsigned int len); + /** * rtc_read16() - Read a 16-bit value from the RTC *