From: "Pandiyan, Dhinakaran" <dhinakaran.pandiyan@intel.com>
To: "puthik@chromium.org" <puthik@chromium.org>
Cc: "intel-gfx@lists.freedesktop.org"
<intel-gfx@lists.freedesktop.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v7 9/9] drm/i915: Set PWM divider to match desired frequency in vbt
Date: Sat, 13 May 2017 00:12:32 +0000 [thread overview]
Message-ID: <1494635550.12250.19.camel@dk-H97M-D3H> (raw)
In-Reply-To: <20170511230225.142870-10-puthik@chromium.org>
On Thu, 2017-05-11 at 16:02 -0700, Puthikorn Voravootivat wrote:
> Read desired PWM frequency from panel vbt and calculate the
> value for divider in DPCD address 0x724 and 0x728 to have
> as many bits as possible for PWM duty cyle for granularity of
> brightness adjustment while the frequency is still within 25%
> of the desired frequency.
I read a few eDP panel data sheets, the PWM frequencies all start from
~200Hz. If the VBT chooses this lowest value to allow for more
brightness control, and then this patch lowers the value by another 25%,
we'll end up below the panel allowed PWM frequency.
In fact, one of the systems I checked had PWM frequency as 200Hz in VBT
and the panel datasheet also had PWM frequency range starting from
200Hz. Have you considered this case?
-DK
>
> Signed-off-by: Puthikorn Voravootivat <puthik@chromium.org>
> ---
> drivers/gpu/drm/i915/intel_dp_aux_backlight.c | 81 +++++++++++++++++++++++++++
> 1 file changed, 81 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
> index 0b48851013cc..6f10a2f1ab76 100644
> --- a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
> +++ b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
> @@ -113,12 +113,86 @@ intel_dp_aux_set_dynamic_backlight_percent(struct intel_dp *intel_dp,
> }
> }
>
> +/*
> + * Set PWM Frequency divider to match desired frequency in vbt.
> + * The PWM Frequency is calculated as 27Mhz / (F x P).
> + * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the
> + * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)
> + * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the
> + * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)
> + */
> +static void intel_dp_aux_set_pwm_freq(struct intel_connector *connector)
> +{
> + struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
> + struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
> + int freq, fxp, fxp_min, fxp_max, fxp_actual, f = 1;
> + u8 pn, pn_min, pn_max;
> +
> + /* Find desired value of (F x P)
> + * Note that, if F x P is out of supported range, the maximum value or
> + * minimum value will applied automatically. So no need to check that.
> + */
> + freq = dev_priv->vbt.backlight.pwm_freq_hz;
> + DRM_DEBUG_KMS("VBT defined backlight frequency %u Hz\n", freq);
> + if (!freq) {
> + DRM_DEBUG_KMS("Use panel default backlight frequency\n");
> + return;
> + }
> +
> + fxp = KHz(DP_EDP_BACKLIGHT_FREQ_BASE_KHZ) / freq;
> +
> + /* Use highest possible value of Pn for more granularity of brightness
> + * adjustment while satifying the conditions below.
> + * - Pn is in the range of Pn_min and Pn_max
> + * - F is in the range of 1 and 255
> + * - Effective frequency is within 25% of desired frequency.
> + */
> + if (drm_dp_dpcd_readb(&intel_dp->aux,
> + DP_EDP_PWMGEN_BIT_COUNT_CAP_MIN, &pn_min) != 1) {
> + DRM_DEBUG_KMS("Failed to read pwmgen bit count cap min\n");
> + return;
> + }
> + if (drm_dp_dpcd_readb(&intel_dp->aux,
> + DP_EDP_PWMGEN_BIT_COUNT_CAP_MAX, &pn_max) != 1) {
> + DRM_DEBUG_KMS("Failed to read pwmgen bit count cap max\n");
> + return;
> + }
> + pn_min &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
> + pn_max &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
> +
> + fxp_min = fxp * 3 / 4;
> + fxp_max = fxp * 5 / 4;
You are allowing fxp between +/- 25% of the actual. This isn't same as
the "Effective frequency is within 25% of desired frequency." right? The
frequency can vary between -20% and +33%.
> + if (fxp_min < (1 << pn_min) || (255 << pn_max) < fxp_max) {
> + DRM_DEBUG_KMS("VBT defined backlight frequency out of range\n");
> + return;
> + }
> +
> + for (pn = pn_max; pn > pn_min; pn--) {
> + f = clamp(fxp >> pn, 1, 255);
> + fxp_actual = f << pn;
> + if (fxp_min <= fxp_actual && fxp_actual <= fxp_max)
> + break;
> + }
> +
> + if (drm_dp_dpcd_writeb(&intel_dp->aux,
> + DP_EDP_PWMGEN_BIT_COUNT, pn) < 0) {
> + DRM_DEBUG_KMS("Failed to write aux pwmgen bit count\n");
> + return;
> + }
> + if (drm_dp_dpcd_writeb(&intel_dp->aux,
> + DP_EDP_BACKLIGHT_FREQ_SET, (u8) f) < 0) {
> + DRM_DEBUG_KMS("Failed to write aux backlight freq\n");
> + return;
> + }
> +}
> +
> static void intel_dp_aux_enable_backlight(struct intel_connector *connector)
> {
> struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
> uint8_t dpcd_buf = 0;
> uint8_t new_dpcd_buf = 0;
> uint8_t edp_backlight_mode = 0;
> + bool freq_cap;
>
> if (drm_dp_dpcd_readb(&intel_dp->aux,
> DP_EDP_BACKLIGHT_MODE_SET_REGISTER, &dpcd_buf) != 1) {
> @@ -151,6 +225,10 @@ static void intel_dp_aux_enable_backlight(struct intel_connector *connector)
> DRM_DEBUG_KMS("Enable dynamic brightness.\n");
> }
>
> + freq_cap = intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP;
> + if (freq_cap)
> + new_dpcd_buf |= DP_EDP_BACKLIGHT_FREQ_AUX_SET_ENABLE;
> +
> if (new_dpcd_buf != dpcd_buf) {
> if (drm_dp_dpcd_writeb(&intel_dp->aux,
> DP_EDP_BACKLIGHT_MODE_SET_REGISTER, new_dpcd_buf) < 0) {
> @@ -158,6 +236,9 @@ static void intel_dp_aux_enable_backlight(struct intel_connector *connector)
> }
> }
>
> + if (freq_cap)
> + intel_dp_aux_set_pwm_freq(connector);
> +
> set_aux_backlight_enable(intel_dp, true);
> intel_dp_aux_set_backlight(connector, connector->panel.backlight.level);
> }
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2017-05-13 0:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-11 23:02 [PATCH v7 0/9] Enhancement to intel_dp_aux_backlight driver Puthikorn Voravootivat
2017-05-11 23:02 ` [PATCH v7 1/9] drm/i915: Fix cap check for " Puthikorn Voravootivat
2017-05-11 23:02 ` [PATCH v7 2/9] drm/i915: Correctly enable backlight brightness adjustment via DPCD Puthikorn Voravootivat
2017-05-11 23:02 ` [PATCH v7 3/9] drm/i915: Drop AUX backlight enable check for backlight control Puthikorn Voravootivat
2017-05-12 5:00 ` Pandiyan, Dhinakaran
2017-05-12 13:14 ` Jani Nikula
2017-05-12 18:10 ` Puthikorn Voravootivat
2017-05-12 20:19 ` Pandiyan, Dhinakaran
2017-05-11 23:02 ` [PATCH v7 4/9] drm/i915: Allow choosing how to adjust brightness if both supported Puthikorn Voravootivat
2017-05-11 23:02 ` [PATCH v7 5/9] drm/i915: Set backlight mode before enable backlight Puthikorn Voravootivat
2017-05-11 23:02 ` [PATCH v7 6/9] drm/i915: Add option to support dynamic backlight via DPCD Puthikorn Voravootivat
2017-05-12 4:02 ` Pandiyan, Dhinakaran
2017-05-11 23:02 ` [PATCH v7 7/9] drm/i915: Restore brightness level in aux backlight driver Puthikorn Voravootivat
2017-05-11 23:02 ` [PATCH v7 8/9] drm: Add definition for eDP backlight frequency Puthikorn Voravootivat
2017-05-11 23:02 ` [PATCH v7 9/9] drm/i915: Set PWM divider to match desired frequency in vbt Puthikorn Voravootivat
2017-05-13 0:12 ` Pandiyan, Dhinakaran [this message]
2017-05-13 0:31 ` Puthikorn Voravootivat
2017-05-15 23:07 ` Pandiyan, Dhinakaran
2017-05-16 0:43 ` Puthikorn Voravootivat
2017-05-16 6:21 ` Pandiyan, Dhinakaran
2017-05-16 18:07 ` Puthikorn Voravootivat
2017-05-16 20:29 ` Pandiyan, Dhinakaran
2017-05-16 20:56 ` Puthikorn Voravootivat
2017-05-16 21:21 ` Pandiyan, Dhinakaran
2017-05-17 0:39 ` Puthikorn Voravootivat
2017-05-17 18:31 ` Pandiyan, Dhinakaran
2017-05-11 23:21 ` ✓ Fi.CI.BAT: success for Enhancement to intel_dp_aux_backlight driver (rev6) 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=1494635550.12250.19.camel@dk-H97M-D3H \
--to=dhinakaran.pandiyan@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=puthik@chromium.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox