2 * newport_con.c: Abscon for newport hardware
7 * This driver is based on sgicons.c and cons_newport.
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>
26 #include <asm/pgtable.h>
27 #include <asm/gio_device.h>
29 #include <video/newport.h>
31 #include <linux/linux_logo.h>
32 #include <linux/font.h>
34 #define FONT_DATA ((unsigned char *)font_vga_8x16.data)
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
42 static unsigned char *font_data[MAX_NR_CONSOLES];
44 static struct newport_regs *npregs;
46 static int logo_active;
48 static int xcurs_correction = 29;
49 static int newport_xsize;
50 static int newport_ysize;
51 static int newport_has_init;
53 static int newport_set_def_font(int unit, struct console_font *op);
55 #define BMASK(c) (c << 24)
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]); \
68 #define TESTVAL 0xdeadbeef
69 #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
71 static inline void newport_render_background(int xstart, int ystart,
72 int xend, int yend, int ci)
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);
83 ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
86 static inline void newport_init_cmap(void)
90 for (i = 0; i < 16; i++) {
91 newport_bfwait(npregs);
92 newport_cmap_setaddr(npregs, color_table[i]);
93 newport_cmap_setrgb(npregs,
95 default_grn[i], default_blu[i]);
99 static const struct linux_logo *newport_show_logo(void)
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;
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]);
119 newport_wait(npregs);
120 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
123 npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0);
124 npregs->set.xyendi = ((newport_xsize - 1) << 16);
125 newport_wait(npregs);
127 for (i = 0; i < logo->width*logo->height; i++)
128 npregs->go.hostrw0 = *data++ << 24;
131 #endif /* CONFIG_LOGO_SGI_CLUT224 */
134 static inline void newport_clear_screen(int xstart, int ystart, int xend,
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;
150 static inline void newport_clear_lines(int ystart, int yend, int ci)
152 ystart = ((ystart << 4) + topscan) & 0x3ff;
153 yend = ((yend << 4) + topscan + 15) & 0x3ff;
154 newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
157 static void newport_reset(void)
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));
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;
176 npregs->set.dcbdata0.byshort.s1 = 0x0000;
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;
190 npregs->cset.topscan = 0x3ff;
191 npregs->cset.xywin = (4096 << 16) | 4096;
193 /* Clear the screen. */
194 newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
198 * calculate the actual screen size by reading
199 * the video timing out of the VC2
201 static void newport_get_screensize(void)
204 unsigned short ventry, treg;
205 unsigned short linetable[128]; /* should be enough */
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;
216 newport_xsize = newport_ysize = 0;
217 for (i = 0; i < ARRAY_SIZE(linetable) - 1 && linetable[i + 1]; i += 2) {
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);
223 newport_bfwait(npregs);
224 treg = npregs->set.dcbdata0.byshort.s1;
226 cols += (treg >> 7) & 0xfe;
227 if ((treg & 0x80) == 0) {
228 newport_bfwait(npregs);
229 treg = npregs->set.dcbdata0.byshort.s1;
231 } while ((treg & 0x8000) == 0);
233 if (cols > newport_xsize)
234 newport_xsize = cols;
235 newport_ysize += linetable[i + 1];
238 printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
241 static void newport_get_revisions(void)
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;
252 rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
254 npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
255 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
256 tmp = npregs->set.dcbdata0.bybytes.b3;
258 board_rev = (tmp >> 4) & 7;
259 bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
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);
267 vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
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;
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;
280 #define L(a) (char)('A'+(a))
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));
287 if (board_rev == 3) /* I don't know all affected revisions */
288 xcurs_correction = 21;
291 static void newport_exit(void)
295 /* free memory used by user font */
296 for (i = 0; i < MAX_NR_CONSOLES; i++)
297 newport_set_def_font(i, NULL);
300 /* Can't be __init, do_take_over_console may call it later */
301 static const char *newport_startup(void)
305 npregs->cset.config = NPORT_CFG_GD0;
307 if (newport_wait(npregs))
310 npregs->set.xstarti = TESTVAL;
311 if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
314 for (i = 0; i < MAX_NR_CONSOLES; i++)
315 font_data[i] = FONT_DATA;
318 newport_get_revisions();
319 newport_get_screensize();
320 newport_has_init = 1;
322 return "SGI Newport";
328 static void newport_init(struct vc_data *vc, int init)
332 cols = newport_xsize / 8;
333 rows = newport_ysize / 16;
334 vc->vc_can_do_color = 1;
339 vc_resize(vc, cols, rows);
342 static void newport_deinit(struct vc_data *c)
344 if (!con_is_bound(&newport_con) && newport_has_init) {
346 newport_has_init = 0;
350 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
353 int xend = ((sx + width) << 3) - 1;
354 int ystart = ((sy << 4) + topscan) & 0x3ff;
355 int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
361 newport_clear_screen(sx << 3, ystart, xend, yend,
362 (vc->vc_color & 0xf0) >> 4);
364 newport_clear_screen(sx << 3, ystart, xend, 1023,
365 (vc->vc_color & 0xf0) >> 4);
366 newport_clear_screen(sx << 3, 0, xend, yend,
367 (vc->vc_color & 0xf0) >> 4);
371 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
376 p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
377 charattr = (charattr >> 8) & 0xff;
381 newport_render_background(xpos, ypos, xpos, ypos,
382 (charattr & 0xf0) >> 4);
384 /* Set the color and drawing mode. */
385 newport_wait(npregs);
386 npregs->set.colori = charattr & 0xf;
387 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
388 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
391 /* Set coordinates for bitmap operation. */
392 npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
393 npregs->set.xyendi = ((xpos + 7) << 16);
394 newport_wait(npregs);
396 /* Go, baby, go... */
400 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
401 int count, int ypos, int xpos)
407 charattr = (scr_readw(s) >> 8) & 0xff;
413 /* Clear the area behing the string */
414 newport_render_background(xpos, ypos,
415 xpos + ((count - 1) << 3), ypos,
416 (charattr & 0xf0) >> 4);
418 newport_wait(npregs);
420 /* Set the color and drawing mode. */
421 npregs->set.colori = charattr & 0xf;
422 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
423 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
426 for (i = 0; i < count; i++, xpos += 8) {
427 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
429 newport_wait(npregs);
431 /* Set coordinates for bitmap operation. */
432 npregs->set.xystarti =
433 (xpos << 16) | ((ypos + topscan) & 0x3ff);
434 npregs->set.xyendi = ((xpos + 7) << 16);
436 /* Go, baby, go... */
441 static void newport_cursor(struct vc_data *vc, int mode)
448 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
449 newport_vc2_set(npregs, VC2_IREG_CONTROL,
450 (treg & ~(VC2_CTRL_ECDISP)));
455 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
456 newport_vc2_set(npregs, VC2_IREG_CONTROL,
457 (treg | VC2_CTRL_ECDISP));
458 xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
459 ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
460 xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
461 newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
462 newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
466 static int newport_switch(struct vc_data *vc)
468 static int logo_drawn = 0;
471 npregs->cset.topscan = 0x3ff;
474 if (newport_show_logo()) {
483 static int newport_blank(struct vc_data *c, int blank, int mode_switch)
488 /* unblank console */
489 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
490 newport_vc2_set(npregs, VC2_IREG_CONTROL,
491 (treg | VC2_CTRL_EDISP));
494 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
495 newport_vc2_set(npregs, VC2_IREG_CONTROL,
496 (treg & ~(VC2_CTRL_EDISP)));
501 static int newport_set_font(int unit, struct console_font *op)
505 int size = h * op->charcount;
507 unsigned char *new_data, *data = op->data, *p;
509 /* ladis: when I grow up, there will be a day... and more sizes will
510 * be supported ;-) */
511 if ((w != 8) || (h != 16)
512 || (op->charcount != 256 && op->charcount != 512))
515 if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
516 GFP_USER))) return -ENOMEM;
518 new_data += FONT_EXTRA_WORDS * sizeof(int);
519 FNTSIZE(new_data) = size;
520 FNTCHARCNT(new_data) = op->charcount;
521 REFCOUNT(new_data) = 0; /* usage counter */
524 for (i = 0; i < op->charcount; i++) {
530 /* check if font is already used by other console */
531 for (i = 0; i < MAX_NR_CONSOLES; i++) {
532 if (font_data[i] != FONT_DATA
533 && FNTSIZE(font_data[i]) == size
534 && !memcmp(font_data[i], new_data, size)) {
535 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
536 /* current font is the same as the new one */
539 new_data = font_data[i];
543 /* old font is user font */
544 if (font_data[unit] != FONT_DATA) {
545 if (--REFCOUNT(font_data[unit]) == 0)
546 kfree(font_data[unit] -
547 FONT_EXTRA_WORDS * sizeof(int));
549 REFCOUNT(new_data)++;
550 font_data[unit] = new_data;
555 static int newport_set_def_font(int unit, struct console_font *op)
557 if (font_data[unit] != FONT_DATA) {
558 if (--REFCOUNT(font_data[unit]) == 0)
559 kfree(font_data[unit] -
560 FONT_EXTRA_WORDS * sizeof(int));
561 font_data[unit] = FONT_DATA;
567 static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
569 return newport_set_def_font(vc->vc_num, op);
572 static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
574 return newport_set_font(vc->vc_num, font);
577 static int newport_set_palette(struct vc_data *vc, unsigned char *table)
582 static int newport_scrolldelta(struct vc_data *vc, int lines)
584 /* there is (nearly) no off-screen memory, so we can't scroll back */
588 static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
592 unsigned short *s, *d;
593 unsigned short chattr;
595 logo_active = 0; /* it's time to disable the logo now.. */
597 if (t == 0 && b == vc->vc_rows) {
599 topscan = (topscan + (lines << 4)) & 0x3ff;
600 newport_clear_lines(vc->vc_rows - lines,
602 (vc->vc_color & 0xf0) >> 4);
604 topscan = (topscan + (-lines << 4)) & 0x3ff;
605 newport_clear_lines(0, lines - 1,
606 (vc->vc_color & 0xf0) >> 4);
608 npregs->cset.topscan = (topscan - 1) & 0x3ff;
612 count = (b - t - lines) * vc->vc_cols;
616 s = (unsigned short *) (vc->vc_origin +
617 vc->vc_size_row * (t + lines));
618 d = (unsigned short *) (vc->vc_origin +
619 vc->vc_size_row * t);
621 chattr = scr_readw(s++);
622 if (chattr != scr_readw(d)) {
623 newport_putc(vc, chattr, y, x);
624 scr_writew(chattr, d);
627 if (++x == vc->vc_cols) {
632 d = (unsigned short *) (vc->vc_origin +
633 vc->vc_size_row * (b - lines));
636 for (count = 0; count < (lines * vc->vc_cols); count++) {
637 if (scr_readw(d) != vc->vc_video_erase_char) {
638 newport_putc(vc, vc->vc_video_erase_char,
640 scr_writew(vc->vc_video_erase_char, d);
643 if (++x == vc->vc_cols) {
651 s = (unsigned short *) (vc->vc_origin +
652 vc->vc_size_row * (b - lines) - 2);
653 d = (unsigned short *) (vc->vc_origin +
654 vc->vc_size_row * b - 2);
656 chattr = scr_readw(s--);
657 if (chattr != scr_readw(d)) {
658 newport_putc(vc, chattr, y, x);
659 scr_writew(chattr, d);
667 d = (unsigned short *) (vc->vc_origin +
668 vc->vc_size_row * t);
671 for (count = 0; count < (lines * vc->vc_cols); count++) {
672 if (scr_readw(d) != vc->vc_video_erase_char) {
673 newport_putc(vc, vc->vc_video_erase_char,
675 scr_writew(vc->vc_video_erase_char, d);
678 if (++x == vc->vc_cols) {
687 static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
688 int dx, int h, int w)
690 short xs, ys, xe, ye, xoffs, yoffs, tmp;
693 xe = ((sx + w) << 3) - 1;
695 * as bmove is only used to move stuff around in the same line
696 * (h == 1), we don't care about wrap arounds caused by topscan != 0
698 ys = ((sy << 4) + topscan) & 0x3ff;
699 ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
700 xoffs = (dx - sx) << 3;
701 yoffs = (dy - sy) << 4;
703 /* move to the right, exchange starting points */
708 newport_wait(npregs);
709 npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK |
710 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
711 | NPORT_DMODE0_STOPY);
712 npregs->set.xystarti = (xs << 16) | ys;
713 npregs->set.xyendi = (xe << 16) | ye;
714 npregs->go.xymove = (xoffs << 16) | yoffs;
717 static int newport_dummy(struct vc_data *c)
722 #define DUMMY (void *) newport_dummy
724 const struct consw newport_con = {
725 .owner = THIS_MODULE,
726 .con_startup = newport_startup,
727 .con_init = newport_init,
728 .con_deinit = newport_deinit,
729 .con_clear = newport_clear,
730 .con_putc = newport_putc,
731 .con_putcs = newport_putcs,
732 .con_cursor = newport_cursor,
733 .con_scroll = newport_scroll,
734 .con_bmove = newport_bmove,
735 .con_switch = newport_switch,
736 .con_blank = newport_blank,
737 .con_font_set = newport_font_set,
738 .con_font_default = newport_font_default,
739 .con_set_palette = newport_set_palette,
740 .con_scrolldelta = newport_scrolldelta,
741 .con_set_origin = DUMMY,
742 .con_save_screen = DUMMY
745 static int newport_probe(struct gio_device *dev,
746 const struct gio_device_id *id)
748 unsigned long newport_addr;
751 if (!dev->resource.start)
755 return -EBUSY; /* we only support one Newport as console */
757 newport_addr = dev->resource.start + 0xF0000;
758 if (!request_mem_region(newport_addr, 0x10000, "Newport"))
761 npregs = (struct newport_regs *)/* ioremap cannot fail */
762 ioremap(newport_addr, sizeof(struct newport_regs));
764 err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
769 static void newport_remove(struct gio_device *dev)
771 give_up_console(&newport_con);
772 iounmap((void *)npregs);
775 static struct gio_device_id newport_ids[] = {
780 MODULE_ALIAS("gio:7e");
782 static struct gio_driver newport_driver = {
784 .id_table = newport_ids,
785 .probe = newport_probe,
786 .remove = newport_remove,
789 int __init newport_console_init(void)
791 return gio_register_driver(&newport_driver);
794 void __exit newport_console_exit(void)
796 gio_unregister_driver(&newport_driver);
799 module_init(newport_console_init);
800 module_exit(newport_console_exit);
802 MODULE_LICENSE("GPL");