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