Skip to contentSkip to conversation

rtc: tegra: Use devm_clk_get_enabled() in probe

PATCH Applied Kartik Rajput 3 participants 7 messages Oct 24, 2025 – Dec 8, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 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. Also remove tegra_rtc_remove() as the clock will automatically be disabled when the device is unbound from the bus.

---
Changes in v4:
* Removed tegra_rtc_remove() as this is not required now.
* Updated commit message to specify this.

---
 drivers/rtc/rtc-tegra.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/rtc/rtc-tegra.c +4 -22
index 46788db89953..e8c83a6a96b3 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,29 +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)
-{
-	struct tegra_rtc_info *info = platform_get_drvdata(pdev);
-
-	clk_disable_unprepare(info->clk);
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -399,7 +382,6 @@ static void tegra_rtc_shutdown(struct platform_device *pdev)
 
 static struct platform_driver tegra_rtc_driver = {
 	.probe = tegra_rtc_probe,
-	.remove = tegra_rtc_remove,
 	.shutdown = tegra_rtc_shutdown,
 	.driver = {
 		.name = "tegra_rtc",
Signature · 1 line
2.43.0
#1 lore raw

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

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 e8c83a6a96b3..9e4e9c88178f 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;
@@ -386,6 +394,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
maintainer Reviewed-by on v4 2/3
#2 lore raw

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

Quoted 58 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.

---
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 +11 -3
index e8c83a6a96b3..9e4e9c88178f 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;

drivers/rtc/rtc-tegra.c static struct platform_driver tegra_rtc_driver = { · line 400

Quoted 7 lines
drivers/rtc/rtc-tegra.c +1 -0
@@ -386,6 +394,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,
  	},
  };

Thanks!
Jon

Signature · 1 line
nvpublic
#3 lore raw

PATCH v4 3/3 rtc: tegra: Replace deprecated SIMPLE_DEV_PM_OPS

In reply to 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.

---
Changes in v4:
* Updated commit subject.

---
 drivers/rtc/rtc-tegra.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/rtc/rtc-tegra.c +2 -4
index 9e4e9c88178f..528e32b7d101 100644
@@ -340,7 +340,6 @@ static int tegra_rtc_probe(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
 static int tegra_rtc_suspend(struct device *dev)
 {
 	struct tegra_rtc_info *info = dev_get_drvdata(dev);
@@ -378,9 +377,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)
 {
@@ -395,7 +393,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
maintainer Reviewed-by on v4 3/3
#4 lore raw

Re: [PATCH v4 3/3] rtc: tegra: Replace deprecated SIMPLE_DEV_PM_OPS

Quoted 38 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.

---
Changes in v4:
* Updated commit subject.

---
  drivers/rtc/rtc-tegra.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/rtc/rtc-tegra.c +1 -3
index 9e4e9c88178f..528e32b7d101 100644
@@ -340,7 +340,6 @@ static int tegra_rtc_probe(struct platform_device *pdev)
  	return 0;
  }
 
-#ifdef CONFIG_PM_SLEEP
  static int tegra_rtc_suspend(struct device *dev)
  {
  	struct tegra_rtc_info *info = dev_get_drvdata(dev);
@@ -378,9 +377,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)
  {

drivers/rtc/rtc-tegra.c static struct platform_driver tegra_rtc_driver = { · line 399

Quoted 8 lines
drivers/rtc/rtc-tegra.c +1 -1
@@ -395,7 +393,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);

Thanks!
Jon

Signature · 1 line
nvpublic
maintainer Reviewed-by on v4 1/3
#5 lore raw
In reply to Kartik Rajput
Quoted 70 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. Also remove tegra_rtc_remove() as the clock will automatically be disabled when the device is unbound from the bus.

---
Changes in v4:
* Removed tegra_rtc_remove() as this is not required now.
* Updated commit message to specify this.

---
  drivers/rtc/rtc-tegra.c | 26 ++++----------------------
  1 file changed, 4 insertions(+), 22 deletions(-)
drivers/rtc/rtc-tegra.c +4 -21
index 46788db89953..e8c83a6a96b3 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,29 +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)
-{
-	struct tegra_rtc_info *info = platform_get_drvdata(pdev);
-
-	clk_disable_unprepare(info->clk);
  }
 
  #ifdef CONFIG_PM_SLEEP

drivers/rtc/rtc-tegra.c static void tegra_rtc_shutdown(struct platform_device *pdev) · line 387

Quoted 7 lines
drivers/rtc/rtc-tegra.c +0 -1
@@ -399,7 +382,6 @@ static void tegra_rtc_shutdown(struct platform_device *pdev)
 
  static struct platform_driver tegra_rtc_driver = {
  	.probe = tegra_rtc_probe,
-	.remove = tegra_rtc_remove,
  	.shutdown = tegra_rtc_shutdown,
  	.driver = {
  		.name = "tegra_rtc",

Thanks!
Jon

Signature · 1 line
nvpublic
maintainer Applied
#6 lore raw
In reply to Kartik Rajput
Quoted 6 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. Also remove tegra_rtc_remove() as the clock will automatically be disabled when the device is unbound from the bus.

Applied, thanks!

[1/3] rtc: tegra: Use devm_clk_get_enabled() in probe

      https://git.kernel.org/abelloni/c/b665c1b620e7
[2/3] rtc: tegra: Add ACPI support
      https://git.kernel.org/abelloni/c/0a293451030b
[3/3] rtc: tegra: Replace deprecated SIMPLE_DEV_PM_OPS
      https://git.kernel.org/abelloni/c/bf5ef3ce42da

Best regards,

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com