cfb_console.c 38 KB

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