Commit 3eca809b authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau/clk: cosmetic changes

This is purely preparation for upcoming commits, there should be no
code changes here.
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 01d6b956
...@@ -71,7 +71,7 @@ struct nvkm_domain { ...@@ -71,7 +71,7 @@ struct nvkm_domain {
}; };
struct nvkm_clk { struct nvkm_clk {
struct nvkm_subdev base; struct nvkm_subdev subdev;
struct nvkm_domain *domains; struct nvkm_domain *domains;
struct nvkm_pstate bstate; struct nvkm_pstate bstate;
...@@ -117,16 +117,16 @@ nvkm_clk(void *obj) ...@@ -117,16 +117,16 @@ nvkm_clk(void *obj)
nvkm_clk_create_((p), (e), (o), (i), (r), (s), (n), sizeof(**d), \ nvkm_clk_create_((p), (e), (o), (i), (r), (s), (n), sizeof(**d), \
(void **)d) (void **)d)
#define nvkm_clk_destroy(p) ({ \ #define nvkm_clk_destroy(p) ({ \
struct nvkm_clk *clk = (p); \ struct nvkm_clk *_clk = (p); \
_nvkm_clk_dtor(nv_object(clk)); \ _nvkm_clk_dtor(nv_object(_clk)); \
}) })
#define nvkm_clk_init(p) ({ \ #define nvkm_clk_init(p) ({ \
struct nvkm_clk *clk = (p); \ struct nvkm_clk *_clk = (p); \
_nvkm_clk_init(nv_object(clk)); \ _nvkm_clk_init(nv_object(_clk)); \
}) })
#define nvkm_clk_fini(p,s) ({ \ #define nvkm_clk_fini(p,s) ({ \
struct nvkm_clk *clk = (p); \ struct nvkm_clk *_clk = (p); \
_nvkm_clk_fini(nv_object(clk), (s)); \ _nvkm_clk_fini(nv_object(_clk), (s)); \
}) })
int nvkm_clk_create_(struct nvkm_object *, struct nvkm_object *, int nvkm_clk_create_(struct nvkm_object *, struct nvkm_object *,
......
...@@ -121,7 +121,7 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei) ...@@ -121,7 +121,7 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
nv_error(clk, "failed to lower fan speed: %d\n", ret); nv_error(clk, "failed to lower fan speed: %d\n", ret);
} }
return 0; return ret;
} }
static void static void
...@@ -474,7 +474,7 @@ _nvkm_clk_fini(struct nvkm_object *object, bool suspend) ...@@ -474,7 +474,7 @@ _nvkm_clk_fini(struct nvkm_object *object, bool suspend)
{ {
struct nvkm_clk *clk = (void *)object; struct nvkm_clk *clk = (void *)object;
nvkm_notify_put(&clk->pwrsrc_ntfy); nvkm_notify_put(&clk->pwrsrc_ntfy);
return nvkm_subdev_fini(&clk->base, suspend); return nvkm_subdev_fini(&clk->subdev, suspend);
} }
int int
...@@ -484,7 +484,7 @@ _nvkm_clk_init(struct nvkm_object *object) ...@@ -484,7 +484,7 @@ _nvkm_clk_init(struct nvkm_object *object)
struct nvkm_domain *clock = clk->domains; struct nvkm_domain *clock = clk->domains;
int ret; int ret;
ret = nvkm_subdev_init(&clk->base); ret = nvkm_subdev_init(&clk->subdev);
if (ret) if (ret)
return ret; return ret;
...@@ -524,7 +524,7 @@ _nvkm_clk_dtor(struct nvkm_object *object) ...@@ -524,7 +524,7 @@ _nvkm_clk_dtor(struct nvkm_object *object)
nvkm_pstate_del(pstate); nvkm_pstate_del(pstate);
} }
nvkm_subdev_destroy(&clk->base); nvkm_subdev_destroy(&clk->subdev);
} }
int int
......
...@@ -13,6 +13,6 @@ struct gt215_clk_info { ...@@ -13,6 +13,6 @@ struct gt215_clk_info {
}; };
int gt215_pll_info(struct nvkm_clk *, int, u32, u32, struct gt215_clk_info *); int gt215_pll_info(struct nvkm_clk *, int, u32, u32, struct gt215_clk_info *);
int gt215_clk_pre(struct nvkm_clk *clk, unsigned long *flags); int gt215_clk_pre(struct nvkm_clk *, unsigned long *flags);
void gt215_clk_post(struct nvkm_clk *clk, unsigned long *flags); void gt215_clk_post(struct nvkm_clk *, unsigned long *flags);
#endif #endif
...@@ -28,10 +28,6 @@ ...@@ -28,10 +28,6 @@
#include <subdev/bios/pll.h> #include <subdev/bios/pll.h>
#include <subdev/devinit/nv04.h> #include <subdev/devinit/nv04.h>
struct nv04_clk_priv {
struct nvkm_clk base;
};
int int
nv04_clk_pll_calc(struct nvkm_clk *clock, struct nvbios_pll *info, nv04_clk_pll_calc(struct nvkm_clk *clock, struct nvbios_pll *info,
int clk, struct nvkm_pll_vals *pv) int clk, struct nvkm_pll_vals *pv)
...@@ -77,17 +73,17 @@ nv04_clk_ctor(struct nvkm_object *parent, struct nvkm_object *engine, ...@@ -77,17 +73,17 @@ nv04_clk_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
struct nvkm_oclass *oclass, void *data, u32 size, struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject) struct nvkm_object **pobject)
{ {
struct nv04_clk_priv *priv; struct nvkm_clk *clk;
int ret; int ret;
ret = nvkm_clk_create(parent, engine, oclass, nv04_domain, ret = nvkm_clk_create(parent, engine, oclass, nv04_domain,
NULL, 0, false, &priv); NULL, 0, false, &clk);
*pobject = nv_object(priv); *pobject = nv_object(clk);
if (ret) if (ret)
return ret; return ret;
priv->base.pll_calc = nv04_clk_pll_calc; clk->pll_calc = nv04_clk_pll_calc;
priv->base.pll_prog = nv04_clk_pll_prog; clk->pll_prog = nv04_clk_pll_prog;
return 0; return 0;
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <subdev/bios.h> #include <subdev/bios.h>
#include <subdev/bios/pll.h> #include <subdev/bios/pll.h>
struct nv40_clk_priv { struct nv40_clk {
struct nvkm_clk base; struct nvkm_clk base;
u32 ctrl; u32 ctrl;
u32 npll_ctrl; u32 npll_ctrl;
...@@ -46,53 +46,53 @@ nv40_domain[] = { ...@@ -46,53 +46,53 @@ nv40_domain[] = {
}; };
static u32 static u32
read_pll_1(struct nv40_clk_priv *priv, u32 reg) read_pll_1(struct nv40_clk *clk, u32 reg)
{ {
u32 ctrl = nv_rd32(priv, reg + 0x00); u32 ctrl = nv_rd32(clk, reg + 0x00);
int P = (ctrl & 0x00070000) >> 16; int P = (ctrl & 0x00070000) >> 16;
int N = (ctrl & 0x0000ff00) >> 8; int N = (ctrl & 0x0000ff00) >> 8;
int M = (ctrl & 0x000000ff) >> 0; int M = (ctrl & 0x000000ff) >> 0;
u32 ref = 27000, clk = 0; u32 ref = 27000, khz = 0;
if (ctrl & 0x80000000) if (ctrl & 0x80000000)
clk = ref * N / M; khz = ref * N / M;
return clk >> P; return khz >> P;
} }
static u32 static u32
read_pll_2(struct nv40_clk_priv *priv, u32 reg) read_pll_2(struct nv40_clk *clk, u32 reg)
{ {
u32 ctrl = nv_rd32(priv, reg + 0x00); u32 ctrl = nv_rd32(clk, reg + 0x00);
u32 coef = nv_rd32(priv, reg + 0x04); u32 coef = nv_rd32(clk, reg + 0x04);
int N2 = (coef & 0xff000000) >> 24; int N2 = (coef & 0xff000000) >> 24;
int M2 = (coef & 0x00ff0000) >> 16; int M2 = (coef & 0x00ff0000) >> 16;
int N1 = (coef & 0x0000ff00) >> 8; int N1 = (coef & 0x0000ff00) >> 8;
int M1 = (coef & 0x000000ff) >> 0; int M1 = (coef & 0x000000ff) >> 0;
int P = (ctrl & 0x00070000) >> 16; int P = (ctrl & 0x00070000) >> 16;
u32 ref = 27000, clk = 0; u32 ref = 27000, khz = 0;
if ((ctrl & 0x80000000) && M1) { if ((ctrl & 0x80000000) && M1) {
clk = ref * N1 / M1; khz = ref * N1 / M1;
if ((ctrl & 0x40000100) == 0x40000000) { if ((ctrl & 0x40000100) == 0x40000000) {
if (M2) if (M2)
clk = clk * N2 / M2; khz = khz * N2 / M2;
else else
clk = 0; khz = 0;
} }
} }
return clk >> P; return khz >> P;
} }
static u32 static u32
read_clk(struct nv40_clk_priv *priv, u32 src) read_clk(struct nv40_clk *clk, u32 src)
{ {
switch (src) { switch (src) {
case 3: case 3:
return read_pll_2(priv, 0x004000); return read_pll_2(clk, 0x004000);
case 2: case 2:
return read_pll_1(priv, 0x004008); return read_pll_1(clk, 0x004008);
default: default:
break; break;
} }
...@@ -101,35 +101,35 @@ read_clk(struct nv40_clk_priv *priv, u32 src) ...@@ -101,35 +101,35 @@ read_clk(struct nv40_clk_priv *priv, u32 src)
} }
static int static int
nv40_clk_read(struct nvkm_clk *clk, enum nv_clk_src src) nv40_clk_read(struct nvkm_clk *obj, enum nv_clk_src src)
{ {
struct nv40_clk_priv *priv = (void *)clk; struct nv40_clk *clk = container_of(obj, typeof(*clk), base);
u32 mast = nv_rd32(priv, 0x00c040); u32 mast = nv_rd32(clk, 0x00c040);
switch (src) { switch (src) {
case nv_clk_src_crystal: case nv_clk_src_crystal:
return nv_device(priv)->crystal; return nv_device(clk)->crystal;
case nv_clk_src_href: case nv_clk_src_href:
return 100000; /*XXX: PCIE/AGP differ*/ return 100000; /*XXX: PCIE/AGP differ*/
case nv_clk_src_core: case nv_clk_src_core:
return read_clk(priv, (mast & 0x00000003) >> 0); return read_clk(clk, (mast & 0x00000003) >> 0);
case nv_clk_src_shader: case nv_clk_src_shader:
return read_clk(priv, (mast & 0x00000030) >> 4); return read_clk(clk, (mast & 0x00000030) >> 4);
case nv_clk_src_mem: case nv_clk_src_mem:
return read_pll_2(priv, 0x4020); return read_pll_2(clk, 0x4020);
default: default:
break; break;
} }
nv_debug(priv, "unknown clock source %d 0x%08x\n", src, mast); nv_debug(clk, "unknown clock source %d 0x%08x\n", src, mast);
return -EINVAL; return -EINVAL;
} }
static int static int
nv40_clk_calc_pll(struct nv40_clk_priv *priv, u32 reg, u32 clk, nv40_clk_calc_pll(struct nv40_clk *clk, u32 reg, u32 khz,
int *N1, int *M1, int *N2, int *M2, int *log2P) int *N1, int *M1, int *N2, int *M2, int *log2P)
{ {
struct nvkm_bios *bios = nvkm_bios(priv); struct nvkm_bios *bios = nvkm_bios(clk);
struct nvbios_pll pll; struct nvbios_pll pll;
int ret; int ret;
...@@ -137,10 +137,10 @@ nv40_clk_calc_pll(struct nv40_clk_priv *priv, u32 reg, u32 clk, ...@@ -137,10 +137,10 @@ nv40_clk_calc_pll(struct nv40_clk_priv *priv, u32 reg, u32 clk,
if (ret) if (ret)
return ret; return ret;
if (clk < pll.vco1.max_freq) if (khz < pll.vco1.max_freq)
pll.vco2.max_freq = 0; pll.vco2.max_freq = 0;
ret = nv04_pll_calc(nv_subdev(priv), &pll, clk, N1, M1, N2, M2, log2P); ret = nv04_pll_calc(nv_subdev(clk), &pll, khz, N1, M1, N2, M2, log2P);
if (ret == 0) if (ret == 0)
return -ERANGE; return -ERANGE;
...@@ -148,60 +148,60 @@ nv40_clk_calc_pll(struct nv40_clk_priv *priv, u32 reg, u32 clk, ...@@ -148,60 +148,60 @@ nv40_clk_calc_pll(struct nv40_clk_priv *priv, u32 reg, u32 clk,
} }
static int static int
nv40_clk_calc(struct nvkm_clk *clk, struct nvkm_cstate *cstate) nv40_clk_calc(struct nvkm_clk *obj, struct nvkm_cstate *cstate)
{ {
struct nv40_clk_priv *priv = (void *)clk; struct nv40_clk *clk = container_of(obj, typeof(*clk), base);
int gclk = cstate->domain[nv_clk_src_core]; int gclk = cstate->domain[nv_clk_src_core];
int sclk = cstate->domain[nv_clk_src_shader]; int sclk = cstate->domain[nv_clk_src_shader];
int N1, M1, N2, M2, log2P; int N1, M1, N2, M2, log2P;
int ret; int ret;
/* core/geometric clock */ /* core/geometric clock */
ret = nv40_clk_calc_pll(priv, 0x004000, gclk, ret = nv40_clk_calc_pll(clk, 0x004000, gclk,
&N1, &M1, &N2, &M2, &log2P); &N1, &M1, &N2, &M2, &log2P);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (N2 == M2) { if (N2 == M2) {
priv->npll_ctrl = 0x80000100 | (log2P << 16); clk->npll_ctrl = 0x80000100 | (log2P << 16);
priv->npll_coef = (N1 << 8) | M1; clk->npll_coef = (N1 << 8) | M1;
} else { } else {
priv->npll_ctrl = 0xc0000000 | (log2P << 16); clk->npll_ctrl = 0xc0000000 | (log2P << 16);
priv->npll_coef = (N2 << 24) | (M2 << 16) | (N1 << 8) | M1; clk->npll_coef = (N2 << 24) | (M2 << 16) | (N1 << 8) | M1;
} }
/* use the second pll for shader/rop clock, if it differs from core */ /* use the second pll for shader/rop clock, if it differs from core */
if (sclk && sclk != gclk) { if (sclk && sclk != gclk) {
ret = nv40_clk_calc_pll(priv, 0x004008, sclk, ret = nv40_clk_calc_pll(clk, 0x004008, sclk,
&N1, &M1, NULL, NULL, &log2P); &N1, &M1, NULL, NULL, &log2P);
if (ret < 0) if (ret < 0)
return ret; return ret;
priv->spll = 0xc0000000 | (log2P << 16) | (N1 << 8) | M1; clk->spll = 0xc0000000 | (log2P << 16) | (N1 << 8) | M1;
priv->ctrl = 0x00000223; clk->ctrl = 0x00000223;
} else { } else {
priv->spll = 0x00000000; clk->spll = 0x00000000;
priv->ctrl = 0x00000333; clk->ctrl = 0x00000333;
} }
return 0; return 0;
} }
static int static int
nv40_clk_prog(struct nvkm_clk *clk) nv40_clk_prog(struct nvkm_clk *obj)
{ {
struct nv40_clk_priv *priv = (void *)clk; struct nv40_clk *clk = container_of(obj, typeof(*clk), base);
nv_mask(priv, 0x00c040, 0x00000333, 0x00000000); nv_mask(clk, 0x00c040, 0x00000333, 0x00000000);
nv_wr32(priv, 0x004004, priv->npll_coef); nv_wr32(clk, 0x004004, clk->npll_coef);
nv_mask(priv, 0x004000, 0xc0070100, priv->npll_ctrl); nv_mask(clk, 0x004000, 0xc0070100, clk->npll_ctrl);
nv_mask(priv, 0x004008, 0xc007ffff, priv->spll); nv_mask(clk, 0x004008, 0xc007ffff, clk->spll);
mdelay(5); mdelay(5);
nv_mask(priv, 0x00c040, 0x00000333, priv->ctrl); nv_mask(clk, 0x00c040, 0x00000333, clk->ctrl);
return 0; return 0;
} }
static void static void
nv40_clk_tidy(struct nvkm_clk *clk) nv40_clk_tidy(struct nvkm_clk *obj)
{ {
} }
...@@ -210,21 +210,21 @@ nv40_clk_ctor(struct nvkm_object *parent, struct nvkm_object *engine, ...@@ -210,21 +210,21 @@ nv40_clk_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
struct nvkm_oclass *oclass, void *data, u32 size, struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject) struct nvkm_object **pobject)
{ {
struct nv40_clk_priv *priv; struct nv40_clk *clk;
int ret; int ret;
ret = nvkm_clk_create(parent, engine, oclass, nv40_domain, ret = nvkm_clk_create(parent, engine, oclass, nv40_domain,
NULL, 0, true, &priv); NULL, 0, true, &clk);
*pobject = nv_object(priv); *pobject = nv_object(clk);
if (ret) if (ret)
return ret; return ret;
priv->base.pll_calc = nv04_clk_pll_calc; clk->base.pll_calc = nv04_clk_pll_calc;
priv->base.pll_prog = nv04_clk_pll_prog; clk->base.pll_prog = nv04_clk_pll_prog;
priv->base.read = nv40_clk_read; clk->base.read = nv40_clk_read;
priv->base.calc = nv40_clk_calc; clk->base.calc = nv40_clk_calc;
priv->base.prog = nv40_clk_prog; clk->base.prog = nv40_clk_prog;
priv->base.tidy = nv40_clk_tidy; clk->base.tidy = nv40_clk_tidy;
return 0; return 0;
} }
......
...@@ -12,7 +12,7 @@ struct nv50_clk_hwsq { ...@@ -12,7 +12,7 @@ struct nv50_clk_hwsq {
struct hwsq_reg r_mast; struct hwsq_reg r_mast;
}; };
struct nv50_clk_priv { struct nv50_clk {
struct nvkm_clk base; struct nvkm_clk base;
struct nv50_clk_hwsq hwsq; struct nv50_clk_hwsq hwsq;
}; };
......
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