1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2010 Matt Turner.
4 * Copyright 2012 Red Hat
6 * Authors: Matthew Garrett
11 #include <linux/delay.h>
12 #include <linux/pci.h>
14 #include <drm/drm_atomic_helper.h>
15 #include <drm/drm_atomic_state_helper.h>
16 #include <drm/drm_crtc_helper.h>
17 #include <drm/drm_damage_helper.h>
18 #include <drm/drm_format_helper.h>
19 #include <drm/drm_fourcc.h>
20 #include <drm/drm_gem_framebuffer_helper.h>
21 #include <drm/drm_plane_helper.h>
22 #include <drm/drm_print.h>
23 #include <drm/drm_probe_helper.h>
24 #include <drm/drm_simple_kms_helper.h>
26 #include "mgag200_drv.h"
28 #define MGAG200_LUT_SIZE 256
31 * This file contains setup code for the CRTC.
34 static void mga_crtc_load_lut(struct drm_crtc *crtc)
36 struct drm_device *dev = crtc->dev;
37 struct mga_device *mdev = to_mga_device(dev);
38 struct drm_framebuffer *fb;
39 u16 *r_ptr, *g_ptr, *b_ptr;
45 if (!mdev->display_pipe.plane.state)
48 fb = mdev->display_pipe.plane.state->fb;
50 r_ptr = crtc->gamma_store;
51 g_ptr = r_ptr + crtc->gamma_size;
52 b_ptr = g_ptr + crtc->gamma_size;
54 WREG8(DAC_INDEX + MGA1064_INDEX, 0);
56 if (fb && fb->format->cpp[0] * 8 == 16) {
57 int inc = (fb->format->depth == 15) ? 8 : 4;
59 for (i = 0; i < MGAG200_LUT_SIZE; i += inc) {
60 if (fb->format->depth == 16) {
61 if (i > (MGAG200_LUT_SIZE >> 1)) {
74 WREG8(DAC_INDEX + MGA1064_COL_PAL, r);
75 WREG8(DAC_INDEX + MGA1064_COL_PAL, *g_ptr++ >> 8);
76 WREG8(DAC_INDEX + MGA1064_COL_PAL, b);
80 for (i = 0; i < MGAG200_LUT_SIZE; i++) {
82 WREG8(DAC_INDEX + MGA1064_COL_PAL, *r_ptr++ >> 8);
83 WREG8(DAC_INDEX + MGA1064_COL_PAL, *g_ptr++ >> 8);
84 WREG8(DAC_INDEX + MGA1064_COL_PAL, *b_ptr++ >> 8);
88 static inline void mga_wait_vsync(struct mga_device *mdev)
90 unsigned long timeout = jiffies + HZ/10;
91 unsigned int status = 0;
94 status = RREG32(MGAREG_Status);
95 } while ((status & 0x08) && time_before(jiffies, timeout));
96 timeout = jiffies + HZ/10;
99 status = RREG32(MGAREG_Status);
100 } while (!(status & 0x08) && time_before(jiffies, timeout));
103 static inline void mga_wait_busy(struct mga_device *mdev)
105 unsigned long timeout = jiffies + HZ;
106 unsigned int status = 0;
108 status = RREG8(MGAREG_Status + 2);
109 } while ((status & 0x01) && time_before(jiffies, timeout));
112 #define P_ARRAY_SIZE 9
114 static int mga_g200se_set_plls(struct mga_device *mdev, long clock)
116 unsigned int vcomax, vcomin, pllreffreq;
117 unsigned int delta, tmpdelta, permitteddelta;
118 unsigned int testp, testm, testn;
119 unsigned int p, m, n;
120 unsigned int computed;
121 unsigned int pvalues_e4[P_ARRAY_SIZE] = {16, 14, 12, 10, 8, 6, 4, 2, 1};
125 if (mdev->unique_rev_id <= 0x03) {
133 permitteddelta = clock * 5 / 1000;
135 for (testp = 8; testp > 0; testp /= 2) {
136 if (clock * testp > vcomax)
138 if (clock * testp < vcomin)
141 for (testn = 17; testn < 256; testn++) {
142 for (testm = 1; testm < 32; testm++) {
143 computed = (pllreffreq * testn) /
145 if (computed > clock)
146 tmpdelta = computed - clock;
148 tmpdelta = clock - computed;
149 if (tmpdelta < delta) {
172 /* Permited delta is 0.5% as VESA Specification */
173 permitteddelta = clock * 5 / 1000;
175 for (i = 0 ; i < P_ARRAY_SIZE ; i++) {
176 testp = pvalues_e4[i];
178 if ((clock * testp) > vcomax)
180 if ((clock * testp) < vcomin)
183 for (testn = 50; testn <= 256; testn++) {
184 for (testm = 1; testm <= 32; testm++) {
185 computed = (pllreffreq * testn) /
187 if (computed > clock)
188 tmpdelta = computed - clock;
190 tmpdelta = clock - computed;
192 if (tmpdelta < delta) {
202 fvv = pllreffreq * (n + 1) / (m + 1);
203 fvv = (fvv - 800000) / 50000;
214 if (delta > permitteddelta) {
215 pr_warn("PLL delta too large\n");
219 WREG_DAC(MGA1064_PIX_PLLC_M, m);
220 WREG_DAC(MGA1064_PIX_PLLC_N, n);
221 WREG_DAC(MGA1064_PIX_PLLC_P, p);
223 if (mdev->unique_rev_id >= 0x04) {
224 WREG_DAC(0x1a, 0x09);
226 WREG_DAC(0x1a, 0x01);
233 static int mga_g200wb_set_plls(struct mga_device *mdev, long clock)
235 unsigned int vcomax, vcomin, pllreffreq;
236 unsigned int delta, tmpdelta;
237 unsigned int testp, testm, testn, testp2;
238 unsigned int p, m, n;
239 unsigned int computed;
240 int i, j, tmpcount, vcount;
241 bool pll_locked = false;
248 if (mdev->type == G200_EW3) {
254 for (testp = 1; testp < 8; testp++) {
255 for (testp2 = 1; testp2 < 8; testp2++) {
258 if ((clock * testp * testp2) > vcomax)
260 if ((clock * testp * testp2) < vcomin)
262 for (testm = 1; testm < 26; testm++) {
263 for (testn = 32; testn < 2048 ; testn++) {
264 computed = (pllreffreq * testn) /
265 (testm * testp * testp2);
266 if (computed > clock)
267 tmpdelta = computed - clock;
269 tmpdelta = clock - computed;
270 if (tmpdelta < delta) {
272 m = ((testn & 0x100) >> 1) |
275 p = ((testn & 0x600) >> 3) |
289 for (testp = 1; testp < 9; testp++) {
290 if (clock * testp > vcomax)
292 if (clock * testp < vcomin)
295 for (testm = 1; testm < 17; testm++) {
296 for (testn = 1; testn < 151; testn++) {
297 computed = (pllreffreq * testn) /
299 if (computed > clock)
300 tmpdelta = computed - clock;
302 tmpdelta = clock - computed;
303 if (tmpdelta < delta) {
315 for (i = 0; i <= 32 && pll_locked == false; i++) {
317 WREG8(MGAREG_CRTC_INDEX, 0x1e);
318 tmp = RREG8(MGAREG_CRTC_DATA);
320 WREG8(MGAREG_CRTC_DATA, tmp+1);
323 /* set pixclkdis to 1 */
324 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
325 tmp = RREG8(DAC_DATA);
326 tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS;
327 WREG8(DAC_DATA, tmp);
329 WREG8(DAC_INDEX, MGA1064_REMHEADCTL);
330 tmp = RREG8(DAC_DATA);
331 tmp |= MGA1064_REMHEADCTL_CLKDIS;
332 WREG8(DAC_DATA, tmp);
334 /* select PLL Set C */
335 tmp = RREG8(MGAREG_MEM_MISC_READ);
337 WREG8(MGAREG_MEM_MISC_WRITE, tmp);
339 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
340 tmp = RREG8(DAC_DATA);
341 tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN | 0x80;
342 WREG8(DAC_DATA, tmp);
347 WREG8(DAC_INDEX, MGA1064_VREF_CTL);
348 tmp = RREG8(DAC_DATA);
350 WREG8(DAC_DATA, tmp);
354 /* program pixel pll register */
355 WREG_DAC(MGA1064_WB_PIX_PLLC_N, n);
356 WREG_DAC(MGA1064_WB_PIX_PLLC_M, m);
357 WREG_DAC(MGA1064_WB_PIX_PLLC_P, p);
362 WREG8(DAC_INDEX, MGA1064_VREF_CTL);
363 tmp = RREG8(DAC_DATA);
365 WREG_DAC(MGA1064_VREF_CTL, tmp);
369 /* select the pixel pll */
370 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
371 tmp = RREG8(DAC_DATA);
372 tmp &= ~MGA1064_PIX_CLK_CTL_SEL_MSK;
373 tmp |= MGA1064_PIX_CLK_CTL_SEL_PLL;
374 WREG8(DAC_DATA, tmp);
376 WREG8(DAC_INDEX, MGA1064_REMHEADCTL);
377 tmp = RREG8(DAC_DATA);
378 tmp &= ~MGA1064_REMHEADCTL_CLKSL_MSK;
379 tmp |= MGA1064_REMHEADCTL_CLKSL_PLL;
380 WREG8(DAC_DATA, tmp);
382 /* reset dotclock rate bit */
383 WREG8(MGAREG_SEQ_INDEX, 1);
384 tmp = RREG8(MGAREG_SEQ_DATA);
386 WREG8(MGAREG_SEQ_DATA, tmp);
388 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
389 tmp = RREG8(DAC_DATA);
390 tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS;
391 WREG8(DAC_DATA, tmp);
393 vcount = RREG8(MGAREG_VCOUNT);
395 for (j = 0; j < 30 && pll_locked == false; j++) {
396 tmpcount = RREG8(MGAREG_VCOUNT);
397 if (tmpcount < vcount)
399 if ((tmpcount - vcount) > 2)
405 WREG8(DAC_INDEX, MGA1064_REMHEADCTL);
406 tmp = RREG8(DAC_DATA);
407 tmp &= ~MGA1064_REMHEADCTL_CLKDIS;
408 WREG_DAC(MGA1064_REMHEADCTL, tmp);
412 static int mga_g200ev_set_plls(struct mga_device *mdev, long clock)
414 unsigned int vcomax, vcomin, pllreffreq;
415 unsigned int delta, tmpdelta;
416 unsigned int testp, testm, testn;
417 unsigned int p, m, n;
418 unsigned int computed;
428 for (testp = 16; testp > 0; testp--) {
429 if (clock * testp > vcomax)
431 if (clock * testp < vcomin)
434 for (testn = 1; testn < 257; testn++) {
435 for (testm = 1; testm < 17; testm++) {
436 computed = (pllreffreq * testn) /
438 if (computed > clock)
439 tmpdelta = computed - clock;
441 tmpdelta = clock - computed;
442 if (tmpdelta < delta) {
452 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
453 tmp = RREG8(DAC_DATA);
454 tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS;
455 WREG8(DAC_DATA, tmp);
457 tmp = RREG8(MGAREG_MEM_MISC_READ);
459 WREG8(MGAREG_MEM_MISC_WRITE, tmp);
461 WREG8(DAC_INDEX, MGA1064_PIX_PLL_STAT);
462 tmp = RREG8(DAC_DATA);
463 WREG8(DAC_DATA, tmp & ~0x40);
465 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
466 tmp = RREG8(DAC_DATA);
467 tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
468 WREG8(DAC_DATA, tmp);
470 WREG_DAC(MGA1064_EV_PIX_PLLC_M, m);
471 WREG_DAC(MGA1064_EV_PIX_PLLC_N, n);
472 WREG_DAC(MGA1064_EV_PIX_PLLC_P, p);
476 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
477 tmp = RREG8(DAC_DATA);
478 tmp &= ~MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
479 WREG8(DAC_DATA, tmp);
483 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
484 tmp = RREG8(DAC_DATA);
485 tmp &= ~MGA1064_PIX_CLK_CTL_SEL_MSK;
486 tmp |= MGA1064_PIX_CLK_CTL_SEL_PLL;
487 WREG8(DAC_DATA, tmp);
489 WREG8(DAC_INDEX, MGA1064_PIX_PLL_STAT);
490 tmp = RREG8(DAC_DATA);
491 WREG8(DAC_DATA, tmp | 0x40);
493 tmp = RREG8(MGAREG_MEM_MISC_READ);
495 WREG8(MGAREG_MEM_MISC_WRITE, tmp);
497 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
498 tmp = RREG8(DAC_DATA);
499 tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS;
500 WREG8(DAC_DATA, tmp);
505 static int mga_g200eh_set_plls(struct mga_device *mdev, long clock)
507 unsigned int vcomax, vcomin, pllreffreq;
508 unsigned int delta, tmpdelta;
509 unsigned int testp, testm, testn;
510 unsigned int p, m, n;
511 unsigned int computed;
512 int i, j, tmpcount, vcount;
514 bool pll_locked = false;
518 if (mdev->type == G200_EH3) {
527 for (testm = 150; testm >= 6; testm--) {
528 if (clock * testm > vcomax)
530 if (clock * testm < vcomin)
532 for (testn = 120; testn >= 60; testn--) {
533 computed = (pllreffreq * testn) / testm;
534 if (computed > clock)
535 tmpdelta = computed - clock;
537 tmpdelta = clock - computed;
538 if (tmpdelta < delta) {
558 for (testp = 16; testp > 0; testp >>= 1) {
559 if (clock * testp > vcomax)
561 if (clock * testp < vcomin)
564 for (testm = 1; testm < 33; testm++) {
565 for (testn = 17; testn < 257; testn++) {
566 computed = (pllreffreq * testn) /
568 if (computed > clock)
569 tmpdelta = computed - clock;
571 tmpdelta = clock - computed;
572 if (tmpdelta < delta) {
578 if ((clock * testp) >= 600000)
584 for (i = 0; i <= 32 && pll_locked == false; i++) {
585 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
586 tmp = RREG8(DAC_DATA);
587 tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS;
588 WREG8(DAC_DATA, tmp);
590 tmp = RREG8(MGAREG_MEM_MISC_READ);
592 WREG8(MGAREG_MEM_MISC_WRITE, tmp);
594 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
595 tmp = RREG8(DAC_DATA);
596 tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
597 WREG8(DAC_DATA, tmp);
601 WREG_DAC(MGA1064_EH_PIX_PLLC_M, m);
602 WREG_DAC(MGA1064_EH_PIX_PLLC_N, n);
603 WREG_DAC(MGA1064_EH_PIX_PLLC_P, p);
607 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
608 tmp = RREG8(DAC_DATA);
609 tmp &= ~MGA1064_PIX_CLK_CTL_SEL_MSK;
610 tmp |= MGA1064_PIX_CLK_CTL_SEL_PLL;
611 WREG8(DAC_DATA, tmp);
613 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
614 tmp = RREG8(DAC_DATA);
615 tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS;
616 tmp &= ~MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
617 WREG8(DAC_DATA, tmp);
619 vcount = RREG8(MGAREG_VCOUNT);
621 for (j = 0; j < 30 && pll_locked == false; j++) {
622 tmpcount = RREG8(MGAREG_VCOUNT);
623 if (tmpcount < vcount)
625 if ((tmpcount - vcount) > 2)
635 static int mga_g200er_set_plls(struct mga_device *mdev, long clock)
637 unsigned int vcomax, vcomin, pllreffreq;
638 unsigned int delta, tmpdelta;
639 int testr, testn, testm, testo;
640 unsigned int p, m, n;
641 unsigned int computed, vco;
643 const unsigned int m_div_val[] = { 1, 2, 4, 8 };
652 for (testr = 0; testr < 4; testr++) {
655 for (testn = 5; testn < 129; testn++) {
658 for (testm = 3; testm >= 0; testm--) {
661 for (testo = 5; testo < 33; testo++) {
662 vco = pllreffreq * (testn + 1) /
668 computed = vco / (m_div_val[testm] * (testo + 1));
669 if (computed > clock)
670 tmpdelta = computed - clock;
672 tmpdelta = clock - computed;
673 if (tmpdelta < delta) {
675 m = testm | (testo << 3);
677 p = testr | (testr << 3);
684 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
685 tmp = RREG8(DAC_DATA);
686 tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS;
687 WREG8(DAC_DATA, tmp);
689 WREG8(DAC_INDEX, MGA1064_REMHEADCTL);
690 tmp = RREG8(DAC_DATA);
691 tmp |= MGA1064_REMHEADCTL_CLKDIS;
692 WREG8(DAC_DATA, tmp);
694 tmp = RREG8(MGAREG_MEM_MISC_READ);
695 tmp |= (0x3<<2) | 0xc0;
696 WREG8(MGAREG_MEM_MISC_WRITE, tmp);
698 WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL);
699 tmp = RREG8(DAC_DATA);
700 tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS;
701 tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
702 WREG8(DAC_DATA, tmp);
706 WREG_DAC(MGA1064_ER_PIX_PLLC_N, n);
707 WREG_DAC(MGA1064_ER_PIX_PLLC_M, m);
708 WREG_DAC(MGA1064_ER_PIX_PLLC_P, p);
715 static int mga_crtc_set_plls(struct mga_device *mdev, long clock)
722 return mga_g200se_set_plls(mdev, clock);
726 return mga_g200wb_set_plls(mdev, clock);
729 return mga_g200ev_set_plls(mdev, clock);
733 return mga_g200eh_set_plls(mdev, clock);
736 return mga_g200er_set_plls(mdev, clock);
740 misc = RREG8(MGA_MISC_IN);
741 misc &= ~MGAREG_MISC_CLK_SEL_MASK;
742 misc |= MGAREG_MISC_CLK_SEL_MGA_MSK;
743 WREG8(MGA_MISC_OUT, misc);
748 static void mga_g200wb_prepare(struct drm_crtc *crtc)
750 struct mga_device *mdev = to_mga_device(crtc->dev);
754 /* 1- The first step is to warn the BMC of an upcoming mode change.
755 * We are putting the misc<0> to output.*/
757 WREG8(DAC_INDEX, MGA1064_GEN_IO_CTL);
758 tmp = RREG8(DAC_DATA);
760 WREG_DAC(MGA1064_GEN_IO_CTL, tmp);
762 /* we are putting a 1 on the misc<0> line */
763 WREG8(DAC_INDEX, MGA1064_GEN_IO_DATA);
764 tmp = RREG8(DAC_DATA);
766 WREG_DAC(MGA1064_GEN_IO_DATA, tmp);
768 /* 2- Second step to mask and further scan request
769 * This will be done by asserting the remfreqmsk bit (XSPAREREG<7>)
771 WREG8(DAC_INDEX, MGA1064_SPAREREG);
772 tmp = RREG8(DAC_DATA);
774 WREG_DAC(MGA1064_SPAREREG, tmp);
776 /* 3a- the third step is to verifu if there is an active scan
777 * We are searching for a 0 on remhsyncsts <XSPAREREG<0>)
780 while (!(tmp & 0x1) && iter_max) {
781 WREG8(DAC_INDEX, MGA1064_SPAREREG);
782 tmp = RREG8(DAC_DATA);
787 /* 3b- this step occurs only if the remove is actually scanning
788 * we are waiting for the end of the frame which is a 1 on
789 * remvsyncsts (XSPAREREG<1>)
793 while ((tmp & 0x2) && iter_max) {
794 WREG8(DAC_INDEX, MGA1064_SPAREREG);
795 tmp = RREG8(DAC_DATA);
802 static void mga_g200wb_commit(struct drm_crtc *crtc)
805 struct mga_device *mdev = to_mga_device(crtc->dev);
807 /* 1- The first step is to ensure that the vrsten and hrsten are set */
808 WREG8(MGAREG_CRTCEXT_INDEX, 1);
809 tmp = RREG8(MGAREG_CRTCEXT_DATA);
810 WREG8(MGAREG_CRTCEXT_DATA, tmp | 0x88);
812 /* 2- second step is to assert the rstlvl2 */
813 WREG8(DAC_INDEX, MGA1064_REMHEADCTL2);
814 tmp = RREG8(DAC_DATA);
816 WREG8(DAC_DATA, tmp);
821 /* 3- deassert rstlvl2 */
823 WREG8(DAC_INDEX, MGA1064_REMHEADCTL2);
824 WREG8(DAC_DATA, tmp);
826 /* 4- remove mask of scan request */
827 WREG8(DAC_INDEX, MGA1064_SPAREREG);
828 tmp = RREG8(DAC_DATA);
830 WREG8(DAC_DATA, tmp);
832 /* 5- put back a 0 on the misc<0> line */
833 WREG8(DAC_INDEX, MGA1064_GEN_IO_DATA);
834 tmp = RREG8(DAC_DATA);
836 WREG_DAC(MGA1064_GEN_IO_DATA, tmp);
840 * This is how the framebuffer base address is stored in g200 cards:
841 * * Assume @offset is the gpu_addr variable of the framebuffer object
842 * * Then addr is the number of _pixels_ (not bytes) from the start of
843 * VRAM to the first pixel we want to display. (divided by 2 for 32bit
845 * * addr is stored in the CRTCEXT0, CRTCC and CRTCD registers
846 * addr<20> -> CRTCEXT0<6>
847 * addr<19-16> -> CRTCEXT0<3-0>
848 * addr<15-8> -> CRTCC<7-0>
849 * addr<7-0> -> CRTCD<7-0>
851 * CRTCEXT0 has to be programmed last to trigger an update and make the
852 * new addr variable take effect.
854 static void mgag200_set_startadd(struct mga_device *mdev,
855 unsigned long offset)
857 struct drm_device *dev = &mdev->base;
859 u8 crtcc, crtcd, crtcext0;
861 startadd = offset / 8;
864 * Can't store addresses any higher than that, but we also
865 * don't have more than 16 MiB of memory, so it should be fine.
867 drm_WARN_ON(dev, startadd > 0x1fffff);
869 RREG_ECRT(0x00, crtcext0);
871 crtcc = (startadd >> 8) & 0xff;
872 crtcd = startadd & 0xff;
874 crtcext0 |= ((startadd >> 14) & BIT(6)) |
875 ((startadd >> 16) & 0x0f);
877 WREG_CRT(0x0c, crtcc);
878 WREG_CRT(0x0d, crtcd);
879 WREG_ECRT(0x00, crtcext0);
882 static void mgag200_set_pci_regs(struct mga_device *mdev)
884 uint32_t option = 0, option2 = 0;
885 struct drm_device *dev = &mdev->base;
887 switch (mdev->type) {
894 option2 = 0x00008000;
899 option2 = 0x0000b000;
903 option2 = 0x0000b000;
908 option2 = 0x0000b000;
915 pci_write_config_dword(dev->pdev, PCI_MGA_OPTION, option);
918 pci_write_config_dword(dev->pdev, PCI_MGA_OPTION2, option2);
921 static void mgag200_set_dac_regs(struct mga_device *mdev)
925 /* 0x00: */ 0, 0, 0, 0, 0, 0, 0x00, 0,
926 /* 0x08: */ 0, 0, 0, 0, 0, 0, 0, 0,
927 /* 0x10: */ 0, 0, 0, 0, 0, 0, 0, 0,
928 /* 0x18: */ 0x00, 0, 0xC9, 0xFF, 0xBF, 0x20, 0x1F, 0x20,
929 /* 0x20: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
930 /* 0x28: */ 0x00, 0x00, 0x00, 0x00, 0, 0, 0, 0x40,
931 /* 0x30: */ 0x00, 0xB0, 0x00, 0xC2, 0x34, 0x14, 0x02, 0x83,
932 /* 0x38: */ 0x00, 0x93, 0x00, 0x77, 0x00, 0x00, 0x00, 0x3A,
933 /* 0x40: */ 0, 0, 0, 0, 0, 0, 0, 0,
934 /* 0x48: */ 0, 0, 0, 0, 0, 0, 0, 0
937 switch (mdev->type) {
940 dacvalue[MGA1064_VREF_CTL] = 0x03;
941 dacvalue[MGA1064_PIX_CLK_CTL] = MGA1064_PIX_CLK_CTL_SEL_PLL;
942 dacvalue[MGA1064_MISC_CTL] = MGA1064_MISC_CTL_DAC_EN |
943 MGA1064_MISC_CTL_VGA8 |
944 MGA1064_MISC_CTL_DAC_RAM_CS;
948 dacvalue[MGA1064_VREF_CTL] = 0x07;
951 dacvalue[MGA1064_PIX_CLK_CTL] = MGA1064_PIX_CLK_CTL_SEL_PLL;
952 dacvalue[MGA1064_MISC_CTL] = MGA1064_MISC_CTL_VGA8 |
953 MGA1064_MISC_CTL_DAC_RAM_CS;
957 dacvalue[MGA1064_MISC_CTL] = MGA1064_MISC_CTL_VGA8 |
958 MGA1064_MISC_CTL_DAC_RAM_CS;
964 for (i = 0; i < ARRAY_SIZE(dacvalue); i++) {
968 ((i >= 0x1f) && (i <= 0x29)) ||
969 ((i >= 0x30) && (i <= 0x37)))
971 if (IS_G200_SE(mdev) &&
972 ((i == 0x2c) || (i == 0x2d) || (i == 0x2e)))
974 if ((mdev->type == G200_EV ||
975 mdev->type == G200_WB ||
976 mdev->type == G200_EH ||
977 mdev->type == G200_EW3 ||
978 mdev->type == G200_EH3) &&
979 (i >= 0x44) && (i <= 0x4e))
982 WREG_DAC(i, dacvalue[i]);
985 if (mdev->type == G200_ER)
989 static void mgag200_init_regs(struct mga_device *mdev)
991 u8 crtcext3, crtcext4, misc;
993 mgag200_set_pci_regs(mdev);
994 mgag200_set_dac_regs(mdev);
1007 RREG_ECRT(0x03, crtcext3);
1009 crtcext3 |= BIT(7); /* enable MGA mode */
1012 WREG_ECRT(0x03, crtcext3);
1013 WREG_ECRT(0x04, crtcext4);
1015 if (mdev->type == G200_ER)
1016 WREG_ECRT(0x24, 0x5);
1018 if (mdev->type == G200_EW3)
1019 WREG_ECRT(0x34, 0x5);
1021 misc = RREG8(MGA_MISC_IN);
1022 misc |= MGAREG_MISC_IOADSEL |
1023 MGAREG_MISC_RAMMAPEN |
1024 MGAREG_MISC_HIGH_PG_SEL;
1025 WREG8(MGA_MISC_OUT, misc);
1028 static void mgag200_set_mode_regs(struct mga_device *mdev,
1029 const struct drm_display_mode *mode)
1031 unsigned int hdisplay, hsyncstart, hsyncend, htotal;
1032 unsigned int vdisplay, vsyncstart, vsyncend, vtotal;
1033 u8 misc, crtcext1, crtcext2, crtcext5;
1035 hdisplay = mode->hdisplay / 8 - 1;
1036 hsyncstart = mode->hsync_start / 8 - 1;
1037 hsyncend = mode->hsync_end / 8 - 1;
1038 htotal = mode->htotal / 8 - 1;
1040 /* Work around hardware quirk */
1041 if ((htotal & 0x07) == 0x06 || (htotal & 0x07) == 0x04)
1044 vdisplay = mode->vdisplay - 1;
1045 vsyncstart = mode->vsync_start - 1;
1046 vsyncend = mode->vsync_end - 1;
1047 vtotal = mode->vtotal - 2;
1049 misc = RREG8(MGA_MISC_IN);
1051 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1052 misc |= MGAREG_MISC_HSYNCPOL;
1054 misc &= ~MGAREG_MISC_HSYNCPOL;
1056 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1057 misc |= MGAREG_MISC_VSYNCPOL;
1059 misc &= ~MGAREG_MISC_VSYNCPOL;
1061 crtcext1 = (((htotal - 4) & 0x100) >> 8) |
1062 ((hdisplay & 0x100) >> 7) |
1063 ((hsyncstart & 0x100) >> 6) |
1065 if (mdev->type == G200_WB || mdev->type == G200_EW3)
1066 crtcext1 |= BIT(7) | /* vrsten */
1067 BIT(3); /* hrsten */
1069 crtcext2 = ((vtotal & 0xc00) >> 10) |
1070 ((vdisplay & 0x400) >> 8) |
1071 ((vdisplay & 0xc00) >> 7) |
1072 ((vsyncstart & 0xc00) >> 5) |
1073 ((vdisplay & 0x400) >> 3);
1076 WREG_CRT(0, htotal - 4);
1077 WREG_CRT(1, hdisplay);
1078 WREG_CRT(2, hdisplay);
1079 WREG_CRT(3, (htotal & 0x1F) | 0x80);
1080 WREG_CRT(4, hsyncstart);
1081 WREG_CRT(5, ((htotal & 0x20) << 2) | (hsyncend & 0x1F));
1082 WREG_CRT(6, vtotal & 0xFF);
1083 WREG_CRT(7, ((vtotal & 0x100) >> 8) |
1084 ((vdisplay & 0x100) >> 7) |
1085 ((vsyncstart & 0x100) >> 6) |
1086 ((vdisplay & 0x100) >> 5) |
1087 ((vdisplay & 0x100) >> 4) | /* linecomp */
1088 ((vtotal & 0x200) >> 4) |
1089 ((vdisplay & 0x200) >> 3) |
1090 ((vsyncstart & 0x200) >> 2));
1091 WREG_CRT(9, ((vdisplay & 0x200) >> 4) |
1092 ((vdisplay & 0x200) >> 3));
1093 WREG_CRT(16, vsyncstart & 0xFF);
1094 WREG_CRT(17, (vsyncend & 0x0F) | 0x20);
1095 WREG_CRT(18, vdisplay & 0xFF);
1097 WREG_CRT(21, vdisplay & 0xFF);
1098 WREG_CRT(22, (vtotal + 1) & 0xFF);
1100 WREG_CRT(24, vdisplay & 0xFF);
1102 WREG_ECRT(0x01, crtcext1);
1103 WREG_ECRT(0x02, crtcext2);
1104 WREG_ECRT(0x05, crtcext5);
1106 WREG8(MGA_MISC_OUT, misc);
1108 mga_crtc_set_plls(mdev, mode->clock);
1111 static u8 mgag200_get_bpp_shift(struct mga_device *mdev,
1112 const struct drm_format_info *format)
1114 return mdev->bpp_shifts[format->cpp[0] - 1];
1118 * Calculates the HW offset value from the framebuffer's pitch. The
1119 * offset is a multiple of the pixel size and depends on the display
1122 static u32 mgag200_calculate_offset(struct mga_device *mdev,
1123 const struct drm_framebuffer *fb)
1125 u32 offset = fb->pitches[0] / fb->format->cpp[0];
1126 u8 bppshift = mgag200_get_bpp_shift(mdev, fb->format);
1128 if (fb->format->cpp[0] * 8 == 24)
1129 offset = (offset * 3) >> (4 - bppshift);
1131 offset = offset >> (4 - bppshift);
1136 static void mgag200_set_offset(struct mga_device *mdev,
1137 const struct drm_framebuffer *fb)
1139 u8 crtc13, crtcext0;
1140 u32 offset = mgag200_calculate_offset(mdev, fb);
1142 RREG_ECRT(0, crtcext0);
1144 crtc13 = offset & 0xff;
1146 crtcext0 &= ~MGAREG_CRTCEXT0_OFFSET_MASK;
1147 crtcext0 |= (offset >> 4) & MGAREG_CRTCEXT0_OFFSET_MASK;
1149 WREG_CRT(0x13, crtc13);
1150 WREG_ECRT(0x00, crtcext0);
1153 static void mgag200_set_format_regs(struct mga_device *mdev,
1154 const struct drm_framebuffer *fb)
1156 struct drm_device *dev = &mdev->base;
1157 const struct drm_format_info *format = fb->format;
1158 unsigned int bpp, bppshift, scale;
1159 u8 crtcext3, xmulctrl;
1161 bpp = format->cpp[0] * 8;
1163 bppshift = mgag200_get_bpp_shift(mdev, format);
1166 scale = ((1 << bppshift) * 3) - 1;
1169 scale = (1 << bppshift) - 1;
1173 RREG_ECRT(3, crtcext3);
1177 xmulctrl = MGA1064_MUL_CTL_8bits;
1180 if (format->depth == 15)
1181 xmulctrl = MGA1064_MUL_CTL_15bits;
1183 xmulctrl = MGA1064_MUL_CTL_16bits;
1186 xmulctrl = MGA1064_MUL_CTL_24bits;
1189 xmulctrl = MGA1064_MUL_CTL_32_24bits;
1192 /* BUG: We should have caught this problem already. */
1193 drm_WARN_ON(dev, "invalid format depth\n");
1197 crtcext3 &= ~GENMASK(2, 0);
1200 WREG_DAC(MGA1064_MUL_CTL, xmulctrl);
1212 WREG_ECRT(3, crtcext3);
1215 static void mgag200_g200er_reset_tagfifo(struct mga_device *mdev)
1217 static uint32_t RESET_FLAG = 0x00200000; /* undocumented magic value */
1222 RREG_SEQ(0x01, seq1);
1223 seq1 |= MGAREG_SEQ1_SCROFF;
1224 WREG_SEQ(0x01, seq1);
1226 memctl = RREG32(MGAREG_MEMCTL);
1228 memctl |= RESET_FLAG;
1229 WREG32(MGAREG_MEMCTL, memctl);
1233 memctl &= ~RESET_FLAG;
1234 WREG32(MGAREG_MEMCTL, memctl);
1237 RREG_SEQ(0x01, seq1);
1238 seq1 &= ~MGAREG_SEQ1_SCROFF;
1239 WREG_SEQ(0x01, seq1);
1242 static void mgag200_g200se_set_hiprilvl(struct mga_device *mdev,
1243 const struct drm_display_mode *mode,
1244 const struct drm_framebuffer *fb)
1246 unsigned int hiprilvl;
1249 if (mdev->unique_rev_id >= 0x04) {
1251 } else if (mdev->unique_rev_id >= 0x02) {
1255 if (fb->format->cpp[0] * 8 > 16)
1257 else if (fb->format->cpp[0] * 8 > 8)
1262 mb = (mode->clock * bpp) / 1000;
1276 } else if (mdev->unique_rev_id >= 0x01) {
1282 crtcext6 = hiprilvl; /* implicitly sets maxhipri to 0 */
1284 WREG_ECRT(0x06, crtcext6);
1287 static void mgag200_g200ev_set_hiprilvl(struct mga_device *mdev)
1289 WREG_ECRT(0x06, 0x00);
1292 static void mga_crtc_dpms(struct drm_crtc *crtc, int mode)
1294 struct drm_device *dev = crtc->dev;
1295 struct mga_device *mdev = to_mga_device(dev);
1296 u8 seq1 = 0, crtcext1 = 0;
1299 case DRM_MODE_DPMS_ON:
1302 mga_crtc_load_lut(crtc);
1304 case DRM_MODE_DPMS_STANDBY:
1308 case DRM_MODE_DPMS_SUSPEND:
1312 case DRM_MODE_DPMS_OFF:
1318 WREG8(MGAREG_SEQ_INDEX, 0x01);
1319 seq1 |= RREG8(MGAREG_SEQ_DATA) & ~0x20;
1320 mga_wait_vsync(mdev);
1321 mga_wait_busy(mdev);
1322 WREG8(MGAREG_SEQ_DATA, seq1);
1324 WREG8(MGAREG_CRTCEXT_INDEX, 0x01);
1325 crtcext1 |= RREG8(MGAREG_CRTCEXT_DATA) & ~0x30;
1326 WREG8(MGAREG_CRTCEXT_DATA, crtcext1);
1330 * This is called before a mode is programmed. A typical use might be to
1331 * enable DPMS during the programming to avoid seeing intermediate stages,
1332 * but that's not relevant to us
1334 static void mga_crtc_prepare(struct drm_crtc *crtc)
1336 struct drm_device *dev = crtc->dev;
1337 struct mga_device *mdev = to_mga_device(dev);
1340 /* mga_resume(crtc);*/
1342 WREG8(MGAREG_CRTC_INDEX, 0x11);
1343 tmp = RREG8(MGAREG_CRTC_DATA);
1344 WREG_CRT(0x11, tmp | 0x80);
1346 if (mdev->type == G200_SE_A || mdev->type == G200_SE_B) {
1352 WREG8(MGAREG_SEQ_INDEX, 0x1);
1353 tmp = RREG8(MGAREG_SEQ_DATA);
1355 /* start sync reset */
1357 WREG_SEQ(1, tmp | 0x20);
1360 if (mdev->type == G200_WB || mdev->type == G200_EW3)
1361 mga_g200wb_prepare(crtc);
1367 * This is called after a mode is programmed. It should reverse anything done
1368 * by the prepare function
1370 static void mga_crtc_commit(struct drm_crtc *crtc)
1372 struct drm_device *dev = crtc->dev;
1373 struct mga_device *mdev = to_mga_device(dev);
1376 if (mdev->type == G200_WB || mdev->type == G200_EW3)
1377 mga_g200wb_commit(crtc);
1379 if (mdev->type == G200_SE_A || mdev->type == G200_SE_B) {
1385 WREG8(MGAREG_SEQ_INDEX, 0x1);
1386 tmp = RREG8(MGAREG_SEQ_DATA);
1392 mga_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
1399 static int mga_vga_get_modes(struct drm_connector *connector)
1401 struct mga_connector *mga_connector = to_mga_connector(connector);
1405 edid = drm_get_edid(connector, &mga_connector->i2c->adapter);
1407 drm_connector_update_edid_property(connector, edid);
1408 ret = drm_add_edid_modes(connector, edid);
1414 static uint32_t mga_vga_calculate_mode_bandwidth(struct drm_display_mode *mode,
1417 uint32_t total_area, divisor;
1418 uint64_t active_area, pixels_per_second, bandwidth;
1419 uint64_t bytes_per_pixel = (bits_per_pixel + 7) / 8;
1423 if (!mode->htotal || !mode->vtotal || !mode->clock)
1426 active_area = mode->hdisplay * mode->vdisplay;
1427 total_area = mode->htotal * mode->vtotal;
1429 pixels_per_second = active_area * mode->clock * 1000;
1430 do_div(pixels_per_second, total_area);
1432 bandwidth = pixels_per_second * bytes_per_pixel * 100;
1433 do_div(bandwidth, divisor);
1435 return (uint32_t)(bandwidth);
1438 #define MODE_BANDWIDTH MODE_BAD
1440 static enum drm_mode_status mga_vga_mode_valid(struct drm_connector *connector,
1441 struct drm_display_mode *mode)
1443 struct drm_device *dev = connector->dev;
1444 struct mga_device *mdev = to_mga_device(dev);
1447 if (IS_G200_SE(mdev)) {
1448 if (mdev->unique_rev_id == 0x01) {
1449 if (mode->hdisplay > 1600)
1450 return MODE_VIRTUAL_X;
1451 if (mode->vdisplay > 1200)
1452 return MODE_VIRTUAL_Y;
1453 if (mga_vga_calculate_mode_bandwidth(mode, bpp)
1455 return MODE_BANDWIDTH;
1456 } else if (mdev->unique_rev_id == 0x02) {
1457 if (mode->hdisplay > 1920)
1458 return MODE_VIRTUAL_X;
1459 if (mode->vdisplay > 1200)
1460 return MODE_VIRTUAL_Y;
1461 if (mga_vga_calculate_mode_bandwidth(mode, bpp)
1463 return MODE_BANDWIDTH;
1465 if (mga_vga_calculate_mode_bandwidth(mode, bpp)
1467 return MODE_BANDWIDTH;
1469 } else if (mdev->type == G200_WB) {
1470 if (mode->hdisplay > 1280)
1471 return MODE_VIRTUAL_X;
1472 if (mode->vdisplay > 1024)
1473 return MODE_VIRTUAL_Y;
1474 if (mga_vga_calculate_mode_bandwidth(mode, bpp) >
1476 return MODE_BANDWIDTH;
1477 } else if (mdev->type == G200_EV &&
1478 (mga_vga_calculate_mode_bandwidth(mode, bpp)
1479 > (32700 * 1024))) {
1480 return MODE_BANDWIDTH;
1481 } else if (mdev->type == G200_EH &&
1482 (mga_vga_calculate_mode_bandwidth(mode, bpp)
1483 > (37500 * 1024))) {
1484 return MODE_BANDWIDTH;
1485 } else if (mdev->type == G200_ER &&
1486 (mga_vga_calculate_mode_bandwidth(mode,
1487 bpp) > (55000 * 1024))) {
1488 return MODE_BANDWIDTH;
1491 if ((mode->hdisplay % 8) != 0 || (mode->hsync_start % 8) != 0 ||
1492 (mode->hsync_end % 8) != 0 || (mode->htotal % 8) != 0) {
1493 return MODE_H_ILLEGAL;
1496 if (mode->crtc_hdisplay > 2048 || mode->crtc_hsync_start > 4096 ||
1497 mode->crtc_hsync_end > 4096 || mode->crtc_htotal > 4096 ||
1498 mode->crtc_vdisplay > 2048 || mode->crtc_vsync_start > 4096 ||
1499 mode->crtc_vsync_end > 4096 || mode->crtc_vtotal > 4096) {
1503 /* Validate the mode input by the user */
1504 if (connector->cmdline_mode.specified) {
1505 if (connector->cmdline_mode.bpp_specified)
1506 bpp = connector->cmdline_mode.bpp;
1509 if ((mode->hdisplay * mode->vdisplay * (bpp/8)) > mdev->vram_fb_available) {
1510 if (connector->cmdline_mode.specified)
1511 connector->cmdline_mode.specified = false;
1518 static void mga_connector_destroy(struct drm_connector *connector)
1520 struct mga_connector *mga_connector = to_mga_connector(connector);
1521 mgag200_i2c_destroy(mga_connector->i2c);
1522 drm_connector_cleanup(connector);
1525 static const struct drm_connector_helper_funcs mga_vga_connector_helper_funcs = {
1526 .get_modes = mga_vga_get_modes,
1527 .mode_valid = mga_vga_mode_valid,
1530 static const struct drm_connector_funcs mga_vga_connector_funcs = {
1531 .reset = drm_atomic_helper_connector_reset,
1532 .fill_modes = drm_helper_probe_single_connector_modes,
1533 .destroy = mga_connector_destroy,
1534 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
1535 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1538 static int mgag200_vga_connector_init(struct mga_device *mdev)
1540 struct drm_device *dev = &mdev->base;
1541 struct mga_connector *mconnector = &mdev->connector;
1542 struct drm_connector *connector = &mconnector->base;
1543 struct mga_i2c_chan *i2c;
1546 i2c = mgag200_i2c_create(dev);
1548 drm_warn(dev, "failed to add DDC bus\n");
1550 ret = drm_connector_init_with_ddc(dev, connector,
1551 &mga_vga_connector_funcs,
1552 DRM_MODE_CONNECTOR_VGA,
1555 goto err_mgag200_i2c_destroy;
1556 drm_connector_helper_add(connector, &mga_vga_connector_helper_funcs);
1558 mconnector->i2c = i2c;
1562 err_mgag200_i2c_destroy:
1563 mgag200_i2c_destroy(i2c);
1568 * Simple Display Pipe
1571 static enum drm_mode_status
1572 mgag200_simple_display_pipe_mode_valid(struct drm_simple_display_pipe *pipe,
1573 const struct drm_display_mode *mode)
1579 mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb,
1580 struct drm_rect *clip)
1582 struct drm_device *dev = &mdev->base;
1585 vmap = drm_gem_shmem_vmap(fb->obj[0]);
1586 if (drm_WARN_ON(dev, !vmap))
1587 return; /* BUG: SHMEM BO should always be vmapped */
1589 drm_fb_memcpy_dstclip(mdev->vram, vmap, fb, clip);
1591 drm_gem_shmem_vunmap(fb->obj[0], vmap);
1593 /* Always scanout image at VRAM offset 0 */
1594 mgag200_set_startadd(mdev, (u32)0);
1595 mgag200_set_offset(mdev, fb);
1599 mgag200_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe,
1600 struct drm_crtc_state *crtc_state,
1601 struct drm_plane_state *plane_state)
1603 struct drm_crtc *crtc = &pipe->crtc;
1604 struct drm_device *dev = crtc->dev;
1605 struct mga_device *mdev = to_mga_device(dev);
1606 struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
1607 struct drm_framebuffer *fb = plane_state->fb;
1608 struct drm_rect fullscreen = {
1615 mga_crtc_prepare(crtc);
1617 mgag200_set_format_regs(mdev, fb);
1618 mgag200_set_mode_regs(mdev, adjusted_mode);
1620 if (mdev->type == G200_ER)
1621 mgag200_g200er_reset_tagfifo(mdev);
1623 if (IS_G200_SE(mdev))
1624 mgag200_g200se_set_hiprilvl(mdev, adjusted_mode, fb);
1625 else if (mdev->type == G200_EV)
1626 mgag200_g200ev_set_hiprilvl(mdev);
1628 mga_crtc_commit(crtc);
1630 mgag200_handle_damage(mdev, fb, &fullscreen);
1634 mgag200_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe)
1636 struct drm_crtc *crtc = &pipe->crtc;
1638 mga_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
1642 mgag200_simple_display_pipe_check(struct drm_simple_display_pipe *pipe,
1643 struct drm_plane_state *plane_state,
1644 struct drm_crtc_state *crtc_state)
1646 struct drm_plane *plane = plane_state->plane;
1647 struct drm_framebuffer *new_fb = plane_state->fb;
1648 struct drm_framebuffer *fb = NULL;
1654 fb = plane->state->fb;
1656 if (!fb || (fb->format != new_fb->format))
1657 crtc_state->mode_changed = true; /* update PLL settings */
1663 mgag200_simple_display_pipe_update(struct drm_simple_display_pipe *pipe,
1664 struct drm_plane_state *old_state)
1666 struct drm_plane *plane = &pipe->plane;
1667 struct drm_device *dev = plane->dev;
1668 struct mga_device *mdev = to_mga_device(dev);
1669 struct drm_plane_state *state = plane->state;
1670 struct drm_framebuffer *fb = state->fb;
1671 struct drm_rect damage;
1676 if (drm_atomic_helper_damage_merged(old_state, state, &damage))
1677 mgag200_handle_damage(mdev, fb, &damage);
1680 static const struct drm_simple_display_pipe_funcs
1681 mgag200_simple_display_pipe_funcs = {
1682 .mode_valid = mgag200_simple_display_pipe_mode_valid,
1683 .enable = mgag200_simple_display_pipe_enable,
1684 .disable = mgag200_simple_display_pipe_disable,
1685 .check = mgag200_simple_display_pipe_check,
1686 .update = mgag200_simple_display_pipe_update,
1687 .prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb,
1690 static const uint32_t mgag200_simple_display_pipe_formats[] = {
1691 DRM_FORMAT_XRGB8888,
1696 static const uint64_t mgag200_simple_display_pipe_fmtmods[] = {
1697 DRM_FORMAT_MOD_LINEAR,
1698 DRM_FORMAT_MOD_INVALID
1705 static const struct drm_mode_config_funcs mgag200_mode_config_funcs = {
1706 .fb_create = drm_gem_fb_create_with_dirty,
1707 .atomic_check = drm_atomic_helper_check,
1708 .atomic_commit = drm_atomic_helper_commit,
1711 static unsigned int mgag200_preferred_depth(struct mga_device *mdev)
1713 if (IS_G200_SE(mdev) && mdev->vram_fb_available < (2048*1024))
1719 int mgag200_modeset_init(struct mga_device *mdev)
1721 struct drm_device *dev = &mdev->base;
1722 struct drm_connector *connector = &mdev->connector.base;
1723 struct drm_simple_display_pipe *pipe = &mdev->display_pipe;
1724 size_t format_count = ARRAY_SIZE(mgag200_simple_display_pipe_formats);
1727 mdev->bpp_shifts[0] = 0;
1728 mdev->bpp_shifts[1] = 1;
1729 mdev->bpp_shifts[2] = 0;
1730 mdev->bpp_shifts[3] = 2;
1732 mgag200_init_regs(mdev);
1734 ret = drmm_mode_config_init(dev);
1736 drm_err(dev, "drmm_mode_config_init() failed, error %d\n",
1741 dev->mode_config.max_width = MGAG200_MAX_FB_WIDTH;
1742 dev->mode_config.max_height = MGAG200_MAX_FB_HEIGHT;
1744 dev->mode_config.preferred_depth = mgag200_preferred_depth(mdev);
1746 dev->mode_config.fb_base = mdev->mc.vram_base;
1748 dev->mode_config.funcs = &mgag200_mode_config_funcs;
1750 ret = mgag200_vga_connector_init(mdev);
1753 "mgag200_vga_connector_init() failed, error %d\n",
1758 ret = drm_simple_display_pipe_init(dev, pipe,
1759 &mgag200_simple_display_pipe_funcs,
1760 mgag200_simple_display_pipe_formats,
1762 mgag200_simple_display_pipe_fmtmods,
1766 "drm_simple_display_pipe_init() failed, error %d\n",
1771 /* FIXME: legacy gamma tables; convert to CRTC state */
1772 drm_mode_crtc_set_gamma_size(&pipe->crtc, MGAG200_LUT_SIZE);
1774 drm_mode_config_reset(dev);