Skip to contentSkip to conversation

drm/i915: go back to switch for VLV mem freq detection

PATCH Jesse Barnes 1 participant 1 message May 2, 2013

lore
Share & tools
lore

Jesse Barnes

author Reviewed-by Kenneth Graunke
#0 lore raw

Yeah, saw that too but was too ashamed... anyway it needs fixing. And apparently the docs are wrong on this anyway and 11 indicates 1333, while 0 or 1 is 800. Will post an updated one.

--
Jesse Barnes, Intel Open Source Technology Center

-------- Original message --------
From: Kenneth Graunke <[email protected]>
Date: 05/01/2013 6:38 PM (GMT-08:00)
To: Ben Widawsky <[email protected]>
Cc: Jesse Barnes <[email protected]>,[email protected]
Subject: Re: [Intel-gfx] [PATCH 3/3] drm/i915: go back to switch for VLV mem freq detection

Quoted 4 lines · Ben Widawsky
Quoted 3 lines · Jesse Barnes

We need to catch the invalid case and override it.

Jesse, it's actually worse than that:

Your parenthesis were off in the previous version, causing it to do the multiplication by 266 before the bitwise-and:

    800 + ((266 * (val >> 6)) & 3)

This meant that you always got 800 or 802 Mhz.

Also, even when corrected, your previous formula would return 1332 Mhz instead of 1333 Mhz, which is slightly off and doesn't work since you use it in explicit switch statements.

It might be worth mentioning in the commit message.

Quoted 30 lines
Quoted 30 lines

---
   drivers/gpu/drm/i915/intel_pm.c |   16 +++++++++++++++-

   1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_pm.c +15 -1
index 0f4b46e..0a3b0b3 100644
@@ -2902,7 +2902,21 @@ static void valleyview_enable_rps(struct drm_device *dev)
       GEN7_RC_CTL_TO_MODE);
 
    valleyview_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS, &val);
-	dev_priv->mem_freq = 800 + (266 * (val >> 6) & 3);
+	switch ((val >> 6) & 3) {
+	case 0:
+	 dev_priv->mem_freq = 800;
+	 break;
+	case 1:
+	 dev_priv->mem_freq = 1066;
+	 break;
+	case 2:
+	 dev_priv->mem_freq = 1333;
+	 break;
+	case 3:
+	 DRM_ERROR("invalid mem freq, assuming 800MHz\n");
+	 dev_priv->mem_freq = 800;
+	 break;
+	}
    DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq);
 
Quoted 5 lines

drivers/gpu/drm/i915/intel_pm.c static void valleyview_enable_rps(struct drm_device *dev) · line 2922

Quoted 1 line
drivers/gpu/drm/i915/intel_pm.c +0 -0
    DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no");

I guess it doesn't handle the last case, but:
dev_priv->mem_freq = 800 + (266 * (val))) + val/2

Don't use this method.  Presumably Ben meant (val >> 6) here, but even with that fix this formula returns 1067 rather than 1066, which is wrong.

Quoted 4 lines

or

u32 freqs[] = {800,1066,1333,800};
dev_priv->mem_freq = freqs[(val >> 6) & 3];

I like this table based approach best.  It's much more succinct than the switch statement, and exact.  Might be worth preserving the DRM_ERROR.

Quoted 6 lines

Are two ways I would have used before making a switch block :P

Just a thought, but perhaps we don't want to enable RPS if we can't reliably figure out the memory freq. (case 3)

For either the switch or Ben's table:

Incidentally, my Punit returns 3 here, but I believe the memory is actually 1066.  Not sure what the deal is.

--Ken

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx