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 
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 /* 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 *)	/* ioremap cannot fail */
294 		 ioremap(sgi_gfxaddr, sizeof(struct newport_regs));
295 	npregs->cset.config = NPORT_CFG_GD0;
296 
297 	if (newport_wait(npregs))
298 		goto out_unmap;
299 
300 	npregs->set.xstarti = TESTVAL;
301 	if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
302 		goto out_unmap;
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 out_unmap:
314 	iounmap((void *)npregs);
315 	return NULL;
316 }
317 
318 static void newport_init(struct vc_data *vc, int init)
319 {
320 	vc->vc_cols = newport_xsize / 8;
321 	vc->vc_rows = newport_ysize / 16;
322 	vc->vc_can_do_color = 1;
323 }
324 
325 static void newport_deinit(struct vc_data *c)
326 {
327 	int i;
328 
329 	/* free memory used by user font */
330 	for (i = 0; i < MAX_NR_CONSOLES; i++)
331 		newport_set_def_font(i, NULL);
332 }
333 
334 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
335 			  int width)
336 {
337 	int xend = ((sx + width) << 3) - 1;
338 	int ystart = ((sy << 4) + topscan) & 0x3ff;
339 	int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
340 
341 	if (logo_active)
342 		return;
343 
344 	if (ystart < yend) {
345 		newport_clear_screen(sx << 3, ystart, xend, yend,
346 				     (vc->vc_color & 0xf0) >> 4);
347 	} else {
348 		newport_clear_screen(sx << 3, ystart, xend, 1023,
349 				     (vc->vc_color & 0xf0) >> 4);
350 		newport_clear_screen(sx << 3, 0, xend, yend,
351 				     (vc->vc_color & 0xf0) >> 4);
352 	}
353 }
354 
355 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
356 			 int xpos)
357 {
358 	unsigned char *p;
359 
360 	p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
361 	charattr = (charattr >> 8) & 0xff;
362 	xpos <<= 3;
363 	ypos <<= 4;
364 
365 	newport_render_background(xpos, ypos, xpos, ypos,
366 				  (charattr & 0xf0) >> 4);
367 
368 	/* Set the color and drawing mode. */
369 	newport_wait(npregs);
370 	npregs->set.colori = charattr & 0xf;
371 	npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
372 				 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
373 				 NPORT_DMODE0_L32);
374 
375 	/* Set coordinates for bitmap operation. */
376 	npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
377 	npregs->set.xyendi = ((xpos + 7) << 16);
378 	newport_wait(npregs);
379 
380 	/* Go, baby, go... */
381 	RENDER(npregs, p);
382 }
383 
384 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
385 			  int count, int ypos, int xpos)
386 {
387 	int i;
388 	int charattr;
389 	unsigned char *p;
390 
391 	charattr = (scr_readw(s) >> 8) & 0xff;
392 
393 	xpos <<= 3;
394 	ypos <<= 4;
395 
396 	if (!logo_active)
397 		/* Clear the area behing the string */
398 		newport_render_background(xpos, ypos,
399 					  xpos + ((count - 1) << 3), ypos,
400 					  (charattr & 0xf0) >> 4);
401 
402 	newport_wait(npregs);
403 
404 	/* Set the color and drawing mode. */
405 	npregs->set.colori = charattr & 0xf;
406 	npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
407 				 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
408 				 NPORT_DMODE0_L32);
409 
410 	for (i = 0; i < count; i++, xpos += 8) {
411 		p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
412 
413 		newport_wait(npregs);
414 
415 		/* Set coordinates for bitmap operation. */
416 		npregs->set.xystarti =
417 		    (xpos << 16) | ((ypos + topscan) & 0x3ff);
418 		npregs->set.xyendi = ((xpos + 7) << 16);
419 
420 		/* Go, baby, go... */
421 		RENDER(npregs, p);
422 	}
423 }
424 
425 static void newport_cursor(struct vc_data *vc, int mode)
426 {
427 	unsigned short treg;
428 	int xcurs, ycurs;
429 
430 	switch (mode) {
431 	case CM_ERASE:
432 		treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
433 		newport_vc2_set(npregs, VC2_IREG_CONTROL,
434 				(treg & ~(VC2_CTRL_ECDISP)));
435 		break;
436 
437 	case CM_MOVE:
438 	case CM_DRAW:
439 		treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
440 		newport_vc2_set(npregs, VC2_IREG_CONTROL,
441 				(treg | VC2_CTRL_ECDISP));
442 		xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
443 		ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
444 		xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
445 		newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
446 		newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
447 	}
448 }
449 
450 static int newport_switch(struct vc_data *vc)
451 {
452 	static int logo_drawn = 0;
453 
454 	topscan = 0;
455 	npregs->cset.topscan = 0x3ff;
456 
457 	if (!logo_drawn) {
458 		newport_show_logo();
459 		logo_drawn = 1;
460 		logo_active = 1;
461 	}
462 
463 	return 1;
464 }
465 
466 static int newport_blank(struct vc_data *c, int blank, int mode_switch)
467 {
468 	unsigned short treg;
469 
470 	if (blank == 0) {
471 		/* unblank console */
472 		treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
473 		newport_vc2_set(npregs, VC2_IREG_CONTROL,
474 				(treg | VC2_CTRL_EDISP));
475 	} else {
476 		/* blank console */
477 		treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
478 		newport_vc2_set(npregs, VC2_IREG_CONTROL,
479 				(treg & ~(VC2_CTRL_EDISP)));
480 	}
481 	return 1;
482 }
483 
484 static int newport_set_font(int unit, struct console_font *op)
485 {
486 	int w = op->width;
487 	int h = op->height;
488 	int size = h * op->charcount;
489 	int i;
490 	unsigned char *new_data, *data = op->data, *p;
491 
492 	/* ladis: when I grow up, there will be a day... and more sizes will
493 	 * be supported ;-) */
494 	if ((w != 8) || (h != 16)
495 	    || (op->charcount != 256 && op->charcount != 512))
496 		return -EINVAL;
497 
498 	if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
499 	     GFP_USER))) return -ENOMEM;
500 
501 	new_data += FONT_EXTRA_WORDS * sizeof(int);
502 	FNTSIZE(new_data) = size;
503 	FNTCHARCNT(new_data) = op->charcount;
504 	REFCOUNT(new_data) = 0;	/* usage counter */
505 
506 	p = new_data;
507 	for (i = 0; i < op->charcount; i++) {
508 		memcpy(p, data, h);
509 		data += 32;
510 		p += h;
511 	}
512 
513 	/* check if font is already used by other console */
514 	for (i = 0; i < MAX_NR_CONSOLES; i++) {
515 		if (font_data[i] != FONT_DATA
516 		    && FNTSIZE(font_data[i]) == size
517 		    && !memcmp(font_data[i], new_data, size)) {
518 			kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
519 			/* current font is the same as the new one */
520 			if (i == unit)
521 				return 0;
522 			new_data = font_data[i];
523 			break;
524 		}
525 	}
526 	/* old font is user font */
527 	if (font_data[unit] != FONT_DATA) {
528 		if (--REFCOUNT(font_data[unit]) == 0)
529 			kfree(font_data[unit] -
530 			      FONT_EXTRA_WORDS * sizeof(int));
531 	}
532 	REFCOUNT(new_data)++;
533 	font_data[unit] = new_data;
534 
535 	return 0;
536 }
537 
538 static int newport_set_def_font(int unit, struct console_font *op)
539 {
540 	if (font_data[unit] != FONT_DATA) {
541 		if (--REFCOUNT(font_data[unit]) == 0)
542 			kfree(font_data[unit] -
543 			      FONT_EXTRA_WORDS * sizeof(int));
544 		font_data[unit] = FONT_DATA;
545 	}
546 
547 	return 0;
548 }
549 
550 static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
551 {
552 	return newport_set_def_font(vc->vc_num, op);
553 }
554 
555 static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
556 {
557 	return newport_set_font(vc->vc_num, font);
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(npregs);
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_set	  = newport_font_set,
721 	.con_font_default = newport_font_default,
722 	.con_set_palette  = newport_set_palette,
723 	.con_scrolldelta  = newport_scrolldelta,
724 	.con_set_origin	  = DUMMY,
725 	.con_save_screen  = DUMMY
726 };
727 
728 #ifdef MODULE
729 static int __init newport_console_init(void)
730 {
731 	return take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
732 }
733 
734 static void __exit newport_console_exit(void)
735 {
736 	give_up_console(&newport_con);
737 	iounmap((void *)npregs);
738 }
739 
740 module_init(newport_console_init);
741 module_exit(newport_console_exit);
742 #endif
743 
744 MODULE_LICENSE("GPL");
745