blob: f45de374f165f674372e7d3a2828f96f929ff8f4 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * newport_con.c: Abscon for newport hardware
4 *
5 * (C) 1998 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
6 * (C) 1999 Ulf Carlsson (ulfc@thepuffingruop.com)
7 *
8 * This driver is based on sgicons.c and cons_newport.
9 *
10 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
11 * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
12 */
13#include <linux/init.h>
14#include <linux/kernel.h>
15#include <linux/errno.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 <linux/uaccess.h>
26#include <asm/page.h>
27#include <asm/pgtable.h>
28#include <asm/gio_device.h>
29
30#include <video/newport.h>
31
32#include <linux/linux_logo.h>
33#include <linux/font.h>
34
35#define NEWPORT_LEN 0x10000
36
37#define FONT_DATA ((unsigned char *)font_vga_8x16.data)
38
39static unsigned char *font_data[MAX_NR_CONSOLES];
40
41static struct newport_regs *npregs;
42static unsigned long newport_addr;
43
44static int logo_active;
45static int topscan;
46static int xcurs_correction = 29;
47static int newport_xsize;
48static int newport_ysize;
49static int newport_has_init;
50
51static int newport_set_def_font(int unit, struct console_font *op);
52
53#define BMASK(c) (c << 24)
54
55#define RENDER(regs, cp) do { \
56(regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \
57(regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \
58(regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \
59(regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \
60(regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \
61(regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \
62(regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \
63(regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \
64} while(0)
65
66#define TESTVAL 0xdeadbeef
67#define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
68
69static inline void newport_render_background(int xstart, int ystart,
70 int xend, int yend, int ci)
71{
72 newport_wait(npregs);
73 npregs->set.wrmask = 0xffffffff;
74 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
75 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
76 | NPORT_DMODE0_STOPY);
77 npregs->set.colori = ci;
78 npregs->set.xystarti =
79 (xstart << 16) | ((ystart + topscan) & 0x3ff);
80 npregs->go.xyendi =
81 ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
82}
83
84static inline void newport_init_cmap(void)
85{
86 unsigned short i;
87
88 for (i = 0; i < 16; i++) {
89 newport_bfwait(npregs);
90 newport_cmap_setaddr(npregs, color_table[i]);
91 newport_cmap_setrgb(npregs,
92 default_red[i],
93 default_grn[i], default_blu[i]);
94 }
95}
96
97static const struct linux_logo *newport_show_logo(void)
98{
99#ifdef CONFIG_LOGO_SGI_CLUT224
100 const struct linux_logo *logo = fb_find_logo(8);
101 const unsigned char *clut;
102 const unsigned char *data;
103 unsigned long i;
104
105 if (!logo)
106 return NULL;
107 clut = logo->clut;
108 data = logo->data;
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
128 return logo;
129#endif /* CONFIG_LOGO_SGI_CLUT224 */
130}
131
132static inline void newport_clear_screen(int xstart, int ystart, int xend,
133 int yend, int ci)
134{
135 if (logo_active)
136 return;
137
138 newport_wait(npregs);
139 npregs->set.wrmask = 0xffffffff;
140 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
141 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
142 | NPORT_DMODE0_STOPY);
143 npregs->set.colori = ci;
144 npregs->set.xystarti = (xstart << 16) | ystart;
145 npregs->go.xyendi = (xend << 16) | yend;
146}
147
148static inline void newport_clear_lines(int ystart, int yend, int ci)
149{
150 ystart = ((ystart << 4) + topscan) & 0x3ff;
151 yend = ((yend << 4) + topscan + 15) & 0x3ff;
152 newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
153}
154
155static void newport_reset(void)
156{
157 unsigned short treg;
158 int i;
159
160 newport_wait(npregs);
161 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
162 newport_vc2_set(npregs, VC2_IREG_CONTROL,
163 (treg | VC2_CTRL_EVIDEO));
164
165 treg = newport_vc2_get(npregs, VC2_IREG_CENTRY);
166 newport_vc2_set(npregs, VC2_IREG_RADDR, treg);
167 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
168 NPORT_DMODE_W2 | VC2_PROTOCOL);
169 for (i = 0; i < 128; i++) {
170 newport_bfwait(npregs);
171 if (i == 92 || i == 94)
172 npregs->set.dcbdata0.byshort.s1 = 0xff00;
173 else
174 npregs->set.dcbdata0.byshort.s1 = 0x0000;
175 }
176
177 newport_init_cmap();
178
179 /* turn off popup plane */
180 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
181 XM9_CRS_CONFIG | NPORT_DMODE_W1);
182 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
183 npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL |
184 XM9_CRS_CONFIG | NPORT_DMODE_W1);
185 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
186
187 topscan = 0;
188 npregs->cset.topscan = 0x3ff;
189 npregs->cset.xywin = (4096 << 16) | 4096;
190
191 /* Clear the screen. */
192 newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
193}
194
195/*
196 * calculate the actual screen size by reading
197 * the video timing out of the VC2
198 */
199static void newport_get_screensize(void)
200{
201 int i, cols;
202 unsigned short ventry, treg;
203 unsigned short linetable[128]; /* should be enough */
204
205 ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY);
206 newport_vc2_set(npregs, VC2_IREG_RADDR, ventry);
207 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
208 NPORT_DMODE_W2 | VC2_PROTOCOL);
209 for (i = 0; i < 128; i++) {
210 newport_bfwait(npregs);
211 linetable[i] = npregs->set.dcbdata0.byshort.s1;
212 }
213
214 newport_xsize = newport_ysize = 0;
215 for (i = 0; i < ARRAY_SIZE(linetable) - 1 && linetable[i + 1]; i += 2) {
216 cols = 0;
217 newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]);
218 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
219 NPORT_DMODE_W2 | VC2_PROTOCOL);
220 do {
221 newport_bfwait(npregs);
222 treg = npregs->set.dcbdata0.byshort.s1;
223 if ((treg & 1) == 0)
224 cols += (treg >> 7) & 0xfe;
225 if ((treg & 0x80) == 0) {
226 newport_bfwait(npregs);
227 treg = npregs->set.dcbdata0.byshort.s1;
228 }
229 } while ((treg & 0x8000) == 0);
230 if (cols) {
231 if (cols > newport_xsize)
232 newport_xsize = cols;
233 newport_ysize += linetable[i + 1];
234 }
235 }
236 printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
237}
238
239static void newport_get_revisions(void)
240{
241 unsigned int tmp;
242 unsigned int board_rev;
243 unsigned int rex3_rev;
244 unsigned int vc2_rev;
245 unsigned int cmap_rev;
246 unsigned int xmap9_rev;
247 unsigned int bt445_rev;
248 unsigned int bitplanes;
249
250 rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
251
252 npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
253 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
254 tmp = npregs->set.dcbdata0.bybytes.b3;
255 cmap_rev = tmp & 7;
256 board_rev = (tmp >> 4) & 7;
257 bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
258
259 npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL |
260 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
261 tmp = npregs->set.dcbdata0.bybytes.b3;
262 if ((tmp & 7) < cmap_rev)
263 cmap_rev = (tmp & 7);
264
265 vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
266
267 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
268 XM9_CRS_REVISION | NPORT_DMODE_W1);
269 xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7;
270
271 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
272 BT445_CSR_ADDR_REG | NPORT_DMODE_W1);
273 npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG;
274 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
275 BT445_CSR_REVISION | NPORT_DMODE_W1);
276 bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a;
277
278#define L(a) (char)('A'+(a))
279 printk
280 ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n",
281 board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev),
282 L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev));
283#undef L
284
285 if (board_rev == 3) /* I don't know all affected revisions */
286 xcurs_correction = 21;
287}
288
289static void newport_exit(void)
290{
291 int i;
292
293 /* free memory used by user font */
294 for (i = 0; i < MAX_NR_CONSOLES; i++)
295 newport_set_def_font(i, NULL);
296}
297
298/* Can't be __init, do_take_over_console may call it later */
299static const char *newport_startup(void)
300{
301 int i;
302
303 npregs->cset.config = NPORT_CFG_GD0;
304
305 if (newport_wait(npregs))
306 goto out_unmap;
307
308 npregs->set.xstarti = TESTVAL;
309 if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
310 goto out_unmap;
311
312 for (i = 0; i < MAX_NR_CONSOLES; i++)
313 font_data[i] = FONT_DATA;
314
315 newport_reset();
316 newport_get_revisions();
317 newport_get_screensize();
318 newport_has_init = 1;
319
320 return "SGI Newport";
321
322out_unmap:
323 return NULL;
324}
325
326static void newport_init(struct vc_data *vc, int init)
327{
328 int cols, rows;
329
330 cols = newport_xsize / 8;
331 rows = newport_ysize / 16;
332 vc->vc_can_do_color = 1;
333 if (init) {
334 vc->vc_cols = cols;
335 vc->vc_rows = rows;
336 } else
337 vc_resize(vc, cols, rows);
338}
339
340static void newport_deinit(struct vc_data *c)
341{
342 if (!con_is_bound(&newport_con) && newport_has_init) {
343 newport_exit();
344 newport_has_init = 0;
345 }
346}
347
348static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
349 int width)
350{
351 int xend = ((sx + width) << 3) - 1;
352 int ystart = ((sy << 4) + topscan) & 0x3ff;
353 int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
354
355 if (logo_active)
356 return;
357
358 if (ystart < yend) {
359 newport_clear_screen(sx << 3, ystart, xend, yend,
360 (vc->vc_color & 0xf0) >> 4);
361 } else {
362 newport_clear_screen(sx << 3, ystart, xend, 1023,
363 (vc->vc_color & 0xf0) >> 4);
364 newport_clear_screen(sx << 3, 0, xend, yend,
365 (vc->vc_color & 0xf0) >> 4);
366 }
367}
368
369static void newport_putc(struct vc_data *vc, int charattr, int ypos,
370 int xpos)
371{
372 unsigned char *p;
373
374 p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
375 charattr = (charattr >> 8) & 0xff;
376 xpos <<= 3;
377 ypos <<= 4;
378
379 newport_render_background(xpos, ypos, xpos, ypos,
380 (charattr & 0xf0) >> 4);
381
382 /* Set the color and drawing mode. */
383 newport_wait(npregs);
384 npregs->set.colori = charattr & 0xf;
385 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
386 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
387 NPORT_DMODE0_L32);
388
389 /* Set coordinates for bitmap operation. */
390 npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
391 npregs->set.xyendi = ((xpos + 7) << 16);
392 newport_wait(npregs);
393
394 /* Go, baby, go... */
395 RENDER(npregs, p);
396}
397
398static void newport_putcs(struct vc_data *vc, const unsigned short *s,
399 int count, int ypos, int xpos)
400{
401 int i;
402 int charattr;
403 unsigned char *p;
404
405 charattr = (scr_readw(s) >> 8) & 0xff;
406
407 xpos <<= 3;
408 ypos <<= 4;
409
410 if (!logo_active)
411 /* Clear the area behing the string */
412 newport_render_background(xpos, ypos,
413 xpos + ((count - 1) << 3), ypos,
414 (charattr & 0xf0) >> 4);
415
416 newport_wait(npregs);
417
418 /* Set the color and drawing mode. */
419 npregs->set.colori = charattr & 0xf;
420 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
421 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
422 NPORT_DMODE0_L32);
423
424 for (i = 0; i < count; i++, xpos += 8) {
425 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
426
427 newport_wait(npregs);
428
429 /* Set coordinates for bitmap operation. */
430 npregs->set.xystarti =
431 (xpos << 16) | ((ypos + topscan) & 0x3ff);
432 npregs->set.xyendi = ((xpos + 7) << 16);
433
434 /* Go, baby, go... */
435 RENDER(npregs, p);
436 }
437}
438
439static void newport_cursor(struct vc_data *vc, int mode)
440{
441 unsigned short treg;
442 int xcurs, ycurs;
443
444 switch (mode) {
445 case CM_ERASE:
446 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
447 newport_vc2_set(npregs, VC2_IREG_CONTROL,
448 (treg & ~(VC2_CTRL_ECDISP)));
449 break;
450
451 case CM_MOVE:
452 case CM_DRAW:
453 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
454 newport_vc2_set(npregs, VC2_IREG_CONTROL,
455 (treg | VC2_CTRL_ECDISP));
456 xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
457 ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
458 xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
459 newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
460 newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
461 }
462}
463
464static int newport_switch(struct vc_data *vc)
465{
466 static int logo_drawn = 0;
467
468 topscan = 0;
469 npregs->cset.topscan = 0x3ff;
470
471 if (!logo_drawn) {
472 if (newport_show_logo()) {
473 logo_drawn = 1;
474 logo_active = 1;
475 }
476 }
477
478 return 1;
479}
480
481static int newport_blank(struct vc_data *c, int blank, int mode_switch)
482{
483 unsigned short treg;
484
485 if (blank == 0) {
486 /* unblank console */
487 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
488 newport_vc2_set(npregs, VC2_IREG_CONTROL,
489 (treg | VC2_CTRL_EDISP));
490 } else {
491 /* blank console */
492 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
493 newport_vc2_set(npregs, VC2_IREG_CONTROL,
494 (treg & ~(VC2_CTRL_EDISP)));
495 }
496 return 1;
497}
498
499static int newport_set_font(int unit, struct console_font *op)
500{
501 int w = op->width;
502 int h = op->height;
503 int size = h * op->charcount;
504 int i;
505 unsigned char *new_data, *data = op->data, *p;
506
507 /* ladis: when I grow up, there will be a day... and more sizes will
508 * be supported ;-) */
509 if ((w != 8) || (h != 16)
510 || (op->charcount != 256 && op->charcount != 512))
511 return -EINVAL;
512
513 if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
514 GFP_USER))) return -ENOMEM;
515
516 new_data += FONT_EXTRA_WORDS * sizeof(int);
517 FNTSIZE(new_data) = size;
518 FNTCHARCNT(new_data) = op->charcount;
519 REFCOUNT(new_data) = 0; /* usage counter */
520 FNTSUM(new_data) = 0;
521
522 p = new_data;
523 for (i = 0; i < op->charcount; i++) {
524 memcpy(p, data, h);
525 data += 32;
526 p += h;
527 }
528
529 /* check if font is already used by other console */
530 for (i = 0; i < MAX_NR_CONSOLES; i++) {
531 if (font_data[i] != FONT_DATA
532 && FNTSIZE(font_data[i]) == size
533 && !memcmp(font_data[i], new_data, size)) {
534 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
535 /* current font is the same as the new one */
536 if (i == unit)
537 return 0;
538 new_data = font_data[i];
539 break;
540 }
541 }
542 /* old font is user font */
543 if (font_data[unit] != FONT_DATA) {
544 if (--REFCOUNT(font_data[unit]) == 0)
545 kfree(font_data[unit] -
546 FONT_EXTRA_WORDS * sizeof(int));
547 }
548 REFCOUNT(new_data)++;
549 font_data[unit] = new_data;
550
551 return 0;
552}
553
554static int newport_set_def_font(int unit, struct console_font *op)
555{
556 if (font_data[unit] != FONT_DATA) {
557 if (--REFCOUNT(font_data[unit]) == 0)
558 kfree(font_data[unit] -
559 FONT_EXTRA_WORDS * sizeof(int));
560 font_data[unit] = FONT_DATA;
561 }
562
563 return 0;
564}
565
566static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
567{
568 return newport_set_def_font(vc->vc_num, op);
569}
570
571static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
572{
573 return newport_set_font(vc->vc_num, font);
574}
575
576static bool newport_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
577 enum con_scroll dir, unsigned int lines)
578{
579 int count, x, y;
580 unsigned short *s, *d;
581 unsigned short chattr;
582
583 logo_active = 0; /* it's time to disable the logo now.. */
584
585 if (t == 0 && b == vc->vc_rows) {
586 if (dir == SM_UP) {
587 topscan = (topscan + (lines << 4)) & 0x3ff;
588 newport_clear_lines(vc->vc_rows - lines,
589 vc->vc_rows - 1,
590 (vc->vc_color & 0xf0) >> 4);
591 } else {
592 topscan = (topscan + (-lines << 4)) & 0x3ff;
593 newport_clear_lines(0, lines - 1,
594 (vc->vc_color & 0xf0) >> 4);
595 }
596 npregs->cset.topscan = (topscan - 1) & 0x3ff;
597 return false;
598 }
599
600 count = (b - t - lines) * vc->vc_cols;
601 if (dir == SM_UP) {
602 x = 0;
603 y = t;
604 s = (unsigned short *) (vc->vc_origin +
605 vc->vc_size_row * (t + lines));
606 d = (unsigned short *) (vc->vc_origin +
607 vc->vc_size_row * t);
608 while (count--) {
609 chattr = scr_readw(s++);
610 if (chattr != scr_readw(d)) {
611 newport_putc(vc, chattr, y, x);
612 scr_writew(chattr, d);
613 }
614 d++;
615 if (++x == vc->vc_cols) {
616 x = 0;
617 y++;
618 }
619 }
620 d = (unsigned short *) (vc->vc_origin +
621 vc->vc_size_row * (b - lines));
622 x = 0;
623 y = b - lines;
624 for (count = 0; count < (lines * vc->vc_cols); count++) {
625 if (scr_readw(d) != vc->vc_video_erase_char) {
626 newport_putc(vc, vc->vc_video_erase_char,
627 y, x);
628 scr_writew(vc->vc_video_erase_char, d);
629 }
630 d++;
631 if (++x == vc->vc_cols) {
632 x = 0;
633 y++;
634 }
635 }
636 } else {
637 x = vc->vc_cols - 1;
638 y = b - 1;
639 s = (unsigned short *) (vc->vc_origin +
640 vc->vc_size_row * (b - lines) - 2);
641 d = (unsigned short *) (vc->vc_origin +
642 vc->vc_size_row * b - 2);
643 while (count--) {
644 chattr = scr_readw(s--);
645 if (chattr != scr_readw(d)) {
646 newport_putc(vc, chattr, y, x);
647 scr_writew(chattr, d);
648 }
649 d--;
650 if (x-- == 0) {
651 x = vc->vc_cols - 1;
652 y--;
653 }
654 }
655 d = (unsigned short *) (vc->vc_origin +
656 vc->vc_size_row * t);
657 x = 0;
658 y = t;
659 for (count = 0; count < (lines * vc->vc_cols); count++) {
660 if (scr_readw(d) != vc->vc_video_erase_char) {
661 newport_putc(vc, vc->vc_video_erase_char,
662 y, x);
663 scr_writew(vc->vc_video_erase_char, d);
664 }
665 d++;
666 if (++x == vc->vc_cols) {
667 x = 0;
668 y++;
669 }
670 }
671 }
672 return true;
673}
674
675static int newport_set_origin(struct vc_data *vc)
676{
677 return 0;
678}
679
680static void newport_save_screen(struct vc_data *vc) { }
681
682const struct consw newport_con = {
683 .owner = THIS_MODULE,
684 .con_startup = newport_startup,
685 .con_init = newport_init,
686 .con_deinit = newport_deinit,
687 .con_clear = newport_clear,
688 .con_putc = newport_putc,
689 .con_putcs = newport_putcs,
690 .con_cursor = newport_cursor,
691 .con_scroll = newport_scroll,
692 .con_switch = newport_switch,
693 .con_blank = newport_blank,
694 .con_font_set = newport_font_set,
695 .con_font_default = newport_font_default,
696 .con_set_origin = newport_set_origin,
697 .con_save_screen = newport_save_screen
698};
699
700static int newport_probe(struct gio_device *dev,
701 const struct gio_device_id *id)
702{
703 int err;
704
705 if (!dev->resource.start)
706 return -EINVAL;
707
708 if (npregs)
709 return -EBUSY; /* we only support one Newport as console */
710
711 newport_addr = dev->resource.start + 0xF0000;
712 if (!request_mem_region(newport_addr, NEWPORT_LEN, "Newport"))
713 return -ENODEV;
714
715 npregs = (struct newport_regs *)/* ioremap cannot fail */
716 ioremap(newport_addr, sizeof(struct newport_regs));
717 console_lock();
718 err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
719 console_unlock();
720
721 if (err) {
722 iounmap((void *)npregs);
723 release_mem_region(newport_addr, NEWPORT_LEN);
724 }
725 return err;
726}
727
728static void newport_remove(struct gio_device *dev)
729{
730 give_up_console(&newport_con);
731 iounmap((void *)npregs);
732 release_mem_region(newport_addr, NEWPORT_LEN);
733}
734
735static struct gio_device_id newport_ids[] = {
736 { .id = 0x7e },
737 { .id = 0xff }
738};
739
740MODULE_ALIAS("gio:7e");
741
742static struct gio_driver newport_driver = {
743 .name = "newport",
744 .id_table = newport_ids,
745 .probe = newport_probe,
746 .remove = newport_remove,
747};
748
749int __init newport_console_init(void)
750{
751 return gio_register_driver(&newport_driver);
752}
753
754void __exit newport_console_exit(void)
755{
756 gio_unregister_driver(&newport_driver);
757}
758
759module_init(newport_console_init);
760module_exit(newport_console_exit);
761
762MODULE_LICENSE("GPL");