All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: u-boot@lists.denx.de
Subject: [PATCH v2 01/10] rtc: add rtc_read helper and ->read method
Date: Wed, 20 May 2020 00:01:08 +0200	[thread overview]
Message-ID: <20200519220117.24448-2-rasmus.villemoes@prevas.dk> (raw)
In-Reply-To: <20200519220117.24448-1-rasmus.villemoes@prevas.dk>

Some users may want to read multiple consecutive 8-bit
registers. Instead of each caller having to implement the loop,
provide a rtc_read() helper. Also, allow a driver to provide a ->read
method, which can be more efficient than reading one register at a
time.

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            | 23 +++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/drivers/rtc/rtc-uclass.c b/drivers/rtc/rtc-uclass.c
index a0a238aedd..44d76bb70f 100644
--- a/drivers/rtc/rtc-uclass.c
+++ b/drivers/rtc/rtc-uclass.c
@@ -39,6 +39,24 @@ int dm_rtc_reset(struct udevice *dev)
 	return ops->reset(dev);
 }
 
+int rtc_read(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len)
+{
+	struct rtc_ops *ops = rtc_get_ops(dev);
+
+	assert(ops);
+	if (ops->read)
+		return ops->read(dev, reg, buf, len);
+	if (!ops->read8)
+		return -ENOSYS;
+	while (len--) {
+		int ret = ops->read8(dev, reg++);
+		if (ret < 0)
+			return ret;
+		*buf++ = 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 8aabfc1162..1c9c09fef8 100644
--- a/include/rtc.h
+++ b/include/rtc.h
@@ -55,6 +55,18 @@ struct rtc_ops {
 	 */
 	int (*reset)(struct udevice *dev);
 
+	/**
+	 * read() - Read multiple 8-bit registers
+	 *
+	 * @dev:	Device to read from
+	 * @reg:	First register to read
+	 * @buf:	Output buffer
+	 * @len:	Number of registers to read
+	 * @return 0 if OK, -ve on error
+	 */
+	int (*read)(struct udevice *dev, unsigned int reg,
+			   u8 *buf, unsigned int len);
+
 	/**
 	 * read8() - Read an 8-bit register
 	 *
@@ -109,6 +121,17 @@ int dm_rtc_set(struct udevice *dev, struct rtc_time *time);
  */
 int dm_rtc_reset(struct udevice *dev);
 
+/**
+ * rtc_read() - Read multiple 8-bit registers
+ *
+ * @dev:	Device to read from
+ * @reg:	First register to read
+ * @buf:	Output buffer
+ * @len:	Number of registers to read
+ * @return 0 if OK, -ve on error
+ */
+int rtc_read(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len);
+
 /**
  * rtc_read8() - Read an 8-bit register
  *
-- 
2.23.0

  reply	other threads:[~2020-05-19 22:01 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04 21:20 [PATCH 0/6] rtc: add rtc_{read,write}8_array and rtc command Rasmus Villemoes
2020-05-04 21:20 ` [PATCH 1/6] rtc: add rtc_read8_array helper and ->read8_array method Rasmus Villemoes
2020-05-06  3:42   ` Simon Glass
2020-05-06  8:13     ` Rasmus Villemoes
2020-05-04 21:20 ` [PATCH 2/6] rtc: add rtc_write8_array() helper Rasmus Villemoes
2020-05-06  3:42   ` Simon Glass
2020-05-04 21:20 ` [PATCH 3/6] rtc: fall back to ->{read, write}8_array if ->{read, write}8 are not provided Rasmus Villemoes
2020-05-06  3:42   ` [PATCH 3/6] rtc: fall back to ->{read,write}8_array if ->{read,write}8 " Simon Glass
2020-05-04 21:20 ` [PATCH 4/6] rtc: pcf2127: provide ->read8_array method Rasmus Villemoes
2020-05-06  3:42   ` Simon Glass
2020-05-04 21:20 ` [PATCH 5/6] rtc: pcf2127: provide ->write8_array method Rasmus Villemoes
2020-05-06  3:42   ` Simon Glass
2020-05-04 21:20 ` [PATCH 6/6] rtc: add rtc command Rasmus Villemoes
2020-05-06  3:42   ` Simon Glass
2020-05-19 22:01 ` [PATCH v2 00/10] new rtc methods, rtc command, and tests Rasmus Villemoes
2020-05-19 22:01   ` Rasmus Villemoes [this message]
2020-05-19 22:01   ` [PATCH v2 02/10] rtc: add rtc_write() helper Rasmus Villemoes
2020-05-19 22:01   ` [PATCH v2 03/10] rtc: fall back to ->{read, write} if ->{read, write}8 are not provided Rasmus Villemoes
2020-05-19 22:01   ` [PATCH v2 04/10] rtc: pcf2127: provide ->read method Rasmus Villemoes
2020-05-19 22:01   ` [PATCH v2 05/10] rtc: pcf2127: provide ->write method Rasmus Villemoes
2020-05-19 22:01   ` [PATCH v2 06/10] rtc: add rtc command Rasmus Villemoes
2020-05-31 14:07     ` Simon Glass
2020-06-02  9:13       ` Rasmus Villemoes
2020-06-02 13:22         ` Simon Glass
2020-06-02 14:36           ` Rasmus Villemoes
2020-06-02 19:29             ` Simon Glass
2020-05-19 22:01   ` [PATCH v2 07/10] rtc: sandbox-rtc: fix set method Rasmus Villemoes
2020-05-31 14:07     ` Simon Glass
2020-05-19 22:01   ` [PATCH v2 08/10] rtc: i2c_rtc_emul: catch any write to the "reset" register Rasmus Villemoes
2020-05-31 14:07     ` Simon Glass
2020-05-19 22:01   ` [PATCH v2 09/10] test: dm: rtc: add test of rtc_read, rtc_write Rasmus Villemoes
2020-05-31 14:07     ` Simon Glass
2020-05-19 22:01   ` [PATCH v2 10/10] test: dm: rtc: add tests of rtc shell command Rasmus Villemoes
2020-05-31 14:07     ` Simon Glass
2020-06-02  9:15       ` Rasmus Villemoes
2020-06-02 18:40   ` [PATCH v2 00/10] new rtc methods, rtc command, and tests Rasmus Villemoes
2020-06-02 19:29     ` Simon Glass
2020-06-02 19:44       ` Rasmus Villemoes
2020-06-02 20:56         ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200519220117.24448-2-rasmus.villemoes@prevas.dk \
    --to=rasmus.villemoes@prevas.dk \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.