linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: linux-rtc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: [PATCH 16/16] rtc: rv3029: add nvram support
Date: Sat, 14 Dec 2019 23:10:22 +0100	[thread overview]
Message-ID: <20191214221022.622482-17-alexandre.belloni@bootlin.com> (raw)
In-Reply-To: <20191214221022.622482-1-alexandre.belloni@bootlin.com>

Export the 8 byte RAM using nvmem.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-rv3029c2.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index 5610ff562652..4eda0db72b66 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -109,10 +109,8 @@
 #define RV3029_CONTROL_E2P_TOV_MASK	0x3F /* XTAL turnover temp mask */
 
 /* user ram section */
-#define RV3029_USR1_RAM_PAGE		0x38
-#define RV3029_USR1_SECTION_LEN		0x04
-#define RV3029_USR2_RAM_PAGE		0x3C
-#define RV3029_USR2_SECTION_LEN		0x04
+#define RV3029_RAM_PAGE			0x38
+#define RV3029_RAM_SECTION_LEN		8
 
 struct rv3029_data {
 	struct device		*dev;
@@ -474,6 +472,18 @@ static int rv3029_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
 	}
 }
 
+static int rv3029_nvram_write(void *priv, unsigned int offset, void *val,
+			      size_t bytes)
+{
+	return regmap_bulk_write(priv, RV3029_RAM_PAGE + offset, val, bytes);
+}
+
+static int rv3029_nvram_read(void *priv, unsigned int offset, void *val,
+			     size_t bytes)
+{
+	return regmap_bulk_read(priv, RV3029_RAM_PAGE + offset, val, bytes);
+}
+
 static const struct rv3029_trickle_tab_elem {
 	u32 r;		/* resistance in ohms */
 	u8 conf;	/* trickle config bits */
@@ -694,6 +704,15 @@ static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq,
 			const char *name)
 {
 	struct rv3029_data *rv3029;
+	struct nvmem_config nvmem_cfg = {
+		.name = "rv3029_nvram",
+		.word_size = 1,
+		.stride = 1,
+		.size = RV3029_RAM_SECTION_LEN,
+		.type = NVMEM_TYPE_BATTERY_BACKED,
+		.reg_read = rv3029_nvram_read,
+		.reg_write = rv3029_nvram_write,
+	};
 	int rc = 0;
 
 	rv3029 = devm_kzalloc(dev, sizeof(*rv3029), GFP_KERNEL);
@@ -731,7 +750,14 @@ static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq,
 	rv3029->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
 	rv3029->rtc->range_max = RTC_TIMESTAMP_END_2079;
 
-	return rtc_register_device(rv3029->rtc);
+	rc = rtc_register_device(rv3029->rtc);
+	if (rc)
+		return rc;
+
+	nvmem_cfg.priv = rv3029->regmap;
+	rtc_nvmem_register(rv3029->rtc, &nvmem_cfg);
+
+	return 0;
 }
 
 static const struct regmap_range rv3029_holes_range[] = {
-- 
2.23.0


      parent reply	other threads:[~2019-12-14 22:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-14 22:10 [PATCH 00/16] rtc: rv3029: cleanup and features Alexandre Belloni
2019-12-14 22:10 ` [PATCH 01/16] rtc: rv3029: use proper name for the driver Alexandre Belloni
2019-12-14 22:10 ` [PATCH 02/16] rtc: rv3029: let regmap validate the register ranges Alexandre Belloni
2019-12-14 22:10 ` [PATCH 03/16] rtc: rv3029: remove open coded regmap_update_bits Alexandre Belloni
2019-12-14 22:10 ` [PATCH 04/16] rtc: rv3029: remove race condition when update STATUS Alexandre Belloni
2019-12-14 22:10 ` [PATCH 05/16] rtc: rv3029: avoid reading the status register uselessly Alexandre Belloni
2019-12-14 22:10 ` [PATCH 06/16] rtc: rv3029: get rid of rv3029_get_sr Alexandre Belloni
2019-12-14 22:10 ` [PATCH 07/16] rtc: rv3029: simplify rv3029_alarm_irq_enable Alexandre Belloni
2019-12-14 22:10 ` [PATCH 08/16] rtc: rv3029: simplify rv3029_set_alarm Alexandre Belloni
2019-12-14 22:10 ` [PATCH 09/16] rtc: rv3029: drop rv3029_read_regs and rv3029_write_regs Alexandre Belloni
2019-12-14 22:10 ` [PATCH 10/16] rtc: rv3029: add RTC_VL_READ and RTC_VL_CLEAR support Alexandre Belloni
2019-12-14 22:10 ` [PATCH 11/16] rtc: rv3029: correctly handle PON and VLOW2 Alexandre Belloni
2019-12-14 22:10 ` [PATCH 12/16] rtc: rv3029: convert to devm_rtc_allocate_device Alexandre Belloni
2019-12-14 22:10 ` [PATCH 13/16] rtc: rv3029: let the core handle rtc range Alexandre Belloni
2019-12-14 22:10 ` [PATCH 14/16] rtc: rv3029: remove useless error messages Alexandre Belloni
2019-12-14 22:10 ` [PATCH 15/16] rtc: rv3029: annotate init and exit functions Alexandre Belloni
2019-12-14 22:10 ` Alexandre Belloni [this message]

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=20191214221022.622482-17-alexandre.belloni@bootlin.com \
    --to=alexandre.belloni@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).