#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: gs.c,v 1.6 2014/03/31 11:25:49 martin Exp $");
#include <sys/param.h>
#include <playstation2/playstation2/sifbios.h>
#include <playstation2/ee/eevar.h>
#include <playstation2/ee/gsvar.h>
#include <playstation2/ee/gsreg.h>
#include <playstation2/ee/gifreg.h>
#ifdef DEBUG
#define STATIC
#else
#define STATIC static
#endif
STATIC const struct gs_crt_param {
int w, h, dvemode;
u_int64_t smode1, smode2, srfsh, synch1, synch2, syncv, display;
} gs_crt_param[] = {
[NTSC_NONINTER] = {
.w = 640,
.h = 240,
.dvemode= 0,
.smode1 = SMODE1(0, 1, 1, 1, 1, 0, 0, 0, 0, 0,
4, 0, 0, 1, 1, 0, 2, 0, 1, 32, 4),
.smode2 = SMODE2(0, 0, 0),
.srfsh = SRFSH(8),
.synch1 = SYNCH1(254, 1462, 124, 222, 64),
.synch2 = SYNCH2(1652, 1240),
.syncv = SYNCV(6, 480, 6, 26, 6, 2),
.display=DISPLAY(239, 2559, 0, 3, 25, 632)
},
[NTSC_INTER] = {
.w = 640,
.h = 480,
.dvemode= 0,
.smode1 = SMODE1(0, 1, 1, 1, 1, 0, 0, 0, 0, 0,
4, 0, 0, 1, 1, 0, 2, 0, 1, 32, 4),
.smode2 = SMODE2(0, 0, 1),
.srfsh = SRFSH(8),
.synch1 = SYNCH1(254, 1462, 124, 222, 64),
.synch2 = SYNCH2(1652, 1240),
.syncv = SYNCV(6, 480, 6, 26, 6, 1),
.display= DISPLAY(479, 2559, 0, 3, 50, 632)
},
[PAL_NONINTER] = {
.w = 640,
.h = 288,
.dvemode= 1,
.smode1 = SMODE1(0, 1, 1, 1, 1, 0, 0, 0, 0, 0,
4, 0, 0, 1, 1, 0, 3, 0, 1, 32, 4),
.smode2 = SMODE2(0, 0, 0),
.srfsh = SRFSH(8),
.synch1 = SYNCH1(254, 1474, 127, 262, 48),
.synch2 = SYNCH2(1680, 1212),
.syncv = SYNCV(5, 576, 5, 33, 5, 4),
.display= DISPLAY(287, 2559, 0, 3, 36, 652)
},
[PAL_INTER] = {
.w = 640,
.h = 576,
.dvemode= 1,
.smode1 = SMODE1(0, 1, 1, 1, 1, 0, 0, 0, 0, 0,
4, 0, 0, 1, 1, 0, 3, 0, 1, 32, 4),
.smode2 = SMODE2(0, 0, 1),
.srfsh = SRFSH(8),
.synch1 = SYNCH1(254, 1474, 127, 262, 48),
.synch2 = SYNCH2(1680, 1212),
.syncv = SYNCV(5, 576, 5, 33, 5, 4),
.display= DISPLAY(575,2559,0,3,72,652)
},
[VESA_1A] = {
.w = 640,
.h = 480,
.dvemode= 2,
.smode1 = SMODE1(1, 0, 1, 1, 1, 0, 0, 0, 0, 0,
2, 0, 0, 1, 0, 0, 0, 0, 1, 15, 2),
.smode2 = SMODE2(0, 0, 0),
.srfsh = SRFSH(4),
.synch1 = SYNCH1(192, 608, 192, 84, 32),
.synch2 = SYNCH2(768, 524),
.syncv = SYNCV(2, 480, 0, 33, 0, 10),
.display= DISPLAY(479, 1279, 0, 1, 34, 276)
}
};
void
gs_init(enum gs_crt_type type)
{
const struct gs_crt_param *p = &gs_crt_param[type];
u_int64_t smode1 = p->smode1;
_reg_write_8(GS_S_CSR_REG, 1 << 9);
_reg_write_8(GS_S_PMODE_REG, 0);
_reg_write_8(GS_S_SMODE1_REG, smode1 | ((u_int64_t)1 << 16));
_reg_write_8(GS_S_SYNCH1_REG, p->synch1);
_reg_write_8(GS_S_SYNCH2_REG, p->synch2);
_reg_write_8(GS_S_SYNCV_REG, p->syncv);
_reg_write_8(GS_S_SMODE2_REG, p->smode2);
_reg_write_8(GS_S_SRFSH_REG, p->srfsh);
if (p->dvemode == 2) {
_reg_write_8(GS_S_SMODE1_REG, smode1 & ~((u_int64_t)1 << 16));
delay(2500);
}
_reg_write_8(GS_S_SMODE1_REG,
smode1 & ~((u_int64_t)1 << 16) & ~((u_int64_t)1 << 17));
sifbios_setdve(p->dvemode);
_reg_write_8(GS_S_PMODE_REG, 0x66);
_reg_write_8(GS_S_DISPLAY2_REG, p->display);
_reg_write_8(GS_S_DISPFB2_REG, (p->w >> 6) << 9);
_reg_write_8(GS_S_SMODE2_REG, p->smode2);
_reg_write_8(GS_S_BGCOLOR_REG, 0);
_reg_write_8(GS_S_CSR_REG, 1 << 8);
_reg_write_4(GIF_CTRL_REG, 1);
}