diff mbox series

[v3,02/10] rtc: add dm_rtc_write() helper

Message ID 20200602191403.7542-3-rasmus.villemoes@prevas.dk
State Superseded
Delegated to: Heiko Schocher
Headers show
Series new rtc methods, rtc command, and tests | expand

Commit Message

Rasmus Villemoes June 2, 2020, 7:13 p.m. UTC
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 <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 drivers/rtc/rtc-uclass.c | 18 ++++++++++++++++++
 include/rtc.h            | 24 ++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

Comments

Heiko Schocher June 3, 2020, 4:20 a.m. UTC | #1
Hello Rasmus,

Am 02.06.2020 um 21:13 schrieb Rasmus Villemoes:
> 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 <sjg@chromium.org>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
>   drivers/rtc/rtc-uclass.c | 18 ++++++++++++++++++
>   include/rtc.h            | 24 ++++++++++++++++++++++++
>   2 files changed, 42 insertions(+)

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-uclass.c b/drivers/rtc/rtc-uclass.c
index 92cc8c5664..a8714156c6 100644
--- a/drivers/rtc/rtc-uclass.c
+++ b/drivers/rtc/rtc-uclass.c
@@ -58,6 +58,24 @@  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);
diff --git a/include/rtc.h b/include/rtc.h
index 6887fe4d42..9538e54b74 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 dm_rtc_read(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len);
 
+/**
+ * dm_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 dm_rtc_write(struct udevice *dev, unsigned int reg,
+		 const u8 *buf, unsigned int len);
+
 /**
  * rtc_read8() - Read an 8-bit register
  *