cfb_console.c 39 KB

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