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