Commit 89d3a912 authored by Alexandre Courbot's avatar Alexandre Courbot Committed by Ben Skeggs

drm/nouveau/clk/gk20a: parameterize PLL settings

Make functions manipulating PLL settings take them as an argument,
instead of assuming we want to work on the copy in the gk20a_clk
structure. This makes these functions more flexible, which we will need
in GM20B.
Signed-off-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent a9608c9b
...@@ -149,19 +149,20 @@ gk20a_pllg_write_mnp(struct gk20a_clk *clk, const struct gk20a_pll *pll) ...@@ -149,19 +149,20 @@ gk20a_pllg_write_mnp(struct gk20a_clk *clk, const struct gk20a_pll *pll)
} }
static u32 static u32
gk20a_pllg_calc_rate(struct gk20a_clk *clk) gk20a_pllg_calc_rate(struct gk20a_clk *clk, struct gk20a_pll *pll)
{ {
u32 rate; u32 rate;
u32 divider; u32 divider;
rate = clk->parent_rate * clk->pll.n; rate = clk->parent_rate * pll->n;
divider = clk->pll.m * clk->pl_to_div(clk->pll.pl); divider = pll->m * clk->pl_to_div(pll->pl);
return rate / divider / 2; return rate / divider / 2;
} }
static int static int
gk20a_pllg_calc_mnp(struct gk20a_clk *clk, unsigned long rate) gk20a_pllg_calc_mnp(struct gk20a_clk *clk, unsigned long rate,
struct gk20a_pll *pll)
{ {
struct nvkm_subdev *subdev = &clk->base.subdev; struct nvkm_subdev *subdev = &clk->base.subdev;
u32 target_clk_f, ref_clk_f, target_freq; u32 target_clk_f, ref_clk_f, target_freq;
...@@ -256,16 +257,16 @@ gk20a_pllg_calc_mnp(struct gk20a_clk *clk, unsigned long rate) ...@@ -256,16 +257,16 @@ gk20a_pllg_calc_mnp(struct gk20a_clk *clk, unsigned long rate)
"no best match for target @ %dMHz on gpc_pll", "no best match for target @ %dMHz on gpc_pll",
target_clk_f / KHZ); target_clk_f / KHZ);
clk->pll.m = best_m; pll->m = best_m;
clk->pll.n = best_n; pll->n = best_n;
clk->pll.pl = best_pl; pll->pl = best_pl;
target_freq = gk20a_pllg_calc_rate(clk); target_freq = gk20a_pllg_calc_rate(clk, pll);
nvkm_debug(subdev, nvkm_debug(subdev,
"actual target freq %d MHz, M %d, N %d, PL %d(div%d)\n", "actual target freq %d KHz, M %d, N %d, PL %d(div%d)\n",
target_freq / MHZ, clk->pll.m, clk->pll.n, clk->pll.pl, target_freq / KHZ, pll->m, pll->n, pll->pl,
clk->pl_to_div(clk->pll.pl)); clk->pl_to_div(pll->pl));
return 0; return 0;
} }
...@@ -333,7 +334,8 @@ gk20a_pllg_disable(struct gk20a_clk *clk) ...@@ -333,7 +334,8 @@ gk20a_pllg_disable(struct gk20a_clk *clk)
} }
static int static int
_gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide) _gk20a_pllg_program_mnp(struct gk20a_clk *clk, struct gk20a_pll *pll,
bool allow_slide)
{ {
struct nvkm_subdev *subdev = &clk->base.subdev; struct nvkm_subdev *subdev = &clk->base.subdev;
struct nvkm_device *device = subdev->device; struct nvkm_device *device = subdev->device;
...@@ -346,9 +348,9 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide) ...@@ -346,9 +348,9 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide)
/* do NDIV slide if there is no change in M and PL */ /* do NDIV slide if there is no change in M and PL */
cfg = nvkm_rd32(device, GPCPLL_CFG); cfg = nvkm_rd32(device, GPCPLL_CFG);
if (allow_slide && clk->pll.m == old_pll.m && if (allow_slide && pll->m == old_pll.m &&
clk->pll.pl == old_pll.pl && (cfg & GPCPLL_CFG_ENABLE)) { pll->pl == old_pll.pl && (cfg & GPCPLL_CFG_ENABLE)) {
return gk20a_pllg_slide(clk, clk->pll.n); return gk20a_pllg_slide(clk, pll->n);
} }
/* slide down to NDIV_LO */ /* slide down to NDIV_LO */
...@@ -385,11 +387,11 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide) ...@@ -385,11 +387,11 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide)
gk20a_pllg_disable(clk); gk20a_pllg_disable(clk);
nvkm_debug(subdev, "%s: m=%d n=%d pl=%d\n", __func__, nvkm_debug(subdev, "%s: m=%d n=%d pl=%d\n", __func__,
clk->pll.m, clk->pll.n, clk->pll.pl); pll->m, pll->n, pll->pl);
old_pll = clk->pll; old_pll = *pll;
if (allow_slide) if (allow_slide)
old_pll.n = DIV_ROUND_UP(clk->pll.m * clk->params->min_vco, old_pll.n = DIV_ROUND_UP(pll->m * clk->params->min_vco,
clk->parent_rate / KHZ); clk->parent_rate / KHZ);
gk20a_pllg_write_mnp(clk, &old_pll); gk20a_pllg_write_mnp(clk, &old_pll);
...@@ -425,7 +427,7 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide) ...@@ -425,7 +427,7 @@ _gk20a_pllg_program_mnp(struct gk20a_clk *clk, bool allow_slide)
} }
/* slide up to new NDIV */ /* slide up to new NDIV */
return allow_slide ? gk20a_pllg_slide(clk, clk->pll.n) : 0; return allow_slide ? gk20a_pllg_slide(clk, pll->n) : 0;
} }
static int static int
...@@ -433,9 +435,9 @@ gk20a_pllg_program_mnp(struct gk20a_clk *clk) ...@@ -433,9 +435,9 @@ gk20a_pllg_program_mnp(struct gk20a_clk *clk)
{ {
int err; int err;
err = _gk20a_pllg_program_mnp(clk, true); err = _gk20a_pllg_program_mnp(clk, &clk->pll, true);
if (err) if (err)
err = _gk20a_pllg_program_mnp(clk, false); err = _gk20a_pllg_program_mnp(clk, &clk->pll, false);
return err; return err;
} }
...@@ -540,13 +542,14 @@ gk20a_clk_read(struct nvkm_clk *base, enum nv_clk_src src) ...@@ -540,13 +542,14 @@ gk20a_clk_read(struct nvkm_clk *base, enum nv_clk_src src)
struct gk20a_clk *clk = gk20a_clk(base); struct gk20a_clk *clk = gk20a_clk(base);
struct nvkm_subdev *subdev = &clk->base.subdev; struct nvkm_subdev *subdev = &clk->base.subdev;
struct nvkm_device *device = subdev->device; struct nvkm_device *device = subdev->device;
struct gk20a_pll pll;
switch (src) { switch (src) {
case nv_clk_src_crystal: case nv_clk_src_crystal:
return device->crystal; return device->crystal;
case nv_clk_src_gpc: case nv_clk_src_gpc:
gk20a_pllg_read_mnp(clk, &clk->pll); gk20a_pllg_read_mnp(clk, &pll);
return gk20a_pllg_calc_rate(clk) / GK20A_CLK_GPC_MDIV; return gk20a_pllg_calc_rate(clk, &pll) / GK20A_CLK_GPC_MDIV;
default: default:
nvkm_error(subdev, "invalid clock source %d\n", src); nvkm_error(subdev, "invalid clock source %d\n", src);
return -EINVAL; return -EINVAL;
...@@ -559,7 +562,7 @@ gk20a_clk_calc(struct nvkm_clk *base, struct nvkm_cstate *cstate) ...@@ -559,7 +562,7 @@ gk20a_clk_calc(struct nvkm_clk *base, struct nvkm_cstate *cstate)
struct gk20a_clk *clk = gk20a_clk(base); struct gk20a_clk *clk = gk20a_clk(base);
return gk20a_pllg_calc_mnp(clk, cstate->domain[nv_clk_src_gpc] * return gk20a_pllg_calc_mnp(clk, cstate->domain[nv_clk_src_gpc] *
GK20A_CLK_GPC_MDIV); GK20A_CLK_GPC_MDIV, &clk->pll);
} }
int int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment