Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
[linux-2.6] / 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/kd.h>
16 #include <linux/selection.h>
17 #include <linux/console.h>
18 #include <linux/vt_kern.h>
19 #include <linux/mm.h>
20 #include <linux/module.h>
21 #include <linux/slab.h>
22
23 #include <asm/io.h>
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 unsigned long sgi_gfxaddr;
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 static 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 static int newport_has_init;
54
55 static int newport_set_def_font(int unit, struct console_font *op);
56
57 #define BMASK(c) (c << 24)
58
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]); \
68 } while(0)
69
70 #define TESTVAL 0xdeadbeef
71 #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
72
73 static inline void newport_render_background(int xstart, int ystart,
74                                              int xend, int yend, int ci)
75 {
76         newport_wait(npregs);
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);
84         npregs->go.xyendi =
85             ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
86 }
87
88 static inline void newport_init_cmap(void)
89 {
90         unsigned short i;
91
92         for (i = 0; i < 16; i++) {
93                 newport_bfwait(npregs);
94                 newport_cmap_setaddr(npregs, color_table[i]);
95                 newport_cmap_setrgb(npregs,
96                                     default_red[i],
97                                     default_grn[i], default_blu[i]);
98         }
99 }
100
101 static void newport_show_logo(void)
102 {
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;
107         unsigned long i;
108
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]);
113                 clut += 3;
114         }
115
116         newport_wait(npregs);
117         npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
118                                  NPORT_DMODE0_CHOST);
119
120         npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0);
121         npregs->set.xyendi = ((newport_xsize - 1) << 16);
122         newport_wait(npregs);
123
124         for (i = 0; i < logo->width*logo->height; i++)
125                 npregs->go.hostrw0 = *data++ << 24;
126 #endif /* CONFIG_LOGO_SGI_CLUT224 */
127 }
128
129 static inline void newport_clear_screen(int xstart, int ystart, int xend,
130                                         int yend, int ci)
131 {
132         if (logo_active)
133                 return;
134
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;
143 }
144
145 static inline void newport_clear_lines(int ystart, int yend, int ci)
146 {
147         ystart = ((ystart << 4) + topscan) & 0x3ff;
148         yend = ((yend << 4) + topscan + 15) & 0x3ff;
149         newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
150 }
151
152 static void newport_reset(void)
153 {
154         unsigned short treg;
155         int i;
156
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));
161
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;
170                 else
171                         npregs->set.dcbdata0.byshort.s1 = 0x0000;
172         }
173
174         newport_init_cmap();
175
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;
183
184         topscan = 0;
185         npregs->cset.topscan = 0x3ff;
186         npregs->cset.xywin = (4096 << 16) | 4096;
187
188         /* Clear the screen. */
189         newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
190 }
191
192 /*
193  * calculate the actual screen size by reading
194  * the video timing out of the VC2
195  */
196 static void newport_get_screensize(void)
197 {
198         int i, cols;
199         unsigned short ventry, treg;
200         unsigned short linetable[128];  /* should be enough */
201
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;
209         }
210
211         newport_xsize = newport_ysize = 0;
212         for (i = 0; linetable[i + 1] && (i < sizeof(linetable)); i += 2) {
213                 cols = 0;
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);
217                 do {
218                         newport_bfwait(npregs);
219                         treg = npregs->set.dcbdata0.byshort.s1;
220                         if ((treg & 1) == 0)
221                                 cols += (treg >> 7) & 0xfe;
222                         if ((treg & 0x80) == 0) {
223                                 newport_bfwait(npregs);
224                                 treg = npregs->set.dcbdata0.byshort.s1;
225                         }
226                 } while ((treg & 0x8000) == 0);
227                 if (cols) {
228                         if (cols > newport_xsize)
229                                 newport_xsize = cols;
230                         newport_ysize += linetable[i + 1];
231                 }
232         }
233         printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
234 }
235
236 static void newport_get_revisions(void)
237 {
238         unsigned int tmp;
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;
246
247         rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
248
249         npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
250                                NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
251         tmp = npregs->set.dcbdata0.bybytes.b3;
252         cmap_rev = tmp & 7;
253         board_rev = (tmp >> 4) & 7;
254         bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
255
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);
261
262         vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
263
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;
267
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;
274
275 #define L(a)     (char)('A'+(a))
276         printk
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));
280 #undef L
281
282         if (board_rev == 3)     /* I don't know all affected revisions */
283                 xcurs_correction = 21;
284 }
285
286 static void newport_exit(void)
287 {
288         int i;
289
290         /* free memory used by user font */
291         for (i = 0; i < MAX_NR_CONSOLES; i++)
292                 newport_set_def_font(i, NULL);
293 }
294
295 /* Can't be __init, take_over_console may call it later */
296 static const char *newport_startup(void)
297 {
298         int i;
299
300         if (!sgi_gfxaddr)
301                 return NULL;
302
303         if (!npregs)
304                 npregs = (struct newport_regs *)/* ioremap cannot fail */
305                         ioremap(sgi_gfxaddr, sizeof(struct newport_regs));
306         npregs->cset.config = NPORT_CFG_GD0;
307
308         if (newport_wait(npregs))
309                 goto out_unmap;
310
311         npregs->set.xstarti = TESTVAL;
312         if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
313                 goto out_unmap;
314
315         for (i = 0; i < MAX_NR_CONSOLES; i++)
316                 font_data[i] = FONT_DATA;
317
318         newport_reset();
319         newport_get_revisions();
320         newport_get_screensize();
321         newport_has_init = 1;
322
323         return "SGI Newport";
324
325 out_unmap:
326         return NULL;
327 }
328
329 static void newport_init(struct vc_data *vc, int init)
330 {
331         vc->vc_cols = newport_xsize / 8;
332         vc->vc_rows = newport_ysize / 16;
333         vc->vc_can_do_color = 1;
334 }
335
336 static void newport_deinit(struct vc_data *c)
337 {
338         if (!con_is_bound(&newport_con) && newport_has_init) {
339                 newport_exit();
340                 newport_has_init = 0;
341         }
342 }
343
344 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
345                           int width)
346 {
347         int xend = ((sx + width) << 3) - 1;
348         int ystart = ((sy << 4) + topscan) & 0x3ff;
349         int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
350
351         if (logo_active)
352                 return;
353
354         if (ystart < yend) {
355                 newport_clear_screen(sx << 3, ystart, xend, yend,
356                                      (vc->vc_color & 0xf0) >> 4);
357         } else {
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);
362         }
363 }
364
365 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
366                          int xpos)
367 {
368         unsigned char *p;
369
370         p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
371         charattr = (charattr >> 8) & 0xff;
372         xpos <<= 3;
373         ypos <<= 4;
374
375         newport_render_background(xpos, ypos, xpos, ypos,
376                                   (charattr & 0xf0) >> 4);
377
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 |
383                                  NPORT_DMODE0_L32);
384
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);
389
390         /* Go, baby, go... */
391         RENDER(npregs, p);
392 }
393
394 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
395                           int count, int ypos, int xpos)
396 {
397         int i;
398         int charattr;
399         unsigned char *p;
400
401         charattr = (scr_readw(s) >> 8) & 0xff;
402
403         xpos <<= 3;
404         ypos <<= 4;
405
406         if (!logo_active)
407                 /* Clear the area behing the string */
408                 newport_render_background(xpos, ypos,
409                                           xpos + ((count - 1) << 3), ypos,
410                                           (charattr & 0xf0) >> 4);
411
412         newport_wait(npregs);
413
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 |
418                                  NPORT_DMODE0_L32);
419
420         for (i = 0; i < count; i++, xpos += 8) {
421                 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
422
423                 newport_wait(npregs);
424
425                 /* Set coordinates for bitmap operation. */
426                 npregs->set.xystarti =
427                     (xpos << 16) | ((ypos + topscan) & 0x3ff);
428                 npregs->set.xyendi = ((xpos + 7) << 16);
429
430                 /* Go, baby, go... */
431                 RENDER(npregs, p);
432         }
433 }
434
435 static void newport_cursor(struct vc_data *vc, int mode)
436 {
437         unsigned short treg;
438         int xcurs, ycurs;
439
440         switch (mode) {
441         case CM_ERASE:
442                 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
443                 newport_vc2_set(npregs, VC2_IREG_CONTROL,
444                                 (treg & ~(VC2_CTRL_ECDISP)));
445                 break;
446
447         case CM_MOVE:
448         case CM_DRAW:
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);
457         }
458 }
459
460 static int newport_switch(struct vc_data *vc)
461 {
462         static int logo_drawn = 0;
463
464         topscan = 0;
465         npregs->cset.topscan = 0x3ff;
466
467         if (!logo_drawn) {
468                 newport_show_logo();
469                 logo_drawn = 1;
470                 logo_active = 1;
471         }
472
473         return 1;
474 }
475
476 static int newport_blank(struct vc_data *c, int blank, int mode_switch)
477 {
478         unsigned short treg;
479
480         if (blank == 0) {
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));
485         } else {
486                 /* blank console */
487                 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
488                 newport_vc2_set(npregs, VC2_IREG_CONTROL,
489                                 (treg & ~(VC2_CTRL_EDISP)));
490         }
491         return 1;
492 }
493
494 static int newport_set_font(int unit, struct console_font *op)
495 {
496         int w = op->width;
497         int h = op->height;
498         int size = h * op->charcount;
499         int i;
500         unsigned char *new_data, *data = op->data, *p;
501
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))
506                 return -EINVAL;
507
508         if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
509              GFP_USER))) return -ENOMEM;
510
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 */
515
516         p = new_data;
517         for (i = 0; i < op->charcount; i++) {
518                 memcpy(p, data, h);
519                 data += 32;
520                 p += h;
521         }
522
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 */
530                         if (i == unit)
531                                 return 0;
532                         new_data = font_data[i];
533                         break;
534                 }
535         }
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));
541         }
542         REFCOUNT(new_data)++;
543         font_data[unit] = new_data;
544
545         return 0;
546 }
547
548 static int newport_set_def_font(int unit, struct console_font *op)
549 {
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;
555         }
556
557         return 0;
558 }
559
560 static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
561 {
562         return newport_set_def_font(vc->vc_num, op);
563 }
564
565 static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
566 {
567         return newport_set_font(vc->vc_num, font);
568 }
569
570 static int newport_set_palette(struct vc_data *vc, unsigned char *table)
571 {
572         return -EINVAL;
573 }
574
575 static int newport_scrolldelta(struct vc_data *vc, int lines)
576 {
577         /* there is (nearly) no off-screen memory, so we can't scroll back */
578         return 0;
579 }
580
581 static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
582                           int lines)
583 {
584         int count, x, y;
585         unsigned short *s, *d;
586         unsigned short chattr;
587
588         logo_active = 0;        /* it's time to disable the logo now.. */
589
590         if (t == 0 && b == vc->vc_rows) {
591                 if (dir == SM_UP) {
592                         topscan = (topscan + (lines << 4)) & 0x3ff;
593                         newport_clear_lines(vc->vc_rows - lines,
594                                             vc->vc_rows - 1,
595                                             (vc->vc_color & 0xf0) >> 4);
596                 } else {
597                         topscan = (topscan + (-lines << 4)) & 0x3ff;
598                         newport_clear_lines(0, lines - 1,
599                                             (vc->vc_color & 0xf0) >> 4);
600                 }
601                 npregs->cset.topscan = (topscan - 1) & 0x3ff;
602                 return 0;
603         }
604
605         count = (b - t - lines) * vc->vc_cols;
606         if (dir == SM_UP) {
607                 x = 0;
608                 y = t;
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);
613                 while (count--) {
614                         chattr = scr_readw(s++);
615                         if (chattr != scr_readw(d)) {
616                                 newport_putc(vc, chattr, y, x);
617                                 scr_writew(chattr, d);
618                         }
619                         d++;
620                         if (++x == vc->vc_cols) {
621                                 x = 0;
622                                 y++;
623                         }
624                 }
625                 d = (unsigned short *) (vc->vc_origin +
626                                         vc->vc_size_row * (b - lines));
627                 x = 0;
628                 y = 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,
632                                              y, x);
633                                 scr_writew(vc->vc_video_erase_char, d);
634                         }
635                         d++;
636                         if (++x == vc->vc_cols) {
637                                 x = 0;
638                                 y++;
639                         }
640                 }
641         } else {
642                 x = vc->vc_cols - 1;
643                 y = b - 1;
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);
648                 while (count--) {
649                         chattr = scr_readw(s--);
650                         if (chattr != scr_readw(d)) {
651                                 newport_putc(vc, chattr, y, x);
652                                 scr_writew(chattr, d);
653                         }
654                         d--;
655                         if (x-- == 0) {
656                                 x = vc->vc_cols - 1;
657                                 y--;
658                         }
659                 }
660                 d = (unsigned short *) (vc->vc_origin +
661                                         vc->vc_size_row * t);
662                 x = 0;
663                 y = 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,
667                                              y, x);
668                                 scr_writew(vc->vc_video_erase_char, d);
669                         }
670                         d++;
671                         if (++x == vc->vc_cols) {
672                                 x = 0;
673                                 y++;
674                         }
675                 }
676         }
677         return 1;
678 }
679
680 static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
681                           int dx, int h, int w)
682 {
683         short xs, ys, xe, ye, xoffs, yoffs, tmp;
684
685         xs = sx << 3;
686         xe = ((sx + w) << 3) - 1;
687         /*
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
690          */
691         ys = ((sy << 4) + topscan) & 0x3ff;
692         ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
693         xoffs = (dx - sx) << 3;
694         yoffs = (dy - sy) << 4;
695         if (xoffs > 0) {
696                 /* move to the right, exchange starting points */
697                 tmp = xe;
698                 xe = xs;
699                 xs = tmp;
700         }
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;
708 }
709
710 static int newport_dummy(struct vc_data *c)
711 {
712         return 0;
713 }
714
715 #define DUMMY (void *) newport_dummy
716
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
736 };
737
738 #ifdef MODULE
739 static int __init newport_console_init(void)
740 {
741         if (!sgi_gfxaddr)
742                 return 0;
743
744         if (!npregs)
745                 npregs = (struct newport_regs *)/* ioremap cannot fail */
746                         ioremap(sgi_gfxaddr, sizeof(struct newport_regs));
747
748         return take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
749 }
750 module_init(newport_console_init);
751
752 static void __exit newport_console_exit(void)
753 {
754         give_up_console(&newport_con);
755         iounmap((void *)npregs);
756 }
757 module_exit(newport_console_exit);
758 #endif
759
760 MODULE_LICENSE("GPL");