All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frieder Schrempf <frieder@fris.de>
To: Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org
Cc: Frieder Schrempf <frieder.schrempf@kontron.de>,
	keliu <liuke94@huawei.com>,
	Shang XiaoJing <shangxiaojing@huawei.com>,
	Vincent Whitchurch <vincent.whitchurch@axis.com>,
	Yang Yingliang <yangyingliang@huawei.com>
Subject: [PATCH 5/7] rtc: class: Support setting backup switch mode from devicetree
Date: Wed,  1 Feb 2023 15:34:27 +0100	[thread overview]
Message-ID: <20230201143431.863784-6-frieder@fris.de> (raw)
In-Reply-To: <20230201143431.863784-1-frieder@fris.de>

From: Frieder Schrempf <frieder.schrempf@kontron.de>

Some RTC devices like the RV3028 have BSM disabled as factory default.
This makes the RTC quite useless if it is expected to preserve the
time on hardware that has a battery buffered supply for the RTC.

Let boards that have a buffered supply for the RTC available force
the BSM to the desired value via devicetree by setting the
'backup-switch-mode' property.

Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
---
 drivers/rtc/class.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index e5b7b48cffac..79417d1fbeee 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -391,6 +391,11 @@ int __devm_rtc_register_device(struct module *owner, struct rtc_device *rtc)
 	struct rtc_wkalrm alrm;
 	int err;
 
+	struct rtc_param bsm = {
+		.param = RTC_PARAM_BACKUP_SWITCH_MODE,
+		.uvalue = RTC_BSM_DISABLED,
+	};
+
 	if (!rtc->ops) {
 		dev_dbg(&rtc->dev, "no ops set\n");
 		return -EINVAL;
@@ -402,6 +407,15 @@ int __devm_rtc_register_device(struct module *owner, struct rtc_device *rtc)
 	if (rtc->ops->set_offset)
 		set_bit(RTC_FEATURE_CORRECTION, rtc->features);
 
+	/* setup backup switching mode */
+	if (test_bit(RTC_FEATURE_BACKUP_SWITCH_MODE, rtc->features) &&
+	    !device_property_read_u32(rtc->dev.parent, "backup-switch-mode",
+				      (u32 *)&bsm.uvalue)) {
+		err = rtc->ops->param_set(rtc->dev.parent, &bsm);
+		if (err && err != -EINVAL)
+			return err;
+	}
+
 	rtc->owner = owner;
 	rtc_device_get_offset(rtc);
 
-- 
2.39.1


  parent reply	other threads:[~2023-02-01 14:43 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-01 14:34 [PATCH 0/7] Enable backup switch mode on RTCs via devicetree Frieder Schrempf
2023-02-01 14:34 ` Frieder Schrempf
2023-02-01 14:34 ` [PATCH 1/7] dt-bindings: rtc: Move RV3028 to separate binding file Frieder Schrempf
2023-02-01 20:10   ` Rob Herring
2023-02-02  9:10   ` Krzysztof Kozlowski
2023-02-02 10:17     ` Frieder Schrempf
2023-02-01 14:34 ` [PATCH 2/7] dt-bindings: rtc: Add backup-switch-mode property Frieder Schrempf
2023-02-01 14:34 ` [PATCH 3/7] dt-bindings: rtc: microcrystal,rv3032: " Frieder Schrempf
2023-02-01 14:34 ` [PATCH 4/7] rtc: Move BSM defines to separate header for DT usage Frieder Schrempf
2023-02-02 23:22   ` kernel test robot
2023-02-01 14:34 ` Frieder Schrempf [this message]
2023-02-01 14:34 ` [PATCH 6/7] arm64: dts: imx8mm-kontron: Remove useless trickle-diode-disable from RTC node Frieder Schrempf
2023-02-01 14:34   ` Frieder Schrempf
2023-02-01 14:34 ` [PATCH 7/7] arm64: dts: imx8mm-kontron: Enable backup switch mode for RTC on OSM-S module Frieder Schrempf
2023-02-01 14:34   ` Frieder Schrempf
2023-02-01 16:15 ` [PATCH 0/7] Enable backup switch mode on RTCs via devicetree Alexandre Belloni
2023-02-01 16:15   ` Alexandre Belloni
2023-02-01 16:26   ` Frieder Schrempf
2023-02-01 16:26     ` Frieder Schrempf
2023-02-13  9:18     ` Frieder Schrempf
2023-02-13  9:18       ` Frieder Schrempf
2023-03-06 13:27       ` Frieder Schrempf
2023-03-06 13:27         ` Frieder Schrempf
2023-03-22 13:14         ` Frieder Schrempf
2023-03-22 13:14           ` Frieder Schrempf
2023-03-22 22:19           ` Alexandre Belloni
2023-03-22 22:19             ` Alexandre Belloni
2023-03-28  7:10             ` Frieder Schrempf
2023-03-28  7:10               ` Frieder Schrempf

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=20230201143431.863784-6-frieder@fris.de \
    --to=frieder@fris.de \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=frieder.schrempf@kontron.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=liuke94@huawei.com \
    --cc=shangxiaojing@huawei.com \
    --cc=vincent.whitchurch@axis.com \
    --cc=yangyingliang@huawei.com \
    /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.