ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / video / console / newport_con.c
1 /*
2  * newport_con.c: Abscon for newport hardware
3  * 
4  * (C) 1998 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
5  * (C) 1999 Ulf Carlsson (ulfc@thepuffingruop.com)
6  * 
7  * This driver is based on sgicons.c and cons_newport.
8  * 
9  * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
10  * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
11  */
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/tty.h>
16 #include <linux/kd.h>
17 #include <linux/selection.h>
18 #include <linux/console.h>
19 #include <linux/vt_kern.h>
20 #include <linux/mm.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23
24 #include <asm/uaccess.h>
25 #include <asm/system.h>
26 #include <asm/page.h>
27 #include <asm/pgtable.h>
28 #include <video/newport.h>
29
30 #include <linux/linux_logo.h>
31 #include <linux/font.h>
32
33
34 extern struct font_desc font_vga_8x16;
35
36 #define FONT_DATA ((unsigned char *)font_vga_8x16.data)
37
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
43
44 static unsigned char *font_data[MAX_NR_CONSOLES];
45
46 extern struct newport_regs *npregs;
47
48 static int logo_active;
49 static int topscan;
50 static int xcurs_correction = 29;
51 static int newport_xsize;
52 static int newport_ysize;
53
54 #define BMASK(c) (c << 24)
55
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]); \
65 } while(0)
66
67 #define TESTVAL 0xdeadbeef
68 #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
69
70 static inline void newport_render_background(int xstart, int ystart,
71                                              int xend, int yend, int ci)
72 {
73         newport_wait();
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);
81         npregs->go.xyendi =
82             ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
83 }
84
85 static inline void newport_init_cmap(void)
86 {
87         unsigned short i;
88
89         for (i = 0; i < 16; i++) {
90                 newport_bfwait();
91                 newport_cmap_setaddr(npregs, color_table[i]);
92                 newport_cmap_setrgb(npregs,
93                                     default_red[i],
94                                     default_grn[i], default_blu[i]);
95         }
96 }
97
98 #ifdef CONFIG_LOGO_SGI_CLUT224
99 static void newport_show_logo(void);
100 #else
101 #define newport_show_logo()     do { } while (0)
102 #endif
103
104 static inline void newport_clear_screen(int xstart, int ystart, int xend,
105                                         int yend, int ci)
106 {
107         if (logo_active)
108                 return;
109
110         newport_wait();
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;
118 }
119
120 static inline void newport_clear_lines(int ystart, int yend, int ci)
121 {
122         ystart = ((ystart << 4) + topscan) & 0x3ff;
123         yend = ((yend << 4) + topscan + 15) & 0x3ff;
124         newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
125 }
126
127 void newport_reset(void)
128 {
129         unsigned short treg;
130         int i;
131
132         newport_wait();
133         treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
134         newport_vc2_set(npregs, VC2_IREG_CONTROL,
135                         (treg | VC2_CTRL_EVIDEO));
136
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++) {
142                 newport_bfwait();
143                 if (i == 92 || i == 94)
144                         npregs->set.dcbdata0.byshort.s1 = 0xff00;
145                 else
146                         npregs->set.dcbdata0.byshort.s1 = 0x0000;
147         }
148
149         newport_init_cmap();
150
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;
158
159         topscan = 0;
160         npregs->cset.topscan = 0x3ff;
161         npregs->cset.xywin = (4096 << 16) | 4096;
162
163         /* Clear the screen. */
164         newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
165 }
166
167 /*
168  * calculate the actual screen size by reading
169  * the video timing out of the VC2
170  */
171 void newport_get_screensize(void)
172 {
173         int i, cols;
174         unsigned short ventry, treg;
175         unsigned short linetable[128];  /* should be enough */
176
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++) {
182                 newport_bfwait();
183                 linetable[i] = npregs->set.dcbdata0.byshort.s1;
184         }
185
186         newport_xsize = newport_ysize = 0;
187         for (i = 0; linetable[i + 1] && (i < sizeof(linetable)); i += 2) {
188                 cols = 0;
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);
192                 do {
193                         newport_bfwait();
194                         treg = npregs->set.dcbdata0.byshort.s1;
195                         if ((treg & 1) == 0)
196                                 cols += (treg >> 7) & 0xfe;
197                         if ((treg & 0x80) == 0) {
198                                 newport_bfwait();
199                                 treg = npregs->set.dcbdata0.byshort.s1;
200                         }
201                 } while ((treg & 0x8000) == 0);
202                 if (cols) {
203                         if (cols > newport_xsize)
204                                 newport_xsize = cols;
205                         newport_ysize += linetable[i + 1];
206                 }
207         }
208         printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
209 }
210
211 static void newport_get_revisions(void)
212 {
213         unsigned int tmp;
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;
221
222         rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
223
224         npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
225                                NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
226         tmp = npregs->set.dcbdata0.bybytes.b3;
227         cmap_rev = tmp & 7;
228         board_rev = (tmp >> 4) & 7;
229         bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
230
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);
236
237         vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
238
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;
242
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;
249
250 #define L(a)     (char)('A'+(a))
251         printk
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));
255 #undef L
256
257         if (board_rev == 3)     /* I don't know all affected revisions */
258                 xcurs_correction = 21;
259 }
260
261 #ifdef MODULE
262 static const char *newport_startup(void)
263 #else
264 static const char *__init newport_startup(void)
265 #endif
266 {
267         int i;
268         struct newport_regs *p;
269
270         npregs = (struct newport_regs *) (KSEG1 + 0x1f0f0000);
271
272         p = npregs;
273         p->cset.config = NPORT_CFG_GD0;
274
275         if (newport_wait()) {
276                 return NULL;
277         }
278
279         p->set.xstarti = TESTVAL;
280         if (p->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
281                 return NULL;
282
283         for (i = 0; i < MAX_NR_CONSOLES; i++)
284                 font_data[i] = FONT_DATA;
285
286         newport_reset();
287         newport_get_revisions();
288         newport_get_screensize();
289
290         /* gfx_init (display_desc); */
291
292         return "SGI Newport";
293 }
294
295 static void newport_init(struct vc_data *vc, int init)
296 {
297         vc->vc_cols = newport_xsize / 8;
298         vc->vc_rows = newport_ysize / 16;
299         vc->vc_can_do_color = 1;
300 }
301
302 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
303                           int width)
304 {
305         int xend = ((sx + width) << 3) - 1;
306         int ystart = ((sy << 4) + topscan) & 0x3ff;
307         int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
308
309         if (logo_active)
310                 return;
311
312         if (ystart < yend) {
313                 newport_clear_screen(sx << 3, ystart, xend, yend,
314                                      (vc->vc_color & 0xf0) >> 4);
315         } else {
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);
320         }
321 }
322
323 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
324                          int xpos)
325 {
326         unsigned char *p;
327
328         p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
329         charattr = (charattr >> 8) & 0xff;
330         xpos <<= 3;
331         ypos <<= 4;
332
333         newport_render_background(xpos, ypos, xpos, ypos,
334                                   (charattr & 0xf0) >> 4);
335
336         /* Set the color and drawing mode. */
337         newport_wait();
338         npregs->set.colori = charattr & 0xf;
339         npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
340                                  NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
341                                  NPORT_DMODE0_L32);
342
343         /* Set coordinates for bitmap operation. */
344         npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
345         npregs->set.xyendi = ((xpos + 7) << 16);
346         newport_wait();
347
348         /* Go, baby, go... */
349         RENDER(npregs, p);
350 }
351
352 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
353                           int count, int ypos, int xpos)
354 {
355         int i;
356         int charattr;
357         unsigned char *p;
358
359         charattr = (scr_readw(s) >> 8) & 0xff;
360
361         xpos <<= 3;
362         ypos <<= 4;
363
364         if (!logo_active)
365                 /* Clear the area behing the string */
366                 newport_render_background(xpos, ypos,
367                                           xpos + ((count - 1) << 3), ypos,
368                                           (charattr & 0xf0) >> 4);
369
370         newport_wait();
371
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 |
376                                  NPORT_DMODE0_L32);
377
378         for (i = 0; i < count; i++, xpos += 8) {
379                 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
380
381                 newport_wait();
382
383                 /* Set coordinates for bitmap operation. */
384                 npregs->set.xystarti =
385                     (xpos << 16) | ((ypos + topscan) & 0x3ff);
386                 npregs->set.xyendi = ((xpos + 7) << 16);
387
388                 /* Go, baby, go... */
389                 RENDER(npregs, p);
390         }
391 }
392
393 static void newport_cursor(struct vc_data *vc, int mode)
394 {
395         unsigned short treg;
396         int xcurs, ycurs;
397
398         switch (mode) {
399         case CM_ERASE:
400                 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
401                 newport_vc2_set(npregs, VC2_IREG_CONTROL,
402                                 (treg & ~(VC2_CTRL_ECDISP)));
403                 break;
404
405         case CM_MOVE:
406         case CM_DRAW:
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);
415         }
416 }
417
418 static int newport_switch(struct vc_data *vc)
419 {
420         static int logo_drawn = 0;
421
422         topscan = 0;
423         npregs->cset.topscan = 0x3ff;
424
425         if (!logo_drawn) {
426                 newport_show_logo();
427                 logo_drawn = 1;
428                 logo_active = 1;
429         }
430
431         return 1;
432 }
433
434 static int newport_blank(struct vc_data *c, int blank)
435 {
436         unsigned short treg;
437
438         if (blank == 0) {
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));
443         } else {
444                 /* blank console */
445                 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
446                 newport_vc2_set(npregs, VC2_IREG_CONTROL,
447                                 (treg & ~(VC2_CTRL_EDISP)));
448         }
449         return 1;
450 }
451
452 static int newport_set_font(int unit, struct console_font_op *op)
453 {
454         int w = op->width;
455         int h = op->height;
456         int size = h * op->charcount;
457         int i;
458         unsigned char *new_data, *data = op->data, *p;
459
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))
464                 return -EINVAL;
465
466         if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
467              GFP_USER))) return -ENOMEM;
468
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 */
473
474         p = new_data;
475         for (i = 0; i < op->charcount; i++) {
476                 memcpy(p, data, h);
477                 data += 32;
478                 p += h;
479         }
480
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 */
488                         if (i == unit)
489                                 return 0;
490                         new_data = font_data[i];
491                         break;
492                 }
493         }
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));
499         }
500         REFCOUNT(new_data)++;
501         font_data[unit] = new_data;
502
503         return 0;
504 }
505
506 static int newport_set_def_font(int unit, struct console_font_op *op)
507 {
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;
513         }
514
515         return 0;
516 }
517
518 static int newport_font_op(struct vc_data *vc, struct console_font_op *op)
519 {
520         int unit = vc->vc_num;
521
522         switch (op->op) {
523         case KD_FONT_OP_SET:
524                 return newport_set_font(unit, op);
525         case KD_FONT_OP_SET_DEFAULT:
526                 return newport_set_def_font(unit, op);
527         default:
528                 return -ENOSYS;
529         }
530 }
531
532 static int newport_set_palette(struct vc_data *vc, unsigned char *table)
533 {
534         return -EINVAL;
535 }
536
537 static int newport_scrolldelta(struct vc_data *vc, int lines)
538 {
539         /* there is (nearly) no off-screen memory, so we can't scroll back */
540         return 0;
541 }
542
543 static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
544                           int lines)
545 {
546         int count, x, y;
547         unsigned short *s, *d;
548         unsigned short chattr;
549
550         logo_active = 0;        /* it's time to disable the logo now.. */
551
552         if (t == 0 && b == vc->vc_rows) {
553                 if (dir == SM_UP) {
554                         topscan = (topscan + (lines << 4)) & 0x3ff;
555                         newport_clear_lines(vc->vc_rows - lines,
556                                             vc->vc_rows - 1,
557                                             (vc->vc_color & 0xf0) >> 4);
558                 } else {
559                         topscan = (topscan + (-lines << 4)) & 0x3ff;
560                         newport_clear_lines(0, lines - 1,
561                                             (vc->vc_color & 0xf0) >> 4);
562                 }
563                 npregs->cset.topscan = (topscan - 1) & 0x3ff;
564                 return 0;
565         }
566
567         count = (b - t - lines) * vc->vc_cols;
568         if (dir == SM_UP) {
569                 x = 0;
570                 y = t;
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);
575                 while (count--) {
576                         chattr = scr_readw(s++);
577                         if (chattr != scr_readw(d)) {
578                                 newport_putc(vc, chattr, y, x);
579                                 scr_writew(chattr, d);
580                         }
581                         d++;
582                         if (++x == vc->vc_cols) {
583                                 x = 0;
584                                 y++;
585                         }
586                 }
587                 d = (unsigned short *) (vc->vc_origin +
588                                         vc->vc_size_row * (b - lines));
589                 x = 0;
590                 y = 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,
594                                              y, x);
595                                 scr_writew(vc->vc_video_erase_char, d);
596                         }
597                         d++;
598                         if (++x == vc->vc_cols) {
599                                 x = 0;
600                                 y++;
601                         }
602                 }
603         } else {
604                 x = vc->vc_cols - 1;
605                 y = b - 1;
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);
610                 while (count--) {
611                         chattr = scr_readw(s--);
612                         if (chattr != scr_readw(d)) {
613                                 newport_putc(vc, chattr, y, x);
614                                 scr_writew(chattr, d);
615                         }
616                         d--;
617                         if (x-- == 0) {
618                                 x = vc->vc_cols - 1;
619                                 y--;
620                         }
621                 }
622                 d = (unsigned short *) (vc->vc_origin +
623                                         vc->vc_size_row * t);
624                 x = 0;
625                 y = 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,
629                                              y, x);
630                                 scr_writew(vc->vc_video_erase_char, d);
631                         }
632                         d++;
633                         if (++x == vc->vc_cols) {
634                                 x = 0;
635                                 y++;
636                         }
637                 }
638         }
639         return 1;
640 }
641
642 static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
643                           int dx, int h, int w)
644 {
645         short xs, ys, xe, ye, xoffs, yoffs, tmp;
646
647         xs = sx << 3;
648         xe = ((sx + w) << 3) - 1;
649         /*
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
652          */
653         ys = ((sy << 4) + topscan) & 0x3ff;
654         ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
655         xoffs = (dx - sx) << 3;
656         yoffs = (dy - sy) << 4;
657         if (xoffs > 0) {
658                 /* move to the right, exchange starting points */
659                 tmp = xe;
660                 xe = xs;
661                 xs = tmp;
662         }
663         newport_wait();
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;
670 }
671
672 static int newport_dummy(struct vc_data *c)
673 {
674         return 0;
675 }
676
677 #define DUMMY (void *) newport_dummy
678
679 const struct consw newport_con = {
680     .con_startup =      newport_startup,
681     .con_init =         newport_init,
682     .con_deinit =       DUMMY,
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
696 };
697
698 #ifdef MODULE
699 MODULE_LICENSE("GPL");
700
701 int init_module(void)
702 {
703         if (!newport_startup())
704                 printk("Error loading SGI Newport Console driver\n");
705         else
706                 printk("Loading SGI Newport Console Driver\n");
707         take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
708
709         return 0;
710 }
711
712 int cleanup_module(void)
713 {
714         int i;
715
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);
720
721         return 0;
722 }
723 #endif
724
725
726 #ifdef CONFIG_LOGO_SGI_CLUT224
727
728 #undef __initdata
729 #define __initdata
730 #include "../logo/logo_sgi_clut224.c"
731
732 static void newport_show_logo(void)
733 {
734         const struct linux_logo *logo = &logo_sgi_clut224;
735         const unsigned char *clut = logo->clut;
736         const unsigned char *data = logo->data;
737         unsigned long i;
738
739         for (i = 0; i < logo->clutsize; i++) {
740                 newport_bfwait();
741                 newport_cmap_setaddr(npregs, i + 0x20);
742                 newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]);
743                 clut += 3;
744         }
745
746         newport_wait();
747         npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
748                                  NPORT_DMODE0_CHOST);
749
750         npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0);
751         npregs->set.xyendi = ((newport_xsize - 1) << 16);
752         newport_wait();
753
754         for (i = 0; i < logo->width*logo->height; i++)
755                 npregs->go.hostrw0 = *data++ << 24;
756 }
757 #endif /* CONFIG_LOGO_SGI_CLUT224 */
758