diff mbox series

[RFC,4/4] WIP rtc: rzn1: add driver support for R-Car Gen5

Message ID 20250313102546.27335-5-wsa+renesas@sang-engineering.com (mailing list archive)
State New
Delegated to: Geert Uytterhoeven
Headers show
Series rtc: rzn1: support XTAL clk and SCMP method | expand

Commit Message

Wolfram Sang March 13, 2025, 10:25 a.m. UTC
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 mbox series

Patch

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);