<div dir="ltr">This is not related to brightness control. This calculation is used to set the PWM frequency.<div>Frequency = 27 Mhz / (F * 2^ Pn)<br></div><div>Lower Pn means higher value for F which mean more accuracy for this calculation.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, May 6, 2017 at 1:35 AM, Pandiyan, Dhinakaran <span dir="ltr"><<a href="mailto:dhinakaran.pandiyan@intel.com" target="_blank">dhinakaran.pandiyan@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, 2017-05-03 at 17:28 -0700, Puthikorn Voravootivat wrote:<br>
> Read desired PWM frequency from panel vbt and calculate the<br>
> value for divider in DPCD address 0x724 and 0x728 to match<br>
> that frequency as close as possible.<br>
><br>
> Signed-off-by: Puthikorn Voravootivat <<a href="mailto:puthik@chromium.org">puthik@chromium.org</a>><br>
> ---<br>
>  drivers/gpu/drm/i915/intel_dp_<wbr>aux_backlight.c | 71 +++++++++++++++++++++++++++<br>
>  1 file changed, 71 insertions(+)<br>
><br>
> diff --git a/drivers/gpu/drm/i915/intel_<wbr>dp_aux_backlight.c b/drivers/gpu/drm/i915/intel_<wbr>dp_aux_backlight.c<br>
> index fc26fea94fd4..441ad434a82b 100644<br>
> --- a/drivers/gpu/drm/i915/intel_<wbr>dp_aux_backlight.c<br>
> +++ b/drivers/gpu/drm/i915/intel_<wbr>dp_aux_backlight.c<br>
> @@ -113,12 +113,76 @@ intel_dp_aux_set_dynamic_<wbr>backlight_percent(struct intel_dp *intel_dp,<br>
>       }<br>
>  }<br>
><br>
> +/*<br>
> + * Set PWM Frequency divider to match desired frequency in vbt.<br>
> + * The PWM Frequency is calculated as 27Mhz / (F x P).<br>
> + * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the<br>
> + *             EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)<br>
> + * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the<br>
> + *             EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)<br>
> + */<br>
> +static void intel_dp_aux_set_pwm_freq(<wbr>struct intel_connector *connector)<br>
> +{<br>
> +     struct drm_i915_private *dev_priv = to_i915(connector->base.dev);<br>
> +     struct intel_dp *intel_dp = enc_to_intel_dp(&connector-><wbr>encoder->base);<br>
> +     int freq, fxp, f;<br>
> +     u8 pn, pn_min, pn_max;<br>
> +<br>
> +     /* Find desired value of (F x P)<br>
> +      * Note that, if F x P is out of supported range, the maximum value or<br>
> +      * minimum value will applied automatically. So no need to check that.<br>
> +      */<br>
> +     freq = dev_priv->vbt.backlight.pwm_<wbr>freq_hz;<br>
> +     DRM_DEBUG_KMS("VBT defined backlight frequency %u Hz\n", freq);<br>
> +     if (!freq) {<br>
> +             DRM_DEBUG_KMS("Use panel default backlight frequency\n");<br>
> +             return;<br>
> +     }<br>
> +<br>
> +     fxp = DP_EDP_BACKLIGHT_FREQ_BASE / freq;<br>
> +<br>
> +     /* Use lowest possible value of Pn to try to make F to be between 1 and<br>
<br>
</div></div>What's the reason to use the lowest possible value of Pn? From what I<br>
understand, choosing a higher value of Pn offers more steps for<br>
brightness control.<br>
<br>
-DK<br>
<div class="HOEnZb"><div class="h5"><br>
> +      * 255 while still in the range Pn_min and Pn_max<br>
> +      */<br>
> +     if (drm_dp_dpcd_readb(&intel_dp-><wbr>aux,<br>
> +                            DP_EDP_PWMGEN_BIT_COUNT_CAP_<wbr>MIN, &pn_min) != 1) {<br>
> +             DRM_DEBUG_KMS("Failed to read pwmgen bit count cap min\n");<br>
> +             return;<br>
> +     }<br>
> +     if (drm_dp_dpcd_readb(&intel_dp-><wbr>aux,<br>
> +                            DP_EDP_PWMGEN_BIT_COUNT_CAP_<wbr>MAX, &pn_max) != 1) {<br>
> +             DRM_DEBUG_KMS("Failed to read pwmgen bit count cap max\n");<br>
> +             return;<br>
> +     }<br>
> +     pn_min &= DP_EDP_PWMGEN_BIT_COUNT_MASK;<br>
> +     pn_max &= DP_EDP_PWMGEN_BIT_COUNT_MASK;<br>
> +<br>
> +     f = fxp >> pn_min;<br>
> +<br>
> +     for (pn = pn_min; pn < pn_max && f > 255; pn++)<br>
> +             f >>= 1;<br>
> +<br>
> +     f = clamp(f, 1, 255);<br>
> +<br>
> +     if (drm_dp_dpcd_writeb(&intel_dp-<wbr>>aux,<br>
> +                            DP_EDP_PWMGEN_BIT_COUNT, pn) < 0) {<br>
> +             DRM_DEBUG_KMS("Failed to write aux pwmgen bit count\n");<br>
> +             return;<br>
> +     }<br>
> +     if (drm_dp_dpcd_writeb(&intel_dp-<wbr>>aux,<br>
> +                            DP_EDP_BACKLIGHT_FREQ_SET, (u8) f) < 0) {<br>
> +             DRM_DEBUG_KMS("Failed to write aux backlight freq\n");<br>
> +             return;<br>
> +     }<br>
> +}<br>
> +<br>
>  static void intel_dp_aux_enable_backlight(<wbr>struct intel_connector *connector)<br>
>  {<br>
>       struct intel_dp *intel_dp = enc_to_intel_dp(&connector-><wbr>encoder->base);<br>
>       uint8_t dpcd_buf = 0;<br>
>       uint8_t new_dpcd_buf = 0;<br>
>       uint8_t edp_backlight_mode = 0;<br>
> +     bool freq_cap;<br>
><br>
>       if (drm_dp_dpcd_readb(&intel_dp-><wbr>aux,<br>
>                       DP_EDP_BACKLIGHT_MODE_SET_<wbr>REGISTER, &dpcd_buf) != 1) {<br>
> @@ -150,6 +214,10 @@ static void intel_dp_aux_enable_backlight(<wbr>struct intel_connector *connector)<br>
>               DRM_DEBUG_KMS("Enable dynamic brightness.\n");<br>
>       }<br>
><br>
> +     freq_cap = intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_<wbr>CAP;<br>
> +     if (freq_cap)<br>
> +             new_dpcd_buf |= DP_EDP_BACKLIGHT_FREQ_AUX_SET_<wbr>ENABLE;<br>
> +<br>
>       if (new_dpcd_buf != dpcd_buf) {<br>
>               if (drm_dp_dpcd_writeb(&intel_dp-<wbr>>aux,<br>
>                       DP_EDP_BACKLIGHT_MODE_SET_<wbr>REGISTER, new_dpcd_buf) < 0) {<br>
> @@ -157,6 +225,9 @@ static void intel_dp_aux_enable_backlight(<wbr>struct intel_connector *connector)<br>
>               }<br>
>       }<br>
><br>
> +     if (freq_cap)<br>
> +             intel_dp_aux_set_pwm_freq(<wbr>connector);<br>
> +<br>
>       set_aux_backlight_enable(<wbr>intel_dp, true);<br>
>       intel_dp_aux_set_backlight(<wbr>connector, connector->panel.backlight.<wbr>level);<br>
>  }<br>
<br>
</div></div></blockquote></div><br></div>