cfb_console.c 41 KB

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