@@ -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;
@@ -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
*
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 <rasmus.villemoes at prevas.dk> --- drivers/rtc/rtc-uclass.c | 18 ++++++++++++++++++ include/rtc.h | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)