Skip to contentSkip to conversation

rtc: tegra: Use devm_clk_get_enabled() in probe

PATCH Superseded Kartik Rajput 2 participants 6 messages Oct 23, 2025

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 rtc: tegra: Use devm_clk_get_enabled() in probe

Simplify clock management by replacing devm_clk_get() and manual clock enable/disable with devm_clk_get_enabled(). This also simplifies the error handling logic.

---
 drivers/rtc/rtc-tegra.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/rtc/rtc-tegra.c +4 -14
index 46788db89953..51f5bb55c176 100644
@@ -300,14 +300,10 @@ static int tegra_rtc_probe(struct platform_device *pdev)
 	info->rtc->ops = &tegra_rtc_ops;
 	info->rtc->range_max = U32_MAX;
 
-	info->clk = devm_clk_get(&pdev->dev, NULL);
+	info->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(info->clk))
 		return PTR_ERR(info->clk);
 
-	ret = clk_prepare_enable(info->clk);
-	if (ret < 0)
-		return ret;
-
 	/* set context info */
 	info->pdev = pdev;
 	spin_lock_init(&info->lock);
@@ -324,22 +320,16 @@ static int tegra_rtc_probe(struct platform_device *pdev)
 	ret = devm_request_irq(&pdev->dev, info->irq, tegra_rtc_irq_handler,
 			       IRQF_TRIGGER_HIGH, dev_name(&pdev->dev),
 			       &pdev->dev);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to request interrupt: %d\n", ret);
-		goto disable_clk;
-	}
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "failed to request interrupt\n");
 
 	ret = devm_rtc_register_device(info->rtc);
 	if (ret)
-		goto disable_clk;
+		return ret;
 
 	dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n");
 
 	return 0;
-
-disable_clk:
-	clk_disable_unprepare(info->clk);
-	return ret;
 }
 
 static void tegra_rtc_remove(struct platform_device *pdev)
Signature · 1 line
2.43.0
#3 lore raw

PATCH v3 3/3 rtc: tegra: Drop deprecated SIMPLE_DEV_PM_OPS

Replace deprecated SIMPLE_DEV_PM_OPS with DEFINE_SIMPLE_DEV_PM_OPS macro and use pm_sleep_ptr() to initialize pm_ops. This also allows us to drop the checks for CONFIG_PM_SLEEP.

---
 drivers/rtc/rtc-tegra.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/rtc/rtc-tegra.c +2 -4
index ad0c57ce87df..3ee8e1c97a5a 100644
@@ -347,7 +347,6 @@ static void tegra_rtc_remove(struct platform_device *pdev)
 	clk_disable_unprepare(info->clk);
 }
 
-#ifdef CONFIG_PM_SLEEP
 static int tegra_rtc_suspend(struct device *dev)
 {
 	struct tegra_rtc_info *info = dev_get_drvdata(dev);
@@ -385,9 +384,8 @@ static int tegra_rtc_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
-static SIMPLE_DEV_PM_OPS(tegra_rtc_pm_ops, tegra_rtc_suspend, tegra_rtc_resume);
+static DEFINE_SIMPLE_DEV_PM_OPS(tegra_rtc_pm_ops, tegra_rtc_suspend, tegra_rtc_resume);
 
 static void tegra_rtc_shutdown(struct platform_device *pdev)
 {
@@ -403,7 +401,7 @@ static struct platform_driver tegra_rtc_driver = {
 		.name = "tegra_rtc",
 		.of_match_table = tegra_rtc_dt_match,
 		.acpi_match_table = tegra_rtc_acpi_match,
-		.pm = &tegra_rtc_pm_ops,
+		.pm = pm_sleep_ptr(&tegra_rtc_pm_ops),
 	},
 };
 module_platform_driver(tegra_rtc_driver);
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 2/3 rtc: tegra: Add ACPI support

In reply to Kartik Rajput

Add ACPI support for Tegra RTC, which is available on Tegra241 and Tegra410. Both Tegra241 and Tegra410 use the same ACPI ID 'NVDA0280'. When ACPI boot is used, the RTC clock is configured by UEFI before the kernel boots. On device-tree boot, the probe must fail if clocks are not provided in the device-tree.

---
Changes in v3:
* Add patch to use devm_clk_get_enabled().
* Add patch to use pm_sleep_ptr().
* Update commit message to specify clocks are requried for device-tree boot.
Changes in v2:
* Dropped "linux/acpi.h" from includes.
* Dropped redundant ', 0' part from tegra_rtc_acpi_match.
* Replaced "is_of_node(dev_fwnode(&pdev->dev))" with "dev_of_node(&pdev->dev)" to check device of node.
* Dropped redundant of_node checks before accessing clock related APIs.

---
 drivers/rtc/rtc-tegra.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/rtc/rtc-tegra.c +12 -3
index 51f5bb55c176..ad0c57ce87df 100644
@@ -274,6 +274,12 @@ static const struct of_device_id tegra_rtc_dt_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tegra_rtc_dt_match);
 
+static const struct acpi_device_id tegra_rtc_acpi_match[] = {
+	{ "NVDA0280" },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, tegra_rtc_acpi_match);
+
 static int tegra_rtc_probe(struct platform_device *pdev)
 {
 	struct tegra_rtc_info *info;
@@ -300,9 +306,11 @@ static int tegra_rtc_probe(struct platform_device *pdev)
 	info->rtc->ops = &tegra_rtc_ops;
 	info->rtc->range_max = U32_MAX;
 
-	info->clk = devm_clk_get_enabled(&pdev->dev, NULL);
-	if (IS_ERR(info->clk))
-		return PTR_ERR(info->clk);
+	if (dev_of_node(&pdev->dev)) {
+		info->clk = devm_clk_get_enabled(&pdev->dev, NULL);
+		if (IS_ERR(info->clk))
+			return PTR_ERR(info->clk);
+	}
 
 	/* set context info */
 	info->pdev = pdev;
@@ -394,6 +402,7 @@ static struct platform_driver tegra_rtc_driver = {
 	.driver = {
 		.name = "tegra_rtc",
 		.of_match_table = tegra_rtc_dt_match,
+		.acpi_match_table = tegra_rtc_acpi_match,
 		.pm = &tegra_rtc_pm_ops,
 	},
 };
Signature · 1 line
2.43.0
Reviewed-by on v3 2/3
#2 lore raw

Re: [PATCH v3 2/3] rtc: tegra: Add ACPI support

Quoted 5 lines · Kartik Rajput

Add ACPI support for Tegra RTC, which is available on Tegra241 and Tegra410. Both Tegra241 and Tegra410 use the same ACPI ID 'NVDA0280'. When ACPI boot is used, the RTC clock is configured by UEFI before the kernel boots. On device-tree boot, the probe must fail if clocks are not provided in the device-tree.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v3 3/3
#4 lore raw

Re: [PATCH v3 3/3] rtc: tegra: Drop deprecated SIMPLE_DEV_PM_OPS

In reply to Kartik Rajput
Quoted 3 lines · Kartik Rajput

Replace deprecated SIMPLE_DEV_PM_OPS with DEFINE_SIMPLE_DEV_PM_OPS macro and use pm_sleep_ptr() to initialize pm_ops. This also allows us to drop the checks for CONFIG_PM_SLEEP.

Probably Subject also should be "Replace deprecated...".

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v3 1/3
#5 lore raw
In reply to Kartik Rajput
Quoted 3 lines · Kartik Rajput

Simplify clock management by replacing devm_clk_get() and manual clock enable/disable with devm_clk_get_enabled(). This also simplifies the error handling logic.

with the caveat that you need to remove ->remove() altogether as well.

Signature · 2 lines
With Best Regards,
Andy Shevchenko