21 #define MGAG200_LUT_SIZE 256
47 static inline void mga_wait_vsync(
struct mga_device *mdev)
49 unsigned int count = 0;
55 }
while ((status & 0x08) && (count < 250000));
61 }
while (!(status & 0x08) && (count < 250000));
64 static inline void mga_wait_busy(
struct mga_device *mdev)
66 unsigned int count = 0;
67 unsigned int status = 0;
71 }
while ((status & 0x01) && (count < 500000));
88 unsigned int vcomax, vcomin, pllreffreq;
89 unsigned int delta, tmpdelta, permitteddelta;
90 unsigned int testp, testm, testn;
92 unsigned int computed;
100 permitteddelta = clock * 5 / 1000;
102 for (testp = 8; testp > 0; testp /= 2) {
103 if (clock * testp > vcomax)
105 if (clock * testp < vcomin)
108 for (testn = 17; testn < 256; testn++) {
109 for (testm = 1; testm < 32; testm++) {
110 computed = (pllreffreq * testn) /
112 if (computed > clock)
113 tmpdelta = computed -
clock;
115 tmpdelta = clock - computed;
116 if (tmpdelta < delta) {
126 if (delta > permitteddelta) {
137 static int mga_g200wb_set_plls(
struct mga_device *mdev,
long clock)
139 unsigned int vcomax, vcomin, pllreffreq;
140 unsigned int delta, tmpdelta, permitteddelta;
141 unsigned int testp, testm, testn;
142 unsigned int p,
m,
n;
143 unsigned int computed;
144 int i,
j, tmpcount, vcount;
145 bool pll_locked =
false;
154 permitteddelta = clock * 5 / 1000;
156 for (testp = 1; testp < 9; testp++) {
157 if (clock * testp > vcomax)
159 if (clock * testp < vcomin)
162 for (testm = 1; testm < 17; testm++) {
163 for (testn = 1; testn < 151; testn++) {
164 computed = (pllreffreq * testn) /
166 if (computed > clock)
167 tmpdelta = computed -
clock;
169 tmpdelta = clock - computed;
170 if (tmpdelta < delta) {
173 m = (testm - 1) | ((n >> 1) & 0x80);
180 for (i = 0; i <= 32 && pll_locked ==
false; i++) {
260 for (j = 0; j < 30 && pll_locked ==
false; j++) {
262 if (tmpcount < vcount)
264 if ((tmpcount - vcount) > 2)
277 static int mga_g200ev_set_plls(
struct mga_device *mdev,
long clock)
279 unsigned int vcomax, vcomin, pllreffreq;
280 unsigned int delta, tmpdelta, permitteddelta;
281 unsigned int testp, testm, testn;
282 unsigned int p,
m,
n;
283 unsigned int computed;
292 permitteddelta = clock * 5 / 1000;
294 for (testp = 16; testp > 0; testp--) {
295 if (clock * testp > vcomax)
297 if (clock * testp < vcomin)
300 for (testn = 1; testn < 257; testn++) {
301 for (testm = 1; testm < 17; testm++) {
302 computed = (pllreffreq * testn) /
304 if (computed > clock)
305 tmpdelta = computed -
clock;
307 tmpdelta = clock - computed;
308 if (tmpdelta < delta) {
371 static int mga_g200eh_set_plls(
struct mga_device *mdev,
long clock)
373 unsigned int vcomax, vcomin, pllreffreq;
374 unsigned int delta, tmpdelta, permitteddelta;
375 unsigned int testp, testm, testn;
376 unsigned int p,
m,
n;
377 unsigned int computed;
378 int i,
j, tmpcount, vcount;
380 bool pll_locked =
false;
388 permitteddelta = clock * 5 / 1000;
390 for (testp = 16; testp > 0; testp--) {
391 if (clock * testp > vcomax)
393 if (clock * testp < vcomin)
396 for (testm = 1; testm < 33; testm++) {
397 for (testn = 1; testn < 257; testn++) {
398 computed = (pllreffreq * testn) /
400 if (computed > clock)
401 tmpdelta = computed -
clock;
403 tmpdelta = clock - computed;
404 if (tmpdelta < delta) {
407 m = (testm - 1) | ((n >> 1) & 0x80);
410 if ((clock * testp) >= 600000)
415 for (i = 0; i <= 32 && pll_locked ==
false; i++) {
452 for (j = 0; j < 30 && pll_locked ==
false; j++) {
454 if (tmpcount < vcount)
456 if ((tmpcount - vcount) > 2)
466 static int mga_g200er_set_plls(
struct mga_device *mdev,
long clock)
468 unsigned int vcomax, vcomin, pllreffreq;
469 unsigned int delta, tmpdelta;
470 int testr, testn, testm, testo;
471 unsigned int p,
m,
n;
472 unsigned int computed, vco;
474 const unsigned int m_div_val[] = { 1, 2, 4, 8 };
483 for (testr = 0; testr < 4; testr++) {
486 for (testn = 5; testn < 129; testn++) {
489 for (testm = 3; testm >= 0; testm--) {
492 for (testo = 5; testo < 33; testo++) {
493 vco = pllreffreq * (testn + 1) /
499 computed = vco / (m_div_val[testm] * (testo + 1));
500 if (computed > clock)
501 tmpdelta = computed -
clock;
503 tmpdelta = clock - computed;
504 if (tmpdelta < delta) {
506 m = testm | (testo << 3);
508 p = testr | (testr << 3);
526 tmp |= (0x3<<2) | 0xc0;
546 static int mga_crtc_set_plls(
struct mga_device *mdev,
long clock)
551 return mga_g200se_set_plls(mdev, clock);
554 return mga_g200wb_set_plls(mdev, clock);
557 return mga_g200ev_set_plls(mdev, clock);
560 return mga_g200eh_set_plls(mdev, clock);
563 return mga_g200er_set_plls(mdev, clock);
601 while (!(tmp & 0x1) && iter_max) {
614 while ((tmp & 0x2) && iter_max) {
623 static void mga_g200wb_commit(
struct drm_crtc *crtc)
667 while (
RREG8(0x1fda) & 0x08);
668 while (!(
RREG8(0x1fda) & 0x08));
681 static int mga_crtc_do_set_base(
struct drm_crtc *crtc,
683 int x,
int y,
int atomic)
686 struct drm_gem_object *obj;
718 if (&mdev->
mfbdev->mfb == mga_fb) {
722 DRM_ERROR(
"failed to kmap fbcon\n");
727 DRM_INFO(
"mga base %llx\n", gpu_addr);
734 static int mga_crtc_mode_set_base(
struct drm_crtc *crtc,
int x,
int y,
737 return mga_crtc_do_set_base(crtc, old_fb, x, y, 0);
740 static int mga_crtc_mode_set(
struct drm_crtc *crtc,
747 int hdisplay, hsyncstart, hsyncend, htotal;
748 int vdisplay, vsyncstart, vsyncend, vtotal;
750 int option = 0, option2 = 0;
752 unsigned char misc = 0;
753 unsigned char ext_vga[6];
754 unsigned char ext_vga_index24;
755 unsigned char dac_index90 = 0;
758 static unsigned char dacvalue[] = {
759 0, 0, 0, 0, 0, 0, 0x00, 0,
760 0, 0, 0, 0, 0, 0, 0, 0,
761 0, 0, 0, 0, 0, 0, 0, 0,
762 0x00, 0, 0xC9, 0xFF, 0xBF, 0x20, 0x1F, 0x20,
763 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
764 0x00, 0x00, 0x00, 0x00, 0, 0, 0, 0x40,
765 0x00, 0xB0, 0x00, 0xC2, 0x34, 0x14, 0x02, 0x83,
766 0x00, 0x93, 0x00, 0x77, 0x00, 0x00, 0x00, 0x3A,
767 0, 0, 0, 0, 0, 0, 0, 0,
768 0, 0, 0, 0, 0, 0, 0, 0
771 bppshift = mdev->
bpp_shifts[(crtc->
fb->bits_per_pixel >> 3) - 1];
773 switch (mdev->
type) {
785 option2 = 0x00008000;
790 option2 = 0x0000b000;
797 option2 = 0x0000b000;
803 option2 = 0x0000b000;
810 switch (crtc->
fb->bits_per_pixel) {
815 if (crtc->
fb->depth == 15)
834 for (i = 0; i <
sizeof(dacvalue); i++) {
839 ((i >= 0x13) && (i <= 0x17)) ||
842 ((i >= 0x1f) && (i <= 0x29)) ||
843 ((i >= 0x30) && (i <= 0x37)))
846 ((i == 0x2c) || (i == 0x2d) || (i == 0x2e)))
849 (i >= 0x44) && (i <= 0x4e))
869 pitch = crtc->
fb->pitches[0] / (crtc->
fb->bits_per_pixel / 8);
870 if (crtc->
fb->bits_per_pixel == 24)
871 pitch = pitch >> (4 - bppshift);
873 pitch = pitch >> (4 - bppshift);
878 htotal = mode->
htotal / 8 - 1;
881 if ((htotal & 0x07) == 0x06 || (htotal & 0x07) == 0x04)
887 vtotal = mode->
vtotal - 2;
902 WREG_CRT(3, (htotal & 0x1F) | 0x80);
904 WREG_CRT(5, ((htotal & 0x20) << 2) | (hsyncend & 0x1F));
906 WREG_CRT(7, ((vtotal & 0x100) >> 8) |
907 ((vdisplay & 0x100) >> 7) |
908 ((vsyncstart & 0x100) >> 6) |
909 ((vdisplay & 0x100) >> 5) |
910 ((vdisplay & 0x100) >> 4) |
911 ((vtotal & 0x200) >> 4)|
912 ((vdisplay & 0x200) >> 3) |
913 ((vsyncstart & 0x200) >> 2));
914 WREG_CRT(9, ((vdisplay & 0x200) >> 4) |
915 ((vdisplay & 0x200) >> 3));
923 WREG_CRT(17, (vsyncend & 0x0F) | 0x20);
937 ext_vga[0] |= (pitch & 0x300) >> 4;
938 ext_vga[1] = (((htotal - 4) & 0x100) >> 8) |
939 ((hdisplay & 0x100) >> 7) |
940 ((hsyncstart & 0x100) >> 6) |
942 ext_vga[2] = ((vtotal & 0xc00) >> 10) |
943 ((vdisplay & 0x400) >> 8) |
944 ((vdisplay & 0xc00) >> 7) |
945 ((vsyncstart & 0xc00) >> 5) |
946 ((vdisplay & 0x400) >> 3);
947 if (crtc->
fb->bits_per_pixel == 24)
948 ext_vga[3] = (((1 << bppshift) * 3) - 1) | 0x80;
950 ext_vga[3] = ((1 << bppshift) - 1) | 0x80;
955 ext_vga_index24 = 0x05;
961 mga_crtc_set_plls(mdev, mode->
clock);
963 for (i = 0; i < 6; i++) {
983 mga_crtc_do_set_base(crtc, old_fb, x, y, 0);
1009 if (crtc->
fb->bits_per_pixel > 16)
1011 else if (crtc->
fb->bits_per_pixel > 8)
1030 WREG8(0x1fde, 0x06);
1031 WREG8(0x1fdf, hi_pri_lvl);
1034 WREG8(0x1fdf, 0x03);
1036 WREG8(0x1fdf, 0x04);
1043 static int mga_suspend(
struct drm_crtc *crtc)
1065 option &= ~(0x1F8024);
1075 static int mga_resume(
struct drm_crtc *crtc)
1080 struct pci_dev *pdev = dev->pdev;
1101 static void mga_crtc_dpms(
struct drm_crtc *crtc,
int mode)
1105 u8 seq1 = 0, crtcext1 = 0;
1111 mga_crtc_load_lut(crtc);
1134 mga_wait_vsync(mdev);
1135 mga_wait_busy(mdev);
1155 static void mga_crtc_prepare(
struct drm_crtc *crtc)
1182 mga_g200wb_prepare(crtc);
1191 static void mga_crtc_commit(
struct drm_crtc *crtc)
1199 mga_g200wb_commit(crtc);
1229 for (i = start; i <
end; i++) {
1230 mga_crtc->
lut_r[
i] = red[
i] >> 8;
1231 mga_crtc->
lut_g[
i] = green[
i] >> 8;
1232 mga_crtc->
lut_b[
i] = blue[
i] >> 8;
1234 mga_crtc_load_lut(crtc);
1238 static void mga_crtc_destroy(
struct drm_crtc *crtc)
1248 .gamma_set = mga_crtc_gamma_set,
1250 .destroy = mga_crtc_destroy,
1254 .dpms = mga_crtc_dpms,
1255 .mode_fixup = mga_crtc_mode_fixup,
1256 .mode_set = mga_crtc_mode_set,
1257 .mode_set_base = mga_crtc_mode_set_base,
1258 .prepare = mga_crtc_prepare,
1259 .commit = mga_crtc_commit,
1260 .load_lut = mga_crtc_load_lut,
1264 static void mga_crtc_init(
struct drm_device *dev)
1267 struct mga_crtc *mga_crtc;
1270 mga_crtc = kzalloc(
sizeof(
struct mga_crtc) +
1274 if (mga_crtc ==
NULL)
1288 drm_crtc_helper_add(&mga_crtc->
base, &mga_helper_funcs);
1293 u16 blue,
int regno)
1297 mga_crtc->
lut_r[regno] = red >> 8;
1298 mga_crtc->
lut_g[regno] = green >> 8;
1299 mga_crtc->
lut_b[regno] = blue >> 8;
1304 u16 *blue,
int regno)
1308 *red = (
u16)mga_crtc->
lut_r[regno] << 8;
1309 *green = (
u16)mga_crtc->
lut_g[regno] << 8;
1310 *blue = (
u16)mga_crtc->
lut_b[regno] << 8;
1325 static bool mga_encoder_mode_fixup(
struct drm_encoder *encoder,
1332 static void mga_encoder_mode_set(
struct drm_encoder *encoder,
1344 static void mga_encoder_prepare(
struct drm_encoder *encoder)
1348 static void mga_encoder_commit(
struct drm_encoder *encoder)
1360 .dpms = mga_encoder_dpms,
1361 .mode_fixup = mga_encoder_mode_fixup,
1362 .mode_set = mga_encoder_mode_set,
1363 .prepare = mga_encoder_prepare,
1364 .commit = mga_encoder_commit,
1376 mga_encoder = kzalloc(
sizeof(
struct mga_encoder),
GFP_KERNEL);
1380 encoder = &mga_encoder->
base;
1385 drm_encoder_helper_add(encoder, &mga_encoder_helper_funcs);
1406 static int mga_vga_mode_valid(
struct drm_connector *connector,
1442 *connector,
bool force)
1447 static void mga_connector_destroy(
struct drm_connector *connector)
1456 .get_modes = mga_vga_get_modes,
1457 .mode_valid = mga_vga_mode_valid,
1463 .detect = mga_vga_detect,
1465 .destroy = mga_connector_destroy,
1471 struct mga_connector *mga_connector;
1473 mga_connector = kzalloc(
sizeof(
struct mga_connector),
GFP_KERNEL);
1477 connector = &mga_connector->
base;
1482 drm_connector_helper_add(connector, &mga_vga_connector_helper_funcs);
1485 if (!mga_connector->
i2c)
1486 DRM_ERROR(
"failed to add ddc bus\n");
1498 mdev->
mode_info.mode_config_initialized =
true;
1503 mdev->
dev->mode_config.fb_base = mdev->
mc.vram_base;
1505 mga_crtc_init(mdev->
dev);
1507 encoder = mga_encoder_init(mdev->
dev);
1509 DRM_ERROR(
"mga_encoder_init failed\n");
1513 connector = mga_vga_init(mdev->
dev);
1515 DRM_ERROR(
"mga_vga_init failed\n");
1523 DRM_ERROR(
"mga_fbdev_init failed\n");