Commit 7471bf4e authored by Jani Nikula's avatar Jani Nikula Committed by Daniel Vetter

drm/i915: clean up dsi pll calculation

Improve readability. No functional changes.

v2: use more rational types (Ville)
Signed-off-by: default avatarJani Nikula <jani.nikula@intel.com>
Reviewed-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 6364e67e
...@@ -162,53 +162,34 @@ static u32 dsi_clk_from_pclk(u32 pclk, int pixel_format, int lane_count) ...@@ -162,53 +162,34 @@ static u32 dsi_clk_from_pclk(u32 pclk, int pixel_format, int lane_count)
#endif #endif
static int dsi_calc_mnp(u32 dsi_clk, struct dsi_mnp *dsi_mnp) static int dsi_calc_mnp(int target_dsi_clk, struct dsi_mnp *dsi_mnp)
{ {
u32 m, n, p; unsigned int calc_m = 0, calc_p = 0;
u32 ref_clk; unsigned int m, n, p;
u32 error; int ref_clk = 25000;
u32 tmp_error; int delta = target_dsi_clk;
int target_dsi_clk;
int calc_dsi_clk;
u32 calc_m;
u32 calc_p;
u32 m_seed; u32 m_seed;
/* dsi_clk is expected in KHZ */ /* target_dsi_clk is expected in kHz */
if (dsi_clk < 300000 || dsi_clk > 1150000) { if (target_dsi_clk < 300000 || target_dsi_clk > 1150000) {
DRM_ERROR("DSI CLK Out of Range\n"); DRM_ERROR("DSI CLK Out of Range\n");
return -ECHRNG; return -ECHRNG;
} }
ref_clk = 25000; for (m = 62; m <= 92 && delta; m++) {
target_dsi_clk = dsi_clk; for (p = 2; p <= 6 && delta; p++) {
error = 0xFFFFFFFF; /*
tmp_error = 0xFFFFFFFF; * Find the optimal m and p divisors with minimal delta
calc_m = 0; * +/- the required clock
calc_p = 0; */
int calc_dsi_clk = (m * ref_clk) / p;
for (m = 62; m <= 92; m++) { int d = abs(target_dsi_clk - calc_dsi_clk);
for (p = 2; p <= 6; p++) { if (d < delta) {
/* Find the optimal m and p divisors delta = d;
with minimal error +/- the required clock */
calc_dsi_clk = (m * ref_clk) / p;
if (calc_dsi_clk == target_dsi_clk) {
calc_m = m;
calc_p = p;
error = 0;
break;
} else
tmp_error = abs(target_dsi_clk - calc_dsi_clk);
if (tmp_error < error) {
error = tmp_error;
calc_m = m; calc_m = m;
calc_p = p; calc_p = p;
} }
} }
if (error == 0)
break;
} }
m_seed = lfsr_converts[calc_m - 62]; m_seed = lfsr_converts[calc_m - 62];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment