Skip to content

Commit

Permalink
clk: tegra: emc: Fix EMC max-rate clamping
Browse files Browse the repository at this point in the history
When a clk user requests rate that is higher than the maximum possible,
the rate shall be clamped to the maximum and not to the current value.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
  • Loading branch information
Dmitry Osipenko authored and Stephen Boyd committed Apr 25, 2019
1 parent 888ca40 commit 913c307
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions drivers/clk/tegra/clk-emc.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static int emc_determine_rate(struct clk_hw *hw, struct clk_rate_request *req)
struct tegra_clk_emc *tegra;
u8 ram_code = tegra_read_ram_code();
struct emc_timing *timing = NULL;
int i, k;
int i, k, t;

tegra = container_of(hw, struct tegra_clk_emc, hw);

Expand All @@ -130,12 +130,17 @@ static int emc_determine_rate(struct clk_hw *hw, struct clk_rate_request *req)
break;
}

for (i = k; i < tegra->num_timings; i++) {
if (tegra->timings[i].ram_code != ram_code)
for (t = k; t < tegra->num_timings; t++) {
if (tegra->timings[t].ram_code != ram_code)
break;
}

for (i = k; i < t; i++) {
timing = tegra->timings + i;

if (timing->rate < req->rate && i != t - 1)
continue;

if (timing->rate > req->max_rate) {
i = max(i, k + 1);
req->rate = tegra->timings[i - 1].rate;
Expand All @@ -145,10 +150,8 @@ static int emc_determine_rate(struct clk_hw *hw, struct clk_rate_request *req)
if (timing->rate < req->min_rate)
continue;

if (timing->rate >= req->rate) {
req->rate = timing->rate;
return 0;
}
req->rate = timing->rate;
return 0;
}

if (timing) {
Expand Down

0 comments on commit 913c307

Please sign in to comment.