newport_con.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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/page.h>
  25. #include <asm/pgtable.h>
  26. #include <asm/gio_device.h>
  27. #include <video/newport.h>
  28. #include <linux/linux_logo.h>
  29. #include <linux/font.h>
  30. #define FONT_DATA ((unsigned char *)font_vga_8x16.data)
  31. /* borrowed from fbcon.c */
  32. #define REFCOUNT(fd) (((int *)(fd))[-1])
  33. #define FNTSIZE(fd) (((int *)(fd))[-2])
  34. #define FNTCHARCNT(fd) (((int *)(fd))[-3])
  35. #define FONT_EXTRA_WORDS 3
  36. static unsigned char *font_data[MAX_NR_CONSOLES];
  37. static struct newport_regs *npregs;
  38. static int logo_active;
  39. static int topscan;
  40. static int xcurs_correction = 29;
  41. static int newport_xsize;
  42. static int newport_ysize;
  43. static int newport_has_init;
  44. static int newport_set_def_font(int unit, struct console_font *op);
  45. #define BMASK(c) (c << 24)
  46. #define RENDER(regs, cp) do { \
  47. (regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \
  48. (regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \
  49. (regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \
  50. (regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \
  51. (regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \
  52. (regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \
  53. (regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \
  54. (regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \
  55. } while(0)
  56. #define TESTVAL 0xdeadbeef
  57. #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11)
  58. static inline void newport_render_background(int xstart, int ystart,
  59. int xend, int yend, int ci)
  60. {
  61. newport_wait(npregs);
  62. npregs->set.wrmask = 0xffffffff;
  63. npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
  64. NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
  65. | NPORT_DMODE0_STOPY);
  66. npregs->set.colori = ci;
  67. npregs->set.xystarti =
  68. (xstart << 16) | ((ystart + topscan) & 0x3ff);
  69. npregs->go.xyendi =
  70. ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff);
  71. }
  72. static inline void newport_init_cmap(void)
  73. {
  74. unsigned short i;
  75. for (i = 0; i < 16; i++) {
  76. newport_bfwait(npregs);
  77. newport_cmap_setaddr(npregs, color_table[i]);
  78. newport_cmap_setrgb(npregs,
  79. default_red[i],
  80. default_grn[i], default_blu[i]);
  81. }
  82. }
  83. static const struct linux_logo *newport_show_logo(void)
  84. {
  85. #ifdef CONFIG_LOGO_SGI_CLUT224
  86. const struct linux_logo *logo = fb_find_logo(8);
  87. const unsigned char *clut;
  88. const unsigned char *data;
  89. unsigned long i;
  90. if (!logo)
  91. return NULL;
  92. clut = logo->clut;
  93. data = logo->data;
  94. for (i = 0; i < logo->clutsize; i++) {
  95. newport_bfwait(npregs);
  96. newport_cmap_setaddr(npregs, i + 0x20);
  97. newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]);
  98. clut += 3;
  99. }
  100. newport_wait(npregs);
  101. npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
  102. NPORT_DMODE0_CHOST);
  103. npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0);
  104. npregs->set.xyendi = ((newport_xsize - 1) << 16);
  105. newport_wait(npregs);
  106. for (i = 0; i < logo->width*logo->height; i++)
  107. npregs->go.hostrw0 = *data++ << 24;
  108. return logo;
  109. #endif /* CONFIG_LOGO_SGI_CLUT224 */
  110. }
  111. static inline void newport_clear_screen(int xstart, int ystart, int xend,
  112. int yend, int ci)
  113. {
  114. if (logo_active)
  115. return;
  116. newport_wait(npregs);
  117. npregs->set.wrmask = 0xffffffff;
  118. npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK |
  119. NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
  120. | NPORT_DMODE0_STOPY);
  121. npregs->set.colori = ci;
  122. npregs->set.xystarti = (xstart << 16) | ystart;
  123. npregs->go.xyendi = (xend << 16) | yend;
  124. }
  125. static inline void newport_clear_lines(int ystart, int yend, int ci)
  126. {
  127. ystart = ((ystart << 4) + topscan) & 0x3ff;
  128. yend = ((yend << 4) + topscan + 15) & 0x3ff;
  129. newport_clear_screen(0, ystart, 1280 + 63, yend, ci);
  130. }
  131. static void newport_reset(void)
  132. {
  133. unsigned short treg;
  134. int i;
  135. newport_wait(npregs);
  136. treg = newport_vc2_get(npregs, VC2_IREG_CONTROL);
  137. newport_vc2_set(npregs, VC2_IREG_CONTROL,
  138. (treg | VC2_CTRL_EVIDEO));
  139. treg = newport_vc2_get(npregs, VC2_IREG_CENTRY);
  140. newport_vc2_set(npregs, VC2_IREG_RADDR, treg);
  141. npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
  142. NPORT_DMODE_W2 | VC2_PROTOCOL);
  143. for (i = 0; i < 128; i++) {
  144. newport_bfwait(npregs);
  145. if (i == 92 || i == 94)
  146. npregs->set.dcbdata0.byshort.s1 = 0xff00;
  147. else
  148. npregs->set.dcbdata0.byshort.s1 = 0x0000;
  149. }
  150. newport_init_cmap();
  151. /* turn off popup plane */
  152. npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
  153. XM9_CRS_CONFIG | NPORT_DMODE_W1);
  154. npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
  155. npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL |
  156. XM9_CRS_CONFIG | NPORT_DMODE_W1);
  157. npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE;
  158. topscan = 0;
  159. npregs->cset.topscan = 0x3ff;
  160. npregs->cset.xywin = (4096 << 16) | 4096;
  161. /* Clear the screen. */
  162. newport_clear_screen(0, 0, 1280 + 63, 1024, 0);
  163. }
  164. /*
  165. * calculate the actual screen size by reading
  166. * the video timing out of the VC2
  167. */
  168. static void newport_get_screensize(void)
  169. {
  170. int i, cols;
  171. unsigned short ventry, treg;
  172. unsigned short linetable[128]; /* should be enough */
  173. ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY);
  174. newport_vc2_set(npregs, VC2_IREG_RADDR, ventry);
  175. npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
  176. NPORT_DMODE_W2 | VC2_PROTOCOL);
  177. for (i = 0; i < 128; i++) {
  178. newport_bfwait(npregs);
  179. linetable[i] = npregs->set.dcbdata0.byshort.s1;
  180. }
  181. newport_xsize = newport_ysize = 0;
  182. for (i = 0; i < ARRAY_SIZE(linetable) - 1 && linetable[i + 1]; i += 2) {
  183. cols = 0;
  184. newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]);
  185. npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM |
  186. NPORT_DMODE_W2 | VC2_PROTOCOL);
  187. do {
  188. newport_bfwait(npregs);
  189. treg = npregs->set.dcbdata0.byshort.s1;
  190. if ((treg & 1) == 0)
  191. cols += (treg >> 7) & 0xfe;
  192. if ((treg & 0x80) == 0) {
  193. newport_bfwait(npregs);
  194. treg = npregs->set.dcbdata0.byshort.s1;
  195. }
  196. } while ((treg & 0x8000) == 0);
  197. if (cols) {
  198. if (cols > newport_xsize)
  199. newport_xsize = cols;
  200. newport_ysize += linetable[i + 1];
  201. }
  202. }
  203. printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize);
  204. }
  205. static void newport_get_revisions(void)
  206. {
  207. unsigned int tmp;
  208. unsigned int board_rev;
  209. unsigned int rex3_rev;
  210. unsigned int vc2_rev;
  211. unsigned int cmap_rev;
  212. unsigned int xmap9_rev;
  213. unsigned int bt445_rev;
  214. unsigned int bitplanes;
  215. rex3_rev = npregs->cset.status & NPORT_STAT_VERS;
  216. npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL |
  217. NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
  218. tmp = npregs->set.dcbdata0.bybytes.b3;
  219. cmap_rev = tmp & 7;
  220. board_rev = (tmp >> 4) & 7;
  221. bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24;
  222. npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL |
  223. NCMAP_REGADDR_RREG | NPORT_DMODE_W1);
  224. tmp = npregs->set.dcbdata0.bybytes.b3;
  225. if ((tmp & 7) < cmap_rev)
  226. cmap_rev = (tmp & 7);
  227. vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7;
  228. npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL |
  229. XM9_CRS_REVISION | NPORT_DMODE_W1);
  230. xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7;
  231. npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
  232. BT445_CSR_ADDR_REG | NPORT_DMODE_W1);
  233. npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG;
  234. npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL |
  235. BT445_CSR_REVISION | NPORT_DMODE_W1);
  236. bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a;
  237. #define L(a) (char)('A'+(a))
  238. printk
  239. ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n",
  240. board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev),
  241. L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev));
  242. #undef L
  243. if (board_rev == 3) /* I don't know all affected revisions */
  244. xcurs_correction = 21;
  245. }
  246. static void newport_exit(void)
  247. {
  248. int i;
  249. /* free memory used by user font */
  250. for (i = 0; i < MAX_NR_CONSOLES; i++)
  251. newport_set_def_font(i, NULL);
  252. }
  253. /* Can't be __init, do_take_over_console may call it later */
  254. static const char *newport_startup(void)
  255. {
  256. int i;
  257. npregs->cset.config = NPORT_CFG_GD0;
  258. if (newport_wait(npregs))
  259. goto out_unmap;
  260. npregs->set.xstarti = TESTVAL;
  261. if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL))
  262. goto out_unmap;
  263. for (i = 0; i < MAX_NR_CONSOLES; i++)
  264. font_data[i] = FONT_DATA;
  265. newport_reset();
  266. newport_get_revisions();
  267. newport_get_screensize();
  268. newport_has_init = 1;
  269. return "SGI Newport";
  270. out_unmap:
  271. return NULL;
  272. }
  273. static void newport_init(struct vc_data *vc, int init)
  274. {
  275. int cols, rows;
  276. cols = newport_xsize / 8;
  277. rows = newport_ysize / 16;
  278. vc->vc_can_do_color = 1;
  279. if (init) {
  280. vc->vc_cols = cols;
  281. vc->vc_rows = rows;
  282. } else
  283. vc_resize(vc, cols, rows);
  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;
  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. swap(xe, xs);
  601. }
  602. newport_wait(npregs);
  603. npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK |
  604. NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX
  605. | NPORT_DMODE0_STOPY);
  606. npregs->set.xystarti = (xs << 16) | ys;
  607. npregs->set.xyendi = (xe << 16) | ye;
  608. npregs->go.xymove = (xoffs << 16) | yoffs;
  609. }
  610. static int newport_dummy(struct vc_data *c)
  611. {
  612. return 0;
  613. }
  614. #define DUMMY (void *) newport_dummy
  615. const struct consw newport_con = {
  616. .owner = THIS_MODULE,
  617. .con_startup = newport_startup,
  618. .con_init = newport_init,
  619. .con_deinit = newport_deinit,
  620. .con_clear = newport_clear,
  621. .con_putc = newport_putc,
  622. .con_putcs = newport_putcs,
  623. .con_cursor = newport_cursor,
  624. .con_scroll = newport_scroll,
  625. .con_bmove = newport_bmove,
  626. .con_switch = newport_switch,
  627. .con_blank = newport_blank,
  628. .con_font_set = newport_font_set,
  629. .con_font_default = newport_font_default,
  630. .con_set_palette = newport_set_palette,
  631. .con_scrolldelta = newport_scrolldelta,
  632. .con_set_origin = DUMMY,
  633. .con_save_screen = DUMMY
  634. };
  635. static int newport_probe(struct gio_device *dev,
  636. const struct gio_device_id *id)
  637. {
  638. unsigned long newport_addr;
  639. int err;
  640. if (!dev->resource.start)
  641. return -EINVAL;
  642. if (npregs)
  643. return -EBUSY; /* we only support one Newport as console */
  644. newport_addr = dev->resource.start + 0xF0000;
  645. if (!request_mem_region(newport_addr, 0x10000, "Newport"))
  646. return -ENODEV;
  647. npregs = (struct newport_regs *)/* ioremap cannot fail */
  648. ioremap(newport_addr, sizeof(struct newport_regs));
  649. console_lock();
  650. err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1);
  651. console_unlock();
  652. return err;
  653. }
  654. static void newport_remove(struct gio_device *dev)
  655. {
  656. give_up_console(&newport_con);
  657. iounmap((void *)npregs);
  658. }
  659. static struct gio_device_id newport_ids[] = {
  660. { .id = 0x7e },
  661. { .id = 0xff }
  662. };
  663. MODULE_ALIAS("gio:7e");
  664. static struct gio_driver newport_driver = {
  665. .name = "newport",
  666. .id_table = newport_ids,
  667. .probe = newport_probe,
  668. .remove = newport_remove,
  669. };
  670. int __init newport_console_init(void)
  671. {
  672. return gio_register_driver(&newport_driver);
  673. }
  674. void __exit newport_console_exit(void)
  675. {
  676. gio_unregister_driver(&newport_driver);
  677. }
  678. module_init(newport_console_init);
  679. module_exit(newport_console_exit);
  680. MODULE_LICENSE("GPL");