From: Jani Nikula <jani.nikula@linux.intel.com>
To: Uma Shankar <uma.shankar@intel.com>, intel-gfx@lists.freedesktop.org
Cc: shobhit.kumar@intel.com
Subject: Re: [PATCH 02/12] drm/i915/bxt: Enable BXT DSI PLL
Date: Mon, 25 May 2015 19:10:53 +0300 [thread overview]
Message-ID: <87k2vwiqnm.fsf@intel.com> (raw)
In-Reply-To: <1432310765-2218-3-git-send-email-uma.shankar@intel.com>
On Fri, 22 May 2015, Uma Shankar <uma.shankar@intel.com> wrote:
> From: Shashank Sharma <shashank.sharma@intel.com>
>
> This patch adds new functions for BXT clock and PLL programming.
> They are:
> 1. configure_dsi_pll for BXT.
> This function does the basic math and generates the divider ratio
> based on requested pixclock, and program clock registers.
> 2. enable_dsi_pll function.
> This function programs the calculated clock values on the PLL.
> 3. intel_enable_dsi_pll
> Wrapper function to use same code for multiple platforms. It checks the
> platform and calls appropriate core pll enable function.
>
> Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
> Signed-off-by: Uma Shankar <uma.shankar@intel.com>
> ---
> drivers/gpu/drm/i915/i915_reg.h | 35 ++++++++++++++
> drivers/gpu/drm/i915/intel_dsi.c | 2 +-
> drivers/gpu/drm/i915/intel_dsi.h | 2 +-
> drivers/gpu/drm/i915/intel_dsi_pll.c | 85 +++++++++++++++++++++++++++++++++-
> 4 files changed, 121 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
> index 46ef269..b63bdce 100644
> --- a/drivers/gpu/drm/i915/i915_reg.h
> +++ b/drivers/gpu/drm/i915/i915_reg.h
> @@ -7352,6 +7352,41 @@ enum skl_disp_power_wells {
>
> /* MIPI DSI registers */
>
> +/* BXT DSI PLL Control */
The macro name says this already, no need for the comment.
> +#define BXT_DSI_PLL_CTL 0x161000
> +#define BXT_DSI_PLL_MASK_PVD_RATIO (3 << 16)
The convention is to have _SHIFT and _MASK at the end of the name.
> +#define BXT_DSI_PLL_PVD_RATIO_1 (1<<16)
Spaces around <<. Please also add macro for _SHIFT.
> +#define BXT_DSIC_16X_BY2 (1 << 10)
> +#define BXT_DSIC_16X_BY3 (1 << 11)
> +#define BXT_DSIC_16X_BY4 (3 << 10)
The convention is to shift the same amount for each alternative in a bit
field. E.g. (1 << 10), (2 << 10), (3 << 10).
> +#define BXT_DSIA_16X_BY2 (1 << 8)
> +#define BXT_DSIA_16X_BY3 (1 << 9)
> +#define BXT_DSIA_16X_BY4 (3 << 8)
Same.
> +#define BXT_DSI_MASK_FREQ_SEL (0xF << 8)
_MASK at the end of the name, and the convention is to define _SHIFT
first, _MASK next, and the possible alternatives after that, i.e.
#define FOO_SHIFT 16
#define FOO_MASK (3 << 16)
#define FOO_A (1 << 16)
> +#define BXT_DSI_PLL_RATIO_MAX 0x7D
> +#define BXT_DSI_PLL_RATIO_MIN 0x22
> +#define BXT_DSI_MASK_PLL_RATIO 0x7F
Same as above. The mask is 8 bits, i.e. 0xff.
The convention is to have bit names shifted by two spaces. For example,
#define REGISTER_NAME 0x50000
#define SOME_BIT (1 << 5)
And please no empty lines between bit names, group them together.
> +#define BXT_REF_CLOCK_KHZ 19500
> +
> +#define BXT_DSI_PLL_ENABLE 0x46080
> +#define BXT_DSI_PLL_DO_ENABLE (1 << 31)
> +#define BXT_DSI_PLL_LOCKED (1 << 30)
> +
> +/* BXT power well control2, for driver */
The macro name says this already, no need for the comment.
> +#define BXT_PWR_WELL_CTL2 0x45404
> +#define BXT_PWR_WELL_2_ENABLE (1 << 31)
> +#define BXT_PWR_WELL_2_ENABLED (1 << 30)
> +#define BXT_PWR_WELL_1_ENABLE (1 << 29)
> +#define BXT_PWR_WELL_1_ENABLED (1 << 28)
> +#define BXT_PWR_WELL_ENABLED (BXT_PWR_WELL_1_ENABLED | \
> + BXT_PWR_WELL_2_ENABLED)
> +#define GEN9_FUSE_STATUS 0x42000
> +#define GEN9_FUSE_PG2_ENABLED (1 << 25)
> +#define GEN9_FUSE_PG1_ENABLED (1 << 26)
> +#define GEN9_FUSE_PG0_ENABLED (1 << 27)
> +
BXT_PWR_WELL_CTL2 and GEN9_FUSE_STATUS are not used in this series at
all, please remove them from this patch (and perhaps send them in a
separate patch).
> #define _MIPI_PORT(port, a, c) _PORT3(port, a, 0, c) /* ports A and C only */
>
> #define _MIPIA_PORT_CTRL (VLV_DISPLAY_BASE + 0x61190)
> diff --git a/drivers/gpu/drm/i915/intel_dsi.c b/drivers/gpu/drm/i915/intel_dsi.c
> index 2419929e..1927546 100644
> --- a/drivers/gpu/drm/i915/intel_dsi.c
> +++ b/drivers/gpu/drm/i915/intel_dsi.c
> @@ -903,8 +903,8 @@ static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
> DRM_DEBUG_KMS("\n");
>
> intel_dsi_prepare(encoder);
> + intel_enable_dsi_pll(encoder);
>
> - vlv_enable_dsi_pll(encoder);
> }
>
> static enum drm_connector_status
> diff --git a/drivers/gpu/drm/i915/intel_dsi.h b/drivers/gpu/drm/i915/intel_dsi.h
> index 2784ac4..20cfcf07 100644
> --- a/drivers/gpu/drm/i915/intel_dsi.h
> +++ b/drivers/gpu/drm/i915/intel_dsi.h
> @@ -121,7 +121,7 @@ static inline struct intel_dsi *enc_to_intel_dsi(struct drm_encoder *encoder)
> return container_of(encoder, struct intel_dsi, base.base);
> }
>
> -extern void vlv_enable_dsi_pll(struct intel_encoder *encoder);
> +extern void intel_enable_dsi_pll(struct intel_encoder *encoder);
> extern void vlv_disable_dsi_pll(struct intel_encoder *encoder);
> extern u32 vlv_get_dsi_pclk(struct intel_encoder *encoder, int pipe_bpp);
>
> diff --git a/drivers/gpu/drm/i915/intel_dsi_pll.c b/drivers/gpu/drm/i915/intel_dsi_pll.c
> index 9688d99..a58f0a1 100644
> --- a/drivers/gpu/drm/i915/intel_dsi_pll.c
> +++ b/drivers/gpu/drm/i915/intel_dsi_pll.c
> @@ -237,7 +237,7 @@ static void vlv_configure_dsi_pll(struct intel_encoder *encoder)
> vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, dsi_mnp.dsi_pll_ctrl);
> }
>
> -void vlv_enable_dsi_pll(struct intel_encoder *encoder)
> +static void vlv_enable_dsi_pll(struct intel_encoder *encoder)
> {
> struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
> u32 tmp;
> @@ -368,3 +368,86 @@ u32 vlv_get_dsi_pclk(struct intel_encoder *encoder, int pipe_bpp)
>
> return pclk;
> }
> +
> +static bool bxt_configure_dsi_pll(struct intel_encoder *encoder)
> +{
> + struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
> + struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
> + u8 dsi_ratio;
> + u32 dsi_clk;
> + u32 val = 0;
Unnecessary initialization.
> +
> + dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
> + intel_dsi->lane_count);
> +
> + /*
> + * From clock diagram, to get PLL ratio divider, divide double of DSI
> + * link rate (i.e., 2*8x=16x frequency value) by ref clock. Make sure to
> + * round 'up' the result
> + */
> + dsi_ratio = DIV_ROUND_UP(dsi_clk * 2, BXT_REF_CLOCK_KHZ);
> + if (dsi_ratio < BXT_DSI_PLL_RATIO_MIN ||
> + dsi_ratio > BXT_DSI_PLL_RATIO_MAX) {
> + DRM_ERROR("Cant get a suitable ratio from DSI PLL ratios\n");
> + return false;
> + }
> +
> + /*
> + * Program DSI ratio and Select MIPIC and MIPIA PLL output as 8x
> + * Spec says both have to be programmed, even if one is not getting
> + * used. Configure MIPI_CLOCK_CTL dividers in modeset
> + */
> + val = I915_READ(BXT_DSI_PLL_CTL);
> + val &= ~BXT_DSI_PLL_MASK_PVD_RATIO;
> + val &= ~BXT_DSI_MASK_FREQ_SEL;
> + val &= ~BXT_DSI_MASK_PLL_RATIO;
> + val |= (dsi_ratio | BXT_DSIA_16X_BY2 | BXT_DSIC_16X_BY2);
> +
> + /* Prog PVD ratio =1 if ratio <= 50 */
I can read that from the code. The comments are for telling the reader
*why* this is being done. What's the magic 50?
> + if (dsi_ratio <= 50) {
> + val &= ~BXT_DSI_PLL_MASK_PVD_RATIO;
> + val |= BXT_DSI_PLL_PVD_RATIO_1;
> + }
> +
> + I915_WRITE(BXT_DSI_PLL_CTL, val);
Hmm, POSTING_READ?
> + return true;
> +}
> +
> +static void bxt_enable_dsi_pll(struct intel_encoder *encoder)
> +{
> + struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
> + u32 val = 0;
Unnecessary initialization, the first thing you do with val is assign to
it.
> +
> + DRM_DEBUG_KMS("\n");
> +
Perhaps you should check if DSI PLL is enabled here, and disable with a
warning if it is?
> + /* Configure PLL vales */
> + if (!bxt_configure_dsi_pll(encoder)) {
> + DRM_ERROR("Configure DSI PLL failed, abort PLL enable\n");
> + return;
> + }
> +
> + /* Enable DSI PLL */
> + val = I915_READ(BXT_DSI_PLL_ENABLE);
> + val |= BXT_DSI_PLL_DO_ENABLE;
> + I915_WRITE(BXT_DSI_PLL_ENABLE, val);
> +
> + /* Timeout and fail if PLL not locked */
> + if (wait_for(I915_READ(BXT_DSI_PLL_ENABLE) & BXT_DSI_PLL_LOCKED, 1)) {
> + DRM_ERROR("DSI PLL not locked\n");
> + return;
> + }
> +
> + DRM_DEBUG_KMS("DSI PLL locked\n");
> +}
> +
> +void intel_enable_dsi_pll(struct intel_encoder *encoder)
> +{
> + struct drm_device *dev = encoder->base.dev;
> +
> + if (IS_VALLEYVIEW(dev))
> + vlv_enable_dsi_pll(encoder);
> + else if (IS_BROXTON(dev))
> + bxt_enable_dsi_pll(encoder);
> + else
> + DRM_ERROR("Invalid DSI device to pre_pll_enable\n");
Please drop all such else branches. It's already evident that having a
few of them around leads to more and more added, and there is no end to
it.
> +}
> --
> 1.7.9.5
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2015-05-25 16:12 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-22 16:05 [PATCH 00/12] *** MIPI DSI Support for BXT *** Uma Shankar
2015-05-22 16:05 ` [PATCH 01/12] drm/i915/bxt: Initialize MIPI for BXT Uma Shankar
2015-05-22 16:05 ` [PATCH 02/12] drm/i915/bxt: Enable BXT DSI PLL Uma Shankar
2015-05-25 16:10 ` Jani Nikula [this message]
2015-05-22 16:05 ` [PATCH 03/12] drm/i915/bxt: Disable DSI PLL for BXT Uma Shankar
2015-05-25 16:12 ` Jani Nikula
2015-05-22 16:05 ` [PATCH 04/12] drm/i915/bxt: DSI prepare changes " Uma Shankar
2015-05-25 16:25 ` Jani Nikula
2015-05-22 16:05 ` [PATCH 05/12] drm/i915/bxt: DSI encoder support in CRTC modeset Uma Shankar
2015-05-25 10:13 ` Jani Nikula
2015-05-25 11:24 ` Jani Nikula
2015-05-25 10:25 ` Jani Nikula
2015-05-26 7:11 ` Daniel Vetter
2015-05-26 7:19 ` Jani Nikula
2015-05-26 8:26 ` Daniel Vetter
2015-05-22 16:05 ` [PATCH 06/12] drm/i915/bxt: DSI enable for BXT Uma Shankar
2015-05-25 16:39 ` Jani Nikula
2015-05-22 16:06 ` [PATCH 07/12] drm/i915/bxt: Program Tx Rx and Dphy clocks Uma Shankar
2015-05-25 16:52 ` Jani Nikula
2015-05-22 16:06 ` [PATCH 08/12] drm/i915/bxt: DSI disable and post-disable Uma Shankar
2015-05-25 16:44 ` Jani Nikula
2015-05-22 16:06 ` [PATCH 09/12] drm/i915/bxt: get_hw_state for BXT Uma Shankar
2015-05-22 16:06 ` [PATCH 10/12] drm/i915/bxt: get DSI pixelclock Uma Shankar
2015-05-25 16:54 ` Jani Nikula
2015-05-22 16:06 ` [PATCH 11/12] drm/i915/bxt: Modify BXT BLC according to VBT changes Uma Shankar
2015-05-25 10:03 ` Jani Nikula
2015-05-25 16:57 ` Jani Nikula
2015-05-22 16:06 ` [PATCH 12/12] drm/i915/bxt: Remove DSP CLK_GATE programming for BXT Uma Shankar
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=87k2vwiqnm.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=shobhit.kumar@intel.com \
--cc=uma.shankar@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.