1 /* 2 * Copyright (c) 1992 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Sony Corp. and Kazumasa Utashiro of Software Research Associates, Inc. 7 * 8 * %sccs.include.redist.c% 9 * 10 * from: $Hdr: fbbm_253.c,v 4.300 91/06/09 06:33:12 root Rel41 $ SONY; 11 * 12 * @(#)fbbm_253.c 7.4 (Berkeley) 03/09/93 13 */ 14 15 /* 16 * NWB-253 frame buffer driver 17 */ 18 19 #include "nwb253.h" 20 21 #if NNWB253 > 0 22 #include <sys/param.h> 23 #include <news3400/iop/framebuf.h> 24 #include <news3400/iop/fbreg.h> 25 26 #include <news3400/fb/fbdefs.h> 27 28 extern int error(); 29 extern int nofunc(); 30 extern char *ext_fnt24_addr[]; 31 extern char *ext_fnt_addr[]; 32 33 extern short zero[]; 34 35 #define NOP { int j; for (j = 0; j < 40; j++); } 36 37 #define VRAM_START (unsigned int *)(0x88000000) 38 #define VRAM_WIDTH (2048/32) 39 40 static caddr_t 41 fb253_Krom_addr(fb, c, sr) 42 struct fbdev *fb; 43 register int c; 44 lRectangle *sr; 45 { 46 unsigned int cvcode16(); 47 48 if ((c >= 0x20) && (c <= 0x7e)) { 49 /* 50 * ASCII char 51 */ 52 c -= ' '; 53 c = ((c & 0x1f) | ((c & 0xe0) << 2)) << 7; 54 return (caddr_t)(c + fb->Krom_base + (sr->extent.y > 16 ? 0 : 96)); 55 } else if ((c >= 0xa1) && (c <= 0xdf)) { 56 /* 57 * KANA char 58 */ 59 if (sr->extent.y > 16) 60 return ((caddr_t)ext_fnt24_addr[c + 64]); 61 else 62 return ((caddr_t)ext_fnt_addr[c + 64]); 63 } else if ((c >= 0x2020) && (c <= 0x7e7e)) { 64 /* 65 * KANJI char 66 */ 67 switch (c & 0x7000) { 68 case 0x2000: 69 c = ((c&0x1f)|((c&0x60)<<5)|((c&0x700)>>1))<<7; 70 break; 71 case 0x3000: 72 case 0x4000: 73 c = ((c&0x7f)|((c&0xf00)>>1)|((c&0x4000)>>3))<<7; 74 break; 75 case 0x5000: 76 case 0x6000: 77 c = ((c&0x7f)|((c&0xf00)>>1)|((c&0x2000)>>2)|0x1000)<<7; 78 break; 79 case 0x7000: 80 c = ((c&0x1f)|((c&0x60)<<5)|((c&0x700)>>1)|0x1000)<<7; 81 break; 82 } 83 return (caddr_t)(c + fb->Krom_base + (sr->extent.y > 16 ? 0 : 96)); 84 } else { 85 /* 86 * UNKNOWN char 87 */ 88 return (caddr_t)zero; 89 } 90 } 91 92 static int 93 fb253_set_dimmer(fb, dim) 94 struct fbdev *fb; 95 int dim; 96 { 97 int s; 98 99 fb->status_flag = (fb->status_flag & 0xf3) | ((dim & 3) << 2); 100 *(volatile u_short *)(0xb8ff0000) = fb->status_flag; 101 102 return (FB_ROK); 103 } 104 105 static int 106 fb253_get_dimmer(fb) 107 struct fbdev *fb; 108 { 109 int dim; 110 111 dim = (fb->status_flag >> 2) & 3; 112 return (dim); 113 } 114 115 int 116 fb253_get_pixel(fb, pixel) 117 struct fbdev *fb; 118 register int pixel; 119 { 120 return (pixel); 121 } 122 123 fb253_ioctl(fb, cmd, data) 124 struct fbdev *fb; 125 int cmd; 126 int *data; 127 { 128 register int result = 0; 129 130 switch (cmd) { 131 case FB_INTCHECK: 132 if (*(volatile u_short *)(0xb8ff0000) & 0x08) 133 result |= FB_INT_VSYNC; 134 break; 135 case FB_INTENABLE: 136 if (*data & FB_INT_VSYNC) { 137 fb->status_flag |= 1; 138 *(volatile u_short *)(0xb8ff0000) = fb->status_flag; 139 WB_FLUSH; 140 } 141 break; 142 case FB_INTCLEAR: 143 if (*data & FB_INT_VSYNC) { 144 fb->status_flag &= ~1; 145 *(volatile u_short *)(0xb8ff0000) = fb->status_flag; 146 WB_FLUSH; 147 } 148 break; 149 case FB_STATUSCHECK: 150 break; 151 default: 152 result = -1; 153 } 154 return (result); 155 } 156 157 int 158 fb253_get_page(fb, off) 159 struct fbdev *fb; 160 off_t off; 161 { 162 if (off < 2048/8 * 2048) /* X/8 * Y */ 163 return (((unsigned int)0x8000000 + off) >> PGSHIFT); 164 else 165 return (-1); 166 } 167 168 int 169 fb253_probe(unit) 170 int unit; 171 { 172 if (unit >= NNWB253) 173 return 0; 174 if (badaddr(0xb8ff0000, 2) || badaddr(0xb8e00000, 2)) 175 return 0; 176 if ((*(volatile u_short *)(0xb8ff0000) & 7) == 4) 177 return FB_NWB253; 178 return 0; 179 } 180 181 void fbmem_rop_init(); 182 void fbmem_rop_copy(); 183 void fbmem_rop_winit(); 184 void fbmem_rop_write(); 185 void fbmem_rop_read(); 186 void fbmem_rop_cinit(); 187 void fbmem_rop_clear(); 188 void fbmem_rop_vect(); 189 void fbmem_rop_dot(); 190 191 static struct fbdev_ops 192 fb253_ops = { 193 fbmem_rop_init, 194 fbmem_rop_copy, 195 fbmem_rop_winit, 196 fbmem_rop_write, 197 fbmem_rop_read, 198 fbmem_rop_cinit, 199 fbmem_rop_clear, 200 fbmem_rop_vect, 201 fbmem_rop_dot, 202 (void (*)())nofunc, 203 (void (*)())error, 204 (void (*)())error, 205 fb253_Krom_addr, 206 (void (*)())error, 207 error, 208 error, 209 fb253_get_pixel, 210 fb253_set_dimmer, 211 fb253_get_dimmer, 212 nofunc, 213 nofunc, 214 fb253_ioctl, 215 fb253_get_page, 216 (void (*)())nofunc, 217 (void (*)())nofunc, 218 (void (*)())nofunc, 219 (void (*)())nofunc, 220 }; 221 222 static u_short 223 nwp512_data1[] = { 224 0x00, 0x44, 225 0x01, 0x33, 226 0x02, 0x3c, 227 0x03, 0x38, 228 0x04, 0x84, 229 0x05, 0x03, 230 0x06, 0x80, 231 0x07, 0x80, 232 0x08, 0x10, 233 0x09, 0x07, 234 0x0a, 0x20, 235 0x0c, 0x00, 236 0x0d, 0x00, 237 0x1b, 0x03 238 }; 239 240 static u_short 241 nwp512_data2[] = { 242 0x1e, 0x08, 243 0x20, 0x08, 244 0x21, 0x0d 245 }; 246 247 static u_short 248 nwp518_data1[] = { 249 0x00, 0x52, 250 0x01, 0x40, 251 0x02, 0x4a, 252 0x03, 0x49, 253 0x04, 0x63, 254 0x05, 0x02, 255 0x06, 0x60, 256 0x07, 0x60, 257 0x08, 0x10, 258 0x09, 0x07, 259 0x0a, 0x20, 260 0x0c, 0x00, 261 0x0d, 0x00, 262 0x1b, 0x04 263 }; 264 265 static u_short 266 nwp518_data2[] = { 267 0x1e, 0x08, 268 0x20, 0x00, 269 0x21, 0x00 270 }; 271 272 static u_short 273 nwe501_data1[] = { 274 0x00, 0x4b, 275 0x01, 0x40, 276 0x02, 0x4a, 277 0x03, 0x43, 278 0x04, 0x64, 279 0x05, 0x02, 280 0x06, 0x60, 281 0x07, 0x60, 282 0x08, 0x10, 283 0x09, 0x07, 284 0x0a, 0x20, 285 0x0c, 0x00, 286 0x0d, 0x00, 287 0x1b, 0x04 288 }; 289 290 static u_short 291 nwe501_data2[] = { 292 0x1e, 0x08, 293 0x20, 0x00, 294 0x21, 0x00 295 }; 296 297 static u_short 298 *crtc_data[3][2] = { 299 nwp512_data1, nwp512_data2, 300 nwp518_data1, nwp518_data2, 301 nwe501_data1, nwe501_data2, 302 }; 303 304 static void 305 fb253_init(fb, id) 306 struct fbdev *fb; 307 int id; 308 { 309 register int i; 310 register volatile u_short *ctlreg = (u_short *)(0xb8ff0000); 311 register volatile u_short *crtreg = (u_short *)(0xb8fe0000); 312 register volatile u_short *p; 313 u_short dummy; 314 315 *ctlreg = 0; /* stop crtc */ 316 NOP; 317 318 /* initialize crtc without R3{0,1,2} */ 319 p = crtc_data[id][0]; 320 for (i = 0; i < 28; i++) { 321 *crtreg++ = *p++; 322 NOP; 323 } 324 325 *ctlreg = 0x02; /* start crtc */ 326 NOP; 327 328 /* set crtc control reg */ 329 p = crtc_data[id][1]; 330 for (i = 0; i < 6; i++) { 331 *crtreg++ = *p++; 332 NOP; 333 } 334 } 335 336 struct mfbdev fb253 = { (caddr_t)VRAM_START, VRAM_WIDTH }; 337 338 void 339 fb253_setup(fb) 340 struct fbdev *fb; 341 { 342 int id; 343 344 if (fb->type) { 345 fb->Mono = 1; 346 fb->Colorwidth = 1; 347 fb->fbNplane = 1; 348 fb->planemask = 0x1; 349 fb->Dimmer = 1; 350 351 id = ((*(volatile u_short *)(0xb8ff0000)) >> 8) & 0xf; 352 353 switch (id) { 354 case 0: 355 fb->FrameRect.extent.x = 2048; 356 fb->FrameRect.extent.y = 2048; 357 fb->VisRect.extent.x = 816; 358 fb->VisRect.extent.y = 1024; 359 fb->cursorP.x = 816/2; 360 fb->cursorP.y = 1024/2; 361 fb->font_w = 8; 362 fb->font_h = 16; 363 fb->char_w = 10; 364 fb->char_h = 24; 365 fb->scr_w = 816; 366 fb->scr_h = 1024; 367 fb->ch_pos = 5; 368 fb->ul_pos = 22; 369 fb->x_offset = 8; 370 fb->y_offset = 8; 371 fb->rit_m = 80; 372 fb->btm_m = 42; 373 break; 374 case 1: 375 case 2: 376 fb->FrameRect.extent.x = 2048; 377 fb->FrameRect.extent.y = 2048; 378 fb->VisRect.extent.x = 1024; 379 fb->VisRect.extent.y = 768; 380 fb->cursorP.x = 1024/2; 381 fb->cursorP.y = 768/2; 382 fb->font_w = 8; 383 fb->font_h = 16; 384 fb->char_w = 12; 385 fb->char_h = 22; 386 fb->scr_w = 1024; 387 fb->scr_h = 768; 388 fb->ch_pos = 2; 389 fb->ul_pos = 20; 390 fb->x_offset = 32; 391 fb->y_offset = 21; 392 fb->rit_m = 80; 393 fb->btm_m = 33; 394 break; 395 } 396 fb->FrameRect.origin.x = 0; 397 fb->FrameRect.origin.y = 0; 398 fb->VisRect.origin.x = 0; 399 fb->VisRect.origin.y = 0; 400 fb->Krom_BM0.type = BM_MEM; 401 fb->Krom_BM0.depth = 1; 402 fb->Krom_BM0.width = 1; 403 fb->Krom_BM0.rect.origin.x = 0; 404 fb->Krom_BM0.rect.origin.y = 0; 405 fb->Krom_BM0.rect.extent.x = 16; 406 fb->Krom_BM0.rect.extent.y = 16; 407 fb->Krom_BM1.type = BM_MEM; 408 fb->Krom_BM1.depth = 1; 409 fb->Krom_BM1.width = 2; 410 fb->Krom_BM1.rect.origin.x = 0; 411 fb->Krom_BM1.rect.origin.y = 0; 412 fb->Krom_BM1.rect.extent.x = 24; 413 fb->Krom_BM1.rect.extent.y = 24; 414 fb->Krom_base = (char *)(0xb8e00000); 415 fb->Krom_font_extent0.x = 16; 416 fb->Krom_font_extent0.y = 16; 417 fb->Krom_font_extent1.x = 24; 418 fb->Krom_font_extent1.y = 24; 419 fb->cursorSet = 0; 420 fb->cursorVis = 0; 421 fb->cursorShow = 0; 422 fb->status_flag = 2; 423 fb->run_flag = 0; 424 fb->hard_cursor = 0; 425 426 fb->fbbm_op = &fb253_ops; 427 428 fb->private = (caddr_t)&fb253; 429 430 fb253_init(fb, id); 431 } 432 } 433 #endif /* NNWB253 > 0 */ 434