sticon.c 9.4 KB

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