Re: [PATCH 6/6] drm/i915: Use DIV_ROUND_CLOSEST for PWM calculations

Ville Syrjälä
2016-03-03T10:54:37Z

On Thu, Mar 03, 2016 at 10:25:06AM +0200, Jani Nikula wrote:
> On Wed, 02 Mar 2016, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > Supposedly we would want to get the PWM output as close as possible to
> > the target, so let's round to closest.
> >
> > Cc: Jani Nikula <jani.nikula@linux.intel.com>
> > Suggested-by: Jani Nikula <jani.nikula@linux.intel.com>
>
> I have zero recollection of asking this change, but since it makes sense
> I won't deny it was me.

https://lists.freedesktop.org/archives/intel-gfx/2015-December/081700.html

>
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>
>
>
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> > drivers/gpu/drm/i915/intel_panel.c | 14 +++++++-------
> > 1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
> > index 5cf377507162..0fe059bc7d80 100644
> > --- a/drivers/gpu/drm/i915/intel_panel.c
> > +++ b/drivers/gpu/drm/i915/intel_panel.c
> > @@ -1240,7 +1240,7 @@ static void intel_backlight_device_unregister(struct intel_connector *connector)
> > */
> > static u32 bxt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
> > {
> > - return KHz(19200) / pwm_freq_hz;
> > + return DIV_ROUND_CLOSEST(KHz(19200), pwm_freq_hz);
> > }
> >
> > /*
> > @@ -1258,7 +1258,7 @@ static u32 spt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
> > else
> > mul = 16;
> >
> > - return MHz(24) / (pwm_freq_hz * mul);
> > + return DIV_ROUND_CLOSEST(MHz(24), pwm_freq_hz * mul);
> > }
> >
> > /*
> > @@ -1281,7 +1281,7 @@ static u32 lpt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
> > else
> > clock = MHz(24); /* LPT:LP */
> >
> > - return clock / (pwm_freq_hz * mul);
> > + return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul);
> > }
> >
> > /*
> > @@ -1292,7 +1292,7 @@ static u32 pch_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
> > {
> > struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
> >
> > - return KHz(dev_priv->rawclk_freq) / (pwm_freq_hz * 128);
> > + return DIV_ROUND_CLOSEST(KHz(dev_priv->rawclk_freq), pwm_freq_hz * 128);
> > }
> >
> > /*
> > @@ -1313,7 +1313,7 @@ static u32 i9xx_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
> > else
> > clock = KHz(dev_priv->cdclk_freq);
> >
> > - return clock / (pwm_freq_hz * 32);
> > + return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 32);
> > }
> >
> > /*
> > @@ -1332,7 +1332,7 @@ static u32 i965_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
> > else
> > clock = KHz(dev_priv->cdclk_freq);
> >
> > - return clock / (pwm_freq_hz * 128);
> > + return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 128);
> > }
> >
> > /*
> > @@ -1356,7 +1356,7 @@ static u32 vlv_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
> > mul = 128;
> > }
> >
> > - return clock / (pwm_freq_hz * mul);
> > + return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul);
> > }
> >
> > static u32 get_backlight_max_vbt(struct intel_connector *connector)
>
> --
> Jani Nikula, Intel Open Source Technology Center

--
Ville Syrjälä
Intel OTC