[v3,03/29] volt: save the voltage range we are able to set

Submitted by Karol Herbst on April 7, 2016, 9:23 p.m.

Details

Message ID 1460064259-1243-4-git-send-email-nouveau@karolherbst.de
State New
Headers show
Series "Volting/Clocking improvements for Fermi and newer" ( rev: 3 ) in Nouveau

Not browsing as part of any series.

Commit Message

Karol Herbst April 7, 2016, 9:23 p.m.
We shouldn't set voltages below the min or above the max voltage the gpu is
able to set, so save the range.

Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
Reviewed-by: Martin Peres <martin.peres@free.fr>
Tested-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/include/nvkm/subdev/volt.h |  3 +++
 drm/nouveau/nvkm/subdev/volt/base.c    | 14 +++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/drm/nouveau/include/nvkm/subdev/volt.h b/drm/nouveau/include/nvkm/subdev/volt.h
index feff55c..b765f4f 100644
--- a/drm/nouveau/include/nvkm/subdev/volt.h
+++ b/drm/nouveau/include/nvkm/subdev/volt.h
@@ -12,6 +12,9 @@  struct nvkm_volt {
 		u32 uv;
 		u8 vid;
 	} vid[256];
+
+	u32 max_uv;
+	u32 min_uv;
 };
 
 int nvkm_volt_get(struct nvkm_volt *);
diff --git a/drm/nouveau/nvkm/subdev/volt/base.c b/drm/nouveau/nvkm/subdev/volt/base.c
index ef653b1..95fe065 100644
--- a/drm/nouveau/nvkm/subdev/volt/base.c
+++ b/drm/nouveau/nvkm/subdev/volt/base.c
@@ -123,6 +123,8 @@  nvkm_volt_parse_bios(struct nvkm_bios *bios, struct nvkm_volt *volt)
 	if (data && info.vidmask && info.base && info.step
 	    && !info.entry_based) {
 		nvkm_debug(subdev, "found header based VIDs\n");
+		volt->min_uv = info.min;
+		volt->max_uv = info.max;
 		for (i = 0; i < info.vidmask + 1; i++) {
 			if (info.base >= info.min &&
 				info.base <= info.max) {
@@ -135,6 +137,8 @@  nvkm_volt_parse_bios(struct nvkm_bios *bios, struct nvkm_volt *volt)
 		volt->vid_mask = info.vidmask;
 	} else if (data && info.vidmask && info.entry_based) {
 		nvkm_debug(subdev, "found entry based VIDs\n");
+		volt->min_uv = 0xffffffff;
+		volt->max_uv = 0;
 		for (i = 0; i < cnt; i++) {
 			data = nvbios_volt_entry_parse(bios, i, &ver, &hdr,
 						       &ivid);
@@ -142,9 +146,14 @@  nvkm_volt_parse_bios(struct nvkm_bios *bios, struct nvkm_volt *volt)
 				volt->vid[volt->vid_nr].uv = ivid.voltage;
 				volt->vid[volt->vid_nr].vid = ivid.vid;
 				volt->vid_nr++;
+				volt->min_uv = min(volt->min_uv, ivid.voltage);
+				volt->max_uv = max(volt->max_uv, ivid.voltage);
 			}
 		}
 		volt->vid_mask = info.vidmask;
+	} else if (data && info.type == NVBIOS_VOLT_PWM) {
+		volt->min_uv = info.base;
+		volt->max_uv = info.base + info.pwm_range;
 	}
 }
 
@@ -185,8 +194,11 @@  nvkm_volt_ctor(const struct nvkm_volt_func *func, struct nvkm_device *device,
 	volt->func = func;
 
 	/* Assuming the non-bios device should build the voltage table later */
-	if (bios)
+	if (bios) {
 		nvkm_volt_parse_bios(bios, volt);
+		nvkm_debug(&volt->subdev, "min: %iuv max: %iuv\n",
+			   volt->min_uv, volt->max_uv);
+	}
 
 	if (volt->vid_nr) {
 		for (i = 0; i < volt->vid_nr; i++) {