cfb_console.c 41 KB

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