diff mbox series

[v7,26/34] i2c: tegra: Factor out hardware initialization into separate function

Message ID 20200908224006.25636-27-digetx@gmail.com
State Accepted
Commit d380d48ff376d6e98ce0c07a70487beb5d05cb4b
Headers show
Series Improvements for Tegra I2C driver | expand

Commit Message

Dmitry Osipenko Sept. 8, 2020, 10:39 p.m. UTC
Factor out hardware initialization into a separate function from the probe
function. The only place where runtime PM needs to be resumed during probe
is the place of hardware initialization, hence it makes sense to factor
out it in order to have a bit cleaner error handling in tegra_i2c_probe().

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/i2c/busses/i2c-tegra.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

Comments

Thierry Reding Sept. 17, 2020, 12:06 p.m. UTC | #1
On Wed, Sep 09, 2020 at 01:39:58AM +0300, Dmitry Osipenko wrote:
> Factor out hardware initialization into a separate function from the probe

> function. The only place where runtime PM needs to be resumed during probe

> is the place of hardware initialization, hence it makes sense to factor

> out it in order to have a bit cleaner error handling in tegra_i2c_probe().

> 

> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

> ---

>  drivers/i2c/busses/i2c-tegra.c | 32 +++++++++++++++++++-------------

>  1 file changed, 19 insertions(+), 13 deletions(-)


Not really sure this is worth it, but since I don't feel strongly, I'll
leave this up to Wolfram to decide:

Acked-by: Thierry Reding <treding@nvidia.com>
Thierry Reding Sept. 21, 2020, 10:20 a.m. UTC | #2
On Wed, 09 Sep 2020 01:39:58 +0300, Dmitry Osipenko wrote:
> Factor out hardware initialization into a separate function from the probe

> function. The only place where runtime PM needs to be resumed during probe

> is the place of hardware initialization, hence it makes sense to factor

> out it in order to have a bit cleaner error handling in tegra_i2c_probe().

> 

> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

> Acked-by: Thierry Reding <treding@nvidia.com>

> ---

>  drivers/i2c/busses/i2c-tegra.c | 32 +++++++++++++++++++-------------

>  1 file changed, 19 insertions(+), 13 deletions(-)


Tested-by: Thierry Reding <treding@nvidia.com>
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index e071de9ce106..2f39366b6d55 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -1661,9 +1661,23 @@  static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev)
 	clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks);
 }
 
+static int tegra_i2c_init_hardware(struct tegra_i2c_dev *i2c_dev)
+{
+	int ret;
+
+	ret = pm_runtime_get_sync(i2c_dev->dev);
+	if (ret < 0)
+		dev_err(i2c_dev->dev, "runtime resume failed: %d\n", ret);
+	else
+		ret = tegra_i2c_init(i2c_dev);
+
+	pm_runtime_put(i2c_dev->dev);
+
+	return ret;
+}
+
 static int tegra_i2c_probe(struct platform_device *pdev)
 {
-	struct device *dev = &pdev->dev;
 	struct tegra_i2c_dev *i2c_dev;
 	struct resource *res;
 	int ret;
@@ -1729,15 +1743,10 @@  static int tegra_i2c_probe(struct platform_device *pdev)
 	if (!i2c_dev->is_vi)
 		pm_runtime_irq_safe(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
-	ret = pm_runtime_get_sync(i2c_dev->dev);
-	if (ret < 0) {
-		dev_err(dev, "runtime resume failed\n");
-		goto put_rpm;
-	}
 
-	ret = tegra_i2c_init(i2c_dev);
+	ret = tegra_i2c_init_hardware(i2c_dev);
 	if (ret)
-		goto put_rpm;
+		goto release_rpm;
 
 	i2c_set_adapdata(&i2c_dev->adapter, i2c_dev);
 	i2c_dev->adapter.dev.of_node = pdev->dev.of_node;
@@ -1758,14 +1767,11 @@  static int tegra_i2c_probe(struct platform_device *pdev)
 
 	ret = i2c_add_numbered_adapter(&i2c_dev->adapter);
 	if (ret)
-		goto put_rpm;
-
-	pm_runtime_put(&pdev->dev);
+		goto release_rpm;
 
 	return 0;
 
-put_rpm:
-	pm_runtime_put_sync(&pdev->dev);
+release_rpm:
 	pm_runtime_disable(&pdev->dev);
 
 	tegra_i2c_release_dma(i2c_dev);