newport_con.c 19 KB

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