2012-07-10 16:45:24 +10:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors: Ben Skeggs
|
|
|
|
*/
|
2013-01-14 08:28:28 +10:00
|
|
|
#include "nv50.h"
|
2012-07-10 17:26:46 +10:00
|
|
|
#include "pll.h"
|
2013-01-14 08:28:28 +10:00
|
|
|
#include "seq.h"
|
2012-07-10 16:45:24 +10:00
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
#include <subdev/bios.h>
|
|
|
|
#include <subdev/bios/pll.h>
|
|
|
|
|
2013-01-14 08:28:28 +10:00
|
|
|
static u32
|
2015-08-20 14:54:06 +10:00
|
|
|
read_div(struct nv50_clk *clk)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:08 +10:00
|
|
|
struct nvkm_device *device = clk->base.subdev.device;
|
|
|
|
switch (device->chipset) {
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x50: /* it exists, but only has bit 31, not the dividers.. */
|
|
|
|
case 0x84:
|
|
|
|
case 0x86:
|
|
|
|
case 0x98:
|
|
|
|
case 0xa0:
|
2015-08-20 14:54:08 +10:00
|
|
|
return nvkm_rd32(device, 0x004700);
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x92:
|
|
|
|
case 0x94:
|
|
|
|
case 0x96:
|
2015-08-20 14:54:08 +10:00
|
|
|
return nvkm_rd32(device, 0x004800);
|
2013-01-14 08:28:28 +10:00
|
|
|
default:
|
|
|
|
return 0x00000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32
|
2015-08-20 14:54:06 +10:00
|
|
|
read_pll_src(struct nv50_clk *clk, u32 base)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:08 +10:00
|
|
|
struct nvkm_device *device = clk->base.subdev.device;
|
2015-08-20 14:54:06 +10:00
|
|
|
u32 coef, ref = clk->base.read(&clk->base, nv_clk_src_crystal);
|
2015-08-20 14:54:08 +10:00
|
|
|
u32 rsel = nvkm_rd32(device, 0x00e18c);
|
2013-01-14 08:28:28 +10:00
|
|
|
int P, N, M, id;
|
|
|
|
|
2015-08-20 14:54:08 +10:00
|
|
|
switch (device->chipset) {
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x50:
|
|
|
|
case 0xa0:
|
|
|
|
switch (base) {
|
|
|
|
case 0x4020:
|
|
|
|
case 0x4028: id = !!(rsel & 0x00000004); break;
|
|
|
|
case 0x4008: id = !!(rsel & 0x00000008); break;
|
|
|
|
case 0x4030: id = 0; break;
|
|
|
|
default:
|
2015-08-20 14:54:06 +10:00
|
|
|
nv_error(clk, "ref: bad pll 0x%06x\n", base);
|
2013-01-14 08:28:28 +10:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-20 14:54:08 +10:00
|
|
|
coef = nvkm_rd32(device, 0x00e81c + (id * 0x0c));
|
2013-01-14 08:28:28 +10:00
|
|
|
ref *= (coef & 0x01000000) ? 2 : 4;
|
|
|
|
P = (coef & 0x00070000) >> 16;
|
|
|
|
N = ((coef & 0x0000ff00) >> 8) + 1;
|
|
|
|
M = ((coef & 0x000000ff) >> 0) + 1;
|
|
|
|
break;
|
|
|
|
case 0x84:
|
|
|
|
case 0x86:
|
|
|
|
case 0x92:
|
2015-08-20 14:54:08 +10:00
|
|
|
coef = nvkm_rd32(device, 0x00e81c);
|
2013-01-14 08:28:28 +10:00
|
|
|
P = (coef & 0x00070000) >> 16;
|
|
|
|
N = (coef & 0x0000ff00) >> 8;
|
|
|
|
M = (coef & 0x000000ff) >> 0;
|
|
|
|
break;
|
|
|
|
case 0x94:
|
|
|
|
case 0x96:
|
|
|
|
case 0x98:
|
2015-08-20 14:54:08 +10:00
|
|
|
rsel = nvkm_rd32(device, 0x00c050);
|
2013-01-14 08:28:28 +10:00
|
|
|
switch (base) {
|
|
|
|
case 0x4020: rsel = (rsel & 0x00000003) >> 0; break;
|
|
|
|
case 0x4008: rsel = (rsel & 0x0000000c) >> 2; break;
|
|
|
|
case 0x4028: rsel = (rsel & 0x00001800) >> 11; break;
|
|
|
|
case 0x4030: rsel = 3; break;
|
|
|
|
default:
|
2015-08-20 14:54:06 +10:00
|
|
|
nv_error(clk, "ref: bad pll 0x%06x\n", base);
|
2013-01-14 08:28:28 +10:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (rsel) {
|
|
|
|
case 0: id = 1; break;
|
2015-08-20 14:54:06 +10:00
|
|
|
case 1: return clk->base.read(&clk->base, nv_clk_src_crystal);
|
|
|
|
case 2: return clk->base.read(&clk->base, nv_clk_src_href);
|
2013-01-14 08:28:28 +10:00
|
|
|
case 3: id = 0; break;
|
|
|
|
}
|
|
|
|
|
2015-08-20 14:54:08 +10:00
|
|
|
coef = nvkm_rd32(device, 0x00e81c + (id * 0x28));
|
|
|
|
P = (nvkm_rd32(device, 0x00e824 + (id * 0x28)) >> 16) & 7;
|
2013-01-14 08:28:28 +10:00
|
|
|
P += (coef & 0x00070000) >> 16;
|
|
|
|
N = (coef & 0x0000ff00) >> 8;
|
|
|
|
M = (coef & 0x000000ff) >> 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG_ON(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (M)
|
|
|
|
return (ref * N / M) >> P;
|
2015-01-14 14:47:24 +10:00
|
|
|
|
2013-01-14 08:28:28 +10:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32
|
2015-08-20 14:54:06 +10:00
|
|
|
read_pll_ref(struct nv50_clk *clk, u32 base)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:08 +10:00
|
|
|
struct nvkm_device *device = clk->base.subdev.device;
|
|
|
|
u32 src, mast = nvkm_rd32(device, 0x00c040);
|
2013-01-14 08:28:28 +10:00
|
|
|
|
|
|
|
switch (base) {
|
|
|
|
case 0x004028:
|
|
|
|
src = !!(mast & 0x00200000);
|
|
|
|
break;
|
|
|
|
case 0x004020:
|
|
|
|
src = !!(mast & 0x00400000);
|
|
|
|
break;
|
|
|
|
case 0x004008:
|
|
|
|
src = !!(mast & 0x00010000);
|
|
|
|
break;
|
|
|
|
case 0x004030:
|
|
|
|
src = !!(mast & 0x02000000);
|
|
|
|
break;
|
|
|
|
case 0x00e810:
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_crystal);
|
2013-01-14 08:28:28 +10:00
|
|
|
default:
|
2015-08-20 14:54:06 +10:00
|
|
|
nv_error(clk, "bad pll 0x%06x\n", base);
|
2013-01-14 08:28:28 +10:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src)
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_href);
|
2015-01-14 14:47:24 +10:00
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
return read_pll_src(clk, base);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static u32
|
2015-08-20 14:54:06 +10:00
|
|
|
read_pll(struct nv50_clk *clk, u32 base)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:08 +10:00
|
|
|
struct nvkm_device *device = clk->base.subdev.device;
|
|
|
|
u32 mast = nvkm_rd32(device, 0x00c040);
|
|
|
|
u32 ctrl = nvkm_rd32(device, base + 0);
|
|
|
|
u32 coef = nvkm_rd32(device, base + 4);
|
2015-08-20 14:54:06 +10:00
|
|
|
u32 ref = read_pll_ref(clk, base);
|
2013-01-14 08:28:28 +10:00
|
|
|
u32 freq = 0;
|
|
|
|
int N1, N2, M1, M2;
|
|
|
|
|
|
|
|
if (base == 0x004028 && (mast & 0x00100000)) {
|
2015-01-14 14:47:24 +10:00
|
|
|
/* wtf, appears to only disable post-divider on gt200 */
|
2015-08-20 14:54:08 +10:00
|
|
|
if (device->chipset != 0xa0)
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_dom6);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
N2 = (coef & 0xff000000) >> 24;
|
|
|
|
M2 = (coef & 0x00ff0000) >> 16;
|
|
|
|
N1 = (coef & 0x0000ff00) >> 8;
|
|
|
|
M1 = (coef & 0x000000ff);
|
|
|
|
if ((ctrl & 0x80000000) && M1) {
|
|
|
|
freq = ref * N1 / M1;
|
|
|
|
if ((ctrl & 0x40000100) == 0x40000000) {
|
|
|
|
if (M2)
|
|
|
|
freq = freq * N2 / M2;
|
|
|
|
else
|
|
|
|
freq = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return freq;
|
|
|
|
}
|
2012-07-10 16:45:24 +10:00
|
|
|
|
|
|
|
static int
|
2015-08-20 14:54:06 +10:00
|
|
|
nv50_clk_read(struct nvkm_clk *obj, enum nv_clk_src src)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:06 +10:00
|
|
|
struct nv50_clk *clk = container_of(obj, typeof(*clk), base);
|
2015-08-20 14:54:08 +10:00
|
|
|
struct nvkm_device *device = clk->base.subdev.device;
|
|
|
|
u32 mast = nvkm_rd32(device, 0x00c040);
|
2013-01-14 08:28:28 +10:00
|
|
|
u32 P = 0;
|
|
|
|
|
|
|
|
switch (src) {
|
|
|
|
case nv_clk_src_crystal:
|
2015-08-20 14:54:08 +10:00
|
|
|
return device->crystal;
|
2013-01-14 08:28:28 +10:00
|
|
|
case nv_clk_src_href:
|
|
|
|
return 100000; /* PCIE reference clock */
|
|
|
|
case nv_clk_src_hclk:
|
2015-08-20 14:54:06 +10:00
|
|
|
return div_u64((u64)clk->base.read(&clk->base, nv_clk_src_href) * 27778, 10000);
|
2013-01-14 08:28:28 +10:00
|
|
|
case nv_clk_src_hclkm3:
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_hclk) * 3;
|
2013-01-14 08:28:28 +10:00
|
|
|
case nv_clk_src_hclkm3d2:
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_hclk) * 3 / 2;
|
2013-01-14 08:28:28 +10:00
|
|
|
case nv_clk_src_host:
|
|
|
|
switch (mast & 0x30000000) {
|
2015-08-20 14:54:06 +10:00
|
|
|
case 0x00000000: return clk->base.read(&clk->base, nv_clk_src_href);
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x10000000: break;
|
|
|
|
case 0x20000000: /* !0x50 */
|
2015-08-20 14:54:06 +10:00
|
|
|
case 0x30000000: return clk->base.read(&clk->base, nv_clk_src_hclk);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nv_clk_src_core:
|
|
|
|
if (!(mast & 0x00100000))
|
2015-08-20 14:54:08 +10:00
|
|
|
P = (nvkm_rd32(device, 0x004028) & 0x00070000) >> 16;
|
2013-01-14 08:28:28 +10:00
|
|
|
switch (mast & 0x00000003) {
|
2015-08-20 14:54:06 +10:00
|
|
|
case 0x00000000: return clk->base.read(&clk->base, nv_clk_src_crystal) >> P;
|
|
|
|
case 0x00000001: return clk->base.read(&clk->base, nv_clk_src_dom6);
|
|
|
|
case 0x00000002: return read_pll(clk, 0x004020) >> P;
|
|
|
|
case 0x00000003: return read_pll(clk, 0x004028) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nv_clk_src_shader:
|
2015-08-20 14:54:08 +10:00
|
|
|
P = (nvkm_rd32(device, 0x004020) & 0x00070000) >> 16;
|
2013-01-14 08:28:28 +10:00
|
|
|
switch (mast & 0x00000030) {
|
|
|
|
case 0x00000000:
|
|
|
|
if (mast & 0x00000080)
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_host) >> P;
|
|
|
|
return clk->base.read(&clk->base, nv_clk_src_crystal) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x00000010: break;
|
2015-08-20 14:54:06 +10:00
|
|
|
case 0x00000020: return read_pll(clk, 0x004028) >> P;
|
|
|
|
case 0x00000030: return read_pll(clk, 0x004020) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nv_clk_src_mem:
|
2015-08-20 14:54:08 +10:00
|
|
|
P = (nvkm_rd32(device, 0x004008) & 0x00070000) >> 16;
|
|
|
|
if (nvkm_rd32(device, 0x004008) & 0x00000200) {
|
2013-01-14 08:28:28 +10:00
|
|
|
switch (mast & 0x0000c000) {
|
|
|
|
case 0x00000000:
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_crystal) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x00008000:
|
|
|
|
case 0x0000c000:
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_href) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
} else {
|
2015-08-20 14:54:06 +10:00
|
|
|
return read_pll(clk, 0x004008) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nv_clk_src_vdec:
|
2015-08-20 14:54:06 +10:00
|
|
|
P = (read_div(clk) & 0x00000700) >> 8;
|
2015-08-20 14:54:08 +10:00
|
|
|
switch (device->chipset) {
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x84:
|
|
|
|
case 0x86:
|
|
|
|
case 0x92:
|
|
|
|
case 0x94:
|
|
|
|
case 0x96:
|
|
|
|
case 0xa0:
|
|
|
|
switch (mast & 0x00000c00) {
|
|
|
|
case 0x00000000:
|
2015-08-20 14:54:08 +10:00
|
|
|
if (device->chipset == 0xa0) /* wtf?? */
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_core) >> P;
|
|
|
|
return clk->base.read(&clk->base, nv_clk_src_crystal) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x00000400:
|
|
|
|
return 0;
|
|
|
|
case 0x00000800:
|
|
|
|
if (mast & 0x01000000)
|
2015-08-20 14:54:06 +10:00
|
|
|
return read_pll(clk, 0x004028) >> P;
|
|
|
|
return read_pll(clk, 0x004030) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x00000c00:
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_core) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x98:
|
|
|
|
switch (mast & 0x00000c00) {
|
|
|
|
case 0x00000000:
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_core) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x00000400:
|
|
|
|
return 0;
|
|
|
|
case 0x00000800:
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_hclkm3d2) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x00000c00:
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_mem) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nv_clk_src_dom6:
|
2015-08-20 14:54:08 +10:00
|
|
|
switch (device->chipset) {
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x50:
|
|
|
|
case 0xa0:
|
2015-08-20 14:54:06 +10:00
|
|
|
return read_pll(clk, 0x00e810) >> 2;
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x84:
|
|
|
|
case 0x86:
|
|
|
|
case 0x92:
|
|
|
|
case 0x94:
|
|
|
|
case 0x96:
|
|
|
|
case 0x98:
|
2015-08-20 14:54:06 +10:00
|
|
|
P = (read_div(clk) & 0x00000007) >> 0;
|
2013-01-14 08:28:28 +10:00
|
|
|
switch (mast & 0x0c000000) {
|
2015-08-20 14:54:06 +10:00
|
|
|
case 0x00000000: return clk->base.read(&clk->base, nv_clk_src_href);
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x04000000: break;
|
2015-08-20 14:54:06 +10:00
|
|
|
case 0x08000000: return clk->base.read(&clk->base, nv_clk_src_hclk);
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x0c000000:
|
2015-08-20 14:54:06 +10:00
|
|
|
return clk->base.read(&clk->base, nv_clk_src_hclkm3) >> P;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
nv_debug(clk, "unknown clock source %d 0x%08x\n", src, mast);
|
2013-01-14 08:28:28 +10:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32
|
2015-08-20 14:54:06 +10:00
|
|
|
calc_pll(struct nv50_clk *clk, u32 reg, u32 idx, int *N, int *M, int *P)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:06 +10:00
|
|
|
struct nvkm_bios *bios = nvkm_bios(clk);
|
2013-01-14 08:28:28 +10:00
|
|
|
struct nvbios_pll pll;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = nvbios_pll_parse(bios, reg, &pll);
|
|
|
|
if (ret)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pll.vco2.max_freq = 0;
|
2015-08-20 14:54:06 +10:00
|
|
|
pll.refclk = read_pll_ref(clk, reg);
|
2013-01-14 08:28:28 +10:00
|
|
|
if (!pll.refclk)
|
|
|
|
return 0;
|
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
return nv04_pll_calc(nv_subdev(clk), &pll, idx, N, M, NULL, NULL, P);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32
|
|
|
|
calc_div(u32 src, u32 target, int *div)
|
|
|
|
{
|
|
|
|
u32 clk0 = src, clk1 = src;
|
|
|
|
for (*div = 0; *div <= 7; (*div)++) {
|
|
|
|
if (clk0 <= target) {
|
|
|
|
clk1 = clk0 << (*div ? 1 : 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
clk0 >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target - clk0 <= clk1 - target)
|
|
|
|
return clk0;
|
|
|
|
(*div)--;
|
|
|
|
return clk1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32
|
|
|
|
clk_same(u32 a, u32 b)
|
|
|
|
{
|
|
|
|
return ((a / 1000) == (b / 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-08-20 14:54:06 +10:00
|
|
|
nv50_clk_calc(struct nvkm_clk *obj, struct nvkm_cstate *cstate)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:06 +10:00
|
|
|
struct nv50_clk *clk = container_of(obj, typeof(*clk), base);
|
|
|
|
struct nv50_clk_hwsq *hwsq = &clk->hwsq;
|
2013-01-14 08:28:28 +10:00
|
|
|
const int shader = cstate->domain[nv_clk_src_shader];
|
|
|
|
const int core = cstate->domain[nv_clk_src_core];
|
|
|
|
const int vdec = cstate->domain[nv_clk_src_vdec];
|
|
|
|
const int dom6 = cstate->domain[nv_clk_src_dom6];
|
|
|
|
u32 mastm = 0, mastv = 0;
|
|
|
|
u32 divsm = 0, divsv = 0;
|
|
|
|
int N, M, P1, P2;
|
|
|
|
int freq, out;
|
|
|
|
|
|
|
|
/* prepare a hwsq script from which we'll perform the reclock */
|
|
|
|
out = clk_init(hwsq, nv_subdev(clk));
|
|
|
|
if (out)
|
|
|
|
return out;
|
|
|
|
|
|
|
|
clk_wr32(hwsq, fifo, 0x00000001); /* block fifo */
|
|
|
|
clk_nsec(hwsq, 8000);
|
|
|
|
clk_setf(hwsq, 0x10, 0x00); /* disable fb */
|
|
|
|
clk_wait(hwsq, 0x00, 0x01); /* wait for fb disabled */
|
|
|
|
|
|
|
|
/* vdec: avoid modifying xpll until we know exactly how the other
|
|
|
|
* clock domains work, i suspect at least some of them can also be
|
|
|
|
* tied to xpll...
|
|
|
|
*/
|
|
|
|
if (vdec) {
|
|
|
|
/* see how close we can get using nvclk as a source */
|
|
|
|
freq = calc_div(core, vdec, &P1);
|
|
|
|
|
|
|
|
/* see how close we can get using xpll/hclk as a source */
|
2015-08-20 14:54:06 +10:00
|
|
|
if (nv_device(clk)->chipset != 0x98)
|
|
|
|
out = read_pll(clk, 0x004030);
|
2013-01-14 08:28:28 +10:00
|
|
|
else
|
2015-08-20 14:54:06 +10:00
|
|
|
out = clk->base.read(&clk->base, nv_clk_src_hclkm3d2);
|
2013-01-14 08:28:28 +10:00
|
|
|
out = calc_div(out, vdec, &P2);
|
|
|
|
|
|
|
|
/* select whichever gets us closest */
|
|
|
|
if (abs(vdec - freq) <= abs(vdec - out)) {
|
2015-08-20 14:54:06 +10:00
|
|
|
if (nv_device(clk)->chipset != 0x98)
|
2013-01-14 08:28:28 +10:00
|
|
|
mastv |= 0x00000c00;
|
|
|
|
divsv |= P1 << 8;
|
|
|
|
} else {
|
|
|
|
mastv |= 0x00000800;
|
|
|
|
divsv |= P2 << 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
mastm |= 0x00000c00;
|
|
|
|
divsm |= 0x00000700;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dom6: nfi what this is, but we're limited to various combinations
|
|
|
|
* of the host clock frequency
|
|
|
|
*/
|
|
|
|
if (dom6) {
|
2015-08-20 14:54:06 +10:00
|
|
|
if (clk_same(dom6, clk->base.read(&clk->base, nv_clk_src_href))) {
|
2013-01-14 08:28:28 +10:00
|
|
|
mastv |= 0x00000000;
|
|
|
|
} else
|
2015-08-20 14:54:06 +10:00
|
|
|
if (clk_same(dom6, clk->base.read(&clk->base, nv_clk_src_hclk))) {
|
2013-01-14 08:28:28 +10:00
|
|
|
mastv |= 0x08000000;
|
|
|
|
} else {
|
2015-08-20 14:54:06 +10:00
|
|
|
freq = clk->base.read(&clk->base, nv_clk_src_hclk) * 3;
|
|
|
|
calc_div(freq, dom6, &P1);
|
2013-01-14 08:28:28 +10:00
|
|
|
|
|
|
|
mastv |= 0x0c000000;
|
|
|
|
divsv |= P1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mastm |= 0x0c000000;
|
|
|
|
divsm |= 0x00000007;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vdec/dom6: switch to "safe" clocks temporarily, update dividers
|
|
|
|
* and then switch to target clocks
|
|
|
|
*/
|
|
|
|
clk_mask(hwsq, mast, mastm, 0x00000000);
|
|
|
|
clk_mask(hwsq, divs, divsm, divsv);
|
|
|
|
clk_mask(hwsq, mast, mastm, mastv);
|
|
|
|
|
|
|
|
/* core/shader: disconnect nvclk/sclk from their PLLs (nvclk to dom6,
|
|
|
|
* sclk to hclk) before reprogramming
|
|
|
|
*/
|
2015-08-20 14:54:06 +10:00
|
|
|
if (nv_device(clk)->chipset < 0x92)
|
2013-01-14 08:28:28 +10:00
|
|
|
clk_mask(hwsq, mast, 0x001000b0, 0x00100080);
|
|
|
|
else
|
|
|
|
clk_mask(hwsq, mast, 0x000000b3, 0x00000081);
|
|
|
|
|
|
|
|
/* core: for the moment at least, always use nvpll */
|
2015-08-20 14:54:06 +10:00
|
|
|
freq = calc_pll(clk, 0x4028, core, &N, &M, &P1);
|
2013-01-14 08:28:28 +10:00
|
|
|
if (freq == 0)
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
clk_mask(hwsq, nvpll[0], 0xc03f0100,
|
|
|
|
0x80000000 | (P1 << 19) | (P1 << 16));
|
|
|
|
clk_mask(hwsq, nvpll[1], 0x0000ffff, (N << 8) | M);
|
|
|
|
|
|
|
|
/* shader: tie to nvclk if possible, otherwise use spll. have to be
|
|
|
|
* very careful that the shader clock is at least twice the core, or
|
|
|
|
* some chipsets will be very unhappy. i expect most or all of these
|
|
|
|
* cases will be handled by tying to nvclk, but it's possible there's
|
|
|
|
* corners
|
|
|
|
*/
|
|
|
|
if (P1-- && shader == (core << 1)) {
|
|
|
|
clk_mask(hwsq, spll[0], 0xc03f0100, (P1 << 19) | (P1 << 16));
|
|
|
|
clk_mask(hwsq, mast, 0x00100033, 0x00000023);
|
|
|
|
} else {
|
2015-08-20 14:54:06 +10:00
|
|
|
freq = calc_pll(clk, 0x4020, shader, &N, &M, &P1);
|
2013-01-14 08:28:28 +10:00
|
|
|
if (freq == 0)
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
clk_mask(hwsq, spll[0], 0xc03f0100,
|
|
|
|
0x80000000 | (P1 << 19) | (P1 << 16));
|
|
|
|
clk_mask(hwsq, spll[1], 0x0000ffff, (N << 8) | M);
|
|
|
|
clk_mask(hwsq, mast, 0x00100033, 0x00000033);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restore normal operation */
|
|
|
|
clk_setf(hwsq, 0x10, 0x01); /* enable fb */
|
|
|
|
clk_wait(hwsq, 0x00, 0x00); /* wait for fb enabled */
|
|
|
|
clk_wr32(hwsq, fifo, 0x00000000); /* un-block fifo */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-08-20 14:54:06 +10:00
|
|
|
nv50_clk_prog(struct nvkm_clk *obj)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:06 +10:00
|
|
|
struct nv50_clk *clk = container_of(obj, typeof(*clk), base);
|
|
|
|
return clk_exec(&clk->hwsq, true);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-08-20 14:54:06 +10:00
|
|
|
nv50_clk_tidy(struct nvkm_clk *obj)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:06 +10:00
|
|
|
struct nv50_clk *clk = container_of(obj, typeof(*clk), base);
|
|
|
|
clk_exec(&clk->hwsq, false);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 14:47:24 +10:00
|
|
|
nv50_clk_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass, void *data, u32 size,
|
|
|
|
struct nvkm_object **pobject)
|
2012-07-10 16:45:24 +10:00
|
|
|
{
|
2015-01-13 23:37:38 +10:00
|
|
|
struct nv50_clk_oclass *pclass = (void *)oclass;
|
2015-08-20 14:54:06 +10:00
|
|
|
struct nv50_clk *clk;
|
2012-07-10 16:45:24 +10:00
|
|
|
int ret;
|
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
ret = nvkm_clk_create(parent, engine, oclass, pclass->domains,
|
2015-05-24 10:44:02 +02:00
|
|
|
NULL, 0, nv_device(parent)->chipset == 0xa0,
|
2015-08-20 14:54:06 +10:00
|
|
|
&clk);
|
|
|
|
*pobject = nv_object(clk);
|
2012-07-10 16:45:24 +10:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
clk->hwsq.r_fifo = hwsq_reg(0x002504);
|
|
|
|
clk->hwsq.r_spll[0] = hwsq_reg(0x004020);
|
|
|
|
clk->hwsq.r_spll[1] = hwsq_reg(0x004024);
|
|
|
|
clk->hwsq.r_nvpll[0] = hwsq_reg(0x004028);
|
|
|
|
clk->hwsq.r_nvpll[1] = hwsq_reg(0x00402c);
|
|
|
|
switch (nv_device(clk)->chipset) {
|
2013-01-14 08:28:28 +10:00
|
|
|
case 0x92:
|
|
|
|
case 0x94:
|
|
|
|
case 0x96:
|
2015-08-20 14:54:06 +10:00
|
|
|
clk->hwsq.r_divs = hwsq_reg(0x004800);
|
2013-01-14 08:28:28 +10:00
|
|
|
break;
|
|
|
|
default:
|
2015-08-20 14:54:06 +10:00
|
|
|
clk->hwsq.r_divs = hwsq_reg(0x004700);
|
2013-01-14 08:28:28 +10:00
|
|
|
break;
|
|
|
|
}
|
2015-08-20 14:54:06 +10:00
|
|
|
clk->hwsq.r_mast = hwsq_reg(0x00c040);
|
2013-01-14 08:28:28 +10:00
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
clk->base.read = nv50_clk_read;
|
|
|
|
clk->base.calc = nv50_clk_calc;
|
|
|
|
clk->base.prog = nv50_clk_prog;
|
|
|
|
clk->base.tidy = nv50_clk_tidy;
|
2012-07-10 16:45:24 +10:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
static struct nvkm_domain
|
2013-01-14 08:28:28 +10:00
|
|
|
nv50_domains[] = {
|
|
|
|
{ nv_clk_src_crystal, 0xff },
|
|
|
|
{ nv_clk_src_href , 0xff },
|
|
|
|
{ nv_clk_src_core , 0xff, 0, "core", 1000 },
|
|
|
|
{ nv_clk_src_shader , 0xff, 0, "shader", 1000 },
|
|
|
|
{ nv_clk_src_mem , 0xff, 0, "memory", 1000 },
|
|
|
|
{ nv_clk_src_max }
|
|
|
|
};
|
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_oclass *
|
2015-01-13 23:37:38 +10:00
|
|
|
nv50_clk_oclass = &(struct nv50_clk_oclass) {
|
|
|
|
.base.handle = NV_SUBDEV(CLK, 0x50),
|
2015-01-14 14:47:24 +10:00
|
|
|
.base.ofuncs = &(struct nvkm_ofuncs) {
|
2015-01-13 23:37:38 +10:00
|
|
|
.ctor = nv50_clk_ctor,
|
2015-01-14 14:47:24 +10:00
|
|
|
.dtor = _nvkm_clk_dtor,
|
|
|
|
.init = _nvkm_clk_init,
|
|
|
|
.fini = _nvkm_clk_fini,
|
2012-07-10 16:45:24 +10:00
|
|
|
},
|
2013-01-14 08:28:28 +10:00
|
|
|
.domains = nv50_domains,
|
|
|
|
}.base;
|