Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * newport_con.c: Abscon for newport hardware
0004  * 
0005  * (C) 1998 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
0006  * (C) 1999 Ulf Carlsson (ulfc@thepuffingruop.com)
0007  * 
0008  * This driver is based on sgicons.c and cons_newport.
0009  * 
0010  * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
0011  * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
0012  */
0013 #include <linux/init.h>
0014 #include <linux/kernel.h>
0015 #include <linux/errno.h>
0016 #include <linux/kd.h>
0017 #include <linux/selection.h>
0018 #include <linux/console.h>
0019 #include <linux/vt_kern.h>
0020 #include <linux/mm.h>
0021 #include <linux/module.h>
0022 #include <linux/slab.h>
0023 
0024 #include <asm/io.h>
0025 #include <linux/uaccess.h>
0026 #include <asm/page.h>
0027 #include <asm/gio_device.h>
0028 
0029 #include <video/newport.h>
0030 
0031 #include <linux/linux_logo.h>
0032 #include <linux/font.h>
0033 
0034 #define NEWPORT_LEN 0x10000
0035 
0036 #define FONT_DATA ((unsigned char *)font_vga_8x16.data)
0037 
0038 static unsigned char *font_data[MAX_NR_CONSOLES];
0039 
0040 static struct newport_regs *npregs;
0041 static unsigned long newport_addr;
0042 
0043 static int logo_active;
0044 static int topscan;
0045 static int xcurs_correction = 29;
0046 static int newport_xsize;
0047 static int newport_ysize;
0048 static int newport_has_init;
0049 
0050 static int newport_set_def_font(int unit, struct console_font *op);
0051 
0052 #define BMASK(c) (c << 24)
0053 
0054 #define RENDER(regs, cp) do { \
0055 (regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \
0056 (regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \
0057 (regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \
0058 (regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \
0059 (regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \
0060 (regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \
0061 (regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \
0062 (regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \
0063 } while(0)
0064 
0065 #define TESTVAL 0xdeadbeef
0066 #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
0067 
0068 static inline void newport_render_background(int xstart, int ystart,
0069                          int xend, int yend, int ci)
0070 {
0071     newport_wait(npregs);
0072     npregs->set.wrmask = 0xffffffff;
0073     npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
0074                  NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
0075                  | NPORT_DMODE0_STOPY);
0076     npregs->set.colori = ci;
0077     npregs->set.xystarti =
0078         (xstart << 16) | ((ystart + topscan) & 0x3ff);
0079     npregs->go.xyendi =
0080         ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
0081 }
0082 
0083 static inline void newport_init_cmap(void)
0084 {
0085     unsigned short i;
0086 
0087     for (i = 0; i < 16; i++) {
0088         newport_bfwait(npregs);
0089         newport_cmap_setaddr(npregs, color_table[i]);
0090         newport_cmap_setrgb(npregs,
0091                     default_red[i],
0092                     default_grn[i], default_blu[i]);
0093     }
0094 }
0095 
0096 static const struct linux_logo *newport_show_logo(void)
0097 {
0098 #ifdef CONFIG_LOGO_SGI_CLUT224
0099     const struct linux_logo *logo = fb_find_logo(8);
0100     const unsigned char *clut;
0101     const unsigned char *data;
0102     unsigned long i;
0103 
0104     if (!logo)
0105         return NULL;
0106     clut = logo->clut;
0107     data = logo->data;
0108 
0109     for (i = 0; i < logo->clutsize; i++) {
0110         newport_bfwait(npregs);
0111         newport_cmap_setaddr(npregs, i + 0x20);
0112         newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]);
0113         clut += 3;
0114     }
0115 
0116     newport_wait(npregs);
0117     npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
0118                  NPORT_DMODE0_CHOST);
0119 
0120     npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0);
0121     npregs->set.xyendi = ((newport_xsize - 1) << 16);
0122     newport_wait(npregs);
0123 
0124     for (i = 0; i < logo->width*logo->height; i++)
0125         npregs->go.hostrw0 = *data++ << 24;
0126 
0127     return logo;
0128 #else
0129     return NULL;
0130 #endif /* CONFIG_LOGO_SGI_CLUT224 */
0131 }
0132 
0133 static inline void newport_clear_screen(int xstart, int ystart, int xend,
0134                     int yend, int ci)
0135 {
0136     if (logo_active)
0137         return;
0138 
0139     newport_wait(npregs);
0140     npregs->set.wrmask = 0xffffffff;
0141     npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
0142                  NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
0143                  | NPORT_DMODE0_STOPY);
0144     npregs->set.colori = ci;
0145     npregs->set.xystarti = (xstart << 16) | ystart;
0146     npregs->go.xyendi = (xend << 16) | yend;
0147 }
0148 
0149 static inline void newport_clear_lines(int ystart, int yend, int ci)
0150 {
0151     ystart = ((ystart << 4) + topscan) & 0x3ff;
0152     yend = ((yend << 4) + topscan + 15) & 0x3ff;
0153     newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
0154 }
0155 
0156 static void newport_reset(void)
0157 {
0158     unsigned short treg;
0159     int i;
0160 
0161     newport_wait(npregs);
0162     treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
0163     newport_vc2_set(npregs, VC2_IREG_CONTROL,
0164             (treg | VC2_CTRL_EVIDEO));
0165 
0166     treg = newport_vc2_get(npregs, VC2_IREG_CENTRY);
0167     newport_vc2_set(npregs, VC2_IREG_RADDR, treg);
0168     npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
0169                    NPORT_DMODE_W2 | VC2_PROTOCOL);
0170     for (i = 0; i < 128; i++) {
0171         newport_bfwait(npregs);
0172         if (i == 92 || i == 94)
0173             npregs->set.dcbdata0.byshort.s1 = 0xff00;
0174         else
0175             npregs->set.dcbdata0.byshort.s1 = 0x0000;
0176     }
0177 
0178     newport_init_cmap();
0179 
0180     /* turn off popup plane */
0181     npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
0182                    XM9_CRS_CONFIG | NPORT_DMODE_W1);
0183     npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
0184     npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL |
0185                    XM9_CRS_CONFIG | NPORT_DMODE_W1);
0186     npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
0187 
0188     topscan = 0;
0189     npregs->cset.topscan = 0x3ff;
0190     npregs->cset.xywin = (4096 << 16) | 4096;
0191 
0192     /* Clear the screen. */
0193     newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
0194 }
0195 
0196 /*
0197  * calculate the actual screen size by reading
0198  * the video timing out of the VC2
0199  */
0200 static void newport_get_screensize(void)
0201 {
0202     int i, cols;
0203     unsigned short ventry, treg;
0204     unsigned short linetable[128];  /* should be enough */
0205 
0206     ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY);
0207     newport_vc2_set(npregs, VC2_IREG_RADDR, ventry);
0208     npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
0209                    NPORT_DMODE_W2 | VC2_PROTOCOL);
0210     for (i = 0; i < 128; i++) {
0211         newport_bfwait(npregs);
0212         linetable[i] = npregs->set.dcbdata0.byshort.s1;
0213     }
0214 
0215     newport_xsize = newport_ysize = 0;
0216     for (i = 0; i < ARRAY_SIZE(linetable) - 1 && linetable[i + 1]; i += 2) {
0217         cols = 0;
0218         newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]);
0219         npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
0220                        NPORT_DMODE_W2 | VC2_PROTOCOL);
0221         do {
0222             newport_bfwait(npregs);
0223             treg = npregs->set.dcbdata0.byshort.s1;
0224             if ((treg & 1) == 0)
0225                 cols += (treg >> 7) & 0xfe;
0226             if ((treg & 0x80) == 0) {
0227                 newport_bfwait(npregs);
0228                 treg = npregs->set.dcbdata0.byshort.s1;
0229             }
0230         } while ((treg & 0x8000) == 0);
0231         if (cols) {
0232             if (cols > newport_xsize)
0233                 newport_xsize = cols;
0234             newport_ysize += linetable[i + 1];
0235         }
0236     }
0237     printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
0238 }
0239 
0240 static void newport_get_revisions(void)
0241 {
0242     unsigned int tmp;
0243     unsigned int board_rev;
0244     unsigned int rex3_rev;
0245     unsigned int vc2_rev;
0246     unsigned int cmap_rev;
0247     unsigned int xmap9_rev;
0248     unsigned int bt445_rev;
0249     unsigned int bitplanes;
0250 
0251     rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
0252 
0253     npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
0254                    NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
0255     tmp = npregs->set.dcbdata0.bybytes.b3;
0256     cmap_rev = tmp & 7;
0257     board_rev = (tmp >> 4) & 7;
0258     bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
0259 
0260     npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL |
0261                    NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
0262     tmp = npregs->set.dcbdata0.bybytes.b3;
0263     if ((tmp & 7) < cmap_rev)
0264         cmap_rev = (tmp & 7);
0265 
0266     vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
0267 
0268     npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
0269                    XM9_CRS_REVISION | NPORT_DMODE_W1);
0270     xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7;
0271 
0272     npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
0273                    BT445_CSR_ADDR_REG | NPORT_DMODE_W1);
0274     npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG;
0275     npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
0276                    BT445_CSR_REVISION | NPORT_DMODE_W1);
0277     bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a;
0278 
0279 #define L(a)     (char)('A'+(a))
0280     printk
0281         ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n",
0282          board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev),
0283          L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev));
0284 #undef L
0285 
0286     if (board_rev == 3) /* I don't know all affected revisions */
0287         xcurs_correction = 21;
0288 }
0289 
0290 static void newport_exit(void)
0291 {
0292     int i;
0293 
0294     /* free memory used by user font */
0295     for (i = 0; i < MAX_NR_CONSOLES; i++)
0296         newport_set_def_font(i, NULL);
0297 }
0298 
0299 /* Can't be __init, do_take_over_console may call it later */
0300 static const char *newport_startup(void)
0301 {
0302     int i;
0303 
0304     npregs->cset.config = NPORT_CFG_GD0;
0305 
0306     if (newport_wait(npregs))
0307         goto out_unmap;
0308 
0309     npregs->set.xstarti = TESTVAL;
0310     if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
0311         goto out_unmap;
0312 
0313     for (i = 0; i < MAX_NR_CONSOLES; i++)
0314         font_data[i] = FONT_DATA;
0315 
0316     newport_reset();
0317     newport_get_revisions();
0318     newport_get_screensize();
0319     newport_has_init = 1;
0320 
0321     return "SGI Newport";
0322 
0323 out_unmap:
0324     return NULL;
0325 }
0326 
0327 static void newport_init(struct vc_data *vc, int init)
0328 {
0329     int cols, rows;
0330 
0331     cols = newport_xsize / 8;
0332     rows = newport_ysize / 16;
0333     vc->vc_can_do_color = 1;
0334     if (init) {
0335         vc->vc_cols = cols;
0336         vc->vc_rows = rows;
0337     } else
0338         vc_resize(vc, cols, rows);
0339 }
0340 
0341 static void newport_deinit(struct vc_data *c)
0342 {
0343     if (!con_is_bound(&newport_con) && newport_has_init) {
0344         newport_exit();
0345         newport_has_init = 0;
0346     }
0347 }
0348 
0349 static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
0350               int width)
0351 {
0352     int xend = ((sx + width) << 3) - 1;
0353     int ystart = ((sy << 4) + topscan) & 0x3ff;
0354     int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
0355 
0356     if (logo_active)
0357         return;
0358 
0359     if (ystart < yend) {
0360         newport_clear_screen(sx << 3, ystart, xend, yend,
0361                      (vc->state.color & 0xf0) >> 4);
0362     } else {
0363         newport_clear_screen(sx << 3, ystart, xend, 1023,
0364                      (vc->state.color & 0xf0) >> 4);
0365         newport_clear_screen(sx << 3, 0, xend, yend,
0366                      (vc->state.color & 0xf0) >> 4);
0367     }
0368 }
0369 
0370 static void newport_putc(struct vc_data *vc, int charattr, int ypos,
0371              int xpos)
0372 {
0373     unsigned char *p;
0374 
0375     p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
0376     charattr = (charattr >> 8) & 0xff;
0377     xpos <<= 3;
0378     ypos <<= 4;
0379 
0380     newport_render_background(xpos, ypos, xpos, ypos,
0381                   (charattr & 0xf0) >> 4);
0382 
0383     /* Set the color and drawing mode. */
0384     newport_wait(npregs);
0385     npregs->set.colori = charattr & 0xf;
0386     npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
0387                  NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
0388                  NPORT_DMODE0_L32);
0389 
0390     /* Set coordinates for bitmap operation. */
0391     npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
0392     npregs->set.xyendi = ((xpos + 7) << 16);
0393     newport_wait(npregs);
0394 
0395     /* Go, baby, go... */
0396     RENDER(npregs, p);
0397 }
0398 
0399 static void newport_putcs(struct vc_data *vc, const unsigned short *s,
0400               int count, int ypos, int xpos)
0401 {
0402     int i;
0403     int charattr;
0404     unsigned char *p;
0405 
0406     charattr = (scr_readw(s) >> 8) & 0xff;
0407 
0408     xpos <<= 3;
0409     ypos <<= 4;
0410 
0411     if (!logo_active)
0412         /* Clear the area behing the string */
0413         newport_render_background(xpos, ypos,
0414                       xpos + ((count - 1) << 3), ypos,
0415                       (charattr & 0xf0) >> 4);
0416 
0417     newport_wait(npregs);
0418 
0419     /* Set the color and drawing mode. */
0420     npregs->set.colori = charattr & 0xf;
0421     npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
0422                  NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
0423                  NPORT_DMODE0_L32);
0424 
0425     for (i = 0; i < count; i++, xpos += 8) {
0426         p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
0427 
0428         newport_wait(npregs);
0429 
0430         /* Set coordinates for bitmap operation. */
0431         npregs->set.xystarti =
0432             (xpos << 16) | ((ypos + topscan) & 0x3ff);
0433         npregs->set.xyendi = ((xpos + 7) << 16);
0434 
0435         /* Go, baby, go... */
0436         RENDER(npregs, p);
0437     }
0438 }
0439 
0440 static void newport_cursor(struct vc_data *vc, int mode)
0441 {
0442     unsigned short treg;
0443     int xcurs, ycurs;
0444 
0445     switch (mode) {
0446     case CM_ERASE:
0447         treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
0448         newport_vc2_set(npregs, VC2_IREG_CONTROL,
0449                 (treg & ~(VC2_CTRL_ECDISP)));
0450         break;
0451 
0452     case CM_MOVE:
0453     case CM_DRAW:
0454         treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
0455         newport_vc2_set(npregs, VC2_IREG_CONTROL,
0456                 (treg | VC2_CTRL_ECDISP));
0457         xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
0458         ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
0459         xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
0460         newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
0461         newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
0462     }
0463 }
0464 
0465 static int newport_switch(struct vc_data *vc)
0466 {
0467     static int logo_drawn = 0;
0468 
0469     topscan = 0;
0470     npregs->cset.topscan = 0x3ff;
0471 
0472     if (!logo_drawn) {
0473         if (newport_show_logo()) {
0474             logo_drawn = 1;
0475             logo_active = 1;
0476         }
0477     }
0478 
0479     return 1;
0480 }
0481 
0482 static int newport_blank(struct vc_data *c, int blank, int mode_switch)
0483 {
0484     unsigned short treg;
0485 
0486     if (blank == 0) {
0487         /* unblank console */
0488         treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
0489         newport_vc2_set(npregs, VC2_IREG_CONTROL,
0490                 (treg | VC2_CTRL_EDISP));
0491     } else {
0492         /* blank console */
0493         treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
0494         newport_vc2_set(npregs, VC2_IREG_CONTROL,
0495                 (treg & ~(VC2_CTRL_EDISP)));
0496     }
0497     return 1;
0498 }
0499 
0500 static int newport_set_font(int unit, struct console_font *op)
0501 {
0502     int w = op->width;
0503     int h = op->height;
0504     int size = h * op->charcount;
0505     int i;
0506     unsigned char *new_data, *data = op->data, *p;
0507 
0508     /* ladis: when I grow up, there will be a day... and more sizes will
0509      * be supported ;-) */
0510     if ((w != 8) || (h != 16)
0511         || (op->charcount != 256 && op->charcount != 512))
0512         return -EINVAL;
0513 
0514     if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
0515          GFP_USER))) return -ENOMEM;
0516 
0517     new_data += FONT_EXTRA_WORDS * sizeof(int);
0518     FNTSIZE(new_data) = size;
0519     FNTCHARCNT(new_data) = op->charcount;
0520     REFCOUNT(new_data) = 0; /* usage counter */
0521     FNTSUM(new_data) = 0;
0522 
0523     p = new_data;
0524     for (i = 0; i < op->charcount; i++) {
0525         memcpy(p, data, h);
0526         data += 32;
0527         p += h;
0528     }
0529 
0530     /* check if font is already used by other console */
0531     for (i = 0; i < MAX_NR_CONSOLES; i++) {
0532         if (font_data[i] != FONT_DATA
0533             && FNTSIZE(font_data[i]) == size
0534             && !memcmp(font_data[i], new_data, size)) {
0535             kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
0536             /* current font is the same as the new one */
0537             if (i == unit)
0538                 return 0;
0539             new_data = font_data[i];
0540             break;
0541         }
0542     }
0543     /* old font is user font */
0544     if (font_data[unit] != FONT_DATA) {
0545         if (--REFCOUNT(font_data[unit]) == 0)
0546             kfree(font_data[unit] -
0547                   FONT_EXTRA_WORDS * sizeof(int));
0548     }
0549     REFCOUNT(new_data)++;
0550     font_data[unit] = new_data;
0551 
0552     return 0;
0553 }
0554 
0555 static int newport_set_def_font(int unit, struct console_font *op)
0556 {
0557     if (font_data[unit] != FONT_DATA) {
0558         if (--REFCOUNT(font_data[unit]) == 0)
0559             kfree(font_data[unit] -
0560                   FONT_EXTRA_WORDS * sizeof(int));
0561         font_data[unit] = FONT_DATA;
0562     }
0563 
0564     return 0;
0565 }
0566 
0567 static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
0568 {
0569     return newport_set_def_font(vc->vc_num, op);
0570 }
0571 
0572 static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
0573 {
0574     return newport_set_font(vc->vc_num, font);
0575 }
0576 
0577 static bool newport_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
0578         enum con_scroll dir, unsigned int lines)
0579 {
0580     int count, x, y;
0581     unsigned short *s, *d;
0582     unsigned short chattr;
0583 
0584     logo_active = 0;    /* it's time to disable the logo now.. */
0585 
0586     if (t == 0 && b == vc->vc_rows) {
0587         if (dir == SM_UP) {
0588             topscan = (topscan + (lines << 4)) & 0x3ff;
0589             newport_clear_lines(vc->vc_rows - lines,
0590                         vc->vc_rows - 1,
0591                         (vc->state.color & 0xf0) >> 4);
0592         } else {
0593             topscan = (topscan + (-lines << 4)) & 0x3ff;
0594             newport_clear_lines(0, lines - 1,
0595                         (vc->state.color & 0xf0) >> 4);
0596         }
0597         npregs->cset.topscan = (topscan - 1) & 0x3ff;
0598         return false;
0599     }
0600 
0601     count = (b - t - lines) * vc->vc_cols;
0602     if (dir == SM_UP) {
0603         x = 0;
0604         y = t;
0605         s = (unsigned short *) (vc->vc_origin +
0606                     vc->vc_size_row * (t + lines));
0607         d = (unsigned short *) (vc->vc_origin +
0608                     vc->vc_size_row * t);
0609         while (count--) {
0610             chattr = scr_readw(s++);
0611             if (chattr != scr_readw(d)) {
0612                 newport_putc(vc, chattr, y, x);
0613                 scr_writew(chattr, d);
0614             }
0615             d++;
0616             if (++x == vc->vc_cols) {
0617                 x = 0;
0618                 y++;
0619             }
0620         }
0621         d = (unsigned short *) (vc->vc_origin +
0622                     vc->vc_size_row * (b - lines));
0623         x = 0;
0624         y = b - lines;
0625         for (count = 0; count < (lines * vc->vc_cols); count++) {
0626             if (scr_readw(d) != vc->vc_video_erase_char) {
0627                 newport_putc(vc, vc->vc_video_erase_char,
0628                          y, x);
0629                 scr_writew(vc->vc_video_erase_char, d);
0630             }
0631             d++;
0632             if (++x == vc->vc_cols) {
0633                 x = 0;
0634                 y++;
0635             }
0636         }
0637     } else {
0638         x = vc->vc_cols - 1;
0639         y = b - 1;
0640         s = (unsigned short *) (vc->vc_origin +
0641                     vc->vc_size_row * (b - lines) - 2);
0642         d = (unsigned short *) (vc->vc_origin +
0643                     vc->vc_size_row * b - 2);
0644         while (count--) {
0645             chattr = scr_readw(s--);
0646             if (chattr != scr_readw(d)) {
0647                 newport_putc(vc, chattr, y, x);
0648                 scr_writew(chattr, d);
0649             }
0650             d--;
0651             if (x-- == 0) {
0652                 x = vc->vc_cols - 1;
0653                 y--;
0654             }
0655         }
0656         d = (unsigned short *) (vc->vc_origin +
0657                     vc->vc_size_row * t);
0658         x = 0;
0659         y = t;
0660         for (count = 0; count < (lines * vc->vc_cols); count++) {
0661             if (scr_readw(d) != vc->vc_video_erase_char) {
0662                 newport_putc(vc, vc->vc_video_erase_char,
0663                          y, x);
0664                 scr_writew(vc->vc_video_erase_char, d);
0665             }
0666             d++;
0667             if (++x == vc->vc_cols) {
0668                 x = 0;
0669                 y++;
0670             }
0671         }
0672     }
0673     return true;
0674 }
0675 
0676 static void newport_save_screen(struct vc_data *vc) { }
0677 
0678 const struct consw newport_con = {
0679     .owner        = THIS_MODULE,
0680     .con_startup      = newport_startup,
0681     .con_init     = newport_init,
0682     .con_deinit   = newport_deinit,
0683     .con_clear    = newport_clear,
0684     .con_putc     = newport_putc,
0685     .con_putcs    = newport_putcs,
0686     .con_cursor   = newport_cursor,
0687     .con_scroll   = newport_scroll,
0688     .con_switch   = newport_switch,
0689     .con_blank    = newport_blank,
0690     .con_font_set     = newport_font_set,
0691     .con_font_default = newport_font_default,
0692     .con_save_screen  = newport_save_screen
0693 };
0694 
0695 static int newport_probe(struct gio_device *dev,
0696              const struct gio_device_id *id)
0697 {
0698     int err;
0699 
0700     if (!dev->resource.start)
0701         return -EINVAL;
0702 
0703     if (npregs)
0704         return -EBUSY; /* we only support one Newport as console */
0705 
0706     newport_addr = dev->resource.start + 0xF0000;
0707     if (!request_mem_region(newport_addr, NEWPORT_LEN, "Newport"))
0708         return -ENODEV;
0709 
0710     npregs = (struct newport_regs *)/* ioremap cannot fail */
0711         ioremap(newport_addr, sizeof(struct newport_regs));
0712     console_lock();
0713     err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
0714     console_unlock();
0715 
0716     if (err) {
0717         iounmap((void *)npregs);
0718         release_mem_region(newport_addr, NEWPORT_LEN);
0719     }
0720     return err;
0721 }
0722 
0723 static void newport_remove(struct gio_device *dev)
0724 {
0725     give_up_console(&newport_con);
0726     iounmap((void *)npregs);
0727     release_mem_region(newport_addr, NEWPORT_LEN);
0728 }
0729 
0730 static struct gio_device_id newport_ids[] = {
0731     { .id = 0x7e },
0732     { .id = 0xff }
0733 };
0734 
0735 MODULE_ALIAS("gio:7e");
0736 
0737 static struct gio_driver newport_driver = {
0738     .name = "newport",
0739     .id_table = newport_ids,
0740     .probe = newport_probe,
0741     .remove = newport_remove,
0742 };
0743 module_driver(newport_driver, gio_register_driver, gio_unregister_driver);
0744 
0745 MODULE_LICENSE("GPL");