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