Linux RTC
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
To: linux-renesas-soc@vger.kernel.org
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Magnus Damm <magnus.damm@gmail.com>,
	linux-rtc@vger.kernel.org
Subject: [RFC PATCH 4/4] WIP rtc: rzn1: add driver support for R-Car Gen5
Date: Thu, 13 Mar 2025 11:25:45 +0100	[thread overview]
Message-ID: <20250313102546.27335-5-wsa+renesas@sang-engineering.com> (raw)
In-Reply-To: <20250313102546.27335-1-wsa+renesas@sang-engineering.com>

This is not for upstream yet. This is a prototype how R-Car Gen5 can be
integrated into this driver. Bindings need to be updated so that they
enforce two input clocks. This patch is only for discussion.

Not-yet-signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/rtc/rtc-rzn1.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/drivers/rtc/rtc-rzn1.c b/drivers/rtc/rtc-rzn1.c
index f8c9308817ae..313e70070904 100644
--- a/drivers/rtc/rtc-rzn1.c
+++ b/drivers/rtc/rtc-rzn1.c
@@ -17,6 +17,7 @@
 #include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/rtc.h>
@@ -71,6 +72,10 @@ struct rzn1_rtc {
 	struct rtc_time tm_alarm;
 };
 
+struct rzn1_rtc_conf {
+	unsigned int force_scmp:1;
+};
+
 static void rzn1_rtc_get_time_snapshot(struct rzn1_rtc *rtc, struct rtc_time *tm)
 {
 	u32 val;
@@ -369,6 +374,7 @@ static struct rtc_class_ops rzn1_rtc_ops = {
 static int rzn1_rtc_probe(struct platform_device *pdev)
 {
 	struct rzn1_rtc *rtc;
+	const struct rzn1_rtc_conf *config;
 	struct clk *xtal;
 	unsigned long rate;
 	u32 use_scmp = 0;
@@ -405,7 +411,12 @@ static int rzn1_rtc_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
-	/* Only switch to scmp if we have an xtal clock with a valid rate and != 32768 */
+	config = of_device_get_match_data(&pdev->dev);
+
+	/*
+	 * Only switch to scmp if we have an xtal clock with a valid rate plus
+	 * either not equal to 32768 or if it is forced in the config
+	 */
 	xtal = devm_clk_get_optional(&pdev->dev, "xtal");
 	if (IS_ERR(xtal)) {
 		ret = PTR_ERR(xtal);
@@ -418,8 +429,14 @@ static int rzn1_rtc_probe(struct platform_device *pdev)
 			goto dis_runtime_pm;
 		}
 
-		if (rate != 32768)
+		if (rate != 32768 || config->force_scmp)
 			use_scmp = RZN1_RTC_CTL0_SLSB_SCMP;
+	} else {
+		/* We need xtal if force_scmp is set */
+		if (config->force_scmp) {
+			ret = -ENOENT;
+			goto dis_runtime_pm;
+		}
 	}
 
 	if (use_scmp) {
@@ -474,8 +491,17 @@ static void rzn1_rtc_remove(struct platform_device *pdev)
 	pm_runtime_put(&pdev->dev);
 }
 
+static const struct rzn1_rtc_conf rzn1_rtc_conf = {
+	.force_scmp = 0,
+};
+
+static const struct rzn1_rtc_conf rzn1_rtc_conf_gen5 = {
+	.force_scmp = 1,
+};
+
 static const struct of_device_id rzn1_rtc_of_match[] = {
-	{ .compatible	= "renesas,rzn1-rtc" },
+	{ .compatible = "renesas,rzn1-rtc", .data = &rzn1_rtc_conf },
+	{ .compatible = "renesas,rcar-gen5-rtc", .data = &rzn1_rtc_conf_gen5 },
 	{},
 };
 MODULE_DEVICE_TABLE(of, rzn1_rtc_of_match);
-- 
2.47.2


      parent reply	other threads:[~2025-03-13 10:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 10:25 [RFC PATCH 0/4] rtc: rzn1: support XTAL clk and SCMP method Wolfram Sang
2025-03-13 10:25 ` [RFC PATCH 1/4] dt-bindings: rtc: rzn1: add optional second clock Wolfram Sang
2025-03-14  8:41   ` Krzysztof Kozlowski
2025-03-14  8:54     ` Wolfram Sang
2025-03-13 10:25 ` [RFC PATCH 3/4] rtc: rzn1: support input frequencies other than 32768Hz Wolfram Sang
2025-03-13 11:29   ` Wolfram Sang
2025-03-13 10:25 ` Wolfram Sang [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=20250313102546.27335-5-wsa+renesas@sang-engineering.com \
    --to=wsa+renesas@sang-engineering.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=geert+renesas@glider.be \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=miquel.raynal@bootlin.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox