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