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>
25 #include <asm/uaccess.h>
26 #include <asm/system.h>
28 #include <asm/pgtable.h>
29 #include <video/newport.h>
31 #include <linux/linux_logo.h>
32 #include <linux/font.h>
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;
54 static int newport_has_init;
56 static int newport_set_def_font(int unit, struct console_font *op);
58 #define BMASK(c) (c << 24)
60 #define RENDER(regs, cp) do { \
61 (regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \
62 (regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \
63 (regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \
64 (regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \
65 (regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \
66 (regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \
67 (regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \
68 (regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \
71 #define TESTVAL 0xdeadbeef
72 #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
74 static inline void newport_render_background(int xstart, int ystart,
75 int xend, int yend, int ci)
78 npregs->set.wrmask = 0xffffffff;
79 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
80 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
81 | NPORT_DMODE0_STOPY);
82 npregs->set.colori = ci;
83 npregs->set.xystarti =
84 (xstart << 16) | ((ystart + topscan) & 0x3ff);
86 ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
89 static inline void newport_init_cmap(void)
93 for (i = 0; i < 16; i++) {
94 newport_bfwait(npregs);
95 newport_cmap_setaddr(npregs, color_table[i]);
96 newport_cmap_setrgb(npregs,
98 default_grn[i], default_blu[i]);
102 static void newport_show_logo(void)
104 #ifdef CONFIG_LOGO_SGI_CLUT224
105 const struct linux_logo *logo = fb_find_logo(8);
106 const unsigned char *clut = logo->clut;
107 const unsigned char *data = logo->data;
110 for (i = 0; i < logo->clutsize; i++) {
111 newport_bfwait(npregs);
112 newport_cmap_setaddr(npregs, i + 0x20);
113 newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]);
117 newport_wait(npregs);
118 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
121 npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0);
122 npregs->set.xyendi = ((newport_xsize - 1) << 16);
123 newport_wait(npregs);
125 for (i = 0; i < logo->width*logo->height; i++)
126 npregs->go.hostrw0 = *data++ << 24;
127 #endif /* CONFIG_LOGO_SGI_CLUT224 */
130 static inline void newport_clear_screen(int xstart, int ystart, int xend,
136 newport_wait(npregs);
137 npregs->set.wrmask = 0xffffffff;
138 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
139 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
140 | NPORT_DMODE0_STOPY);
141 npregs->set.colori = ci;
142 npregs->set.xystarti = (xstart << 16) | ystart;
143 npregs->go.xyendi = (xend << 16) | yend;
146 static inline void newport_clear_lines(int ystart, int yend, int ci)
148 ystart = ((ystart << 4) + topscan) & 0x3ff;
149 yend = ((yend << 4) + topscan + 15) & 0x3ff;
150 newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
153 static void newport_reset(void)
158 newport_wait(npregs);
159 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
160 newport_vc2_set(npregs, VC2_IREG_CONTROL,
161 (treg | VC2_CTRL_EVIDEO));
163 treg = newport_vc2_get(npregs, VC2_IREG_CENTRY);
164 newport_vc2_set(npregs, VC2_IREG_RADDR, treg);
165 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
166 NPORT_DMODE_W2 | VC2_PROTOCOL);
167 for (i = 0; i < 128; i++) {
168 newport_bfwait(npregs);
169 if (i == 92 || i == 94)
170 npregs->set.dcbdata0.byshort.s1 = 0xff00;
172 npregs->set.dcbdata0.byshort.s1 = 0x0000;
177 /* turn off popup plane */
178 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
179 XM9_CRS_CONFIG | NPORT_DMODE_W1);
180 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
181 npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL |
182 XM9_CRS_CONFIG | NPORT_DMODE_W1);
183 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
186 npregs->cset.topscan = 0x3ff;
187 npregs->cset.xywin = (4096 << 16) | 4096;
189 /* Clear the screen. */
190 newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
194 * calculate the actual screen size by reading
195 * the video timing out of the VC2
197 static void newport_get_screensize(void)
200 unsigned short ventry, treg;
201 unsigned short linetable[128]; /* should be enough */
203 ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY);
204 newport_vc2_set(npregs, VC2_IREG_RADDR, ventry);
205 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
206 NPORT_DMODE_W2 | VC2_PROTOCOL);
207 for (i = 0; i < 128; i++) {
208 newport_bfwait(npregs);
209 linetable[i] = npregs->set.dcbdata0.byshort.s1;
212 newport_xsize = newport_ysize = 0;
213 for (i = 0; linetable[i + 1] && (i < sizeof(linetable)); i += 2) {
215 newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]);
216 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
217 NPORT_DMODE_W2 | VC2_PROTOCOL);
219 newport_bfwait(npregs);
220 treg = npregs->set.dcbdata0.byshort.s1;
222 cols += (treg >> 7) & 0xfe;
223 if ((treg & 0x80) == 0) {
224 newport_bfwait(npregs);
225 treg = npregs->set.dcbdata0.byshort.s1;
227 } while ((treg & 0x8000) == 0);
229 if (cols > newport_xsize)
230 newport_xsize = cols;
231 newport_ysize += linetable[i + 1];
234 printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
237 static void newport_get_revisions(void)
240 unsigned int board_rev;
241 unsigned int rex3_rev;
242 unsigned int vc2_rev;
243 unsigned int cmap_rev;
244 unsigned int xmap9_rev;
245 unsigned int bt445_rev;
246 unsigned int bitplanes;
248 rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
250 npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
251 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
252 tmp = npregs->set.dcbdata0.bybytes.b3;
254 board_rev = (tmp >> 4) & 7;
255 bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
257 npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL |
258 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
259 tmp = npregs->set.dcbdata0.bybytes.b3;
260 if ((tmp & 7) < cmap_rev)
261 cmap_rev = (tmp & 7);
263 vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
265 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
266 XM9_CRS_REVISION | NPORT_DMODE_W1);
267 xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7;
269 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
270 BT445_CSR_ADDR_REG | NPORT_DMODE_W1);
271 npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG;
272 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
273 BT445_CSR_REVISION | NPORT_DMODE_W1);
274 bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a;
276 #define L(a) (char)('A'+(a))
278 ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n",
279 board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev),
280 L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev));
283 if (board_rev == 3) /* I don't know all affected revisions */
284 xcurs_correction = 21;
287 static void newport_exit(void)
291 /* free memory used by user font */
292 for (i = 0; i < MAX_NR_CONSOLES; i++)
293 newport_set_def_font(i, NULL);
296 /* Can't be __init, take_over_console may call it later */
297 static const char *newport_startup(void)
305 npregs = (struct newport_regs *)/* ioremap cannot fail */
306 ioremap(sgi_gfxaddr, sizeof(struct newport_regs));
307 npregs->cset.config = NPORT_CFG_GD0;
309 if (newport_wait(npregs))
312 npregs->set.xstarti = TESTVAL;
313 if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
316 for (i = 0; i < MAX_NR_CONSOLES; i++)
317 font_data[i] = FONT_DATA;
320 newport_get_revisions();
321 newport_get_screensize();
322 newport_has_init = 1;
324 return "SGI Newport";
330 static void newport_init(struct vc_data *vc, int init)
332 vc->vc_cols = newport_xsize / 8;
333 vc->vc_rows = newport_ysize / 16;
334 vc->vc_can_do_color = 1;
337 static void newport_deinit(struct vc_data *c)
339 if (!con_is_bound(&newport_con) && newport_has_init) {
341 newport_has_init = 0;
345 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
348 int xend = ((sx + width) << 3) - 1;
349 int ystart = ((sy << 4) + topscan) & 0x3ff;
350 int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
356 newport_clear_screen(sx << 3, ystart, xend, yend,
357 (vc->vc_color & 0xf0) >> 4);
359 newport_clear_screen(sx << 3, ystart, xend, 1023,
360 (vc->vc_color & 0xf0) >> 4);
361 newport_clear_screen(sx << 3, 0, xend, yend,
362 (vc->vc_color & 0xf0) >> 4);
366 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
371 p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
372 charattr = (charattr >> 8) & 0xff;
376 newport_render_background(xpos, ypos, xpos, ypos,
377 (charattr & 0xf0) >> 4);
379 /* Set the color and drawing mode. */
380 newport_wait(npregs);
381 npregs->set.colori = charattr & 0xf;
382 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
383 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
386 /* Set coordinates for bitmap operation. */
387 npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
388 npregs->set.xyendi = ((xpos + 7) << 16);
389 newport_wait(npregs);
391 /* Go, baby, go... */
395 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
396 int count, int ypos, int xpos)
402 charattr = (scr_readw(s) >> 8) & 0xff;
408 /* Clear the area behing the string */
409 newport_render_background(xpos, ypos,
410 xpos + ((count - 1) << 3), ypos,
411 (charattr & 0xf0) >> 4);
413 newport_wait(npregs);
415 /* Set the color and drawing mode. */
416 npregs->set.colori = charattr & 0xf;
417 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
418 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
421 for (i = 0; i < count; i++, xpos += 8) {
422 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
424 newport_wait(npregs);
426 /* Set coordinates for bitmap operation. */
427 npregs->set.xystarti =
428 (xpos << 16) | ((ypos + topscan) & 0x3ff);
429 npregs->set.xyendi = ((xpos + 7) << 16);
431 /* Go, baby, go... */
436 static void newport_cursor(struct vc_data *vc, int mode)
443 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
444 newport_vc2_set(npregs, VC2_IREG_CONTROL,
445 (treg & ~(VC2_CTRL_ECDISP)));
450 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
451 newport_vc2_set(npregs, VC2_IREG_CONTROL,
452 (treg | VC2_CTRL_ECDISP));
453 xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
454 ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
455 xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
456 newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
457 newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
461 static int newport_switch(struct vc_data *vc)
463 static int logo_drawn = 0;
466 npregs->cset.topscan = 0x3ff;
477 static int newport_blank(struct vc_data *c, int blank, int mode_switch)
482 /* unblank console */
483 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
484 newport_vc2_set(npregs, VC2_IREG_CONTROL,
485 (treg | VC2_CTRL_EDISP));
488 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
489 newport_vc2_set(npregs, VC2_IREG_CONTROL,
490 (treg & ~(VC2_CTRL_EDISP)));
495 static int newport_set_font(int unit, struct console_font *op)
499 int size = h * op->charcount;
501 unsigned char *new_data, *data = op->data, *p;
503 /* ladis: when I grow up, there will be a day... and more sizes will
504 * be supported ;-) */
505 if ((w != 8) || (h != 16)
506 || (op->charcount != 256 && op->charcount != 512))
509 if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
510 GFP_USER))) return -ENOMEM;
512 new_data += FONT_EXTRA_WORDS * sizeof(int);
513 FNTSIZE(new_data) = size;
514 FNTCHARCNT(new_data) = op->charcount;
515 REFCOUNT(new_data) = 0; /* usage counter */
518 for (i = 0; i < op->charcount; i++) {
524 /* check if font is already used by other console */
525 for (i = 0; i < MAX_NR_CONSOLES; i++) {
526 if (font_data[i] != FONT_DATA
527 && FNTSIZE(font_data[i]) == size
528 && !memcmp(font_data[i], new_data, size)) {
529 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
530 /* current font is the same as the new one */
533 new_data = font_data[i];
537 /* old font is user font */
538 if (font_data[unit] != FONT_DATA) {
539 if (--REFCOUNT(font_data[unit]) == 0)
540 kfree(font_data[unit] -
541 FONT_EXTRA_WORDS * sizeof(int));
543 REFCOUNT(new_data)++;
544 font_data[unit] = new_data;
549 static int newport_set_def_font(int unit, struct console_font *op)
551 if (font_data[unit] != FONT_DATA) {
552 if (--REFCOUNT(font_data[unit]) == 0)
553 kfree(font_data[unit] -
554 FONT_EXTRA_WORDS * sizeof(int));
555 font_data[unit] = FONT_DATA;
561 static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
563 return newport_set_def_font(vc->vc_num, op);
566 static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
568 return newport_set_font(vc->vc_num, font);
571 static int newport_set_palette(struct vc_data *vc, unsigned char *table)
576 static int newport_scrolldelta(struct vc_data *vc, int lines)
578 /* there is (nearly) no off-screen memory, so we can't scroll back */
582 static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
586 unsigned short *s, *d;
587 unsigned short chattr;
589 logo_active = 0; /* it's time to disable the logo now.. */
591 if (t == 0 && b == vc->vc_rows) {
593 topscan = (topscan + (lines << 4)) & 0x3ff;
594 newport_clear_lines(vc->vc_rows - lines,
596 (vc->vc_color & 0xf0) >> 4);
598 topscan = (topscan + (-lines << 4)) & 0x3ff;
599 newport_clear_lines(0, lines - 1,
600 (vc->vc_color & 0xf0) >> 4);
602 npregs->cset.topscan = (topscan - 1) & 0x3ff;
606 count = (b - t - lines) * vc->vc_cols;
610 s = (unsigned short *) (vc->vc_origin +
611 vc->vc_size_row * (t + lines));
612 d = (unsigned short *) (vc->vc_origin +
613 vc->vc_size_row * t);
615 chattr = scr_readw(s++);
616 if (chattr != scr_readw(d)) {
617 newport_putc(vc, chattr, y, x);
618 scr_writew(chattr, d);
621 if (++x == vc->vc_cols) {
626 d = (unsigned short *) (vc->vc_origin +
627 vc->vc_size_row * (b - lines));
630 for (count = 0; count < (lines * vc->vc_cols); count++) {
631 if (scr_readw(d) != vc->vc_video_erase_char) {
632 newport_putc(vc, vc->vc_video_erase_char,
634 scr_writew(vc->vc_video_erase_char, d);
637 if (++x == vc->vc_cols) {
645 s = (unsigned short *) (vc->vc_origin +
646 vc->vc_size_row * (b - lines) - 2);
647 d = (unsigned short *) (vc->vc_origin +
648 vc->vc_size_row * b - 2);
650 chattr = scr_readw(s--);
651 if (chattr != scr_readw(d)) {
652 newport_putc(vc, chattr, y, x);
653 scr_writew(chattr, d);
661 d = (unsigned short *) (vc->vc_origin +
662 vc->vc_size_row * t);
665 for (count = 0; count < (lines * vc->vc_cols); count++) {
666 if (scr_readw(d) != vc->vc_video_erase_char) {
667 newport_putc(vc, vc->vc_video_erase_char,
669 scr_writew(vc->vc_video_erase_char, d);
672 if (++x == vc->vc_cols) {
681 static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
682 int dx, int h, int w)
684 short xs, ys, xe, ye, xoffs, yoffs, tmp;
687 xe = ((sx + w) << 3) - 1;
689 * as bmove is only used to move stuff around in the same line
690 * (h == 1), we don't care about wrap arounds caused by topscan != 0
692 ys = ((sy << 4) + topscan) & 0x3ff;
693 ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
694 xoffs = (dx - sx) << 3;
695 yoffs = (dy - sy) << 4;
697 /* move to the right, exchange starting points */
702 newport_wait(npregs);
703 npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK |
704 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
705 | NPORT_DMODE0_STOPY);
706 npregs->set.xystarti = (xs << 16) | ys;
707 npregs->set.xyendi = (xe << 16) | ye;
708 npregs->go.xymove = (xoffs << 16) | yoffs;
711 static int newport_dummy(struct vc_data *c)
716 #define DUMMY (void *) newport_dummy
718 const struct consw newport_con = {
719 .owner = THIS_MODULE,
720 .con_startup = newport_startup,
721 .con_init = newport_init,
722 .con_deinit = newport_deinit,
723 .con_clear = newport_clear,
724 .con_putc = newport_putc,
725 .con_putcs = newport_putcs,
726 .con_cursor = newport_cursor,
727 .con_scroll = newport_scroll,
728 .con_bmove = newport_bmove,
729 .con_switch = newport_switch,
730 .con_blank = newport_blank,
731 .con_font_set = newport_font_set,
732 .con_font_default = newport_font_default,
733 .con_set_palette = newport_set_palette,
734 .con_scrolldelta = newport_scrolldelta,
735 .con_set_origin = DUMMY,
736 .con_save_screen = DUMMY
740 static int __init newport_console_init(void)
747 npregs = (struct newport_regs *)/* ioremap cannot fail */
748 ioremap(sgi_gfxaddr, sizeof(struct newport_regs));
750 return take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
752 module_init(newport_console_init);
754 static void __exit newport_console_exit(void)
756 give_up_console(&newport_con);
757 iounmap((void *)npregs);
759 module_exit(newport_console_exit);
762 MODULE_LICENSE("GPL");