cfb_console.c 40 KB

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