[PATCH v6 28/35] i2c: tegra: Factor out hardware initialization into separate function
From: Dmitry Osipenko
Date: Mon Sep 07 2020 - 22:14:20 EST
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@xxxxxxxxx>
---
drivers/i2c/busses/i2c-tegra.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 2e7beadd381f..44a8c7ae8509 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -1655,6 +1655,21 @@ 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 tegra_i2c_dev *i2c_dev;
@@ -1724,16 +1739,9 @@ static int tegra_i2c_probe(struct platform_device *pdev)
pm_runtime_enable(i2c_dev->dev);
- err = pm_runtime_get_sync(i2c_dev->dev);
- if (err < 0) {
- dev_err(i2c_dev->dev, "runtime resume failed: %d\n", err);
- goto put_rpm;
- }
-
- /* initialize hardware state */
- err = tegra_i2c_init(i2c_dev);
+ err = tegra_i2c_init_hardware(i2c_dev);
if (err)
- goto put_rpm;
+ goto release_rpm;
i2c_dev->adapter.dev.of_node = i2c_dev->dev->of_node;
i2c_dev->adapter.dev.parent = i2c_dev->dev;
@@ -1755,14 +1763,11 @@ static int tegra_i2c_probe(struct platform_device *pdev)
err = i2c_add_numbered_adapter(&i2c_dev->adapter);
if (err)
- goto put_rpm;
-
- pm_runtime_put(i2c_dev->dev);
+ goto release_rpm;
return 0;
-put_rpm:
- pm_runtime_put(i2c_dev->dev);
+release_rpm:
pm_runtime_disable(i2c_dev->dev);
tegra_i2c_release_dma(i2c_dev);
--
2.27.0