newport_con.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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 (dm@engr.sgi.com)
  10. * 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>
  15. #include <linux/tty.h>
  16. #include <linux/kd.h>
  17. #include <linux/selection.h>
  18. #include <linux/console.h>
  19. #include <linux/vt_kern.h>
  20. #include <linux/mm.h>
  21. #include <linux/module.h>
  22. #include <linux/slab.h>
  23. #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 <video/newport.h>
  29. #include <linux/linux_logo.h>
  30. #include <linux/font.h>
  31. extern struct font_desc font_vga_8x16;
  32. extern unsigned long sgi_gfxaddr;
  33. #define FONT_DATA ((unsigned char *)font_vga_8x16.data)
  34. /* borrowed from fbcon.c */
  35. #define REFCOUNT(fd) (((int *)(fd))[-1])
  36. #define FNTSIZE(fd) (((int *)(fd))[-2])
  37. #define FNTCHARCNT(fd) (((int *)(fd))[-3])
  38. #define FONT_EXTRA_WORDS 3
  39. static unsigned char *font_data[MAX_NR_CONSOLES];
  40. static struct newport_regs *npregs;
  41. static int logo_active;
  42. static int topscan;
  43. static int xcurs_correction = 29;
  44. static int newport_xsize;
  45. static int newport_ysize;
  46. static int newport_set_def_font(int unit, struct console_font *op);
  47. #define BMASK(c) (c << 24)
  48. #define RENDER(regs, cp) do { \
  49. (regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \
  50. (regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \
  51. (regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \
  52. (regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \
  53. (regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \
  54. (regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \
  55. (regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \
  56. (regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \
  57. } while(0)
  58. #define TESTVAL 0xdeadbeef
  59. #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
  60. static inline void newport_render_background(int xstart, int ystart,
  61. int xend, int yend, int ci)
  62. {
  63. newport_wait(npregs);
  64. npregs->set.wrmask = 0xffffffff;
  65. npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
  66. NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
  67. | NPORT_DMODE0_STOPY);
  68. npregs->set.colori = ci;
  69. npregs->set.xystarti =
  70. (xstart << 16) | ((ystart + topscan) & 0x3ff);
  71. npregs->go.xyendi =
  72. ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
  73. }
  74. static inline void newport_init_cmap(void)
  75. {
  76. unsigned short i;
  77. for (i = 0; i < 16; i++) {
  78. newport_bfwait(npregs);
  79. newport_cmap_setaddr(npregs, color_table[i]);
  80. newport_cmap_setrgb(npregs,
  81. default_red[i],
  82. default_grn[i], default_blu[i]);
  83. }
  84. }
  85. static void newport_show_logo(void)
  86. {
  87. #ifdef CONFIG_LOGO_SGI_CLUT224
  88. const struct linux_logo *logo = fb_find_logo(8);
  89. const unsigned char *clut = logo->clut;
  90. const unsigned char *data = logo->data;
  91. unsigned long i;
  92. for (i = 0; i < logo->clutsize; i++) {
  93. newport_bfwait(npregs);
  94. newport_cmap_setaddr(npregs, i + 0x20);
  95. newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]);
  96. clut += 3;
  97. }
  98. newport_wait(npregs);
  99. npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
  100. NPORT_DMODE0_CHOST);
  101. npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0);
  102. npregs->set.xyendi = ((newport_xsize - 1) << 16);
  103. newport_wait(npregs);
  104. for (i = 0; i < logo->width*logo->height; i++)
  105. npregs->go.hostrw0 = *data++ << 24;
  106. #endif /* CONFIG_LOGO_SGI_CLUT224 */
  107. }
  108. static inline void newport_clear_screen(int xstart, int ystart, int xend,
  109. int yend, int ci)
  110. {
  111. if (logo_active)
  112. return;
  113. newport_wait(npregs);
  114. npregs->set.wrmask = 0xffffffff;
  115. npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
  116. NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
  117. | NPORT_DMODE0_STOPY);
  118. npregs->set.colori = ci;
  119. npregs->set.xystarti = (xstart << 16) | ystart;
  120. npregs->go.xyendi = (xend << 16) | yend;
  121. }
  122. static inline void newport_clear_lines(int ystart, int yend, int ci)
  123. {
  124. ystart = ((ystart << 4) + topscan) & 0x3ff;
  125. yend = ((yend << 4) + topscan + 15) & 0x3ff;
  126. newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
  127. }
  128. void newport_reset(void)
  129. {
  130. unsigned short treg;
  131. int i;
  132. newport_wait(npregs);
  133. treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
  134. newport_vc2_set(npregs, VC2_IREG_CONTROL,
  135. (treg | VC2_CTRL_EVIDEO));
  136. treg = newport_vc2_get(npregs, VC2_IREG_CENTRY);
  137. newport_vc2_set(npregs, VC2_IREG_RADDR, treg);
  138. npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
  139. NPORT_DMODE_W2 | VC2_PROTOCOL);
  140. for (i = 0; i < 128; i++) {
  141. newport_bfwait(npregs);
  142. if (i == 92 || i == 94)
  143. npregs->set.dcbdata0.byshort.s1 = 0xff00;
  144. else
  145. npregs->set.dcbdata0.byshort.s1 = 0x0000;
  146. }
  147. newport_init_cmap();
  148. /* turn off popup plane */
  149. npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
  150. XM9_CRS_CONFIG | NPORT_DMODE_W1);
  151. npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
  152. npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL |
  153. XM9_CRS_CONFIG | NPORT_DMODE_W1);
  154. npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
  155. topscan = 0;
  156. npregs->cset.topscan = 0x3ff;
  157. npregs->cset.xywin = (4096 << 16) | 4096;
  158. /* Clear the screen. */
  159. newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
  160. }
  161. /*
  162. * calculate the actual screen size by reading
  163. * the video timing out of the VC2
  164. */
  165. void newport_get_screensize(void)
  166. {
  167. int i, cols;
  168. unsigned short ventry, treg;
  169. unsigned short linetable[128]; /* should be enough */
  170. ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY);
  171. newport_vc2_set(npregs, VC2_IREG_RADDR, ventry);
  172. npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
  173. NPORT_DMODE_W2 | VC2_PROTOCOL);
  174. for (i = 0; i < 128; i++) {
  175. newport_bfwait(npregs);
  176. linetable[i] = npregs->set.dcbdata0.byshort.s1;
  177. }
  178. newport_xsize = newport_ysize = 0;
  179. for (i = 0; linetable[i + 1] && (i < sizeof(linetable)); i += 2) {
  180. cols = 0;
  181. newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]);
  182. npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
  183. NPORT_DMODE_W2 | VC2_PROTOCOL);
  184. do {
  185. newport_bfwait(npregs);
  186. treg = npregs->set.dcbdata0.byshort.s1;
  187. if ((treg & 1) == 0)
  188. cols += (treg >> 7) & 0xfe;
  189. if ((treg & 0x80) == 0) {
  190. newport_bfwait(npregs);
  191. treg = npregs->set.dcbdata0.byshort.s1;
  192. }
  193. } while ((treg & 0x8000) == 0);
  194. if (cols) {
  195. if (cols > newport_xsize)
  196. newport_xsize = cols;
  197. newport_ysize += linetable[i + 1];
  198. }
  199. }
  200. printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
  201. }
  202. static void newport_get_revisions(void)
  203. {
  204. unsigned int tmp;
  205. unsigned int board_rev;
  206. unsigned int rex3_rev;
  207. unsigned int vc2_rev;
  208. unsigned int cmap_rev;
  209. unsigned int xmap9_rev;
  210. unsigned int bt445_rev;
  211. unsigned int bitplanes;
  212. rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
  213. npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
  214. NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
  215. tmp = npregs->set.dcbdata0.bybytes.b3;
  216. cmap_rev = tmp & 7;
  217. board_rev = (tmp >> 4) & 7;
  218. bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
  219. npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL |
  220. NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
  221. tmp = npregs->set.dcbdata0.bybytes.b3;
  222. if ((tmp & 7) < cmap_rev)
  223. cmap_rev = (tmp & 7);
  224. vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
  225. npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
  226. XM9_CRS_REVISION | NPORT_DMODE_W1);
  227. xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7;
  228. npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
  229. BT445_CSR_ADDR_REG | NPORT_DMODE_W1);
  230. npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG;
  231. npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
  232. BT445_CSR_REVISION | NPORT_DMODE_W1);
  233. bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a;
  234. #define L(a) (char)('A'+(a))
  235. printk
  236. ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n",
  237. board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev),
  238. L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev));
  239. #undef L
  240. if (board_rev == 3) /* I don't know all affected revisions */
  241. xcurs_correction = 21;
  242. }
  243. /* Can't be __init, take_over_console may call it later */
  244. static const char *newport_startup(void)
  245. {
  246. int i;
  247. if (!sgi_gfxaddr)
  248. return NULL;
  249. npregs = (struct newport_regs *) /* ioremap cannot fail */
  250. ioremap(sgi_gfxaddr, sizeof(struct newport_regs));
  251. npregs->cset.config = NPORT_CFG_GD0;
  252. if (newport_wait(npregs))
  253. goto out_unmap;
  254. npregs->set.xstarti = TESTVAL;
  255. if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
  256. goto out_unmap;
  257. for (i = 0; i < MAX_NR_CONSOLES; i++)
  258. font_data[i] = FONT_DATA;
  259. newport_reset();
  260. newport_get_revisions();
  261. newport_get_screensize();
  262. return "SGI Newport";
  263. out_unmap:
  264. iounmap((void *)npregs);
  265. return NULL;
  266. }
  267. static void newport_init(struct vc_data *vc, int init)
  268. {
  269. vc->vc_cols = newport_xsize / 8;
  270. vc->vc_rows = newport_ysize / 16;
  271. vc->vc_can_do_color = 1;
  272. }
  273. static void newport_deinit(struct vc_data *c)
  274. {
  275. int i;
  276. /* free memory used by user font */
  277. for (i = 0; i < MAX_NR_CONSOLES; i++)
  278. newport_set_def_font(i, NULL);
  279. }
  280. static void newport_clear(struct vc_data *vc, int sy, int sx, int height,
  281. int width)
  282. {
  283. int xend = ((sx + width) << 3) - 1;
  284. int ystart = ((sy << 4) + topscan) & 0x3ff;
  285. int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff;
  286. if (logo_active)
  287. return;
  288. if (ystart < yend) {
  289. newport_clear_screen(sx << 3, ystart, xend, yend,
  290. (vc->vc_color & 0xf0) >> 4);
  291. } else {
  292. newport_clear_screen(sx << 3, ystart, xend, 1023,
  293. (vc->vc_color & 0xf0) >> 4);
  294. newport_clear_screen(sx << 3, 0, xend, yend,
  295. (vc->vc_color & 0xf0) >> 4);
  296. }
  297. }
  298. static void newport_putc(struct vc_data *vc, int charattr, int ypos,
  299. int xpos)
  300. {
  301. unsigned char *p;
  302. p = &font_data[vc->vc_num][(charattr & 0xff) << 4];
  303. charattr = (charattr >> 8) & 0xff;
  304. xpos <<= 3;
  305. ypos <<= 4;
  306. newport_render_background(xpos, ypos, xpos, ypos,
  307. (charattr & 0xf0) >> 4);
  308. /* Set the color and drawing mode. */
  309. newport_wait(npregs);
  310. npregs->set.colori = charattr & 0xf;
  311. npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
  312. NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
  313. NPORT_DMODE0_L32);
  314. /* Set coordinates for bitmap operation. */
  315. npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff);
  316. npregs->set.xyendi = ((xpos + 7) << 16);
  317. newport_wait(npregs);
  318. /* Go, baby, go... */
  319. RENDER(npregs, p);
  320. }
  321. static void newport_putcs(struct vc_data *vc, const unsigned short *s,
  322. int count, int ypos, int xpos)
  323. {
  324. int i;
  325. int charattr;
  326. unsigned char *p;
  327. charattr = (scr_readw(s) >> 8) & 0xff;
  328. xpos <<= 3;
  329. ypos <<= 4;
  330. if (!logo_active)
  331. /* Clear the area behing the string */
  332. newport_render_background(xpos, ypos,
  333. xpos + ((count - 1) << 3), ypos,
  334. (charattr & 0xf0) >> 4);
  335. newport_wait(npregs);
  336. /* Set the color and drawing mode. */
  337. npregs->set.colori = charattr & 0xf;
  338. npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
  339. NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB |
  340. NPORT_DMODE0_L32);
  341. for (i = 0; i < count; i++, xpos += 8) {
  342. p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4];
  343. newport_wait(npregs);
  344. /* Set coordinates for bitmap operation. */
  345. npregs->set.xystarti =
  346. (xpos << 16) | ((ypos + topscan) & 0x3ff);
  347. npregs->set.xyendi = ((xpos + 7) << 16);
  348. /* Go, baby, go... */
  349. RENDER(npregs, p);
  350. }
  351. }
  352. static void newport_cursor(struct vc_data *vc, int mode)
  353. {
  354. unsigned short treg;
  355. int xcurs, ycurs;
  356. switch (mode) {
  357. case CM_ERASE:
  358. treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
  359. newport_vc2_set(npregs, VC2_IREG_CONTROL,
  360. (treg & ~(VC2_CTRL_ECDISP)));
  361. break;
  362. case CM_MOVE:
  363. case CM_DRAW:
  364. treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
  365. newport_vc2_set(npregs, VC2_IREG_CONTROL,
  366. (treg | VC2_CTRL_ECDISP));
  367. xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2;
  368. ycurs = ((xcurs / vc->vc_cols) << 4) + 31;
  369. xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction;
  370. newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs);
  371. newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs);
  372. }
  373. }
  374. static int newport_switch(struct vc_data *vc)
  375. {
  376. static int logo_drawn = 0;
  377. topscan = 0;
  378. npregs->cset.topscan = 0x3ff;
  379. if (!logo_drawn) {
  380. newport_show_logo();
  381. logo_drawn = 1;
  382. logo_active = 1;
  383. }
  384. return 1;
  385. }
  386. static int newport_blank(struct vc_data *c, int blank, int mode_switch)
  387. {
  388. unsigned short treg;
  389. if (blank == 0) {
  390. /* unblank console */
  391. treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
  392. newport_vc2_set(npregs, VC2_IREG_CONTROL,
  393. (treg | VC2_CTRL_EDISP));
  394. } else {
  395. /* blank console */
  396. treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
  397. newport_vc2_set(npregs, VC2_IREG_CONTROL,
  398. (treg & ~(VC2_CTRL_EDISP)));
  399. }
  400. return 1;
  401. }
  402. static int newport_set_font(int unit, struct console_font *op)
  403. {
  404. int w = op->width;
  405. int h = op->height;
  406. int size = h * op->charcount;
  407. int i;
  408. unsigned char *new_data, *data = op->data, *p;
  409. /* ladis: when I grow up, there will be a day... and more sizes will
  410. * be supported ;-) */
  411. if ((w != 8) || (h != 16)
  412. || (op->charcount != 256 && op->charcount != 512))
  413. return -EINVAL;
  414. if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size,
  415. GFP_USER))) return -ENOMEM;
  416. new_data += FONT_EXTRA_WORDS * sizeof(int);
  417. FNTSIZE(new_data) = size;
  418. FNTCHARCNT(new_data) = op->charcount;
  419. REFCOUNT(new_data) = 0; /* usage counter */
  420. p = new_data;
  421. for (i = 0; i < op->charcount; i++) {
  422. memcpy(p, data, h);
  423. data += 32;
  424. p += h;
  425. }
  426. /* check if font is already used by other console */
  427. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  428. if (font_data[i] != FONT_DATA
  429. && FNTSIZE(font_data[i]) == size
  430. && !memcmp(font_data[i], new_data, size)) {
  431. kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
  432. /* current font is the same as the new one */
  433. if (i == unit)
  434. return 0;
  435. new_data = font_data[i];
  436. break;
  437. }
  438. }
  439. /* old font is user font */
  440. if (font_data[unit] != FONT_DATA) {
  441. if (--REFCOUNT(font_data[unit]) == 0)
  442. kfree(font_data[unit] -
  443. FONT_EXTRA_WORDS * sizeof(int));
  444. }
  445. REFCOUNT(new_data)++;
  446. font_data[unit] = new_data;
  447. return 0;
  448. }
  449. static int newport_set_def_font(int unit, struct console_font *op)
  450. {
  451. if (font_data[unit] != FONT_DATA) {
  452. if (--REFCOUNT(font_data[unit]) == 0)
  453. kfree(font_data[unit] -
  454. FONT_EXTRA_WORDS * sizeof(int));
  455. font_data[unit] = FONT_DATA;
  456. }
  457. return 0;
  458. }
  459. static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
  460. {
  461. return newport_set_def_font(vc->vc_num, op);
  462. }
  463. static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
  464. {
  465. return newport_set_font(vc->vc_num, font);
  466. }
  467. static int newport_set_palette(struct vc_data *vc, unsigned char *table)
  468. {
  469. return -EINVAL;
  470. }
  471. static int newport_scrolldelta(struct vc_data *vc, int lines)
  472. {
  473. /* there is (nearly) no off-screen memory, so we can't scroll back */
  474. return 0;
  475. }
  476. static int newport_scroll(struct vc_data *vc, int t, int b, int dir,
  477. int lines)
  478. {
  479. int count, x, y;
  480. unsigned short *s, *d;
  481. unsigned short chattr;
  482. logo_active = 0; /* it's time to disable the logo now.. */
  483. if (t == 0 && b == vc->vc_rows) {
  484. if (dir == SM_UP) {
  485. topscan = (topscan + (lines << 4)) & 0x3ff;
  486. newport_clear_lines(vc->vc_rows - lines,
  487. vc->vc_rows - 1,
  488. (vc->vc_color & 0xf0) >> 4);
  489. } else {
  490. topscan = (topscan + (-lines << 4)) & 0x3ff;
  491. newport_clear_lines(0, lines - 1,
  492. (vc->vc_color & 0xf0) >> 4);
  493. }
  494. npregs->cset.topscan = (topscan - 1) & 0x3ff;
  495. return 0;
  496. }
  497. count = (b - t - lines) * vc->vc_cols;
  498. if (dir == SM_UP) {
  499. x = 0;
  500. y = t;
  501. s = (unsigned short *) (vc->vc_origin +
  502. vc->vc_size_row * (t + lines));
  503. d = (unsigned short *) (vc->vc_origin +
  504. vc->vc_size_row * t);
  505. while (count--) {
  506. chattr = scr_readw(s++);
  507. if (chattr != scr_readw(d)) {
  508. newport_putc(vc, chattr, y, x);
  509. scr_writew(chattr, d);
  510. }
  511. d++;
  512. if (++x == vc->vc_cols) {
  513. x = 0;
  514. y++;
  515. }
  516. }
  517. d = (unsigned short *) (vc->vc_origin +
  518. vc->vc_size_row * (b - lines));
  519. x = 0;
  520. y = b - lines;
  521. for (count = 0; count < (lines * vc->vc_cols); count++) {
  522. if (scr_readw(d) != vc->vc_video_erase_char) {
  523. newport_putc(vc, vc->vc_video_erase_char,
  524. y, x);
  525. scr_writew(vc->vc_video_erase_char, d);
  526. }
  527. d++;
  528. if (++x == vc->vc_cols) {
  529. x = 0;
  530. y++;
  531. }
  532. }
  533. } else {
  534. x = vc->vc_cols - 1;
  535. y = b - 1;
  536. s = (unsigned short *) (vc->vc_origin +
  537. vc->vc_size_row * (b - lines) - 2);
  538. d = (unsigned short *) (vc->vc_origin +
  539. vc->vc_size_row * b - 2);
  540. while (count--) {
  541. chattr = scr_readw(s--);
  542. if (chattr != scr_readw(d)) {
  543. newport_putc(vc, chattr, y, x);
  544. scr_writew(chattr, d);
  545. }
  546. d--;
  547. if (x-- == 0) {
  548. x = vc->vc_cols - 1;
  549. y--;
  550. }
  551. }
  552. d = (unsigned short *) (vc->vc_origin +
  553. vc->vc_size_row * t);
  554. x = 0;
  555. y = t;
  556. for (count = 0; count < (lines * vc->vc_cols); count++) {
  557. if (scr_readw(d) != vc->vc_video_erase_char) {
  558. newport_putc(vc, vc->vc_video_erase_char,
  559. y, x);
  560. scr_writew(vc->vc_video_erase_char, d);
  561. }
  562. d++;
  563. if (++x == vc->vc_cols) {
  564. x = 0;
  565. y++;
  566. }
  567. }
  568. }
  569. return 1;
  570. }
  571. static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy,
  572. int dx, int h, int w)
  573. {
  574. short xs, ys, xe, ye, xoffs, yoffs, tmp;
  575. xs = sx << 3;
  576. xe = ((sx + w) << 3) - 1;
  577. /*
  578. * as bmove is only used to move stuff around in the same line
  579. * (h == 1), we don't care about wrap arounds caused by topscan != 0
  580. */
  581. ys = ((sy << 4) + topscan) & 0x3ff;
  582. ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff;
  583. xoffs = (dx - sx) << 3;
  584. yoffs = (dy - sy) << 4;
  585. if (xoffs > 0) {
  586. /* move to the right, exchange starting points */
  587. tmp = xe;
  588. xe = xs;
  589. xs = tmp;
  590. }
  591. newport_wait(npregs);
  592. npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK |
  593. NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
  594. | NPORT_DMODE0_STOPY);
  595. npregs->set.xystarti = (xs << 16) | ys;
  596. npregs->set.xyendi = (xe << 16) | ye;
  597. npregs->go.xymove = (xoffs << 16) | yoffs;
  598. }
  599. static int newport_dummy(struct vc_data *c)
  600. {
  601. return 0;
  602. }
  603. #define DUMMY (void *) newport_dummy
  604. const struct consw newport_con = {
  605. .owner = THIS_MODULE,
  606. .con_startup = newport_startup,
  607. .con_init = newport_init,
  608. .con_deinit = newport_deinit,
  609. .con_clear = newport_clear,
  610. .con_putc = newport_putc,
  611. .con_putcs = newport_putcs,
  612. .con_cursor = newport_cursor,
  613. .con_scroll = newport_scroll,
  614. .con_bmove = newport_bmove,
  615. .con_switch = newport_switch,
  616. .con_blank = newport_blank,
  617. .con_font_set = newport_font_set,
  618. .con_font_default = newport_font_default,
  619. .con_set_palette = newport_set_palette,
  620. .con_scrolldelta = newport_scrolldelta,
  621. .con_set_origin = DUMMY,
  622. .con_save_screen = DUMMY
  623. };
  624. #ifdef MODULE
  625. static int __init newport_console_init(void)
  626. {
  627. return take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
  628. }
  629. static void __exit newport_console_exit(void)
  630. {
  631. give_up_console(&newport_con);
  632. iounmap((void *)npregs);
  633. }
  634. module_init(newport_console_init);
  635. module_exit(newport_console_exit);
  636. #endif
  637. MODULE_LICENSE("GPL");