OMAPDSS: VENC: fix NULL pointer dereference in DSS2 VENC sysfs debug attr on OMAP4
[zen-stable.git] / drivers / video / console / newport_con.c
bloba122d9287d1659e60ad35f1b1cdf6bd8121366e6
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 (davem@davemloft.net)
10 * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/kd.h>
16 #include <linux/selection.h>
17 #include <linux/console.h>
18 #include <linux/vt_kern.h>
19 #include <linux/mm.h>
20 #include <linux/module.h>
21 #include <linux/slab.h>
23 #include <asm/io.h>
24 #include <asm/uaccess.h>
25 #include <asm/system.h>
26 #include <asm/page.h>
27 #include <asm/pgtable.h>
28 #include <asm/gio_device.h>
30 #include <video/newport.h>
32 #include <linux/linux_logo.h>
33 #include <linux/font.h>
35 #define FONT_DATA ((unsigned char *)font_vga_8x16.data)
37 /* borrowed from fbcon.c */
38 #define REFCOUNT(fd) (((int *)(fd))[-1])
39 #define FNTSIZE(fd) (((int *)(fd))[-2])
40 #define FNTCHARCNT(fd) (((int *)(fd))[-3])
41 #define FONT_EXTRA_WORDS 3
43 static unsigned char *font_data[MAX_NR_CONSOLES];
45 static struct newport_regs *npregs;
47 static int logo_active;
48 static int topscan;
49 static int xcurs_correction = 29;
50 static int newport_xsize;
51 static int newport_ysize;
52 static int newport_has_init;
54 static int newport_set_def_font(int unit, struct console_font *op);
56 #define BMASK(c) (c << 24)
58 #define RENDER(regs, cp) do { \
59 (regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \
60 (regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \
61 (regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \
62 (regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \
63 (regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \
64 (regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \
65 (regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \
66 (regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \
67 } while(0)
69 #define TESTVAL 0xdeadbeef
70 #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
72 static inline void newport_render_background(int xstart, int ystart,
73 int xend, int yend, int ci)
75 newport_wait(npregs);
76 npregs->set.wrmask = 0xffffffff;
77 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
78 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
79 | NPORT_DMODE0_STOPY);
80 npregs->set.colori = ci;
81 npregs->set.xystarti =
82 (xstart << 16) | ((ystart + topscan) & 0x3ff);
83 npregs->go.xyendi =
84 ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
87 static inline void newport_init_cmap(void)
89 unsigned short i;
91 for (i = 0; i < 16; i++) {
92 newport_bfwait(npregs);
93 newport_cmap_setaddr(npregs, color_table[i]);
94 newport_cmap_setrgb(npregs,
95 default_red[i],
96 default_grn[i], default_blu[i]);
100 static const struct linux_logo *newport_show_logo(void)
102 #ifdef CONFIG_LOGO_SGI_CLUT224
103 const struct linux_logo *logo = fb_find_logo(8);
104 const unsigned char *clut;
105 const unsigned char *data;
106 unsigned long i;
108 if (!logo)
109 return NULL;
110 clut = logo->clut;
111 data = logo->data;
113 for (i = 0; i < logo->clutsize; i++) {
114 newport_bfwait(npregs);
115 newport_cmap_setaddr(npregs, i + 0x20);
116 newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]);
117 clut += 3;
120 newport_wait(npregs);
121 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
122 NPORT_DMODE0_CHOST);
124 npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0);
125 npregs->set.xyendi = ((newport_xsize - 1) << 16);
126 newport_wait(npregs);
128 for (i = 0; i < logo->width*logo->height; i++)
129 npregs->go.hostrw0 = *data++ << 24;
131 return logo;
132 #endif /* CONFIG_LOGO_SGI_CLUT224 */
135 static inline void newport_clear_screen(int xstart, int ystart, int xend,
136 int yend, int ci)
138 if (logo_active)
139 return;
141 newport_wait(npregs);
142 npregs->set.wrmask = 0xffffffff;
143 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
144 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
145 | NPORT_DMODE0_STOPY);
146 npregs->set.colori = ci;
147 npregs->set.xystarti = (xstart << 16) | ystart;
148 npregs->go.xyendi = (xend << 16) | yend;
151 static inline void newport_clear_lines(int ystart, int yend, int ci)
153 ystart = ((ystart << 4) + topscan) & 0x3ff;
154 yend = ((yend << 4) + topscan + 15) & 0x3ff;
155 newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
158 static void newport_reset(void)
160 unsigned short treg;
161 int i;
163 newport_wait(npregs);
164 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
165 newport_vc2_set(npregs, VC2_IREG_CONTROL,
166 (treg | VC2_CTRL_EVIDEO));
168 treg = newport_vc2_get(npregs, VC2_IREG_CENTRY);
169 newport_vc2_set(npregs, VC2_IREG_RADDR, treg);
170 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
171 NPORT_DMODE_W2 | VC2_PROTOCOL);
172 for (i = 0; i < 128; i++) {
173 newport_bfwait(npregs);
174 if (i == 92 || i == 94)
175 npregs->set.dcbdata0.byshort.s1 = 0xff00;
176 else
177 npregs->set.dcbdata0.byshort.s1 = 0x0000;
180 newport_init_cmap();
182 /* turn off popup plane */
183 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
184 XM9_CRS_CONFIG | NPORT_DMODE_W1);
185 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
186 npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL |
187 XM9_CRS_CONFIG | NPORT_DMODE_W1);
188 npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
190 topscan = 0;
191 npregs->cset.topscan = 0x3ff;
192 npregs->cset.xywin = (4096 << 16) | 4096;
194 /* Clear the screen. */
195 newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
199 * calculate the actual screen size by reading
200 * the video timing out of the VC2
202 static void newport_get_screensize(void)
204 int i, cols;
205 unsigned short ventry, treg;
206 unsigned short linetable[128]; /* should be enough */
208 ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY);
209 newport_vc2_set(npregs, VC2_IREG_RADDR, ventry);
210 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
211 NPORT_DMODE_W2 | VC2_PROTOCOL);
212 for (i = 0; i < 128; i++) {
213 newport_bfwait(npregs);
214 linetable[i] = npregs->set.dcbdata0.byshort.s1;
217 newport_xsize = newport_ysize = 0;
218 for (i = 0; i < ARRAY_SIZE(linetable) - 1 && linetable[i + 1]; i += 2) {
219 cols = 0;
220 newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]);
221 npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
222 NPORT_DMODE_W2 | VC2_PROTOCOL);
223 do {
224 newport_bfwait(npregs);
225 treg = npregs->set.dcbdata0.byshort.s1;
226 if ((treg & 1) == 0)
227 cols += (treg >> 7) & 0xfe;
228 if ((treg & 0x80) == 0) {
229 newport_bfwait(npregs);
230 treg = npregs->set.dcbdata0.byshort.s1;
232 } while ((treg & 0x8000) == 0);
233 if (cols) {
234 if (cols > newport_xsize)
235 newport_xsize = cols;
236 newport_ysize += linetable[i + 1];
239 printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
242 static void newport_get_revisions(void)
244 unsigned int tmp;
245 unsigned int board_rev;
246 unsigned int rex3_rev;
247 unsigned int vc2_rev;
248 unsigned int cmap_rev;
249 unsigned int xmap9_rev;
250 unsigned int bt445_rev;
251 unsigned int bitplanes;
253 rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
255 npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
256 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
257 tmp = npregs->set.dcbdata0.bybytes.b3;
258 cmap_rev = tmp & 7;
259 board_rev = (tmp >> 4) & 7;
260 bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
262 npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL |
263 NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
264 tmp = npregs->set.dcbdata0.bybytes.b3;
265 if ((tmp & 7) < cmap_rev)
266 cmap_rev = (tmp & 7);
268 vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
270 npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
271 XM9_CRS_REVISION | NPORT_DMODE_W1);
272 xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7;
274 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
275 BT445_CSR_ADDR_REG | NPORT_DMODE_W1);
276 npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG;
277 npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
278 BT445_CSR_REVISION | NPORT_DMODE_W1);
279 bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a;
281 #define L(a) (char)('A'+(a))
282 printk
283 ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n",
284 board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev),
285 L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev));
286 #undef L
288 if (board_rev == 3) /* I don't know all affected revisions */
289 xcurs_correction = 21;
292 static void newport_exit(void)
294 int i;
296 /* free memory used by user font */
297 for (i = 0; i < MAX_NR_CONSOLES; i++)
298 newport_set_def_font(i, NULL);
301 /* Can't be __init, take_over_console may call it later */
302 static const char *newport_startup(void)
304 int i;
306 npregs->cset.config = NPORT_CFG_GD0;
308 if (newport_wait(npregs))
309 goto out_unmap;
311 npregs->set.xstarti = TESTVAL;
312 if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
313 goto out_unmap;
315 for (i = 0; i < MAX_NR_CONSOLES; i++)
316 font_data[i] = FONT_DATA;
318 newport_reset();
319 newport_get_revisions();
320 newport_get_screensize();
321 newport_has_init = 1;
323 return "SGI Newport";
325 out_unmap:
326 return NULL;
329 static void newport_init(struct vc_data *vc, int init)
331 vc->vc_cols = newport_xsize / 8;
332 vc->vc_rows = newport_ysize / 16;
333 vc->vc_can_do_color = 1;
336 static void newport_deinit(struct vc_data *c)
338 if (!con_is_bound(&newport_con) && newport_has_init) {
339 newport_exit();
340 newport_has_init = 0;
344 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
345 int width)
347 int xend = ((sx + width) << 3) - 1;
348 int ystart = ((sy << 4) + topscan) & 0x3ff;
349 int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
351 if (logo_active)
352 return;
354 if (ystart < yend) {
355 newport_clear_screen(sx << 3, ystart, xend, yend,
356 (vc->vc_color & 0xf0) >> 4);
357 } else {
358 newport_clear_screen(sx << 3, ystart, xend, 1023,
359 (vc->vc_color & 0xf0) >> 4);
360 newport_clear_screen(sx << 3, 0, xend, yend,
361 (vc->vc_color & 0xf0) >> 4);
365 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
366 int xpos)
368 unsigned char *p;
370 p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
371 charattr = (charattr >> 8) & 0xff;
372 xpos <<= 3;
373 ypos <<= 4;
375 newport_render_background(xpos, ypos, xpos, ypos,
376 (charattr & 0xf0) >> 4);
378 /* Set the color and drawing mode. */
379 newport_wait(npregs);
380 npregs->set.colori = charattr & 0xf;
381 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
382 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
383 NPORT_DMODE0_L32);
385 /* Set coordinates for bitmap operation. */
386 npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
387 npregs->set.xyendi = ((xpos + 7) << 16);
388 newport_wait(npregs);
390 /* Go, baby, go... */
391 RENDER(npregs, p);
394 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
395 int count, int ypos, int xpos)
397 int i;
398 int charattr;
399 unsigned char *p;
401 charattr = (scr_readw(s) >> 8) & 0xff;
403 xpos <<= 3;
404 ypos <<= 4;
406 if (!logo_active)
407 /* Clear the area behing the string */
408 newport_render_background(xpos, ypos,
409 xpos + ((count - 1) << 3), ypos,
410 (charattr & 0xf0) >> 4);
412 newport_wait(npregs);
414 /* Set the color and drawing mode. */
415 npregs->set.colori = charattr & 0xf;
416 npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
417 NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
418 NPORT_DMODE0_L32);
420 for (i = 0; i < count; i++, xpos += 8) {
421 p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
423 newport_wait(npregs);
425 /* Set coordinates for bitmap operation. */
426 npregs->set.xystarti =
427 (xpos << 16) | ((ypos + topscan) & 0x3ff);
428 npregs->set.xyendi = ((xpos + 7) << 16);
430 /* Go, baby, go... */
431 RENDER(npregs, p);
435 static void newport_cursor(struct vc_data *vc, int mode)
437 unsigned short treg;
438 int xcurs, ycurs;
440 switch (mode) {
441 case CM_ERASE:
442 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
443 newport_vc2_set(npregs, VC2_IREG_CONTROL,
444 (treg & ~(VC2_CTRL_ECDISP)));
445 break;
447 case CM_MOVE:
448 case CM_DRAW:
449 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
450 newport_vc2_set(npregs, VC2_IREG_CONTROL,
451 (treg | VC2_CTRL_ECDISP));
452 xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
453 ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
454 xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
455 newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
456 newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
460 static int newport_switch(struct vc_data *vc)
462 static int logo_drawn = 0;
464 topscan = 0;
465 npregs->cset.topscan = 0x3ff;
467 if (!logo_drawn) {
468 if (newport_show_logo()) {
469 logo_drawn = 1;
470 logo_active = 1;
474 return 1;
477 static int newport_blank(struct vc_data *c, int blank, int mode_switch)
479 unsigned short treg;
481 if (blank == 0) {
482 /* unblank console */
483 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
484 newport_vc2_set(npregs, VC2_IREG_CONTROL,
485 (treg | VC2_CTRL_EDISP));
486 } else {
487 /* blank console */
488 treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
489 newport_vc2_set(npregs, VC2_IREG_CONTROL,
490 (treg & ~(VC2_CTRL_EDISP)));
492 return 1;
495 static int newport_set_font(int unit, struct console_font *op)
497 int w = op->width;
498 int h = op->height;
499 int size = h * op->charcount;
500 int i;
501 unsigned char *new_data, *data = op->data, *p;
503 /* ladis: when I grow up, there will be a day... and more sizes will
504 * be supported ;-) */
505 if ((w != 8) || (h != 16)
506 || (op->charcount != 256 && op->charcount != 512))
507 return -EINVAL;
509 if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
510 GFP_USER))) return -ENOMEM;
512 new_data += FONT_EXTRA_WORDS * sizeof(int);
513 FNTSIZE(new_data) = size;
514 FNTCHARCNT(new_data) = op->charcount;
515 REFCOUNT(new_data) = 0; /* usage counter */
517 p = new_data;
518 for (i = 0; i < op->charcount; i++) {
519 memcpy(p, data, h);
520 data += 32;
521 p += h;
524 /* check if font is already used by other console */
525 for (i = 0; i < MAX_NR_CONSOLES; i++) {
526 if (font_data[i] != FONT_DATA
527 && FNTSIZE(font_data[i]) == size
528 && !memcmp(font_data[i], new_data, size)) {
529 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
530 /* current font is the same as the new one */
531 if (i == unit)
532 return 0;
533 new_data = font_data[i];
534 break;
537 /* old font is user font */
538 if (font_data[unit] != FONT_DATA) {
539 if (--REFCOUNT(font_data[unit]) == 0)
540 kfree(font_data[unit] -
541 FONT_EXTRA_WORDS * sizeof(int));
543 REFCOUNT(new_data)++;
544 font_data[unit] = new_data;
546 return 0;
549 static int newport_set_def_font(int unit, struct console_font *op)
551 if (font_data[unit] != FONT_DATA) {
552 if (--REFCOUNT(font_data[unit]) == 0)
553 kfree(font_data[unit] -
554 FONT_EXTRA_WORDS * sizeof(int));
555 font_data[unit] = FONT_DATA;
558 return 0;
561 static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
563 return newport_set_def_font(vc->vc_num, op);
566 static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
568 return newport_set_font(vc->vc_num, font);
571 static int newport_set_palette(struct vc_data *vc, unsigned char *table)
573 return -EINVAL;
576 static int newport_scrolldelta(struct vc_data *vc, int lines)
578 /* there is (nearly) no off-screen memory, so we can't scroll back */
579 return 0;
582 static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
583 int lines)
585 int count, x, y;
586 unsigned short *s, *d;
587 unsigned short chattr;
589 logo_active = 0; /* it's time to disable the logo now.. */
591 if (t == 0 && b == vc->vc_rows) {
592 if (dir == SM_UP) {
593 topscan = (topscan + (lines << 4)) & 0x3ff;
594 newport_clear_lines(vc->vc_rows - lines,
595 vc->vc_rows - 1,
596 (vc->vc_color & 0xf0) >> 4);
597 } else {
598 topscan = (topscan + (-lines << 4)) & 0x3ff;
599 newport_clear_lines(0, lines - 1,
600 (vc->vc_color & 0xf0) >> 4);
602 npregs->cset.topscan = (topscan - 1) & 0x3ff;
603 return 0;
606 count = (b - t - lines) * vc->vc_cols;
607 if (dir == SM_UP) {
608 x = 0;
609 y = t;
610 s = (unsigned short *) (vc->vc_origin +
611 vc->vc_size_row * (t + lines));
612 d = (unsigned short *) (vc->vc_origin +
613 vc->vc_size_row * t);
614 while (count--) {
615 chattr = scr_readw(s++);
616 if (chattr != scr_readw(d)) {
617 newport_putc(vc, chattr, y, x);
618 scr_writew(chattr, d);
620 d++;
621 if (++x == vc->vc_cols) {
622 x = 0;
623 y++;
626 d = (unsigned short *) (vc->vc_origin +
627 vc->vc_size_row * (b - lines));
628 x = 0;
629 y = b - lines;
630 for (count = 0; count < (lines * vc->vc_cols); count++) {
631 if (scr_readw(d) != vc->vc_video_erase_char) {
632 newport_putc(vc, vc->vc_video_erase_char,
633 y, x);
634 scr_writew(vc->vc_video_erase_char, d);
636 d++;
637 if (++x == vc->vc_cols) {
638 x = 0;
639 y++;
642 } else {
643 x = vc->vc_cols - 1;
644 y = b - 1;
645 s = (unsigned short *) (vc->vc_origin +
646 vc->vc_size_row * (b - lines) - 2);
647 d = (unsigned short *) (vc->vc_origin +
648 vc->vc_size_row * b - 2);
649 while (count--) {
650 chattr = scr_readw(s--);
651 if (chattr != scr_readw(d)) {
652 newport_putc(vc, chattr, y, x);
653 scr_writew(chattr, d);
655 d--;
656 if (x-- == 0) {
657 x = vc->vc_cols - 1;
658 y--;
661 d = (unsigned short *) (vc->vc_origin +
662 vc->vc_size_row * t);
663 x = 0;
664 y = t;
665 for (count = 0; count < (lines * vc->vc_cols); count++) {
666 if (scr_readw(d) != vc->vc_video_erase_char) {
667 newport_putc(vc, vc->vc_video_erase_char,
668 y, x);
669 scr_writew(vc->vc_video_erase_char, d);
671 d++;
672 if (++x == vc->vc_cols) {
673 x = 0;
674 y++;
678 return 1;
681 static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
682 int dx, int h, int w)
684 short xs, ys, xe, ye, xoffs, yoffs, tmp;
686 xs = sx << 3;
687 xe = ((sx + w) << 3) - 1;
689 * as bmove is only used to move stuff around in the same line
690 * (h == 1), we don't care about wrap arounds caused by topscan != 0
692 ys = ((sy << 4) + topscan) & 0x3ff;
693 ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
694 xoffs = (dx - sx) << 3;
695 yoffs = (dy - sy) << 4;
696 if (xoffs > 0) {
697 /* move to the right, exchange starting points */
698 tmp = xe;
699 xe = xs;
700 xs = tmp;
702 newport_wait(npregs);
703 npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK |
704 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
705 | NPORT_DMODE0_STOPY);
706 npregs->set.xystarti = (xs << 16) | ys;
707 npregs->set.xyendi = (xe << 16) | ye;
708 npregs->go.xymove = (xoffs << 16) | yoffs;
711 static int newport_dummy(struct vc_data *c)
713 return 0;
716 #define DUMMY (void *) newport_dummy
718 const struct consw newport_con = {
719 .owner = THIS_MODULE,
720 .con_startup = newport_startup,
721 .con_init = newport_init,
722 .con_deinit = newport_deinit,
723 .con_clear = newport_clear,
724 .con_putc = newport_putc,
725 .con_putcs = newport_putcs,
726 .con_cursor = newport_cursor,
727 .con_scroll = newport_scroll,
728 .con_bmove = newport_bmove,
729 .con_switch = newport_switch,
730 .con_blank = newport_blank,
731 .con_font_set = newport_font_set,
732 .con_font_default = newport_font_default,
733 .con_set_palette = newport_set_palette,
734 .con_scrolldelta = newport_scrolldelta,
735 .con_set_origin = DUMMY,
736 .con_save_screen = DUMMY
739 static int newport_probe(struct gio_device *dev,
740 const struct gio_device_id *id)
742 unsigned long newport_addr;
744 if (!dev->resource.start)
745 return -EINVAL;
747 if (npregs)
748 return -EBUSY; /* we only support one Newport as console */
750 newport_addr = dev->resource.start + 0xF0000;
751 if (!request_mem_region(newport_addr, 0x10000, "Newport"))
752 return -ENODEV;
754 npregs = (struct newport_regs *)/* ioremap cannot fail */
755 ioremap(newport_addr, sizeof(struct newport_regs));
757 return take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
760 static void newport_remove(struct gio_device *dev)
762 give_up_console(&newport_con);
763 iounmap((void *)npregs);
766 static struct gio_device_id newport_ids[] = {
767 { .id = 0x7e },
768 { .id = 0xff }
771 MODULE_ALIAS("gio:7e");
773 static struct gio_driver newport_driver = {
774 .name = "newport",
775 .id_table = newport_ids,
776 .probe = newport_probe,
777 .remove = newport_remove,
780 int __init newport_console_init(void)
782 return gio_register_driver(&newport_driver);
785 void __exit newport_console_exit(void)
787 gio_unregister_driver(&newport_driver);
790 module_init(newport_console_init);
791 module_exit(newport_console_exit);
793 MODULE_LICENSE("GPL");