1 /* 2 * newport_con.c: Abscon for newport hardware 3 * 4 * (C) 1998 Thomas Bogendoerfer (tsbogend@alpha.franken.de) 5 * (C) 1999 Ulf Carlsson (ulfc@thepuffingruop.com) 6 * 7 * This driver is based on sgicons.c and cons_newport. 8 * 9 * Copyright (C) 1996 David S. Miller (davem@davemloft.net) 10 * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx) 11 */ 12 #include <linux/init.h> 13 #include <linux/kernel.h> 14 #include <linux/errno.h> 15 #include <linux/kd.h> 16 #include <linux/selection.h> 17 #include <linux/console.h> 18 #include <linux/vt_kern.h> 19 #include <linux/mm.h> 20 #include <linux/module.h> 21 #include <linux/slab.h> 22 23 #include <asm/io.h> 24 #include <asm/uaccess.h> 25 #include <asm/page.h> 26 #include <asm/pgtable.h> 27 #include <asm/gio_device.h> 28 29 #include <video/newport.h> 30 31 #include <linux/linux_logo.h> 32 #include <linux/font.h> 33 34 #define FONT_DATA ((unsigned char *)font_vga_8x16.data) 35 36 /* borrowed from fbcon.c */ 37 #define REFCOUNT(fd) (((int *)(fd))[-1]) 38 #define FNTSIZE(fd) (((int *)(fd))[-2]) 39 #define FNTCHARCNT(fd) (((int *)(fd))[-3]) 40 #define FONT_EXTRA_WORDS 3 41 42 static unsigned char *font_data[MAX_NR_CONSOLES]; 43 44 static struct newport_regs *npregs; 45 46 static int logo_active; 47 static int topscan; 48 static int xcurs_correction = 29; 49 static int newport_xsize; 50 static int newport_ysize; 51 static int newport_has_init; 52 53 static int newport_set_def_font(int unit, struct console_font *op); 54 55 #define BMASK(c) (c << 24) 56 57 #define RENDER(regs, cp) do { \ 58 (regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \ 59 (regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \ 60 (regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \ 61 (regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \ 62 (regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \ 63 (regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \ 64 (regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \ 65 (regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \ 66 } while(0) 67 68 #define TESTVAL 0xdeadbeef 69 #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11) 70 71 static inline void newport_render_background(int xstart, int ystart, 72 int xend, int yend, int ci) 73 { 74 newport_wait(npregs); 75 npregs->set.wrmask = 0xffffffff; 76 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | 77 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX 78 | NPORT_DMODE0_STOPY); 79 npregs->set.colori = ci; 80 npregs->set.xystarti = 81 (xstart << 16) | ((ystart + topscan) & 0x3ff); 82 npregs->go.xyendi = 83 ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff); 84 } 85 86 static inline void newport_init_cmap(void) 87 { 88 unsigned short i; 89 90 for (i = 0; i < 16; i++) { 91 newport_bfwait(npregs); 92 newport_cmap_setaddr(npregs, color_table[i]); 93 newport_cmap_setrgb(npregs, 94 default_red[i], 95 default_grn[i], default_blu[i]); 96 } 97 } 98 99 static const struct linux_logo *newport_show_logo(void) 100 { 101 #ifdef CONFIG_LOGO_SGI_CLUT224 102 const struct linux_logo *logo = fb_find_logo(8); 103 const unsigned char *clut; 104 const unsigned char *data; 105 unsigned long i; 106 107 if (!logo) 108 return NULL; 109 clut = logo->clut; 110 data = logo->data; 111 112 for (i = 0; i < logo->clutsize; i++) { 113 newport_bfwait(npregs); 114 newport_cmap_setaddr(npregs, i + 0x20); 115 newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]); 116 clut += 3; 117 } 118 119 newport_wait(npregs); 120 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | 121 NPORT_DMODE0_CHOST); 122 123 npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0); 124 npregs->set.xyendi = ((newport_xsize - 1) << 16); 125 newport_wait(npregs); 126 127 for (i = 0; i < logo->width*logo->height; i++) 128 npregs->go.hostrw0 = *data++ << 24; 129 130 return logo; 131 #endif /* CONFIG_LOGO_SGI_CLUT224 */ 132 } 133 134 static inline void newport_clear_screen(int xstart, int ystart, int xend, 135 int yend, int ci) 136 { 137 if (logo_active) 138 return; 139 140 newport_wait(npregs); 141 npregs->set.wrmask = 0xffffffff; 142 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | 143 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX 144 | NPORT_DMODE0_STOPY); 145 npregs->set.colori = ci; 146 npregs->set.xystarti = (xstart << 16) | ystart; 147 npregs->go.xyendi = (xend << 16) | yend; 148 } 149 150 static inline void newport_clear_lines(int ystart, int yend, int ci) 151 { 152 ystart = ((ystart << 4) + topscan) & 0x3ff; 153 yend = ((yend << 4) + topscan + 15) & 0x3ff; 154 newport_clear_screen(0, ystart, 1280 + 63, yend, ci); 155 } 156 157 static void newport_reset(void) 158 { 159 unsigned short treg; 160 int i; 161 162 newport_wait(npregs); 163 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); 164 newport_vc2_set(npregs, VC2_IREG_CONTROL, 165 (treg | VC2_CTRL_EVIDEO)); 166 167 treg = newport_vc2_get(npregs, VC2_IREG_CENTRY); 168 newport_vc2_set(npregs, VC2_IREG_RADDR, treg); 169 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM | 170 NPORT_DMODE_W2 | VC2_PROTOCOL); 171 for (i = 0; i < 128; i++) { 172 newport_bfwait(npregs); 173 if (i == 92 || i == 94) 174 npregs->set.dcbdata0.byshort.s1 = 0xff00; 175 else 176 npregs->set.dcbdata0.byshort.s1 = 0x0000; 177 } 178 179 newport_init_cmap(); 180 181 /* turn off popup plane */ 182 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL | 183 XM9_CRS_CONFIG | NPORT_DMODE_W1); 184 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE; 185 npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL | 186 XM9_CRS_CONFIG | NPORT_DMODE_W1); 187 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE; 188 189 topscan = 0; 190 npregs->cset.topscan = 0x3ff; 191 npregs->cset.xywin = (4096 << 16) | 4096; 192 193 /* Clear the screen. */ 194 newport_clear_screen(0, 0, 1280 + 63, 1024, 0); 195 } 196 197 /* 198 * calculate the actual screen size by reading 199 * the video timing out of the VC2 200 */ 201 static void newport_get_screensize(void) 202 { 203 int i, cols; 204 unsigned short ventry, treg; 205 unsigned short linetable[128]; /* should be enough */ 206 207 ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY); 208 newport_vc2_set(npregs, VC2_IREG_RADDR, ventry); 209 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM | 210 NPORT_DMODE_W2 | VC2_PROTOCOL); 211 for (i = 0; i < 128; i++) { 212 newport_bfwait(npregs); 213 linetable[i] = npregs->set.dcbdata0.byshort.s1; 214 } 215 216 newport_xsize = newport_ysize = 0; 217 for (i = 0; i < ARRAY_SIZE(linetable) - 1 && linetable[i + 1]; i += 2) { 218 cols = 0; 219 newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]); 220 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM | 221 NPORT_DMODE_W2 | VC2_PROTOCOL); 222 do { 223 newport_bfwait(npregs); 224 treg = npregs->set.dcbdata0.byshort.s1; 225 if ((treg & 1) == 0) 226 cols += (treg >> 7) & 0xfe; 227 if ((treg & 0x80) == 0) { 228 newport_bfwait(npregs); 229 treg = npregs->set.dcbdata0.byshort.s1; 230 } 231 } while ((treg & 0x8000) == 0); 232 if (cols) { 233 if (cols > newport_xsize) 234 newport_xsize = cols; 235 newport_ysize += linetable[i + 1]; 236 } 237 } 238 printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize); 239 } 240 241 static void newport_get_revisions(void) 242 { 243 unsigned int tmp; 244 unsigned int board_rev; 245 unsigned int rex3_rev; 246 unsigned int vc2_rev; 247 unsigned int cmap_rev; 248 unsigned int xmap9_rev; 249 unsigned int bt445_rev; 250 unsigned int bitplanes; 251 252 rex3_rev = npregs->cset.status & NPORT_STAT_VERS; 253 254 npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL | 255 NCMAP_REGADDR_RREG | NPORT_DMODE_W1); 256 tmp = npregs->set.dcbdata0.bybytes.b3; 257 cmap_rev = tmp & 7; 258 board_rev = (tmp >> 4) & 7; 259 bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24; 260 261 npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL | 262 NCMAP_REGADDR_RREG | NPORT_DMODE_W1); 263 tmp = npregs->set.dcbdata0.bybytes.b3; 264 if ((tmp & 7) < cmap_rev) 265 cmap_rev = (tmp & 7); 266 267 vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7; 268 269 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL | 270 XM9_CRS_REVISION | NPORT_DMODE_W1); 271 xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7; 272 273 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL | 274 BT445_CSR_ADDR_REG | NPORT_DMODE_W1); 275 npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG; 276 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL | 277 BT445_CSR_REVISION | NPORT_DMODE_W1); 278 bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a; 279 280 #define L(a) (char)('A'+(a)) 281 printk 282 ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n", 283 board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev), 284 L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev)); 285 #undef L 286 287 if (board_rev == 3) /* I don't know all affected revisions */ 288 xcurs_correction = 21; 289 } 290 291 static void newport_exit(void) 292 { 293 int i; 294 295 /* free memory used by user font */ 296 for (i = 0; i < MAX_NR_CONSOLES; i++) 297 newport_set_def_font(i, NULL); 298 } 299 300 /* Can't be __init, take_over_console may call it later */ 301 static const char *newport_startup(void) 302 { 303 int i; 304 305 npregs->cset.config = NPORT_CFG_GD0; 306 307 if (newport_wait(npregs)) 308 goto out_unmap; 309 310 npregs->set.xstarti = TESTVAL; 311 if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL)) 312 goto out_unmap; 313 314 for (i = 0; i < MAX_NR_CONSOLES; i++) 315 font_data[i] = FONT_DATA; 316 317 newport_reset(); 318 newport_get_revisions(); 319 newport_get_screensize(); 320 newport_has_init = 1; 321 322 return "SGI Newport"; 323 324 out_unmap: 325 return NULL; 326 } 327 328 static void newport_init(struct vc_data *vc, int init) 329 { 330 vc->vc_cols = newport_xsize / 8; 331 vc->vc_rows = newport_ysize / 16; 332 vc->vc_can_do_color = 1; 333 } 334 335 static void newport_deinit(struct vc_data *c) 336 { 337 if (!con_is_bound(&newport_con) && newport_has_init) { 338 newport_exit(); 339 newport_has_init = 0; 340 } 341 } 342 343 static void newport_clear(struct vc_data *vc, int sy, int sx, int height, 344 int width) 345 { 346 int xend = ((sx + width) << 3) - 1; 347 int ystart = ((sy << 4) + topscan) & 0x3ff; 348 int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff; 349 350 if (logo_active) 351 return; 352 353 if (ystart < yend) { 354 newport_clear_screen(sx << 3, ystart, xend, yend, 355 (vc->vc_color & 0xf0) >> 4); 356 } else { 357 newport_clear_screen(sx << 3, ystart, xend, 1023, 358 (vc->vc_color & 0xf0) >> 4); 359 newport_clear_screen(sx << 3, 0, xend, yend, 360 (vc->vc_color & 0xf0) >> 4); 361 } 362 } 363 364 static void newport_putc(struct vc_data *vc, int charattr, int ypos, 365 int xpos) 366 { 367 unsigned char *p; 368 369 p = &font_data[vc->vc_num][(charattr & 0xff) << 4]; 370 charattr = (charattr >> 8) & 0xff; 371 xpos <<= 3; 372 ypos <<= 4; 373 374 newport_render_background(xpos, ypos, xpos, ypos, 375 (charattr & 0xf0) >> 4); 376 377 /* Set the color and drawing mode. */ 378 newport_wait(npregs); 379 npregs->set.colori = charattr & 0xf; 380 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | 381 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB | 382 NPORT_DMODE0_L32); 383 384 /* Set coordinates for bitmap operation. */ 385 npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff); 386 npregs->set.xyendi = ((xpos + 7) << 16); 387 newport_wait(npregs); 388 389 /* Go, baby, go... */ 390 RENDER(npregs, p); 391 } 392 393 static void newport_putcs(struct vc_data *vc, const unsigned short *s, 394 int count, int ypos, int xpos) 395 { 396 int i; 397 int charattr; 398 unsigned char *p; 399 400 charattr = (scr_readw(s) >> 8) & 0xff; 401 402 xpos <<= 3; 403 ypos <<= 4; 404 405 if (!logo_active) 406 /* Clear the area behing the string */ 407 newport_render_background(xpos, ypos, 408 xpos + ((count - 1) << 3), ypos, 409 (charattr & 0xf0) >> 4); 410 411 newport_wait(npregs); 412 413 /* Set the color and drawing mode. */ 414 npregs->set.colori = charattr & 0xf; 415 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | 416 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB | 417 NPORT_DMODE0_L32); 418 419 for (i = 0; i < count; i++, xpos += 8) { 420 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4]; 421 422 newport_wait(npregs); 423 424 /* Set coordinates for bitmap operation. */ 425 npregs->set.xystarti = 426 (xpos << 16) | ((ypos + topscan) & 0x3ff); 427 npregs->set.xyendi = ((xpos + 7) << 16); 428 429 /* Go, baby, go... */ 430 RENDER(npregs, p); 431 } 432 } 433 434 static void newport_cursor(struct vc_data *vc, int mode) 435 { 436 unsigned short treg; 437 int xcurs, ycurs; 438 439 switch (mode) { 440 case CM_ERASE: 441 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); 442 newport_vc2_set(npregs, VC2_IREG_CONTROL, 443 (treg & ~(VC2_CTRL_ECDISP))); 444 break; 445 446 case CM_MOVE: 447 case CM_DRAW: 448 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); 449 newport_vc2_set(npregs, VC2_IREG_CONTROL, 450 (treg | VC2_CTRL_ECDISP)); 451 xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2; 452 ycurs = ((xcurs / vc->vc_cols) << 4) + 31; 453 xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction; 454 newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs); 455 newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs); 456 } 457 } 458 459 static int newport_switch(struct vc_data *vc) 460 { 461 static int logo_drawn = 0; 462 463 topscan = 0; 464 npregs->cset.topscan = 0x3ff; 465 466 if (!logo_drawn) { 467 if (newport_show_logo()) { 468 logo_drawn = 1; 469 logo_active = 1; 470 } 471 } 472 473 return 1; 474 } 475 476 static int newport_blank(struct vc_data *c, int blank, int mode_switch) 477 { 478 unsigned short treg; 479 480 if (blank == 0) { 481 /* unblank console */ 482 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); 483 newport_vc2_set(npregs, VC2_IREG_CONTROL, 484 (treg | VC2_CTRL_EDISP)); 485 } else { 486 /* blank console */ 487 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); 488 newport_vc2_set(npregs, VC2_IREG_CONTROL, 489 (treg & ~(VC2_CTRL_EDISP))); 490 } 491 return 1; 492 } 493 494 static int newport_set_font(int unit, struct console_font *op) 495 { 496 int w = op->width; 497 int h = op->height; 498 int size = h * op->charcount; 499 int i; 500 unsigned char *new_data, *data = op->data, *p; 501 502 /* ladis: when I grow up, there will be a day... and more sizes will 503 * be supported ;-) */ 504 if ((w != 8) || (h != 16) 505 || (op->charcount != 256 && op->charcount != 512)) 506 return -EINVAL; 507 508 if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, 509 GFP_USER))) return -ENOMEM; 510 511 new_data += FONT_EXTRA_WORDS * sizeof(int); 512 FNTSIZE(new_data) = size; 513 FNTCHARCNT(new_data) = op->charcount; 514 REFCOUNT(new_data) = 0; /* usage counter */ 515 516 p = new_data; 517 for (i = 0; i < op->charcount; i++) { 518 memcpy(p, data, h); 519 data += 32; 520 p += h; 521 } 522 523 /* check if font is already used by other console */ 524 for (i = 0; i < MAX_NR_CONSOLES; i++) { 525 if (font_data[i] != FONT_DATA 526 && FNTSIZE(font_data[i]) == size 527 && !memcmp(font_data[i], new_data, size)) { 528 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int)); 529 /* current font is the same as the new one */ 530 if (i == unit) 531 return 0; 532 new_data = font_data[i]; 533 break; 534 } 535 } 536 /* old font is user font */ 537 if (font_data[unit] != FONT_DATA) { 538 if (--REFCOUNT(font_data[unit]) == 0) 539 kfree(font_data[unit] - 540 FONT_EXTRA_WORDS * sizeof(int)); 541 } 542 REFCOUNT(new_data)++; 543 font_data[unit] = new_data; 544 545 return 0; 546 } 547 548 static int newport_set_def_font(int unit, struct console_font *op) 549 { 550 if (font_data[unit] != FONT_DATA) { 551 if (--REFCOUNT(font_data[unit]) == 0) 552 kfree(font_data[unit] - 553 FONT_EXTRA_WORDS * sizeof(int)); 554 font_data[unit] = FONT_DATA; 555 } 556 557 return 0; 558 } 559 560 static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name) 561 { 562 return newport_set_def_font(vc->vc_num, op); 563 } 564 565 static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags) 566 { 567 return newport_set_font(vc->vc_num, font); 568 } 569 570 static int newport_set_palette(struct vc_data *vc, unsigned char *table) 571 { 572 return -EINVAL; 573 } 574 575 static int newport_scrolldelta(struct vc_data *vc, int lines) 576 { 577 /* there is (nearly) no off-screen memory, so we can't scroll back */ 578 return 0; 579 } 580 581 static int newport_scroll(struct vc_data *vc, int t, int b, int dir, 582 int lines) 583 { 584 int count, x, y; 585 unsigned short *s, *d; 586 unsigned short chattr; 587 588 logo_active = 0; /* it's time to disable the logo now.. */ 589 590 if (t == 0 && b == vc->vc_rows) { 591 if (dir == SM_UP) { 592 topscan = (topscan + (lines << 4)) & 0x3ff; 593 newport_clear_lines(vc->vc_rows - lines, 594 vc->vc_rows - 1, 595 (vc->vc_color & 0xf0) >> 4); 596 } else { 597 topscan = (topscan + (-lines << 4)) & 0x3ff; 598 newport_clear_lines(0, lines - 1, 599 (vc->vc_color & 0xf0) >> 4); 600 } 601 npregs->cset.topscan = (topscan - 1) & 0x3ff; 602 return 0; 603 } 604 605 count = (b - t - lines) * vc->vc_cols; 606 if (dir == SM_UP) { 607 x = 0; 608 y = t; 609 s = (unsigned short *) (vc->vc_origin + 610 vc->vc_size_row * (t + lines)); 611 d = (unsigned short *) (vc->vc_origin + 612 vc->vc_size_row * t); 613 while (count--) { 614 chattr = scr_readw(s++); 615 if (chattr != scr_readw(d)) { 616 newport_putc(vc, chattr, y, x); 617 scr_writew(chattr, d); 618 } 619 d++; 620 if (++x == vc->vc_cols) { 621 x = 0; 622 y++; 623 } 624 } 625 d = (unsigned short *) (vc->vc_origin + 626 vc->vc_size_row * (b - lines)); 627 x = 0; 628 y = b - lines; 629 for (count = 0; count < (lines * vc->vc_cols); count++) { 630 if (scr_readw(d) != vc->vc_video_erase_char) { 631 newport_putc(vc, vc->vc_video_erase_char, 632 y, x); 633 scr_writew(vc->vc_video_erase_char, d); 634 } 635 d++; 636 if (++x == vc->vc_cols) { 637 x = 0; 638 y++; 639 } 640 } 641 } else { 642 x = vc->vc_cols - 1; 643 y = b - 1; 644 s = (unsigned short *) (vc->vc_origin + 645 vc->vc_size_row * (b - lines) - 2); 646 d = (unsigned short *) (vc->vc_origin + 647 vc->vc_size_row * b - 2); 648 while (count--) { 649 chattr = scr_readw(s--); 650 if (chattr != scr_readw(d)) { 651 newport_putc(vc, chattr, y, x); 652 scr_writew(chattr, d); 653 } 654 d--; 655 if (x-- == 0) { 656 x = vc->vc_cols - 1; 657 y--; 658 } 659 } 660 d = (unsigned short *) (vc->vc_origin + 661 vc->vc_size_row * t); 662 x = 0; 663 y = t; 664 for (count = 0; count < (lines * vc->vc_cols); count++) { 665 if (scr_readw(d) != vc->vc_video_erase_char) { 666 newport_putc(vc, vc->vc_video_erase_char, 667 y, x); 668 scr_writew(vc->vc_video_erase_char, d); 669 } 670 d++; 671 if (++x == vc->vc_cols) { 672 x = 0; 673 y++; 674 } 675 } 676 } 677 return 1; 678 } 679 680 static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy, 681 int dx, int h, int w) 682 { 683 short xs, ys, xe, ye, xoffs, yoffs, tmp; 684 685 xs = sx << 3; 686 xe = ((sx + w) << 3) - 1; 687 /* 688 * as bmove is only used to move stuff around in the same line 689 * (h == 1), we don't care about wrap arounds caused by topscan != 0 690 */ 691 ys = ((sy << 4) + topscan) & 0x3ff; 692 ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff; 693 xoffs = (dx - sx) << 3; 694 yoffs = (dy - sy) << 4; 695 if (xoffs > 0) { 696 /* move to the right, exchange starting points */ 697 tmp = xe; 698 xe = xs; 699 xs = tmp; 700 } 701 newport_wait(npregs); 702 npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK | 703 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX 704 | NPORT_DMODE0_STOPY); 705 npregs->set.xystarti = (xs << 16) | ys; 706 npregs->set.xyendi = (xe << 16) | ye; 707 npregs->go.xymove = (xoffs << 16) | yoffs; 708 } 709 710 static int newport_dummy(struct vc_data *c) 711 { 712 return 0; 713 } 714 715 #define DUMMY (void *) newport_dummy 716 717 const struct consw newport_con = { 718 .owner = THIS_MODULE, 719 .con_startup = newport_startup, 720 .con_init = newport_init, 721 .con_deinit = newport_deinit, 722 .con_clear = newport_clear, 723 .con_putc = newport_putc, 724 .con_putcs = newport_putcs, 725 .con_cursor = newport_cursor, 726 .con_scroll = newport_scroll, 727 .con_bmove = newport_bmove, 728 .con_switch = newport_switch, 729 .con_blank = newport_blank, 730 .con_font_set = newport_font_set, 731 .con_font_default = newport_font_default, 732 .con_set_palette = newport_set_palette, 733 .con_scrolldelta = newport_scrolldelta, 734 .con_set_origin = DUMMY, 735 .con_save_screen = DUMMY 736 }; 737 738 static int newport_probe(struct gio_device *dev, 739 const struct gio_device_id *id) 740 { 741 unsigned long newport_addr; 742 743 if (!dev->resource.start) 744 return -EINVAL; 745 746 if (npregs) 747 return -EBUSY; /* we only support one Newport as console */ 748 749 newport_addr = dev->resource.start + 0xF0000; 750 if (!request_mem_region(newport_addr, 0x10000, "Newport")) 751 return -ENODEV; 752 753 npregs = (struct newport_regs *)/* ioremap cannot fail */ 754 ioremap(newport_addr, sizeof(struct newport_regs)); 755 756 return take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); 757 } 758 759 static void newport_remove(struct gio_device *dev) 760 { 761 give_up_console(&newport_con); 762 iounmap((void *)npregs); 763 } 764 765 static struct gio_device_id newport_ids[] = { 766 { .id = 0x7e }, 767 { .id = 0xff } 768 }; 769 770 MODULE_ALIAS("gio:7e"); 771 772 static struct gio_driver newport_driver = { 773 .name = "newport", 774 .id_table = newport_ids, 775 .probe = newport_probe, 776 .remove = newport_remove, 777 }; 778 779 int __init newport_console_init(void) 780 { 781 return gio_register_driver(&newport_driver); 782 } 783 784 void __exit newport_console_exit(void) 785 { 786 gio_unregister_driver(&newport_driver); 787 } 788 789 module_init(newport_console_init); 790 module_exit(newport_console_exit); 791 792 MODULE_LICENSE("GPL"); 793