Commit 35b36ff4 authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/mgag200: Split PLL compute functions by device type

Several PLL functions compute values for different device types. Split
them up to make the code more readable. No functional changes.
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Acked-by: default avatarSam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20210714142240.21979-8-tzimmermann@suse.de
parent 2dd04094
...@@ -349,7 +349,7 @@ static int mgag200_compute_pixpll_values_g200wb(struct mga_device *mdev, long cl ...@@ -349,7 +349,7 @@ static int mgag200_compute_pixpll_values_g200wb(struct mga_device *mdev, long cl
{ {
unsigned int vcomax, vcomin, pllreffreq; unsigned int vcomax, vcomin, pllreffreq;
unsigned int delta, tmpdelta; unsigned int delta, tmpdelta;
unsigned int testp, testm, testn, testp2; unsigned int testp, testm, testn;
unsigned int p, m, n, s; unsigned int p, m, n, s;
unsigned int computed; unsigned int computed;
...@@ -357,64 +357,29 @@ static int mgag200_compute_pixpll_values_g200wb(struct mga_device *mdev, long cl ...@@ -357,64 +357,29 @@ static int mgag200_compute_pixpll_values_g200wb(struct mga_device *mdev, long cl
delta = 0xffffffff; delta = 0xffffffff;
if (mdev->type == G200_EW3) { vcomax = 550000;
vcomax = 800000; vcomin = 150000;
vcomin = 400000; pllreffreq = 48000;
pllreffreq = 25000;
for (testp = 1; testp < 8; testp++) {
for (testp2 = 1; testp2 < 8; testp2++) {
if (testp < testp2)
continue;
if ((clock * testp * testp2) > vcomax)
continue;
if ((clock * testp * testp2) < vcomin)
continue;
for (testm = 1; testm < 26; testm++) {
for (testn = 32; testn < 2048 ; testn++) {
computed = (pllreffreq * testn) /
(testm * testp * testp2);
if (computed > clock)
tmpdelta = computed - clock;
else
tmpdelta = clock - computed;
if (tmpdelta < delta) {
delta = tmpdelta;
m = testm + 1;
n = testn + 1;
p = testp + 1;
s = testp2;
}
}
}
}
}
} else {
vcomax = 550000;
vcomin = 150000;
pllreffreq = 48000;
for (testp = 1; testp < 9; testp++) { for (testp = 1; testp < 9; testp++) {
if (clock * testp > vcomax) if (clock * testp > vcomax)
continue; continue;
if (clock * testp < vcomin) if (clock * testp < vcomin)
continue; continue;
for (testm = 1; testm < 17; testm++) { for (testm = 1; testm < 17; testm++) {
for (testn = 1; testn < 151; testn++) { for (testn = 1; testn < 151; testn++) {
computed = (pllreffreq * testn) / computed = (pllreffreq * testn) / (testm * testp);
(testm * testp); if (computed > clock)
if (computed > clock) tmpdelta = computed - clock;
tmpdelta = computed - clock; else
else tmpdelta = clock - computed;
tmpdelta = clock - computed; if (tmpdelta < delta) {
if (tmpdelta < delta) { delta = tmpdelta;
delta = tmpdelta; n = testn;
n = testn; m = testm;
m = testm; p = testp;
p = testp; s = 0;
s = 0;
}
} }
} }
} }
...@@ -671,66 +636,30 @@ static int mgag200_compute_pixpll_values_g200eh(struct mga_device *mdev, long cl ...@@ -671,66 +636,30 @@ static int mgag200_compute_pixpll_values_g200eh(struct mga_device *mdev, long cl
m = n = p = s = 0; m = n = p = s = 0;
if (mdev->type == G200_EH3) { vcomax = 800000;
vcomax = 3000000; vcomin = 400000;
vcomin = 1500000; pllreffreq = 33333;
pllreffreq = 25000;
delta = 0xffffffff; delta = 0xffffffff;
testp = 0; for (testp = 16; testp > 0; testp >>= 1) {
if (clock * testp > vcomax)
continue;
if (clock * testp < vcomin)
continue;
for (testm = 150; testm >= 6; testm--) { for (testm = 1; testm < 33; testm++) {
if (clock * testm > vcomax) for (testn = 17; testn < 257; testn++) {
continue; computed = (pllreffreq * testn) / (testm * testp);
if (clock * testm < vcomin)
continue;
for (testn = 120; testn >= 60; testn--) {
computed = (pllreffreq * testn) / testm;
if (computed > clock) if (computed > clock)
tmpdelta = computed - clock; tmpdelta = computed - clock;
else else
tmpdelta = clock - computed; tmpdelta = clock - computed;
if (tmpdelta < delta) { if (tmpdelta < delta) {
delta = tmpdelta; delta = tmpdelta;
n = testn + 1; n = testn;
m = testm + 1; m = testm;
p = testp + 1; p = testp;
}
if (delta == 0)
break;
}
if (delta == 0)
break;
}
} else {
vcomax = 800000;
vcomin = 400000;
pllreffreq = 33333;
delta = 0xffffffff;
for (testp = 16; testp > 0; testp >>= 1) {
if (clock * testp > vcomax)
continue;
if (clock * testp < vcomin)
continue;
for (testm = 1; testm < 33; testm++) {
for (testn = 17; testn < 257; testn++) {
computed = (pllreffreq * testn) /
(testm * testp);
if (computed > clock)
tmpdelta = computed - clock;
else
tmpdelta = clock - computed;
if (tmpdelta < delta) {
delta = tmpdelta;
n = testn;
m = testm;
p = testp;
}
} }
} }
} }
...@@ -812,6 +741,57 @@ static void mgag200_set_pixpll_g200eh(struct mga_device *mdev, ...@@ -812,6 +741,57 @@ static void mgag200_set_pixpll_g200eh(struct mga_device *mdev,
} }
} }
static int mgag200_compute_pixpll_values_g200eh3(struct mga_device *mdev, long clock,
struct mgag200_pll_values *pixpllc)
{
unsigned int vcomax, vcomin, pllreffreq;
unsigned int delta, tmpdelta;
unsigned int testp, testm, testn;
unsigned int p, m, n, s;
unsigned int computed;
m = n = p = s = 0;
vcomax = 3000000;
vcomin = 1500000;
pllreffreq = 25000;
delta = 0xffffffff;
testp = 0;
for (testm = 150; testm >= 6; testm--) {
if (clock * testm > vcomax)
continue;
if (clock * testm < vcomin)
continue;
for (testn = 120; testn >= 60; testn--) {
computed = (pllreffreq * testn) / testm;
if (computed > clock)
tmpdelta = computed - clock;
else
tmpdelta = clock - computed;
if (tmpdelta < delta) {
delta = tmpdelta;
n = testn + 1;
m = testm + 1;
p = testp + 1;
}
if (delta == 0)
break;
}
if (delta == 0)
break;
}
pixpllc->m = m;
pixpllc->n = n;
pixpllc->p = p;
pixpllc->s = s;
return 0;
}
static int mgag200_compute_pixpll_values_g200er(struct mga_device *mdev, long clock, static int mgag200_compute_pixpll_values_g200er(struct mga_device *mdev, long clock,
struct mgag200_pll_values *pixpllc) struct mgag200_pll_values *pixpllc)
{ {
...@@ -916,6 +896,58 @@ static void mgag200_set_pixpll_g200er(struct mga_device *mdev, ...@@ -916,6 +896,58 @@ static void mgag200_set_pixpll_g200er(struct mga_device *mdev,
udelay(50); udelay(50);
} }
static int mgag200_compute_pixpll_values_g200ew3(struct mga_device *mdev, long clock,
struct mgag200_pll_values *pixpllc)
{
unsigned int vcomax, vcomin, pllreffreq;
unsigned int delta, tmpdelta;
unsigned int testp, testm, testn, testp2;
unsigned int p, m, n, s;
unsigned int computed;
m = n = p = s = 0;
delta = 0xffffffff;
vcomax = 800000;
vcomin = 400000;
pllreffreq = 25000;
for (testp = 1; testp < 8; testp++) {
for (testp2 = 1; testp2 < 8; testp2++) {
if (testp < testp2)
continue;
if ((clock * testp * testp2) > vcomax)
continue;
if ((clock * testp * testp2) < vcomin)
continue;
for (testm = 1; testm < 26; testm++) {
for (testn = 32; testn < 2048 ; testn++) {
computed = (pllreffreq * testn) / (testm * testp * testp2);
if (computed > clock)
tmpdelta = computed - clock;
else
tmpdelta = clock - computed;
if (tmpdelta < delta) {
delta = tmpdelta;
m = testm + 1;
n = testn + 1;
p = testp + 1;
s = testp2;
}
}
}
}
}
pixpllc->m = m;
pixpllc->n = n;
pixpllc->p = p;
pixpllc->s = s;
return 0;
}
static void mgag200_crtc_set_plls(struct mga_device *mdev, long clock) static void mgag200_crtc_set_plls(struct mga_device *mdev, long clock)
{ {
struct mgag200_pll_values pixpll; struct mgag200_pll_values pixpll;
...@@ -931,19 +963,23 @@ static void mgag200_crtc_set_plls(struct mga_device *mdev, long clock) ...@@ -931,19 +963,23 @@ static void mgag200_crtc_set_plls(struct mga_device *mdev, long clock)
ret = mgag200_compute_pixpll_values_g200se(mdev, clock, &pixpll); ret = mgag200_compute_pixpll_values_g200se(mdev, clock, &pixpll);
break; break;
case G200_WB: case G200_WB:
case G200_EW3:
ret = mgag200_compute_pixpll_values_g200wb(mdev, clock, &pixpll); ret = mgag200_compute_pixpll_values_g200wb(mdev, clock, &pixpll);
break; break;
case G200_EV: case G200_EV:
ret = mgag200_compute_pixpll_values_g200ev(mdev, clock, &pixpll); ret = mgag200_compute_pixpll_values_g200ev(mdev, clock, &pixpll);
break; break;
case G200_EH: case G200_EH:
case G200_EH3:
ret = mgag200_compute_pixpll_values_g200eh(mdev, clock, &pixpll); ret = mgag200_compute_pixpll_values_g200eh(mdev, clock, &pixpll);
break; break;
case G200_EH3:
ret = mgag200_compute_pixpll_values_g200eh3(mdev, clock, &pixpll);
break;
case G200_ER: case G200_ER:
ret = mgag200_compute_pixpll_values_g200er(mdev, clock, &pixpll); ret = mgag200_compute_pixpll_values_g200er(mdev, clock, &pixpll);
break; break;
case G200_EW3:
ret = mgag200_compute_pixpll_values_g200ew3(mdev, clock, &pixpll);
break;
} }
if (ret) if (ret)
......
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