The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@nabladev.com>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Krzysztof Kozlowski <krzk+dt@kernel.org>,
	linux-kernel@vger.kernel.org, Conor Dooley <conor+dt@kernel.org>,
	devicetree@vger.kernel.org, Rob Herring <robh@kernel.org>,
	linux-rtc@vger.kernel.org, Heiko Schocher <hs@nabladev.com>
Subject: [PATCH v2 3/3] rtc: rs5c372: support eco mode on R2223x
Date: Tue, 25 Aug 2026 09:19:18 +0200	[thread overview]
Message-ID: <20260825071927.4090460-4-hs@nabladev.com> (raw)
In-Reply-To: <20260825071927.4090460-1-hs@nabladev.com>

The R2223x can run in an eco mode that lowers its current consumption
from the backup supply. Follow the ricoh,eco-mode property from the
device tree: enable the mode when the property is set, turn it off when
it is not set, as the bit is in CTRL2 register, which is backed by the
same supply and keeps its contents across a reset, and no other path in
the driver touches it.

Signed-off-by: Heiko Schocher <hs@nabladev.com>
---

Changes in v2:
- Fixed results of a local run of the sashiko review prompts: apply the
  device tree setting in both directions. v1 only set the eco bit, so
  the mode stayed on when a board dropped the property.
- Leave rs5c372_probe() through goto exit like its other error paths,
  instead of returning directly.

 drivers/rtc/rtc-rs5c372.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index c65b76cc0dc6..9ab6f2c28f7b 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -52,6 +52,7 @@
 #define RS5C_REG_CTRL2		15
 #	define RS5C372_CTRL2_24		(1 << 5)
 #	define RS5C_CTRL2_XSTP		(1 << 4)	/* only if !R2x2x */
+#	define R2223x_CTRL2_ECO		(1 << 7)	/* only if  R2223x */
 #	define R2x2x_CTRL2_VDET		(1 << 6)	/* only if  R2x2x */
 #	define R2x2x_CTRL2_XSTP		(1 << 5)	/* only if  R2x2x */
 #	define R2x2x_CTRL2_PON		(1 << 4)	/* only if  R2x2x */
@@ -807,6 +808,24 @@ static int rs5c_oscillator_setup(struct rs5c372 *rs5c372)
 	return 0;
 }
 
+static int rs5c372_set_eco_mode(struct rs5c372 *rs5c372, bool eco)
+{
+	struct i2c_client *client = rs5c372->client;
+	int ctrl2;
+
+	ctrl2 = i2c_smbus_read_byte_data(client, RS5C_ADDR(RS5C_REG_CTRL2));
+	if (ctrl2 < 0)
+		return ctrl2;
+
+	if (eco)
+		ctrl2 |= R2223x_CTRL2_ECO;
+	else
+		ctrl2 &= ~R2223x_CTRL2_ECO;
+
+	return i2c_smbus_write_byte_data(client, RS5C_ADDR(RS5C_REG_CTRL2),
+					 ctrl2);
+}
+
 static int rs5c372_probe(struct i2c_client *client)
 {
 	int err = 0;
@@ -903,6 +922,15 @@ static int rs5c372_probe(struct i2c_client *client)
 			rs5c372->time24 ? "24hr" : "am/pm"
 			);
 
+	if (rs5c372->type == rtc_r2223x) {
+		bool eco = device_property_read_bool(&client->dev,
+						     "ricoh,eco-mode");
+
+		err = rs5c372_set_eco_mode(rs5c372, eco);
+		if (err < 0)
+			goto exit;
+	}
+
 	/* REVISIT use client->irq to register alarm irq ... */
 	rs5c372->rtc = devm_rtc_device_register(&client->dev,
 					rs5c372_driver.driver.name,
-- 
2.55.0


      parent reply	other threads:[~2026-08-25  7:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  7:19 [PATCH v2 0/3] rtc: rs5c372: add Ricoh R2223x support Heiko Schocher
2026-08-25  7:19 ` [PATCH v2 1/3] dt-bindings: rtc: add ricoh,r2223x binding Heiko Schocher
2026-08-25  7:19 ` [PATCH v2 2/3] rtc: rs5c372: add support for Ricoh R2223x Heiko Schocher
2026-08-25  7:19 ` Heiko Schocher [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=20260825071927.4090460-4-hs@nabladev.com \
    --to=hs@nabladev.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=robh@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