Home | History | Annotate | Line # | Download | only in ee
gs.c revision 1.6.6.2
      1  1.6.6.2  tls /*	$NetBSD: gs.c,v 1.6.6.2 2014/08/20 00:03:18 tls Exp $	*/
      2  1.6.6.2  tls 
      3  1.6.6.2  tls /*-
      4  1.6.6.2  tls  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.6.6.2  tls  * All rights reserved.
      6  1.6.6.2  tls  *
      7  1.6.6.2  tls  * This code is derived from software contributed to The NetBSD Foundation
      8  1.6.6.2  tls  * by UCHIYAMA Yasushi.
      9  1.6.6.2  tls  *
     10  1.6.6.2  tls  * Redistribution and use in source and binary forms, with or without
     11  1.6.6.2  tls  * modification, are permitted provided that the following conditions
     12  1.6.6.2  tls  * are met:
     13  1.6.6.2  tls  * 1. Redistributions of source code must retain the above copyright
     14  1.6.6.2  tls  *    notice, this list of conditions and the following disclaimer.
     15  1.6.6.2  tls  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.6.6.2  tls  *    notice, this list of conditions and the following disclaimer in the
     17  1.6.6.2  tls  *    documentation and/or other materials provided with the distribution.
     18  1.6.6.2  tls  *
     19  1.6.6.2  tls  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.6.6.2  tls  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.6.6.2  tls  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.6.6.2  tls  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.6.6.2  tls  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.6.6.2  tls  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.6.6.2  tls  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.6.6.2  tls  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.6.6.2  tls  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.6.6.2  tls  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.6.6.2  tls  * POSSIBILITY OF SUCH DAMAGE.
     30  1.6.6.2  tls  */
     31  1.6.6.2  tls 
     32  1.6.6.2  tls #include <sys/cdefs.h>
     33  1.6.6.2  tls __KERNEL_RCSID(0, "$NetBSD: gs.c,v 1.6.6.2 2014/08/20 00:03:18 tls Exp $");
     34  1.6.6.2  tls 
     35  1.6.6.2  tls #include <sys/param.h>
     36  1.6.6.2  tls 
     37  1.6.6.2  tls #include <playstation2/playstation2/sifbios.h>
     38  1.6.6.2  tls #include <playstation2/ee/eevar.h>
     39  1.6.6.2  tls #include <playstation2/ee/gsvar.h>
     40  1.6.6.2  tls #include <playstation2/ee/gsreg.h>
     41  1.6.6.2  tls #include <playstation2/ee/gifreg.h>
     42  1.6.6.2  tls 
     43  1.6.6.2  tls #ifdef DEBUG
     44  1.6.6.2  tls #define STATIC
     45  1.6.6.2  tls #else
     46  1.6.6.2  tls #define STATIC	static
     47  1.6.6.2  tls #endif
     48  1.6.6.2  tls 
     49  1.6.6.2  tls STATIC const struct gs_crt_param {
     50  1.6.6.2  tls 	int w, h, dvemode;
     51  1.6.6.2  tls 	u_int64_t smode1, smode2, srfsh, synch1, synch2, syncv, display;
     52  1.6.6.2  tls } gs_crt_param[] = {
     53  1.6.6.2  tls 	[NTSC_NONINTER] = {
     54  1.6.6.2  tls 		.w	= 640,
     55  1.6.6.2  tls 		.h	= 240,
     56  1.6.6.2  tls 		.dvemode= 0,
     57  1.6.6.2  tls 		.smode1	= SMODE1(0, 1, 1, 1, 1, 0, 0, 0, 0, 0,
     58  1.6.6.2  tls 		    4, 0, 0, 1, 1, 0, 2, 0, 1, 32, 4),
     59  1.6.6.2  tls 		.smode2 = SMODE2(0, 0, 0),
     60  1.6.6.2  tls 		.srfsh	= SRFSH(8),
     61  1.6.6.2  tls 		.synch1	= SYNCH1(254, 1462, 124, 222, 64),
     62  1.6.6.2  tls 		.synch2	= SYNCH2(1652, 1240),
     63  1.6.6.2  tls 		.syncv	= SYNCV(6, 480, 6, 26, 6, 2),
     64  1.6.6.2  tls 		.display=DISPLAY(239, 2559, 0, 3, 25, 632)
     65  1.6.6.2  tls 	},
     66  1.6.6.2  tls 	[NTSC_INTER] = {
     67  1.6.6.2  tls 		.w	= 640,
     68  1.6.6.2  tls 		.h	= 480,
     69  1.6.6.2  tls 		.dvemode= 0,
     70  1.6.6.2  tls 		.smode1	= SMODE1(0, 1, 1, 1, 1, 0, 0, 0, 0, 0,
     71  1.6.6.2  tls 		    4, 0, 0, 1, 1, 0, 2, 0, 1, 32, 4),
     72  1.6.6.2  tls 		.smode2	= SMODE2(0, 0, 1),
     73  1.6.6.2  tls 		.srfsh	= SRFSH(8),
     74  1.6.6.2  tls 		.synch1	= SYNCH1(254, 1462, 124, 222, 64),
     75  1.6.6.2  tls 		.synch2	= SYNCH2(1652, 1240),
     76  1.6.6.2  tls 		.syncv	= SYNCV(6, 480, 6, 26, 6, 1),
     77  1.6.6.2  tls 		.display= DISPLAY(479, 2559, 0, 3, 50, 632)
     78  1.6.6.2  tls 	},
     79  1.6.6.2  tls 	[PAL_NONINTER] = {
     80  1.6.6.2  tls 		.w	= 640,
     81  1.6.6.2  tls 		.h	= 288,
     82  1.6.6.2  tls 		.dvemode= 1,
     83  1.6.6.2  tls 		.smode1	= SMODE1(0, 1, 1, 1, 1, 0, 0, 0, 0, 0,
     84  1.6.6.2  tls 		    4, 0, 0, 1, 1, 0, 3, 0, 1, 32, 4),
     85  1.6.6.2  tls 		.smode2	= SMODE2(0, 0, 0),
     86  1.6.6.2  tls 		.srfsh	= SRFSH(8),
     87  1.6.6.2  tls 		.synch1	= SYNCH1(254, 1474, 127, 262, 48),
     88  1.6.6.2  tls 		.synch2	= SYNCH2(1680, 1212),
     89  1.6.6.2  tls 		.syncv	= SYNCV(5, 576, 5, 33, 5, 4),
     90  1.6.6.2  tls 		.display= DISPLAY(287, 2559, 0, 3, 36, 652)
     91  1.6.6.2  tls 	},
     92  1.6.6.2  tls 	[PAL_INTER] = {
     93  1.6.6.2  tls 		.w	= 640,
     94  1.6.6.2  tls 		.h	= 576,
     95  1.6.6.2  tls 		.dvemode= 1,
     96  1.6.6.2  tls 		.smode1	= SMODE1(0, 1, 1, 1, 1, 0, 0, 0, 0, 0,
     97  1.6.6.2  tls 		    4, 0, 0, 1, 1, 0, 3, 0, 1, 32, 4),
     98  1.6.6.2  tls 		.smode2	= SMODE2(0, 0, 1),
     99  1.6.6.2  tls 		.srfsh	= SRFSH(8),
    100  1.6.6.2  tls 		.synch1	= SYNCH1(254, 1474, 127, 262, 48),
    101  1.6.6.2  tls 		.synch2	= SYNCH2(1680, 1212),
    102  1.6.6.2  tls 		.syncv	= SYNCV(5, 576, 5, 33, 5, 4),
    103  1.6.6.2  tls 		.display= DISPLAY(575,2559,0,3,72,652)
    104  1.6.6.2  tls 	},
    105  1.6.6.2  tls 	[VESA_1A] = {
    106  1.6.6.2  tls 		.w	= 640,
    107  1.6.6.2  tls 		.h	= 480,
    108  1.6.6.2  tls 		.dvemode= 2,
    109  1.6.6.2  tls 		.smode1	= SMODE1(1, 0, 1, 1, 1, 0, 0, 0, 0, 0,
    110  1.6.6.2  tls 		    2, 0, 0, 1, 0, 0, 0, 0, 1, 15, 2),
    111  1.6.6.2  tls 		.smode2	= SMODE2(0, 0, 0),
    112  1.6.6.2  tls 		.srfsh	= SRFSH(4),
    113  1.6.6.2  tls 		.synch1	= SYNCH1(192, 608, 192, 84, 32),
    114  1.6.6.2  tls 		.synch2	= SYNCH2(768, 524),
    115  1.6.6.2  tls 		.syncv	= SYNCV(2, 480, 0, 33, 0, 10),
    116  1.6.6.2  tls 		.display= DISPLAY(479, 1279, 0, 1, 34, 276)
    117  1.6.6.2  tls 	}
    118  1.6.6.2  tls };
    119  1.6.6.2  tls 
    120  1.6.6.2  tls void
    121  1.6.6.2  tls gs_init(enum gs_crt_type type)
    122  1.6.6.2  tls {
    123  1.6.6.2  tls 	const struct gs_crt_param *p = &gs_crt_param[type];
    124  1.6.6.2  tls 	u_int64_t smode1 = p->smode1;
    125  1.6.6.2  tls 
    126  1.6.6.2  tls 	/* GS reset */
    127  1.6.6.2  tls 	_reg_write_8(GS_S_CSR_REG, 1 << 9);
    128  1.6.6.2  tls 
    129  1.6.6.2  tls 	/* setup PCRTC */
    130  1.6.6.2  tls 	_reg_write_8(GS_S_PMODE_REG, 0); /* disable circuit 1/2 */
    131  1.6.6.2  tls 
    132  1.6.6.2  tls 	_reg_write_8(GS_S_SMODE1_REG, smode1 | ((u_int64_t)1 << 16));
    133  1.6.6.2  tls 	_reg_write_8(GS_S_SYNCH1_REG, p->synch1);
    134  1.6.6.2  tls 	_reg_write_8(GS_S_SYNCH2_REG, p->synch2);
    135  1.6.6.2  tls 	_reg_write_8(GS_S_SYNCV_REG, p->syncv);
    136  1.6.6.2  tls 	_reg_write_8(GS_S_SMODE2_REG, p->smode2);
    137  1.6.6.2  tls 	_reg_write_8(GS_S_SRFSH_REG, p->srfsh);
    138  1.6.6.2  tls 
    139  1.6.6.2  tls 	if (p->dvemode == 2) { /* PLL on */
    140  1.6.6.2  tls 		_reg_write_8(GS_S_SMODE1_REG, smode1 & ~((u_int64_t)1 << 16));
    141  1.6.6.2  tls 		delay(2500);
    142  1.6.6.2  tls 	}
    143  1.6.6.2  tls 
    144  1.6.6.2  tls 	/* start sync */
    145  1.6.6.2  tls 	_reg_write_8(GS_S_SMODE1_REG,
    146  1.6.6.2  tls 	    smode1 & ~((u_int64_t)1 << 16) & ~((u_int64_t)1 << 17));
    147  1.6.6.2  tls 
    148  1.6.6.2  tls 	sifbios_setdve(p->dvemode);
    149  1.6.6.2  tls 
    150  1.6.6.2  tls 	/* enable circuit */
    151  1.6.6.2  tls 	_reg_write_8(GS_S_PMODE_REG, 0x66);
    152  1.6.6.2  tls 
    153  1.6.6.2  tls 	/* display environment */
    154  1.6.6.2  tls 	_reg_write_8(GS_S_DISPLAY2_REG, p->display);
    155  1.6.6.2  tls 	_reg_write_8(GS_S_DISPFB2_REG, (p->w >> 6) << 9);
    156  1.6.6.2  tls 	_reg_write_8(GS_S_SMODE2_REG, p->smode2);
    157  1.6.6.2  tls 	_reg_write_8(GS_S_BGCOLOR_REG, 0);
    158  1.6.6.2  tls 
    159  1.6.6.2  tls 	/* Flush GS FIFO */
    160  1.6.6.2  tls 	_reg_write_8(GS_S_CSR_REG, 1 << 8);
    161  1.6.6.2  tls 
    162  1.6.6.2  tls 	/* GIF reset */
    163  1.6.6.2  tls 	_reg_write_4(GIF_CTRL_REG, 1);
    164  1.6.6.2  tls }
    165