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>
16 #include <linux/selection.h>
17 #include <linux/console.h>
18 #include <linux/vt_kern.h>
20 #include <linux/module.h>
21 #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 unsigned long sgi_gfxaddr;
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 static 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;
53 static int newport_has_init;
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++) {
93 newport_bfwait(npregs);
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++) {
110 newport_bfwait(npregs);
111 newport_cmap_setaddr(npregs, i + 0x20);
112 newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]);
116 newport_wait(npregs);
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);
122 newport_wait(npregs);
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,
135 newport_wait(npregs);
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 static void newport_reset(void)
157 newport_wait(npregs);
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++) {
167 newport_bfwait(npregs);
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 static 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++) {
207 newport_bfwait(npregs);
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);
218 newport_bfwait(npregs);
219 treg = npregs->set.dcbdata0.byshort.s1;
221 cols += (treg >> 7) & 0xfe;
222 if ((treg & 0x80) == 0) {
223 newport_bfwait(npregs);
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 static void newport_exit(void)
290 /* free memory used by user font */
291 for (i = 0; i < MAX_NR_CONSOLES; i++)
292 newport_set_def_font(i, NULL);
295 /* Can't be __init, take_over_console may call it later */
296 static const char *newport_startup(void)
304 npregs = (struct newport_regs *)/* ioremap cannot fail */
305 ioremap(sgi_gfxaddr, sizeof(struct newport_regs));
306 npregs->cset.config = NPORT_CFG_GD0;
308 if (newport_wait(npregs))
311 npregs->set.xstarti = TESTVAL;
312 if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
315 for (i = 0; i < MAX_NR_CONSOLES; i++)
316 font_data[i] = FONT_DATA;
319 newport_get_revisions();
320 newport_get_screensize();
321 newport_has_init = 1;
323 return "SGI Newport";
329 static void newport_init(struct vc_data *vc, int init)
331 vc->vc_cols = newport_xsize / 8;
332 vc->vc_rows = newport_ysize / 16;
333 vc->vc_can_do_color = 1;
336 static void newport_deinit(struct vc_data *c)
338 if (!con_is_bound(&newport_con) && newport_has_init) {
340 newport_has_init = 0;
344 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
347 int xend = ((sx + width) << 3) - 1;
348 int ystart = ((sy << 4) + topscan) & 0x3ff;
349 int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
355 newport_clear_screen(sx << 3, ystart, xend, yend,
356 (vc->vc_color & 0xf0) >> 4);
358 newport_clear_screen(sx << 3, ystart, xend, 1023,
359 (vc->vc_color & 0xf0) >> 4);
360 newport_clear_screen(sx << 3, 0, xend, yend,
361 (vc->vc_color & 0xf0) >> 4);
365 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
370 p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
371 charattr = (charattr >> 8) & 0xff;
375 newport_render_background(xpos, ypos, xpos, ypos,
376 (charattr & 0xf0) >> 4);
378 /* Set the color and drawing mode. */
379 newport_wait(npregs);
380 npregs->set.colori = charattr & 0xf;
381 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
382 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
385 /* Set coordinates for bitmap operation. */
386 npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
387 npregs->set.xyendi = ((xpos + 7) << 16);
388 newport_wait(npregs);
390 /* Go, baby, go... */
394 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
395 int count, int ypos, int xpos)
401 charattr = (scr_readw(s) >> 8) & 0xff;
407 /* Clear the area behing the string */
408 newport_render_background(xpos, ypos,
409 xpos + ((count - 1) << 3), ypos,
410 (charattr & 0xf0) >> 4);
412 newport_wait(npregs);
414 /* Set the color and drawing mode. */
415 npregs->set.colori = charattr & 0xf;
416 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
417 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
420 for (i = 0; i < count; i++, xpos += 8) {
421 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
423 newport_wait(npregs);
425 /* Set coordinates for bitmap operation. */
426 npregs->set.xystarti =
427 (xpos << 16) | ((ypos + topscan) & 0x3ff);
428 npregs->set.xyendi = ((xpos + 7) << 16);
430 /* Go, baby, go... */
435 static void newport_cursor(struct vc_data *vc, int mode)
442 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
443 newport_vc2_set(npregs, VC2_IREG_CONTROL,
444 (treg & ~(VC2_CTRL_ECDISP)));
449 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
450 newport_vc2_set(npregs, VC2_IREG_CONTROL,
451 (treg | VC2_CTRL_ECDISP));
452 xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
453 ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
454 xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
455 newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
456 newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
460 static int newport_switch(struct vc_data *vc)
462 static int logo_drawn = 0;
465 npregs->cset.topscan = 0x3ff;
476 static int newport_blank(struct vc_data *c, int blank, int mode_switch)
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));
487 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
488 newport_vc2_set(npregs, VC2_IREG_CONTROL,
489 (treg & ~(VC2_CTRL_EDISP)));
494 static int newport_set_font(int unit, struct console_font *op)
498 int size = h * op->charcount;
500 unsigned char *new_data, *data = op->data, *p;
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))
508 if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
509 GFP_USER))) return -ENOMEM;
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 */
517 for (i = 0; i < op->charcount; i++) {
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 */
532 new_data = font_data[i];
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));
542 REFCOUNT(new_data)++;
543 font_data[unit] = new_data;
548 static int newport_set_def_font(int unit, struct console_font *op)
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;
560 static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
562 return newport_set_def_font(vc->vc_num, op);
565 static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
567 return newport_set_font(vc->vc_num, font);
570 static int newport_set_palette(struct vc_data *vc, unsigned char *table)
575 static int newport_scrolldelta(struct vc_data *vc, int lines)
577 /* there is (nearly) no off-screen memory, so we can't scroll back */
581 static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
585 unsigned short *s, *d;
586 unsigned short chattr;
588 logo_active = 0; /* it's time to disable the logo now.. */
590 if (t == 0 && b == vc->vc_rows) {
592 topscan = (topscan + (lines << 4)) & 0x3ff;
593 newport_clear_lines(vc->vc_rows - lines,
595 (vc->vc_color & 0xf0) >> 4);
597 topscan = (topscan + (-lines << 4)) & 0x3ff;
598 newport_clear_lines(0, lines - 1,
599 (vc->vc_color & 0xf0) >> 4);
601 npregs->cset.topscan = (topscan - 1) & 0x3ff;
605 count = (b - t - lines) * vc->vc_cols;
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);
614 chattr = scr_readw(s++);
615 if (chattr != scr_readw(d)) {
616 newport_putc(vc, chattr, y, x);
617 scr_writew(chattr, d);
620 if (++x == vc->vc_cols) {
625 d = (unsigned short *) (vc->vc_origin +
626 vc->vc_size_row * (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,
633 scr_writew(vc->vc_video_erase_char, d);
636 if (++x == vc->vc_cols) {
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);
649 chattr = scr_readw(s--);
650 if (chattr != scr_readw(d)) {
651 newport_putc(vc, chattr, y, x);
652 scr_writew(chattr, d);
660 d = (unsigned short *) (vc->vc_origin +
661 vc->vc_size_row * 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,
668 scr_writew(vc->vc_video_erase_char, d);
671 if (++x == vc->vc_cols) {
680 static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
681 int dx, int h, int w)
683 short xs, ys, xe, ye, xoffs, yoffs, tmp;
686 xe = ((sx + w) << 3) - 1;
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
691 ys = ((sy << 4) + topscan) & 0x3ff;
692 ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
693 xoffs = (dx - sx) << 3;
694 yoffs = (dy - sy) << 4;
696 /* move to the right, exchange starting points */
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;
710 static int newport_dummy(struct vc_data *c)
715 #define DUMMY (void *) newport_dummy
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
739 static int __init newport_console_init(void)
746 npregs = (struct newport_regs *)/* ioremap cannot fail */
747 ioremap(sgi_gfxaddr, sizeof(struct newport_regs));
749 return take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
751 module_init(newport_console_init);
753 static void __exit newport_console_exit(void)
755 give_up_console(&newport_con);
756 iounmap((void *)npregs);
758 module_exit(newport_console_exit);
761 MODULE_LICENSE("GPL");