[PATCH v3 21/22] i2c: tegra: Initialization div-clk rate unconditionally

From: Dmitry Osipenko
Date: Wed Sep 02 2020 - 20:54:49 EST


It doesn't make sense to conditionalize the div-clk rate changes because
rate is fixed and it won't ever change once it's set at the driver's probe
time. All further changes are NO-OPs because CCF caches rate and skips
rate-change if rate is unchanged.

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

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 79caf87bb4c0..bc7954c8a5a0 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -601,7 +601,7 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev)
return -ETIMEDOUT;
}

-static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit)
+static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)
{
u32 val, clk_divisor, clk_multiplier, tsu_thd, tlow, thigh;
int err;
@@ -656,16 +656,14 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit)
if (i2c_dev->hw->has_interface_timing_reg && tsu_thd)
i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1);

- if (!clk_reinit) {
- clk_multiplier = (tlow + thigh + 2);
- clk_multiplier *= (i2c_dev->clk_divisor_non_hs_mode + 1);
- err = clk_set_rate(i2c_dev->div_clk,
- i2c_dev->bus_clk_rate * clk_multiplier);
- if (err) {
- dev_err(i2c_dev->dev,
- "failed to set div-clk rate: %d\n", err);
- return err;
- }
+ clk_multiplier = tlow + thigh + 2;
+ clk_multiplier *= i2c_dev->clk_divisor_non_hs_mode + 1;
+
+ err = clk_set_rate(i2c_dev->div_clk,
+ i2c_dev->bus_clk_rate * clk_multiplier);
+ if (err) {
+ dev_err(i2c_dev->dev, "failed to set div-clk rate: %d\n", err);
+ return err;
}

if (!i2c_dev->is_dvc && !i2c_dev->is_vi) {
@@ -1163,7 +1161,7 @@ static int tegra_i2c_error_recover(struct tegra_i2c_dev *i2c_dev,
if (i2c_dev->msg_err == I2C_ERR_NONE)
return 0;

- tegra_i2c_init(i2c_dev, true);
+ tegra_i2c_init(i2c_dev);

/* start recovery upon arbitration loss in single master mode */
if (i2c_dev->msg_err == I2C_ERR_ARBITRATION_LOST) {
@@ -1303,7 +1301,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,

if (!time_left && !completion_done(&i2c_dev->dma_complete)) {
dev_err(i2c_dev->dev, "DMA transfer timeout\n");
- tegra_i2c_init(i2c_dev, true);
+ tegra_i2c_init(i2c_dev);
return -ETIMEDOUT;
}

@@ -1324,7 +1322,7 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,

if (time_left == 0) {
dev_err(i2c_dev->dev, "I2C transfer timed out\n");
- tegra_i2c_init(i2c_dev, true);
+ tegra_i2c_init(i2c_dev);
return -ETIMEDOUT;
}

@@ -1752,7 +1750,7 @@ static int tegra_i2c_init_runtime_pm_and_hardware(struct tegra_i2c_dev *i2c_dev)
}

/* initialize hardware state */
- ret = tegra_i2c_init(i2c_dev, false);
+ ret = tegra_i2c_init(i2c_dev);

pm_runtime_put(i2c_dev->dev);

@@ -1907,7 +1905,7 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev)
* domain ON.
*/
if (i2c_dev->is_vi) {
- ret = tegra_i2c_init(i2c_dev, true);
+ ret = tegra_i2c_init(i2c_dev);
if (ret)
goto disable_div_clk;
}
@@ -1961,7 +1959,7 @@ static int __maybe_unused tegra_i2c_resume(struct device *dev)
if (err)
return err;

- err = tegra_i2c_init(i2c_dev, false);
+ err = tegra_i2c_init(i2c_dev);
if (err)
return err;

--
2.27.0