blob: bb4e96255974af27d090b0c4d25a1269976d2d76 [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
577static int newport_set_palette(struct vc_data *vc, unsigned char *table)
578{
579 return -EINVAL;
580}
581
582static int newport_scrolldelta(struct vc_data *vc, int lines)
583{
584 /* there is (nearly) no off-screen memory, so we can't scroll back */
585 return 0;
586}
587
588static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
589 int lines)
590{
591 int count, x, y;
592 unsigned short *s, *d;
593 unsigned short chattr;
594
595 logo_active = 0; /* it's time to disable the logo now.. */
596
597 if (t == 0 && b == vc->vc_rows) {
598 if (dir == SM_UP) {
599 topscan = (topscan + (lines << 4)) & 0x3ff;
600 newport_clear_lines(vc->vc_rows - lines,
601 vc->vc_rows - 1,
602 (vc->vc_color & 0xf0) >> 4);
603 } else {
604 topscan = (topscan + (-lines << 4)) & 0x3ff;
605 newport_clear_lines(0, lines - 1,
606 (vc->vc_color & 0xf0) >> 4);
607 }
608 npregs->cset.topscan = (topscan - 1) & 0x3ff;
609 return 0;
610 }
611
612 count = (b - t - lines) * vc->vc_cols;
613 if (dir == SM_UP) {
614 x = 0;
615 y = t;
616 s = (unsigned short *) (vc->vc_origin +
617 vc->vc_size_row * (t + lines));
618 d = (unsigned short *) (vc->vc_origin +
619 vc->vc_size_row * t);
620 while (count--) {
621 chattr = scr_readw(s++);
622 if (chattr != scr_readw(d)) {
623 newport_putc(vc, chattr, y, x);
624 scr_writew(chattr, d);
625 }
626 d++;
627 if (++x == vc->vc_cols) {
628 x = 0;
629 y++;
630 }
631 }
632 d = (unsigned short *) (vc->vc_origin +
633 vc->vc_size_row * (b - lines));
634 x = 0;
635 y = b - lines;
636 for (count = 0; count < (lines * vc->vc_cols); count++) {
637 if (scr_readw(d) != vc->vc_video_erase_char) {
638 newport_putc(vc, vc->vc_video_erase_char,
639 y, x);
640 scr_writew(vc->vc_video_erase_char, d);
641 }
642 d++;
643 if (++x == vc->vc_cols) {
644 x = 0;
645 y++;
646 }
647 }
648 } else {
649 x = vc->vc_cols - 1;
650 y = b - 1;
651 s = (unsigned short *) (vc->vc_origin +
652 vc->vc_size_row * (b - lines) - 2);
653 d = (unsigned short *) (vc->vc_origin +
654 vc->vc_size_row * b - 2);
655 while (count--) {
656 chattr = scr_readw(s--);
657 if (chattr != scr_readw(d)) {
658 newport_putc(vc, chattr, y, x);
659 scr_writew(chattr, d);
660 }
661 d--;
662 if (x-- == 0) {
663 x = vc->vc_cols - 1;
664 y--;
665 }
666 }
667 d = (unsigned short *) (vc->vc_origin +
668 vc->vc_size_row * t);
669 x = 0;
670 y = t;
671 for (count = 0; count < (lines * vc->vc_cols); count++) {
672 if (scr_readw(d) != vc->vc_video_erase_char) {
673 newport_putc(vc, vc->vc_video_erase_char,
674 y, x);
675 scr_writew(vc->vc_video_erase_char, d);
676 }
677 d++;
678 if (++x == vc->vc_cols) {
679 x = 0;
680 y++;
681 }
682 }
683 }
684 return 1;
685}
686
687static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
688 int dx, int h, int w)
689{
Fabian Frederick36520842015-05-18 19:43:21 +0200690 short xs, ys, xe, ye, xoffs, yoffs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692 xs = sx << 3;
693 xe = ((sx + w) << 3) - 1;
694 /*
695 * as bmove is only used to move stuff around in the same line
696 * (h == 1), we don't care about wrap arounds caused by topscan != 0
697 */
698 ys = ((sy << 4) + topscan) & 0x3ff;
699 ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
700 xoffs = (dx - sx) << 3;
701 yoffs = (dy - sy) << 4;
702 if (xoffs > 0) {
703 /* move to the right, exchange starting points */
Fabian Frederick36520842015-05-18 19:43:21 +0200704 swap(xe, xs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 }
706 newport_wait(npregs);
707 npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK |
708 NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
709 | NPORT_DMODE0_STOPY);
710 npregs->set.xystarti = (xs << 16) | ys;
711 npregs->set.xyendi = (xe << 16) | ye;
712 npregs->go.xymove = (xoffs << 16) | yoffs;
713}
714
715static int newport_dummy(struct vc_data *c)
716{
717 return 0;
718}
719
720#define DUMMY (void *) newport_dummy
721
722const struct consw newport_con = {
723 .owner = THIS_MODULE,
724 .con_startup = newport_startup,
725 .con_init = newport_init,
726 .con_deinit = newport_deinit,
727 .con_clear = newport_clear,
728 .con_putc = newport_putc,
729 .con_putcs = newport_putcs,
730 .con_cursor = newport_cursor,
731 .con_scroll = newport_scroll,
732 .con_bmove = newport_bmove,
733 .con_switch = newport_switch,
734 .con_blank = newport_blank,
735 .con_font_set = newport_font_set,
736 .con_font_default = newport_font_default,
737 .con_set_palette = newport_set_palette,
738 .con_scrolldelta = newport_scrolldelta,
739 .con_set_origin = DUMMY,
740 .con_save_screen = DUMMY
741};
742
Thomas Bogendoerfere84de0c2011-11-22 14:38:02 +0000743static int newport_probe(struct gio_device *dev,
744 const struct gio_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745{
Thomas Bogendoerfere84de0c2011-11-22 14:38:02 +0000746 unsigned long newport_addr;
Wang YanQing155957f2013-05-21 13:15:12 +0800747 int err;
Antonino A. Daplase86bb8a2006-06-26 00:27:15 -0700748
Thomas Bogendoerfere84de0c2011-11-22 14:38:02 +0000749 if (!dev->resource.start)
750 return -EINVAL;
751
752 if (npregs)
753 return -EBUSY; /* we only support one Newport as console */
754
755 newport_addr = dev->resource.start + 0xF0000;
756 if (!request_mem_region(newport_addr, 0x10000, "Newport"))
757 return -ENODEV;
758
759 npregs = (struct newport_regs *)/* ioremap cannot fail */
760 ioremap(newport_addr, sizeof(struct newport_regs));
Wang YanQing155957f2013-05-21 13:15:12 +0800761 console_lock();
762 err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
763 console_unlock();
764 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765}
766
Thomas Bogendoerfere84de0c2011-11-22 14:38:02 +0000767static void newport_remove(struct gio_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
769 give_up_console(&newport_con);
770 iounmap((void *)npregs);
771}
Thomas Bogendoerfere84de0c2011-11-22 14:38:02 +0000772
773static struct gio_device_id newport_ids[] = {
774 { .id = 0x7e },
775 { .id = 0xff }
776};
777
778MODULE_ALIAS("gio:7e");
779
780static struct gio_driver newport_driver = {
781 .name = "newport",
782 .id_table = newport_ids,
783 .probe = newport_probe,
784 .remove = newport_remove,
785};
786
787int __init newport_console_init(void)
788{
789 return gio_register_driver(&newport_driver);
790}
791
792void __exit newport_console_exit(void)
793{
794 gio_unregister_driver(&newport_driver);
795}
796
797module_init(newport_console_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798module_exit(newport_console_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800MODULE_LICENSE("GPL");