Skip to content

Commit 37f2248

Browse files
committed
drm/i915: Use DIV_ROUND_CLOSEST for PWM calculations
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> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/1456932138-14004-7-git-send-email-ville.syrjala@linux.intel.com Reviewed-by: Jani Nikula <jani.nikula@intel.com>
1 parent a457f54 commit 37f2248

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/gpu/drm/i915/intel_panel.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ static void intel_backlight_device_unregister(struct intel_connector *connector)
12401240
*/
12411241
static u32 bxt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
12421242
{
1243-
return KHz(19200) / pwm_freq_hz;
1243+
return DIV_ROUND_CLOSEST(KHz(19200), pwm_freq_hz);
12441244
}
12451245

12461246
/*
@@ -1258,7 +1258,7 @@ static u32 spt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
12581258
else
12591259
mul = 16;
12601260

1261-
return MHz(24) / (pwm_freq_hz * mul);
1261+
return DIV_ROUND_CLOSEST(MHz(24), pwm_freq_hz * mul);
12621262
}
12631263

12641264
/*
@@ -1281,7 +1281,7 @@ static u32 lpt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
12811281
else
12821282
clock = MHz(24); /* LPT:LP */
12831283

1284-
return clock / (pwm_freq_hz * mul);
1284+
return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul);
12851285
}
12861286

12871287
/*
@@ -1292,7 +1292,7 @@ static u32 pch_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
12921292
{
12931293
struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
12941294

1295-
return KHz(dev_priv->rawclk_freq) / (pwm_freq_hz * 128);
1295+
return DIV_ROUND_CLOSEST(KHz(dev_priv->rawclk_freq), pwm_freq_hz * 128);
12961296
}
12971297

12981298
/*
@@ -1313,7 +1313,7 @@ static u32 i9xx_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
13131313
else
13141314
clock = KHz(dev_priv->cdclk_freq);
13151315

1316-
return clock / (pwm_freq_hz * 32);
1316+
return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 32);
13171317
}
13181318

13191319
/*
@@ -1332,7 +1332,7 @@ static u32 i965_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
13321332
else
13331333
clock = KHz(dev_priv->cdclk_freq);
13341334

1335-
return clock / (pwm_freq_hz * 128);
1335+
return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 128);
13361336
}
13371337

13381338
/*
@@ -1356,7 +1356,7 @@ static u32 vlv_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz)
13561356
mul = 128;
13571357
}
13581358

1359-
return clock / (pwm_freq_hz * mul);
1359+
return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul);
13601360
}
13611361

13621362
static u32 get_backlight_max_vbt(struct intel_connector *connector)

0 commit comments

Comments
 (0)