sticon.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. * linux/drivers/video/console/sticon.c - console driver using HP's STI firmware
  3. *
  4. * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
  5. * Copyright (C) 2002 Helge Deller <deller@gmx.de>
  6. *
  7. * Based on linux/drivers/video/vgacon.c and linux/drivers/video/fbcon.c,
  8. * which were
  9. *
  10. * Created 28 Sep 1997 by Geert Uytterhoeven
  11. * Rewritten by Martin Mares <mj@ucw.cz>, July 1998
  12. * Copyright (C) 1991, 1992 Linus Torvalds
  13. * 1995 Jay Estabrook
  14. * Copyright (C) 1995 Geert Uytterhoeven
  15. * Copyright (C) 1993 Bjoern Brauel
  16. * Roman Hodek
  17. * Copyright (C) 1993 Hamish Macdonald
  18. * Greg Harp
  19. * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
  20. *
  21. * with work by William Rucklidge (wjr@cs.cornell.edu)
  22. * Geert Uytterhoeven
  23. * Jes Sorensen (jds@kom.auc.dk)
  24. * Martin Apel
  25. * with work by Guenther Kelleter
  26. * Martin Schaller
  27. * Andreas Schwab
  28. * Emmanuel Marty (core@ggi-project.org)
  29. * Jakub Jelinek (jj@ultra.linux.cz)
  30. * Martin Mares <mj@ucw.cz>
  31. *
  32. * This file is subject to the terms and conditions of the GNU General Public
  33. * License. See the file COPYING in the main directory of this archive for
  34. * more details.
  35. *
  36. */
  37. #include <linux/init.h>
  38. #include <linux/kernel.h>
  39. #include <linux/tty.h>
  40. #include <linux/console.h>
  41. #include <linux/errno.h>
  42. #include <linux/vt_kern.h>
  43. #include <linux/kd.h>
  44. #include <linux/selection.h>
  45. #include <linux/module.h>
  46. #include <asm/io.h>
  47. #include "../sticore.h"
  48. /* switching to graphics mode */
  49. #define BLANK 0
  50. static int vga_is_gfx;
  51. /* this is the sti_struct used for this console */
  52. static struct sti_struct *sticon_sti;
  53. /* Software scrollback */
  54. static unsigned long softback_buf, softback_curr;
  55. static unsigned long softback_in;
  56. static unsigned long /* softback_top, */ softback_end;
  57. static int softback_lines;
  58. /* software cursor */
  59. static int cursor_drawn;
  60. #define CURSOR_DRAW_DELAY (1)
  61. #define DEFAULT_CURSOR_BLINK_RATE (20)
  62. static int vbl_cursor_cnt;
  63. static inline void cursor_undrawn(void)
  64. {
  65. vbl_cursor_cnt = 0;
  66. cursor_drawn = 0;
  67. }
  68. static const char *__init sticon_startup(void)
  69. {
  70. return "STI console";
  71. }
  72. static int sticon_set_palette(struct vc_data *c, unsigned char *table)
  73. {
  74. return -EINVAL;
  75. }
  76. static void sticon_putc(struct vc_data *conp, int c, int ypos, int xpos)
  77. {
  78. int redraw_cursor = 0;
  79. if (vga_is_gfx || console_blanked)
  80. return;
  81. if (conp->vc_mode != KD_TEXT)
  82. return;
  83. #if 0
  84. if ((p->cursor_x == xpos) && (p->cursor_y == ypos)) {
  85. cursor_undrawn();
  86. redraw_cursor = 1;
  87. }
  88. #endif
  89. sti_putc(sticon_sti, c, ypos, xpos);
  90. if (redraw_cursor)
  91. vbl_cursor_cnt = CURSOR_DRAW_DELAY;
  92. }
  93. static void sticon_putcs(struct vc_data *conp, const unsigned short *s,
  94. int count, int ypos, int xpos)
  95. {
  96. int redraw_cursor = 0;
  97. if (vga_is_gfx || console_blanked)
  98. return;
  99. if (conp->vc_mode != KD_TEXT)
  100. return;
  101. #if 0
  102. if ((p->cursor_y == ypos) && (xpos <= p->cursor_x) &&
  103. (p->cursor_x < (xpos + count))) {
  104. cursor_undrawn();
  105. redraw_cursor = 1;
  106. }
  107. #endif
  108. while (count--) {
  109. sti_putc(sticon_sti, scr_readw(s++), ypos, xpos++);
  110. }
  111. if (redraw_cursor)
  112. vbl_cursor_cnt = CURSOR_DRAW_DELAY;
  113. }
  114. static void sticon_cursor(struct vc_data *conp, int mode)
  115. {
  116. unsigned short car1;
  117. car1 = conp->vc_screenbuf[conp->vc_x + conp->vc_y * conp->vc_cols];
  118. switch (mode) {
  119. case CM_ERASE:
  120. sti_putc(sticon_sti, car1, conp->vc_y, conp->vc_x);
  121. break;
  122. case CM_MOVE:
  123. case CM_DRAW:
  124. switch (conp->vc_cursor_type & 0x0f) {
  125. case CUR_UNDERLINE:
  126. case CUR_LOWER_THIRD:
  127. case CUR_LOWER_HALF:
  128. case CUR_TWO_THIRDS:
  129. case CUR_BLOCK:
  130. sti_putc(sticon_sti, (car1 & 255) + (0 << 8) + (7 << 11),
  131. conp->vc_y, conp->vc_x);
  132. break;
  133. }
  134. break;
  135. }
  136. }
  137. static int sticon_scroll(struct vc_data *conp, int t, int b, int dir, int count)
  138. {
  139. struct sti_struct *sti = sticon_sti;
  140. if (vga_is_gfx)
  141. return 0;
  142. sticon_cursor(conp, CM_ERASE);
  143. switch (dir) {
  144. case SM_UP:
  145. sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols);
  146. sti_clear(sti, b - count, 0, count, conp->vc_cols, conp->vc_video_erase_char);
  147. break;
  148. case SM_DOWN:
  149. sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols);
  150. sti_clear(sti, t, 0, count, conp->vc_cols, conp->vc_video_erase_char);
  151. break;
  152. }
  153. return 0;
  154. }
  155. static void sticon_bmove(struct vc_data *conp, int sy, int sx,
  156. int dy, int dx, int height, int width)
  157. {
  158. if (!width || !height)
  159. return;
  160. #if 0
  161. if (((sy <= p->cursor_y) && (p->cursor_y < sy+height) &&
  162. (sx <= p->cursor_x) && (p->cursor_x < sx+width)) ||
  163. ((dy <= p->cursor_y) && (p->cursor_y < dy+height) &&
  164. (dx <= p->cursor_x) && (p->cursor_x < dx+width)))
  165. sticon_cursor(p, CM_ERASE /*|CM_SOFTBACK*/);
  166. #endif
  167. sti_bmove(sticon_sti, sy, sx, dy, dx, height, width);
  168. }
  169. static void sticon_init(struct vc_data *c, int init)
  170. {
  171. struct sti_struct *sti = sticon_sti;
  172. int vc_cols, vc_rows;
  173. sti_set(sti, 0, 0, sti_onscreen_y(sti), sti_onscreen_x(sti), 0);
  174. vc_cols = sti_onscreen_x(sti) / sti->font_width;
  175. vc_rows = sti_onscreen_y(sti) / sti->font_height;
  176. c->vc_can_do_color = 1;
  177. if (init) {
  178. c->vc_cols = vc_cols;
  179. c->vc_rows = vc_rows;
  180. } else {
  181. /* vc_rows = (c->vc_rows > vc_rows) ? vc_rows : c->vc_rows; */
  182. /* vc_cols = (c->vc_cols > vc_cols) ? vc_cols : c->vc_cols; */
  183. vc_resize(c, vc_cols, vc_rows);
  184. /* vc_resize_con(vc_rows, vc_cols, c->vc_num); */
  185. }
  186. }
  187. static void sticon_deinit(struct vc_data *c)
  188. {
  189. }
  190. static void sticon_clear(struct vc_data *conp, int sy, int sx, int height,
  191. int width)
  192. {
  193. if (!height || !width)
  194. return;
  195. sti_clear(sticon_sti, sy, sx, height, width, conp->vc_video_erase_char);
  196. }
  197. static int sticon_switch(struct vc_data *conp)
  198. {
  199. return 1; /* needs refreshing */
  200. }
  201. static int sticon_set_origin(struct vc_data *conp)
  202. {
  203. return 0;
  204. }
  205. static int sticon_blank(struct vc_data *c, int blank, int mode_switch)
  206. {
  207. if (blank == 0) {
  208. if (mode_switch)
  209. vga_is_gfx = 0;
  210. return 1;
  211. }
  212. sticon_set_origin(c);
  213. sti_clear(sticon_sti, 0,0, c->vc_rows, c->vc_cols, BLANK);
  214. if (mode_switch)
  215. vga_is_gfx = 1;
  216. return 1;
  217. }
  218. static int sticon_scrolldelta(struct vc_data *conp, int lines)
  219. {
  220. return 0;
  221. }
  222. static u16 *sticon_screen_pos(struct vc_data *conp, int offset)
  223. {
  224. int line;
  225. unsigned long p;
  226. if (conp->vc_num != fg_console || !softback_lines)
  227. return (u16 *)(conp->vc_origin + offset);
  228. line = offset / conp->vc_size_row;
  229. if (line >= softback_lines)
  230. return (u16 *)(conp->vc_origin + offset - softback_lines * conp->vc_size_row);
  231. p = softback_curr + offset;
  232. if (p >= softback_end)
  233. p += softback_buf - softback_end;
  234. return (u16 *)p;
  235. }
  236. static unsigned long sticon_getxy(struct vc_data *conp, unsigned long pos,
  237. int *px, int *py)
  238. {
  239. int x, y;
  240. unsigned long ret;
  241. if (pos >= conp->vc_origin && pos < conp->vc_scr_end) {
  242. unsigned long offset = (pos - conp->vc_origin) / 2;
  243. x = offset % conp->vc_cols;
  244. y = offset / conp->vc_cols;
  245. if (conp->vc_num == fg_console)
  246. y += softback_lines;
  247. ret = pos + (conp->vc_cols - x) * 2;
  248. } else if (conp->vc_num == fg_console && softback_lines) {
  249. unsigned long offset = pos - softback_curr;
  250. if (pos < softback_curr)
  251. offset += softback_end - softback_buf;
  252. offset /= 2;
  253. x = offset % conp->vc_cols;
  254. y = offset / conp->vc_cols;
  255. ret = pos + (conp->vc_cols - x) * 2;
  256. if (ret == softback_end)
  257. ret = softback_buf;
  258. if (ret == softback_in)
  259. ret = conp->vc_origin;
  260. } else {
  261. /* Should not happen */
  262. x = y = 0;
  263. ret = conp->vc_origin;
  264. }
  265. if (px) *px = x;
  266. if (py) *py = y;
  267. return ret;
  268. }
  269. static u8 sticon_build_attr(struct vc_data *conp, u8 color, u8 intens,
  270. u8 blink, u8 underline, u8 reverse)
  271. {
  272. u8 attr = ((color & 0x70) >> 1) | ((color & 7));
  273. if (reverse) {
  274. color = ((color >> 3) & 0x7) | ((color & 0x7) << 3);
  275. }
  276. return attr;
  277. }
  278. static void sticon_invert_region(struct vc_data *conp, u16 *p, int count)
  279. {
  280. int col = 1; /* vga_can_do_color; */
  281. while (count--) {
  282. u16 a = scr_readw(p);
  283. if (col)
  284. a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
  285. else
  286. a = ((a & 0x0700) == 0x0100) ? 0x7000 : 0x7700;
  287. scr_writew(a, p++);
  288. }
  289. }
  290. static void sticon_save_screen(struct vc_data *conp)
  291. {
  292. }
  293. static struct consw sti_con = {
  294. .owner = THIS_MODULE,
  295. .con_startup = sticon_startup,
  296. .con_init = sticon_init,
  297. .con_deinit = sticon_deinit,
  298. .con_clear = sticon_clear,
  299. .con_putc = sticon_putc,
  300. .con_putcs = sticon_putcs,
  301. .con_cursor = sticon_cursor,
  302. .con_scroll = sticon_scroll,
  303. .con_bmove = sticon_bmove,
  304. .con_switch = sticon_switch,
  305. .con_blank = sticon_blank,
  306. .con_set_palette = sticon_set_palette,
  307. .con_scrolldelta = sticon_scrolldelta,
  308. .con_set_origin = sticon_set_origin,
  309. .con_save_screen = sticon_save_screen,
  310. .con_build_attr = sticon_build_attr,
  311. .con_invert_region = sticon_invert_region,
  312. .con_screen_pos = sticon_screen_pos,
  313. .con_getxy = sticon_getxy,
  314. };
  315. int __init sticonsole_init(void)
  316. {
  317. /* already initialized ? */
  318. if (sticon_sti)
  319. return 0;
  320. sticon_sti = sti_get_rom(0);
  321. if (!sticon_sti)
  322. return -ENODEV;
  323. if (conswitchp == &dummy_con) {
  324. printk(KERN_INFO "sticon: Initializing STI text console.\n");
  325. return take_over_console(&sti_con, 0, MAX_NR_CONSOLES - 1, 1);
  326. }
  327. return 0;
  328. }
  329. module_init(sticonsole_init);
  330. MODULE_LICENSE("GPL");