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