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;
36 #define FONT_DATA ((unsigned char *)font_vga_8x16.data)
38 /* borrowed from fbcon.c */
39 #define REFCOUNT(fd) (((int *)(fd))[-1])
40 #define FNTSIZE(fd) (((int *)(fd))[-2])
41 #define FNTCHARCNT(fd) (((int *)(fd))[-3])
42 #define FONT_EXTRA_WORDS 3
44 static unsigned char *font_data[MAX_NR_CONSOLES];
46 extern struct newport_regs *npregs;
48 static int logo_active;
50 static int xcurs_correction = 29;
51 static int newport_xsize;
52 static int newport_ysize;
54 #define BMASK(c) (c << 24)
56 #define RENDER(regs, cp) do { \
57 (regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \
58 (regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \
59 (regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \
60 (regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \
61 (regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \
62 (regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \
63 (regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \
64 (regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \
67 #define TESTVAL 0xdeadbeef
68 #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
70 static inline void newport_render_background(int xstart, int ystart,
71 int xend, int yend, int ci)
74 npregs->set.wrmask = 0xffffffff;
75 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
76 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
77 | NPORT_DMODE0_STOPY);
78 npregs->set.colori = ci;
79 npregs->set.xystarti =
80 (xstart << 16) | ((ystart + topscan) & 0x3ff);
82 ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
85 static inline void newport_init_cmap(void)
89 for (i = 0; i < 16; i++) {
91 newport_cmap_setaddr(npregs, color_table[i]);
92 newport_cmap_setrgb(npregs,
94 default_grn[i], default_blu[i]);
98 #ifdef CONFIG_LOGO_SGI_CLUT224
99 static void newport_show_logo(void);
101 #define newport_show_logo() do { } while (0)
104 static inline void newport_clear_screen(int xstart, int ystart, int xend,
111 npregs->set.wrmask = 0xffffffff;
112 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
113 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
114 | NPORT_DMODE0_STOPY);
115 npregs->set.colori = ci;
116 npregs->set.xystarti = (xstart << 16) | ystart;
117 npregs->go.xyendi = (xend << 16) | yend;
120 static inline void newport_clear_lines(int ystart, int yend, int ci)
122 ystart = ((ystart << 4) + topscan) & 0x3ff;
123 yend = ((yend << 4) + topscan + 15) & 0x3ff;
124 newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
127 void newport_reset(void)
133 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
134 newport_vc2_set(npregs, VC2_IREG_CONTROL,
135 (treg | VC2_CTRL_EVIDEO));
137 treg = newport_vc2_get(npregs, VC2_IREG_CENTRY);
138 newport_vc2_set(npregs, VC2_IREG_RADDR, treg);
139 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
140 NPORT_DMODE_W2 | VC2_PROTOCOL);
141 for (i = 0; i < 128; i++) {
143 if (i == 92 || i == 94)
144 npregs->set.dcbdata0.byshort.s1 = 0xff00;
146 npregs->set.dcbdata0.byshort.s1 = 0x0000;
151 /* turn off popup plane */
152 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
153 XM9_CRS_CONFIG | NPORT_DMODE_W1);
154 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
155 npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL |
156 XM9_CRS_CONFIG | NPORT_DMODE_W1);
157 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
160 npregs->cset.topscan = 0x3ff;
161 npregs->cset.xywin = (4096 << 16) | 4096;
163 /* Clear the screen. */
164 newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
168 * calculate the actual screen size by reading
169 * the video timing out of the VC2
171 void newport_get_screensize(void)
174 unsigned short ventry, treg;
175 unsigned short linetable[128]; /* should be enough */
177 ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY);
178 newport_vc2_set(npregs, VC2_IREG_RADDR, ventry);
179 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
180 NPORT_DMODE_W2 | VC2_PROTOCOL);
181 for (i = 0; i < 128; i++) {
183 linetable[i] = npregs->set.dcbdata0.byshort.s1;
186 newport_xsize = newport_ysize = 0;
187 for (i = 0; linetable[i + 1] && (i < sizeof(linetable)); i += 2) {
189 newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]);
190 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
191 NPORT_DMODE_W2 | VC2_PROTOCOL);
194 treg = npregs->set.dcbdata0.byshort.s1;
196 cols += (treg >> 7) & 0xfe;
197 if ((treg & 0x80) == 0) {
199 treg = npregs->set.dcbdata0.byshort.s1;
201 } while ((treg & 0x8000) == 0);
203 if (cols > newport_xsize)
204 newport_xsize = cols;
205 newport_ysize += linetable[i + 1];
208 printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
211 static void newport_get_revisions(void)
214 unsigned int board_rev;
215 unsigned int rex3_rev;
216 unsigned int vc2_rev;
217 unsigned int cmap_rev;
218 unsigned int xmap9_rev;
219 unsigned int bt445_rev;
220 unsigned int bitplanes;
222 rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
224 npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
225 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
226 tmp = npregs->set.dcbdata0.bybytes.b3;
228 board_rev = (tmp >> 4) & 7;
229 bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
231 npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL |
232 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
233 tmp = npregs->set.dcbdata0.bybytes.b3;
234 if ((tmp & 7) < cmap_rev)
235 cmap_rev = (tmp & 7);
237 vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
239 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
240 XM9_CRS_REVISION | NPORT_DMODE_W1);
241 xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7;
243 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
244 BT445_CSR_ADDR_REG | NPORT_DMODE_W1);
245 npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG;
246 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
247 BT445_CSR_REVISION | NPORT_DMODE_W1);
248 bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a;
250 #define L(a) (char)('A'+(a))
252 ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n",
253 board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev),
254 L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev));
257 if (board_rev == 3) /* I don't know all affected revisions */
258 xcurs_correction = 21;
262 static const char *newport_startup(void)
264 static const char *__init newport_startup(void)
268 struct newport_regs *p;
270 npregs = (struct newport_regs *) (KSEG1 + 0x1f0f0000);
273 p->cset.config = NPORT_CFG_GD0;
275 if (newport_wait()) {
279 p->set.xstarti = TESTVAL;
280 if (p->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
283 for (i = 0; i < MAX_NR_CONSOLES; i++)
284 font_data[i] = FONT_DATA;
287 newport_get_revisions();
288 newport_get_screensize();
290 /* gfx_init (display_desc); */
292 return "SGI Newport";
295 static void newport_init(struct vc_data *vc, int init)
297 vc->vc_cols = newport_xsize / 8;
298 vc->vc_rows = newport_ysize / 16;
299 vc->vc_can_do_color = 1;
302 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
305 int xend = ((sx + width) << 3) - 1;
306 int ystart = ((sy << 4) + topscan) & 0x3ff;
307 int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
313 newport_clear_screen(sx << 3, ystart, xend, yend,
314 (vc->vc_color & 0xf0) >> 4);
316 newport_clear_screen(sx << 3, ystart, xend, 1023,
317 (vc->vc_color & 0xf0) >> 4);
318 newport_clear_screen(sx << 3, 0, xend, yend,
319 (vc->vc_color & 0xf0) >> 4);
323 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
328 p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
329 charattr = (charattr >> 8) & 0xff;
333 newport_render_background(xpos, ypos, xpos, ypos,
334 (charattr & 0xf0) >> 4);
336 /* Set the color and drawing mode. */
338 npregs->set.colori = charattr & 0xf;
339 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
340 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
343 /* Set coordinates for bitmap operation. */
344 npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
345 npregs->set.xyendi = ((xpos + 7) << 16);
348 /* Go, baby, go... */
352 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
353 int count, int ypos, int xpos)
359 charattr = (scr_readw(s) >> 8) & 0xff;
365 /* Clear the area behing the string */
366 newport_render_background(xpos, ypos,
367 xpos + ((count - 1) << 3), ypos,
368 (charattr & 0xf0) >> 4);
372 /* Set the color and drawing mode. */
373 npregs->set.colori = charattr & 0xf;
374 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
375 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
378 for (i = 0; i < count; i++, xpos += 8) {
379 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
383 /* Set coordinates for bitmap operation. */
384 npregs->set.xystarti =
385 (xpos << 16) | ((ypos + topscan) & 0x3ff);
386 npregs->set.xyendi = ((xpos + 7) << 16);
388 /* Go, baby, go... */
393 static void newport_cursor(struct vc_data *vc, int mode)
400 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
401 newport_vc2_set(npregs, VC2_IREG_CONTROL,
402 (treg & ~(VC2_CTRL_ECDISP)));
407 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
408 newport_vc2_set(npregs, VC2_IREG_CONTROL,
409 (treg | VC2_CTRL_ECDISP));
410 xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
411 ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
412 xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
413 newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
414 newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
418 static int newport_switch(struct vc_data *vc)
420 static int logo_drawn = 0;
423 npregs->cset.topscan = 0x3ff;
434 static int newport_blank(struct vc_data *c, int blank)
439 /* unblank console */
440 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
441 newport_vc2_set(npregs, VC2_IREG_CONTROL,
442 (treg | VC2_CTRL_EDISP));
445 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
446 newport_vc2_set(npregs, VC2_IREG_CONTROL,
447 (treg & ~(VC2_CTRL_EDISP)));
452 static int newport_set_font(int unit, struct console_font_op *op)
456 int size = h * op->charcount;
458 unsigned char *new_data, *data = op->data, *p;
460 /* ladis: when I grow up, there will be a day... and more sizes will
461 * be supported ;-) */
462 if ((w != 8) || (h != 16)
463 || (op->charcount != 256 && op->charcount != 512))
466 if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
467 GFP_USER))) return -ENOMEM;
469 new_data += FONT_EXTRA_WORDS * sizeof(int);
470 FNTSIZE(new_data) = size;
471 FNTCHARCNT(new_data) = op->charcount;
472 REFCOUNT(new_data) = 0; /* usage counter */
475 for (i = 0; i < op->charcount; i++) {
481 /* check if font is already used by other console */
482 for (i = 0; i < MAX_NR_CONSOLES; i++) {
483 if (font_data[i] != FONT_DATA
484 && FNTSIZE(font_data[i]) == size
485 && !memcmp(font_data[i], new_data, size)) {
486 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
487 /* current font is the same as the new one */
490 new_data = font_data[i];
494 /* old font is user font */
495 if (font_data[unit] != FONT_DATA) {
496 if (--REFCOUNT(font_data[unit]) == 0)
497 kfree(font_data[unit] -
498 FONT_EXTRA_WORDS * sizeof(int));
500 REFCOUNT(new_data)++;
501 font_data[unit] = new_data;
506 static int newport_set_def_font(int unit, struct console_font_op *op)
508 if (font_data[unit] != FONT_DATA) {
509 if (--REFCOUNT(font_data[unit]) == 0)
510 kfree(font_data[unit] -
511 FONT_EXTRA_WORDS * sizeof(int));
512 font_data[unit] = FONT_DATA;
518 static int newport_font_op(struct vc_data *vc, struct console_font_op *op)
520 int unit = vc->vc_num;
524 return newport_set_font(unit, op);
525 case KD_FONT_OP_SET_DEFAULT:
526 return newport_set_def_font(unit, op);
532 static int newport_set_palette(struct vc_data *vc, unsigned char *table)
537 static int newport_scrolldelta(struct vc_data *vc, int lines)
539 /* there is (nearly) no off-screen memory, so we can't scroll back */
543 static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
547 unsigned short *s, *d;
548 unsigned short chattr;
550 logo_active = 0; /* it's time to disable the logo now.. */
552 if (t == 0 && b == vc->vc_rows) {
554 topscan = (topscan + (lines << 4)) & 0x3ff;
555 newport_clear_lines(vc->vc_rows - lines,
557 (vc->vc_color & 0xf0) >> 4);
559 topscan = (topscan + (-lines << 4)) & 0x3ff;
560 newport_clear_lines(0, lines - 1,
561 (vc->vc_color & 0xf0) >> 4);
563 npregs->cset.topscan = (topscan - 1) & 0x3ff;
567 count = (b - t - lines) * vc->vc_cols;
571 s = (unsigned short *) (vc->vc_origin +
572 vc->vc_size_row * (t + lines));
573 d = (unsigned short *) (vc->vc_origin +
574 vc->vc_size_row * t);
576 chattr = scr_readw(s++);
577 if (chattr != scr_readw(d)) {
578 newport_putc(vc, chattr, y, x);
579 scr_writew(chattr, d);
582 if (++x == vc->vc_cols) {
587 d = (unsigned short *) (vc->vc_origin +
588 vc->vc_size_row * (b - lines));
591 for (count = 0; count < (lines * vc->vc_cols); count++) {
592 if (scr_readw(d) != vc->vc_video_erase_char) {
593 newport_putc(vc, vc->vc_video_erase_char,
595 scr_writew(vc->vc_video_erase_char, d);
598 if (++x == vc->vc_cols) {
606 s = (unsigned short *) (vc->vc_origin +
607 vc->vc_size_row * (b - lines) - 2);
608 d = (unsigned short *) (vc->vc_origin +
609 vc->vc_size_row * b - 2);
611 chattr = scr_readw(s--);
612 if (chattr != scr_readw(d)) {
613 newport_putc(vc, chattr, y, x);
614 scr_writew(chattr, d);
622 d = (unsigned short *) (vc->vc_origin +
623 vc->vc_size_row * t);
626 for (count = 0; count < (lines * vc->vc_cols); count++) {
627 if (scr_readw(d) != vc->vc_video_erase_char) {
628 newport_putc(vc, vc->vc_video_erase_char,
630 scr_writew(vc->vc_video_erase_char, d);
633 if (++x == vc->vc_cols) {
642 static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
643 int dx, int h, int w)
645 short xs, ys, xe, ye, xoffs, yoffs, tmp;
648 xe = ((sx + w) << 3) - 1;
650 * as bmove is only used to move stuff around in the same line
651 * (h == 1), we don't care about wrap arounds caused by topscan != 0
653 ys = ((sy << 4) + topscan) & 0x3ff;
654 ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
655 xoffs = (dx - sx) << 3;
656 yoffs = (dy - sy) << 4;
658 /* move to the right, exchange starting points */
664 npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK |
665 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
666 | NPORT_DMODE0_STOPY);
667 npregs->set.xystarti = (xs << 16) | ys;
668 npregs->set.xyendi = (xe << 16) | ye;
669 npregs->go.xymove = (xoffs << 16) | yoffs;
672 static int newport_dummy(struct vc_data *c)
677 #define DUMMY (void *) newport_dummy
679 const struct consw newport_con = {
680 .con_startup = newport_startup,
681 .con_init = newport_init,
683 .con_clear = newport_clear,
684 .con_putc = newport_putc,
685 .con_putcs = newport_putcs,
686 .con_cursor = newport_cursor,
687 .con_scroll = newport_scroll,
688 .con_bmove = newport_bmove,
689 .con_switch = newport_switch,
690 .con_blank = newport_blank,
691 .con_font_op = newport_font_op,
692 .con_set_palette = newport_set_palette,
693 .con_scrolldelta = newport_scrolldelta,
694 .con_set_origin = DUMMY,
695 .con_save_screen = DUMMY
699 MODULE_LICENSE("GPL");
701 int init_module(void)
703 if (!newport_startup())
704 printk("Error loading SGI Newport Console driver\n");
706 printk("Loading SGI Newport Console Driver\n");
707 take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
712 int cleanup_module(void)
716 printk("Unloading SGI Newport Console Driver\n");
717 /* free memory used by user font */
718 for (i = 0; i < MAX_NR_CONSOLES; i++)
719 newport_set_def_font(i, NULL);
726 #ifdef CONFIG_LOGO_SGI_CLUT224
730 #include "../logo/logo_sgi_clut224.c"
732 static void newport_show_logo(void)
734 const struct linux_logo *logo = &logo_sgi_clut224;
735 const unsigned char *clut = logo->clut;
736 const unsigned char *data = logo->data;
739 for (i = 0; i < logo->clutsize; i++) {
741 newport_cmap_setaddr(npregs, i + 0x20);
742 newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]);
747 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
750 npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0);
751 npregs->set.xyendi = ((newport_xsize - 1) << 16);
754 for (i = 0; i < logo->width*logo->height; i++)
755 npregs->go.hostrw0 = *data++ << 24;
757 #endif /* CONFIG_LOGO_SGI_CLUT224 */