cfb_console.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  1. /*
  2. * (C) Copyright 2002 ELTEC Elektronik AG
  3. * Frank Gottschling <fgottschling@eltec.de>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * cfb_console.c
  25. *
  26. * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
  27. *
  28. * At the moment only the 8x16 font is tested and the font fore- and
  29. * background color is limited to black/white/gray colors. The Linux
  30. * logo can be placed in the upper left corner and additional board
  31. * information strings (that normaly goes to serial port) can be drawed.
  32. *
  33. * The console driver can use the standard PC keyboard interface (i8042)
  34. * for character input. Character output goes to a memory mapped video
  35. * framebuffer with little or big-endian organisation.
  36. * With environment setting 'console=serial' the console i/o can be
  37. * forced to serial port.
  38. The driver uses graphic specific defines/parameters/functions:
  39. (for SMI LynxE graphic chip)
  40. CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810
  41. VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
  42. VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
  43. VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
  44. Console Parameters are set by graphic drivers global struct:
  45. VIDEO_VISIBLE_COLS - x resolution
  46. VIDEO_VISIBLE_ROWS - y resolution
  47. VIDEO_PIXEL_SIZE - storage size in byte per pixel
  48. VIDEO_DATA_FORMAT - graphical data format GDF
  49. VIDEO_FB_ADRS - start of video memory
  50. CONFIG_I8042_KBD - AT Keyboard driver for i8042
  51. VIDEO_KBD_INIT_FCT - init function for keyboard
  52. VIDEO_TSTC_FCT - keyboard_tstc function
  53. VIDEO_GETC_FCT - keyboard_getc function
  54. CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with delay
  55. loop in VIDEO_TSTC_FCT (i8042)
  56. CFG_CONSOLE_BLINK_COUNT - value for delay loop - blink rate
  57. CONFIG_CONSOLE_TIME - display time/date in upper right corner,
  58. needs CFG_CMD_DATE and CONFIG_CONSOLE_CURSOR
  59. CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner
  60. CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
  61. CONFIG_CONSOLE_EXTRA_INFO - display additional board information strings
  62. that normaly goes to serial port. This define
  63. requires a board specific function:
  64. video_drawstring (VIDEO_INFO_X,
  65. VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
  66. info);
  67. that fills a info buffer at i=row.
  68. s.a: board/eltec/bab7xx.
  69. CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be initialised
  70. as an output only device. The Keyboard driver
  71. will not be set-up. This may be used, if you
  72. have none or more than one Keyboard devices
  73. (USB Keyboard, AT Keyboard).
  74. CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last character. No
  75. blinking is provided. Uses the macros CURSOR_SET
  76. and CURSOR_OFF.
  77. CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability of the
  78. graphic chip. Uses the macro CURSOR_SET.
  79. ATTENTION: If booting an OS, the display driver
  80. must disable the hardware register of the graphic
  81. chip. Otherwise a blinking field is displayed
  82. */
  83. #include <common.h>
  84. #ifdef CONFIG_CFB_CONSOLE
  85. #include <malloc.h>
  86. /*****************************************************************************/
  87. /* Console device defines with SMI graphic */
  88. /* Any other graphic must change this section */
  89. /*****************************************************************************/
  90. #ifdef CONFIG_VIDEO_SMI_LYNXEM
  91. #define VIDEO_FB_LITTLE_ENDIAN
  92. #define VIDEO_HW_RECTFILL
  93. #define VIDEO_HW_BITBLT
  94. #endif
  95. /*****************************************************************************/
  96. /* Defines for the CT69000 driver */
  97. /*****************************************************************************/
  98. #ifdef CONFIG_VIDEO_CT69000
  99. #define VIDEO_FB_LITTLE_ENDIAN
  100. #define VIDEO_HW_RECTFILL
  101. #define VIDEO_HW_BITBLT
  102. #endif
  103. /*****************************************************************************/
  104. /* Defines for the SED13806 driver */
  105. /*****************************************************************************/
  106. #ifdef CONFIG_VIDEO_SED13806
  107. #define VIDEO_FB_LITTLE_ENDIAN
  108. #define VIDEO_HW_RECTFILL
  109. #define VIDEO_HW_BITBLT
  110. #endif
  111. /*****************************************************************************/
  112. /* Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc */
  113. /*****************************************************************************/
  114. #include <video_fb.h>
  115. /*****************************************************************************/
  116. /* some Macros */
  117. /*****************************************************************************/
  118. #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
  119. #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
  120. #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
  121. #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
  122. #define VIDEO_FB_ADRS (pGD->frameAdrs)
  123. /*****************************************************************************/
  124. /* Console device defines with i8042 keyboard controller */
  125. /* Any other keyboard controller must change this section */
  126. /*****************************************************************************/
  127. #ifdef CONFIG_I8042_KBD
  128. #include <i8042.h>
  129. #define VIDEO_KBD_INIT_FCT i8042_kbd_init()
  130. #define VIDEO_TSTC_FCT i8042_tstc
  131. #define VIDEO_GETC_FCT i8042_getc
  132. #endif
  133. /*****************************************************************************/
  134. /* Console device */
  135. /*****************************************************************************/
  136. #include <version.h>
  137. #include <linux/types.h>
  138. #include <devices.h>
  139. #include <video_font.h>
  140. #ifdef CFG_CMD_DATE
  141. #include <rtc.h>
  142. #endif
  143. #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  144. #include <watchdog.h>
  145. #include <bmp_layout.h>
  146. #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
  147. /*****************************************************************************/
  148. /* Cursor definition: */
  149. /* CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/i8042.c) to */
  150. /* let the cursor blink. Uses the macros CURSOR_OFF */
  151. /* and CURSOR_ON. */
  152. /* CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No */
  153. /* blinking is provided. Uses the macros CURSOR_SET */
  154. /* and CURSOR_OFF. */
  155. /* CONFIG_VIDEO_HW_CURSOR: Uses the hardware cursor capability of the */
  156. /* graphic chip. Uses the macro CURSOR_SET. */
  157. /* ATTENTION: If booting an OS, the display driver */
  158. /* must disable the hardware register of the graphic */
  159. /* chip. Otherwise a blinking field is displayed */
  160. /*****************************************************************************/
  161. #if !defined(CONFIG_CONSOLE_CURSOR) && \
  162. !defined(CONFIG_VIDEO_SW_CURSOR) && \
  163. !defined(CONFIG_VIDEO_HW_CURSOR)
  164. /* no Cursor defined */
  165. #define CURSOR_ON
  166. #define CURSOR_OFF
  167. #define CURSOR_SET
  168. #endif
  169. #ifdef CONFIG_CONSOLE_CURSOR
  170. #ifdef CURSOR_ON
  171. #error only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined
  172. #endif
  173. void console_cursor (int state);
  174. #define CURSOR_ON console_cursor(1);
  175. #define CURSOR_OFF console_cursor(0);
  176. #define CURSOR_SET
  177. #ifndef CONFIG_I8042_KBD
  178. #warning Cursor drawing on/off needs timer function s.a. drivers/i8042.c
  179. #endif
  180. #else
  181. #ifdef CONFIG_CONSOLE_TIME
  182. #error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
  183. #endif
  184. #endif /* CONFIG_CONSOLE_CURSOR */
  185. #ifdef CONFIG_VIDEO_SW_CURSOR
  186. #ifdef CURSOR_ON
  187. #error only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined
  188. #endif
  189. #define CURSOR_ON
  190. #define CURSOR_OFF video_putchar(console_col * VIDEO_FONT_WIDTH,\
  191. console_row * VIDEO_FONT_HEIGHT, ' ');
  192. #define CURSOR_SET video_set_cursor();
  193. #endif /* CONFIG_VIDEO_SW_CURSOR */
  194. #ifdef CONFIG_VIDEO_HW_CURSOR
  195. #ifdef CURSOR_ON
  196. #error only one of CONFIG_CONSOLE_CURSOR,CONFIG_VIDEO_SW_CURSOR,CONFIG_VIDEO_HW_CURSOR can be defined
  197. #endif
  198. #define CURSOR_ON
  199. #define CURSOR_OFF
  200. #define CURSOR_SET video_set_hw_cursor(console_col * VIDEO_FONT_WIDTH, \
  201. (console_row * VIDEO_FONT_HEIGHT) + VIDEO_LOGO_HEIGHT);
  202. #endif /* CONFIG_VIDEO_HW_CURSOR */
  203. #ifdef CONFIG_VIDEO_LOGO
  204. #ifdef CONFIG_VIDEO_BMP_LOGO
  205. #include <bmp_logo.h>
  206. #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
  207. #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
  208. #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
  209. #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
  210. #else /* CONFIG_VIDEO_BMP_LOGO */
  211. #define LINUX_LOGO_WIDTH 80
  212. #define LINUX_LOGO_HEIGHT 80
  213. #define LINUX_LOGO_COLORS 214
  214. #define LINUX_LOGO_LUT_OFFSET 0x20
  215. #define __initdata
  216. #include <linux_logo.h>
  217. #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
  218. #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
  219. #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
  220. #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
  221. #endif /* CONFIG_VIDEO_BMP_LOGO */
  222. #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
  223. #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
  224. #else /* CONFIG_VIDEO_LOGO */
  225. #define VIDEO_LOGO_WIDTH 0
  226. #define VIDEO_LOGO_HEIGHT 0
  227. #endif /* CONFIG_VIDEO_LOGO */
  228. #define VIDEO_COLS VIDEO_VISIBLE_COLS
  229. #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
  230. #define VIDEO_SIZE (VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
  231. #define VIDEO_PIX_BLOCKS (VIDEO_SIZE >> 2)
  232. #define VIDEO_LINE_LEN (VIDEO_COLS*VIDEO_PIXEL_SIZE)
  233. #define VIDEO_BURST_LEN (VIDEO_COLS/8)
  234. #ifdef CONFIG_VIDEO_LOGO
  235. #define CONSOLE_ROWS ((VIDEO_ROWS - VIDEO_LOGO_HEIGHT) / VIDEO_FONT_HEIGHT)
  236. #else
  237. #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
  238. #endif
  239. #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
  240. #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
  241. #define CONSOLE_ROW_FIRST (video_console_address)
  242. #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
  243. #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
  244. #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
  245. #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
  246. /* Macros */
  247. #ifdef VIDEO_FB_LITTLE_ENDIAN
  248. #define SWAP16(x) ((((x) & 0x00ff) << 8) | ( (x) >> 8))
  249. #define SWAP32(x) ((((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) << 8)|\
  250. (((x) & 0x00ff0000) >> 8) | (((x) & 0xff000000) >> 24) )
  251. #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | (((x) & 0x0000ff00) >> 8)|\
  252. (((x) & 0x00ff0000) << 8) | (((x) & 0xff000000) >> 8) )
  253. #else
  254. #define SWAP16(x) (x)
  255. #define SWAP32(x) (x)
  256. #define SHORTSWAP32(x) (x)
  257. #endif
  258. #if defined(DEBUG) || defined(DEBUG_CFB_CONSOLE)
  259. #define PRINTD(x) printf(x)
  260. #else
  261. #define PRINTD(x)
  262. #endif
  263. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  264. extern void video_get_info_str ( /* setup a board string: type, speed, etc. */
  265. int line_number, /* location to place info string beside logo */
  266. char *info /* buffer for info string */
  267. );
  268. #endif
  269. /* Locals */
  270. static GraphicDevice *pGD; /* Pointer to Graphic array */
  271. static void *video_fb_address; /* frame buffer address */
  272. static void *video_console_address; /* console buffer start address */
  273. static int console_col = 0; /* cursor col */
  274. static int console_row = 0; /* cursor row */
  275. static u32 eorx, fgx, bgx; /* color pats */
  276. static const int video_font_draw_table8[] = {
  277. 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
  278. 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
  279. 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
  280. 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff };
  281. static const int video_font_draw_table15[] = {
  282. 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff };
  283. static const int video_font_draw_table16[] = {
  284. 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff };
  285. static const int video_font_draw_table24[16][3] = {
  286. { 0x00000000, 0x00000000, 0x00000000 },
  287. { 0x00000000, 0x00000000, 0x00ffffff },
  288. { 0x00000000, 0x0000ffff, 0xff000000 },
  289. { 0x00000000, 0x0000ffff, 0xffffffff },
  290. { 0x000000ff, 0xffff0000, 0x00000000 },
  291. { 0x000000ff, 0xffff0000, 0x00ffffff },
  292. { 0x000000ff, 0xffffffff, 0xff000000 },
  293. { 0x000000ff, 0xffffffff, 0xffffffff },
  294. { 0xffffff00, 0x00000000, 0x00000000 },
  295. { 0xffffff00, 0x00000000, 0x00ffffff },
  296. { 0xffffff00, 0x0000ffff, 0xff000000 },
  297. { 0xffffff00, 0x0000ffff, 0xffffffff },
  298. { 0xffffffff, 0xffff0000, 0x00000000 },
  299. { 0xffffffff, 0xffff0000, 0x00ffffff },
  300. { 0xffffffff, 0xffffffff, 0xff000000 },
  301. { 0xffffffff, 0xffffffff, 0xffffffff } };
  302. static const int video_font_draw_table32[16][4] = {
  303. { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
  304. { 0x00000000, 0x00000000, 0x00000000, 0x00ffffff },
  305. { 0x00000000, 0x00000000, 0x00ffffff, 0x00000000 },
  306. { 0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff },
  307. { 0x00000000, 0x00ffffff, 0x00000000, 0x00000000 },
  308. { 0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff },
  309. { 0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000 },
  310. { 0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff },
  311. { 0x00ffffff, 0x00000000, 0x00000000, 0x00000000 },
  312. { 0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff },
  313. { 0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000 },
  314. { 0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff },
  315. { 0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000 },
  316. { 0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff },
  317. { 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000 },
  318. { 0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff } };
  319. /******************************************************************************/
  320. static void video_drawchars (int xx, int yy, unsigned char *s, int count)
  321. {
  322. u8 *cdat, *dest, *dest0;
  323. int rows, offset, c;
  324. offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
  325. dest0 = video_fb_address + offset;
  326. switch (VIDEO_DATA_FORMAT) {
  327. case GDF__8BIT_INDEX:
  328. case GDF__8BIT_332RGB:
  329. while (count--) {
  330. c = *s;
  331. cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
  332. for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
  333. rows--;
  334. dest += VIDEO_LINE_LEN) {
  335. u8 bits = *cdat++;
  336. ((u32 *) dest)[0] = (video_font_draw_table8[bits >> 4] & eorx) ^ bgx;
  337. ((u32 *) dest)[1] = (video_font_draw_table8[bits & 15] & eorx) ^ bgx;
  338. }
  339. dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
  340. s++;
  341. }
  342. break;
  343. case GDF_15BIT_555RGB:
  344. while (count--) {
  345. c = *s;
  346. cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
  347. for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
  348. rows--;
  349. dest += VIDEO_LINE_LEN) {
  350. u8 bits = *cdat++;
  351. ((u32 *) dest)[0] = SHORTSWAP32 ((video_font_draw_table15 [bits >> 6] & eorx) ^ bgx);
  352. ((u32 *) dest)[1] = SHORTSWAP32 ((video_font_draw_table15 [bits >> 4 & 3] & eorx) ^ bgx);
  353. ((u32 *) dest)[2] = SHORTSWAP32 ((video_font_draw_table15 [bits >> 2 & 3] & eorx) ^ bgx);
  354. ((u32 *) dest)[3] = SHORTSWAP32 ((video_font_draw_table15 [bits & 3] & eorx) ^ bgx);
  355. }
  356. dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
  357. s++;
  358. }
  359. break;
  360. case GDF_16BIT_565RGB:
  361. while (count--) {
  362. c = *s;
  363. cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
  364. for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
  365. rows--;
  366. dest += VIDEO_LINE_LEN) {
  367. u8 bits = *cdat++;
  368. ((u32 *) dest)[0] = SHORTSWAP32 ((video_font_draw_table16 [bits >> 6] & eorx) ^ bgx);
  369. ((u32 *) dest)[1] = SHORTSWAP32 ((video_font_draw_table16 [bits >> 4 & 3] & eorx) ^ bgx);
  370. ((u32 *) dest)[2] = SHORTSWAP32 ((video_font_draw_table16 [bits >> 2 & 3] & eorx) ^ bgx);
  371. ((u32 *) dest)[3] = SHORTSWAP32 ((video_font_draw_table16 [bits & 3] & eorx) ^ bgx);
  372. }
  373. dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
  374. s++;
  375. }
  376. break;
  377. case GDF_32BIT_X888RGB:
  378. while (count--) {
  379. c = *s;
  380. cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
  381. for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
  382. rows--;
  383. dest += VIDEO_LINE_LEN) {
  384. u8 bits = *cdat++;
  385. ((u32 *) dest)[0] = SWAP32 ((video_font_draw_table32 [bits >> 4][0] & eorx) ^ bgx);
  386. ((u32 *) dest)[1] = SWAP32 ((video_font_draw_table32 [bits >> 4][1] & eorx) ^ bgx);
  387. ((u32 *) dest)[2] = SWAP32 ((video_font_draw_table32 [bits >> 4][2] & eorx) ^ bgx);
  388. ((u32 *) dest)[3] = SWAP32 ((video_font_draw_table32 [bits >> 4][3] & eorx) ^ bgx);
  389. ((u32 *) dest)[4] = SWAP32 ((video_font_draw_table32 [bits & 15][0] & eorx) ^ bgx);
  390. ((u32 *) dest)[5] = SWAP32 ((video_font_draw_table32 [bits & 15][1] & eorx) ^ bgx);
  391. ((u32 *) dest)[6] = SWAP32 ((video_font_draw_table32 [bits & 15][2] & eorx) ^ bgx);
  392. ((u32 *) dest)[7] = SWAP32 ((video_font_draw_table32 [bits & 15][3] & eorx) ^ bgx);
  393. }
  394. dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
  395. s++;
  396. }
  397. break;
  398. case GDF_24BIT_888RGB:
  399. while (count--) {
  400. c = *s;
  401. cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
  402. for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
  403. rows--;
  404. dest += VIDEO_LINE_LEN) {
  405. u8 bits = *cdat++;
  406. ((u32 *) dest)[0] = (video_font_draw_table24[bits >> 4][0] & eorx) ^ bgx;
  407. ((u32 *) dest)[1] = (video_font_draw_table24[bits >> 4][1] & eorx) ^ bgx;
  408. ((u32 *) dest)[2] = (video_font_draw_table24[bits >> 4][2] & eorx) ^ bgx;
  409. ((u32 *) dest)[3] = (video_font_draw_table24[bits & 15][0] & eorx) ^ bgx;
  410. ((u32 *) dest)[4] = (video_font_draw_table24[bits & 15][1] & eorx) ^ bgx;
  411. ((u32 *) dest)[5] = (video_font_draw_table24[bits & 15][2] & eorx) ^ bgx;
  412. }
  413. dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
  414. s++;
  415. }
  416. break;
  417. }
  418. }
  419. /*****************************************************************************/
  420. static inline void video_drawstring (int xx, int yy, unsigned char *s)
  421. {
  422. video_drawchars (xx, yy, s, strlen (s));
  423. }
  424. /*****************************************************************************/
  425. static void video_putchar (int xx, int yy, unsigned char c)
  426. {
  427. video_drawchars (xx, yy + VIDEO_LOGO_HEIGHT, &c, 1);
  428. }
  429. /*****************************************************************************/
  430. #if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
  431. static void video_set_cursor (void)
  432. {
  433. /* swap drawing colors */
  434. eorx = fgx;
  435. fgx = bgx;
  436. bgx = eorx;
  437. eorx = fgx ^ bgx;
  438. /* draw cursor */
  439. video_putchar (console_col * VIDEO_FONT_WIDTH,
  440. console_row * VIDEO_FONT_HEIGHT,
  441. ' ');
  442. /* restore drawing colors */
  443. eorx = fgx;
  444. fgx = bgx;
  445. bgx = eorx;
  446. eorx = fgx ^ bgx;
  447. }
  448. #endif
  449. /*****************************************************************************/
  450. #ifdef CONFIG_CONSOLE_CURSOR
  451. void console_cursor (int state)
  452. {
  453. static int last_state = 0;
  454. #ifdef CONFIG_CONSOLE_TIME
  455. struct rtc_time tm;
  456. char info[16];
  457. /* time update only if cursor is on (faster scroll) */
  458. if (state) {
  459. rtc_get (&tm);
  460. sprintf (info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
  461. tm.tm_sec);
  462. video_drawstring (VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
  463. VIDEO_INFO_Y, info);
  464. sprintf (info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
  465. tm.tm_year);
  466. video_drawstring (VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
  467. VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT, info);
  468. }
  469. #endif
  470. if (state && (last_state != state)) {
  471. video_set_cursor ();
  472. }
  473. if (!state && (last_state != state)) {
  474. /* clear cursor */
  475. video_putchar (console_col * VIDEO_FONT_WIDTH,
  476. console_row * VIDEO_FONT_HEIGHT,
  477. ' ');
  478. }
  479. last_state = state;
  480. }
  481. #endif
  482. /*****************************************************************************/
  483. #ifndef VIDEO_HW_RECTFILL
  484. static void memsetl (int *p, int c, int v)
  485. {
  486. while (c--)
  487. *(p++) = v;
  488. }
  489. #endif
  490. /*****************************************************************************/
  491. #ifndef VIDEO_HW_BITBLT
  492. static void memcpyl (int *d, int *s, int c)
  493. {
  494. while (c--)
  495. *(d++) = *(s++);
  496. }
  497. #endif
  498. /*****************************************************************************/
  499. static void console_scrollup (void)
  500. {
  501. /* copy up rows ignoring the first one */
  502. #ifdef VIDEO_HW_BITBLT
  503. video_hw_bitblt (VIDEO_PIXEL_SIZE, /* bytes per pixel */
  504. 0, /* source pos x */
  505. VIDEO_LOGO_HEIGHT + VIDEO_FONT_HEIGHT, /* source pos y */
  506. 0, /* dest pos x */
  507. VIDEO_LOGO_HEIGHT, /* dest pos y */
  508. VIDEO_VISIBLE_COLS, /* frame width */
  509. VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT - VIDEO_FONT_HEIGHT /* frame height */
  510. );
  511. #else
  512. memcpyl (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND,
  513. CONSOLE_SCROLL_SIZE >> 2);
  514. #endif
  515. /* clear the last one */
  516. #ifdef VIDEO_HW_RECTFILL
  517. video_hw_rectfill (VIDEO_PIXEL_SIZE, /* bytes per pixel */
  518. 0, /* dest pos x */
  519. VIDEO_VISIBLE_ROWS - VIDEO_FONT_HEIGHT, /* dest pos y */
  520. VIDEO_VISIBLE_COLS, /* frame width */
  521. VIDEO_FONT_HEIGHT, /* frame height */
  522. CONSOLE_BG_COL /* fill color */
  523. );
  524. #else
  525. memsetl (CONSOLE_ROW_LAST, CONSOLE_ROW_SIZE >> 2, CONSOLE_BG_COL);
  526. #endif
  527. }
  528. /*****************************************************************************/
  529. static void console_back (void)
  530. {
  531. CURSOR_OFF console_col--;
  532. if (console_col < 0) {
  533. console_col = CONSOLE_COLS - 1;
  534. console_row--;
  535. if (console_row < 0)
  536. console_row = 0;
  537. }
  538. video_putchar (console_col * VIDEO_FONT_WIDTH,
  539. console_row * VIDEO_FONT_HEIGHT,
  540. ' ');
  541. }
  542. /*****************************************************************************/
  543. static void console_newline (void)
  544. {
  545. CURSOR_OFF console_row++;
  546. console_col = 0;
  547. /* Check if we need to scroll the terminal */
  548. if (console_row >= CONSOLE_ROWS) {
  549. /* Scroll everything up */
  550. console_scrollup ();
  551. /* Decrement row number */
  552. console_row--;
  553. }
  554. }
  555. /*****************************************************************************/
  556. void video_putc (const char c)
  557. {
  558. switch (c) {
  559. case 13: /* ignore */
  560. break;
  561. case '\n': /* next line */
  562. console_newline ();
  563. break;
  564. case 9: /* tab 8 */
  565. CURSOR_OFF console_col |= 0x0008;
  566. console_col &= ~0x0007;
  567. if (console_col >= CONSOLE_COLS)
  568. console_newline ();
  569. break;
  570. case 8: /* backspace */
  571. console_back ();
  572. break;
  573. default: /* draw the char */
  574. video_putchar (console_col * VIDEO_FONT_WIDTH,
  575. console_row * VIDEO_FONT_HEIGHT,
  576. c);
  577. console_col++;
  578. /* check for newline */
  579. if (console_col >= CONSOLE_COLS)
  580. console_newline ();
  581. }
  582. CURSOR_SET}
  583. /*****************************************************************************/
  584. void video_puts (const char *s)
  585. {
  586. int count = strlen (s);
  587. while (count--)
  588. video_putc (*s++);
  589. }
  590. /*****************************************************************************/
  591. #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  592. #define FILL_8BIT_332RGB(r,g,b) { \
  593. *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
  594. fb ++; \
  595. }
  596. #define FILL_15BIT_555RGB(r,g,b) { \
  597. *(unsigned short *)fb = SWAP16((unsigned short)(((r>>3)<<10) | ((g>>3)<<5) | (b>>3))); \
  598. fb += 2; \
  599. }
  600. #define FILL_16BIT_565RGB(r,g,b) { \
  601. *(unsigned short *)fb = SWAP16((unsigned short)((((r)>>3)<<11) | (((g)>>2)<<5) | ((b)>>3))); \
  602. fb += 2; \
  603. }
  604. #define FILL_32BIT_X888RGB(r,g,b) { \
  605. *(unsigned long *)fb = SWAP32((unsigned long)(((r<<16) | (g<<8) | b))); \
  606. fb += 4; \
  607. }
  608. #ifdef VIDEO_FB_LITTLE_ENDIAN
  609. #define FILL_24BIT_888RGB(r,g,b) { \
  610. fb[0] = b; \
  611. fb[1] = g; \
  612. fb[2] = r; \
  613. fb += 3; \
  614. }
  615. #else
  616. #define FILL_24BIT_888RGB(r,g,b) { \
  617. fb[0] = r; \
  618. fb[1] = g; \
  619. fb[2] = b; \
  620. fb += 3; \
  621. }
  622. #endif
  623. /*
  624. * Display the BMP file located at address bmp_image.
  625. * Only uncompressed
  626. */
  627. int video_display_bitmap (ulong bmp_image, int x, int y)
  628. {
  629. ushort xcount, ycount;
  630. uchar *fb;
  631. bmp_image_t *bmp = (bmp_image_t *) bmp_image;
  632. uchar *bmap;
  633. ushort padded_line;
  634. unsigned long width, height, bpp;
  635. unsigned colors;
  636. unsigned long compression;
  637. bmp_color_table_entry_t cte;
  638. WATCHDOG_RESET ();
  639. if (!((bmp->header.signature[0] == 'B') &&
  640. (bmp->header.signature[1] == 'M'))) {
  641. printf ("Error: no valid bmp image at %lx\n", bmp_image);
  642. return 1;
  643. }
  644. width = le32_to_cpu (bmp->header.width);
  645. height = le32_to_cpu (bmp->header.height);
  646. bpp = le16_to_cpu (bmp->header.bit_count);
  647. colors = le32_to_cpu (bmp->header.colors_used);
  648. compression = le32_to_cpu (bmp->header.compression);
  649. debug ("Display-bmp: %d x %d with %d colors\n",
  650. width, height, colors);
  651. if (compression != BMP_BI_RGB) {
  652. printf ("Error: compression type %ld not supported\n",
  653. compression);
  654. return 1;
  655. }
  656. padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
  657. if ((x + width) > VIDEO_VISIBLE_COLS)
  658. width = VIDEO_VISIBLE_COLS - x;
  659. if ((y + height) > VIDEO_VISIBLE_ROWS)
  660. height = VIDEO_VISIBLE_ROWS - y;
  661. bmap = (uchar *) bmp + le32_to_cpu (bmp->header.data_offset);
  662. fb = (uchar *) (video_fb_address +
  663. ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
  664. x * VIDEO_PIXEL_SIZE);
  665. /* We handle only 8bpp or 24 bpp bitmap */
  666. switch (le16_to_cpu (bmp->header.bit_count)) {
  667. case 8:
  668. padded_line -= width;
  669. if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
  670. /* Copy colormap */
  671. for (xcount = 0; xcount < colors; ++xcount) {
  672. cte = bmp->color_table[xcount];
  673. video_set_lut (xcount, cte.red, cte.green, cte.blue);
  674. }
  675. }
  676. ycount = height;
  677. switch (VIDEO_DATA_FORMAT) {
  678. case GDF__8BIT_INDEX:
  679. while (ycount--) {
  680. WATCHDOG_RESET ();
  681. xcount = width;
  682. while (xcount--) {
  683. *fb++ = *bmap++;
  684. }
  685. bmap += padded_line;
  686. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  687. }
  688. break;
  689. case GDF__8BIT_332RGB:
  690. while (ycount--) {
  691. WATCHDOG_RESET ();
  692. xcount = width;
  693. while (xcount--) {
  694. cte = bmp->color_table[*bmap++];
  695. FILL_8BIT_332RGB (cte.red, cte.green, cte.blue);
  696. }
  697. bmap += padded_line;
  698. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  699. }
  700. break;
  701. case GDF_15BIT_555RGB:
  702. while (ycount--) {
  703. WATCHDOG_RESET ();
  704. xcount = width;
  705. while (xcount--) {
  706. cte = bmp->color_table[*bmap++];
  707. FILL_15BIT_555RGB (cte.red, cte.green, cte.blue);
  708. }
  709. bmap += padded_line;
  710. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  711. }
  712. break;
  713. case GDF_16BIT_565RGB:
  714. while (ycount--) {
  715. WATCHDOG_RESET ();
  716. xcount = width;
  717. while (xcount--) {
  718. cte = bmp->color_table[*bmap++];
  719. FILL_16BIT_565RGB (cte.red, cte.green, cte.blue);
  720. }
  721. bmap += padded_line;
  722. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  723. }
  724. break;
  725. case GDF_32BIT_X888RGB:
  726. while (ycount--) {
  727. WATCHDOG_RESET ();
  728. xcount = width;
  729. while (xcount--) {
  730. cte = bmp->color_table[*bmap++];
  731. FILL_32BIT_X888RGB (cte.red, cte.green, cte.blue);
  732. }
  733. bmap += padded_line;
  734. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  735. }
  736. break;
  737. case GDF_24BIT_888RGB:
  738. while (ycount--) {
  739. WATCHDOG_RESET ();
  740. xcount = width;
  741. while (xcount--) {
  742. cte = bmp->color_table[*bmap++];
  743. FILL_24BIT_888RGB (cte.red, cte.green, cte.blue);
  744. }
  745. bmap += padded_line;
  746. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  747. }
  748. break;
  749. }
  750. break;
  751. case 24:
  752. padded_line -= 3 * width;
  753. ycount = height;
  754. switch (VIDEO_DATA_FORMAT) {
  755. case GDF__8BIT_332RGB:
  756. while (ycount--) {
  757. WATCHDOG_RESET ();
  758. xcount = width;
  759. while (xcount--) {
  760. FILL_8BIT_332RGB (bmap[2], bmap[1], bmap[0]);
  761. bmap += 3;
  762. }
  763. bmap += padded_line;
  764. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  765. }
  766. break;
  767. case GDF_15BIT_555RGB:
  768. while (ycount--) {
  769. WATCHDOG_RESET ();
  770. xcount = width;
  771. while (xcount--) {
  772. FILL_15BIT_555RGB (bmap[2], bmap[1], bmap[0]);
  773. bmap += 3;
  774. }
  775. bmap += padded_line;
  776. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  777. }
  778. break;
  779. case GDF_16BIT_565RGB:
  780. while (ycount--) {
  781. WATCHDOG_RESET ();
  782. xcount = width;
  783. while (xcount--) {
  784. FILL_16BIT_565RGB (bmap[2], bmap[1], bmap[0]);
  785. bmap += 3;
  786. }
  787. bmap += padded_line;
  788. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  789. }
  790. break;
  791. case GDF_32BIT_X888RGB:
  792. while (ycount--) {
  793. WATCHDOG_RESET ();
  794. xcount = width;
  795. while (xcount--) {
  796. FILL_32BIT_X888RGB (bmap[2], bmap[1], bmap[0]);
  797. bmap += 3;
  798. }
  799. bmap += padded_line;
  800. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  801. }
  802. break;
  803. case GDF_24BIT_888RGB:
  804. while (ycount--) {
  805. WATCHDOG_RESET ();
  806. xcount = width;
  807. while (xcount--) {
  808. FILL_24BIT_888RGB (bmap[2], bmap[1], bmap[0]);
  809. bmap += 3;
  810. }
  811. bmap += padded_line;
  812. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  813. }
  814. break;
  815. default:
  816. printf ("Error: 24 bits/pixel bitmap incompatible with current video mode\n");
  817. break;
  818. }
  819. break;
  820. default:
  821. printf ("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
  822. le16_to_cpu (bmp->header.bit_count));
  823. break;
  824. }
  825. return (0);
  826. }
  827. #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
  828. /*****************************************************************************/
  829. #ifdef CONFIG_VIDEO_LOGO
  830. void logo_plot (void *screen, int width, int x, int y)
  831. {
  832. int xcount, i;
  833. int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
  834. int ycount = VIDEO_LOGO_HEIGHT;
  835. unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
  836. unsigned char *source;
  837. unsigned char *dest = (unsigned char *)screen + ((y * width * VIDEO_PIXEL_SIZE) + x);
  838. #ifdef CONFIG_VIDEO_BMP_LOGO
  839. source = bmp_logo_bitmap;
  840. /* Allocate temporary space for computing colormap */
  841. logo_red = malloc (BMP_LOGO_COLORS);
  842. logo_green = malloc (BMP_LOGO_COLORS);
  843. logo_blue = malloc (BMP_LOGO_COLORS);
  844. /* Compute color map */
  845. for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
  846. logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
  847. logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
  848. logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
  849. }
  850. #else
  851. source = linux_logo;
  852. logo_red = linux_logo_red;
  853. logo_green = linux_logo_green;
  854. logo_blue = linux_logo_blue;
  855. #endif
  856. if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
  857. for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
  858. video_set_lut (i + VIDEO_LOGO_LUT_OFFSET,
  859. logo_red[i], logo_green[i], logo_blue[i]);
  860. }
  861. }
  862. while (ycount--) {
  863. xcount = VIDEO_LOGO_WIDTH;
  864. while (xcount--) {
  865. r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
  866. g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
  867. b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
  868. switch (VIDEO_DATA_FORMAT) {
  869. case GDF__8BIT_INDEX:
  870. *dest = *source;
  871. break;
  872. case GDF__8BIT_332RGB:
  873. *dest = ((r >> 5) << 5) | ((g >> 5) << 2) | (b >> 6);
  874. break;
  875. case GDF_15BIT_555RGB:
  876. *(unsigned short *) dest =
  877. SWAP16 ((unsigned short) (((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3)));
  878. break;
  879. case GDF_16BIT_565RGB:
  880. *(unsigned short *) dest =
  881. SWAP16 ((unsigned short) (((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)));
  882. break;
  883. case GDF_32BIT_X888RGB:
  884. *(unsigned long *) dest =
  885. SWAP32 ((unsigned long) ((r << 16) | (g << 8) | b));
  886. break;
  887. case GDF_24BIT_888RGB:
  888. #ifdef VIDEO_FB_LITTLE_ENDIAN
  889. dest[0] = b;
  890. dest[1] = g;
  891. dest[2] = r;
  892. #else
  893. dest[0] = r;
  894. dest[1] = g;
  895. dest[2] = b;
  896. #endif
  897. break;
  898. }
  899. source++;
  900. dest += VIDEO_PIXEL_SIZE;
  901. }
  902. dest += skip;
  903. }
  904. #ifdef CONFIG_VIDEO_BMP_LOGO
  905. free (logo_red);
  906. free (logo_green);
  907. free (logo_blue);
  908. #endif
  909. }
  910. /*****************************************************************************/
  911. static void *video_logo (void)
  912. {
  913. char info[128];
  914. extern char version_string;
  915. #ifdef CONFIG_SPLASH_SCREEN
  916. char *s;
  917. ulong addr;
  918. if ((s = getenv ("splashimage")) != NULL) {
  919. addr = simple_strtoul (s, NULL, 16);
  920. if (video_display_bitmap (addr, 0, 0) == 0) {
  921. return ((void *) (video_fb_address));
  922. }
  923. }
  924. #endif /* CONFIG_SPLASH_SCREEN */
  925. logo_plot (video_fb_address, VIDEO_COLS, 0, 0);
  926. sprintf (info, " %s", &version_string);
  927. video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
  928. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  929. {
  930. int i, n = ((VIDEO_LOGO_HEIGHT - VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
  931. for (i = 1; i < n; i++) {
  932. video_get_info_str (i, info);
  933. if (*info)
  934. video_drawstring (VIDEO_INFO_X,
  935. VIDEO_INFO_Y + i * VIDEO_FONT_HEIGHT,
  936. info);
  937. }
  938. }
  939. #endif
  940. return (video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN);
  941. }
  942. #endif
  943. /*****************************************************************************/
  944. static int video_init (void)
  945. {
  946. unsigned char color8;
  947. if ((pGD = video_hw_init ()) == NULL)
  948. return -1;
  949. video_fb_address = (void *) VIDEO_FB_ADRS;
  950. #ifdef CONFIG_VIDEO_HW_CURSOR
  951. video_init_hw_cursor (VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
  952. #endif
  953. /* Init drawing pats */
  954. switch (VIDEO_DATA_FORMAT) {
  955. case GDF__8BIT_INDEX:
  956. video_set_lut (0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, CONSOLE_FG_COL);
  957. video_set_lut (0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, CONSOLE_BG_COL);
  958. fgx = 0x01010101;
  959. bgx = 0x00000000;
  960. break;
  961. case GDF__8BIT_332RGB:
  962. color8 = ((CONSOLE_FG_COL & 0xe0) |
  963. ((CONSOLE_FG_COL >> 3) & 0x1c) | CONSOLE_FG_COL >> 6);
  964. fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8;
  965. color8 = ((CONSOLE_BG_COL & 0xe0) |
  966. ((CONSOLE_BG_COL >> 3) & 0x1c) | CONSOLE_BG_COL >> 6);
  967. bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8;
  968. break;
  969. case GDF_15BIT_555RGB:
  970. fgx = (((CONSOLE_FG_COL >> 3) << 26) |
  971. ((CONSOLE_FG_COL >> 3) << 21) | ((CONSOLE_FG_COL >> 3) << 16) |
  972. ((CONSOLE_FG_COL >> 3) << 10) | ((CONSOLE_FG_COL >> 3) << 5) |
  973. (CONSOLE_FG_COL >> 3));
  974. bgx = (((CONSOLE_BG_COL >> 3) << 26) |
  975. ((CONSOLE_BG_COL >> 3) << 21) | ((CONSOLE_BG_COL >> 3) << 16) |
  976. ((CONSOLE_BG_COL >> 3) << 10) | ((CONSOLE_BG_COL >> 3) << 5) |
  977. (CONSOLE_BG_COL >> 3));
  978. break;
  979. case GDF_16BIT_565RGB:
  980. fgx = (((CONSOLE_FG_COL >> 3) << 27) |
  981. ((CONSOLE_FG_COL >> 2) << 21) | ((CONSOLE_FG_COL >> 3) << 16) |
  982. ((CONSOLE_FG_COL >> 3) << 11) | ((CONSOLE_FG_COL >> 2) << 5) |
  983. (CONSOLE_FG_COL >> 3));
  984. bgx = (((CONSOLE_BG_COL >> 3) << 27) |
  985. ((CONSOLE_BG_COL >> 2) << 21) | ((CONSOLE_BG_COL >> 3) << 16) |
  986. ((CONSOLE_BG_COL >> 3) << 11) | ((CONSOLE_BG_COL >> 2) << 5) |
  987. (CONSOLE_BG_COL >> 3));
  988. break;
  989. case GDF_32BIT_X888RGB:
  990. fgx = (CONSOLE_FG_COL << 16) | (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL;
  991. bgx = (CONSOLE_BG_COL << 16) | (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL;
  992. break;
  993. case GDF_24BIT_888RGB:
  994. fgx = (CONSOLE_FG_COL << 24) | (CONSOLE_FG_COL << 16) |
  995. (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL;
  996. bgx = (CONSOLE_BG_COL << 24) | (CONSOLE_BG_COL << 16) |
  997. (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL;
  998. break;
  999. }
  1000. eorx = fgx ^ bgx;
  1001. #ifdef CONFIG_VIDEO_LOGO
  1002. /* Plot the logo and get start point of console */
  1003. PRINTD ("Video: Drawing the logo ...\n");
  1004. video_console_address = video_logo ();
  1005. #else
  1006. video_console_address = video_fb_address;
  1007. #endif
  1008. /* Initialize the console */
  1009. console_col = 0;
  1010. console_row = 0;
  1011. return 0;
  1012. }
  1013. /*****************************************************************************/
  1014. int drv_video_init (void)
  1015. {
  1016. int skip_dev_init;
  1017. device_t console_dev;
  1018. char *penv;
  1019. skip_dev_init = 0;
  1020. /* Init video chip - returns with framebuffer cleared */
  1021. if (video_init () == -1)
  1022. skip_dev_init = 1;
  1023. /* Force console i/o to serial ? */
  1024. if ((penv = getenv ("console")) != NULL)
  1025. if (strcmp (penv, "serial") == 0)
  1026. return 0;
  1027. #ifdef CONFIG_VGA_AS_SINGLE_DEVICE
  1028. /* Devices VGA and Keyboard will be assigned seperately */
  1029. /* Init vga device */
  1030. if (!skip_dev_init) {
  1031. memset (&console_dev, 0, sizeof (console_dev));
  1032. strcpy (console_dev.name, "vga");
  1033. console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
  1034. console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
  1035. console_dev.putc = video_putc; /* 'putc' function */
  1036. console_dev.puts = video_puts; /* 'puts' function */
  1037. console_dev.tstc = NULL; /* 'tstc' function */
  1038. console_dev.getc = NULL; /* 'getc' function */
  1039. if (device_register (&console_dev) == 0)
  1040. return 1;
  1041. }
  1042. #else
  1043. PRINTD ("KBD: Keyboard init ...\n");
  1044. if (VIDEO_KBD_INIT_FCT == -1)
  1045. skip_dev_init = 1;
  1046. /* Init console device */
  1047. if (!skip_dev_init) {
  1048. memset (&console_dev, 0, sizeof (console_dev));
  1049. strcpy (console_dev.name, "console");
  1050. console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
  1051. console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
  1052. console_dev.putc = video_putc; /* 'putc' function */
  1053. console_dev.puts = video_puts; /* 'puts' function */
  1054. console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
  1055. console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
  1056. if (device_register (&console_dev) == 0)
  1057. return 1;
  1058. }
  1059. #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
  1060. /* No console dev available */
  1061. return 0;
  1062. }
  1063. #endif /* CONFIG_CFB_CONSOLE */