#define MODULE_BIT 0x00040000
#include "std.h"
status_t eng_crtc_validate_timing(
uint16 *hd_e,uint16 *hs_s,uint16 *hs_e,uint16 *ht,
uint16 *vd_e,uint16 *vs_s,uint16 *vs_e,uint16 *vt
)
{
*hd_e &= 0xfff8;
*hs_s &= 0xfff8;
*hs_e &= 0xfff8;
*ht &= 0xfff8;
if (*hd_e > ((0x00ff - 2) << 3)) *hd_e = ((0x00ff - 2) << 3);
if (*hs_s > ((0x01ff - 1) << 3)) *hs_s = ((0x01ff - 1) << 3);
if (*hs_e > ( 0x01ff << 3)) *hs_e = ( 0x01ff << 3);
if (*ht > ((0x01ff + 5) << 3)) *ht = ((0x01ff + 5) << 3);
if (*hd_e < 640) *hd_e = 640;
if (*hd_e > 1600) *hd_e = 1600;
if (*ht < (*hd_e + 80)) *ht = (*hd_e + 80);
if (*ht > (*hd_e + 0x3f8)) *ht = (*hd_e + 0x3f8);
if (*hs_e > (*ht - 8)) *hs_e = (*ht - 8);
if (*hs_s < (*hd_e + 8)) *hs_s = (*hd_e + 8);
if (*hs_e > (*hs_s + 0xf8)) *hs_e = (*hs_s + 0xf8);
if (*vd_e > (0x7ff - 2)) *vd_e = (0x7ff - 2);
if (*vs_s > (0x7ff - 1)) *vs_s = (0x7ff - 1);
if (*vs_e > 0x7ff ) *vs_e = 0x7ff ;
if (*vt > (0x7ff + 2)) *vt = (0x7ff + 2);
if (*vd_e < 480) *vd_e = 480;
if (*vd_e > 1200) *vd_e = 1200;
if (*vt < (*vd_e + 3)) *vt = (*vd_e + 3);
if (*vt > (*vd_e + 0xff)) *vt = (*vd_e + 0xff);
if (*vs_e > (*vt - 1)) *vs_e = (*vt - 1);
if (*vs_s < (*vd_e + 1)) *vs_s = (*vd_e + 1);
if (*vs_e > (*vs_s + 0x0f)) *vs_e = (*vs_s + 0x0f);
return B_OK;
}
status_t eng_crtc_set_timing(display_mode target)
{
uint16 fifolimit = 0;
uint8 temp;
uint32 htotal;
uint32 hdisp_e;
uint32 hsync_s;
uint32 hsync_e;
uint32 hblnk_s;
uint32 hblnk_e;
uint32 vtotal;
uint32 vdisp_e;
uint32 vsync_s;
uint32 vsync_e;
uint32 vblnk_s;
uint32 vblnk_e;
uint32 linecomp;
LOG(4,("CRTC: setting timing\n"));
if (0)
{
LOG(2,("CRTC: DFP active: tuning modeline\n"));
target.timing.h_sync_start =
((uint16)((si->ps.p1_timing.h_sync_start / ((float)si->ps.p1_timing.h_display)) *
target.timing.h_display)) & 0xfff8;
target.timing.h_sync_end =
((uint16)((si->ps.p1_timing.h_sync_end / ((float)si->ps.p1_timing.h_display)) *
target.timing.h_display)) & 0xfff8;
target.timing.h_total =
(((uint16)((si->ps.p1_timing.h_total / ((float)si->ps.p1_timing.h_display)) *
target.timing.h_display)) & 0xfff8) - 8;
if (target.timing.h_display == si->ps.p1_timing.h_display)
{
if (si->ps.card_type == NV11)
target.timing.h_total -= 56;
else
target.timing.h_total -= 32;
}
if (target.timing.h_sync_start == target.timing.h_display)
target.timing.h_sync_start += 8;
if (target.timing.h_sync_end == target.timing.h_total)
target.timing.h_sync_end -= 8;
target.timing.v_sync_start =
((uint16)((si->ps.p1_timing.v_sync_start / ((float)si->ps.p1_timing.v_display)) *
target.timing.v_display));
target.timing.v_sync_end =
((uint16)((si->ps.p1_timing.v_sync_end / ((float)si->ps.p1_timing.v_display)) *
target.timing.v_display));
target.timing.v_total =
((uint16)((si->ps.p1_timing.v_total / ((float)si->ps.p1_timing.v_display)) *
target.timing.v_display)) - 1;
if (target.timing.v_sync_start == target.timing.v_display)
target.timing.v_sync_start += 1;
if (target.timing.v_sync_end == target.timing.v_total)
target.timing.v_sync_end -= 1;
DACW(FP_DEBUG1, 0);
}
htotal = ((target.timing.h_total >> 3) - 5);
hdisp_e = ((target.timing.h_display >> 3) - 1);
hblnk_s = hdisp_e;
hblnk_e = (htotal + 4);
hsync_s = (target.timing.h_sync_start >> 3);
hsync_e = (target.timing.h_sync_end >> 3);
vtotal = target.timing.v_total - 2;
vdisp_e = target.timing.v_display - 1;
vblnk_s = vdisp_e;
vblnk_e = (vtotal + 1);
vsync_s = target.timing.v_sync_start;
vsync_e = target.timing.v_sync_end;
linecomp = 0xffff;
{
LOG(4,("CRTC: Setting full timing...\n"));
LOG(2,("CRTC:\n\tHTOT:%x\n\tHDISPEND:%x\n\tHBLNKS:%x\n\tHBLNKE:%x\n\tHSYNCS:%x\n\tHSYNCE:%x\n\t",htotal,hdisp_e,hblnk_s,hblnk_e,hsync_s,hsync_e));
LOG(2,("VTOT:%x\n\tVDISPEND:%x\n\tVBLNKS:%x\n\tVBLNKE:%x\n\tVSYNCS:%x\n\tVSYNCE:%x\n",vtotal,vdisp_e,vblnk_s,vblnk_e,vsync_s,vsync_e));
CRTCW(VSYNCE, (CRTCR(VSYNCE) & 0x7f));
CRTCW(HTOTAL, (htotal & 0xff));
CRTCW(HDISPE, (hdisp_e & 0xff));
CRTCW(HBLANKS, (hblnk_s & 0xff));
CRTCW(HBLANKE, ((hblnk_e & 0x1f) | 0x80));
CRTCW(HSYNCS, (hsync_s & 0xff));
CRTCW(HSYNCE, ((hsync_e & 0x1f) | ((hblnk_e & 0x20) << 2)));
CRTCW(VTOTAL, (vtotal & 0xff));
CRTCW(OVERFLOW,
(
((vtotal & 0x100) >> (8 - 0)) | ((vtotal & 0x200) >> (9 - 5)) |
((vdisp_e & 0x100) >> (8 - 1)) | ((vdisp_e & 0x200) >> (9 - 6)) |
((vsync_s & 0x100) >> (8 - 2)) | ((vsync_s & 0x200) >> (9 - 7)) |
((vblnk_s & 0x100) >> (8 - 3)) | ((linecomp & 0x0100) >> (8 - 4))
));
CRTCW(PRROWSCN, 0x00);
CRTCW(MAXSCLIN, (((vblnk_s & 0x200) >> (9 - 5)) | ((linecomp & 0x0200) >> (9 - 6))));
CRTCW(VSYNCS, (vsync_s & 0xff));
CRTCW(VSYNCE, ((CRTCR(VSYNCE) & 0xf0) | (vsync_e & 0x0f)));
CRTCW(VDISPE, (vdisp_e & 0xff));
CRTCW(VBLANKS, (vblnk_s & 0xff));
CRTCW(VBLANKE, (vblnk_e & 0xff));
CRTCW(LINECOMP, (linecomp & 0xff));
CRTCW(HTIMEXT1, (CRTCR(HTIMEXT1) & 0xc8) |
(
((linecomp & 0x1c00) >> (10 - 0)) |
((hblnk_e & 0x040) >> (6 - 5)) |
((hsync_s & 0x100) >> (8 - 4))
));
CRTCW(HTIMEXT2, (CRTCR(HTIMEXT2) & 0xf7) | ((htotal & 0x100) >> (8 - 3)));
CRTCW(VTIMEXT_PIT, (CRTCR(VTIMEXT_PIT) & 0xe0) |
(
((vtotal & 0x400) >> (10 - 0)) |
((vsync_s & 0x400) >> (10 - 1)) |
((vdisp_e & 0x400) >> (10 - 2)) |
((vblnk_s & 0x400) >> (10 - 3)) |
((linecomp & 0x2000) >> (13 - 4))
));
LOG(2,("CRTC: sync polarity: "));
temp = ENG_REG8(RG8_MISCR);
if (target.timing.flags & B_POSITIVE_HSYNC)
{
LOG(2,("H:pos "));
temp &= ~0x40;
}
else
{
LOG(2,("H:neg "));
temp |= 0x40;
}
if (target.timing.flags & B_POSITIVE_VSYNC)
{
LOG(2,("V:pos "));
temp &= ~0x80;
}
else
{
LOG(2,("V:neg "));
temp |= 0x80;
}
ENG_REG8(RG8_MISCW) = temp;
LOG(2,(", MISC reg readback: $%02x\n", ENG_REG8(RG8_MISCR)));
switch (target.space)
{
case B_CMAP8:
fifolimit = 0x0001;
break;
case B_RGB15_LITTLE:
case B_RGB16_LITTLE:
fifolimit = 0x0002;
break;
case B_RGB24_LITTLE:
fifolimit = 0x0003;
break;
case B_RGB32_LITTLE:
fifolimit = 0x0004;
break;
}
fifolimit *= target.timing.h_display;
fifolimit >>= 4;
fifolimit += 4;
SEQW(FETCHCNTLO, (fifolimit & 0x00fe));
SEQW(FETCHCNTHI, (((SEQR(FETCHCNTHI)) & 0xfc) | ((fifolimit & 0x0300) >> 8)));
}
if (0)
{
uint32 iscale_x, iscale_y;
iscale_x = (((1 << 12) * target.timing.h_display) / si->ps.p1_timing.h_display);
iscale_y = (((1 << 12) * target.timing.v_display) / si->ps.p1_timing.v_display);
CRTCW(FP_HTIMING, 0);
CRTCW(FP_VTIMING, 0);
LOG(2,("CRTC: FP_HTIMING reg readback: $%02x\n", CRTCR(FP_HTIMING)));
LOG(2,("CRTC: FP_VTIMING reg readback: $%02x\n", CRTCR(FP_VTIMING)));
DACW(FP_HVALID_S, 0);
DACW(FP_HVALID_E, (si->ps.p1_timing.h_display - 1));
DACW(FP_VVALID_S, 0);
DACW(FP_VVALID_E, (si->ps.p1_timing.v_display - 1));
if (0)
{
DACW(FP_DEBUG2, 0x00000000);
if ((iscale_x != (1 << 12)) || (iscale_y != (1 << 12)))
{
LOG(2,("CRTC: DFP needs to do scaling\n"));
DACW(FP_TG_CTRL, (DACR(FP_TG_CTRL) | 0x00000100));
}
else
{
LOG(2,("CRTC: no scaling for DFP needed\n"));
DACW(FP_TG_CTRL, (DACR(FP_TG_CTRL) & 0xfffffeff));
}
}
else
{
float dm_aspect;
LOG(2,("CRTC: GPU scales for DFP if needed\n"));
dm_aspect = (target.timing.h_display / ((float)target.timing.v_display));
if (iscale_y != (1 << 12))
DACW(FP_DEBUG2, ((1 << 28) | ((target.timing.v_display - 1) << 16)));
else
DACW(FP_DEBUG2, 0x00000000);
DACW(FP_TG_CTRL, (DACR(FP_TG_CTRL) & 0xfffffeff));
if ((iscale_x != (1 << 12)) && (si->ps.panel1_aspect > (dm_aspect + 0.10)))
{
uint16 diff;
LOG(2,("CRTC: (relative) widescreen panel: tuning horizontal scaling\n"));
iscale_x = iscale_y;
DACW(FP_DEBUG1, (((iscale_x >> 1) & 0x00000fff) | (1 << 12)));
diff = ((si->ps.p1_timing.h_display -
(target.timing.h_display * ((1 << 12) / ((float)iscale_x))))
/ 2);
DACW(FP_HVALID_S, diff);
DACW(FP_HVALID_E, ((si->ps.p1_timing.h_display - diff) - 1));
}
if ((iscale_y != (1 << 12)) && (si->ps.panel1_aspect < (dm_aspect - 0.10)))
{
LOG(2,("CRTC: (relative) portrait panel: should tune vertical scaling\n"));
}
}
LOG(2,("CRTC: FP_HVALID_S reg readback: $%08x\n", DACR(FP_HVALID_S)));
LOG(2,("CRTC: FP_HVALID_E reg readback: $%08x\n", DACR(FP_HVALID_E)));
LOG(2,("CRTC: FP_VVALID_S reg readback: $%08x\n", DACR(FP_VVALID_S)));
LOG(2,("CRTC: FP_VVALID_E reg readback: $%08x\n", DACR(FP_VVALID_E)));
LOG(2,("CRTC: FP_DEBUG0 reg readback: $%08x\n", DACR(FP_DEBUG0)));
LOG(2,("CRTC: FP_DEBUG1 reg readback: $%08x\n", DACR(FP_DEBUG1)));
LOG(2,("CRTC: FP_DEBUG2 reg readback: $%08x\n", DACR(FP_DEBUG2)));
LOG(2,("CRTC: FP_DEBUG3 reg readback: $%08x\n", DACR(FP_DEBUG3)));
LOG(2,("CRTC: FP_TG_CTRL reg readback: $%08x\n", DACR(FP_TG_CTRL)));
}
return B_OK;
}
status_t eng_crtc_depth(int mode)
{
uint8 genctrl = 0;
switch(mode)
{
case BPP8:
genctrl = 0xa2;
break;
case BPP15:
genctrl = 0xa6;
break;
case BPP16:
genctrl = 0xb6;
break;
case BPP24:
genctrl = 0xaa;
break;
case BPP32:
genctrl = 0xae;
break;
}
SEQW(COLDEPTH, genctrl);
return B_OK;
}
status_t eng_crtc_dpms(bool display, bool h, bool v)
{
uint8 temp;
LOG(4,("CRTC: setting DPMS: "));
SEQW(RESET, 0x01);
temp = SEQR(CLKMODE);
if (display)
{
SEQW(CLKMODE, (temp & ~0x20));
SEQW(RESET, 0x03);
if (0)
{
DACW(FP_DEBUG0, (DACR(FP_DEBUG0) & 0xcfffffff));
CRTCW(0x59, (CRTCR(0x59) | 0x01));
}
LOG(4,("display on, "));
}
else
{
SEQW(CLKMODE, (temp | 0x20));
if (0)
{
DACW(FP_DEBUG0, (DACR(FP_DEBUG0) | 0x30000000));
CRTCW(0x59, (CRTCR(0x59) & 0xfe));
}
LOG(4,("display off, "));
}
if (h)
{
CRTCW(HTIMEXT2, (CRTCR(HTIMEXT2) & 0xef));
LOG(4,("hsync enabled, "));
}
else
{
CRTCW(HTIMEXT2, (CRTCR(HTIMEXT2) | 0x10));
LOG(4,("hsync disabled, "));
}
if (v)
{
CRTCW(HTIMEXT2, (CRTCR(HTIMEXT2) & 0xdf));
LOG(4,("vsync enabled\n"));
}
else
{
CRTCW(HTIMEXT2, (CRTCR(HTIMEXT2) | 0x20));
LOG(4,("vsync disabled\n"));
}
return B_OK;
}
status_t eng_crtc_dpms_fetch(bool *display, bool *h, bool *v)
{
*display = !(SEQR(CLKMODE) & 0x20);
*h = !(CRTCR(HTIMEXT2) & 0x10);
*v = !(CRTCR(HTIMEXT2) & 0x20);
LOG(4,("CTRC: fetched DPMS state: "));
if (*display) LOG(4,("display on, "));
else LOG(4,("display off, "));
if (*h) LOG(4,("hsync enabled, "));
else LOG(4,("hsync disabled, "));
if (*v) LOG(4,("vsync enabled\n"));
else LOG(4,("vsync disabled\n"));
return B_OK;
}
status_t eng_crtc_set_display_pitch()
{
uint16 offset;
LOG(4,("CRTC: setting card pitch (offset between lines)\n"));
offset = si->fbc.bytes_per_row >> 3;
LOG(2,("CRTC: offset register set to: $%04x\n", offset));
CRTCW(PITCHL, (offset & 0x00ff));
CRTCW(VTIMEXT_PIT, (((CRTCR(VTIMEXT_PIT)) & 0x1f) | ((offset & 0x0700) >> 3)));
return B_OK;
}
status_t eng_crtc_set_display_start(uint32 startadd,uint8 bpp)
{
LOG(4,("CRTC: setting card RAM to be displayed bpp %d\n", bpp));
LOG(2,("CRTC: startadd: $%08x\n", startadd));
LOG(2,("CRTC: frameRAM: $%08x\n", si->framebuffer));
LOG(2,("CRTC: framebuffer: $%08x\n", si->fbc.frame_buffer));
CRTCW(FBSTADDL, ((startadd & 0x000001f8) >> 1));
CRTCW(FBSTADDH, ((startadd & 0x0001fe00) >> 9));
CRTCW(FBSTADDE, ((startadd & 0x01fe0000) >> 17));
return B_OK;
}
status_t eng_crtc_cursor_init()
{
int i;
uint32 * fb;
const uint32 curadd = 0;
CRTCDW(CURSOR_BG, 0xffffffff);
CRTCDW(CURSOR_FG, 0x00000000);
CRTCDW(CURSOR_MODE, (curadd & 0xfffffffc));
fb = (uint32 *) si->framebuffer + curadd;
for (i = 0; i < (4096/4); i += 2)
{
fb[i + 0] = 0x00000000;
fb[i + 1] = 0xffffffff;
}
eng_crtc_cursor_show();
return B_OK;
}
status_t eng_crtc_cursor_show()
{
LOG(4,("CRTC: enabling cursor\n"));
CRTCDW(CURSOR_MODE, (CRTCDR(CURSOR_MODE) | 0x00000003));
return B_OK;
}
status_t eng_crtc_cursor_hide()
{
LOG(4,("CRTC: disabling cursor\n"));
CRTCDW(CURSOR_MODE, (CRTCDR(CURSOR_MODE) & 0xfffffffc));
return B_OK;
}
status_t eng_crtc_cursor_define(uint8* andMask,uint8* xorMask)
{
int y;
uint8 *cursor;
cursor = (uint8*) si->framebuffer;
for (y = 0; y < 16; y++)
{
cursor[0 + (y * 8)] = *xorMask++;
cursor[1 + (y * 8)] = *xorMask++;
cursor[4 + (y * 8)] = *andMask++;
cursor[5 + (y * 8)] = *andMask++;
}
return B_OK;
}
status_t eng_crtc_cursor_position(uint16 x, uint16 y)
{
CRTCDW(CURSOR_ORG, 0x00000000);
CRTCDW(CURSOR_POS, (((x & 0x07ff) << 16) | (y & 0x07ff)));
return B_OK;
}