diff mbox series

[2/6] rtc: add rtc_write8_array() helper

Message ID 20200504212032.3759-3-rasmus.villemoes@prevas.dk
State New
Headers show
Series rtc: add rtc_{read,write}8_array and rtc command | expand

Commit Message

Rasmus Villemoes May 4, 2020, 9:20 p.m. UTC
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(+)

Comments

Simon Glass May 6, 2020, 3:42 a.m. UTC | #1
Hi Rasmus,

On Mon, 4 May 2020 at 15:20, Rasmus Villemoes
<rasmus.villemoes at prevas.dk> wrote:
>
> 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(+)
>
> 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)

I wonder if we could call this rtc_write() ?

Reviewed-by: Simon Glass <sjg at chromium.org>
diff mbox series

Patch

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
  *