sticon.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * linux/drivers/video/console/sticon.c - console driver using HP's STI firmware
  3. *
  4. * Copyright (C) 2000 Philipp Rumpf <[email protected]>
  5. * Copyright (C) 2002 Helge Deller <[email protected]>
  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 <[email protected]>, 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 [[email protected]]
  20. *
  21. * with work by William Rucklidge ([email protected])
  22. * Geert Uytterhoeven
  23. * Jes Sorensen ([email protected])
  24. * Martin Apel
  25. * with work by Guenther Kelleter
  26. * Martin Schaller
  27. * Andreas Schwab
  28. * Emmanuel Marty ([email protected])
  29. * Jakub Jelinek ([email protected])
  30. * Martin Mares <[email protected]>
  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 int sticon_scroll(struct vc_data *conp, int t, int b, int dir, int count)
  133. {
  134. struct sti_struct *sti = sticon_sti;
  135. if (vga_is_gfx)
  136. return 0;
  137. sticon_cursor(conp, CM_ERASE);
  138. switch (dir) {
  139. case SM_UP:
  140. sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols);
  141. sti_clear(sti, b - count, 0, count, conp->vc_cols, conp->vc_video_erase_char);
  142. break;
  143. case SM_DOWN:
  144. sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols);
  145. sti_clear(sti, t, 0, count, conp->vc_cols, conp->vc_video_erase_char);
  146. break;
  147. }
  148. return 0;
  149. }
  150. static void sticon_init(struct vc_data *c, int init)
  151. {
  152. struct sti_struct *sti = sticon_sti;
  153. int vc_cols, vc_rows;
  154. sti_set(sti, 0, 0, sti_onscreen_y(sti), sti_onscreen_x(sti), 0);
  155. vc_cols = sti_onscreen_x(sti) / sti->font_width;
  156. vc_rows = sti_onscreen_y(sti) / sti->font_height;
  157. c->vc_can_do_color = 1;
  158. if (init) {
  159. c->vc_cols = vc_cols;
  160. c->vc_rows = vc_rows;
  161. } else {
  162. /* vc_rows = (c->vc_rows > vc_rows) ? vc_rows : c->vc_rows; */
  163. /* vc_cols = (c->vc_cols > vc_cols) ? vc_cols : c->vc_cols; */
  164. vc_resize(c, vc_cols, vc_rows);
  165. /* vc_resize_con(vc_rows, vc_cols, c->vc_num); */
  166. }
  167. }
  168. static void sticon_deinit(struct vc_data *c)
  169. {
  170. }
  171. static void sticon_clear(struct vc_data *conp, int sy, int sx, int height,
  172. int width)
  173. {
  174. if (!height || !width)
  175. return;
  176. sti_clear(sticon_sti, sy, sx, height, width, conp->vc_video_erase_char);
  177. }
  178. static int sticon_switch(struct vc_data *conp)
  179. {
  180. return 1; /* needs refreshing */
  181. }
  182. static int sticon_set_origin(struct vc_data *conp)
  183. {
  184. return 0;
  185. }
  186. static int sticon_blank(struct vc_data *c, int blank, int mode_switch)
  187. {
  188. if (blank == 0) {
  189. if (mode_switch)
  190. vga_is_gfx = 0;
  191. return 1;
  192. }
  193. sticon_set_origin(c);
  194. sti_clear(sticon_sti, 0,0, c->vc_rows, c->vc_cols, BLANK);
  195. if (mode_switch)
  196. vga_is_gfx = 1;
  197. return 1;
  198. }
  199. static u16 *sticon_screen_pos(struct vc_data *conp, int offset)
  200. {
  201. int line;
  202. unsigned long p;
  203. if (conp->vc_num != fg_console || !softback_lines)
  204. return (u16 *)(conp->vc_origin + offset);
  205. line = offset / conp->vc_size_row;
  206. if (line >= softback_lines)
  207. return (u16 *)(conp->vc_origin + offset - softback_lines * conp->vc_size_row);
  208. p = softback_curr + offset;
  209. if (p >= softback_end)
  210. p += softback_buf - softback_end;
  211. return (u16 *)p;
  212. }
  213. static unsigned long sticon_getxy(struct vc_data *conp, unsigned long pos,
  214. int *px, int *py)
  215. {
  216. int x, y;
  217. unsigned long ret;
  218. if (pos >= conp->vc_origin && pos < conp->vc_scr_end) {
  219. unsigned long offset = (pos - conp->vc_origin) / 2;
  220. x = offset % conp->vc_cols;
  221. y = offset / conp->vc_cols;
  222. if (conp->vc_num == fg_console)
  223. y += softback_lines;
  224. ret = pos + (conp->vc_cols - x) * 2;
  225. } else if (conp->vc_num == fg_console && softback_lines) {
  226. unsigned long offset = pos - softback_curr;
  227. if (pos < softback_curr)
  228. offset += softback_end - softback_buf;
  229. offset /= 2;
  230. x = offset % conp->vc_cols;
  231. y = offset / conp->vc_cols;
  232. ret = pos + (conp->vc_cols - x) * 2;
  233. if (ret == softback_end)
  234. ret = softback_buf;
  235. if (ret == softback_in)
  236. ret = conp->vc_origin;
  237. } else {
  238. /* Should not happen */
  239. x = y = 0;
  240. ret = conp->vc_origin;
  241. }
  242. if (px) *px = x;
  243. if (py) *py = y;
  244. return ret;
  245. }
  246. static u8 sticon_build_attr(struct vc_data *conp, u8 color, u8 intens,
  247. u8 blink, u8 underline, u8 reverse, u8 italic)
  248. {
  249. u8 attr = ((color & 0x70) >> 1) | ((color & 7));
  250. if (reverse) {
  251. color = ((color >> 3) & 0x7) | ((color & 0x7) << 3);
  252. }
  253. return attr;
  254. }
  255. static void sticon_invert_region(struct vc_data *conp, u16 *p, int count)
  256. {
  257. int col = 1; /* vga_can_do_color; */
  258. while (count--) {
  259. u16 a = scr_readw(p);
  260. if (col)
  261. a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
  262. else
  263. a = ((a & 0x0700) == 0x0100) ? 0x7000 : 0x7700;
  264. scr_writew(a, p++);
  265. }
  266. }
  267. static void sticon_save_screen(struct vc_data *conp)
  268. {
  269. }
  270. static const struct consw sti_con = {
  271. .owner = THIS_MODULE,
  272. .con_startup = sticon_startup,
  273. .con_init = sticon_init,
  274. .con_deinit = sticon_deinit,
  275. .con_clear = sticon_clear,
  276. .con_putc = sticon_putc,
  277. .con_putcs = sticon_putcs,
  278. .con_cursor = sticon_cursor,
  279. .con_scroll = sticon_scroll,
  280. .con_switch = sticon_switch,
  281. .con_blank = sticon_blank,
  282. .con_set_origin = sticon_set_origin,
  283. .con_save_screen = sticon_save_screen,
  284. .con_build_attr = sticon_build_attr,
  285. .con_invert_region = sticon_invert_region,
  286. .con_screen_pos = sticon_screen_pos,
  287. .con_getxy = sticon_getxy,
  288. };
  289. static int __init sticonsole_init(void)
  290. {
  291. int err;
  292. /* already initialized ? */
  293. if (sticon_sti)
  294. return 0;
  295. sticon_sti = sti_get_rom(0);
  296. if (!sticon_sti)
  297. return -ENODEV;
  298. if (conswitchp == &dummy_con) {
  299. printk(KERN_INFO "sticon: Initializing STI text console.\n");
  300. console_lock();
  301. err = do_take_over_console(&sti_con, 0, MAX_NR_CONSOLES - 1, 1);
  302. console_unlock();
  303. return err;
  304. }
  305. return 0;
  306. }
  307. module_init(sticonsole_init);
  308. MODULE_LICENSE("GPL");