2013-01-14 08:28:28 +10:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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
|
|
|
|
*/
|
2015-01-13 23:37:38 +10:00
|
|
|
#include <subdev/clk.h>
|
2013-01-14 08:28:28 +10:00
|
|
|
#include <subdev/bios.h>
|
|
|
|
#include <subdev/bios/boost.h>
|
|
|
|
#include <subdev/bios/cstep.h>
|
|
|
|
#include <subdev/bios/perf.h>
|
2015-01-14 14:47:24 +10:00
|
|
|
#include <subdev/fb.h>
|
|
|
|
#include <subdev/therm.h>
|
|
|
|
#include <subdev/volt.h>
|
|
|
|
|
|
|
|
#include <core/option.h>
|
2013-01-14 08:28:28 +10:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* misc
|
|
|
|
*****************************************************************************/
|
|
|
|
static u32
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_clk_adjust(struct nvkm_clk *clk, bool adjust,
|
|
|
|
u8 pstate, u8 domain, u32 input)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_bios *bios = nvkm_bios(clk);
|
2013-01-14 08:28:28 +10:00
|
|
|
struct nvbios_boostE boostE;
|
|
|
|
u8 ver, hdr, cnt, len;
|
|
|
|
u16 data;
|
|
|
|
|
|
|
|
data = nvbios_boostEm(bios, pstate, &ver, &hdr, &cnt, &len, &boostE);
|
|
|
|
if (data) {
|
|
|
|
struct nvbios_boostS boostS;
|
|
|
|
u8 idx = 0, sver, shdr;
|
|
|
|
u16 subd;
|
|
|
|
|
|
|
|
input = max(boostE.min, input);
|
|
|
|
input = min(boostE.max, input);
|
|
|
|
do {
|
|
|
|
sver = ver;
|
|
|
|
shdr = hdr;
|
|
|
|
subd = nvbios_boostSp(bios, idx++, data, &sver, &shdr,
|
|
|
|
cnt, len, &boostS);
|
|
|
|
if (subd && boostS.domain == domain) {
|
|
|
|
if (adjust)
|
|
|
|
input = input * boostS.percent / 100;
|
|
|
|
input = max(boostS.min, input);
|
|
|
|
input = min(boostS.max, input);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (subd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* C-States
|
|
|
|
*****************************************************************************/
|
|
|
|
static int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:12 +10:00
|
|
|
struct nvkm_subdev *subdev = &clk->subdev;
|
|
|
|
struct nvkm_device *device = subdev->device;
|
|
|
|
struct nvkm_therm *therm = device->therm;
|
|
|
|
struct nvkm_volt *volt = device->volt;
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_cstate *cstate;
|
2013-01-14 08:28:28 +10:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!list_empty(&pstate->list)) {
|
|
|
|
cstate = list_entry(pstate->list.prev, typeof(*cstate), head);
|
|
|
|
} else {
|
|
|
|
cstate = &pstate->base;
|
|
|
|
}
|
|
|
|
|
2015-08-20 14:54:07 +10:00
|
|
|
if (therm) {
|
|
|
|
ret = nvkm_therm_cstate(therm, pstate->fanspeed, +1);
|
2014-07-26 18:41:39 +09:00
|
|
|
if (ret && ret != -ENODEV) {
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_error(subdev, "failed to raise fan speed: %d\n", ret);
|
2014-07-26 18:41:39 +09:00
|
|
|
return ret;
|
|
|
|
}
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
2014-07-26 18:41:39 +09:00
|
|
|
if (volt) {
|
|
|
|
ret = volt->set_id(volt, cstate->voltage, +1);
|
|
|
|
if (ret && ret != -ENODEV) {
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_error(subdev, "failed to raise voltage: %d\n", ret);
|
2014-07-26 18:41:39 +09:00
|
|
|
return ret;
|
|
|
|
}
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk->calc(clk, cstate);
|
|
|
|
if (ret == 0) {
|
|
|
|
ret = clk->prog(clk);
|
|
|
|
clk->tidy(clk);
|
|
|
|
}
|
|
|
|
|
2014-07-26 18:41:39 +09:00
|
|
|
if (volt) {
|
|
|
|
ret = volt->set_id(volt, cstate->voltage, -1);
|
|
|
|
if (ret && ret != -ENODEV)
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_error(subdev, "failed to lower voltage: %d\n", ret);
|
2014-07-26 18:41:39 +09:00
|
|
|
}
|
2013-01-14 08:28:28 +10:00
|
|
|
|
2015-08-20 14:54:07 +10:00
|
|
|
if (therm) {
|
|
|
|
ret = nvkm_therm_cstate(therm, pstate->fanspeed, -1);
|
2014-07-26 18:41:39 +09:00
|
|
|
if (ret && ret != -ENODEV)
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_error(subdev, "failed to lower fan speed: %d\n", ret);
|
2014-07-26 18:41:39 +09:00
|
|
|
}
|
2013-01-14 08:28:28 +10:00
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
return ret;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_cstate_del(struct nvkm_cstate *cstate)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
|
|
|
list_del(&cstate->head);
|
|
|
|
kfree(cstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_cstate_new(struct nvkm_clk *clk, int idx, struct nvkm_pstate *pstate)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_bios *bios = nvkm_bios(clk);
|
|
|
|
struct nvkm_domain *domain = clk->domains;
|
|
|
|
struct nvkm_cstate *cstate = NULL;
|
2013-01-14 08:28:28 +10:00
|
|
|
struct nvbios_cstepX cstepX;
|
|
|
|
u8 ver, hdr;
|
|
|
|
u16 data;
|
|
|
|
|
|
|
|
data = nvbios_cstepXp(bios, idx, &ver, &hdr, &cstepX);
|
|
|
|
if (!data)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
cstate = kzalloc(sizeof(*cstate), GFP_KERNEL);
|
|
|
|
if (!cstate)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
*cstate = pstate->base;
|
|
|
|
cstate->voltage = cstepX.voltage;
|
|
|
|
|
|
|
|
while (domain && domain->name != nv_clk_src_max) {
|
|
|
|
if (domain->flags & NVKM_CLK_DOM_FLAG_CORE) {
|
2015-01-14 14:47:24 +10:00
|
|
|
u32 freq = nvkm_clk_adjust(clk, true, pstate->pstate,
|
|
|
|
domain->bios, cstepX.freq);
|
2013-01-14 08:28:28 +10:00
|
|
|
cstate->domain[domain->name] = freq;
|
|
|
|
}
|
|
|
|
domain++;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add(&cstate->head, &pstate->list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* P-States
|
|
|
|
*****************************************************************************/
|
|
|
|
static int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-08-20 14:54:12 +10:00
|
|
|
struct nvkm_subdev *subdev = &clk->subdev;
|
|
|
|
struct nvkm_fb *fb = subdev->device->fb;
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_pstate *pstate;
|
2013-01-14 08:28:28 +10:00
|
|
|
int ret, idx = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(pstate, &clk->states, head) {
|
|
|
|
if (idx++ == pstatei)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_debug(subdev, "setting performance state %d\n", pstatei);
|
2013-01-14 08:28:28 +10:00
|
|
|
clk->pstate = pstatei;
|
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
if (fb->ram && fb->ram->calc) {
|
2013-12-03 08:25:04 +10:00
|
|
|
int khz = pstate->base.domain[nv_clk_src_mem];
|
|
|
|
do {
|
2015-08-20 14:54:06 +10:00
|
|
|
ret = fb->ram->calc(fb, khz);
|
2013-12-03 08:25:04 +10:00
|
|
|
if (ret == 0)
|
2015-08-20 14:54:06 +10:00
|
|
|
ret = fb->ram->prog(fb);
|
2013-12-03 08:25:04 +10:00
|
|
|
} while (ret > 0);
|
2015-08-20 14:54:06 +10:00
|
|
|
fb->ram->tidy(fb);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
return nvkm_cstate_prog(clk, pstate, 0);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
2014-06-13 14:58:21 +10:00
|
|
|
static void
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_work(struct work_struct *work)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_clk *clk = container_of(work, typeof(*clk), work);
|
2015-08-20 14:54:12 +10:00
|
|
|
struct nvkm_subdev *subdev = &clk->subdev;
|
2014-06-13 14:58:21 +10:00
|
|
|
int pstate;
|
|
|
|
|
|
|
|
if (!atomic_xchg(&clk->waiting, 0))
|
|
|
|
return;
|
2014-06-13 13:23:42 +10:00
|
|
|
clk->pwrsrc = power_supply_is_system_supplied();
|
2013-01-14 08:28:28 +10:00
|
|
|
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_trace(subdev, "P %d PWR %d U(AC) %d U(DC) %d A %d T %d D %d\n",
|
|
|
|
clk->pstate, clk->pwrsrc, clk->ustate_ac, clk->ustate_dc,
|
|
|
|
clk->astate, clk->tstate, clk->dstate);
|
2013-01-14 08:28:28 +10:00
|
|
|
|
2014-06-13 13:23:42 +10:00
|
|
|
pstate = clk->pwrsrc ? clk->ustate_ac : clk->ustate_dc;
|
|
|
|
if (clk->state_nr && pstate != -1) {
|
|
|
|
pstate = (pstate < 0) ? clk->astate : pstate;
|
2015-06-16 17:35:12 +08:00
|
|
|
pstate = min(pstate, clk->state_nr - 1 + clk->tstate);
|
2013-01-14 08:28:28 +10:00
|
|
|
pstate = max(pstate, clk->dstate);
|
|
|
|
} else {
|
|
|
|
pstate = clk->pstate = -1;
|
|
|
|
}
|
|
|
|
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_trace(subdev, "-> %d\n", pstate);
|
2014-06-13 14:58:21 +10:00
|
|
|
if (pstate != clk->pstate) {
|
2015-01-14 14:47:24 +10:00
|
|
|
int ret = nvkm_pstate_prog(clk, pstate);
|
2014-06-13 14:58:21 +10:00
|
|
|
if (ret) {
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_error(subdev, "error setting pstate %d: %d\n",
|
|
|
|
pstate, ret);
|
2014-06-13 14:58:21 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wake_up_all(&clk->wait);
|
2014-08-10 04:10:20 +10:00
|
|
|
nvkm_notify_get(&clk->pwrsrc_ntfy);
|
2014-06-13 14:58:21 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_calc(struct nvkm_clk *clk, bool wait)
|
2014-06-13 14:58:21 +10:00
|
|
|
{
|
|
|
|
atomic_set(&clk->waiting, 1);
|
|
|
|
schedule_work(&clk->work);
|
|
|
|
if (wait)
|
|
|
|
wait_event(clk->wait, !atomic_read(&clk->waiting));
|
|
|
|
return 0;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_info(struct nvkm_clk *clk, struct nvkm_pstate *pstate)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_domain *clock = clk->domains - 1;
|
|
|
|
struct nvkm_cstate *cstate;
|
2015-08-20 14:54:12 +10:00
|
|
|
struct nvkm_subdev *subdev = &clk->subdev;
|
2013-01-14 08:28:28 +10:00
|
|
|
char info[3][32] = { "", "", "" };
|
|
|
|
char name[4] = "--";
|
|
|
|
int i = -1;
|
|
|
|
|
|
|
|
if (pstate->pstate != 0xff)
|
|
|
|
snprintf(name, sizeof(name), "%02x", pstate->pstate);
|
|
|
|
|
|
|
|
while ((++clock)->name != nv_clk_src_max) {
|
|
|
|
u32 lo = pstate->base.domain[clock->name];
|
|
|
|
u32 hi = lo;
|
|
|
|
if (hi == 0)
|
|
|
|
continue;
|
|
|
|
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_debug(subdev, "%02x: %10d KHz\n", clock->name, lo);
|
2013-01-14 08:28:28 +10:00
|
|
|
list_for_each_entry(cstate, &pstate->list, head) {
|
|
|
|
u32 freq = cstate->domain[clock->name];
|
|
|
|
lo = min(lo, freq);
|
|
|
|
hi = max(hi, freq);
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_debug(subdev, "%10d KHz\n", freq);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
if (clock->mname && ++i < ARRAY_SIZE(info)) {
|
|
|
|
lo /= clock->mdiv;
|
|
|
|
hi /= clock->mdiv;
|
|
|
|
if (lo == hi) {
|
|
|
|
snprintf(info[i], sizeof(info[i]), "%s %d MHz",
|
|
|
|
clock->mname, lo);
|
|
|
|
} else {
|
|
|
|
snprintf(info[i], sizeof(info[i]),
|
|
|
|
"%s %d-%d MHz", clock->mname, lo, hi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_debug(subdev, "%s: %s %s %s\n", name, info[0], info[1], info[2]);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_del(struct nvkm_pstate *pstate)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_cstate *cstate, *temp;
|
2013-01-14 08:28:28 +10:00
|
|
|
|
|
|
|
list_for_each_entry_safe(cstate, temp, &pstate->list, head) {
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_cstate_del(cstate);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
list_del(&pstate->head);
|
|
|
|
kfree(pstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_new(struct nvkm_clk *clk, int idx)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_bios *bios = nvkm_bios(clk);
|
|
|
|
struct nvkm_domain *domain = clk->domains - 1;
|
|
|
|
struct nvkm_pstate *pstate;
|
|
|
|
struct nvkm_cstate *cstate;
|
2013-01-14 08:28:28 +10:00
|
|
|
struct nvbios_cstepE cstepE;
|
|
|
|
struct nvbios_perfE perfE;
|
|
|
|
u8 ver, hdr, cnt, len;
|
|
|
|
u16 data;
|
|
|
|
|
|
|
|
data = nvbios_perfEp(bios, idx, &ver, &hdr, &cnt, &len, &perfE);
|
|
|
|
if (!data)
|
|
|
|
return -EINVAL;
|
|
|
|
if (perfE.pstate == 0xff)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pstate = kzalloc(sizeof(*pstate), GFP_KERNEL);
|
|
|
|
cstate = &pstate->base;
|
|
|
|
if (!pstate)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&pstate->list);
|
|
|
|
|
|
|
|
pstate->pstate = perfE.pstate;
|
|
|
|
pstate->fanspeed = perfE.fanspeed;
|
|
|
|
cstate->voltage = perfE.voltage;
|
|
|
|
cstate->domain[nv_clk_src_core] = perfE.core;
|
|
|
|
cstate->domain[nv_clk_src_shader] = perfE.shader;
|
|
|
|
cstate->domain[nv_clk_src_mem] = perfE.memory;
|
|
|
|
cstate->domain[nv_clk_src_vdec] = perfE.vdec;
|
|
|
|
cstate->domain[nv_clk_src_dom6] = perfE.disp;
|
|
|
|
|
|
|
|
while (ver >= 0x40 && (++domain)->name != nv_clk_src_max) {
|
|
|
|
struct nvbios_perfS perfS;
|
|
|
|
u8 sver = ver, shdr = hdr;
|
|
|
|
u32 perfSe = nvbios_perfSp(bios, data, domain->bios,
|
|
|
|
&sver, &shdr, cnt, len, &perfS);
|
|
|
|
if (perfSe == 0 || sver != 0x40)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (domain->flags & NVKM_CLK_DOM_FLAG_CORE) {
|
2015-01-14 14:47:24 +10:00
|
|
|
perfS.v40.freq = nvkm_clk_adjust(clk, false,
|
|
|
|
pstate->pstate,
|
|
|
|
domain->bios,
|
|
|
|
perfS.v40.freq);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
cstate->domain[domain->name] = perfS.v40.freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = nvbios_cstepEm(bios, pstate->pstate, &ver, &hdr, &cstepE);
|
|
|
|
if (data) {
|
|
|
|
int idx = cstepE.index;
|
|
|
|
do {
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_cstate_new(clk, idx, pstate);
|
2013-01-14 08:28:28 +10:00
|
|
|
} while(idx--);
|
|
|
|
}
|
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_info(clk, pstate);
|
2013-01-14 08:28:28 +10:00
|
|
|
list_add_tail(&pstate->head, &clk->states);
|
|
|
|
clk->state_nr++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Adjustment triggers
|
|
|
|
*****************************************************************************/
|
|
|
|
static int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_clk_ustate_update(struct nvkm_clk *clk, int req)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_pstate *pstate;
|
2013-01-14 08:28:28 +10:00
|
|
|
int i = 0;
|
|
|
|
|
2014-05-18 01:04:16 -04:00
|
|
|
if (!clk->allow_reclock)
|
|
|
|
return -ENOSYS;
|
2013-01-14 08:28:28 +10:00
|
|
|
|
|
|
|
if (req != -1 && req != -2) {
|
|
|
|
list_for_each_entry(pstate, &clk->states, head) {
|
|
|
|
if (pstate->pstate == req)
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pstate->pstate != req)
|
|
|
|
return -EINVAL;
|
|
|
|
req = i;
|
|
|
|
}
|
|
|
|
|
2014-06-13 13:23:42 +10:00
|
|
|
return req + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_clk_nstate(struct nvkm_clk *clk, const char *mode, int arglen)
|
2014-06-13 13:23:42 +10:00
|
|
|
{
|
|
|
|
int ret = 1;
|
|
|
|
|
2014-12-22 17:11:40 +08:00
|
|
|
if (clk->allow_reclock && !strncasecmpz(mode, "auto", arglen))
|
|
|
|
return -2;
|
|
|
|
|
2014-06-13 13:23:42 +10:00
|
|
|
if (strncasecmpz(mode, "disabled", arglen)) {
|
|
|
|
char save = mode[arglen];
|
|
|
|
long v;
|
|
|
|
|
|
|
|
((char *)mode)[arglen] = '\0';
|
|
|
|
if (!kstrtol(mode, 0, &v)) {
|
2015-01-14 14:47:24 +10:00
|
|
|
ret = nvkm_clk_ustate_update(clk, v);
|
2014-06-13 13:23:42 +10:00
|
|
|
if (ret < 0)
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
((char *)mode)[arglen] = save;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret - 2;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_clk_ustate(struct nvkm_clk *clk, int req, int pwr)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
int ret = nvkm_clk_ustate_update(clk, req);
|
2014-06-13 13:23:42 +10:00
|
|
|
if (ret >= 0) {
|
|
|
|
if (ret -= 2, pwr) clk->ustate_ac = ret;
|
|
|
|
else clk->ustate_dc = ret;
|
2015-01-14 14:47:24 +10:00
|
|
|
return nvkm_pstate_calc(clk, true);
|
2014-06-13 13:23:42 +10:00
|
|
|
}
|
|
|
|
return ret;
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_clk_astate(struct nvkm_clk *clk, int req, int rel, bool wait)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
|
|
|
if (!rel) clk->astate = req;
|
|
|
|
if ( rel) clk->astate += rel;
|
|
|
|
clk->astate = min(clk->astate, clk->state_nr - 1);
|
|
|
|
clk->astate = max(clk->astate, 0);
|
2015-01-14 14:47:24 +10:00
|
|
|
return nvkm_pstate_calc(clk, wait);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_clk_tstate(struct nvkm_clk *clk, int req, int rel)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
|
|
|
if (!rel) clk->tstate = req;
|
|
|
|
if ( rel) clk->tstate += rel;
|
|
|
|
clk->tstate = min(clk->tstate, 0);
|
|
|
|
clk->tstate = max(clk->tstate, -(clk->state_nr - 1));
|
2015-01-14 14:47:24 +10:00
|
|
|
return nvkm_pstate_calc(clk, true);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_clk_dstate(struct nvkm_clk *clk, int req, int rel)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
|
|
|
if (!rel) clk->dstate = req;
|
|
|
|
if ( rel) clk->dstate += rel;
|
|
|
|
clk->dstate = min(clk->dstate, clk->state_nr - 1);
|
|
|
|
clk->dstate = max(clk->dstate, 0);
|
2015-01-14 14:47:24 +10:00
|
|
|
return nvkm_pstate_calc(clk, true);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
2014-06-13 13:23:42 +10:00
|
|
|
static int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_clk_pwrsrc(struct nvkm_notify *notify)
|
2014-06-13 13:23:42 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_clk *clk =
|
2014-08-10 04:10:20 +10:00
|
|
|
container_of(notify, typeof(*clk), pwrsrc_ntfy);
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_calc(clk, false);
|
2014-08-10 04:10:20 +10:00
|
|
|
return NVKM_NOTIFY_DROP;
|
2014-06-13 13:23:42 +10:00
|
|
|
}
|
|
|
|
|
2013-01-14 08:28:28 +10:00
|
|
|
/******************************************************************************
|
|
|
|
* subdev base class implementation
|
|
|
|
*****************************************************************************/
|
2014-06-13 13:23:42 +10:00
|
|
|
|
|
|
|
int
|
2015-01-14 14:47:24 +10:00
|
|
|
_nvkm_clk_fini(struct nvkm_object *object, bool suspend)
|
2014-06-13 13:23:42 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_clk *clk = (void *)object;
|
2014-08-10 04:10:20 +10:00
|
|
|
nvkm_notify_put(&clk->pwrsrc_ntfy);
|
2015-08-20 14:54:06 +10:00
|
|
|
return nvkm_subdev_fini(&clk->subdev, suspend);
|
2014-06-13 13:23:42 +10:00
|
|
|
}
|
|
|
|
|
2013-01-14 08:28:28 +10:00
|
|
|
int
|
2015-01-14 14:47:24 +10:00
|
|
|
_nvkm_clk_init(struct nvkm_object *object)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_clk *clk = (void *)object;
|
2015-08-20 14:54:12 +10:00
|
|
|
struct nvkm_subdev *subdev = &clk->subdev;
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_domain *clock = clk->domains;
|
2013-01-14 08:28:28 +10:00
|
|
|
int ret;
|
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
ret = nvkm_subdev_init(&clk->subdev);
|
2014-06-13 13:23:42 +10:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2013-01-14 08:28:28 +10:00
|
|
|
memset(&clk->bstate, 0x00, sizeof(clk->bstate));
|
|
|
|
INIT_LIST_HEAD(&clk->bstate.list);
|
|
|
|
clk->bstate.pstate = 0xff;
|
|
|
|
|
|
|
|
while (clock->name != nv_clk_src_max) {
|
|
|
|
ret = clk->read(clk, clock->name);
|
|
|
|
if (ret < 0) {
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_error(subdev, "%02x freq unknown\n", clock->name);
|
2013-01-14 08:28:28 +10:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
clk->bstate.base.domain[clock->name] = ret;
|
|
|
|
clock++;
|
|
|
|
}
|
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_info(clk, &clk->bstate);
|
2013-01-14 08:28:28 +10:00
|
|
|
|
|
|
|
clk->astate = clk->state_nr - 1;
|
|
|
|
clk->tstate = 0;
|
|
|
|
clk->dstate = 0;
|
|
|
|
clk->pstate = -1;
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_calc(clk, true);
|
2013-01-14 08:28:28 +10:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-01-14 14:47:24 +10:00
|
|
|
_nvkm_clk_dtor(struct nvkm_object *object)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_clk *clk = (void *)object;
|
|
|
|
struct nvkm_pstate *pstate, *temp;
|
2013-01-14 08:28:28 +10:00
|
|
|
|
2014-08-10 04:10:20 +10:00
|
|
|
nvkm_notify_fini(&clk->pwrsrc_ntfy);
|
2014-06-13 13:23:42 +10:00
|
|
|
|
2013-01-14 08:28:28 +10:00
|
|
|
list_for_each_entry_safe(pstate, temp, &clk->states, head) {
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_pstate_del(pstate);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
2015-08-20 14:54:06 +10:00
|
|
|
nvkm_subdev_destroy(&clk->subdev);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 14:47:24 +10:00
|
|
|
nvkm_clk_create_(struct nvkm_object *parent, struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass, struct nvkm_domain *clocks,
|
|
|
|
struct nvkm_pstate *pstates, int nb_pstates,
|
|
|
|
bool allow_reclock, int length, void **object)
|
2013-01-14 08:28:28 +10:00
|
|
|
{
|
2015-01-14 14:47:24 +10:00
|
|
|
struct nvkm_device *device = nv_device(parent);
|
|
|
|
struct nvkm_clk *clk;
|
2013-01-14 08:28:28 +10:00
|
|
|
int ret, idx, arglen;
|
|
|
|
const char *mode;
|
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
ret = nvkm_subdev_create_(parent, engine, oclass, 0, "CLK",
|
|
|
|
"clock", length, object);
|
2013-01-14 08:28:28 +10:00
|
|
|
clk = *object;
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&clk->states);
|
|
|
|
clk->domains = clocks;
|
2014-06-13 13:23:42 +10:00
|
|
|
clk->ustate_ac = -1;
|
|
|
|
clk->ustate_dc = -1;
|
2013-01-14 08:28:28 +10:00
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
INIT_WORK(&clk->work, nvkm_pstate_work);
|
2014-06-13 14:58:21 +10:00
|
|
|
init_waitqueue_head(&clk->wait);
|
|
|
|
atomic_set(&clk->waiting, 0);
|
|
|
|
|
2014-07-26 18:41:40 +09:00
|
|
|
/* If no pstates are provided, try and fetch them from the BIOS */
|
|
|
|
if (!pstates) {
|
|
|
|
idx = 0;
|
|
|
|
do {
|
2015-01-14 14:47:24 +10:00
|
|
|
ret = nvkm_pstate_new(clk, idx++);
|
2014-07-26 18:41:40 +09:00
|
|
|
} while (ret == 0);
|
|
|
|
} else {
|
|
|
|
for (idx = 0; idx < nb_pstates; idx++)
|
|
|
|
list_add_tail(&pstates[idx].head, &clk->states);
|
|
|
|
clk->state_nr = nb_pstates;
|
|
|
|
}
|
2013-01-14 08:28:28 +10:00
|
|
|
|
2014-05-18 01:04:16 -04:00
|
|
|
clk->allow_reclock = allow_reclock;
|
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
ret = nvkm_notify_init(NULL, &device->event, nvkm_clk_pwrsrc, true,
|
2014-08-10 04:10:20 +10:00
|
|
|
NULL, 0, 0, &clk->pwrsrc_ntfy);
|
2014-06-13 13:23:42 +10:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
mode = nvkm_stropt(device->cfgopt, "NvClkMode", &arglen);
|
2013-01-14 08:28:28 +10:00
|
|
|
if (mode) {
|
2015-01-14 14:47:24 +10:00
|
|
|
clk->ustate_ac = nvkm_clk_nstate(clk, mode, arglen);
|
|
|
|
clk->ustate_dc = nvkm_clk_nstate(clk, mode, arglen);
|
2013-01-14 08:28:28 +10:00
|
|
|
}
|
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
mode = nvkm_stropt(device->cfgopt, "NvClkModeAC", &arglen);
|
2014-06-13 13:23:42 +10:00
|
|
|
if (mode)
|
2015-01-14 14:47:24 +10:00
|
|
|
clk->ustate_ac = nvkm_clk_nstate(clk, mode, arglen);
|
2014-06-13 13:23:42 +10:00
|
|
|
|
2015-01-14 14:47:24 +10:00
|
|
|
mode = nvkm_stropt(device->cfgopt, "NvClkModeDC", &arglen);
|
2014-06-13 13:23:42 +10:00
|
|
|
if (mode)
|
2015-01-14 14:47:24 +10:00
|
|
|
clk->ustate_dc = nvkm_clk_nstate(clk, mode, arglen);
|
2014-06-13 13:23:42 +10:00
|
|
|
|
2013-01-14 08:28:28 +10:00
|
|
|
return 0;
|
|
|
|
}
|