All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: Jani Nikula <jani.nikula@intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>
Subject: [PATCH 03/13] drm/i915/cnp: Get/set proper Raw clock frequency on CNP.
Date: Tue, 30 May 2017 15:42:53 -0700	[thread overview]
Message-ID: <1496184183-30740-3-git-send-email-rodrigo.vivi@intel.com> (raw)
In-Reply-To: <1496184183-30740-1-git-send-email-rodrigo.vivi@intel.com>

RAWCLK_FREQ register has changed for platforms with CNP+.

[29:26] This field provides the denominator for the fractional
	part of the microsecond counter divider.  The numerator
	is fixed at 1. Program this field to the denominator of
	the fractional portion of reference frequency minus one.
	If the fraction is 0, program to 0.
	0100b = Fraction .2 MHz = Fraction 1/5.
	0000b = Fraction .0 MHz.

[25:16] This field provides the integer part of the microsecond
	counter divider. Program this field to the integer portion
	of the reference frequenct minus one.

Also this register tells us that proper raw clock should be read
from SFUSE_STRAP and programmed to this register. Up to this point
on other platforms we are reading instead of programming it so
probably relying on whatever BIOS had configured here.

Now on let's follow the spec and also program this register
fetching the right value from SFUSE_STRAP as Spec tells us to do.

v2: Read from SFUSE_STRAP and Program RAWCLK_FREQ instead of
    reading the value relying someone else will program that
    for us.
v3: Add missing else. (Jani)
v4: Addressing all Ville's catches:
    Use macro for shift bits instead of defining shift.
    Remove shift from the cleaning bits with mask that already
    has it.
    Add missing I915_WRITE to actually write the reg.
    Stop using useless DIV_ROUND_* on divider that is exact
    dividion and use DIV_ROUND_CLOSEST for the fraction part.
v5: Remove useless Read-Modify-Write on raclk_freq reg. (Ville).
v6: Change is per PCH instead of per platform.

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_reg.h    |  5 +++++
 drivers/gpu/drm/i915/intel_cdclk.c | 29 ++++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 231ee86..cb83fb7 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -6838,6 +6838,10 @@ enum {
 #define  FDL_TP2_TIMER_SHIFT    10
 #define  FDL_TP2_TIMER_MASK     (3<<10)
 #define  RAWCLK_FREQ_MASK       0x3ff
+#define  CNP_RAWCLK_DIV_MASK	(0x3ff << 16)
+#define  CNP_RAWCLK_DIV(div)	((div) << 16)
+#define  CNP_RAWCLK_FRAC_MASK	(0xf << 26)
+#define  CNP_RAWCLK_FRAC(frac)	((frac) << 26)
 
 #define PCH_DPLL_TMR_CFG        _MMIO(0xc6208)
 
@@ -8141,6 +8145,7 @@ enum {
 /* SFUSE_STRAP */
 #define SFUSE_STRAP			_MMIO(0xc2014)
 #define  SFUSE_STRAP_FUSE_LOCK		(1<<13)
+#define  SFUSE_STRAP_RAW_FREQUENCY	(1<<8)
 #define  SFUSE_STRAP_DISPLAY_DISABLED	(1<<7)
 #define  SFUSE_STRAP_CRT_DISABLED	(1<<6)
 #define  SFUSE_STRAP_DDIB_DETECTED	(1<<2)
diff --git a/drivers/gpu/drm/i915/intel_cdclk.c b/drivers/gpu/drm/i915/intel_cdclk.c
index 2979297..634c89f 100644
--- a/drivers/gpu/drm/i915/intel_cdclk.c
+++ b/drivers/gpu/drm/i915/intel_cdclk.c
@@ -1780,6 +1780,30 @@ void intel_update_cdclk(struct drm_i915_private *dev_priv)
 			   DIV_ROUND_UP(dev_priv->cdclk.hw.cdclk, 1000));
 }
 
+static int cnp_rawclk(struct drm_i915_private *dev_priv)
+{
+	u32 rawclk;
+	int divider, fraction;
+
+	if (I915_READ(SFUSE_STRAP) & SFUSE_STRAP_RAW_FREQUENCY) {
+		/* 24 MHz */
+		divider = 24000;
+		fraction = 0;
+	} else {
+		/* 19.2 MHz */
+		divider = 19000;
+		fraction = 200;
+	}
+
+	rawclk = CNP_RAWCLK_DIV((divider / 1000) - 1);
+	if (fraction)
+		rawclk |= CNP_RAWCLK_FRAC(DIV_ROUND_CLOSEST(1000,
+							    fraction) - 1);
+
+	I915_WRITE(PCH_RAWCLK_FREQ, rawclk);
+	return divider + fraction;
+}
+
 static int pch_rawclk(struct drm_i915_private *dev_priv)
 {
 	return (I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK) * 1000;
@@ -1827,7 +1851,10 @@ static int g4x_hrawclk(struct drm_i915_private *dev_priv)
  */
 void intel_update_rawclk(struct drm_i915_private *dev_priv)
 {
-	if (HAS_PCH_SPLIT(dev_priv))
+
+	if (HAS_PCH_CNP(dev_priv))
+		dev_priv->rawclk_freq = cnp_rawclk(dev_priv);
+	else if (HAS_PCH_SPLIT(dev_priv))
 		dev_priv->rawclk_freq = pch_rawclk(dev_priv);
 	else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
 		dev_priv->rawclk_freq = vlv_hrawclk(dev_priv);
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2017-05-30 22:42 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-30 22:42 [PATCH 01/13] drm/i915/cnp: Introduce Cannonpoint PCH Rodrigo Vivi
2017-05-30 22:42 ` [PATCH 02/13] drm/i915/cnp: Add PCI ID for Cannonpoint LP PCH Rodrigo Vivi
2017-05-30 22:42 ` Rodrigo Vivi [this message]
2017-05-30 22:42 ` [PATCH 04/13] drm/i915/cnp: Backlight support for CNP Rodrigo Vivi
2017-06-01  2:15   ` Pandiyan, Dhinakaran
2017-06-01 16:28     ` Vivi, Rodrigo
2017-06-01 17:43       ` Pandiyan, Dhinakaran
2017-06-02  7:02         ` Jani Nikula
2017-05-30 22:42 ` [PATCH 05/13] drm/i915/cnp: add CNP gmbus support Rodrigo Vivi
2017-05-31 18:26   ` [PATCH] " Rodrigo Vivi
2017-05-31 18:29     ` Rodrigo Vivi
2017-05-31 21:31       ` Srivatsa, Anusha
2017-06-01  0:17     ` kbuild test robot
2017-05-30 22:42 ` [PATCH 06/13] drm/i915/cnp: Panel Power sequence changes for CNP PCH Rodrigo Vivi
2017-05-31 17:33   ` Clint Taylor
2017-05-31 21:08   ` Pandiyan, Dhinakaran
2017-05-31 21:45     ` Vivi, Rodrigo
2017-05-31 21:54     ` [PATCH] " Rodrigo Vivi
2017-05-31 23:07       ` Pandiyan, Dhinakaran
2017-05-31 23:46         ` Vivi, Rodrigo
2017-05-31 23:52           ` Pandiyan, Dhinakaran
2017-06-01  4:25       ` kbuild test robot
2017-05-30 22:42 ` [PATCH 07/13] drm/i915/cfl: Introduce Coffee Lake platform definition Rodrigo Vivi
2017-06-01 22:27   ` Srivatsa, Anusha
2017-06-01 22:48     ` Rodrigo Vivi
2017-06-01 23:14       ` Srivatsa, Anusha
2017-06-01 23:19         ` Vivi, Rodrigo
2017-06-01 23:23           ` Srivatsa, Anusha
2017-06-02 22:27             ` [PATCH] " Rodrigo Vivi
2017-05-30 22:42 ` [PATCH 08/13] drm/i915/cfl: Coffee Lake uses CNP PCH Rodrigo Vivi
2017-06-05 23:41   ` Srivatsa, Anusha
2017-05-30 22:42 ` [PATCH 09/13] drm/i915/cfl: Basic PM plumbing for Coffee Lake Rodrigo Vivi
2017-06-02 21:25   ` Pandiyan, Dhinakaran
2017-06-02 21:31     ` Pandiyan, Dhinakaran
2017-05-30 22:43 ` [PATCH 10/13] drm/i915/cfl: Add Coffee Lake PCI IDs for H and S Skus Rodrigo Vivi
2017-05-30 22:43 ` [PATCH 11/13] drm/i915/cfl: Add CFL PCI IDs for U SKU Rodrigo Vivi
2017-05-30 22:43 ` [PATCH 12/13] drm/i915/cfl: Introduce Coffee Lake workardounds Rodrigo Vivi
2017-05-30 22:43 ` [PATCH 13/13] drm/i915/cfl: Coffe Lake reuses Kabylake DMC Rodrigo Vivi
2017-06-02 21:49   ` Pandiyan, Dhinakaran
2017-05-30 22:59 ` ✓ Fi.CI.BAT: success for series starting with [01/13] drm/i915/cnp: Introduce Cannonpoint PCH Patchwork
2017-05-31 18:43 ` ✓ Fi.CI.BAT: success for series starting with [01/13] drm/i915/cnp: Introduce Cannonpoint PCH. (rev2) Patchwork
2017-05-31 22:12 ` ✓ Fi.CI.BAT: success for series starting with [01/13] drm/i915/cnp: Introduce Cannonpoint PCH. (rev3) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1496184183-30740-3-git-send-email-rodrigo.vivi@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.