[29/32] clk: Limit clocks on battery

Submitted by Karol Herbst on Nov. 17, 2017, 12:04 a.m.

Details

Message ID 20171117000436.2432-30-karolherbst@gmail.com
State New
Headers show
Series "Updated State of my clk patches" ( rev: 1 ) in Nouveau

Not browsing as part of any series.

Commit Message

Karol Herbst Nov. 17, 2017, 12:04 a.m.
Signed-off-by: Karol Herbst <karolherbst@gmail.com>
---
 drm/nouveau/include/nvkm/subdev/clk.h |  1 +
 drm/nouveau/nvkm/subdev/clk/base.c    | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

Patch hide | download patch | download mbox

diff --git a/drm/nouveau/include/nvkm/subdev/clk.h b/drm/nouveau/include/nvkm/subdev/clk.h
index df12bbd5..d0497e9b 100644
--- a/drm/nouveau/include/nvkm/subdev/clk.h
+++ b/drm/nouveau/include/nvkm/subdev/clk.h
@@ -119,6 +119,7 @@  struct nvkm_clk {
 	u8  boost_mode;
 	struct nvkm_clk_limit base_limit;
 	struct nvkm_clk_limit boost_limit;
+	struct nvkm_clk_limit batt_limit;
 	u32 max_khz;
 
 	/*XXX: die, these are here *only* to support the completely
diff --git a/drm/nouveau/nvkm/subdev/clk/base.c b/drm/nouveau/nvkm/subdev/clk/base.c
index ce427eaa..1f136862 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -99,6 +99,15 @@  nvkm_cstate_valid(struct nvkm_clk *clk, struct nvkm_cstate *cstate,
 		break;
 	}
 
+	if (!clk->pwrsrc) {
+		u32 blimit = clk->batt_limit.max_khz;
+
+		if (!limit)
+			limit = blimit;
+		else if (blimit)
+			limit = min(blimit, limit);
+	}
+
 	if (limit) {
 		for (; domain && domain->name != nv_clk_src_max; domain++) {
 			if (!(domain->flags & NVKM_CLK_DOM_FLAG_VPSTATE))
@@ -305,6 +314,15 @@  nvkm_pstate_find_best(struct nvkm_clk *clk, struct nvkm_pstate *pstate)
 		break;
 	}
 
+	if (!clk->pwrsrc) {
+		u8 blimit = clk->batt_limit.pstate;
+
+		if (!limit)
+			limit = blimit;
+		else if (blimit)
+			limit = min(blimit, limit);
+	}
+
 	if (!limit)
 		return pstate;
 
@@ -791,6 +809,8 @@  nvkm_clk_ctor(const struct nvkm_clk_func *func, struct nvkm_device *device,
 			nvkm_clk_fill_limit(&clk->boost_limit, &vpe);
 		if (!nvbios_vpstate_entry(bios, &h, h.base_id, &vpe))
 			nvkm_clk_fill_limit(&clk->base_limit, &vpe);
+		if (!nvbios_vpstate_entry(bios, &h, h.battery_id, &vpe))
+			nvkm_clk_fill_limit(&clk->batt_limit, &vpe);
 	}
 
 	clk->func = func;