[PATCH v5 26/36] i2c: tegra: Factor out hardware initialization into separate function
From: Dmitry Osipenko
Date: Sun Sep 06 2020 - 14:54:26 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 | 36 ++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index b5ec540ae2c6..5fe138ead45e 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -1684,6 +1684,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);
+ return ret;
+ }
+
+ 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;
@@ -1753,16 +1770,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 disable_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;
@@ -1784,15 +1794,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);
-disable_rpm:
+release_rpm:
pm_runtime_disable(i2c_dev->dev);
tegra_i2c_release_dma(i2c_dev);
--
2.27.0