2 * newport_con.c: Abscon for newport hardware
4 * (C) 1998 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
5 * (C) 1999 Ulf Carlsson (ulfc@thepuffingruop.com)
7 * This driver is based on sgicons.c and cons_newport.
9 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
10 * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/tty.h>
17 #include <linux/selection.h>
18 #include <linux/console.h>
19 #include <linux/vt_kern.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
24 #include <asm/uaccess.h>
25 #include <asm/system.h>
27 #include <asm/pgtable.h>
28 #include <video/newport.h>
30 #include <linux/linux_logo.h>
31 #include <linux/font.h>
34 extern struct font_desc font_vga_8x16;
35 extern unsigned long sgi_gfxaddr;
37 #define FONT_DATA ((unsigned char *)font_vga_8x16.data)
39 /* borrowed from fbcon.c */
40 #define REFCOUNT(fd) (((int *)(fd))[-1])
41 #define FNTSIZE(fd) (((int *)(fd))[-2])
42 #define FNTCHARCNT(fd) (((int *)(fd))[-3])
43 #define FONT_EXTRA_WORDS 3
45 static unsigned char *font_data[MAX_NR_CONSOLES];
47 static struct newport_regs *npregs;
49 static int logo_active;
51 static int xcurs_correction = 29;
52 static int newport_xsize;
53 static int newport_ysize;
55 static int newport_set_def_font(int unit, struct console_font *op);
57 #define BMASK(c) (c << 24)
59 #define RENDER(regs, cp) do { \
60 (regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \
61 (regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \
62 (regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \
63 (regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \
64 (regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \
65 (regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \
66 (regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \
67 (regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \
70 #define TESTVAL 0xdeadbeef
71 #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
73 static inline void newport_render_background(int xstart, int ystart,
74 int xend, int yend, int ci)
77 npregs->set.wrmask = 0xffffffff;
78 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
79 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
80 | NPORT_DMODE0_STOPY);
81 npregs->set.colori = ci;
82 npregs->set.xystarti =
83 (xstart << 16) | ((ystart + topscan) & 0x3ff);
85 ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
88 static inline void newport_init_cmap(void)
92 for (i = 0; i < 16; i++) {
94 newport_cmap_setaddr(npregs, color_table[i]);
95 newport_cmap_setrgb(npregs,
97 default_grn[i], default_blu[i]);
101 static void newport_show_logo(void)
103 #ifdef CONFIG_LOGO_SGI_CLUT224
104 const struct linux_logo *logo = fb_find_logo(8);
105 const unsigned char *clut = logo->clut;
106 const unsigned char *data = logo->data;
109 for (i = 0; i < logo->clutsize; i++) {
111 newport_cmap_setaddr(npregs, i + 0x20);
112 newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]);
117 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
120 npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0);
121 npregs->set.xyendi = ((newport_xsize - 1) << 16);
124 for (i = 0; i < logo->width*logo->height; i++)
125 npregs->go.hostrw0 = *data++ << 24;
126 #endif /* CONFIG_LOGO_SGI_CLUT224 */
129 static inline void newport_clear_screen(int xstart, int ystart, int xend,
136 npregs->set.wrmask = 0xffffffff;
137 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
138 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
139 | NPORT_DMODE0_STOPY);
140 npregs->set.colori = ci;
141 npregs->set.xystarti = (xstart << 16) | ystart;
142 npregs->go.xyendi = (xend << 16) | yend;
145 static inline void newport_clear_lines(int ystart, int yend, int ci)
147 ystart = ((ystart << 4) + topscan) & 0x3ff;
148 yend = ((yend << 4) + topscan + 15) & 0x3ff;
149 newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
152 void newport_reset(void)
158 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
159 newport_vc2_set(npregs, VC2_IREG_CONTROL,
160 (treg | VC2_CTRL_EVIDEO));
162 treg = newport_vc2_get(npregs, VC2_IREG_CENTRY);
163 newport_vc2_set(npregs, VC2_IREG_RADDR, treg);
164 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
165 NPORT_DMODE_W2 | VC2_PROTOCOL);
166 for (i = 0; i < 128; i++) {
168 if (i == 92 || i == 94)
169 npregs->set.dcbdata0.byshort.s1 = 0xff00;
171 npregs->set.dcbdata0.byshort.s1 = 0x0000;
176 /* turn off popup plane */
177 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
178 XM9_CRS_CONFIG | NPORT_DMODE_W1);
179 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
180 npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL |
181 XM9_CRS_CONFIG | NPORT_DMODE_W1);
182 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
185 npregs->cset.topscan = 0x3ff;
186 npregs->cset.xywin = (4096 << 16) | 4096;
188 /* Clear the screen. */
189 newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
193 * calculate the actual screen size by reading
194 * the video timing out of the VC2
196 void newport_get_screensize(void)
199 unsigned short ventry, treg;
200 unsigned short linetable[128]; /* should be enough */
202 ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY);
203 newport_vc2_set(npregs, VC2_IREG_RADDR, ventry);
204 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
205 NPORT_DMODE_W2 | VC2_PROTOCOL);
206 for (i = 0; i < 128; i++) {
208 linetable[i] = npregs->set.dcbdata0.byshort.s1;
211 newport_xsize = newport_ysize = 0;
212 for (i = 0; linetable[i + 1] && (i < sizeof(linetable)); i += 2) {
214 newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]);
215 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
216 NPORT_DMODE_W2 | VC2_PROTOCOL);
219 treg = npregs->set.dcbdata0.byshort.s1;
221 cols += (treg >> 7) & 0xfe;
222 if ((treg & 0x80) == 0) {
224 treg = npregs->set.dcbdata0.byshort.s1;
226 } while ((treg & 0x8000) == 0);
228 if (cols > newport_xsize)
229 newport_xsize = cols;
230 newport_ysize += linetable[i + 1];
233 printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
236 static void newport_get_revisions(void)
239 unsigned int board_rev;
240 unsigned int rex3_rev;
241 unsigned int vc2_rev;
242 unsigned int cmap_rev;
243 unsigned int xmap9_rev;
244 unsigned int bt445_rev;
245 unsigned int bitplanes;
247 rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
249 npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
250 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
251 tmp = npregs->set.dcbdata0.bybytes.b3;
253 board_rev = (tmp >> 4) & 7;
254 bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
256 npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL |
257 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
258 tmp = npregs->set.dcbdata0.bybytes.b3;
259 if ((tmp & 7) < cmap_rev)
260 cmap_rev = (tmp & 7);
262 vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
264 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
265 XM9_CRS_REVISION | NPORT_DMODE_W1);
266 xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7;
268 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
269 BT445_CSR_ADDR_REG | NPORT_DMODE_W1);
270 npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG;
271 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
272 BT445_CSR_REVISION | NPORT_DMODE_W1);
273 bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a;
275 #define L(a) (char)('A'+(a))
277 ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n",
278 board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev),
279 L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev));
282 if (board_rev == 3) /* I don't know all affected revisions */
283 xcurs_correction = 21;
286 /* Can't be __init, take_over_console may call it later */
287 static const char *newport_startup(void)
293 npregs = (struct newport_regs *) (KSEG1 + sgi_gfxaddr);
294 npregs->cset.config = NPORT_CFG_GD0;
296 if (newport_wait()) {
300 npregs->set.xstarti = TESTVAL;
301 if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
304 for (i = 0; i < MAX_NR_CONSOLES; i++)
305 font_data[i] = FONT_DATA;
308 newport_get_revisions();
309 newport_get_screensize();
311 return "SGI Newport";
314 static void newport_init(struct vc_data *vc, int init)
316 vc->vc_cols = newport_xsize / 8;
317 vc->vc_rows = newport_ysize / 16;
318 vc->vc_can_do_color = 1;
321 static void newport_deinit(struct vc_data *c)
325 /* free memory used by user font */
326 for (i = 0; i < MAX_NR_CONSOLES; i++)
327 newport_set_def_font(i, NULL);
330 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
333 int xend = ((sx + width) << 3) - 1;
334 int ystart = ((sy << 4) + topscan) & 0x3ff;
335 int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
341 newport_clear_screen(sx << 3, ystart, xend, yend,
342 (vc->vc_color & 0xf0) >> 4);
344 newport_clear_screen(sx << 3, ystart, xend, 1023,
345 (vc->vc_color & 0xf0) >> 4);
346 newport_clear_screen(sx << 3, 0, xend, yend,
347 (vc->vc_color & 0xf0) >> 4);
351 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
356 p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
357 charattr = (charattr >> 8) & 0xff;
361 newport_render_background(xpos, ypos, xpos, ypos,
362 (charattr & 0xf0) >> 4);
364 /* Set the color and drawing mode. */
366 npregs->set.colori = charattr & 0xf;
367 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
368 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
371 /* Set coordinates for bitmap operation. */
372 npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
373 npregs->set.xyendi = ((xpos + 7) << 16);
376 /* Go, baby, go... */
380 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
381 int count, int ypos, int xpos)
387 charattr = (scr_readw(s) >> 8) & 0xff;
393 /* Clear the area behing the string */
394 newport_render_background(xpos, ypos,
395 xpos + ((count - 1) << 3), ypos,
396 (charattr & 0xf0) >> 4);
400 /* Set the color and drawing mode. */
401 npregs->set.colori = charattr & 0xf;
402 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
403 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
406 for (i = 0; i < count; i++, xpos += 8) {
407 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
411 /* Set coordinates for bitmap operation. */
412 npregs->set.xystarti =
413 (xpos << 16) | ((ypos + topscan) & 0x3ff);
414 npregs->set.xyendi = ((xpos + 7) << 16);
416 /* Go, baby, go... */
421 static void newport_cursor(struct vc_data *vc, int mode)
428 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
429 newport_vc2_set(npregs, VC2_IREG_CONTROL,
430 (treg & ~(VC2_CTRL_ECDISP)));
435 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
436 newport_vc2_set(npregs, VC2_IREG_CONTROL,
437 (treg | VC2_CTRL_ECDISP));
438 xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
439 ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
440 xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
441 newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
442 newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
446 static int newport_switch(struct vc_data *vc)
448 static int logo_drawn = 0;
451 npregs->cset.topscan = 0x3ff;
462 static int newport_blank(struct vc_data *c, int blank)
467 /* unblank console */
468 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
469 newport_vc2_set(npregs, VC2_IREG_CONTROL,
470 (treg | VC2_CTRL_EDISP));
473 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
474 newport_vc2_set(npregs, VC2_IREG_CONTROL,
475 (treg & ~(VC2_CTRL_EDISP)));
480 static int newport_set_font(int unit, struct console_font *op)
484 int size = h * op->charcount;
486 unsigned char *new_data, *data = op->data, *p;
488 /* ladis: when I grow up, there will be a day... and more sizes will
489 * be supported ;-) */
490 if ((w != 8) || (h != 16)
491 || (op->charcount != 256 && op->charcount != 512))
494 if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
495 GFP_USER))) return -ENOMEM;
497 new_data += FONT_EXTRA_WORDS * sizeof(int);
498 FNTSIZE(new_data) = size;
499 FNTCHARCNT(new_data) = op->charcount;
500 REFCOUNT(new_data) = 0; /* usage counter */
503 for (i = 0; i < op->charcount; i++) {
509 /* check if font is already used by other console */
510 for (i = 0; i < MAX_NR_CONSOLES; i++) {
511 if (font_data[i] != FONT_DATA
512 && FNTSIZE(font_data[i]) == size
513 && !memcmp(font_data[i], new_data, size)) {
514 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
515 /* current font is the same as the new one */
518 new_data = font_data[i];
522 /* old font is user font */
523 if (font_data[unit] != FONT_DATA) {
524 if (--REFCOUNT(font_data[unit]) == 0)
525 kfree(font_data[unit] -
526 FONT_EXTRA_WORDS * sizeof(int));
528 REFCOUNT(new_data)++;
529 font_data[unit] = new_data;
534 static int newport_set_def_font(int unit, struct console_font *op)
536 if (font_data[unit] != FONT_DATA) {
537 if (--REFCOUNT(font_data[unit]) == 0)
538 kfree(font_data[unit] -
539 FONT_EXTRA_WORDS * sizeof(int));
540 font_data[unit] = FONT_DATA;
546 static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
548 return newport_set_def_font(vc->vc_num, op);
551 static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
553 return newport_set_font(vc->vc_num, font);
556 static int newport_set_palette(struct vc_data *vc, unsigned char *table)
561 static int newport_scrolldelta(struct vc_data *vc, int lines)
563 /* there is (nearly) no off-screen memory, so we can't scroll back */
567 static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
571 unsigned short *s, *d;
572 unsigned short chattr;
574 logo_active = 0; /* it's time to disable the logo now.. */
576 if (t == 0 && b == vc->vc_rows) {
578 topscan = (topscan + (lines << 4)) & 0x3ff;
579 newport_clear_lines(vc->vc_rows - lines,
581 (vc->vc_color & 0xf0) >> 4);
583 topscan = (topscan + (-lines << 4)) & 0x3ff;
584 newport_clear_lines(0, lines - 1,
585 (vc->vc_color & 0xf0) >> 4);
587 npregs->cset.topscan = (topscan - 1) & 0x3ff;
591 count = (b - t - lines) * vc->vc_cols;
595 s = (unsigned short *) (vc->vc_origin +
596 vc->vc_size_row * (t + lines));
597 d = (unsigned short *) (vc->vc_origin +
598 vc->vc_size_row * t);
600 chattr = scr_readw(s++);
601 if (chattr != scr_readw(d)) {
602 newport_putc(vc, chattr, y, x);
603 scr_writew(chattr, d);
606 if (++x == vc->vc_cols) {
611 d = (unsigned short *) (vc->vc_origin +
612 vc->vc_size_row * (b - lines));
615 for (count = 0; count < (lines * vc->vc_cols); count++) {
616 if (scr_readw(d) != vc->vc_video_erase_char) {
617 newport_putc(vc, vc->vc_video_erase_char,
619 scr_writew(vc->vc_video_erase_char, d);
622 if (++x == vc->vc_cols) {
630 s = (unsigned short *) (vc->vc_origin +
631 vc->vc_size_row * (b - lines) - 2);
632 d = (unsigned short *) (vc->vc_origin +
633 vc->vc_size_row * b - 2);
635 chattr = scr_readw(s--);
636 if (chattr != scr_readw(d)) {
637 newport_putc(vc, chattr, y, x);
638 scr_writew(chattr, d);
646 d = (unsigned short *) (vc->vc_origin +
647 vc->vc_size_row * t);
650 for (count = 0; count < (lines * vc->vc_cols); count++) {
651 if (scr_readw(d) != vc->vc_video_erase_char) {
652 newport_putc(vc, vc->vc_video_erase_char,
654 scr_writew(vc->vc_video_erase_char, d);
657 if (++x == vc->vc_cols) {
666 static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
667 int dx, int h, int w)
669 short xs, ys, xe, ye, xoffs, yoffs, tmp;
672 xe = ((sx + w) << 3) - 1;
674 * as bmove is only used to move stuff around in the same line
675 * (h == 1), we don't care about wrap arounds caused by topscan != 0
677 ys = ((sy << 4) + topscan) & 0x3ff;
678 ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
679 xoffs = (dx - sx) << 3;
680 yoffs = (dy - sy) << 4;
682 /* move to the right, exchange starting points */
688 npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK |
689 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
690 | NPORT_DMODE0_STOPY);
691 npregs->set.xystarti = (xs << 16) | ys;
692 npregs->set.xyendi = (xe << 16) | ye;
693 npregs->go.xymove = (xoffs << 16) | yoffs;
696 static int newport_dummy(struct vc_data *c)
701 #define DUMMY (void *) newport_dummy
703 const struct consw newport_con = {
704 .owner = THIS_MODULE,
705 .con_startup = newport_startup,
706 .con_init = newport_init,
707 .con_deinit = newport_deinit,
708 .con_clear = newport_clear,
709 .con_putc = newport_putc,
710 .con_putcs = newport_putcs,
711 .con_cursor = newport_cursor,
712 .con_scroll = newport_scroll,
713 .con_bmove = newport_bmove,
714 .con_switch = newport_switch,
715 .con_blank = newport_blank,
716 .con_font_set = newport_font_set,
717 .con_font_default = newport_font_default,
718 .con_set_palette = newport_set_palette,
719 .con_scrolldelta = newport_scrolldelta,
720 .con_set_origin = DUMMY,
721 .con_save_screen = DUMMY
725 static int __init newport_console_init(void)
727 return take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
730 static void __exit newport_console_exit(void)
732 give_up_console(&newport_con);
735 module_init(newport_console_init);
736 module_exit(newport_console_exit);
739 MODULE_LICENSE("GPL");