sticon.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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/console.h>
  40. #include <linux/errno.h>
  41. #include <linux/vt_kern.h>
  42. #include <linux/kd.h>
  43. #include <linux/selection.h>
  44. #include <linux/module.h>
  45. #include <asm/io.h>
  46. #include "../fbdev/sticore.h"
  47. /* switching to graphics mode */
  48. #define BLANK 0
  49. static int vga_is_gfx;
  50. /* this is the sti_struct used for this console */
  51. static struct sti_struct *sticon_sti;
  52. /* Software scrollback */
  53. static unsigned long softback_buf, softback_curr;
  54. static unsigned long softback_in;
  55. static unsigned long /* softback_top, */ softback_end;
  56. static int softback_lines;
  57. /* software cursor */
  58. static int cursor_drawn;
  59. #define CURSOR_DRAW_DELAY (1)
  60. #define DEFAULT_CURSOR_BLINK_RATE (20)
  61. static int vbl_cursor_cnt;
  62. static inline void cursor_undrawn(void)
  63. {
  64. vbl_cursor_cnt = 0;
  65. cursor_drawn = 0;
  66. }
  67. static const char *sticon_startup(void)
  68. {
  69. return "STI console";
  70. }
  71. static void sticon_putc(struct vc_data *conp, int c, int ypos, int xpos)
  72. {
  73. int redraw_cursor = 0;
  74. if (vga_is_gfx || console_blanked)
  75. return;
  76. if (conp->vc_mode != KD_TEXT)
  77. return;
  78. #if 0
  79. if ((p->cursor_x == xpos) && (p->cursor_y == ypos)) {
  80. cursor_undrawn();
  81. redraw_cursor = 1;
  82. }
  83. #endif
  84. sti_putc(sticon_sti, c, ypos, xpos);
  85. if (redraw_cursor)
  86. vbl_cursor_cnt = CURSOR_DRAW_DELAY;
  87. }
  88. static void sticon_putcs(struct vc_data *conp, const unsigned short *s,
  89. int count, int ypos, int xpos)
  90. {
  91. int redraw_cursor = 0;
  92. if (vga_is_gfx || console_blanked)
  93. return;
  94. if (conp->vc_mode != KD_TEXT)
  95. return;
  96. #if 0
  97. if ((p->cursor_y == ypos) && (xpos <= p->cursor_x) &&
  98. (p->cursor_x < (xpos + count))) {
  99. cursor_undrawn();
  100. redraw_cursor = 1;
  101. }
  102. #endif
  103. while (count--) {
  104. sti_putc(sticon_sti, scr_readw(s++), ypos, xpos++);
  105. }
  106. if (redraw_cursor)
  107. vbl_cursor_cnt = CURSOR_DRAW_DELAY;
  108. }
  109. static void sticon_cursor(struct vc_data *conp, int mode)
  110. {
  111. unsigned short car1;
  112. car1 = conp->vc_screenbuf[conp->vc_x + conp->vc_y * conp->vc_cols];
  113. switch (mode) {
  114. case CM_ERASE:
  115. sti_putc(sticon_sti, car1, conp->vc_y, conp->vc_x);
  116. break;
  117. case CM_MOVE:
  118. case CM_DRAW:
  119. switch (conp->vc_cursor_type & 0x0f) {
  120. case CUR_UNDERLINE:
  121. case CUR_LOWER_THIRD:
  122. case CUR_LOWER_HALF:
  123. case CUR_TWO_THIRDS:
  124. case CUR_BLOCK:
  125. sti_putc(sticon_sti, (car1 & 255) + (0 << 8) + (7 << 11),
  126. conp->vc_y, conp->vc_x);
  127. break;
  128. }
  129. break;
  130. }
  131. }
  132. static bool sticon_scroll(struct vc_data *conp, unsigned int t,
  133. unsigned int b, enum con_scroll dir, unsigned int count)
  134. {
  135. struct sti_struct *sti = sticon_sti;
  136. if (vga_is_gfx)
  137. return false;
  138. sticon_cursor(conp, CM_ERASE);
  139. switch (dir) {
  140. case SM_UP:
  141. sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols);
  142. sti_clear(sti, b - count, 0, count, conp->vc_cols, conp->vc_video_erase_char);
  143. break;
  144. case SM_DOWN:
  145. sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols);
  146. sti_clear(sti, t, 0, count, conp->vc_cols, conp->vc_video_erase_char);
  147. break;
  148. }
  149. return false;
  150. }
  151. static void sticon_init(struct vc_data *c, int init)
  152. {
  153. struct sti_struct *sti = sticon_sti;
  154. int vc_cols, vc_rows;
  155. sti_set(sti, 0, 0, sti_onscreen_y(sti), sti_onscreen_x(sti), 0);
  156. vc_cols = sti_onscreen_x(sti) / sti->font_width;
  157. vc_rows = sti_onscreen_y(sti) / sti->font_height;
  158. c->vc_can_do_color = 1;
  159. if (init) {
  160. c->vc_cols = vc_cols;
  161. c->vc_rows = vc_rows;
  162. } else {
  163. /* vc_rows = (c->vc_rows > vc_rows) ? vc_rows : c->vc_rows; */
  164. /* vc_cols = (c->vc_cols > vc_cols) ? vc_cols : c->vc_cols; */
  165. vc_resize(c, vc_cols, vc_rows);
  166. /* vc_resize_con(vc_rows, vc_cols, c->vc_num); */
  167. }
  168. }
  169. static void sticon_deinit(struct vc_data *c)
  170. {
  171. }
  172. static void sticon_clear(struct vc_data *conp, int sy, int sx, int height,
  173. int width)
  174. {
  175. if (!height || !width)
  176. return;
  177. sti_clear(sticon_sti, sy, sx, height, width, conp->vc_video_erase_char);
  178. }
  179. static int sticon_switch(struct vc_data *conp)
  180. {
  181. return 1; /* needs refreshing */
  182. }
  183. static int sticon_set_origin(struct vc_data *conp)
  184. {
  185. return 0;
  186. }
  187. static int sticon_blank(struct vc_data *c, int blank, int mode_switch)
  188. {
  189. if (blank == 0) {
  190. if (mode_switch)
  191. vga_is_gfx = 0;
  192. return 1;
  193. }
  194. sticon_set_origin(c);
  195. sti_clear(sticon_sti, 0,0, c->vc_rows, c->vc_cols, BLANK);
  196. if (mode_switch)
  197. vga_is_gfx = 1;
  198. return 1;
  199. }
  200. static u16 *sticon_screen_pos(struct vc_data *conp, int offset)
  201. {
  202. int line;
  203. unsigned long p;
  204. if (conp->vc_num != fg_console || !softback_lines)
  205. return (u16 *)(conp->vc_origin + offset);
  206. line = offset / conp->vc_size_row;
  207. if (line >= softback_lines)
  208. return (u16 *)(conp->vc_origin + offset - softback_lines * conp->vc_size_row);
  209. p = softback_curr + offset;
  210. if (p >= softback_end)
  211. p += softback_buf - softback_end;
  212. return (u16 *)p;
  213. }
  214. static unsigned long sticon_getxy(struct vc_data *conp, unsigned long pos,
  215. int *px, int *py)
  216. {
  217. int x, y;
  218. unsigned long ret;
  219. if (pos >= conp->vc_origin && pos < conp->vc_scr_end) {
  220. unsigned long offset = (pos - conp->vc_origin) / 2;
  221. x = offset % conp->vc_cols;
  222. y = offset / conp->vc_cols;
  223. if (conp->vc_num == fg_console)
  224. y += softback_lines;
  225. ret = pos + (conp->vc_cols - x) * 2;
  226. } else if (conp->vc_num == fg_console && softback_lines) {
  227. unsigned long offset = pos - softback_curr;
  228. if (pos < softback_curr)
  229. offset += softback_end - softback_buf;
  230. offset /= 2;
  231. x = offset % conp->vc_cols;
  232. y = offset / conp->vc_cols;
  233. ret = pos + (conp->vc_cols - x) * 2;
  234. if (ret == softback_end)
  235. ret = softback_buf;
  236. if (ret == softback_in)
  237. ret = conp->vc_origin;
  238. } else {
  239. /* Should not happen */
  240. x = y = 0;
  241. ret = conp->vc_origin;
  242. }
  243. if (px) *px = x;
  244. if (py) *py = y;
  245. return ret;
  246. }
  247. static u8 sticon_build_attr(struct vc_data *conp, u8 color, u8 intens,
  248. u8 blink, u8 underline, u8 reverse, u8 italic)
  249. {
  250. u8 attr = ((color & 0x70) >> 1) | ((color & 7));
  251. if (reverse) {
  252. color = ((color >> 3) & 0x7) | ((color & 0x7) << 3);
  253. }
  254. return attr;
  255. }
  256. static void sticon_invert_region(struct vc_data *conp, u16 *p, int count)
  257. {
  258. int col = 1; /* vga_can_do_color; */
  259. while (count--) {
  260. u16 a = scr_readw(p);
  261. if (col)
  262. a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
  263. else
  264. a = ((a & 0x0700) == 0x0100) ? 0x7000 : 0x7700;
  265. scr_writew(a, p++);
  266. }
  267. }
  268. static void sticon_save_screen(struct vc_data *conp)
  269. {
  270. }
  271. static const struct consw sti_con = {
  272. .owner = THIS_MODULE,
  273. .con_startup = sticon_startup,
  274. .con_init = sticon_init,
  275. .con_deinit = sticon_deinit,
  276. .con_clear = sticon_clear,
  277. .con_putc = sticon_putc,
  278. .con_putcs = sticon_putcs,
  279. .con_cursor = sticon_cursor,
  280. .con_scroll = sticon_scroll,
  281. .con_switch = sticon_switch,
  282. .con_blank = sticon_blank,
  283. .con_set_origin = sticon_set_origin,
  284. .con_save_screen = sticon_save_screen,
  285. .con_build_attr = sticon_build_attr,
  286. .con_invert_region = sticon_invert_region,
  287. .con_screen_pos = sticon_screen_pos,
  288. .con_getxy = sticon_getxy,
  289. };
  290. static int __init sticonsole_init(void)
  291. {
  292. int err;
  293. /* already initialized ? */
  294. if (sticon_sti)
  295. return 0;
  296. sticon_sti = sti_get_rom(0);
  297. if (!sticon_sti)
  298. return -ENODEV;
  299. if (conswitchp == &dummy_con) {
  300. printk(KERN_INFO "sticon: Initializing STI text console.\n");
  301. console_lock();
  302. err = do_take_over_console(&sti_con, 0, MAX_NR_CONSOLES - 1, 1);
  303. console_unlock();
  304. return err;
  305. }
  306. return 0;
  307. }
  308. module_init(sticonsole_init);
  309. MODULE_LICENSE("GPL");