<div dir="ltr">Actually you are right. Sorry it's my mistake.<div>I was focusing on make the actual frequency match the desired frequency as much as possible.<br></div><div>But more <span style="font-size:12.8px">granularity in </span><span style="font-size:12.8px">backlight adjustment probably more important than that.</span></div><div><br></div><div><span style="font-size:12.8px">Will submit new version of this patch to fix this.</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 8, 2017 at 11:17 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"><span class="">On Mon, 2017-05-08 at 10:49 -0700, Puthikorn Voravootivat wrote:<br>
> This is not related to brightness control. This calculation is used to<br>
> set the PWM frequency.<br>
> Frequency = 27 Mhz / (F * 2^ Pn)<br>
><br>
> Lower Pn means higher value for F which mean more accuracy for this<br>
> calculation.<br>
<br>
</span>I am not sure I follow this. Quoting from the spec -<br>
"A larger Pn value (meaning more PWM generator control bits) provides a<br>
finer backlight adjustment (increased granularity), but also limits<br>
the maximum backlight frequency, as described in this section."<br>
<br>
and then again<br>
<br>
"Allowing Pn to be adjustable provides the flexibility of backlight<br>
dimming granularity vs. maximum backlight frequency."<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> On Sat, May 6, 2017 at 1:35 AM, Pandiyan, Dhinakaran<br>
> <<a href="mailto:dhinakaran.pandiyan@intel.com">dhinakaran.pandiyan@intel.com</a><wbr>> wrote:<br>
> On Wed, 2017-05-03 at 17:28 -0700, Puthikorn Voravootivat<br>
> 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>
> +++++++++++++++++++++++++++<br>
> > 1 file changed, 71 insertions(+)<br>
> ><br>
> > diff --git a/drivers/gpu/drm/i915/intel_<wbr>dp_aux_backlight.c<br>
> 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 @@<br>
> intel_dp_aux_set_dynamic_<wbr>backlight_percent(struct intel_dp<br>
> *intel_dp,<br>
> > }<br>
> > }<br>
> ><br>
> > +/*<br>
> > + * Set PWM Frequency divider to match desired frequency in<br>
> vbt.<br>
> > + * The PWM Frequency is calculated as 27Mhz / (F x P).<br>
> > + * - Where F = PWM Frequency Pre-Divider value programmed<br>
> by field 7:0 of the<br>
> > + * EDP_BACKLIGHT_FREQ_SET register (DPCD<br>
> Address 00728h)<br>
> > + * - Where P = 2^Pn, where Pn is the value programmed by<br>
> field 4:0 of the<br>
> > + * EDP_PWMGEN_BIT_COUNT register (DPCD Address<br>
> 00724h)<br>
> > + */<br>
> > +static void intel_dp_aux_set_pwm_freq(<wbr>struct<br>
> intel_connector *connector)<br>
> > +{<br>
> > + struct drm_i915_private *dev_priv =<br>
> to_i915(connector->base.dev);<br>
> > + struct intel_dp *intel_dp =<br>
> 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<br>
> maximum value or<br>
> > + * minimum value will applied automatically. So no<br>
> 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<br>
> \n", freq);<br>
> > + if (!freq) {<br>
> > + DRM_DEBUG_KMS("Use panel default backlight<br>
> 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<br>
> be between 1 and<br>
><br>
><br>
> What's the reason to use the lowest possible value of Pn? From<br>
> what I<br>
> understand, choosing a higher value of Pn offers more steps<br>
> for<br>
> brightness control.<br>
><br>
> -DK<br>
><br>
> > + * 255 while still in the range Pn_min and Pn_max<br>
> > + */<br>
> > + if (drm_dp_dpcd_readb(&intel_dp-><wbr>aux,<br>
> > +<br>
> DP_EDP_PWMGEN_BIT_COUNT_CAP_<wbr>MIN, &pn_min) != 1) {<br>
> > + DRM_DEBUG_KMS("Failed to read pwmgen bit count<br>
> cap min\n");<br>
> > + return;<br>
> > + }<br>
> > + if (drm_dp_dpcd_readb(&intel_dp-><wbr>aux,<br>
> > +<br>
> DP_EDP_PWMGEN_BIT_COUNT_CAP_<wbr>MAX, &pn_max) != 1) {<br>
> > + DRM_DEBUG_KMS("Failed to read pwmgen bit count<br>
> 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) <<br>
> 0) {<br>
> > + DRM_DEBUG_KMS("Failed to write aux pwmgen bit<br>
> count\n");<br>
> > + return;<br>
> > + }<br>
> > + if (drm_dp_dpcd_writeb(&intel_dp-<wbr>>aux,<br>
> > + DP_EDP_BACKLIGHT_FREQ_SET, (u8)<br>
> f) < 0) {<br>
> > + DRM_DEBUG_KMS("Failed to write aux backlight<br>
> freq\n");<br>
> > + return;<br>
> > + }<br>
> > +}<br>
> > +<br>
> > static void intel_dp_aux_enable_backlight(<wbr>struct<br>
> intel_connector *connector)<br>
> > {<br>
> > struct intel_dp *intel_dp =<br>
> 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,<br>
> &dpcd_buf) != 1) {<br>
> > @@ -150,6 +214,10 @@ static void<br>
> intel_dp_aux_enable_backlight(<wbr>struct intel_connector<br>
> *connector)<br>
> > DRM_DEBUG_KMS("Enable dynamic brightness.\n");<br>
> > }<br>
> ><br>
> > + freq_cap = intel_dp->edp_dpcd[2] &<br>
> DP_EDP_BACKLIGHT_FREQ_AUX_SET_<wbr>CAP;<br>
> > + if (freq_cap)<br>
> > + new_dpcd_buf |=<br>
> 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,<br>
> new_dpcd_buf) < 0) {<br>
> > @@ -157,6 +225,9 @@ static void<br>
> intel_dp_aux_enable_backlight(<wbr>struct intel_connector<br>
> *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,<br>
> connector->panel.backlight.<wbr>level);<br>
> > }<br>
><br>
><br>
><br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> ______________________________<wbr>_________________<br>
> Intel-gfx mailing list<br>
> <a href="mailto:Intel-gfx@lists.freedesktop.org">Intel-gfx@lists.freedesktop.<wbr>org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/intel-gfx" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/intel-gfx</a><br>
<br>
______________________________<wbr>_________________<br>
Intel-gfx mailing list<br>
<a href="mailto:Intel-gfx@lists.freedesktop.org">Intel-gfx@lists.freedesktop.<wbr>org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/intel-gfx" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/intel-gfx</a><br>
</div></div></blockquote></div><br></div>