patch-2_6_7-vs1_9_1_12
[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 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
55 static int newport_set_def_font(int unit, struct console_font_op *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();
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();
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();
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();
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();
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();
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 void newport_reset(void)
153 {
154         unsigned short treg;
155         int i;
156
157         newport_wait();
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();
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 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();
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();
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();
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 /* Can't be __init, take_over_console may call it later */
287 static const char *newport_startup(void)
288 {
289         int i;
290
291         if (!sgi_gfxaddr)
292                 return NULL;
293         npregs = (struct newport_regs *) (KSEG1 + sgi_gfxaddr);
294         npregs->cset.config = NPORT_CFG_GD0;
295
296         if (newport_wait()) {
297                 return NULL;
298         }
299
300         npregs->set.xstarti = TESTVAL;
301         if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
302                 return NULL;
303
304         for (i = 0; i < MAX_NR_CONSOLES; i++)
305                 font_data[i] = FONT_DATA;
306
307         newport_reset();
308         newport_get_revisions();
309         newport_get_screensize();
310
311         return "SGI Newport";
312 }
313
314 static void newport_init(struct vc_data *vc, int init)
315 {
316         vc->vc_cols = newport_xsize / 8;
317         vc->vc_rows = newport_ysize / 16;
318         vc->vc_can_do_color = 1;
319 }
320
321 static void newport_deinit(struct vc_data *c)
322 {
323         int i;
324
325         /* free memory used by user font */
326         for (i = 0; i < MAX_NR_CONSOLES; i++)
327                 newport_set_def_font(i, NULL);
328 }
329
330 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
331                           int width)
332 {
333         int xend = ((sx + width) << 3) - 1;
334         int ystart = ((sy << 4) + topscan) & 0x3ff;
335         int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
336
337         if (logo_active)
338                 return;
339
340         if (ystart < yend) {
341                 newport_clear_screen(sx << 3, ystart, xend, yend,
342                                      (vc->vc_color & 0xf0) >> 4);
343         } else {
344                 newport_clear_screen(sx << 3, ystart, xend, 1023,
345                                      (vc->vc_color & 0xf0) >> 4);
346                 newport_clear_screen(sx << 3, 0, xend, yend,
347                                      (vc->vc_color & 0xf0) >> 4);
348         }
349 }
350
351 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
352                          int xpos)
353 {
354         unsigned char *p;
355
356         p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
357         charattr = (charattr >> 8) & 0xff;
358         xpos <<= 3;
359         ypos <<= 4;
360
361         newport_render_background(xpos, ypos, xpos, ypos,
362                                   (charattr & 0xf0) >> 4);
363
364         /* Set the color and drawing mode. */
365         newport_wait();
366         npregs->set.colori = charattr & 0xf;
367         npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
368                                  NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
369                                  NPORT_DMODE0_L32);
370
371         /* Set coordinates for bitmap operation. */
372         npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
373         npregs->set.xyendi = ((xpos + 7) << 16);
374         newport_wait();
375
376         /* Go, baby, go... */
377         RENDER(npregs, p);
378 }
379
380 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
381                           int count, int ypos, int xpos)
382 {
383         int i;
384         int charattr;
385         unsigned char *p;
386
387         charattr = (scr_readw(s) >> 8) & 0xff;
388
389         xpos <<= 3;
390         ypos <<= 4;
391
392         if (!logo_active)
393                 /* Clear the area behing the string */
394                 newport_render_background(xpos, ypos,
395                                           xpos + ((count - 1) << 3), ypos,
396                                           (charattr & 0xf0) >> 4);
397
398         newport_wait();
399
400         /* Set the color and drawing mode. */
401         npregs->set.colori = charattr & 0xf;
402         npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
403                                  NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
404                                  NPORT_DMODE0_L32);
405
406         for (i = 0; i < count; i++, xpos += 8) {
407                 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
408
409                 newport_wait();
410
411                 /* Set coordinates for bitmap operation. */
412                 npregs->set.xystarti =
413                     (xpos << 16) | ((ypos + topscan) & 0x3ff);
414                 npregs->set.xyendi = ((xpos + 7) << 16);
415
416                 /* Go, baby, go... */
417                 RENDER(npregs, p);
418         }
419 }
420
421 static void newport_cursor(struct vc_data *vc, int mode)
422 {
423         unsigned short treg;
424         int xcurs, ycurs;
425
426         switch (mode) {
427         case CM_ERASE:
428                 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
429                 newport_vc2_set(npregs, VC2_IREG_CONTROL,
430                                 (treg & ~(VC2_CTRL_ECDISP)));
431                 break;
432
433         case CM_MOVE:
434         case CM_DRAW:
435                 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
436                 newport_vc2_set(npregs, VC2_IREG_CONTROL,
437                                 (treg | VC2_CTRL_ECDISP));
438                 xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
439                 ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
440                 xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
441                 newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
442                 newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
443         }
444 }
445
446 static int newport_switch(struct vc_data *vc)
447 {
448         static int logo_drawn = 0;
449
450         topscan = 0;
451         npregs->cset.topscan = 0x3ff;
452
453         if (!logo_drawn) {
454                 newport_show_logo();
455                 logo_drawn = 1;
456                 logo_active = 1;
457         }
458
459         return 1;
460 }
461
462 static int newport_blank(struct vc_data *c, int blank)
463 {
464         unsigned short treg;
465
466         if (blank == 0) {
467                 /* unblank console */
468                 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
469                 newport_vc2_set(npregs, VC2_IREG_CONTROL,
470                                 (treg | VC2_CTRL_EDISP));
471         } else {
472                 /* blank console */
473                 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
474                 newport_vc2_set(npregs, VC2_IREG_CONTROL,
475                                 (treg & ~(VC2_CTRL_EDISP)));
476         }
477         return 1;
478 }
479
480 static int newport_set_font(int unit, struct console_font_op *op)
481 {
482         int w = op->width;
483         int h = op->height;
484         int size = h * op->charcount;
485         int i;
486         unsigned char *new_data, *data = op->data, *p;
487
488         /* ladis: when I grow up, there will be a day... and more sizes will
489          * be supported ;-) */
490         if ((w != 8) || (h != 16)
491             || (op->charcount != 256 && op->charcount != 512))
492                 return -EINVAL;
493
494         if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
495              GFP_USER))) return -ENOMEM;
496
497         new_data += FONT_EXTRA_WORDS * sizeof(int);
498         FNTSIZE(new_data) = size;
499         FNTCHARCNT(new_data) = op->charcount;
500         REFCOUNT(new_data) = 0; /* usage counter */
501
502         p = new_data;
503         for (i = 0; i < op->charcount; i++) {
504                 memcpy(p, data, h);
505                 data += 32;
506                 p += h;
507         }
508
509         /* check if font is already used by other console */
510         for (i = 0; i < MAX_NR_CONSOLES; i++) {
511                 if (font_data[i] != FONT_DATA
512                     && FNTSIZE(font_data[i]) == size
513                     && !memcmp(font_data[i], new_data, size)) {
514                         kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
515                         /* current font is the same as the new one */
516                         if (i == unit)
517                                 return 0;
518                         new_data = font_data[i];
519                         break;
520                 }
521         }
522         /* old font is user font */
523         if (font_data[unit] != FONT_DATA) {
524                 if (--REFCOUNT(font_data[unit]) == 0)
525                         kfree(font_data[unit] -
526                               FONT_EXTRA_WORDS * sizeof(int));
527         }
528         REFCOUNT(new_data)++;
529         font_data[unit] = new_data;
530
531         return 0;
532 }
533
534 static int newport_set_def_font(int unit, struct console_font_op *op)
535 {
536         if (font_data[unit] != FONT_DATA) {
537                 if (--REFCOUNT(font_data[unit]) == 0)
538                         kfree(font_data[unit] -
539                               FONT_EXTRA_WORDS * sizeof(int));
540                 font_data[unit] = FONT_DATA;
541         }
542
543         return 0;
544 }
545
546 static int newport_font_op(struct vc_data *vc, struct console_font_op *op)
547 {
548         int unit = vc->vc_num;
549
550         switch (op->op) {
551         case KD_FONT_OP_SET:
552                 return newport_set_font(unit, op);
553         case KD_FONT_OP_SET_DEFAULT:
554                 return newport_set_def_font(unit, op);
555         default:
556                 return -ENOSYS;
557         }
558 }
559
560 static int newport_set_palette(struct vc_data *vc, unsigned char *table)
561 {
562         return -EINVAL;
563 }
564
565 static int newport_scrolldelta(struct vc_data *vc, int lines)
566 {
567         /* there is (nearly) no off-screen memory, so we can't scroll back */
568         return 0;
569 }
570
571 static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
572                           int lines)
573 {
574         int count, x, y;
575         unsigned short *s, *d;
576         unsigned short chattr;
577
578         logo_active = 0;        /* it's time to disable the logo now.. */
579
580         if (t == 0 && b == vc->vc_rows) {
581                 if (dir == SM_UP) {
582                         topscan = (topscan + (lines << 4)) & 0x3ff;
583                         newport_clear_lines(vc->vc_rows - lines,
584                                             vc->vc_rows - 1,
585                                             (vc->vc_color & 0xf0) >> 4);
586                 } else {
587                         topscan = (topscan + (-lines << 4)) & 0x3ff;
588                         newport_clear_lines(0, lines - 1,
589                                             (vc->vc_color & 0xf0) >> 4);
590                 }
591                 npregs->cset.topscan = (topscan - 1) & 0x3ff;
592                 return 0;
593         }
594
595         count = (b - t - lines) * vc->vc_cols;
596         if (dir == SM_UP) {
597                 x = 0;
598                 y = t;
599                 s = (unsigned short *) (vc->vc_origin +
600                                         vc->vc_size_row * (t + lines));
601                 d = (unsigned short *) (vc->vc_origin +
602                                         vc->vc_size_row * t);
603                 while (count--) {
604                         chattr = scr_readw(s++);
605                         if (chattr != scr_readw(d)) {
606                                 newport_putc(vc, chattr, y, x);
607                                 scr_writew(chattr, d);
608                         }
609                         d++;
610                         if (++x == vc->vc_cols) {
611                                 x = 0;
612                                 y++;
613                         }
614                 }
615                 d = (unsigned short *) (vc->vc_origin +
616                                         vc->vc_size_row * (b - lines));
617                 x = 0;
618                 y = b - lines;
619                 for (count = 0; count < (lines * vc->vc_cols); count++) {
620                         if (scr_readw(d) != vc->vc_video_erase_char) {
621                                 newport_putc(vc, vc->vc_video_erase_char,
622                                              y, x);
623                                 scr_writew(vc->vc_video_erase_char, d);
624                         }
625                         d++;
626                         if (++x == vc->vc_cols) {
627                                 x = 0;
628                                 y++;
629                         }
630                 }
631         } else {
632                 x = vc->vc_cols - 1;
633                 y = b - 1;
634                 s = (unsigned short *) (vc->vc_origin +
635                                         vc->vc_size_row * (b - lines) - 2);
636                 d = (unsigned short *) (vc->vc_origin +
637                                         vc->vc_size_row * b - 2);
638                 while (count--) {
639                         chattr = scr_readw(s--);
640                         if (chattr != scr_readw(d)) {
641                                 newport_putc(vc, chattr, y, x);
642                                 scr_writew(chattr, d);
643                         }
644                         d--;
645                         if (x-- == 0) {
646                                 x = vc->vc_cols - 1;
647                                 y--;
648                         }
649                 }
650                 d = (unsigned short *) (vc->vc_origin +
651                                         vc->vc_size_row * t);
652                 x = 0;
653                 y = t;
654                 for (count = 0; count < (lines * vc->vc_cols); count++) {
655                         if (scr_readw(d) != vc->vc_video_erase_char) {
656                                 newport_putc(vc, vc->vc_video_erase_char,
657                                              y, x);
658                                 scr_writew(vc->vc_video_erase_char, d);
659                         }
660                         d++;
661                         if (++x == vc->vc_cols) {
662                                 x = 0;
663                                 y++;
664                         }
665                 }
666         }
667         return 1;
668 }
669
670 static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
671                           int dx, int h, int w)
672 {
673         short xs, ys, xe, ye, xoffs, yoffs, tmp;
674
675         xs = sx << 3;
676         xe = ((sx + w) << 3) - 1;
677         /*
678          * as bmove is only used to move stuff around in the same line
679          * (h == 1), we don't care about wrap arounds caused by topscan != 0
680          */
681         ys = ((sy << 4) + topscan) & 0x3ff;
682         ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
683         xoffs = (dx - sx) << 3;
684         yoffs = (dy - sy) << 4;
685         if (xoffs > 0) {
686                 /* move to the right, exchange starting points */
687                 tmp = xe;
688                 xe = xs;
689                 xs = tmp;
690         }
691         newport_wait();
692         npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK |
693                                  NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
694                                  | NPORT_DMODE0_STOPY);
695         npregs->set.xystarti = (xs << 16) | ys;
696         npregs->set.xyendi = (xe << 16) | ye;
697         npregs->go.xymove = (xoffs << 16) | yoffs;
698 }
699
700 static int newport_dummy(struct vc_data *c)
701 {
702         return 0;
703 }
704
705 #define DUMMY (void *) newport_dummy
706
707 const struct consw newport_con = {
708     .owner =            THIS_MODULE,
709     .con_startup =      newport_startup,
710     .con_init =         newport_init,
711     .con_deinit =       newport_deinit,
712     .con_clear =        newport_clear,
713     .con_putc =         newport_putc,
714     .con_putcs =        newport_putcs,
715     .con_cursor =       newport_cursor,
716     .con_scroll =       newport_scroll,
717     .con_bmove =        newport_bmove,
718     .con_switch =       newport_switch,
719     .con_blank =        newport_blank,
720     .con_font_op =      newport_font_op,
721     .con_set_palette =  newport_set_palette,
722     .con_scrolldelta =  newport_scrolldelta,
723     .con_set_origin =   DUMMY,
724     .con_save_screen =  DUMMY
725 };
726
727 #ifdef MODULE
728 static int __init newport_console_init(void)
729 {
730         return take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
731 }
732
733 static void __exit newport_console_exit(void)
734 {
735         give_up_console(&newport_con);
736 }
737
738 module_init(newport_console_init);
739 module_exit(newport_console_exit);
740 #endif
741
742 MODULE_LICENSE("GPL");