cfb_console.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. /*
  2. * (C) Copyright 2002 ELTEC Elektronik AG
  3. * Frank Gottschling <fgottschling@eltec.de>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * cfb_console.c
  25. *
  26. * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
  27. *
  28. * At the moment only the 8x16 font is tested and the font fore- and
  29. * background color is limited to black/white/gray colors. The Linux
  30. * logo can be placed in the upper left corner and additional board
  31. * information strings (that normaly goes to serial port) can be drawed.
  32. *
  33. * The console driver can use the standard PC keyboard interface (i8042)
  34. * for character input. Character output goes to a memory mapped video
  35. * framebuffer with little or big-endian organisation.
  36. * With environment setting 'console=serial' the console i/o can be
  37. * forced to serial port.
  38. The driver uses graphic specific defines/parameters/functions:
  39. (for SMI LynxE graphic chip)
  40. CONFIG_VIDEO_SMI_LYNXEM - use graphic driver for SMI 710,712,810
  41. VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
  42. VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
  43. VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
  44. Console Parameters are set by graphic drivers global struct:
  45. VIDEO_VISIBLE_COLS - x resolution
  46. VIDEO_VISIBLE_ROWS - y resolution
  47. VIDEO_PIXEL_SIZE - storage size in byte per pixel
  48. VIDEO_DATA_FORMAT - graphical data format GDF
  49. VIDEO_FB_ADRS - start of video memory
  50. CONFIG_I8042_KBD - AT Keyboard driver for i8042
  51. VIDEO_KBD_INIT_FCT - init function for keyboard
  52. VIDEO_TSTC_FCT - keyboard_tstc function
  53. VIDEO_GETC_FCT - keyboard_getc function
  54. CONFIG_CONSOLE_CURSOR - on/off drawing cursor is done with delay
  55. loop in VIDEO_TSTC_FCT (i8042)
  56. CFG_CONSOLE_BLINK_COUNT - value for delay loop - blink rate
  57. CONFIG_CONSOLE_TIME - display time/date in upper right corner,
  58. needs CFG_CMD_DATE and CONFIG_CONSOLE_CURSOR
  59. CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner
  60. CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
  61. CONFIG_CONSOLE_EXTRA_INFO - display additional board information strings
  62. that normaly goes to serial port. This define
  63. requires a board specific function:
  64. video_drawstring (VIDEO_INFO_X,
  65. VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
  66. info);
  67. that fills a info buffer at i=row.
  68. s.a: board/eltec/bab7xx.
  69. CONFIG_VGA_AS_SINGLE_DEVICE - If set the framebuffer device will be initialised
  70. as an output only device. The Keyboard driver
  71. will not be set-up. This may be used, if you
  72. have none or more than one Keyboard devices
  73. (USB Keyboard, AT Keyboard).
  74. CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last character. No
  75. blinking is provided. Uses the macros CURSOR_SET
  76. and CURSOR_OFF.
  77. CONFIG_VIDEO_HW_CURSOR: - Uses the hardware cursor capability of the
  78. graphic chip. Uses the macro CURSOR_SET.
  79. ATTENTION: If booting an OS, the display driver
  80. must disable the hardware register of the graphic
  81. chip. Otherwise a blinking field is displayed
  82. */
  83. #include <common.h>
  84. #ifdef CONFIG_CFB_CONSOLE
  85. #include <malloc.h>
  86. /*****************************************************************************/
  87. /* Console device defines with SMI graphic */
  88. /* Any other graphic must change this section */
  89. /*****************************************************************************/
  90. #ifdef CONFIG_VIDEO_SMI_LYNXEM
  91. #define VIDEO_FB_LITTLE_ENDIAN
  92. #define VIDEO_HW_RECTFILL
  93. #define VIDEO_HW_BITBLT
  94. #endif
  95. /*****************************************************************************/
  96. /* Defines for the CT69000 driver */
  97. /*****************************************************************************/
  98. #ifdef CONFIG_VIDEO_CT69000
  99. #define VIDEO_FB_LITTLE_ENDIAN
  100. #define VIDEO_HW_RECTFILL
  101. #define VIDEO_HW_BITBLT
  102. #endif
  103. /*****************************************************************************/
  104. /* Defines for the SED13806 driver */
  105. /*****************************************************************************/
  106. #ifdef CONFIG_VIDEO_SED13806
  107. #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. #ifdef CFG_CMD_DATE
  151. #include <rtc.h>
  152. #endif
  153. #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  154. #include <watchdog.h>
  155. #include <bmp_layout.h>
  156. #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
  157. /*****************************************************************************/
  158. /* Cursor definition: */
  159. /* CONFIG_CONSOLE_CURSOR: Uses a timer function (see drivers/i8042.c) to */
  160. /* let the cursor blink. Uses the macros CURSOR_OFF */
  161. /* 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/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 (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, 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, 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. CURSOR_OFF console_row++;
  557. console_col = 0;
  558. /* Check if we need to scroll the terminal */
  559. if (console_row >= CONSOLE_ROWS) {
  560. /* Scroll everything up */
  561. console_scrollup ();
  562. /* Decrement row number */
  563. console_row--;
  564. }
  565. }
  566. /*****************************************************************************/
  567. void video_putc (const char c)
  568. {
  569. switch (c) {
  570. case 13: /* ignore */
  571. break;
  572. case '\n': /* next line */
  573. console_newline ();
  574. break;
  575. case 9: /* tab 8 */
  576. CURSOR_OFF console_col |= 0x0008;
  577. console_col &= ~0x0007;
  578. if (console_col >= CONSOLE_COLS)
  579. console_newline ();
  580. break;
  581. case 8: /* backspace */
  582. console_back ();
  583. break;
  584. default: /* draw the char */
  585. video_putchar (console_col * VIDEO_FONT_WIDTH,
  586. console_row * VIDEO_FONT_HEIGHT,
  587. c);
  588. console_col++;
  589. /* check for newline */
  590. if (console_col >= CONSOLE_COLS)
  591. console_newline ();
  592. }
  593. CURSOR_SET}
  594. /*****************************************************************************/
  595. void video_puts (const char *s)
  596. {
  597. int count = strlen (s);
  598. while (count--)
  599. video_putc (*s++);
  600. }
  601. /*****************************************************************************/
  602. #if (CONFIG_COMMANDS & CFG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  603. #define FILL_8BIT_332RGB(r,g,b) { \
  604. *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
  605. fb ++; \
  606. }
  607. #define FILL_15BIT_555RGB(r,g,b) { \
  608. *(unsigned short *)fb = SWAP16((unsigned short)(((r>>3)<<10) | ((g>>3)<<5) | (b>>3))); \
  609. fb += 2; \
  610. }
  611. #define FILL_16BIT_565RGB(r,g,b) { \
  612. *(unsigned short *)fb = SWAP16((unsigned short)((((r)>>3)<<11) | (((g)>>2)<<5) | ((b)>>3))); \
  613. fb += 2; \
  614. }
  615. #define FILL_32BIT_X888RGB(r,g,b) { \
  616. *(unsigned long *)fb = SWAP32((unsigned long)(((r<<16) | (g<<8) | b))); \
  617. fb += 4; \
  618. }
  619. #ifdef VIDEO_FB_LITTLE_ENDIAN
  620. #define FILL_24BIT_888RGB(r,g,b) { \
  621. fb[0] = b; \
  622. fb[1] = g; \
  623. fb[2] = r; \
  624. fb += 3; \
  625. }
  626. #else
  627. #define FILL_24BIT_888RGB(r,g,b) { \
  628. fb[0] = r; \
  629. fb[1] = g; \
  630. fb[2] = b; \
  631. fb += 3; \
  632. }
  633. #endif
  634. /*
  635. * Display the BMP file located at address bmp_image.
  636. * Only uncompressed
  637. */
  638. int video_display_bitmap (ulong bmp_image, int x, int y)
  639. {
  640. ushort xcount, ycount;
  641. uchar *fb;
  642. bmp_image_t *bmp = (bmp_image_t *) bmp_image;
  643. uchar *bmap;
  644. ushort padded_line;
  645. unsigned long width, height, bpp;
  646. unsigned colors;
  647. unsigned long compression;
  648. bmp_color_table_entry_t cte;
  649. #ifdef CONFIG_VIDEO_BMP_GZIP
  650. unsigned char *dst = NULL;
  651. ulong len;
  652. #endif
  653. WATCHDOG_RESET ();
  654. if (!((bmp->header.signature[0] == 'B') &&
  655. (bmp->header.signature[1] == 'M'))) {
  656. #ifdef CONFIG_VIDEO_BMP_GZIP
  657. /*
  658. * Could be a gzipped bmp image, try to decrompress...
  659. */
  660. len = CFG_VIDEO_LOGO_MAX_SIZE;
  661. dst = malloc(CFG_VIDEO_LOGO_MAX_SIZE);
  662. if (gunzip(dst, CFG_VIDEO_LOGO_MAX_SIZE, (uchar *)bmp_image, &len) != 0) {
  663. printf ("Error: no valid bmp or bmp.gz image at %lx\n", bmp_image);
  664. free(dst);
  665. return 1;
  666. }
  667. /*
  668. * Set addr to decompressed image
  669. */
  670. bmp = (bmp_image_t *)dst;
  671. if (!((bmp->header.signature[0] == 'B') &&
  672. (bmp->header.signature[1] == 'M'))) {
  673. printf ("Error: no valid bmp.gz image at %lx\n", bmp_image);
  674. return 1;
  675. }
  676. #else
  677. printf ("Error: no valid bmp image at %lx\n", bmp_image);
  678. return 1;
  679. #endif /* CONFIG_VIDEO_BMP_GZIP */
  680. }
  681. width = le32_to_cpu (bmp->header.width);
  682. height = le32_to_cpu (bmp->header.height);
  683. bpp = le16_to_cpu (bmp->header.bit_count);
  684. colors = le32_to_cpu (bmp->header.colors_used);
  685. compression = le32_to_cpu (bmp->header.compression);
  686. debug ("Display-bmp: %d x %d with %d colors\n",
  687. width, height, colors);
  688. if (compression != BMP_BI_RGB) {
  689. printf ("Error: compression type %ld not supported\n",
  690. compression);
  691. return 1;
  692. }
  693. padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
  694. if ((x + width) > VIDEO_VISIBLE_COLS)
  695. width = VIDEO_VISIBLE_COLS - x;
  696. if ((y + height) > VIDEO_VISIBLE_ROWS)
  697. height = VIDEO_VISIBLE_ROWS - y;
  698. bmap = (uchar *) bmp + le32_to_cpu (bmp->header.data_offset);
  699. fb = (uchar *) (video_fb_address +
  700. ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
  701. x * VIDEO_PIXEL_SIZE);
  702. /* We handle only 8bpp or 24 bpp bitmap */
  703. switch (le16_to_cpu (bmp->header.bit_count)) {
  704. case 8:
  705. padded_line -= width;
  706. if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
  707. /* Copy colormap */
  708. for (xcount = 0; xcount < colors; ++xcount) {
  709. cte = bmp->color_table[xcount];
  710. video_set_lut (xcount, cte.red, cte.green, cte.blue);
  711. }
  712. }
  713. ycount = height;
  714. switch (VIDEO_DATA_FORMAT) {
  715. case GDF__8BIT_INDEX:
  716. while (ycount--) {
  717. WATCHDOG_RESET ();
  718. xcount = width;
  719. while (xcount--) {
  720. *fb++ = *bmap++;
  721. }
  722. bmap += padded_line;
  723. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  724. }
  725. break;
  726. case GDF__8BIT_332RGB:
  727. while (ycount--) {
  728. WATCHDOG_RESET ();
  729. xcount = width;
  730. while (xcount--) {
  731. cte = bmp->color_table[*bmap++];
  732. FILL_8BIT_332RGB (cte.red, cte.green, cte.blue);
  733. }
  734. bmap += padded_line;
  735. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  736. }
  737. break;
  738. case GDF_15BIT_555RGB:
  739. while (ycount--) {
  740. WATCHDOG_RESET ();
  741. xcount = width;
  742. while (xcount--) {
  743. cte = bmp->color_table[*bmap++];
  744. FILL_15BIT_555RGB (cte.red, cte.green, cte.blue);
  745. }
  746. bmap += padded_line;
  747. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  748. }
  749. break;
  750. case GDF_16BIT_565RGB:
  751. while (ycount--) {
  752. WATCHDOG_RESET ();
  753. xcount = width;
  754. while (xcount--) {
  755. cte = bmp->color_table[*bmap++];
  756. FILL_16BIT_565RGB (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_32BIT_X888RGB:
  763. while (ycount--) {
  764. WATCHDOG_RESET ();
  765. xcount = width;
  766. while (xcount--) {
  767. cte = bmp->color_table[*bmap++];
  768. FILL_32BIT_X888RGB (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_24BIT_888RGB:
  775. while (ycount--) {
  776. WATCHDOG_RESET ();
  777. xcount = width;
  778. while (xcount--) {
  779. cte = bmp->color_table[*bmap++];
  780. FILL_24BIT_888RGB (cte.red, cte.green, cte.blue);
  781. }
  782. bmap += padded_line;
  783. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  784. }
  785. break;
  786. }
  787. break;
  788. case 24:
  789. padded_line -= 3 * width;
  790. ycount = height;
  791. switch (VIDEO_DATA_FORMAT) {
  792. case GDF__8BIT_332RGB:
  793. while (ycount--) {
  794. WATCHDOG_RESET ();
  795. xcount = width;
  796. while (xcount--) {
  797. FILL_8BIT_332RGB (bmap[2], bmap[1], bmap[0]);
  798. bmap += 3;
  799. }
  800. bmap += padded_line;
  801. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  802. }
  803. break;
  804. case GDF_15BIT_555RGB:
  805. while (ycount--) {
  806. WATCHDOG_RESET ();
  807. xcount = width;
  808. while (xcount--) {
  809. FILL_15BIT_555RGB (bmap[2], bmap[1], bmap[0]);
  810. bmap += 3;
  811. }
  812. bmap += padded_line;
  813. fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
  814. }
  815. break;
  816. case GDF_16BIT_565RGB:
  817. while (ycount--) {
  818. WATCHDOG_RESET ();
  819. xcount = width;
  820. while (xcount--) {
  821. FILL_16BIT_565RGB (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_32BIT_X888RGB:
  829. while (ycount--) {
  830. WATCHDOG_RESET ();
  831. xcount = width;
  832. while (xcount--) {
  833. FILL_32BIT_X888RGB (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_24BIT_888RGB:
  841. while (ycount--) {
  842. WATCHDOG_RESET ();
  843. xcount = width;
  844. while (xcount--) {
  845. FILL_24BIT_888RGB (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. default:
  853. printf ("Error: 24 bits/pixel bitmap incompatible with current video mode\n");
  854. break;
  855. }
  856. break;
  857. default:
  858. printf ("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
  859. le16_to_cpu (bmp->header.bit_count));
  860. break;
  861. }
  862. #ifdef CONFIG_VIDEO_BMP_GZIP
  863. if (dst) {
  864. free(dst);
  865. }
  866. #endif
  867. return (0);
  868. }
  869. #endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) || CONFIG_SPLASH_SCREEN */
  870. /*****************************************************************************/
  871. #ifdef CONFIG_VIDEO_LOGO
  872. void logo_plot (void *screen, int width, int x, int y)
  873. {
  874. int xcount, i;
  875. int skip = (width - VIDEO_LOGO_WIDTH) * VIDEO_PIXEL_SIZE;
  876. int ycount = VIDEO_LOGO_HEIGHT;
  877. unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
  878. unsigned char *source;
  879. unsigned char *dest = (unsigned char *)screen + ((y * width * VIDEO_PIXEL_SIZE) + x);
  880. #ifdef CONFIG_VIDEO_BMP_LOGO
  881. source = bmp_logo_bitmap;
  882. /* Allocate temporary space for computing colormap */
  883. logo_red = malloc (BMP_LOGO_COLORS);
  884. logo_green = malloc (BMP_LOGO_COLORS);
  885. logo_blue = malloc (BMP_LOGO_COLORS);
  886. /* Compute color map */
  887. for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
  888. logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
  889. logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
  890. logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
  891. }
  892. #else
  893. source = linux_logo;
  894. logo_red = linux_logo_red;
  895. logo_green = linux_logo_green;
  896. logo_blue = linux_logo_blue;
  897. #endif
  898. if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
  899. for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
  900. video_set_lut (i + VIDEO_LOGO_LUT_OFFSET,
  901. logo_red[i], logo_green[i], logo_blue[i]);
  902. }
  903. }
  904. while (ycount--) {
  905. xcount = VIDEO_LOGO_WIDTH;
  906. while (xcount--) {
  907. r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
  908. g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
  909. b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
  910. switch (VIDEO_DATA_FORMAT) {
  911. case GDF__8BIT_INDEX:
  912. *dest = *source;
  913. break;
  914. case GDF__8BIT_332RGB:
  915. *dest = ((r >> 5) << 5) | ((g >> 5) << 2) | (b >> 6);
  916. break;
  917. case GDF_15BIT_555RGB:
  918. *(unsigned short *) dest =
  919. SWAP16 ((unsigned short) (((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3)));
  920. break;
  921. case GDF_16BIT_565RGB:
  922. *(unsigned short *) dest =
  923. SWAP16 ((unsigned short) (((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)));
  924. break;
  925. case GDF_32BIT_X888RGB:
  926. *(unsigned long *) dest =
  927. SWAP32 ((unsigned long) ((r << 16) | (g << 8) | b));
  928. break;
  929. case GDF_24BIT_888RGB:
  930. #ifdef VIDEO_FB_LITTLE_ENDIAN
  931. dest[0] = b;
  932. dest[1] = g;
  933. dest[2] = r;
  934. #else
  935. dest[0] = r;
  936. dest[1] = g;
  937. dest[2] = b;
  938. #endif
  939. break;
  940. }
  941. source++;
  942. dest += VIDEO_PIXEL_SIZE;
  943. }
  944. dest += skip;
  945. }
  946. #ifdef CONFIG_VIDEO_BMP_LOGO
  947. free (logo_red);
  948. free (logo_green);
  949. free (logo_blue);
  950. #endif
  951. }
  952. /*****************************************************************************/
  953. static void *video_logo (void)
  954. {
  955. char info[128];
  956. extern char version_string;
  957. #ifdef CONFIG_SPLASH_SCREEN
  958. char *s;
  959. ulong addr;
  960. if ((s = getenv ("splashimage")) != NULL) {
  961. addr = simple_strtoul (s, NULL, 16);
  962. if (video_display_bitmap (addr, 0, 0) == 0) {
  963. return ((void *) (video_fb_address));
  964. }
  965. }
  966. #endif /* CONFIG_SPLASH_SCREEN */
  967. logo_plot (video_fb_address, VIDEO_COLS, 0, 0);
  968. sprintf (info, " %s", &version_string);
  969. video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);
  970. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  971. {
  972. int i, n = ((VIDEO_LOGO_HEIGHT - VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
  973. for (i = 1; i < n; i++) {
  974. video_get_info_str (i, info);
  975. if (*info)
  976. video_drawstring (VIDEO_INFO_X,
  977. VIDEO_INFO_Y + i * VIDEO_FONT_HEIGHT,
  978. info);
  979. }
  980. }
  981. #endif
  982. return (video_fb_address + VIDEO_LOGO_HEIGHT * VIDEO_LINE_LEN);
  983. }
  984. #endif
  985. /*****************************************************************************/
  986. static int video_init (void)
  987. {
  988. unsigned char color8;
  989. if ((pGD = video_hw_init ()) == NULL)
  990. return -1;
  991. video_fb_address = (void *) VIDEO_FB_ADRS;
  992. #ifdef CONFIG_VIDEO_HW_CURSOR
  993. video_init_hw_cursor (VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT);
  994. #endif
  995. /* Init drawing pats */
  996. switch (VIDEO_DATA_FORMAT) {
  997. case GDF__8BIT_INDEX:
  998. video_set_lut (0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, CONSOLE_FG_COL);
  999. video_set_lut (0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, CONSOLE_BG_COL);
  1000. fgx = 0x01010101;
  1001. bgx = 0x00000000;
  1002. break;
  1003. case GDF__8BIT_332RGB:
  1004. color8 = ((CONSOLE_FG_COL & 0xe0) |
  1005. ((CONSOLE_FG_COL >> 3) & 0x1c) | CONSOLE_FG_COL >> 6);
  1006. fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8;
  1007. color8 = ((CONSOLE_BG_COL & 0xe0) |
  1008. ((CONSOLE_BG_COL >> 3) & 0x1c) | CONSOLE_BG_COL >> 6);
  1009. bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8;
  1010. break;
  1011. case GDF_15BIT_555RGB:
  1012. fgx = (((CONSOLE_FG_COL >> 3) << 26) |
  1013. ((CONSOLE_FG_COL >> 3) << 21) | ((CONSOLE_FG_COL >> 3) << 16) |
  1014. ((CONSOLE_FG_COL >> 3) << 10) | ((CONSOLE_FG_COL >> 3) << 5) |
  1015. (CONSOLE_FG_COL >> 3));
  1016. bgx = (((CONSOLE_BG_COL >> 3) << 26) |
  1017. ((CONSOLE_BG_COL >> 3) << 21) | ((CONSOLE_BG_COL >> 3) << 16) |
  1018. ((CONSOLE_BG_COL >> 3) << 10) | ((CONSOLE_BG_COL >> 3) << 5) |
  1019. (CONSOLE_BG_COL >> 3));
  1020. break;
  1021. case GDF_16BIT_565RGB:
  1022. fgx = (((CONSOLE_FG_COL >> 3) << 27) |
  1023. ((CONSOLE_FG_COL >> 2) << 21) | ((CONSOLE_FG_COL >> 3) << 16) |
  1024. ((CONSOLE_FG_COL >> 3) << 11) | ((CONSOLE_FG_COL >> 2) << 5) |
  1025. (CONSOLE_FG_COL >> 3));
  1026. bgx = (((CONSOLE_BG_COL >> 3) << 27) |
  1027. ((CONSOLE_BG_COL >> 2) << 21) | ((CONSOLE_BG_COL >> 3) << 16) |
  1028. ((CONSOLE_BG_COL >> 3) << 11) | ((CONSOLE_BG_COL >> 2) << 5) |
  1029. (CONSOLE_BG_COL >> 3));
  1030. break;
  1031. case GDF_32BIT_X888RGB:
  1032. fgx = (CONSOLE_FG_COL << 16) | (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL;
  1033. bgx = (CONSOLE_BG_COL << 16) | (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL;
  1034. break;
  1035. case GDF_24BIT_888RGB:
  1036. fgx = (CONSOLE_FG_COL << 24) | (CONSOLE_FG_COL << 16) |
  1037. (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL;
  1038. bgx = (CONSOLE_BG_COL << 24) | (CONSOLE_BG_COL << 16) |
  1039. (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL;
  1040. break;
  1041. }
  1042. eorx = fgx ^ bgx;
  1043. #ifdef CONFIG_VIDEO_LOGO
  1044. /* Plot the logo and get start point of console */
  1045. PRINTD ("Video: Drawing the logo ...\n");
  1046. video_console_address = video_logo ();
  1047. #else
  1048. video_console_address = video_fb_address;
  1049. #endif
  1050. /* Initialize the console */
  1051. console_col = 0;
  1052. console_row = 0;
  1053. return 0;
  1054. }
  1055. /*****************************************************************************/
  1056. int drv_video_init (void)
  1057. {
  1058. int skip_dev_init;
  1059. device_t console_dev;
  1060. skip_dev_init = 0;
  1061. /* Init video chip - returns with framebuffer cleared */
  1062. if (video_init () == -1)
  1063. skip_dev_init = 1;
  1064. #ifdef CONFIG_VGA_AS_SINGLE_DEVICE
  1065. /* Devices VGA and Keyboard will be assigned seperately */
  1066. /* Init vga device */
  1067. if (!skip_dev_init) {
  1068. memset (&console_dev, 0, sizeof (console_dev));
  1069. strcpy (console_dev.name, "vga");
  1070. console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
  1071. console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
  1072. console_dev.putc = video_putc; /* 'putc' function */
  1073. console_dev.puts = video_puts; /* 'puts' function */
  1074. console_dev.tstc = NULL; /* 'tstc' function */
  1075. console_dev.getc = NULL; /* 'getc' function */
  1076. if (device_register (&console_dev) == 0)
  1077. return 1;
  1078. }
  1079. #else
  1080. PRINTD ("KBD: Keyboard init ...\n");
  1081. if (VIDEO_KBD_INIT_FCT == -1)
  1082. skip_dev_init = 1;
  1083. /* Init console device */
  1084. if (!skip_dev_init) {
  1085. memset (&console_dev, 0, sizeof (console_dev));
  1086. strcpy (console_dev.name, "vga");
  1087. console_dev.ext = DEV_EXT_VIDEO; /* Video extensions */
  1088. console_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
  1089. console_dev.putc = video_putc; /* 'putc' function */
  1090. console_dev.puts = video_puts; /* 'puts' function */
  1091. console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
  1092. console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
  1093. if (device_register (&console_dev) == 0)
  1094. return 1;
  1095. }
  1096. #endif /* CONFIG_VGA_AS_SINGLE_DEVICE */
  1097. /* No console dev available */
  1098. return 0;
  1099. }
  1100. #endif /* CONFIG_CFB_CONSOLE */